Tue, 10 Mar 2009 08:52:16 -0700
Merge
1 /*
2 * Copyright 2003-2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
25 #include "incls/_precompiled.incl"
26 #include "incls/_interpreter_x86_64.cpp.incl"
28 #define __ _masm->
30 #ifndef CC_INTERP
32 const int method_offset = frame::interpreter_frame_method_offset * wordSize;
33 const int bci_offset = frame::interpreter_frame_bcx_offset * wordSize;
34 const int locals_offset = frame::interpreter_frame_locals_offset * wordSize;
36 //-----------------------------------------------------------------------------
38 address TemplateInterpreterGenerator::generate_StackOverflowError_handler() {
39 address entry = __ pc();
41 #ifdef ASSERT
42 {
43 Label L;
44 __ lea(rax, Address(rbp,
45 frame::interpreter_frame_monitor_block_top_offset *
46 wordSize));
47 __ cmpptr(rax, rsp); // rax = maximal rsp for current rbp (stack
48 // grows negative)
49 __ jcc(Assembler::aboveEqual, L); // check if frame is complete
50 __ stop ("interpreter frame not set up");
51 __ bind(L);
52 }
53 #endif // ASSERT
54 // Restore bcp under the assumption that the current frame is still
55 // interpreted
56 __ restore_bcp();
58 // expression stack must be empty before entering the VM if an
59 // exception happened
60 __ empty_expression_stack();
61 // throw exception
62 __ call_VM(noreg,
63 CAST_FROM_FN_PTR(address,
64 InterpreterRuntime::throw_StackOverflowError));
65 return entry;
66 }
68 address TemplateInterpreterGenerator::generate_ArrayIndexOutOfBounds_handler(
69 const char* name) {
70 address entry = __ pc();
71 // expression stack must be empty before entering the VM if an
72 // exception happened
73 __ empty_expression_stack();
74 // setup parameters
75 // ??? convention: expect aberrant index in register ebx
76 __ lea(c_rarg1, ExternalAddress((address)name));
77 __ call_VM(noreg,
78 CAST_FROM_FN_PTR(address,
79 InterpreterRuntime::
80 throw_ArrayIndexOutOfBoundsException),
81 c_rarg1, rbx);
82 return entry;
83 }
85 address TemplateInterpreterGenerator::generate_ClassCastException_handler() {
86 address entry = __ pc();
88 // object is at TOS
89 __ pop(c_rarg1);
91 // expression stack must be empty before entering the VM if an
92 // exception happened
93 __ empty_expression_stack();
95 __ call_VM(noreg,
96 CAST_FROM_FN_PTR(address,
97 InterpreterRuntime::
98 throw_ClassCastException),
99 c_rarg1);
100 return entry;
101 }
103 address TemplateInterpreterGenerator::generate_exception_handler_common(
104 const char* name, const char* message, bool pass_oop) {
105 assert(!pass_oop || message == NULL, "either oop or message but not both");
106 address entry = __ pc();
107 if (pass_oop) {
108 // object is at TOS
109 __ pop(c_rarg2);
110 }
111 // expression stack must be empty before entering the VM if an
112 // exception happened
113 __ empty_expression_stack();
114 // setup parameters
115 __ lea(c_rarg1, ExternalAddress((address)name));
116 if (pass_oop) {
117 __ call_VM(rax, CAST_FROM_FN_PTR(address,
118 InterpreterRuntime::
119 create_klass_exception),
120 c_rarg1, c_rarg2);
121 } else {
122 // kind of lame ExternalAddress can't take NULL because
123 // external_word_Relocation will assert.
124 if (message != NULL) {
125 __ lea(c_rarg2, ExternalAddress((address)message));
126 } else {
127 __ movptr(c_rarg2, NULL_WORD);
128 }
129 __ call_VM(rax,
130 CAST_FROM_FN_PTR(address, InterpreterRuntime::create_exception),
131 c_rarg1, c_rarg2);
132 }
133 // throw exception
134 __ jump(ExternalAddress(Interpreter::throw_exception_entry()));
135 return entry;
136 }
139 address TemplateInterpreterGenerator::generate_continuation_for(TosState state) {
140 address entry = __ pc();
141 // NULL last_sp until next java call
142 __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
143 __ dispatch_next(state);
144 return entry;
145 }
148 address TemplateInterpreterGenerator::generate_return_entry_for(TosState state,
149 int step) {
151 // amd64 doesn't need to do anything special about compiled returns
152 // to the interpreter so the code that exists on x86 to place a sentinel
153 // here and the specialized cleanup code is not needed here.
155 address entry = __ pc();
157 // Restore stack bottom in case i2c adjusted stack
158 __ movptr(rsp, Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize));
159 // and NULL it as marker that esp is now tos until next java call
160 __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
162 __ restore_bcp();
163 __ restore_locals();
165 __ get_cache_and_index_at_bcp(rbx, rcx, 1);
166 __ movl(rbx, Address(rbx, rcx,
167 Address::times_8,
168 in_bytes(constantPoolCacheOopDesc::base_offset()) +
169 3 * wordSize));
170 __ andl(rbx, 0xFF);
171 if (TaggedStackInterpreter) __ shll(rbx, 1); // 2 slots per parameter.
172 __ lea(rsp, Address(rsp, rbx, Address::times_8));
173 __ dispatch_next(state, step);
174 return entry;
175 }
178 address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state,
179 int step) {
180 address entry = __ pc();
181 // NULL last_sp until next java call
182 __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
183 __ restore_bcp();
184 __ restore_locals();
185 // handle exceptions
186 {
187 Label L;
188 __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t) NULL_WORD);
189 __ jcc(Assembler::zero, L);
190 __ call_VM(noreg,
191 CAST_FROM_FN_PTR(address,
192 InterpreterRuntime::throw_pending_exception));
193 __ should_not_reach_here();
194 __ bind(L);
195 }
196 __ dispatch_next(state, step);
197 return entry;
198 }
200 int AbstractInterpreter::BasicType_as_index(BasicType type) {
201 int i = 0;
202 switch (type) {
203 case T_BOOLEAN: i = 0; break;
204 case T_CHAR : i = 1; break;
205 case T_BYTE : i = 2; break;
206 case T_SHORT : i = 3; break;
207 case T_INT : i = 4; break;
208 case T_LONG : i = 5; break;
209 case T_VOID : i = 6; break;
210 case T_FLOAT : i = 7; break;
211 case T_DOUBLE : i = 8; break;
212 case T_OBJECT : i = 9; break;
213 case T_ARRAY : i = 9; break;
214 default : ShouldNotReachHere();
215 }
216 assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers,
217 "index out of bounds");
218 return i;
219 }
222 address TemplateInterpreterGenerator::generate_result_handler_for(
223 BasicType type) {
224 address entry = __ pc();
225 switch (type) {
226 case T_BOOLEAN: __ c2bool(rax); break;
227 case T_CHAR : __ movzwl(rax, rax); break;
228 case T_BYTE : __ sign_extend_byte(rax); break;
229 case T_SHORT : __ sign_extend_short(rax); break;
230 case T_INT : /* nothing to do */ break;
231 case T_LONG : /* nothing to do */ break;
232 case T_VOID : /* nothing to do */ break;
233 case T_FLOAT : /* nothing to do */ break;
234 case T_DOUBLE : /* nothing to do */ break;
235 case T_OBJECT :
236 // retrieve result from frame
237 __ movptr(rax, Address(rbp, frame::interpreter_frame_oop_temp_offset*wordSize));
238 // and verify it
239 __ verify_oop(rax);
240 break;
241 default : ShouldNotReachHere();
242 }
243 __ ret(0); // return from result handler
244 return entry;
245 }
247 address TemplateInterpreterGenerator::generate_safept_entry_for(
248 TosState state,
249 address runtime_entry) {
250 address entry = __ pc();
251 __ push(state);
252 __ call_VM(noreg, runtime_entry);
253 __ dispatch_via(vtos, Interpreter::_normal_table.table_for(vtos));
254 return entry;
255 }
259 // Helpers for commoning out cases in the various type of method entries.
260 //
263 // increment invocation count & check for overflow
264 //
265 // Note: checking for negative value instead of overflow
266 // so we have a 'sticky' overflow test
267 //
268 // rbx: method
269 // ecx: invocation counter
270 //
271 void InterpreterGenerator::generate_counter_incr(
272 Label* overflow,
273 Label* profile_method,
274 Label* profile_method_continue) {
276 const Address invocation_counter(rbx,
277 methodOopDesc::invocation_counter_offset() +
278 InvocationCounter::counter_offset());
279 const Address backedge_counter(rbx,
280 methodOopDesc::backedge_counter_offset() +
281 InvocationCounter::counter_offset());
283 if (ProfileInterpreter) { // %%% Merge this into methodDataOop
284 __ incrementl(Address(rbx,
285 methodOopDesc::interpreter_invocation_counter_offset()));
286 }
287 // Update standard invocation counters
288 __ movl(rax, backedge_counter); // load backedge counter
290 __ incrementl(rcx, InvocationCounter::count_increment);
291 __ andl(rax, InvocationCounter::count_mask_value); // mask out the
292 // status bits
294 __ movl(invocation_counter, rcx); // save invocation count
295 __ addl(rcx, rax); // add both counters
297 // profile_method is non-null only for interpreted method so
298 // profile_method != NULL == !native_call
300 if (ProfileInterpreter && profile_method != NULL) {
301 // Test to see if we should create a method data oop
302 __ cmp32(rcx, ExternalAddress((address)&InvocationCounter::InterpreterProfileLimit));
303 __ jcc(Assembler::less, *profile_method_continue);
305 // if no method data exists, go to profile_method
306 __ test_method_data_pointer(rax, *profile_method);
307 }
309 __ cmp32(rcx, ExternalAddress((address)&InvocationCounter::InterpreterInvocationLimit));
310 __ jcc(Assembler::aboveEqual, *overflow);
311 }
313 void InterpreterGenerator::generate_counter_overflow(Label* do_continue) {
315 // Asm interpreter on entry
316 // r14 - locals
317 // r13 - bcp
318 // rbx - method
319 // edx - cpool --- DOES NOT APPEAR TO BE TRUE
320 // rbp - interpreter frame
322 // On return (i.e. jump to entry_point) [ back to invocation of interpreter ]
323 // Everything as it was on entry
324 // rdx is not restored. Doesn't appear to really be set.
326 const Address size_of_parameters(rbx,
327 methodOopDesc::size_of_parameters_offset());
329 // InterpreterRuntime::frequency_counter_overflow takes two
330 // arguments, the first (thread) is passed by call_VM, the second
331 // indicates if the counter overflow occurs at a backwards branch
332 // (NULL bcp). We pass zero for it. The call returns the address
333 // of the verified entry point for the method or NULL if the
334 // compilation did not complete (either went background or bailed
335 // out).
336 __ movl(c_rarg1, 0);
337 __ call_VM(noreg,
338 CAST_FROM_FN_PTR(address,
339 InterpreterRuntime::frequency_counter_overflow),
340 c_rarg1);
342 __ movptr(rbx, Address(rbp, method_offset)); // restore methodOop
343 // Preserve invariant that r13/r14 contain bcp/locals of sender frame
344 // and jump to the interpreted entry.
345 __ jmp(*do_continue, relocInfo::none);
346 }
348 // See if we've got enough room on the stack for locals plus overhead.
349 // The expression stack grows down incrementally, so the normal guard
350 // page mechanism will work for that.
351 //
352 // NOTE: Since the additional locals are also always pushed (wasn't
353 // obvious in generate_method_entry) so the guard should work for them
354 // too.
355 //
356 // Args:
357 // rdx: number of additional locals this frame needs (what we must check)
358 // rbx: methodOop
359 //
360 // Kills:
361 // rax
362 void InterpreterGenerator::generate_stack_overflow_check(void) {
364 // monitor entry size: see picture of stack set
365 // (generate_method_entry) and frame_amd64.hpp
366 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
368 // total overhead size: entry_size + (saved rbp through expr stack
369 // bottom). be sure to change this if you add/subtract anything
370 // to/from the overhead area
371 const int overhead_size =
372 -(frame::interpreter_frame_initial_sp_offset * wordSize) + entry_size;
374 const int page_size = os::vm_page_size();
376 Label after_frame_check;
378 // see if the frame is greater than one page in size. If so,
379 // then we need to verify there is enough stack space remaining
380 // for the additional locals.
381 __ cmpl(rdx, (page_size - overhead_size) / Interpreter::stackElementSize());
382 __ jcc(Assembler::belowEqual, after_frame_check);
384 // compute rsp as if this were going to be the last frame on
385 // the stack before the red zone
387 const Address stack_base(r15_thread, Thread::stack_base_offset());
388 const Address stack_size(r15_thread, Thread::stack_size_offset());
390 // locals + overhead, in bytes
391 __ mov(rax, rdx);
392 __ shlptr(rax, Interpreter::logStackElementSize()); // 2 slots per parameter.
393 __ addptr(rax, overhead_size);
395 #ifdef ASSERT
396 Label stack_base_okay, stack_size_okay;
397 // verify that thread stack base is non-zero
398 __ cmpptr(stack_base, (int32_t)NULL_WORD);
399 __ jcc(Assembler::notEqual, stack_base_okay);
400 __ stop("stack base is zero");
401 __ bind(stack_base_okay);
402 // verify that thread stack size is non-zero
403 __ cmpptr(stack_size, 0);
404 __ jcc(Assembler::notEqual, stack_size_okay);
405 __ stop("stack size is zero");
406 __ bind(stack_size_okay);
407 #endif
409 // Add stack base to locals and subtract stack size
410 __ addptr(rax, stack_base);
411 __ subptr(rax, stack_size);
413 // add in the red and yellow zone sizes
414 __ addptr(rax, (StackRedPages + StackYellowPages) * page_size);
416 // check against the current stack bottom
417 __ cmpptr(rsp, rax);
418 __ jcc(Assembler::above, after_frame_check);
420 __ pop(rax); // get return address
421 __ jump(ExternalAddress(Interpreter::throw_StackOverflowError_entry()));
423 // all done with frame size check
424 __ bind(after_frame_check);
425 }
427 // Allocate monitor and lock method (asm interpreter)
428 //
429 // Args:
430 // rbx: methodOop
431 // r14: locals
432 //
433 // Kills:
434 // rax
435 // c_rarg0, c_rarg1, c_rarg2, c_rarg3, ...(param regs)
436 // rscratch1, rscratch2 (scratch regs)
437 void InterpreterGenerator::lock_method(void) {
438 // synchronize method
439 const Address access_flags(rbx, methodOopDesc::access_flags_offset());
440 const Address monitor_block_top(
441 rbp,
442 frame::interpreter_frame_monitor_block_top_offset * wordSize);
443 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
445 #ifdef ASSERT
446 {
447 Label L;
448 __ movl(rax, access_flags);
449 __ testl(rax, JVM_ACC_SYNCHRONIZED);
450 __ jcc(Assembler::notZero, L);
451 __ stop("method doesn't need synchronization");
452 __ bind(L);
453 }
454 #endif // ASSERT
456 // get synchronization object
457 {
458 const int mirror_offset = klassOopDesc::klass_part_offset_in_bytes() +
459 Klass::java_mirror_offset_in_bytes();
460 Label done;
461 __ movl(rax, access_flags);
462 __ testl(rax, JVM_ACC_STATIC);
463 // get receiver (assume this is frequent case)
464 __ movptr(rax, Address(r14, Interpreter::local_offset_in_bytes(0)));
465 __ jcc(Assembler::zero, done);
466 __ movptr(rax, Address(rbx, methodOopDesc::constants_offset()));
467 __ movptr(rax, Address(rax,
468 constantPoolOopDesc::pool_holder_offset_in_bytes()));
469 __ movptr(rax, Address(rax, mirror_offset));
471 #ifdef ASSERT
472 {
473 Label L;
474 __ testptr(rax, rax);
475 __ jcc(Assembler::notZero, L);
476 __ stop("synchronization object is NULL");
477 __ bind(L);
478 }
479 #endif // ASSERT
481 __ bind(done);
482 }
484 // add space for monitor & lock
485 __ subptr(rsp, entry_size); // add space for a monitor entry
486 __ movptr(monitor_block_top, rsp); // set new monitor block top
487 // store object
488 __ movptr(Address(rsp, BasicObjectLock::obj_offset_in_bytes()), rax);
489 __ movptr(c_rarg1, rsp); // object address
490 __ lock_object(c_rarg1);
491 }
493 // Generate a fixed interpreter frame. This is identical setup for
494 // interpreted methods and for native methods hence the shared code.
495 //
496 // Args:
497 // rax: return address
498 // rbx: methodOop
499 // r14: pointer to locals
500 // r13: sender sp
501 // rdx: cp cache
502 void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) {
503 // initialize fixed part of activation frame
504 __ push(rax); // save return address
505 __ enter(); // save old & set new rbp
506 __ push(r13); // set sender sp
507 __ push((int)NULL_WORD); // leave last_sp as null
508 __ movptr(r13, Address(rbx, methodOopDesc::const_offset())); // get constMethodOop
509 __ lea(r13, Address(r13, constMethodOopDesc::codes_offset())); // get codebase
510 __ push(rbx); // save methodOop
511 if (ProfileInterpreter) {
512 Label method_data_continue;
513 __ movptr(rdx, Address(rbx, in_bytes(methodOopDesc::method_data_offset())));
514 __ testptr(rdx, rdx);
515 __ jcc(Assembler::zero, method_data_continue);
516 __ addptr(rdx, in_bytes(methodDataOopDesc::data_offset()));
517 __ bind(method_data_continue);
518 __ push(rdx); // set the mdp (method data pointer)
519 } else {
520 __ push(0);
521 }
523 __ movptr(rdx, Address(rbx, methodOopDesc::constants_offset()));
524 __ movptr(rdx, Address(rdx, constantPoolOopDesc::cache_offset_in_bytes()));
525 __ push(rdx); // set constant pool cache
526 __ push(r14); // set locals pointer
527 if (native_call) {
528 __ push(0); // no bcp
529 } else {
530 __ push(r13); // set bcp
531 }
532 __ push(0); // reserve word for pointer to expression stack bottom
533 __ movptr(Address(rsp, 0), rsp); // set expression stack bottom
534 }
536 // End of helpers
538 // Various method entries
539 //------------------------------------------------------------------------------------------------------------------------
540 //
541 //
543 // Call an accessor method (assuming it is resolved, otherwise drop
544 // into vanilla (slow path) entry
545 address InterpreterGenerator::generate_accessor_entry(void) {
546 // rbx: methodOop
548 // r13: senderSP must preserver for slow path, set SP to it on fast path
550 address entry_point = __ pc();
551 Label xreturn_path;
553 // do fastpath for resolved accessor methods
554 if (UseFastAccessorMethods) {
555 // Code: _aload_0, _(i|a)getfield, _(i|a)return or any rewrites
556 // thereof; parameter size = 1
557 // Note: We can only use this code if the getfield has been resolved
558 // and if we don't have a null-pointer exception => check for
559 // these conditions first and use slow path if necessary.
560 Label slow_path;
561 // If we need a safepoint check, generate full interpreter entry.
562 __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
563 SafepointSynchronize::_not_synchronized);
565 __ jcc(Assembler::notEqual, slow_path);
566 // rbx: method
567 __ movptr(rax, Address(rsp, wordSize));
569 // check if local 0 != NULL and read field
570 __ testptr(rax, rax);
571 __ jcc(Assembler::zero, slow_path);
573 __ movptr(rdi, Address(rbx, methodOopDesc::constants_offset()));
574 // read first instruction word and extract bytecode @ 1 and index @ 2
575 __ movptr(rdx, Address(rbx, methodOopDesc::const_offset()));
576 __ movl(rdx, Address(rdx, constMethodOopDesc::codes_offset()));
577 // Shift codes right to get the index on the right.
578 // The bytecode fetched looks like <index><0xb4><0x2a>
579 __ shrl(rdx, 2 * BitsPerByte);
580 __ shll(rdx, exact_log2(in_words(ConstantPoolCacheEntry::size())));
581 __ movptr(rdi, Address(rdi, constantPoolOopDesc::cache_offset_in_bytes()));
583 // rax: local 0
584 // rbx: method
585 // rdx: constant pool cache index
586 // rdi: constant pool cache
588 // check if getfield has been resolved and read constant pool cache entry
589 // check the validity of the cache entry by testing whether _indices field
590 // contains Bytecode::_getfield in b1 byte.
591 assert(in_words(ConstantPoolCacheEntry::size()) == 4,
592 "adjust shift below");
593 __ movl(rcx,
594 Address(rdi,
595 rdx,
596 Address::times_8,
597 constantPoolCacheOopDesc::base_offset() +
598 ConstantPoolCacheEntry::indices_offset()));
599 __ shrl(rcx, 2 * BitsPerByte);
600 __ andl(rcx, 0xFF);
601 __ cmpl(rcx, Bytecodes::_getfield);
602 __ jcc(Assembler::notEqual, slow_path);
604 // Note: constant pool entry is not valid before bytecode is resolved
605 __ movptr(rcx,
606 Address(rdi,
607 rdx,
608 Address::times_8,
609 constantPoolCacheOopDesc::base_offset() +
610 ConstantPoolCacheEntry::f2_offset()));
611 // edx: flags
612 __ movl(rdx,
613 Address(rdi,
614 rdx,
615 Address::times_8,
616 constantPoolCacheOopDesc::base_offset() +
617 ConstantPoolCacheEntry::flags_offset()));
619 Label notObj, notInt, notByte, notShort;
620 const Address field_address(rax, rcx, Address::times_1);
622 // Need to differentiate between igetfield, agetfield, bgetfield etc.
623 // because they are different sizes.
624 // Use the type from the constant pool cache
625 __ shrl(rdx, ConstantPoolCacheEntry::tosBits);
626 // Make sure we don't need to mask edx for tosBits after the above shift
627 ConstantPoolCacheEntry::verify_tosBits();
629 __ cmpl(rdx, atos);
630 __ jcc(Assembler::notEqual, notObj);
631 // atos
632 __ load_heap_oop(rax, field_address);
633 __ jmp(xreturn_path);
635 __ bind(notObj);
636 __ cmpl(rdx, itos);
637 __ jcc(Assembler::notEqual, notInt);
638 // itos
639 __ movl(rax, field_address);
640 __ jmp(xreturn_path);
642 __ bind(notInt);
643 __ cmpl(rdx, btos);
644 __ jcc(Assembler::notEqual, notByte);
645 // btos
646 __ load_signed_byte(rax, field_address);
647 __ jmp(xreturn_path);
649 __ bind(notByte);
650 __ cmpl(rdx, stos);
651 __ jcc(Assembler::notEqual, notShort);
652 // stos
653 __ load_signed_short(rax, field_address);
654 __ jmp(xreturn_path);
656 __ bind(notShort);
657 #ifdef ASSERT
658 Label okay;
659 __ cmpl(rdx, ctos);
660 __ jcc(Assembler::equal, okay);
661 __ stop("what type is this?");
662 __ bind(okay);
663 #endif
664 // ctos
665 __ load_unsigned_short(rax, field_address);
667 __ bind(xreturn_path);
669 // _ireturn/_areturn
670 __ pop(rdi);
671 __ mov(rsp, r13);
672 __ jmp(rdi);
673 __ ret(0);
675 // generate a vanilla interpreter entry as the slow path
676 __ bind(slow_path);
677 (void) generate_normal_entry(false);
678 } else {
679 (void) generate_normal_entry(false);
680 }
682 return entry_point;
683 }
685 // Interpreter stub for calling a native method. (asm interpreter)
686 // This sets up a somewhat different looking stack for calling the
687 // native method than the typical interpreter frame setup.
688 address InterpreterGenerator::generate_native_entry(bool synchronized) {
689 // determine code generation flags
690 bool inc_counter = UseCompiler || CountCompiledCalls;
692 // rbx: methodOop
693 // r13: sender sp
695 address entry_point = __ pc();
697 const Address size_of_parameters(rbx, methodOopDesc::
698 size_of_parameters_offset());
699 const Address invocation_counter(rbx, methodOopDesc::
700 invocation_counter_offset() +
701 InvocationCounter::counter_offset());
702 const Address access_flags (rbx, methodOopDesc::access_flags_offset());
704 // get parameter size (always needed)
705 __ load_unsigned_short(rcx, size_of_parameters);
707 // native calls don't need the stack size check since they have no
708 // expression stack and the arguments are already on the stack and
709 // we only add a handful of words to the stack
711 // rbx: methodOop
712 // rcx: size of parameters
713 // r13: sender sp
714 __ pop(rax); // get return address
716 // for natives the size of locals is zero
718 // compute beginning of parameters (r14)
719 if (TaggedStackInterpreter) __ shll(rcx, 1); // 2 slots per parameter.
720 __ lea(r14, Address(rsp, rcx, Address::times_8, -wordSize));
722 // add 2 zero-initialized slots for native calls
723 // initialize result_handler slot
724 __ push((int) NULL_WORD);
725 // slot for oop temp
726 // (static native method holder mirror/jni oop result)
727 __ push((int) NULL_WORD);
729 if (inc_counter) {
730 __ movl(rcx, invocation_counter); // (pre-)fetch invocation count
731 }
733 // initialize fixed part of activation frame
734 generate_fixed_frame(true);
736 // make sure method is native & not abstract
737 #ifdef ASSERT
738 __ movl(rax, access_flags);
739 {
740 Label L;
741 __ testl(rax, JVM_ACC_NATIVE);
742 __ jcc(Assembler::notZero, L);
743 __ stop("tried to execute non-native method as native");
744 __ bind(L);
745 }
746 {
747 Label L;
748 __ testl(rax, JVM_ACC_ABSTRACT);
749 __ jcc(Assembler::zero, L);
750 __ stop("tried to execute abstract method in interpreter");
751 __ bind(L);
752 }
753 #endif
755 // Since at this point in the method invocation the exception handler
756 // would try to exit the monitor of synchronized methods which hasn't
757 // been entered yet, we set the thread local variable
758 // _do_not_unlock_if_synchronized to true. The remove_activation will
759 // check this flag.
761 const Address do_not_unlock_if_synchronized(r15_thread,
762 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
763 __ movbool(do_not_unlock_if_synchronized, true);
765 // increment invocation count & check for overflow
766 Label invocation_counter_overflow;
767 if (inc_counter) {
768 generate_counter_incr(&invocation_counter_overflow, NULL, NULL);
769 }
771 Label continue_after_compile;
772 __ bind(continue_after_compile);
774 bang_stack_shadow_pages(true);
776 // reset the _do_not_unlock_if_synchronized flag
777 __ movbool(do_not_unlock_if_synchronized, false);
779 // check for synchronized methods
780 // Must happen AFTER invocation_counter check and stack overflow check,
781 // so method is not locked if overflows.
782 if (synchronized) {
783 lock_method();
784 } else {
785 // no synchronization necessary
786 #ifdef ASSERT
787 {
788 Label L;
789 __ movl(rax, access_flags);
790 __ testl(rax, JVM_ACC_SYNCHRONIZED);
791 __ jcc(Assembler::zero, L);
792 __ stop("method needs synchronization");
793 __ bind(L);
794 }
795 #endif
796 }
798 // start execution
799 #ifdef ASSERT
800 {
801 Label L;
802 const Address monitor_block_top(rbp,
803 frame::interpreter_frame_monitor_block_top_offset * wordSize);
804 __ movptr(rax, monitor_block_top);
805 __ cmpptr(rax, rsp);
806 __ jcc(Assembler::equal, L);
807 __ stop("broken stack frame setup in interpreter");
808 __ bind(L);
809 }
810 #endif
812 // jvmti support
813 __ notify_method_entry();
815 // work registers
816 const Register method = rbx;
817 const Register t = r11;
819 // allocate space for parameters
820 __ get_method(method);
821 __ verify_oop(method);
822 __ load_unsigned_short(t,
823 Address(method,
824 methodOopDesc::size_of_parameters_offset()));
825 __ shll(t, Interpreter::logStackElementSize());
827 __ subptr(rsp, t);
828 __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows
829 __ andptr(rsp, -16); // must be 16 byte boundary (see amd64 ABI)
831 // get signature handler
832 {
833 Label L;
834 __ movptr(t, Address(method, methodOopDesc::signature_handler_offset()));
835 __ testptr(t, t);
836 __ jcc(Assembler::notZero, L);
837 __ call_VM(noreg,
838 CAST_FROM_FN_PTR(address,
839 InterpreterRuntime::prepare_native_call),
840 method);
841 __ get_method(method);
842 __ movptr(t, Address(method, methodOopDesc::signature_handler_offset()));
843 __ bind(L);
844 }
846 // call signature handler
847 assert(InterpreterRuntime::SignatureHandlerGenerator::from() == r14,
848 "adjust this code");
849 assert(InterpreterRuntime::SignatureHandlerGenerator::to() == rsp,
850 "adjust this code");
851 assert(InterpreterRuntime::SignatureHandlerGenerator::temp() == rscratch1,
852 "adjust this code");
854 // The generated handlers do not touch RBX (the method oop).
855 // However, large signatures cannot be cached and are generated
856 // each time here. The slow-path generator can do a GC on return,
857 // so we must reload it after the call.
858 __ call(t);
859 __ get_method(method); // slow path can do a GC, reload RBX
862 // result handler is in rax
863 // set result handler
864 __ movptr(Address(rbp,
865 (frame::interpreter_frame_result_handler_offset) * wordSize),
866 rax);
868 // pass mirror handle if static call
869 {
870 Label L;
871 const int mirror_offset = klassOopDesc::klass_part_offset_in_bytes() +
872 Klass::java_mirror_offset_in_bytes();
873 __ movl(t, Address(method, methodOopDesc::access_flags_offset()));
874 __ testl(t, JVM_ACC_STATIC);
875 __ jcc(Assembler::zero, L);
876 // get mirror
877 __ movptr(t, Address(method, methodOopDesc::constants_offset()));
878 __ movptr(t, Address(t, constantPoolOopDesc::pool_holder_offset_in_bytes()));
879 __ movptr(t, Address(t, mirror_offset));
880 // copy mirror into activation frame
881 __ movptr(Address(rbp, frame::interpreter_frame_oop_temp_offset * wordSize),
882 t);
883 // pass handle to mirror
884 __ lea(c_rarg1,
885 Address(rbp, frame::interpreter_frame_oop_temp_offset * wordSize));
886 __ bind(L);
887 }
889 // get native function entry point
890 {
891 Label L;
892 __ movptr(rax, Address(method, methodOopDesc::native_function_offset()));
893 ExternalAddress unsatisfied(SharedRuntime::native_method_throw_unsatisfied_link_error_entry());
894 __ movptr(rscratch2, unsatisfied.addr());
895 __ cmpptr(rax, rscratch2);
896 __ jcc(Assembler::notEqual, L);
897 __ call_VM(noreg,
898 CAST_FROM_FN_PTR(address,
899 InterpreterRuntime::prepare_native_call),
900 method);
901 __ get_method(method);
902 __ verify_oop(method);
903 __ movptr(rax, Address(method, methodOopDesc::native_function_offset()));
904 __ bind(L);
905 }
907 // pass JNIEnv
908 __ lea(c_rarg0, Address(r15_thread, JavaThread::jni_environment_offset()));
910 // It is enough that the pc() points into the right code
911 // segment. It does not have to be the correct return pc.
912 __ set_last_Java_frame(rsp, rbp, (address) __ pc());
914 // change thread state
915 #ifdef ASSERT
916 {
917 Label L;
918 __ movl(t, Address(r15_thread, JavaThread::thread_state_offset()));
919 __ cmpl(t, _thread_in_Java);
920 __ jcc(Assembler::equal, L);
921 __ stop("Wrong thread state in native stub");
922 __ bind(L);
923 }
924 #endif
926 // Change state to native
928 __ movl(Address(r15_thread, JavaThread::thread_state_offset()),
929 _thread_in_native);
931 // Call the native method.
932 __ call(rax);
933 // result potentially in rax or xmm0
935 // Depending on runtime options, either restore the MXCSR
936 // register after returning from the JNI Call or verify that
937 // it wasn't changed during -Xcheck:jni.
938 if (RestoreMXCSROnJNICalls) {
939 __ ldmxcsr(ExternalAddress(StubRoutines::x86::mxcsr_std()));
940 }
941 else if (CheckJNICalls) {
942 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::x86::verify_mxcsr_entry())));
943 }
945 // NOTE: The order of these pushes is known to frame::interpreter_frame_result
946 // in order to extract the result of a method call. If the order of these
947 // pushes change or anything else is added to the stack then the code in
948 // interpreter_frame_result must also change.
950 __ push(dtos);
951 __ push(ltos);
953 // change thread state
954 __ movl(Address(r15_thread, JavaThread::thread_state_offset()),
955 _thread_in_native_trans);
957 if (os::is_MP()) {
958 if (UseMembar) {
959 // Force this write out before the read below
960 __ membar(Assembler::Membar_mask_bits(
961 Assembler::LoadLoad | Assembler::LoadStore |
962 Assembler::StoreLoad | Assembler::StoreStore));
963 } else {
964 // Write serialization page so VM thread can do a pseudo remote membar.
965 // We use the current thread pointer to calculate a thread specific
966 // offset to write to within the page. This minimizes bus traffic
967 // due to cache line collision.
968 __ serialize_memory(r15_thread, rscratch2);
969 }
970 }
972 // check for safepoint operation in progress and/or pending suspend requests
973 {
974 Label Continue;
975 __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
976 SafepointSynchronize::_not_synchronized);
978 Label L;
979 __ jcc(Assembler::notEqual, L);
980 __ cmpl(Address(r15_thread, JavaThread::suspend_flags_offset()), 0);
981 __ jcc(Assembler::equal, Continue);
982 __ bind(L);
984 // Don't use call_VM as it will see a possible pending exception
985 // and forward it and never return here preventing us from
986 // clearing _last_native_pc down below. Also can't use
987 // call_VM_leaf either as it will check to see if r13 & r14 are
988 // preserved and correspond to the bcp/locals pointers. So we do a
989 // runtime call by hand.
990 //
991 __ mov(c_rarg0, r15_thread);
992 __ mov(r12, rsp); // remember sp
993 __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows
994 __ andptr(rsp, -16); // align stack as required by ABI
995 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans)));
996 __ mov(rsp, r12); // restore sp
997 __ reinit_heapbase();
998 __ bind(Continue);
999 }
1001 // change thread state
1002 __ movl(Address(r15_thread, JavaThread::thread_state_offset()), _thread_in_Java);
1004 // reset_last_Java_frame
1005 __ reset_last_Java_frame(true, true);
1007 // reset handle block
1008 __ movptr(t, Address(r15_thread, JavaThread::active_handles_offset()));
1009 __ movptr(Address(t, JNIHandleBlock::top_offset_in_bytes()), (int32_t)NULL_WORD);
1011 // If result is an oop unbox and store it in frame where gc will see it
1012 // and result handler will pick it up
1014 {
1015 Label no_oop, store_result;
1016 __ lea(t, ExternalAddress(AbstractInterpreter::result_handler(T_OBJECT)));
1017 __ cmpptr(t, Address(rbp, frame::interpreter_frame_result_handler_offset*wordSize));
1018 __ jcc(Assembler::notEqual, no_oop);
1019 // retrieve result
1020 __ pop(ltos);
1021 __ testptr(rax, rax);
1022 __ jcc(Assembler::zero, store_result);
1023 __ movptr(rax, Address(rax, 0));
1024 __ bind(store_result);
1025 __ movptr(Address(rbp, frame::interpreter_frame_oop_temp_offset*wordSize), rax);
1026 // keep stack depth as expected by pushing oop which will eventually be discarde
1027 __ push(ltos);
1028 __ bind(no_oop);
1029 }
1032 {
1033 Label no_reguard;
1034 __ cmpl(Address(r15_thread, JavaThread::stack_guard_state_offset()),
1035 JavaThread::stack_guard_yellow_disabled);
1036 __ jcc(Assembler::notEqual, no_reguard);
1038 __ pusha(); // XXX only save smashed registers
1039 __ mov(r12, rsp); // remember sp
1040 __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows
1041 __ andptr(rsp, -16); // align stack as required by ABI
1042 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages)));
1043 __ mov(rsp, r12); // restore sp
1044 __ popa(); // XXX only restore smashed registers
1045 __ reinit_heapbase();
1047 __ bind(no_reguard);
1048 }
1051 // The method register is junk from after the thread_in_native transition
1052 // until here. Also can't call_VM until the bcp has been
1053 // restored. Need bcp for throwing exception below so get it now.
1054 __ get_method(method);
1055 __ verify_oop(method);
1057 // restore r13 to have legal interpreter frame, i.e., bci == 0 <=>
1058 // r13 == code_base()
1059 __ movptr(r13, Address(method, methodOopDesc::const_offset())); // get constMethodOop
1060 __ lea(r13, Address(r13, constMethodOopDesc::codes_offset())); // get codebase
1061 // handle exceptions (exception handling will handle unlocking!)
1062 {
1063 Label L;
1064 __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t) NULL_WORD);
1065 __ jcc(Assembler::zero, L);
1066 // Note: At some point we may want to unify this with the code
1067 // used in call_VM_base(); i.e., we should use the
1068 // StubRoutines::forward_exception code. For now this doesn't work
1069 // here because the rsp is not correctly set at this point.
1070 __ MacroAssembler::call_VM(noreg,
1071 CAST_FROM_FN_PTR(address,
1072 InterpreterRuntime::throw_pending_exception));
1073 __ should_not_reach_here();
1074 __ bind(L);
1075 }
1077 // do unlocking if necessary
1078 {
1079 Label L;
1080 __ movl(t, Address(method, methodOopDesc::access_flags_offset()));
1081 __ testl(t, JVM_ACC_SYNCHRONIZED);
1082 __ jcc(Assembler::zero, L);
1083 // the code below should be shared with interpreter macro
1084 // assembler implementation
1085 {
1086 Label unlock;
1087 // BasicObjectLock will be first in list, since this is a
1088 // synchronized method. However, need to check that the object
1089 // has not been unlocked by an explicit monitorexit bytecode.
1090 const Address monitor(rbp,
1091 (intptr_t)(frame::interpreter_frame_initial_sp_offset *
1092 wordSize - sizeof(BasicObjectLock)));
1094 // monitor expect in c_rarg1 for slow unlock path
1095 __ lea(c_rarg1, monitor); // address of first monitor
1097 __ movptr(t, Address(c_rarg1, BasicObjectLock::obj_offset_in_bytes()));
1098 __ testptr(t, t);
1099 __ jcc(Assembler::notZero, unlock);
1101 // Entry already unlocked, need to throw exception
1102 __ MacroAssembler::call_VM(noreg,
1103 CAST_FROM_FN_PTR(address,
1104 InterpreterRuntime::throw_illegal_monitor_state_exception));
1105 __ should_not_reach_here();
1107 __ bind(unlock);
1108 __ unlock_object(c_rarg1);
1109 }
1110 __ bind(L);
1111 }
1113 // jvmti support
1114 // Note: This must happen _after_ handling/throwing any exceptions since
1115 // the exception handler code notifies the runtime of method exits
1116 // too. If this happens before, method entry/exit notifications are
1117 // not properly paired (was bug - gri 11/22/99).
1118 __ notify_method_exit(vtos, InterpreterMacroAssembler::NotifyJVMTI);
1120 // restore potential result in edx:eax, call result handler to
1121 // restore potential result in ST0 & handle result
1123 __ pop(ltos);
1124 __ pop(dtos);
1126 __ movptr(t, Address(rbp,
1127 (frame::interpreter_frame_result_handler_offset) * wordSize));
1128 __ call(t);
1130 // remove activation
1131 __ movptr(t, Address(rbp,
1132 frame::interpreter_frame_sender_sp_offset *
1133 wordSize)); // get sender sp
1134 __ leave(); // remove frame anchor
1135 __ pop(rdi); // get return address
1136 __ mov(rsp, t); // set sp to sender sp
1137 __ jmp(rdi);
1139 if (inc_counter) {
1140 // Handle overflow of counter and compile method
1141 __ bind(invocation_counter_overflow);
1142 generate_counter_overflow(&continue_after_compile);
1143 }
1145 return entry_point;
1146 }
1148 //
1149 // Generic interpreted method entry to (asm) interpreter
1150 //
1151 address InterpreterGenerator::generate_normal_entry(bool synchronized) {
1152 // determine code generation flags
1153 bool inc_counter = UseCompiler || CountCompiledCalls;
1155 // ebx: methodOop
1156 // r13: sender sp
1157 address entry_point = __ pc();
1159 const Address size_of_parameters(rbx,
1160 methodOopDesc::size_of_parameters_offset());
1161 const Address size_of_locals(rbx, methodOopDesc::size_of_locals_offset());
1162 const Address invocation_counter(rbx,
1163 methodOopDesc::invocation_counter_offset() +
1164 InvocationCounter::counter_offset());
1165 const Address access_flags(rbx, methodOopDesc::access_flags_offset());
1167 // get parameter size (always needed)
1168 __ load_unsigned_short(rcx, size_of_parameters);
1170 // rbx: methodOop
1171 // rcx: size of parameters
1172 // r13: sender_sp (could differ from sp+wordSize if we were called via c2i )
1174 __ load_unsigned_short(rdx, size_of_locals); // get size of locals in words
1175 __ subl(rdx, rcx); // rdx = no. of additional locals
1177 // YYY
1178 // __ incrementl(rdx);
1179 // __ andl(rdx, -2);
1181 // see if we've got enough room on the stack for locals plus overhead.
1182 generate_stack_overflow_check();
1184 // get return address
1185 __ pop(rax);
1187 // compute beginning of parameters (r14)
1188 if (TaggedStackInterpreter) __ shll(rcx, 1); // 2 slots per parameter.
1189 __ lea(r14, Address(rsp, rcx, Address::times_8, -wordSize));
1191 // rdx - # of additional locals
1192 // allocate space for locals
1193 // explicitly initialize locals
1194 {
1195 Label exit, loop;
1196 __ testl(rdx, rdx);
1197 __ jcc(Assembler::lessEqual, exit); // do nothing if rdx <= 0
1198 __ bind(loop);
1199 if (TaggedStackInterpreter) __ push((int) NULL_WORD); // push tag
1200 __ push((int) NULL_WORD); // initialize local variables
1201 __ decrementl(rdx); // until everything initialized
1202 __ jcc(Assembler::greater, loop);
1203 __ bind(exit);
1204 }
1206 // (pre-)fetch invocation count
1207 if (inc_counter) {
1208 __ movl(rcx, invocation_counter);
1209 }
1210 // initialize fixed part of activation frame
1211 generate_fixed_frame(false);
1213 // make sure method is not native & not abstract
1214 #ifdef ASSERT
1215 __ movl(rax, access_flags);
1216 {
1217 Label L;
1218 __ testl(rax, JVM_ACC_NATIVE);
1219 __ jcc(Assembler::zero, L);
1220 __ stop("tried to execute native method as non-native");
1221 __ bind(L);
1222 }
1223 {
1224 Label L;
1225 __ testl(rax, JVM_ACC_ABSTRACT);
1226 __ jcc(Assembler::zero, L);
1227 __ stop("tried to execute abstract method in interpreter");
1228 __ bind(L);
1229 }
1230 #endif
1232 // Since at this point in the method invocation the exception
1233 // handler would try to exit the monitor of synchronized methods
1234 // which hasn't been entered yet, we set the thread local variable
1235 // _do_not_unlock_if_synchronized to true. The remove_activation
1236 // will check this flag.
1238 const Address do_not_unlock_if_synchronized(r15_thread,
1239 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
1240 __ movbool(do_not_unlock_if_synchronized, true);
1242 // increment invocation count & check for overflow
1243 Label invocation_counter_overflow;
1244 Label profile_method;
1245 Label profile_method_continue;
1246 if (inc_counter) {
1247 generate_counter_incr(&invocation_counter_overflow,
1248 &profile_method,
1249 &profile_method_continue);
1250 if (ProfileInterpreter) {
1251 __ bind(profile_method_continue);
1252 }
1253 }
1255 Label continue_after_compile;
1256 __ bind(continue_after_compile);
1258 // check for synchronized interpreted methods
1259 bang_stack_shadow_pages(false);
1261 // reset the _do_not_unlock_if_synchronized flag
1262 __ movbool(do_not_unlock_if_synchronized, false);
1264 // check for synchronized methods
1265 // Must happen AFTER invocation_counter check and stack overflow check,
1266 // so method is not locked if overflows.
1267 if (synchronized) {
1268 // Allocate monitor and lock method
1269 lock_method();
1270 } else {
1271 // no synchronization necessary
1272 #ifdef ASSERT
1273 {
1274 Label L;
1275 __ movl(rax, access_flags);
1276 __ testl(rax, JVM_ACC_SYNCHRONIZED);
1277 __ jcc(Assembler::zero, L);
1278 __ stop("method needs synchronization");
1279 __ bind(L);
1280 }
1281 #endif
1282 }
1284 // start execution
1285 #ifdef ASSERT
1286 {
1287 Label L;
1288 const Address monitor_block_top (rbp,
1289 frame::interpreter_frame_monitor_block_top_offset * wordSize);
1290 __ movptr(rax, monitor_block_top);
1291 __ cmpptr(rax, rsp);
1292 __ jcc(Assembler::equal, L);
1293 __ stop("broken stack frame setup in interpreter");
1294 __ bind(L);
1295 }
1296 #endif
1298 // jvmti support
1299 __ notify_method_entry();
1301 __ dispatch_next(vtos);
1303 // invocation counter overflow
1304 if (inc_counter) {
1305 if (ProfileInterpreter) {
1306 // We have decided to profile this method in the interpreter
1307 __ bind(profile_method);
1309 __ call_VM(noreg,
1310 CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method),
1311 r13, true);
1313 __ movptr(rbx, Address(rbp, method_offset)); // restore methodOop
1314 __ movptr(rax, Address(rbx,
1315 in_bytes(methodOopDesc::method_data_offset())));
1316 __ movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize),
1317 rax);
1318 __ test_method_data_pointer(rax, profile_method_continue);
1319 __ addptr(rax, in_bytes(methodDataOopDesc::data_offset()));
1320 __ movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize),
1321 rax);
1322 __ jmp(profile_method_continue);
1323 }
1324 // Handle overflow of counter and compile method
1325 __ bind(invocation_counter_overflow);
1326 generate_counter_overflow(&continue_after_compile);
1327 }
1329 return entry_point;
1330 }
1332 // Entry points
1333 //
1334 // Here we generate the various kind of entries into the interpreter.
1335 // The two main entry type are generic bytecode methods and native
1336 // call method. These both come in synchronized and non-synchronized
1337 // versions but the frame layout they create is very similar. The
1338 // other method entry types are really just special purpose entries
1339 // that are really entry and interpretation all in one. These are for
1340 // trivial methods like accessor, empty, or special math methods.
1341 //
1342 // When control flow reaches any of the entry types for the interpreter
1343 // the following holds ->
1344 //
1345 // Arguments:
1346 //
1347 // rbx: methodOop
1348 //
1349 // Stack layout immediately at entry
1350 //
1351 // [ return address ] <--- rsp
1352 // [ parameter n ]
1353 // ...
1354 // [ parameter 1 ]
1355 // [ expression stack ] (caller's java expression stack)
1357 // Assuming that we don't go to one of the trivial specialized entries
1358 // the stack will look like below when we are ready to execute the
1359 // first bytecode (or call the native routine). The register usage
1360 // will be as the template based interpreter expects (see
1361 // interpreter_amd64.hpp).
1362 //
1363 // local variables follow incoming parameters immediately; i.e.
1364 // the return address is moved to the end of the locals).
1365 //
1366 // [ monitor entry ] <--- rsp
1367 // ...
1368 // [ monitor entry ]
1369 // [ expr. stack bottom ]
1370 // [ saved r13 ]
1371 // [ current r14 ]
1372 // [ methodOop ]
1373 // [ saved ebp ] <--- rbp
1374 // [ return address ]
1375 // [ local variable m ]
1376 // ...
1377 // [ local variable 1 ]
1378 // [ parameter n ]
1379 // ...
1380 // [ parameter 1 ] <--- r14
1382 address AbstractInterpreterGenerator::generate_method_entry(
1383 AbstractInterpreter::MethodKind kind) {
1384 // determine code generation flags
1385 bool synchronized = false;
1386 address entry_point = NULL;
1388 switch (kind) {
1389 case Interpreter::zerolocals : break;
1390 case Interpreter::zerolocals_synchronized: synchronized = true; break;
1391 case Interpreter::native : entry_point = ((InterpreterGenerator*) this)->generate_native_entry(false); break;
1392 case Interpreter::native_synchronized : entry_point = ((InterpreterGenerator*) this)->generate_native_entry(true); break;
1393 case Interpreter::empty : entry_point = ((InterpreterGenerator*) this)->generate_empty_entry(); break;
1394 case Interpreter::accessor : entry_point = ((InterpreterGenerator*) this)->generate_accessor_entry(); break;
1395 case Interpreter::abstract : entry_point = ((InterpreterGenerator*) this)->generate_abstract_entry(); break;
1396 case Interpreter::java_lang_math_sin : break;
1397 case Interpreter::java_lang_math_cos : break;
1398 case Interpreter::java_lang_math_tan : break;
1399 case Interpreter::java_lang_math_abs : break;
1400 case Interpreter::java_lang_math_log : break;
1401 case Interpreter::java_lang_math_log10 : break;
1402 case Interpreter::java_lang_math_sqrt : entry_point = ((InterpreterGenerator*) this)->generate_math_entry(kind); break;
1403 default : ShouldNotReachHere(); break;
1404 }
1406 if (entry_point) {
1407 return entry_point;
1408 }
1410 return ((InterpreterGenerator*) this)->
1411 generate_normal_entry(synchronized);
1412 }
1414 // How much stack a method activation needs in words.
1415 int AbstractInterpreter::size_top_interpreter_activation(methodOop method) {
1416 const int entry_size = frame::interpreter_frame_monitor_size();
1418 // total overhead size: entry_size + (saved rbp thru expr stack
1419 // bottom). be sure to change this if you add/subtract anything
1420 // to/from the overhead area
1421 const int overhead_size =
1422 -(frame::interpreter_frame_initial_sp_offset) + entry_size;
1424 const int stub_code = frame::entry_frame_after_call_words;
1425 const int method_stack = (method->max_locals() + method->max_stack()) *
1426 Interpreter::stackElementWords();
1427 return (overhead_size + method_stack + stub_code);
1428 }
1430 int AbstractInterpreter::layout_activation(methodOop method,
1431 int tempcount,
1432 int popframe_extra_args,
1433 int moncount,
1434 int callee_param_count,
1435 int callee_locals,
1436 frame* caller,
1437 frame* interpreter_frame,
1438 bool is_top_frame) {
1439 // Note: This calculation must exactly parallel the frame setup
1440 // in AbstractInterpreterGenerator::generate_method_entry.
1441 // If interpreter_frame!=NULL, set up the method, locals, and monitors.
1442 // The frame interpreter_frame, if not NULL, is guaranteed to be the
1443 // right size, as determined by a previous call to this method.
1444 // It is also guaranteed to be walkable even though it is in a skeletal state
1446 // fixed size of an interpreter frame:
1447 int max_locals = method->max_locals() * Interpreter::stackElementWords();
1448 int extra_locals = (method->max_locals() - method->size_of_parameters()) *
1449 Interpreter::stackElementWords();
1451 int overhead = frame::sender_sp_offset -
1452 frame::interpreter_frame_initial_sp_offset;
1453 // Our locals were accounted for by the caller (or last_frame_adjust
1454 // on the transistion) Since the callee parameters already account
1455 // for the callee's params we only need to account for the extra
1456 // locals.
1457 int size = overhead +
1458 (callee_locals - callee_param_count)*Interpreter::stackElementWords() +
1459 moncount * frame::interpreter_frame_monitor_size() +
1460 tempcount* Interpreter::stackElementWords() + popframe_extra_args;
1461 if (interpreter_frame != NULL) {
1462 #ifdef ASSERT
1463 assert(caller->unextended_sp() == interpreter_frame->interpreter_frame_sender_sp(),
1464 "Frame not properly walkable");
1465 assert(caller->sp() == interpreter_frame->sender_sp(), "Frame not properly walkable(2)");
1466 #endif
1468 interpreter_frame->interpreter_frame_set_method(method);
1469 // NOTE the difference in using sender_sp and
1470 // interpreter_frame_sender_sp interpreter_frame_sender_sp is
1471 // the original sp of the caller (the unextended_sp) and
1472 // sender_sp is fp+16 XXX
1473 intptr_t* locals = interpreter_frame->sender_sp() + max_locals - 1;
1475 interpreter_frame->interpreter_frame_set_locals(locals);
1476 BasicObjectLock* montop = interpreter_frame->interpreter_frame_monitor_begin();
1477 BasicObjectLock* monbot = montop - moncount;
1478 interpreter_frame->interpreter_frame_set_monitor_end(monbot);
1480 // Set last_sp
1481 intptr_t* esp = (intptr_t*) monbot -
1482 tempcount*Interpreter::stackElementWords() -
1483 popframe_extra_args;
1484 interpreter_frame->interpreter_frame_set_last_sp(esp);
1486 // All frames but the initial (oldest) interpreter frame we fill in have
1487 // a value for sender_sp that allows walking the stack but isn't
1488 // truly correct. Correct the value here.
1489 if (extra_locals != 0 &&
1490 interpreter_frame->sender_sp() ==
1491 interpreter_frame->interpreter_frame_sender_sp()) {
1492 interpreter_frame->set_interpreter_frame_sender_sp(caller->sp() +
1493 extra_locals);
1494 }
1495 *interpreter_frame->interpreter_frame_cache_addr() =
1496 method->constants()->cache();
1497 }
1498 return size;
1499 }
1501 //-----------------------------------------------------------------------------
1502 // Exceptions
1504 void TemplateInterpreterGenerator::generate_throw_exception() {
1505 // Entry point in previous activation (i.e., if the caller was
1506 // interpreted)
1507 Interpreter::_rethrow_exception_entry = __ pc();
1508 // Restore sp to interpreter_frame_last_sp even though we are going
1509 // to empty the expression stack for the exception processing.
1510 __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
1511 // rax: exception
1512 // rdx: return address/pc that threw exception
1513 __ restore_bcp(); // r13 points to call/send
1514 __ restore_locals();
1515 __ reinit_heapbase(); // restore r12 as heapbase.
1516 // Entry point for exceptions thrown within interpreter code
1517 Interpreter::_throw_exception_entry = __ pc();
1518 // expression stack is undefined here
1519 // rax: exception
1520 // r13: exception bcp
1521 __ verify_oop(rax);
1522 __ mov(c_rarg1, rax);
1524 // expression stack must be empty before entering the VM in case of
1525 // an exception
1526 __ empty_expression_stack();
1527 // find exception handler address and preserve exception oop
1528 __ call_VM(rdx,
1529 CAST_FROM_FN_PTR(address,
1530 InterpreterRuntime::exception_handler_for_exception),
1531 c_rarg1);
1532 // rax: exception handler entry point
1533 // rdx: preserved exception oop
1534 // r13: bcp for exception handler
1535 __ push_ptr(rdx); // push exception which is now the only value on the stack
1536 __ jmp(rax); // jump to exception handler (may be _remove_activation_entry!)
1538 // If the exception is not handled in the current frame the frame is
1539 // removed and the exception is rethrown (i.e. exception
1540 // continuation is _rethrow_exception).
1541 //
1542 // Note: At this point the bci is still the bxi for the instruction
1543 // which caused the exception and the expression stack is
1544 // empty. Thus, for any VM calls at this point, GC will find a legal
1545 // oop map (with empty expression stack).
1547 // In current activation
1548 // tos: exception
1549 // esi: exception bcp
1551 //
1552 // JVMTI PopFrame support
1553 //
1555 Interpreter::_remove_activation_preserving_args_entry = __ pc();
1556 __ empty_expression_stack();
1557 // Set the popframe_processing bit in pending_popframe_condition
1558 // indicating that we are currently handling popframe, so that
1559 // call_VMs that may happen later do not trigger new popframe
1560 // handling cycles.
1561 __ movl(rdx, Address(r15_thread, JavaThread::popframe_condition_offset()));
1562 __ orl(rdx, JavaThread::popframe_processing_bit);
1563 __ movl(Address(r15_thread, JavaThread::popframe_condition_offset()), rdx);
1565 {
1566 // Check to see whether we are returning to a deoptimized frame.
1567 // (The PopFrame call ensures that the caller of the popped frame is
1568 // either interpreted or compiled and deoptimizes it if compiled.)
1569 // In this case, we can't call dispatch_next() after the frame is
1570 // popped, but instead must save the incoming arguments and restore
1571 // them after deoptimization has occurred.
1572 //
1573 // Note that we don't compare the return PC against the
1574 // deoptimization blob's unpack entry because of the presence of
1575 // adapter frames in C2.
1576 Label caller_not_deoptimized;
1577 __ movptr(c_rarg1, Address(rbp, frame::return_addr_offset * wordSize));
1578 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address,
1579 InterpreterRuntime::interpreter_contains), c_rarg1);
1580 __ testl(rax, rax);
1581 __ jcc(Assembler::notZero, caller_not_deoptimized);
1583 // Compute size of arguments for saving when returning to
1584 // deoptimized caller
1585 __ get_method(rax);
1586 __ load_unsigned_short(rax, Address(rax, in_bytes(methodOopDesc::
1587 size_of_parameters_offset())));
1588 __ shll(rax, Interpreter::logStackElementSize());
1589 __ restore_locals(); // XXX do we need this?
1590 __ subptr(r14, rax);
1591 __ addptr(r14, wordSize);
1592 // Save these arguments
1593 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address,
1594 Deoptimization::
1595 popframe_preserve_args),
1596 r15_thread, rax, r14);
1598 __ remove_activation(vtos, rdx,
1599 /* throw_monitor_exception */ false,
1600 /* install_monitor_exception */ false,
1601 /* notify_jvmdi */ false);
1603 // Inform deoptimization that it is responsible for restoring
1604 // these arguments
1605 __ movl(Address(r15_thread, JavaThread::popframe_condition_offset()),
1606 JavaThread::popframe_force_deopt_reexecution_bit);
1608 // Continue in deoptimization handler
1609 __ jmp(rdx);
1611 __ bind(caller_not_deoptimized);
1612 }
1614 __ remove_activation(vtos, rdx, /* rdx result (retaddr) is not used */
1615 /* throw_monitor_exception */ false,
1616 /* install_monitor_exception */ false,
1617 /* notify_jvmdi */ false);
1619 // Finish with popframe handling
1620 // A previous I2C followed by a deoptimization might have moved the
1621 // outgoing arguments further up the stack. PopFrame expects the
1622 // mutations to those outgoing arguments to be preserved and other
1623 // constraints basically require this frame to look exactly as
1624 // though it had previously invoked an interpreted activation with
1625 // no space between the top of the expression stack (current
1626 // last_sp) and the top of stack. Rather than force deopt to
1627 // maintain this kind of invariant all the time we call a small
1628 // fixup routine to move the mutated arguments onto the top of our
1629 // expression stack if necessary.
1630 __ mov(c_rarg1, rsp);
1631 __ movptr(c_rarg2, Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize));
1632 // PC must point into interpreter here
1633 __ set_last_Java_frame(noreg, rbp, __ pc());
1634 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::popframe_move_outgoing_args), r15_thread, c_rarg1, c_rarg2);
1635 __ reset_last_Java_frame(true, true);
1636 // Restore the last_sp and null it out
1637 __ movptr(rsp, Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize));
1638 __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
1640 __ restore_bcp(); // XXX do we need this?
1641 __ restore_locals(); // XXX do we need this?
1642 // The method data pointer was incremented already during
1643 // call profiling. We have to restore the mdp for the current bcp.
1644 if (ProfileInterpreter) {
1645 __ set_method_data_pointer_for_bcp();
1646 }
1648 // Clear the popframe condition flag
1649 __ movl(Address(r15_thread, JavaThread::popframe_condition_offset()),
1650 JavaThread::popframe_inactive);
1652 __ dispatch_next(vtos);
1653 // end of PopFrame support
1655 Interpreter::_remove_activation_entry = __ pc();
1657 // preserve exception over this code sequence
1658 __ pop_ptr(rax);
1659 __ movptr(Address(r15_thread, JavaThread::vm_result_offset()), rax);
1660 // remove the activation (without doing throws on illegalMonitorExceptions)
1661 __ remove_activation(vtos, rdx, false, true, false);
1662 // restore exception
1663 __ movptr(rax, Address(r15_thread, JavaThread::vm_result_offset()));
1664 __ movptr(Address(r15_thread, JavaThread::vm_result_offset()), (int32_t)NULL_WORD);
1665 __ verify_oop(rax);
1667 // In between activations - previous activation type unknown yet
1668 // compute continuation point - the continuation point expects the
1669 // following registers set up:
1670 //
1671 // rax: exception
1672 // rdx: return address/pc that threw exception
1673 // rsp: expression stack of caller
1674 // rbp: ebp of caller
1675 __ push(rax); // save exception
1676 __ push(rdx); // save return address
1677 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address,
1678 SharedRuntime::exception_handler_for_return_address),
1679 rdx);
1680 __ mov(rbx, rax); // save exception handler
1681 __ pop(rdx); // restore return address
1682 __ pop(rax); // restore exception
1683 // Note that an "issuing PC" is actually the next PC after the call
1684 __ jmp(rbx); // jump to exception
1685 // handler of caller
1686 }
1689 //
1690 // JVMTI ForceEarlyReturn support
1691 //
1692 address TemplateInterpreterGenerator::generate_earlyret_entry_for(TosState state) {
1693 address entry = __ pc();
1695 __ restore_bcp();
1696 __ restore_locals();
1697 __ empty_expression_stack();
1698 __ load_earlyret_value(state);
1700 __ movptr(rdx, Address(r15_thread, JavaThread::jvmti_thread_state_offset()));
1701 Address cond_addr(rdx, JvmtiThreadState::earlyret_state_offset());
1703 // Clear the earlyret state
1704 __ movl(cond_addr, JvmtiThreadState::earlyret_inactive);
1706 __ remove_activation(state, rsi,
1707 false, /* throw_monitor_exception */
1708 false, /* install_monitor_exception */
1709 true); /* notify_jvmdi */
1710 __ jmp(rsi);
1712 return entry;
1713 } // end of ForceEarlyReturn support
1716 //-----------------------------------------------------------------------------
1717 // Helper for vtos entry point generation
1719 void TemplateInterpreterGenerator::set_vtos_entry_points(Template* t,
1720 address& bep,
1721 address& cep,
1722 address& sep,
1723 address& aep,
1724 address& iep,
1725 address& lep,
1726 address& fep,
1727 address& dep,
1728 address& vep) {
1729 assert(t->is_valid() && t->tos_in() == vtos, "illegal template");
1730 Label L;
1731 aep = __ pc(); __ push_ptr(); __ jmp(L);
1732 fep = __ pc(); __ push_f(); __ jmp(L);
1733 dep = __ pc(); __ push_d(); __ jmp(L);
1734 lep = __ pc(); __ push_l(); __ jmp(L);
1735 bep = cep = sep =
1736 iep = __ pc(); __ push_i();
1737 vep = __ pc();
1738 __ bind(L);
1739 generate_and_dispatch(t);
1740 }
1743 //-----------------------------------------------------------------------------
1744 // Generation of individual instructions
1746 // helpers for generate_and_dispatch
1749 InterpreterGenerator::InterpreterGenerator(StubQueue* code)
1750 : TemplateInterpreterGenerator(code) {
1751 generate_all(); // down here so it can be "virtual"
1752 }
1754 //-----------------------------------------------------------------------------
1756 // Non-product code
1757 #ifndef PRODUCT
1758 address TemplateInterpreterGenerator::generate_trace_code(TosState state) {
1759 address entry = __ pc();
1761 __ push(state);
1762 __ push(c_rarg0);
1763 __ push(c_rarg1);
1764 __ push(c_rarg2);
1765 __ push(c_rarg3);
1766 __ mov(c_rarg2, rax); // Pass itos
1767 #ifdef _WIN64
1768 __ movflt(xmm3, xmm0); // Pass ftos
1769 #endif
1770 __ call_VM(noreg,
1771 CAST_FROM_FN_PTR(address, SharedRuntime::trace_bytecode),
1772 c_rarg1, c_rarg2, c_rarg3);
1773 __ pop(c_rarg3);
1774 __ pop(c_rarg2);
1775 __ pop(c_rarg1);
1776 __ pop(c_rarg0);
1777 __ pop(state);
1778 __ ret(0); // return from result handler
1780 return entry;
1781 }
1783 void TemplateInterpreterGenerator::count_bytecode() {
1784 __ incrementl(ExternalAddress((address) &BytecodeCounter::_counter_value));
1785 }
1787 void TemplateInterpreterGenerator::histogram_bytecode(Template* t) {
1788 __ incrementl(ExternalAddress((address) &BytecodeHistogram::_counters[t->bytecode()]));
1789 }
1791 void TemplateInterpreterGenerator::histogram_bytecode_pair(Template* t) {
1792 __ mov32(rbx, ExternalAddress((address) &BytecodePairHistogram::_index));
1793 __ shrl(rbx, BytecodePairHistogram::log2_number_of_codes);
1794 __ orl(rbx,
1795 ((int) t->bytecode()) <<
1796 BytecodePairHistogram::log2_number_of_codes);
1797 __ mov32(ExternalAddress((address) &BytecodePairHistogram::_index), rbx);
1798 __ lea(rscratch1, ExternalAddress((address) BytecodePairHistogram::_counters));
1799 __ incrementl(Address(rscratch1, rbx, Address::times_4));
1800 }
1803 void TemplateInterpreterGenerator::trace_bytecode(Template* t) {
1804 // Call a little run-time stub to avoid blow-up for each bytecode.
1805 // The run-time runtime saves the right registers, depending on
1806 // the tosca in-state for the given template.
1808 assert(Interpreter::trace_code(t->tos_in()) != NULL,
1809 "entry must have been generated");
1810 __ mov(r12, rsp); // remember sp
1811 __ andptr(rsp, -16); // align stack as required by ABI
1812 __ call(RuntimeAddress(Interpreter::trace_code(t->tos_in())));
1813 __ mov(rsp, r12); // restore sp
1814 __ reinit_heapbase();
1815 }
1818 void TemplateInterpreterGenerator::stop_interpreter_at() {
1819 Label L;
1820 __ cmp32(ExternalAddress((address) &BytecodeCounter::_counter_value),
1821 StopInterpreterAt);
1822 __ jcc(Assembler::notEqual, L);
1823 __ int3();
1824 __ bind(L);
1825 }
1826 #endif // !PRODUCT
1827 #endif // ! CC_INTERP