src/share/vm/interpreter/bytecodeInterpreter.cpp

Print this page
rev 5189 : 8024469: PPC64 (part 202): cppInterpreter: support for OSR.
Summary: Call OSR migration with last java frame.


 328 // Backedge counting is kind of strange. The asm interpreter will increment
 329 // the backedge counter as a separate counter but it does it's comparisons
 330 // to the sum (scaled) of invocation counter and backedge count to make
 331 // a decision. Seems kind of odd to sum them together like that
 332 
 333 // skip is delta from current bcp/bci for target, branch_pc is pre-branch bcp
 334 
 335 
 336 #define DO_BACKEDGE_CHECKS(skip, branch_pc)                                                         \
 337     if ((skip) <= 0) {                                                                              \
 338       MethodCounters* mcs;                                                                          \
 339       GET_METHOD_COUNTERS(mcs);                                                                     \
 340       if (UseLoopCounter) {                                                                         \
 341         bool do_OSR = UseOnStackReplacement;                                                        \
 342         mcs->backedge_counter()->increment();                                                       \
 343         if (do_OSR) do_OSR = mcs->backedge_counter()->reached_InvocationLimit();                    \
 344         if (do_OSR) {                                                                               \
 345           nmethod*  osr_nmethod;                                                                    \
 346           OSR_REQUEST(osr_nmethod, branch_pc);                                                      \
 347           if (osr_nmethod != NULL && osr_nmethod->osr_entry_bci() != InvalidOSREntryBci) {          \
 348             intptr_t* buf = SharedRuntime::OSR_migration_begin(THREAD);                             \


 349             istate->set_msg(do_osr);                                                                \
 350             istate->set_osr_buf((address)buf);                                                      \
 351             istate->set_osr_entry(osr_nmethod->osr_entry());                                        \
 352             return;                                                                                 \
 353           }                                                                                         \
 354         }                                                                                           \
 355       }  /* UseCompiler ... */                                                                      \
 356       mcs->invocation_counter()->increment();                                                       \
 357       SAFEPOINT;                                                                                    \
 358     }
 359 
 360 /*
 361  * For those opcodes that need to have a GC point on a backwards branch
 362  */
 363 
 364 /*
 365  * Macros for caching and flushing the interpreter state. Some local
 366  * variables need to be flushed out to the frame before we do certain
 367  * things (like pushing frames or becomming gc safe) and some need to
 368  * be recached later (like after popping a frame). We could use one


 401 #define VMdoubleConstZero() 0.0
 402 #define VMdoubleConstOne() 1.0
 403 #define VMlongConstZero() (max_jlong-max_jlong)
 404 #define VMlongConstOne() ((max_jlong-max_jlong)+1)
 405 
 406 /*
 407  * Alignment
 408  */
 409 #define VMalignWordUp(val)          (((uintptr_t)(val) + 3) & ~3)
 410 
 411 // Decache the interpreter state that interpreter modifies directly (i.e. GC is indirect mod)
 412 #define DECACHE_STATE() DECACHE_PC(); DECACHE_TOS();
 413 
 414 // Reload interpreter state after calling the VM or a possible GC
 415 #define CACHE_STATE()   \
 416         CACHE_TOS();    \
 417         CACHE_PC();     \
 418         CACHE_CP();     \
 419         CACHE_LOCALS();
 420 
 421 // Call the VM don't check for pending exceptions
 422 #define CALL_VM_NOCHECK(func)                                      \
 423         DECACHE_STATE();                                           \
 424         SET_LAST_JAVA_FRAME();                                     \
 425         func;                                                      \
 426         RESET_LAST_JAVA_FRAME();                                   \
 427         CACHE_STATE();                                             \




 428         if (THREAD->pop_frame_pending() &&                         \
 429             !THREAD->pop_frame_in_process()) {                     \
 430           goto handle_Pop_Frame;                                   \
 431         }                                                          \
 432         if (THREAD->jvmti_thread_state() &&                        \
 433             THREAD->jvmti_thread_state()->is_earlyret_pending()) { \
 434           goto handle_Early_Return;                                \
 435         }
 436 
 437 // Call the VM and check for pending exceptions
 438 #define CALL_VM(func, label) {                                     \
 439           CALL_VM_NOCHECK(func);                                   \
 440           if (THREAD->has_pending_exception()) goto label;         \
 441         }
 442 
 443 /*
 444  * BytecodeInterpreter::run(interpreterState istate)
 445  * BytecodeInterpreter::runWithChecks(interpreterState istate)
 446  *
 447  * The real deal. This is where byte codes actually get interpreted.


2685     assert(except_oop(), "No exception to process");
2686     intptr_t continuation_bci;
2687     // expression stack is emptied
2688     topOfStack = istate->stack_base() - Interpreter::stackElementWords;
2689     CALL_VM(continuation_bci = (intptr_t)InterpreterRuntime::exception_handler_for_exception(THREAD, except_oop()),
2690             handle_exception);
2691 
2692     except_oop = THREAD->vm_result();
2693     THREAD->set_vm_result(NULL);
2694     if (continuation_bci >= 0) {
2695       // Place exception on top of stack
2696       SET_STACK_OBJECT(except_oop(), 0);
2697       MORE_STACK(1);
2698       pc = METHOD->code_base() + continuation_bci;
2699       if (TraceExceptions) {
2700         ttyLocker ttyl;
2701         ResourceMark rm;
2702         tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")", except_oop->print_value_string(), except_oop());
2703         tty->print_cr(" thrown in interpreter method <%s>", METHOD->print_value_string());
2704         tty->print_cr(" at bci %d, continuing at %d for thread " INTPTR_FORMAT,
2705                       pc - (intptr_t)METHOD->code_base(),
2706                       continuation_bci, THREAD);
2707       }
2708       // for AbortVMOnException flag
2709       NOT_PRODUCT(Exceptions::debug_check_abort(except_oop));
2710       goto run;
2711     }
2712     if (TraceExceptions) {
2713       ttyLocker ttyl;
2714       ResourceMark rm;
2715       tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")", except_oop->print_value_string(), except_oop());
2716       tty->print_cr(" thrown in interpreter method <%s>", METHOD->print_value_string());
2717       tty->print_cr(" at bci %d, unwinding for thread " INTPTR_FORMAT,
2718                     pc  - (intptr_t) METHOD->code_base(),
2719                     THREAD);
2720     }
2721     // for AbortVMOnException flag
2722     NOT_PRODUCT(Exceptions::debug_check_abort(except_oop));
2723     // No handler in this activation, unwind and try again
2724     THREAD->set_pending_exception(except_oop(), NULL, 0);
2725     goto handle_return;
2726   }  // handle_exception:
2727 
2728   // Return from an interpreter invocation with the result of the interpretation
2729   // on the top of the Java Stack (or a pending exception)
2730 
2731   handle_Pop_Frame: {
2732 
2733     // We don't really do anything special here except we must be aware
2734     // that we can get here without ever locking the method (if sync).
2735     // Also we skip the notification of the exit.
2736 
2737     istate->set_msg(popping_frame);
2738     // Clear pending so while the pop is in process




 328 // Backedge counting is kind of strange. The asm interpreter will increment
 329 // the backedge counter as a separate counter but it does it's comparisons
 330 // to the sum (scaled) of invocation counter and backedge count to make
 331 // a decision. Seems kind of odd to sum them together like that
 332 
 333 // skip is delta from current bcp/bci for target, branch_pc is pre-branch bcp
 334 
 335 
 336 #define DO_BACKEDGE_CHECKS(skip, branch_pc)                                                         \
 337     if ((skip) <= 0) {                                                                              \
 338       MethodCounters* mcs;                                                                          \
 339       GET_METHOD_COUNTERS(mcs);                                                                     \
 340       if (UseLoopCounter) {                                                                         \
 341         bool do_OSR = UseOnStackReplacement;                                                        \
 342         mcs->backedge_counter()->increment();                                                       \
 343         if (do_OSR) do_OSR = mcs->backedge_counter()->reached_InvocationLimit();                    \
 344         if (do_OSR) {                                                                               \
 345           nmethod*  osr_nmethod;                                                                    \
 346           OSR_REQUEST(osr_nmethod, branch_pc);                                                      \
 347           if (osr_nmethod != NULL && osr_nmethod->osr_entry_bci() != InvalidOSREntryBci) {          \
 348             intptr_t* buf;                                                                          \
 349             /* Call OSR migration with last java frame only, no checks. */                          \
 350             CALL_VM_NAKED_LJF(buf=SharedRuntime::OSR_migration_begin(THREAD));                      \
 351             istate->set_msg(do_osr);                                                                \
 352             istate->set_osr_buf((address)buf);                                                      \
 353             istate->set_osr_entry(osr_nmethod->osr_entry());                                        \
 354             return;                                                                                 \
 355           }                                                                                         \
 356         }                                                                                           \
 357       }  /* UseCompiler ... */                                                                      \
 358       mcs->invocation_counter()->increment();                                                       \
 359       SAFEPOINT;                                                                                    \
 360     }
 361 
 362 /*
 363  * For those opcodes that need to have a GC point on a backwards branch
 364  */
 365 
 366 /*
 367  * Macros for caching and flushing the interpreter state. Some local
 368  * variables need to be flushed out to the frame before we do certain
 369  * things (like pushing frames or becomming gc safe) and some need to
 370  * be recached later (like after popping a frame). We could use one


 403 #define VMdoubleConstZero() 0.0
 404 #define VMdoubleConstOne() 1.0
 405 #define VMlongConstZero() (max_jlong-max_jlong)
 406 #define VMlongConstOne() ((max_jlong-max_jlong)+1)
 407 
 408 /*
 409  * Alignment
 410  */
 411 #define VMalignWordUp(val)          (((uintptr_t)(val) + 3) & ~3)
 412 
 413 // Decache the interpreter state that interpreter modifies directly (i.e. GC is indirect mod)
 414 #define DECACHE_STATE() DECACHE_PC(); DECACHE_TOS();
 415 
 416 // Reload interpreter state after calling the VM or a possible GC
 417 #define CACHE_STATE()   \
 418         CACHE_TOS();    \
 419         CACHE_PC();     \
 420         CACHE_CP();     \
 421         CACHE_LOCALS();
 422 
 423 // Call the VM with last java frame only.
 424 #define CALL_VM_NAKED_LJF(func)                                    \
 425         DECACHE_STATE();                                           \
 426         SET_LAST_JAVA_FRAME();                                     \
 427         func;                                                      \
 428         RESET_LAST_JAVA_FRAME();                                   \
 429         CACHE_STATE();
 430 
 431 // Call the VM. Don't check for pending exceptions.
 432 #define CALL_VM_NOCHECK(func)                                      \
 433         CALL_VM_NAKED_LJF(func)                                    \
 434         if (THREAD->pop_frame_pending() &&                         \
 435             !THREAD->pop_frame_in_process()) {                     \
 436           goto handle_Pop_Frame;                                   \
 437         }                                                          \
 438         if (THREAD->jvmti_thread_state() &&                        \
 439             THREAD->jvmti_thread_state()->is_earlyret_pending()) { \
 440           goto handle_Early_Return;                                \
 441         }
 442 
 443 // Call the VM and check for pending exceptions
 444 #define CALL_VM(func, label) {                                     \
 445           CALL_VM_NOCHECK(func);                                   \
 446           if (THREAD->has_pending_exception()) goto label;         \
 447         }
 448 
 449 /*
 450  * BytecodeInterpreter::run(interpreterState istate)
 451  * BytecodeInterpreter::runWithChecks(interpreterState istate)
 452  *
 453  * The real deal. This is where byte codes actually get interpreted.


2691     assert(except_oop(), "No exception to process");
2692     intptr_t continuation_bci;
2693     // expression stack is emptied
2694     topOfStack = istate->stack_base() - Interpreter::stackElementWords;
2695     CALL_VM(continuation_bci = (intptr_t)InterpreterRuntime::exception_handler_for_exception(THREAD, except_oop()),
2696             handle_exception);
2697 
2698     except_oop = THREAD->vm_result();
2699     THREAD->set_vm_result(NULL);
2700     if (continuation_bci >= 0) {
2701       // Place exception on top of stack
2702       SET_STACK_OBJECT(except_oop(), 0);
2703       MORE_STACK(1);
2704       pc = METHOD->code_base() + continuation_bci;
2705       if (TraceExceptions) {
2706         ttyLocker ttyl;
2707         ResourceMark rm;
2708         tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")", except_oop->print_value_string(), except_oop());
2709         tty->print_cr(" thrown in interpreter method <%s>", METHOD->print_value_string());
2710         tty->print_cr(" at bci %d, continuing at %d for thread " INTPTR_FORMAT,
2711                       istate->bcp() - (intptr_t)METHOD->code_base(),
2712                       continuation_bci, THREAD);
2713       }
2714       // for AbortVMOnException flag
2715       NOT_PRODUCT(Exceptions::debug_check_abort(except_oop));
2716       goto run;
2717     }
2718     if (TraceExceptions) {
2719       ttyLocker ttyl;
2720       ResourceMark rm;
2721       tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")", except_oop->print_value_string(), except_oop());
2722       tty->print_cr(" thrown in interpreter method <%s>", METHOD->print_value_string());
2723       tty->print_cr(" at bci %d, unwinding for thread " INTPTR_FORMAT,
2724                     istate->bcp() - (intptr_t)METHOD->code_base(),
2725                     THREAD);
2726     }
2727     // for AbortVMOnException flag
2728     NOT_PRODUCT(Exceptions::debug_check_abort(except_oop));
2729     // No handler in this activation, unwind and try again
2730     THREAD->set_pending_exception(except_oop(), NULL, 0);
2731     goto handle_return;
2732   }  // handle_exception:
2733 
2734   // Return from an interpreter invocation with the result of the interpretation
2735   // on the top of the Java Stack (or a pending exception)
2736 
2737   handle_Pop_Frame: {
2738 
2739     // We don't really do anything special here except we must be aware
2740     // that we can get here without ever locking the method (if sync).
2741     // Also we skip the notification of the exit.
2742 
2743     istate->set_msg(popping_frame);
2744     // Clear pending so while the pop is in process