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