Fri, 29 Apr 2016 11:06:40 -0400
Fix the concurrency issue for 3A2000-1way.
1 /*
2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2015, 2016, Loongson Technology. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
26 #include "precompiled.hpp"
27 #include "asm/macroAssembler.hpp"
28 #include "interpreter/interpreter.hpp"
29 #include "interpreter/interpreterRuntime.hpp"
30 #include "interpreter/templateTable.hpp"
31 #include "memory/universe.inline.hpp"
32 #include "oops/methodData.hpp"
33 #include "oops/objArrayKlass.hpp"
34 #include "oops/oop.inline.hpp"
35 #include "prims/methodHandles.hpp"
36 #include "runtime/sharedRuntime.hpp"
37 #include "runtime/stubRoutines.hpp"
38 #include "runtime/synchronizer.hpp"
41 #ifndef CC_INTERP
43 #define __ _masm->
45 // Platform-dependent initialization
47 void TemplateTable::pd_initialize() {
48 // No mips specific initialization
49 }
51 // Address computation: local variables
52 // we use t8 as the local variables pointer register, by yjl 6/27/2005
53 static inline Address iaddress(int n) {
54 return Address(LVP, Interpreter::local_offset_in_bytes(n));
55 }
57 static inline Address laddress(int n) {
58 return iaddress(n + 1);
59 }
61 static inline Address faddress(int n) {
62 return iaddress(n);
63 }
65 static inline Address daddress(int n) {
66 return laddress(n);
67 }
69 static inline Address aaddress(int n) {
70 return iaddress(n);
71 }
72 static inline Address haddress(int n) { return iaddress(n + 0); }
74 //FIXME , can not use dadd and dsll
75 /*
76 static inline Address iaddress(Register r) {
77 return Address(r14, r, Address::times_8, Interpreter::value_offset_in_bytes());
78 }
80 static inline Address laddress(Register r) {
81 return Address(r14, r, Address::times_8, Interpreter::local_offset_in_bytes(1));
82 }
84 static inline Address faddress(Register r) {
85 return iaddress(r);
86 }
88 static inline Address daddress(Register r) {
89 return laddress(r);
90 }
92 static inline Address aaddress(Register r) {
93 return iaddress(r);
94 }
95 */
97 static inline Address at_sp() { return Address(SP, 0); }
98 static inline Address at_sp_p1() { return Address(SP, 1 * wordSize); }
99 static inline Address at_sp_p2() { return Address(SP, 2 * wordSize); }
101 // At top of Java expression stack which may be different than esp(). It
102 // isn't for category 1 objects.
103 static inline Address at_tos () {
104 Address tos = Address(SP, Interpreter::expr_offset_in_bytes(0));
105 return tos;
106 }
108 static inline Address at_tos_p1() {
109 return Address(SP, Interpreter::expr_offset_in_bytes(1));
110 }
112 static inline Address at_tos_p2() {
113 return Address(SP, Interpreter::expr_offset_in_bytes(2));
114 }
116 static inline Address at_tos_p3() {
117 return Address(SP, Interpreter::expr_offset_in_bytes(3));
118 }
120 // we use S0 as bcp, be sure you have bcp in S0 before you call any of the Template generator
121 Address TemplateTable::at_bcp(int offset) {
122 assert(_desc->uses_bcp(), "inconsistent uses_bcp information");
123 return Address(BCP, offset);
124 }
126 #define callee_saved_register(R) assert((R>=S0 && R<=S7), "should use callee saved registers!")
128 // bytecode folding
129 void TemplateTable::patch_bytecode(Bytecodes::Code bc, Register bc_reg,
130 Register tmp_reg,
131 bool load_bc_into_bc_reg,/*=true*/
132 int byte_no) {
133 if (!RewriteBytecodes) {
134 return;
135 }
137 Label L_patch_done;
138 switch (bc) {
139 case Bytecodes::_fast_aputfield:
140 case Bytecodes::_fast_bputfield:
141 case Bytecodes::_fast_cputfield:
142 case Bytecodes::_fast_dputfield:
143 case Bytecodes::_fast_fputfield:
144 case Bytecodes::_fast_iputfield:
145 case Bytecodes::_fast_lputfield:
146 case Bytecodes::_fast_sputfield:
147 {
148 // We skip bytecode quickening for putfield instructions when the put_code written to the constant pool cache
149 // is zero. This is required so that every execution of this instruction calls out to
150 // InterpreterRuntime::resolve_get_put to do additional, required work.
151 assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
152 assert(load_bc_into_bc_reg, "we use bc_reg as temp");
153 __ get_cache_and_index_and_bytecode_at_bcp(tmp_reg, bc_reg, tmp_reg, byte_no, 1);
154 __ daddi(bc_reg, R0, bc);
155 __ beq(tmp_reg, R0, L_patch_done);
156 __ delayed()->nop();
157 }
158 break;
159 default:
160 assert(byte_no == -1, "sanity");
161 // the pair bytecodes have already done the load.
162 if (load_bc_into_bc_reg) {
163 __ move(bc_reg, bc);
164 }
166 }
167 if (JvmtiExport::can_post_breakpoint()) {
168 Label L_fast_patch;
169 // if a breakpoint is present we can't rewrite the stream directly
170 __ lbu(tmp_reg, at_bcp(0));
171 __ move(AT, Bytecodes::_breakpoint);
172 __ bne(tmp_reg, AT, L_fast_patch);
173 __ delayed()->nop();
175 __ get_method(tmp_reg);
176 // Let breakpoint table handling rewrite to quicker bytecode
177 __ call_VM(NOREG, CAST_FROM_FN_PTR(address,
178 InterpreterRuntime::set_original_bytecode_at), tmp_reg, BCP, bc_reg);
180 __ b(L_patch_done);
181 __ delayed()->nop();
182 __ bind(L_fast_patch);
183 }
185 #ifdef ASSERT
186 Label L_okay;
187 __ lbu(tmp_reg, at_bcp(0));
188 __ move(AT, (int)Bytecodes::java_code(bc));
189 __ beq(tmp_reg, AT, L_okay);
190 __ delayed()->nop();
191 __ beq(tmp_reg, bc_reg, L_patch_done);
192 __ delayed()->nop();
193 __ stop("patching the wrong bytecode");
194 __ bind(L_okay);
195 #endif
197 // patch bytecode
198 __ sb(bc_reg, at_bcp(0));
199 __ bind(L_patch_done);
200 }
203 // Individual instructions
205 void TemplateTable::nop() {
206 transition(vtos, vtos);
207 // nothing to do
208 }
210 void TemplateTable::shouldnotreachhere() {
211 transition(vtos, vtos);
212 __ stop("shouldnotreachhere bytecode");
213 }
215 void TemplateTable::aconst_null() {
216 transition(vtos, atos);
217 __ move(FSR, R0);
218 }
220 void TemplateTable::iconst(int value) {
221 transition(vtos, itos);
222 if (value == 0) {
223 __ move(FSR, R0);
224 } else {
225 __ move(FSR, value);
226 }
227 }
229 void TemplateTable::lconst(int value) {
230 transition(vtos, ltos);
231 if (value == 0) {
232 __ move(FSR, R0);
233 } else {
234 __ move(FSR, value);
235 }
236 assert(value >= 0, "check this code");
237 //__ move(SSR, R0);
238 }
240 void TemplateTable::fconst(int value) {
241 static float _f1 = 1.0, _f2 = 2.0;
242 transition(vtos, ftos);
243 float* p;
244 switch( value ) {
245 default: ShouldNotReachHere();
246 case 0: __ dmtc1(R0, FSF); return;
247 case 1: p = &_f1; break;
248 case 2: p = &_f2; break;
249 }
250 __ li(AT, (address)p);
251 __ lwc1(FSF, AT, 0);
252 }
254 void TemplateTable::dconst(int value) {
255 static double _d1 = 1.0;
256 transition(vtos, dtos);
257 double* p;
258 switch( value ) {
259 default: ShouldNotReachHere();
260 case 0: __ dmtc1(R0, FSF); return;
261 case 1: p = &_d1; break;
262 }
263 __ li(AT, (address)p);
264 __ ldc1(FSF, AT, 0);
265 }
267 void TemplateTable::bipush() {
268 transition(vtos, itos);
269 __ lb(FSR, at_bcp(1));
270 }
272 void TemplateTable::sipush() {
273 transition(vtos, itos);
274 __ get_2_byte_integer_at_bcp(FSR, AT, 1);
275 __ hswap(FSR);
276 }
278 // T1 : tags
279 // T2 : index
280 // T3 : cpool
281 // T8 : tag
282 void TemplateTable::ldc(bool wide) {
283 transition(vtos, vtos);
284 Label call_ldc, notFloat, notClass, Done;
285 // get index in cpool
286 if (wide) {
287 __ get_2_byte_integer_at_bcp(T2, AT, 1);
288 __ huswap(T2);
289 } else {
290 __ lbu(T2, at_bcp(1));
291 }
293 __ get_cpool_and_tags(T3, T1);
295 const int base_offset = ConstantPool::header_size() * wordSize;
296 const int tags_offset = Array<u1>::base_offset_in_bytes();
298 // get type
299 __ dadd(AT, T1, T2);
300 __ lb(T1, AT, tags_offset);
301 //now T1 is the tag
303 // unresolved string - get the resolved string
304 /*__ daddiu(AT, T1, - JVM_CONSTANT_UnresolvedString);
305 __ beq(AT, R0, call_ldc);
306 __ delayed()->nop();*/
308 // unresolved class - get the resolved class
309 __ daddiu(AT, T1, - JVM_CONSTANT_UnresolvedClass);
310 __ beq(AT, R0, call_ldc);
311 __ delayed()->nop();
313 // unresolved class in error (resolution failed) - call into runtime
314 // so that the same error from first resolution attempt is thrown.
315 __ daddiu(AT, T1, -JVM_CONSTANT_UnresolvedClassInError);
316 __ beq(AT, R0, call_ldc);
317 __ delayed()->nop();
319 // resolved class - need to call vm to get java mirror of the class
320 __ daddiu(AT, T1, - JVM_CONSTANT_Class);
321 __ bne(AT, R0, notClass);
322 __ delayed()->dsll(T2, T2, Address::times_8);
324 __ bind(call_ldc);
326 __ move(A1, wide);
327 call_VM(FSR, CAST_FROM_FN_PTR(address, InterpreterRuntime::ldc), A1);
328 // __ sw(FSR, SP, - 1 * wordSize);
329 __ push(atos);
330 __ b(Done);
331 // __ delayed()->daddi(SP, SP, - 1 * wordSize);
332 __ delayed()->nop();
333 __ bind(notClass);
335 __ daddiu(AT, T1, -JVM_CONSTANT_Float);
336 __ bne(AT, R0, notFloat);
337 __ delayed()->nop();
338 // ftos
339 __ dadd(AT, T3, T2);
340 __ lwc1(FSF, AT, base_offset);
341 __ push_f();
342 __ b(Done);
343 __ delayed()->nop();
345 __ bind(notFloat);
346 #ifdef ASSERT
347 {
348 Label L;
349 __ daddiu(AT, T1, -JVM_CONSTANT_Integer);
350 __ beq(AT, R0, L);
351 __ delayed()->nop();
352 __ stop("unexpected tag type in ldc");
353 __ bind(L);
354 }
355 #endif
356 // atos and itos
357 __ dadd(T0, T3, T2);
358 __ lw(FSR, T0, base_offset);
359 __ push(itos);
360 __ b(Done);
361 __ delayed()->nop();
364 if (VerifyOops) {
365 __ verify_oop(FSR);
366 }
368 __ bind(Done);
369 }
371 // Fast path for caching oop constants.
372 void TemplateTable::fast_aldc(bool wide) {
373 transition(vtos, atos);
375 Register result = FSR;
376 Register tmp = SSR;
377 int index_size = wide ? sizeof(u2) : sizeof(u1);
379 Label resolved;
380 // We are resolved if the resolved reference cache entry contains a
381 // non-null object (String, MethodType, etc.)
382 assert_different_registers(result, tmp);
383 __ get_cache_index_at_bcp(tmp, 1, index_size);
384 __ load_resolved_reference_at_index(result, tmp);
385 __ bne(result, R0, resolved);
386 __ delayed()->nop();
388 address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_ldc);
389 // first time invocation - must resolve first
390 int i = (int)bytecode();
391 __ move(tmp, i);
392 __ call_VM(result, entry, tmp);
394 __ bind(resolved);
396 if (VerifyOops) {
397 __ verify_oop(result);
398 }
399 }
402 // used register: T2, T3, T1
403 // T2 : index
404 // T3 : cpool
405 // T1 : tag
406 void TemplateTable::ldc2_w() {
407 transition(vtos, vtos);
408 Label Long, Done;
410 // get index in cpool
411 __ get_2_byte_integer_at_bcp(T2, AT, 1);
412 __ huswap(T2);
414 __ get_cpool_and_tags(T3, T1);
416 const int base_offset = ConstantPool::header_size() * wordSize;
417 const int tags_offset = Array<u1>::base_offset_in_bytes();
419 // get type in T1
420 __ dadd(AT, T1, T2);
421 __ lb(T1, AT, tags_offset);
423 __ daddiu(AT, T1, - JVM_CONSTANT_Double);
424 __ bne(AT, R0, Long);
425 __ delayed()->dsll(T2, T2, Address::times_8);
426 // dtos
427 __ daddu(AT, T3, T2);
428 __ ldc1(FSF, AT, base_offset + 0 * wordSize);
429 __ sdc1(FSF, SP, - 2 * wordSize);
430 __ b(Done);
431 __ delayed()->daddi(SP, SP, - 2 * wordSize);
433 // ltos
434 __ bind(Long);
435 __ dadd(AT, T3, T2);
436 __ ld(FSR, AT, base_offset + 0 * wordSize);
437 __ push(ltos);
439 __ bind(Done);
440 }
442 // we compute the actual local variable address here
443 // the x86 dont do so for it has scaled index memory access model, we dont have, so do here
444 void TemplateTable::locals_index(Register reg, int offset) {
445 __ lbu(reg, at_bcp(offset));
446 __ dsll(reg, reg, Address::times_8);
447 __ dsub(reg, LVP, reg);
448 }
450 // this method will do bytecode folding of the two form:
451 // iload iload iload caload
452 // used register : T2, T3
453 // T2 : bytecode
454 // T3 : folded code
455 void TemplateTable::iload() {
456 transition(vtos, itos);
457 if (RewriteFrequentPairs) {
458 Label rewrite, done;
459 // get the next bytecode in T2
460 __ lbu(T2, at_bcp(Bytecodes::length_for(Bytecodes::_iload)));
461 // if _iload, wait to rewrite to iload2. We only want to rewrite the
462 // last two iloads in a pair. Comparing against fast_iload means that
463 // the next bytecode is neither an iload or a caload, and therefore
464 // an iload pair.
465 __ move(AT, Bytecodes::_iload);
466 __ beq(AT, T2, done);
467 __ delayed()->nop();
469 __ move(T3, Bytecodes::_fast_iload2);
470 __ move(AT, Bytecodes::_fast_iload);
471 __ beq(AT, T2, rewrite);
472 __ delayed()->nop();
474 // if _caload, rewrite to fast_icaload
475 __ move(T3, Bytecodes::_fast_icaload);
476 __ move(AT, Bytecodes::_caload);
477 __ beq(AT, T2, rewrite);
478 __ delayed()->nop();
480 // rewrite so iload doesn't check again.
481 __ move(T3, Bytecodes::_fast_iload);
483 // rewrite
484 // T3 : fast bytecode
485 __ bind(rewrite);
486 patch_bytecode(Bytecodes::_iload, T3, T2, false);
487 __ bind(done);
488 }
490 // Get the local value into tos
491 locals_index(T2);
492 __ lw(FSR, T2, 0);
493 }
495 // used register T2
496 // T2 : index
497 void TemplateTable::fast_iload2() {
498 transition(vtos, itos);
499 locals_index(T2);
500 __ lw(FSR, T2, 0);
501 __ push(itos);
502 locals_index(T2, 3);
503 __ lw(FSR, T2, 0);
504 }
506 // used register T2
507 // T2 : index
508 void TemplateTable::fast_iload() {
509 transition(vtos, itos);
510 locals_index(T2);
511 __ lw(FSR, T2, 0);
512 }
514 // used register T2
515 // T2 : index
516 void TemplateTable::lload() {
518 transition(vtos, ltos);
519 locals_index(T2);
520 __ ld(FSR, T2, -wordSize);
521 __ ld(SSR, T2, 0);
522 }
524 // used register T2
525 // T2 : index
526 void TemplateTable::fload() {
527 transition(vtos, ftos);
528 locals_index(T2);
529 //FIXME, aoqi. How should the high 32bits be when store a single float into a 64bits register.
530 //__ mtc1(R0, FSF);
531 __ lwc1(FSF, T2, 0);
532 }
534 // used register T2
535 // T2 : index
536 void TemplateTable::dload() {
538 transition(vtos, dtos);
539 locals_index(T2);
540 /* if (TaggedStackInterpreter) {
541 // Get double out of locals array, onto temp stack and load with
542 // float instruction into ST0
543 __ dsll(AT,T2,Interpreter::stackElementScale());
544 __ dadd(AT, LVP, AT);
545 __ ldc1(FSF, AT, Interpreter::local_offset_in_bytes(1));
546 } else {*/
547 __ ldc1(FSF, T2, -wordSize);
548 __ ldc1(SSF, T2, 0);
549 // }
550 }
552 // used register T2
553 // T2 : index
554 void TemplateTable::aload()
555 {
556 transition(vtos, atos);
557 locals_index(T2);
558 __ ld(FSR, T2, 0);
559 }
561 void TemplateTable::locals_index_wide(Register reg) {
562 __ get_2_byte_integer_at_bcp(reg, AT, 2);
563 __ huswap(reg);
564 __ dsll(reg, reg, Address::times_8);
565 __ dsub(reg, LVP, reg);
566 }
568 // used register T2
569 // T2 : index
570 void TemplateTable::wide_iload() {
571 transition(vtos, itos);
572 locals_index_wide(T2);
573 __ ld(FSR, T2, 0);
574 }
576 // used register T2
577 // T2 : index
578 void TemplateTable::wide_lload() {
579 transition(vtos, ltos);
580 locals_index_wide(T2);
581 __ ld(FSR, T2, -4);
582 }
584 // used register T2
585 // T2 : index
586 void TemplateTable::wide_fload() {
587 transition(vtos, ftos);
588 locals_index_wide(T2);
589 __ lwc1(FSF, T2, 0);
590 }
592 // used register T2
593 // T2 : index
594 void TemplateTable::wide_dload() {
595 transition(vtos, dtos);
596 locals_index_wide(T2);
597 /* if (TaggedStackInterpreter) {
598 // Get double out of locals array, onto temp stack and load with
599 // float instruction into ST0
600 // __ movl(eax, laddress(ebx));
601 // __ movl(edx, haddress(ebx));
602 __ dsll(AT,T2,Interpreter::stackElementScale());
603 __ dadd(AT, LVP, AT);
604 __ ldc1(FSF, AT, Interpreter::local_offset_in_bytes(1));
606 // __ pushl(edx); // push hi first
607 // __ pushl(eax);
608 // __ fld_d(Address(esp));
609 // __ addl(esp, 2*wordSize);
610 } else {*/
611 __ ldc1(FSF, T2, -4);
612 //}
613 }
615 // used register T2
616 // T2 : index
617 void TemplateTable::wide_aload() {
618 transition(vtos, atos);
619 locals_index_wide(T2);
620 __ ld(FSR, T2, 0);
621 }
623 // we use A2 as the regiser for index, BE CAREFUL!
624 // we dont use our tge 29 now, for later optimization
625 void TemplateTable::index_check(Register array, Register index) {
626 // Pop ptr into array
627 __ pop_ptr(array);
628 index_check_without_pop(array, index);
629 }
631 void TemplateTable::index_check_without_pop(Register array, Register index) {
632 // destroys ebx
633 // check array
634 __ null_check(array, arrayOopDesc::length_offset_in_bytes());
636 // check index
637 Label ok;
638 __ lw(AT, array, arrayOopDesc::length_offset_in_bytes());
639 #ifndef OPT_RANGECHECK
640 __ sltu(AT, index, AT);
641 __ bne(AT, R0, ok);
642 __ delayed()->nop();
644 //throw_ArrayIndexOutOfBoundsException assume abberrant index in A2
645 if (A2 != index) __ move(A2, index);
646 __ jmp(Interpreter::_throw_ArrayIndexOutOfBoundsException_entry);
647 __ delayed()->nop();
648 __ bind(ok);
649 #else
650 __ lw(AT, array, arrayOopDesc::length_offset_in_bytes());
651 __ move(A2, index);
652 __ tgeu(A2, AT, 29);
653 #endif
654 }
656 void TemplateTable::iaload() {
657 transition(itos, itos);
658 // __ pop(SSR);
659 index_check(SSR, FSR);
660 __ dsll(FSR, FSR, 2);
661 __ dadd(FSR, SSR, FSR);
662 //FSR: index
663 __ lw(FSR, FSR, arrayOopDesc::base_offset_in_bytes(T_INT));
664 }
667 void TemplateTable::laload() {
668 transition(itos, ltos);
669 // __ pop(SSR);
670 index_check(SSR, FSR);
671 __ dsll(AT, FSR, Address::times_8);
672 __ dadd(AT, SSR, AT);
673 __ ld(FSR, AT, arrayOopDesc::base_offset_in_bytes(T_LONG) + 0 * wordSize);
674 }
676 void TemplateTable::faload() {
677 transition(itos, ftos);
678 // __ pop(SSR);
679 index_check(SSR, FSR);
680 __ shl(FSR, 2);
681 __ dadd(FSR, SSR, FSR);
682 __ lwc1(FSF, FSR, arrayOopDesc::base_offset_in_bytes(T_FLOAT));
683 }
685 void TemplateTable::daload() {
686 transition(itos, dtos);
687 //__ pop(SSR);
688 index_check(SSR, FSR);
689 __ dsll(AT, FSR, 3);
690 __ dadd(AT, SSR, AT);
691 __ ldc1(FSF, AT, arrayOopDesc::base_offset_in_bytes(T_DOUBLE) + 0 * wordSize);
692 }
694 void TemplateTable::aaload() {
695 transition(itos, atos);
696 //__ pop(SSR);
697 index_check(SSR, FSR);
698 __ dsll(FSR, FSR, UseCompressedOops ? Address::times_4 : Address::times_8);
699 __ dadd(FSR, SSR, FSR);
700 //add for compressedoops
701 __ load_heap_oop(FSR, Address(FSR, arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
702 }
704 void TemplateTable::baload() {
705 transition(itos, itos);
706 //__ pop(SSR);
707 index_check(SSR, FSR);
708 __ dadd(FSR, SSR, FSR);
709 __ lb(FSR, FSR, arrayOopDesc::base_offset_in_bytes(T_BYTE));
710 }
712 void TemplateTable::caload() {
713 transition(itos, itos);
714 // __ pop(SSR);
715 index_check(SSR, FSR);
716 __ dsll(FSR, FSR, Address::times_2);
717 __ dadd(FSR, SSR, FSR);
718 __ lhu(FSR, FSR, arrayOopDesc::base_offset_in_bytes(T_CHAR));
719 }
721 // iload followed by caload frequent pair
722 // used register : T2
723 // T2 : index
724 void TemplateTable::fast_icaload() {
725 transition(vtos, itos);
726 // load index out of locals
727 locals_index(T2);
728 __ lw(FSR, T2, 0);
729 // __ pop(SSR);
730 index_check(SSR, FSR);
731 __ dsll(FSR, FSR, 1);
732 __ dadd(FSR, SSR, FSR);
733 __ lhu(FSR, FSR, arrayOopDesc::base_offset_in_bytes(T_CHAR));
734 }
736 void TemplateTable::saload() {
737 transition(itos, itos);
738 // __ pop(SSR);
739 index_check(SSR, FSR);
740 __ dsll(FSR, FSR, Address::times_2);
741 __ dadd(FSR, SSR, FSR);
742 __ lh(FSR, FSR, arrayOopDesc::base_offset_in_bytes(T_SHORT));
743 }
745 void TemplateTable::iload(int n) {
746 transition(vtos, itos);
747 __ lw(FSR, iaddress(n));
748 }
750 void TemplateTable::lload(int n) {
751 transition(vtos, ltos);
752 __ ld(FSR, laddress(n));
753 }
755 void TemplateTable::fload(int n) {
756 transition(vtos, ftos);
757 //__ mtc1(R0, FSF);
758 __ lwc1(FSF, faddress(n));
759 }
760 //FIXME here
761 void TemplateTable::dload(int n) {
762 transition(vtos, dtos);
763 __ ldc1(FSF, laddress(n));
764 }
766 void TemplateTable::aload(int n) {
767 transition(vtos, atos);
768 __ ld(FSR, aaddress(n));
769 }
771 // used register : T2, T3
772 // T2 : bytecode
773 // T3 : folded code
774 void TemplateTable::aload_0() {
775 transition(vtos, atos);
776 // According to bytecode histograms, the pairs:
777 //
778 // _aload_0, _fast_igetfield
779 // _aload_0, _fast_agetfield
780 // _aload_0, _fast_fgetfield
781 //
782 // occur frequently. If RewriteFrequentPairs is set, the (slow) _aload_0
783 // bytecode checks if the next bytecode is either _fast_igetfield,
784 // _fast_agetfield or _fast_fgetfield and then rewrites the
785 // current bytecode into a pair bytecode; otherwise it rewrites the current
786 // bytecode into _fast_aload_0 that doesn't do the pair check anymore.
787 //
788 // Note: If the next bytecode is _getfield, the rewrite must be delayed,
789 // otherwise we may miss an opportunity for a pair.
790 //
791 // Also rewrite frequent pairs
792 // aload_0, aload_1
793 // aload_0, iload_1
794 // These bytecodes with a small amount of code are most profitable to rewrite
795 if (RewriteFrequentPairs) {
796 Label rewrite, done;
797 // get the next bytecode in T2
798 __ lbu(T2, at_bcp(Bytecodes::length_for(Bytecodes::_aload_0)));
800 // do actual aload_0
801 aload(0);
803 // if _getfield then wait with rewrite
804 __ move(AT, Bytecodes::_getfield);
805 __ beq(AT, T2, done);
806 __ delayed()->nop();
808 // if _igetfield then reqrite to _fast_iaccess_0
809 assert(Bytecodes::java_code(Bytecodes::_fast_iaccess_0) ==
810 Bytecodes::_aload_0, "fix bytecode definition");
811 __ move(T3, Bytecodes::_fast_iaccess_0);
812 __ move(AT, Bytecodes::_fast_igetfield);
813 __ beq(AT, T2, rewrite);
814 __ delayed()->nop();
816 // if _agetfield then reqrite to _fast_aaccess_0
817 assert(Bytecodes::java_code(Bytecodes::_fast_aaccess_0) ==
818 Bytecodes::_aload_0, "fix bytecode definition");
819 __ move(T3, Bytecodes::_fast_aaccess_0);
820 __ move(AT, Bytecodes::_fast_agetfield);
821 __ beq(AT, T2, rewrite);
822 __ delayed()->nop();
824 // if _fgetfield then reqrite to _fast_faccess_0
825 assert(Bytecodes::java_code(Bytecodes::_fast_faccess_0) ==
826 Bytecodes::_aload_0, "fix bytecode definition");
827 __ move(T3, Bytecodes::_fast_faccess_0);
828 __ move(AT, Bytecodes::_fast_fgetfield);
829 __ beq(AT, T2, rewrite);
830 __ delayed()->nop();
832 // else rewrite to _fast_aload0
833 assert(Bytecodes::java_code(Bytecodes::_fast_aload_0) ==
834 Bytecodes::_aload_0, "fix bytecode definition");
835 __ move(T3, Bytecodes::_fast_aload_0);
837 // rewrite
838 __ bind(rewrite);
839 patch_bytecode(Bytecodes::_aload_0, T3, T2, false);
841 __ bind(done);
842 } else {
843 aload(0);
844 }
845 }
847 void TemplateTable::istore() {
848 transition(itos, vtos);
849 locals_index(T2);
850 __ sw(FSR, T2, 0);
851 }
853 void TemplateTable::lstore() {
854 transition(ltos, vtos);
855 locals_index(T2);
856 __ sd(FSR, T2, -wordSize);
857 }
859 void TemplateTable::fstore() {
860 transition(ftos, vtos);
861 locals_index(T2);
862 __ swc1(FSF, T2, 0);
863 }
865 void TemplateTable::dstore() {
866 transition(dtos, vtos);
867 locals_index(T2);
868 __ sdc1(FSF, T2, -wordSize);
869 }
871 void TemplateTable::astore() {
872 transition(vtos, vtos);
873 // __ pop(FSR);
874 __ pop_ptr(FSR);
875 locals_index(T2);
876 __ sd(FSR, T2, 0);
877 }
879 void TemplateTable::wide_istore() {
880 transition(vtos, vtos);
881 // __ pop(FSR);
882 __ pop_i(FSR);
883 locals_index_wide(T2);
884 __ sd(FSR, T2, 0);
885 }
887 void TemplateTable::wide_lstore() {
888 transition(vtos, vtos);
889 //__ pop2(FSR, SSR);
890 //__ pop_l(FSR, SSR);
891 __ pop_l(FSR); //aoqi:FIXME Is this right?
892 locals_index_wide(T2);
893 __ sd(FSR, T2, -4);
894 }
896 void TemplateTable::wide_fstore() {
897 wide_istore();
898 }
900 void TemplateTable::wide_dstore() {
901 wide_lstore();
902 }
904 void TemplateTable::wide_astore() {
905 transition(vtos, vtos);
906 __ pop_ptr(FSR);
907 locals_index_wide(T2);
908 __ sd(FSR, T2, 0);
909 }
911 // used register : T2
912 void TemplateTable::iastore() {
913 transition(itos, vtos);
914 __ pop_i(SSR);
915 index_check(T2, SSR); // prefer index in ebx
916 __ dsll(SSR, SSR, Address::times_4);
917 __ dadd(T2, T2, SSR);
918 __ sw(FSR, T2, arrayOopDesc::base_offset_in_bytes(T_INT));
919 }
923 // used register T2, T3
924 void TemplateTable::lastore() {
925 transition(ltos, vtos);
926 __ pop_i (T2);
927 index_check(T3, T2);
928 __ dsll(T2, T2, Address::times_8);
929 __ dadd(T3, T3, T2);
930 __ sd(FSR, T3, arrayOopDesc::base_offset_in_bytes(T_LONG) + 0 * wordSize);
931 }
933 // used register T2
934 void TemplateTable::fastore() {
935 transition(ftos, vtos);
936 __ pop_i(SSR);
937 index_check(T2, SSR);
938 __ dsll(SSR, SSR, Address::times_4);
939 __ dadd(T2, T2, SSR);
940 __ swc1(FSF, T2, arrayOopDesc::base_offset_in_bytes(T_FLOAT));
941 }
943 // used register T2, T3
944 void TemplateTable::dastore() {
945 transition(dtos, vtos);
946 __ pop_i (T2);
947 index_check(T3, T2);
948 __ dsll(T2, T2, Address::times_8);
949 __ daddu(T3, T3, T2);
950 __ sdc1(FSF, T3, arrayOopDesc::base_offset_in_bytes(T_DOUBLE) + 0 * wordSize);
952 }
954 // used register : T2, T3, T8
955 // T2 : array
956 // T3 : subklass
957 // T8 : supklass
958 void TemplateTable::aastore() {
959 Label is_null, ok_is_subtype, done;
960 transition(vtos, vtos);
961 // stack: ..., array, index, value
962 __ ld(FSR, at_tos()); // Value
963 __ lw(SSR, at_tos_p1()); // Index
964 __ ld(T2, at_tos_p2()); // Array
966 // index_check(T2, SSR);
967 index_check_without_pop(T2, SSR);
968 // do array store check - check for NULL value first
969 __ beq(FSR, R0, is_null);
970 __ delayed()->nop();
972 // Move subklass into T3
973 //__ ld(T3, Address(FSR, oopDesc::klass_offset_in_bytes()));
974 //add for compressedoops
975 __ load_klass(T3, FSR);
976 // Move superklass into T8
977 //__ ld(T8, Address(T2, oopDesc::klass_offset_in_bytes()));
978 //add for compressedoops
979 __ load_klass(T8, T2);
980 __ ld(T8, Address(T8, ObjArrayKlass::element_klass_offset()));
981 // Compress array+index*4+12 into a single register. T2
982 __ dsll(AT, SSR, UseCompressedOops? Address::times_4 : Address::times_8);
983 __ dadd(T2, T2, AT);
984 __ daddi(T2, T2, arrayOopDesc::base_offset_in_bytes(T_OBJECT));
986 // Generate subtype check.
987 // Superklass in T8. Subklass in T3.
988 __ gen_subtype_check(T8, T3, ok_is_subtype); // <-- Jin
989 // Come here on failure
990 // object is at FSR
991 __ jmp(Interpreter::_throw_ArrayStoreException_entry); // <-- Jin
992 __ delayed()->nop();
993 // Come here on success
994 __ bind(ok_is_subtype);
995 //replace with do_oop_store->store_heap_oop
996 //__ sd(FSR, T2, 0);
997 __ store_heap_oop(Address(T2, 0), FSR); // <-- Jin
998 __ sync();
999 __ store_check(T2);
1000 __ b(done);
1001 __ delayed()->nop();
1003 // Have a NULL in FSR, EDX=T2, SSR=index. Store NULL at ary[idx]
1004 __ bind(is_null);
1005 __ profile_null_seen(T9);
1006 __ dsll(AT, SSR, UseCompressedOops? Address::times_4 : Address::times_8);
1007 __ dadd(T2, T2, AT);
1008 //__ sd(FSR, T2, arrayOopDesc::base_offset_in_bytes(T_OBJECT));
1009 __ store_heap_oop(Address(T2, arrayOopDesc::base_offset_in_bytes(T_OBJECT)), FSR); /* FSR is null here */
1010 __ sync();
1012 __ bind(done);
1013 __ daddi(SP, SP, 3 * Interpreter::stackElementSize);
1014 }
1016 void TemplateTable::bastore() {
1017 transition(itos, vtos);
1018 __ pop_i (SSR);
1019 index_check(T2, SSR);
1020 __ dadd(SSR, T2, SSR);
1021 __ sb(FSR, SSR, arrayOopDesc::base_offset_in_bytes(T_BYTE));
1022 }
1024 void TemplateTable::castore() {
1025 transition(itos, vtos);
1026 __ pop_i(SSR);
1027 index_check(T2, SSR);
1028 __ dsll(SSR, SSR, Address::times_2);
1029 __ dadd(SSR, T2, SSR);
1030 __ sh(FSR, SSR, arrayOopDesc::base_offset_in_bytes(T_CHAR));
1031 }
1033 void TemplateTable::sastore() {
1034 castore();
1035 }
1037 void TemplateTable::istore(int n) {
1038 transition(itos, vtos);
1039 __ sw(FSR, iaddress(n));
1040 }
1042 void TemplateTable::lstore(int n) {
1043 transition(ltos, vtos);
1044 __ sd(FSR, laddress(n));
1045 }
1047 void TemplateTable::fstore(int n) {
1048 transition(ftos, vtos);
1049 __ swc1(FSF, faddress(n));
1050 }
1052 void TemplateTable::dstore(int n) {
1053 transition(dtos, vtos);
1054 __ sdc1(FSF, laddress(n));
1055 }
1057 void TemplateTable::astore(int n) {
1058 transition(vtos, vtos);
1059 __ pop_ptr(FSR);
1060 __ sd(FSR, aaddress(n));
1061 }
1063 void TemplateTable::pop() {
1064 transition(vtos, vtos);
1065 __ daddi(SP, SP, Interpreter::stackElementSize);
1066 }
1068 void TemplateTable::pop2() {
1069 transition(vtos, vtos);
1070 __ daddi(SP, SP, 2 * Interpreter::stackElementSize);
1071 }
1073 void TemplateTable::dup() {
1074 transition(vtos, vtos);
1075 // stack: ..., a
1076 __ load_ptr(0, FSR);
1077 __ push_ptr(FSR);
1078 // stack: ..., a, a
1079 }
1081 // blows FSR
1082 void TemplateTable::dup_x1() {
1083 transition(vtos, vtos);
1084 // stack: ..., a, b
1085 __ load_ptr(0, FSR); // load b
1086 __ load_ptr(1, A5); // load a
1087 __ store_ptr(1, FSR); // store b
1088 __ store_ptr(0, A5); // store a
1089 __ push_ptr(FSR); // push b
1090 // stack: ..., b, a, b
1091 }
1093 // blows FSR
1094 void TemplateTable::dup_x2() {
1095 transition(vtos, vtos);
1096 // stack: ..., a, b, c
1097 __ load_ptr(0, FSR); // load c
1098 __ load_ptr(2, A5); // load a
1099 __ store_ptr(2, FSR); // store c in a
1100 __ push_ptr(FSR); // push c
1101 // stack: ..., c, b, c, c
1102 __ load_ptr(2, FSR); // load b
1103 __ store_ptr(2, A5); // store a in b
1104 // stack: ..., c, a, c, c
1105 __ store_ptr(1, FSR); // store b in c
1106 // stack: ..., c, a, b, c
1107 }
1109 // blows FSR
1110 void TemplateTable::dup2() {
1111 transition(vtos, vtos);
1112 // stack: ..., a, b
1113 __ load_ptr(1, FSR); // load a
1114 __ push_ptr(FSR); // push a
1115 __ load_ptr(1, FSR); // load b
1116 __ push_ptr(FSR); // push b
1117 // stack: ..., a, b, a, b
1118 }
1120 // blows FSR
1121 void TemplateTable::dup2_x1() {
1122 transition(vtos, vtos);
1123 // stack: ..., a, b, c
1124 __ load_ptr(0, T2); // load c
1125 __ load_ptr(1, FSR); // load b
1126 __ push_ptr(FSR); // push b
1127 __ push_ptr(T2); // push c
1128 // stack: ..., a, b, c, b, c
1129 __ store_ptr(3, T2); // store c in b
1130 // stack: ..., a, c, c, b, c
1131 __ load_ptr(4, T2); // load a
1132 __ store_ptr(2, T2); // store a in 2nd c
1133 // stack: ..., a, c, a, b, c
1134 __ store_ptr(4, FSR); // store b in a
1135 // stack: ..., b, c, a, b, c
1137 // stack: ..., b, c, a, b, c
1138 }
1140 // blows FSR, SSR
1141 void TemplateTable::dup2_x2() {
1142 transition(vtos, vtos);
1143 // stack: ..., a, b, c, d
1144 // stack: ..., a, b, c, d
1145 __ load_ptr(0, T2); // load d
1146 __ load_ptr(1, FSR); // load c
1147 __ push_ptr(FSR); // push c
1148 __ push_ptr(T2); // push d
1149 // stack: ..., a, b, c, d, c, d
1150 __ load_ptr(4, FSR); // load b
1151 __ store_ptr(2, FSR); // store b in d
1152 __ store_ptr(4, T2); // store d in b
1153 // stack: ..., a, d, c, b, c, d
1154 __ load_ptr(5, T2); // load a
1155 __ load_ptr(3, FSR); // load c
1156 __ store_ptr(3, T2); // store a in c
1157 __ store_ptr(5, FSR); // store c in a
1158 // stack: ..., c, d, a, b, c, d
1160 // stack: ..., c, d, a, b, c, d
1161 }
1163 // blows FSR
1164 void TemplateTable::swap() {
1165 transition(vtos, vtos);
1166 // stack: ..., a, b
1168 __ load_ptr(1, A5); // load a
1169 __ load_ptr(0, FSR); // load b
1170 __ store_ptr(0, A5); // store a in b
1171 __ store_ptr(1, FSR); // store b in a
1173 // stack: ..., b, a
1174 }
1176 void TemplateTable::iop2(Operation op) {
1177 transition(itos, itos);
1178 switch (op) {
1179 case add :
1180 __ pop_i(SSR);
1181 __ addu32(FSR, SSR, FSR);
1182 break;
1183 case sub :
1184 __ pop_i(SSR);
1185 __ subu32(FSR, SSR, FSR);
1186 break;
1187 case mul :
1188 __ lw(SSR, SP, 0);
1189 __ mult(SSR, FSR);
1190 __ daddi(SP, SP, wordSize);
1191 __ nop();
1192 __ mflo(FSR);
1193 break;
1194 case _and :
1195 __ pop_i(SSR);
1196 __ andr(FSR, SSR, FSR);
1197 break;
1198 case _or :
1199 __ pop_i(SSR);
1200 __ orr(FSR, SSR, FSR);
1201 break;
1202 case _xor :
1203 __ pop_i(SSR);
1204 __ xorr(FSR, SSR, FSR);
1205 break;
1206 case shl :
1207 __ pop_i(SSR);
1208 __ sllv(FSR, SSR, FSR);
1209 break; // implicit masking of lower 5 bits by Intel shift instr. mips also
1210 case shr :
1211 __ pop_i(SSR);
1212 __ srav(FSR, SSR, FSR);
1213 break; // implicit masking of lower 5 bits by Intel shift instr. mips also
1214 case ushr :
1215 __ pop_i(SSR);
1216 __ srlv(FSR, SSR, FSR);
1217 break; // implicit masking of lower 5 bits by Intel shift instr. mips also
1218 default : ShouldNotReachHere();
1219 }
1220 }
1222 // the result stored in FSR, SSR,
1223 // used registers : T2, T3
1224 //FIXME, aoqi
1225 void TemplateTable::lop2(Operation op) {
1226 transition(ltos, ltos);
1227 //__ pop2(T2, T3);
1228 __ pop_l(T2, T3);
1229 #ifdef ASSERT
1230 {
1231 Label L;
1232 __ beq(T3, R0, L);
1233 __ delayed()->nop();
1234 // FIXME: stack verification required
1235 // __ stop("lop2, wrong stack"); // <--- Fu 20130930
1236 __ bind(L);
1237 }
1238 #endif
1239 switch (op) {
1240 case add :
1241 __ daddu(FSR, T2, FSR);
1242 //__ sltu(AT, FSR, T2);
1243 //__ daddu(SSR, T3, SSR);
1244 //__ daddu(SSR, SSR, AT);
1245 break;
1246 case sub :
1247 __ dsubu(FSR, T2, FSR);
1248 //__ sltu(AT, T2, FSR);
1249 //__ dsubu(SSR, T3, SSR);
1250 //__ dsubu(SSR, SSR, AT);
1251 break;
1252 case _and:
1253 __ andr(FSR, T2, FSR);
1254 //__ andr(SSR, T3, SSR);
1255 break;
1256 case _or :
1257 __ orr(FSR, T2, FSR);
1258 //__ orr(SSR, T3, SSR);
1259 break;
1260 case _xor:
1261 __ xorr(FSR, T2, FSR);
1262 //__ xorr(SSR, T3, SSR);
1263 break;
1264 default : ShouldNotReachHere();
1265 }
1266 }
1268 // java require this bytecode could handle 0x80000000/-1, dont cause a overflow exception,
1269 // the result is 0x80000000
1270 // the godson2 cpu do the same, so we need not handle this specially like x86
1271 void TemplateTable::idiv() {
1272 transition(itos, itos);
1273 Label not_zero;
1274 //__ pop(SSR);
1275 __ pop_i(SSR);
1276 __ div(SSR, FSR);
1278 __ bne(FSR, R0, not_zero);
1279 __ delayed()->nop();
1280 //__ brk(7);
1281 __ jmp(Interpreter::_throw_ArithmeticException_entry);
1282 __ delayed()->nop();
1284 __ bind(not_zero);
1285 __ mflo(FSR);
1286 }
1288 void TemplateTable::irem() {
1289 transition(itos, itos);
1290 Label not_zero;
1291 //__ pop(SSR);
1292 __ pop_i(SSR);
1293 __ div(SSR, FSR);
1295 __ bne(FSR, R0, not_zero);
1296 __ delayed()->nop();
1297 //__ brk(7);
1298 __ jmp(Interpreter::_throw_ArithmeticException_entry);
1299 __ delayed()->nop();
1301 __ bind(not_zero);
1302 __ mfhi(FSR);
1303 }
1305 // the multiplier in SSR||FSR, the multiplicand in stack
1306 // the result in SSR||FSR
1307 // used registers : T2, T3
1308 void TemplateTable::lmul() {
1309 transition(ltos, ltos);
1310 Label done;
1312 __ pop_l(T2, T3);
1313 #ifdef ASSERT
1314 {
1315 Label L;
1316 __ orr(AT, T3, SSR);
1317 __ beq(AT, R0, L);
1318 __ delayed()->nop();
1319 //FIXME, aoqi
1320 //__ stop("lmul, wrong stack");
1321 __ bind(L);
1322 }
1323 #endif
1324 __ orr(AT, T2, FSR);
1325 __ beq(AT, R0, done);
1326 __ delayed()->nop();
1328 __ dmultu(T2, FSR);
1329 __ daddu(SSR, SSR, T3);
1330 __ nop();
1331 __ mflo(FSR);
1332 __ mfhi(SSR);
1333 __ b(done);
1334 __ delayed()->nop();
1336 __ bind(done);
1337 }
1339 // NOTE: i DONT use the Interpreter::_throw_ArithmeticException_entry
1340 void TemplateTable::ldiv() {
1341 transition(ltos, ltos);
1342 Label normal;
1344 __ bne(FSR, R0, normal);
1345 __ delayed()->nop();
1347 //__ brk(7); //generate FPE
1348 __ jmp(Interpreter::_throw_ArithmeticException_entry);
1349 __ delayed()->nop();
1351 __ bind(normal);
1352 __ move(A1, FSR);
1353 __ pop_l(A2, A3);
1354 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::ldiv), A1, A2);
1355 }
1357 // NOTE: i DONT use the Interpreter::_throw_ArithmeticException_entry
1358 void TemplateTable::lrem() {
1359 transition(ltos, ltos);
1360 Label normal;
1362 __ bne(FSR, R0, normal);
1363 __ delayed()->nop();
1365 __ jmp(Interpreter::_throw_ArithmeticException_entry);
1366 __ delayed()->nop();
1368 __ bind(normal);
1369 __ move(A1, FSR);
1370 __ pop_l (A2, A3);
1371 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::lrem), A1, A2);
1372 }
1374 // result in FSR
1375 // used registers : T0
1376 void TemplateTable::lshl() {
1377 transition(itos, ltos);
1378 __ pop_l(T0, T1);
1379 #ifdef ASSERT
1380 {
1381 Label L;
1382 __ beq(T1, R0, L);
1383 __ delayed()->nop();
1384 //__ stop("lshl, wrong stack"); // <-- Fu 20130930
1385 __ bind(L);
1386 }
1387 #endif
1388 __ andi(FSR, FSR, 0x3f); // the bit to be shifted
1389 __ dsllv(FSR, T0, FSR);
1390 }
1392 // used registers : T0
1393 void TemplateTable::lshr() {
1394 transition(itos, ltos);
1395 __ pop_l(T0, T1);
1396 #ifdef ASSERT
1397 {
1398 Label L;
1399 __ beq(T1, R0, L);
1400 __ delayed()->nop();
1401 __ stop("lshr, wrong stack");
1402 __ bind(L);
1403 }
1404 #endif
1405 __ andi(FSR, FSR, 0x3f); // the bit to be shifted
1406 __ dsrav(FSR, T0, FSR);
1407 }
1409 // used registers : T0
1410 void TemplateTable::lushr() {
1411 transition(itos, ltos);
1412 __ pop_l(T0, T1);
1413 #ifdef ASSERT
1414 {
1415 Label L;
1416 __ beq(T1, R0, L);
1417 __ delayed()->nop();
1418 __ stop("lushr, wrong stack");
1419 __ bind(L);
1420 }
1421 #endif
1422 __ andi(FSR, FSR, 0x3f); // the bit to be shifted
1423 __ dsrlv(FSR, T0, FSR);
1424 }
1426 // result in FSF
1427 void TemplateTable::fop2(Operation op) {
1428 transition(ftos, ftos);
1429 __ pop_ftos_to_esp(); // pop ftos into esp
1430 switch (op) {
1431 case add:
1432 __ lwc1(FTF, at_sp());
1433 __ add_s(FSF, FTF, FSF);
1434 break;
1435 case sub:
1436 __ lwc1(FTF, at_sp());
1437 __ sub_s(FSF, FTF, FSF);
1438 break;
1439 case mul:
1440 __ lwc1(FTF, at_sp());
1441 __ mul_s(FSF, FTF, FSF);
1442 break;
1443 case div:
1444 __ lwc1(FTF, at_sp());
1445 __ div_s(FSF, FTF, FSF);
1446 break;
1447 case rem:
1448 __ mfc1(FSR, FSF);
1449 __ mtc1(FSR, F12);
1450 __ lwc1(FTF, at_sp());
1451 __ rem_s(FSF, FTF, F12, FSF);
1452 break;
1453 default : ShouldNotReachHere();
1454 }
1456 __ daddi(SP, SP, 1 * wordSize);
1457 }
1459 // result in SSF||FSF
1460 // i dont handle the strict flags
1461 void TemplateTable::dop2(Operation op) {
1462 transition(dtos, dtos);
1463 __ pop_dtos_to_esp(); // pop dtos into esp
1464 switch (op) {
1465 case add:
1466 __ ldc1(FTF, at_sp());
1467 __ add_d(FSF, FTF, FSF);
1468 break;
1469 case sub:
1470 __ ldc1(FTF, at_sp());
1471 __ sub_d(FSF, FTF, FSF);
1472 break;
1473 case mul:
1474 __ ldc1(FTF, at_sp());
1475 __ mul_d(FSF, FTF, FSF);
1476 break;
1477 case div:
1478 __ ldc1(FTF, at_sp());
1479 __ div_d(FSF, FTF, FSF);
1480 break;
1481 case rem:
1482 __ dmfc1(FSR, FSF);
1483 __ dmtc1(FSR, F12);
1484 __ ldc1(FTF, at_sp());
1485 __ rem_d(FSF, FTF, F12, FSF);
1486 break;
1487 default : ShouldNotReachHere();
1488 }
1490 __ daddi(SP, SP, 2 * wordSize);
1491 }
1493 void TemplateTable::ineg() {
1494 transition(itos, itos);
1495 __ neg(FSR);
1496 }
1498 void TemplateTable::lneg() {
1499 transition(ltos, ltos);
1500 __ dsubu(FSR, R0, FSR);
1501 }
1502 /*
1503 // Note: 'double' and 'long long' have 32-bits alignment on x86.
1504 static jlong* double_quadword(jlong *adr, jlong lo, jlong hi) {
1505 // Use the expression (adr)&(~0xF) to provide 128-bits aligned address
1506 // of 128-bits operands for SSE instructions.
1507 jlong *operand = (jlong*)(((intptr_t)adr)&((intptr_t)(~0xF)));
1508 // Store the value to a 128-bits operand.
1509 operand[0] = lo;
1510 operand[1] = hi;
1511 return operand;
1512 }
1514 // Buffer for 128-bits masks used by SSE instructions.
1515 static jlong float_signflip_pool[2*2];
1516 static jlong double_signflip_pool[2*2];
1517 */
1518 void TemplateTable::fneg() {
1519 transition(ftos, ftos);
1520 __ neg_s(FSF, FSF);
1521 }
1523 void TemplateTable::dneg() {
1524 transition(dtos, dtos);
1525 __ neg_d(FSF, FSF);
1526 }
1528 // used registers : T2
1529 void TemplateTable::iinc() {
1530 transition(vtos, vtos);
1531 locals_index(T2);
1532 __ lw(FSR, T2, 0);
1533 __ lb(AT, at_bcp(2)); // get constant
1534 __ daddu(FSR, FSR, AT);
1535 __ sw(FSR, T2, 0);
1536 }
1538 // used register : T2
1539 void TemplateTable::wide_iinc() {
1540 transition(vtos, vtos);
1541 locals_index_wide(T2);
1542 __ get_2_byte_integer_at_bcp(FSR, AT, 4);
1543 __ hswap(FSR);
1544 __ lw(AT, T2, 0);
1545 __ daddu(FSR, AT, FSR);
1546 __ sw(FSR, T2, 0);
1547 }
1549 void TemplateTable::convert() {
1550 // Checking
1551 #ifdef ASSERT
1552 { TosState tos_in = ilgl;
1553 TosState tos_out = ilgl;
1554 switch (bytecode()) {
1555 case Bytecodes::_i2l: // fall through
1556 case Bytecodes::_i2f: // fall through
1557 case Bytecodes::_i2d: // fall through
1558 case Bytecodes::_i2b: // fall through
1559 case Bytecodes::_i2c: // fall through
1560 case Bytecodes::_i2s: tos_in = itos; break;
1561 case Bytecodes::_l2i: // fall through
1562 case Bytecodes::_l2f: // fall through
1563 case Bytecodes::_l2d: tos_in = ltos; break;
1564 case Bytecodes::_f2i: // fall through
1565 case Bytecodes::_f2l: // fall through
1566 case Bytecodes::_f2d: tos_in = ftos; break;
1567 case Bytecodes::_d2i: // fall through
1568 case Bytecodes::_d2l: // fall through
1569 case Bytecodes::_d2f: tos_in = dtos; break;
1570 default : ShouldNotReachHere();
1571 }
1572 switch (bytecode()) {
1573 case Bytecodes::_l2i: // fall through
1574 case Bytecodes::_f2i: // fall through
1575 case Bytecodes::_d2i: // fall through
1576 case Bytecodes::_i2b: // fall through
1577 case Bytecodes::_i2c: // fall through
1578 case Bytecodes::_i2s: tos_out = itos; break;
1579 case Bytecodes::_i2l: // fall through
1580 case Bytecodes::_f2l: // fall through
1581 case Bytecodes::_d2l: tos_out = ltos; break;
1582 case Bytecodes::_i2f: // fall through
1583 case Bytecodes::_l2f: // fall through
1584 case Bytecodes::_d2f: tos_out = ftos; break;
1585 case Bytecodes::_i2d: // fall through
1586 case Bytecodes::_l2d: // fall through
1587 case Bytecodes::_f2d: tos_out = dtos; break;
1588 default : ShouldNotReachHere();
1589 }
1590 transition(tos_in, tos_out);
1591 }
1592 #endif // ASSERT
1594 // Conversion
1595 // (Note: use pushl(ecx)/popl(ecx) for 1/2-word stack-ptr manipulation)
1596 switch (bytecode()) {
1597 case Bytecodes::_i2l:
1598 //__ extend_sign(SSR, FSR);
1599 __ sll(FSR, FSR, 0);
1600 break;
1601 case Bytecodes::_i2f:
1602 __ mtc1(FSR, FSF);
1603 __ cvt_s_w(FSF, FSF);
1604 break;
1605 case Bytecodes::_i2d:
1606 __ mtc1(FSR, FSF);
1607 __ cvt_d_w(FSF, FSF);
1608 break;
1609 case Bytecodes::_i2b:
1610 __ dsll32(FSR, FSR, 24);
1611 __ dsra32(FSR, FSR, 24);
1612 break;
1613 case Bytecodes::_i2c:
1614 __ andi(FSR, FSR, 0xFFFF); // truncate upper 56 bits
1615 break;
1616 case Bytecodes::_i2s:
1617 __ dsll32(FSR, FSR, 16);
1618 __ dsra32(FSR, FSR, 16);
1619 break;
1620 case Bytecodes::_l2i:
1621 __ dsll32(FSR, FSR, 0);
1622 __ dsra32(FSR, FSR, 0);
1623 break;
1624 case Bytecodes::_l2f:
1625 __ dmtc1(FSR, FSF);
1626 //__ mtc1(SSR, SSF);
1627 __ cvt_s_l(FSF, FSF);
1628 break;
1629 case Bytecodes::_l2d:
1630 __ dmtc1(FSR, FSF);
1631 //__ mtc1(SSR, SSF);
1632 __ cvt_d_l(FSF, FSF);
1633 break;
1634 case Bytecodes::_f2i:
1635 {
1636 Label L;
1637 /*
1638 __ c_un_s(FSF, FSF); //NaN?
1639 __ bc1t(L);
1640 __ delayed(); __ move(FSR, R0);
1641 */
1642 __ trunc_w_s(F12, FSF);
1643 __ cfc1(AT, 31);
1644 __ li(T0, 0x10000);
1645 __ andr(AT, AT, T0);
1646 __ beq(AT, R0, L);
1647 __ delayed()->mfc1(FSR, F12);
1649 __ mov_s(F12, FSF);
1650 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::f2i), 1);
1651 __ bind(L);
1652 }
1653 break;
1654 case Bytecodes::_f2l:
1655 {
1656 Label L;
1657 /*
1658 __ move(SSR, R0);
1659 __ c_un_s(FSF, FSF); //NaN?
1660 __ bc1t(L);
1661 __ delayed();
1662 __ move(FSR, R0);
1663 */
1664 __ trunc_l_s(F12, FSF);
1665 __ cfc1(AT, 31);
1666 __ li(T0, 0x10000);
1667 __ andr(AT, AT, T0);
1668 __ beq(AT, R0, L);
1669 __ delayed()->dmfc1(FSR, F12);
1671 __ mov_s(F12, FSF);
1672 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::f2l), 1);
1673 __ bind(L);
1674 }
1675 break;
1676 case Bytecodes::_f2d:
1677 __ cvt_d_s(FSF, FSF);
1678 break;
1679 case Bytecodes::_d2i:
1680 {
1681 Label L;
1682 /*
1683 __ c_un_d(FSF, FSF); //NaN?
1684 __ bc1t(L);
1685 __ delayed(); __ move(FSR, R0);
1686 */
1687 __ trunc_w_d(F12, FSF);
1688 __ cfc1(AT, 31);
1689 __ li(T0, 0x10000);
1690 __ andr(AT, AT, T0);
1691 __ beq(AT, R0, L);
1692 __ delayed()->mfc1(FSR, F12);
1694 __ mov_d(F12, FSF);
1695 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::d2i), 1);
1696 __ bind(L);
1697 }
1698 break;
1699 case Bytecodes::_d2l:
1700 {
1701 Label L;
1702 /*
1703 __ move(SSR, R0);
1704 __ c_un_d(FSF, FSF); //NaN?
1705 __ bc1t(L);
1706 __ delayed(); __ move(FSR, R0);
1707 */
1708 __ trunc_l_d(F12, FSF);
1709 __ cfc1(AT, 31);
1710 __ li(T0, 0x10000);
1711 __ andr(AT, AT, T0);
1712 __ beq(AT, R0, L);
1713 __ delayed()->dmfc1(FSR, F12);
1715 __ mov_d(F12, FSF);
1716 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::d2l), 1);
1717 __ bind(L);
1718 }
1719 break;
1720 case Bytecodes::_d2f:
1721 __ cvt_s_d(FSF, FSF);
1722 break;
1723 default :
1724 ShouldNotReachHere();
1725 }
1726 }
1728 void TemplateTable::lcmp() {
1729 transition(ltos, itos);
1731 Label low, high, done;
1732 __ pop(T0);
1733 __ pop(R0);
1734 __ slt(AT, T0, FSR);
1735 __ bne(AT, R0, low);
1736 __ delayed()->nop();
1738 __ bne(T0, FSR, high);
1739 __ delayed()->nop();
1741 __ li(FSR, (long)0);
1742 __ b(done);
1743 __ delayed()->nop();
1745 __ bind(low);
1746 __ li(FSR, (long)-1);
1747 __ b(done);
1748 __ delayed()->nop();
1750 __ bind(high);
1751 __ li(FSR, (long)1);
1752 __ b(done);
1753 __ delayed()->nop();
1755 __ bind(done);
1756 }
1758 void TemplateTable::float_cmp(bool is_float, int unordered_result) {
1759 Label less, done;
1761 __ move(FSR, R0);
1763 if (is_float) {
1764 __ pop_ftos_to_esp();
1765 __ lwc1(FTF, at_sp());
1766 __ c_eq_s(FTF, FSF);
1767 __ bc1t(done);
1768 __ delayed()->daddi(SP, SP, 1 * wordSize);
1770 if (unordered_result<0)
1771 __ c_ult_s(FTF, FSF);
1772 else
1773 __ c_olt_s(FTF, FSF);
1774 } else {
1775 __ pop_dtos_to_esp();
1776 __ ldc1(FTF, at_sp());
1777 __ c_eq_d(FTF, FSF);
1778 __ bc1t(done);
1779 __ delayed()->daddi(SP, SP, 2 * wordSize);
1781 if (unordered_result<0)
1782 __ c_ult_d(FTF, FSF);
1783 else
1784 __ c_olt_d(FTF, FSF);
1785 }
1786 __ bc1t(less);
1787 __ delayed()->nop();
1788 __ move(FSR, 1);
1789 __ b(done);
1790 __ delayed()->nop();
1791 __ bind(less);
1792 __ move(FSR, -1);
1793 __ bind(done);
1794 }
1797 // used registers : T3, A7, Rnext
1798 // FSR : return bci, this is defined by the vm specification
1799 // T2 : MDO taken count
1800 // T3 : method
1801 // A7 : offset
1802 // Rnext : next bytecode, this is required by dispatch_base
1803 void TemplateTable::branch(bool is_jsr, bool is_wide) {
1804 __ get_method(T3);
1805 __ profile_taken_branch(A7, T2); // only C2 meaningful
1807 #ifndef CORE
1808 const ByteSize be_offset = MethodCounters::backedge_counter_offset()
1809 + InvocationCounter::counter_offset();
1810 const ByteSize inv_offset = MethodCounters::invocation_counter_offset()
1811 + InvocationCounter::counter_offset();
1812 const int method_offset = frame::interpreter_frame_method_offset * wordSize;
1813 #endif // CORE
1815 // Load up T4 with the branch displacement
1816 if (!is_wide) {
1817 __ get_2_byte_integer_at_bcp(A7, AT, 1);
1818 __ hswap(A7);
1819 } else {
1820 __ get_4_byte_integer_at_bcp(A7, AT, 1);
1821 __ swap(A7);
1822 }
1824 // Handle all the JSR stuff here, then exit.
1825 // It's much shorter and cleaner than intermingling with the
1826 // non-JSR normal-branch stuff occuring below.
1827 if (is_jsr) {
1828 // Pre-load the next target bytecode into Rnext
1829 __ dadd(AT, BCP, A7);
1830 __ lbu(Rnext, AT, 0);
1832 // compute return address as bci in FSR
1833 __ daddi(FSR, BCP, (is_wide?5:3) - in_bytes(ConstMethod::codes_offset()));
1834 __ ld(AT, T3, in_bytes(Method::const_offset()));
1835 __ dsub(FSR, FSR, AT);
1836 // Adjust the bcp in BCP by the displacement in A7
1837 __ dadd(BCP, BCP, A7);
1838 // jsr returns atos that is not an oop
1839 // __ dispatch_only_noverify(atos);
1840 // Push return address
1841 __ push_i(FSR);
1842 // jsr returns vtos
1843 __ dispatch_only_noverify(vtos);
1845 return;
1846 }
1848 // Normal (non-jsr) branch handling
1850 // Adjust the bcp in S0 by the displacement in T4
1851 __ dadd(BCP, BCP, A7);
1853 #ifdef CORE
1854 // Pre-load the next target bytecode into EBX
1855 __ lbu(Rnext, BCP, 0);
1856 // continue with the bytecode @ target
1857 __ dispatch_only(vtos);
1858 #else
1859 assert(UseLoopCounter || !UseOnStackReplacement, "on-stack-replacement requires loop counters");
1860 Label backedge_counter_overflow;
1861 Label profile_method;
1862 Label dispatch;
1863 if (UseLoopCounter) {
1864 // increment backedge counter for backward branches
1865 // eax: MDO
1866 // ebx: MDO bumped taken-count
1867 // T3: method
1868 // T4: target offset
1869 // BCP: target bcp
1870 // LVP: locals pointer
1871 __ bgtz(A7, dispatch); // check if forward or backward branch
1872 __ delayed()->nop();
1874 // check if MethodCounters exists
1875 Label has_counters;
1876 __ ld(AT, T3, in_bytes(Method::method_counters_offset())); // use AT as MDO, TEMP
1877 __ bne(AT, R0, has_counters);
1878 __ nop();
1879 //__ push(T3);
1880 //__ push(A7);
1881 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::build_method_counters),
1882 T3);
1883 //__ pop(A7);
1884 //__ pop(T3);
1885 __ ld(AT, T3, in_bytes(Method::method_counters_offset())); // use AT as MDO, TEMP
1886 __ beq(AT, R0, dispatch);
1887 __ nop();
1888 __ bind(has_counters);
1890 // increment back edge counter
1891 __ ld(T1, T3, in_bytes(Method::method_counters_offset()));
1892 __ lw(T0, T1, in_bytes(be_offset));
1893 __ increment(T0, InvocationCounter::count_increment);
1894 __ sw(T0, T1, in_bytes(be_offset));
1896 // load invocation counter
1897 __ lw(T1, T1, in_bytes(inv_offset));
1898 // buffer bit added, mask no needed
1899 // by yjl 10/24/2005
1900 //__ move(AT, InvocationCounter::count_mask_value);
1901 //__ andr(T1, T1, AT);
1903 // dadd backedge counter & invocation counter
1904 __ dadd(T1, T1, T0);
1906 if (ProfileInterpreter) {
1907 // Test to see if we should create a method data oop
1908 //__ lui(AT, Assembler::split_high(int(&InvocationCounter::InterpreterProfileLimit)));
1909 //__ lw(AT, AT, Assembler::split_low(int(&InvocationCounter::InterpreterProfileLimit)));
1910 // T1 : backedge counter & invocation counter
1911 __ li(AT, (long)&InvocationCounter::InterpreterProfileLimit);
1912 __ lw(AT, AT, 0);
1913 __ slt(AT, T1, AT);
1914 __ bne(AT, R0, dispatch);
1915 __ delayed()->nop();
1917 // if no method data exists, go to profile method
1918 __ test_method_data_pointer(T1, profile_method);
1920 if (UseOnStackReplacement) {
1921 // check for overflow against ebx which is the MDO taken count
1922 //__ lui(AT, Assembler::split_high(int(&InvocationCounter::InterpreterBackwardBranchLimit)));
1923 //__ lw(AT, AT, Assembler::split_low(int(&InvocationCounter::InterpreterBackwardBranchLimit)));
1924 __ li(AT, (long)&InvocationCounter::InterpreterBackwardBranchLimit);
1925 __ lw(AT, AT, 0);
1926 // the value Rnext Is get from the beginning profile_taken_branch
1927 __ slt(AT, T2, AT);
1928 __ bne(AT, R0, dispatch);
1929 __ delayed()->nop();
1931 // When ProfileInterpreter is on, the backedge_count comes
1932 // from the methodDataOop, which value does not get reset on
1933 // the call to frequency_counter_overflow().
1934 // To avoid excessive calls to the overflow routine while
1935 // the method is being compiled, dadd a second test to make
1936 // sure the overflow function is called only once every
1937 // overflow_frequency.
1938 const int overflow_frequency = 1024;
1939 __ andi(AT, T2, overflow_frequency-1);
1940 __ beq(AT, R0, backedge_counter_overflow);
1941 __ delayed()->nop();
1942 }
1943 } else {
1944 if (UseOnStackReplacement) {
1945 // check for overflow against eax, which is the sum of the counters
1946 //__ lui(AT, Assembler::split_high(int(&InvocationCounter::InterpreterBackwardBranchLimit)));
1947 //__ lw(AT, AT, Assembler::split_low(int(&InvocationCounter::InterpreterBackwardBranchLimit)));
1948 __ li(AT, (long)&InvocationCounter::InterpreterBackwardBranchLimit);
1949 __ lw(AT, AT, 0);
1950 __ slt(AT, T1, AT);
1951 __ beq(AT, R0, backedge_counter_overflow);
1952 __ delayed()->nop();
1953 }
1954 }
1955 __ bind(dispatch);
1956 }
1958 // Pre-load the next target bytecode into Rnext
1959 __ lbu(Rnext, BCP, 0);
1961 // continue with the bytecode @ target
1962 // FSR: return bci for jsr's, unused otherwise
1963 // Rnext: target bytecode
1964 // BCP: target bcp
1965 __ dispatch_only(vtos);
1967 if (UseLoopCounter) {
1968 if (ProfileInterpreter) {
1969 // Out-of-line code to allocate method data oop.
1970 __ bind(profile_method);
1971 __ call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method));
1972 __ lbu(Rnext, BCP, 0);
1974 __ set_method_data_pointer_for_bcp();
1975 /*
1976 __ ld(T3, FP, method_offset);
1977 __ lw(T3, T3, in_bytes(Method::method_data_offset()));
1978 __ sw(T3, FP, frame::interpreter_frame_mdx_offset * wordSize);
1979 __ test_method_data_pointer(T3, dispatch);
1980 // offset non-null mdp by MDO::data_offset() + IR::profile_method()
1981 __ daddi(T3, T3, in_bytes(MethodData::data_offset()));
1982 __ dadd(T3, T3, T1);
1983 __ sw(T3, FP, frame::interpreter_frame_mdx_offset * wordSize);
1984 */
1985 __ b(dispatch);
1986 __ delayed()->nop();
1987 }
1989 if (UseOnStackReplacement) {
1990 // invocation counter overflow
1991 __ bind(backedge_counter_overflow);
1992 __ sub(A7, BCP, A7); // branch bcp
1993 call_VM(NOREG, CAST_FROM_FN_PTR(address,
1994 InterpreterRuntime::frequency_counter_overflow), A7);
1995 __ lbu(Rnext, BCP, 0);
1997 // V0: osr nmethod (osr ok) or NULL (osr not possible)
1998 // V1: osr adapter frame return address
1999 // Rnext: target bytecode
2000 // LVP: locals pointer
2001 // BCP: bcp
2002 __ beq(V0, R0, dispatch);
2003 __ delayed()->nop();
2004 // nmethod may have been invalidated (VM may block upon call_VM return)
2005 __ lw(T3, V0, nmethod::entry_bci_offset());
2006 __ move(AT, InvalidOSREntryBci);
2007 __ beq(AT, T3, dispatch);
2008 __ delayed()->nop();
2009 // We need to prepare to execute the OSR method. First we must
2010 // migrate the locals and monitors off of the stack.
2011 //eax V0: osr nmethod (osr ok) or NULL (osr not possible)
2012 //ebx V1: osr adapter frame return address
2013 //edx Rnext: target bytecode
2014 //edi LVP: locals pointer
2015 //esi BCP: bcp
2016 __ move(BCP, V0);
2017 // const Register thread = ecx;
2018 const Register thread = TREG;
2019 #ifndef OPT_THREAD
2020 __ get_thread(thread);
2021 #endif
2022 call_VM(noreg, CAST_FROM_FN_PTR(address,
2023 SharedRuntime::OSR_migration_begin));
2024 // eax is OSR buffer, move it to expected parameter location
2025 //refer to osrBufferPointer in c1_LIRAssembler_mips.cpp
2026 __ move(T0, V0);
2028 // pop the interpreter frame
2029 // __ movl(edx, Address(ebp, frame::interpreter_frame_sender_sp_offset
2030 // * wordSize)); // get sender sp
2031 __ ld(A7, Address(FP,
2032 frame::interpreter_frame_sender_sp_offset * wordSize));
2033 //FIXME, shall we keep the return address on the stack?
2034 __ leave(); // remove frame anchor
2035 // __ popl(edi); // get return address
2036 //__ daddi(SP, SP, wordSize); // get return address
2037 // __ pop(LVP);
2038 __ move(LVP, RA);
2039 // __ movl(esp, edx); // set sp to sender sp
2040 __ move(SP, A7);
2042 Label skip;
2043 Label chkint;
2045 // The interpreter frame we have removed may be returning to
2046 // either the callstub or the interpreter. Since we will
2047 // now be returning from a compiled (OSR) nmethod we must
2048 // adjust the return to the return were it can handler compiled
2049 // results and clean the fpu stack. This is very similar to
2050 // what a i2c adapter must do.
2052 // Are we returning to the call stub?
2053 #if 0
2054 // __ cmpl(edi, (int)StubRoutines::_call_stub_return_address);
2055 __ daddi(AT, LVP, -(int)StubRoutines::_call_stub_return_address);
2056 // __ jcc(Assembler::notEqual, chkint);
2057 __ bne(AT, R0, chkint);
2058 __ delayed()->nop();
2059 // yes adjust to the specialized call stub return.
2060 // assert(StubRoutines::i486::get_call_stub_compiled_return() != NULL,
2061 // "must be set");
2062 assert(StubRoutines::gs2::get_call_stub_compiled_return() != NULL,
2063 "must be set");
2064 // __ movl(edi, (intptr_t) StubRoutines::i486::get_call_stub_compiled_return());
2065 __ move(LVP, (intptr_t) StubRoutines::gs2::get_call_stub_compiled_return());
2066 // __ jmp(skip);
2067 __ b(skip);
2068 __ delayed()->nop();
2069 __ bind(chkint);
2071 // Are we returning to the interpreter? Look for sentinel
2073 //__ cmpl(Address(edi, -8), Interpreter::return_sentinel);
2074 __ lw(AT, LVP , -8);
2075 __ daddi(AT, AT, -Interpreter::return_sentinel);
2076 //__ jcc(Assembler::notEqual, skip);
2077 __ bne(AT, R0, skip);
2078 __ delayed()->nop();
2079 // Adjust to compiled return back to interpreter
2081 // __ movl(edi, Address(edi, -4));
2082 __ lw(LVP, LVP, -4);
2084 __ bind(skip);
2085 #endif
2086 // Align stack pointer for compiled code (note that caller is
2087 // responsible for undoing this fixup by remembering the old SP
2088 // in an ebp-relative location)
2089 // __ andl(esp, -(StackAlignmentInBytes));
2090 __ move(AT, -(StackAlignmentInBytes));
2091 __ andr(SP , SP , AT);
2092 // push the (possibly adjusted) return address
2093 // __ pushl(edi);
2094 //__ push(LVP);
2095 // __ move(RA, LVP);
2096 // and begin the OSR nmethod
2097 // __ jmp(Address(esi, nmethod::osr_entry_point_offset()));
2098 //refer to osr_entry in c1_LIRAssembler_mips.cpp
2099 __ ld(AT, BCP, nmethod::osr_entry_point_offset());
2100 __ jr(AT);
2101 __ delayed()->nop();
2102 }
2103 }
2104 #endif // not CORE
2105 }
2107 void TemplateTable::if_0cmp(Condition cc) {
2108 transition(itos, vtos);
2109 // assume branch is more often taken than not (loops use backward branches)
2110 Label not_taken;
2111 switch(cc) {
2112 case not_equal:
2113 __ beq(FSR, R0, not_taken);
2114 break;
2115 case equal:
2116 __ bne(FSR, R0, not_taken);
2117 break;
2118 case less:
2119 __ bgez(FSR, not_taken);
2120 break;
2121 case less_equal:
2122 __ bgtz(FSR, not_taken);
2123 break;
2124 case greater:
2125 __ blez(FSR, not_taken);
2126 break;
2127 case greater_equal:
2128 __ bltz(FSR, not_taken);
2129 break;
2130 }
2131 __ delayed()->nop();
2133 branch(false, false);
2135 __ bind(not_taken);
2136 __ profile_not_taken_branch(FSR);
2137 }
2140 void TemplateTable::if_icmp(Condition cc) {
2141 transition(itos, vtos);
2142 // assume branch is more often taken than not (loops use backward branches)
2143 Label not_taken;
2145 __ pop_i(SSR);
2146 switch(cc) {
2147 case not_equal:
2148 __ beq(SSR, FSR, not_taken);
2149 break;
2150 case equal:
2151 __ bne(SSR, FSR, not_taken);
2152 break;
2153 case less:
2154 __ slt(AT, SSR, FSR);
2155 __ beq(AT, R0, not_taken);
2156 break;
2157 case less_equal:
2158 __ slt(AT, FSR, SSR);
2159 __ bne(AT, R0, not_taken);
2160 break;
2161 case greater:
2162 __ slt(AT, FSR, SSR);
2163 __ beq(AT, R0, not_taken);
2164 break;
2165 case greater_equal:
2166 __ slt(AT, SSR, FSR);
2167 __ bne(AT, R0, not_taken);
2168 break;
2169 }
2170 __ delayed()->nop();
2172 branch(false, false);
2174 __ bind(not_taken);
2175 __ profile_not_taken_branch(FSR);
2176 }
2179 void TemplateTable::if_nullcmp(Condition cc) {
2180 transition(atos, vtos);
2181 // assume branch is more often taken than not (loops use backward branches)
2182 Label not_taken;
2183 switch(cc) {
2184 case not_equal:
2185 __ beq(FSR, R0, not_taken);
2186 break;
2187 case equal:
2188 __ bne(FSR, R0, not_taken);
2189 break;
2190 default:
2191 ShouldNotReachHere();
2192 }
2193 __ delayed()->nop();
2195 branch(false, false);
2197 __ bind(not_taken);
2198 __ profile_not_taken_branch(FSR);
2199 }
2202 void TemplateTable::if_acmp(Condition cc) {
2203 transition(atos, vtos);
2204 // assume branch is more often taken than not (loops use backward branches)
2205 Label not_taken;
2206 // __ lw(SSR, SP, 0);
2207 __ pop_ptr(SSR);
2208 switch(cc) {
2209 case not_equal:
2210 __ beq(SSR, FSR, not_taken);
2211 break;
2212 case equal:
2213 __ bne(SSR, FSR, not_taken);
2214 break;
2215 default:
2216 ShouldNotReachHere();
2217 }
2218 // __ delayed()->daddi(SP, SP, 4);
2219 __ delayed()->nop();
2221 branch(false, false);
2223 __ bind(not_taken);
2224 __ profile_not_taken_branch(FSR);
2225 }
2227 // used registers : T1, T2, T3
2228 // T1 : method
2229 // T2 : returb bci
2230 void TemplateTable::ret() {
2231 transition(vtos, vtos);
2233 locals_index(T2);
2234 __ ld(T2, T2, 0);
2235 __ profile_ret(T2, T3);
2237 __ get_method(T1);
2238 __ ld(BCP, T1, in_bytes(Method::const_offset()));
2239 __ dadd(BCP, BCP, T2);
2240 __ daddi(BCP, BCP, in_bytes(ConstMethod::codes_offset()));
2242 __ dispatch_next(vtos);
2243 }
2245 // used registers : T1, T2, T3
2246 // T1 : method
2247 // T2 : returb bci
2248 void TemplateTable::wide_ret() {
2249 transition(vtos, vtos);
2251 locals_index_wide(T2);
2252 __ ld(T2, T2, 0); // get return bci, compute return bcp
2253 __ profile_ret(T2, T3);
2255 __ get_method(T1);
2256 __ ld(BCP, T1, in_bytes(Method::const_offset()));
2257 __ dadd(BCP, BCP, T2);
2258 __ daddi(BCP, BCP, in_bytes(ConstMethod::codes_offset()));
2260 __ dispatch_next(vtos);
2261 }
2263 // used register T2, T3, A7, Rnext
2264 // T2 : bytecode pointer
2265 // T3 : low
2266 // A7 : high
2267 // Rnext : dest bytecode, required by dispatch_base
2268 void TemplateTable::tableswitch() {
2269 Label default_case, continue_execution;
2270 transition(itos, vtos);
2272 // align BCP
2273 __ daddi(T2, BCP, BytesPerInt);
2274 __ li(AT, -BytesPerInt);
2275 __ andr(T2, T2, AT);
2277 // load lo & hi
2278 __ lw(T3, T2, 1 * BytesPerInt);
2279 __ swap(T3);
2280 __ lw(A7, T2, 2 * BytesPerInt);
2281 __ swap(A7);
2283 // check against lo & hi
2284 __ slt(AT, FSR, T3);
2285 __ bne(AT, R0, default_case);
2286 __ delayed()->nop();
2288 __ slt(AT, A7, FSR);
2289 __ bne(AT, R0, default_case);
2290 __ delayed()->nop();
2292 // lookup dispatch offset, in A7 big endian
2293 __ dsub(FSR, FSR, T3);
2294 __ dsll(AT, FSR, Address::times_4);
2295 __ dadd(AT, T2, AT);
2296 __ lw(A7, AT, 3 * BytesPerInt);
2297 __ profile_switch_case(FSR, T9, T3);
2299 __ bind(continue_execution);
2300 __ swap(A7);
2301 __ dadd(BCP, BCP, A7);
2302 __ lbu(Rnext, BCP, 0);
2303 __ dispatch_only(vtos);
2305 // handle default
2306 __ bind(default_case);
2307 __ profile_switch_default(FSR);
2308 __ lw(A7, T2, 0);
2309 __ b(continue_execution);
2310 __ delayed()->nop();
2311 }
2313 void TemplateTable::lookupswitch() {
2314 transition(itos, itos);
2315 __ stop("lookupswitch bytecode should have been rewritten");
2316 }
2318 // used registers : T2, T3, A7, Rnext
2319 // T2 : bytecode pointer
2320 // T3 : pair index
2321 // A7 : offset
2322 // Rnext : dest bytecode
2323 // the data after the opcode is the same as lookupswitch
2324 // see Rewriter::rewrite_method for more information
2325 void TemplateTable::fast_linearswitch() {
2326 transition(itos, vtos);
2327 Label loop_entry, loop, found, continue_execution;
2329 // swap eax so we can avoid swapping the table entries
2330 __ swap(FSR);
2332 // align BCP
2333 __ daddi(T2, BCP, BytesPerInt);
2334 __ li(AT, -BytesPerInt);
2335 __ andr(T2, T2, AT);
2337 // set counter
2338 __ lw(T3, T2, BytesPerInt);
2339 __ swap(T3);
2340 __ b(loop_entry);
2341 __ delayed()->nop();
2343 // table search
2344 __ bind(loop);
2345 // get the entry value
2346 __ dsll(AT, T3, Address::times_8);
2347 __ dadd(AT, T2, AT);
2348 __ lw(AT, AT, 2 * BytesPerInt);
2350 // found?
2351 __ beq(FSR, AT, found);
2352 __ delayed()->nop();
2354 __ bind(loop_entry);
2355 __ bgtz(T3, loop);
2356 __ delayed()->daddiu(T3, T3, -1);
2358 // default case
2359 __ profile_switch_default(FSR);
2360 __ lw(A7, T2, 0);
2361 __ b(continue_execution);
2362 __ delayed()->nop();
2364 // entry found -> get offset
2365 __ bind(found);
2366 __ dsll(AT, T3, Address::times_8);
2367 __ dadd(AT, T2, AT);
2368 __ lw(A7, AT, 3 * BytesPerInt);
2369 __ profile_switch_case(T3, FSR, T2);
2371 // continue execution
2372 __ bind(continue_execution);
2373 __ swap(A7);
2374 __ dadd(BCP, BCP, A7);
2375 __ lbu(Rnext, BCP, 0);
2376 __ dispatch_only(vtos);
2377 }
2379 // used registers : T0, T1, T2, T3, A7, Rnext
2380 // T2 : pairs address(array)
2381 // Rnext : dest bytecode
2382 // the data after the opcode is the same as lookupswitch
2383 // see Rewriter::rewrite_method for more information
2384 void TemplateTable::fast_binaryswitch() {
2385 transition(itos, vtos);
2386 // Implementation using the following core algorithm:
2387 //
2388 // int binary_search(int key, LookupswitchPair* array, int n) {
2389 // // Binary search according to "Methodik des Programmierens" by
2390 // // Edsger W. Dijkstra and W.H.J. Feijen, Addison Wesley Germany 1985.
2391 // int i = 0;
2392 // int j = n;
2393 // while (i+1 < j) {
2394 // // invariant P: 0 <= i < j <= n and (a[i] <= key < a[j] or Q)
2395 // // with Q: for all i: 0 <= i < n: key < a[i]
2396 // // where a stands for the array and assuming that the (inexisting)
2397 // // element a[n] is infinitely big.
2398 // int h = (i + j) >> 1;
2399 // // i < h < j
2400 // if (key < array[h].fast_match()) {
2401 // j = h;
2402 // } else {
2403 // i = h;
2404 // }
2405 // }
2406 // // R: a[i] <= key < a[i+1] or Q
2407 // // (i.e., if key is within array, i is the correct index)
2408 // return i;
2409 // }
2411 // register allocation
2412 const Register array = T2;
2413 const Register i = T3, j = A7;
2414 const Register h = T1;
2415 const Register temp = T0;
2416 const Register key = FSR;
2418 // setup array
2419 __ daddi(array, BCP, 3*BytesPerInt);
2420 __ li(AT, -BytesPerInt);
2421 __ andr(array, array, AT);
2423 // initialize i & j
2424 __ move(i, R0);
2425 __ lw(j, array, - 1 * BytesPerInt);
2426 // Convert j into native byteordering
2427 __ swap(j);
2429 // and start
2430 Label entry;
2431 __ b(entry);
2432 __ delayed()->nop();
2434 // binary search loop
2435 {
2436 Label loop;
2437 __ bind(loop);
2438 // int h = (i + j) >> 1;
2439 __ dadd(h, i, j);
2440 __ dsrl(h, h, 1);
2441 // if (key < array[h].fast_match()) {
2442 // j = h;
2443 // } else {
2444 // i = h;
2445 // }
2446 // Convert array[h].match to native byte-ordering before compare
2447 __ dsll(AT, h, Address::times_8);
2448 __ dadd(AT, array, AT);
2449 __ lw(temp, AT, 0 * BytesPerInt);
2450 __ swap(temp);
2452 {
2453 Label set_i, end_of_if;
2454 __ slt(AT, key, temp);
2455 __ beq(AT, R0, set_i);
2456 __ delayed()->nop();
2458 __ b(end_of_if);
2459 __ delayed(); __ move(j, h);
2461 __ bind(set_i);
2462 __ move(i, h);
2464 __ bind(end_of_if);
2465 }
2466 // while (i+1 < j)
2467 __ bind(entry);
2468 __ daddi(h, i, 1);
2469 __ slt(AT, h, j);
2470 __ bne(AT, R0, loop);
2471 __ delayed()->nop();
2472 }
2474 // end of binary search, result index is i (must check again!)
2475 Label default_case;
2476 // Convert array[i].match to native byte-ordering before compare
2477 __ dsll(AT, i, Address::times_8);
2478 __ dadd(AT, array, AT);
2479 __ lw(temp, AT, 0 * BytesPerInt);
2480 __ swap(temp);
2481 __ bne(key, temp, default_case);
2482 __ delayed()->nop();
2484 // entry found -> j = offset
2485 __ dsll(AT, i, Address::times_8);
2486 __ dadd(AT, array, AT);
2487 __ lw(j, AT, 1 * BytesPerInt);
2488 __ profile_switch_case(i, key, array);
2489 __ swap(j);
2491 __ dadd(BCP, BCP, j);
2492 __ lbu(Rnext, BCP, 0);
2493 __ dispatch_only(vtos);
2495 // default case -> j = default offset
2496 __ bind(default_case);
2497 __ profile_switch_default(i);
2498 __ lw(j, array, - 2 * BytesPerInt);
2499 __ swap(j);
2500 __ dadd(BCP, BCP, j);
2501 __ lbu(Rnext, BCP, 0);
2502 __ dispatch_only(vtos);
2503 }
2505 void TemplateTable::_return(TosState state) {
2506 transition(state, state);
2507 assert(_desc->calls_vm(), "inconsistent calls_vm information"); // call in remove_activation
2508 if (_desc->bytecode() == Bytecodes::_return_register_finalizer) {
2509 assert(state == vtos, "only valid state");
2510 __ ld(T1, aaddress(0));
2511 //__ ld(LVP, T1, oopDesc::klass_offset_in_bytes());
2512 __ load_klass(LVP, T1);
2513 __ lw(LVP, LVP, in_bytes(Klass::access_flags_offset()));
2514 __ move(AT, JVM_ACC_HAS_FINALIZER);
2515 __ andr(AT, AT, LVP);//by_css
2516 Label skip_register_finalizer;
2517 __ beq(AT, R0, skip_register_finalizer);
2518 __ delayed()->nop();
2519 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
2520 InterpreterRuntime::register_finalizer), T1);
2521 __ bind(skip_register_finalizer);
2522 }
2523 __ remove_activation(state, T9);
2524 __ sync();
2526 __ jr(T9);
2527 __ delayed()->nop();
2528 }
2530 // ----------------------------------------------------------------------------
2531 // Volatile variables demand their effects be made known to all CPU's
2532 // in order. Store buffers on most chips allow reads & writes to
2533 // reorder; the JMM's ReadAfterWrite.java test fails in -Xint mode
2534 // without some kind of memory barrier (i.e., it's not sufficient that
2535 // the interpreter does not reorder volatile references, the hardware
2536 // also must not reorder them).
2537 //
2538 // According to the new Java Memory Model (JMM):
2539 // (1) All volatiles are serialized wrt to each other. ALSO reads &
2540 // writes act as aquire & release, so:
2541 // (2) A read cannot let unrelated NON-volatile memory refs that
2542 // happen after the read float up to before the read. It's OK for
2543 // non-volatile memory refs that happen before the volatile read to
2544 // float down below it.
2545 // (3) Similar a volatile write cannot let unrelated NON-volatile
2546 // memory refs that happen BEFORE the write float down to after the
2547 // write. It's OK for non-volatile memory refs that happen after the
2548 // volatile write to float up before it.
2549 //
2550 // We only put in barriers around volatile refs (they are expensive),
2551 // not _between_ memory refs (that would require us to track the
2552 // flavor of the previous memory refs). Requirements (2) and (3)
2553 // require some barriers before volatile stores and after volatile
2554 // loads. These nearly cover requirement (1) but miss the
2555 // volatile-store-volatile-load case. This final case is placed after
2556 // volatile-stores although it could just as well go before
2557 // volatile-loads.
2558 //void TemplateTable::volatile_barrier(Assembler::Membar_mask_bits
2559 // order_constraint) {
2560 void TemplateTable::volatile_barrier( ) {
2561 // Helper function to insert a is-volatile test and memory barrier
2562 //if (os::is_MP()) { // Not needed on single CPU
2563 // __ membar(order_constraint);
2564 //}
2565 if( !os::is_MP() ) return; // Not needed on single CPU
2566 __ sync();
2567 }
2569 // we dont shift left 2 bits in get_cache_and_index_at_bcp
2570 // for we always need shift the index we use it. the ConstantPoolCacheEntry
2571 // is 16-byte long, index is the index in
2572 // ConstantPoolCache, so cache + base_offset() + index * 16 is
2573 // the corresponding ConstantPoolCacheEntry
2574 // used registers : T2
2575 // NOTE : the returned index need also shift left 4 to get the address!
2576 void TemplateTable::resolve_cache_and_index(int byte_no,
2577 Register Rcache,
2578 Register index,
2579 size_t index_size) {
2580 assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
2581 const Register temp = A1;
2582 assert_different_registers(Rcache, index);
2583 const int shift_count = (1 + byte_no)*BitsPerByte;
2584 Label resolved;
2585 __ get_cache_and_index_and_bytecode_at_bcp(Rcache, index, temp, byte_no, 1, index_size);
2586 // is resolved?
2587 int i = (int)bytecode();
2588 __ addi(temp, temp, -i);
2589 __ beq(temp, R0, resolved);
2590 __ delayed()->nop();
2591 // resolve first time through
2592 address entry;
2593 switch (bytecode()) {
2594 case Bytecodes::_getstatic : // fall through
2595 case Bytecodes::_putstatic : // fall through
2596 case Bytecodes::_getfield : // fall through
2597 case Bytecodes::_putfield :
2598 entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_get_put);
2599 break;
2600 case Bytecodes::_invokevirtual : // fall through
2601 case Bytecodes::_invokespecial : // fall through
2602 case Bytecodes::_invokestatic : // fall through
2603 case Bytecodes::_invokeinterface:
2604 entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invoke);
2605 break;
2606 case Bytecodes::_invokehandle:
2607 entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invokehandle);
2608 break;
2609 case Bytecodes::_invokedynamic:
2610 entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invokedynamic);
2611 break;
2612 default :
2613 fatal(err_msg("unexpected bytecode: %s", Bytecodes::name(bytecode())));
2614 }
2616 __ move(temp, i);
2617 __ call_VM(NOREG, entry, temp);
2619 // Update registers with resolved info
2620 __ get_cache_and_index_at_bcp(Rcache, index, 1, index_size);
2621 __ bind(resolved);
2622 }
2624 // The Rcache and index registers must be set before call
2625 void TemplateTable::load_field_cp_cache_entry(Register obj,
2626 Register cache,
2627 Register index,
2628 Register off,
2629 Register flags,
2630 bool is_static = false) {
2631 assert_different_registers(cache, index, flags, off);
2632 ByteSize cp_base_offset = ConstantPoolCache::base_offset();
2633 // Field offset
2634 __ dsll(AT, index, Address::times_ptr);
2635 __ dadd(AT, cache, AT);
2636 __ ld(off, AT, in_bytes(cp_base_offset + ConstantPoolCacheEntry::f2_offset()));
2637 // Flags
2638 __ ld(flags, AT, in_bytes(cp_base_offset + ConstantPoolCacheEntry::flags_offset()));
2640 // klass overwrite register
2641 if (is_static) {
2642 __ ld(obj, AT, in_bytes(cp_base_offset + ConstantPoolCacheEntry::f1_offset()));
2643 const int mirror_offset = in_bytes(Klass::java_mirror_offset());
2644 __ ld(obj, Address(obj, mirror_offset));
2646 __ verify_oop(obj);
2647 }
2648 }
2650 // get the method, itable_index and flags of the current invoke
2651 void TemplateTable::load_invoke_cp_cache_entry(int byte_no,
2652 Register method,
2653 Register itable_index,
2654 Register flags,
2655 bool is_invokevirtual,
2656 bool is_invokevfinal, /*unused*/
2657 bool is_invokedynamic) {
2658 // setup registers
2659 const Register cache = T3;
2660 const Register index = T1;
2661 assert_different_registers(method, flags);
2662 assert_different_registers(method, cache, index);
2663 assert_different_registers(itable_index, flags);
2664 assert_different_registers(itable_index, cache, index);
2665 assert(is_invokevirtual == (byte_no == f2_byte), "is invokevirtual flag redundant");
2666 // determine constant pool cache field offsets
2667 const int method_offset = in_bytes(
2668 ConstantPoolCache::base_offset() +
2669 ((byte_no == f2_byte)
2670 ? ConstantPoolCacheEntry::f2_offset()
2671 : ConstantPoolCacheEntry::f1_offset()
2672 )
2673 );
2674 const int flags_offset = in_bytes(ConstantPoolCache::base_offset() +
2675 ConstantPoolCacheEntry::flags_offset());
2676 // access constant pool cache fields
2677 const int index_offset = in_bytes(ConstantPoolCache::base_offset() +
2678 ConstantPoolCacheEntry::f2_offset());
2679 size_t index_size = (is_invokedynamic ? sizeof(u4): sizeof(u2));
2680 resolve_cache_and_index(byte_no, cache, index, index_size);
2682 //assert(wordSize == 8, "adjust code below");
2683 // note we shift 4 not 2, for we get is the true inde
2684 // of ConstantPoolCacheEntry, not the shifted 2-bit index as x86 version
2685 __ dsll(AT, index, Address::times_ptr);
2686 __ dadd(AT, cache, AT);
2687 __ ld(method, AT, method_offset);
2690 if (itable_index != NOREG) {
2691 __ ld(itable_index, AT, index_offset);
2692 }
2693 __ ld(flags, AT, flags_offset);
2694 }
2697 // The registers cache and index expected to be set before call.
2698 // Correct values of the cache and index registers are preserved.
2699 void TemplateTable::jvmti_post_field_access(Register cache, Register index,
2700 bool is_static, bool has_tos) {
2701 // do the JVMTI work here to avoid disturbing the register state below
2702 // We use c_rarg registers here because we want to use the register used in
2703 // the call to the VM
2704 if (JvmtiExport::can_post_field_access()) {
2705 // Check to see if a field access watch has been set before we take
2706 // the time to call into the VM.
2707 Label L1;
2708 assert_different_registers(cache, index, FSR);
2709 __ li(AT, (intptr_t)JvmtiExport::get_field_access_count_addr());
2710 __ lw(FSR, AT, 0);
2711 __ beq(FSR, R0, L1);
2712 __ delayed()->nop();
2714 // We rely on the bytecode being resolved and the cpCache entry filled in.
2715 // cache entry pointer
2716 //__ get_cache_and_index_at_bcp(c_rarg2, c_rarg3, 1);
2717 __ daddi(cache, cache, in_bytes(ConstantPoolCache::base_offset()));
2718 __ shl(index, 4);
2719 __ dadd(cache, cache, index);
2720 if (is_static) {
2721 __ move(FSR, R0);
2722 } else {
2723 __ lw(FSR, SP, 0);
2724 __ verify_oop(FSR);
2725 }
2726 // FSR: object pointer or NULL
2727 // cache: cache entry pointer
2728 __ call_VM(NOREG, CAST_FROM_FN_PTR(address,
2729 InterpreterRuntime::post_field_access), FSR, cache);
2730 __ get_cache_and_index_at_bcp(cache, index, 1);
2731 __ bind(L1);
2732 }
2733 }
2735 void TemplateTable::pop_and_check_object(Register r) {
2736 __ pop_ptr(r);
2737 __ null_check(r); // for field access must check obj.
2738 __ verify_oop(r);
2739 }
2741 // used registers : T1, T2, T3, T1
2742 // T1 : flags
2743 // T2 : off
2744 // T3 : obj
2745 // T1 : field address
2746 // The flags 31, 30, 29, 28 together build a 4 bit number 0 to 8 with the
2747 // following mapping to the TosState states:
2748 // btos: 0
2749 // ctos: 1
2750 // stos: 2
2751 // itos: 3
2752 // ltos: 4
2753 // ftos: 5
2754 // dtos: 6
2755 // atos: 7
2756 // vtos: 8
2757 // see ConstantPoolCacheEntry::set_field for more info
2758 void TemplateTable::getfield_or_static(int byte_no, bool is_static) {
2759 transition(vtos, vtos);
2761 const Register cache = T3;
2762 const Register index = T0;
2764 const Register obj = T3;
2765 const Register off = T2;
2766 const Register flags = T1;
2767 resolve_cache_and_index(byte_no, cache, index, sizeof(u2));
2768 //jvmti_post_field_access(cache, index, is_static, false);
2770 load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
2772 if (!is_static) pop_and_check_object(obj);
2773 __ dadd(index, obj, off);
2776 Label Done, notByte, notInt, notShort, notChar, notLong, notFloat, notObj, notDouble;
2778 assert(btos == 0, "change code, btos != 0");
2779 __ dsrl(flags, flags, ConstantPoolCacheEntry::tos_state_shift);
2780 __ andi(flags, flags, 0xf);
2781 __ bne(flags, R0, notByte);
2782 __ delayed()->nop();
2784 // btos
2785 __ lb(FSR, index, 0);
2786 __ sd(FSR, SP, - wordSize);
2788 // Rewrite bytecode to be faster
2789 if (!is_static) {
2790 patch_bytecode(Bytecodes::_fast_bgetfield, T3, T2);
2791 }
2792 __ b(Done);
2793 __ delayed()->daddi(SP, SP, - wordSize);
2795 __ bind(notByte);
2796 __ move(AT, itos);
2797 __ bne(flags, AT, notInt);
2798 __ delayed()->nop();
2800 // itos
2801 __ lw(FSR, index, 0);
2802 __ sd(FSR, SP, - wordSize);
2804 // Rewrite bytecode to be faster
2805 if (!is_static) {
2806 // patch_bytecode(Bytecodes::_fast_igetfield, T3, T2);
2807 patch_bytecode(Bytecodes::_fast_igetfield, T3, T2);
2808 }
2809 __ b(Done);
2810 __ delayed()->daddi(SP, SP, - wordSize);
2812 __ bind(notInt);
2813 __ move(AT, atos);
2814 __ bne(flags, AT, notObj);
2815 __ delayed()->nop();
2817 // atos
2818 //add for compressedoops
2819 __ load_heap_oop(FSR, Address(index, 0));
2820 __ sd(FSR, SP, - wordSize);
2822 if (!is_static) {
2823 //patch_bytecode(Bytecodes::_fast_agetfield, T3, T2);
2824 patch_bytecode(Bytecodes::_fast_agetfield, T3, T2);
2825 }
2826 __ b(Done);
2827 __ delayed()->daddi(SP, SP, - wordSize);
2829 __ bind(notObj);
2830 __ move(AT, ctos);
2831 __ bne(flags, AT, notChar);
2832 __ delayed()->nop();
2834 // ctos
2835 __ lhu(FSR, index, 0);
2836 __ sd(FSR, SP, - wordSize);
2838 if (!is_static) {
2839 patch_bytecode(Bytecodes::_fast_cgetfield, T3, T2);
2840 }
2841 __ b(Done);
2842 __ delayed()->daddi(SP, SP, - wordSize);
2844 __ bind(notChar);
2845 __ move(AT, stos);
2846 __ bne(flags, AT, notShort);
2847 __ delayed()->nop();
2849 // stos
2850 __ lh(FSR, index, 0);
2851 __ sd(FSR, SP, - wordSize);
2853 if (!is_static) {
2854 // patch_bytecode(Bytecodes::_fast_sgetfield, T3, T2);
2855 patch_bytecode(Bytecodes::_fast_sgetfield, T3, T2);
2856 }
2857 __ b(Done);
2858 __ delayed()->daddi(SP, SP, - wordSize);
2860 __ bind(notShort);
2861 __ move(AT, ltos);
2862 __ bne(flags, AT, notLong);
2863 __ delayed()->nop();
2865 // FIXME : the load/store should be atomic, we have no simple method to do this in mips32
2866 // ltos
2867 __ ld(FSR, index, 0 * wordSize);
2868 __ sd(FSR, SP, -2 * wordSize);
2869 __ sd(R0, SP, -1 * wordSize);
2871 // Don't rewrite to _fast_lgetfield for potential volatile case.
2872 __ b(Done);
2873 __ delayed()->daddi(SP, SP, - 2 * wordSize);
2875 __ bind(notLong);
2876 __ move(AT, ftos);
2877 __ bne(flags, AT, notFloat);
2878 __ delayed()->nop();
2880 // ftos
2881 __ lwc1(FSF, index, 0);
2882 __ sdc1(FSF, SP, - wordSize);
2884 if (!is_static) {
2885 patch_bytecode(Bytecodes::_fast_fgetfield, T3, T2);
2886 }
2887 __ b(Done);
2888 __ delayed()->daddi(SP, SP, - wordSize);
2890 __ bind(notFloat);
2891 __ move(AT, dtos);
2892 __ bne(flags, AT, notDouble);
2893 __ delayed()->nop();
2895 // dtos
2896 __ ldc1(FSF, index, 0 * wordSize);
2897 __ sdc1(FSF, SP, - 2 * wordSize);
2898 __ sd(R0, SP, - 1 * wordSize);
2900 if (!is_static) {
2901 patch_bytecode(Bytecodes::_fast_dgetfield, T3, T2);
2902 }
2903 __ b(Done);
2904 __ delayed()->daddi(SP, SP, - 2 * wordSize);
2906 __ bind(notDouble);
2908 __ stop("Bad state");
2910 __ bind(Done);
2911 }
2913 void TemplateTable::getfield(int byte_no) {
2914 getfield_or_static(byte_no, false);
2915 }
2917 void TemplateTable::getstatic(int byte_no) {
2918 getfield_or_static(byte_no, true);
2919 }
2920 /*
2921 // used registers : T1, T2, T3, T1
2922 // T1 : cache & cp entry
2923 // T2 : obj
2924 // T3 : flags & value pointer
2925 // T1 : index
2926 // see ConstantPoolCacheEntry::set_field for more info
2927 void TemplateTable::jvmti_post_field_mod(int byte_no, bool is_static) {
2928 */
2930 // The registers cache and index expected to be set before call.
2931 // The function may destroy various registers, just not the cache and index registers.
2932 void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
2933 ByteSize cp_base_offset = ConstantPoolCache::base_offset();
2935 if (JvmtiExport::can_post_field_modification()) {
2936 // Check to see if a field modification watch has been set before we take
2937 // the time to call into the VM.
2938 Label L1;
2939 assert_different_registers(cache, index, AT);
2941 //__ lui(AT, Assembler::split_high((int)JvmtiExport::get_field_modification_count_addr()));
2942 //__ lw(FSR, AT, Assembler::split_low((int)JvmtiExport::get_field_modification_count_addr()));
2943 __ li(AT, JvmtiExport::get_field_modification_count_addr());
2944 __ lw(FSR, AT, 0);
2945 __ beq(FSR, R0, L1);
2946 __ delayed()->nop();
2948 /* // We rely on the bytecode being resolved and the cpCache entry filled in.
2949 resolve_cache_and_index(byte_no, T1, T1);
2950 */
2951 // The cache and index registers have been already set.
2952 // This allows to eliminate this call but the cache and index
2953 // registers have to be correspondingly used after this line.
2954 // __ get_cache_and_index_at_bcp(eax, edx, 1);
2955 __ get_cache_and_index_at_bcp(T1, T9, 1);
2957 if (is_static) {
2958 __ move(T2, R0);
2959 } else {
2960 // Life is harder. The stack holds the value on top,
2961 // followed by the object.
2962 // We don't know the size of the value, though;
2963 // it could be one or two words
2964 // depending on its type. As a result, we must find
2965 // the type to determine where the object is.
2966 Label two_word, valsize_known;
2967 __ dsll(AT, T1, 4);
2968 __ dadd(AT, T1, AT);
2969 __ lw(T3, AT, in_bytes(cp_base_offset
2970 + ConstantPoolCacheEntry::flags_offset()));
2971 __ move(T2, SP);
2972 __ shr(T3, ConstantPoolCacheEntry::tos_state_shift);
2974 // Make sure we don't need to mask ecx for tos_state_shift
2975 // after the above shift
2976 ConstantPoolCacheEntry::verify_tos_state_shift();
2977 __ move(AT, ltos);
2978 __ beq(T3, AT, two_word);
2979 __ delayed()->nop();
2980 __ move(AT, dtos);
2981 __ beq(T3, AT, two_word);
2982 __ delayed()->nop();
2983 __ b(valsize_known);
2984 //__ delayed()->daddi(T2, T2, wordSize*1);
2985 __ delayed()->daddi(T2, T2,Interpreter::expr_offset_in_bytes(1) );
2987 __ bind(two_word);
2988 // __ daddi(T2, T2, wordSize*2);
2989 __ daddi(T2, T2,Interpreter::expr_offset_in_bytes(2));
2991 __ bind(valsize_known);
2992 // setup object pointer
2993 __ lw(T2, T2, 0*wordSize);
2994 }
2995 // cache entry pointer
2996 __ daddi(T1, T1, in_bytes(cp_base_offset));
2997 __ shl(T1, 4);
2998 __ daddu(T1, T1, T1);
2999 // object (tos)
3000 __ move(T3, SP);
3001 // T2: object pointer set up above (NULL if static)
3002 // T1: cache entry pointer
3003 // T3: jvalue object on the stack
3004 __ call_VM(NOREG, CAST_FROM_FN_PTR(address,
3005 InterpreterRuntime::post_field_modification), T2, T1, T3);
3006 __ get_cache_and_index_at_bcp(cache, index, 1);
3007 __ bind(L1);
3008 }
3009 }
3011 // used registers : T0, T1, T2, T3, T8
3012 // T1 : flags
3013 // T2 : off
3014 // T3 : obj
3015 // T8 : volatile bit
3016 // see ConstantPoolCacheEntry::set_field for more info
3017 void TemplateTable::putfield_or_static(int byte_no, bool is_static) {
3018 transition(vtos, vtos);
3020 const Register cache = T3;
3021 const Register index = T0;
3022 const Register obj = T3;
3023 const Register off = T2;
3024 const Register flags = T1;
3025 const Register bc = T3;
3027 resolve_cache_and_index(byte_no, cache, index, sizeof(u2));
3028 //TODO: LEE
3029 //jvmti_post_field_mod(cache, index, is_static);
3030 load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
3031 // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
3032 // volatile_barrier( );
3034 Label notVolatile, Done;
3035 __ move(AT, 1<<ConstantPoolCacheEntry::is_volatile_shift);
3036 __ andr(T8, flags, AT);
3038 Label notByte, notInt, notShort, notChar, notLong, notFloat, notObj, notDouble;
3040 assert(btos == 0, "change code, btos != 0");
3041 // btos
3042 __ dsrl(flags, flags, ConstantPoolCacheEntry::tos_state_shift);
3043 __ andi(flags, flags, ConstantPoolCacheEntry::tos_state_mask);
3044 __ bne(flags, R0, notByte);
3045 __ delayed()->nop();
3047 __ pop(btos);
3048 if (!is_static) {
3049 pop_and_check_object(obj);
3050 }
3051 __ dadd(AT, obj, off);
3052 __ sb(FSR, AT, 0);
3054 if (!is_static) {
3055 patch_bytecode(Bytecodes::_fast_bputfield, bc, off, true, byte_no);
3056 }
3057 __ b(Done);
3058 __ delayed()->nop();
3060 __ bind(notByte);
3061 // itos
3062 __ move(AT, itos);
3063 __ bne(flags, AT, notInt);
3064 __ delayed()->nop();
3066 __ pop(itos);
3067 if (!is_static) {
3068 pop_and_check_object(obj);
3069 }
3070 __ dadd(AT, obj, off);
3071 __ sw(FSR, AT, 0);
3073 if (!is_static) {
3074 patch_bytecode(Bytecodes::_fast_iputfield, bc, off, true, byte_no);
3075 }
3076 __ b(Done);
3077 __ delayed()->nop();
3078 __ bind(notInt);
3079 // atos
3080 __ move(AT, atos);
3081 __ bne(flags, AT, notObj);
3082 __ delayed()->nop();
3084 __ pop(atos);
3085 if (!is_static) {
3086 pop_and_check_object(obj);
3087 }
3089 __ dadd(AT, obj, off);
3090 //__ sd(FSR, AT, 0);
3091 __ store_heap_oop(Address(AT, 0), FSR);
3092 __ sync();
3093 __ store_check(obj);
3095 if (!is_static) {
3096 patch_bytecode(Bytecodes::_fast_aputfield, bc, off, true, byte_no);
3097 }
3098 __ b(Done);
3099 __ delayed()->nop();
3100 __ bind(notObj);
3101 // ctos
3102 __ move(AT, ctos);
3103 __ bne(flags, AT, notChar);
3104 __ delayed()->nop();
3106 __ pop(ctos);
3107 if (!is_static) {
3108 pop_and_check_object(obj);
3109 }
3110 __ dadd(AT, obj, off);
3111 __ sh(FSR, AT, 0);
3112 if (!is_static) {
3113 patch_bytecode(Bytecodes::_fast_cputfield, bc, off, true, byte_no);
3114 }
3115 __ b(Done);
3116 __ delayed()->nop();
3117 __ bind(notChar);
3118 // stos
3119 __ move(AT, stos);
3120 __ bne(flags, AT, notShort);
3121 __ delayed()->nop();
3123 __ pop(stos);
3124 if (!is_static) {
3125 pop_and_check_object(obj);
3126 }
3127 __ dadd(AT, obj, off);
3128 __ sh(FSR, AT, 0);
3129 if (!is_static) {
3130 patch_bytecode(Bytecodes::_fast_sputfield, bc, off, true, byte_no);
3131 }
3132 __ b(Done);
3133 __ delayed()->nop();
3134 __ bind(notShort);
3135 // ltos
3136 __ move(AT, ltos);
3137 __ bne(flags, AT, notLong);
3138 __ delayed()->nop();
3140 // FIXME: there is no simple method to load/store 64-bit data in a atomic operation
3141 // we just ignore the volatile flag.
3142 //Label notVolatileLong;
3143 //__ beq(T1, R0, notVolatileLong);
3144 //__ delayed()->nop();
3146 //addent = 2 * wordSize;
3147 // no need
3148 //__ lw(FSR, SP, 0);
3149 //__ lw(SSR, SP, 1 * wordSize);
3150 //if (!is_static) {
3151 // __ lw(T3, SP, addent);
3152 // addent += 1 * wordSize;
3153 // __ verify_oop(T3);
3154 //}
3156 //__ daddu(AT, T3, T2);
3158 // Replace with real volatile test
3159 // NOTE : we assume that sdc1&ldc1 operate in 32-bit, this is true for Godson2 even in 64-bit kernel
3160 // last modified by yjl 7/12/2005
3161 //__ ldc1(FSF, SP, 0);
3162 //__ sdc1(FSF, AT, 0);
3163 //volatile_barrier();
3165 // Don't rewrite volatile version
3166 //__ b(notVolatile);
3167 //__ delayed()->addiu(SP, SP, addent);
3169 //__ bind(notVolatileLong);
3171 //__ pop(ltos); // overwrites edx
3172 // __ lw(FSR, SP, 0 * wordSize);
3173 // __ lw(SSR, SP, 1 * wordSize);
3174 // __ daddi(SP, SP, 2*wordSize);
3175 __ pop(ltos);
3176 if (!is_static) {
3177 pop_and_check_object(obj);
3178 }
3179 __ dadd(AT, obj, off);
3180 __ sd(FSR, AT, 0);
3181 if (!is_static) {
3182 patch_bytecode(Bytecodes::_fast_lputfield, bc, off, true, byte_no);
3183 }
3184 __ b(notVolatile);
3185 __ delayed()->nop();
3187 __ bind(notLong);
3188 // ftos
3189 __ move(AT, ftos);
3190 __ bne(flags, AT, notFloat);
3191 __ delayed()->nop();
3193 __ pop(ftos);
3194 if (!is_static) {
3195 pop_and_check_object(obj);
3196 }
3197 __ dadd(AT, obj, off);
3198 __ swc1(FSF, AT, 0);
3199 if (!is_static) {
3200 patch_bytecode(Bytecodes::_fast_fputfield, bc, off, true, byte_no);
3201 }
3202 __ b(Done);
3203 __ delayed()->nop();
3204 __ bind(notFloat);
3205 // dtos
3206 __ move(AT, dtos);
3207 __ bne(flags, AT, notDouble);
3208 __ delayed()->nop();
3210 __ pop(dtos);
3211 if (!is_static) {
3212 pop_and_check_object(obj);
3213 }
3214 __ dadd(AT, obj, off);
3215 __ sdc1(FSF, AT, 0);
3216 if (!is_static) {
3217 patch_bytecode(Bytecodes::_fast_dputfield, bc, off, true, byte_no);
3218 }
3219 __ b(Done);
3220 __ delayed()->nop();
3221 __ bind(notDouble);
3223 __ stop("Bad state");
3225 __ bind(Done);
3227 // Check for volatile store
3228 __ beq(T8, R0, notVolatile);
3229 __ delayed()->nop();
3230 volatile_barrier( );
3231 __ bind(notVolatile);
3232 }
3234 void TemplateTable::putfield(int byte_no) {
3235 putfield_or_static(byte_no, false);
3236 }
3238 void TemplateTable::putstatic(int byte_no) {
3239 putfield_or_static(byte_no, true);
3240 }
3242 // used registers : T1, T2, T3
3243 // T1 : cp_entry
3244 // T2 : obj
3245 // T3 : value pointer
3246 void TemplateTable::jvmti_post_fast_field_mod() {
3247 if (JvmtiExport::can_post_field_modification()) {
3248 // Check to see if a field modification watch has been set before we take
3249 // the time to call into the VM.
3250 Label L2;
3251 //__ lui(AT, Assembler::split_high((intptr_t)JvmtiExport::get_field_modification_count_addr()));
3252 //__ lw(T3, AT, Assembler::split_low((intptr_t)JvmtiExport::get_field_modification_count_addr()));
3253 __ li(AT, JvmtiExport::get_field_modification_count_addr());
3254 __ lw(T3, AT, 0);
3255 __ beq(T3, R0, L2);
3256 __ delayed()->nop();
3257 //__ pop(T2);
3258 __ pop_ptr(T2);
3259 //__ lw(T2, SP, 0);
3260 __ verify_oop(T2);
3261 __ push_ptr(T2);
3262 __ li(AT, -sizeof(jvalue));
3263 __ daddu(SP, SP, AT);
3264 __ move(T3, SP);
3265 //__ push(T2);
3266 //__ move(T2, R0);
3268 switch (bytecode()) { // load values into the jvalue object
3269 case Bytecodes::_fast_bputfield:
3270 __ sb(FSR, SP, 0);
3271 break;
3272 case Bytecodes::_fast_sputfield:
3273 __ sh(FSR, SP, 0);
3274 break;
3275 case Bytecodes::_fast_cputfield:
3276 __ sh(FSR, SP, 0);
3277 break;
3278 case Bytecodes::_fast_iputfield:
3279 __ sw(FSR, SP, 0);
3280 break;
3281 case Bytecodes::_fast_lputfield:
3282 __ sd(FSR, SP, 0);
3283 break;
3284 case Bytecodes::_fast_fputfield:
3285 __ swc1(FSF, SP, 0);
3286 break;
3287 case Bytecodes::_fast_dputfield:
3288 __ sdc1(FSF, SP, 0);
3289 break;
3290 case Bytecodes::_fast_aputfield:
3291 __ sd(FSR, SP, 0);
3292 break;
3293 default: ShouldNotReachHere();
3294 }
3296 //__ pop(T2); // restore copy of object pointer
3298 // Save eax and sometimes edx because call_VM() will clobber them,
3299 // then use them for JVM/DI purposes
3300 __ push(FSR);
3301 if (bytecode() == Bytecodes::_fast_lputfield) __ push(SSR);
3302 // access constant pool cache entry
3303 __ get_cache_entry_pointer_at_bcp(T1, T2, 1);
3304 // no need, verified ahead
3305 __ verify_oop(T2);
3307 // ebx: object pointer copied above
3308 // eax: cache entry pointer
3309 // ecx: jvalue object on the stack
3310 __ call_VM(NOREG, CAST_FROM_FN_PTR(address,
3311 InterpreterRuntime::post_field_modification), T2, T1, T3);
3312 if (bytecode() == Bytecodes::_fast_lputfield) __ pop(SSR); // restore high value
3313 //__ pop(FSR); // restore lower value
3314 //__ daddi(SP, SP, sizeof(jvalue)); // release jvalue object space
3315 __ lw(FSR, SP, 0);
3316 __ daddiu(SP, SP, sizeof(jvalue) + 1 * wordSize);
3317 __ bind(L2);
3318 }
3319 }
3321 // used registers : T2, T3, T1
3322 // T2 : index & off & field address
3323 // T3 : cache & obj
3324 // T1 : flags
3325 void TemplateTable::fast_storefield(TosState state) {
3326 transition(state, vtos);
3328 ByteSize base = ConstantPoolCache::base_offset();
3330 jvmti_post_fast_field_mod();
3332 // access constant pool cache
3333 __ get_cache_and_index_at_bcp(T3, T2, 1);
3335 // test for volatile with edx but edx is tos register for lputfield.
3336 __ dsll(AT, T2, Address::times_8);
3337 __ dadd(AT, T3, AT);
3338 __ ld(T1, AT, in_bytes(base + ConstantPoolCacheEntry::flags_offset()));
3340 // replace index with field offset from cache entry
3341 __ ld(T2, AT, in_bytes(base + ConstantPoolCacheEntry::f2_offset()));
3343 // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
3344 // volatile_barrier( );
3346 Label notVolatile, Done;
3347 // Check for volatile store
3348 __ move(AT, 1<<ConstantPoolCacheEntry::is_volatile_shift);
3349 __ andr(AT, T1, AT);
3350 __ beq(AT, R0, notVolatile);
3351 __ delayed()->nop();
3354 // Get object from stack
3355 // NOTE : the value in FSR/FSF now
3356 // __ pop(T3);
3357 // __ verify_oop(T3);
3358 pop_and_check_object(T3);
3359 // field addresses
3360 __ dadd(T2, T3, T2);
3362 // access field
3363 switch (bytecode()) {
3364 case Bytecodes::_fast_bputfield:
3365 __ sb(FSR, T2, 0);
3366 break;
3367 case Bytecodes::_fast_sputfield: // fall through
3368 case Bytecodes::_fast_cputfield:
3369 __ sh(FSR, T2, 0);
3370 break;
3371 case Bytecodes::_fast_iputfield:
3372 __ sw(FSR, T2, 0);
3373 break;
3374 case Bytecodes::_fast_lputfield:
3375 __ sd(FSR, T2, 0 * wordSize);
3376 break;
3377 case Bytecodes::_fast_fputfield:
3378 __ swc1(FSF, T2, 0);
3379 break;
3380 case Bytecodes::_fast_dputfield:
3381 __ sdc1(FSF, T2, 0 * wordSize);
3382 break;
3383 case Bytecodes::_fast_aputfield:
3384 __ store_heap_oop(Address(T2, 0), FSR);
3385 __ sync();
3386 __ store_check(T3);
3387 break;
3388 default:
3389 ShouldNotReachHere();
3390 }
3392 Label done;
3393 volatile_barrier( );
3394 __ b(done);
3395 __ delayed()->nop();
3397 // Same code as above, but don't need edx to test for volatile.
3398 __ bind(notVolatile);
3400 // Get object from stack
3401 // __ pop(T3);
3402 // __ verify_oop(T3);
3403 pop_and_check_object(T3);
3404 //get the field address
3405 __ dadd(T2, T3, T2);
3407 // access field
3408 switch (bytecode()) {
3409 case Bytecodes::_fast_bputfield:
3410 __ sb(FSR, T2, 0);
3411 break;
3412 case Bytecodes::_fast_sputfield: // fall through
3413 case Bytecodes::_fast_cputfield:
3414 __ sh(FSR, T2, 0);
3415 break;
3416 case Bytecodes::_fast_iputfield:
3417 __ sw(FSR, T2, 0);
3418 break;
3419 case Bytecodes::_fast_lputfield:
3420 __ sd(FSR, T2, 0 * wordSize);
3421 break;
3422 case Bytecodes::_fast_fputfield:
3423 __ swc1(FSF, T2, 0);
3424 break;
3425 case Bytecodes::_fast_dputfield:
3426 __ sdc1(FSF, T2, 0 * wordSize);
3427 break;
3428 case Bytecodes::_fast_aputfield:
3429 //add for compressedoops
3430 __ store_heap_oop(Address(T2, 0), FSR);
3431 __ sync();
3432 __ store_check(T3);
3433 break;
3434 default:
3435 ShouldNotReachHere();
3436 }
3437 __ bind(done);
3438 }
3440 // used registers : T2, T3, T1
3441 // T3 : cp_entry & cache
3442 // T2 : index & offset
3443 void TemplateTable::fast_accessfield(TosState state) {
3444 transition(atos, state);
3446 // do the JVMTI work here to avoid disturbing the register state below
3447 if (JvmtiExport::can_post_field_access()) {
3448 // Check to see if a field access watch has been set before we take
3449 // the time to call into the VM.
3450 Label L1;
3451 __ li(AT, (intptr_t)JvmtiExport::get_field_access_count_addr());
3452 __ lw(T3, AT, 0);
3453 __ beq(T3, R0, L1);
3454 __ delayed()->nop();
3455 // access constant pool cache entry
3456 __ get_cache_entry_pointer_at_bcp(T3, T1, 1);
3457 __ move(TSR, FSR);
3458 __ verify_oop(FSR);
3459 // FSR: object pointer copied above
3460 // T3: cache entry pointer
3461 __ call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access),
3462 FSR, T3);
3463 __ move(FSR, TSR);
3464 __ bind(L1);
3465 }
3467 // access constant pool cache
3468 __ get_cache_and_index_at_bcp(T3, T2, 1);
3469 // replace index with field offset from cache entry
3470 __ dsll(AT, T2, Address::times_8);
3471 //__ dsll(AT, T2, 4);
3472 __ dadd(AT, T3, AT);
3473 __ ld(T2, AT, in_bytes(ConstantPoolCache::base_offset()
3474 + ConstantPoolCacheEntry::f2_offset()));
3476 // eax: object
3477 __ verify_oop(FSR);
3478 // __ null_check(FSR, 0);
3479 __ null_check(FSR);
3480 // field addresses
3481 __ dadd(FSR, FSR, T2);
3483 // access field
3484 switch (bytecode()) {
3485 case Bytecodes::_fast_bgetfield:
3486 __ lb(FSR, FSR, 0);
3487 break;
3488 case Bytecodes::_fast_sgetfield:
3489 __ lh(FSR, FSR, 0);
3490 break;
3491 case Bytecodes::_fast_cgetfield:
3492 __ lhu(FSR, FSR, 0);
3493 break;
3494 case Bytecodes::_fast_igetfield:
3495 __ lw(FSR, FSR, 0);
3496 break;
3497 case Bytecodes::_fast_lgetfield:
3498 __ stop("should not be rewritten");
3499 break;
3500 case Bytecodes::_fast_fgetfield:
3501 __ lwc1(FSF, FSR, 0);
3502 break;
3503 case Bytecodes::_fast_dgetfield:
3504 __ ldc1(FSF, FSR, 0);
3505 break;
3506 case Bytecodes::_fast_agetfield:
3507 //add for compressedoops
3508 __ load_heap_oop(FSR, Address(FSR, 0));
3509 __ verify_oop(FSR);
3510 break;
3511 default:
3512 ShouldNotReachHere();
3513 }
3515 // Doug Lea believes this is not needed with current Sparcs(TSO) and Intel(PSO)
3516 // volatile_barrier( );
3517 }
3519 // generator for _fast_iaccess_0, _fast_aaccess_0, _fast_faccess_0
3520 // used registers : T1, T2, T3, T1
3521 // T1 : obj & field address
3522 // T2 : off
3523 // T3 : cache
3524 // T1 : index
3525 void TemplateTable::fast_xaccess(TosState state) {
3526 transition(vtos, state);
3527 // get receiver
3528 __ ld(T1, aaddress(0));
3529 // access constant pool cache
3530 __ get_cache_and_index_at_bcp(T3, T2, 2);
3531 __ dsll(AT, T2, Address::times_8);
3532 __ dadd(AT, T3, AT);
3533 __ ld(T2, AT, in_bytes(ConstantPoolCache::base_offset()
3534 + ConstantPoolCacheEntry::f2_offset()));
3536 // make sure exception is reported in correct bcp range (getfield is next instruction)
3537 __ daddi(BCP, BCP, 1);
3538 // __ null_check(T1, 0);
3539 __ null_check(T1);
3540 __ dadd(T1, T1, T2);
3542 if (state == itos) {
3543 __ lw(FSR, T1, 0);
3544 } else if (state == atos) {
3545 //__ ld(FSR, T1, 0);
3546 __ load_heap_oop(FSR, Address(T1, 0));
3547 __ verify_oop(FSR);
3548 } else if (state == ftos) {
3549 __ lwc1(FSF, T1, 0);
3550 } else {
3551 ShouldNotReachHere();
3552 }
3553 __ daddi(BCP, BCP, -1);
3554 }
3556 //---------------------------------------------------
3557 //-------------------------------------------------
3558 // Calls
3560 void TemplateTable::count_calls(Register method, Register temp) {
3561 // implemented elsewhere
3562 ShouldNotReachHere();
3563 }
3565 // method, index, recv, flags: T1, T2, T3, T1
3566 // byte_no = 2 for _invokevirtual, 1 else
3567 // T0 : return address
3568 // get the method & index of the invoke, and push the return address of
3569 // the invoke(first word in the frame)
3570 // this address is where the return code jmp to.
3571 // NOTE : this method will set T3&T1 as recv&flags
3572 void TemplateTable::prepare_invoke(int byte_no,
3573 Register method, //linked method (or i-klass)
3574 Register index, //itable index, MethodType ,etc.
3575 Register recv, // if caller wants to see it
3576 Register flags // if caller wants to test it
3577 ) {
3578 // determine flags
3579 const Bytecodes::Code code = bytecode();
3580 const bool is_invokeinterface = code == Bytecodes::_invokeinterface;
3581 const bool is_invokedynamic = code == Bytecodes::_invokedynamic;
3582 const bool is_invokehandle = code == Bytecodes::_invokehandle;
3583 const bool is_invokevirtual = code == Bytecodes::_invokevirtual;
3584 const bool is_invokespecial = code == Bytecodes::_invokespecial;
3585 const bool load_receiver = (recv != noreg);
3586 const bool save_flags = (flags != noreg);
3587 assert(load_receiver == (code != Bytecodes::_invokestatic && code != Bytecodes::_invokedynamic),"");
3588 assert(save_flags == (is_invokeinterface || is_invokevirtual), "need flags for vfinal");
3589 assert(flags == noreg || flags == T1, "error flags reg.");
3590 assert(recv == noreg || recv == T3, "error recv reg.");
3591 // setup registers & access constant pool cache
3592 if(recv == noreg) recv = T3;
3593 if(flags == noreg) flags = T1;
3595 assert_different_registers(method, index, recv, flags);
3597 // save 'interpreter return address'
3598 __ save_bcp();
3600 load_invoke_cp_cache_entry(byte_no, method, index, flags, is_invokevirtual, false, is_invokedynamic);
3601 if (is_invokedynamic || is_invokehandle) {
3602 Label L_no_push;
3603 __ move(AT, (1 << ConstantPoolCacheEntry::has_appendix_shift));
3604 __ andr(AT, AT, flags);
3605 __ beq(AT, R0, L_no_push);
3606 __ delayed()->nop();
3607 // Push the appendix as a trailing parameter.
3608 // This must be done before we get the receiver,
3609 // since the parameter_size includes it.
3610 Register tmp = SSR;
3611 __ push(tmp);
3612 __ move(tmp, index);
3613 assert(ConstantPoolCacheEntry::_indy_resolved_references_appendix_offset == 0, "appendix expected at index+0");
3614 __ load_resolved_reference_at_index(index, tmp);
3615 __ pop(tmp);
3616 __ push(index); // push appendix (MethodType, CallSite, etc.)
3617 __ bind(L_no_push);
3619 }
3621 // load receiver if needed (after appendix is pushed so parameter size is correct)
3622 // Note: no return address pushed yet
3623 if (load_receiver) {
3624 __ move(AT, ConstantPoolCacheEntry::parameter_size_mask);
3625 __ andr(recv, flags, AT);
3626 // 2014/07/31 Fu: Since we won't push RA on stack, no_return_pc_pushed_yet should be 0.
3627 const int no_return_pc_pushed_yet = 0; // argument slot correction before we push return address
3628 const int receiver_is_at_end = -1; // back off one slot to get receiver
3629 Address recv_addr = __ argument_address(recv, no_return_pc_pushed_yet + receiver_is_at_end);
3631 __ ld(recv, recv_addr);
3632 __ verify_oop(recv);
3633 }
3634 if(save_flags) {
3635 //__ movl(r13, flags);
3636 __ move(BCP, flags);
3637 }
3638 // compute return type
3639 __ dsrl(flags, flags, ConstantPoolCacheEntry::tos_state_shift);
3640 __ andi(flags, flags, 0xf);
3642 // Make sure we don't need to mask flags for tos_state_shift after the above shift
3643 ConstantPoolCacheEntry::verify_tos_state_shift();
3644 // load return address
3645 {
3646 const address table = (address) Interpreter::invoke_return_entry_table_for(code);
3647 __ li(AT, (long)table);
3648 __ dsll(flags, flags, LogBytesPerWord);
3649 __ dadd(AT, AT, flags);
3650 __ ld(RA, AT, 0);
3651 }
3653 if (save_flags) {
3654 __ move(flags, BCP);
3655 __ restore_bcp();
3656 }
3657 }
3659 // used registers : T0, T3, T1, T2
3660 // T3 : recv, this two register using convention is by prepare_invoke
3661 // T1 : flags, klass
3662 // Rmethod : method, index must be Rmethod
3663 void TemplateTable::invokevirtual_helper(Register index, Register recv,
3664 Register flags) {
3666 assert_different_registers(index, recv, flags, T2);
3668 // Test for an invoke of a final method
3669 Label notFinal;
3670 __ move(AT, (1 << ConstantPoolCacheEntry::is_vfinal_shift));
3671 __ andr(AT, flags, AT);
3672 __ beq(AT, R0, notFinal);
3673 __ delayed()->nop();
3675 Register method = index; // method must be Rmethod
3676 assert(method == Rmethod, "methodOop must be Rmethod for interpreter calling convention");
3678 // do the call - the index is actually the method to call
3679 // the index is indeed methodOop, for this is vfinal,
3680 // see ConstantPoolCacheEntry::set_method for more info
3682 __ verify_oop(method);
3684 // It's final, need a null check here!
3685 __ null_check(recv);
3687 // profile this call
3688 __ profile_final_call(T2);
3690 // 2014/11/24 Fu
3691 // T2: tmp, used for mdp
3692 // method: callee
3693 // T9: tmp
3694 // is_virtual: true
3695 __ profile_arguments_type(T2, method, T9, true);
3697 // __ move(T0, recv);
3698 __ jump_from_interpreted(method, T2);
3700 __ bind(notFinal);
3702 // get receiver klass
3703 __ null_check(recv, oopDesc::klass_offset_in_bytes());
3704 // Keep recv in ecx for callee expects it there
3705 __ load_klass(T2, recv);
3706 __ verify_oop(T2);
3707 // profile this call
3708 __ profile_virtual_call(T2, T0, T1);
3710 // get target methodOop & entry point
3711 const int base = InstanceKlass::vtable_start_offset() * wordSize;
3712 assert(vtableEntry::size() * wordSize == 8, "adjust the scaling in the code below");
3713 __ dsll(AT, index, Address::times_8);
3714 __ dadd(AT, T2, AT);
3715 //this is a ualign read
3716 __ ld(method, AT, base + vtableEntry::method_offset_in_bytes());
3717 __ jump_from_interpreted(method, T2);
3719 }
3721 void TemplateTable::invokevirtual(int byte_no) {
3722 transition(vtos, vtos);
3723 assert(byte_no == f2_byte, "use this argument");
3724 prepare_invoke(byte_no, Rmethod, NOREG, T3, T1);
3725 // now recv & flags in T3, T1
3726 invokevirtual_helper(Rmethod, T3, T1);
3727 }
3729 // T9 : entry
3730 // Rmethod : method
3731 void TemplateTable::invokespecial(int byte_no) {
3732 transition(vtos, vtos);
3733 assert(byte_no == f1_byte, "use this argument");
3734 prepare_invoke(byte_no, Rmethod, NOREG, T3);
3735 // now recv & flags in T3, T1
3736 __ verify_oop(T3);
3737 __ null_check(T3);
3738 __ profile_call(T9);
3740 // 2014/11/24 Fu
3741 // T8: tmp, used for mdp
3742 // Rmethod: callee
3743 // T9: tmp
3744 // is_virtual: false
3745 __ profile_arguments_type(T8, Rmethod, T9, false);
3747 __ jump_from_interpreted(Rmethod, T9);
3748 __ move(T0, T3);//aoqi ?
3749 }
3751 void TemplateTable::invokestatic(int byte_no) {
3752 transition(vtos, vtos);
3753 assert(byte_no == f1_byte, "use this argument");
3754 prepare_invoke(byte_no, Rmethod, NOREG);
3755 __ verify_oop(Rmethod);
3757 __ profile_call(T9);
3759 // 2014/11/24 Fu
3760 // T8: tmp, used for mdp
3761 // Rmethod: callee
3762 // T9: tmp
3763 // is_virtual: false
3764 __ profile_arguments_type(T8, Rmethod, T9, false);
3766 __ jump_from_interpreted(Rmethod, T9);
3767 }
3769 // i have no idea what to do here, now. for future change. FIXME.
3770 void TemplateTable::fast_invokevfinal(int byte_no) {
3771 transition(vtos, vtos);
3772 assert(byte_no == f2_byte, "use this argument");
3773 __ stop("fast_invokevfinal not used on x86");
3774 }
3776 // used registers : T0, T1, T2, T3, T1, A7
3777 // T0 : itable, vtable, entry
3778 // T1 : interface
3779 // T3 : receiver
3780 // T1 : flags, klass
3781 // Rmethod : index, method, this is required by interpreter_entry
3782 void TemplateTable::invokeinterface(int byte_no) {
3783 transition(vtos, vtos);
3784 //this method will use T1-T4 and T0
3785 assert(byte_no == f1_byte, "use this argument");
3786 prepare_invoke(byte_no, T2, Rmethod, T3, T1);
3787 // T2: Interface
3788 // Rmethod: index
3789 // T3: receiver
3790 // T1: flags
3791 Label notMethod;
3792 __ move(AT, (1 << ConstantPoolCacheEntry::is_forced_virtual_shift));
3793 __ andr(AT, T1, AT);
3794 __ beq(AT, R0, notMethod);
3795 __ delayed()->nop();
3797 // Special case of invokeinterface called for virtual method of
3798 // java.lang.Object. See cpCacheOop.cpp for details.
3799 // This code isn't produced by javac, but could be produced by
3800 // another compliant java compiler.
3801 invokevirtual_helper(Rmethod, T3, T1);
3803 __ bind(notMethod);
3804 // Get receiver klass into T1 - also a null check
3805 //__ ld(T1, T3, oopDesc::klass_offset_in_bytes());
3806 //add for compressedoops
3807 //__ restore_locals();
3808 //__ null_check(T3, oopDesc::klass_offset_in_bytes());
3809 __ load_klass(T1, T3);
3810 __ verify_oop(T1);
3812 // profile this call
3813 __ profile_virtual_call(T1, T0, FSR);
3815 // Compute start of first itableOffsetEntry (which is at the end of the vtable)
3816 // TODO: x86 add a new method lookup_interface_method // LEE
3817 const int base = InstanceKlass::vtable_start_offset() * wordSize;
3818 assert(vtableEntry::size() * wordSize == 8, "adjust the scaling in the code below");
3819 __ lw(AT, T1, InstanceKlass::vtable_length_offset() * wordSize);
3820 __ dsll(AT, AT, Address::times_8);
3821 __ dadd(T0, T1, AT);
3822 __ daddi(T0, T0, base);
3823 if (HeapWordsPerLong > 1) {
3824 // Round up to align_object_offset boundary
3825 __ round_to(T0, BytesPerLong);
3826 }
3827 // now T0 is the begin of the itable
3829 Label entry, search, interface_ok;
3831 ///__ jmp(entry);
3832 __ b(entry);
3833 __ delayed()->nop();
3835 __ bind(search);
3836 __ increment(T0, itableOffsetEntry::size() * wordSize);
3838 __ bind(entry);
3840 // Check that the entry is non-null. A null entry means that the receiver
3841 // class doesn't implement the interface, and wasn't the same as the
3842 // receiver class checked when the interface was resolved.
3843 __ ld(AT, T0, itableOffsetEntry::interface_offset_in_bytes());
3844 __ bne(AT, R0, interface_ok);
3845 __ delayed()->nop();
3846 // throw exception
3847 // the call_VM checks for exception, so we should never return here.
3849 //__ pop();//FIXME here,
3850 // pop return address (pushed by prepare_invoke).
3851 // no need now, we just save the value in RA now
3853 __ call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_IncompatibleClassChangeError));
3854 __ should_not_reach_here();
3856 __ bind(interface_ok);
3857 //NOTICE here, no pop as x86 do
3858 //__ lw(AT, T0, itableOffsetEntry::interface_offset_in_bytes());
3859 __ bne(AT, T2, search);
3860 __ delayed()->nop();
3862 // now we get vtable of the interface
3863 __ ld(T0, T0, itableOffsetEntry::offset_offset_in_bytes());
3864 __ daddu(T0, T1, T0);
3865 assert(itableMethodEntry::size() * wordSize == 8, "adjust the scaling in the code below");
3866 __ dsll(AT, Rmethod, Address::times_8);
3867 __ daddu(AT, T0, AT);
3868 // now we get the method
3869 __ ld(Rmethod, AT, 0);
3870 // Rnext: methodOop to call
3871 // T3: receiver
3872 // Check for abstract method error
3873 // Note: This should be done more efficiently via a throw_abstract_method_error
3874 // interpreter entry point and a conditional jump to it in case of a null
3875 // method.
3876 {
3877 Label L;
3878 ///__ testl(ebx, ebx);
3879 ///__ jcc(Assembler::notZero, L);
3880 __ bne(Rmethod, R0, L);
3881 __ delayed()->nop();
3883 // throw exception
3884 // note: must restore interpreter registers to canonical
3885 // state for exception handling to work correctly!
3886 ///__ popl(ebx); // pop return address (pushed by prepare_invoke)
3887 //__ restore_bcp(); // esi must be correct for exception handler
3888 //(was destroyed)
3889 //__ restore_locals(); // make sure locals pointer
3890 //is correct as well (was destroyed)
3891 ///__ call_VM(noreg, CAST_FROM_FN_PTR(address,
3892 //InterpreterRuntime::throw_AbstractMethodError));
3893 __ call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError));
3894 // the call_VM checks for exception, so we should never return here.
3895 __ should_not_reach_here();
3896 __ bind(L);
3897 }
3899 // 2014/11/24 Fu
3900 // T8: tmp, used for mdp
3901 // Rmethod: callee
3902 // T9: tmp
3903 // is_virtual: true
3904 __ profile_arguments_type(T8, Rmethod, T9, true);
3906 __ jump_from_interpreted(Rmethod, T9);
3907 }
3909 void TemplateTable::invokehandle(int byte_no) {
3910 transition(vtos, vtos);
3911 assert(byte_no == f1_byte, "use this argument");
3912 const Register T2_method = Rmethod;
3913 const Register FSR_mtype = FSR;
3914 const Register T3_recv = T3;
3916 if (!EnableInvokeDynamic) {
3917 // rewriter does not generate this bytecode
3918 __ should_not_reach_here();
3919 return;
3920 }
3922 prepare_invoke(byte_no, T2_method, FSR_mtype, T3_recv);
3923 //??__ verify_method_ptr(T2_method);
3924 __ verify_oop(T3_recv);
3925 __ null_check(T3_recv);
3927 // rax: MethodType object (from cpool->resolved_references[f1], if necessary)
3928 // rbx: MH.invokeExact_MT method (from f2)
3930 // Note: rax_mtype is already pushed (if necessary) by prepare_invoke
3932 // FIXME: profile the LambdaForm also
3933 __ profile_final_call(T9);
3935 // 2014/11/24 Fu
3936 // T8: tmp, used for mdp
3937 // T2_method: callee
3938 // T9: tmp
3939 // is_virtual: true
3940 __ profile_arguments_type(T8, T2_method, T9, true);
3942 __ jump_from_interpreted(T2_method, T9);
3943 }
3945 void TemplateTable::invokedynamic(int byte_no) {
3946 transition(vtos, vtos);
3947 assert(byte_no == f1_byte, "use this argument");
3949 if (!EnableInvokeDynamic) {
3950 // We should not encounter this bytecode if !EnableInvokeDynamic.
3951 // The verifier will stop it. However, if we get past the verifier,
3952 // this will stop the thread in a reasonable way, without crashing the JVM.
3953 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
3954 InterpreterRuntime::throw_IncompatibleClassChangeError));
3955 // the call_VM checks for exception, so we should never return here.
3956 __ should_not_reach_here();
3957 return;
3958 }
3960 //const Register Rmethod = T2;
3961 const Register T2_callsite = T2;
3963 prepare_invoke(byte_no, Rmethod, T2_callsite);
3965 // rax: CallSite object (from cpool->resolved_references[f1])
3966 // rbx: MH.linkToCallSite method (from f2)
3968 // Note: rax_callsite is already pushed by prepare_invoke
3969 // %%% should make a type profile for any invokedynamic that takes a ref argument
3970 // profile this call
3971 __ profile_call(T9);
3973 // 2014/11/24 Fu
3974 // T8: tmp, used for mdp
3975 // Rmethod: callee
3976 // T9: tmp
3977 // is_virtual: false
3978 __ profile_arguments_type(T8, Rmethod, T9, false);
3980 __ verify_oop(T2_callsite);
3982 __ jump_from_interpreted(Rmethod, T9);
3983 }
3985 //----------------------------------------------------------------------------------------------------
3986 // Allocation
3987 // T1 : tags & buffer end & thread
3988 // T2 : object end
3989 // T3 : klass
3990 // T1 : object size
3991 // A1 : cpool
3992 // A2 : cp index
3993 // return object in FSR
3994 void TemplateTable::_new() {
3995 transition(vtos, atos);
3996 __ get_2_byte_integer_at_bcp(A2, AT, 1);
3997 __ huswap(A2);
3999 Label slow_case;
4000 Label done;
4001 Label initialize_header;
4002 Label initialize_object; // including clearing the fields
4003 Label allocate_shared;
4005 // get InstanceKlass in T3
4006 __ get_cpool_and_tags(A1, T1);
4007 __ dsll(AT, A2, Address::times_8);
4008 __ dadd(AT, A1, AT);
4009 __ ld(T3, AT, sizeof(ConstantPool));
4011 // make sure the class we're about to instantiate has been resolved.
4012 // Note: slow_case does a pop of stack, which is why we loaded class/pushed above
4013 const int tags_offset = Array<u1>::base_offset_in_bytes();
4014 __ dadd(T1, T1, A2);
4015 __ lb(AT, T1, tags_offset);
4016 //__ addiu(AT, AT, - (int)JVM_CONSTANT_UnresolvedClass);
4017 __ daddiu(AT, AT, - (int)JVM_CONSTANT_Class);
4018 //__ beq(AT, R0, slow_case);
4019 __ bne(AT, R0, slow_case);
4020 __ delayed()->nop();
4022 /*make sure klass is initialized & doesn't have finalizer*/
4024 // make sure klass is fully initialized
4025 __ lhu(T1, T3, in_bytes(InstanceKlass::init_state_offset()));
4026 __ daddiu(AT, T1, - (int)InstanceKlass::fully_initialized);
4027 __ bne(AT, R0, slow_case);
4028 __ delayed()->nop();
4030 // has_finalizer
4031 //__ lw(T1, T3, Klass::access_flags_offset() + sizeof(oopDesc));
4032 //__ move(AT, JVM_ACC_CAN_BE_FASTPATH_ALLOCATED);
4033 //__ andr(AT, T1, AT);
4034 __ lw(T1, T3, in_bytes(Klass::layout_helper_offset()) );
4035 __ andi(AT, T1, Klass::_lh_instance_slow_path_bit);
4036 __ bne(AT, R0, slow_case);
4037 __ delayed()->nop();
4039 // get instance_size in InstanceKlass (already aligned) in T0,
4040 // be sure to preserve this value
4041 //__ lw(T0, T3, Klass::size_helper_offset_in_bytes() + sizeof(oopDesc));
4042 //Klass::_size_helper is renamed Klass::_layout_helper. aoqi
4043 __ lw(T0, T3, in_bytes(Klass::layout_helper_offset()) );
4045 //
4046 // Allocate the instance
4047 // 1) Try to allocate in the TLAB
4048 // 2) if fail and the object is large allocate in the shared Eden
4049 // 3) if the above fails (or is not applicable), go to a slow case
4050 // (creates a new TLAB, etc.)
4052 const bool allow_shared_alloc =
4053 Universe::heap()->supports_inline_contig_alloc() && !CMSIncrementalMode;
4055 if (UseTLAB) {
4056 #ifndef OPT_THREAD
4057 const Register thread = T8;
4058 __ get_thread(thread);
4059 #else
4060 const Register thread = TREG;
4061 #endif
4062 // get tlab_top
4063 __ ld(FSR, thread, in_bytes(JavaThread::tlab_top_offset()));
4064 __ dadd(T2, FSR, T0);
4065 // get tlab_end
4066 __ ld(AT, thread, in_bytes(JavaThread::tlab_end_offset()));
4067 __ slt(AT, AT, T2);
4068 // __ bne(AT, R0, allocate_shared);
4069 __ bne(AT, R0, allow_shared_alloc ? allocate_shared : slow_case);
4070 __ delayed()->nop();
4071 __ sd(T2, thread, in_bytes(JavaThread::tlab_top_offset()));
4073 if (ZeroTLAB) {
4074 // the fields have been already cleared
4075 __ b_far(initialize_header);
4076 } else {
4077 // initialize both the header and fields
4078 __ b_far(initialize_object);
4079 }
4080 __ delayed()->nop();
4081 /*
4083 if (CMSIncrementalMode) {
4084 // No allocation in shared eden.
4085 ///__ jmp(slow_case);
4086 __ b(slow_case);
4087 __ delayed()->nop();
4088 }
4089 */
4090 }
4092 // Allocation in the shared Eden , if allowed
4093 // T0 : instance size in words
4094 if(allow_shared_alloc){
4095 __ bind(allocate_shared);
4096 Label retry;
4097 //Address heap_top(T1, (int)Universe::heap()->top_addr());
4098 Address heap_top(T1);
4099 //__ lui(T1, Assembler::split_high((int)Universe::heap()->top_addr()));
4100 __ li(T1, (long)Universe::heap()->top_addr());
4102 __ ld(FSR, heap_top);
4103 __ bind(retry);
4104 __ dadd(T2, FSR, T0);
4105 //__ lui(AT, Assembler::split_high((int)Universe::heap()->end_addr()));
4106 //__ lw(AT, AT, Assembler::split_low((int)Universe::heap()->end_addr()));
4107 __ li(AT, (long)Universe::heap()->end_addr());
4108 __ ld(AT, AT, 0);
4109 __ slt(AT, AT, T2);
4110 __ bne(AT, R0, slow_case);
4111 __ delayed()->nop();
4113 // Compare FSR with the top addr, and if still equal, store the new
4114 // top addr in ebx at the address of the top addr pointer. Sets ZF if was
4115 // equal, and clears it otherwise. Use lock prefix for atomicity on MPs.
4116 //
4117 // FSR: object begin
4118 // T2: object end
4119 // T0: instance size in words
4121 // if someone beat us on the allocation, try again, otherwise continue
4122 //__ lui(T1, Assembler::split_high((int)Universe::heap()->top_addr()));
4123 __ cmpxchg(T2, heap_top, FSR);
4124 __ beq(AT, R0, retry);
4125 __ delayed()->nop();
4126 }
4128 if (UseTLAB || Universe::heap()->supports_inline_contig_alloc()) {
4129 // The object is initialized before the header. If the object size is
4130 // zero, go directly to the header initialization.
4131 __ bind(initialize_object);
4132 __ li(AT, - sizeof(oopDesc));
4133 __ daddu(T0, T0, AT);
4134 __ beq_far(T0, R0, initialize_header);
4135 __ delayed()->nop();
4138 // T0 must have been multiple of 2
4139 #ifdef ASSERT
4140 // make sure T0 was multiple of 2
4141 Label L;
4142 __ andi(AT, T0, 1);
4143 __ beq(AT, R0, L);
4144 __ delayed()->nop();
4145 __ stop("object size is not multiple of 2 - adjust this code");
4146 __ bind(L);
4147 // edx must be > 0, no extra check needed here
4148 #endif
4150 // initialize remaining object fields: T0 is a multiple of 2
4151 {
4152 Label loop;
4153 __ dadd(T1, FSR, T0);
4154 __ daddi(T1, T1, -oopSize);
4156 __ bind(loop);
4157 __ sd(R0, T1, sizeof(oopDesc) + 0 * oopSize);
4158 // __ sd(R0, T1, sizeof(oopDesc) + 1 * oopSize);
4159 __ bne(T1, FSR, loop); //dont clear header
4160 __ delayed()->daddi(T1, T1, -oopSize);
4161 // actually sizeof(oopDesc)==8, so we can move
4162 // __ addiu(AT, AT, -8) to delay slot, and compare FSR with T1
4163 }
4164 //klass in T3,
4165 // initialize object header only.
4166 __ bind(initialize_header);
4167 if (UseBiasedLocking) {
4168 // __ popl(ecx); // get saved klass back in the register.
4169 // __ movl(ebx, Address(ecx, Klass::prototype_header_offset_in_bytes()
4170 // + klassOopDesc::klass_part_offset_in_bytes()));
4171 __ ld(AT, T3, in_bytes(Klass::prototype_header_offset()));
4172 // __ movl(Address(eax, oopDesc::mark_offset_in_bytes ()), ebx);
4173 __ sd(AT, FSR, oopDesc::mark_offset_in_bytes ());
4174 } else {
4175 __ li(AT, (long)markOopDesc::prototype());
4176 __ sd(AT, FSR, oopDesc::mark_offset_in_bytes());
4177 }
4179 //__ sd(T3, FSR, oopDesc::klass_offset_in_bytes());
4180 __ store_klass_gap(FSR, R0);
4181 __ store_klass(FSR, T3);
4183 {
4184 SkipIfEqual skip_if(_masm, &DTraceAllocProbes, 0);
4185 // Trigger dtrace event for fastpath
4186 __ push(atos);
4187 __ call_VM_leaf(
4188 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc), FSR);
4189 __ pop(atos);
4190 }
4191 __ b(done);
4192 __ delayed()->nop();
4193 }
4194 // slow case
4195 __ bind(slow_case);
4196 call_VM(FSR, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), A1, A2);
4198 // continue
4199 __ bind(done);
4200 __ sync();
4201 }
4203 void TemplateTable::newarray() {
4204 transition(itos, atos);
4205 __ lbu(A1, at_bcp(1));
4206 //type, count
4207 call_VM(FSR, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray), A1, FSR);
4208 __ sync();
4209 }
4211 void TemplateTable::anewarray() {
4212 transition(itos, atos);
4213 __ get_2_byte_integer_at_bcp(A2, AT, 1);
4214 __ huswap(A2);
4215 __ get_constant_pool(A1);
4216 // cp, index, count
4217 call_VM(FSR, CAST_FROM_FN_PTR(address, InterpreterRuntime::anewarray), A1, A2, FSR);
4218 __ sync();
4219 }
4221 void TemplateTable::arraylength() {
4222 transition(atos, itos);
4223 __ null_check(FSR, arrayOopDesc::length_offset_in_bytes());
4224 __ lw(FSR, FSR, arrayOopDesc::length_offset_in_bytes());
4225 }
4227 // i use T2 as ebx, T3 as ecx, T1 as edx
4228 // when invoke gen_subtype_check, super in T3, sub in T2, object in FSR(it's always)
4229 // T2 : sub klass
4230 // T3 : cpool
4231 // T3 : super klass
4232 void TemplateTable::checkcast() {
4233 transition(atos, atos);
4234 Label done, is_null, ok_is_subtype, quicked, resolved;
4235 __ beq(FSR, R0, is_null);
4236 __ delayed()->nop();
4238 // Get cpool & tags index
4239 __ get_cpool_and_tags(T3, T1);
4240 __ get_2_byte_integer_at_bcp(T2, AT, 1);
4241 __ huswap(T2);
4243 // See if bytecode has already been quicked
4244 __ dadd(AT, T1, T2);
4245 __ lb(AT, AT, Array<u1>::base_offset_in_bytes());
4246 __ daddiu(AT, AT, - (int)JVM_CONSTANT_Class);
4247 __ beq(AT, R0, quicked);
4248 __ delayed()->nop();
4250 /* 2012/6/2 Jin: In InterpreterRuntime::quicken_io_cc, lots of new classes may be loaded.
4251 * Then, GC will move the object in V0 to another places in heap.
4252 * Therefore, We should never save such an object in register.
4253 * Instead, we should save it in the stack. It can be modified automatically by the GC thread.
4254 * After GC, the object address in FSR is changed to a new place.
4255 */
4256 __ push(atos);
4257 const Register thread = TREG;
4258 #ifndef OPT_THREAD
4259 __ get_thread(thread);
4260 #endif
4261 call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
4262 __ get_vm_result_2(T3, thread);
4263 __ pop_ptr(FSR);
4264 __ b(resolved);
4265 __ delayed()->nop();
4267 // klass already in cp, get superklass in T3
4268 __ bind(quicked);
4269 __ dsll(AT, T2, Address::times_8);
4270 __ dadd(AT, T3, AT);
4271 __ ld(T3, AT, sizeof(ConstantPool));
4273 __ bind(resolved);
4275 // get subklass in T2
4276 //__ ld(T2, FSR, oopDesc::klass_offset_in_bytes());
4277 //add for compressedoops
4278 __ load_klass(T2, FSR);
4279 // Superklass in T3. Subklass in T2.
4280 __ gen_subtype_check(T3, T2, ok_is_subtype);
4282 // Come here on failure
4283 // object is at FSR
4284 __ jmp(Interpreter::_throw_ClassCastException_entry);
4285 __ delayed()->nop();
4287 // Come here on success
4288 __ bind(ok_is_subtype);
4290 // Collect counts on whether this check-cast sees NULLs a lot or not.
4291 if (ProfileInterpreter) {
4292 __ b(done);
4293 __ delayed()->nop();
4294 __ bind(is_null);
4295 __ profile_null_seen(T3);
4296 } else {
4297 __ bind(is_null);
4298 }
4299 __ bind(done);
4300 }
4302 // i use T3 as cpool, T1 as tags, T2 as index
4303 // object always in FSR, superklass in T3, subklass in T2
4304 void TemplateTable::instanceof() {
4305 transition(atos, itos);
4306 Label done, is_null, ok_is_subtype, quicked, resolved;
4308 __ beq(FSR, R0, is_null);
4309 __ delayed()->nop();
4311 // Get cpool & tags index
4312 __ get_cpool_and_tags(T3, T1);
4313 // get index
4314 __ get_2_byte_integer_at_bcp(T2, AT, 1);
4315 __ hswap(T2);
4317 // See if bytecode has already been quicked
4318 // quicked
4319 __ daddu(AT, T1, T2);
4320 __ lb(AT, AT, Array<u1>::base_offset_in_bytes());
4321 __ daddiu(AT, AT, - (int)JVM_CONSTANT_Class);
4322 __ beq(AT, R0, quicked);
4323 __ delayed()->nop();
4325 // get superklass in T3
4326 //__ move(TSR, FSR);
4327 // sometimes S2 may be changed during the call,
4328 // be careful if u use TSR as a saving place
4329 //__ push(FSR);
4330 __ push(atos);
4331 const Register thread = TREG;
4332 #ifndef OPT_THREAD
4333 __ get_thread(thread);
4334 #endif
4335 call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
4336 __ get_vm_result_2(T3, thread);
4337 //__ lw(FSR, SP, 0);
4338 __ pop_ptr(FSR);
4339 __ b(resolved);
4340 __ delayed()->nop();
4341 //__ move(FSR, TSR);
4343 // get superklass in T3, subklass in T2
4344 __ bind(quicked);
4345 __ dsll(AT, T2, Address::times_8);
4346 __ daddu(AT, T3, AT);
4347 __ ld(T3, AT, sizeof(ConstantPool));
4349 __ bind(resolved);
4350 // get subklass in T2
4351 //__ ld(T2, FSR, oopDesc::klass_offset_in_bytes());
4352 //add for compressedoops
4353 __ load_klass(T2, FSR);
4355 // Superklass in T3. Subklass in T2.
4356 __ gen_subtype_check(T3, T2, ok_is_subtype);
4357 // Come here on failure
4358 __ b(done);
4359 __ delayed(); __ move(FSR, R0);
4361 // Come here on success
4362 __ bind(ok_is_subtype);
4363 __ move(FSR, 1);
4365 // Collect counts on whether this test sees NULLs a lot or not.
4366 if (ProfileInterpreter) {
4367 __ beq(R0, R0, done);
4368 __ nop();
4369 __ bind(is_null);
4370 __ profile_null_seen(T3);
4371 } else {
4372 __ bind(is_null); // same as 'done'
4373 }
4374 __ bind(done);
4375 // FSR = 0: obj == NULL or obj is not an instanceof the specified klass
4376 // FSR = 1: obj != NULL and obj is an instanceof the specified klass
4377 }
4379 //--------------------------------------------------------
4380 //--------------------------------------------
4381 // Breakpoints
4382 void TemplateTable::_breakpoint() {
4384 // Note: We get here even if we are single stepping..
4385 // jbug inists on setting breakpoints at every bytecode
4386 // even if we are in single step mode.
4388 transition(vtos, vtos);
4390 // get the unpatched byte code
4391 ///__ get_method(ecx);
4392 ///__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::get_original_bytecode_at)
4393 //, ecx, esi);
4394 ///__ movl(ebx, eax);
4395 __ get_method(A1);
4396 __ call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::get_original_bytecode_at),
4397 A1, BCP);
4398 __ move(Rnext, V0); // Jin: Rnext will be used in dispatch_only_normal
4400 // post the breakpoint event
4401 ///__ get_method(ecx);
4402 ///__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::_breakpoint), ecx, esi);
4403 __ get_method(A1);
4404 __ call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::_breakpoint), A1, BCP);
4406 // complete the execution of original bytecode
4407 __ dispatch_only_normal(vtos);
4408 }
4410 //----------------------------------------------------------------------------------------------------
4411 // Exceptions
4413 void TemplateTable::athrow() {
4414 transition(atos, vtos);
4415 __ null_check(FSR);
4416 __ jmp(Interpreter::throw_exception_entry());
4417 __ delayed()->nop();
4418 }
4420 //----------------------------------------------------------------------------------------------------
4421 // Synchronization
4422 //
4423 // Note: monitorenter & exit are symmetric routines; which is reflected
4424 // in the assembly code structure as well
4425 //
4426 // Stack layout:
4427 //
4428 // [expressions ] <--- SP = expression stack top
4429 // ..
4430 // [expressions ]
4431 // [monitor entry] <--- monitor block top = expression stack bot
4432 // ..
4433 // [monitor entry]
4434 // [frame data ] <--- monitor block bot
4435 // ...
4436 // [return addr ] <--- FP
4438 // we use T2 as monitor entry pointer, T3 as monitor top pointer, c_rarg0 as free slot pointer
4439 // object always in FSR
4440 void TemplateTable::monitorenter() {
4441 transition(atos, vtos);
4442 // check for NULL object
4443 __ null_check(FSR);
4445 const Address monitor_block_top(FP, frame::interpreter_frame_monitor_block_top_offset
4446 * wordSize);
4447 const int entry_size = (frame::interpreter_frame_monitor_size()* wordSize);
4448 Label allocated;
4450 // initialize entry pointer
4451 __ move(c_rarg0, R0);
4453 // find a free slot in the monitor block (result in edx)
4454 {
4455 Label entry, loop, exit, next;
4456 __ ld(T2, monitor_block_top);
4457 __ b(entry);
4458 __ delayed()->daddi(T3, FP, frame::interpreter_frame_initial_sp_offset * wordSize);
4460 // free slot?
4461 __ bind(loop);
4462 __ ld(AT, T2, BasicObjectLock::obj_offset_in_bytes());
4463 __ bne(AT, R0, next);
4464 __ delayed()->nop();
4465 __ move(c_rarg0, T2);
4467 __ bind(next);
4468 __ beq(FSR, AT, exit);
4469 __ delayed()->nop();
4470 __ daddi(T2, T2, entry_size);
4472 __ bind(entry);
4473 __ bne(T3, T2, loop);
4474 __ delayed()->nop();
4475 __ bind(exit);
4476 }
4478 __ bne(c_rarg0, R0, allocated);
4479 __ delayed()->nop();
4481 // allocate one if there's no free slot
4482 {
4483 Label entry, loop;
4484 // 1. compute new pointers // SP: old expression stack top
4485 __ ld(c_rarg0, monitor_block_top);
4486 __ daddi(SP, SP, - entry_size);
4487 __ daddi(c_rarg0, c_rarg0, - entry_size);
4488 __ sd(c_rarg0, monitor_block_top);
4489 __ b(entry);
4490 __ delayed(); __ move(T3, SP);
4492 // 2. move expression stack contents
4493 __ bind(loop);
4494 __ ld(AT, T3, entry_size);
4495 __ sd(AT, T3, 0);
4496 __ daddi(T3, T3, wordSize);
4497 __ bind(entry);
4498 __ bne(T3, c_rarg0, loop);
4499 __ delayed()->nop();
4500 }
4502 __ bind(allocated);
4503 // Increment bcp to point to the next bytecode,
4504 // so exception handling for async. exceptions work correctly.
4505 // The object has already been poped from the stack, so the
4506 // expression stack looks correct.
4507 __ daddi(BCP, BCP, 1);
4508 __ sd(FSR, c_rarg0, BasicObjectLock::obj_offset_in_bytes());
4509 __ lock_object(c_rarg0);
4510 // check to make sure this monitor doesn't cause stack overflow after locking
4511 __ save_bcp(); // in case of exception
4512 __ generate_stack_overflow_check(0);
4513 // The bcp has already been incremented. Just need to dispatch to next instruction.
4515 __ dispatch_next(vtos);
4516 }
4518 // T2 : top
4519 // c_rarg0 : entry
4520 void TemplateTable::monitorexit() {
4521 transition(atos, vtos);
4523 __ null_check(FSR);
4525 const int entry_size =(frame::interpreter_frame_monitor_size()* wordSize);
4526 Label found;
4528 // find matching slot
4529 {
4530 Label entry, loop;
4531 __ ld(c_rarg0, FP, frame::interpreter_frame_monitor_block_top_offset * wordSize);
4532 __ b(entry);
4533 __ delayed()->daddiu(T2, FP, frame::interpreter_frame_initial_sp_offset * wordSize);
4535 __ bind(loop);
4536 __ ld(AT, c_rarg0, BasicObjectLock::obj_offset_in_bytes());
4537 __ beq(FSR, AT, found);
4538 __ delayed()->nop();
4539 __ daddiu(c_rarg0, c_rarg0, entry_size);
4540 __ bind(entry);
4541 __ bne(T2, c_rarg0, loop);
4542 __ delayed()->nop();
4543 }
4545 // error handling. Unlocking was not block-structured
4546 Label end;
4547 __ call_VM(NOREG, CAST_FROM_FN_PTR(address,
4548 InterpreterRuntime::throw_illegal_monitor_state_exception));
4549 __ should_not_reach_here();
4551 // call run-time routine
4552 // c_rarg0: points to monitor entry
4553 __ bind(found);
4554 __ move(TSR, FSR);
4555 __ unlock_object(c_rarg0);
4556 __ move(FSR, TSR);
4557 __ bind(end);
4558 }
4560 //--------------------------------------------------------------------------------------------------// Wide instructions
4562 void TemplateTable::wide() {
4563 transition(vtos, vtos);
4564 // Note: the esi increment step is part of the individual wide bytecode implementations
4565 __ lbu(Rnext, at_bcp(1));
4566 __ dsll(T9, Rnext, Address::times_8);
4567 __ li(AT, (long)Interpreter::_wentry_point);
4568 __ dadd(AT, T9, AT);
4569 __ ld(T9, AT, 0);
4570 __ jr(T9);
4571 __ delayed()->nop();
4572 }
4574 //--------------------------------------------------------------------------------------------------// Multi arrays
4576 void TemplateTable::multianewarray() {
4577 transition(vtos, atos);
4578 // last dim is on top of stack; we want address of first one:
4579 // first_addr = last_addr + (ndims - 1) * wordSize
4580 __ lbu(A1, at_bcp(3)); // dimension
4581 __ daddi(A1, A1, -1);
4582 __ dsll(A1, A1, Address::times_8);
4583 __ dadd(A1, SP, A1); // now A1 pointer to the count array on the stack
4584 call_VM(FSR, CAST_FROM_FN_PTR(address, InterpreterRuntime::multianewarray), A1);
4585 __ lbu(AT, at_bcp(3));
4586 __ dsll(AT, AT, Address::times_8);
4587 __ dadd(SP, SP, AT);
4588 __ sync();
4589 }
4591 #endif // !CC_INTERP