Mercurial > hg > truffle
annotate src/cpu/sparc/vm/cppInterpreter_sparc.cpp @ 5222:155f8ca28f11
Fix for peeling : fix a bug in the Virtual chain reconstruction
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Tue, 10 Apr 2012 15:48:54 +0200 |
parents | 069ab3f976d3 |
children | 8a48c2906f91 |
rev | line source |
---|---|
0 | 1 /* |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
1972
diff
changeset
|
2 * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
710
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
710
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
710
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "asm/assembler.hpp" | |
27 #include "interpreter/bytecodeHistogram.hpp" | |
28 #include "interpreter/cppInterpreter.hpp" | |
29 #include "interpreter/interpreter.hpp" | |
30 #include "interpreter/interpreterGenerator.hpp" | |
31 #include "interpreter/interpreterRuntime.hpp" | |
32 #include "oops/arrayOop.hpp" | |
33 #include "oops/methodDataOop.hpp" | |
34 #include "oops/methodOop.hpp" | |
35 #include "oops/oop.inline.hpp" | |
36 #include "prims/jvmtiExport.hpp" | |
37 #include "prims/jvmtiThreadState.hpp" | |
38 #include "runtime/arguments.hpp" | |
39 #include "runtime/deoptimization.hpp" | |
40 #include "runtime/frame.inline.hpp" | |
41 #include "runtime/interfaceSupport.hpp" | |
42 #include "runtime/sharedRuntime.hpp" | |
43 #include "runtime/stubRoutines.hpp" | |
44 #include "runtime/synchronizer.hpp" | |
45 #include "runtime/timer.hpp" | |
46 #include "runtime/vframeArray.hpp" | |
47 #include "utilities/debug.hpp" | |
48 #ifdef SHARK | |
49 #include "shark/shark_globals.hpp" | |
50 #endif | |
0 | 51 |
52 #ifdef CC_INTERP | |
53 | |
54 // Routine exists to make tracebacks look decent in debugger | |
55 // while "shadow" interpreter frames are on stack. It is also | |
56 // used to distinguish interpreter frames. | |
57 | |
58 extern "C" void RecursiveInterpreterActivation(interpreterState istate) { | |
59 ShouldNotReachHere(); | |
60 } | |
61 | |
62 bool CppInterpreter::contains(address pc) { | |
63 return ( _code->contains(pc) || | |
64 ( pc == (CAST_FROM_FN_PTR(address, RecursiveInterpreterActivation) + frame::pc_return_offset))); | |
65 } | |
66 | |
67 #define STATE(field_name) Lstate, in_bytes(byte_offset_of(BytecodeInterpreter, field_name)) | |
68 #define __ _masm-> | |
69 | |
70 Label frame_manager_entry; | |
71 Label fast_accessor_slow_entry_path; // fast accessor methods need to be able to jmp to unsynchronized | |
72 // c++ interpreter entry point this holds that entry point label. | |
73 | |
74 static address unctrap_frame_manager_entry = NULL; | |
75 | |
76 static address interpreter_return_address = NULL; | |
77 static address deopt_frame_manager_return_atos = NULL; | |
78 static address deopt_frame_manager_return_btos = NULL; | |
79 static address deopt_frame_manager_return_itos = NULL; | |
80 static address deopt_frame_manager_return_ltos = NULL; | |
81 static address deopt_frame_manager_return_ftos = NULL; | |
82 static address deopt_frame_manager_return_dtos = NULL; | |
83 static address deopt_frame_manager_return_vtos = NULL; | |
84 | |
85 const Register prevState = G1_scratch; | |
86 | |
87 void InterpreterGenerator::save_native_result(void) { | |
88 // result potentially in O0/O1: save it across calls | |
89 __ stf(FloatRegisterImpl::D, F0, STATE(_native_fresult)); | |
90 #ifdef _LP64 | |
91 __ stx(O0, STATE(_native_lresult)); | |
92 #else | |
93 __ std(O0, STATE(_native_lresult)); | |
94 #endif | |
95 } | |
96 | |
97 void InterpreterGenerator::restore_native_result(void) { | |
98 | |
99 // Restore any method result value | |
100 __ ldf(FloatRegisterImpl::D, STATE(_native_fresult), F0); | |
101 #ifdef _LP64 | |
102 __ ldx(STATE(_native_lresult), O0); | |
103 #else | |
104 __ ldd(STATE(_native_lresult), O0); | |
105 #endif | |
106 } | |
107 | |
108 // A result handler converts/unboxes a native call result into | |
109 // a java interpreter/compiler result. The current frame is an | |
110 // interpreter frame. The activation frame unwind code must be | |
111 // consistent with that of TemplateTable::_return(...). In the | |
112 // case of native methods, the caller's SP was not modified. | |
113 address CppInterpreterGenerator::generate_result_handler_for(BasicType type) { | |
114 address entry = __ pc(); | |
115 Register Itos_i = Otos_i ->after_save(); | |
116 Register Itos_l = Otos_l ->after_save(); | |
117 Register Itos_l1 = Otos_l1->after_save(); | |
118 Register Itos_l2 = Otos_l2->after_save(); | |
119 switch (type) { | |
120 case T_BOOLEAN: __ subcc(G0, O0, G0); __ addc(G0, 0, Itos_i); break; // !0 => true; 0 => false | |
121 case T_CHAR : __ sll(O0, 16, O0); __ srl(O0, 16, Itos_i); break; // cannot use and3, 0xFFFF too big as immediate value! | |
122 case T_BYTE : __ sll(O0, 24, O0); __ sra(O0, 24, Itos_i); break; | |
123 case T_SHORT : __ sll(O0, 16, O0); __ sra(O0, 16, Itos_i); break; | |
124 case T_LONG : | |
125 #ifndef _LP64 | |
126 __ mov(O1, Itos_l2); // move other half of long | |
127 #endif // ifdef or no ifdef, fall through to the T_INT case | |
128 case T_INT : __ mov(O0, Itos_i); break; | |
129 case T_VOID : /* nothing to do */ break; | |
130 case T_FLOAT : assert(F0 == Ftos_f, "fix this code" ); break; | |
131 case T_DOUBLE : assert(F0 == Ftos_d, "fix this code" ); break; | |
132 case T_OBJECT : | |
133 __ ld_ptr(STATE(_oop_temp), Itos_i); | |
134 __ verify_oop(Itos_i); | |
135 break; | |
136 default : ShouldNotReachHere(); | |
137 } | |
138 __ ret(); // return from interpreter activation | |
139 __ delayed()->restore(I5_savedSP, G0, SP); // remove interpreter frame | |
140 NOT_PRODUCT(__ emit_long(0);) // marker for disassembly | |
141 return entry; | |
142 } | |
143 | |
144 // tosca based result to c++ interpreter stack based result. | |
145 // Result goes to address in L1_scratch | |
146 | |
147 address CppInterpreterGenerator::generate_tosca_to_stack_converter(BasicType type) { | |
148 // A result is in the native abi result register from a native method call. | |
149 // We need to return this result to the interpreter by pushing the result on the interpreter's | |
150 // stack. This is relatively simple the destination is in L1_scratch | |
151 // i.e. L1_scratch is the first free element on the stack. If we "push" a return value we must | |
152 // adjust L1_scratch | |
153 address entry = __ pc(); | |
154 switch (type) { | |
155 case T_BOOLEAN: | |
156 // !0 => true; 0 => false | |
157 __ subcc(G0, O0, G0); | |
158 __ addc(G0, 0, O0); | |
159 __ st(O0, L1_scratch, 0); | |
160 __ sub(L1_scratch, wordSize, L1_scratch); | |
161 break; | |
162 | |
163 // cannot use and3, 0xFFFF too big as immediate value! | |
164 case T_CHAR : | |
165 __ sll(O0, 16, O0); | |
166 __ srl(O0, 16, O0); | |
167 __ st(O0, L1_scratch, 0); | |
168 __ sub(L1_scratch, wordSize, L1_scratch); | |
169 break; | |
170 | |
171 case T_BYTE : | |
172 __ sll(O0, 24, O0); | |
173 __ sra(O0, 24, O0); | |
174 __ st(O0, L1_scratch, 0); | |
175 __ sub(L1_scratch, wordSize, L1_scratch); | |
176 break; | |
177 | |
178 case T_SHORT : | |
179 __ sll(O0, 16, O0); | |
180 __ sra(O0, 16, O0); | |
181 __ st(O0, L1_scratch, 0); | |
182 __ sub(L1_scratch, wordSize, L1_scratch); | |
183 break; | |
184 case T_LONG : | |
185 #ifndef _LP64 | |
123 | 186 #if defined(COMPILER2) |
0 | 187 // All return values are where we want them, except for Longs. C2 returns |
188 // longs in G1 in the 32-bit build whereas the interpreter wants them in O0/O1. | |
189 // Since the interpreter will return longs in G1 and O0/O1 in the 32bit | |
190 // build even if we are returning from interpreted we just do a little | |
191 // stupid shuffing. | |
192 // Note: I tried to make c2 return longs in O0/O1 and G1 so we wouldn't have to | |
193 // do this here. Unfortunately if we did a rethrow we'd see an machepilog node | |
194 // first which would move g1 -> O0/O1 and destroy the exception we were throwing. | |
195 __ stx(G1, L1_scratch, -wordSize); | |
196 #else | |
197 // native result is in O0, O1 | |
198 __ st(O1, L1_scratch, 0); // Low order | |
199 __ st(O0, L1_scratch, -wordSize); // High order | |
123 | 200 #endif /* COMPILER2 */ |
0 | 201 #else |
123 | 202 __ stx(O0, L1_scratch, -wordSize); |
0 | 203 #endif |
204 __ sub(L1_scratch, 2*wordSize, L1_scratch); | |
205 break; | |
206 | |
207 case T_INT : | |
208 __ st(O0, L1_scratch, 0); | |
209 __ sub(L1_scratch, wordSize, L1_scratch); | |
210 break; | |
211 | |
212 case T_VOID : /* nothing to do */ | |
213 break; | |
214 | |
215 case T_FLOAT : | |
216 __ stf(FloatRegisterImpl::S, F0, L1_scratch, 0); | |
217 __ sub(L1_scratch, wordSize, L1_scratch); | |
218 break; | |
219 | |
220 case T_DOUBLE : | |
221 // Every stack slot is aligned on 64 bit, However is this | |
222 // the correct stack slot on 64bit?? QQQ | |
223 __ stf(FloatRegisterImpl::D, F0, L1_scratch, -wordSize); | |
224 __ sub(L1_scratch, 2*wordSize, L1_scratch); | |
225 break; | |
226 case T_OBJECT : | |
227 __ verify_oop(O0); | |
228 __ st_ptr(O0, L1_scratch, 0); | |
229 __ sub(L1_scratch, wordSize, L1_scratch); | |
230 break; | |
231 default : ShouldNotReachHere(); | |
232 } | |
233 __ retl(); // return from interpreter activation | |
234 __ delayed()->nop(); // schedule this better | |
235 NOT_PRODUCT(__ emit_long(0);) // marker for disassembly | |
236 return entry; | |
237 } | |
238 | |
239 address CppInterpreterGenerator::generate_stack_to_stack_converter(BasicType type) { | |
240 // A result is in the java expression stack of the interpreted method that has just | |
241 // returned. Place this result on the java expression stack of the caller. | |
242 // | |
243 // The current interpreter activation in Lstate is for the method just returning its | |
244 // result. So we know that the result of this method is on the top of the current | |
245 // execution stack (which is pre-pushed) and will be return to the top of the caller | |
246 // stack. The top of the callers stack is the bottom of the locals of the current | |
247 // activation. | |
248 // Because of the way activation are managed by the frame manager the value of esp is | |
249 // below both the stack top of the current activation and naturally the stack top | |
250 // of the calling activation. This enable this routine to leave the return address | |
251 // to the frame manager on the stack and do a vanilla return. | |
252 // | |
253 // On entry: O0 - points to source (callee stack top) | |
254 // O1 - points to destination (caller stack top [i.e. free location]) | |
255 // destroys O2, O3 | |
256 // | |
257 | |
258 address entry = __ pc(); | |
259 switch (type) { | |
260 case T_VOID: break; | |
261 break; | |
262 case T_FLOAT : | |
263 case T_BOOLEAN: | |
264 case T_CHAR : | |
265 case T_BYTE : | |
266 case T_SHORT : | |
267 case T_INT : | |
268 // 1 word result | |
269 __ ld(O0, 0, O2); | |
270 __ st(O2, O1, 0); | |
271 __ sub(O1, wordSize, O1); | |
272 break; | |
273 case T_DOUBLE : | |
274 case T_LONG : | |
275 // return top two words on current expression stack to caller's expression stack | |
276 // The caller's expression stack is adjacent to the current frame manager's intepretState | |
277 // except we allocated one extra word for this intepretState so we won't overwrite it | |
278 // when we return a two word result. | |
279 #ifdef _LP64 | |
280 __ ld_ptr(O0, 0, O2); | |
281 __ st_ptr(O2, O1, -wordSize); | |
282 #else | |
283 __ ld(O0, 0, O2); | |
284 __ ld(O0, wordSize, O3); | |
285 __ st(O3, O1, 0); | |
286 __ st(O2, O1, -wordSize); | |
287 #endif | |
288 __ sub(O1, 2*wordSize, O1); | |
289 break; | |
290 case T_OBJECT : | |
291 __ ld_ptr(O0, 0, O2); | |
292 __ verify_oop(O2); // verify it | |
293 __ st_ptr(O2, O1, 0); | |
294 __ sub(O1, wordSize, O1); | |
295 break; | |
296 default : ShouldNotReachHere(); | |
297 } | |
298 __ retl(); | |
299 __ delayed()->nop(); // QQ schedule this better | |
300 return entry; | |
301 } | |
302 | |
303 address CppInterpreterGenerator::generate_stack_to_native_abi_converter(BasicType type) { | |
304 // A result is in the java expression stack of the interpreted method that has just | |
305 // returned. Place this result in the native abi that the caller expects. | |
306 // We are in a new frame registers we set must be in caller (i.e. callstub) frame. | |
307 // | |
308 // Similar to generate_stack_to_stack_converter above. Called at a similar time from the | |
309 // frame manager execept in this situation the caller is native code (c1/c2/call_stub) | |
310 // and so rather than return result onto caller's java expression stack we return the | |
311 // result in the expected location based on the native abi. | |
312 // On entry: O0 - source (stack top) | |
313 // On exit result in expected output register | |
314 // QQQ schedule this better | |
315 | |
316 address entry = __ pc(); | |
317 switch (type) { | |
318 case T_VOID: break; | |
319 break; | |
320 case T_FLOAT : | |
321 __ ldf(FloatRegisterImpl::S, O0, 0, F0); | |
322 break; | |
323 case T_BOOLEAN: | |
324 case T_CHAR : | |
325 case T_BYTE : | |
326 case T_SHORT : | |
327 case T_INT : | |
328 // 1 word result | |
329 __ ld(O0, 0, O0->after_save()); | |
330 break; | |
331 case T_DOUBLE : | |
332 __ ldf(FloatRegisterImpl::D, O0, 0, F0); | |
333 break; | |
334 case T_LONG : | |
335 // return top two words on current expression stack to caller's expression stack | |
336 // The caller's expression stack is adjacent to the current frame manager's interpretState | |
337 // except we allocated one extra word for this intepretState so we won't overwrite it | |
338 // when we return a two word result. | |
339 #ifdef _LP64 | |
340 __ ld_ptr(O0, 0, O0->after_save()); | |
341 #else | |
342 __ ld(O0, wordSize, O1->after_save()); | |
343 __ ld(O0, 0, O0->after_save()); | |
344 #endif | |
345 #if defined(COMPILER2) && !defined(_LP64) | |
346 // C2 expects long results in G1 we can't tell if we're returning to interpreted | |
347 // or compiled so just be safe use G1 and O0/O1 | |
348 | |
349 // Shift bits into high (msb) of G1 | |
350 __ sllx(Otos_l1->after_save(), 32, G1); | |
351 // Zero extend low bits | |
352 __ srl (Otos_l2->after_save(), 0, Otos_l2->after_save()); | |
353 __ or3 (Otos_l2->after_save(), G1, G1); | |
354 #endif /* COMPILER2 */ | |
355 break; | |
356 case T_OBJECT : | |
357 __ ld_ptr(O0, 0, O0->after_save()); | |
358 __ verify_oop(O0->after_save()); // verify it | |
359 break; | |
360 default : ShouldNotReachHere(); | |
361 } | |
362 __ retl(); | |
363 __ delayed()->nop(); | |
364 return entry; | |
365 } | |
366 | |
367 address CppInterpreter::return_entry(TosState state, int length) { | |
368 // make it look good in the debugger | |
369 return CAST_FROM_FN_PTR(address, RecursiveInterpreterActivation) + frame::pc_return_offset; | |
370 } | |
371 | |
372 address CppInterpreter::deopt_entry(TosState state, int length) { | |
373 address ret = NULL; | |
374 if (length != 0) { | |
375 switch (state) { | |
376 case atos: ret = deopt_frame_manager_return_atos; break; | |
377 case btos: ret = deopt_frame_manager_return_btos; break; | |
378 case ctos: | |
379 case stos: | |
380 case itos: ret = deopt_frame_manager_return_itos; break; | |
381 case ltos: ret = deopt_frame_manager_return_ltos; break; | |
382 case ftos: ret = deopt_frame_manager_return_ftos; break; | |
383 case dtos: ret = deopt_frame_manager_return_dtos; break; | |
384 case vtos: ret = deopt_frame_manager_return_vtos; break; | |
385 } | |
386 } else { | |
387 ret = unctrap_frame_manager_entry; // re-execute the bytecode ( e.g. uncommon trap) | |
388 } | |
389 assert(ret != NULL, "Not initialized"); | |
390 return ret; | |
391 } | |
392 | |
393 // | |
394 // Helpers for commoning out cases in the various type of method entries. | |
395 // | |
396 | |
397 // increment invocation count & check for overflow | |
398 // | |
399 // Note: checking for negative value instead of overflow | |
400 // so we have a 'sticky' overflow test | |
401 // | |
402 // Lmethod: method | |
403 // ??: invocation counter | |
404 // | |
405 void InterpreterGenerator::generate_counter_incr(Label* overflow, Label* profile_method, Label* profile_method_continue) { | |
406 // Update standard invocation counters | |
407 __ increment_invocation_counter(O0, G3_scratch); | |
408 if (ProfileInterpreter) { // %%% Merge this into methodDataOop | |
409 __ ld_ptr(STATE(_method), G3_scratch); | |
410 Address interpreter_invocation_counter(G3_scratch, 0, in_bytes(methodOopDesc::interpreter_invocation_counter_offset())); | |
411 __ ld(interpreter_invocation_counter, G3_scratch); | |
412 __ inc(G3_scratch); | |
413 __ st(G3_scratch, interpreter_invocation_counter); | |
414 } | |
415 | |
416 Address invocation_limit(G3_scratch, (address)&InvocationCounter::InterpreterInvocationLimit); | |
417 __ sethi(invocation_limit); | |
418 __ ld(invocation_limit, G3_scratch); | |
419 __ cmp(O0, G3_scratch); | |
420 __ br(Assembler::greaterEqualUnsigned, false, Assembler::pn, *overflow); | |
421 __ delayed()->nop(); | |
422 | |
423 } | |
424 | |
425 address InterpreterGenerator::generate_empty_entry(void) { | |
426 | |
427 // A method that does nothing but return... | |
428 | |
429 address entry = __ pc(); | |
430 Label slow_path; | |
431 | |
432 __ verify_oop(G5_method); | |
433 | |
434 // do nothing for empty methods (do not even increment invocation counter) | |
435 if ( UseFastEmptyMethods) { | |
436 // If we need a safepoint check, generate full interpreter entry. | |
437 Address sync_state(G3_scratch, SafepointSynchronize::address_of_state()); | |
438 __ load_contents(sync_state, G3_scratch); | |
439 __ cmp(G3_scratch, SafepointSynchronize::_not_synchronized); | |
440 __ br(Assembler::notEqual, false, Assembler::pn, frame_manager_entry); | |
441 __ delayed()->nop(); | |
442 | |
443 // Code: _return | |
444 __ retl(); | |
445 __ delayed()->mov(O5_savedSP, SP); | |
446 return entry; | |
447 } | |
448 return NULL; | |
449 } | |
450 | |
451 // Call an accessor method (assuming it is resolved, otherwise drop into | |
452 // vanilla (slow path) entry | |
453 | |
454 // Generates code to elide accessor methods | |
455 // Uses G3_scratch and G1_scratch as scratch | |
456 address InterpreterGenerator::generate_accessor_entry(void) { | |
457 | |
458 // Code: _aload_0, _(i|a)getfield, _(i|a)return or any rewrites thereof; | |
459 // parameter size = 1 | |
460 // Note: We can only use this code if the getfield has been resolved | |
461 // and if we don't have a null-pointer exception => check for | |
462 // these conditions first and use slow path if necessary. | |
463 address entry = __ pc(); | |
464 Label slow_path; | |
465 | |
466 if ( UseFastAccessorMethods) { | |
467 // Check if we need to reach a safepoint and generate full interpreter | |
468 // frame if so. | |
469 Address sync_state(G3_scratch, SafepointSynchronize::address_of_state()); | |
470 __ load_contents(sync_state, G3_scratch); | |
471 __ cmp(G3_scratch, SafepointSynchronize::_not_synchronized); | |
472 __ br(Assembler::notEqual, false, Assembler::pn, slow_path); | |
473 __ delayed()->nop(); | |
474 | |
475 // Check if local 0 != NULL | |
476 __ ld_ptr(Gargs, G0, Otos_i ); // get local 0 | |
477 __ tst(Otos_i); // check if local 0 == NULL and go the slow path | |
478 __ brx(Assembler::zero, false, Assembler::pn, slow_path); | |
479 __ delayed()->nop(); | |
480 | |
481 | |
482 // read first instruction word and extract bytecode @ 1 and index @ 2 | |
483 // get first 4 bytes of the bytecodes (big endian!) | |
484 __ ld_ptr(Address(G5_method, 0, in_bytes(methodOopDesc::const_offset())), G1_scratch); | |
485 __ ld(Address(G1_scratch, 0, in_bytes(constMethodOopDesc::codes_offset())), G1_scratch); | |
486 | |
487 // move index @ 2 far left then to the right most two bytes. | |
488 __ sll(G1_scratch, 2*BitsPerByte, G1_scratch); | |
489 __ srl(G1_scratch, 2*BitsPerByte - exact_log2(in_words( | |
490 ConstantPoolCacheEntry::size()) * BytesPerWord), G1_scratch); | |
491 | |
492 // get constant pool cache | |
493 __ ld_ptr(G5_method, in_bytes(methodOopDesc::constants_offset()), G3_scratch); | |
494 __ ld_ptr(G3_scratch, constantPoolOopDesc::cache_offset_in_bytes(), G3_scratch); | |
495 | |
496 // get specific constant pool cache entry | |
497 __ add(G3_scratch, G1_scratch, G3_scratch); | |
498 | |
499 // Check the constant Pool cache entry to see if it has been resolved. | |
500 // If not, need the slow path. | |
501 ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset(); | |
502 __ ld_ptr(G3_scratch, in_bytes(cp_base_offset + ConstantPoolCacheEntry::indices_offset()), G1_scratch); | |
503 __ srl(G1_scratch, 2*BitsPerByte, G1_scratch); | |
504 __ and3(G1_scratch, 0xFF, G1_scratch); | |
505 __ cmp(G1_scratch, Bytecodes::_getfield); | |
506 __ br(Assembler::notEqual, false, Assembler::pn, slow_path); | |
507 __ delayed()->nop(); | |
508 | |
509 // Get the type and return field offset from the constant pool cache | |
510 __ ld_ptr(G3_scratch, in_bytes(cp_base_offset + ConstantPoolCacheEntry::flags_offset()), G1_scratch); | |
511 __ ld_ptr(G3_scratch, in_bytes(cp_base_offset + ConstantPoolCacheEntry::f2_offset()), G3_scratch); | |
512 | |
513 Label xreturn_path; | |
514 // Need to differentiate between igetfield, agetfield, bgetfield etc. | |
515 // because they are different sizes. | |
516 // Get the type from the constant pool cache | |
517 __ srl(G1_scratch, ConstantPoolCacheEntry::tosBits, G1_scratch); | |
518 // Make sure we don't need to mask G1_scratch for tosBits after the above shift | |
519 ConstantPoolCacheEntry::verify_tosBits(); | |
520 __ cmp(G1_scratch, atos ); | |
521 __ br(Assembler::equal, true, Assembler::pt, xreturn_path); | |
522 __ delayed()->ld_ptr(Otos_i, G3_scratch, Otos_i); | |
523 __ cmp(G1_scratch, itos); | |
524 __ br(Assembler::equal, true, Assembler::pt, xreturn_path); | |
525 __ delayed()->ld(Otos_i, G3_scratch, Otos_i); | |
526 __ cmp(G1_scratch, stos); | |
527 __ br(Assembler::equal, true, Assembler::pt, xreturn_path); | |
528 __ delayed()->ldsh(Otos_i, G3_scratch, Otos_i); | |
529 __ cmp(G1_scratch, ctos); | |
530 __ br(Assembler::equal, true, Assembler::pt, xreturn_path); | |
531 __ delayed()->lduh(Otos_i, G3_scratch, Otos_i); | |
532 #ifdef ASSERT | |
533 __ cmp(G1_scratch, btos); | |
534 __ br(Assembler::equal, true, Assembler::pt, xreturn_path); | |
535 __ delayed()->ldsb(Otos_i, G3_scratch, Otos_i); | |
536 __ should_not_reach_here(); | |
537 #endif | |
538 __ ldsb(Otos_i, G3_scratch, Otos_i); | |
539 __ bind(xreturn_path); | |
540 | |
541 // _ireturn/_areturn | |
542 __ retl(); // return from leaf routine | |
543 __ delayed()->mov(O5_savedSP, SP); | |
544 | |
545 // Generate regular method entry | |
546 __ bind(slow_path); | |
3839 | 547 __ ba(fast_accessor_slow_entry_path); |
0 | 548 __ delayed()->nop(); |
549 return entry; | |
550 } | |
551 return NULL; | |
552 } | |
553 | |
3249
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2357
diff
changeset
|
554 address InterpreterGenerator::generate_Reference_get_entry(void) { |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2357
diff
changeset
|
555 #ifndef SERIALGC |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2357
diff
changeset
|
556 if (UseG1GC) { |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2357
diff
changeset
|
557 // We need to generate have a routine that generates code to: |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2357
diff
changeset
|
558 // * load the value in the referent field |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2357
diff
changeset
|
559 // * passes that value to the pre-barrier. |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2357
diff
changeset
|
560 // |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2357
diff
changeset
|
561 // In the case of G1 this will record the value of the |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2357
diff
changeset
|
562 // referent in an SATB buffer if marking is active. |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2357
diff
changeset
|
563 // This will cause concurrent marking to mark the referent |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2357
diff
changeset
|
564 // field as live. |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2357
diff
changeset
|
565 Unimplemented(); |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2357
diff
changeset
|
566 } |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2357
diff
changeset
|
567 #endif // SERIALGC |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2357
diff
changeset
|
568 |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2357
diff
changeset
|
569 // If G1 is not enabled then attempt to go through the accessor entry point |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2357
diff
changeset
|
570 // Reference.get is an accessor |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2357
diff
changeset
|
571 return generate_accessor_entry(); |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2357
diff
changeset
|
572 } |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2357
diff
changeset
|
573 |
0 | 574 // |
575 // Interpreter stub for calling a native method. (C++ interpreter) | |
576 // This sets up a somewhat different looking stack for calling the native method | |
577 // than the typical interpreter frame setup. | |
578 // | |
579 | |
580 address InterpreterGenerator::generate_native_entry(bool synchronized) { | |
581 address entry = __ pc(); | |
582 | |
583 // the following temporary registers are used during frame creation | |
584 const Register Gtmp1 = G3_scratch ; | |
585 const Register Gtmp2 = G1_scratch; | |
586 const Address size_of_parameters(G5_method, 0, in_bytes(methodOopDesc::size_of_parameters_offset())); | |
587 | |
588 bool inc_counter = UseCompiler || CountCompiledCalls; | |
589 | |
590 // make sure registers are different! | |
591 assert_different_registers(G2_thread, G5_method, Gargs, Gtmp1, Gtmp2); | |
592 | |
593 const Address access_flags (G5_method, 0, in_bytes(methodOopDesc::access_flags_offset())); | |
594 | |
595 Label Lentry; | |
596 __ bind(Lentry); | |
597 | |
598 __ verify_oop(G5_method); | |
599 | |
600 const Register Glocals_size = G3; | |
601 assert_different_registers(Glocals_size, G4_scratch, Gframe_size); | |
602 | |
603 // make sure method is native & not abstract | |
604 // rethink these assertions - they can be simplified and shared (gri 2/25/2000) | |
605 #ifdef ASSERT | |
606 __ ld(access_flags, Gtmp1); | |
607 { | |
608 Label L; | |
609 __ btst(JVM_ACC_NATIVE, Gtmp1); | |
610 __ br(Assembler::notZero, false, Assembler::pt, L); | |
611 __ delayed()->nop(); | |
612 __ stop("tried to execute non-native method as native"); | |
613 __ bind(L); | |
614 } | |
615 { Label L; | |
616 __ btst(JVM_ACC_ABSTRACT, Gtmp1); | |
617 __ br(Assembler::zero, false, Assembler::pt, L); | |
618 __ delayed()->nop(); | |
619 __ stop("tried to execute abstract method as non-abstract"); | |
620 __ bind(L); | |
621 } | |
622 #endif // ASSERT | |
623 | |
624 __ lduh(size_of_parameters, Gtmp1); | |
625 __ sll(Gtmp1, LogBytesPerWord, Gtmp2); // parameter size in bytes | |
626 __ add(Gargs, Gtmp2, Gargs); // points to first local + BytesPerWord | |
627 // NEW | |
628 __ add(Gargs, -wordSize, Gargs); // points to first local[0] | |
629 // generate the code to allocate the interpreter stack frame | |
630 // NEW FRAME ALLOCATED HERE | |
631 // save callers original sp | |
632 // __ mov(SP, I5_savedSP->after_restore()); | |
633 | |
634 generate_compute_interpreter_state(Lstate, G0, true); | |
635 | |
636 // At this point Lstate points to new interpreter state | |
637 // | |
638 | |
639 const Address do_not_unlock_if_synchronized(G2_thread, 0, | |
640 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset())); | |
641 // Since at this point in the method invocation the exception handler | |
642 // would try to exit the monitor of synchronized methods which hasn't | |
643 // been entered yet, we set the thread local variable | |
644 // _do_not_unlock_if_synchronized to true. If any exception was thrown by | |
645 // runtime, exception handling i.e. unlock_if_synchronized_method will | |
646 // check this thread local flag. | |
647 // This flag has two effects, one is to force an unwind in the topmost | |
648 // interpreter frame and not perform an unlock while doing so. | |
649 | |
650 __ movbool(true, G3_scratch); | |
651 __ stbool(G3_scratch, do_not_unlock_if_synchronized); | |
652 | |
653 | |
654 // increment invocation counter and check for overflow | |
655 // | |
656 // Note: checking for negative value instead of overflow | |
657 // so we have a 'sticky' overflow test (may be of | |
658 // importance as soon as we have true MT/MP) | |
659 Label invocation_counter_overflow; | |
660 if (inc_counter) { | |
661 generate_counter_incr(&invocation_counter_overflow, NULL, NULL); | |
662 } | |
663 Label Lcontinue; | |
664 __ bind(Lcontinue); | |
665 | |
666 bang_stack_shadow_pages(true); | |
667 // reset the _do_not_unlock_if_synchronized flag | |
668 __ stbool(G0, do_not_unlock_if_synchronized); | |
669 | |
670 // check for synchronized methods | |
671 // Must happen AFTER invocation_counter check, so method is not locked | |
672 // if counter overflows. | |
673 | |
674 if (synchronized) { | |
675 lock_method(); | |
676 // Don't see how G2_thread is preserved here... | |
677 // __ verify_thread(); QQQ destroys L0,L1 can't use | |
678 } else { | |
679 #ifdef ASSERT | |
680 { Label ok; | |
681 __ ld_ptr(STATE(_method), G5_method); | |
682 __ ld(access_flags, O0); | |
683 __ btst(JVM_ACC_SYNCHRONIZED, O0); | |
684 __ br( Assembler::zero, false, Assembler::pt, ok); | |
685 __ delayed()->nop(); | |
686 __ stop("method needs synchronization"); | |
687 __ bind(ok); | |
688 } | |
689 #endif // ASSERT | |
690 } | |
691 | |
692 // start execution | |
693 | |
694 // __ verify_thread(); kills L1,L2 can't use at the moment | |
695 | |
696 // jvmti/jvmpi support | |
697 __ notify_method_entry(); | |
698 | |
699 // native call | |
700 | |
701 // (note that O0 is never an oop--at most it is a handle) | |
702 // It is important not to smash any handles created by this call, | |
703 // until any oop handle in O0 is dereferenced. | |
704 | |
705 // (note that the space for outgoing params is preallocated) | |
706 | |
707 // get signature handler | |
708 | |
709 Label pending_exception_present; | |
710 | |
711 { Label L; | |
712 __ ld_ptr(STATE(_method), G5_method); | |
713 __ ld_ptr(Address(G5_method, 0, in_bytes(methodOopDesc::signature_handler_offset())), G3_scratch); | |
714 __ tst(G3_scratch); | |
715 __ brx(Assembler::notZero, false, Assembler::pt, L); | |
716 __ delayed()->nop(); | |
717 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), G5_method, false); | |
718 __ ld_ptr(STATE(_method), G5_method); | |
719 | |
720 Address exception_addr(G2_thread, 0, in_bytes(Thread::pending_exception_offset())); | |
721 __ ld_ptr(exception_addr, G3_scratch); | |
3839 | 722 __ br_notnull_short(G3_scratch, Assembler::pn, pending_exception_present); |
0 | 723 __ ld_ptr(Address(G5_method, 0, in_bytes(methodOopDesc::signature_handler_offset())), G3_scratch); |
724 __ bind(L); | |
725 } | |
726 | |
727 // Push a new frame so that the args will really be stored in | |
728 // Copy a few locals across so the new frame has the variables | |
729 // we need but these values will be dead at the jni call and | |
730 // therefore not gc volatile like the values in the current | |
731 // frame (Lstate in particular) | |
732 | |
733 // Flush the state pointer to the register save area | |
734 // Which is the only register we need for a stack walk. | |
735 __ st_ptr(Lstate, SP, (Lstate->sp_offset_in_saved_window() * wordSize) + STACK_BIAS); | |
736 | |
737 __ mov(Lstate, O1); // Need to pass the state pointer across the frame | |
738 | |
739 // Calculate current frame size | |
740 __ sub(SP, FP, O3); // Calculate negative of current frame size | |
741 __ save(SP, O3, SP); // Allocate an identical sized frame | |
742 | |
743 __ mov(I1, Lstate); // In the "natural" register. | |
744 | |
745 // Note I7 has leftover trash. Slow signature handler will fill it in | |
746 // should we get there. Normal jni call will set reasonable last_Java_pc | |
747 // below (and fix I7 so the stack trace doesn't have a meaningless frame | |
748 // in it). | |
749 | |
750 | |
751 // call signature handler | |
752 __ ld_ptr(STATE(_method), Lmethod); | |
753 __ ld_ptr(STATE(_locals), Llocals); | |
754 | |
755 __ callr(G3_scratch, 0); | |
756 __ delayed()->nop(); | |
757 __ ld_ptr(STATE(_thread), G2_thread); // restore thread (shouldn't be needed) | |
758 | |
759 { Label not_static; | |
760 | |
761 __ ld_ptr(STATE(_method), G5_method); | |
762 __ ld(access_flags, O0); | |
763 __ btst(JVM_ACC_STATIC, O0); | |
764 __ br( Assembler::zero, false, Assembler::pt, not_static); | |
765 __ delayed()-> | |
766 // get native function entry point(O0 is a good temp until the very end) | |
767 ld_ptr(Address(G5_method, 0, in_bytes(methodOopDesc::native_function_offset())), O0); | |
768 // for static methods insert the mirror argument | |
4762
069ab3f976d3
7118863: Move sizeof(klassOopDesc) into the *Klass::*_offset_in_bytes() functions
stefank
parents:
3839
diff
changeset
|
769 const int mirror_offset = in_bytes(Klass::java_mirror_offset()); |
0 | 770 |
771 __ ld_ptr(Address(G5_method, 0, in_bytes(methodOopDesc:: constants_offset())), O1); | |
772 __ ld_ptr(Address(O1, 0, constantPoolOopDesc::pool_holder_offset_in_bytes()), O1); | |
773 __ ld_ptr(O1, mirror_offset, O1); | |
774 // where the mirror handle body is allocated: | |
775 #ifdef ASSERT | |
776 if (!PrintSignatureHandlers) // do not dirty the output with this | |
777 { Label L; | |
778 __ tst(O1); | |
779 __ brx(Assembler::notZero, false, Assembler::pt, L); | |
780 __ delayed()->nop(); | |
781 __ stop("mirror is missing"); | |
782 __ bind(L); | |
783 } | |
784 #endif // ASSERT | |
785 __ st_ptr(O1, STATE(_oop_temp)); | |
786 __ add(STATE(_oop_temp), O1); // this is really an LEA not an add | |
787 __ bind(not_static); | |
788 } | |
789 | |
790 // At this point, arguments have been copied off of stack into | |
791 // their JNI positions, which are O1..O5 and SP[68..]. | |
792 // Oops are boxed in-place on the stack, with handles copied to arguments. | |
793 // The result handler is in Lscratch. O0 will shortly hold the JNIEnv*. | |
794 | |
795 #ifdef ASSERT | |
796 { Label L; | |
797 __ tst(O0); | |
798 __ brx(Assembler::notZero, false, Assembler::pt, L); | |
799 __ delayed()->nop(); | |
800 __ stop("native entry point is missing"); | |
801 __ bind(L); | |
802 } | |
803 #endif // ASSERT | |
804 | |
805 // | |
806 // setup the java frame anchor | |
807 // | |
808 // The scavenge function only needs to know that the PC of this frame is | |
809 // in the interpreter method entry code, it doesn't need to know the exact | |
810 // PC and hence we can use O7 which points to the return address from the | |
811 // previous call in the code stream (signature handler function) | |
812 // | |
813 // The other trick is we set last_Java_sp to FP instead of the usual SP because | |
814 // we have pushed the extra frame in order to protect the volatile register(s) | |
815 // in that frame when we return from the jni call | |
816 // | |
817 | |
818 | |
819 __ set_last_Java_frame(FP, O7); | |
820 __ mov(O7, I7); // make dummy interpreter frame look like one above, | |
821 // not meaningless information that'll confuse me. | |
822 | |
823 // flush the windows now. We don't care about the current (protection) frame | |
824 // only the outer frames | |
825 | |
826 __ flush_windows(); | |
827 | |
828 // mark windows as flushed | |
829 Address flags(G2_thread, | |
830 0, | |
831 in_bytes(JavaThread::frame_anchor_offset()) + in_bytes(JavaFrameAnchor::flags_offset())); | |
832 __ set(JavaFrameAnchor::flushed, G3_scratch); | |
833 __ st(G3_scratch, flags); | |
834 | |
835 // Transition from _thread_in_Java to _thread_in_native. We are already safepoint ready. | |
836 | |
837 Address thread_state(G2_thread, 0, in_bytes(JavaThread::thread_state_offset())); | |
838 #ifdef ASSERT | |
839 { Label L; | |
840 __ ld(thread_state, G3_scratch); | |
841 __ cmp(G3_scratch, _thread_in_Java); | |
842 __ br(Assembler::equal, false, Assembler::pt, L); | |
843 __ delayed()->nop(); | |
844 __ stop("Wrong thread state in native stub"); | |
845 __ bind(L); | |
846 } | |
847 #endif // ASSERT | |
848 __ set(_thread_in_native, G3_scratch); | |
849 __ st(G3_scratch, thread_state); | |
850 | |
851 // Call the jni method, using the delay slot to set the JNIEnv* argument. | |
852 __ callr(O0, 0); | |
853 __ delayed()-> | |
854 add(G2_thread, in_bytes(JavaThread::jni_environment_offset()), O0); | |
855 __ ld_ptr(STATE(_thread), G2_thread); // restore thread | |
856 | |
857 // must we block? | |
858 | |
859 // Block, if necessary, before resuming in _thread_in_Java state. | |
860 // In order for GC to work, don't clear the last_Java_sp until after blocking. | |
861 { Label no_block; | |
862 Address sync_state(G3_scratch, SafepointSynchronize::address_of_state()); | |
863 | |
864 // Switch thread to "native transition" state before reading the synchronization state. | |
865 // This additional state is necessary because reading and testing the synchronization | |
866 // state is not atomic w.r.t. GC, as this scenario demonstrates: | |
867 // Java thread A, in _thread_in_native state, loads _not_synchronized and is preempted. | |
868 // VM thread changes sync state to synchronizing and suspends threads for GC. | |
869 // Thread A is resumed to finish this native method, but doesn't block here since it | |
870 // didn't see any synchronization is progress, and escapes. | |
871 __ set(_thread_in_native_trans, G3_scratch); | |
872 __ st(G3_scratch, thread_state); | |
873 if(os::is_MP()) { | |
874 // Write serialization page so VM thread can do a pseudo remote membar. | |
875 // We use the current thread pointer to calculate a thread specific | |
876 // offset to write to within the page. This minimizes bus traffic | |
877 // due to cache line collision. | |
878 __ serialize_memory(G2_thread, G1_scratch, G3_scratch); | |
879 } | |
880 __ load_contents(sync_state, G3_scratch); | |
881 __ cmp(G3_scratch, SafepointSynchronize::_not_synchronized); | |
882 | |
883 | |
884 Label L; | |
885 Address suspend_state(G2_thread, 0, in_bytes(JavaThread::suspend_flags_offset())); | |
886 __ br(Assembler::notEqual, false, Assembler::pn, L); | |
887 __ delayed()-> | |
888 ld(suspend_state, G3_scratch); | |
889 __ cmp(G3_scratch, 0); | |
890 __ br(Assembler::equal, false, Assembler::pt, no_block); | |
891 __ delayed()->nop(); | |
892 __ bind(L); | |
893 | |
894 // Block. Save any potential method result value before the operation and | |
895 // use a leaf call to leave the last_Java_frame setup undisturbed. | |
896 save_native_result(); | |
897 __ call_VM_leaf(noreg, | |
898 CAST_FROM_FN_PTR(address, JavaThread::check_safepoint_and_suspend_for_native_trans), | |
899 G2_thread); | |
900 __ ld_ptr(STATE(_thread), G2_thread); // restore thread | |
901 // Restore any method result value | |
902 restore_native_result(); | |
903 __ bind(no_block); | |
904 } | |
905 | |
906 // Clear the frame anchor now | |
907 | |
908 __ reset_last_Java_frame(); | |
909 | |
910 // Move the result handler address | |
911 __ mov(Lscratch, G3_scratch); | |
912 // return possible result to the outer frame | |
913 #ifndef __LP64 | |
914 __ mov(O0, I0); | |
915 __ restore(O1, G0, O1); | |
916 #else | |
917 __ restore(O0, G0, O0); | |
918 #endif /* __LP64 */ | |
919 | |
920 // Move result handler to expected register | |
921 __ mov(G3_scratch, Lscratch); | |
922 | |
923 | |
924 // thread state is thread_in_native_trans. Any safepoint blocking has | |
925 // happened in the trampoline we are ready to switch to thread_in_Java. | |
926 | |
927 __ set(_thread_in_Java, G3_scratch); | |
928 __ st(G3_scratch, thread_state); | |
929 | |
930 // If we have an oop result store it where it will be safe for any further gc | |
931 // until we return now that we've released the handle it might be protected by | |
932 | |
933 { | |
934 Label no_oop, store_result; | |
935 | |
936 __ set((intptr_t)AbstractInterpreter::result_handler(T_OBJECT), G3_scratch); | |
937 __ cmp(G3_scratch, Lscratch); | |
938 __ brx(Assembler::notEqual, false, Assembler::pt, no_oop); | |
939 __ delayed()->nop(); | |
940 __ addcc(G0, O0, O0); | |
941 __ brx(Assembler::notZero, true, Assembler::pt, store_result); // if result is not NULL: | |
942 __ delayed()->ld_ptr(O0, 0, O0); // unbox it | |
943 __ mov(G0, O0); | |
944 | |
945 __ bind(store_result); | |
946 // Store it where gc will look for it and result handler expects it. | |
947 __ st_ptr(O0, STATE(_oop_temp)); | |
948 | |
949 __ bind(no_oop); | |
950 | |
951 } | |
952 | |
953 // reset handle block | |
954 __ ld_ptr(G2_thread, in_bytes(JavaThread::active_handles_offset()), G3_scratch); | |
955 __ st_ptr(G0, G3_scratch, JNIHandleBlock::top_offset_in_bytes()); | |
956 | |
957 | |
958 // handle exceptions (exception handling will handle unlocking!) | |
959 { Label L; | |
960 Address exception_addr (G2_thread, 0, in_bytes(Thread::pending_exception_offset())); | |
961 | |
962 __ ld_ptr(exception_addr, Gtemp); | |
963 __ tst(Gtemp); | |
964 __ brx(Assembler::equal, false, Assembler::pt, L); | |
965 __ delayed()->nop(); | |
966 __ bind(pending_exception_present); | |
967 // With c++ interpreter we just leave it pending caller will do the correct thing. However... | |
968 // Like x86 we ignore the result of the native call and leave the method locked. This | |
969 // seems wrong to leave things locked. | |
970 | |
971 __ br(Assembler::always, false, Assembler::pt, StubRoutines::forward_exception_entry(), relocInfo::runtime_call_type); | |
972 __ delayed()->restore(I5_savedSP, G0, SP); // remove interpreter frame | |
973 | |
974 __ bind(L); | |
975 } | |
976 | |
977 // jvmdi/jvmpi support (preserves thread register) | |
978 __ notify_method_exit(true, ilgl, InterpreterMacroAssembler::NotifyJVMTI); | |
979 | |
980 if (synchronized) { | |
981 // save and restore any potential method result value around the unlocking operation | |
982 save_native_result(); | |
983 | |
984 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; | |
985 // Get the initial monitor we allocated | |
986 __ sub(Lstate, entry_size, O1); // initial monitor | |
987 __ unlock_object(O1); | |
988 restore_native_result(); | |
989 } | |
990 | |
991 #if defined(COMPILER2) && !defined(_LP64) | |
992 | |
993 // C2 expects long results in G1 we can't tell if we're returning to interpreted | |
994 // or compiled so just be safe. | |
995 | |
996 __ sllx(O0, 32, G1); // Shift bits into high G1 | |
997 __ srl (O1, 0, O1); // Zero extend O1 | |
998 __ or3 (O1, G1, G1); // OR 64 bits into G1 | |
999 | |
1000 #endif /* COMPILER2 && !_LP64 */ | |
1001 | |
1002 #ifdef ASSERT | |
1003 { | |
1004 Label ok; | |
1005 __ cmp(I5_savedSP, FP); | |
1006 __ brx(Assembler::greaterEqualUnsigned, false, Assembler::pt, ok); | |
1007 __ delayed()->nop(); | |
1008 __ stop("bad I5_savedSP value"); | |
1009 __ should_not_reach_here(); | |
1010 __ bind(ok); | |
1011 } | |
1012 #endif | |
1013 // Calls result handler which POPS FRAME | |
1014 if (TraceJumps) { | |
1015 // Move target to register that is recordable | |
1016 __ mov(Lscratch, G3_scratch); | |
1017 __ JMP(G3_scratch, 0); | |
1018 } else { | |
1019 __ jmp(Lscratch, 0); | |
1020 } | |
1021 __ delayed()->nop(); | |
1022 | |
1023 if (inc_counter) { | |
1024 // handle invocation counter overflow | |
1025 __ bind(invocation_counter_overflow); | |
1026 generate_counter_overflow(Lcontinue); | |
1027 } | |
1028 | |
1029 | |
1030 return entry; | |
1031 } | |
1032 | |
1033 void CppInterpreterGenerator::generate_compute_interpreter_state(const Register state, | |
1034 const Register prev_state, | |
1035 bool native) { | |
1036 | |
1037 // On entry | |
1038 // G5_method - caller's method | |
1039 // Gargs - points to initial parameters (i.e. locals[0]) | |
1040 // G2_thread - valid? (C1 only??) | |
1041 // "prev_state" - contains any previous frame manager state which we must save a link | |
1042 // | |
1043 // On return | |
1044 // "state" is a pointer to the newly allocated state object. We must allocate and initialize | |
1045 // a new interpretState object and the method expression stack. | |
1046 | |
1047 assert_different_registers(state, prev_state); | |
1048 assert_different_registers(prev_state, G3_scratch); | |
1049 const Register Gtmp = G3_scratch; | |
1050 const Address constants (G5_method, 0, in_bytes(methodOopDesc::constants_offset())); | |
1051 const Address access_flags (G5_method, 0, in_bytes(methodOopDesc::access_flags_offset())); | |
1052 const Address size_of_parameters(G5_method, 0, in_bytes(methodOopDesc::size_of_parameters_offset())); | |
1053 const Address max_stack (G5_method, 0, in_bytes(methodOopDesc::max_stack_offset())); | |
1054 const Address size_of_locals (G5_method, 0, in_bytes(methodOopDesc::size_of_locals_offset())); | |
1055 | |
1056 // slop factor is two extra slots on the expression stack so that | |
1057 // we always have room to store a result when returning from a call without parameters | |
1058 // that returns a result. | |
1059 | |
1060 const int slop_factor = 2*wordSize; | |
1061 | |
1062 const int fixed_size = ((sizeof(BytecodeInterpreter) + slop_factor) >> LogBytesPerWord) + // what is the slop factor? | |
710 | 1063 //6815692//methodOopDesc::extra_stack_words() + // extra push slots for MH adapters |
0 | 1064 frame::memory_parameter_word_sp_offset + // register save area + param window |
1065 (native ? frame::interpreter_frame_extra_outgoing_argument_words : 0); // JNI, class | |
1066 | |
1067 // XXX G5_method valid | |
1068 | |
1069 // Now compute new frame size | |
1070 | |
1071 if (native) { | |
1072 __ lduh( size_of_parameters, Gtmp ); | |
1073 __ calc_mem_param_words(Gtmp, Gtmp); // space for native call parameters passed on the stack in words | |
1074 } else { | |
1075 __ lduh(max_stack, Gtmp); // Full size expression stack | |
1076 } | |
1077 __ add(Gtmp, fixed_size, Gtmp); // plus the fixed portion | |
1078 | |
1079 __ neg(Gtmp); // negative space for stack/parameters in words | |
1080 __ and3(Gtmp, -WordsPerLong, Gtmp); // make multiple of 2 (SP must be 2-word aligned) | |
1081 __ sll(Gtmp, LogBytesPerWord, Gtmp); // negative space for frame in bytes | |
1082 | |
1083 // Need to do stack size check here before we fault on large frames | |
1084 | |
1085 Label stack_ok; | |
1086 | |
1087 const int max_pages = StackShadowPages > (StackRedPages+StackYellowPages) ? StackShadowPages : | |
1088 (StackRedPages+StackYellowPages); | |
1089 | |
1090 | |
1091 __ ld_ptr(G2_thread, in_bytes(Thread::stack_base_offset()), O0); | |
1092 __ ld_ptr(G2_thread, in_bytes(Thread::stack_size_offset()), O1); | |
1093 // compute stack bottom | |
1094 __ sub(O0, O1, O0); | |
1095 | |
1096 // Avoid touching the guard pages | |
1097 // Also a fudge for frame size of BytecodeInterpreter::run | |
1098 // It varies from 1k->4k depending on build type | |
1099 const int fudge = 6 * K; | |
1100 | |
1101 __ set(fudge + (max_pages * os::vm_page_size()), O1); | |
1102 | |
1103 __ add(O0, O1, O0); | |
1104 __ sub(O0, Gtmp, O0); | |
1105 __ cmp(SP, O0); | |
1106 __ brx(Assembler::greaterUnsigned, false, Assembler::pt, stack_ok); | |
1107 __ delayed()->nop(); | |
1108 | |
1109 // throw exception return address becomes throwing pc | |
1110 | |
1111 __ call_VM(Oexception, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_StackOverflowError)); | |
1112 __ stop("never reached"); | |
1113 | |
1114 __ bind(stack_ok); | |
1115 | |
1116 __ save(SP, Gtmp, SP); // setup new frame and register window | |
1117 | |
1118 // New window I7 call_stub or previous activation | |
1119 // O6 - register save area, BytecodeInterpreter just below it, args/locals just above that | |
1120 // | |
1121 __ sub(FP, sizeof(BytecodeInterpreter), state); // Point to new Interpreter state | |
1122 __ add(state, STACK_BIAS, state ); // Account for 64bit bias | |
1123 | |
1124 #define XXX_STATE(field_name) state, in_bytes(byte_offset_of(BytecodeInterpreter, field_name)) | |
1125 | |
1126 // Initialize a new Interpreter state | |
1127 // orig_sp - caller's original sp | |
1128 // G2_thread - thread | |
1129 // Gargs - &locals[0] (unbiased?) | |
1130 // G5_method - method | |
1131 // SP (biased) - accounts for full size java stack, BytecodeInterpreter object, register save area, and register parameter save window | |
1132 | |
1133 | |
1134 __ set(0xdead0004, O1); | |
1135 | |
1136 | |
1137 __ st_ptr(Gargs, XXX_STATE(_locals)); | |
1138 __ st_ptr(G0, XXX_STATE(_oop_temp)); | |
1139 | |
1140 __ st_ptr(state, XXX_STATE(_self_link)); // point to self | |
1141 __ st_ptr(prev_state->after_save(), XXX_STATE(_prev_link)); // Chain interpreter states | |
1142 __ st_ptr(G2_thread, XXX_STATE(_thread)); // Store javathread | |
1143 | |
1144 if (native) { | |
1145 __ st_ptr(G0, XXX_STATE(_bcp)); | |
1146 } else { | |
1147 __ ld_ptr(G5_method, in_bytes(methodOopDesc::const_offset()), O2); // get constMethodOop | |
1148 __ add(O2, in_bytes(constMethodOopDesc::codes_offset()), O2); // get bcp | |
1149 __ st_ptr(O2, XXX_STATE(_bcp)); | |
1150 } | |
1151 | |
1152 __ st_ptr(G0, XXX_STATE(_mdx)); | |
1153 __ st_ptr(G5_method, XXX_STATE(_method)); | |
1154 | |
1155 __ set((int) BytecodeInterpreter::method_entry, O1); | |
1156 __ st(O1, XXX_STATE(_msg)); | |
1157 | |
1158 __ ld_ptr(constants, O3); | |
1159 __ ld_ptr(O3, constantPoolOopDesc::cache_offset_in_bytes(), O2); | |
1160 __ st_ptr(O2, XXX_STATE(_constants)); | |
1161 | |
1162 __ st_ptr(G0, XXX_STATE(_result._to_call._callee)); | |
1163 | |
1164 // Monitor base is just start of BytecodeInterpreter object; | |
1165 __ mov(state, O2); | |
1166 __ st_ptr(O2, XXX_STATE(_monitor_base)); | |
1167 | |
1168 // Do we need a monitor for synchonized method? | |
1169 { | |
1170 __ ld(access_flags, O1); | |
1171 Label done; | |
1172 Label got_obj; | |
1173 __ btst(JVM_ACC_SYNCHRONIZED, O1); | |
1174 __ br( Assembler::zero, false, Assembler::pt, done); | |
1175 | |
4762
069ab3f976d3
7118863: Move sizeof(klassOopDesc) into the *Klass::*_offset_in_bytes() functions
stefank
parents:
3839
diff
changeset
|
1176 const int mirror_offset = in_bytes(Klass::java_mirror_offset()); |
0 | 1177 __ delayed()->btst(JVM_ACC_STATIC, O1); |
1178 __ ld_ptr(XXX_STATE(_locals), O1); | |
1179 __ br( Assembler::zero, true, Assembler::pt, got_obj); | |
1180 __ delayed()->ld_ptr(O1, 0, O1); // get receiver for not-static case | |
1181 __ ld_ptr(constants, O1); | |
1182 __ ld_ptr( O1, constantPoolOopDesc::pool_holder_offset_in_bytes(), O1); | |
1183 // lock the mirror, not the klassOop | |
1184 __ ld_ptr( O1, mirror_offset, O1); | |
1185 | |
1186 __ bind(got_obj); | |
1187 | |
1188 #ifdef ASSERT | |
1189 __ tst(O1); | |
1190 __ breakpoint_trap(Assembler::zero); | |
1191 #endif // ASSERT | |
1192 | |
1193 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; | |
1194 __ sub(SP, entry_size, SP); // account for initial monitor | |
1195 __ sub(O2, entry_size, O2); // initial monitor | |
1196 __ st_ptr(O1, O2, BasicObjectLock::obj_offset_in_bytes()); // and allocate it for interpreter use | |
1197 __ bind(done); | |
1198 } | |
1199 | |
1200 // Remember initial frame bottom | |
1201 | |
1202 __ st_ptr(SP, XXX_STATE(_frame_bottom)); | |
1203 | |
1204 __ st_ptr(O2, XXX_STATE(_stack_base)); | |
1205 | |
1206 __ sub(O2, wordSize, O2); // prepush | |
1207 __ st_ptr(O2, XXX_STATE(_stack)); // PREPUSH | |
1208 | |
1209 __ lduh(max_stack, O3); // Full size expression stack | |
2416
38fea01eb669
6817525: turn on method handle functionality by default for JSR 292
twisti
parents:
2357
diff
changeset
|
1210 guarantee(!EnableInvokeDynamic, "no support yet for java.lang.invoke.MethodHandle"); //6815692 |
38fea01eb669
6817525: turn on method handle functionality by default for JSR 292
twisti
parents:
2357
diff
changeset
|
1211 //6815692//if (EnableInvokeDynamic) |
710 | 1212 //6815692// __ inc(O3, methodOopDesc::extra_stack_entries()); |
0 | 1213 __ sll(O3, LogBytesPerWord, O3); |
1214 __ sub(O2, O3, O3); | |
1215 // __ sub(O3, wordSize, O3); // so prepush doesn't look out of bounds | |
1216 __ st_ptr(O3, XXX_STATE(_stack_limit)); | |
1217 | |
1218 if (!native) { | |
1219 // | |
1220 // Code to initialize locals | |
1221 // | |
1222 Register init_value = noreg; // will be G0 if we must clear locals | |
1223 // Now zero locals | |
1224 if (true /* zerolocals */ || ClearInterpreterLocals) { | |
1225 // explicitly initialize locals | |
1226 init_value = G0; | |
1227 } else { | |
1228 #ifdef ASSERT | |
1229 // initialize locals to a garbage pattern for better debugging | |
1230 init_value = O3; | |
1231 __ set( 0x0F0F0F0F, init_value ); | |
1232 #endif // ASSERT | |
1233 } | |
1234 if (init_value != noreg) { | |
1235 Label clear_loop; | |
1236 | |
1237 // NOTE: If you change the frame layout, this code will need to | |
1238 // be updated! | |
1239 __ lduh( size_of_locals, O2 ); | |
1240 __ lduh( size_of_parameters, O1 ); | |
1241 __ sll( O2, LogBytesPerWord, O2); | |
1242 __ sll( O1, LogBytesPerWord, O1 ); | |
1243 __ ld_ptr(XXX_STATE(_locals), L2_scratch); | |
1244 __ sub( L2_scratch, O2, O2 ); | |
1245 __ sub( L2_scratch, O1, O1 ); | |
1246 | |
1247 __ bind( clear_loop ); | |
1248 __ inc( O2, wordSize ); | |
1249 | |
1250 __ cmp( O2, O1 ); | |
1251 __ br( Assembler::lessEqualUnsigned, true, Assembler::pt, clear_loop ); | |
1252 __ delayed()->st_ptr( init_value, O2, 0 ); | |
1253 } | |
1254 } | |
1255 } | |
1256 // Find preallocated monitor and lock method (C++ interpreter) | |
1257 // | |
1258 void InterpreterGenerator::lock_method(void) { | |
1259 // Lock the current method. | |
1260 // Destroys registers L2_scratch, L3_scratch, O0 | |
1261 // | |
1262 // Find everything relative to Lstate | |
1263 | |
1264 #ifdef ASSERT | |
1265 __ ld_ptr(STATE(_method), L2_scratch); | |
1266 __ ld(L2_scratch, in_bytes(methodOopDesc::access_flags_offset()), O0); | |
1267 | |
1268 { Label ok; | |
1269 __ btst(JVM_ACC_SYNCHRONIZED, O0); | |
1270 __ br( Assembler::notZero, false, Assembler::pt, ok); | |
1271 __ delayed()->nop(); | |
1272 __ stop("method doesn't need synchronization"); | |
1273 __ bind(ok); | |
1274 } | |
1275 #endif // ASSERT | |
1276 | |
1277 // monitor is already allocated at stack base | |
1278 // and the lockee is already present | |
1279 __ ld_ptr(STATE(_stack_base), L2_scratch); | |
1280 __ ld_ptr(L2_scratch, BasicObjectLock::obj_offset_in_bytes(), O0); // get object | |
1281 __ lock_object(L2_scratch, O0); | |
1282 | |
1283 } | |
1284 | |
1285 // Generate code for handling resuming a deopted method | |
1286 void CppInterpreterGenerator::generate_deopt_handling() { | |
1287 | |
1288 Label return_from_deopt_common; | |
1289 | |
1290 // deopt needs to jump to here to enter the interpreter (return a result) | |
1291 deopt_frame_manager_return_atos = __ pc(); | |
1292 | |
1293 // O0/O1 live | |
3839 | 1294 __ ba(return_from_deopt_common); |
0 | 1295 __ delayed()->set(AbstractInterpreter::BasicType_as_index(T_OBJECT), L3_scratch); // Result stub address array index |
1296 | |
1297 | |
1298 // deopt needs to jump to here to enter the interpreter (return a result) | |
1299 deopt_frame_manager_return_btos = __ pc(); | |
1300 | |
1301 // O0/O1 live | |
3839 | 1302 __ ba(return_from_deopt_common); |
0 | 1303 __ delayed()->set(AbstractInterpreter::BasicType_as_index(T_BOOLEAN), L3_scratch); // Result stub address array index |
1304 | |
1305 // deopt needs to jump to here to enter the interpreter (return a result) | |
1306 deopt_frame_manager_return_itos = __ pc(); | |
1307 | |
1308 // O0/O1 live | |
3839 | 1309 __ ba(return_from_deopt_common); |
0 | 1310 __ delayed()->set(AbstractInterpreter::BasicType_as_index(T_INT), L3_scratch); // Result stub address array index |
1311 | |
1312 // deopt needs to jump to here to enter the interpreter (return a result) | |
1313 | |
1314 deopt_frame_manager_return_ltos = __ pc(); | |
1315 #if !defined(_LP64) && defined(COMPILER2) | |
1316 // All return values are where we want them, except for Longs. C2 returns | |
1317 // longs in G1 in the 32-bit build whereas the interpreter wants them in O0/O1. | |
1318 // Since the interpreter will return longs in G1 and O0/O1 in the 32bit | |
1319 // build even if we are returning from interpreted we just do a little | |
1320 // stupid shuffing. | |
1321 // Note: I tried to make c2 return longs in O0/O1 and G1 so we wouldn't have to | |
1322 // do this here. Unfortunately if we did a rethrow we'd see an machepilog node | |
1323 // first which would move g1 -> O0/O1 and destroy the exception we were throwing. | |
1324 | |
1325 __ srl (G1, 0,O1); | |
1326 __ srlx(G1,32,O0); | |
1327 #endif /* !_LP64 && COMPILER2 */ | |
1328 // O0/O1 live | |
3839 | 1329 __ ba(return_from_deopt_common); |
0 | 1330 __ delayed()->set(AbstractInterpreter::BasicType_as_index(T_LONG), L3_scratch); // Result stub address array index |
1331 | |
1332 // deopt needs to jump to here to enter the interpreter (return a result) | |
1333 | |
1334 deopt_frame_manager_return_ftos = __ pc(); | |
1335 // O0/O1 live | |
3839 | 1336 __ ba(return_from_deopt_common); |
0 | 1337 __ delayed()->set(AbstractInterpreter::BasicType_as_index(T_FLOAT), L3_scratch); // Result stub address array index |
1338 | |
1339 // deopt needs to jump to here to enter the interpreter (return a result) | |
1340 deopt_frame_manager_return_dtos = __ pc(); | |
1341 | |
1342 // O0/O1 live | |
3839 | 1343 __ ba(return_from_deopt_common); |
0 | 1344 __ delayed()->set(AbstractInterpreter::BasicType_as_index(T_DOUBLE), L3_scratch); // Result stub address array index |
1345 | |
1346 // deopt needs to jump to here to enter the interpreter (return a result) | |
1347 deopt_frame_manager_return_vtos = __ pc(); | |
1348 | |
1349 // O0/O1 live | |
1350 __ set(AbstractInterpreter::BasicType_as_index(T_VOID), L3_scratch); | |
1351 | |
1352 // Deopt return common | |
1353 // an index is present that lets us move any possible result being | |
1354 // return to the interpreter's stack | |
1355 // | |
1356 __ bind(return_from_deopt_common); | |
1357 | |
1358 // Result if any is in native abi result (O0..O1/F0..F1). The java expression | |
1359 // stack is in the state that the calling convention left it. | |
1360 // Copy the result from native abi result and place it on java expression stack. | |
1361 | |
1362 // Current interpreter state is present in Lstate | |
1363 | |
1364 // Get current pre-pushed top of interpreter stack | |
1365 // Any result (if any) is in native abi | |
1366 // result type index is in L3_scratch | |
1367 | |
1368 __ ld_ptr(STATE(_stack), L1_scratch); // get top of java expr stack | |
1369 | |
1370 __ set((intptr_t)CppInterpreter::_tosca_to_stack, L4_scratch); | |
1371 __ sll(L3_scratch, LogBytesPerWord, L3_scratch); | |
1372 __ ld_ptr(L4_scratch, L3_scratch, Lscratch); // get typed result converter address | |
1373 __ jmpl(Lscratch, G0, O7); // and convert it | |
1374 __ delayed()->nop(); | |
1375 | |
1376 // L1_scratch points to top of stack (prepushed) | |
1377 __ st_ptr(L1_scratch, STATE(_stack)); | |
1378 } | |
1379 | |
1380 // Generate the code to handle a more_monitors message from the c++ interpreter | |
1381 void CppInterpreterGenerator::generate_more_monitors() { | |
1382 | |
1383 Label entry, loop; | |
1384 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; | |
1385 // 1. compute new pointers // esp: old expression stack top | |
1386 __ delayed()->ld_ptr(STATE(_stack_base), L4_scratch); // current expression stack bottom | |
1387 __ sub(L4_scratch, entry_size, L4_scratch); | |
1388 __ st_ptr(L4_scratch, STATE(_stack_base)); | |
1389 | |
1390 __ sub(SP, entry_size, SP); // Grow stack | |
1391 __ st_ptr(SP, STATE(_frame_bottom)); | |
1392 | |
1393 __ ld_ptr(STATE(_stack_limit), L2_scratch); | |
1394 __ sub(L2_scratch, entry_size, L2_scratch); | |
1395 __ st_ptr(L2_scratch, STATE(_stack_limit)); | |
1396 | |
1397 __ ld_ptr(STATE(_stack), L1_scratch); // Get current stack top | |
1398 __ sub(L1_scratch, entry_size, L1_scratch); | |
1399 __ st_ptr(L1_scratch, STATE(_stack)); | |
3839 | 1400 __ ba(entry); |
0 | 1401 __ delayed()->add(L1_scratch, wordSize, L1_scratch); // first real entry (undo prepush) |
1402 | |
1403 // 2. move expression stack | |
1404 | |
1405 __ bind(loop); | |
1406 __ st_ptr(L3_scratch, Address(L1_scratch, 0)); | |
1407 __ add(L1_scratch, wordSize, L1_scratch); | |
1408 __ bind(entry); | |
1409 __ cmp(L1_scratch, L4_scratch); | |
1410 __ br(Assembler::notEqual, false, Assembler::pt, loop); | |
1411 __ delayed()->ld_ptr(L1_scratch, entry_size, L3_scratch); | |
1412 | |
1413 // now zero the slot so we can find it. | |
123 | 1414 __ st_ptr(G0, L4_scratch, BasicObjectLock::obj_offset_in_bytes()); |
0 | 1415 |
1416 } | |
1417 | |
1418 // Initial entry to C++ interpreter from the call_stub. | |
1419 // This entry point is called the frame manager since it handles the generation | |
1420 // of interpreter activation frames via requests directly from the vm (via call_stub) | |
1421 // and via requests from the interpreter. The requests from the call_stub happen | |
1422 // directly thru the entry point. Requests from the interpreter happen via returning | |
1423 // from the interpreter and examining the message the interpreter has returned to | |
1424 // the frame manager. The frame manager can take the following requests: | |
1425 | |
1426 // NO_REQUEST - error, should never happen. | |
1427 // MORE_MONITORS - need a new monitor. Shuffle the expression stack on down and | |
1428 // allocate a new monitor. | |
1429 // CALL_METHOD - setup a new activation to call a new method. Very similar to what | |
1430 // happens during entry during the entry via the call stub. | |
1431 // RETURN_FROM_METHOD - remove an activation. Return to interpreter or call stub. | |
1432 // | |
1433 // Arguments: | |
1434 // | |
1435 // ebx: methodOop | |
1436 // ecx: receiver - unused (retrieved from stack as needed) | |
1437 // esi: previous frame manager state (NULL from the call_stub/c1/c2) | |
1438 // | |
1439 // | |
1440 // Stack layout at entry | |
1441 // | |
1442 // [ return address ] <--- esp | |
1443 // [ parameter n ] | |
1444 // ... | |
1445 // [ parameter 1 ] | |
1446 // [ expression stack ] | |
1447 // | |
1448 // | |
1449 // We are free to blow any registers we like because the call_stub which brought us here | |
1450 // initially has preserved the callee save registers already. | |
1451 // | |
1452 // | |
1453 | |
1454 static address interpreter_frame_manager = NULL; | |
1455 | |
1456 #ifdef ASSERT | |
1457 #define VALIDATE_STATE(scratch, marker) \ | |
1458 { \ | |
1459 Label skip; \ | |
1460 __ ld_ptr(STATE(_self_link), scratch); \ | |
1461 __ cmp(Lstate, scratch); \ | |
1462 __ brx(Assembler::equal, false, Assembler::pt, skip); \ | |
1463 __ delayed()->nop(); \ | |
1464 __ breakpoint_trap(); \ | |
1465 __ emit_long(marker); \ | |
1466 __ bind(skip); \ | |
1467 } | |
1468 #else | |
1469 #define VALIDATE_STATE(scratch, marker) | |
1470 #endif /* ASSERT */ | |
1471 | |
1472 void CppInterpreterGenerator::adjust_callers_stack(Register args) { | |
1473 // | |
1474 // Adjust caller's stack so that all the locals can be contiguous with | |
1475 // the parameters. | |
1476 // Worries about stack overflow make this a pain. | |
1477 // | |
1478 // Destroys args, G3_scratch, G3_scratch | |
1479 // In/Out O5_savedSP (sender's original SP) | |
1480 // | |
1481 // assert_different_registers(state, prev_state); | |
1482 const Register Gtmp = G3_scratch; | |
1483 const Register tmp = O2; | |
1484 const Address size_of_parameters(G5_method, 0, in_bytes(methodOopDesc::size_of_parameters_offset())); | |
1485 const Address size_of_locals (G5_method, 0, in_bytes(methodOopDesc::size_of_locals_offset())); | |
1486 | |
1487 __ lduh(size_of_parameters, tmp); | |
1488 __ sll(tmp, LogBytesPerWord, Gtmp); // parameter size in bytes | |
1489 __ add(args, Gtmp, Gargs); // points to first local + BytesPerWord | |
1490 // NEW | |
1491 __ add(Gargs, -wordSize, Gargs); // points to first local[0] | |
1492 // determine extra space for non-argument locals & adjust caller's SP | |
1493 // Gtmp1: parameter size in words | |
1494 __ lduh(size_of_locals, Gtmp); | |
1495 __ compute_extra_locals_size_in_bytes(tmp, Gtmp, Gtmp); | |
1496 | |
1497 #if 1 | |
1498 // c2i adapters place the final interpreter argument in the register save area for O0/I0 | |
1499 // the call_stub will place the final interpreter argument at | |
1500 // frame::memory_parameter_word_sp_offset. This is mostly not noticable for either asm | |
1501 // or c++ interpreter. However with the c++ interpreter when we do a recursive call | |
1502 // and try to make it look good in the debugger we will store the argument to | |
1503 // RecursiveInterpreterActivation in the register argument save area. Without allocating | |
1504 // extra space for the compiler this will overwrite locals in the local array of the | |
1505 // interpreter. | |
1506 // QQQ still needed with frameless adapters??? | |
1507 | |
1508 const int c2i_adjust_words = frame::memory_parameter_word_sp_offset - frame::callee_register_argument_save_area_sp_offset; | |
1509 | |
1510 __ add(Gtmp, c2i_adjust_words*wordSize, Gtmp); | |
1511 #endif // 1 | |
1512 | |
1513 | |
1514 __ sub(SP, Gtmp, SP); // just caller's frame for the additional space we need. | |
1515 } | |
1516 | |
1517 address InterpreterGenerator::generate_normal_entry(bool synchronized) { | |
1518 | |
1519 // G5_method: methodOop | |
1520 // G2_thread: thread (unused) | |
1521 // Gargs: bottom of args (sender_sp) | |
1522 // O5: sender's sp | |
1523 | |
1524 // A single frame manager is plenty as we don't specialize for synchronized. We could and | |
1525 // the code is pretty much ready. Would need to change the test below and for good measure | |
1526 // modify generate_interpreter_state to only do the (pre) sync stuff stuff for synchronized | |
1527 // routines. Not clear this is worth it yet. | |
1528 | |
1529 if (interpreter_frame_manager) { | |
1530 return interpreter_frame_manager; | |
1531 } | |
1532 | |
1533 __ bind(frame_manager_entry); | |
1534 | |
1535 // the following temporary registers are used during frame creation | |
1536 const Register Gtmp1 = G3_scratch; | |
1537 // const Register Lmirror = L1; // native mirror (native calls only) | |
1538 | |
1539 const Address constants (G5_method, 0, in_bytes(methodOopDesc::constants_offset())); | |
1540 const Address access_flags (G5_method, 0, in_bytes(methodOopDesc::access_flags_offset())); | |
1541 const Address size_of_parameters(G5_method, 0, in_bytes(methodOopDesc::size_of_parameters_offset())); | |
1542 const Address max_stack (G5_method, 0, in_bytes(methodOopDesc::max_stack_offset())); | |
1543 const Address size_of_locals (G5_method, 0, in_bytes(methodOopDesc::size_of_locals_offset())); | |
1544 | |
1545 address entry_point = __ pc(); | |
1546 __ mov(G0, prevState); // no current activation | |
1547 | |
1548 | |
1549 Label re_dispatch; | |
1550 | |
1551 __ bind(re_dispatch); | |
1552 | |
1553 // Interpreter needs to have locals completely contiguous. In order to do that | |
1554 // We must adjust the caller's stack pointer for any locals beyond just the | |
1555 // parameters | |
1556 adjust_callers_stack(Gargs); | |
1557 | |
1558 // O5_savedSP still contains sender's sp | |
1559 | |
1560 // NEW FRAME | |
1561 | |
1562 generate_compute_interpreter_state(Lstate, prevState, false); | |
1563 | |
1564 // At this point a new interpreter frame and state object are created and initialized | |
1565 // Lstate has the pointer to the new activation | |
1566 // Any stack banging or limit check should already be done. | |
1567 | |
1568 Label call_interpreter; | |
1569 | |
1570 __ bind(call_interpreter); | |
1571 | |
1572 | |
1573 #if 1 | |
1574 __ set(0xdead002, Lmirror); | |
1575 __ set(0xdead002, L2_scratch); | |
1576 __ set(0xdead003, L3_scratch); | |
1577 __ set(0xdead004, L4_scratch); | |
1578 __ set(0xdead005, Lscratch); | |
1579 __ set(0xdead006, Lscratch2); | |
1580 __ set(0xdead007, L7_scratch); | |
1581 | |
1582 __ set(0xdeaf002, O2); | |
1583 __ set(0xdeaf003, O3); | |
1584 __ set(0xdeaf004, O4); | |
1585 __ set(0xdeaf005, O5); | |
1586 #endif | |
1587 | |
1588 // Call interpreter (stack bang complete) enter here if message is | |
1589 // set and we know stack size is valid | |
1590 | |
1591 Label call_interpreter_2; | |
1592 | |
1593 __ bind(call_interpreter_2); | |
1594 | |
1595 #ifdef ASSERT | |
1596 { | |
1597 Label skip; | |
1598 __ ld_ptr(STATE(_frame_bottom), G3_scratch); | |
1599 __ cmp(G3_scratch, SP); | |
1600 __ brx(Assembler::equal, false, Assembler::pt, skip); | |
1601 __ delayed()->nop(); | |
1602 __ stop("SP not restored to frame bottom"); | |
1603 __ bind(skip); | |
1604 } | |
1605 #endif | |
1606 | |
1607 VALIDATE_STATE(G3_scratch, 4); | |
1608 __ set_last_Java_frame(SP, noreg); | |
1609 __ mov(Lstate, O0); // (arg) pointer to current state | |
1610 | |
1611 __ call(CAST_FROM_FN_PTR(address, | |
1612 JvmtiExport::can_post_interpreter_events() ? | |
1613 BytecodeInterpreter::runWithChecks | |
1614 : BytecodeInterpreter::run), | |
1615 relocInfo::runtime_call_type); | |
1616 | |
1617 __ delayed()->nop(); | |
1618 | |
1619 __ ld_ptr(STATE(_thread), G2_thread); | |
1620 __ reset_last_Java_frame(); | |
1621 | |
1622 // examine msg from interpreter to determine next action | |
1623 __ ld_ptr(STATE(_thread), G2_thread); // restore G2_thread | |
1624 | |
1625 __ ld(STATE(_msg), L1_scratch); // Get new message | |
1626 | |
1627 Label call_method; | |
1628 Label return_from_interpreted_method; | |
1629 Label throw_exception; | |
1630 Label do_OSR; | |
1631 Label bad_msg; | |
1632 Label resume_interpreter; | |
1633 | |
1634 __ cmp(L1_scratch, (int)BytecodeInterpreter::call_method); | |
1635 __ br(Assembler::equal, false, Assembler::pt, call_method); | |
1636 __ delayed()->cmp(L1_scratch, (int)BytecodeInterpreter::return_from_method); | |
1637 __ br(Assembler::equal, false, Assembler::pt, return_from_interpreted_method); | |
1638 __ delayed()->cmp(L1_scratch, (int)BytecodeInterpreter::throwing_exception); | |
1639 __ br(Assembler::equal, false, Assembler::pt, throw_exception); | |
1640 __ delayed()->cmp(L1_scratch, (int)BytecodeInterpreter::do_osr); | |
1641 __ br(Assembler::equal, false, Assembler::pt, do_OSR); | |
1642 __ delayed()->cmp(L1_scratch, (int)BytecodeInterpreter::more_monitors); | |
1643 __ br(Assembler::notEqual, false, Assembler::pt, bad_msg); | |
1644 | |
1645 // Allocate more monitor space, shuffle expression stack.... | |
1646 | |
1647 generate_more_monitors(); | |
1648 | |
1649 // new monitor slot allocated, resume the interpreter. | |
1650 | |
1651 __ set((int)BytecodeInterpreter::got_monitors, L1_scratch); | |
1652 VALIDATE_STATE(G3_scratch, 5); | |
3839 | 1653 __ ba(call_interpreter); |
0 | 1654 __ delayed()->st(L1_scratch, STATE(_msg)); |
1655 | |
1656 // uncommon trap needs to jump to here to enter the interpreter (re-execute current bytecode) | |
1657 unctrap_frame_manager_entry = __ pc(); | |
1658 | |
1659 // QQQ what message do we send | |
1660 | |
3839 | 1661 __ ba(call_interpreter); |
0 | 1662 __ delayed()->ld_ptr(STATE(_frame_bottom), SP); // restore to full stack frame |
1663 | |
1664 //============================================================================= | |
1665 // Returning from a compiled method into a deopted method. The bytecode at the | |
1666 // bcp has completed. The result of the bytecode is in the native abi (the tosca | |
1667 // for the template based interpreter). Any stack space that was used by the | |
1668 // bytecode that has completed has been removed (e.g. parameters for an invoke) | |
1669 // so all that we have to do is place any pending result on the expression stack | |
1670 // and resume execution on the next bytecode. | |
1671 | |
1672 generate_deopt_handling(); | |
1673 | |
1674 // ready to resume the interpreter | |
1675 | |
1676 __ set((int)BytecodeInterpreter::deopt_resume, L1_scratch); | |
3839 | 1677 __ ba(call_interpreter); |
0 | 1678 __ delayed()->st(L1_scratch, STATE(_msg)); |
1679 | |
1680 // Current frame has caught an exception we need to dispatch to the | |
1681 // handler. We can get here because a native interpreter frame caught | |
1682 // an exception in which case there is no handler and we must rethrow | |
1683 // If it is a vanilla interpreted frame the we simply drop into the | |
1684 // interpreter and let it do the lookup. | |
1685 | |
1686 Interpreter::_rethrow_exception_entry = __ pc(); | |
1687 | |
1688 Label return_with_exception; | |
1689 Label unwind_and_forward; | |
1690 | |
1691 // O0: exception | |
1692 // O7: throwing pc | |
1693 | |
1694 // We want exception in the thread no matter what we ultimately decide about frame type. | |
1695 | |
1696 Address exception_addr (G2_thread, 0, in_bytes(Thread::pending_exception_offset())); | |
1697 __ verify_thread(); | |
1698 __ st_ptr(O0, exception_addr); | |
1699 | |
1700 // get the methodOop | |
1701 __ ld_ptr(STATE(_method), G5_method); | |
1702 | |
1703 // if this current frame vanilla or native? | |
1704 | |
1705 __ ld(access_flags, Gtmp1); | |
1706 __ btst(JVM_ACC_NATIVE, Gtmp1); | |
1707 __ br(Assembler::zero, false, Assembler::pt, return_with_exception); // vanilla interpreted frame handle directly | |
1708 __ delayed()->nop(); | |
1709 | |
1710 // We drop thru to unwind a native interpreted frame with a pending exception | |
1711 // We jump here for the initial interpreter frame with exception pending | |
1712 // We unwind the current acivation and forward it to our caller. | |
1713 | |
1714 __ bind(unwind_and_forward); | |
1715 | |
1716 // Unwind frame and jump to forward exception. unwinding will place throwing pc in O7 | |
1717 // as expected by forward_exception. | |
1718 | |
1719 __ restore(FP, G0, SP); // unwind interpreter state frame | |
1720 __ br(Assembler::always, false, Assembler::pt, StubRoutines::forward_exception_entry(), relocInfo::runtime_call_type); | |
1721 __ delayed()->mov(I5_savedSP->after_restore(), SP); | |
1722 | |
1723 // Return point from a call which returns a result in the native abi | |
1724 // (c1/c2/jni-native). This result must be processed onto the java | |
1725 // expression stack. | |
1726 // | |
1727 // A pending exception may be present in which case there is no result present | |
1728 | |
1729 address return_from_native_method = __ pc(); | |
1730 | |
1731 VALIDATE_STATE(G3_scratch, 6); | |
1732 | |
1733 // Result if any is in native abi result (O0..O1/F0..F1). The java expression | |
1734 // stack is in the state that the calling convention left it. | |
1735 // Copy the result from native abi result and place it on java expression stack. | |
1736 | |
1737 // Current interpreter state is present in Lstate | |
1738 | |
1739 // Exception pending? | |
1740 | |
1741 __ ld_ptr(STATE(_frame_bottom), SP); // restore to full stack frame | |
1742 __ ld_ptr(exception_addr, Lscratch); // get any pending exception | |
1743 __ tst(Lscratch); // exception pending? | |
1744 __ brx(Assembler::notZero, false, Assembler::pt, return_with_exception); | |
1745 __ delayed()->nop(); | |
1746 | |
1747 // Process the native abi result to java expression stack | |
1748 | |
1749 __ ld_ptr(STATE(_result._to_call._callee), L4_scratch); // called method | |
1750 __ ld_ptr(STATE(_stack), L1_scratch); // get top of java expr stack | |
1751 __ lduh(L4_scratch, in_bytes(methodOopDesc::size_of_parameters_offset()), L2_scratch); // get parameter size | |
1752 __ sll(L2_scratch, LogBytesPerWord, L2_scratch ); // parameter size in bytes | |
1753 __ add(L1_scratch, L2_scratch, L1_scratch); // stack destination for result | |
123 | 1754 __ ld(L4_scratch, in_bytes(methodOopDesc::result_index_offset()), L3_scratch); // called method result type index |
0 | 1755 |
1756 // tosca is really just native abi | |
1757 __ set((intptr_t)CppInterpreter::_tosca_to_stack, L4_scratch); | |
1758 __ sll(L3_scratch, LogBytesPerWord, L3_scratch); | |
1759 __ ld_ptr(L4_scratch, L3_scratch, Lscratch); // get typed result converter address | |
1760 __ jmpl(Lscratch, G0, O7); // and convert it | |
1761 __ delayed()->nop(); | |
1762 | |
1763 // L1_scratch points to top of stack (prepushed) | |
1764 | |
3839 | 1765 __ ba(resume_interpreter); |
0 | 1766 __ delayed()->mov(L1_scratch, O1); |
1767 | |
1768 // An exception is being caught on return to a vanilla interpreter frame. | |
1769 // Empty the stack and resume interpreter | |
1770 | |
1771 __ bind(return_with_exception); | |
1772 | |
1773 __ ld_ptr(STATE(_frame_bottom), SP); // restore to full stack frame | |
1774 __ ld_ptr(STATE(_stack_base), O1); // empty java expression stack | |
3839 | 1775 __ ba(resume_interpreter); |
0 | 1776 __ delayed()->sub(O1, wordSize, O1); // account for prepush |
1777 | |
1778 // Return from interpreted method we return result appropriate to the caller (i.e. "recursive" | |
1779 // interpreter call, or native) and unwind this interpreter activation. | |
1780 // All monitors should be unlocked. | |
1781 | |
1782 __ bind(return_from_interpreted_method); | |
1783 | |
1784 VALIDATE_STATE(G3_scratch, 7); | |
1785 | |
1786 Label return_to_initial_caller; | |
1787 | |
1788 // Interpreted result is on the top of the completed activation expression stack. | |
1789 // We must return it to the top of the callers stack if caller was interpreted | |
1790 // otherwise we convert to native abi result and return to call_stub/c1/c2 | |
1791 // The caller's expression stack was truncated by the call however the current activation | |
1792 // has enough stuff on the stack that we have usable space there no matter what. The | |
1793 // other thing that makes it easy is that the top of the caller's stack is stored in STATE(_locals) | |
1794 // for the current activation | |
1795 | |
1796 __ ld_ptr(STATE(_prev_link), L1_scratch); | |
1797 __ ld_ptr(STATE(_method), L2_scratch); // get method just executed | |
123 | 1798 __ ld(L2_scratch, in_bytes(methodOopDesc::result_index_offset()), L2_scratch); |
0 | 1799 __ tst(L1_scratch); |
1800 __ brx(Assembler::zero, false, Assembler::pt, return_to_initial_caller); | |
1801 __ delayed()->sll(L2_scratch, LogBytesPerWord, L2_scratch); | |
1802 | |
1803 // Copy result to callers java stack | |
1804 | |
1805 __ set((intptr_t)CppInterpreter::_stack_to_stack, L4_scratch); | |
1806 __ ld_ptr(L4_scratch, L2_scratch, Lscratch); // get typed result converter address | |
1807 __ ld_ptr(STATE(_stack), O0); // current top (prepushed) | |
1808 __ ld_ptr(STATE(_locals), O1); // stack destination | |
1809 | |
1810 // O0 - will be source, O1 - will be destination (preserved) | |
1811 __ jmpl(Lscratch, G0, O7); // and convert it | |
1812 __ delayed()->add(O0, wordSize, O0); // get source (top of current expr stack) | |
1813 | |
1814 // O1 == &locals[0] | |
1815 | |
1816 // Result is now on caller's stack. Just unwind current activation and resume | |
1817 | |
1818 Label unwind_recursive_activation; | |
1819 | |
1820 | |
1821 __ bind(unwind_recursive_activation); | |
1822 | |
1823 // O1 == &locals[0] (really callers stacktop) for activation now returning | |
1824 // returning to interpreter method from "recursive" interpreter call | |
1825 // result converter left O1 pointing to top of the( prepushed) java stack for method we are returning | |
1826 // to. Now all we must do is unwind the state from the completed call | |
1827 | |
1828 // Must restore stack | |
1829 VALIDATE_STATE(G3_scratch, 8); | |
1830 | |
1831 // Return to interpreter method after a method call (interpreted/native/c1/c2) has completed. | |
1832 // Result if any is already on the caller's stack. All we must do now is remove the now dead | |
1833 // frame and tell interpreter to resume. | |
1834 | |
1835 | |
1836 __ mov(O1, I1); // pass back new stack top across activation | |
1837 // POP FRAME HERE ================================== | |
1838 __ restore(FP, G0, SP); // unwind interpreter state frame | |
1839 __ ld_ptr(STATE(_frame_bottom), SP); // restore to full stack frame | |
1840 | |
1841 | |
1842 // Resume the interpreter. The current frame contains the current interpreter | |
1843 // state object. | |
1844 // | |
1845 // O1 == new java stack pointer | |
1846 | |
1847 __ bind(resume_interpreter); | |
1848 VALIDATE_STATE(G3_scratch, 10); | |
1849 | |
1850 // A frame we have already used before so no need to bang stack so use call_interpreter_2 entry | |
1851 | |
1852 __ set((int)BytecodeInterpreter::method_resume, L1_scratch); | |
1853 __ st(L1_scratch, STATE(_msg)); | |
3839 | 1854 __ ba(call_interpreter_2); |
0 | 1855 __ delayed()->st_ptr(O1, STATE(_stack)); |
1856 | |
1857 | |
1858 // Fast accessor methods share this entry point. | |
1859 // This works because frame manager is in the same codelet | |
1860 // This can either be an entry via call_stub/c1/c2 or a recursive interpreter call | |
1861 // we need to do a little register fixup here once we distinguish the two of them | |
1862 if (UseFastAccessorMethods && !synchronized) { | |
1863 // Call stub_return address still in O7 | |
1864 __ bind(fast_accessor_slow_entry_path); | |
1865 __ set((intptr_t)return_from_native_method - 8, Gtmp1); | |
1866 __ cmp(Gtmp1, O7); // returning to interpreter? | |
1867 __ brx(Assembler::equal, true, Assembler::pt, re_dispatch); // yep | |
1868 __ delayed()->nop(); | |
3839 | 1869 __ ba(re_dispatch); |
1870 __ delayed()->mov(G0, prevState); // initial entry | |
0 | 1871 |
1872 } | |
1873 | |
1874 // interpreter returning to native code (call_stub/c1/c2) | |
1875 // convert result and unwind initial activation | |
1876 // L2_scratch - scaled result type index | |
1877 | |
1878 __ bind(return_to_initial_caller); | |
1879 | |
1880 __ set((intptr_t)CppInterpreter::_stack_to_native_abi, L4_scratch); | |
1881 __ ld_ptr(L4_scratch, L2_scratch, Lscratch); // get typed result converter address | |
1882 __ ld_ptr(STATE(_stack), O0); // current top (prepushed) | |
1883 __ jmpl(Lscratch, G0, O7); // and convert it | |
1884 __ delayed()->add(O0, wordSize, O0); // get source (top of current expr stack) | |
1885 | |
1886 Label unwind_initial_activation; | |
1887 __ bind(unwind_initial_activation); | |
1888 | |
1889 // RETURN TO CALL_STUB/C1/C2 code (result if any in I0..I1/(F0/..F1) | |
1890 // we can return here with an exception that wasn't handled by interpreted code | |
1891 // how does c1/c2 see it on return? | |
1892 | |
1893 // compute resulting sp before/after args popped depending upon calling convention | |
1894 // __ ld_ptr(STATE(_saved_sp), Gtmp1); | |
1895 // | |
1896 // POP FRAME HERE ================================== | |
1897 __ restore(FP, G0, SP); | |
1898 __ retl(); | |
1899 __ delayed()->mov(I5_savedSP->after_restore(), SP); | |
1900 | |
1901 // OSR request, unwind the current frame and transfer to the OSR entry | |
1902 // and enter OSR nmethod | |
1903 | |
1904 __ bind(do_OSR); | |
1905 Label remove_initial_frame; | |
1906 __ ld_ptr(STATE(_prev_link), L1_scratch); | |
1907 __ ld_ptr(STATE(_result._osr._osr_buf), G1_scratch); | |
1908 | |
1909 // We are going to pop this frame. Is there another interpreter frame underneath | |
1910 // it or is it callstub/compiled? | |
1911 | |
1912 __ tst(L1_scratch); | |
1913 __ brx(Assembler::zero, false, Assembler::pt, remove_initial_frame); | |
1914 __ delayed()->ld_ptr(STATE(_result._osr._osr_entry), G3_scratch); | |
1915 | |
1916 // Frame underneath is an interpreter frame simply unwind | |
1917 // POP FRAME HERE ================================== | |
1918 __ restore(FP, G0, SP); // unwind interpreter state frame | |
1919 __ mov(I5_savedSP->after_restore(), SP); | |
1920 | |
1921 // Since we are now calling native need to change our "return address" from the | |
1922 // dummy RecursiveInterpreterActivation to a return from native | |
1923 | |
1924 __ set((intptr_t)return_from_native_method - 8, O7); | |
1925 | |
1926 __ jmpl(G3_scratch, G0, G0); | |
1927 __ delayed()->mov(G1_scratch, O0); | |
1928 | |
1929 __ bind(remove_initial_frame); | |
1930 | |
1931 // POP FRAME HERE ================================== | |
1932 __ restore(FP, G0, SP); | |
1933 __ mov(I5_savedSP->after_restore(), SP); | |
1934 __ jmpl(G3_scratch, G0, G0); | |
1935 __ delayed()->mov(G1_scratch, O0); | |
1936 | |
1937 // Call a new method. All we do is (temporarily) trim the expression stack | |
1938 // push a return address to bring us back to here and leap to the new entry. | |
1939 // At this point we have a topmost frame that was allocated by the frame manager | |
1940 // which contains the current method interpreted state. We trim this frame | |
1941 // of excess java expression stack entries and then recurse. | |
1942 | |
1943 __ bind(call_method); | |
1944 | |
1945 // stack points to next free location and not top element on expression stack | |
1946 // method expects sp to be pointing to topmost element | |
1947 | |
1948 __ ld_ptr(STATE(_thread), G2_thread); | |
1949 __ ld_ptr(STATE(_result._to_call._callee), G5_method); | |
1950 | |
1951 | |
1952 // SP already takes in to account the 2 extra words we use for slop | |
1953 // when we call a "static long no_params()" method. So if | |
1954 // we trim back sp by the amount of unused java expression stack | |
1955 // there will be automagically the 2 extra words we need. | |
1956 // We also have to worry about keeping SP aligned. | |
1957 | |
1958 __ ld_ptr(STATE(_stack), Gargs); | |
1959 __ ld_ptr(STATE(_stack_limit), L1_scratch); | |
1960 | |
1961 // compute the unused java stack size | |
1962 __ sub(Gargs, L1_scratch, L2_scratch); // compute unused space | |
1963 | |
123 | 1964 // Round down the unused space to that stack is always 16-byte aligned |
1965 // by making the unused space a multiple of the size of two longs. | |
0 | 1966 |
123 | 1967 __ and3(L2_scratch, -2*BytesPerLong, L2_scratch); |
0 | 1968 |
1969 // Now trim the stack | |
1970 __ add(SP, L2_scratch, SP); | |
1971 | |
1972 | |
1973 // Now point to the final argument (account for prepush) | |
1974 __ add(Gargs, wordSize, Gargs); | |
1975 #ifdef ASSERT | |
1976 // Make sure we have space for the window | |
1977 __ sub(Gargs, SP, L1_scratch); | |
1978 __ cmp(L1_scratch, 16*wordSize); | |
1979 { | |
1980 Label skip; | |
1981 __ brx(Assembler::greaterEqual, false, Assembler::pt, skip); | |
1982 __ delayed()->nop(); | |
1983 __ stop("killed stack"); | |
1984 __ bind(skip); | |
1985 } | |
1986 #endif // ASSERT | |
1987 | |
1988 // Create a new frame where we can store values that make it look like the interpreter | |
1989 // really recursed. | |
1990 | |
1991 // prepare to recurse or call specialized entry | |
1992 | |
1993 // First link the registers we need | |
1994 | |
1995 // make the pc look good in debugger | |
1996 __ set(CAST_FROM_FN_PTR(intptr_t, RecursiveInterpreterActivation), O7); | |
1997 // argument too | |
1998 __ mov(Lstate, I0); | |
1999 | |
2000 // Record our sending SP | |
2001 __ mov(SP, O5_savedSP); | |
2002 | |
2003 __ ld_ptr(STATE(_result._to_call._callee_entry_point), L2_scratch); | |
2004 __ set((intptr_t) entry_point, L1_scratch); | |
2005 __ cmp(L1_scratch, L2_scratch); | |
2006 __ brx(Assembler::equal, false, Assembler::pt, re_dispatch); | |
2007 __ delayed()->mov(Lstate, prevState); // link activations | |
2008 | |
2009 // method uses specialized entry, push a return so we look like call stub setup | |
2010 // this path will handle fact that result is returned in registers and not | |
2011 // on the java stack. | |
2012 | |
2013 __ set((intptr_t)return_from_native_method - 8, O7); | |
2014 __ jmpl(L2_scratch, G0, G0); // Do specialized entry | |
2015 __ delayed()->nop(); | |
2016 | |
2017 // | |
2018 // Bad Message from interpreter | |
2019 // | |
2020 __ bind(bad_msg); | |
2021 __ stop("Bad message from interpreter"); | |
2022 | |
2023 // Interpreted method "returned" with an exception pass it on... | |
2024 // Pass result, unwind activation and continue/return to interpreter/call_stub | |
2025 // We handle result (if any) differently based on return to interpreter or call_stub | |
2026 | |
2027 __ bind(throw_exception); | |
2028 __ ld_ptr(STATE(_prev_link), L1_scratch); | |
2029 __ tst(L1_scratch); | |
2030 __ brx(Assembler::zero, false, Assembler::pt, unwind_and_forward); | |
2031 __ delayed()->nop(); | |
2032 | |
3839 | 2033 __ ld_ptr(STATE(_locals), O1); // get result of popping callee's args |
2034 __ ba(unwind_recursive_activation); | |
0 | 2035 __ delayed()->nop(); |
2036 | |
2037 interpreter_frame_manager = entry_point; | |
2038 return entry_point; | |
2039 } | |
2040 | |
2041 InterpreterGenerator::InterpreterGenerator(StubQueue* code) | |
2042 : CppInterpreterGenerator(code) { | |
2043 generate_all(); // down here so it can be "virtual" | |
2044 } | |
2045 | |
2046 | |
2047 static int size_activation_helper(int callee_extra_locals, int max_stack, int monitor_size) { | |
2048 | |
2049 // Figure out the size of an interpreter frame (in words) given that we have a fully allocated | |
2050 // expression stack, the callee will have callee_extra_locals (so we can account for | |
2051 // frame extension) and monitor_size for monitors. Basically we need to calculate | |
2052 // this exactly like generate_fixed_frame/generate_compute_interpreter_state. | |
2053 // | |
2054 // | |
2055 // The big complicating thing here is that we must ensure that the stack stays properly | |
2056 // aligned. This would be even uglier if monitor size wasn't modulo what the stack | |
2057 // needs to be aligned for). We are given that the sp (fp) is already aligned by | |
2058 // the caller so we must ensure that it is properly aligned for our callee. | |
2059 // | |
2060 // Ths c++ interpreter always makes sure that we have a enough extra space on the | |
2061 // stack at all times to deal with the "stack long no_params()" method issue. This | |
2062 // is "slop_factor" here. | |
2063 const int slop_factor = 2; | |
2064 | |
2065 const int fixed_size = sizeof(BytecodeInterpreter)/wordSize + // interpreter state object | |
2066 frame::memory_parameter_word_sp_offset; // register save area + param window | |
710 | 2067 const int extra_stack = 0; //6815692//methodOopDesc::extra_stack_entries(); |
0 | 2068 return (round_to(max_stack + |
710 | 2069 extra_stack + |
0 | 2070 slop_factor + |
2071 fixed_size + | |
2072 monitor_size + | |
2073 (callee_extra_locals * Interpreter::stackElementWords()), WordsPerLong)); | |
2074 | |
2075 } | |
2076 | |
2077 int AbstractInterpreter::size_top_interpreter_activation(methodOop method) { | |
2078 | |
2079 // See call_stub code | |
2080 int call_stub_size = round_to(7 + frame::memory_parameter_word_sp_offset, | |
2081 WordsPerLong); // 7 + register save area | |
2082 | |
2083 // Save space for one monitor to get into the interpreted method in case | |
2084 // the method is synchronized | |
2085 int monitor_size = method->is_synchronized() ? | |
2086 1*frame::interpreter_frame_monitor_size() : 0; | |
2087 return size_activation_helper(method->max_locals(), method->max_stack(), | |
2088 monitor_size) + call_stub_size; | |
2089 } | |
2090 | |
2091 void BytecodeInterpreter::layout_interpreterState(interpreterState to_fill, | |
2092 frame* caller, | |
2093 frame* current, | |
2094 methodOop method, | |
2095 intptr_t* locals, | |
2096 intptr_t* stack, | |
2097 intptr_t* stack_base, | |
2098 intptr_t* monitor_base, | |
2099 intptr_t* frame_bottom, | |
2100 bool is_top_frame | |
2101 ) | |
2102 { | |
2103 // What about any vtable? | |
2104 // | |
2105 to_fill->_thread = JavaThread::current(); | |
2106 // This gets filled in later but make it something recognizable for now | |
2107 to_fill->_bcp = method->code_base(); | |
2108 to_fill->_locals = locals; | |
2109 to_fill->_constants = method->constants()->cache(); | |
2110 to_fill->_method = method; | |
2111 to_fill->_mdx = NULL; | |
2112 to_fill->_stack = stack; | |
2113 if (is_top_frame && JavaThread::current()->popframe_forcing_deopt_reexecution() ) { | |
2114 to_fill->_msg = deopt_resume2; | |
2115 } else { | |
2116 to_fill->_msg = method_resume; | |
2117 } | |
2118 to_fill->_result._to_call._bcp_advance = 0; | |
2119 to_fill->_result._to_call._callee_entry_point = NULL; // doesn't matter to anyone | |
2120 to_fill->_result._to_call._callee = NULL; // doesn't matter to anyone | |
2121 to_fill->_prev_link = NULL; | |
2122 | |
2123 // Fill in the registers for the frame | |
2124 | |
2125 // Need to install _sender_sp. Actually not too hard in C++! | |
2126 // When the skeletal frames are layed out we fill in a value | |
2127 // for _sender_sp. That value is only correct for the oldest | |
2128 // skeletal frame constructed (because there is only a single | |
2129 // entry for "caller_adjustment". While the skeletal frames | |
2130 // exist that is good enough. We correct that calculation | |
2131 // here and get all the frames correct. | |
2132 | |
2133 // to_fill->_sender_sp = locals - (method->size_of_parameters() - 1); | |
2134 | |
2135 *current->register_addr(Lstate) = (intptr_t) to_fill; | |
2136 // skeletal already places a useful value here and this doesn't account | |
2137 // for alignment so don't bother. | |
2138 // *current->register_addr(I5_savedSP) = (intptr_t) locals - (method->size_of_parameters() - 1); | |
2139 | |
2140 if (caller->is_interpreted_frame()) { | |
2141 interpreterState prev = caller->get_interpreterState(); | |
2142 to_fill->_prev_link = prev; | |
2143 // Make the prev callee look proper | |
2144 prev->_result._to_call._callee = method; | |
2145 if (*prev->_bcp == Bytecodes::_invokeinterface) { | |
2146 prev->_result._to_call._bcp_advance = 5; | |
2147 } else { | |
2148 prev->_result._to_call._bcp_advance = 3; | |
2149 } | |
2150 } | |
2151 to_fill->_oop_temp = NULL; | |
2152 to_fill->_stack_base = stack_base; | |
2153 // Need +1 here because stack_base points to the word just above the first expr stack entry | |
2154 // and stack_limit is supposed to point to the word just below the last expr stack entry. | |
2155 // See generate_compute_interpreter_state. | |
710 | 2156 int extra_stack = 0; //6815692//methodOopDesc::extra_stack_entries(); |
2157 to_fill->_stack_limit = stack_base - (method->max_stack() + 1 + extra_stack); | |
0 | 2158 to_fill->_monitor_base = (BasicObjectLock*) monitor_base; |
2159 | |
2160 // sparc specific | |
2161 to_fill->_frame_bottom = frame_bottom; | |
2162 to_fill->_self_link = to_fill; | |
2163 #ifdef ASSERT | |
2164 to_fill->_native_fresult = 123456.789; | |
2165 to_fill->_native_lresult = CONST64(0xdeadcafedeafcafe); | |
2166 #endif | |
2167 } | |
2168 | |
2169 void BytecodeInterpreter::pd_layout_interpreterState(interpreterState istate, address last_Java_pc, intptr_t* last_Java_fp) { | |
2170 istate->_last_Java_pc = (intptr_t*) last_Java_pc; | |
2171 } | |
2172 | |
2173 | |
2174 int AbstractInterpreter::layout_activation(methodOop method, | |
2175 int tempcount, // Number of slots on java expression stack in use | |
2176 int popframe_extra_args, | |
2177 int moncount, // Number of active monitors | |
3369
3d2ab563047a
7043461: VM crashes in void LinkResolver::runtime_resolve_virtual_method
never
parents:
3252
diff
changeset
|
2178 int caller_actual_parameters, |
0 | 2179 int callee_param_size, |
2180 int callee_locals_size, | |
2181 frame* caller, | |
2182 frame* interpreter_frame, | |
2183 bool is_top_frame) { | |
2184 | |
2185 assert(popframe_extra_args == 0, "NEED TO FIX"); | |
2186 // NOTE this code must exactly mimic what InterpreterGenerator::generate_compute_interpreter_state() | |
2187 // does as far as allocating an interpreter frame. | |
2188 // If interpreter_frame!=NULL, set up the method, locals, and monitors. | |
2189 // The frame interpreter_frame, if not NULL, is guaranteed to be the right size, | |
2190 // as determined by a previous call to this method. | |
2191 // It is also guaranteed to be walkable even though it is in a skeletal state | |
2192 // NOTE: return size is in words not bytes | |
2193 // NOTE: tempcount is the current size of the java expression stack. For top most | |
2194 // frames we will allocate a full sized expression stack and not the curback | |
2195 // version that non-top frames have. | |
2196 | |
2197 // Calculate the amount our frame will be adjust by the callee. For top frame | |
2198 // this is zero. | |
2199 | |
2200 // NOTE: ia64 seems to do this wrong (or at least backwards) in that it | |
2201 // calculates the extra locals based on itself. Not what the callee does | |
2202 // to it. So it ignores last_frame_adjust value. Seems suspicious as far | |
2203 // as getting sender_sp correct. | |
2204 | |
2205 int extra_locals_size = callee_locals_size - callee_param_size; | |
2206 int monitor_size = (sizeof(BasicObjectLock) * moncount) / wordSize; | |
2207 int full_frame_words = size_activation_helper(extra_locals_size, method->max_stack(), monitor_size); | |
2208 int short_frame_words = size_activation_helper(extra_locals_size, method->max_stack(), monitor_size); | |
2209 int frame_words = is_top_frame ? full_frame_words : short_frame_words; | |
2210 | |
2211 | |
2212 /* | |
2213 if we actually have a frame to layout we must now fill in all the pieces. This means both | |
2214 the interpreterState and the registers. | |
2215 */ | |
2216 if (interpreter_frame != NULL) { | |
2217 | |
2218 // MUCHO HACK | |
2219 | |
2220 intptr_t* frame_bottom = interpreter_frame->sp() - (full_frame_words - frame_words); | |
123 | 2221 // 'interpreter_frame->sp()' is unbiased while 'frame_bottom' must be a biased value in 64bit mode. |
2222 assert(((intptr_t)frame_bottom & 0xf) == 0, "SP biased in layout_activation"); | |
2223 frame_bottom = (intptr_t*)((intptr_t)frame_bottom - STACK_BIAS); | |
0 | 2224 |
2225 /* Now fillin the interpreterState object */ | |
2226 | |
2227 interpreterState cur_state = (interpreterState) ((intptr_t)interpreter_frame->fp() - sizeof(BytecodeInterpreter)); | |
2228 | |
2229 | |
2230 intptr_t* locals; | |
2231 | |
2232 // Calculate the postion of locals[0]. This is painful because of | |
2233 // stack alignment (same as ia64). The problem is that we can | |
2234 // not compute the location of locals from fp(). fp() will account | |
2235 // for the extra locals but it also accounts for aligning the stack | |
2236 // and we can't determine if the locals[0] was misaligned but max_locals | |
2237 // was enough to have the | |
2238 // calculate postion of locals. fp already accounts for extra locals. | |
2239 // +2 for the static long no_params() issue. | |
2240 | |
2241 if (caller->is_interpreted_frame()) { | |
2242 // locals must agree with the caller because it will be used to set the | |
2243 // caller's tos when we return. | |
2244 interpreterState prev = caller->get_interpreterState(); | |
2245 // stack() is prepushed. | |
2246 locals = prev->stack() + method->size_of_parameters(); | |
2247 } else { | |
2248 // Lay out locals block in the caller adjacent to the register window save area. | |
2249 // | |
2250 // Compiled frames do not allocate a varargs area which is why this if | |
2251 // statement is needed. | |
2252 // | |
2253 intptr_t* fp = interpreter_frame->fp(); | |
2254 int local_words = method->max_locals() * Interpreter::stackElementWords(); | |
2255 | |
2256 if (caller->is_compiled_frame()) { | |
2257 locals = fp + frame::register_save_words + local_words - 1; | |
2258 } else { | |
2259 locals = fp + frame::memory_parameter_word_sp_offset + local_words - 1; | |
2260 } | |
2261 | |
2262 } | |
2263 // END MUCHO HACK | |
2264 | |
2265 intptr_t* monitor_base = (intptr_t*) cur_state; | |
2266 intptr_t* stack_base = monitor_base - monitor_size; | |
2267 /* +1 because stack is always prepushed */ | |
2268 intptr_t* stack = stack_base - (tempcount + 1); | |
2269 | |
2270 | |
2271 BytecodeInterpreter::layout_interpreterState(cur_state, | |
2272 caller, | |
2273 interpreter_frame, | |
2274 method, | |
2275 locals, | |
2276 stack, | |
2277 stack_base, | |
2278 monitor_base, | |
2279 frame_bottom, | |
2280 is_top_frame); | |
2281 | |
2282 BytecodeInterpreter::pd_layout_interpreterState(cur_state, interpreter_return_address, interpreter_frame->fp()); | |
2283 | |
2284 } | |
2285 return frame_words; | |
2286 } | |
2287 | |
2288 #endif // CC_INTERP |