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