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