Mercurial > hg > graal-compiler
comparison src/cpu/x86/vm/cppInterpreter_x86.cpp @ 0:a61af66fc99e jdk7-b24
Initial load
author | duke |
---|---|
date | Sat, 01 Dec 2007 00:00:00 +0000 |
parents | |
children | dc7f315e41f7 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a61af66fc99e |
---|---|
1 /* | |
2 * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 #include "incls/_precompiled.incl" | |
26 #include "incls/_cppInterpreter_x86.cpp.incl" | |
27 | |
28 #ifdef CC_INTERP | |
29 | |
30 // Routine exists to make tracebacks look decent in debugger | |
31 // while we are recursed in the frame manager/c++ interpreter. | |
32 // We could use an address in the frame manager but having | |
33 // frames look natural in the debugger is a plus. | |
34 extern "C" void RecursiveInterpreterActivation(interpreterState istate ) | |
35 { | |
36 // | |
37 ShouldNotReachHere(); | |
38 } | |
39 | |
40 | |
41 #define __ _masm-> | |
42 #define STATE(field_name) (Address(state, byte_offset_of(BytecodeInterpreter, field_name))) | |
43 | |
44 Label fast_accessor_slow_entry_path; // fast accessor methods need to be able to jmp to unsynchronized | |
45 // c++ interpreter entry point this holds that entry point label. | |
46 | |
47 // NEEDED for JVMTI? | |
48 // address AbstractInterpreter::_remove_activation_preserving_args_entry; | |
49 | |
50 static address unctrap_frame_manager_entry = NULL; | |
51 | |
52 static address deopt_frame_manager_return_atos = NULL; | |
53 static address deopt_frame_manager_return_btos = NULL; | |
54 static address deopt_frame_manager_return_itos = NULL; | |
55 static address deopt_frame_manager_return_ltos = NULL; | |
56 static address deopt_frame_manager_return_ftos = NULL; | |
57 static address deopt_frame_manager_return_dtos = NULL; | |
58 static address deopt_frame_manager_return_vtos = NULL; | |
59 | |
60 int AbstractInterpreter::BasicType_as_index(BasicType type) { | |
61 int i = 0; | |
62 switch (type) { | |
63 case T_BOOLEAN: i = 0; break; | |
64 case T_CHAR : i = 1; break; | |
65 case T_BYTE : i = 2; break; | |
66 case T_SHORT : i = 3; break; | |
67 case T_INT : i = 4; break; | |
68 case T_VOID : i = 5; break; | |
69 case T_FLOAT : i = 8; break; | |
70 case T_LONG : i = 9; break; | |
71 case T_DOUBLE : i = 6; break; | |
72 case T_OBJECT : // fall through | |
73 case T_ARRAY : i = 7; break; | |
74 default : ShouldNotReachHere(); | |
75 } | |
76 assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers, "index out of bounds"); | |
77 return i; | |
78 } | |
79 | |
80 // Is this pc anywhere within code owned by the interpreter? | |
81 // This only works for pc that might possibly be exposed to frame | |
82 // walkers. It clearly misses all of the actual c++ interpreter | |
83 // implementation | |
84 bool CppInterpreter::contains(address pc) { | |
85 return (_code->contains(pc) || | |
86 pc == CAST_FROM_FN_PTR(address, RecursiveInterpreterActivation)); | |
87 } | |
88 | |
89 | |
90 address CppInterpreterGenerator::generate_result_handler_for(BasicType type) { | |
91 const Register state = rsi; // current activation object, valid on entry | |
92 address entry = __ pc(); | |
93 switch (type) { | |
94 case T_BOOLEAN: __ c2bool(rax); break; | |
95 case T_CHAR : __ andl(rax, 0xFFFF); break; | |
96 case T_BYTE : __ sign_extend_byte (rax); break; | |
97 case T_SHORT : __ sign_extend_short(rax); break; | |
98 case T_VOID : // fall thru | |
99 case T_LONG : // fall thru | |
100 case T_INT : /* nothing to do */ break; | |
101 case T_DOUBLE : | |
102 case T_FLOAT : | |
103 { const Register t = InterpreterRuntime::SignatureHandlerGenerator::temp(); | |
104 __ popl(t); // remove return address first | |
105 __ pop_dtos_to_rsp(); | |
106 // Must return a result for interpreter or compiler. In SSE | |
107 // mode, results are returned in xmm0 and the FPU stack must | |
108 // be empty. | |
109 if (type == T_FLOAT && UseSSE >= 1) { | |
110 // Load ST0 | |
111 __ fld_d(Address(rsp, 0)); | |
112 // Store as float and empty fpu stack | |
113 __ fstp_s(Address(rsp, 0)); | |
114 // and reload | |
115 __ movflt(xmm0, Address(rsp, 0)); | |
116 } else if (type == T_DOUBLE && UseSSE >= 2 ) { | |
117 __ movdbl(xmm0, Address(rsp, 0)); | |
118 } else { | |
119 // restore ST0 | |
120 __ fld_d(Address(rsp, 0)); | |
121 } | |
122 // and pop the temp | |
123 __ addl(rsp, 2 * wordSize); | |
124 __ pushl(t); // restore return address | |
125 } | |
126 break; | |
127 case T_OBJECT : | |
128 // retrieve result from frame | |
129 __ movl(rax, STATE(_oop_temp)); | |
130 // and verify it | |
131 __ verify_oop(rax); | |
132 break; | |
133 default : ShouldNotReachHere(); | |
134 } | |
135 __ ret(0); // return from result handler | |
136 return entry; | |
137 } | |
138 | |
139 // tosca based result to c++ interpreter stack based result. | |
140 // Result goes to top of native stack. | |
141 | |
142 #undef EXTEND // SHOULD NOT BE NEEDED | |
143 address CppInterpreterGenerator::generate_tosca_to_stack_converter(BasicType type) { | |
144 // A result is in the tosca (abi result) from either a native method call or compiled | |
145 // code. Place this result on the java expression stack so C++ interpreter can use it. | |
146 address entry = __ pc(); | |
147 | |
148 const Register t = InterpreterRuntime::SignatureHandlerGenerator::temp(); | |
149 __ popl(t); // remove return address first | |
150 switch (type) { | |
151 case T_VOID: | |
152 break; | |
153 case T_BOOLEAN: | |
154 #ifdef EXTEND | |
155 __ c2bool(rax); | |
156 #endif | |
157 __ pushl(rax); | |
158 break; | |
159 case T_CHAR : | |
160 #ifdef EXTEND | |
161 __ andl(rax, 0xFFFF); | |
162 #endif | |
163 __ pushl(rax); | |
164 break; | |
165 case T_BYTE : | |
166 #ifdef EXTEND | |
167 __ sign_extend_byte (rax); | |
168 #endif | |
169 __ pushl(rax); | |
170 break; | |
171 case T_SHORT : | |
172 #ifdef EXTEND | |
173 __ sign_extend_short(rax); | |
174 #endif | |
175 __ pushl(rax); | |
176 break; | |
177 case T_LONG : | |
178 __ pushl(rdx); | |
179 __ pushl(rax); | |
180 break; | |
181 case T_INT : | |
182 __ pushl(rax); | |
183 break; | |
184 case T_FLOAT : | |
185 // Result is in ST(0) | |
186 if ( UseSSE < 1) { | |
187 __ push(ftos); // and save it | |
188 } else { | |
189 __ subl(rsp, wordSize); | |
190 __ movflt(Address(rsp, 0), xmm0); | |
191 } | |
192 break; | |
193 case T_DOUBLE : | |
194 if ( UseSSE < 2 ) { | |
195 __ push(dtos); // put ST0 on java stack | |
196 } else { | |
197 __ subl(rsp, 2*wordSize); | |
198 __ movdbl(Address(rsp, 0), xmm0); | |
199 } | |
200 break; | |
201 case T_OBJECT : | |
202 __ verify_oop(rax); // verify it | |
203 __ pushl(rax); | |
204 break; | |
205 default : ShouldNotReachHere(); | |
206 } | |
207 __ jmp(t); // return from result handler | |
208 return entry; | |
209 } | |
210 | |
211 address CppInterpreterGenerator::generate_stack_to_stack_converter(BasicType type) { | |
212 // A result is in the java expression stack of the interpreted method that has just | |
213 // returned. Place this result on the java expression stack of the caller. | |
214 // | |
215 // The current interpreter activation in rsi is for the method just returning its | |
216 // result. So we know that the result of this method is on the top of the current | |
217 // execution stack (which is pre-pushed) and will be return to the top of the caller | |
218 // stack. The top of the callers stack is the bottom of the locals of the current | |
219 // activation. | |
220 // Because of the way activation are managed by the frame manager the value of rsp is | |
221 // below both the stack top of the current activation and naturally the stack top | |
222 // of the calling activation. This enable this routine to leave the return address | |
223 // to the frame manager on the stack and do a vanilla return. | |
224 // | |
225 // On entry: rsi - interpreter state of activation returning a (potential) result | |
226 // On Return: rsi - unchanged | |
227 // rax - new stack top for caller activation (i.e. activation in _prev_link) | |
228 // | |
229 // Can destroy rdx, rcx. | |
230 // | |
231 | |
232 address entry = __ pc(); | |
233 const Register state = rsi; // current activation object, valid on entry | |
234 const Register t = InterpreterRuntime::SignatureHandlerGenerator::temp(); | |
235 switch (type) { | |
236 case T_VOID: | |
237 __ movl(rax, STATE(_locals)); // pop parameters get new stack value | |
238 __ addl(rax, wordSize); // account for prepush before we return | |
239 break; | |
240 case T_FLOAT : | |
241 case T_BOOLEAN: | |
242 case T_CHAR : | |
243 case T_BYTE : | |
244 case T_SHORT : | |
245 case T_INT : | |
246 // 1 word result | |
247 __ movl(rdx, STATE(_stack)); | |
248 __ movl(rax, STATE(_locals)); // address for result | |
249 __ movl(rdx, Address(rdx, wordSize)); // get result | |
250 __ movl(Address(rax, 0), rdx); // and store it | |
251 break; | |
252 case T_LONG : | |
253 case T_DOUBLE : | |
254 // return top two words on current expression stack to caller's expression stack | |
255 // The caller's expression stack is adjacent to the current frame manager's intepretState | |
256 // except we allocated one extra word for this intepretState so we won't overwrite it | |
257 // when we return a two word result. | |
258 | |
259 __ movl(rax, STATE(_locals)); // address for result | |
260 __ movl(rcx, STATE(_stack)); | |
261 __ subl(rax, wordSize); // need addition word besides locals[0] | |
262 __ movl(rdx, Address(rcx, 2*wordSize)); // get result word | |
263 __ movl(Address(rax, wordSize), rdx); // and store it | |
264 __ movl(rdx, Address(rcx, wordSize)); // get result word | |
265 __ movl(Address(rax, 0), rdx); // and store it | |
266 break; | |
267 case T_OBJECT : | |
268 __ movl(rdx, STATE(_stack)); | |
269 __ movl(rax, STATE(_locals)); // address for result | |
270 __ movl(rdx, Address(rdx, wordSize)); // get result | |
271 __ verify_oop(rdx); // verify it | |
272 __ movl(Address(rax, 0), rdx); // and store it | |
273 break; | |
274 default : ShouldNotReachHere(); | |
275 } | |
276 __ ret(0); | |
277 return entry; | |
278 } | |
279 | |
280 address CppInterpreterGenerator::generate_stack_to_native_abi_converter(BasicType type) { | |
281 // A result is in the java expression stack of the interpreted method that has just | |
282 // returned. Place this result in the native abi that the caller expects. | |
283 // | |
284 // Similar to generate_stack_to_stack_converter above. Called at a similar time from the | |
285 // frame manager execept in this situation the caller is native code (c1/c2/call_stub) | |
286 // and so rather than return result onto caller's java expression stack we return the | |
287 // result in the expected location based on the native abi. | |
288 // On entry: rsi - interpreter state of activation returning a (potential) result | |
289 // On Return: rsi - unchanged | |
290 // Other registers changed [rax/rdx/ST(0) as needed for the result returned] | |
291 | |
292 address entry = __ pc(); | |
293 const Register state = rsi; // current activation object, valid on entry | |
294 switch (type) { | |
295 case T_VOID: | |
296 break; | |
297 case T_BOOLEAN: | |
298 case T_CHAR : | |
299 case T_BYTE : | |
300 case T_SHORT : | |
301 case T_INT : | |
302 __ movl(rdx, STATE(_stack)); // get top of stack | |
303 __ movl(rax, Address(rdx, wordSize)); // get result word 1 | |
304 break; | |
305 case T_LONG : | |
306 __ movl(rdx, STATE(_stack)); // get top of stack | |
307 __ movl(rax, Address(rdx, wordSize)); // get result low word | |
308 __ movl(rdx, Address(rdx, 2*wordSize)); // get result high word | |
309 break; | |
310 break; | |
311 case T_FLOAT : | |
312 __ movl(rdx, STATE(_stack)); // get top of stack | |
313 if ( UseSSE >= 1) { | |
314 __ movflt(xmm0, Address(rdx, wordSize)); | |
315 } else { | |
316 __ fld_s(Address(rdx, wordSize)); // pushd float result | |
317 } | |
318 break; | |
319 case T_DOUBLE : | |
320 __ movl(rdx, STATE(_stack)); // get top of stack | |
321 if ( UseSSE > 1) { | |
322 __ movdbl(xmm0, Address(rdx, wordSize)); | |
323 } else { | |
324 __ fld_d(Address(rdx, wordSize)); // push double result | |
325 } | |
326 break; | |
327 case T_OBJECT : | |
328 __ movl(rdx, STATE(_stack)); // get top of stack | |
329 __ movl(rax, Address(rdx, wordSize)); // get result word 1 | |
330 __ verify_oop(rax); // verify it | |
331 break; | |
332 default : ShouldNotReachHere(); | |
333 } | |
334 __ ret(0); | |
335 return entry; | |
336 } | |
337 | |
338 address CppInterpreter::return_entry(TosState state, int length) { | |
339 // make it look good in the debugger | |
340 return CAST_FROM_FN_PTR(address, RecursiveInterpreterActivation); | |
341 } | |
342 | |
343 address CppInterpreter::deopt_entry(TosState state, int length) { | |
344 address ret = NULL; | |
345 if (length != 0) { | |
346 switch (state) { | |
347 case atos: ret = deopt_frame_manager_return_atos; break; | |
348 case btos: ret = deopt_frame_manager_return_btos; break; | |
349 case ctos: | |
350 case stos: | |
351 case itos: ret = deopt_frame_manager_return_itos; break; | |
352 case ltos: ret = deopt_frame_manager_return_ltos; break; | |
353 case ftos: ret = deopt_frame_manager_return_ftos; break; | |
354 case dtos: ret = deopt_frame_manager_return_dtos; break; | |
355 case vtos: ret = deopt_frame_manager_return_vtos; break; | |
356 } | |
357 } else { | |
358 ret = unctrap_frame_manager_entry; // re-execute the bytecode ( e.g. uncommon trap) | |
359 } | |
360 assert(ret != NULL, "Not initialized"); | |
361 return ret; | |
362 } | |
363 | |
364 // C++ Interpreter | |
365 void CppInterpreterGenerator::generate_compute_interpreter_state(const Register state, | |
366 const Register locals, | |
367 const Register sender_sp, | |
368 bool native) { | |
369 | |
370 // On entry the "locals" argument points to locals[0] (or where it would be in case no locals in | |
371 // a static method). "state" contains any previous frame manager state which we must save a link | |
372 // to in the newly generated state object. On return "state" is a pointer to the newly allocated | |
373 // state object. We must allocate and initialize a new interpretState object and the method | |
374 // expression stack. Because the returned result (if any) of the method will be placed on the caller's | |
375 // expression stack and this will overlap with locals[0] (and locals[1] if double/long) we must | |
376 // be sure to leave space on the caller's stack so that this result will not overwrite values when | |
377 // locals[0] and locals[1] do not exist (and in fact are return address and saved rbp). So when | |
378 // we are non-native we in essence ensure that locals[0-1] exist. We play an extra trick in | |
379 // non-product builds and initialize this last local with the previous interpreterState as | |
380 // this makes things look real nice in the debugger. | |
381 | |
382 // State on entry | |
383 // Assumes locals == &locals[0] | |
384 // Assumes state == any previous frame manager state (assuming call path from c++ interpreter) | |
385 // Assumes rax = return address | |
386 // rcx == senders_sp | |
387 // rbx == method | |
388 // Modifies rcx, rdx, rax | |
389 // Returns: | |
390 // state == address of new interpreterState | |
391 // rsp == bottom of method's expression stack. | |
392 | |
393 const Address const_offset (rbx, methodOopDesc::const_offset()); | |
394 | |
395 | |
396 // On entry sp is the sender's sp. This includes the space for the arguments | |
397 // that the sender pushed. If the sender pushed no args (a static) and the | |
398 // caller returns a long then we need two words on the sender's stack which | |
399 // are not present (although when we return a restore full size stack the | |
400 // space will be present). If we didn't allocate two words here then when | |
401 // we "push" the result of the caller's stack we would overwrite the return | |
402 // address and the saved rbp. Not good. So simply allocate 2 words now | |
403 // just to be safe. This is the "static long no_params() method" issue. | |
404 // See Lo.java for a testcase. | |
405 // We don't need this for native calls because they return result in | |
406 // register and the stack is expanded in the caller before we store | |
407 // the results on the stack. | |
408 | |
409 if (!native) { | |
410 #ifdef PRODUCT | |
411 __ subl(rsp, 2*wordSize); | |
412 #else /* PRODUCT */ | |
413 __ pushl((int)NULL); | |
414 __ pushl(state); // make it look like a real argument | |
415 #endif /* PRODUCT */ | |
416 } | |
417 | |
418 // Now that we are assure of space for stack result, setup typical linkage | |
419 | |
420 __ pushl(rax); | |
421 __ enter(); | |
422 | |
423 __ movl(rax, state); // save current state | |
424 | |
425 __ leal(rsp, Address(rsp, -(int)sizeof(BytecodeInterpreter))); | |
426 __ movl(state, rsp); | |
427 | |
428 // rsi == state/locals rax == prevstate | |
429 | |
430 // initialize the "shadow" frame so that use since C++ interpreter not directly | |
431 // recursive. Simpler to recurse but we can't trim expression stack as we call | |
432 // new methods. | |
433 __ movl(STATE(_locals), locals); // state->_locals = locals() | |
434 __ movl(STATE(_self_link), state); // point to self | |
435 __ movl(STATE(_prev_link), rax); // state->_link = state on entry (NULL or previous state) | |
436 __ movl(STATE(_sender_sp), sender_sp); // state->_sender_sp = sender_sp | |
437 __ get_thread(rax); // get vm's javathread* | |
438 __ movl(STATE(_thread), rax); // state->_bcp = codes() | |
439 __ movl(rdx, Address(rbx, methodOopDesc::const_offset())); // get constantMethodOop | |
440 __ leal(rdx, Address(rdx, constMethodOopDesc::codes_offset())); // get code base | |
441 if (native) { | |
442 __ movl(STATE(_bcp), (intptr_t)NULL); // state->_bcp = NULL | |
443 } else { | |
444 __ movl(STATE(_bcp), rdx); // state->_bcp = codes() | |
445 } | |
446 __ xorl(rdx, rdx); | |
447 __ movl(STATE(_oop_temp), rdx); // state->_oop_temp = NULL (only really needed for native) | |
448 __ movl(STATE(_mdx), rdx); // state->_mdx = NULL | |
449 __ movl(rdx, Address(rbx, methodOopDesc::constants_offset())); | |
450 __ movl(rdx, Address(rdx, constantPoolOopDesc::cache_offset_in_bytes())); | |
451 __ movl(STATE(_constants), rdx); // state->_constants = constants() | |
452 | |
453 __ movl(STATE(_method), rbx); // state->_method = method() | |
454 __ movl(STATE(_msg), (int) BytecodeInterpreter::method_entry); // state->_msg = initial method entry | |
455 __ movl(STATE(_result._to_call._callee), (int) NULL); // state->_result._to_call._callee_callee = NULL | |
456 | |
457 | |
458 __ movl(STATE(_monitor_base), rsp); // set monitor block bottom (grows down) this would point to entry [0] | |
459 // entries run from -1..x where &monitor[x] == | |
460 | |
461 { | |
462 // Must not attempt to lock method until we enter interpreter as gc won't be able to find the | |
463 // initial frame. However we allocate a free monitor so we don't have to shuffle the expression stack | |
464 // immediately. | |
465 | |
466 // synchronize method | |
467 const Address access_flags (rbx, methodOopDesc::access_flags_offset()); | |
468 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; | |
469 Label not_synced; | |
470 | |
471 __ movl(rax, access_flags); | |
472 __ testl(rax, JVM_ACC_SYNCHRONIZED); | |
473 __ jcc(Assembler::zero, not_synced); | |
474 | |
475 // Allocate initial monitor and pre initialize it | |
476 // get synchronization object | |
477 | |
478 Label done; | |
479 const int mirror_offset = klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes(); | |
480 __ movl(rax, access_flags); | |
481 __ testl(rax, JVM_ACC_STATIC); | |
482 __ movl(rax, Address(locals, 0)); // get receiver (assume this is frequent case) | |
483 __ jcc(Assembler::zero, done); | |
484 __ movl(rax, Address(rbx, methodOopDesc::constants_offset())); | |
485 __ movl(rax, Address(rax, constantPoolOopDesc::pool_holder_offset_in_bytes())); | |
486 __ movl(rax, Address(rax, mirror_offset)); | |
487 __ bind(done); | |
488 // add space for monitor & lock | |
489 __ subl(rsp, entry_size); // add space for a monitor entry | |
490 __ movl(Address(rsp, BasicObjectLock::obj_offset_in_bytes()), rax); // store object | |
491 __ bind(not_synced); | |
492 } | |
493 | |
494 __ movl(STATE(_stack_base), rsp); // set expression stack base ( == &monitors[-count]) | |
495 if (native) { | |
496 __ movl(STATE(_stack), rsp); // set current expression stack tos | |
497 __ movl(STATE(_stack_limit), rsp); | |
498 } else { | |
499 __ subl(rsp, wordSize); // pre-push stack | |
500 __ movl(STATE(_stack), rsp); // set current expression stack tos | |
501 | |
502 // compute full expression stack limit | |
503 | |
504 const Address size_of_stack (rbx, methodOopDesc::max_stack_offset()); | |
505 __ load_unsigned_word(rdx, size_of_stack); // get size of expression stack in words | |
506 __ negl(rdx); // so we can subtract in next step | |
507 // Allocate expression stack | |
508 __ leal(rsp, Address(rsp, rdx, Address::times_4)); | |
509 __ movl(STATE(_stack_limit), rsp); | |
510 } | |
511 | |
512 } | |
513 | |
514 // Helpers for commoning out cases in the various type of method entries. | |
515 // | |
516 | |
517 // increment invocation count & check for overflow | |
518 // | |
519 // Note: checking for negative value instead of overflow | |
520 // so we have a 'sticky' overflow test | |
521 // | |
522 // rbx,: method | |
523 // rcx: invocation counter | |
524 // | |
525 void InterpreterGenerator::generate_counter_incr(Label* overflow, Label* profile_method, Label* profile_method_continue) { | |
526 | |
527 const Address invocation_counter(rbx, methodOopDesc::invocation_counter_offset() + InvocationCounter::counter_offset()); | |
528 const Address backedge_counter (rbx, methodOopDesc::backedge_counter_offset() + InvocationCounter::counter_offset()); | |
529 | |
530 if (ProfileInterpreter) { // %%% Merge this into methodDataOop | |
531 __ increment(Address(rbx,methodOopDesc::interpreter_invocation_counter_offset())); | |
532 } | |
533 // Update standard invocation counters | |
534 __ movl(rax, backedge_counter); // load backedge counter | |
535 | |
536 __ increment(rcx, InvocationCounter::count_increment); | |
537 __ andl(rax, InvocationCounter::count_mask_value); // mask out the status bits | |
538 | |
539 __ movl(invocation_counter, rcx); // save invocation count | |
540 __ addl(rcx, rax); // add both counters | |
541 | |
542 // profile_method is non-null only for interpreted method so | |
543 // profile_method != NULL == !native_call | |
544 // BytecodeInterpreter only calls for native so code is elided. | |
545 | |
546 __ cmp32(rcx, | |
547 ExternalAddress((address)&InvocationCounter::InterpreterInvocationLimit)); | |
548 __ jcc(Assembler::aboveEqual, *overflow); | |
549 | |
550 } | |
551 | |
552 void InterpreterGenerator::generate_counter_overflow(Label* do_continue) { | |
553 | |
554 // C++ interpreter on entry | |
555 // rsi - new interpreter state pointer | |
556 // rbp - interpreter frame pointer | |
557 // rbx - method | |
558 | |
559 // On return (i.e. jump to entry_point) [ back to invocation of interpreter ] | |
560 // rbx, - method | |
561 // rcx - rcvr (assuming there is one) | |
562 // top of stack return address of interpreter caller | |
563 // rsp - sender_sp | |
564 | |
565 // C++ interpreter only | |
566 // rsi - previous interpreter state pointer | |
567 | |
568 const Address size_of_parameters(rbx, methodOopDesc::size_of_parameters_offset()); | |
569 | |
570 // InterpreterRuntime::frequency_counter_overflow takes one argument | |
571 // indicating if the counter overflow occurs at a backwards branch (non-NULL bcp). | |
572 // The call returns the address of the verified entry point for the method or NULL | |
573 // if the compilation did not complete (either went background or bailed out). | |
574 __ movl(rax, (int)false); | |
575 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), rax); | |
576 | |
577 // for c++ interpreter can rsi really be munged? | |
578 __ leal(rsi, Address(rbp, -sizeof(BytecodeInterpreter))); // restore state | |
579 __ movl(rbx, Address(rsi, byte_offset_of(BytecodeInterpreter, _method))); // restore method | |
580 __ movl(rdi, Address(rsi, byte_offset_of(BytecodeInterpreter, _locals))); // get locals pointer | |
581 | |
582 // Preserve invariant that rsi/rdi contain bcp/locals of sender frame | |
583 // and jump to the interpreted entry. | |
584 __ jmp(*do_continue, relocInfo::none); | |
585 | |
586 } | |
587 | |
588 void InterpreterGenerator::generate_stack_overflow_check(void) { | |
589 // see if we've got enough room on the stack for locals plus overhead. | |
590 // the expression stack grows down incrementally, so the normal guard | |
591 // page mechanism will work for that. | |
592 // | |
593 // Registers live on entry: | |
594 // | |
595 // Asm interpreter | |
596 // rdx: number of additional locals this frame needs (what we must check) | |
597 // rbx,: methodOop | |
598 | |
599 // C++ Interpreter | |
600 // rsi: previous interpreter frame state object | |
601 // rdi: &locals[0] | |
602 // rcx: # of locals | |
603 // rdx: number of additional locals this frame needs (what we must check) | |
604 // rbx: methodOop | |
605 | |
606 // destroyed on exit | |
607 // rax, | |
608 | |
609 // NOTE: since the additional locals are also always pushed (wasn't obvious in | |
610 // generate_method_entry) so the guard should work for them too. | |
611 // | |
612 | |
613 // monitor entry size: see picture of stack set (generate_method_entry) and frame_i486.hpp | |
614 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; | |
615 | |
616 // total overhead size: entry_size + (saved rbp, thru expr stack bottom). | |
617 // be sure to change this if you add/subtract anything to/from the overhead area | |
618 const int overhead_size = (int)sizeof(BytecodeInterpreter); | |
619 | |
620 const int page_size = os::vm_page_size(); | |
621 | |
622 Label after_frame_check; | |
623 | |
624 // compute rsp as if this were going to be the last frame on | |
625 // the stack before the red zone | |
626 | |
627 Label after_frame_check_pop; | |
628 | |
629 // save rsi == caller's bytecode ptr (c++ previous interp. state) | |
630 // QQQ problem here?? rsi overload???? | |
631 __ pushl(rsi); | |
632 | |
633 const Register thread = rsi; | |
634 | |
635 __ get_thread(thread); | |
636 | |
637 const Address stack_base(thread, Thread::stack_base_offset()); | |
638 const Address stack_size(thread, Thread::stack_size_offset()); | |
639 | |
640 // locals + overhead, in bytes | |
641 const Address size_of_stack (rbx, methodOopDesc::max_stack_offset()); | |
642 // Always give one monitor to allow us to start interp if sync method. | |
643 // Any additional monitors need a check when moving the expression stack | |
644 const one_monitor = frame::interpreter_frame_monitor_size() * wordSize; | |
645 __ load_unsigned_word(rax, size_of_stack); // get size of expression stack in words | |
646 __ leal(rax, Address(noreg, rax, Interpreter::stackElementScale(), one_monitor)); | |
647 __ leal(rax, Address(rax, rdx, Interpreter::stackElementScale(), overhead_size)); | |
648 | |
649 #ifdef ASSERT | |
650 Label stack_base_okay, stack_size_okay; | |
651 // verify that thread stack base is non-zero | |
652 __ cmpl(stack_base, 0); | |
653 __ jcc(Assembler::notEqual, stack_base_okay); | |
654 __ stop("stack base is zero"); | |
655 __ bind(stack_base_okay); | |
656 // verify that thread stack size is non-zero | |
657 __ cmpl(stack_size, 0); | |
658 __ jcc(Assembler::notEqual, stack_size_okay); | |
659 __ stop("stack size is zero"); | |
660 __ bind(stack_size_okay); | |
661 #endif | |
662 | |
663 // Add stack base to locals and subtract stack size | |
664 __ addl(rax, stack_base); | |
665 __ subl(rax, stack_size); | |
666 | |
667 // We should have a magic number here for the size of the c++ interpreter frame. | |
668 // We can't actually tell this ahead of time. The debug version size is around 3k | |
669 // product is 1k and fastdebug is 4k | |
670 const int slop = 6 * K; | |
671 | |
672 // Use the maximum number of pages we might bang. | |
673 const int max_pages = StackShadowPages > (StackRedPages+StackYellowPages) ? StackShadowPages : | |
674 (StackRedPages+StackYellowPages); | |
675 // Only need this if we are stack banging which is temporary while | |
676 // we're debugging. | |
677 __ addl(rax, slop + 2*max_pages * page_size); | |
678 | |
679 // check against the current stack bottom | |
680 __ cmpl(rsp, rax); | |
681 __ jcc(Assembler::above, after_frame_check_pop); | |
682 | |
683 __ popl(rsi); // get saved bcp / (c++ prev state ). | |
684 | |
685 // throw exception return address becomes throwing pc | |
686 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_StackOverflowError)); | |
687 | |
688 // all done with frame size check | |
689 __ bind(after_frame_check_pop); | |
690 __ popl(rsi); | |
691 | |
692 __ bind(after_frame_check); | |
693 } | |
694 | |
695 // Find preallocated monitor and lock method (C++ interpreter) | |
696 // rbx - methodOop | |
697 // | |
698 void InterpreterGenerator::lock_method(void) { | |
699 // assumes state == rsi == pointer to current interpreterState | |
700 // minimally destroys rax, rdx, rdi | |
701 // | |
702 // synchronize method | |
703 const Register state = rsi; | |
704 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; | |
705 const Address access_flags (rbx, methodOopDesc::access_flags_offset()); | |
706 | |
707 // find initial monitor i.e. monitors[-1] | |
708 __ movl(rdx, STATE(_monitor_base)); // get monitor bottom limit | |
709 __ subl(rdx, entry_size); // point to initial monitor | |
710 | |
711 #ifdef ASSERT | |
712 { Label L; | |
713 __ movl(rax, access_flags); | |
714 __ testl(rax, JVM_ACC_SYNCHRONIZED); | |
715 __ jcc(Assembler::notZero, L); | |
716 __ stop("method doesn't need synchronization"); | |
717 __ bind(L); | |
718 } | |
719 #endif // ASSERT | |
720 // get synchronization object | |
721 { Label done; | |
722 const int mirror_offset = klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes(); | |
723 __ movl(rax, access_flags); | |
724 __ movl(rdi, STATE(_locals)); // prepare to get receiver (assume common case) | |
725 __ testl(rax, JVM_ACC_STATIC); | |
726 __ movl(rax, Address(rdi, 0)); // get receiver (assume this is frequent case) | |
727 __ jcc(Assembler::zero, done); | |
728 __ movl(rax, Address(rbx, methodOopDesc::constants_offset())); | |
729 __ movl(rax, Address(rax, constantPoolOopDesc::pool_holder_offset_in_bytes())); | |
730 __ movl(rax, Address(rax, mirror_offset)); | |
731 __ bind(done); | |
732 } | |
733 #ifdef ASSERT | |
734 { Label L; | |
735 __ cmpl(rax, Address(rdx, BasicObjectLock::obj_offset_in_bytes())); // correct object? | |
736 __ jcc(Assembler::equal, L); | |
737 __ stop("wrong synchronization lobject"); | |
738 __ bind(L); | |
739 } | |
740 #endif // ASSERT | |
741 // can destroy rax, rdx, rcx, and (via call_VM) rdi! | |
742 __ lock_object(rdx); | |
743 } | |
744 | |
745 // Call an accessor method (assuming it is resolved, otherwise drop into vanilla (slow path) entry | |
746 | |
747 address InterpreterGenerator::generate_accessor_entry(void) { | |
748 | |
749 // rbx,: methodOop | |
750 // rcx: receiver (preserve for slow entry into asm interpreter) | |
751 | |
752 // rsi: senderSP must preserved for slow path, set SP to it on fast path | |
753 | |
754 Label xreturn_path; | |
755 | |
756 // do fastpath for resolved accessor methods | |
757 if (UseFastAccessorMethods) { | |
758 | |
759 address entry_point = __ pc(); | |
760 | |
761 Label slow_path; | |
762 // If we need a safepoint check, generate full interpreter entry. | |
763 ExternalAddress state(SafepointSynchronize::address_of_state()); | |
764 __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()), | |
765 SafepointSynchronize::_not_synchronized); | |
766 | |
767 __ jcc(Assembler::notEqual, slow_path); | |
768 // ASM/C++ Interpreter | |
769 // Code: _aload_0, _(i|a)getfield, _(i|a)return or any rewrites thereof; parameter size = 1 | |
770 // Note: We can only use this code if the getfield has been resolved | |
771 // and if we don't have a null-pointer exception => check for | |
772 // these conditions first and use slow path if necessary. | |
773 // rbx,: method | |
774 // rcx: receiver | |
775 __ movl(rax, Address(rsp, wordSize)); | |
776 | |
777 // check if local 0 != NULL and read field | |
778 __ testl(rax, rax); | |
779 __ jcc(Assembler::zero, slow_path); | |
780 | |
781 __ movl(rdi, Address(rbx, methodOopDesc::constants_offset())); | |
782 // read first instruction word and extract bytecode @ 1 and index @ 2 | |
783 __ movl(rdx, Address(rbx, methodOopDesc::const_offset())); | |
784 __ movl(rdx, Address(rdx, constMethodOopDesc::codes_offset())); | |
785 // Shift codes right to get the index on the right. | |
786 // The bytecode fetched looks like <index><0xb4><0x2a> | |
787 __ shrl(rdx, 2*BitsPerByte); | |
788 __ shll(rdx, exact_log2(in_words(ConstantPoolCacheEntry::size()))); | |
789 __ movl(rdi, Address(rdi, constantPoolOopDesc::cache_offset_in_bytes())); | |
790 | |
791 // rax,: local 0 | |
792 // rbx,: method | |
793 // rcx: receiver - do not destroy since it is needed for slow path! | |
794 // rcx: scratch | |
795 // rdx: constant pool cache index | |
796 // rdi: constant pool cache | |
797 // rsi: sender sp | |
798 | |
799 // check if getfield has been resolved and read constant pool cache entry | |
800 // check the validity of the cache entry by testing whether _indices field | |
801 // contains Bytecode::_getfield in b1 byte. | |
802 assert(in_words(ConstantPoolCacheEntry::size()) == 4, "adjust shift below"); | |
803 __ movl(rcx, | |
804 Address(rdi, | |
805 rdx, | |
806 Address::times_4, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::indices_offset())); | |
807 __ shrl(rcx, 2*BitsPerByte); | |
808 __ andl(rcx, 0xFF); | |
809 __ cmpl(rcx, Bytecodes::_getfield); | |
810 __ jcc(Assembler::notEqual, slow_path); | |
811 | |
812 // Note: constant pool entry is not valid before bytecode is resolved | |
813 __ movl(rcx, | |
814 Address(rdi, | |
815 rdx, | |
816 Address::times_4, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::f2_offset())); | |
817 __ movl(rdx, | |
818 Address(rdi, | |
819 rdx, | |
820 Address::times_4, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::flags_offset())); | |
821 | |
822 Label notByte, notShort, notChar; | |
823 const Address field_address (rax, rcx, Address::times_1); | |
824 | |
825 // Need to differentiate between igetfield, agetfield, bgetfield etc. | |
826 // because they are different sizes. | |
827 // Use the type from the constant pool cache | |
828 __ shrl(rdx, ConstantPoolCacheEntry::tosBits); | |
829 // Make sure we don't need to mask rdx for tosBits after the above shift | |
830 ConstantPoolCacheEntry::verify_tosBits(); | |
831 __ cmpl(rdx, btos); | |
832 __ jcc(Assembler::notEqual, notByte); | |
833 __ load_signed_byte(rax, field_address); | |
834 __ jmp(xreturn_path); | |
835 | |
836 __ bind(notByte); | |
837 __ cmpl(rdx, stos); | |
838 __ jcc(Assembler::notEqual, notShort); | |
839 __ load_signed_word(rax, field_address); | |
840 __ jmp(xreturn_path); | |
841 | |
842 __ bind(notShort); | |
843 __ cmpl(rdx, ctos); | |
844 __ jcc(Assembler::notEqual, notChar); | |
845 __ load_unsigned_word(rax, field_address); | |
846 __ jmp(xreturn_path); | |
847 | |
848 __ bind(notChar); | |
849 #ifdef ASSERT | |
850 Label okay; | |
851 __ cmpl(rdx, atos); | |
852 __ jcc(Assembler::equal, okay); | |
853 __ cmpl(rdx, itos); | |
854 __ jcc(Assembler::equal, okay); | |
855 __ stop("what type is this?"); | |
856 __ bind(okay); | |
857 #endif // ASSERT | |
858 // All the rest are a 32 bit wordsize | |
859 __ movl(rax, field_address); | |
860 | |
861 __ bind(xreturn_path); | |
862 | |
863 // _ireturn/_areturn | |
864 __ popl(rdi); // get return address | |
865 __ movl(rsp, rsi); // set sp to sender sp | |
866 __ jmp(rdi); | |
867 | |
868 // generate a vanilla interpreter entry as the slow path | |
869 __ bind(slow_path); | |
870 // We will enter c++ interpreter looking like it was | |
871 // called by the call_stub this will cause it to return | |
872 // a tosca result to the invoker which might have been | |
873 // the c++ interpreter itself. | |
874 | |
875 __ jmp(fast_accessor_slow_entry_path); | |
876 return entry_point; | |
877 | |
878 } else { | |
879 return NULL; | |
880 } | |
881 | |
882 } | |
883 | |
884 // | |
885 // C++ Interpreter stub for calling a native method. | |
886 // This sets up a somewhat different looking stack for calling the native method | |
887 // than the typical interpreter frame setup but still has the pointer to | |
888 // an interpreter state. | |
889 // | |
890 | |
891 address InterpreterGenerator::generate_native_entry(bool synchronized) { | |
892 // determine code generation flags | |
893 bool inc_counter = UseCompiler || CountCompiledCalls; | |
894 | |
895 // rbx: methodOop | |
896 // rcx: receiver (unused) | |
897 // rsi: previous interpreter state (if called from C++ interpreter) must preserve | |
898 // in any case. If called via c1/c2/call_stub rsi is junk (to use) but harmless | |
899 // to save/restore. | |
900 address entry_point = __ pc(); | |
901 | |
902 const Address size_of_parameters(rbx, methodOopDesc::size_of_parameters_offset()); | |
903 const Address size_of_locals (rbx, methodOopDesc::size_of_locals_offset()); | |
904 const Address invocation_counter(rbx, methodOopDesc::invocation_counter_offset() + InvocationCounter::counter_offset()); | |
905 const Address access_flags (rbx, methodOopDesc::access_flags_offset()); | |
906 | |
907 // rsi == state/locals rdi == prevstate | |
908 const Register state = rsi; | |
909 const Register locals = rdi; | |
910 | |
911 // get parameter size (always needed) | |
912 __ load_unsigned_word(rcx, size_of_parameters); | |
913 | |
914 // rbx: methodOop | |
915 // rcx: size of parameters | |
916 __ popl(rax); // get return address | |
917 // for natives the size of locals is zero | |
918 | |
919 // compute beginning of parameters /locals | |
920 __ leal(locals, Address(rsp, rcx, Address::times_4, -wordSize)); | |
921 | |
922 // initialize fixed part of activation frame | |
923 | |
924 // Assumes rax = return address | |
925 | |
926 // allocate and initialize new interpreterState and method expression stack | |
927 // IN(locals) -> locals | |
928 // IN(state) -> previous frame manager state (NULL from stub/c1/c2) | |
929 // destroys rax, rcx, rdx | |
930 // OUT (state) -> new interpreterState | |
931 // OUT(rsp) -> bottom of methods expression stack | |
932 | |
933 // save sender_sp | |
934 __ movl(rcx, rsi); | |
935 // start with NULL previous state | |
936 __ movl(state, 0); | |
937 generate_compute_interpreter_state(state, locals, rcx, true); | |
938 | |
939 #ifdef ASSERT | |
940 { Label L; | |
941 __ movl(rax, STATE(_stack_base)); | |
942 __ cmpl(rax, rsp); | |
943 __ jcc(Assembler::equal, L); | |
944 __ stop("broken stack frame setup in interpreter"); | |
945 __ bind(L); | |
946 } | |
947 #endif | |
948 | |
949 if (inc_counter) __ movl(rcx, invocation_counter); // (pre-)fetch invocation count | |
950 | |
951 __ movl(rax, STATE(_thread)); // get thread | |
952 // Since at this point in the method invocation the exception handler | |
953 // would try to exit the monitor of synchronized methods which hasn't | |
954 // been entered yet, we set the thread local variable | |
955 // _do_not_unlock_if_synchronized to true. The remove_activation will | |
956 // check this flag. | |
957 | |
958 const Address do_not_unlock_if_synchronized(rax, | |
959 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset())); | |
960 __ movbool(do_not_unlock_if_synchronized, true); | |
961 | |
962 // make sure method is native & not abstract | |
963 #ifdef ASSERT | |
964 __ movl(rax, access_flags); | |
965 { | |
966 Label L; | |
967 __ testl(rax, JVM_ACC_NATIVE); | |
968 __ jcc(Assembler::notZero, L); | |
969 __ stop("tried to execute non-native method as native"); | |
970 __ bind(L); | |
971 } | |
972 { Label L; | |
973 __ testl(rax, JVM_ACC_ABSTRACT); | |
974 __ jcc(Assembler::zero, L); | |
975 __ stop("tried to execute abstract method in interpreter"); | |
976 __ bind(L); | |
977 } | |
978 #endif | |
979 | |
980 | |
981 // increment invocation count & check for overflow | |
982 Label invocation_counter_overflow; | |
983 if (inc_counter) { | |
984 generate_counter_incr(&invocation_counter_overflow, NULL, NULL); | |
985 } | |
986 | |
987 Label continue_after_compile; | |
988 | |
989 __ bind(continue_after_compile); | |
990 | |
991 bang_stack_shadow_pages(true); | |
992 | |
993 // reset the _do_not_unlock_if_synchronized flag | |
994 __ movl(rax, STATE(_thread)); // get thread | |
995 __ movbool(do_not_unlock_if_synchronized, false); | |
996 | |
997 | |
998 // check for synchronized native methods | |
999 // | |
1000 // Note: This must happen *after* invocation counter check, since | |
1001 // when overflow happens, the method should not be locked. | |
1002 if (synchronized) { | |
1003 // potentially kills rax, rcx, rdx, rdi | |
1004 lock_method(); | |
1005 } else { | |
1006 // no synchronization necessary | |
1007 #ifdef ASSERT | |
1008 { Label L; | |
1009 __ movl(rax, access_flags); | |
1010 __ testl(rax, JVM_ACC_SYNCHRONIZED); | |
1011 __ jcc(Assembler::zero, L); | |
1012 __ stop("method needs synchronization"); | |
1013 __ bind(L); | |
1014 } | |
1015 #endif | |
1016 } | |
1017 | |
1018 // start execution | |
1019 | |
1020 // jvmti support | |
1021 __ notify_method_entry(); | |
1022 | |
1023 // work registers | |
1024 const Register method = rbx; | |
1025 const Register thread = rdi; | |
1026 const Register t = rcx; | |
1027 | |
1028 // allocate space for parameters | |
1029 __ movl(method, STATE(_method)); | |
1030 __ verify_oop(method); | |
1031 __ load_unsigned_word(t, Address(method, methodOopDesc::size_of_parameters_offset())); | |
1032 __ shll(t, 2); | |
1033 __ addl(t, 2*wordSize); // allocate two more slots for JNIEnv and possible mirror | |
1034 __ subl(rsp, t); | |
1035 __ andl(rsp, -(StackAlignmentInBytes)); // gcc needs 16 byte aligned stacks to do XMM intrinsics | |
1036 | |
1037 // get signature handler | |
1038 Label pending_exception_present; | |
1039 | |
1040 { Label L; | |
1041 __ movl(t, Address(method, methodOopDesc::signature_handler_offset())); | |
1042 __ testl(t, t); | |
1043 __ jcc(Assembler::notZero, L); | |
1044 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), method, false); | |
1045 __ movl(method, STATE(_method)); | |
1046 __ cmpl(Address(thread, Thread::pending_exception_offset()), NULL_WORD); | |
1047 __ jcc(Assembler::notEqual, pending_exception_present); | |
1048 __ verify_oop(method); | |
1049 __ movl(t, Address(method, methodOopDesc::signature_handler_offset())); | |
1050 __ bind(L); | |
1051 } | |
1052 #ifdef ASSERT | |
1053 { | |
1054 Label L; | |
1055 __ pushl(t); | |
1056 __ get_thread(t); // get vm's javathread* | |
1057 __ cmpl(t, STATE(_thread)); | |
1058 __ jcc(Assembler::equal, L); | |
1059 __ int3(); | |
1060 __ bind(L); | |
1061 __ popl(t); | |
1062 } | |
1063 #endif // | |
1064 | |
1065 // call signature handler | |
1066 assert(InterpreterRuntime::SignatureHandlerGenerator::from() == rdi, "adjust this code"); | |
1067 assert(InterpreterRuntime::SignatureHandlerGenerator::to () == rsp, "adjust this code"); | |
1068 assert(InterpreterRuntime::SignatureHandlerGenerator::temp() == t , "adjust this code"); | |
1069 // The generated handlers do not touch RBX (the method oop). | |
1070 // However, large signatures cannot be cached and are generated | |
1071 // each time here. The slow-path generator will blow RBX | |
1072 // sometime, so we must reload it after the call. | |
1073 __ movl(rdi, STATE(_locals)); // get the from pointer | |
1074 __ call(t); | |
1075 __ movl(method, STATE(_method)); | |
1076 __ verify_oop(method); | |
1077 | |
1078 // result handler is in rax | |
1079 // set result handler | |
1080 __ movl(STATE(_result_handler), rax); | |
1081 | |
1082 // pass mirror handle if static call | |
1083 { Label L; | |
1084 const int mirror_offset = klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes(); | |
1085 __ movl(t, Address(method, methodOopDesc::access_flags_offset())); | |
1086 __ testl(t, JVM_ACC_STATIC); | |
1087 __ jcc(Assembler::zero, L); | |
1088 // get mirror | |
1089 __ movl(t, Address(method, methodOopDesc:: constants_offset())); | |
1090 __ movl(t, Address(t, constantPoolOopDesc::pool_holder_offset_in_bytes())); | |
1091 __ movl(t, Address(t, mirror_offset)); | |
1092 // copy mirror into activation object | |
1093 __ movl(STATE(_oop_temp), t); | |
1094 // pass handle to mirror | |
1095 __ leal(t, STATE(_oop_temp)); | |
1096 __ movl(Address(rsp, wordSize), t); | |
1097 __ bind(L); | |
1098 } | |
1099 #ifdef ASSERT | |
1100 { | |
1101 Label L; | |
1102 __ pushl(t); | |
1103 __ get_thread(t); // get vm's javathread* | |
1104 __ cmpl(t, STATE(_thread)); | |
1105 __ jcc(Assembler::equal, L); | |
1106 __ int3(); | |
1107 __ bind(L); | |
1108 __ popl(t); | |
1109 } | |
1110 #endif // | |
1111 | |
1112 // get native function entry point | |
1113 { Label L; | |
1114 __ movl(rax, Address(method, methodOopDesc::native_function_offset())); | |
1115 __ testl(rax, rax); | |
1116 __ jcc(Assembler::notZero, L); | |
1117 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), method); | |
1118 __ movl(method, STATE(_method)); | |
1119 __ verify_oop(method); | |
1120 __ movl(rax, Address(method, methodOopDesc::native_function_offset())); | |
1121 __ bind(L); | |
1122 } | |
1123 | |
1124 // pass JNIEnv | |
1125 __ movl(thread, STATE(_thread)); // get thread | |
1126 __ leal(t, Address(thread, JavaThread::jni_environment_offset())); | |
1127 __ movl(Address(rsp, 0), t); | |
1128 #ifdef ASSERT | |
1129 { | |
1130 Label L; | |
1131 __ pushl(t); | |
1132 __ get_thread(t); // get vm's javathread* | |
1133 __ cmpl(t, STATE(_thread)); | |
1134 __ jcc(Assembler::equal, L); | |
1135 __ int3(); | |
1136 __ bind(L); | |
1137 __ popl(t); | |
1138 } | |
1139 #endif // | |
1140 | |
1141 #ifdef ASSERT | |
1142 { Label L; | |
1143 __ movl(t, Address(thread, JavaThread::thread_state_offset())); | |
1144 __ cmpl(t, _thread_in_Java); | |
1145 __ jcc(Assembler::equal, L); | |
1146 __ stop("Wrong thread state in native stub"); | |
1147 __ bind(L); | |
1148 } | |
1149 #endif | |
1150 | |
1151 // Change state to native (we save the return address in the thread, since it might not | |
1152 // be pushed on the stack when we do a a stack traversal). It is enough that the pc() | |
1153 // points into the right code segment. It does not have to be the correct return pc. | |
1154 | |
1155 __ set_last_Java_frame(thread, noreg, rbp, __ pc()); | |
1156 | |
1157 __ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_native); | |
1158 | |
1159 __ call(rax); | |
1160 | |
1161 // result potentially in rdx:rax or ST0 | |
1162 __ movl(method, STATE(_method)); | |
1163 __ movl(thread, STATE(_thread)); // get thread | |
1164 | |
1165 // The potential result is in ST(0) & rdx:rax | |
1166 // With C++ interpreter we leave any possible result in ST(0) until we are in result handler and then | |
1167 // we do the appropriate stuff for returning the result. rdx:rax must always be saved because just about | |
1168 // anything we do here will destroy it, st(0) is only saved if we re-enter the vm where it would | |
1169 // be destroyed. | |
1170 // It is safe to do these pushes because state is _thread_in_native and return address will be found | |
1171 // via _last_native_pc and not via _last_jave_sp | |
1172 | |
1173 // Must save the value of ST(0) since it could be destroyed before we get to result handler | |
1174 { Label Lpush, Lskip; | |
1175 ExternalAddress float_handler(AbstractInterpreter::result_handler(T_FLOAT)); | |
1176 ExternalAddress double_handler(AbstractInterpreter::result_handler(T_DOUBLE)); | |
1177 __ cmpptr(STATE(_result_handler), float_handler.addr()); | |
1178 __ jcc(Assembler::equal, Lpush); | |
1179 __ cmpptr(STATE(_result_handler), double_handler.addr()); | |
1180 __ jcc(Assembler::notEqual, Lskip); | |
1181 __ bind(Lpush); | |
1182 __ push(dtos); | |
1183 __ bind(Lskip); | |
1184 } | |
1185 | |
1186 __ push(ltos); // save rax:rdx for potential use by result handler. | |
1187 | |
1188 // Either restore the MXCSR register after returning from the JNI Call | |
1189 // or verify that it wasn't changed. | |
1190 if (VM_Version::supports_sse()) { | |
1191 if (RestoreMXCSROnJNICalls) { | |
1192 __ ldmxcsr(ExternalAddress(StubRoutines::addr_mxcsr_std())); | |
1193 } | |
1194 else if (CheckJNICalls ) { | |
1195 __ call(RuntimeAddress(StubRoutines::i486::verify_mxcsr_entry())); | |
1196 } | |
1197 } | |
1198 | |
1199 // Either restore the x87 floating pointer control word after returning | |
1200 // from the JNI call or verify that it wasn't changed. | |
1201 if (CheckJNICalls) { | |
1202 __ call(RuntimeAddress(StubRoutines::i486::verify_fpu_cntrl_wrd_entry())); | |
1203 } | |
1204 | |
1205 | |
1206 // change thread state | |
1207 __ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_native_trans); | |
1208 if(os::is_MP()) { | |
1209 // Write serialization page so VM thread can do a pseudo remote membar. | |
1210 // We use the current thread pointer to calculate a thread specific | |
1211 // offset to write to within the page. This minimizes bus traffic | |
1212 // due to cache line collision. | |
1213 __ serialize_memory(thread, rcx); | |
1214 } | |
1215 | |
1216 // check for safepoint operation in progress and/or pending suspend requests | |
1217 { Label Continue; | |
1218 | |
1219 __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()), | |
1220 SafepointSynchronize::_not_synchronized); | |
1221 | |
1222 // threads running native code and they are expected to self-suspend | |
1223 // when leaving the _thread_in_native state. We need to check for | |
1224 // pending suspend requests here. | |
1225 Label L; | |
1226 __ jcc(Assembler::notEqual, L); | |
1227 __ cmpl(Address(thread, JavaThread::suspend_flags_offset()), 0); | |
1228 __ jcc(Assembler::equal, Continue); | |
1229 __ bind(L); | |
1230 | |
1231 // Don't use call_VM as it will see a possible pending exception and forward it | |
1232 // and never return here preventing us from clearing _last_native_pc down below. | |
1233 // Also can't use call_VM_leaf either as it will check to see if rsi & rdi are | |
1234 // preserved and correspond to the bcp/locals pointers. So we do a runtime call | |
1235 // by hand. | |
1236 // | |
1237 __ pushl(thread); | |
1238 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, | |
1239 JavaThread::check_special_condition_for_native_trans))); | |
1240 __ increment(rsp, wordSize); | |
1241 | |
1242 __ movl(method, STATE(_method)); | |
1243 __ verify_oop(method); | |
1244 __ movl(thread, STATE(_thread)); // get thread | |
1245 | |
1246 __ bind(Continue); | |
1247 } | |
1248 | |
1249 // change thread state | |
1250 __ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_Java); | |
1251 | |
1252 __ reset_last_Java_frame(thread, true, true); | |
1253 | |
1254 // reset handle block | |
1255 __ movl(t, Address(thread, JavaThread::active_handles_offset())); | |
1256 __ movl(Address(t, JNIHandleBlock::top_offset_in_bytes()), NULL_WORD); | |
1257 | |
1258 // If result was an oop then unbox and save it in the frame | |
1259 { Label L; | |
1260 Label no_oop, store_result; | |
1261 ExternalAddress oop_handler(AbstractInterpreter::result_handler(T_OBJECT)); | |
1262 __ cmpptr(STATE(_result_handler), oop_handler.addr()); | |
1263 __ jcc(Assembler::notEqual, no_oop); | |
1264 __ pop(ltos); | |
1265 __ testl(rax, rax); | |
1266 __ jcc(Assembler::zero, store_result); | |
1267 // unbox | |
1268 __ movl(rax, Address(rax, 0)); | |
1269 __ bind(store_result); | |
1270 __ movl(STATE(_oop_temp), rax); | |
1271 // keep stack depth as expected by pushing oop which will eventually be discarded | |
1272 __ push(ltos); | |
1273 __ bind(no_oop); | |
1274 } | |
1275 | |
1276 { | |
1277 Label no_reguard; | |
1278 __ cmpl(Address(thread, JavaThread::stack_guard_state_offset()), JavaThread::stack_guard_yellow_disabled); | |
1279 __ jcc(Assembler::notEqual, no_reguard); | |
1280 | |
1281 __ pushad(); | |
1282 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages))); | |
1283 __ popad(); | |
1284 | |
1285 __ bind(no_reguard); | |
1286 } | |
1287 | |
1288 | |
1289 // QQQ Seems like for native methods we simply return and the caller will see the pending | |
1290 // exception and do the right thing. Certainly the interpreter will, don't know about | |
1291 // compiled methods. | |
1292 // Seems that the answer to above is no this is wrong. The old code would see the exception | |
1293 // and forward it before doing the unlocking and notifying jvmdi that method has exited. | |
1294 // This seems wrong need to investigate the spec. | |
1295 | |
1296 // handle exceptions (exception handling will handle unlocking!) | |
1297 { Label L; | |
1298 __ cmpl(Address(thread, Thread::pending_exception_offset()), NULL_WORD); | |
1299 __ jcc(Assembler::zero, L); | |
1300 __ bind(pending_exception_present); | |
1301 | |
1302 // There are potential results on the stack (rax/rdx, ST(0)) we ignore these and simply | |
1303 // return and let caller deal with exception. This skips the unlocking here which | |
1304 // seems wrong but seems to be what asm interpreter did. Can't find this in the spec. | |
1305 // Note: must preverve method in rbx | |
1306 // | |
1307 | |
1308 // remove activation | |
1309 | |
1310 __ movl(t, STATE(_sender_sp)); | |
1311 __ leave(); // remove frame anchor | |
1312 __ popl(rdi); // get return address | |
1313 __ movl(state, STATE(_prev_link)); // get previous state for return | |
1314 __ movl(rsp, t); // set sp to sender sp | |
1315 __ pushl(rdi); // [ush throwing pc | |
1316 // The skips unlocking!! This seems to be what asm interpreter does but seems | |
1317 // very wrong. Not clear if this violates the spec. | |
1318 __ jump(RuntimeAddress(StubRoutines::forward_exception_entry())); | |
1319 __ bind(L); | |
1320 } | |
1321 | |
1322 // do unlocking if necessary | |
1323 { Label L; | |
1324 __ movl(t, Address(method, methodOopDesc::access_flags_offset())); | |
1325 __ testl(t, JVM_ACC_SYNCHRONIZED); | |
1326 __ jcc(Assembler::zero, L); | |
1327 // the code below should be shared with interpreter macro assembler implementation | |
1328 { Label unlock; | |
1329 // BasicObjectLock will be first in list, since this is a synchronized method. However, need | |
1330 // to check that the object has not been unlocked by an explicit monitorexit bytecode. | |
1331 __ movl(rdx, STATE(_monitor_base)); | |
1332 __ subl(rdx, frame::interpreter_frame_monitor_size() * wordSize); // address of initial monitor | |
1333 | |
1334 __ movl(t, Address(rdx, BasicObjectLock::obj_offset_in_bytes())); | |
1335 __ testl(t, t); | |
1336 __ jcc(Assembler::notZero, unlock); | |
1337 | |
1338 // Entry already unlocked, need to throw exception | |
1339 __ MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception)); | |
1340 __ should_not_reach_here(); | |
1341 | |
1342 __ bind(unlock); | |
1343 __ unlock_object(rdx); | |
1344 // unlock can blow rbx so restore it for path that needs it below | |
1345 __ movl(method, STATE(_method)); | |
1346 } | |
1347 __ bind(L); | |
1348 } | |
1349 | |
1350 // jvmti support | |
1351 // Note: This must happen _after_ handling/throwing any exceptions since | |
1352 // the exception handler code notifies the runtime of method exits | |
1353 // too. If this happens before, method entry/exit notifications are | |
1354 // not properly paired (was bug - gri 11/22/99). | |
1355 __ notify_method_exit(vtos, InterpreterMacroAssembler::NotifyJVMTI); | |
1356 | |
1357 // restore potential result in rdx:rax, call result handler to restore potential result in ST0 & handle result | |
1358 __ pop(ltos); // restore rax/rdx floating result if present still on stack | |
1359 __ movl(t, STATE(_result_handler)); // get result handler | |
1360 __ call(t); // call result handler to convert to tosca form | |
1361 | |
1362 // remove activation | |
1363 | |
1364 __ movl(t, STATE(_sender_sp)); | |
1365 | |
1366 __ leave(); // remove frame anchor | |
1367 __ popl(rdi); // get return address | |
1368 __ movl(state, STATE(_prev_link)); // get previous state for return (if c++ interpreter was caller) | |
1369 __ movl(rsp, t); // set sp to sender sp | |
1370 __ jmp(rdi); | |
1371 | |
1372 // invocation counter overflow | |
1373 if (inc_counter) { | |
1374 // Handle overflow of counter and compile method | |
1375 __ bind(invocation_counter_overflow); | |
1376 generate_counter_overflow(&continue_after_compile); | |
1377 } | |
1378 | |
1379 return entry_point; | |
1380 } | |
1381 | |
1382 // Generate entries that will put a result type index into rcx | |
1383 void CppInterpreterGenerator::generate_deopt_handling() { | |
1384 | |
1385 const Register state = rsi; | |
1386 Label return_from_deopt_common; | |
1387 | |
1388 // Generate entries that will put a result type index into rcx | |
1389 // deopt needs to jump to here to enter the interpreter (return a result) | |
1390 deopt_frame_manager_return_atos = __ pc(); | |
1391 | |
1392 // rax is live here | |
1393 __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_OBJECT)); // Result stub address array index | |
1394 __ jmp(return_from_deopt_common); | |
1395 | |
1396 | |
1397 // deopt needs to jump to here to enter the interpreter (return a result) | |
1398 deopt_frame_manager_return_btos = __ pc(); | |
1399 | |
1400 // rax is live here | |
1401 __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_BOOLEAN)); // Result stub address array index | |
1402 __ jmp(return_from_deopt_common); | |
1403 | |
1404 // deopt needs to jump to here to enter the interpreter (return a result) | |
1405 deopt_frame_manager_return_itos = __ pc(); | |
1406 | |
1407 // rax is live here | |
1408 __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_INT)); // Result stub address array index | |
1409 __ jmp(return_from_deopt_common); | |
1410 | |
1411 // deopt needs to jump to here to enter the interpreter (return a result) | |
1412 | |
1413 deopt_frame_manager_return_ltos = __ pc(); | |
1414 // rax,rdx are live here | |
1415 __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_LONG)); // Result stub address array index | |
1416 __ jmp(return_from_deopt_common); | |
1417 | |
1418 // deopt needs to jump to here to enter the interpreter (return a result) | |
1419 | |
1420 deopt_frame_manager_return_ftos = __ pc(); | |
1421 // st(0) is live here | |
1422 __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_FLOAT)); // Result stub address array index | |
1423 __ jmp(return_from_deopt_common); | |
1424 | |
1425 // deopt needs to jump to here to enter the interpreter (return a result) | |
1426 deopt_frame_manager_return_dtos = __ pc(); | |
1427 | |
1428 // st(0) is live here | |
1429 __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_DOUBLE)); // Result stub address array index | |
1430 __ jmp(return_from_deopt_common); | |
1431 | |
1432 // deopt needs to jump to here to enter the interpreter (return a result) | |
1433 deopt_frame_manager_return_vtos = __ pc(); | |
1434 | |
1435 __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_VOID)); | |
1436 | |
1437 // Deopt return common | |
1438 // an index is present in rcx that lets us move any possible result being | |
1439 // return to the interpreter's stack | |
1440 // | |
1441 // Because we have a full sized interpreter frame on the youngest | |
1442 // activation the stack is pushed too deep to share the tosca to | |
1443 // stack converters directly. We shrink the stack to the desired | |
1444 // amount and then push result and then re-extend the stack. | |
1445 // We could have the code in size_activation layout a short | |
1446 // frame for the top activation but that would look different | |
1447 // than say sparc (which needs a full size activation because | |
1448 // the windows are in the way. Really it could be short? QQQ | |
1449 // | |
1450 __ bind(return_from_deopt_common); | |
1451 | |
1452 __ leal(state, Address(rbp, -(int)sizeof(BytecodeInterpreter))); | |
1453 | |
1454 // setup rsp so we can push the "result" as needed. | |
1455 __ movl(rsp, STATE(_stack)); // trim stack (is prepushed) | |
1456 __ addl(rsp, wordSize); // undo prepush | |
1457 | |
1458 ExternalAddress tosca_to_stack((address)CppInterpreter::_tosca_to_stack); | |
1459 // Address index(noreg, rcx, Address::times_4); | |
1460 __ movptr(rcx, ArrayAddress(tosca_to_stack, Address(noreg, rcx, Address::times_4))); | |
1461 // __ movl(rcx, Address(noreg, rcx, Address::times_4, int(AbstractInterpreter::_tosca_to_stack))); | |
1462 __ call(rcx); // call result converter | |
1463 | |
1464 __ movl(STATE(_msg), (int)BytecodeInterpreter::deopt_resume); | |
1465 __ leal(rsp, Address(rsp, -wordSize)); // prepush stack (result if any already present) | |
1466 __ movl(STATE(_stack), rsp); // inform interpreter of new stack depth (parameters removed, | |
1467 // result if any on stack already ) | |
1468 __ movl(rsp, STATE(_stack_limit)); // restore expression stack to full depth | |
1469 } | |
1470 | |
1471 // Generate the code to handle a more_monitors message from the c++ interpreter | |
1472 void CppInterpreterGenerator::generate_more_monitors() { | |
1473 | |
1474 const Register state = rsi; | |
1475 | |
1476 Label entry, loop; | |
1477 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; | |
1478 // 1. compute new pointers // rsp: old expression stack top | |
1479 __ movl(rdx, STATE(_stack_base)); // rdx: old expression stack bottom | |
1480 __ subl(rsp, entry_size); // move expression stack top limit | |
1481 __ subl(STATE(_stack), entry_size); // update interpreter stack top | |
1482 __ movl(STATE(_stack_limit), rsp); // inform interpreter | |
1483 __ subl(rdx, entry_size); // move expression stack bottom | |
1484 __ movl(STATE(_stack_base), rdx); // inform interpreter | |
1485 __ movl(rcx, STATE(_stack)); // set start value for copy loop | |
1486 __ jmp(entry); | |
1487 // 2. move expression stack contents | |
1488 __ bind(loop); | |
1489 __ movl(rbx, Address(rcx, entry_size)); // load expression stack word from old location | |
1490 __ movl(Address(rcx, 0), rbx); // and store it at new location | |
1491 __ addl(rcx, wordSize); // advance to next word | |
1492 __ bind(entry); | |
1493 __ cmpl(rcx, rdx); // check if bottom reached | |
1494 __ jcc(Assembler::notEqual, loop); // if not at bottom then copy next word | |
1495 // now zero the slot so we can find it. | |
1496 __ movl(Address(rdx, BasicObjectLock::obj_offset_in_bytes()), (int) NULL); | |
1497 __ movl(STATE(_msg), (int)BytecodeInterpreter::got_monitors); | |
1498 } | |
1499 | |
1500 | |
1501 // Initial entry to C++ interpreter from the call_stub. | |
1502 // This entry point is called the frame manager since it handles the generation | |
1503 // of interpreter activation frames via requests directly from the vm (via call_stub) | |
1504 // and via requests from the interpreter. The requests from the call_stub happen | |
1505 // directly thru the entry point. Requests from the interpreter happen via returning | |
1506 // from the interpreter and examining the message the interpreter has returned to | |
1507 // the frame manager. The frame manager can take the following requests: | |
1508 | |
1509 // NO_REQUEST - error, should never happen. | |
1510 // MORE_MONITORS - need a new monitor. Shuffle the expression stack on down and | |
1511 // allocate a new monitor. | |
1512 // CALL_METHOD - setup a new activation to call a new method. Very similar to what | |
1513 // happens during entry during the entry via the call stub. | |
1514 // RETURN_FROM_METHOD - remove an activation. Return to interpreter or call stub. | |
1515 // | |
1516 // Arguments: | |
1517 // | |
1518 // rbx: methodOop | |
1519 // rcx: receiver - unused (retrieved from stack as needed) | |
1520 // rsi: previous frame manager state (NULL from the call_stub/c1/c2) | |
1521 // | |
1522 // | |
1523 // Stack layout at entry | |
1524 // | |
1525 // [ return address ] <--- rsp | |
1526 // [ parameter n ] | |
1527 // ... | |
1528 // [ parameter 1 ] | |
1529 // [ expression stack ] | |
1530 // | |
1531 // | |
1532 // We are free to blow any registers we like because the call_stub which brought us here | |
1533 // initially has preserved the callee save registers already. | |
1534 // | |
1535 // | |
1536 | |
1537 static address interpreter_frame_manager = NULL; | |
1538 | |
1539 address InterpreterGenerator::generate_normal_entry(bool synchronized) { | |
1540 | |
1541 // rbx: methodOop | |
1542 // rsi: sender sp | |
1543 | |
1544 // Because we redispatch "recursive" interpreter entries thru this same entry point | |
1545 // the "input" register usage is a little strange and not what you expect coming | |
1546 // from the call_stub. From the call stub rsi/rdi (current/previous) interpreter | |
1547 // state are NULL but on "recursive" dispatches they are what you'd expect. | |
1548 // rsi: current interpreter state (C++ interpreter) must preserve (null from call_stub/c1/c2) | |
1549 | |
1550 | |
1551 // A single frame manager is plenty as we don't specialize for synchronized. We could and | |
1552 // the code is pretty much ready. Would need to change the test below and for good measure | |
1553 // modify generate_interpreter_state to only do the (pre) sync stuff stuff for synchronized | |
1554 // routines. Not clear this is worth it yet. | |
1555 | |
1556 if (interpreter_frame_manager) return interpreter_frame_manager; | |
1557 | |
1558 address entry_point = __ pc(); | |
1559 | |
1560 // Fast accessor methods share this entry point. | |
1561 // This works because frame manager is in the same codelet | |
1562 if (UseFastAccessorMethods && !synchronized) __ bind(fast_accessor_slow_entry_path); | |
1563 | |
1564 Label dispatch_entry_2; | |
1565 __ movl(rcx, rsi); | |
1566 __ movl(rsi, 0); // no current activation | |
1567 | |
1568 __ jmp(dispatch_entry_2); | |
1569 | |
1570 const Register state = rsi; // current activation object, valid on entry | |
1571 const Register locals = rdi; | |
1572 | |
1573 Label re_dispatch; | |
1574 | |
1575 __ bind(re_dispatch); | |
1576 | |
1577 // save sender sp (doesn't include return address | |
1578 __ leal(rcx, Address(rsp, wordSize)); | |
1579 | |
1580 __ bind(dispatch_entry_2); | |
1581 | |
1582 // save sender sp | |
1583 __ pushl(rcx); | |
1584 | |
1585 const Address size_of_parameters(rbx, methodOopDesc::size_of_parameters_offset()); | |
1586 const Address size_of_locals (rbx, methodOopDesc::size_of_locals_offset()); | |
1587 const Address access_flags (rbx, methodOopDesc::access_flags_offset()); | |
1588 | |
1589 // const Address monitor_block_top (rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize); | |
1590 // const Address monitor_block_bot (rbp, frame::interpreter_frame_initial_sp_offset * wordSize); | |
1591 // const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset * wordSize - (int)sizeof(BasicObjectLock)); | |
1592 | |
1593 // get parameter size (always needed) | |
1594 __ load_unsigned_word(rcx, size_of_parameters); | |
1595 | |
1596 // rbx: methodOop | |
1597 // rcx: size of parameters | |
1598 __ load_unsigned_word(rdx, size_of_locals); // get size of locals in words | |
1599 | |
1600 __ subl(rdx, rcx); // rdx = no. of additional locals | |
1601 | |
1602 // see if we've got enough room on the stack for locals plus overhead. | |
1603 generate_stack_overflow_check(); // C++ | |
1604 | |
1605 // c++ interpreter does not use stack banging or any implicit exceptions | |
1606 // leave for now to verify that check is proper. | |
1607 bang_stack_shadow_pages(false); | |
1608 | |
1609 | |
1610 | |
1611 // compute beginning of parameters (rdi) | |
1612 __ leal(locals, Address(rsp, rcx, Address::times_4, wordSize)); | |
1613 | |
1614 // save sender's sp | |
1615 // __ movl(rcx, rsp); | |
1616 | |
1617 // get sender's sp | |
1618 __ popl(rcx); | |
1619 | |
1620 // get return address | |
1621 __ popl(rax); | |
1622 | |
1623 // rdx - # of additional locals | |
1624 // allocate space for locals | |
1625 // explicitly initialize locals | |
1626 { | |
1627 Label exit, loop; | |
1628 __ testl(rdx, rdx); | |
1629 __ jcc(Assembler::lessEqual, exit); // do nothing if rdx <= 0 | |
1630 __ bind(loop); | |
1631 __ pushl((int)NULL); // initialize local variables | |
1632 __ decrement(rdx); // until everything initialized | |
1633 __ jcc(Assembler::greater, loop); | |
1634 __ bind(exit); | |
1635 } | |
1636 | |
1637 | |
1638 // Assumes rax = return address | |
1639 | |
1640 // allocate and initialize new interpreterState and method expression stack | |
1641 // IN(locals) -> locals | |
1642 // IN(state) -> any current interpreter activation | |
1643 // destroys rax, rcx, rdx, rdi | |
1644 // OUT (state) -> new interpreterState | |
1645 // OUT(rsp) -> bottom of methods expression stack | |
1646 | |
1647 generate_compute_interpreter_state(state, locals, rcx, false); | |
1648 | |
1649 // Call interpreter | |
1650 | |
1651 Label call_interpreter; | |
1652 __ bind(call_interpreter); | |
1653 | |
1654 // c++ interpreter does not use stack banging or any implicit exceptions | |
1655 // leave for now to verify that check is proper. | |
1656 bang_stack_shadow_pages(false); | |
1657 | |
1658 | |
1659 // Call interpreter enter here if message is | |
1660 // set and we know stack size is valid | |
1661 | |
1662 Label call_interpreter_2; | |
1663 | |
1664 __ bind(call_interpreter_2); | |
1665 | |
1666 { | |
1667 const Register thread = rcx; | |
1668 | |
1669 __ pushl(state); // push arg to interpreter | |
1670 __ movl(thread, STATE(_thread)); | |
1671 | |
1672 // We can setup the frame anchor with everything we want at this point | |
1673 // as we are thread_in_Java and no safepoints can occur until we go to | |
1674 // vm mode. We do have to clear flags on return from vm but that is it | |
1675 // | |
1676 __ movl(Address(thread, JavaThread::last_Java_fp_offset()), rbp); | |
1677 __ movl(Address(thread, JavaThread::last_Java_sp_offset()), rsp); | |
1678 | |
1679 // Call the interpreter | |
1680 | |
1681 RuntimeAddress normal(CAST_FROM_FN_PTR(address, BytecodeInterpreter::run)); | |
1682 RuntimeAddress checking(CAST_FROM_FN_PTR(address, BytecodeInterpreter::runWithChecks)); | |
1683 | |
1684 __ call(JvmtiExport::can_post_interpreter_events() ? checking : normal); | |
1685 __ popl(rax); // discard parameter to run | |
1686 // | |
1687 // state is preserved since it is callee saved | |
1688 // | |
1689 | |
1690 // reset_last_Java_frame | |
1691 | |
1692 __ movl(thread, STATE(_thread)); | |
1693 __ reset_last_Java_frame(thread, true, true); | |
1694 } | |
1695 | |
1696 // examine msg from interpreter to determine next action | |
1697 | |
1698 __ movl(rdx, STATE(_msg)); // Get new message | |
1699 | |
1700 Label call_method; | |
1701 Label return_from_interpreted_method; | |
1702 Label throw_exception; | |
1703 Label bad_msg; | |
1704 Label do_OSR; | |
1705 | |
1706 __ cmpl(rdx, (int)BytecodeInterpreter::call_method); | |
1707 __ jcc(Assembler::equal, call_method); | |
1708 __ cmpl(rdx, (int)BytecodeInterpreter::return_from_method); | |
1709 __ jcc(Assembler::equal, return_from_interpreted_method); | |
1710 __ cmpl(rdx, (int)BytecodeInterpreter::do_osr); | |
1711 __ jcc(Assembler::equal, do_OSR); | |
1712 __ cmpl(rdx, (int)BytecodeInterpreter::throwing_exception); | |
1713 __ jcc(Assembler::equal, throw_exception); | |
1714 __ cmpl(rdx, (int)BytecodeInterpreter::more_monitors); | |
1715 __ jcc(Assembler::notEqual, bad_msg); | |
1716 | |
1717 // Allocate more monitor space, shuffle expression stack.... | |
1718 | |
1719 generate_more_monitors(); | |
1720 | |
1721 __ jmp(call_interpreter); | |
1722 | |
1723 // uncommon trap needs to jump to here to enter the interpreter (re-execute current bytecode) | |
1724 unctrap_frame_manager_entry = __ pc(); | |
1725 // | |
1726 // Load the registers we need. | |
1727 __ leal(state, Address(rbp, -(int)sizeof(BytecodeInterpreter))); | |
1728 __ movl(rsp, STATE(_stack_limit)); // restore expression stack to full depth | |
1729 __ jmp(call_interpreter_2); | |
1730 | |
1731 | |
1732 | |
1733 //============================================================================= | |
1734 // Returning from a compiled method into a deopted method. The bytecode at the | |
1735 // bcp has completed. The result of the bytecode is in the native abi (the tosca | |
1736 // for the template based interpreter). Any stack space that was used by the | |
1737 // bytecode that has completed has been removed (e.g. parameters for an invoke) | |
1738 // so all that we have to do is place any pending result on the expression stack | |
1739 // and resume execution on the next bytecode. | |
1740 | |
1741 | |
1742 generate_deopt_handling(); | |
1743 __ jmp(call_interpreter); | |
1744 | |
1745 | |
1746 // Current frame has caught an exception we need to dispatch to the | |
1747 // handler. We can get here because a native interpreter frame caught | |
1748 // an exception in which case there is no handler and we must rethrow | |
1749 // If it is a vanilla interpreted frame the we simply drop into the | |
1750 // interpreter and let it do the lookup. | |
1751 | |
1752 Interpreter::_rethrow_exception_entry = __ pc(); | |
1753 // rax: exception | |
1754 // rdx: return address/pc that threw exception | |
1755 | |
1756 Label return_with_exception; | |
1757 Label unwind_and_forward; | |
1758 | |
1759 // restore state pointer. | |
1760 __ leal(state, Address(rbp, -sizeof(BytecodeInterpreter))); | |
1761 | |
1762 __ movl(rbx, STATE(_method)); // get method | |
1763 __ movl(rcx, STATE(_thread)); // get thread | |
1764 | |
1765 // Store exception with interpreter will expect it | |
1766 __ movl(Address(rcx, Thread::pending_exception_offset()), rax); | |
1767 | |
1768 // is current frame vanilla or native? | |
1769 | |
1770 __ movl(rdx, access_flags); | |
1771 __ testl(rdx, JVM_ACC_NATIVE); | |
1772 __ jcc(Assembler::zero, return_with_exception); // vanilla interpreted frame, handle directly | |
1773 | |
1774 // We drop thru to unwind a native interpreted frame with a pending exception | |
1775 // We jump here for the initial interpreter frame with exception pending | |
1776 // We unwind the current acivation and forward it to our caller. | |
1777 | |
1778 __ bind(unwind_and_forward); | |
1779 | |
1780 // unwind rbp, return stack to unextended value and re-push return address | |
1781 | |
1782 __ movl(rcx, STATE(_sender_sp)); | |
1783 __ leave(); | |
1784 __ popl(rdx); | |
1785 __ movl(rsp, rcx); | |
1786 __ pushl(rdx); | |
1787 __ jump(RuntimeAddress(StubRoutines::forward_exception_entry())); | |
1788 | |
1789 // Return point from a call which returns a result in the native abi | |
1790 // (c1/c2/jni-native). This result must be processed onto the java | |
1791 // expression stack. | |
1792 // | |
1793 // A pending exception may be present in which case there is no result present | |
1794 | |
1795 Label resume_interpreter; | |
1796 Label do_float; | |
1797 Label do_double; | |
1798 Label done_conv; | |
1799 | |
1800 address compiled_entry = __ pc(); | |
1801 | |
1802 // The FPU stack is clean if UseSSE >= 2 but must be cleaned in other cases | |
1803 if (UseSSE < 2) { | |
1804 __ leal(state, Address(rbp, -sizeof(BytecodeInterpreter))); | |
1805 __ movl(rbx, STATE(_result._to_call._callee)); // get method just executed | |
1806 __ movl(rcx, Address(rbx, methodOopDesc::result_index_offset())); | |
1807 __ cmpl(rcx, AbstractInterpreter::BasicType_as_index(T_FLOAT)); // Result stub address array index | |
1808 __ jcc(Assembler::equal, do_float); | |
1809 __ cmpl(rcx, AbstractInterpreter::BasicType_as_index(T_DOUBLE)); // Result stub address array index | |
1810 __ jcc(Assembler::equal, do_double); | |
1811 #ifdef COMPILER2 | |
1812 __ empty_FPU_stack(); | |
1813 #endif // COMPILER2 | |
1814 __ jmp(done_conv); | |
1815 | |
1816 __ bind(do_float); | |
1817 #ifdef COMPILER2 | |
1818 for (int i = 1; i < 8; i++) { | |
1819 __ ffree(i); | |
1820 } | |
1821 #endif // COMPILER2 | |
1822 __ jmp(done_conv); | |
1823 __ bind(do_double); | |
1824 #ifdef COMPILER2 | |
1825 for (int i = 1; i < 8; i++) { | |
1826 __ ffree(i); | |
1827 } | |
1828 #endif // COMPILER2 | |
1829 __ jmp(done_conv); | |
1830 } else { | |
1831 __ MacroAssembler::verify_FPU(0, "generate_return_entry_for compiled"); | |
1832 __ jmp(done_conv); | |
1833 } | |
1834 | |
1835 // emit a sentinel we can test for when converting an interpreter | |
1836 // entry point to a compiled entry point. | |
1837 __ a_long(Interpreter::return_sentinel); | |
1838 __ a_long((int)compiled_entry); | |
1839 | |
1840 // Return point to interpreter from compiled/native method | |
1841 | |
1842 InternalAddress return_from_native_method(__ pc()); | |
1843 | |
1844 __ bind(done_conv); | |
1845 | |
1846 | |
1847 // Result if any is in tosca. The java expression stack is in the state that the | |
1848 // calling convention left it (i.e. params may or may not be present) | |
1849 // Copy the result from tosca and place it on java expression stack. | |
1850 | |
1851 // Restore rsi as compiled code may not preserve it | |
1852 | |
1853 __ leal(state, Address(rbp, -sizeof(BytecodeInterpreter))); | |
1854 | |
1855 // restore stack to what we had when we left (in case i2c extended it) | |
1856 | |
1857 __ movl(rsp, STATE(_stack)); | |
1858 __ leal(rsp, Address(rsp, wordSize)); | |
1859 | |
1860 // If there is a pending exception then we don't really have a result to process | |
1861 | |
1862 __ movl(rcx, STATE(_thread)); // get thread | |
1863 __ cmpl(Address(rcx, Thread::pending_exception_offset()), (int)NULL); | |
1864 __ jcc(Assembler::notZero, return_with_exception); | |
1865 | |
1866 // get method just executed | |
1867 __ movl(rbx, STATE(_result._to_call._callee)); | |
1868 | |
1869 // callee left args on top of expression stack, remove them | |
1870 __ load_unsigned_word(rcx, Address(rbx, methodOopDesc::size_of_parameters_offset())); | |
1871 __ leal(rsp, Address(rsp, rcx, Address::times_4)); | |
1872 | |
1873 __ movl(rcx, Address(rbx, methodOopDesc::result_index_offset())); | |
1874 ExternalAddress tosca_to_stack((address)CppInterpreter::_tosca_to_stack); | |
1875 // Address index(noreg, rax, Address::times_4); | |
1876 __ movptr(rcx, ArrayAddress(tosca_to_stack, Address(noreg, rcx, Address::times_4))); | |
1877 // __ movl(rcx, Address(noreg, rcx, Address::times_4, int(AbstractInterpreter::_tosca_to_stack))); | |
1878 __ call(rcx); // call result converter | |
1879 __ jmp(resume_interpreter); | |
1880 | |
1881 // An exception is being caught on return to a vanilla interpreter frame. | |
1882 // Empty the stack and resume interpreter | |
1883 | |
1884 __ bind(return_with_exception); | |
1885 | |
1886 // Exception present, empty stack | |
1887 __ movl(rsp, STATE(_stack_base)); | |
1888 __ jmp(resume_interpreter); | |
1889 | |
1890 // Return from interpreted method we return result appropriate to the caller (i.e. "recursive" | |
1891 // interpreter call, or native) and unwind this interpreter activation. | |
1892 // All monitors should be unlocked. | |
1893 | |
1894 __ bind(return_from_interpreted_method); | |
1895 | |
1896 Label return_to_initial_caller; | |
1897 | |
1898 __ movl(rbx, STATE(_method)); // get method just executed | |
1899 __ cmpl(STATE(_prev_link), (int)NULL); // returning from "recursive" interpreter call? | |
1900 __ movl(rax, Address(rbx, methodOopDesc::result_index_offset())); // get result type index | |
1901 __ jcc(Assembler::equal, return_to_initial_caller); // back to native code (call_stub/c1/c2) | |
1902 | |
1903 // Copy result to callers java stack | |
1904 ExternalAddress stack_to_stack((address)CppInterpreter::_stack_to_stack); | |
1905 // Address index(noreg, rax, Address::times_4); | |
1906 | |
1907 __ movptr(rax, ArrayAddress(stack_to_stack, Address(noreg, rax, Address::times_4))); | |
1908 // __ movl(rax, Address(noreg, rax, Address::times_4, int(AbstractInterpreter::_stack_to_stack))); | |
1909 __ call(rax); // call result converter | |
1910 | |
1911 Label unwind_recursive_activation; | |
1912 __ bind(unwind_recursive_activation); | |
1913 | |
1914 // returning to interpreter method from "recursive" interpreter call | |
1915 // result converter left rax pointing to top of the java stack for method we are returning | |
1916 // to. Now all we must do is unwind the state from the completed call | |
1917 | |
1918 __ movl(state, STATE(_prev_link)); // unwind state | |
1919 __ leave(); // pop the frame | |
1920 __ movl(rsp, rax); // unwind stack to remove args | |
1921 | |
1922 // Resume the interpreter. The current frame contains the current interpreter | |
1923 // state object. | |
1924 // | |
1925 | |
1926 __ bind(resume_interpreter); | |
1927 | |
1928 // state == interpreterState object for method we are resuming | |
1929 | |
1930 __ movl(STATE(_msg), (int)BytecodeInterpreter::method_resume); | |
1931 __ leal(rsp, Address(rsp, -wordSize)); // prepush stack (result if any already present) | |
1932 __ movl(STATE(_stack), rsp); // inform interpreter of new stack depth (parameters removed, | |
1933 // result if any on stack already ) | |
1934 __ movl(rsp, STATE(_stack_limit)); // restore expression stack to full depth | |
1935 __ jmp(call_interpreter_2); // No need to bang | |
1936 | |
1937 // interpreter returning to native code (call_stub/c1/c2) | |
1938 // convert result and unwind initial activation | |
1939 // rax - result index | |
1940 | |
1941 __ bind(return_to_initial_caller); | |
1942 ExternalAddress stack_to_native((address)CppInterpreter::_stack_to_native_abi); | |
1943 // Address index(noreg, rax, Address::times_4); | |
1944 | |
1945 __ movptr(rax, ArrayAddress(stack_to_native, Address(noreg, rax, Address::times_4))); | |
1946 __ call(rax); // call result converter | |
1947 | |
1948 Label unwind_initial_activation; | |
1949 __ bind(unwind_initial_activation); | |
1950 | |
1951 // RETURN TO CALL_STUB/C1/C2 code (result if any in rax/rdx ST(0)) | |
1952 | |
1953 /* Current stack picture | |
1954 | |
1955 [ incoming parameters ] | |
1956 [ extra locals ] | |
1957 [ return address to CALL_STUB/C1/C2] | |
1958 fp -> [ CALL_STUB/C1/C2 fp ] | |
1959 BytecodeInterpreter object | |
1960 expression stack | |
1961 sp -> | |
1962 | |
1963 */ | |
1964 | |
1965 // return restoring the stack to the original sender_sp value | |
1966 | |
1967 __ movl(rcx, STATE(_sender_sp)); | |
1968 __ leave(); | |
1969 __ popl(rdi); // get return address | |
1970 // set stack to sender's sp | |
1971 __ movl(rsp, rcx); | |
1972 __ jmp(rdi); // return to call_stub | |
1973 | |
1974 // OSR request, adjust return address to make current frame into adapter frame | |
1975 // and enter OSR nmethod | |
1976 | |
1977 __ bind(do_OSR); | |
1978 | |
1979 Label remove_initial_frame; | |
1980 | |
1981 // We are going to pop this frame. Is there another interpreter frame underneath | |
1982 // it or is it callstub/compiled? | |
1983 | |
1984 // Move buffer to the expected parameter location | |
1985 __ movl(rcx, STATE(_result._osr._osr_buf)); | |
1986 | |
1987 __ movl(rax, STATE(_result._osr._osr_entry)); | |
1988 | |
1989 __ cmpl(STATE(_prev_link), (int)NULL); // returning from "recursive" interpreter call? | |
1990 __ jcc(Assembler::equal, remove_initial_frame); // back to native code (call_stub/c1/c2) | |
1991 | |
1992 // __ movl(state, STATE(_prev_link)); // unwind state | |
1993 __ movl(rsi, STATE(_sender_sp)); // get sender's sp in expected register | |
1994 __ leave(); // pop the frame | |
1995 __ movl(rsp, rsi); // trim any stack expansion | |
1996 | |
1997 | |
1998 // We know we are calling compiled so push specialized return | |
1999 // method uses specialized entry, push a return so we look like call stub setup | |
2000 // this path will handle fact that result is returned in registers and not | |
2001 // on the java stack. | |
2002 | |
2003 __ pushptr(return_from_native_method.addr()); | |
2004 | |
2005 __ jmp(rax); | |
2006 | |
2007 __ bind(remove_initial_frame); | |
2008 | |
2009 __ movl(rdx, STATE(_sender_sp)); | |
2010 __ leave(); | |
2011 // get real return | |
2012 __ popl(rsi); | |
2013 // set stack to sender's sp | |
2014 __ movl(rsp, rdx); | |
2015 // repush real return | |
2016 __ pushl(rsi); | |
2017 // Enter OSR nmethod | |
2018 __ jmp(rax); | |
2019 | |
2020 | |
2021 | |
2022 | |
2023 // Call a new method. All we do is (temporarily) trim the expression stack | |
2024 // push a return address to bring us back to here and leap to the new entry. | |
2025 | |
2026 __ bind(call_method); | |
2027 | |
2028 // stack points to next free location and not top element on expression stack | |
2029 // method expects sp to be pointing to topmost element | |
2030 | |
2031 __ movl(rsp, STATE(_stack)); // pop args to c++ interpreter, set sp to java stack top | |
2032 __ leal(rsp, Address(rsp, wordSize)); | |
2033 | |
2034 __ movl(rbx, STATE(_result._to_call._callee)); // get method to execute | |
2035 | |
2036 // don't need a return address if reinvoking interpreter | |
2037 | |
2038 // Make it look like call_stub calling conventions | |
2039 | |
2040 // Get (potential) receiver | |
2041 __ load_unsigned_word(rcx, size_of_parameters); // get size of parameters in words | |
2042 | |
2043 ExternalAddress recursive(CAST_FROM_FN_PTR(address, RecursiveInterpreterActivation)); | |
2044 __ pushptr(recursive.addr()); // make it look good in the debugger | |
2045 | |
2046 InternalAddress entry(entry_point); | |
2047 __ cmpptr(STATE(_result._to_call._callee_entry_point), entry.addr()); // returning to interpreter? | |
2048 __ jcc(Assembler::equal, re_dispatch); // yes | |
2049 | |
2050 __ popl(rax); // pop dummy address | |
2051 | |
2052 | |
2053 // get specialized entry | |
2054 __ movl(rax, STATE(_result._to_call._callee_entry_point)); | |
2055 // set sender SP | |
2056 __ movl(rsi, rsp); | |
2057 | |
2058 // method uses specialized entry, push a return so we look like call stub setup | |
2059 // this path will handle fact that result is returned in registers and not | |
2060 // on the java stack. | |
2061 | |
2062 __ pushptr(return_from_native_method.addr()); | |
2063 | |
2064 __ jmp(rax); | |
2065 | |
2066 __ bind(bad_msg); | |
2067 __ stop("Bad message from interpreter"); | |
2068 | |
2069 // Interpreted method "returned" with an exception pass it on... | |
2070 // Pass result, unwind activation and continue/return to interpreter/call_stub | |
2071 // We handle result (if any) differently based on return to interpreter or call_stub | |
2072 | |
2073 Label unwind_initial_with_pending_exception; | |
2074 | |
2075 __ bind(throw_exception); | |
2076 __ cmpl(STATE(_prev_link), (int)NULL); // returning from recursive interpreter call? | |
2077 __ jcc(Assembler::equal, unwind_initial_with_pending_exception); // no, back to native code (call_stub/c1/c2) | |
2078 __ movl(rax, STATE(_locals)); // pop parameters get new stack value | |
2079 __ addl(rax, wordSize); // account for prepush before we return | |
2080 __ jmp(unwind_recursive_activation); | |
2081 | |
2082 __ bind(unwind_initial_with_pending_exception); | |
2083 | |
2084 // We will unwind the current (initial) interpreter frame and forward | |
2085 // the exception to the caller. We must put the exception in the | |
2086 // expected register and clear pending exception and then forward. | |
2087 | |
2088 __ jmp(unwind_and_forward); | |
2089 | |
2090 interpreter_frame_manager = entry_point; | |
2091 return entry_point; | |
2092 } | |
2093 | |
2094 address AbstractInterpreterGenerator::generate_method_entry(AbstractInterpreter::MethodKind kind) { | |
2095 // determine code generation flags | |
2096 bool synchronized = false; | |
2097 address entry_point = NULL; | |
2098 | |
2099 switch (kind) { | |
2100 case Interpreter::zerolocals : break; | |
2101 case Interpreter::zerolocals_synchronized: synchronized = true; break; | |
2102 case Interpreter::native : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(false); break; | |
2103 case Interpreter::native_synchronized : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(true); break; | |
2104 case Interpreter::empty : entry_point = ((InterpreterGenerator*)this)->generate_empty_entry(); break; | |
2105 case Interpreter::accessor : entry_point = ((InterpreterGenerator*)this)->generate_accessor_entry(); break; | |
2106 case Interpreter::abstract : entry_point = ((InterpreterGenerator*)this)->generate_abstract_entry(); break; | |
2107 | |
2108 case Interpreter::java_lang_math_sin : // fall thru | |
2109 case Interpreter::java_lang_math_cos : // fall thru | |
2110 case Interpreter::java_lang_math_tan : // fall thru | |
2111 case Interpreter::java_lang_math_abs : // fall thru | |
2112 case Interpreter::java_lang_math_log : // fall thru | |
2113 case Interpreter::java_lang_math_log10 : // fall thru | |
2114 case Interpreter::java_lang_math_sqrt : entry_point = ((InterpreterGenerator*)this)->generate_math_entry(kind); break; | |
2115 default : ShouldNotReachHere(); break; | |
2116 } | |
2117 | |
2118 if (entry_point) return entry_point; | |
2119 | |
2120 return ((InterpreterGenerator*)this)->generate_normal_entry(synchronized); | |
2121 | |
2122 } | |
2123 | |
2124 InterpreterGenerator::InterpreterGenerator(StubQueue* code) | |
2125 : CppInterpreterGenerator(code) { | |
2126 generate_all(); // down here so it can be "virtual" | |
2127 } | |
2128 | |
2129 // Deoptimization helpers for C++ interpreter | |
2130 | |
2131 // How much stack a method activation needs in words. | |
2132 int AbstractInterpreter::size_top_interpreter_activation(methodOop method) { | |
2133 | |
2134 const int stub_code = 4; // see generate_call_stub | |
2135 // Save space for one monitor to get into the interpreted method in case | |
2136 // the method is synchronized | |
2137 int monitor_size = method->is_synchronized() ? | |
2138 1*frame::interpreter_frame_monitor_size() : 0; | |
2139 | |
2140 // total static overhead size. Account for interpreter state object, return | |
2141 // address, saved rbp and 2 words for a "static long no_params() method" issue. | |
2142 | |
2143 const int overhead_size = sizeof(BytecodeInterpreter)/wordSize + | |
2144 ( frame::sender_sp_offset - frame::link_offset) + 2; | |
2145 | |
2146 const int method_stack = (method->max_locals() + method->max_stack()) * | |
2147 Interpreter::stackElementWords(); | |
2148 return overhead_size + method_stack + stub_code; | |
2149 } | |
2150 | |
2151 // returns the activation size. | |
2152 static int size_activation_helper(int extra_locals_size, int monitor_size) { | |
2153 return (extra_locals_size + // the addition space for locals | |
2154 2*BytesPerWord + // return address and saved rbp | |
2155 2*BytesPerWord + // "static long no_params() method" issue | |
2156 sizeof(BytecodeInterpreter) + // interpreterState | |
2157 monitor_size); // monitors | |
2158 } | |
2159 | |
2160 void BytecodeInterpreter::layout_interpreterState(interpreterState to_fill, | |
2161 frame* caller, | |
2162 frame* current, | |
2163 methodOop method, | |
2164 intptr_t* locals, | |
2165 intptr_t* stack, | |
2166 intptr_t* stack_base, | |
2167 intptr_t* monitor_base, | |
2168 intptr_t* frame_bottom, | |
2169 bool is_top_frame | |
2170 ) | |
2171 { | |
2172 // What about any vtable? | |
2173 // | |
2174 to_fill->_thread = JavaThread::current(); | |
2175 // This gets filled in later but make it something recognizable for now | |
2176 to_fill->_bcp = method->code_base(); | |
2177 to_fill->_locals = locals; | |
2178 to_fill->_constants = method->constants()->cache(); | |
2179 to_fill->_method = method; | |
2180 to_fill->_mdx = NULL; | |
2181 to_fill->_stack = stack; | |
2182 if (is_top_frame && JavaThread::current()->popframe_forcing_deopt_reexecution() ) { | |
2183 to_fill->_msg = deopt_resume2; | |
2184 } else { | |
2185 to_fill->_msg = method_resume; | |
2186 } | |
2187 to_fill->_result._to_call._bcp_advance = 0; | |
2188 to_fill->_result._to_call._callee_entry_point = NULL; // doesn't matter to anyone | |
2189 to_fill->_result._to_call._callee = NULL; // doesn't matter to anyone | |
2190 to_fill->_prev_link = NULL; | |
2191 | |
2192 to_fill->_sender_sp = caller->unextended_sp(); | |
2193 | |
2194 if (caller->is_interpreted_frame()) { | |
2195 interpreterState prev = caller->get_interpreterState(); | |
2196 to_fill->_prev_link = prev; | |
2197 // *current->register_addr(GR_Iprev_state) = (intptr_t) prev; | |
2198 // Make the prev callee look proper | |
2199 prev->_result._to_call._callee = method; | |
2200 if (*prev->_bcp == Bytecodes::_invokeinterface) { | |
2201 prev->_result._to_call._bcp_advance = 5; | |
2202 } else { | |
2203 prev->_result._to_call._bcp_advance = 3; | |
2204 } | |
2205 } | |
2206 to_fill->_oop_temp = NULL; | |
2207 to_fill->_stack_base = stack_base; | |
2208 // Need +1 here because stack_base points to the word just above the first expr stack entry | |
2209 // and stack_limit is supposed to point to the word just below the last expr stack entry. | |
2210 // See generate_compute_interpreter_state. | |
2211 to_fill->_stack_limit = stack_base - (method->max_stack() + 1); | |
2212 to_fill->_monitor_base = (BasicObjectLock*) monitor_base; | |
2213 | |
2214 to_fill->_self_link = to_fill; | |
2215 assert(stack >= to_fill->_stack_limit && stack < to_fill->_stack_base, | |
2216 "Stack top out of range"); | |
2217 } | |
2218 | |
2219 int AbstractInterpreter::layout_activation(methodOop method, | |
2220 int tempcount, // | |
2221 int popframe_extra_args, | |
2222 int moncount, | |
2223 int callee_param_count, | |
2224 int callee_locals, | |
2225 frame* caller, | |
2226 frame* interpreter_frame, | |
2227 bool is_top_frame) { | |
2228 | |
2229 assert(popframe_extra_args == 0, "FIX ME"); | |
2230 // NOTE this code must exactly mimic what InterpreterGenerator::generate_compute_interpreter_state() | |
2231 // does as far as allocating an interpreter frame. | |
2232 // If interpreter_frame!=NULL, set up the method, locals, and monitors. | |
2233 // The frame interpreter_frame, if not NULL, is guaranteed to be the right size, | |
2234 // as determined by a previous call to this method. | |
2235 // It is also guaranteed to be walkable even though it is in a skeletal state | |
2236 // NOTE: return size is in words not bytes | |
2237 // NOTE: tempcount is the current size of the java expression stack. For top most | |
2238 // frames we will allocate a full sized expression stack and not the curback | |
2239 // version that non-top frames have. | |
2240 | |
2241 // Calculate the amount our frame will be adjust by the callee. For top frame | |
2242 // this is zero. | |
2243 | |
2244 // NOTE: ia64 seems to do this wrong (or at least backwards) in that it | |
2245 // calculates the extra locals based on itself. Not what the callee does | |
2246 // to it. So it ignores last_frame_adjust value. Seems suspicious as far | |
2247 // as getting sender_sp correct. | |
2248 | |
2249 int extra_locals_size = (callee_locals - callee_param_count) * BytesPerWord; | |
2250 int monitor_size = sizeof(BasicObjectLock) * moncount; | |
2251 | |
2252 // First calculate the frame size without any java expression stack | |
2253 int short_frame_size = size_activation_helper(extra_locals_size, | |
2254 monitor_size); | |
2255 | |
2256 // Now with full size expression stack | |
2257 int full_frame_size = short_frame_size + method->max_stack() * BytesPerWord; | |
2258 | |
2259 // and now with only live portion of the expression stack | |
2260 short_frame_size = short_frame_size + tempcount * BytesPerWord; | |
2261 | |
2262 // the size the activation is right now. Only top frame is full size | |
2263 int frame_size = (is_top_frame ? full_frame_size : short_frame_size); | |
2264 | |
2265 if (interpreter_frame != NULL) { | |
2266 #ifdef ASSERT | |
2267 assert(caller->unextended_sp() == interpreter_frame->interpreter_frame_sender_sp(), "Frame not properly walkable"); | |
2268 #endif | |
2269 | |
2270 // MUCHO HACK | |
2271 | |
2272 intptr_t* frame_bottom = (intptr_t*) ((intptr_t)interpreter_frame->sp() - (full_frame_size - frame_size)); | |
2273 | |
2274 /* Now fillin the interpreterState object */ | |
2275 | |
2276 // The state object is the first thing on the frame and easily located | |
2277 | |
2278 interpreterState cur_state = (interpreterState) ((intptr_t)interpreter_frame->fp() - sizeof(BytecodeInterpreter)); | |
2279 | |
2280 | |
2281 // Find the locals pointer. This is rather simple on x86 because there is no | |
2282 // confusing rounding at the callee to account for. We can trivially locate | |
2283 // our locals based on the current fp(). | |
2284 // Note: the + 2 is for handling the "static long no_params() method" issue. | |
2285 // (too bad I don't really remember that issue well...) | |
2286 | |
2287 intptr_t* locals; | |
2288 // If the caller is interpreted we need to make sure that locals points to the first | |
2289 // argument that the caller passed and not in an area where the stack might have been extended. | |
2290 // because the stack to stack to converter needs a proper locals value in order to remove the | |
2291 // arguments from the caller and place the result in the proper location. Hmm maybe it'd be | |
2292 // simpler if we simply stored the result in the BytecodeInterpreter object and let the c++ code | |
2293 // adjust the stack?? HMMM QQQ | |
2294 // | |
2295 if (caller->is_interpreted_frame()) { | |
2296 // locals must agree with the caller because it will be used to set the | |
2297 // caller's tos when we return. | |
2298 interpreterState prev = caller->get_interpreterState(); | |
2299 // stack() is prepushed. | |
2300 locals = prev->stack() + method->size_of_parameters(); | |
2301 // locals = caller->unextended_sp() + (method->size_of_parameters() - 1); | |
2302 if (locals != interpreter_frame->fp() + frame::sender_sp_offset + (method->max_locals() - 1) + 2) { | |
2303 // os::breakpoint(); | |
2304 } | |
2305 } else { | |
2306 // this is where a c2i would have placed locals (except for the +2) | |
2307 locals = interpreter_frame->fp() + frame::sender_sp_offset + (method->max_locals() - 1) + 2; | |
2308 } | |
2309 | |
2310 intptr_t* monitor_base = (intptr_t*) cur_state; | |
2311 intptr_t* stack_base = (intptr_t*) ((intptr_t) monitor_base - monitor_size); | |
2312 /* +1 because stack is always prepushed */ | |
2313 intptr_t* stack = (intptr_t*) ((intptr_t) stack_base - (tempcount + 1) * BytesPerWord); | |
2314 | |
2315 | |
2316 BytecodeInterpreter::layout_interpreterState(cur_state, | |
2317 caller, | |
2318 interpreter_frame, | |
2319 method, | |
2320 locals, | |
2321 stack, | |
2322 stack_base, | |
2323 monitor_base, | |
2324 frame_bottom, | |
2325 is_top_frame); | |
2326 | |
2327 // BytecodeInterpreter::pd_layout_interpreterState(cur_state, interpreter_return_address, interpreter_frame->fp()); | |
2328 } | |
2329 return frame_size/BytesPerWord; | |
2330 } | |
2331 | |
2332 #endif // CC_INTERP (all) |