Fri, 03 Sep 2010 17:51:07 -0700
6953144: Tiered compilation
Summary: Infrastructure for tiered compilation support (interpreter + c1 + c2) for 32 and 64 bit. Simple tiered policy implementation.
Reviewed-by: kvn, never, phh, twisti
1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
25 #include "incls/_precompiled.incl"
26 #include "incls/_templateTable_x86_32.cpp.incl"
28 #ifndef CC_INTERP
29 #define __ _masm->
31 //----------------------------------------------------------------------------------------------------
32 // Platform-dependent initialization
34 void TemplateTable::pd_initialize() {
35 // No i486 specific initialization
36 }
38 //----------------------------------------------------------------------------------------------------
39 // Address computation
41 // local variables
42 static inline Address iaddress(int n) {
43 return Address(rdi, Interpreter::local_offset_in_bytes(n));
44 }
46 static inline Address laddress(int n) { return iaddress(n + 1); }
47 static inline Address haddress(int n) { return iaddress(n + 0); }
48 static inline Address faddress(int n) { return iaddress(n); }
49 static inline Address daddress(int n) { return laddress(n); }
50 static inline Address aaddress(int n) { return iaddress(n); }
52 static inline Address iaddress(Register r) {
53 return Address(rdi, r, Interpreter::stackElementScale());
54 }
55 static inline Address laddress(Register r) {
56 return Address(rdi, r, Interpreter::stackElementScale(), Interpreter::local_offset_in_bytes(1));
57 }
58 static inline Address haddress(Register r) {
59 return Address(rdi, r, Interpreter::stackElementScale(), Interpreter::local_offset_in_bytes(0));
60 }
62 static inline Address faddress(Register r) { return iaddress(r); }
63 static inline Address daddress(Register r) { return laddress(r); }
64 static inline Address aaddress(Register r) { return iaddress(r); }
66 // expression stack
67 // (Note: Must not use symmetric equivalents at_rsp_m1/2 since they store
68 // data beyond the rsp which is potentially unsafe in an MT environment;
69 // an interrupt may overwrite that data.)
70 static inline Address at_rsp () {
71 return Address(rsp, 0);
72 }
74 // At top of Java expression stack which may be different than rsp(). It
75 // isn't for category 1 objects.
76 static inline Address at_tos () {
77 Address tos = Address(rsp, Interpreter::expr_offset_in_bytes(0));
78 return tos;
79 }
81 static inline Address at_tos_p1() {
82 return Address(rsp, Interpreter::expr_offset_in_bytes(1));
83 }
85 static inline Address at_tos_p2() {
86 return Address(rsp, Interpreter::expr_offset_in_bytes(2));
87 }
89 // Condition conversion
90 static Assembler::Condition j_not(TemplateTable::Condition cc) {
91 switch (cc) {
92 case TemplateTable::equal : return Assembler::notEqual;
93 case TemplateTable::not_equal : return Assembler::equal;
94 case TemplateTable::less : return Assembler::greaterEqual;
95 case TemplateTable::less_equal : return Assembler::greater;
96 case TemplateTable::greater : return Assembler::lessEqual;
97 case TemplateTable::greater_equal: return Assembler::less;
98 }
99 ShouldNotReachHere();
100 return Assembler::zero;
101 }
104 //----------------------------------------------------------------------------------------------------
105 // Miscelaneous helper routines
107 // Store an oop (or NULL) at the address described by obj.
108 // If val == noreg this means store a NULL
110 static void do_oop_store(InterpreterMacroAssembler* _masm,
111 Address obj,
112 Register val,
113 BarrierSet::Name barrier,
114 bool precise) {
115 assert(val == noreg || val == rax, "parameter is just for looks");
116 switch (barrier) {
117 #ifndef SERIALGC
118 case BarrierSet::G1SATBCT:
119 case BarrierSet::G1SATBCTLogging:
120 {
121 // flatten object address if needed
122 // We do it regardless of precise because we need the registers
123 if (obj.index() == noreg && obj.disp() == 0) {
124 if (obj.base() != rdx) {
125 __ movl(rdx, obj.base());
126 }
127 } else {
128 __ leal(rdx, obj);
129 }
130 __ get_thread(rcx);
131 __ save_bcp();
132 __ g1_write_barrier_pre(rdx, rcx, rsi, rbx, val != noreg);
134 // Do the actual store
135 // noreg means NULL
136 if (val == noreg) {
137 __ movptr(Address(rdx, 0), NULL_WORD);
138 // No post barrier for NULL
139 } else {
140 __ movl(Address(rdx, 0), val);
141 __ g1_write_barrier_post(rdx, rax, rcx, rbx, rsi);
142 }
143 __ restore_bcp();
145 }
146 break;
147 #endif // SERIALGC
148 case BarrierSet::CardTableModRef:
149 case BarrierSet::CardTableExtension:
150 {
151 if (val == noreg) {
152 __ movptr(obj, NULL_WORD);
153 } else {
154 __ movl(obj, val);
155 // flatten object address if needed
156 if (!precise || (obj.index() == noreg && obj.disp() == 0)) {
157 __ store_check(obj.base());
158 } else {
159 __ leal(rdx, obj);
160 __ store_check(rdx);
161 }
162 }
163 }
164 break;
165 case BarrierSet::ModRef:
166 case BarrierSet::Other:
167 if (val == noreg) {
168 __ movptr(obj, NULL_WORD);
169 } else {
170 __ movl(obj, val);
171 }
172 break;
173 default :
174 ShouldNotReachHere();
176 }
177 }
179 Address TemplateTable::at_bcp(int offset) {
180 assert(_desc->uses_bcp(), "inconsistent uses_bcp information");
181 return Address(rsi, offset);
182 }
185 void TemplateTable::patch_bytecode(Bytecodes::Code bytecode, Register bc,
186 Register scratch,
187 bool load_bc_into_scratch/*=true*/) {
189 if (!RewriteBytecodes) return;
190 // the pair bytecodes have already done the load.
191 if (load_bc_into_scratch) {
192 __ movl(bc, bytecode);
193 }
194 Label patch_done;
195 if (JvmtiExport::can_post_breakpoint()) {
196 Label fast_patch;
197 // if a breakpoint is present we can't rewrite the stream directly
198 __ movzbl(scratch, at_bcp(0));
199 __ cmpl(scratch, Bytecodes::_breakpoint);
200 __ jcc(Assembler::notEqual, fast_patch);
201 __ get_method(scratch);
202 // Let breakpoint table handling rewrite to quicker bytecode
203 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::set_original_bytecode_at), scratch, rsi, bc);
204 #ifndef ASSERT
205 __ jmpb(patch_done);
206 #else
207 __ jmp(patch_done);
208 #endif
209 __ bind(fast_patch);
210 }
211 #ifdef ASSERT
212 Label okay;
213 __ load_unsigned_byte(scratch, at_bcp(0));
214 __ cmpl(scratch, (int)Bytecodes::java_code(bytecode));
215 __ jccb(Assembler::equal, okay);
216 __ cmpl(scratch, bc);
217 __ jcc(Assembler::equal, okay);
218 __ stop("patching the wrong bytecode");
219 __ bind(okay);
220 #endif
221 // patch bytecode
222 __ movb(at_bcp(0), bc);
223 __ bind(patch_done);
224 }
226 //----------------------------------------------------------------------------------------------------
227 // Individual instructions
229 void TemplateTable::nop() {
230 transition(vtos, vtos);
231 // nothing to do
232 }
234 void TemplateTable::shouldnotreachhere() {
235 transition(vtos, vtos);
236 __ stop("shouldnotreachhere bytecode");
237 }
241 void TemplateTable::aconst_null() {
242 transition(vtos, atos);
243 __ xorptr(rax, rax);
244 }
247 void TemplateTable::iconst(int value) {
248 transition(vtos, itos);
249 if (value == 0) {
250 __ xorptr(rax, rax);
251 } else {
252 __ movptr(rax, value);
253 }
254 }
257 void TemplateTable::lconst(int value) {
258 transition(vtos, ltos);
259 if (value == 0) {
260 __ xorptr(rax, rax);
261 } else {
262 __ movptr(rax, value);
263 }
264 assert(value >= 0, "check this code");
265 __ xorptr(rdx, rdx);
266 }
269 void TemplateTable::fconst(int value) {
270 transition(vtos, ftos);
271 if (value == 0) { __ fldz();
272 } else if (value == 1) { __ fld1();
273 } else if (value == 2) { __ fld1(); __ fld1(); __ faddp(); // should do a better solution here
274 } else { ShouldNotReachHere();
275 }
276 }
279 void TemplateTable::dconst(int value) {
280 transition(vtos, dtos);
281 if (value == 0) { __ fldz();
282 } else if (value == 1) { __ fld1();
283 } else { ShouldNotReachHere();
284 }
285 }
288 void TemplateTable::bipush() {
289 transition(vtos, itos);
290 __ load_signed_byte(rax, at_bcp(1));
291 }
294 void TemplateTable::sipush() {
295 transition(vtos, itos);
296 __ load_unsigned_short(rax, at_bcp(1));
297 __ bswapl(rax);
298 __ sarl(rax, 16);
299 }
301 void TemplateTable::ldc(bool wide) {
302 transition(vtos, vtos);
303 Label call_ldc, notFloat, notClass, Done;
305 if (wide) {
306 __ get_unsigned_2_byte_index_at_bcp(rbx, 1);
307 } else {
308 __ load_unsigned_byte(rbx, at_bcp(1));
309 }
310 __ get_cpool_and_tags(rcx, rax);
311 const int base_offset = constantPoolOopDesc::header_size() * wordSize;
312 const int tags_offset = typeArrayOopDesc::header_size(T_BYTE) * wordSize;
314 // get type
315 __ xorptr(rdx, rdx);
316 __ movb(rdx, Address(rax, rbx, Address::times_1, tags_offset));
318 // unresolved string - get the resolved string
319 __ cmpl(rdx, JVM_CONSTANT_UnresolvedString);
320 __ jccb(Assembler::equal, call_ldc);
322 // unresolved class - get the resolved class
323 __ cmpl(rdx, JVM_CONSTANT_UnresolvedClass);
324 __ jccb(Assembler::equal, call_ldc);
326 // unresolved class in error (resolution failed) - call into runtime
327 // so that the same error from first resolution attempt is thrown.
328 __ cmpl(rdx, JVM_CONSTANT_UnresolvedClassInError);
329 __ jccb(Assembler::equal, call_ldc);
331 // resolved class - need to call vm to get java mirror of the class
332 __ cmpl(rdx, JVM_CONSTANT_Class);
333 __ jcc(Assembler::notEqual, notClass);
335 __ bind(call_ldc);
336 __ movl(rcx, wide);
337 call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::ldc), rcx);
338 __ push(atos);
339 __ jmp(Done);
341 __ bind(notClass);
342 __ cmpl(rdx, JVM_CONSTANT_Float);
343 __ jccb(Assembler::notEqual, notFloat);
344 // ftos
345 __ fld_s( Address(rcx, rbx, Address::times_ptr, base_offset));
346 __ push(ftos);
347 __ jmp(Done);
349 __ bind(notFloat);
350 #ifdef ASSERT
351 { Label L;
352 __ cmpl(rdx, JVM_CONSTANT_Integer);
353 __ jcc(Assembler::equal, L);
354 __ cmpl(rdx, JVM_CONSTANT_String);
355 __ jcc(Assembler::equal, L);
356 __ stop("unexpected tag type in ldc");
357 __ bind(L);
358 }
359 #endif
360 Label isOop;
361 // atos and itos
362 // String is only oop type we will see here
363 __ cmpl(rdx, JVM_CONSTANT_String);
364 __ jccb(Assembler::equal, isOop);
365 __ movl(rax, Address(rcx, rbx, Address::times_ptr, base_offset));
366 __ push(itos);
367 __ jmp(Done);
368 __ bind(isOop);
369 __ movptr(rax, Address(rcx, rbx, Address::times_ptr, base_offset));
370 __ push(atos);
372 if (VerifyOops) {
373 __ verify_oop(rax);
374 }
375 __ bind(Done);
376 }
378 // Fast path for caching oop constants.
379 // %%% We should use this to handle Class and String constants also.
380 // %%% It will simplify the ldc/primitive path considerably.
381 void TemplateTable::fast_aldc(bool wide) {
382 transition(vtos, atos);
384 if (!EnableMethodHandles) {
385 // We should not encounter this bytecode if !EnableMethodHandles.
386 // The verifier will stop it. However, if we get past the verifier,
387 // this will stop the thread in a reasonable way, without crashing the JVM.
388 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
389 InterpreterRuntime::throw_IncompatibleClassChangeError));
390 // the call_VM checks for exception, so we should never return here.
391 __ should_not_reach_here();
392 return;
393 }
395 const Register cache = rcx;
396 const Register index = rdx;
398 resolve_cache_and_index(f1_oop, rax, cache, index, wide ? sizeof(u2) : sizeof(u1));
399 if (VerifyOops) {
400 __ verify_oop(rax);
401 }
402 }
404 void TemplateTable::ldc2_w() {
405 transition(vtos, vtos);
406 Label Long, Done;
407 __ get_unsigned_2_byte_index_at_bcp(rbx, 1);
409 __ get_cpool_and_tags(rcx, rax);
410 const int base_offset = constantPoolOopDesc::header_size() * wordSize;
411 const int tags_offset = typeArrayOopDesc::header_size(T_BYTE) * wordSize;
413 // get type
414 __ cmpb(Address(rax, rbx, Address::times_1, tags_offset), JVM_CONSTANT_Double);
415 __ jccb(Assembler::notEqual, Long);
416 // dtos
417 __ fld_d( Address(rcx, rbx, Address::times_ptr, base_offset));
418 __ push(dtos);
419 __ jmpb(Done);
421 __ bind(Long);
422 // ltos
423 __ movptr(rax, Address(rcx, rbx, Address::times_ptr, base_offset + 0 * wordSize));
424 NOT_LP64(__ movptr(rdx, Address(rcx, rbx, Address::times_ptr, base_offset + 1 * wordSize)));
426 __ push(ltos);
428 __ bind(Done);
429 }
432 void TemplateTable::locals_index(Register reg, int offset) {
433 __ load_unsigned_byte(reg, at_bcp(offset));
434 __ negptr(reg);
435 }
438 void TemplateTable::iload() {
439 transition(vtos, itos);
440 if (RewriteFrequentPairs) {
441 Label rewrite, done;
443 // get next byte
444 __ load_unsigned_byte(rbx, at_bcp(Bytecodes::length_for(Bytecodes::_iload)));
445 // if _iload, wait to rewrite to iload2. We only want to rewrite the
446 // last two iloads in a pair. Comparing against fast_iload means that
447 // the next bytecode is neither an iload or a caload, and therefore
448 // an iload pair.
449 __ cmpl(rbx, Bytecodes::_iload);
450 __ jcc(Assembler::equal, done);
452 __ cmpl(rbx, Bytecodes::_fast_iload);
453 __ movl(rcx, Bytecodes::_fast_iload2);
454 __ jccb(Assembler::equal, rewrite);
456 // if _caload, rewrite to fast_icaload
457 __ cmpl(rbx, Bytecodes::_caload);
458 __ movl(rcx, Bytecodes::_fast_icaload);
459 __ jccb(Assembler::equal, rewrite);
461 // rewrite so iload doesn't check again.
462 __ movl(rcx, Bytecodes::_fast_iload);
464 // rewrite
465 // rcx: fast bytecode
466 __ bind(rewrite);
467 patch_bytecode(Bytecodes::_iload, rcx, rbx, false);
468 __ bind(done);
469 }
471 // Get the local value into tos
472 locals_index(rbx);
473 __ movl(rax, iaddress(rbx));
474 }
477 void TemplateTable::fast_iload2() {
478 transition(vtos, itos);
479 locals_index(rbx);
480 __ movl(rax, iaddress(rbx));
481 __ push(itos);
482 locals_index(rbx, 3);
483 __ movl(rax, iaddress(rbx));
484 }
486 void TemplateTable::fast_iload() {
487 transition(vtos, itos);
488 locals_index(rbx);
489 __ movl(rax, iaddress(rbx));
490 }
493 void TemplateTable::lload() {
494 transition(vtos, ltos);
495 locals_index(rbx);
496 __ movptr(rax, laddress(rbx));
497 NOT_LP64(__ movl(rdx, haddress(rbx)));
498 }
501 void TemplateTable::fload() {
502 transition(vtos, ftos);
503 locals_index(rbx);
504 __ fld_s(faddress(rbx));
505 }
508 void TemplateTable::dload() {
509 transition(vtos, dtos);
510 locals_index(rbx);
511 __ fld_d(daddress(rbx));
512 }
515 void TemplateTable::aload() {
516 transition(vtos, atos);
517 locals_index(rbx);
518 __ movptr(rax, aaddress(rbx));
519 }
522 void TemplateTable::locals_index_wide(Register reg) {
523 __ movl(reg, at_bcp(2));
524 __ bswapl(reg);
525 __ shrl(reg, 16);
526 __ negptr(reg);
527 }
530 void TemplateTable::wide_iload() {
531 transition(vtos, itos);
532 locals_index_wide(rbx);
533 __ movl(rax, iaddress(rbx));
534 }
537 void TemplateTable::wide_lload() {
538 transition(vtos, ltos);
539 locals_index_wide(rbx);
540 __ movptr(rax, laddress(rbx));
541 NOT_LP64(__ movl(rdx, haddress(rbx)));
542 }
545 void TemplateTable::wide_fload() {
546 transition(vtos, ftos);
547 locals_index_wide(rbx);
548 __ fld_s(faddress(rbx));
549 }
552 void TemplateTable::wide_dload() {
553 transition(vtos, dtos);
554 locals_index_wide(rbx);
555 __ fld_d(daddress(rbx));
556 }
559 void TemplateTable::wide_aload() {
560 transition(vtos, atos);
561 locals_index_wide(rbx);
562 __ movptr(rax, aaddress(rbx));
563 }
565 void TemplateTable::index_check(Register array, Register index) {
566 // Pop ptr into array
567 __ pop_ptr(array);
568 index_check_without_pop(array, index);
569 }
571 void TemplateTable::index_check_without_pop(Register array, Register index) {
572 // destroys rbx,
573 // check array
574 __ null_check(array, arrayOopDesc::length_offset_in_bytes());
575 LP64_ONLY(__ movslq(index, index));
576 // check index
577 __ cmpl(index, Address(array, arrayOopDesc::length_offset_in_bytes()));
578 if (index != rbx) {
579 // ??? convention: move aberrant index into rbx, for exception message
580 assert(rbx != array, "different registers");
581 __ mov(rbx, index);
582 }
583 __ jump_cc(Assembler::aboveEqual,
584 ExternalAddress(Interpreter::_throw_ArrayIndexOutOfBoundsException_entry));
585 }
588 void TemplateTable::iaload() {
589 transition(itos, itos);
590 // rdx: array
591 index_check(rdx, rax); // kills rbx,
592 // rax,: index
593 __ movl(rax, Address(rdx, rax, Address::times_4, arrayOopDesc::base_offset_in_bytes(T_INT)));
594 }
597 void TemplateTable::laload() {
598 transition(itos, ltos);
599 // rax,: index
600 // rdx: array
601 index_check(rdx, rax);
602 __ mov(rbx, rax);
603 // rbx,: index
604 __ movptr(rax, Address(rdx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_LONG) + 0 * wordSize));
605 NOT_LP64(__ movl(rdx, Address(rdx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_LONG) + 1 * wordSize)));
606 }
609 void TemplateTable::faload() {
610 transition(itos, ftos);
611 // rdx: array
612 index_check(rdx, rax); // kills rbx,
613 // rax,: index
614 __ fld_s(Address(rdx, rax, Address::times_4, arrayOopDesc::base_offset_in_bytes(T_FLOAT)));
615 }
618 void TemplateTable::daload() {
619 transition(itos, dtos);
620 // rdx: array
621 index_check(rdx, rax); // kills rbx,
622 // rax,: index
623 __ fld_d(Address(rdx, rax, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_DOUBLE)));
624 }
627 void TemplateTable::aaload() {
628 transition(itos, atos);
629 // rdx: array
630 index_check(rdx, rax); // kills rbx,
631 // rax,: index
632 __ movptr(rax, Address(rdx, rax, Address::times_ptr, arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
633 }
636 void TemplateTable::baload() {
637 transition(itos, itos);
638 // rdx: array
639 index_check(rdx, rax); // kills rbx,
640 // rax,: index
641 // can do better code for P5 - fix this at some point
642 __ load_signed_byte(rbx, Address(rdx, rax, Address::times_1, arrayOopDesc::base_offset_in_bytes(T_BYTE)));
643 __ mov(rax, rbx);
644 }
647 void TemplateTable::caload() {
648 transition(itos, itos);
649 // rdx: array
650 index_check(rdx, rax); // kills rbx,
651 // rax,: index
652 // can do better code for P5 - may want to improve this at some point
653 __ load_unsigned_short(rbx, Address(rdx, rax, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_CHAR)));
654 __ mov(rax, rbx);
655 }
657 // iload followed by caload frequent pair
658 void TemplateTable::fast_icaload() {
659 transition(vtos, itos);
660 // load index out of locals
661 locals_index(rbx);
662 __ movl(rax, iaddress(rbx));
664 // rdx: array
665 index_check(rdx, rax);
666 // rax,: index
667 __ load_unsigned_short(rbx, Address(rdx, rax, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_CHAR)));
668 __ mov(rax, rbx);
669 }
671 void TemplateTable::saload() {
672 transition(itos, itos);
673 // rdx: array
674 index_check(rdx, rax); // kills rbx,
675 // rax,: index
676 // can do better code for P5 - may want to improve this at some point
677 __ load_signed_short(rbx, Address(rdx, rax, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_SHORT)));
678 __ mov(rax, rbx);
679 }
682 void TemplateTable::iload(int n) {
683 transition(vtos, itos);
684 __ movl(rax, iaddress(n));
685 }
688 void TemplateTable::lload(int n) {
689 transition(vtos, ltos);
690 __ movptr(rax, laddress(n));
691 NOT_LP64(__ movptr(rdx, haddress(n)));
692 }
695 void TemplateTable::fload(int n) {
696 transition(vtos, ftos);
697 __ fld_s(faddress(n));
698 }
701 void TemplateTable::dload(int n) {
702 transition(vtos, dtos);
703 __ fld_d(daddress(n));
704 }
707 void TemplateTable::aload(int n) {
708 transition(vtos, atos);
709 __ movptr(rax, aaddress(n));
710 }
713 void TemplateTable::aload_0() {
714 transition(vtos, atos);
715 // According to bytecode histograms, the pairs:
716 //
717 // _aload_0, _fast_igetfield
718 // _aload_0, _fast_agetfield
719 // _aload_0, _fast_fgetfield
720 //
721 // occur frequently. If RewriteFrequentPairs is set, the (slow) _aload_0
722 // bytecode checks if the next bytecode is either _fast_igetfield,
723 // _fast_agetfield or _fast_fgetfield and then rewrites the
724 // current bytecode into a pair bytecode; otherwise it rewrites the current
725 // bytecode into _fast_aload_0 that doesn't do the pair check anymore.
726 //
727 // Note: If the next bytecode is _getfield, the rewrite must be delayed,
728 // otherwise we may miss an opportunity for a pair.
729 //
730 // Also rewrite frequent pairs
731 // aload_0, aload_1
732 // aload_0, iload_1
733 // These bytecodes with a small amount of code are most profitable to rewrite
734 if (RewriteFrequentPairs) {
735 Label rewrite, done;
736 // get next byte
737 __ load_unsigned_byte(rbx, at_bcp(Bytecodes::length_for(Bytecodes::_aload_0)));
739 // do actual aload_0
740 aload(0);
742 // if _getfield then wait with rewrite
743 __ cmpl(rbx, Bytecodes::_getfield);
744 __ jcc(Assembler::equal, done);
746 // if _igetfield then reqrite to _fast_iaccess_0
747 assert(Bytecodes::java_code(Bytecodes::_fast_iaccess_0) == Bytecodes::_aload_0, "fix bytecode definition");
748 __ cmpl(rbx, Bytecodes::_fast_igetfield);
749 __ movl(rcx, Bytecodes::_fast_iaccess_0);
750 __ jccb(Assembler::equal, rewrite);
752 // if _agetfield then reqrite to _fast_aaccess_0
753 assert(Bytecodes::java_code(Bytecodes::_fast_aaccess_0) == Bytecodes::_aload_0, "fix bytecode definition");
754 __ cmpl(rbx, Bytecodes::_fast_agetfield);
755 __ movl(rcx, Bytecodes::_fast_aaccess_0);
756 __ jccb(Assembler::equal, rewrite);
758 // if _fgetfield then reqrite to _fast_faccess_0
759 assert(Bytecodes::java_code(Bytecodes::_fast_faccess_0) == Bytecodes::_aload_0, "fix bytecode definition");
760 __ cmpl(rbx, Bytecodes::_fast_fgetfield);
761 __ movl(rcx, Bytecodes::_fast_faccess_0);
762 __ jccb(Assembler::equal, rewrite);
764 // else rewrite to _fast_aload0
765 assert(Bytecodes::java_code(Bytecodes::_fast_aload_0) == Bytecodes::_aload_0, "fix bytecode definition");
766 __ movl(rcx, Bytecodes::_fast_aload_0);
768 // rewrite
769 // rcx: fast bytecode
770 __ bind(rewrite);
771 patch_bytecode(Bytecodes::_aload_0, rcx, rbx, false);
773 __ bind(done);
774 } else {
775 aload(0);
776 }
777 }
779 void TemplateTable::istore() {
780 transition(itos, vtos);
781 locals_index(rbx);
782 __ movl(iaddress(rbx), rax);
783 }
786 void TemplateTable::lstore() {
787 transition(ltos, vtos);
788 locals_index(rbx);
789 __ movptr(laddress(rbx), rax);
790 NOT_LP64(__ movptr(haddress(rbx), rdx));
791 }
794 void TemplateTable::fstore() {
795 transition(ftos, vtos);
796 locals_index(rbx);
797 __ fstp_s(faddress(rbx));
798 }
801 void TemplateTable::dstore() {
802 transition(dtos, vtos);
803 locals_index(rbx);
804 __ fstp_d(daddress(rbx));
805 }
808 void TemplateTable::astore() {
809 transition(vtos, vtos);
810 __ pop_ptr(rax);
811 locals_index(rbx);
812 __ movptr(aaddress(rbx), rax);
813 }
816 void TemplateTable::wide_istore() {
817 transition(vtos, vtos);
818 __ pop_i(rax);
819 locals_index_wide(rbx);
820 __ movl(iaddress(rbx), rax);
821 }
824 void TemplateTable::wide_lstore() {
825 transition(vtos, vtos);
826 __ pop_l(rax, rdx);
827 locals_index_wide(rbx);
828 __ movptr(laddress(rbx), rax);
829 NOT_LP64(__ movl(haddress(rbx), rdx));
830 }
833 void TemplateTable::wide_fstore() {
834 wide_istore();
835 }
838 void TemplateTable::wide_dstore() {
839 wide_lstore();
840 }
843 void TemplateTable::wide_astore() {
844 transition(vtos, vtos);
845 __ pop_ptr(rax);
846 locals_index_wide(rbx);
847 __ movptr(aaddress(rbx), rax);
848 }
851 void TemplateTable::iastore() {
852 transition(itos, vtos);
853 __ pop_i(rbx);
854 // rax,: value
855 // rdx: array
856 index_check(rdx, rbx); // prefer index in rbx,
857 // rbx,: index
858 __ movl(Address(rdx, rbx, Address::times_4, arrayOopDesc::base_offset_in_bytes(T_INT)), rax);
859 }
862 void TemplateTable::lastore() {
863 transition(ltos, vtos);
864 __ pop_i(rbx);
865 // rax,: low(value)
866 // rcx: array
867 // rdx: high(value)
868 index_check(rcx, rbx); // prefer index in rbx,
869 // rbx,: index
870 __ movptr(Address(rcx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_LONG) + 0 * wordSize), rax);
871 NOT_LP64(__ movl(Address(rcx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_LONG) + 1 * wordSize), rdx));
872 }
875 void TemplateTable::fastore() {
876 transition(ftos, vtos);
877 __ pop_i(rbx);
878 // rdx: array
879 // st0: value
880 index_check(rdx, rbx); // prefer index in rbx,
881 // rbx,: index
882 __ fstp_s(Address(rdx, rbx, Address::times_4, arrayOopDesc::base_offset_in_bytes(T_FLOAT)));
883 }
886 void TemplateTable::dastore() {
887 transition(dtos, vtos);
888 __ pop_i(rbx);
889 // rdx: array
890 // st0: value
891 index_check(rdx, rbx); // prefer index in rbx,
892 // rbx,: index
893 __ fstp_d(Address(rdx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_DOUBLE)));
894 }
897 void TemplateTable::aastore() {
898 Label is_null, ok_is_subtype, done;
899 transition(vtos, vtos);
900 // stack: ..., array, index, value
901 __ movptr(rax, at_tos()); // Value
902 __ movl(rcx, at_tos_p1()); // Index
903 __ movptr(rdx, at_tos_p2()); // Array
905 Address element_address(rdx, rcx, Address::times_4, arrayOopDesc::base_offset_in_bytes(T_OBJECT));
906 index_check_without_pop(rdx, rcx); // kills rbx,
907 // do array store check - check for NULL value first
908 __ testptr(rax, rax);
909 __ jcc(Assembler::zero, is_null);
911 // Move subklass into EBX
912 __ movptr(rbx, Address(rax, oopDesc::klass_offset_in_bytes()));
913 // Move superklass into EAX
914 __ movptr(rax, Address(rdx, oopDesc::klass_offset_in_bytes()));
915 __ movptr(rax, Address(rax, sizeof(oopDesc) + objArrayKlass::element_klass_offset_in_bytes()));
916 // Compress array+index*wordSize+12 into a single register. Frees ECX.
917 __ lea(rdx, element_address);
919 // Generate subtype check. Blows ECX. Resets EDI to locals.
920 // Superklass in EAX. Subklass in EBX.
921 __ gen_subtype_check( rbx, ok_is_subtype );
923 // Come here on failure
924 // object is at TOS
925 __ jump(ExternalAddress(Interpreter::_throw_ArrayStoreException_entry));
927 // Come here on success
928 __ bind(ok_is_subtype);
930 // Get the value to store
931 __ movptr(rax, at_rsp());
932 // and store it with appropriate barrier
933 do_oop_store(_masm, Address(rdx, 0), rax, _bs->kind(), true);
935 __ jmp(done);
937 // Have a NULL in EAX, EDX=array, ECX=index. Store NULL at ary[idx]
938 __ bind(is_null);
939 __ profile_null_seen(rbx);
941 // Store NULL, (noreg means NULL to do_oop_store)
942 do_oop_store(_masm, element_address, noreg, _bs->kind(), true);
944 // Pop stack arguments
945 __ bind(done);
946 __ addptr(rsp, 3 * Interpreter::stackElementSize);
947 }
950 void TemplateTable::bastore() {
951 transition(itos, vtos);
952 __ pop_i(rbx);
953 // rax,: value
954 // rdx: array
955 index_check(rdx, rbx); // prefer index in rbx,
956 // rbx,: index
957 __ movb(Address(rdx, rbx, Address::times_1, arrayOopDesc::base_offset_in_bytes(T_BYTE)), rax);
958 }
961 void TemplateTable::castore() {
962 transition(itos, vtos);
963 __ pop_i(rbx);
964 // rax,: value
965 // rdx: array
966 index_check(rdx, rbx); // prefer index in rbx,
967 // rbx,: index
968 __ movw(Address(rdx, rbx, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_CHAR)), rax);
969 }
972 void TemplateTable::sastore() {
973 castore();
974 }
977 void TemplateTable::istore(int n) {
978 transition(itos, vtos);
979 __ movl(iaddress(n), rax);
980 }
983 void TemplateTable::lstore(int n) {
984 transition(ltos, vtos);
985 __ movptr(laddress(n), rax);
986 NOT_LP64(__ movptr(haddress(n), rdx));
987 }
990 void TemplateTable::fstore(int n) {
991 transition(ftos, vtos);
992 __ fstp_s(faddress(n));
993 }
996 void TemplateTable::dstore(int n) {
997 transition(dtos, vtos);
998 __ fstp_d(daddress(n));
999 }
1002 void TemplateTable::astore(int n) {
1003 transition(vtos, vtos);
1004 __ pop_ptr(rax);
1005 __ movptr(aaddress(n), rax);
1006 }
1009 void TemplateTable::pop() {
1010 transition(vtos, vtos);
1011 __ addptr(rsp, Interpreter::stackElementSize);
1012 }
1015 void TemplateTable::pop2() {
1016 transition(vtos, vtos);
1017 __ addptr(rsp, 2*Interpreter::stackElementSize);
1018 }
1021 void TemplateTable::dup() {
1022 transition(vtos, vtos);
1023 // stack: ..., a
1024 __ load_ptr(0, rax);
1025 __ push_ptr(rax);
1026 // stack: ..., a, a
1027 }
1030 void TemplateTable::dup_x1() {
1031 transition(vtos, vtos);
1032 // stack: ..., a, b
1033 __ load_ptr( 0, rax); // load b
1034 __ load_ptr( 1, rcx); // load a
1035 __ store_ptr(1, rax); // store b
1036 __ store_ptr(0, rcx); // store a
1037 __ push_ptr(rax); // push b
1038 // stack: ..., b, a, b
1039 }
1042 void TemplateTable::dup_x2() {
1043 transition(vtos, vtos);
1044 // stack: ..., a, b, c
1045 __ load_ptr( 0, rax); // load c
1046 __ load_ptr( 2, rcx); // load a
1047 __ store_ptr(2, rax); // store c in a
1048 __ push_ptr(rax); // push c
1049 // stack: ..., c, b, c, c
1050 __ load_ptr( 2, rax); // load b
1051 __ store_ptr(2, rcx); // store a in b
1052 // stack: ..., c, a, c, c
1053 __ store_ptr(1, rax); // store b in c
1054 // stack: ..., c, a, b, c
1055 }
1058 void TemplateTable::dup2() {
1059 transition(vtos, vtos);
1060 // stack: ..., a, b
1061 __ load_ptr(1, rax); // load a
1062 __ push_ptr(rax); // push a
1063 __ load_ptr(1, rax); // load b
1064 __ push_ptr(rax); // push b
1065 // stack: ..., a, b, a, b
1066 }
1069 void TemplateTable::dup2_x1() {
1070 transition(vtos, vtos);
1071 // stack: ..., a, b, c
1072 __ load_ptr( 0, rcx); // load c
1073 __ load_ptr( 1, rax); // load b
1074 __ push_ptr(rax); // push b
1075 __ push_ptr(rcx); // push c
1076 // stack: ..., a, b, c, b, c
1077 __ store_ptr(3, rcx); // store c in b
1078 // stack: ..., a, c, c, b, c
1079 __ load_ptr( 4, rcx); // load a
1080 __ store_ptr(2, rcx); // store a in 2nd c
1081 // stack: ..., a, c, a, b, c
1082 __ store_ptr(4, rax); // store b in a
1083 // stack: ..., b, c, a, b, c
1084 // stack: ..., b, c, a, b, c
1085 }
1088 void TemplateTable::dup2_x2() {
1089 transition(vtos, vtos);
1090 // stack: ..., a, b, c, d
1091 __ load_ptr( 0, rcx); // load d
1092 __ load_ptr( 1, rax); // load c
1093 __ push_ptr(rax); // push c
1094 __ push_ptr(rcx); // push d
1095 // stack: ..., a, b, c, d, c, d
1096 __ load_ptr( 4, rax); // load b
1097 __ store_ptr(2, rax); // store b in d
1098 __ store_ptr(4, rcx); // store d in b
1099 // stack: ..., a, d, c, b, c, d
1100 __ load_ptr( 5, rcx); // load a
1101 __ load_ptr( 3, rax); // load c
1102 __ store_ptr(3, rcx); // store a in c
1103 __ store_ptr(5, rax); // store c in a
1104 // stack: ..., c, d, a, b, c, d
1105 // stack: ..., c, d, a, b, c, d
1106 }
1109 void TemplateTable::swap() {
1110 transition(vtos, vtos);
1111 // stack: ..., a, b
1112 __ load_ptr( 1, rcx); // load a
1113 __ load_ptr( 0, rax); // load b
1114 __ store_ptr(0, rcx); // store a in b
1115 __ store_ptr(1, rax); // store b in a
1116 // stack: ..., b, a
1117 }
1120 void TemplateTable::iop2(Operation op) {
1121 transition(itos, itos);
1122 switch (op) {
1123 case add : __ pop_i(rdx); __ addl (rax, rdx); break;
1124 case sub : __ mov(rdx, rax); __ pop_i(rax); __ subl (rax, rdx); break;
1125 case mul : __ pop_i(rdx); __ imull(rax, rdx); break;
1126 case _and : __ pop_i(rdx); __ andl (rax, rdx); break;
1127 case _or : __ pop_i(rdx); __ orl (rax, rdx); break;
1128 case _xor : __ pop_i(rdx); __ xorl (rax, rdx); break;
1129 case shl : __ mov(rcx, rax); __ pop_i(rax); __ shll (rax); break; // implicit masking of lower 5 bits by Intel shift instr.
1130 case shr : __ mov(rcx, rax); __ pop_i(rax); __ sarl (rax); break; // implicit masking of lower 5 bits by Intel shift instr.
1131 case ushr : __ mov(rcx, rax); __ pop_i(rax); __ shrl (rax); break; // implicit masking of lower 5 bits by Intel shift instr.
1132 default : ShouldNotReachHere();
1133 }
1134 }
1137 void TemplateTable::lop2(Operation op) {
1138 transition(ltos, ltos);
1139 __ pop_l(rbx, rcx);
1140 switch (op) {
1141 case add : __ addl(rax, rbx); __ adcl(rdx, rcx); break;
1142 case sub : __ subl(rbx, rax); __ sbbl(rcx, rdx);
1143 __ mov (rax, rbx); __ mov (rdx, rcx); break;
1144 case _and : __ andl(rax, rbx); __ andl(rdx, rcx); break;
1145 case _or : __ orl (rax, rbx); __ orl (rdx, rcx); break;
1146 case _xor : __ xorl(rax, rbx); __ xorl(rdx, rcx); break;
1147 default : ShouldNotReachHere();
1148 }
1149 }
1152 void TemplateTable::idiv() {
1153 transition(itos, itos);
1154 __ mov(rcx, rax);
1155 __ pop_i(rax);
1156 // Note: could xor rax, and rcx and compare with (-1 ^ min_int). If
1157 // they are not equal, one could do a normal division (no correction
1158 // needed), which may speed up this implementation for the common case.
1159 // (see also JVM spec., p.243 & p.271)
1160 __ corrected_idivl(rcx);
1161 }
1164 void TemplateTable::irem() {
1165 transition(itos, itos);
1166 __ mov(rcx, rax);
1167 __ pop_i(rax);
1168 // Note: could xor rax, and rcx and compare with (-1 ^ min_int). If
1169 // they are not equal, one could do a normal division (no correction
1170 // needed), which may speed up this implementation for the common case.
1171 // (see also JVM spec., p.243 & p.271)
1172 __ corrected_idivl(rcx);
1173 __ mov(rax, rdx);
1174 }
1177 void TemplateTable::lmul() {
1178 transition(ltos, ltos);
1179 __ pop_l(rbx, rcx);
1180 __ push(rcx); __ push(rbx);
1181 __ push(rdx); __ push(rax);
1182 __ lmul(2 * wordSize, 0);
1183 __ addptr(rsp, 4 * wordSize); // take off temporaries
1184 }
1187 void TemplateTable::ldiv() {
1188 transition(ltos, ltos);
1189 __ pop_l(rbx, rcx);
1190 __ push(rcx); __ push(rbx);
1191 __ push(rdx); __ push(rax);
1192 // check if y = 0
1193 __ orl(rax, rdx);
1194 __ jump_cc(Assembler::zero,
1195 ExternalAddress(Interpreter::_throw_ArithmeticException_entry));
1196 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::ldiv));
1197 __ addptr(rsp, 4 * wordSize); // take off temporaries
1198 }
1201 void TemplateTable::lrem() {
1202 transition(ltos, ltos);
1203 __ pop_l(rbx, rcx);
1204 __ push(rcx); __ push(rbx);
1205 __ push(rdx); __ push(rax);
1206 // check if y = 0
1207 __ orl(rax, rdx);
1208 __ jump_cc(Assembler::zero,
1209 ExternalAddress(Interpreter::_throw_ArithmeticException_entry));
1210 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::lrem));
1211 __ addptr(rsp, 4 * wordSize);
1212 }
1215 void TemplateTable::lshl() {
1216 transition(itos, ltos);
1217 __ movl(rcx, rax); // get shift count
1218 __ pop_l(rax, rdx); // get shift value
1219 __ lshl(rdx, rax);
1220 }
1223 void TemplateTable::lshr() {
1224 transition(itos, ltos);
1225 __ mov(rcx, rax); // get shift count
1226 __ pop_l(rax, rdx); // get shift value
1227 __ lshr(rdx, rax, true);
1228 }
1231 void TemplateTable::lushr() {
1232 transition(itos, ltos);
1233 __ mov(rcx, rax); // get shift count
1234 __ pop_l(rax, rdx); // get shift value
1235 __ lshr(rdx, rax);
1236 }
1239 void TemplateTable::fop2(Operation op) {
1240 transition(ftos, ftos);
1241 switch (op) {
1242 case add: __ fadd_s (at_rsp()); break;
1243 case sub: __ fsubr_s(at_rsp()); break;
1244 case mul: __ fmul_s (at_rsp()); break;
1245 case div: __ fdivr_s(at_rsp()); break;
1246 case rem: __ fld_s (at_rsp()); __ fremr(rax); break;
1247 default : ShouldNotReachHere();
1248 }
1249 __ f2ieee();
1250 __ pop(rax); // pop float thing off
1251 }
1254 void TemplateTable::dop2(Operation op) {
1255 transition(dtos, dtos);
1257 switch (op) {
1258 case add: __ fadd_d (at_rsp()); break;
1259 case sub: __ fsubr_d(at_rsp()); break;
1260 case mul: {
1261 Label L_strict;
1262 Label L_join;
1263 const Address access_flags (rcx, methodOopDesc::access_flags_offset());
1264 __ get_method(rcx);
1265 __ movl(rcx, access_flags);
1266 __ testl(rcx, JVM_ACC_STRICT);
1267 __ jccb(Assembler::notZero, L_strict);
1268 __ fmul_d (at_rsp());
1269 __ jmpb(L_join);
1270 __ bind(L_strict);
1271 __ fld_x(ExternalAddress(StubRoutines::addr_fpu_subnormal_bias1()));
1272 __ fmulp();
1273 __ fmul_d (at_rsp());
1274 __ fld_x(ExternalAddress(StubRoutines::addr_fpu_subnormal_bias2()));
1275 __ fmulp();
1276 __ bind(L_join);
1277 break;
1278 }
1279 case div: {
1280 Label L_strict;
1281 Label L_join;
1282 const Address access_flags (rcx, methodOopDesc::access_flags_offset());
1283 __ get_method(rcx);
1284 __ movl(rcx, access_flags);
1285 __ testl(rcx, JVM_ACC_STRICT);
1286 __ jccb(Assembler::notZero, L_strict);
1287 __ fdivr_d(at_rsp());
1288 __ jmp(L_join);
1289 __ bind(L_strict);
1290 __ fld_x(ExternalAddress(StubRoutines::addr_fpu_subnormal_bias1()));
1291 __ fmul_d (at_rsp());
1292 __ fdivrp();
1293 __ fld_x(ExternalAddress(StubRoutines::addr_fpu_subnormal_bias2()));
1294 __ fmulp();
1295 __ bind(L_join);
1296 break;
1297 }
1298 case rem: __ fld_d (at_rsp()); __ fremr(rax); break;
1299 default : ShouldNotReachHere();
1300 }
1301 __ d2ieee();
1302 // Pop double precision number from rsp.
1303 __ pop(rax);
1304 __ pop(rdx);
1305 }
1308 void TemplateTable::ineg() {
1309 transition(itos, itos);
1310 __ negl(rax);
1311 }
1314 void TemplateTable::lneg() {
1315 transition(ltos, ltos);
1316 __ lneg(rdx, rax);
1317 }
1320 void TemplateTable::fneg() {
1321 transition(ftos, ftos);
1322 __ fchs();
1323 }
1326 void TemplateTable::dneg() {
1327 transition(dtos, dtos);
1328 __ fchs();
1329 }
1332 void TemplateTable::iinc() {
1333 transition(vtos, vtos);
1334 __ load_signed_byte(rdx, at_bcp(2)); // get constant
1335 locals_index(rbx);
1336 __ addl(iaddress(rbx), rdx);
1337 }
1340 void TemplateTable::wide_iinc() {
1341 transition(vtos, vtos);
1342 __ movl(rdx, at_bcp(4)); // get constant
1343 locals_index_wide(rbx);
1344 __ bswapl(rdx); // swap bytes & sign-extend constant
1345 __ sarl(rdx, 16);
1346 __ addl(iaddress(rbx), rdx);
1347 // Note: should probably use only one movl to get both
1348 // the index and the constant -> fix this
1349 }
1352 void TemplateTable::convert() {
1353 // Checking
1354 #ifdef ASSERT
1355 { TosState tos_in = ilgl;
1356 TosState tos_out = ilgl;
1357 switch (bytecode()) {
1358 case Bytecodes::_i2l: // fall through
1359 case Bytecodes::_i2f: // fall through
1360 case Bytecodes::_i2d: // fall through
1361 case Bytecodes::_i2b: // fall through
1362 case Bytecodes::_i2c: // fall through
1363 case Bytecodes::_i2s: tos_in = itos; break;
1364 case Bytecodes::_l2i: // fall through
1365 case Bytecodes::_l2f: // fall through
1366 case Bytecodes::_l2d: tos_in = ltos; break;
1367 case Bytecodes::_f2i: // fall through
1368 case Bytecodes::_f2l: // fall through
1369 case Bytecodes::_f2d: tos_in = ftos; break;
1370 case Bytecodes::_d2i: // fall through
1371 case Bytecodes::_d2l: // fall through
1372 case Bytecodes::_d2f: tos_in = dtos; break;
1373 default : ShouldNotReachHere();
1374 }
1375 switch (bytecode()) {
1376 case Bytecodes::_l2i: // fall through
1377 case Bytecodes::_f2i: // fall through
1378 case Bytecodes::_d2i: // fall through
1379 case Bytecodes::_i2b: // fall through
1380 case Bytecodes::_i2c: // fall through
1381 case Bytecodes::_i2s: tos_out = itos; break;
1382 case Bytecodes::_i2l: // fall through
1383 case Bytecodes::_f2l: // fall through
1384 case Bytecodes::_d2l: tos_out = ltos; break;
1385 case Bytecodes::_i2f: // fall through
1386 case Bytecodes::_l2f: // fall through
1387 case Bytecodes::_d2f: tos_out = ftos; break;
1388 case Bytecodes::_i2d: // fall through
1389 case Bytecodes::_l2d: // fall through
1390 case Bytecodes::_f2d: tos_out = dtos; break;
1391 default : ShouldNotReachHere();
1392 }
1393 transition(tos_in, tos_out);
1394 }
1395 #endif // ASSERT
1397 // Conversion
1398 // (Note: use push(rcx)/pop(rcx) for 1/2-word stack-ptr manipulation)
1399 switch (bytecode()) {
1400 case Bytecodes::_i2l:
1401 __ extend_sign(rdx, rax);
1402 break;
1403 case Bytecodes::_i2f:
1404 __ push(rax); // store int on tos
1405 __ fild_s(at_rsp()); // load int to ST0
1406 __ f2ieee(); // truncate to float size
1407 __ pop(rcx); // adjust rsp
1408 break;
1409 case Bytecodes::_i2d:
1410 __ push(rax); // add one slot for d2ieee()
1411 __ push(rax); // store int on tos
1412 __ fild_s(at_rsp()); // load int to ST0
1413 __ d2ieee(); // truncate to double size
1414 __ pop(rcx); // adjust rsp
1415 __ pop(rcx);
1416 break;
1417 case Bytecodes::_i2b:
1418 __ shll(rax, 24); // truncate upper 24 bits
1419 __ sarl(rax, 24); // and sign-extend byte
1420 LP64_ONLY(__ movsbl(rax, rax));
1421 break;
1422 case Bytecodes::_i2c:
1423 __ andl(rax, 0xFFFF); // truncate upper 16 bits
1424 LP64_ONLY(__ movzwl(rax, rax));
1425 break;
1426 case Bytecodes::_i2s:
1427 __ shll(rax, 16); // truncate upper 16 bits
1428 __ sarl(rax, 16); // and sign-extend short
1429 LP64_ONLY(__ movswl(rax, rax));
1430 break;
1431 case Bytecodes::_l2i:
1432 /* nothing to do */
1433 break;
1434 case Bytecodes::_l2f:
1435 __ push(rdx); // store long on tos
1436 __ push(rax);
1437 __ fild_d(at_rsp()); // load long to ST0
1438 __ f2ieee(); // truncate to float size
1439 __ pop(rcx); // adjust rsp
1440 __ pop(rcx);
1441 break;
1442 case Bytecodes::_l2d:
1443 __ push(rdx); // store long on tos
1444 __ push(rax);
1445 __ fild_d(at_rsp()); // load long to ST0
1446 __ d2ieee(); // truncate to double size
1447 __ pop(rcx); // adjust rsp
1448 __ pop(rcx);
1449 break;
1450 case Bytecodes::_f2i:
1451 __ push(rcx); // reserve space for argument
1452 __ fstp_s(at_rsp()); // pass float argument on stack
1453 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::f2i), 1);
1454 break;
1455 case Bytecodes::_f2l:
1456 __ push(rcx); // reserve space for argument
1457 __ fstp_s(at_rsp()); // pass float argument on stack
1458 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::f2l), 1);
1459 break;
1460 case Bytecodes::_f2d:
1461 /* nothing to do */
1462 break;
1463 case Bytecodes::_d2i:
1464 __ push(rcx); // reserve space for argument
1465 __ push(rcx);
1466 __ fstp_d(at_rsp()); // pass double argument on stack
1467 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::d2i), 2);
1468 break;
1469 case Bytecodes::_d2l:
1470 __ push(rcx); // reserve space for argument
1471 __ push(rcx);
1472 __ fstp_d(at_rsp()); // pass double argument on stack
1473 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::d2l), 2);
1474 break;
1475 case Bytecodes::_d2f:
1476 __ push(rcx); // reserve space for f2ieee()
1477 __ f2ieee(); // truncate to float size
1478 __ pop(rcx); // adjust rsp
1479 break;
1480 default :
1481 ShouldNotReachHere();
1482 }
1483 }
1486 void TemplateTable::lcmp() {
1487 transition(ltos, itos);
1488 // y = rdx:rax
1489 __ pop_l(rbx, rcx); // get x = rcx:rbx
1490 __ lcmp2int(rcx, rbx, rdx, rax);// rcx := cmp(x, y)
1491 __ mov(rax, rcx);
1492 }
1495 void TemplateTable::float_cmp(bool is_float, int unordered_result) {
1496 if (is_float) {
1497 __ fld_s(at_rsp());
1498 } else {
1499 __ fld_d(at_rsp());
1500 __ pop(rdx);
1501 }
1502 __ pop(rcx);
1503 __ fcmp2int(rax, unordered_result < 0);
1504 }
1507 void TemplateTable::branch(bool is_jsr, bool is_wide) {
1508 __ get_method(rcx); // ECX holds method
1509 __ profile_taken_branch(rax,rbx); // EAX holds updated MDP, EBX holds bumped taken count
1511 const ByteSize be_offset = methodOopDesc::backedge_counter_offset() + InvocationCounter::counter_offset();
1512 const ByteSize inv_offset = methodOopDesc::invocation_counter_offset() + InvocationCounter::counter_offset();
1513 const int method_offset = frame::interpreter_frame_method_offset * wordSize;
1515 // Load up EDX with the branch displacement
1516 __ movl(rdx, at_bcp(1));
1517 __ bswapl(rdx);
1518 if (!is_wide) __ sarl(rdx, 16);
1519 LP64_ONLY(__ movslq(rdx, rdx));
1522 // Handle all the JSR stuff here, then exit.
1523 // It's much shorter and cleaner than intermingling with the
1524 // non-JSR normal-branch stuff occurring below.
1525 if (is_jsr) {
1526 // Pre-load the next target bytecode into EBX
1527 __ load_unsigned_byte(rbx, Address(rsi, rdx, Address::times_1, 0));
1529 // compute return address as bci in rax,
1530 __ lea(rax, at_bcp((is_wide ? 5 : 3) - in_bytes(constMethodOopDesc::codes_offset())));
1531 __ subptr(rax, Address(rcx, methodOopDesc::const_offset()));
1532 // Adjust the bcp in RSI by the displacement in EDX
1533 __ addptr(rsi, rdx);
1534 // Push return address
1535 __ push_i(rax);
1536 // jsr returns vtos
1537 __ dispatch_only_noverify(vtos);
1538 return;
1539 }
1541 // Normal (non-jsr) branch handling
1543 // Adjust the bcp in RSI by the displacement in EDX
1544 __ addptr(rsi, rdx);
1546 assert(UseLoopCounter || !UseOnStackReplacement, "on-stack-replacement requires loop counters");
1547 Label backedge_counter_overflow;
1548 Label profile_method;
1549 Label dispatch;
1550 if (UseLoopCounter) {
1551 // increment backedge counter for backward branches
1552 // rax,: MDO
1553 // rbx,: MDO bumped taken-count
1554 // rcx: method
1555 // rdx: target offset
1556 // rsi: target bcp
1557 // rdi: locals pointer
1558 __ testl(rdx, rdx); // check if forward or backward branch
1559 __ jcc(Assembler::positive, dispatch); // count only if backward branch
1561 if (TieredCompilation) {
1562 Label no_mdo;
1563 int increment = InvocationCounter::count_increment;
1564 int mask = ((1 << Tier0BackedgeNotifyFreqLog) - 1) << InvocationCounter::count_shift;
1565 if (ProfileInterpreter) {
1566 // Are we profiling?
1567 __ movptr(rbx, Address(rcx, in_bytes(methodOopDesc::method_data_offset())));
1568 __ testptr(rbx, rbx);
1569 __ jccb(Assembler::zero, no_mdo);
1570 // Increment the MDO backedge counter
1571 const Address mdo_backedge_counter(rbx, in_bytes(methodDataOopDesc::backedge_counter_offset()) +
1572 in_bytes(InvocationCounter::counter_offset()));
1573 __ increment_mask_and_jump(mdo_backedge_counter, increment, mask,
1574 rax, false, Assembler::zero, &backedge_counter_overflow);
1575 __ jmp(dispatch);
1576 }
1577 __ bind(no_mdo);
1578 // Increment backedge counter in methodOop
1579 __ increment_mask_and_jump(Address(rcx, be_offset), increment, mask,
1580 rax, false, Assembler::zero, &backedge_counter_overflow);
1581 } else {
1582 // increment counter
1583 __ movl(rax, Address(rcx, be_offset)); // load backedge counter
1584 __ incrementl(rax, InvocationCounter::count_increment); // increment counter
1585 __ movl(Address(rcx, be_offset), rax); // store counter
1587 __ movl(rax, Address(rcx, inv_offset)); // load invocation counter
1588 __ andl(rax, InvocationCounter::count_mask_value); // and the status bits
1589 __ addl(rax, Address(rcx, be_offset)); // add both counters
1591 if (ProfileInterpreter) {
1592 // Test to see if we should create a method data oop
1593 __ cmp32(rax,
1594 ExternalAddress((address) &InvocationCounter::InterpreterProfileLimit));
1595 __ jcc(Assembler::less, dispatch);
1597 // if no method data exists, go to profile method
1598 __ test_method_data_pointer(rax, profile_method);
1600 if (UseOnStackReplacement) {
1601 // check for overflow against rbx, which is the MDO taken count
1602 __ cmp32(rbx,
1603 ExternalAddress((address) &InvocationCounter::InterpreterBackwardBranchLimit));
1604 __ jcc(Assembler::below, dispatch);
1606 // When ProfileInterpreter is on, the backedge_count comes from the
1607 // methodDataOop, which value does not get reset on the call to
1608 // frequency_counter_overflow(). To avoid excessive calls to the overflow
1609 // routine while the method is being compiled, add a second test to make
1610 // sure the overflow function is called only once every overflow_frequency.
1611 const int overflow_frequency = 1024;
1612 __ andptr(rbx, overflow_frequency-1);
1613 __ jcc(Assembler::zero, backedge_counter_overflow);
1614 }
1615 } else {
1616 if (UseOnStackReplacement) {
1617 // check for overflow against rax, which is the sum of the counters
1618 __ cmp32(rax,
1619 ExternalAddress((address) &InvocationCounter::InterpreterBackwardBranchLimit));
1620 __ jcc(Assembler::aboveEqual, backedge_counter_overflow);
1622 }
1623 }
1624 }
1625 __ bind(dispatch);
1626 }
1628 // Pre-load the next target bytecode into EBX
1629 __ load_unsigned_byte(rbx, Address(rsi, 0));
1631 // continue with the bytecode @ target
1632 // rax,: return bci for jsr's, unused otherwise
1633 // rbx,: target bytecode
1634 // rsi: target bcp
1635 __ dispatch_only(vtos);
1637 if (UseLoopCounter) {
1638 if (ProfileInterpreter) {
1639 // Out-of-line code to allocate method data oop.
1640 __ bind(profile_method);
1641 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method), rsi);
1642 __ load_unsigned_byte(rbx, Address(rsi, 0)); // restore target bytecode
1643 __ movptr(rcx, Address(rbp, method_offset));
1644 __ movptr(rcx, Address(rcx, in_bytes(methodOopDesc::method_data_offset())));
1645 __ movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), rcx);
1646 __ test_method_data_pointer(rcx, dispatch);
1647 // offset non-null mdp by MDO::data_offset() + IR::profile_method()
1648 __ addptr(rcx, in_bytes(methodDataOopDesc::data_offset()));
1649 __ addptr(rcx, rax);
1650 __ movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), rcx);
1651 __ jmp(dispatch);
1652 }
1654 if (UseOnStackReplacement) {
1656 // invocation counter overflow
1657 __ bind(backedge_counter_overflow);
1658 __ negptr(rdx);
1659 __ addptr(rdx, rsi); // branch bcp
1660 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), rdx);
1661 __ load_unsigned_byte(rbx, Address(rsi, 0)); // restore target bytecode
1663 // rax,: osr nmethod (osr ok) or NULL (osr not possible)
1664 // rbx,: target bytecode
1665 // rdx: scratch
1666 // rdi: locals pointer
1667 // rsi: bcp
1668 __ testptr(rax, rax); // test result
1669 __ jcc(Assembler::zero, dispatch); // no osr if null
1670 // nmethod may have been invalidated (VM may block upon call_VM return)
1671 __ movl(rcx, Address(rax, nmethod::entry_bci_offset()));
1672 __ cmpl(rcx, InvalidOSREntryBci);
1673 __ jcc(Assembler::equal, dispatch);
1675 // We have the address of an on stack replacement routine in rax,
1676 // We need to prepare to execute the OSR method. First we must
1677 // migrate the locals and monitors off of the stack.
1679 __ mov(rbx, rax); // save the nmethod
1681 const Register thread = rcx;
1682 __ get_thread(thread);
1683 call_VM(noreg, CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_begin));
1684 // rax, is OSR buffer, move it to expected parameter location
1685 __ mov(rcx, rax);
1687 // pop the interpreter frame
1688 __ movptr(rdx, Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize)); // get sender sp
1689 __ leave(); // remove frame anchor
1690 __ pop(rdi); // get return address
1691 __ mov(rsp, rdx); // set sp to sender sp
1694 Label skip;
1695 Label chkint;
1697 // The interpreter frame we have removed may be returning to
1698 // either the callstub or the interpreter. Since we will
1699 // now be returning from a compiled (OSR) nmethod we must
1700 // adjust the return to the return were it can handler compiled
1701 // results and clean the fpu stack. This is very similar to
1702 // what a i2c adapter must do.
1704 // Are we returning to the call stub?
1706 __ cmp32(rdi, ExternalAddress(StubRoutines::_call_stub_return_address));
1707 __ jcc(Assembler::notEqual, chkint);
1709 // yes adjust to the specialized call stub return.
1710 assert(StubRoutines::x86::get_call_stub_compiled_return() != NULL, "must be set");
1711 __ lea(rdi, ExternalAddress(StubRoutines::x86::get_call_stub_compiled_return()));
1712 __ jmp(skip);
1714 __ bind(chkint);
1716 // Are we returning to the interpreter? Look for sentinel
1718 __ cmpl(Address(rdi, -2*wordSize), Interpreter::return_sentinel);
1719 __ jcc(Assembler::notEqual, skip);
1721 // Adjust to compiled return back to interpreter
1723 __ movptr(rdi, Address(rdi, -wordSize));
1724 __ bind(skip);
1726 // Align stack pointer for compiled code (note that caller is
1727 // responsible for undoing this fixup by remembering the old SP
1728 // in an rbp,-relative location)
1729 __ andptr(rsp, -(StackAlignmentInBytes));
1731 // push the (possibly adjusted) return address
1732 __ push(rdi);
1734 // and begin the OSR nmethod
1735 __ jmp(Address(rbx, nmethod::osr_entry_point_offset()));
1736 }
1737 }
1738 }
1741 void TemplateTable::if_0cmp(Condition cc) {
1742 transition(itos, vtos);
1743 // assume branch is more often taken than not (loops use backward branches)
1744 Label not_taken;
1745 __ testl(rax, rax);
1746 __ jcc(j_not(cc), not_taken);
1747 branch(false, false);
1748 __ bind(not_taken);
1749 __ profile_not_taken_branch(rax);
1750 }
1753 void TemplateTable::if_icmp(Condition cc) {
1754 transition(itos, vtos);
1755 // assume branch is more often taken than not (loops use backward branches)
1756 Label not_taken;
1757 __ pop_i(rdx);
1758 __ cmpl(rdx, rax);
1759 __ jcc(j_not(cc), not_taken);
1760 branch(false, false);
1761 __ bind(not_taken);
1762 __ profile_not_taken_branch(rax);
1763 }
1766 void TemplateTable::if_nullcmp(Condition cc) {
1767 transition(atos, vtos);
1768 // assume branch is more often taken than not (loops use backward branches)
1769 Label not_taken;
1770 __ testptr(rax, rax);
1771 __ jcc(j_not(cc), not_taken);
1772 branch(false, false);
1773 __ bind(not_taken);
1774 __ profile_not_taken_branch(rax);
1775 }
1778 void TemplateTable::if_acmp(Condition cc) {
1779 transition(atos, vtos);
1780 // assume branch is more often taken than not (loops use backward branches)
1781 Label not_taken;
1782 __ pop_ptr(rdx);
1783 __ cmpptr(rdx, rax);
1784 __ jcc(j_not(cc), not_taken);
1785 branch(false, false);
1786 __ bind(not_taken);
1787 __ profile_not_taken_branch(rax);
1788 }
1791 void TemplateTable::ret() {
1792 transition(vtos, vtos);
1793 locals_index(rbx);
1794 __ movptr(rbx, iaddress(rbx)); // get return bci, compute return bcp
1795 __ profile_ret(rbx, rcx);
1796 __ get_method(rax);
1797 __ movptr(rsi, Address(rax, methodOopDesc::const_offset()));
1798 __ lea(rsi, Address(rsi, rbx, Address::times_1,
1799 constMethodOopDesc::codes_offset()));
1800 __ dispatch_next(vtos);
1801 }
1804 void TemplateTable::wide_ret() {
1805 transition(vtos, vtos);
1806 locals_index_wide(rbx);
1807 __ movptr(rbx, iaddress(rbx)); // get return bci, compute return bcp
1808 __ profile_ret(rbx, rcx);
1809 __ get_method(rax);
1810 __ movptr(rsi, Address(rax, methodOopDesc::const_offset()));
1811 __ lea(rsi, Address(rsi, rbx, Address::times_1, constMethodOopDesc::codes_offset()));
1812 __ dispatch_next(vtos);
1813 }
1816 void TemplateTable::tableswitch() {
1817 Label default_case, continue_execution;
1818 transition(itos, vtos);
1819 // align rsi
1820 __ lea(rbx, at_bcp(wordSize));
1821 __ andptr(rbx, -wordSize);
1822 // load lo & hi
1823 __ movl(rcx, Address(rbx, 1 * wordSize));
1824 __ movl(rdx, Address(rbx, 2 * wordSize));
1825 __ bswapl(rcx);
1826 __ bswapl(rdx);
1827 // check against lo & hi
1828 __ cmpl(rax, rcx);
1829 __ jccb(Assembler::less, default_case);
1830 __ cmpl(rax, rdx);
1831 __ jccb(Assembler::greater, default_case);
1832 // lookup dispatch offset
1833 __ subl(rax, rcx);
1834 __ movl(rdx, Address(rbx, rax, Address::times_4, 3 * BytesPerInt));
1835 __ profile_switch_case(rax, rbx, rcx);
1836 // continue execution
1837 __ bind(continue_execution);
1838 __ bswapl(rdx);
1839 __ load_unsigned_byte(rbx, Address(rsi, rdx, Address::times_1));
1840 __ addptr(rsi, rdx);
1841 __ dispatch_only(vtos);
1842 // handle default
1843 __ bind(default_case);
1844 __ profile_switch_default(rax);
1845 __ movl(rdx, Address(rbx, 0));
1846 __ jmp(continue_execution);
1847 }
1850 void TemplateTable::lookupswitch() {
1851 transition(itos, itos);
1852 __ stop("lookupswitch bytecode should have been rewritten");
1853 }
1856 void TemplateTable::fast_linearswitch() {
1857 transition(itos, vtos);
1858 Label loop_entry, loop, found, continue_execution;
1859 // bswapl rax, so we can avoid bswapping the table entries
1860 __ bswapl(rax);
1861 // align rsi
1862 __ lea(rbx, at_bcp(wordSize)); // btw: should be able to get rid of this instruction (change offsets below)
1863 __ andptr(rbx, -wordSize);
1864 // set counter
1865 __ movl(rcx, Address(rbx, wordSize));
1866 __ bswapl(rcx);
1867 __ jmpb(loop_entry);
1868 // table search
1869 __ bind(loop);
1870 __ cmpl(rax, Address(rbx, rcx, Address::times_8, 2 * wordSize));
1871 __ jccb(Assembler::equal, found);
1872 __ bind(loop_entry);
1873 __ decrementl(rcx);
1874 __ jcc(Assembler::greaterEqual, loop);
1875 // default case
1876 __ profile_switch_default(rax);
1877 __ movl(rdx, Address(rbx, 0));
1878 __ jmpb(continue_execution);
1879 // entry found -> get offset
1880 __ bind(found);
1881 __ movl(rdx, Address(rbx, rcx, Address::times_8, 3 * wordSize));
1882 __ profile_switch_case(rcx, rax, rbx);
1883 // continue execution
1884 __ bind(continue_execution);
1885 __ bswapl(rdx);
1886 __ load_unsigned_byte(rbx, Address(rsi, rdx, Address::times_1));
1887 __ addptr(rsi, rdx);
1888 __ dispatch_only(vtos);
1889 }
1892 void TemplateTable::fast_binaryswitch() {
1893 transition(itos, vtos);
1894 // Implementation using the following core algorithm:
1895 //
1896 // int binary_search(int key, LookupswitchPair* array, int n) {
1897 // // Binary search according to "Methodik des Programmierens" by
1898 // // Edsger W. Dijkstra and W.H.J. Feijen, Addison Wesley Germany 1985.
1899 // int i = 0;
1900 // int j = n;
1901 // while (i+1 < j) {
1902 // // invariant P: 0 <= i < j <= n and (a[i] <= key < a[j] or Q)
1903 // // with Q: for all i: 0 <= i < n: key < a[i]
1904 // // where a stands for the array and assuming that the (inexisting)
1905 // // element a[n] is infinitely big.
1906 // int h = (i + j) >> 1;
1907 // // i < h < j
1908 // if (key < array[h].fast_match()) {
1909 // j = h;
1910 // } else {
1911 // i = h;
1912 // }
1913 // }
1914 // // R: a[i] <= key < a[i+1] or Q
1915 // // (i.e., if key is within array, i is the correct index)
1916 // return i;
1917 // }
1919 // register allocation
1920 const Register key = rax; // already set (tosca)
1921 const Register array = rbx;
1922 const Register i = rcx;
1923 const Register j = rdx;
1924 const Register h = rdi; // needs to be restored
1925 const Register temp = rsi;
1926 // setup array
1927 __ save_bcp();
1929 __ lea(array, at_bcp(3*wordSize)); // btw: should be able to get rid of this instruction (change offsets below)
1930 __ andptr(array, -wordSize);
1931 // initialize i & j
1932 __ xorl(i, i); // i = 0;
1933 __ movl(j, Address(array, -wordSize)); // j = length(array);
1934 // Convert j into native byteordering
1935 __ bswapl(j);
1936 // and start
1937 Label entry;
1938 __ jmp(entry);
1940 // binary search loop
1941 { Label loop;
1942 __ bind(loop);
1943 // int h = (i + j) >> 1;
1944 __ leal(h, Address(i, j, Address::times_1)); // h = i + j;
1945 __ sarl(h, 1); // h = (i + j) >> 1;
1946 // if (key < array[h].fast_match()) {
1947 // j = h;
1948 // } else {
1949 // i = h;
1950 // }
1951 // Convert array[h].match to native byte-ordering before compare
1952 __ movl(temp, Address(array, h, Address::times_8, 0*wordSize));
1953 __ bswapl(temp);
1954 __ cmpl(key, temp);
1955 if (VM_Version::supports_cmov()) {
1956 __ cmovl(Assembler::less , j, h); // j = h if (key < array[h].fast_match())
1957 __ cmovl(Assembler::greaterEqual, i, h); // i = h if (key >= array[h].fast_match())
1958 } else {
1959 Label set_i, end_of_if;
1960 __ jccb(Assembler::greaterEqual, set_i); // {
1961 __ mov(j, h); // j = h;
1962 __ jmp(end_of_if); // }
1963 __ bind(set_i); // else {
1964 __ mov(i, h); // i = h;
1965 __ bind(end_of_if); // }
1966 }
1967 // while (i+1 < j)
1968 __ bind(entry);
1969 __ leal(h, Address(i, 1)); // i+1
1970 __ cmpl(h, j); // i+1 < j
1971 __ jcc(Assembler::less, loop);
1972 }
1974 // end of binary search, result index is i (must check again!)
1975 Label default_case;
1976 // Convert array[i].match to native byte-ordering before compare
1977 __ movl(temp, Address(array, i, Address::times_8, 0*wordSize));
1978 __ bswapl(temp);
1979 __ cmpl(key, temp);
1980 __ jcc(Assembler::notEqual, default_case);
1982 // entry found -> j = offset
1983 __ movl(j , Address(array, i, Address::times_8, 1*wordSize));
1984 __ profile_switch_case(i, key, array);
1985 __ bswapl(j);
1986 LP64_ONLY(__ movslq(j, j));
1987 __ restore_bcp();
1988 __ restore_locals(); // restore rdi
1989 __ load_unsigned_byte(rbx, Address(rsi, j, Address::times_1));
1991 __ addptr(rsi, j);
1992 __ dispatch_only(vtos);
1994 // default case -> j = default offset
1995 __ bind(default_case);
1996 __ profile_switch_default(i);
1997 __ movl(j, Address(array, -2*wordSize));
1998 __ bswapl(j);
1999 LP64_ONLY(__ movslq(j, j));
2000 __ restore_bcp();
2001 __ restore_locals(); // restore rdi
2002 __ load_unsigned_byte(rbx, Address(rsi, j, Address::times_1));
2003 __ addptr(rsi, j);
2004 __ dispatch_only(vtos);
2005 }
2008 void TemplateTable::_return(TosState state) {
2009 transition(state, state);
2010 assert(_desc->calls_vm(), "inconsistent calls_vm information"); // call in remove_activation
2012 if (_desc->bytecode() == Bytecodes::_return_register_finalizer) {
2013 assert(state == vtos, "only valid state");
2014 __ movptr(rax, aaddress(0));
2015 __ movptr(rdi, Address(rax, oopDesc::klass_offset_in_bytes()));
2016 __ movl(rdi, Address(rdi, Klass::access_flags_offset_in_bytes() + sizeof(oopDesc)));
2017 __ testl(rdi, JVM_ACC_HAS_FINALIZER);
2018 Label skip_register_finalizer;
2019 __ jcc(Assembler::zero, skip_register_finalizer);
2021 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::register_finalizer), rax);
2023 __ bind(skip_register_finalizer);
2024 }
2026 __ remove_activation(state, rsi);
2027 __ jmp(rsi);
2028 }
2031 // ----------------------------------------------------------------------------
2032 // Volatile variables demand their effects be made known to all CPU's in
2033 // order. Store buffers on most chips allow reads & writes to reorder; the
2034 // JMM's ReadAfterWrite.java test fails in -Xint mode without some kind of
2035 // memory barrier (i.e., it's not sufficient that the interpreter does not
2036 // reorder volatile references, the hardware also must not reorder them).
2037 //
2038 // According to the new Java Memory Model (JMM):
2039 // (1) All volatiles are serialized wrt to each other.
2040 // ALSO reads & writes act as aquire & release, so:
2041 // (2) A read cannot let unrelated NON-volatile memory refs that happen after
2042 // the read float up to before the read. It's OK for non-volatile memory refs
2043 // that happen before the volatile read to float down below it.
2044 // (3) Similar a volatile write cannot let unrelated NON-volatile memory refs
2045 // that happen BEFORE the write float down to after the write. It's OK for
2046 // non-volatile memory refs that happen after the volatile write to float up
2047 // before it.
2048 //
2049 // We only put in barriers around volatile refs (they are expensive), not
2050 // _between_ memory refs (that would require us to track the flavor of the
2051 // previous memory refs). Requirements (2) and (3) require some barriers
2052 // before volatile stores and after volatile loads. These nearly cover
2053 // requirement (1) but miss the volatile-store-volatile-load case. This final
2054 // case is placed after volatile-stores although it could just as well go
2055 // before volatile-loads.
2056 void TemplateTable::volatile_barrier(Assembler::Membar_mask_bits order_constraint ) {
2057 // Helper function to insert a is-volatile test and memory barrier
2058 if( !os::is_MP() ) return; // Not needed on single CPU
2059 __ membar(order_constraint);
2060 }
2062 void TemplateTable::resolve_cache_and_index(int byte_no,
2063 Register result,
2064 Register Rcache,
2065 Register index,
2066 size_t index_size) {
2067 Register temp = rbx;
2069 assert_different_registers(result, Rcache, index, temp);
2071 Label resolved;
2072 __ get_cache_and_index_at_bcp(Rcache, index, 1, index_size);
2073 if (byte_no == f1_oop) {
2074 // We are resolved if the f1 field contains a non-null object (CallSite, etc.)
2075 // This kind of CP cache entry does not need to match the flags byte, because
2076 // there is a 1-1 relation between bytecode type and CP entry type.
2077 assert(result != noreg, ""); //else do cmpptr(Address(...), (int32_t) NULL_WORD)
2078 __ movptr(result, Address(Rcache, index, Address::times_ptr, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::f1_offset()));
2079 __ testptr(result, result);
2080 __ jcc(Assembler::notEqual, resolved);
2081 } else {
2082 assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
2083 assert(result == noreg, ""); //else change code for setting result
2084 const int shift_count = (1 + byte_no)*BitsPerByte;
2085 __ movl(temp, Address(Rcache, index, Address::times_4, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::indices_offset()));
2086 __ shrl(temp, shift_count);
2087 // have we resolved this bytecode?
2088 __ andl(temp, 0xFF);
2089 __ cmpl(temp, (int)bytecode());
2090 __ jcc(Assembler::equal, resolved);
2091 }
2093 // resolve first time through
2094 address entry;
2095 switch (bytecode()) {
2096 case Bytecodes::_getstatic : // fall through
2097 case Bytecodes::_putstatic : // fall through
2098 case Bytecodes::_getfield : // fall through
2099 case Bytecodes::_putfield : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_get_put); break;
2100 case Bytecodes::_invokevirtual : // fall through
2101 case Bytecodes::_invokespecial : // fall through
2102 case Bytecodes::_invokestatic : // fall through
2103 case Bytecodes::_invokeinterface: entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invoke); break;
2104 case Bytecodes::_invokedynamic : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invokedynamic); break;
2105 case Bytecodes::_fast_aldc : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_ldc); break;
2106 case Bytecodes::_fast_aldc_w : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_ldc); break;
2107 default : ShouldNotReachHere(); break;
2108 }
2109 __ movl(temp, (int)bytecode());
2110 __ call_VM(noreg, entry, temp);
2111 // Update registers with resolved info
2112 __ get_cache_and_index_at_bcp(Rcache, index, 1, index_size);
2113 if (result != noreg)
2114 __ movptr(result, Address(Rcache, index, Address::times_ptr, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::f1_offset()));
2115 __ bind(resolved);
2116 }
2119 // The cache and index registers must be set before call
2120 void TemplateTable::load_field_cp_cache_entry(Register obj,
2121 Register cache,
2122 Register index,
2123 Register off,
2124 Register flags,
2125 bool is_static = false) {
2126 assert_different_registers(cache, index, flags, off);
2128 ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
2129 // Field offset
2130 __ movptr(off, Address(cache, index, Address::times_ptr,
2131 in_bytes(cp_base_offset + ConstantPoolCacheEntry::f2_offset())));
2132 // Flags
2133 __ movl(flags, Address(cache, index, Address::times_ptr,
2134 in_bytes(cp_base_offset + ConstantPoolCacheEntry::flags_offset())));
2136 // klass overwrite register
2137 if (is_static) {
2138 __ movptr(obj, Address(cache, index, Address::times_ptr,
2139 in_bytes(cp_base_offset + ConstantPoolCacheEntry::f1_offset())));
2140 }
2141 }
2143 void TemplateTable::load_invoke_cp_cache_entry(int byte_no,
2144 Register method,
2145 Register itable_index,
2146 Register flags,
2147 bool is_invokevirtual,
2148 bool is_invokevfinal /*unused*/,
2149 bool is_invokedynamic) {
2150 // setup registers
2151 const Register cache = rcx;
2152 const Register index = rdx;
2153 assert_different_registers(method, flags);
2154 assert_different_registers(method, cache, index);
2155 assert_different_registers(itable_index, flags);
2156 assert_different_registers(itable_index, cache, index);
2157 // determine constant pool cache field offsets
2158 const int method_offset = in_bytes(
2159 constantPoolCacheOopDesc::base_offset() +
2160 (is_invokevirtual
2161 ? ConstantPoolCacheEntry::f2_offset()
2162 : ConstantPoolCacheEntry::f1_offset()
2163 )
2164 );
2165 const int flags_offset = in_bytes(constantPoolCacheOopDesc::base_offset() +
2166 ConstantPoolCacheEntry::flags_offset());
2167 // access constant pool cache fields
2168 const int index_offset = in_bytes(constantPoolCacheOopDesc::base_offset() +
2169 ConstantPoolCacheEntry::f2_offset());
2171 if (byte_no == f1_oop) {
2172 // Resolved f1_oop goes directly into 'method' register.
2173 assert(is_invokedynamic, "");
2174 resolve_cache_and_index(byte_no, method, cache, index, sizeof(u4));
2175 } else {
2176 resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
2177 __ movptr(method, Address(cache, index, Address::times_ptr, method_offset));
2178 }
2179 if (itable_index != noreg) {
2180 __ movptr(itable_index, Address(cache, index, Address::times_ptr, index_offset));
2181 }
2182 __ movl(flags, Address(cache, index, Address::times_ptr, flags_offset));
2183 }
2186 // The registers cache and index expected to be set before call.
2187 // Correct values of the cache and index registers are preserved.
2188 void TemplateTable::jvmti_post_field_access(Register cache,
2189 Register index,
2190 bool is_static,
2191 bool has_tos) {
2192 if (JvmtiExport::can_post_field_access()) {
2193 // Check to see if a field access watch has been set before we take
2194 // the time to call into the VM.
2195 Label L1;
2196 assert_different_registers(cache, index, rax);
2197 __ mov32(rax, ExternalAddress((address) JvmtiExport::get_field_access_count_addr()));
2198 __ testl(rax,rax);
2199 __ jcc(Assembler::zero, L1);
2201 // cache entry pointer
2202 __ addptr(cache, in_bytes(constantPoolCacheOopDesc::base_offset()));
2203 __ shll(index, LogBytesPerWord);
2204 __ addptr(cache, index);
2205 if (is_static) {
2206 __ xorptr(rax, rax); // NULL object reference
2207 } else {
2208 __ pop(atos); // Get the object
2209 __ verify_oop(rax);
2210 __ push(atos); // Restore stack state
2211 }
2212 // rax,: object pointer or NULL
2213 // cache: cache entry pointer
2214 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access),
2215 rax, cache);
2216 __ get_cache_and_index_at_bcp(cache, index, 1);
2217 __ bind(L1);
2218 }
2219 }
2221 void TemplateTable::pop_and_check_object(Register r) {
2222 __ pop_ptr(r);
2223 __ null_check(r); // for field access must check obj.
2224 __ verify_oop(r);
2225 }
2227 void TemplateTable::getfield_or_static(int byte_no, bool is_static) {
2228 transition(vtos, vtos);
2230 const Register cache = rcx;
2231 const Register index = rdx;
2232 const Register obj = rcx;
2233 const Register off = rbx;
2234 const Register flags = rax;
2236 resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
2237 jvmti_post_field_access(cache, index, is_static, false);
2238 load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
2240 if (!is_static) pop_and_check_object(obj);
2242 const Address lo(obj, off, Address::times_1, 0*wordSize);
2243 const Address hi(obj, off, Address::times_1, 1*wordSize);
2245 Label Done, notByte, notInt, notShort, notChar, notLong, notFloat, notObj, notDouble;
2247 __ shrl(flags, ConstantPoolCacheEntry::tosBits);
2248 assert(btos == 0, "change code, btos != 0");
2249 // btos
2250 __ andptr(flags, 0x0f);
2251 __ jcc(Assembler::notZero, notByte);
2253 __ load_signed_byte(rax, lo );
2254 __ push(btos);
2255 // Rewrite bytecode to be faster
2256 if (!is_static) {
2257 patch_bytecode(Bytecodes::_fast_bgetfield, rcx, rbx);
2258 }
2259 __ jmp(Done);
2261 __ bind(notByte);
2262 // itos
2263 __ cmpl(flags, itos );
2264 __ jcc(Assembler::notEqual, notInt);
2266 __ movl(rax, lo );
2267 __ push(itos);
2268 // Rewrite bytecode to be faster
2269 if (!is_static) {
2270 patch_bytecode(Bytecodes::_fast_igetfield, rcx, rbx);
2271 }
2272 __ jmp(Done);
2274 __ bind(notInt);
2275 // atos
2276 __ cmpl(flags, atos );
2277 __ jcc(Assembler::notEqual, notObj);
2279 __ movl(rax, lo );
2280 __ push(atos);
2281 if (!is_static) {
2282 patch_bytecode(Bytecodes::_fast_agetfield, rcx, rbx);
2283 }
2284 __ jmp(Done);
2286 __ bind(notObj);
2287 // ctos
2288 __ cmpl(flags, ctos );
2289 __ jcc(Assembler::notEqual, notChar);
2291 __ load_unsigned_short(rax, lo );
2292 __ push(ctos);
2293 if (!is_static) {
2294 patch_bytecode(Bytecodes::_fast_cgetfield, rcx, rbx);
2295 }
2296 __ jmp(Done);
2298 __ bind(notChar);
2299 // stos
2300 __ cmpl(flags, stos );
2301 __ jcc(Assembler::notEqual, notShort);
2303 __ load_signed_short(rax, lo );
2304 __ push(stos);
2305 if (!is_static) {
2306 patch_bytecode(Bytecodes::_fast_sgetfield, rcx, rbx);
2307 }
2308 __ jmp(Done);
2310 __ bind(notShort);
2311 // ltos
2312 __ cmpl(flags, ltos );
2313 __ jcc(Assembler::notEqual, notLong);
2315 // Generate code as if volatile. There just aren't enough registers to
2316 // save that information and this code is faster than the test.
2317 __ fild_d(lo); // Must load atomically
2318 __ subptr(rsp,2*wordSize); // Make space for store
2319 __ fistp_d(Address(rsp,0));
2320 __ pop(rax);
2321 __ pop(rdx);
2323 __ push(ltos);
2324 // Don't rewrite to _fast_lgetfield for potential volatile case.
2325 __ jmp(Done);
2327 __ bind(notLong);
2328 // ftos
2329 __ cmpl(flags, ftos );
2330 __ jcc(Assembler::notEqual, notFloat);
2332 __ fld_s(lo);
2333 __ push(ftos);
2334 if (!is_static) {
2335 patch_bytecode(Bytecodes::_fast_fgetfield, rcx, rbx);
2336 }
2337 __ jmp(Done);
2339 __ bind(notFloat);
2340 // dtos
2341 __ cmpl(flags, dtos );
2342 __ jcc(Assembler::notEqual, notDouble);
2344 __ fld_d(lo);
2345 __ push(dtos);
2346 if (!is_static) {
2347 patch_bytecode(Bytecodes::_fast_dgetfield, rcx, rbx);
2348 }
2349 __ jmpb(Done);
2351 __ bind(notDouble);
2353 __ stop("Bad state");
2355 __ bind(Done);
2356 // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
2357 // volatile_barrier( );
2358 }
2361 void TemplateTable::getfield(int byte_no) {
2362 getfield_or_static(byte_no, false);
2363 }
2366 void TemplateTable::getstatic(int byte_no) {
2367 getfield_or_static(byte_no, true);
2368 }
2370 // The registers cache and index expected to be set before call.
2371 // The function may destroy various registers, just not the cache and index registers.
2372 void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
2374 ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
2376 if (JvmtiExport::can_post_field_modification()) {
2377 // Check to see if a field modification watch has been set before we take
2378 // the time to call into the VM.
2379 Label L1;
2380 assert_different_registers(cache, index, rax);
2381 __ mov32(rax, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr()));
2382 __ testl(rax, rax);
2383 __ jcc(Assembler::zero, L1);
2385 // The cache and index registers have been already set.
2386 // This allows to eliminate this call but the cache and index
2387 // registers have to be correspondingly used after this line.
2388 __ get_cache_and_index_at_bcp(rax, rdx, 1);
2390 if (is_static) {
2391 // Life is simple. Null out the object pointer.
2392 __ xorptr(rbx, rbx);
2393 } else {
2394 // Life is harder. The stack holds the value on top, followed by the object.
2395 // We don't know the size of the value, though; it could be one or two words
2396 // depending on its type. As a result, we must find the type to determine where
2397 // the object is.
2398 Label two_word, valsize_known;
2399 __ movl(rcx, Address(rax, rdx, Address::times_ptr, in_bytes(cp_base_offset +
2400 ConstantPoolCacheEntry::flags_offset())));
2401 __ mov(rbx, rsp);
2402 __ shrl(rcx, ConstantPoolCacheEntry::tosBits);
2403 // Make sure we don't need to mask rcx for tosBits after the above shift
2404 ConstantPoolCacheEntry::verify_tosBits();
2405 __ cmpl(rcx, ltos);
2406 __ jccb(Assembler::equal, two_word);
2407 __ cmpl(rcx, dtos);
2408 __ jccb(Assembler::equal, two_word);
2409 __ addptr(rbx, Interpreter::expr_offset_in_bytes(1)); // one word jvalue (not ltos, dtos)
2410 __ jmpb(valsize_known);
2412 __ bind(two_word);
2413 __ addptr(rbx, Interpreter::expr_offset_in_bytes(2)); // two words jvalue
2415 __ bind(valsize_known);
2416 // setup object pointer
2417 __ movptr(rbx, Address(rbx, 0));
2418 }
2419 // cache entry pointer
2420 __ addptr(rax, in_bytes(cp_base_offset));
2421 __ shll(rdx, LogBytesPerWord);
2422 __ addptr(rax, rdx);
2423 // object (tos)
2424 __ mov(rcx, rsp);
2425 // rbx,: object pointer set up above (NULL if static)
2426 // rax,: cache entry pointer
2427 // rcx: jvalue object on the stack
2428 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification),
2429 rbx, rax, rcx);
2430 __ get_cache_and_index_at_bcp(cache, index, 1);
2431 __ bind(L1);
2432 }
2433 }
2436 void TemplateTable::putfield_or_static(int byte_no, bool is_static) {
2437 transition(vtos, vtos);
2439 const Register cache = rcx;
2440 const Register index = rdx;
2441 const Register obj = rcx;
2442 const Register off = rbx;
2443 const Register flags = rax;
2445 resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
2446 jvmti_post_field_mod(cache, index, is_static);
2447 load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
2449 // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
2450 // volatile_barrier( );
2452 Label notVolatile, Done;
2453 __ movl(rdx, flags);
2454 __ shrl(rdx, ConstantPoolCacheEntry::volatileField);
2455 __ andl(rdx, 0x1);
2457 // field addresses
2458 const Address lo(obj, off, Address::times_1, 0*wordSize);
2459 const Address hi(obj, off, Address::times_1, 1*wordSize);
2461 Label notByte, notInt, notShort, notChar, notLong, notFloat, notObj, notDouble;
2463 __ shrl(flags, ConstantPoolCacheEntry::tosBits);
2464 assert(btos == 0, "change code, btos != 0");
2465 // btos
2466 __ andl(flags, 0x0f);
2467 __ jcc(Assembler::notZero, notByte);
2469 __ pop(btos);
2470 if (!is_static) pop_and_check_object(obj);
2471 __ movb(lo, rax );
2472 if (!is_static) {
2473 patch_bytecode(Bytecodes::_fast_bputfield, rcx, rbx);
2474 }
2475 __ jmp(Done);
2477 __ bind(notByte);
2478 // itos
2479 __ cmpl(flags, itos );
2480 __ jcc(Assembler::notEqual, notInt);
2482 __ pop(itos);
2483 if (!is_static) pop_and_check_object(obj);
2485 __ movl(lo, rax );
2486 if (!is_static) {
2487 patch_bytecode(Bytecodes::_fast_iputfield, rcx, rbx);
2488 }
2489 __ jmp(Done);
2491 __ bind(notInt);
2492 // atos
2493 __ cmpl(flags, atos );
2494 __ jcc(Assembler::notEqual, notObj);
2496 __ pop(atos);
2497 if (!is_static) pop_and_check_object(obj);
2499 do_oop_store(_masm, lo, rax, _bs->kind(), false);
2501 if (!is_static) {
2502 patch_bytecode(Bytecodes::_fast_aputfield, rcx, rbx);
2503 }
2505 __ jmp(Done);
2507 __ bind(notObj);
2508 // ctos
2509 __ cmpl(flags, ctos );
2510 __ jcc(Assembler::notEqual, notChar);
2512 __ pop(ctos);
2513 if (!is_static) pop_and_check_object(obj);
2514 __ movw(lo, rax );
2515 if (!is_static) {
2516 patch_bytecode(Bytecodes::_fast_cputfield, rcx, rbx);
2517 }
2518 __ jmp(Done);
2520 __ bind(notChar);
2521 // stos
2522 __ cmpl(flags, stos );
2523 __ jcc(Assembler::notEqual, notShort);
2525 __ pop(stos);
2526 if (!is_static) pop_and_check_object(obj);
2527 __ movw(lo, rax );
2528 if (!is_static) {
2529 patch_bytecode(Bytecodes::_fast_sputfield, rcx, rbx);
2530 }
2531 __ jmp(Done);
2533 __ bind(notShort);
2534 // ltos
2535 __ cmpl(flags, ltos );
2536 __ jcc(Assembler::notEqual, notLong);
2538 Label notVolatileLong;
2539 __ testl(rdx, rdx);
2540 __ jcc(Assembler::zero, notVolatileLong);
2542 __ pop(ltos); // overwrites rdx, do this after testing volatile.
2543 if (!is_static) pop_and_check_object(obj);
2545 // Replace with real volatile test
2546 __ push(rdx);
2547 __ push(rax); // Must update atomically with FIST
2548 __ fild_d(Address(rsp,0)); // So load into FPU register
2549 __ fistp_d(lo); // and put into memory atomically
2550 __ addptr(rsp, 2*wordSize);
2551 // volatile_barrier();
2552 volatile_barrier(Assembler::Membar_mask_bits(Assembler::StoreLoad |
2553 Assembler::StoreStore));
2554 // Don't rewrite volatile version
2555 __ jmp(notVolatile);
2557 __ bind(notVolatileLong);
2559 __ pop(ltos); // overwrites rdx
2560 if (!is_static) pop_and_check_object(obj);
2561 NOT_LP64(__ movptr(hi, rdx));
2562 __ movptr(lo, rax);
2563 if (!is_static) {
2564 patch_bytecode(Bytecodes::_fast_lputfield, rcx, rbx);
2565 }
2566 __ jmp(notVolatile);
2568 __ bind(notLong);
2569 // ftos
2570 __ cmpl(flags, ftos );
2571 __ jcc(Assembler::notEqual, notFloat);
2573 __ pop(ftos);
2574 if (!is_static) pop_and_check_object(obj);
2575 __ fstp_s(lo);
2576 if (!is_static) {
2577 patch_bytecode(Bytecodes::_fast_fputfield, rcx, rbx);
2578 }
2579 __ jmp(Done);
2581 __ bind(notFloat);
2582 // dtos
2583 __ cmpl(flags, dtos );
2584 __ jcc(Assembler::notEqual, notDouble);
2586 __ pop(dtos);
2587 if (!is_static) pop_and_check_object(obj);
2588 __ fstp_d(lo);
2589 if (!is_static) {
2590 patch_bytecode(Bytecodes::_fast_dputfield, rcx, rbx);
2591 }
2592 __ jmp(Done);
2594 __ bind(notDouble);
2596 __ stop("Bad state");
2598 __ bind(Done);
2600 // Check for volatile store
2601 __ testl(rdx, rdx);
2602 __ jcc(Assembler::zero, notVolatile);
2603 volatile_barrier(Assembler::Membar_mask_bits(Assembler::StoreLoad |
2604 Assembler::StoreStore));
2605 __ bind(notVolatile);
2606 }
2609 void TemplateTable::putfield(int byte_no) {
2610 putfield_or_static(byte_no, false);
2611 }
2614 void TemplateTable::putstatic(int byte_no) {
2615 putfield_or_static(byte_no, true);
2616 }
2618 void TemplateTable::jvmti_post_fast_field_mod() {
2619 if (JvmtiExport::can_post_field_modification()) {
2620 // Check to see if a field modification watch has been set before we take
2621 // the time to call into the VM.
2622 Label L2;
2623 __ mov32(rcx, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr()));
2624 __ testl(rcx,rcx);
2625 __ jcc(Assembler::zero, L2);
2626 __ pop_ptr(rbx); // copy the object pointer from tos
2627 __ verify_oop(rbx);
2628 __ push_ptr(rbx); // put the object pointer back on tos
2629 __ subptr(rsp, sizeof(jvalue)); // add space for a jvalue object
2630 __ mov(rcx, rsp);
2631 __ push_ptr(rbx); // save object pointer so we can steal rbx,
2632 __ xorptr(rbx, rbx);
2633 const Address lo_value(rcx, rbx, Address::times_1, 0*wordSize);
2634 const Address hi_value(rcx, rbx, Address::times_1, 1*wordSize);
2635 switch (bytecode()) { // load values into the jvalue object
2636 case Bytecodes::_fast_bputfield: __ movb(lo_value, rax); break;
2637 case Bytecodes::_fast_sputfield: __ movw(lo_value, rax); break;
2638 case Bytecodes::_fast_cputfield: __ movw(lo_value, rax); break;
2639 case Bytecodes::_fast_iputfield: __ movl(lo_value, rax); break;
2640 case Bytecodes::_fast_lputfield:
2641 NOT_LP64(__ movptr(hi_value, rdx));
2642 __ movptr(lo_value, rax);
2643 break;
2645 // need to call fld_s() after fstp_s() to restore the value for below
2646 case Bytecodes::_fast_fputfield: __ fstp_s(lo_value); __ fld_s(lo_value); break;
2648 // need to call fld_d() after fstp_d() to restore the value for below
2649 case Bytecodes::_fast_dputfield: __ fstp_d(lo_value); __ fld_d(lo_value); break;
2651 // since rcx is not an object we don't call store_check() here
2652 case Bytecodes::_fast_aputfield: __ movptr(lo_value, rax); break;
2654 default: ShouldNotReachHere();
2655 }
2656 __ pop_ptr(rbx); // restore copy of object pointer
2658 // Save rax, and sometimes rdx because call_VM() will clobber them,
2659 // then use them for JVM/DI purposes
2660 __ push(rax);
2661 if (bytecode() == Bytecodes::_fast_lputfield) __ push(rdx);
2662 // access constant pool cache entry
2663 __ get_cache_entry_pointer_at_bcp(rax, rdx, 1);
2664 __ verify_oop(rbx);
2665 // rbx,: object pointer copied above
2666 // rax,: cache entry pointer
2667 // rcx: jvalue object on the stack
2668 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification), rbx, rax, rcx);
2669 if (bytecode() == Bytecodes::_fast_lputfield) __ pop(rdx); // restore high value
2670 __ pop(rax); // restore lower value
2671 __ addptr(rsp, sizeof(jvalue)); // release jvalue object space
2672 __ bind(L2);
2673 }
2674 }
2676 void TemplateTable::fast_storefield(TosState state) {
2677 transition(state, vtos);
2679 ByteSize base = constantPoolCacheOopDesc::base_offset();
2681 jvmti_post_fast_field_mod();
2683 // access constant pool cache
2684 __ get_cache_and_index_at_bcp(rcx, rbx, 1);
2686 // test for volatile with rdx but rdx is tos register for lputfield.
2687 if (bytecode() == Bytecodes::_fast_lputfield) __ push(rdx);
2688 __ movl(rdx, Address(rcx, rbx, Address::times_ptr, in_bytes(base +
2689 ConstantPoolCacheEntry::flags_offset())));
2691 // replace index with field offset from cache entry
2692 __ movptr(rbx, Address(rcx, rbx, Address::times_ptr, in_bytes(base + ConstantPoolCacheEntry::f2_offset())));
2694 // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
2695 // volatile_barrier( );
2697 Label notVolatile, Done;
2698 __ shrl(rdx, ConstantPoolCacheEntry::volatileField);
2699 __ andl(rdx, 0x1);
2700 // Check for volatile store
2701 __ testl(rdx, rdx);
2702 __ jcc(Assembler::zero, notVolatile);
2704 if (bytecode() == Bytecodes::_fast_lputfield) __ pop(rdx);
2706 // Get object from stack
2707 pop_and_check_object(rcx);
2709 // field addresses
2710 const Address lo(rcx, rbx, Address::times_1, 0*wordSize);
2711 const Address hi(rcx, rbx, Address::times_1, 1*wordSize);
2713 // access field
2714 switch (bytecode()) {
2715 case Bytecodes::_fast_bputfield: __ movb(lo, rax); break;
2716 case Bytecodes::_fast_sputfield: // fall through
2717 case Bytecodes::_fast_cputfield: __ movw(lo, rax); break;
2718 case Bytecodes::_fast_iputfield: __ movl(lo, rax); break;
2719 case Bytecodes::_fast_lputfield:
2720 NOT_LP64(__ movptr(hi, rdx));
2721 __ movptr(lo, rax);
2722 break;
2723 case Bytecodes::_fast_fputfield: __ fstp_s(lo); break;
2724 case Bytecodes::_fast_dputfield: __ fstp_d(lo); break;
2725 case Bytecodes::_fast_aputfield: {
2726 do_oop_store(_masm, lo, rax, _bs->kind(), false);
2727 break;
2728 }
2729 default:
2730 ShouldNotReachHere();
2731 }
2733 Label done;
2734 volatile_barrier(Assembler::Membar_mask_bits(Assembler::StoreLoad |
2735 Assembler::StoreStore));
2736 // Barriers are so large that short branch doesn't reach!
2737 __ jmp(done);
2739 // Same code as above, but don't need rdx to test for volatile.
2740 __ bind(notVolatile);
2742 if (bytecode() == Bytecodes::_fast_lputfield) __ pop(rdx);
2744 // Get object from stack
2745 pop_and_check_object(rcx);
2747 // access field
2748 switch (bytecode()) {
2749 case Bytecodes::_fast_bputfield: __ movb(lo, rax); break;
2750 case Bytecodes::_fast_sputfield: // fall through
2751 case Bytecodes::_fast_cputfield: __ movw(lo, rax); break;
2752 case Bytecodes::_fast_iputfield: __ movl(lo, rax); break;
2753 case Bytecodes::_fast_lputfield:
2754 NOT_LP64(__ movptr(hi, rdx));
2755 __ movptr(lo, rax);
2756 break;
2757 case Bytecodes::_fast_fputfield: __ fstp_s(lo); break;
2758 case Bytecodes::_fast_dputfield: __ fstp_d(lo); break;
2759 case Bytecodes::_fast_aputfield: {
2760 do_oop_store(_masm, lo, rax, _bs->kind(), false);
2761 break;
2762 }
2763 default:
2764 ShouldNotReachHere();
2765 }
2766 __ bind(done);
2767 }
2770 void TemplateTable::fast_accessfield(TosState state) {
2771 transition(atos, state);
2773 // do the JVMTI work here to avoid disturbing the register state below
2774 if (JvmtiExport::can_post_field_access()) {
2775 // Check to see if a field access watch has been set before we take
2776 // the time to call into the VM.
2777 Label L1;
2778 __ mov32(rcx, ExternalAddress((address) JvmtiExport::get_field_access_count_addr()));
2779 __ testl(rcx,rcx);
2780 __ jcc(Assembler::zero, L1);
2781 // access constant pool cache entry
2782 __ get_cache_entry_pointer_at_bcp(rcx, rdx, 1);
2783 __ push_ptr(rax); // save object pointer before call_VM() clobbers it
2784 __ verify_oop(rax);
2785 // rax,: object pointer copied above
2786 // rcx: cache entry pointer
2787 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), rax, rcx);
2788 __ pop_ptr(rax); // restore object pointer
2789 __ bind(L1);
2790 }
2792 // access constant pool cache
2793 __ get_cache_and_index_at_bcp(rcx, rbx, 1);
2794 // replace index with field offset from cache entry
2795 __ movptr(rbx, Address(rcx,
2796 rbx,
2797 Address::times_ptr,
2798 in_bytes(constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::f2_offset())));
2801 // rax,: object
2802 __ verify_oop(rax);
2803 __ null_check(rax);
2804 // field addresses
2805 const Address lo = Address(rax, rbx, Address::times_1, 0*wordSize);
2806 const Address hi = Address(rax, rbx, Address::times_1, 1*wordSize);
2808 // access field
2809 switch (bytecode()) {
2810 case Bytecodes::_fast_bgetfield: __ movsbl(rax, lo ); break;
2811 case Bytecodes::_fast_sgetfield: __ load_signed_short(rax, lo ); break;
2812 case Bytecodes::_fast_cgetfield: __ load_unsigned_short(rax, lo ); break;
2813 case Bytecodes::_fast_igetfield: __ movl(rax, lo); break;
2814 case Bytecodes::_fast_lgetfield: __ stop("should not be rewritten"); break;
2815 case Bytecodes::_fast_fgetfield: __ fld_s(lo); break;
2816 case Bytecodes::_fast_dgetfield: __ fld_d(lo); break;
2817 case Bytecodes::_fast_agetfield: __ movptr(rax, lo); __ verify_oop(rax); break;
2818 default:
2819 ShouldNotReachHere();
2820 }
2822 // Doug Lea believes this is not needed with current Sparcs(TSO) and Intel(PSO)
2823 // volatile_barrier( );
2824 }
2826 void TemplateTable::fast_xaccess(TosState state) {
2827 transition(vtos, state);
2828 // get receiver
2829 __ movptr(rax, aaddress(0));
2830 // access constant pool cache
2831 __ get_cache_and_index_at_bcp(rcx, rdx, 2);
2832 __ movptr(rbx, Address(rcx,
2833 rdx,
2834 Address::times_ptr,
2835 in_bytes(constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::f2_offset())));
2836 // make sure exception is reported in correct bcp range (getfield is next instruction)
2837 __ increment(rsi);
2838 __ null_check(rax);
2839 const Address lo = Address(rax, rbx, Address::times_1, 0*wordSize);
2840 if (state == itos) {
2841 __ movl(rax, lo);
2842 } else if (state == atos) {
2843 __ movptr(rax, lo);
2844 __ verify_oop(rax);
2845 } else if (state == ftos) {
2846 __ fld_s(lo);
2847 } else {
2848 ShouldNotReachHere();
2849 }
2850 __ decrement(rsi);
2851 }
2855 //----------------------------------------------------------------------------------------------------
2856 // Calls
2858 void TemplateTable::count_calls(Register method, Register temp) {
2859 // implemented elsewhere
2860 ShouldNotReachHere();
2861 }
2864 void TemplateTable::prepare_invoke(Register method, Register index, int byte_no) {
2865 // determine flags
2866 Bytecodes::Code code = bytecode();
2867 const bool is_invokeinterface = code == Bytecodes::_invokeinterface;
2868 const bool is_invokedynamic = code == Bytecodes::_invokedynamic;
2869 const bool is_invokevirtual = code == Bytecodes::_invokevirtual;
2870 const bool is_invokespecial = code == Bytecodes::_invokespecial;
2871 const bool load_receiver = (code != Bytecodes::_invokestatic && code != Bytecodes::_invokedynamic);
2872 const bool receiver_null_check = is_invokespecial;
2873 const bool save_flags = is_invokeinterface || is_invokevirtual;
2874 // setup registers & access constant pool cache
2875 const Register recv = rcx;
2876 const Register flags = rdx;
2877 assert_different_registers(method, index, recv, flags);
2879 // save 'interpreter return address'
2880 __ save_bcp();
2882 load_invoke_cp_cache_entry(byte_no, method, index, flags, is_invokevirtual, false, is_invokedynamic);
2884 // load receiver if needed (note: no return address pushed yet)
2885 if (load_receiver) {
2886 assert(!is_invokedynamic, "");
2887 __ movl(recv, flags);
2888 __ andl(recv, 0xFF);
2889 // recv count is 0 based?
2890 Address recv_addr(rsp, recv, Interpreter::stackElementScale(), -Interpreter::expr_offset_in_bytes(1));
2891 __ movptr(recv, recv_addr);
2892 __ verify_oop(recv);
2893 }
2895 // do null check if needed
2896 if (receiver_null_check) {
2897 __ null_check(recv);
2898 }
2900 if (save_flags) {
2901 __ mov(rsi, flags);
2902 }
2904 // compute return type
2905 __ shrl(flags, ConstantPoolCacheEntry::tosBits);
2906 // Make sure we don't need to mask flags for tosBits after the above shift
2907 ConstantPoolCacheEntry::verify_tosBits();
2908 // load return address
2909 {
2910 address table_addr;
2911 if (is_invokeinterface || is_invokedynamic)
2912 table_addr = (address)Interpreter::return_5_addrs_by_index_table();
2913 else
2914 table_addr = (address)Interpreter::return_3_addrs_by_index_table();
2915 ExternalAddress table(table_addr);
2916 __ movptr(flags, ArrayAddress(table, Address(noreg, flags, Address::times_ptr)));
2917 }
2919 // push return address
2920 __ push(flags);
2922 // Restore flag value from the constant pool cache, and restore rsi
2923 // for later null checks. rsi is the bytecode pointer
2924 if (save_flags) {
2925 __ mov(flags, rsi);
2926 __ restore_bcp();
2927 }
2928 }
2931 void TemplateTable::invokevirtual_helper(Register index, Register recv,
2932 Register flags) {
2934 // Uses temporary registers rax, rdx
2935 assert_different_registers(index, recv, rax, rdx);
2937 // Test for an invoke of a final method
2938 Label notFinal;
2939 __ movl(rax, flags);
2940 __ andl(rax, (1 << ConstantPoolCacheEntry::vfinalMethod));
2941 __ jcc(Assembler::zero, notFinal);
2943 Register method = index; // method must be rbx,
2944 assert(method == rbx, "methodOop must be rbx, for interpreter calling convention");
2946 // do the call - the index is actually the method to call
2947 __ verify_oop(method);
2949 // It's final, need a null check here!
2950 __ null_check(recv);
2952 // profile this call
2953 __ profile_final_call(rax);
2955 __ jump_from_interpreted(method, rax);
2957 __ bind(notFinal);
2959 // get receiver klass
2960 __ null_check(recv, oopDesc::klass_offset_in_bytes());
2961 // Keep recv in rcx for callee expects it there
2962 __ movptr(rax, Address(recv, oopDesc::klass_offset_in_bytes()));
2963 __ verify_oop(rax);
2965 // profile this call
2966 __ profile_virtual_call(rax, rdi, rdx);
2968 // get target methodOop & entry point
2969 const int base = instanceKlass::vtable_start_offset() * wordSize;
2970 assert(vtableEntry::size() * wordSize == 4, "adjust the scaling in the code below");
2971 __ movptr(method, Address(rax, index, Address::times_ptr, base + vtableEntry::method_offset_in_bytes()));
2972 __ jump_from_interpreted(method, rdx);
2973 }
2976 void TemplateTable::invokevirtual(int byte_no) {
2977 transition(vtos, vtos);
2978 assert(byte_no == f2_byte, "use this argument");
2979 prepare_invoke(rbx, noreg, byte_no);
2981 // rbx,: index
2982 // rcx: receiver
2983 // rdx: flags
2985 invokevirtual_helper(rbx, rcx, rdx);
2986 }
2989 void TemplateTable::invokespecial(int byte_no) {
2990 transition(vtos, vtos);
2991 assert(byte_no == f1_byte, "use this argument");
2992 prepare_invoke(rbx, noreg, byte_no);
2993 // do the call
2994 __ verify_oop(rbx);
2995 __ profile_call(rax);
2996 __ jump_from_interpreted(rbx, rax);
2997 }
3000 void TemplateTable::invokestatic(int byte_no) {
3001 transition(vtos, vtos);
3002 assert(byte_no == f1_byte, "use this argument");
3003 prepare_invoke(rbx, noreg, byte_no);
3004 // do the call
3005 __ verify_oop(rbx);
3006 __ profile_call(rax);
3007 __ jump_from_interpreted(rbx, rax);
3008 }
3011 void TemplateTable::fast_invokevfinal(int byte_no) {
3012 transition(vtos, vtos);
3013 assert(byte_no == f2_byte, "use this argument");
3014 __ stop("fast_invokevfinal not used on x86");
3015 }
3018 void TemplateTable::invokeinterface(int byte_no) {
3019 transition(vtos, vtos);
3020 assert(byte_no == f1_byte, "use this argument");
3021 prepare_invoke(rax, rbx, byte_no);
3023 // rax,: Interface
3024 // rbx,: index
3025 // rcx: receiver
3026 // rdx: flags
3028 // Special case of invokeinterface called for virtual method of
3029 // java.lang.Object. See cpCacheOop.cpp for details.
3030 // This code isn't produced by javac, but could be produced by
3031 // another compliant java compiler.
3032 Label notMethod;
3033 __ movl(rdi, rdx);
3034 __ andl(rdi, (1 << ConstantPoolCacheEntry::methodInterface));
3035 __ jcc(Assembler::zero, notMethod);
3037 invokevirtual_helper(rbx, rcx, rdx);
3038 __ bind(notMethod);
3040 // Get receiver klass into rdx - also a null check
3041 __ restore_locals(); // restore rdi
3042 __ movptr(rdx, Address(rcx, oopDesc::klass_offset_in_bytes()));
3043 __ verify_oop(rdx);
3045 // profile this call
3046 __ profile_virtual_call(rdx, rsi, rdi);
3048 Label no_such_interface, no_such_method;
3050 __ lookup_interface_method(// inputs: rec. class, interface, itable index
3051 rdx, rax, rbx,
3052 // outputs: method, scan temp. reg
3053 rbx, rsi,
3054 no_such_interface);
3056 // rbx,: methodOop to call
3057 // rcx: receiver
3058 // Check for abstract method error
3059 // Note: This should be done more efficiently via a throw_abstract_method_error
3060 // interpreter entry point and a conditional jump to it in case of a null
3061 // method.
3062 __ testptr(rbx, rbx);
3063 __ jcc(Assembler::zero, no_such_method);
3065 // do the call
3066 // rcx: receiver
3067 // rbx,: methodOop
3068 __ jump_from_interpreted(rbx, rdx);
3069 __ should_not_reach_here();
3071 // exception handling code follows...
3072 // note: must restore interpreter registers to canonical
3073 // state for exception handling to work correctly!
3075 __ bind(no_such_method);
3076 // throw exception
3077 __ pop(rbx); // pop return address (pushed by prepare_invoke)
3078 __ restore_bcp(); // rsi must be correct for exception handler (was destroyed)
3079 __ restore_locals(); // make sure locals pointer is correct as well (was destroyed)
3080 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError));
3081 // the call_VM checks for exception, so we should never return here.
3082 __ should_not_reach_here();
3084 __ bind(no_such_interface);
3085 // throw exception
3086 __ pop(rbx); // pop return address (pushed by prepare_invoke)
3087 __ restore_bcp(); // rsi must be correct for exception handler (was destroyed)
3088 __ restore_locals(); // make sure locals pointer is correct as well (was destroyed)
3089 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
3090 InterpreterRuntime::throw_IncompatibleClassChangeError));
3091 // the call_VM checks for exception, so we should never return here.
3092 __ should_not_reach_here();
3093 }
3095 void TemplateTable::invokedynamic(int byte_no) {
3096 transition(vtos, vtos);
3098 if (!EnableInvokeDynamic) {
3099 // We should not encounter this bytecode if !EnableInvokeDynamic.
3100 // The verifier will stop it. However, if we get past the verifier,
3101 // this will stop the thread in a reasonable way, without crashing the JVM.
3102 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
3103 InterpreterRuntime::throw_IncompatibleClassChangeError));
3104 // the call_VM checks for exception, so we should never return here.
3105 __ should_not_reach_here();
3106 return;
3107 }
3109 assert(byte_no == f1_oop, "use this argument");
3110 prepare_invoke(rax, rbx, byte_no);
3112 // rax: CallSite object (f1)
3113 // rbx: unused (f2)
3114 // rdx: flags (unused)
3116 if (ProfileInterpreter) {
3117 Label L;
3118 // %%% should make a type profile for any invokedynamic that takes a ref argument
3119 // profile this call
3120 __ profile_call(rsi);
3121 }
3123 __ movptr(rcx, Address(rax, __ delayed_value(java_dyn_CallSite::target_offset_in_bytes, rcx)));
3124 __ null_check(rcx);
3125 __ prepare_to_jump_from_interpreted();
3126 __ jump_to_method_handle_entry(rcx, rdx);
3127 }
3129 //----------------------------------------------------------------------------------------------------
3130 // Allocation
3132 void TemplateTable::_new() {
3133 transition(vtos, atos);
3134 __ get_unsigned_2_byte_index_at_bcp(rdx, 1);
3135 Label slow_case;
3136 Label slow_case_no_pop;
3137 Label done;
3138 Label initialize_header;
3139 Label initialize_object; // including clearing the fields
3140 Label allocate_shared;
3142 __ get_cpool_and_tags(rcx, rax);
3144 // Make sure the class we're about to instantiate has been resolved.
3145 // This is done before loading instanceKlass to be consistent with the order
3146 // how Constant Pool is updated (see constantPoolOopDesc::klass_at_put)
3147 const int tags_offset = typeArrayOopDesc::header_size(T_BYTE) * wordSize;
3148 __ cmpb(Address(rax, rdx, Address::times_1, tags_offset), JVM_CONSTANT_Class);
3149 __ jcc(Assembler::notEqual, slow_case_no_pop);
3151 // get instanceKlass
3152 __ movptr(rcx, Address(rcx, rdx, Address::times_ptr, sizeof(constantPoolOopDesc)));
3153 __ push(rcx); // save the contexts of klass for initializing the header
3155 // make sure klass is initialized & doesn't have finalizer
3156 // make sure klass is fully initialized
3157 __ cmpl(Address(rcx, instanceKlass::init_state_offset_in_bytes() + sizeof(oopDesc)), instanceKlass::fully_initialized);
3158 __ jcc(Assembler::notEqual, slow_case);
3160 // get instance_size in instanceKlass (scaled to a count of bytes)
3161 __ movl(rdx, Address(rcx, Klass::layout_helper_offset_in_bytes() + sizeof(oopDesc)));
3162 // test to see if it has a finalizer or is malformed in some way
3163 __ testl(rdx, Klass::_lh_instance_slow_path_bit);
3164 __ jcc(Assembler::notZero, slow_case);
3166 //
3167 // Allocate the instance
3168 // 1) Try to allocate in the TLAB
3169 // 2) if fail and the object is large allocate in the shared Eden
3170 // 3) if the above fails (or is not applicable), go to a slow case
3171 // (creates a new TLAB, etc.)
3173 const bool allow_shared_alloc =
3174 Universe::heap()->supports_inline_contig_alloc() && !CMSIncrementalMode;
3176 if (UseTLAB) {
3177 const Register thread = rcx;
3179 __ get_thread(thread);
3180 __ movptr(rax, Address(thread, in_bytes(JavaThread::tlab_top_offset())));
3181 __ lea(rbx, Address(rax, rdx, Address::times_1));
3182 __ cmpptr(rbx, Address(thread, in_bytes(JavaThread::tlab_end_offset())));
3183 __ jcc(Assembler::above, allow_shared_alloc ? allocate_shared : slow_case);
3184 __ movptr(Address(thread, in_bytes(JavaThread::tlab_top_offset())), rbx);
3185 if (ZeroTLAB) {
3186 // the fields have been already cleared
3187 __ jmp(initialize_header);
3188 } else {
3189 // initialize both the header and fields
3190 __ jmp(initialize_object);
3191 }
3192 }
3194 // Allocation in the shared Eden, if allowed.
3195 //
3196 // rdx: instance size in bytes
3197 if (allow_shared_alloc) {
3198 __ bind(allocate_shared);
3200 ExternalAddress heap_top((address)Universe::heap()->top_addr());
3202 Label retry;
3203 __ bind(retry);
3204 __ movptr(rax, heap_top);
3205 __ lea(rbx, Address(rax, rdx, Address::times_1));
3206 __ cmpptr(rbx, ExternalAddress((address)Universe::heap()->end_addr()));
3207 __ jcc(Assembler::above, slow_case);
3209 // Compare rax, with the top addr, and if still equal, store the new
3210 // top addr in rbx, at the address of the top addr pointer. Sets ZF if was
3211 // equal, and clears it otherwise. Use lock prefix for atomicity on MPs.
3212 //
3213 // rax,: object begin
3214 // rbx,: object end
3215 // rdx: instance size in bytes
3216 __ locked_cmpxchgptr(rbx, heap_top);
3218 // if someone beat us on the allocation, try again, otherwise continue
3219 __ jcc(Assembler::notEqual, retry);
3220 }
3222 if (UseTLAB || Universe::heap()->supports_inline_contig_alloc()) {
3223 // The object is initialized before the header. If the object size is
3224 // zero, go directly to the header initialization.
3225 __ bind(initialize_object);
3226 __ decrement(rdx, sizeof(oopDesc));
3227 __ jcc(Assembler::zero, initialize_header);
3229 // Initialize topmost object field, divide rdx by 8, check if odd and
3230 // test if zero.
3231 __ xorl(rcx, rcx); // use zero reg to clear memory (shorter code)
3232 __ shrl(rdx, LogBytesPerLong); // divide by 2*oopSize and set carry flag if odd
3234 // rdx must have been multiple of 8
3235 #ifdef ASSERT
3236 // make sure rdx was multiple of 8
3237 Label L;
3238 // Ignore partial flag stall after shrl() since it is debug VM
3239 __ jccb(Assembler::carryClear, L);
3240 __ stop("object size is not multiple of 2 - adjust this code");
3241 __ bind(L);
3242 // rdx must be > 0, no extra check needed here
3243 #endif
3245 // initialize remaining object fields: rdx was a multiple of 8
3246 { Label loop;
3247 __ bind(loop);
3248 __ movptr(Address(rax, rdx, Address::times_8, sizeof(oopDesc) - 1*oopSize), rcx);
3249 NOT_LP64(__ movptr(Address(rax, rdx, Address::times_8, sizeof(oopDesc) - 2*oopSize), rcx));
3250 __ decrement(rdx);
3251 __ jcc(Assembler::notZero, loop);
3252 }
3254 // initialize object header only.
3255 __ bind(initialize_header);
3256 if (UseBiasedLocking) {
3257 __ pop(rcx); // get saved klass back in the register.
3258 __ movptr(rbx, Address(rcx, Klass::prototype_header_offset_in_bytes() + klassOopDesc::klass_part_offset_in_bytes()));
3259 __ movptr(Address(rax, oopDesc::mark_offset_in_bytes ()), rbx);
3260 } else {
3261 __ movptr(Address(rax, oopDesc::mark_offset_in_bytes ()),
3262 (int32_t)markOopDesc::prototype()); // header
3263 __ pop(rcx); // get saved klass back in the register.
3264 }
3265 __ movptr(Address(rax, oopDesc::klass_offset_in_bytes()), rcx); // klass
3267 {
3268 SkipIfEqual skip_if(_masm, &DTraceAllocProbes, 0);
3269 // Trigger dtrace event for fastpath
3270 __ push(atos);
3271 __ call_VM_leaf(
3272 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc), rax);
3273 __ pop(atos);
3274 }
3276 __ jmp(done);
3277 }
3279 // slow case
3280 __ bind(slow_case);
3281 __ pop(rcx); // restore stack pointer to what it was when we came in.
3282 __ bind(slow_case_no_pop);
3283 __ get_constant_pool(rax);
3284 __ get_unsigned_2_byte_index_at_bcp(rdx, 1);
3285 call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), rax, rdx);
3287 // continue
3288 __ bind(done);
3289 }
3292 void TemplateTable::newarray() {
3293 transition(itos, atos);
3294 __ push_i(rax); // make sure everything is on the stack
3295 __ load_unsigned_byte(rdx, at_bcp(1));
3296 call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray), rdx, rax);
3297 __ pop_i(rdx); // discard size
3298 }
3301 void TemplateTable::anewarray() {
3302 transition(itos, atos);
3303 __ get_unsigned_2_byte_index_at_bcp(rdx, 1);
3304 __ get_constant_pool(rcx);
3305 call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::anewarray), rcx, rdx, rax);
3306 }
3309 void TemplateTable::arraylength() {
3310 transition(atos, itos);
3311 __ null_check(rax, arrayOopDesc::length_offset_in_bytes());
3312 __ movl(rax, Address(rax, arrayOopDesc::length_offset_in_bytes()));
3313 }
3316 void TemplateTable::checkcast() {
3317 transition(atos, atos);
3318 Label done, is_null, ok_is_subtype, quicked, resolved;
3319 __ testptr(rax, rax); // Object is in EAX
3320 __ jcc(Assembler::zero, is_null);
3322 // Get cpool & tags index
3323 __ get_cpool_and_tags(rcx, rdx); // ECX=cpool, EDX=tags array
3324 __ get_unsigned_2_byte_index_at_bcp(rbx, 1); // EBX=index
3325 // See if bytecode has already been quicked
3326 __ cmpb(Address(rdx, rbx, Address::times_1, typeArrayOopDesc::header_size(T_BYTE) * wordSize), JVM_CONSTANT_Class);
3327 __ jcc(Assembler::equal, quicked);
3329 __ push(atos);
3330 call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc) );
3331 __ pop_ptr(rdx);
3332 __ jmpb(resolved);
3334 // Get superklass in EAX and subklass in EBX
3335 __ bind(quicked);
3336 __ mov(rdx, rax); // Save object in EDX; EAX needed for subtype check
3337 __ movptr(rax, Address(rcx, rbx, Address::times_ptr, sizeof(constantPoolOopDesc)));
3339 __ bind(resolved);
3340 __ movptr(rbx, Address(rdx, oopDesc::klass_offset_in_bytes()));
3342 // Generate subtype check. Blows ECX. Resets EDI. Object in EDX.
3343 // Superklass in EAX. Subklass in EBX.
3344 __ gen_subtype_check( rbx, ok_is_subtype );
3346 // Come here on failure
3347 __ push(rdx);
3348 // object is at TOS
3349 __ jump(ExternalAddress(Interpreter::_throw_ClassCastException_entry));
3351 // Come here on success
3352 __ bind(ok_is_subtype);
3353 __ mov(rax,rdx); // Restore object in EDX
3355 // Collect counts on whether this check-cast sees NULLs a lot or not.
3356 if (ProfileInterpreter) {
3357 __ jmp(done);
3358 __ bind(is_null);
3359 __ profile_null_seen(rcx);
3360 } else {
3361 __ bind(is_null); // same as 'done'
3362 }
3363 __ bind(done);
3364 }
3367 void TemplateTable::instanceof() {
3368 transition(atos, itos);
3369 Label done, is_null, ok_is_subtype, quicked, resolved;
3370 __ testptr(rax, rax);
3371 __ jcc(Assembler::zero, is_null);
3373 // Get cpool & tags index
3374 __ get_cpool_and_tags(rcx, rdx); // ECX=cpool, EDX=tags array
3375 __ get_unsigned_2_byte_index_at_bcp(rbx, 1); // EBX=index
3376 // See if bytecode has already been quicked
3377 __ cmpb(Address(rdx, rbx, Address::times_1, typeArrayOopDesc::header_size(T_BYTE) * wordSize), JVM_CONSTANT_Class);
3378 __ jcc(Assembler::equal, quicked);
3380 __ push(atos);
3381 call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc) );
3382 __ pop_ptr(rdx);
3383 __ movptr(rdx, Address(rdx, oopDesc::klass_offset_in_bytes()));
3384 __ jmp(resolved);
3386 // Get superklass in EAX and subklass in EDX
3387 __ bind(quicked);
3388 __ movptr(rdx, Address(rax, oopDesc::klass_offset_in_bytes()));
3389 __ movptr(rax, Address(rcx, rbx, Address::times_ptr, sizeof(constantPoolOopDesc)));
3391 __ bind(resolved);
3393 // Generate subtype check. Blows ECX. Resets EDI.
3394 // Superklass in EAX. Subklass in EDX.
3395 __ gen_subtype_check( rdx, ok_is_subtype );
3397 // Come here on failure
3398 __ xorl(rax,rax);
3399 __ jmpb(done);
3400 // Come here on success
3401 __ bind(ok_is_subtype);
3402 __ movl(rax, 1);
3404 // Collect counts on whether this test sees NULLs a lot or not.
3405 if (ProfileInterpreter) {
3406 __ jmp(done);
3407 __ bind(is_null);
3408 __ profile_null_seen(rcx);
3409 } else {
3410 __ bind(is_null); // same as 'done'
3411 }
3412 __ bind(done);
3413 // rax, = 0: obj == NULL or obj is not an instanceof the specified klass
3414 // rax, = 1: obj != NULL and obj is an instanceof the specified klass
3415 }
3418 //----------------------------------------------------------------------------------------------------
3419 // Breakpoints
3420 void TemplateTable::_breakpoint() {
3422 // Note: We get here even if we are single stepping..
3423 // jbug inists on setting breakpoints at every bytecode
3424 // even if we are in single step mode.
3426 transition(vtos, vtos);
3428 // get the unpatched byte code
3429 __ get_method(rcx);
3430 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::get_original_bytecode_at), rcx, rsi);
3431 __ mov(rbx, rax);
3433 // post the breakpoint event
3434 __ get_method(rcx);
3435 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::_breakpoint), rcx, rsi);
3437 // complete the execution of original bytecode
3438 __ dispatch_only_normal(vtos);
3439 }
3442 //----------------------------------------------------------------------------------------------------
3443 // Exceptions
3445 void TemplateTable::athrow() {
3446 transition(atos, vtos);
3447 __ null_check(rax);
3448 __ jump(ExternalAddress(Interpreter::throw_exception_entry()));
3449 }
3452 //----------------------------------------------------------------------------------------------------
3453 // Synchronization
3454 //
3455 // Note: monitorenter & exit are symmetric routines; which is reflected
3456 // in the assembly code structure as well
3457 //
3458 // Stack layout:
3459 //
3460 // [expressions ] <--- rsp = expression stack top
3461 // ..
3462 // [expressions ]
3463 // [monitor entry] <--- monitor block top = expression stack bot
3464 // ..
3465 // [monitor entry]
3466 // [frame data ] <--- monitor block bot
3467 // ...
3468 // [saved rbp, ] <--- rbp,
3471 void TemplateTable::monitorenter() {
3472 transition(atos, vtos);
3474 // check for NULL object
3475 __ null_check(rax);
3477 const Address monitor_block_top(rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
3478 const Address monitor_block_bot(rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
3479 const int entry_size = ( frame::interpreter_frame_monitor_size() * wordSize);
3480 Label allocated;
3482 // initialize entry pointer
3483 __ xorl(rdx, rdx); // points to free slot or NULL
3485 // find a free slot in the monitor block (result in rdx)
3486 { Label entry, loop, exit;
3487 __ movptr(rcx, monitor_block_top); // points to current entry, starting with top-most entry
3488 __ lea(rbx, monitor_block_bot); // points to word before bottom of monitor block
3489 __ jmpb(entry);
3491 __ bind(loop);
3492 __ cmpptr(Address(rcx, BasicObjectLock::obj_offset_in_bytes()), (int32_t)NULL_WORD); // check if current entry is used
3494 // TODO - need new func here - kbt
3495 if (VM_Version::supports_cmov()) {
3496 __ cmov(Assembler::equal, rdx, rcx); // if not used then remember entry in rdx
3497 } else {
3498 Label L;
3499 __ jccb(Assembler::notEqual, L);
3500 __ mov(rdx, rcx); // if not used then remember entry in rdx
3501 __ bind(L);
3502 }
3503 __ cmpptr(rax, Address(rcx, BasicObjectLock::obj_offset_in_bytes())); // check if current entry is for same object
3504 __ jccb(Assembler::equal, exit); // if same object then stop searching
3505 __ addptr(rcx, entry_size); // otherwise advance to next entry
3506 __ bind(entry);
3507 __ cmpptr(rcx, rbx); // check if bottom reached
3508 __ jcc(Assembler::notEqual, loop); // if not at bottom then check this entry
3509 __ bind(exit);
3510 }
3512 __ testptr(rdx, rdx); // check if a slot has been found
3513 __ jccb(Assembler::notZero, allocated); // if found, continue with that one
3515 // allocate one if there's no free slot
3516 { Label entry, loop;
3517 // 1. compute new pointers // rsp: old expression stack top
3518 __ movptr(rdx, monitor_block_bot); // rdx: old expression stack bottom
3519 __ subptr(rsp, entry_size); // move expression stack top
3520 __ subptr(rdx, entry_size); // move expression stack bottom
3521 __ mov(rcx, rsp); // set start value for copy loop
3522 __ movptr(monitor_block_bot, rdx); // set new monitor block top
3523 __ jmp(entry);
3524 // 2. move expression stack contents
3525 __ bind(loop);
3526 __ movptr(rbx, Address(rcx, entry_size)); // load expression stack word from old location
3527 __ movptr(Address(rcx, 0), rbx); // and store it at new location
3528 __ addptr(rcx, wordSize); // advance to next word
3529 __ bind(entry);
3530 __ cmpptr(rcx, rdx); // check if bottom reached
3531 __ jcc(Assembler::notEqual, loop); // if not at bottom then copy next word
3532 }
3534 // call run-time routine
3535 // rdx: points to monitor entry
3536 __ bind(allocated);
3538 // Increment bcp to point to the next bytecode, so exception handling for async. exceptions work correctly.
3539 // The object has already been poped from the stack, so the expression stack looks correct.
3540 __ increment(rsi);
3542 __ movptr(Address(rdx, BasicObjectLock::obj_offset_in_bytes()), rax); // store object
3543 __ lock_object(rdx);
3545 // check to make sure this monitor doesn't cause stack overflow after locking
3546 __ save_bcp(); // in case of exception
3547 __ generate_stack_overflow_check(0);
3549 // The bcp has already been incremented. Just need to dispatch to next instruction.
3550 __ dispatch_next(vtos);
3551 }
3554 void TemplateTable::monitorexit() {
3555 transition(atos, vtos);
3557 // check for NULL object
3558 __ null_check(rax);
3560 const Address monitor_block_top(rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
3561 const Address monitor_block_bot(rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
3562 const int entry_size = ( frame::interpreter_frame_monitor_size() * wordSize);
3563 Label found;
3565 // find matching slot
3566 { Label entry, loop;
3567 __ movptr(rdx, monitor_block_top); // points to current entry, starting with top-most entry
3568 __ lea(rbx, monitor_block_bot); // points to word before bottom of monitor block
3569 __ jmpb(entry);
3571 __ bind(loop);
3572 __ cmpptr(rax, Address(rdx, BasicObjectLock::obj_offset_in_bytes())); // check if current entry is for same object
3573 __ jcc(Assembler::equal, found); // if same object then stop searching
3574 __ addptr(rdx, entry_size); // otherwise advance to next entry
3575 __ bind(entry);
3576 __ cmpptr(rdx, rbx); // check if bottom reached
3577 __ jcc(Assembler::notEqual, loop); // if not at bottom then check this entry
3578 }
3580 // error handling. Unlocking was not block-structured
3581 Label end;
3582 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
3583 __ should_not_reach_here();
3585 // call run-time routine
3586 // rcx: points to monitor entry
3587 __ bind(found);
3588 __ push_ptr(rax); // make sure object is on stack (contract with oopMaps)
3589 __ unlock_object(rdx);
3590 __ pop_ptr(rax); // discard object
3591 __ bind(end);
3592 }
3595 //----------------------------------------------------------------------------------------------------
3596 // Wide instructions
3598 void TemplateTable::wide() {
3599 transition(vtos, vtos);
3600 __ load_unsigned_byte(rbx, at_bcp(1));
3601 ExternalAddress wtable((address)Interpreter::_wentry_point);
3602 __ jump(ArrayAddress(wtable, Address(noreg, rbx, Address::times_ptr)));
3603 // Note: the rsi increment step is part of the individual wide bytecode implementations
3604 }
3607 //----------------------------------------------------------------------------------------------------
3608 // Multi arrays
3610 void TemplateTable::multianewarray() {
3611 transition(vtos, atos);
3612 __ load_unsigned_byte(rax, at_bcp(3)); // get number of dimensions
3613 // last dim is on top of stack; we want address of first one:
3614 // first_addr = last_addr + (ndims - 1) * stackElementSize - 1*wordsize
3615 // the latter wordSize to point to the beginning of the array.
3616 __ lea( rax, Address(rsp, rax, Interpreter::stackElementScale(), -wordSize));
3617 call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::multianewarray), rax); // pass in rax,
3618 __ load_unsigned_byte(rbx, at_bcp(3));
3619 __ lea(rsp, Address(rsp, rbx, Interpreter::stackElementScale())); // get rid of counts
3620 }
3622 #endif /* !CC_INTERP */