Tue, 26 Jul 2016 17:06:17 +0800
Add multiply word to GPR instruction (mul) in MIPS assembler.
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 __ sync();
2786 __ lb(FSR, index, 0);
2787 __ sd(FSR, SP, - wordSize);
2789 // Rewrite bytecode to be faster
2790 if (!is_static) {
2791 patch_bytecode(Bytecodes::_fast_bgetfield, T3, T2);
2792 }
2793 __ b(Done);
2794 __ delayed()->daddi(SP, SP, - wordSize);
2796 __ bind(notByte);
2797 __ move(AT, itos);
2798 __ bne(flags, AT, notInt);
2799 __ delayed()->nop();
2801 // itos
2802 __ sync();
2803 __ lw(FSR, index, 0);
2804 __ sd(FSR, SP, - wordSize);
2806 // Rewrite bytecode to be faster
2807 if (!is_static) {
2808 // patch_bytecode(Bytecodes::_fast_igetfield, T3, T2);
2809 patch_bytecode(Bytecodes::_fast_igetfield, T3, T2);
2810 }
2811 __ b(Done);
2812 __ delayed()->daddi(SP, SP, - wordSize);
2814 __ bind(notInt);
2815 __ move(AT, atos);
2816 __ bne(flags, AT, notObj);
2817 __ delayed()->nop();
2819 // atos
2820 //add for compressedoops
2821 __ sync();
2822 __ load_heap_oop(FSR, Address(index, 0));
2823 __ sd(FSR, SP, - wordSize);
2825 if (!is_static) {
2826 //patch_bytecode(Bytecodes::_fast_agetfield, T3, T2);
2827 patch_bytecode(Bytecodes::_fast_agetfield, T3, T2);
2828 }
2829 __ b(Done);
2830 __ delayed()->daddi(SP, SP, - wordSize);
2832 __ bind(notObj);
2833 __ move(AT, ctos);
2834 __ bne(flags, AT, notChar);
2835 __ delayed()->nop();
2837 // ctos
2838 __ sync();
2839 __ lhu(FSR, index, 0);
2840 __ sd(FSR, SP, - wordSize);
2842 if (!is_static) {
2843 patch_bytecode(Bytecodes::_fast_cgetfield, T3, T2);
2844 }
2845 __ b(Done);
2846 __ delayed()->daddi(SP, SP, - wordSize);
2848 __ bind(notChar);
2849 __ move(AT, stos);
2850 __ bne(flags, AT, notShort);
2851 __ delayed()->nop();
2853 // stos
2854 __ sync();
2855 __ lh(FSR, index, 0);
2856 __ sd(FSR, SP, - wordSize);
2858 if (!is_static) {
2859 // patch_bytecode(Bytecodes::_fast_sgetfield, T3, T2);
2860 patch_bytecode(Bytecodes::_fast_sgetfield, T3, T2);
2861 }
2862 __ b(Done);
2863 __ delayed()->daddi(SP, SP, - wordSize);
2865 __ bind(notShort);
2866 __ move(AT, ltos);
2867 __ bne(flags, AT, notLong);
2868 __ delayed()->nop();
2870 // FIXME : the load/store should be atomic, we have no simple method to do this in mips32
2871 // ltos
2872 __ sync();
2873 __ ld(FSR, index, 0 * wordSize);
2874 __ sd(FSR, SP, -2 * wordSize);
2875 __ sd(R0, SP, -1 * wordSize);
2877 // Don't rewrite to _fast_lgetfield for potential volatile case.
2878 __ b(Done);
2879 __ delayed()->daddi(SP, SP, - 2 * wordSize);
2881 __ bind(notLong);
2882 __ move(AT, ftos);
2883 __ bne(flags, AT, notFloat);
2884 __ delayed()->nop();
2886 // ftos
2887 __ sync();
2888 __ lwc1(FSF, index, 0);
2889 __ sdc1(FSF, SP, - wordSize);
2891 if (!is_static) {
2892 patch_bytecode(Bytecodes::_fast_fgetfield, T3, T2);
2893 }
2894 __ b(Done);
2895 __ delayed()->daddi(SP, SP, - wordSize);
2897 __ bind(notFloat);
2898 __ move(AT, dtos);
2899 __ bne(flags, AT, notDouble);
2900 __ delayed()->nop();
2902 // dtos
2903 __ sync();
2904 __ ldc1(FSF, index, 0 * wordSize);
2905 __ sdc1(FSF, SP, - 2 * wordSize);
2906 __ sd(R0, SP, - 1 * wordSize);
2908 if (!is_static) {
2909 patch_bytecode(Bytecodes::_fast_dgetfield, T3, T2);
2910 }
2911 __ b(Done);
2912 __ delayed()->daddi(SP, SP, - 2 * wordSize);
2914 __ bind(notDouble);
2916 __ stop("Bad state");
2918 __ bind(Done);
2919 }
2921 void TemplateTable::getfield(int byte_no) {
2922 getfield_or_static(byte_no, false);
2923 }
2925 void TemplateTable::getstatic(int byte_no) {
2926 getfield_or_static(byte_no, true);
2927 }
2928 /*
2929 // used registers : T1, T2, T3, T1
2930 // T1 : cache & cp entry
2931 // T2 : obj
2932 // T3 : flags & value pointer
2933 // T1 : index
2934 // see ConstantPoolCacheEntry::set_field for more info
2935 void TemplateTable::jvmti_post_field_mod(int byte_no, bool is_static) {
2936 */
2938 // The registers cache and index expected to be set before call.
2939 // The function may destroy various registers, just not the cache and index registers.
2940 void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
2941 ByteSize cp_base_offset = ConstantPoolCache::base_offset();
2943 if (JvmtiExport::can_post_field_modification()) {
2944 // Check to see if a field modification watch has been set before we take
2945 // the time to call into the VM.
2946 Label L1;
2947 assert_different_registers(cache, index, AT);
2949 //__ lui(AT, Assembler::split_high((int)JvmtiExport::get_field_modification_count_addr()));
2950 //__ lw(FSR, AT, Assembler::split_low((int)JvmtiExport::get_field_modification_count_addr()));
2951 __ li(AT, JvmtiExport::get_field_modification_count_addr());
2952 __ lw(FSR, AT, 0);
2953 __ beq(FSR, R0, L1);
2954 __ delayed()->nop();
2956 /* // We rely on the bytecode being resolved and the cpCache entry filled in.
2957 resolve_cache_and_index(byte_no, T1, T1);
2958 */
2959 // The cache and index registers have been already set.
2960 // This allows to eliminate this call but the cache and index
2961 // registers have to be correspondingly used after this line.
2962 // __ get_cache_and_index_at_bcp(eax, edx, 1);
2963 __ get_cache_and_index_at_bcp(T1, T9, 1);
2965 if (is_static) {
2966 __ move(T2, R0);
2967 } else {
2968 // Life is harder. The stack holds the value on top,
2969 // followed by the object.
2970 // We don't know the size of the value, though;
2971 // it could be one or two words
2972 // depending on its type. As a result, we must find
2973 // the type to determine where the object is.
2974 Label two_word, valsize_known;
2975 __ dsll(AT, T1, 4);
2976 __ dadd(AT, T1, AT);
2977 __ lw(T3, AT, in_bytes(cp_base_offset
2978 + ConstantPoolCacheEntry::flags_offset()));
2979 __ move(T2, SP);
2980 __ shr(T3, ConstantPoolCacheEntry::tos_state_shift);
2982 // Make sure we don't need to mask ecx for tos_state_shift
2983 // after the above shift
2984 ConstantPoolCacheEntry::verify_tos_state_shift();
2985 __ move(AT, ltos);
2986 __ beq(T3, AT, two_word);
2987 __ delayed()->nop();
2988 __ move(AT, dtos);
2989 __ beq(T3, AT, two_word);
2990 __ delayed()->nop();
2991 __ b(valsize_known);
2992 //__ delayed()->daddi(T2, T2, wordSize*1);
2993 __ delayed()->daddi(T2, T2,Interpreter::expr_offset_in_bytes(1) );
2995 __ bind(two_word);
2996 // __ daddi(T2, T2, wordSize*2);
2997 __ daddi(T2, T2,Interpreter::expr_offset_in_bytes(2));
2999 __ bind(valsize_known);
3000 // setup object pointer
3001 __ lw(T2, T2, 0*wordSize);
3002 }
3003 // cache entry pointer
3004 __ daddi(T1, T1, in_bytes(cp_base_offset));
3005 __ shl(T1, 4);
3006 __ daddu(T1, T1, T1);
3007 // object (tos)
3008 __ move(T3, SP);
3009 // T2: object pointer set up above (NULL if static)
3010 // T1: cache entry pointer
3011 // T3: jvalue object on the stack
3012 __ call_VM(NOREG, CAST_FROM_FN_PTR(address,
3013 InterpreterRuntime::post_field_modification), T2, T1, T3);
3014 __ get_cache_and_index_at_bcp(cache, index, 1);
3015 __ bind(L1);
3016 }
3017 }
3019 // used registers : T0, T1, T2, T3, T8
3020 // T1 : flags
3021 // T2 : off
3022 // T3 : obj
3023 // T8 : volatile bit
3024 // see ConstantPoolCacheEntry::set_field for more info
3025 void TemplateTable::putfield_or_static(int byte_no, bool is_static) {
3026 transition(vtos, vtos);
3028 const Register cache = T3;
3029 const Register index = T0;
3030 const Register obj = T3;
3031 const Register off = T2;
3032 const Register flags = T1;
3033 const Register bc = T3;
3035 resolve_cache_and_index(byte_no, cache, index, sizeof(u2));
3036 //TODO: LEE
3037 //jvmti_post_field_mod(cache, index, is_static);
3038 load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
3039 // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
3040 // volatile_barrier( );
3042 Label notVolatile, Done;
3043 __ move(AT, 1<<ConstantPoolCacheEntry::is_volatile_shift);
3044 __ andr(T8, flags, AT);
3046 Label notByte, notInt, notShort, notChar, notLong, notFloat, notObj, notDouble;
3048 assert(btos == 0, "change code, btos != 0");
3049 // btos
3050 __ dsrl(flags, flags, ConstantPoolCacheEntry::tos_state_shift);
3051 __ andi(flags, flags, ConstantPoolCacheEntry::tos_state_mask);
3052 __ bne(flags, R0, notByte);
3053 __ delayed()->nop();
3055 __ pop(btos);
3056 if (!is_static) {
3057 pop_and_check_object(obj);
3058 }
3059 __ dadd(AT, obj, off);
3060 __ sb(FSR, AT, 0);
3062 if (!is_static) {
3063 patch_bytecode(Bytecodes::_fast_bputfield, bc, off, true, byte_no);
3064 }
3065 __ b(Done);
3066 __ delayed()->nop();
3068 __ bind(notByte);
3069 // itos
3070 __ move(AT, itos);
3071 __ bne(flags, AT, notInt);
3072 __ delayed()->nop();
3074 __ pop(itos);
3075 if (!is_static) {
3076 pop_and_check_object(obj);
3077 }
3078 __ dadd(AT, obj, off);
3079 __ sw(FSR, AT, 0);
3081 if (!is_static) {
3082 patch_bytecode(Bytecodes::_fast_iputfield, bc, off, true, byte_no);
3083 }
3084 __ b(Done);
3085 __ delayed()->nop();
3086 __ bind(notInt);
3087 // atos
3088 __ move(AT, atos);
3089 __ bne(flags, AT, notObj);
3090 __ delayed()->nop();
3092 __ pop(atos);
3093 if (!is_static) {
3094 pop_and_check_object(obj);
3095 }
3097 __ dadd(AT, obj, off);
3098 //__ sd(FSR, AT, 0);
3099 __ store_heap_oop(Address(AT, 0), FSR);
3100 __ sync();
3101 __ store_check(obj);
3103 if (!is_static) {
3104 patch_bytecode(Bytecodes::_fast_aputfield, bc, off, true, byte_no);
3105 }
3106 __ b(Done);
3107 __ delayed()->nop();
3108 __ bind(notObj);
3109 // ctos
3110 __ move(AT, ctos);
3111 __ bne(flags, AT, notChar);
3112 __ delayed()->nop();
3114 __ pop(ctos);
3115 if (!is_static) {
3116 pop_and_check_object(obj);
3117 }
3118 __ dadd(AT, obj, off);
3119 __ sh(FSR, AT, 0);
3120 if (!is_static) {
3121 patch_bytecode(Bytecodes::_fast_cputfield, bc, off, true, byte_no);
3122 }
3123 __ b(Done);
3124 __ delayed()->nop();
3125 __ bind(notChar);
3126 // stos
3127 __ move(AT, stos);
3128 __ bne(flags, AT, notShort);
3129 __ delayed()->nop();
3131 __ pop(stos);
3132 if (!is_static) {
3133 pop_and_check_object(obj);
3134 }
3135 __ dadd(AT, obj, off);
3136 __ sh(FSR, AT, 0);
3137 if (!is_static) {
3138 patch_bytecode(Bytecodes::_fast_sputfield, bc, off, true, byte_no);
3139 }
3140 __ b(Done);
3141 __ delayed()->nop();
3142 __ bind(notShort);
3143 // ltos
3144 __ move(AT, ltos);
3145 __ bne(flags, AT, notLong);
3146 __ delayed()->nop();
3148 // FIXME: there is no simple method to load/store 64-bit data in a atomic operation
3149 // we just ignore the volatile flag.
3150 //Label notVolatileLong;
3151 //__ beq(T1, R0, notVolatileLong);
3152 //__ delayed()->nop();
3154 //addent = 2 * wordSize;
3155 // no need
3156 //__ lw(FSR, SP, 0);
3157 //__ lw(SSR, SP, 1 * wordSize);
3158 //if (!is_static) {
3159 // __ lw(T3, SP, addent);
3160 // addent += 1 * wordSize;
3161 // __ verify_oop(T3);
3162 //}
3164 //__ daddu(AT, T3, T2);
3166 // Replace with real volatile test
3167 // NOTE : we assume that sdc1&ldc1 operate in 32-bit, this is true for Godson2 even in 64-bit kernel
3168 // last modified by yjl 7/12/2005
3169 //__ ldc1(FSF, SP, 0);
3170 //__ sdc1(FSF, AT, 0);
3171 //volatile_barrier();
3173 // Don't rewrite volatile version
3174 //__ b(notVolatile);
3175 //__ delayed()->addiu(SP, SP, addent);
3177 //__ bind(notVolatileLong);
3179 //__ pop(ltos); // overwrites edx
3180 // __ lw(FSR, SP, 0 * wordSize);
3181 // __ lw(SSR, SP, 1 * wordSize);
3182 // __ daddi(SP, SP, 2*wordSize);
3183 __ pop(ltos);
3184 if (!is_static) {
3185 pop_and_check_object(obj);
3186 }
3187 __ dadd(AT, obj, off);
3188 __ sd(FSR, AT, 0);
3189 if (!is_static) {
3190 patch_bytecode(Bytecodes::_fast_lputfield, bc, off, true, byte_no);
3191 }
3192 __ b(notVolatile);
3193 __ delayed()->nop();
3195 __ bind(notLong);
3196 // ftos
3197 __ move(AT, ftos);
3198 __ bne(flags, AT, notFloat);
3199 __ delayed()->nop();
3201 __ pop(ftos);
3202 if (!is_static) {
3203 pop_and_check_object(obj);
3204 }
3205 __ dadd(AT, obj, off);
3206 __ swc1(FSF, AT, 0);
3207 if (!is_static) {
3208 patch_bytecode(Bytecodes::_fast_fputfield, bc, off, true, byte_no);
3209 }
3210 __ b(Done);
3211 __ delayed()->nop();
3212 __ bind(notFloat);
3213 // dtos
3214 __ move(AT, dtos);
3215 __ bne(flags, AT, notDouble);
3216 __ delayed()->nop();
3218 __ pop(dtos);
3219 if (!is_static) {
3220 pop_and_check_object(obj);
3221 }
3222 __ dadd(AT, obj, off);
3223 __ sdc1(FSF, AT, 0);
3224 if (!is_static) {
3225 patch_bytecode(Bytecodes::_fast_dputfield, bc, off, true, byte_no);
3226 }
3227 __ b(Done);
3228 __ delayed()->nop();
3229 __ bind(notDouble);
3231 __ stop("Bad state");
3233 __ bind(Done);
3235 // Check for volatile store
3236 __ beq(T8, R0, notVolatile);
3237 __ delayed()->nop();
3238 volatile_barrier( );
3239 __ bind(notVolatile);
3240 }
3242 void TemplateTable::putfield(int byte_no) {
3243 putfield_or_static(byte_no, false);
3244 }
3246 void TemplateTable::putstatic(int byte_no) {
3247 putfield_or_static(byte_no, true);
3248 }
3250 // used registers : T1, T2, T3
3251 // T1 : cp_entry
3252 // T2 : obj
3253 // T3 : value pointer
3254 void TemplateTable::jvmti_post_fast_field_mod() {
3255 if (JvmtiExport::can_post_field_modification()) {
3256 // Check to see if a field modification watch has been set before we take
3257 // the time to call into the VM.
3258 Label L2;
3259 //__ lui(AT, Assembler::split_high((intptr_t)JvmtiExport::get_field_modification_count_addr()));
3260 //__ lw(T3, AT, Assembler::split_low((intptr_t)JvmtiExport::get_field_modification_count_addr()));
3261 __ li(AT, JvmtiExport::get_field_modification_count_addr());
3262 __ lw(T3, AT, 0);
3263 __ beq(T3, R0, L2);
3264 __ delayed()->nop();
3265 //__ pop(T2);
3266 __ pop_ptr(T2);
3267 //__ lw(T2, SP, 0);
3268 __ verify_oop(T2);
3269 __ push_ptr(T2);
3270 __ li(AT, -sizeof(jvalue));
3271 __ daddu(SP, SP, AT);
3272 __ move(T3, SP);
3273 //__ push(T2);
3274 //__ move(T2, R0);
3276 switch (bytecode()) { // load values into the jvalue object
3277 case Bytecodes::_fast_bputfield:
3278 __ sb(FSR, SP, 0);
3279 break;
3280 case Bytecodes::_fast_sputfield:
3281 __ sh(FSR, SP, 0);
3282 break;
3283 case Bytecodes::_fast_cputfield:
3284 __ sh(FSR, SP, 0);
3285 break;
3286 case Bytecodes::_fast_iputfield:
3287 __ sw(FSR, SP, 0);
3288 break;
3289 case Bytecodes::_fast_lputfield:
3290 __ sd(FSR, SP, 0);
3291 break;
3292 case Bytecodes::_fast_fputfield:
3293 __ swc1(FSF, SP, 0);
3294 break;
3295 case Bytecodes::_fast_dputfield:
3296 __ sdc1(FSF, SP, 0);
3297 break;
3298 case Bytecodes::_fast_aputfield:
3299 __ sd(FSR, SP, 0);
3300 break;
3301 default: ShouldNotReachHere();
3302 }
3304 //__ pop(T2); // restore copy of object pointer
3306 // Save eax and sometimes edx because call_VM() will clobber them,
3307 // then use them for JVM/DI purposes
3308 __ push(FSR);
3309 if (bytecode() == Bytecodes::_fast_lputfield) __ push(SSR);
3310 // access constant pool cache entry
3311 __ get_cache_entry_pointer_at_bcp(T1, T2, 1);
3312 // no need, verified ahead
3313 __ verify_oop(T2);
3315 // ebx: object pointer copied above
3316 // eax: cache entry pointer
3317 // ecx: jvalue object on the stack
3318 __ call_VM(NOREG, CAST_FROM_FN_PTR(address,
3319 InterpreterRuntime::post_field_modification), T2, T1, T3);
3320 if (bytecode() == Bytecodes::_fast_lputfield) __ pop(SSR); // restore high value
3321 //__ pop(FSR); // restore lower value
3322 //__ daddi(SP, SP, sizeof(jvalue)); // release jvalue object space
3323 __ lw(FSR, SP, 0);
3324 __ daddiu(SP, SP, sizeof(jvalue) + 1 * wordSize);
3325 __ bind(L2);
3326 }
3327 }
3329 // used registers : T2, T3, T1
3330 // T2 : index & off & field address
3331 // T3 : cache & obj
3332 // T1 : flags
3333 void TemplateTable::fast_storefield(TosState state) {
3334 transition(state, vtos);
3336 ByteSize base = ConstantPoolCache::base_offset();
3338 jvmti_post_fast_field_mod();
3340 // access constant pool cache
3341 __ get_cache_and_index_at_bcp(T3, T2, 1);
3343 // test for volatile with edx but edx is tos register for lputfield.
3344 __ dsll(AT, T2, Address::times_8);
3345 __ dadd(AT, T3, AT);
3346 __ ld(T1, AT, in_bytes(base + ConstantPoolCacheEntry::flags_offset()));
3348 // replace index with field offset from cache entry
3349 __ ld(T2, AT, in_bytes(base + ConstantPoolCacheEntry::f2_offset()));
3351 // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
3352 // volatile_barrier( );
3354 Label notVolatile, Done;
3355 // Check for volatile store
3356 __ move(AT, 1<<ConstantPoolCacheEntry::is_volatile_shift);
3357 __ andr(AT, T1, AT);
3358 __ beq(AT, R0, notVolatile);
3359 __ delayed()->nop();
3362 // Get object from stack
3363 // NOTE : the value in FSR/FSF now
3364 // __ pop(T3);
3365 // __ verify_oop(T3);
3366 pop_and_check_object(T3);
3367 // field addresses
3368 __ dadd(T2, T3, T2);
3370 // access field
3371 switch (bytecode()) {
3372 case Bytecodes::_fast_bputfield:
3373 __ sb(FSR, T2, 0);
3374 break;
3375 case Bytecodes::_fast_sputfield: // fall through
3376 case Bytecodes::_fast_cputfield:
3377 __ sh(FSR, T2, 0);
3378 break;
3379 case Bytecodes::_fast_iputfield:
3380 __ sw(FSR, T2, 0);
3381 break;
3382 case Bytecodes::_fast_lputfield:
3383 __ sd(FSR, T2, 0 * wordSize);
3384 break;
3385 case Bytecodes::_fast_fputfield:
3386 __ swc1(FSF, T2, 0);
3387 break;
3388 case Bytecodes::_fast_dputfield:
3389 __ sdc1(FSF, T2, 0 * wordSize);
3390 break;
3391 case Bytecodes::_fast_aputfield:
3392 __ store_heap_oop(Address(T2, 0), FSR);
3393 __ sync();
3394 __ store_check(T3);
3395 break;
3396 default:
3397 ShouldNotReachHere();
3398 }
3400 Label done;
3401 volatile_barrier( );
3402 __ b(done);
3403 __ delayed()->nop();
3405 // Same code as above, but don't need edx to test for volatile.
3406 __ bind(notVolatile);
3408 // Get object from stack
3409 // __ pop(T3);
3410 // __ verify_oop(T3);
3411 pop_and_check_object(T3);
3412 //get the field address
3413 __ dadd(T2, T3, T2);
3415 // access field
3416 switch (bytecode()) {
3417 case Bytecodes::_fast_bputfield:
3418 __ sb(FSR, T2, 0);
3419 break;
3420 case Bytecodes::_fast_sputfield: // fall through
3421 case Bytecodes::_fast_cputfield:
3422 __ sh(FSR, T2, 0);
3423 break;
3424 case Bytecodes::_fast_iputfield:
3425 __ sw(FSR, T2, 0);
3426 break;
3427 case Bytecodes::_fast_lputfield:
3428 __ sd(FSR, T2, 0 * wordSize);
3429 break;
3430 case Bytecodes::_fast_fputfield:
3431 __ swc1(FSF, T2, 0);
3432 break;
3433 case Bytecodes::_fast_dputfield:
3434 __ sdc1(FSF, T2, 0 * wordSize);
3435 break;
3436 case Bytecodes::_fast_aputfield:
3437 //add for compressedoops
3438 __ store_heap_oop(Address(T2, 0), FSR);
3439 __ sync();
3440 __ store_check(T3);
3441 break;
3442 default:
3443 ShouldNotReachHere();
3444 }
3445 __ bind(done);
3446 }
3448 // used registers : T2, T3, T1
3449 // T3 : cp_entry & cache
3450 // T2 : index & offset
3451 void TemplateTable::fast_accessfield(TosState state) {
3452 transition(atos, state);
3454 // do the JVMTI work here to avoid disturbing the register state below
3455 if (JvmtiExport::can_post_field_access()) {
3456 // Check to see if a field access watch has been set before we take
3457 // the time to call into the VM.
3458 Label L1;
3459 __ li(AT, (intptr_t)JvmtiExport::get_field_access_count_addr());
3460 __ lw(T3, AT, 0);
3461 __ beq(T3, R0, L1);
3462 __ delayed()->nop();
3463 // access constant pool cache entry
3464 __ get_cache_entry_pointer_at_bcp(T3, T1, 1);
3465 __ move(TSR, FSR);
3466 __ verify_oop(FSR);
3467 // FSR: object pointer copied above
3468 // T3: cache entry pointer
3469 __ call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access),
3470 FSR, T3);
3471 __ move(FSR, TSR);
3472 __ bind(L1);
3473 }
3475 // access constant pool cache
3476 __ get_cache_and_index_at_bcp(T3, T2, 1);
3477 // replace index with field offset from cache entry
3478 __ dsll(AT, T2, Address::times_8);
3479 //__ dsll(AT, T2, 4);
3480 __ dadd(AT, T3, AT);
3481 __ ld(T2, AT, in_bytes(ConstantPoolCache::base_offset()
3482 + ConstantPoolCacheEntry::f2_offset()));
3484 // eax: object
3485 __ verify_oop(FSR);
3486 // __ null_check(FSR, 0);
3487 __ null_check(FSR);
3488 // field addresses
3489 __ dadd(FSR, FSR, T2);
3491 // access field
3492 switch (bytecode()) {
3493 case Bytecodes::_fast_bgetfield:
3494 __ lb(FSR, FSR, 0);
3495 break;
3496 case Bytecodes::_fast_sgetfield:
3497 __ lh(FSR, FSR, 0);
3498 break;
3499 case Bytecodes::_fast_cgetfield:
3500 __ lhu(FSR, FSR, 0);
3501 break;
3502 case Bytecodes::_fast_igetfield:
3503 __ lw(FSR, FSR, 0);
3504 break;
3505 case Bytecodes::_fast_lgetfield:
3506 __ stop("should not be rewritten");
3507 break;
3508 case Bytecodes::_fast_fgetfield:
3509 __ lwc1(FSF, FSR, 0);
3510 break;
3511 case Bytecodes::_fast_dgetfield:
3512 __ ldc1(FSF, FSR, 0);
3513 break;
3514 case Bytecodes::_fast_agetfield:
3515 //add for compressedoops
3516 __ load_heap_oop(FSR, Address(FSR, 0));
3517 __ verify_oop(FSR);
3518 break;
3519 default:
3520 ShouldNotReachHere();
3521 }
3523 // Doug Lea believes this is not needed with current Sparcs(TSO) and Intel(PSO)
3524 // volatile_barrier( );
3525 }
3527 // generator for _fast_iaccess_0, _fast_aaccess_0, _fast_faccess_0
3528 // used registers : T1, T2, T3, T1
3529 // T1 : obj & field address
3530 // T2 : off
3531 // T3 : cache
3532 // T1 : index
3533 void TemplateTable::fast_xaccess(TosState state) {
3534 transition(vtos, state);
3535 // get receiver
3536 __ ld(T1, aaddress(0));
3537 // access constant pool cache
3538 __ get_cache_and_index_at_bcp(T3, T2, 2);
3539 __ dsll(AT, T2, Address::times_8);
3540 __ dadd(AT, T3, AT);
3541 __ ld(T2, AT, in_bytes(ConstantPoolCache::base_offset()
3542 + ConstantPoolCacheEntry::f2_offset()));
3544 // make sure exception is reported in correct bcp range (getfield is next instruction)
3545 __ daddi(BCP, BCP, 1);
3546 // __ null_check(T1, 0);
3547 __ null_check(T1);
3548 __ dadd(T1, T1, T2);
3550 if (state == itos) {
3551 __ lw(FSR, T1, 0);
3552 } else if (state == atos) {
3553 //__ ld(FSR, T1, 0);
3554 __ load_heap_oop(FSR, Address(T1, 0));
3555 __ verify_oop(FSR);
3556 } else if (state == ftos) {
3557 __ lwc1(FSF, T1, 0);
3558 } else {
3559 ShouldNotReachHere();
3560 }
3561 __ daddi(BCP, BCP, -1);
3562 }
3564 //---------------------------------------------------
3565 //-------------------------------------------------
3566 // Calls
3568 void TemplateTable::count_calls(Register method, Register temp) {
3569 // implemented elsewhere
3570 ShouldNotReachHere();
3571 }
3573 // method, index, recv, flags: T1, T2, T3, T1
3574 // byte_no = 2 for _invokevirtual, 1 else
3575 // T0 : return address
3576 // get the method & index of the invoke, and push the return address of
3577 // the invoke(first word in the frame)
3578 // this address is where the return code jmp to.
3579 // NOTE : this method will set T3&T1 as recv&flags
3580 void TemplateTable::prepare_invoke(int byte_no,
3581 Register method, //linked method (or i-klass)
3582 Register index, //itable index, MethodType ,etc.
3583 Register recv, // if caller wants to see it
3584 Register flags // if caller wants to test it
3585 ) {
3586 // determine flags
3587 const Bytecodes::Code code = bytecode();
3588 const bool is_invokeinterface = code == Bytecodes::_invokeinterface;
3589 const bool is_invokedynamic = code == Bytecodes::_invokedynamic;
3590 const bool is_invokehandle = code == Bytecodes::_invokehandle;
3591 const bool is_invokevirtual = code == Bytecodes::_invokevirtual;
3592 const bool is_invokespecial = code == Bytecodes::_invokespecial;
3593 const bool load_receiver = (recv != noreg);
3594 const bool save_flags = (flags != noreg);
3595 assert(load_receiver == (code != Bytecodes::_invokestatic && code != Bytecodes::_invokedynamic),"");
3596 assert(save_flags == (is_invokeinterface || is_invokevirtual), "need flags for vfinal");
3597 assert(flags == noreg || flags == T1, "error flags reg.");
3598 assert(recv == noreg || recv == T3, "error recv reg.");
3599 // setup registers & access constant pool cache
3600 if(recv == noreg) recv = T3;
3601 if(flags == noreg) flags = T1;
3603 assert_different_registers(method, index, recv, flags);
3605 // save 'interpreter return address'
3606 __ save_bcp();
3608 load_invoke_cp_cache_entry(byte_no, method, index, flags, is_invokevirtual, false, is_invokedynamic);
3609 if (is_invokedynamic || is_invokehandle) {
3610 Label L_no_push;
3611 __ move(AT, (1 << ConstantPoolCacheEntry::has_appendix_shift));
3612 __ andr(AT, AT, flags);
3613 __ beq(AT, R0, L_no_push);
3614 __ delayed()->nop();
3615 // Push the appendix as a trailing parameter.
3616 // This must be done before we get the receiver,
3617 // since the parameter_size includes it.
3618 Register tmp = SSR;
3619 __ push(tmp);
3620 __ move(tmp, index);
3621 assert(ConstantPoolCacheEntry::_indy_resolved_references_appendix_offset == 0, "appendix expected at index+0");
3622 __ load_resolved_reference_at_index(index, tmp);
3623 __ pop(tmp);
3624 __ push(index); // push appendix (MethodType, CallSite, etc.)
3625 __ bind(L_no_push);
3627 }
3629 // load receiver if needed (after appendix is pushed so parameter size is correct)
3630 // Note: no return address pushed yet
3631 if (load_receiver) {
3632 __ move(AT, ConstantPoolCacheEntry::parameter_size_mask);
3633 __ andr(recv, flags, AT);
3634 // 2014/07/31 Fu: Since we won't push RA on stack, no_return_pc_pushed_yet should be 0.
3635 const int no_return_pc_pushed_yet = 0; // argument slot correction before we push return address
3636 const int receiver_is_at_end = -1; // back off one slot to get receiver
3637 Address recv_addr = __ argument_address(recv, no_return_pc_pushed_yet + receiver_is_at_end);
3639 __ ld(recv, recv_addr);
3640 __ verify_oop(recv);
3641 }
3642 if(save_flags) {
3643 //__ movl(r13, flags);
3644 __ move(BCP, flags);
3645 }
3646 // compute return type
3647 __ dsrl(flags, flags, ConstantPoolCacheEntry::tos_state_shift);
3648 __ andi(flags, flags, 0xf);
3650 // Make sure we don't need to mask flags for tos_state_shift after the above shift
3651 ConstantPoolCacheEntry::verify_tos_state_shift();
3652 // load return address
3653 {
3654 const address table = (address) Interpreter::invoke_return_entry_table_for(code);
3655 __ li(AT, (long)table);
3656 __ dsll(flags, flags, LogBytesPerWord);
3657 __ dadd(AT, AT, flags);
3658 __ ld(RA, AT, 0);
3659 }
3661 if (save_flags) {
3662 __ move(flags, BCP);
3663 __ restore_bcp();
3664 }
3665 }
3667 // used registers : T0, T3, T1, T2
3668 // T3 : recv, this two register using convention is by prepare_invoke
3669 // T1 : flags, klass
3670 // Rmethod : method, index must be Rmethod
3671 void TemplateTable::invokevirtual_helper(Register index, Register recv,
3672 Register flags) {
3674 assert_different_registers(index, recv, flags, T2);
3676 // Test for an invoke of a final method
3677 Label notFinal;
3678 __ move(AT, (1 << ConstantPoolCacheEntry::is_vfinal_shift));
3679 __ andr(AT, flags, AT);
3680 __ beq(AT, R0, notFinal);
3681 __ delayed()->nop();
3683 Register method = index; // method must be Rmethod
3684 assert(method == Rmethod, "methodOop must be Rmethod for interpreter calling convention");
3686 // do the call - the index is actually the method to call
3687 // the index is indeed methodOop, for this is vfinal,
3688 // see ConstantPoolCacheEntry::set_method for more info
3690 __ verify_oop(method);
3692 // It's final, need a null check here!
3693 __ null_check(recv);
3695 // profile this call
3696 __ profile_final_call(T2);
3698 // 2014/11/24 Fu
3699 // T2: tmp, used for mdp
3700 // method: callee
3701 // T9: tmp
3702 // is_virtual: true
3703 __ profile_arguments_type(T2, method, T9, true);
3705 // __ move(T0, recv);
3706 __ jump_from_interpreted(method, T2);
3708 __ bind(notFinal);
3710 // get receiver klass
3711 __ null_check(recv, oopDesc::klass_offset_in_bytes());
3712 // Keep recv in ecx for callee expects it there
3713 __ load_klass(T2, recv);
3714 __ verify_oop(T2);
3715 // profile this call
3716 __ profile_virtual_call(T2, T0, T1);
3718 // get target methodOop & entry point
3719 const int base = InstanceKlass::vtable_start_offset() * wordSize;
3720 assert(vtableEntry::size() * wordSize == 8, "adjust the scaling in the code below");
3721 __ dsll(AT, index, Address::times_8);
3722 __ dadd(AT, T2, AT);
3723 //this is a ualign read
3724 __ ld(method, AT, base + vtableEntry::method_offset_in_bytes());
3725 __ jump_from_interpreted(method, T2);
3727 }
3729 void TemplateTable::invokevirtual(int byte_no) {
3730 transition(vtos, vtos);
3731 assert(byte_no == f2_byte, "use this argument");
3732 prepare_invoke(byte_no, Rmethod, NOREG, T3, T1);
3733 // now recv & flags in T3, T1
3734 invokevirtual_helper(Rmethod, T3, T1);
3735 }
3737 // T9 : entry
3738 // Rmethod : method
3739 void TemplateTable::invokespecial(int byte_no) {
3740 transition(vtos, vtos);
3741 assert(byte_no == f1_byte, "use this argument");
3742 prepare_invoke(byte_no, Rmethod, NOREG, T3);
3743 // now recv & flags in T3, T1
3744 __ verify_oop(T3);
3745 __ null_check(T3);
3746 __ profile_call(T9);
3748 // 2014/11/24 Fu
3749 // T8: tmp, used for mdp
3750 // Rmethod: callee
3751 // T9: tmp
3752 // is_virtual: false
3753 __ profile_arguments_type(T8, Rmethod, T9, false);
3755 __ jump_from_interpreted(Rmethod, T9);
3756 __ move(T0, T3);//aoqi ?
3757 }
3759 void TemplateTable::invokestatic(int byte_no) {
3760 transition(vtos, vtos);
3761 assert(byte_no == f1_byte, "use this argument");
3762 prepare_invoke(byte_no, Rmethod, NOREG);
3763 __ verify_oop(Rmethod);
3765 __ profile_call(T9);
3767 // 2014/11/24 Fu
3768 // T8: tmp, used for mdp
3769 // Rmethod: callee
3770 // T9: tmp
3771 // is_virtual: false
3772 __ profile_arguments_type(T8, Rmethod, T9, false);
3774 __ jump_from_interpreted(Rmethod, T9);
3775 }
3777 // i have no idea what to do here, now. for future change. FIXME.
3778 void TemplateTable::fast_invokevfinal(int byte_no) {
3779 transition(vtos, vtos);
3780 assert(byte_no == f2_byte, "use this argument");
3781 __ stop("fast_invokevfinal not used on x86");
3782 }
3784 // used registers : T0, T1, T2, T3, T1, A7
3785 // T0 : itable, vtable, entry
3786 // T1 : interface
3787 // T3 : receiver
3788 // T1 : flags, klass
3789 // Rmethod : index, method, this is required by interpreter_entry
3790 void TemplateTable::invokeinterface(int byte_no) {
3791 transition(vtos, vtos);
3792 //this method will use T1-T4 and T0
3793 assert(byte_no == f1_byte, "use this argument");
3794 prepare_invoke(byte_no, T2, Rmethod, T3, T1);
3795 // T2: Interface
3796 // Rmethod: index
3797 // T3: receiver
3798 // T1: flags
3799 Label notMethod;
3800 __ move(AT, (1 << ConstantPoolCacheEntry::is_forced_virtual_shift));
3801 __ andr(AT, T1, AT);
3802 __ beq(AT, R0, notMethod);
3803 __ delayed()->nop();
3805 // Special case of invokeinterface called for virtual method of
3806 // java.lang.Object. See cpCacheOop.cpp for details.
3807 // This code isn't produced by javac, but could be produced by
3808 // another compliant java compiler.
3809 invokevirtual_helper(Rmethod, T3, T1);
3811 __ bind(notMethod);
3812 // Get receiver klass into T1 - also a null check
3813 //__ ld(T1, T3, oopDesc::klass_offset_in_bytes());
3814 //add for compressedoops
3815 //__ restore_locals();
3816 //__ null_check(T3, oopDesc::klass_offset_in_bytes());
3817 __ load_klass(T1, T3);
3818 __ verify_oop(T1);
3820 // profile this call
3821 __ profile_virtual_call(T1, T0, FSR);
3823 // Compute start of first itableOffsetEntry (which is at the end of the vtable)
3824 // TODO: x86 add a new method lookup_interface_method // LEE
3825 const int base = InstanceKlass::vtable_start_offset() * wordSize;
3826 assert(vtableEntry::size() * wordSize == 8, "adjust the scaling in the code below");
3827 __ lw(AT, T1, InstanceKlass::vtable_length_offset() * wordSize);
3828 __ dsll(AT, AT, Address::times_8);
3829 __ dadd(T0, T1, AT);
3830 __ daddi(T0, T0, base);
3831 if (HeapWordsPerLong > 1) {
3832 // Round up to align_object_offset boundary
3833 __ round_to(T0, BytesPerLong);
3834 }
3835 // now T0 is the begin of the itable
3837 Label entry, search, interface_ok;
3839 ///__ jmp(entry);
3840 __ b(entry);
3841 __ delayed()->nop();
3843 __ bind(search);
3844 __ increment(T0, itableOffsetEntry::size() * wordSize);
3846 __ bind(entry);
3848 // Check that the entry is non-null. A null entry means that the receiver
3849 // class doesn't implement the interface, and wasn't the same as the
3850 // receiver class checked when the interface was resolved.
3851 __ ld(AT, T0, itableOffsetEntry::interface_offset_in_bytes());
3852 __ bne(AT, R0, interface_ok);
3853 __ delayed()->nop();
3854 // throw exception
3855 // the call_VM checks for exception, so we should never return here.
3857 //__ pop();//FIXME here,
3858 // pop return address (pushed by prepare_invoke).
3859 // no need now, we just save the value in RA now
3861 __ call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_IncompatibleClassChangeError));
3862 __ should_not_reach_here();
3864 __ bind(interface_ok);
3865 //NOTICE here, no pop as x86 do
3866 //__ lw(AT, T0, itableOffsetEntry::interface_offset_in_bytes());
3867 __ bne(AT, T2, search);
3868 __ delayed()->nop();
3870 // now we get vtable of the interface
3871 __ ld(T0, T0, itableOffsetEntry::offset_offset_in_bytes());
3872 __ daddu(T0, T1, T0);
3873 assert(itableMethodEntry::size() * wordSize == 8, "adjust the scaling in the code below");
3874 __ dsll(AT, Rmethod, Address::times_8);
3875 __ daddu(AT, T0, AT);
3876 // now we get the method
3877 __ ld(Rmethod, AT, 0);
3878 // Rnext: methodOop to call
3879 // T3: receiver
3880 // Check for abstract method error
3881 // Note: This should be done more efficiently via a throw_abstract_method_error
3882 // interpreter entry point and a conditional jump to it in case of a null
3883 // method.
3884 {
3885 Label L;
3886 ///__ testl(ebx, ebx);
3887 ///__ jcc(Assembler::notZero, L);
3888 __ bne(Rmethod, R0, L);
3889 __ delayed()->nop();
3891 // throw exception
3892 // note: must restore interpreter registers to canonical
3893 // state for exception handling to work correctly!
3894 ///__ popl(ebx); // pop return address (pushed by prepare_invoke)
3895 //__ restore_bcp(); // esi must be correct for exception handler
3896 //(was destroyed)
3897 //__ restore_locals(); // make sure locals pointer
3898 //is correct as well (was destroyed)
3899 ///__ call_VM(noreg, CAST_FROM_FN_PTR(address,
3900 //InterpreterRuntime::throw_AbstractMethodError));
3901 __ call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError));
3902 // the call_VM checks for exception, so we should never return here.
3903 __ should_not_reach_here();
3904 __ bind(L);
3905 }
3907 // 2014/11/24 Fu
3908 // T8: tmp, used for mdp
3909 // Rmethod: callee
3910 // T9: tmp
3911 // is_virtual: true
3912 __ profile_arguments_type(T8, Rmethod, T9, true);
3914 __ jump_from_interpreted(Rmethod, T9);
3915 }
3917 void TemplateTable::invokehandle(int byte_no) {
3918 transition(vtos, vtos);
3919 assert(byte_no == f1_byte, "use this argument");
3920 const Register T2_method = Rmethod;
3921 const Register FSR_mtype = FSR;
3922 const Register T3_recv = T3;
3924 if (!EnableInvokeDynamic) {
3925 // rewriter does not generate this bytecode
3926 __ should_not_reach_here();
3927 return;
3928 }
3930 prepare_invoke(byte_no, T2_method, FSR_mtype, T3_recv);
3931 //??__ verify_method_ptr(T2_method);
3932 __ verify_oop(T3_recv);
3933 __ null_check(T3_recv);
3935 // rax: MethodType object (from cpool->resolved_references[f1], if necessary)
3936 // rbx: MH.invokeExact_MT method (from f2)
3938 // Note: rax_mtype is already pushed (if necessary) by prepare_invoke
3940 // FIXME: profile the LambdaForm also
3941 __ profile_final_call(T9);
3943 // 2014/11/24 Fu
3944 // T8: tmp, used for mdp
3945 // T2_method: callee
3946 // T9: tmp
3947 // is_virtual: true
3948 __ profile_arguments_type(T8, T2_method, T9, true);
3950 __ jump_from_interpreted(T2_method, T9);
3951 }
3953 void TemplateTable::invokedynamic(int byte_no) {
3954 transition(vtos, vtos);
3955 assert(byte_no == f1_byte, "use this argument");
3957 if (!EnableInvokeDynamic) {
3958 // We should not encounter this bytecode if !EnableInvokeDynamic.
3959 // The verifier will stop it. However, if we get past the verifier,
3960 // this will stop the thread in a reasonable way, without crashing the JVM.
3961 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
3962 InterpreterRuntime::throw_IncompatibleClassChangeError));
3963 // the call_VM checks for exception, so we should never return here.
3964 __ should_not_reach_here();
3965 return;
3966 }
3968 //const Register Rmethod = T2;
3969 const Register T2_callsite = T2;
3971 prepare_invoke(byte_no, Rmethod, T2_callsite);
3973 // rax: CallSite object (from cpool->resolved_references[f1])
3974 // rbx: MH.linkToCallSite method (from f2)
3976 // Note: rax_callsite is already pushed by prepare_invoke
3977 // %%% should make a type profile for any invokedynamic that takes a ref argument
3978 // profile this call
3979 __ profile_call(T9);
3981 // 2014/11/24 Fu
3982 // T8: tmp, used for mdp
3983 // Rmethod: callee
3984 // T9: tmp
3985 // is_virtual: false
3986 __ profile_arguments_type(T8, Rmethod, T9, false);
3988 __ verify_oop(T2_callsite);
3990 __ jump_from_interpreted(Rmethod, T9);
3991 }
3993 //----------------------------------------------------------------------------------------------------
3994 // Allocation
3995 // T1 : tags & buffer end & thread
3996 // T2 : object end
3997 // T3 : klass
3998 // T1 : object size
3999 // A1 : cpool
4000 // A2 : cp index
4001 // return object in FSR
4002 void TemplateTable::_new() {
4003 transition(vtos, atos);
4004 __ get_2_byte_integer_at_bcp(A2, AT, 1);
4005 __ huswap(A2);
4007 Label slow_case;
4008 Label done;
4009 Label initialize_header;
4010 Label initialize_object; // including clearing the fields
4011 Label allocate_shared;
4013 // get InstanceKlass in T3
4014 __ get_cpool_and_tags(A1, T1);
4015 __ dsll(AT, A2, Address::times_8);
4016 __ dadd(AT, A1, AT);
4017 __ ld(T3, AT, sizeof(ConstantPool));
4019 // make sure the class we're about to instantiate has been resolved.
4020 // Note: slow_case does a pop of stack, which is why we loaded class/pushed above
4021 const int tags_offset = Array<u1>::base_offset_in_bytes();
4022 __ dadd(T1, T1, A2);
4023 __ lb(AT, T1, tags_offset);
4024 //__ addiu(AT, AT, - (int)JVM_CONSTANT_UnresolvedClass);
4025 __ daddiu(AT, AT, - (int)JVM_CONSTANT_Class);
4026 //__ beq(AT, R0, slow_case);
4027 __ bne(AT, R0, slow_case);
4028 __ delayed()->nop();
4030 /*make sure klass is initialized & doesn't have finalizer*/
4032 // make sure klass is fully initialized
4033 __ lhu(T1, T3, in_bytes(InstanceKlass::init_state_offset()));
4034 __ daddiu(AT, T1, - (int)InstanceKlass::fully_initialized);
4035 __ bne(AT, R0, slow_case);
4036 __ delayed()->nop();
4038 // has_finalizer
4039 //__ lw(T1, T3, Klass::access_flags_offset() + sizeof(oopDesc));
4040 //__ move(AT, JVM_ACC_CAN_BE_FASTPATH_ALLOCATED);
4041 //__ andr(AT, T1, AT);
4042 __ lw(T1, T3, in_bytes(Klass::layout_helper_offset()) );
4043 __ andi(AT, T1, Klass::_lh_instance_slow_path_bit);
4044 __ bne(AT, R0, slow_case);
4045 __ delayed()->nop();
4047 // get instance_size in InstanceKlass (already aligned) in T0,
4048 // be sure to preserve this value
4049 //__ lw(T0, T3, Klass::size_helper_offset_in_bytes() + sizeof(oopDesc));
4050 //Klass::_size_helper is renamed Klass::_layout_helper. aoqi
4051 __ lw(T0, T3, in_bytes(Klass::layout_helper_offset()) );
4053 //
4054 // Allocate the instance
4055 // 1) Try to allocate in the TLAB
4056 // 2) if fail and the object is large allocate in the shared Eden
4057 // 3) if the above fails (or is not applicable), go to a slow case
4058 // (creates a new TLAB, etc.)
4060 const bool allow_shared_alloc =
4061 Universe::heap()->supports_inline_contig_alloc() && !CMSIncrementalMode;
4063 if (UseTLAB) {
4064 #ifndef OPT_THREAD
4065 const Register thread = T8;
4066 __ get_thread(thread);
4067 #else
4068 const Register thread = TREG;
4069 #endif
4070 // get tlab_top
4071 __ ld(FSR, thread, in_bytes(JavaThread::tlab_top_offset()));
4072 __ dadd(T2, FSR, T0);
4073 // get tlab_end
4074 __ ld(AT, thread, in_bytes(JavaThread::tlab_end_offset()));
4075 __ slt(AT, AT, T2);
4076 // __ bne(AT, R0, allocate_shared);
4077 __ bne(AT, R0, allow_shared_alloc ? allocate_shared : slow_case);
4078 __ delayed()->nop();
4079 __ sd(T2, thread, in_bytes(JavaThread::tlab_top_offset()));
4081 if (ZeroTLAB) {
4082 // the fields have been already cleared
4083 __ b_far(initialize_header);
4084 } else {
4085 // initialize both the header and fields
4086 __ b_far(initialize_object);
4087 }
4088 __ delayed()->nop();
4089 /*
4091 if (CMSIncrementalMode) {
4092 // No allocation in shared eden.
4093 ///__ jmp(slow_case);
4094 __ b(slow_case);
4095 __ delayed()->nop();
4096 }
4097 */
4098 }
4100 // Allocation in the shared Eden , if allowed
4101 // T0 : instance size in words
4102 if(allow_shared_alloc){
4103 __ bind(allocate_shared);
4104 Label retry;
4105 //Address heap_top(T1, (int)Universe::heap()->top_addr());
4106 Address heap_top(T1);
4107 //__ lui(T1, Assembler::split_high((int)Universe::heap()->top_addr()));
4108 __ li(T1, (long)Universe::heap()->top_addr());
4110 __ ld(FSR, heap_top);
4111 __ bind(retry);
4112 __ dadd(T2, FSR, T0);
4113 //__ lui(AT, Assembler::split_high((int)Universe::heap()->end_addr()));
4114 //__ lw(AT, AT, Assembler::split_low((int)Universe::heap()->end_addr()));
4115 __ li(AT, (long)Universe::heap()->end_addr());
4116 __ ld(AT, AT, 0);
4117 __ slt(AT, AT, T2);
4118 __ bne(AT, R0, slow_case);
4119 __ delayed()->nop();
4121 // Compare FSR with the top addr, and if still equal, store the new
4122 // top addr in ebx at the address of the top addr pointer. Sets ZF if was
4123 // equal, and clears it otherwise. Use lock prefix for atomicity on MPs.
4124 //
4125 // FSR: object begin
4126 // T2: object end
4127 // T0: instance size in words
4129 // if someone beat us on the allocation, try again, otherwise continue
4130 //__ lui(T1, Assembler::split_high((int)Universe::heap()->top_addr()));
4131 __ cmpxchg(T2, heap_top, FSR);
4132 __ beq(AT, R0, retry);
4133 __ delayed()->nop();
4134 }
4136 if (UseTLAB || Universe::heap()->supports_inline_contig_alloc()) {
4137 // The object is initialized before the header. If the object size is
4138 // zero, go directly to the header initialization.
4139 __ bind(initialize_object);
4140 __ li(AT, - sizeof(oopDesc));
4141 __ daddu(T0, T0, AT);
4142 __ beq_far(T0, R0, initialize_header);
4143 __ delayed()->nop();
4146 // T0 must have been multiple of 2
4147 #ifdef ASSERT
4148 // make sure T0 was multiple of 2
4149 Label L;
4150 __ andi(AT, T0, 1);
4151 __ beq(AT, R0, L);
4152 __ delayed()->nop();
4153 __ stop("object size is not multiple of 2 - adjust this code");
4154 __ bind(L);
4155 // edx must be > 0, no extra check needed here
4156 #endif
4158 // initialize remaining object fields: T0 is a multiple of 2
4159 {
4160 Label loop;
4161 __ dadd(T1, FSR, T0);
4162 __ daddi(T1, T1, -oopSize);
4164 __ bind(loop);
4165 __ sd(R0, T1, sizeof(oopDesc) + 0 * oopSize);
4166 // __ sd(R0, T1, sizeof(oopDesc) + 1 * oopSize);
4167 __ bne(T1, FSR, loop); //dont clear header
4168 __ delayed()->daddi(T1, T1, -oopSize);
4169 // actually sizeof(oopDesc)==8, so we can move
4170 // __ addiu(AT, AT, -8) to delay slot, and compare FSR with T1
4171 }
4172 //klass in T3,
4173 // initialize object header only.
4174 __ bind(initialize_header);
4175 if (UseBiasedLocking) {
4176 // __ popl(ecx); // get saved klass back in the register.
4177 // __ movl(ebx, Address(ecx, Klass::prototype_header_offset_in_bytes()
4178 // + klassOopDesc::klass_part_offset_in_bytes()));
4179 __ ld(AT, T3, in_bytes(Klass::prototype_header_offset()));
4180 // __ movl(Address(eax, oopDesc::mark_offset_in_bytes ()), ebx);
4181 __ sd(AT, FSR, oopDesc::mark_offset_in_bytes ());
4182 } else {
4183 __ li(AT, (long)markOopDesc::prototype());
4184 __ sd(AT, FSR, oopDesc::mark_offset_in_bytes());
4185 }
4187 //__ sd(T3, FSR, oopDesc::klass_offset_in_bytes());
4188 __ store_klass_gap(FSR, R0);
4189 __ store_klass(FSR, T3);
4191 {
4192 SkipIfEqual skip_if(_masm, &DTraceAllocProbes, 0);
4193 // Trigger dtrace event for fastpath
4194 __ push(atos);
4195 __ call_VM_leaf(
4196 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc), FSR);
4197 __ pop(atos);
4198 }
4199 __ b(done);
4200 __ delayed()->nop();
4201 }
4202 // slow case
4203 __ bind(slow_case);
4204 call_VM(FSR, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), A1, A2);
4206 // continue
4207 __ bind(done);
4208 __ sync();
4209 }
4211 void TemplateTable::newarray() {
4212 transition(itos, atos);
4213 __ lbu(A1, at_bcp(1));
4214 //type, count
4215 call_VM(FSR, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray), A1, FSR);
4216 __ sync();
4217 }
4219 void TemplateTable::anewarray() {
4220 transition(itos, atos);
4221 __ get_2_byte_integer_at_bcp(A2, AT, 1);
4222 __ huswap(A2);
4223 __ get_constant_pool(A1);
4224 // cp, index, count
4225 call_VM(FSR, CAST_FROM_FN_PTR(address, InterpreterRuntime::anewarray), A1, A2, FSR);
4226 __ sync();
4227 }
4229 void TemplateTable::arraylength() {
4230 transition(atos, itos);
4231 __ null_check(FSR, arrayOopDesc::length_offset_in_bytes());
4232 __ lw(FSR, FSR, arrayOopDesc::length_offset_in_bytes());
4233 }
4235 // i use T2 as ebx, T3 as ecx, T1 as edx
4236 // when invoke gen_subtype_check, super in T3, sub in T2, object in FSR(it's always)
4237 // T2 : sub klass
4238 // T3 : cpool
4239 // T3 : super klass
4240 void TemplateTable::checkcast() {
4241 transition(atos, atos);
4242 Label done, is_null, ok_is_subtype, quicked, resolved;
4243 __ beq(FSR, R0, is_null);
4244 __ delayed()->nop();
4246 // Get cpool & tags index
4247 __ get_cpool_and_tags(T3, T1);
4248 __ get_2_byte_integer_at_bcp(T2, AT, 1);
4249 __ huswap(T2);
4251 // See if bytecode has already been quicked
4252 __ dadd(AT, T1, T2);
4253 __ lb(AT, AT, Array<u1>::base_offset_in_bytes());
4254 __ daddiu(AT, AT, - (int)JVM_CONSTANT_Class);
4255 __ beq(AT, R0, quicked);
4256 __ delayed()->nop();
4258 /* 2012/6/2 Jin: In InterpreterRuntime::quicken_io_cc, lots of new classes may be loaded.
4259 * Then, GC will move the object in V0 to another places in heap.
4260 * Therefore, We should never save such an object in register.
4261 * Instead, we should save it in the stack. It can be modified automatically by the GC thread.
4262 * After GC, the object address in FSR is changed to a new place.
4263 */
4264 __ push(atos);
4265 const Register thread = TREG;
4266 #ifndef OPT_THREAD
4267 __ get_thread(thread);
4268 #endif
4269 call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
4270 __ get_vm_result_2(T3, thread);
4271 __ pop_ptr(FSR);
4272 __ b(resolved);
4273 __ delayed()->nop();
4275 // klass already in cp, get superklass in T3
4276 __ bind(quicked);
4277 __ dsll(AT, T2, Address::times_8);
4278 __ dadd(AT, T3, AT);
4279 __ ld(T3, AT, sizeof(ConstantPool));
4281 __ bind(resolved);
4283 // get subklass in T2
4284 //__ ld(T2, FSR, oopDesc::klass_offset_in_bytes());
4285 //add for compressedoops
4286 __ load_klass(T2, FSR);
4287 // Superklass in T3. Subklass in T2.
4288 __ gen_subtype_check(T3, T2, ok_is_subtype);
4290 // Come here on failure
4291 // object is at FSR
4292 __ jmp(Interpreter::_throw_ClassCastException_entry);
4293 __ delayed()->nop();
4295 // Come here on success
4296 __ bind(ok_is_subtype);
4298 // Collect counts on whether this check-cast sees NULLs a lot or not.
4299 if (ProfileInterpreter) {
4300 __ b(done);
4301 __ delayed()->nop();
4302 __ bind(is_null);
4303 __ profile_null_seen(T3);
4304 } else {
4305 __ bind(is_null);
4306 }
4307 __ bind(done);
4308 }
4310 // i use T3 as cpool, T1 as tags, T2 as index
4311 // object always in FSR, superklass in T3, subklass in T2
4312 void TemplateTable::instanceof() {
4313 transition(atos, itos);
4314 Label done, is_null, ok_is_subtype, quicked, resolved;
4316 __ beq(FSR, R0, is_null);
4317 __ delayed()->nop();
4319 // Get cpool & tags index
4320 __ get_cpool_and_tags(T3, T1);
4321 // get index
4322 __ get_2_byte_integer_at_bcp(T2, AT, 1);
4323 __ hswap(T2);
4325 // See if bytecode has already been quicked
4326 // quicked
4327 __ daddu(AT, T1, T2);
4328 __ lb(AT, AT, Array<u1>::base_offset_in_bytes());
4329 __ daddiu(AT, AT, - (int)JVM_CONSTANT_Class);
4330 __ beq(AT, R0, quicked);
4331 __ delayed()->nop();
4333 // get superklass in T3
4334 //__ move(TSR, FSR);
4335 // sometimes S2 may be changed during the call,
4336 // be careful if u use TSR as a saving place
4337 //__ push(FSR);
4338 __ push(atos);
4339 const Register thread = TREG;
4340 #ifndef OPT_THREAD
4341 __ get_thread(thread);
4342 #endif
4343 call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
4344 __ get_vm_result_2(T3, thread);
4345 //__ lw(FSR, SP, 0);
4346 __ pop_ptr(FSR);
4347 __ b(resolved);
4348 __ delayed()->nop();
4349 //__ move(FSR, TSR);
4351 // get superklass in T3, subklass in T2
4352 __ bind(quicked);
4353 __ dsll(AT, T2, Address::times_8);
4354 __ daddu(AT, T3, AT);
4355 __ ld(T3, AT, sizeof(ConstantPool));
4357 __ bind(resolved);
4358 // get subklass in T2
4359 //__ ld(T2, FSR, oopDesc::klass_offset_in_bytes());
4360 //add for compressedoops
4361 __ load_klass(T2, FSR);
4363 // Superklass in T3. Subklass in T2.
4364 __ gen_subtype_check(T3, T2, ok_is_subtype);
4365 // Come here on failure
4366 __ b(done);
4367 __ delayed(); __ move(FSR, R0);
4369 // Come here on success
4370 __ bind(ok_is_subtype);
4371 __ move(FSR, 1);
4373 // Collect counts on whether this test sees NULLs a lot or not.
4374 if (ProfileInterpreter) {
4375 __ beq(R0, R0, done);
4376 __ nop();
4377 __ bind(is_null);
4378 __ profile_null_seen(T3);
4379 } else {
4380 __ bind(is_null); // same as 'done'
4381 }
4382 __ bind(done);
4383 // FSR = 0: obj == NULL or obj is not an instanceof the specified klass
4384 // FSR = 1: obj != NULL and obj is an instanceof the specified klass
4385 }
4387 //--------------------------------------------------------
4388 //--------------------------------------------
4389 // Breakpoints
4390 void TemplateTable::_breakpoint() {
4392 // Note: We get here even if we are single stepping..
4393 // jbug inists on setting breakpoints at every bytecode
4394 // even if we are in single step mode.
4396 transition(vtos, vtos);
4398 // get the unpatched byte code
4399 ///__ get_method(ecx);
4400 ///__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::get_original_bytecode_at)
4401 //, ecx, esi);
4402 ///__ movl(ebx, eax);
4403 __ get_method(A1);
4404 __ call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::get_original_bytecode_at),
4405 A1, BCP);
4406 __ move(Rnext, V0); // Jin: Rnext will be used in dispatch_only_normal
4408 // post the breakpoint event
4409 ///__ get_method(ecx);
4410 ///__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::_breakpoint), ecx, esi);
4411 __ get_method(A1);
4412 __ call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::_breakpoint), A1, BCP);
4414 // complete the execution of original bytecode
4415 __ dispatch_only_normal(vtos);
4416 }
4418 //----------------------------------------------------------------------------------------------------
4419 // Exceptions
4421 void TemplateTable::athrow() {
4422 transition(atos, vtos);
4423 __ null_check(FSR);
4424 __ jmp(Interpreter::throw_exception_entry());
4425 __ delayed()->nop();
4426 }
4428 //----------------------------------------------------------------------------------------------------
4429 // Synchronization
4430 //
4431 // Note: monitorenter & exit are symmetric routines; which is reflected
4432 // in the assembly code structure as well
4433 //
4434 // Stack layout:
4435 //
4436 // [expressions ] <--- SP = expression stack top
4437 // ..
4438 // [expressions ]
4439 // [monitor entry] <--- monitor block top = expression stack bot
4440 // ..
4441 // [monitor entry]
4442 // [frame data ] <--- monitor block bot
4443 // ...
4444 // [return addr ] <--- FP
4446 // we use T2 as monitor entry pointer, T3 as monitor top pointer, c_rarg0 as free slot pointer
4447 // object always in FSR
4448 void TemplateTable::monitorenter() {
4449 transition(atos, vtos);
4450 // check for NULL object
4451 __ null_check(FSR);
4453 const Address monitor_block_top(FP, frame::interpreter_frame_monitor_block_top_offset
4454 * wordSize);
4455 const int entry_size = (frame::interpreter_frame_monitor_size()* wordSize);
4456 Label allocated;
4458 // initialize entry pointer
4459 __ move(c_rarg0, R0);
4461 // find a free slot in the monitor block (result in edx)
4462 {
4463 Label entry, loop, exit, next;
4464 __ ld(T2, monitor_block_top);
4465 __ b(entry);
4466 __ delayed()->daddi(T3, FP, frame::interpreter_frame_initial_sp_offset * wordSize);
4468 // free slot?
4469 __ bind(loop);
4470 __ ld(AT, T2, BasicObjectLock::obj_offset_in_bytes());
4471 __ bne(AT, R0, next);
4472 __ delayed()->nop();
4473 __ move(c_rarg0, T2);
4475 __ bind(next);
4476 __ beq(FSR, AT, exit);
4477 __ delayed()->nop();
4478 __ daddi(T2, T2, entry_size);
4480 __ bind(entry);
4481 __ bne(T3, T2, loop);
4482 __ delayed()->nop();
4483 __ bind(exit);
4484 }
4486 __ bne(c_rarg0, R0, allocated);
4487 __ delayed()->nop();
4489 // allocate one if there's no free slot
4490 {
4491 Label entry, loop;
4492 // 1. compute new pointers // SP: old expression stack top
4493 __ ld(c_rarg0, monitor_block_top);
4494 __ daddi(SP, SP, - entry_size);
4495 __ daddi(c_rarg0, c_rarg0, - entry_size);
4496 __ sd(c_rarg0, monitor_block_top);
4497 __ b(entry);
4498 __ delayed(); __ move(T3, SP);
4500 // 2. move expression stack contents
4501 __ bind(loop);
4502 __ ld(AT, T3, entry_size);
4503 __ sd(AT, T3, 0);
4504 __ daddi(T3, T3, wordSize);
4505 __ bind(entry);
4506 __ bne(T3, c_rarg0, loop);
4507 __ delayed()->nop();
4508 }
4510 __ bind(allocated);
4511 // Increment bcp to point to the next bytecode,
4512 // so exception handling for async. exceptions work correctly.
4513 // The object has already been poped from the stack, so the
4514 // expression stack looks correct.
4515 __ daddi(BCP, BCP, 1);
4516 __ sd(FSR, c_rarg0, BasicObjectLock::obj_offset_in_bytes());
4517 __ lock_object(c_rarg0);
4518 // check to make sure this monitor doesn't cause stack overflow after locking
4519 __ save_bcp(); // in case of exception
4520 __ generate_stack_overflow_check(0);
4521 // The bcp has already been incremented. Just need to dispatch to next instruction.
4523 __ dispatch_next(vtos);
4524 }
4526 // T2 : top
4527 // c_rarg0 : entry
4528 void TemplateTable::monitorexit() {
4529 transition(atos, vtos);
4531 __ null_check(FSR);
4533 const int entry_size =(frame::interpreter_frame_monitor_size()* wordSize);
4534 Label found;
4536 // find matching slot
4537 {
4538 Label entry, loop;
4539 __ ld(c_rarg0, FP, frame::interpreter_frame_monitor_block_top_offset * wordSize);
4540 __ b(entry);
4541 __ delayed()->daddiu(T2, FP, frame::interpreter_frame_initial_sp_offset * wordSize);
4543 __ bind(loop);
4544 __ ld(AT, c_rarg0, BasicObjectLock::obj_offset_in_bytes());
4545 __ beq(FSR, AT, found);
4546 __ delayed()->nop();
4547 __ daddiu(c_rarg0, c_rarg0, entry_size);
4548 __ bind(entry);
4549 __ bne(T2, c_rarg0, loop);
4550 __ delayed()->nop();
4551 }
4553 // error handling. Unlocking was not block-structured
4554 Label end;
4555 __ call_VM(NOREG, CAST_FROM_FN_PTR(address,
4556 InterpreterRuntime::throw_illegal_monitor_state_exception));
4557 __ should_not_reach_here();
4559 // call run-time routine
4560 // c_rarg0: points to monitor entry
4561 __ bind(found);
4562 __ move(TSR, FSR);
4563 __ unlock_object(c_rarg0);
4564 __ move(FSR, TSR);
4565 __ bind(end);
4566 }
4568 //--------------------------------------------------------------------------------------------------// Wide instructions
4570 void TemplateTable::wide() {
4571 transition(vtos, vtos);
4572 // Note: the esi increment step is part of the individual wide bytecode implementations
4573 __ lbu(Rnext, at_bcp(1));
4574 __ dsll(T9, Rnext, Address::times_8);
4575 __ li(AT, (long)Interpreter::_wentry_point);
4576 __ dadd(AT, T9, AT);
4577 __ ld(T9, AT, 0);
4578 __ jr(T9);
4579 __ delayed()->nop();
4580 }
4582 //--------------------------------------------------------------------------------------------------// Multi arrays
4584 void TemplateTable::multianewarray() {
4585 transition(vtos, atos);
4586 // last dim is on top of stack; we want address of first one:
4587 // first_addr = last_addr + (ndims - 1) * wordSize
4588 __ lbu(A1, at_bcp(3)); // dimension
4589 __ daddi(A1, A1, -1);
4590 __ dsll(A1, A1, Address::times_8);
4591 __ dadd(A1, SP, A1); // now A1 pointer to the count array on the stack
4592 call_VM(FSR, CAST_FROM_FN_PTR(address, InterpreterRuntime::multianewarray), A1);
4593 __ lbu(AT, at_bcp(3));
4594 __ dsll(AT, AT, Address::times_8);
4595 __ dadd(SP, SP, AT);
4596 __ sync();
4597 }
4599 #endif // !CC_INTERP