28 #include "code/codeCache.hpp"
29 #include "code/debugInfoRec.hpp"
30 #include "code/nmethod.hpp"
31 #include "code/pcDesc.hpp"
32 #include "code/scopeDesc.hpp"
33 #include "interpreter/bytecode.hpp"
34 #include "interpreter/interpreter.hpp"
35 #include "interpreter/oopMapCache.hpp"
36 #include "memory/allocation.inline.hpp"
37 #include "memory/oopFactory.hpp"
38 #include "memory/resourceArea.hpp"
39 #include "oops/method.hpp"
40 #include "oops/objArrayOop.inline.hpp"
41 #include "oops/oop.inline.hpp"
42 #include "oops/fieldStreams.hpp"
43 #include "oops/typeArrayOop.inline.hpp"
44 #include "oops/verifyOopClosure.hpp"
45 #include "prims/jvmtiThreadState.hpp"
46 #include "runtime/biasedLocking.hpp"
47 #include "runtime/compilationPolicy.hpp"
48 #include "runtime/deoptimization.hpp"
49 #include "runtime/frame.inline.hpp"
50 #include "runtime/interfaceSupport.inline.hpp"
51 #include "runtime/safepointVerifiers.hpp"
52 #include "runtime/sharedRuntime.hpp"
53 #include "runtime/signature.hpp"
54 #include "runtime/stubRoutines.hpp"
55 #include "runtime/thread.hpp"
56 #include "runtime/threadSMR.hpp"
57 #include "runtime/vframe.hpp"
58 #include "runtime/vframeArray.hpp"
59 #include "runtime/vframe_hp.hpp"
60 #include "utilities/events.hpp"
61 #include "utilities/preserveException.hpp"
62 #include "utilities/xmlstream.hpp"
63
64 #if INCLUDE_JVMCI
65 #include "jvmci/jvmciRuntime.hpp"
66 #include "jvmci/jvmciJavaClasses.hpp"
67 #endif
399 frame deopt_sender = stub_frame.sender(&dummy_map); // First is the deoptee frame
400 deopt_sender = deopt_sender.sender(&dummy_map); // Now deoptee caller
401
402 // It's possible that the number of parameters at the call site is
403 // different than number of arguments in the callee when method
404 // handles are used. If the caller is interpreted get the real
405 // value so that the proper amount of space can be added to it's
406 // frame.
407 bool caller_was_method_handle = false;
408 if (deopt_sender.is_interpreted_frame()) {
409 methodHandle method = deopt_sender.interpreter_frame_method();
410 Bytecode_invoke cur = Bytecode_invoke_check(method, deopt_sender.interpreter_frame_bci());
411 if (cur.is_invokedynamic() || cur.is_invokehandle()) {
412 // Method handle invokes may involve fairly arbitrary chains of
413 // calls so it's impossible to know how much actual space the
414 // caller has for locals.
415 caller_was_method_handle = true;
416 }
417 }
418
419 //
420 // frame_sizes/frame_pcs[0] oldest frame (int or c2i)
421 // frame_sizes/frame_pcs[1] next oldest frame (int)
422 // frame_sizes/frame_pcs[n] youngest frame (int)
423 //
424 // Now a pc in frame_pcs is actually the return address to the frame's caller (a frame
425 // owns the space for the return address to it's caller). Confusing ain't it.
426 //
427 // The vframe array can address vframes with indices running from
428 // 0.._frames-1. Index 0 is the youngest frame and _frame - 1 is the oldest (root) frame.
429 // When we create the skeletal frames we need the oldest frame to be in the zero slot
430 // in the frame_sizes/frame_pcs so the assembly code can do a trivial walk.
431 // so things look a little strange in this loop.
432 //
433 int callee_parameters = 0;
434 int callee_locals = 0;
435 for (int index = 0; index < array->frames(); index++ ) {
436 // frame[number_of_frames - 1 ] = on_stack_size(youngest)
437 // frame[number_of_frames - 2 ] = on_stack_size(sender(youngest))
438 // frame[number_of_frames - 3 ] = on_stack_size(sender(sender(youngest)))
457 methodHandle method(thread, array->element(0)->method());
458 Bytecode_invoke invoke = Bytecode_invoke_check(method, array->element(0)->bci());
459 return_type = invoke.is_valid() ? invoke.result_type() : T_ILLEGAL;
460 }
461
462 // Compute information for handling adapters and adjusting the frame size of the caller.
463 int caller_adjustment = 0;
464
465 // Compute the amount the oldest interpreter frame will have to adjust
466 // its caller's stack by. If the caller is a compiled frame then
467 // we pretend that the callee has no parameters so that the
468 // extension counts for the full amount of locals and not just
469 // locals-parms. This is because without a c2i adapter the parm
470 // area as created by the compiled frame will not be usable by
471 // the interpreter. (Depending on the calling convention there
472 // may not even be enough space).
473
474 // QQQ I'd rather see this pushed down into last_frame_adjust
475 // and have it take the sender (aka caller).
476
477 if (deopt_sender.is_compiled_frame() || caller_was_method_handle) {
478 caller_adjustment = last_frame_adjust(0, callee_locals);
479 } else if (callee_locals > callee_parameters) {
480 // The caller frame may need extending to accommodate
481 // non-parameter locals of the first unpacked interpreted frame.
482 // Compute that adjustment.
483 caller_adjustment = last_frame_adjust(callee_parameters, callee_locals);
484 }
485
486 // If the sender is deoptimized the we must retrieve the address of the handler
487 // since the frame will "magically" show the original pc before the deopt
488 // and we'd undo the deopt.
489
490 frame_pcs[0] = deopt_sender.raw_pc();
491
492 assert(CodeCache::find_blob_unsafe(frame_pcs[0]) != NULL, "bad pc");
493
494 #if INCLUDE_JVMCI
495 if (exceptionObject() != NULL) {
496 thread->set_exception_oop(exceptionObject());
497 exec_mode = Unpack_exception;
498 }
499 #endif
500
501 if (thread->frames_to_pop_failed_realloc() > 0 && exec_mode != Unpack_uncommon_trap) {
502 assert(thread->has_pending_exception(), "should have thrown OOME");
503 thread->set_exception_oop(thread->pending_exception());
504 thread->clear_pending_exception();
505 exec_mode = Unpack_exception;
506 }
507
508 #if INCLUDE_JVMCI
509 if (thread->frames_to_pop_failed_realloc() > 0) {
510 thread->set_pending_monitorenter(false);
|
28 #include "code/codeCache.hpp"
29 #include "code/debugInfoRec.hpp"
30 #include "code/nmethod.hpp"
31 #include "code/pcDesc.hpp"
32 #include "code/scopeDesc.hpp"
33 #include "interpreter/bytecode.hpp"
34 #include "interpreter/interpreter.hpp"
35 #include "interpreter/oopMapCache.hpp"
36 #include "memory/allocation.inline.hpp"
37 #include "memory/oopFactory.hpp"
38 #include "memory/resourceArea.hpp"
39 #include "oops/method.hpp"
40 #include "oops/objArrayOop.inline.hpp"
41 #include "oops/oop.inline.hpp"
42 #include "oops/fieldStreams.hpp"
43 #include "oops/typeArrayOop.inline.hpp"
44 #include "oops/verifyOopClosure.hpp"
45 #include "prims/jvmtiThreadState.hpp"
46 #include "runtime/biasedLocking.hpp"
47 #include "runtime/compilationPolicy.hpp"
48 #include "runtime/continuation.hpp"
49 #include "runtime/deoptimization.hpp"
50 #include "runtime/frame.inline.hpp"
51 #include "runtime/interfaceSupport.inline.hpp"
52 #include "runtime/safepointVerifiers.hpp"
53 #include "runtime/sharedRuntime.hpp"
54 #include "runtime/signature.hpp"
55 #include "runtime/stubRoutines.hpp"
56 #include "runtime/thread.hpp"
57 #include "runtime/threadSMR.hpp"
58 #include "runtime/vframe.hpp"
59 #include "runtime/vframeArray.hpp"
60 #include "runtime/vframe_hp.hpp"
61 #include "utilities/events.hpp"
62 #include "utilities/preserveException.hpp"
63 #include "utilities/xmlstream.hpp"
64
65 #if INCLUDE_JVMCI
66 #include "jvmci/jvmciRuntime.hpp"
67 #include "jvmci/jvmciJavaClasses.hpp"
68 #endif
400 frame deopt_sender = stub_frame.sender(&dummy_map); // First is the deoptee frame
401 deopt_sender = deopt_sender.sender(&dummy_map); // Now deoptee caller
402
403 // It's possible that the number of parameters at the call site is
404 // different than number of arguments in the callee when method
405 // handles are used. If the caller is interpreted get the real
406 // value so that the proper amount of space can be added to it's
407 // frame.
408 bool caller_was_method_handle = false;
409 if (deopt_sender.is_interpreted_frame()) {
410 methodHandle method = deopt_sender.interpreter_frame_method();
411 Bytecode_invoke cur = Bytecode_invoke_check(method, deopt_sender.interpreter_frame_bci());
412 if (cur.is_invokedynamic() || cur.is_invokehandle()) {
413 // Method handle invokes may involve fairly arbitrary chains of
414 // calls so it's impossible to know how much actual space the
415 // caller has for locals.
416 caller_was_method_handle = true;
417 }
418 }
419
420 // If the caller is a continuation entry and the callee has a return barrier
421 // then we cannot use the parameters in the caller
422 bool caller_was_continuation_entry = Continuation::is_cont_bottom_frame(deopt_sender);
423
424 //
425 // frame_sizes/frame_pcs[0] oldest frame (int or c2i)
426 // frame_sizes/frame_pcs[1] next oldest frame (int)
427 // frame_sizes/frame_pcs[n] youngest frame (int)
428 //
429 // Now a pc in frame_pcs is actually the return address to the frame's caller (a frame
430 // owns the space for the return address to it's caller). Confusing ain't it.
431 //
432 // The vframe array can address vframes with indices running from
433 // 0.._frames-1. Index 0 is the youngest frame and _frame - 1 is the oldest (root) frame.
434 // When we create the skeletal frames we need the oldest frame to be in the zero slot
435 // in the frame_sizes/frame_pcs so the assembly code can do a trivial walk.
436 // so things look a little strange in this loop.
437 //
438 int callee_parameters = 0;
439 int callee_locals = 0;
440 for (int index = 0; index < array->frames(); index++ ) {
441 // frame[number_of_frames - 1 ] = on_stack_size(youngest)
442 // frame[number_of_frames - 2 ] = on_stack_size(sender(youngest))
443 // frame[number_of_frames - 3 ] = on_stack_size(sender(sender(youngest)))
462 methodHandle method(thread, array->element(0)->method());
463 Bytecode_invoke invoke = Bytecode_invoke_check(method, array->element(0)->bci());
464 return_type = invoke.is_valid() ? invoke.result_type() : T_ILLEGAL;
465 }
466
467 // Compute information for handling adapters and adjusting the frame size of the caller.
468 int caller_adjustment = 0;
469
470 // Compute the amount the oldest interpreter frame will have to adjust
471 // its caller's stack by. If the caller is a compiled frame then
472 // we pretend that the callee has no parameters so that the
473 // extension counts for the full amount of locals and not just
474 // locals-parms. This is because without a c2i adapter the parm
475 // area as created by the compiled frame will not be usable by
476 // the interpreter. (Depending on the calling convention there
477 // may not even be enough space).
478
479 // QQQ I'd rather see this pushed down into last_frame_adjust
480 // and have it take the sender (aka caller).
481
482 // TODO LOOM: consider *always* adjusting instead of the conditionals below. What's the harm?
483 caller_adjustment = last_frame_adjust(0, callee_locals);
484 // if (deopt_sender.is_compiled_frame() || caller_was_method_handle || caller_was_continuation_entry) {
485 // caller_adjustment = last_frame_adjust(0, callee_locals);
486 // } else if (callee_locals > callee_parameters) {
487 // // The caller frame may need extending to accommodate
488 // // non-parameter locals of the first unpacked interpreted frame.
489 // // Compute that adjustment.
490 // caller_adjustment = last_frame_adjust(callee_parameters, callee_locals);
491 // }
492
493 // If the sender is deoptimized the we must retrieve the address of the handler
494 // since the frame will "magically" show the original pc before the deopt
495 // and we'd undo the deopt.
496
497 frame_pcs[0] = Continuation::is_cont_bottom_frame(deoptee) ? StubRoutines::cont_returnBarrier() : deopt_sender.raw_pc();
498 // if (Continuation::is_cont_bottom_frame(deoptee)) tty->print_cr("WOWEE Continuation::is_cont_bottom_frame(deoptee)");
499
500 assert(CodeCache::find_blob_unsafe(frame_pcs[0]) != NULL, "bad pc");
501
502 #if INCLUDE_JVMCI
503 if (exceptionObject() != NULL) {
504 thread->set_exception_oop(exceptionObject());
505 exec_mode = Unpack_exception;
506 }
507 #endif
508
509 if (thread->frames_to_pop_failed_realloc() > 0 && exec_mode != Unpack_uncommon_trap) {
510 assert(thread->has_pending_exception(), "should have thrown OOME");
511 thread->set_exception_oop(thread->pending_exception());
512 thread->clear_pending_exception();
513 exec_mode = Unpack_exception;
514 }
515
516 #if INCLUDE_JVMCI
517 if (thread->frames_to_pop_failed_realloc() > 0) {
518 thread->set_pending_monitorenter(false);
|