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