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