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