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