1 /*
   2  * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 // no precompiled headers
  26 #include "classfile/vmSymbols.hpp"
  27 #include "gc_interface/collectedHeap.hpp"
  28 #include "interpreter/bytecodeHistogram.hpp"
  29 #include "interpreter/bytecodeInterpreter.hpp"
  30 #include "interpreter/bytecodeInterpreter.inline.hpp"
  31 #include "interpreter/bytecodeInterpreterProfiling.hpp"
  32 #include "interpreter/interpreter.hpp"
  33 #include "interpreter/interpreterRuntime.hpp"
  34 #include "memory/resourceArea.hpp"
  35 #include "oops/methodCounters.hpp"
  36 #include "oops/objArrayKlass.hpp"
  37 #include "oops/oop.inline.hpp"
  38 #include "prims/jvmtiExport.hpp"
  39 #include "prims/jvmtiThreadState.hpp"
  40 #include "runtime/atomic.inline.hpp"
  41 #include "runtime/biasedLocking.hpp"
  42 #include "runtime/frame.inline.hpp"
  43 #include "runtime/handles.inline.hpp"
  44 #include "runtime/interfaceSupport.hpp"
  45 #include "runtime/orderAccess.inline.hpp"
  46 #include "runtime/sharedRuntime.hpp"
  47 #include "runtime/threadCritical.hpp"
  48 #include "utilities/exceptions.hpp"
  49 
  50 // no precompiled headers
  51 #ifdef CC_INTERP
  52 
  53 /*
  54  * USELABELS - If using GCC, then use labels for the opcode dispatching
  55  * rather -then a switch statement. This improves performance because it
  56  * gives us the oportunity to have the instructions that calculate the
  57  * next opcode to jump to be intermixed with the rest of the instructions
  58  * that implement the opcode (see UPDATE_PC_AND_TOS_AND_CONTINUE macro).
  59  */
  60 #undef USELABELS
  61 #ifdef __GNUC__
  62 /*
  63    ASSERT signifies debugging. It is much easier to step thru bytecodes if we
  64    don't use the computed goto approach.
  65 */
  66 #ifndef ASSERT
  67 #define USELABELS
  68 #endif
  69 #endif
  70 
  71 #undef CASE
  72 #ifdef USELABELS
  73 #define CASE(opcode) opc ## opcode
  74 #define DEFAULT opc_default
  75 #else
  76 #define CASE(opcode) case Bytecodes:: opcode
  77 #define DEFAULT default
  78 #endif
  79 
  80 /*
  81  * PREFETCH_OPCCODE - Some compilers do better if you prefetch the next
  82  * opcode before going back to the top of the while loop, rather then having
  83  * the top of the while loop handle it. This provides a better opportunity
  84  * for instruction scheduling. Some compilers just do this prefetch
  85  * automatically. Some actually end up with worse performance if you
  86  * force the prefetch. Solaris gcc seems to do better, but cc does worse.
  87  */
  88 #undef PREFETCH_OPCCODE
  89 #define PREFETCH_OPCCODE
  90 
  91 /*
  92   Interpreter safepoint: it is expected that the interpreter will have no live
  93   handles of its own creation live at an interpreter safepoint. Therefore we
  94   run a HandleMarkCleaner and trash all handles allocated in the call chain
  95   since the JavaCalls::call_helper invocation that initiated the chain.
  96   There really shouldn't be any handles remaining to trash but this is cheap
  97   in relation to a safepoint.
  98 */
  99 #define SAFEPOINT                                                                 \
 100     if ( SafepointSynchronize::is_synchronizing()) {                              \
 101         {                                                                         \
 102           /* zap freed handles rather than GC'ing them */                         \
 103           HandleMarkCleaner __hmc(THREAD);                                        \
 104         }                                                                         \
 105         CALL_VM(SafepointSynchronize::block(THREAD), handle_exception);           \
 106     }
 107 
 108 /*
 109  * VM_JAVA_ERROR - Macro for throwing a java exception from
 110  * the interpreter loop. Should really be a CALL_VM but there
 111  * is no entry point to do the transition to vm so we just
 112  * do it by hand here.
 113  */
 114 #define VM_JAVA_ERROR_NO_JUMP(name, msg, note_a_trap)                             \
 115     DECACHE_STATE();                                                              \
 116     SET_LAST_JAVA_FRAME();                                                        \
 117     {                                                                             \
 118        InterpreterRuntime::note_a_trap(THREAD, istate->method(), BCI());          \
 119        ThreadInVMfromJava trans(THREAD);                                          \
 120        Exceptions::_throw_msg(THREAD, __FILE__, __LINE__, name, msg);             \
 121     }                                                                             \
 122     RESET_LAST_JAVA_FRAME();                                                      \
 123     CACHE_STATE();
 124 
 125 // Normal throw of a java error.
 126 #define VM_JAVA_ERROR(name, msg, note_a_trap)                                     \
 127     VM_JAVA_ERROR_NO_JUMP(name, msg, note_a_trap)                                 \
 128     goto handle_exception;
 129 
 130 #ifdef PRODUCT
 131 #define DO_UPDATE_INSTRUCTION_COUNT(opcode)
 132 #else
 133 #define DO_UPDATE_INSTRUCTION_COUNT(opcode)                                                          \
 134 {                                                                                                    \
 135     BytecodeCounter::_counter_value++;                                                               \
 136     BytecodeHistogram::_counters[(Bytecodes::Code)opcode]++;                                         \
 137     if (StopInterpreterAt && StopInterpreterAt == BytecodeCounter::_counter_value) os::breakpoint(); \
 138     if (TraceBytecodes) {                                                                            \
 139       CALL_VM((void)SharedRuntime::trace_bytecode(THREAD, 0,               \
 140                                    topOfStack[Interpreter::expr_index_at(1)],   \
 141                                    topOfStack[Interpreter::expr_index_at(2)]),  \
 142                                    handle_exception);                      \
 143     }                                                                      \
 144 }
 145 #endif
 146 
 147 #undef DEBUGGER_SINGLE_STEP_NOTIFY
 148 #ifdef VM_JVMTI
 149 /* NOTE: (kbr) This macro must be called AFTER the PC has been
 150    incremented. JvmtiExport::at_single_stepping_point() may cause a
 151    breakpoint opcode to get inserted at the current PC to allow the
 152    debugger to coalesce single-step events.
 153 
 154    As a result if we call at_single_stepping_point() we refetch opcode
 155    to get the current opcode. This will override any other prefetching
 156    that might have occurred.
 157 */
 158 #define DEBUGGER_SINGLE_STEP_NOTIFY()                                            \
 159 {                                                                                \
 160       if (_jvmti_interp_events) {                                                \
 161         if (JvmtiExport::should_post_single_step()) {                            \
 162           DECACHE_STATE();                                                       \
 163           SET_LAST_JAVA_FRAME();                                                 \
 164           ThreadInVMfromJava trans(THREAD);                                      \
 165           JvmtiExport::at_single_stepping_point(THREAD,                          \
 166                                           istate->method(),                      \
 167                                           pc);                                   \
 168           RESET_LAST_JAVA_FRAME();                                               \
 169           CACHE_STATE();                                                         \
 170           if (THREAD->pop_frame_pending() &&                                     \
 171               !THREAD->pop_frame_in_process()) {                                 \
 172             goto handle_Pop_Frame;                                               \
 173           }                                                                      \
 174           if (THREAD->jvmti_thread_state() &&                                    \
 175               THREAD->jvmti_thread_state()->is_earlyret_pending()) {             \
 176             goto handle_Early_Return;                                            \
 177           }                                                                      \
 178           opcode = *pc;                                                          \
 179         }                                                                        \
 180       }                                                                          \
 181 }
 182 #else
 183 #define DEBUGGER_SINGLE_STEP_NOTIFY()
 184 #endif
 185 
 186 /*
 187  * CONTINUE - Macro for executing the next opcode.
 188  */
 189 #undef CONTINUE
 190 #ifdef USELABELS
 191 // Have to do this dispatch this way in C++ because otherwise gcc complains about crossing an
 192 // initialization (which is is the initialization of the table pointer...)
 193 #define DISPATCH(opcode) goto *(void*)dispatch_table[opcode]
 194 #define CONTINUE {                              \
 195         opcode = *pc;                           \
 196         DO_UPDATE_INSTRUCTION_COUNT(opcode);    \
 197         DEBUGGER_SINGLE_STEP_NOTIFY();          \
 198         DISPATCH(opcode);                       \
 199     }
 200 #else
 201 #ifdef PREFETCH_OPCCODE
 202 #define CONTINUE {                              \
 203         opcode = *pc;                           \
 204         DO_UPDATE_INSTRUCTION_COUNT(opcode);    \
 205         DEBUGGER_SINGLE_STEP_NOTIFY();          \
 206         continue;                               \
 207     }
 208 #else
 209 #define CONTINUE {                              \
 210         DO_UPDATE_INSTRUCTION_COUNT(opcode);    \
 211         DEBUGGER_SINGLE_STEP_NOTIFY();          \
 212         continue;                               \
 213     }
 214 #endif
 215 #endif
 216 
 217 
 218 #define UPDATE_PC(opsize) {pc += opsize; }
 219 /*
 220  * UPDATE_PC_AND_TOS - Macro for updating the pc and topOfStack.
 221  */
 222 #undef UPDATE_PC_AND_TOS
 223 #define UPDATE_PC_AND_TOS(opsize, stack) \
 224     {pc += opsize; MORE_STACK(stack); }
 225 
 226 /*
 227  * UPDATE_PC_AND_TOS_AND_CONTINUE - Macro for updating the pc and topOfStack,
 228  * and executing the next opcode. It's somewhat similar to the combination
 229  * of UPDATE_PC_AND_TOS and CONTINUE, but with some minor optimizations.
 230  */
 231 #undef UPDATE_PC_AND_TOS_AND_CONTINUE
 232 #ifdef USELABELS
 233 #define UPDATE_PC_AND_TOS_AND_CONTINUE(opsize, stack) {         \
 234         pc += opsize; opcode = *pc; MORE_STACK(stack);          \
 235         DO_UPDATE_INSTRUCTION_COUNT(opcode);                    \
 236         DEBUGGER_SINGLE_STEP_NOTIFY();                          \
 237         DISPATCH(opcode);                                       \
 238     }
 239 
 240 #define UPDATE_PC_AND_CONTINUE(opsize) {                        \
 241         pc += opsize; opcode = *pc;                             \
 242         DO_UPDATE_INSTRUCTION_COUNT(opcode);                    \
 243         DEBUGGER_SINGLE_STEP_NOTIFY();                          \
 244         DISPATCH(opcode);                                       \
 245     }
 246 #else
 247 #ifdef PREFETCH_OPCCODE
 248 #define UPDATE_PC_AND_TOS_AND_CONTINUE(opsize, stack) {         \
 249         pc += opsize; opcode = *pc; MORE_STACK(stack);          \
 250         DO_UPDATE_INSTRUCTION_COUNT(opcode);                    \
 251         DEBUGGER_SINGLE_STEP_NOTIFY();                          \
 252         goto do_continue;                                       \
 253     }
 254 
 255 #define UPDATE_PC_AND_CONTINUE(opsize) {                        \
 256         pc += opsize; opcode = *pc;                             \
 257         DO_UPDATE_INSTRUCTION_COUNT(opcode);                    \
 258         DEBUGGER_SINGLE_STEP_NOTIFY();                          \
 259         goto do_continue;                                       \
 260     }
 261 #else
 262 #define UPDATE_PC_AND_TOS_AND_CONTINUE(opsize, stack) { \
 263         pc += opsize; MORE_STACK(stack);                \
 264         DO_UPDATE_INSTRUCTION_COUNT(opcode);            \
 265         DEBUGGER_SINGLE_STEP_NOTIFY();                  \
 266         goto do_continue;                               \
 267     }
 268 
 269 #define UPDATE_PC_AND_CONTINUE(opsize) {                \
 270         pc += opsize;                                   \
 271         DO_UPDATE_INSTRUCTION_COUNT(opcode);            \
 272         DEBUGGER_SINGLE_STEP_NOTIFY();                  \
 273         goto do_continue;                               \
 274     }
 275 #endif /* PREFETCH_OPCCODE */
 276 #endif /* USELABELS */
 277 
 278 // About to call a new method, update the save the adjusted pc and return to frame manager
 279 #define UPDATE_PC_AND_RETURN(opsize)  \
 280    DECACHE_TOS();                     \
 281    istate->set_bcp(pc+opsize);        \
 282    return;
 283 
 284 
 285 #define METHOD istate->method()
 286 #define GET_METHOD_COUNTERS(res)    \
 287   res = METHOD->method_counters();  \
 288   if (res == NULL) {                \
 289     CALL_VM(res = InterpreterRuntime::build_method_counters(THREAD, METHOD), handle_exception); \
 290   }
 291 
 292 #define OSR_REQUEST(res, branch_pc) \
 293             CALL_VM(res=InterpreterRuntime::frequency_counter_overflow(THREAD, branch_pc), handle_exception);
 294 /*
 295  * For those opcodes that need to have a GC point on a backwards branch
 296  */
 297 
 298 // Backedge counting is kind of strange. The asm interpreter will increment
 299 // the backedge counter as a separate counter but it does it's comparisons
 300 // to the sum (scaled) of invocation counter and backedge count to make
 301 // a decision. Seems kind of odd to sum them together like that
 302 
 303 // skip is delta from current bcp/bci for target, branch_pc is pre-branch bcp
 304 
 305 
 306 #define DO_BACKEDGE_CHECKS(skip, branch_pc)                                                         \
 307     if ((skip) <= 0) {                                                                              \
 308       MethodCounters* mcs;                                                                          \
 309       GET_METHOD_COUNTERS(mcs);                                                                     \
 310       if (UseLoopCounter) {                                                                         \
 311         bool do_OSR = UseOnStackReplacement;                                                        \
 312         mcs->backedge_counter()->increment();                                                       \
 313         if (ProfileInterpreter) {                                                                   \
 314           BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception);                                   \
 315           /* Check for overflow against MDO count. */                                               \
 316           do_OSR = do_OSR                                                                           \
 317             && (mdo_last_branch_taken_count >= (uint)InvocationCounter::InterpreterBackwardBranchLimit)\
 318             /* When ProfileInterpreter is on, the backedge_count comes     */                       \
 319             /* from the methodDataOop, which value does not get reset on   */                       \
 320             /* the call to frequency_counter_overflow(). To avoid          */                       \
 321             /* excessive calls to the overflow routine while the method is */                       \
 322             /* being compiled, add a second test to make sure the overflow */                       \
 323             /* function is called only once every overflow_frequency.      */                       \
 324             && (!(mdo_last_branch_taken_count & 1023));                                             \
 325         } else {                                                                                    \
 326           /* check for overflow of backedge counter */                                              \
 327           do_OSR = do_OSR                                                                           \
 328             && mcs->invocation_counter()->reached_InvocationLimit(mcs->backedge_counter());         \
 329         }                                                                                           \
 330         if (do_OSR) {                                                                               \
 331           nmethod* osr_nmethod;                                                                     \
 332           OSR_REQUEST(osr_nmethod, branch_pc);                                                      \
 333           if (osr_nmethod != NULL && osr_nmethod->osr_entry_bci() != InvalidOSREntryBci) {          \
 334             intptr_t* buf;                                                                          \
 335             /* Call OSR migration with last java frame only, no checks. */                          \
 336             CALL_VM_NAKED_LJF(buf=SharedRuntime::OSR_migration_begin(THREAD));                      \
 337             istate->set_msg(do_osr);                                                                \
 338             istate->set_osr_buf((address)buf);                                                      \
 339             istate->set_osr_entry(osr_nmethod->osr_entry());                                        \
 340             return;                                                                                 \
 341           }                                                                                         \
 342         }                                                                                           \
 343       }  /* UseCompiler ... */                                                                      \
 344       SAFEPOINT;                                                                                    \
 345     }
 346 
 347 /*
 348  * For those opcodes that need to have a GC point on a backwards branch
 349  */
 350 
 351 /*
 352  * Macros for caching and flushing the interpreter state. Some local
 353  * variables need to be flushed out to the frame before we do certain
 354  * things (like pushing frames or becomming gc safe) and some need to
 355  * be recached later (like after popping a frame). We could use one
 356  * macro to cache or decache everything, but this would be less then
 357  * optimal because we don't always need to cache or decache everything
 358  * because some things we know are already cached or decached.
 359  */
 360 #undef DECACHE_TOS
 361 #undef CACHE_TOS
 362 #undef CACHE_PREV_TOS
 363 #define DECACHE_TOS()    istate->set_stack(topOfStack);
 364 
 365 #define CACHE_TOS()      topOfStack = (intptr_t *)istate->stack();
 366 
 367 #undef DECACHE_PC
 368 #undef CACHE_PC
 369 #define DECACHE_PC()    istate->set_bcp(pc);
 370 #define CACHE_PC()      pc = istate->bcp();
 371 #define CACHE_CP()      cp = istate->constants();
 372 #define CACHE_LOCALS()  locals = istate->locals();
 373 #undef CACHE_FRAME
 374 #define CACHE_FRAME()
 375 
 376 // BCI() returns the current bytecode-index.
 377 #undef  BCI
 378 #define BCI()           ((int)(intptr_t)(pc - (intptr_t)istate->method()->code_base()))
 379 
 380 /*
 381  * CHECK_NULL - Macro for throwing a NullPointerException if the object
 382  * passed is a null ref.
 383  * On some architectures/platforms it should be possible to do this implicitly
 384  */
 385 #undef CHECK_NULL
 386 #define CHECK_NULL(obj_)                                                                         \
 387         if ((obj_) == NULL) {                                                                    \
 388           VM_JAVA_ERROR(vmSymbols::java_lang_NullPointerException(), NULL, note_nullCheck_trap); \
 389         }                                                                                        \
 390         VERIFY_OOP(obj_)
 391 
 392 #define VMdoubleConstZero() 0.0
 393 #define VMdoubleConstOne() 1.0
 394 #define VMlongConstZero() (max_jlong-max_jlong)
 395 #define VMlongConstOne() ((max_jlong-max_jlong)+1)
 396 
 397 /*
 398  * Alignment
 399  */
 400 #define VMalignWordUp(val)          (((uintptr_t)(val) + 3) & ~3)
 401 
 402 // Decache the interpreter state that interpreter modifies directly (i.e. GC is indirect mod)
 403 #define DECACHE_STATE() DECACHE_PC(); DECACHE_TOS();
 404 
 405 // Reload interpreter state after calling the VM or a possible GC
 406 #define CACHE_STATE()   \
 407         CACHE_TOS();    \
 408         CACHE_PC();     \
 409         CACHE_CP();     \
 410         CACHE_LOCALS();
 411 
 412 // Call the VM with last java frame only.
 413 #define CALL_VM_NAKED_LJF(func)                                    \
 414         DECACHE_STATE();                                           \
 415         SET_LAST_JAVA_FRAME();                                     \
 416         func;                                                      \
 417         RESET_LAST_JAVA_FRAME();                                   \
 418         CACHE_STATE();
 419 
 420 // Call the VM. Don't check for pending exceptions.
 421 #define CALL_VM_NOCHECK(func)                                      \
 422         CALL_VM_NAKED_LJF(func)                                    \
 423         if (THREAD->pop_frame_pending() &&                         \
 424             !THREAD->pop_frame_in_process()) {                     \
 425           goto handle_Pop_Frame;                                   \
 426         }                                                          \
 427         if (THREAD->jvmti_thread_state() &&                        \
 428             THREAD->jvmti_thread_state()->is_earlyret_pending()) { \
 429           goto handle_Early_Return;                                \
 430         }
 431 
 432 // Call the VM and check for pending exceptions
 433 #define CALL_VM(func, label) {                                     \
 434           CALL_VM_NOCHECK(func);                                   \
 435           if (THREAD->has_pending_exception()) goto label;         \
 436         }
 437 
 438 /*
 439  * BytecodeInterpreter::run(interpreterState istate)
 440  * BytecodeInterpreter::runWithChecks(interpreterState istate)
 441  *
 442  * The real deal. This is where byte codes actually get interpreted.
 443  * Basically it's a big while loop that iterates until we return from
 444  * the method passed in.
 445  *
 446  * The runWithChecks is used if JVMTI is enabled.
 447  *
 448  */
 449 #if defined(VM_JVMTI)
 450 void
 451 BytecodeInterpreter::runWithChecks(interpreterState istate) {
 452 #else
 453 void
 454 BytecodeInterpreter::run(interpreterState istate) {
 455 #endif
 456 
 457   // In order to simplify some tests based on switches set at runtime
 458   // we invoke the interpreter a single time after switches are enabled
 459   // and set simpler to to test variables rather than method calls or complex
 460   // boolean expressions.
 461 
 462   static int initialized = 0;
 463   static int checkit = 0;
 464   static intptr_t* c_addr = NULL;
 465   static intptr_t  c_value;
 466 
 467   if (checkit && *c_addr != c_value) {
 468     os::breakpoint();
 469   }
 470 #ifdef VM_JVMTI
 471   static bool _jvmti_interp_events = 0;
 472 #endif
 473 
 474   static int _compiling;  // (UseCompiler || CountCompiledCalls)
 475 
 476 #ifdef ASSERT
 477   if (istate->_msg != initialize) {
 478     // We have a problem here if we are running with a pre-hsx24 JDK (for example during bootstrap)
 479     // because in that case, EnableInvokeDynamic is true by default but will be later switched off
 480     // if java_lang_invoke_MethodHandle::compute_offsets() detects that the JDK only has the classes
 481     // for the old JSR292 implementation.
 482     // This leads to a situation where 'istate->_stack_limit' always accounts for
 483     // methodOopDesc::extra_stack_entries() because it is computed in
 484     // CppInterpreterGenerator::generate_compute_interpreter_state() which was generated while
 485     // EnableInvokeDynamic was still true. On the other hand, istate->_method->max_stack() doesn't
 486     // account for extra_stack_entries() anymore because at the time when it is called
 487     // EnableInvokeDynamic was already set to false.
 488     // So we have a second version of the assertion which handles the case where EnableInvokeDynamic was
 489     // switched off because of the wrong classes.
 490     if (EnableInvokeDynamic || FLAG_IS_CMDLINE(EnableInvokeDynamic)) {
 491       assert(labs(istate->_stack_base - istate->_stack_limit) == (istate->_method->max_stack() + 1), "bad stack limit");
 492     } else {
 493       const int extra_stack_entries = Method::extra_stack_entries_for_jsr292;
 494       assert(labs(istate->_stack_base - istate->_stack_limit) == (istate->_method->max_stack() + extra_stack_entries
 495                                                                                                + 1), "bad stack limit");
 496     }
 497 #ifndef SHARK
 498     IA32_ONLY(assert(istate->_stack_limit == istate->_thread->last_Java_sp() + 1, "wrong"));
 499 #endif // !SHARK
 500   }
 501   // Verify linkages.
 502   interpreterState l = istate;
 503   do {
 504     assert(l == l->_self_link, "bad link");
 505     l = l->_prev_link;
 506   } while (l != NULL);
 507   // Screwups with stack management usually cause us to overwrite istate
 508   // save a copy so we can verify it.
 509   interpreterState orig = istate;
 510 #endif
 511 
 512   register intptr_t*        topOfStack = (intptr_t *)istate->stack(); /* access with STACK macros */
 513   register address          pc = istate->bcp();
 514   register jubyte opcode;
 515   register intptr_t*        locals = istate->locals();
 516   register ConstantPoolCache*    cp = istate->constants(); // method()->constants()->cache()
 517 #ifdef LOTS_OF_REGS
 518   register JavaThread*      THREAD = istate->thread();
 519 #else
 520 #undef THREAD
 521 #define THREAD istate->thread()
 522 #endif
 523 
 524 #ifdef USELABELS
 525   const static void* const opclabels_data[256] = {
 526 /* 0x00 */ &&opc_nop,     &&opc_aconst_null,&&opc_iconst_m1,&&opc_iconst_0,
 527 /* 0x04 */ &&opc_iconst_1,&&opc_iconst_2,   &&opc_iconst_3, &&opc_iconst_4,
 528 /* 0x08 */ &&opc_iconst_5,&&opc_lconst_0,   &&opc_lconst_1, &&opc_fconst_0,
 529 /* 0x0C */ &&opc_fconst_1,&&opc_fconst_2,   &&opc_dconst_0, &&opc_dconst_1,
 530 
 531 /* 0x10 */ &&opc_bipush, &&opc_sipush, &&opc_ldc,    &&opc_ldc_w,
 532 /* 0x14 */ &&opc_ldc2_w, &&opc_iload,  &&opc_lload,  &&opc_fload,
 533 /* 0x18 */ &&opc_dload,  &&opc_aload,  &&opc_iload_0,&&opc_iload_1,
 534 /* 0x1C */ &&opc_iload_2,&&opc_iload_3,&&opc_lload_0,&&opc_lload_1,
 535 
 536 /* 0x20 */ &&opc_lload_2,&&opc_lload_3,&&opc_fload_0,&&opc_fload_1,
 537 /* 0x24 */ &&opc_fload_2,&&opc_fload_3,&&opc_dload_0,&&opc_dload_1,
 538 /* 0x28 */ &&opc_dload_2,&&opc_dload_3,&&opc_aload_0,&&opc_aload_1,
 539 /* 0x2C */ &&opc_aload_2,&&opc_aload_3,&&opc_iaload, &&opc_laload,
 540 
 541 /* 0x30 */ &&opc_faload,  &&opc_daload,  &&opc_aaload,  &&opc_baload,
 542 /* 0x34 */ &&opc_caload,  &&opc_saload,  &&opc_istore,  &&opc_lstore,
 543 /* 0x38 */ &&opc_fstore,  &&opc_dstore,  &&opc_astore,  &&opc_istore_0,
 544 /* 0x3C */ &&opc_istore_1,&&opc_istore_2,&&opc_istore_3,&&opc_lstore_0,
 545 
 546 /* 0x40 */ &&opc_lstore_1,&&opc_lstore_2,&&opc_lstore_3,&&opc_fstore_0,
 547 /* 0x44 */ &&opc_fstore_1,&&opc_fstore_2,&&opc_fstore_3,&&opc_dstore_0,
 548 /* 0x48 */ &&opc_dstore_1,&&opc_dstore_2,&&opc_dstore_3,&&opc_astore_0,
 549 /* 0x4C */ &&opc_astore_1,&&opc_astore_2,&&opc_astore_3,&&opc_iastore,
 550 
 551 /* 0x50 */ &&opc_lastore,&&opc_fastore,&&opc_dastore,&&opc_aastore,
 552 /* 0x54 */ &&opc_bastore,&&opc_castore,&&opc_sastore,&&opc_pop,
 553 /* 0x58 */ &&opc_pop2,   &&opc_dup,    &&opc_dup_x1, &&opc_dup_x2,
 554 /* 0x5C */ &&opc_dup2,   &&opc_dup2_x1,&&opc_dup2_x2,&&opc_swap,
 555 
 556 /* 0x60 */ &&opc_iadd,&&opc_ladd,&&opc_fadd,&&opc_dadd,
 557 /* 0x64 */ &&opc_isub,&&opc_lsub,&&opc_fsub,&&opc_dsub,
 558 /* 0x68 */ &&opc_imul,&&opc_lmul,&&opc_fmul,&&opc_dmul,
 559 /* 0x6C */ &&opc_idiv,&&opc_ldiv,&&opc_fdiv,&&opc_ddiv,
 560 
 561 /* 0x70 */ &&opc_irem, &&opc_lrem, &&opc_frem,&&opc_drem,
 562 /* 0x74 */ &&opc_ineg, &&opc_lneg, &&opc_fneg,&&opc_dneg,
 563 /* 0x78 */ &&opc_ishl, &&opc_lshl, &&opc_ishr,&&opc_lshr,
 564 /* 0x7C */ &&opc_iushr,&&opc_lushr,&&opc_iand,&&opc_land,
 565 
 566 /* 0x80 */ &&opc_ior, &&opc_lor,&&opc_ixor,&&opc_lxor,
 567 /* 0x84 */ &&opc_iinc,&&opc_i2l,&&opc_i2f, &&opc_i2d,
 568 /* 0x88 */ &&opc_l2i, &&opc_l2f,&&opc_l2d, &&opc_f2i,
 569 /* 0x8C */ &&opc_f2l, &&opc_f2d,&&opc_d2i, &&opc_d2l,
 570 
 571 /* 0x90 */ &&opc_d2f,  &&opc_i2b,  &&opc_i2c,  &&opc_i2s,
 572 /* 0x94 */ &&opc_lcmp, &&opc_fcmpl,&&opc_fcmpg,&&opc_dcmpl,
 573 /* 0x98 */ &&opc_dcmpg,&&opc_ifeq, &&opc_ifne, &&opc_iflt,
 574 /* 0x9C */ &&opc_ifge, &&opc_ifgt, &&opc_ifle, &&opc_if_icmpeq,
 575 
 576 /* 0xA0 */ &&opc_if_icmpne,&&opc_if_icmplt,&&opc_if_icmpge,  &&opc_if_icmpgt,
 577 /* 0xA4 */ &&opc_if_icmple,&&opc_if_acmpeq,&&opc_if_acmpne,  &&opc_goto,
 578 /* 0xA8 */ &&opc_jsr,      &&opc_ret,      &&opc_tableswitch,&&opc_lookupswitch,
 579 /* 0xAC */ &&opc_ireturn,  &&opc_lreturn,  &&opc_freturn,    &&opc_dreturn,
 580 
 581 /* 0xB0 */ &&opc_areturn,     &&opc_return,         &&opc_getstatic,    &&opc_putstatic,
 582 /* 0xB4 */ &&opc_getfield,    &&opc_putfield,       &&opc_invokevirtual,&&opc_invokespecial,
 583 /* 0xB8 */ &&opc_invokestatic,&&opc_invokeinterface,&&opc_invokedynamic,&&opc_new,
 584 /* 0xBC */ &&opc_newarray,    &&opc_anewarray,      &&opc_arraylength,  &&opc_athrow,
 585 
 586 /* 0xC0 */ &&opc_checkcast,   &&opc_instanceof,     &&opc_monitorenter, &&opc_monitorexit,
 587 /* 0xC4 */ &&opc_wide,        &&opc_multianewarray, &&opc_ifnull,       &&opc_ifnonnull,
 588 /* 0xC8 */ &&opc_goto_w,      &&opc_jsr_w,          &&opc_breakpoint,   &&opc_default,
 589 /* 0xCC */ &&opc_default,     &&opc_default,        &&opc_default,      &&opc_default,
 590 
 591 /* 0xD0 */ &&opc_default,     &&opc_default,        &&opc_default,      &&opc_default,
 592 /* 0xD4 */ &&opc_default,     &&opc_default,        &&opc_default,      &&opc_default,
 593 /* 0xD8 */ &&opc_default,     &&opc_default,        &&opc_default,      &&opc_default,
 594 /* 0xDC */ &&opc_default,     &&opc_default,        &&opc_default,      &&opc_default,
 595 
 596 /* 0xE0 */ &&opc_default,     &&opc_default,        &&opc_default,      &&opc_default,
 597 /* 0xE4 */ &&opc_default,     &&opc_fast_aldc,      &&opc_fast_aldc_w,  &&opc_return_register_finalizer,
 598 /* 0xE8 */ &&opc_invokehandle,&&opc_default,        &&opc_default,      &&opc_default,
 599 /* 0xEC */ &&opc_default,     &&opc_default,        &&opc_default,      &&opc_default,
 600 
 601 /* 0xF0 */ &&opc_default,     &&opc_default,        &&opc_default,      &&opc_default,
 602 /* 0xF4 */ &&opc_default,     &&opc_default,        &&opc_default,      &&opc_default,
 603 /* 0xF8 */ &&opc_default,     &&opc_default,        &&opc_default,      &&opc_default,
 604 /* 0xFC */ &&opc_default,     &&opc_default,        &&opc_default,      &&opc_default
 605   };
 606   register uintptr_t *dispatch_table = (uintptr_t*)&opclabels_data[0];
 607 #endif /* USELABELS */
 608 
 609 #ifdef ASSERT
 610   // this will trigger a VERIFY_OOP on entry
 611   if (istate->msg() != initialize && ! METHOD->is_static()) {
 612     oop rcvr = LOCALS_OBJECT(0);
 613     VERIFY_OOP(rcvr);
 614   }
 615 #endif
 616 // #define HACK
 617 #ifdef HACK
 618   bool interesting = false;
 619 #endif // HACK
 620 
 621   /* QQQ this should be a stack method so we don't know actual direction */
 622   guarantee(istate->msg() == initialize ||
 623          topOfStack >= istate->stack_limit() &&
 624          topOfStack < istate->stack_base(),
 625          "Stack top out of range");
 626 
 627 #ifdef CC_INTERP_PROFILE
 628   // MethodData's last branch taken count.
 629   uint mdo_last_branch_taken_count = 0;
 630 #else
 631   const uint mdo_last_branch_taken_count = 0;
 632 #endif
 633 
 634   switch (istate->msg()) {
 635     case initialize: {
 636       if (initialized++) ShouldNotReachHere(); // Only one initialize call.
 637       _compiling = (UseCompiler || CountCompiledCalls);
 638 #ifdef VM_JVMTI
 639       _jvmti_interp_events = JvmtiExport::can_post_interpreter_events();
 640 #endif
 641       return;
 642     }
 643     break;
 644     case method_entry: {
 645       THREAD->set_do_not_unlock();
 646       // count invocations
 647       assert(initialized, "Interpreter not initialized");
 648       if (_compiling) {
 649         MethodCounters* mcs;
 650         GET_METHOD_COUNTERS(mcs);
 651         if (ProfileInterpreter) {
 652           METHOD->increment_interpreter_invocation_count(THREAD);
 653         }
 654         mcs->invocation_counter()->increment();
 655         if (mcs->invocation_counter()->reached_InvocationLimit(mcs->backedge_counter())) {
 656           CALL_VM((void)InterpreterRuntime::frequency_counter_overflow(THREAD, NULL), handle_exception);
 657           // We no longer retry on a counter overflow.
 658         }
 659         // Get or create profile data. Check for pending (async) exceptions.
 660         BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception);
 661         SAFEPOINT;
 662       }
 663 
 664       if ((istate->_stack_base - istate->_stack_limit) != istate->method()->max_stack() + 1) {
 665         // initialize
 666         os::breakpoint();
 667       }
 668 
 669 #ifdef HACK
 670       {
 671         ResourceMark rm;
 672         char *method_name = istate->method()->name_and_sig_as_C_string();
 673         if (strstr(method_name, "runThese$TestRunner.run()V") != NULL) {
 674           tty->print_cr("entering: depth %d bci: %d",
 675                          (istate->_stack_base - istate->_stack),
 676                          istate->_bcp - istate->_method->code_base());
 677           interesting = true;
 678         }
 679       }
 680 #endif // HACK
 681 
 682       // Lock method if synchronized.
 683       if (METHOD->is_synchronized()) {
 684         // oop rcvr = locals[0].j.r;
 685         oop rcvr;
 686         if (METHOD->is_static()) {
 687           rcvr = METHOD->constants()->pool_holder()->java_mirror();
 688         } else {
 689           rcvr = LOCALS_OBJECT(0);
 690           VERIFY_OOP(rcvr);
 691         }
 692         // The initial monitor is ours for the taking.
 693         // Monitor not filled in frame manager any longer as this caused race condition with biased locking.
 694         BasicObjectLock* mon = &istate->monitor_base()[-1];
 695         mon->set_obj(rcvr);
 696         bool success = false;
 697         uintptr_t epoch_mask_in_place = (uintptr_t)markOopDesc::epoch_mask_in_place;
 698         markOop mark = rcvr->mark();
 699         intptr_t hash = (intptr_t) markOopDesc::no_hash;
 700         // Implies UseBiasedLocking.
 701         if (mark->has_bias_pattern()) {
 702           uintptr_t thread_ident;
 703           uintptr_t anticipated_bias_locking_value;
 704           thread_ident = (uintptr_t)istate->thread();
 705           anticipated_bias_locking_value =
 706             (((uintptr_t)rcvr->klass()->prototype_header() | thread_ident) ^ (uintptr_t)mark) &
 707             ~((uintptr_t) markOopDesc::age_mask_in_place);
 708 
 709           if (anticipated_bias_locking_value == 0) {
 710             // Already biased towards this thread, nothing to do.
 711             if (PrintBiasedLockingStatistics) {
 712               (* BiasedLocking::biased_lock_entry_count_addr())++;
 713             }
 714             success = true;
 715           } else if ((anticipated_bias_locking_value & markOopDesc::biased_lock_mask_in_place) != 0) {
 716             // Try to revoke bias.
 717             markOop header = rcvr->klass()->prototype_header();
 718             if (hash != markOopDesc::no_hash) {
 719               header = header->copy_set_hash(hash);
 720             }
 721             if (Atomic::cmpxchg_ptr(header, rcvr->mark_addr(), mark) == mark) {
 722               if (PrintBiasedLockingStatistics)
 723                 (*BiasedLocking::revoked_lock_entry_count_addr())++;
 724             }
 725           } else if ((anticipated_bias_locking_value & epoch_mask_in_place) != 0) {
 726             // Try to rebias.
 727             markOop new_header = (markOop) ( (intptr_t) rcvr->klass()->prototype_header() | thread_ident);
 728             if (hash != markOopDesc::no_hash) {
 729               new_header = new_header->copy_set_hash(hash);
 730             }
 731             if (Atomic::cmpxchg_ptr((void*)new_header, rcvr->mark_addr(), mark) == mark) {
 732               if (PrintBiasedLockingStatistics) {
 733                 (* BiasedLocking::rebiased_lock_entry_count_addr())++;
 734               }
 735             } else {
 736               CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);
 737             }
 738             success = true;
 739           } else {
 740             // Try to bias towards thread in case object is anonymously biased.
 741             markOop header = (markOop) ((uintptr_t) mark &
 742                                         ((uintptr_t)markOopDesc::biased_lock_mask_in_place |
 743                                          (uintptr_t)markOopDesc::age_mask_in_place | epoch_mask_in_place));
 744             if (hash != markOopDesc::no_hash) {
 745               header = header->copy_set_hash(hash);
 746             }
 747             markOop new_header = (markOop) ((uintptr_t) header | thread_ident);
 748             // Debugging hint.
 749             DEBUG_ONLY(mon->lock()->set_displaced_header((markOop) (uintptr_t) 0xdeaddead);)
 750             if (Atomic::cmpxchg_ptr((void*)new_header, rcvr->mark_addr(), header) == header) {
 751               if (PrintBiasedLockingStatistics) {
 752                 (* BiasedLocking::anonymously_biased_lock_entry_count_addr())++;
 753               }
 754             } else {
 755               CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);
 756             }
 757             success = true;
 758           }
 759         }
 760 
 761         // Traditional lightweight locking.
 762         if (!success) {
 763           markOop displaced = rcvr->mark()->set_unlocked();
 764           mon->lock()->set_displaced_header(displaced);
 765           bool call_vm = UseHeavyMonitors;
 766           if (call_vm || Atomic::cmpxchg_ptr(mon, rcvr->mark_addr(), displaced) != displaced) {
 767             // Is it simple recursive case?
 768             if (!call_vm && THREAD->is_lock_owned((address) displaced->clear_lock_bits())) {
 769               mon->lock()->set_displaced_header(NULL);
 770             } else {
 771               CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);
 772             }
 773           }
 774         }
 775       }
 776       THREAD->clr_do_not_unlock();
 777 
 778       // Notify jvmti
 779 #ifdef VM_JVMTI
 780       if (_jvmti_interp_events) {
 781         // Whenever JVMTI puts a thread in interp_only_mode, method
 782         // entry/exit events are sent for that thread to track stack depth.
 783         if (THREAD->is_interp_only_mode()) {
 784           CALL_VM(InterpreterRuntime::post_method_entry(THREAD),
 785                   handle_exception);
 786         }
 787       }
 788 #endif /* VM_JVMTI */
 789 
 790       goto run;
 791     }
 792 
 793     case popping_frame: {
 794       // returned from a java call to pop the frame, restart the call
 795       // clear the message so we don't confuse ourselves later
 796       assert(THREAD->pop_frame_in_process(), "wrong frame pop state");
 797       istate->set_msg(no_request);
 798       if (_compiling) {
 799         // Set MDX back to the ProfileData of the invoke bytecode that will be
 800         // restarted.
 801         SET_MDX(NULL);
 802         BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception);
 803       }
 804       THREAD->clr_pop_frame_in_process();
 805       goto run;
 806     }
 807 
 808     case method_resume: {
 809       if ((istate->_stack_base - istate->_stack_limit) != istate->method()->max_stack() + 1) {
 810         // resume
 811         os::breakpoint();
 812       }
 813 #ifdef HACK
 814       {
 815         ResourceMark rm;
 816         char *method_name = istate->method()->name_and_sig_as_C_string();
 817         if (strstr(method_name, "runThese$TestRunner.run()V") != NULL) {
 818           tty->print_cr("resume: depth %d bci: %d",
 819                          (istate->_stack_base - istate->_stack) ,
 820                          istate->_bcp - istate->_method->code_base());
 821           interesting = true;
 822         }
 823       }
 824 #endif // HACK
 825       // returned from a java call, continue executing.
 826       if (THREAD->pop_frame_pending() && !THREAD->pop_frame_in_process()) {
 827         goto handle_Pop_Frame;
 828       }
 829       if (THREAD->jvmti_thread_state() &&
 830           THREAD->jvmti_thread_state()->is_earlyret_pending()) {
 831         goto handle_Early_Return;
 832       }
 833 
 834       if (THREAD->has_pending_exception()) goto handle_exception;
 835       // Update the pc by the saved amount of the invoke bytecode size
 836       UPDATE_PC(istate->bcp_advance());
 837 
 838       if (_compiling) {
 839         // Get or create profile data. Check for pending (async) exceptions.
 840         BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception);
 841       }
 842       goto run;
 843     }
 844 
 845     case deopt_resume2: {
 846       // Returned from an opcode that will reexecute. Deopt was
 847       // a result of a PopFrame request.
 848       //
 849 
 850       if (_compiling) {
 851         // Get or create profile data. Check for pending (async) exceptions.
 852         BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception);
 853       }
 854       goto run;
 855     }
 856 
 857     case deopt_resume: {
 858       // Returned from an opcode that has completed. The stack has
 859       // the result all we need to do is skip across the bytecode
 860       // and continue (assuming there is no exception pending)
 861       //
 862       // compute continuation length
 863       //
 864       // Note: it is possible to deopt at a return_register_finalizer opcode
 865       // because this requires entering the vm to do the registering. While the
 866       // opcode is complete we can't advance because there are no more opcodes
 867       // much like trying to deopt at a poll return. In that has we simply
 868       // get out of here
 869       //
 870       if ( Bytecodes::code_at(METHOD, pc) == Bytecodes::_return_register_finalizer) {
 871         // this will do the right thing even if an exception is pending.
 872         goto handle_return;
 873       }
 874       UPDATE_PC(Bytecodes::length_at(METHOD, pc));
 875       if (THREAD->has_pending_exception()) goto handle_exception;
 876 
 877       if (_compiling) {
 878         // Get or create profile data. Check for pending (async) exceptions.
 879         BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception);
 880       }
 881       goto run;
 882     }
 883     case got_monitors: {
 884       // continue locking now that we have a monitor to use
 885       // we expect to find newly allocated monitor at the "top" of the monitor stack.
 886       oop lockee = STACK_OBJECT(-1);
 887       VERIFY_OOP(lockee);
 888       // derefing's lockee ought to provoke implicit null check
 889       // find a free monitor
 890       BasicObjectLock* entry = (BasicObjectLock*) istate->stack_base();
 891       assert(entry->obj() == NULL, "Frame manager didn't allocate the monitor");
 892       entry->set_obj(lockee);
 893       bool success = false;
 894       uintptr_t epoch_mask_in_place = (uintptr_t)markOopDesc::epoch_mask_in_place;
 895 
 896       markOop mark = lockee->mark();
 897       intptr_t hash = (intptr_t) markOopDesc::no_hash;
 898       // implies UseBiasedLocking
 899       if (mark->has_bias_pattern()) {
 900         uintptr_t thread_ident;
 901         uintptr_t anticipated_bias_locking_value;
 902         thread_ident = (uintptr_t)istate->thread();
 903         anticipated_bias_locking_value =
 904           (((uintptr_t)lockee->klass()->prototype_header() | thread_ident) ^ (uintptr_t)mark) &
 905           ~((uintptr_t) markOopDesc::age_mask_in_place);
 906 
 907         if  (anticipated_bias_locking_value == 0) {
 908           // already biased towards this thread, nothing to do
 909           if (PrintBiasedLockingStatistics) {
 910             (* BiasedLocking::biased_lock_entry_count_addr())++;
 911           }
 912           success = true;
 913         } else if ((anticipated_bias_locking_value & markOopDesc::biased_lock_mask_in_place) != 0) {
 914           // try revoke bias
 915           markOop header = lockee->klass()->prototype_header();
 916           if (hash != markOopDesc::no_hash) {
 917             header = header->copy_set_hash(hash);
 918           }
 919           if (Atomic::cmpxchg_ptr(header, lockee->mark_addr(), mark) == mark) {
 920             if (PrintBiasedLockingStatistics) {
 921               (*BiasedLocking::revoked_lock_entry_count_addr())++;
 922             }
 923           }
 924         } else if ((anticipated_bias_locking_value & epoch_mask_in_place) !=0) {
 925           // try rebias
 926           markOop new_header = (markOop) ( (intptr_t) lockee->klass()->prototype_header() | thread_ident);
 927           if (hash != markOopDesc::no_hash) {
 928                 new_header = new_header->copy_set_hash(hash);
 929           }
 930           if (Atomic::cmpxchg_ptr((void*)new_header, lockee->mark_addr(), mark) == mark) {
 931             if (PrintBiasedLockingStatistics) {
 932               (* BiasedLocking::rebiased_lock_entry_count_addr())++;
 933             }
 934           } else {
 935             CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
 936           }
 937           success = true;
 938         } else {
 939           // try to bias towards thread in case object is anonymously biased
 940           markOop header = (markOop) ((uintptr_t) mark & ((uintptr_t)markOopDesc::biased_lock_mask_in_place |
 941                                                           (uintptr_t)markOopDesc::age_mask_in_place | epoch_mask_in_place));
 942           if (hash != markOopDesc::no_hash) {
 943             header = header->copy_set_hash(hash);
 944           }
 945           markOop new_header = (markOop) ((uintptr_t) header | thread_ident);
 946           // debugging hint
 947           DEBUG_ONLY(entry->lock()->set_displaced_header((markOop) (uintptr_t) 0xdeaddead);)
 948           if (Atomic::cmpxchg_ptr((void*)new_header, lockee->mark_addr(), header) == header) {
 949             if (PrintBiasedLockingStatistics) {
 950               (* BiasedLocking::anonymously_biased_lock_entry_count_addr())++;
 951             }
 952           } else {
 953             CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
 954           }
 955           success = true;
 956         }
 957       }
 958 
 959       // traditional lightweight locking
 960       if (!success) {
 961         markOop displaced = lockee->mark()->set_unlocked();
 962         entry->lock()->set_displaced_header(displaced);
 963         bool call_vm = UseHeavyMonitors;
 964         if (call_vm || Atomic::cmpxchg_ptr(entry, lockee->mark_addr(), displaced) != displaced) {
 965           // Is it simple recursive case?
 966           if (!call_vm && THREAD->is_lock_owned((address) displaced->clear_lock_bits())) {
 967             entry->lock()->set_displaced_header(NULL);
 968           } else {
 969             CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
 970           }
 971         }
 972       }
 973       UPDATE_PC_AND_TOS(1, -1);
 974       goto run;
 975     }
 976     default: {
 977       fatal("Unexpected message from frame manager");
 978     }
 979   }
 980 
 981 run:
 982 
 983   DO_UPDATE_INSTRUCTION_COUNT(*pc)
 984   DEBUGGER_SINGLE_STEP_NOTIFY();
 985 #ifdef PREFETCH_OPCCODE
 986   opcode = *pc;  /* prefetch first opcode */
 987 #endif
 988 
 989 #ifndef USELABELS
 990   while (1)
 991 #endif
 992   {
 993 #ifndef PREFETCH_OPCCODE
 994       opcode = *pc;
 995 #endif
 996       // Seems like this happens twice per opcode. At worst this is only
 997       // need at entry to the loop.
 998       // DEBUGGER_SINGLE_STEP_NOTIFY();
 999       /* Using this labels avoids double breakpoints when quickening and
1000        * when returing from transition frames.
1001        */
1002   opcode_switch:
1003       assert(istate == orig, "Corrupted istate");
1004       /* QQQ Hmm this has knowledge of direction, ought to be a stack method */
1005       assert(topOfStack >= istate->stack_limit(), "Stack overrun");
1006       assert(topOfStack < istate->stack_base(), "Stack underrun");
1007 
1008 #ifdef USELABELS
1009       DISPATCH(opcode);
1010 #else
1011       switch (opcode)
1012 #endif
1013       {
1014       CASE(_nop):
1015           UPDATE_PC_AND_CONTINUE(1);
1016 
1017           /* Push miscellaneous constants onto the stack. */
1018 
1019       CASE(_aconst_null):
1020           SET_STACK_OBJECT(NULL, 0);
1021           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1022 
1023 #undef  OPC_CONST_n
1024 #define OPC_CONST_n(opcode, const_type, value)                          \
1025       CASE(opcode):                                                     \
1026           SET_STACK_ ## const_type(value, 0);                           \
1027           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1028 
1029           OPC_CONST_n(_iconst_m1,   INT,       -1);
1030           OPC_CONST_n(_iconst_0,    INT,        0);
1031           OPC_CONST_n(_iconst_1,    INT,        1);
1032           OPC_CONST_n(_iconst_2,    INT,        2);
1033           OPC_CONST_n(_iconst_3,    INT,        3);
1034           OPC_CONST_n(_iconst_4,    INT,        4);
1035           OPC_CONST_n(_iconst_5,    INT,        5);
1036           OPC_CONST_n(_fconst_0,    FLOAT,      0.0);
1037           OPC_CONST_n(_fconst_1,    FLOAT,      1.0);
1038           OPC_CONST_n(_fconst_2,    FLOAT,      2.0);
1039 
1040 #undef  OPC_CONST2_n
1041 #define OPC_CONST2_n(opcname, value, key, kind)                         \
1042       CASE(_##opcname):                                                 \
1043       {                                                                 \
1044           SET_STACK_ ## kind(VM##key##Const##value(), 1);               \
1045           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);                         \
1046       }
1047          OPC_CONST2_n(dconst_0, Zero, double, DOUBLE);
1048          OPC_CONST2_n(dconst_1, One,  double, DOUBLE);
1049          OPC_CONST2_n(lconst_0, Zero, long, LONG);
1050          OPC_CONST2_n(lconst_1, One,  long, LONG);
1051 
1052          /* Load constant from constant pool: */
1053 
1054           /* Push a 1-byte signed integer value onto the stack. */
1055       CASE(_bipush):
1056           SET_STACK_INT((jbyte)(pc[1]), 0);
1057           UPDATE_PC_AND_TOS_AND_CONTINUE(2, 1);
1058 
1059           /* Push a 2-byte signed integer constant onto the stack. */
1060       CASE(_sipush):
1061           SET_STACK_INT((int16_t)Bytes::get_Java_u2(pc + 1), 0);
1062           UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1);
1063 
1064           /* load from local variable */
1065 
1066       CASE(_aload):
1067           VERIFY_OOP(LOCALS_OBJECT(pc[1]));
1068           SET_STACK_OBJECT(LOCALS_OBJECT(pc[1]), 0);
1069           UPDATE_PC_AND_TOS_AND_CONTINUE(2, 1);
1070 
1071       CASE(_iload):
1072       CASE(_fload):
1073           SET_STACK_SLOT(LOCALS_SLOT(pc[1]), 0);
1074           UPDATE_PC_AND_TOS_AND_CONTINUE(2, 1);
1075 
1076       CASE(_lload):
1077           SET_STACK_LONG_FROM_ADDR(LOCALS_LONG_AT(pc[1]), 1);
1078           UPDATE_PC_AND_TOS_AND_CONTINUE(2, 2);
1079 
1080       CASE(_dload):
1081           SET_STACK_DOUBLE_FROM_ADDR(LOCALS_DOUBLE_AT(pc[1]), 1);
1082           UPDATE_PC_AND_TOS_AND_CONTINUE(2, 2);
1083 
1084 #undef  OPC_LOAD_n
1085 #define OPC_LOAD_n(num)                                                 \
1086       CASE(_aload_##num):                                               \
1087           VERIFY_OOP(LOCALS_OBJECT(num));                               \
1088           SET_STACK_OBJECT(LOCALS_OBJECT(num), 0);                      \
1089           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);                         \
1090                                                                         \
1091       CASE(_iload_##num):                                               \
1092       CASE(_fload_##num):                                               \
1093           SET_STACK_SLOT(LOCALS_SLOT(num), 0);                          \
1094           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);                         \
1095                                                                         \
1096       CASE(_lload_##num):                                               \
1097           SET_STACK_LONG_FROM_ADDR(LOCALS_LONG_AT(num), 1);             \
1098           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);                         \
1099       CASE(_dload_##num):                                               \
1100           SET_STACK_DOUBLE_FROM_ADDR(LOCALS_DOUBLE_AT(num), 1);         \
1101           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1102 
1103           OPC_LOAD_n(0);
1104           OPC_LOAD_n(1);
1105           OPC_LOAD_n(2);
1106           OPC_LOAD_n(3);
1107 
1108           /* store to a local variable */
1109 
1110       CASE(_astore):
1111           astore(topOfStack, -1, locals, pc[1]);
1112           UPDATE_PC_AND_TOS_AND_CONTINUE(2, -1);
1113 
1114       CASE(_istore):
1115       CASE(_fstore):
1116           SET_LOCALS_SLOT(STACK_SLOT(-1), pc[1]);
1117           UPDATE_PC_AND_TOS_AND_CONTINUE(2, -1);
1118 
1119       CASE(_lstore):
1120           SET_LOCALS_LONG(STACK_LONG(-1), pc[1]);
1121           UPDATE_PC_AND_TOS_AND_CONTINUE(2, -2);
1122 
1123       CASE(_dstore):
1124           SET_LOCALS_DOUBLE(STACK_DOUBLE(-1), pc[1]);
1125           UPDATE_PC_AND_TOS_AND_CONTINUE(2, -2);
1126 
1127       CASE(_wide): {
1128           uint16_t reg = Bytes::get_Java_u2(pc + 2);
1129 
1130           opcode = pc[1];
1131 
1132           // Wide and it's sub-bytecode are counted as separate instructions. If we
1133           // don't account for this here, the bytecode trace skips the next bytecode.
1134           DO_UPDATE_INSTRUCTION_COUNT(opcode);
1135 
1136           switch(opcode) {
1137               case Bytecodes::_aload:
1138                   VERIFY_OOP(LOCALS_OBJECT(reg));
1139                   SET_STACK_OBJECT(LOCALS_OBJECT(reg), 0);
1140                   UPDATE_PC_AND_TOS_AND_CONTINUE(4, 1);
1141 
1142               case Bytecodes::_iload:
1143               case Bytecodes::_fload:
1144                   SET_STACK_SLOT(LOCALS_SLOT(reg), 0);
1145                   UPDATE_PC_AND_TOS_AND_CONTINUE(4, 1);
1146 
1147               case Bytecodes::_lload:
1148                   SET_STACK_LONG_FROM_ADDR(LOCALS_LONG_AT(reg), 1);
1149                   UPDATE_PC_AND_TOS_AND_CONTINUE(4, 2);
1150 
1151               case Bytecodes::_dload:
1152                   SET_STACK_DOUBLE_FROM_ADDR(LOCALS_LONG_AT(reg), 1);
1153                   UPDATE_PC_AND_TOS_AND_CONTINUE(4, 2);
1154 
1155               case Bytecodes::_astore:
1156                   astore(topOfStack, -1, locals, reg);
1157                   UPDATE_PC_AND_TOS_AND_CONTINUE(4, -1);
1158 
1159               case Bytecodes::_istore:
1160               case Bytecodes::_fstore:
1161                   SET_LOCALS_SLOT(STACK_SLOT(-1), reg);
1162                   UPDATE_PC_AND_TOS_AND_CONTINUE(4, -1);
1163 
1164               case Bytecodes::_lstore:
1165                   SET_LOCALS_LONG(STACK_LONG(-1), reg);
1166                   UPDATE_PC_AND_TOS_AND_CONTINUE(4, -2);
1167 
1168               case Bytecodes::_dstore:
1169                   SET_LOCALS_DOUBLE(STACK_DOUBLE(-1), reg);
1170                   UPDATE_PC_AND_TOS_AND_CONTINUE(4, -2);
1171 
1172               case Bytecodes::_iinc: {
1173                   int16_t offset = (int16_t)Bytes::get_Java_u2(pc+4);
1174                   // Be nice to see what this generates.... QQQ
1175                   SET_LOCALS_INT(LOCALS_INT(reg) + offset, reg);
1176                   UPDATE_PC_AND_CONTINUE(6);
1177               }
1178               case Bytecodes::_ret:
1179                   // Profile ret.
1180                   BI_PROFILE_UPDATE_RET(/*bci=*/((int)(intptr_t)(LOCALS_ADDR(reg))));
1181                   // Now, update the pc.
1182                   pc = istate->method()->code_base() + (intptr_t)(LOCALS_ADDR(reg));
1183                   UPDATE_PC_AND_CONTINUE(0);
1184               default:
1185                   VM_JAVA_ERROR(vmSymbols::java_lang_InternalError(), "undefined opcode", note_no_trap);
1186           }
1187       }
1188 
1189 
1190 #undef  OPC_STORE_n
1191 #define OPC_STORE_n(num)                                                \
1192       CASE(_astore_##num):                                              \
1193           astore(topOfStack, -1, locals, num);                          \
1194           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);                        \
1195       CASE(_istore_##num):                                              \
1196       CASE(_fstore_##num):                                              \
1197           SET_LOCALS_SLOT(STACK_SLOT(-1), num);                         \
1198           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1199 
1200           OPC_STORE_n(0);
1201           OPC_STORE_n(1);
1202           OPC_STORE_n(2);
1203           OPC_STORE_n(3);
1204 
1205 #undef  OPC_DSTORE_n
1206 #define OPC_DSTORE_n(num)                                               \
1207       CASE(_dstore_##num):                                              \
1208           SET_LOCALS_DOUBLE(STACK_DOUBLE(-1), num);                     \
1209           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2);                        \
1210       CASE(_lstore_##num):                                              \
1211           SET_LOCALS_LONG(STACK_LONG(-1), num);                         \
1212           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2);
1213 
1214           OPC_DSTORE_n(0);
1215           OPC_DSTORE_n(1);
1216           OPC_DSTORE_n(2);
1217           OPC_DSTORE_n(3);
1218 
1219           /* stack pop, dup, and insert opcodes */
1220 
1221 
1222       CASE(_pop):                /* Discard the top item on the stack */
1223           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1224 
1225 
1226       CASE(_pop2):               /* Discard the top 2 items on the stack */
1227           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2);
1228 
1229 
1230       CASE(_dup):               /* Duplicate the top item on the stack */
1231           dup(topOfStack);
1232           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1233 
1234       CASE(_dup2):              /* Duplicate the top 2 items on the stack */
1235           dup2(topOfStack);
1236           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1237 
1238       CASE(_dup_x1):    /* insert top word two down */
1239           dup_x1(topOfStack);
1240           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1241 
1242       CASE(_dup_x2):    /* insert top word three down  */
1243           dup_x2(topOfStack);
1244           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1245 
1246       CASE(_dup2_x1):   /* insert top 2 slots three down */
1247           dup2_x1(topOfStack);
1248           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1249 
1250       CASE(_dup2_x2):   /* insert top 2 slots four down */
1251           dup2_x2(topOfStack);
1252           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1253 
1254       CASE(_swap): {        /* swap top two elements on the stack */
1255           swap(topOfStack);
1256           UPDATE_PC_AND_CONTINUE(1);
1257       }
1258 
1259           /* Perform various binary integer operations */
1260 
1261 #undef  OPC_INT_BINARY
1262 #define OPC_INT_BINARY(opcname, opname, test)                           \
1263       CASE(_i##opcname):                                                \
1264           if (test && (STACK_INT(-1) == 0)) {                           \
1265               VM_JAVA_ERROR(vmSymbols::java_lang_ArithmeticException(), \
1266                             "/ by zero", note_div0Check_trap);          \
1267           }                                                             \
1268           SET_STACK_INT(VMint##opname(STACK_INT(-2),                    \
1269                                       STACK_INT(-1)),                   \
1270                                       -2);                              \
1271           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);                        \
1272       CASE(_l##opcname):                                                \
1273       {                                                                 \
1274           if (test) {                                                   \
1275             jlong l1 = STACK_LONG(-1);                                  \
1276             if (VMlongEqz(l1)) {                                        \
1277               VM_JAVA_ERROR(vmSymbols::java_lang_ArithmeticException(), \
1278                             "/ by long zero", note_div0Check_trap);     \
1279             }                                                           \
1280           }                                                             \
1281           /* First long at (-1,-2) next long at (-3,-4) */              \
1282           SET_STACK_LONG(VMlong##opname(STACK_LONG(-3),                 \
1283                                         STACK_LONG(-1)),                \
1284                                         -3);                            \
1285           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2);                        \
1286       }
1287 
1288       OPC_INT_BINARY(add, Add, 0);
1289       OPC_INT_BINARY(sub, Sub, 0);
1290       OPC_INT_BINARY(mul, Mul, 0);
1291       OPC_INT_BINARY(and, And, 0);
1292       OPC_INT_BINARY(or,  Or,  0);
1293       OPC_INT_BINARY(xor, Xor, 0);
1294       OPC_INT_BINARY(div, Div, 1);
1295       OPC_INT_BINARY(rem, Rem, 1);
1296 
1297 
1298       /* Perform various binary floating number operations */
1299       /* On some machine/platforms/compilers div zero check can be implicit */
1300 
1301 #undef  OPC_FLOAT_BINARY
1302 #define OPC_FLOAT_BINARY(opcname, opname)                                  \
1303       CASE(_d##opcname): {                                                 \
1304           SET_STACK_DOUBLE(VMdouble##opname(STACK_DOUBLE(-3),              \
1305                                             STACK_DOUBLE(-1)),             \
1306                                             -3);                           \
1307           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2);                           \
1308       }                                                                    \
1309       CASE(_f##opcname):                                                   \
1310           SET_STACK_FLOAT(VMfloat##opname(STACK_FLOAT(-2),                 \
1311                                           STACK_FLOAT(-1)),                \
1312                                           -2);                             \
1313           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1314 
1315 
1316      OPC_FLOAT_BINARY(add, Add);
1317      OPC_FLOAT_BINARY(sub, Sub);
1318      OPC_FLOAT_BINARY(mul, Mul);
1319      OPC_FLOAT_BINARY(div, Div);
1320      OPC_FLOAT_BINARY(rem, Rem);
1321 
1322       /* Shift operations
1323        * Shift left int and long: ishl, lshl
1324        * Logical shift right int and long w/zero extension: iushr, lushr
1325        * Arithmetic shift right int and long w/sign extension: ishr, lshr
1326        */
1327 
1328 #undef  OPC_SHIFT_BINARY
1329 #define OPC_SHIFT_BINARY(opcname, opname)                               \
1330       CASE(_i##opcname):                                                \
1331          SET_STACK_INT(VMint##opname(STACK_INT(-2),                     \
1332                                      STACK_INT(-1)),                    \
1333                                      -2);                               \
1334          UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);                         \
1335       CASE(_l##opcname):                                                \
1336       {                                                                 \
1337          SET_STACK_LONG(VMlong##opname(STACK_LONG(-2),                  \
1338                                        STACK_INT(-1)),                  \
1339                                        -2);                             \
1340          UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);                         \
1341       }
1342 
1343       OPC_SHIFT_BINARY(shl, Shl);
1344       OPC_SHIFT_BINARY(shr, Shr);
1345       OPC_SHIFT_BINARY(ushr, Ushr);
1346 
1347      /* Increment local variable by constant */
1348       CASE(_iinc):
1349       {
1350           // locals[pc[1]].j.i += (jbyte)(pc[2]);
1351           SET_LOCALS_INT(LOCALS_INT(pc[1]) + (jbyte)(pc[2]), pc[1]);
1352           UPDATE_PC_AND_CONTINUE(3);
1353       }
1354 
1355      /* negate the value on the top of the stack */
1356 
1357       CASE(_ineg):
1358          SET_STACK_INT(VMintNeg(STACK_INT(-1)), -1);
1359          UPDATE_PC_AND_CONTINUE(1);
1360 
1361       CASE(_fneg):
1362          SET_STACK_FLOAT(VMfloatNeg(STACK_FLOAT(-1)), -1);
1363          UPDATE_PC_AND_CONTINUE(1);
1364 
1365       CASE(_lneg):
1366       {
1367          SET_STACK_LONG(VMlongNeg(STACK_LONG(-1)), -1);
1368          UPDATE_PC_AND_CONTINUE(1);
1369       }
1370 
1371       CASE(_dneg):
1372       {
1373          SET_STACK_DOUBLE(VMdoubleNeg(STACK_DOUBLE(-1)), -1);
1374          UPDATE_PC_AND_CONTINUE(1);
1375       }
1376 
1377       /* Conversion operations */
1378 
1379       CASE(_i2f):       /* convert top of stack int to float */
1380          SET_STACK_FLOAT(VMint2Float(STACK_INT(-1)), -1);
1381          UPDATE_PC_AND_CONTINUE(1);
1382 
1383       CASE(_i2l):       /* convert top of stack int to long */
1384       {
1385           // this is ugly QQQ
1386           jlong r = VMint2Long(STACK_INT(-1));
1387           MORE_STACK(-1); // Pop
1388           SET_STACK_LONG(r, 1);
1389 
1390           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1391       }
1392 
1393       CASE(_i2d):       /* convert top of stack int to double */
1394       {
1395           // this is ugly QQQ (why cast to jlong?? )
1396           jdouble r = (jlong)STACK_INT(-1);
1397           MORE_STACK(-1); // Pop
1398           SET_STACK_DOUBLE(r, 1);
1399 
1400           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1401       }
1402 
1403       CASE(_l2i):       /* convert top of stack long to int */
1404       {
1405           jint r = VMlong2Int(STACK_LONG(-1));
1406           MORE_STACK(-2); // Pop
1407           SET_STACK_INT(r, 0);
1408           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1409       }
1410 
1411       CASE(_l2f):   /* convert top of stack long to float */
1412       {
1413           jlong r = STACK_LONG(-1);
1414           MORE_STACK(-2); // Pop
1415           SET_STACK_FLOAT(VMlong2Float(r), 0);
1416           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1417       }
1418 
1419       CASE(_l2d):       /* convert top of stack long to double */
1420       {
1421           jlong r = STACK_LONG(-1);
1422           MORE_STACK(-2); // Pop
1423           SET_STACK_DOUBLE(VMlong2Double(r), 1);
1424           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1425       }
1426 
1427       CASE(_f2i):  /* Convert top of stack float to int */
1428           SET_STACK_INT(SharedRuntime::f2i(STACK_FLOAT(-1)), -1);
1429           UPDATE_PC_AND_CONTINUE(1);
1430 
1431       CASE(_f2l):  /* convert top of stack float to long */
1432       {
1433           jlong r = SharedRuntime::f2l(STACK_FLOAT(-1));
1434           MORE_STACK(-1); // POP
1435           SET_STACK_LONG(r, 1);
1436           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1437       }
1438 
1439       CASE(_f2d):  /* convert top of stack float to double */
1440       {
1441           jfloat f;
1442           jdouble r;
1443           f = STACK_FLOAT(-1);
1444           r = (jdouble) f;
1445           MORE_STACK(-1); // POP
1446           SET_STACK_DOUBLE(r, 1);
1447           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1448       }
1449 
1450       CASE(_d2i): /* convert top of stack double to int */
1451       {
1452           jint r1 = SharedRuntime::d2i(STACK_DOUBLE(-1));
1453           MORE_STACK(-2);
1454           SET_STACK_INT(r1, 0);
1455           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1456       }
1457 
1458       CASE(_d2f): /* convert top of stack double to float */
1459       {
1460           jfloat r1 = VMdouble2Float(STACK_DOUBLE(-1));
1461           MORE_STACK(-2);
1462           SET_STACK_FLOAT(r1, 0);
1463           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1464       }
1465 
1466       CASE(_d2l): /* convert top of stack double to long */
1467       {
1468           jlong r1 = SharedRuntime::d2l(STACK_DOUBLE(-1));
1469           MORE_STACK(-2);
1470           SET_STACK_LONG(r1, 1);
1471           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1472       }
1473 
1474       CASE(_i2b):
1475           SET_STACK_INT(VMint2Byte(STACK_INT(-1)), -1);
1476           UPDATE_PC_AND_CONTINUE(1);
1477 
1478       CASE(_i2c):
1479           SET_STACK_INT(VMint2Char(STACK_INT(-1)), -1);
1480           UPDATE_PC_AND_CONTINUE(1);
1481 
1482       CASE(_i2s):
1483           SET_STACK_INT(VMint2Short(STACK_INT(-1)), -1);
1484           UPDATE_PC_AND_CONTINUE(1);
1485 
1486       /* comparison operators */
1487 
1488 
1489 #define COMPARISON_OP(name, comparison)                                      \
1490       CASE(_if_icmp##name): {                                                \
1491           const bool cmp = (STACK_INT(-2) comparison STACK_INT(-1));         \
1492           int skip = cmp                                                     \
1493                       ? (int16_t)Bytes::get_Java_u2(pc + 1) : 3;             \
1494           address branch_pc = pc;                                            \
1495           /* Profile branch. */                                              \
1496           BI_PROFILE_UPDATE_BRANCH(/*is_taken=*/cmp);                        \
1497           UPDATE_PC_AND_TOS(skip, -2);                                       \
1498           DO_BACKEDGE_CHECKS(skip, branch_pc);                               \
1499           CONTINUE;                                                          \
1500       }                                                                      \
1501       CASE(_if##name): {                                                     \
1502           const bool cmp = (STACK_INT(-1) comparison 0);                     \
1503           int skip = cmp                                                     \
1504                       ? (int16_t)Bytes::get_Java_u2(pc + 1) : 3;             \
1505           address branch_pc = pc;                                            \
1506           /* Profile branch. */                                              \
1507           BI_PROFILE_UPDATE_BRANCH(/*is_taken=*/cmp);                        \
1508           UPDATE_PC_AND_TOS(skip, -1);                                       \
1509           DO_BACKEDGE_CHECKS(skip, branch_pc);                               \
1510           CONTINUE;                                                          \
1511       }
1512 
1513 #define COMPARISON_OP2(name, comparison)                                     \
1514       COMPARISON_OP(name, comparison)                                        \
1515       CASE(_if_acmp##name): {                                                \
1516           const bool cmp = (STACK_OBJECT(-2) comparison STACK_OBJECT(-1));   \
1517           int skip = cmp                                                     \
1518                        ? (int16_t)Bytes::get_Java_u2(pc + 1) : 3;            \
1519           address branch_pc = pc;                                            \
1520           /* Profile branch. */                                              \
1521           BI_PROFILE_UPDATE_BRANCH(/*is_taken=*/cmp);                        \
1522           UPDATE_PC_AND_TOS(skip, -2);                                       \
1523           DO_BACKEDGE_CHECKS(skip, branch_pc);                               \
1524           CONTINUE;                                                          \
1525       }
1526 
1527 #define NULL_COMPARISON_NOT_OP(name)                                         \
1528       CASE(_if##name): {                                                     \
1529           const bool cmp = (!(STACK_OBJECT(-1) == NULL));                    \
1530           int skip = cmp                                                     \
1531                       ? (int16_t)Bytes::get_Java_u2(pc + 1) : 3;             \
1532           address branch_pc = pc;                                            \
1533           /* Profile branch. */                                              \
1534           BI_PROFILE_UPDATE_BRANCH(/*is_taken=*/cmp);                        \
1535           UPDATE_PC_AND_TOS(skip, -1);                                       \
1536           DO_BACKEDGE_CHECKS(skip, branch_pc);                               \
1537           CONTINUE;                                                          \
1538       }
1539 
1540 #define NULL_COMPARISON_OP(name)                                             \
1541       CASE(_if##name): {                                                     \
1542           const bool cmp = ((STACK_OBJECT(-1) == NULL));                     \
1543           int skip = cmp                                                     \
1544                       ? (int16_t)Bytes::get_Java_u2(pc + 1) : 3;             \
1545           address branch_pc = pc;                                            \
1546           /* Profile branch. */                                              \
1547           BI_PROFILE_UPDATE_BRANCH(/*is_taken=*/cmp);                        \
1548           UPDATE_PC_AND_TOS(skip, -1);                                       \
1549           DO_BACKEDGE_CHECKS(skip, branch_pc);                               \
1550           CONTINUE;                                                          \
1551       }
1552       COMPARISON_OP(lt, <);
1553       COMPARISON_OP(gt, >);
1554       COMPARISON_OP(le, <=);
1555       COMPARISON_OP(ge, >=);
1556       COMPARISON_OP2(eq, ==);  /* include ref comparison */
1557       COMPARISON_OP2(ne, !=);  /* include ref comparison */
1558       NULL_COMPARISON_OP(null);
1559       NULL_COMPARISON_NOT_OP(nonnull);
1560 
1561       /* Goto pc at specified offset in switch table. */
1562 
1563       CASE(_tableswitch): {
1564           jint* lpc  = (jint*)VMalignWordUp(pc+1);
1565           int32_t  key  = STACK_INT(-1);
1566           int32_t  low  = Bytes::get_Java_u4((address)&lpc[1]);
1567           int32_t  high = Bytes::get_Java_u4((address)&lpc[2]);
1568           int32_t  skip;
1569           key -= low;
1570           if (((uint32_t) key > (uint32_t)(high - low))) {
1571             key = -1;
1572             skip = Bytes::get_Java_u4((address)&lpc[0]);
1573           } else {
1574             skip = Bytes::get_Java_u4((address)&lpc[key + 3]);
1575           }
1576           // Profile switch.
1577           BI_PROFILE_UPDATE_SWITCH(/*switch_index=*/key);
1578           // Does this really need a full backedge check (osr)?
1579           address branch_pc = pc;
1580           UPDATE_PC_AND_TOS(skip, -1);
1581           DO_BACKEDGE_CHECKS(skip, branch_pc);
1582           CONTINUE;
1583       }
1584 
1585       /* Goto pc whose table entry matches specified key. */
1586 
1587       CASE(_lookupswitch): {
1588           jint* lpc  = (jint*)VMalignWordUp(pc+1);
1589           int32_t  key  = STACK_INT(-1);
1590           int32_t  skip = Bytes::get_Java_u4((address) lpc); /* default amount */
1591           // Remember index.
1592           int      index = -1;
1593           int      newindex = 0;
1594           int32_t  npairs = Bytes::get_Java_u4((address) &lpc[1]);
1595           while (--npairs >= 0) {
1596             lpc += 2;
1597             if (key == (int32_t)Bytes::get_Java_u4((address)lpc)) {
1598               skip = Bytes::get_Java_u4((address)&lpc[1]);
1599               index = newindex;
1600               break;
1601             }
1602             newindex += 1;
1603           }
1604           // Profile switch.
1605           BI_PROFILE_UPDATE_SWITCH(/*switch_index=*/index);
1606           address branch_pc = pc;
1607           UPDATE_PC_AND_TOS(skip, -1);
1608           DO_BACKEDGE_CHECKS(skip, branch_pc);
1609           CONTINUE;
1610       }
1611 
1612       CASE(_fcmpl):
1613       CASE(_fcmpg):
1614       {
1615           SET_STACK_INT(VMfloatCompare(STACK_FLOAT(-2),
1616                                         STACK_FLOAT(-1),
1617                                         (opcode == Bytecodes::_fcmpl ? -1 : 1)),
1618                         -2);
1619           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1620       }
1621 
1622       CASE(_dcmpl):
1623       CASE(_dcmpg):
1624       {
1625           int r = VMdoubleCompare(STACK_DOUBLE(-3),
1626                                   STACK_DOUBLE(-1),
1627                                   (opcode == Bytecodes::_dcmpl ? -1 : 1));
1628           MORE_STACK(-4); // Pop
1629           SET_STACK_INT(r, 0);
1630           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1631       }
1632 
1633       CASE(_lcmp):
1634       {
1635           int r = VMlongCompare(STACK_LONG(-3), STACK_LONG(-1));
1636           MORE_STACK(-4);
1637           SET_STACK_INT(r, 0);
1638           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1639       }
1640 
1641 
1642       /* Return from a method */
1643 
1644       CASE(_areturn):
1645       CASE(_ireturn):
1646       CASE(_freturn):
1647       {
1648           // Allow a safepoint before returning to frame manager.
1649           SAFEPOINT;
1650 
1651           goto handle_return;
1652       }
1653 
1654       CASE(_lreturn):
1655       CASE(_dreturn):
1656       {
1657           // Allow a safepoint before returning to frame manager.
1658           SAFEPOINT;
1659           goto handle_return;
1660       }
1661 
1662       CASE(_return_register_finalizer): {
1663 
1664           oop rcvr = LOCALS_OBJECT(0);
1665           VERIFY_OOP(rcvr);
1666           if (rcvr->klass()->has_finalizer()) {
1667             CALL_VM(InterpreterRuntime::register_finalizer(THREAD, rcvr), handle_exception);
1668           }
1669           goto handle_return;
1670       }
1671       CASE(_return): {
1672 
1673           // Allow a safepoint before returning to frame manager.
1674           SAFEPOINT;
1675           goto handle_return;
1676       }
1677 
1678       /* Array access byte-codes */
1679 
1680       /* Every array access byte-code starts out like this */
1681 //        arrayOopDesc* arrObj = (arrayOopDesc*)STACK_OBJECT(arrayOff);
1682 #define ARRAY_INTRO(arrayOff)                                                  \
1683       arrayOop arrObj = (arrayOop)STACK_OBJECT(arrayOff);                      \
1684       jint     index  = STACK_INT(arrayOff + 1);                               \
1685       char message[jintAsStringSize];                                          \
1686       CHECK_NULL(arrObj);                                                      \
1687       if ((uint32_t)index >= (uint32_t)arrObj->length()) {                     \
1688           sprintf(message, "%d", index);                                       \
1689           VM_JAVA_ERROR(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), \
1690                         message, note_rangeCheck_trap);                        \
1691       }
1692 
1693       /* 32-bit loads. These handle conversion from < 32-bit types */
1694 #define ARRAY_LOADTO32(T, T2, format, stackRes, extra)                                \
1695       {                                                                               \
1696           ARRAY_INTRO(-2);                                                            \
1697           (void)extra;                                                                \
1698           SET_ ## stackRes(*(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)), \
1699                            -2);                                                       \
1700           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);                                      \
1701       }
1702 
1703       /* 64-bit loads */
1704 #define ARRAY_LOADTO64(T,T2, stackRes, extra)                                              \
1705       {                                                                                    \
1706           ARRAY_INTRO(-2);                                                                 \
1707           SET_ ## stackRes(*(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)), -1); \
1708           (void)extra;                                                                     \
1709           UPDATE_PC_AND_CONTINUE(1);                                                       \
1710       }
1711 
1712       CASE(_iaload):
1713           ARRAY_LOADTO32(T_INT, jint,   "%d",   STACK_INT, 0);
1714       CASE(_faload):
1715           ARRAY_LOADTO32(T_FLOAT, jfloat, "%f",   STACK_FLOAT, 0);
1716       CASE(_aaload): {
1717           ARRAY_INTRO(-2);
1718           SET_STACK_OBJECT(((objArrayOop) arrObj)->obj_at(index), -2);
1719           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1720       }
1721       CASE(_baload):
1722           ARRAY_LOADTO32(T_BYTE, jbyte,  "%d",   STACK_INT, 0);
1723       CASE(_caload):
1724           ARRAY_LOADTO32(T_CHAR,  jchar, "%d",   STACK_INT, 0);
1725       CASE(_saload):
1726           ARRAY_LOADTO32(T_SHORT, jshort, "%d",   STACK_INT, 0);
1727       CASE(_laload):
1728           ARRAY_LOADTO64(T_LONG, jlong, STACK_LONG, 0);
1729       CASE(_daload):
1730           ARRAY_LOADTO64(T_DOUBLE, jdouble, STACK_DOUBLE, 0);
1731 
1732       /* 32-bit stores. These handle conversion to < 32-bit types */
1733 #define ARRAY_STOREFROM32(T, T2, format, stackSrc, extra)                            \
1734       {                                                                              \
1735           ARRAY_INTRO(-3);                                                           \
1736           (void)extra;                                                               \
1737           *(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)) = stackSrc( -1); \
1738           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -3);                                     \
1739       }
1740 
1741       /* 64-bit stores */
1742 #define ARRAY_STOREFROM64(T, T2, stackSrc, extra)                                    \
1743       {                                                                              \
1744           ARRAY_INTRO(-4);                                                           \
1745           (void)extra;                                                               \
1746           *(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)) = stackSrc( -1); \
1747           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -4);                                     \
1748       }
1749 
1750       CASE(_iastore):
1751           ARRAY_STOREFROM32(T_INT, jint,   "%d",   STACK_INT, 0);
1752       CASE(_fastore):
1753           ARRAY_STOREFROM32(T_FLOAT, jfloat, "%f",   STACK_FLOAT, 0);
1754       /*
1755        * This one looks different because of the assignability check
1756        */
1757       CASE(_aastore): {
1758           oop rhsObject = STACK_OBJECT(-1);
1759           VERIFY_OOP(rhsObject);
1760           ARRAY_INTRO( -3);
1761           // arrObj, index are set
1762           if (rhsObject != NULL) {
1763             /* Check assignability of rhsObject into arrObj */
1764             Klass* rhsKlass = rhsObject->klass(); // EBX (subclass)
1765             Klass* elemKlass = ObjArrayKlass::cast(arrObj->klass())->element_klass(); // superklass EAX
1766             //
1767             // Check for compatibilty. This check must not GC!!
1768             // Seems way more expensive now that we must dispatch
1769             //
1770             if (rhsKlass != elemKlass && !rhsKlass->is_subtype_of(elemKlass)) { // ebx->is...
1771               // Decrement counter if subtype check failed.
1772               BI_PROFILE_SUBTYPECHECK_FAILED(rhsKlass);
1773               VM_JAVA_ERROR(vmSymbols::java_lang_ArrayStoreException(), "", note_arrayCheck_trap);
1774             }
1775             // Profile checkcast with null_seen and receiver.
1776             BI_PROFILE_UPDATE_CHECKCAST(/*null_seen=*/false, rhsKlass);
1777           } else {
1778             // Profile checkcast with null_seen and receiver.
1779             BI_PROFILE_UPDATE_CHECKCAST(/*null_seen=*/true, NULL);
1780           }
1781           ((objArrayOop) arrObj)->obj_at_put(index, rhsObject);
1782           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -3);
1783       }
1784       CASE(_bastore):
1785           ARRAY_STOREFROM32(T_BYTE, jbyte,  "%d",   STACK_INT, 0);
1786       CASE(_castore):
1787           ARRAY_STOREFROM32(T_CHAR, jchar,  "%d",   STACK_INT, 0);
1788       CASE(_sastore):
1789           ARRAY_STOREFROM32(T_SHORT, jshort, "%d",   STACK_INT, 0);
1790       CASE(_lastore):
1791           ARRAY_STOREFROM64(T_LONG, jlong, STACK_LONG, 0);
1792       CASE(_dastore):
1793           ARRAY_STOREFROM64(T_DOUBLE, jdouble, STACK_DOUBLE, 0);
1794 
1795       CASE(_arraylength):
1796       {
1797           arrayOop ary = (arrayOop) STACK_OBJECT(-1);
1798           CHECK_NULL(ary);
1799           SET_STACK_INT(ary->length(), -1);
1800           UPDATE_PC_AND_CONTINUE(1);
1801       }
1802 
1803       /* monitorenter and monitorexit for locking/unlocking an object */
1804 
1805       CASE(_monitorenter): {
1806         oop lockee = STACK_OBJECT(-1);
1807         // derefing's lockee ought to provoke implicit null check
1808         CHECK_NULL(lockee);
1809         // find a free monitor or one already allocated for this object
1810         // if we find a matching object then we need a new monitor
1811         // since this is recursive enter
1812         BasicObjectLock* limit = istate->monitor_base();
1813         BasicObjectLock* most_recent = (BasicObjectLock*) istate->stack_base();
1814         BasicObjectLock* entry = NULL;
1815         while (most_recent != limit ) {
1816           if (most_recent->obj() == NULL) entry = most_recent;
1817           else if (most_recent->obj() == lockee) break;
1818           most_recent++;
1819         }
1820         if (entry != NULL) {
1821           entry->set_obj(lockee);
1822           int success = false;
1823           uintptr_t epoch_mask_in_place = (uintptr_t)markOopDesc::epoch_mask_in_place;
1824 
1825           markOop mark = lockee->mark();
1826           intptr_t hash = (intptr_t) markOopDesc::no_hash;
1827           // implies UseBiasedLocking
1828           if (mark->has_bias_pattern()) {
1829             uintptr_t thread_ident;
1830             uintptr_t anticipated_bias_locking_value;
1831             thread_ident = (uintptr_t)istate->thread();
1832             anticipated_bias_locking_value =
1833               (((uintptr_t)lockee->klass()->prototype_header() | thread_ident) ^ (uintptr_t)mark) &
1834               ~((uintptr_t) markOopDesc::age_mask_in_place);
1835 
1836             if  (anticipated_bias_locking_value == 0) {
1837               // already biased towards this thread, nothing to do
1838               if (PrintBiasedLockingStatistics) {
1839                 (* BiasedLocking::biased_lock_entry_count_addr())++;
1840               }
1841               success = true;
1842             }
1843             else if ((anticipated_bias_locking_value & markOopDesc::biased_lock_mask_in_place) != 0) {
1844               // try revoke bias
1845               markOop header = lockee->klass()->prototype_header();
1846               if (hash != markOopDesc::no_hash) {
1847                 header = header->copy_set_hash(hash);
1848               }
1849               if (Atomic::cmpxchg_ptr(header, lockee->mark_addr(), mark) == mark) {
1850                 if (PrintBiasedLockingStatistics)
1851                   (*BiasedLocking::revoked_lock_entry_count_addr())++;
1852               }
1853             }
1854             else if ((anticipated_bias_locking_value & epoch_mask_in_place) !=0) {
1855               // try rebias
1856               markOop new_header = (markOop) ( (intptr_t) lockee->klass()->prototype_header() | thread_ident);
1857               if (hash != markOopDesc::no_hash) {
1858                 new_header = new_header->copy_set_hash(hash);
1859               }
1860               if (Atomic::cmpxchg_ptr((void*)new_header, lockee->mark_addr(), mark) == mark) {
1861                 if (PrintBiasedLockingStatistics)
1862                   (* BiasedLocking::rebiased_lock_entry_count_addr())++;
1863               }
1864               else {
1865                 CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
1866               }
1867               success = true;
1868             }
1869             else {
1870               // try to bias towards thread in case object is anonymously biased
1871               markOop header = (markOop) ((uintptr_t) mark & ((uintptr_t)markOopDesc::biased_lock_mask_in_place |
1872                                                               (uintptr_t)markOopDesc::age_mask_in_place |
1873                                                               epoch_mask_in_place));
1874               if (hash != markOopDesc::no_hash) {
1875                 header = header->copy_set_hash(hash);
1876               }
1877               markOop new_header = (markOop) ((uintptr_t) header | thread_ident);
1878               // debugging hint
1879               DEBUG_ONLY(entry->lock()->set_displaced_header((markOop) (uintptr_t) 0xdeaddead);)
1880               if (Atomic::cmpxchg_ptr((void*)new_header, lockee->mark_addr(), header) == header) {
1881                 if (PrintBiasedLockingStatistics)
1882                   (* BiasedLocking::anonymously_biased_lock_entry_count_addr())++;
1883               }
1884               else {
1885                 CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
1886               }
1887               success = true;
1888             }
1889           }
1890 
1891           // traditional lightweight locking
1892           if (!success) {
1893             markOop displaced = lockee->mark()->set_unlocked();
1894             entry->lock()->set_displaced_header(displaced);
1895             bool call_vm = UseHeavyMonitors;
1896             if (call_vm || Atomic::cmpxchg_ptr(entry, lockee->mark_addr(), displaced) != displaced) {
1897               // Is it simple recursive case?
1898               if (!call_vm && THREAD->is_lock_owned((address) displaced->clear_lock_bits())) {
1899                 entry->lock()->set_displaced_header(NULL);
1900               } else {
1901                 CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
1902               }
1903             }
1904           }
1905           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1906         } else {
1907           istate->set_msg(more_monitors);
1908           UPDATE_PC_AND_RETURN(0); // Re-execute
1909         }
1910       }
1911 
1912       CASE(_monitorexit): {
1913         oop lockee = STACK_OBJECT(-1);
1914         CHECK_NULL(lockee);
1915         // derefing's lockee ought to provoke implicit null check
1916         // find our monitor slot
1917         BasicObjectLock* limit = istate->monitor_base();
1918         BasicObjectLock* most_recent = (BasicObjectLock*) istate->stack_base();
1919         while (most_recent != limit ) {
1920           if ((most_recent)->obj() == lockee) {
1921             BasicLock* lock = most_recent->lock();
1922             markOop header = lock->displaced_header();
1923             most_recent->set_obj(NULL);
1924             if (!lockee->mark()->has_bias_pattern()) {
1925               bool call_vm = UseHeavyMonitors;
1926               // If it isn't recursive we either must swap old header or call the runtime
1927               if (header != NULL || call_vm) {
1928                 if (call_vm || Atomic::cmpxchg_ptr(header, lockee->mark_addr(), lock) != lock) {
1929                   // restore object for the slow case
1930                   most_recent->set_obj(lockee);
1931                   CALL_VM(InterpreterRuntime::monitorexit(THREAD, most_recent), handle_exception);
1932                 }
1933               }
1934             }
1935             UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1936           }
1937           most_recent++;
1938         }
1939         // Need to throw illegal monitor state exception
1940         CALL_VM(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD), handle_exception);
1941         ShouldNotReachHere();
1942       }
1943 
1944       /* All of the non-quick opcodes. */
1945 
1946       /* -Set clobbersCpIndex true if the quickened opcode clobbers the
1947        *  constant pool index in the instruction.
1948        */
1949       CASE(_getfield):
1950       CASE(_getstatic):
1951         {
1952           u2 index;
1953           ConstantPoolCacheEntry* cache;
1954           index = Bytes::get_native_u2(pc+1);
1955 
1956           // QQQ Need to make this as inlined as possible. Probably need to
1957           // split all the bytecode cases out so c++ compiler has a chance
1958           // for constant prop to fold everything possible away.
1959 
1960           cache = cp->entry_at(index);
1961           if (!cache->is_resolved((Bytecodes::Code)opcode)) {
1962             CALL_VM(InterpreterRuntime::resolve_get_put(THREAD, (Bytecodes::Code)opcode),
1963                     handle_exception);
1964             cache = cp->entry_at(index);
1965           }
1966 
1967 #ifdef VM_JVMTI
1968           if (_jvmti_interp_events) {
1969             int *count_addr;
1970             oop obj;
1971             // Check to see if a field modification watch has been set
1972             // before we take the time to call into the VM.
1973             count_addr = (int *)JvmtiExport::get_field_access_count_addr();
1974             if ( *count_addr > 0 ) {
1975               if ((Bytecodes::Code)opcode == Bytecodes::_getstatic) {
1976                 obj = (oop)NULL;
1977               } else {
1978                 obj = (oop) STACK_OBJECT(-1);
1979                 VERIFY_OOP(obj);
1980               }
1981               CALL_VM(InterpreterRuntime::post_field_access(THREAD,
1982                                           obj,
1983                                           cache),
1984                                           handle_exception);
1985             }
1986           }
1987 #endif /* VM_JVMTI */
1988 
1989           oop obj;
1990           if ((Bytecodes::Code)opcode == Bytecodes::_getstatic) {
1991             Klass* k = cache->f1_as_klass();
1992             obj = k->java_mirror();
1993             MORE_STACK(1);  // Assume single slot push
1994           } else {
1995             obj = (oop) STACK_OBJECT(-1);
1996             CHECK_NULL(obj);
1997           }
1998 
1999           //
2000           // Now store the result on the stack
2001           //
2002           TosState tos_type = cache->flag_state();
2003           int field_offset = cache->f2_as_index();
2004           if (cache->is_volatile()) {
2005             if (support_IRIW_for_not_multiple_copy_atomic_cpu) {
2006               OrderAccess::fence();
2007             }
2008             if (tos_type == atos) {
2009               VERIFY_OOP(obj->obj_field_acquire(field_offset));
2010               SET_STACK_OBJECT(obj->obj_field_acquire(field_offset), -1);
2011             } else if (tos_type == itos) {
2012               SET_STACK_INT(obj->int_field_acquire(field_offset), -1);
2013             } else if (tos_type == ltos) {
2014               SET_STACK_LONG(obj->long_field_acquire(field_offset), 0);
2015               MORE_STACK(1);
2016             } else if (tos_type == btos) {
2017               SET_STACK_INT(obj->byte_field_acquire(field_offset), -1);
2018             } else if (tos_type == ctos) {
2019               SET_STACK_INT(obj->char_field_acquire(field_offset), -1);
2020             } else if (tos_type == stos) {
2021               SET_STACK_INT(obj->short_field_acquire(field_offset), -1);
2022             } else if (tos_type == ftos) {
2023               SET_STACK_FLOAT(obj->float_field_acquire(field_offset), -1);
2024             } else {
2025               SET_STACK_DOUBLE(obj->double_field_acquire(field_offset), 0);
2026               MORE_STACK(1);
2027             }
2028           } else {
2029             if (tos_type == atos) {
2030               VERIFY_OOP(obj->obj_field(field_offset));
2031               SET_STACK_OBJECT(obj->obj_field(field_offset), -1);
2032             } else if (tos_type == itos) {
2033               SET_STACK_INT(obj->int_field(field_offset), -1);
2034             } else if (tos_type == ltos) {
2035               SET_STACK_LONG(obj->long_field(field_offset), 0);
2036               MORE_STACK(1);
2037             } else if (tos_type == btos) {
2038               SET_STACK_INT(obj->byte_field(field_offset), -1);
2039             } else if (tos_type == ctos) {
2040               SET_STACK_INT(obj->char_field(field_offset), -1);
2041             } else if (tos_type == stos) {
2042               SET_STACK_INT(obj->short_field(field_offset), -1);
2043             } else if (tos_type == ftos) {
2044               SET_STACK_FLOAT(obj->float_field(field_offset), -1);
2045             } else {
2046               SET_STACK_DOUBLE(obj->double_field(field_offset), 0);
2047               MORE_STACK(1);
2048             }
2049           }
2050 
2051           UPDATE_PC_AND_CONTINUE(3);
2052          }
2053 
2054       CASE(_putfield):
2055       CASE(_putstatic):
2056         {
2057           u2 index = Bytes::get_native_u2(pc+1);
2058           ConstantPoolCacheEntry* cache = cp->entry_at(index);
2059           if (!cache->is_resolved((Bytecodes::Code)opcode)) {
2060             CALL_VM(InterpreterRuntime::resolve_get_put(THREAD, (Bytecodes::Code)opcode),
2061                     handle_exception);
2062             cache = cp->entry_at(index);
2063           }
2064 
2065 #ifdef VM_JVMTI
2066           if (_jvmti_interp_events) {
2067             int *count_addr;
2068             oop obj;
2069             // Check to see if a field modification watch has been set
2070             // before we take the time to call into the VM.
2071             count_addr = (int *)JvmtiExport::get_field_modification_count_addr();
2072             if ( *count_addr > 0 ) {
2073               if ((Bytecodes::Code)opcode == Bytecodes::_putstatic) {
2074                 obj = (oop)NULL;
2075               }
2076               else {
2077                 if (cache->is_long() || cache->is_double()) {
2078                   obj = (oop) STACK_OBJECT(-3);
2079                 } else {
2080                   obj = (oop) STACK_OBJECT(-2);
2081                 }
2082                 VERIFY_OOP(obj);
2083               }
2084 
2085               CALL_VM(InterpreterRuntime::post_field_modification(THREAD,
2086                                           obj,
2087                                           cache,
2088                                           (jvalue *)STACK_SLOT(-1)),
2089                                           handle_exception);
2090             }
2091           }
2092 #endif /* VM_JVMTI */
2093 
2094           // QQQ Need to make this as inlined as possible. Probably need to split all the bytecode cases
2095           // out so c++ compiler has a chance for constant prop to fold everything possible away.
2096 
2097           oop obj;
2098           int count;
2099           TosState tos_type = cache->flag_state();
2100 
2101           count = -1;
2102           if (tos_type == ltos || tos_type == dtos) {
2103             --count;
2104           }
2105           if ((Bytecodes::Code)opcode == Bytecodes::_putstatic) {
2106             Klass* k = cache->f1_as_klass();
2107             obj = k->java_mirror();
2108           } else {
2109             --count;
2110             obj = (oop) STACK_OBJECT(count);
2111             CHECK_NULL(obj);
2112           }
2113 
2114           //
2115           // Now store the result
2116           //
2117           int field_offset = cache->f2_as_index();
2118           if (cache->is_volatile()) {
2119             if (tos_type == itos) {
2120               obj->release_int_field_put(field_offset, STACK_INT(-1));
2121             } else if (tos_type == atos) {
2122               VERIFY_OOP(STACK_OBJECT(-1));
2123               obj->release_obj_field_put(field_offset, STACK_OBJECT(-1));
2124             } else if (tos_type == btos) {
2125               obj->release_byte_field_put(field_offset, STACK_INT(-1));
2126             } else if (tos_type == ltos) {
2127               obj->release_long_field_put(field_offset, STACK_LONG(-1));
2128             } else if (tos_type == ctos) {
2129               obj->release_char_field_put(field_offset, STACK_INT(-1));
2130             } else if (tos_type == stos) {
2131               obj->release_short_field_put(field_offset, STACK_INT(-1));
2132             } else if (tos_type == ftos) {
2133               obj->release_float_field_put(field_offset, STACK_FLOAT(-1));
2134             } else {
2135               obj->release_double_field_put(field_offset, STACK_DOUBLE(-1));
2136             }
2137             OrderAccess::storeload();
2138           } else {
2139             if (tos_type == itos) {
2140               obj->int_field_put(field_offset, STACK_INT(-1));
2141             } else if (tos_type == atos) {
2142               VERIFY_OOP(STACK_OBJECT(-1));
2143               obj->obj_field_put(field_offset, STACK_OBJECT(-1));
2144             } else if (tos_type == btos) {
2145               obj->byte_field_put(field_offset, STACK_INT(-1));
2146             } else if (tos_type == ltos) {
2147               obj->long_field_put(field_offset, STACK_LONG(-1));
2148             } else if (tos_type == ctos) {
2149               obj->char_field_put(field_offset, STACK_INT(-1));
2150             } else if (tos_type == stos) {
2151               obj->short_field_put(field_offset, STACK_INT(-1));
2152             } else if (tos_type == ftos) {
2153               obj->float_field_put(field_offset, STACK_FLOAT(-1));
2154             } else {
2155               obj->double_field_put(field_offset, STACK_DOUBLE(-1));
2156             }
2157           }
2158 
2159           UPDATE_PC_AND_TOS_AND_CONTINUE(3, count);
2160         }
2161 
2162       CASE(_new): {
2163         u2 index = Bytes::get_Java_u2(pc+1);
2164         ConstantPool* constants = istate->method()->constants();
2165         if (!constants->tag_at(index).is_unresolved_klass()) {
2166           // Make sure klass is initialized and doesn't have a finalizer
2167           Klass* entry = constants->slot_at(index).get_klass();
2168           assert(entry->is_klass(), "Should be resolved klass");
2169           Klass* k_entry = (Klass*) entry;
2170           assert(k_entry->oop_is_instance(), "Should be InstanceKlass");
2171           InstanceKlass* ik = (InstanceKlass*) k_entry;
2172           if ( ik->is_initialized() && ik->can_be_fastpath_allocated() ) {
2173             size_t obj_size = ik->size_helper();
2174             oop result = NULL;
2175             // If the TLAB isn't pre-zeroed then we'll have to do it
2176             bool need_zero = !ZeroTLAB;
2177             if (UseTLAB) {
2178               result = (oop) THREAD->tlab().allocate(obj_size);
2179             }
2180             // Disable non-TLAB-based fast-path, because profiling requires that all
2181             // allocations go through InterpreterRuntime::_new() if THREAD->tlab().allocate
2182             // returns NULL.
2183 #ifndef CC_INTERP_PROFILE
2184             if (result == NULL) {
2185               need_zero = true;
2186               // Try allocate in shared eden
2187             retry:
2188               HeapWord* compare_to = *Universe::heap()->top_addr();
2189               HeapWord* new_top = compare_to + obj_size;
2190               if (new_top <= *Universe::heap()->end_addr()) {
2191                 if (Atomic::cmpxchg_ptr(new_top, Universe::heap()->top_addr(), compare_to) != compare_to) {
2192                   goto retry;
2193                 }
2194                 result = (oop) compare_to;
2195               }
2196             }
2197 #endif
2198             if (result != NULL) {
2199               // Initialize object (if nonzero size and need) and then the header
2200               if (need_zero ) {
2201                 HeapWord* to_zero = (HeapWord*) result + sizeof(oopDesc) / oopSize;
2202                 obj_size -= sizeof(oopDesc) / oopSize;
2203                 if (obj_size > 0 ) {
2204                   memset(to_zero, 0, obj_size * HeapWordSize);
2205                 }
2206               }
2207               if (UseBiasedLocking) {
2208                 result->set_mark(ik->prototype_header());
2209               } else {
2210                 result->set_mark(markOopDesc::prototype());
2211               }
2212               result->set_klass_gap(0);
2213               result->set_klass(k_entry);
2214               // Must prevent reordering of stores for object initialization
2215               // with stores that publish the new object.
2216               OrderAccess::storestore();
2217               SET_STACK_OBJECT(result, 0);
2218               UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1);
2219             }
2220           }
2221         }
2222         // Slow case allocation
2223         CALL_VM(InterpreterRuntime::_new(THREAD, METHOD->constants(), index),
2224                 handle_exception);
2225         // Must prevent reordering of stores for object initialization
2226         // with stores that publish the new object.
2227         OrderAccess::storestore();
2228         SET_STACK_OBJECT(THREAD->vm_result(), 0);
2229         THREAD->set_vm_result(NULL);
2230         UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1);
2231       }
2232       CASE(_anewarray): {
2233         u2 index = Bytes::get_Java_u2(pc+1);
2234         jint size = STACK_INT(-1);
2235         CALL_VM(InterpreterRuntime::anewarray(THREAD, METHOD->constants(), index, size),
2236                 handle_exception);
2237         // Must prevent reordering of stores for object initialization
2238         // with stores that publish the new object.
2239         OrderAccess::storestore();
2240         SET_STACK_OBJECT(THREAD->vm_result(), -1);
2241         THREAD->set_vm_result(NULL);
2242         UPDATE_PC_AND_CONTINUE(3);
2243       }
2244       CASE(_multianewarray): {
2245         jint dims = *(pc+3);
2246         jint size = STACK_INT(-1);
2247         // stack grows down, dimensions are up!
2248         jint *dimarray =
2249                    (jint*)&topOfStack[dims * Interpreter::stackElementWords+
2250                                       Interpreter::stackElementWords-1];
2251         //adjust pointer to start of stack element
2252         CALL_VM(InterpreterRuntime::multianewarray(THREAD, dimarray),
2253                 handle_exception);
2254         // Must prevent reordering of stores for object initialization
2255         // with stores that publish the new object.
2256         OrderAccess::storestore();
2257         SET_STACK_OBJECT(THREAD->vm_result(), -dims);
2258         THREAD->set_vm_result(NULL);
2259         UPDATE_PC_AND_TOS_AND_CONTINUE(4, -(dims-1));
2260       }
2261       CASE(_checkcast):
2262           if (STACK_OBJECT(-1) != NULL) {
2263             VERIFY_OOP(STACK_OBJECT(-1));
2264             u2 index = Bytes::get_Java_u2(pc+1);
2265             // Constant pool may have actual klass or unresolved klass. If it is
2266             // unresolved we must resolve it.
2267             if (METHOD->constants()->tag_at(index).is_unresolved_klass()) {
2268               CALL_VM(InterpreterRuntime::quicken_io_cc(THREAD), handle_exception);
2269             }
2270             Klass* klassOf = (Klass*) METHOD->constants()->slot_at(index).get_klass();
2271             Klass* objKlass = STACK_OBJECT(-1)->klass(); // ebx
2272             //
2273             // Check for compatibilty. This check must not GC!!
2274             // Seems way more expensive now that we must dispatch.
2275             //
2276             if (objKlass != klassOf && !objKlass->is_subtype_of(klassOf)) {
2277               // Decrement counter at checkcast.
2278               BI_PROFILE_SUBTYPECHECK_FAILED(objKlass);
2279               ResourceMark rm(THREAD);
2280               const char* objName = objKlass->external_name();
2281               const char* klassName = klassOf->external_name();
2282               char* message = SharedRuntime::generate_class_cast_message(
2283                 objName, klassName);
2284               VM_JAVA_ERROR(vmSymbols::java_lang_ClassCastException(), message, note_classCheck_trap);
2285             }
2286             // Profile checkcast with null_seen and receiver.
2287             BI_PROFILE_UPDATE_CHECKCAST(/*null_seen=*/false, objKlass);
2288           } else {
2289             // Profile checkcast with null_seen and receiver.
2290             BI_PROFILE_UPDATE_CHECKCAST(/*null_seen=*/true, NULL);
2291           }
2292           UPDATE_PC_AND_CONTINUE(3);
2293 
2294       CASE(_instanceof):
2295           if (STACK_OBJECT(-1) == NULL) {
2296             SET_STACK_INT(0, -1);
2297             // Profile instanceof with null_seen and receiver.
2298             BI_PROFILE_UPDATE_INSTANCEOF(/*null_seen=*/true, NULL);
2299           } else {
2300             VERIFY_OOP(STACK_OBJECT(-1));
2301             u2 index = Bytes::get_Java_u2(pc+1);
2302             // Constant pool may have actual klass or unresolved klass. If it is
2303             // unresolved we must resolve it.
2304             if (METHOD->constants()->tag_at(index).is_unresolved_klass()) {
2305               CALL_VM(InterpreterRuntime::quicken_io_cc(THREAD), handle_exception);
2306             }
2307             Klass* klassOf = (Klass*) METHOD->constants()->slot_at(index).get_klass();
2308             Klass* objKlass = STACK_OBJECT(-1)->klass();
2309             //
2310             // Check for compatibilty. This check must not GC!!
2311             // Seems way more expensive now that we must dispatch.
2312             //
2313             if ( objKlass == klassOf || objKlass->is_subtype_of(klassOf)) {
2314               SET_STACK_INT(1, -1);
2315             } else {
2316               SET_STACK_INT(0, -1);
2317               // Decrement counter at checkcast.
2318               BI_PROFILE_SUBTYPECHECK_FAILED(objKlass);
2319             }
2320             // Profile instanceof with null_seen and receiver.
2321             BI_PROFILE_UPDATE_INSTANCEOF(/*null_seen=*/false, objKlass);
2322           }
2323           UPDATE_PC_AND_CONTINUE(3);
2324 
2325       CASE(_ldc_w):
2326       CASE(_ldc):
2327         {
2328           u2 index;
2329           bool wide = false;
2330           int incr = 2; // frequent case
2331           if (opcode == Bytecodes::_ldc) {
2332             index = pc[1];
2333           } else {
2334             index = Bytes::get_Java_u2(pc+1);
2335             incr = 3;
2336             wide = true;
2337           }
2338 
2339           ConstantPool* constants = METHOD->constants();
2340           switch (constants->tag_at(index).value()) {
2341           case JVM_CONSTANT_Integer:
2342             SET_STACK_INT(constants->int_at(index), 0);
2343             break;
2344 
2345           case JVM_CONSTANT_Float:
2346             SET_STACK_FLOAT(constants->float_at(index), 0);
2347             break;
2348 
2349           case JVM_CONSTANT_String:
2350             {
2351               oop result = constants->resolved_references()->obj_at(index);
2352               if (result == NULL) {
2353                 CALL_VM(InterpreterRuntime::resolve_ldc(THREAD, (Bytecodes::Code) opcode), handle_exception);
2354                 SET_STACK_OBJECT(THREAD->vm_result(), 0);
2355                 THREAD->set_vm_result(NULL);
2356               } else {
2357                 VERIFY_OOP(result);
2358                 SET_STACK_OBJECT(result, 0);
2359               }
2360             break;
2361             }
2362 
2363           case JVM_CONSTANT_Class:
2364             VERIFY_OOP(constants->resolved_klass_at(index)->java_mirror());
2365             SET_STACK_OBJECT(constants->resolved_klass_at(index)->java_mirror(), 0);
2366             break;
2367 
2368           case JVM_CONSTANT_UnresolvedClass:
2369           case JVM_CONSTANT_UnresolvedClassInError:
2370             CALL_VM(InterpreterRuntime::ldc(THREAD, wide), handle_exception);
2371             SET_STACK_OBJECT(THREAD->vm_result(), 0);
2372             THREAD->set_vm_result(NULL);
2373             break;
2374 
2375           default:  ShouldNotReachHere();
2376           }
2377           UPDATE_PC_AND_TOS_AND_CONTINUE(incr, 1);
2378         }
2379 
2380       CASE(_ldc2_w):
2381         {
2382           u2 index = Bytes::get_Java_u2(pc+1);
2383 
2384           ConstantPool* constants = METHOD->constants();
2385           switch (constants->tag_at(index).value()) {
2386 
2387           case JVM_CONSTANT_Long:
2388              SET_STACK_LONG(constants->long_at(index), 1);
2389             break;
2390 
2391           case JVM_CONSTANT_Double:
2392              SET_STACK_DOUBLE(constants->double_at(index), 1);
2393             break;
2394           default:  ShouldNotReachHere();
2395           }
2396           UPDATE_PC_AND_TOS_AND_CONTINUE(3, 2);
2397         }
2398 
2399       CASE(_fast_aldc_w):
2400       CASE(_fast_aldc): {
2401         u2 index;
2402         int incr;
2403         if (opcode == Bytecodes::_fast_aldc) {
2404           index = pc[1];
2405           incr = 2;
2406         } else {
2407           index = Bytes::get_native_u2(pc+1);
2408           incr = 3;
2409         }
2410 
2411         // We are resolved if the f1 field contains a non-null object (CallSite, etc.)
2412         // This kind of CP cache entry does not need to match the flags byte, because
2413         // there is a 1-1 relation between bytecode type and CP entry type.
2414         ConstantPool* constants = METHOD->constants();
2415         oop result = constants->resolved_references()->obj_at(index);
2416         if (result == NULL) {
2417           CALL_VM(InterpreterRuntime::resolve_ldc(THREAD, (Bytecodes::Code) opcode),
2418                   handle_exception);
2419           result = THREAD->vm_result();
2420         }
2421 
2422         VERIFY_OOP(result);
2423         SET_STACK_OBJECT(result, 0);
2424         UPDATE_PC_AND_TOS_AND_CONTINUE(incr, 1);
2425       }
2426 
2427       CASE(_invokedynamic): {
2428 
2429         if (!EnableInvokeDynamic) {
2430           // We should not encounter this bytecode if !EnableInvokeDynamic.
2431           // The verifier will stop it.  However, if we get past the verifier,
2432           // this will stop the thread in a reasonable way, without crashing the JVM.
2433           CALL_VM(InterpreterRuntime::throw_IncompatibleClassChangeError(THREAD),
2434                   handle_exception);
2435           ShouldNotReachHere();
2436         }
2437 
2438         u4 index = Bytes::get_native_u4(pc+1);
2439         ConstantPoolCacheEntry* cache = cp->constant_pool()->invokedynamic_cp_cache_entry_at(index);
2440 
2441         // We are resolved if the resolved_references field contains a non-null object (CallSite, etc.)
2442         // This kind of CP cache entry does not need to match the flags byte, because
2443         // there is a 1-1 relation between bytecode type and CP entry type.
2444         if (! cache->is_resolved((Bytecodes::Code) opcode)) {
2445           CALL_VM(InterpreterRuntime::resolve_invokedynamic(THREAD),
2446                   handle_exception);
2447           cache = cp->constant_pool()->invokedynamic_cp_cache_entry_at(index);
2448         }
2449 
2450         Method* method = cache->f1_as_method();
2451         if (VerifyOops) method->verify();
2452 
2453         if (cache->has_appendix()) {
2454           ConstantPool* constants = METHOD->constants();
2455           SET_STACK_OBJECT(cache->appendix_if_resolved(constants), 0);
2456           MORE_STACK(1);
2457         }
2458 
2459         istate->set_msg(call_method);
2460         istate->set_callee(method);
2461         istate->set_callee_entry_point(method->from_interpreted_entry());
2462         istate->set_bcp_advance(5);
2463 
2464         // Invokedynamic has got a call counter, just like an invokestatic -> increment!
2465         BI_PROFILE_UPDATE_CALL();
2466 
2467         UPDATE_PC_AND_RETURN(0); // I'll be back...
2468       }
2469 
2470       CASE(_invokehandle): {
2471 
2472         if (!EnableInvokeDynamic) {
2473           ShouldNotReachHere();
2474         }
2475 
2476         u2 index = Bytes::get_native_u2(pc+1);
2477         ConstantPoolCacheEntry* cache = cp->entry_at(index);
2478 
2479         if (! cache->is_resolved((Bytecodes::Code) opcode)) {
2480           CALL_VM(InterpreterRuntime::resolve_invokehandle(THREAD),
2481                   handle_exception);
2482           cache = cp->entry_at(index);
2483         }
2484 
2485         Method* method = cache->f1_as_method();
2486         if (VerifyOops) method->verify();
2487 
2488         if (cache->has_appendix()) {
2489           ConstantPool* constants = METHOD->constants();
2490           SET_STACK_OBJECT(cache->appendix_if_resolved(constants), 0);
2491           MORE_STACK(1);
2492         }
2493 
2494         istate->set_msg(call_method);
2495         istate->set_callee(method);
2496         istate->set_callee_entry_point(method->from_interpreted_entry());
2497         istate->set_bcp_advance(3);
2498 
2499         // Invokehandle has got a call counter, just like a final call -> increment!
2500         BI_PROFILE_UPDATE_FINALCALL();
2501 
2502         UPDATE_PC_AND_RETURN(0); // I'll be back...
2503       }
2504 
2505       CASE(_invokeinterface): {
2506         u2 index = Bytes::get_native_u2(pc+1);
2507 
2508         // QQQ Need to make this as inlined as possible. Probably need to split all the bytecode cases
2509         // out so c++ compiler has a chance for constant prop to fold everything possible away.
2510 
2511         ConstantPoolCacheEntry* cache = cp->entry_at(index);
2512         if (!cache->is_resolved((Bytecodes::Code)opcode)) {
2513           CALL_VM(InterpreterRuntime::resolve_invoke(THREAD, (Bytecodes::Code)opcode),
2514                   handle_exception);
2515           cache = cp->entry_at(index);
2516         }
2517 
2518         istate->set_msg(call_method);
2519 
2520         // Special case of invokeinterface called for virtual method of
2521         // java.lang.Object.  See cpCacheOop.cpp for details.
2522         // This code isn't produced by javac, but could be produced by
2523         // another compliant java compiler.
2524         if (cache->is_forced_virtual()) {
2525           Method* callee;
2526           CHECK_NULL(STACK_OBJECT(-(cache->parameter_size())));
2527           if (cache->is_vfinal()) {
2528             callee = cache->f2_as_vfinal_method();
2529             // Profile 'special case of invokeinterface' final call.
2530             BI_PROFILE_UPDATE_FINALCALL();
2531           } else {
2532             // Get receiver.
2533             int parms = cache->parameter_size();
2534             // Same comments as invokevirtual apply here.
2535             oop rcvr = STACK_OBJECT(-parms);
2536             VERIFY_OOP(rcvr);
2537             InstanceKlass* rcvrKlass = (InstanceKlass*)rcvr->klass();
2538             callee = (Method*) rcvrKlass->start_of_vtable()[ cache->f2_as_index()];
2539             // Profile 'special case of invokeinterface' virtual call.
2540             BI_PROFILE_UPDATE_VIRTUALCALL(rcvr->klass());
2541           }
2542           istate->set_callee(callee);
2543           istate->set_callee_entry_point(callee->from_interpreted_entry());
2544 #ifdef VM_JVMTI
2545           if (JvmtiExport::can_post_interpreter_events() && THREAD->is_interp_only_mode()) {
2546             istate->set_callee_entry_point(callee->interpreter_entry());
2547           }
2548 #endif /* VM_JVMTI */
2549           istate->set_bcp_advance(5);
2550           UPDATE_PC_AND_RETURN(0); // I'll be back...
2551         }
2552 
2553         // this could definitely be cleaned up QQQ
2554         Method* callee;
2555         Klass* iclass = cache->f1_as_klass();
2556         // InstanceKlass* interface = (InstanceKlass*) iclass;
2557         // get receiver
2558         int parms = cache->parameter_size();
2559         oop rcvr = STACK_OBJECT(-parms);
2560         CHECK_NULL(rcvr);
2561         InstanceKlass* int2 = (InstanceKlass*) rcvr->klass();
2562         itableOffsetEntry* ki = (itableOffsetEntry*) int2->start_of_itable();
2563         int i;
2564         for ( i = 0 ; i < int2->itable_length() ; i++, ki++ ) {
2565           if (ki->interface_klass() == iclass) break;
2566         }
2567         // If the interface isn't found, this class doesn't implement this
2568         // interface.  The link resolver checks this but only for the first
2569         // time this interface is called.
2570         if (i == int2->itable_length()) {
2571           VM_JAVA_ERROR(vmSymbols::java_lang_IncompatibleClassChangeError(), "", note_no_trap);
2572         }
2573         int mindex = cache->f2_as_index();
2574         itableMethodEntry* im = ki->first_method_entry(rcvr->klass());
2575         callee = im[mindex].method();
2576         if (callee == NULL) {
2577           VM_JAVA_ERROR(vmSymbols::java_lang_AbstractMethodError(), "", note_no_trap);
2578         }
2579 
2580         // Profile virtual call.
2581         BI_PROFILE_UPDATE_VIRTUALCALL(rcvr->klass());
2582 
2583         istate->set_callee(callee);
2584         istate->set_callee_entry_point(callee->from_interpreted_entry());
2585 #ifdef VM_JVMTI
2586         if (JvmtiExport::can_post_interpreter_events() && THREAD->is_interp_only_mode()) {
2587           istate->set_callee_entry_point(callee->interpreter_entry());
2588         }
2589 #endif /* VM_JVMTI */
2590         istate->set_bcp_advance(5);
2591         UPDATE_PC_AND_RETURN(0); // I'll be back...
2592       }
2593 
2594       CASE(_invokevirtual):
2595       CASE(_invokespecial):
2596       CASE(_invokestatic): {
2597         u2 index = Bytes::get_native_u2(pc+1);
2598 
2599         ConstantPoolCacheEntry* cache = cp->entry_at(index);
2600         // QQQ Need to make this as inlined as possible. Probably need to split all the bytecode cases
2601         // out so c++ compiler has a chance for constant prop to fold everything possible away.
2602 
2603         if (!cache->is_resolved((Bytecodes::Code)opcode)) {
2604           CALL_VM(InterpreterRuntime::resolve_invoke(THREAD, (Bytecodes::Code)opcode),
2605                   handle_exception);
2606           cache = cp->entry_at(index);
2607         }
2608 
2609         istate->set_msg(call_method);
2610         {
2611           Method* callee;
2612           if ((Bytecodes::Code)opcode == Bytecodes::_invokevirtual) {
2613             CHECK_NULL(STACK_OBJECT(-(cache->parameter_size())));
2614             if (cache->is_vfinal()) {
2615               callee = cache->f2_as_vfinal_method();
2616               // Profile final call.
2617               BI_PROFILE_UPDATE_FINALCALL();
2618             } else {
2619               // get receiver
2620               int parms = cache->parameter_size();
2621               // this works but needs a resourcemark and seems to create a vtable on every call:
2622               // Method* callee = rcvr->klass()->vtable()->method_at(cache->f2_as_index());
2623               //
2624               // this fails with an assert
2625               // InstanceKlass* rcvrKlass = InstanceKlass::cast(STACK_OBJECT(-parms)->klass());
2626               // but this works
2627               oop rcvr = STACK_OBJECT(-parms);
2628               VERIFY_OOP(rcvr);
2629               InstanceKlass* rcvrKlass = (InstanceKlass*)rcvr->klass();
2630               /*
2631                 Executing this code in java.lang.String:
2632                     public String(char value[]) {
2633                           this.count = value.length;
2634                           this.value = (char[])value.clone();
2635                      }
2636 
2637                  a find on rcvr->klass() reports:
2638                  {type array char}{type array class}
2639                   - klass: {other class}
2640 
2641                   but using InstanceKlass::cast(STACK_OBJECT(-parms)->klass()) causes in assertion failure
2642                   because rcvr->klass()->oop_is_instance() == 0
2643                   However it seems to have a vtable in the right location. Huh?
2644 
2645               */
2646               callee = (Method*) rcvrKlass->start_of_vtable()[ cache->f2_as_index()];
2647               // Profile virtual call.
2648               BI_PROFILE_UPDATE_VIRTUALCALL(rcvr->klass());
2649             }
2650           } else {
2651             if ((Bytecodes::Code)opcode == Bytecodes::_invokespecial) {
2652               CHECK_NULL(STACK_OBJECT(-(cache->parameter_size())));
2653             }
2654             callee = cache->f1_as_method();
2655 
2656             // Profile call.
2657             BI_PROFILE_UPDATE_CALL();
2658           }
2659 
2660           istate->set_callee(callee);
2661           istate->set_callee_entry_point(callee->from_interpreted_entry());
2662 #ifdef VM_JVMTI
2663           if (JvmtiExport::can_post_interpreter_events() && THREAD->is_interp_only_mode()) {
2664             istate->set_callee_entry_point(callee->interpreter_entry());
2665           }
2666 #endif /* VM_JVMTI */
2667           istate->set_bcp_advance(3);
2668           UPDATE_PC_AND_RETURN(0); // I'll be back...
2669         }
2670       }
2671 
2672       /* Allocate memory for a new java object. */
2673 
2674       CASE(_newarray): {
2675         BasicType atype = (BasicType) *(pc+1);
2676         jint size = STACK_INT(-1);
2677         CALL_VM(InterpreterRuntime::newarray(THREAD, atype, size),
2678                 handle_exception);
2679         // Must prevent reordering of stores for object initialization
2680         // with stores that publish the new object.
2681         OrderAccess::storestore();
2682         SET_STACK_OBJECT(THREAD->vm_result(), -1);
2683         THREAD->set_vm_result(NULL);
2684 
2685         UPDATE_PC_AND_CONTINUE(2);
2686       }
2687 
2688       /* Throw an exception. */
2689 
2690       CASE(_athrow): {
2691           oop except_oop = STACK_OBJECT(-1);
2692           CHECK_NULL(except_oop);
2693           // set pending_exception so we use common code
2694           THREAD->set_pending_exception(except_oop, NULL, 0);
2695           goto handle_exception;
2696       }
2697 
2698       /* goto and jsr. They are exactly the same except jsr pushes
2699        * the address of the next instruction first.
2700        */
2701 
2702       CASE(_jsr): {
2703           /* push bytecode index on stack */
2704           SET_STACK_ADDR(((address)pc - (intptr_t)(istate->method()->code_base()) + 3), 0);
2705           MORE_STACK(1);
2706           /* FALL THROUGH */
2707       }
2708 
2709       CASE(_goto):
2710       {
2711           int16_t offset = (int16_t)Bytes::get_Java_u2(pc + 1);
2712           // Profile jump.
2713           BI_PROFILE_UPDATE_JUMP();
2714           address branch_pc = pc;
2715           UPDATE_PC(offset);
2716           DO_BACKEDGE_CHECKS(offset, branch_pc);
2717           CONTINUE;
2718       }
2719 
2720       CASE(_jsr_w): {
2721           /* push return address on the stack */
2722           SET_STACK_ADDR(((address)pc - (intptr_t)(istate->method()->code_base()) + 5), 0);
2723           MORE_STACK(1);
2724           /* FALL THROUGH */
2725       }
2726 
2727       CASE(_goto_w):
2728       {
2729           int32_t offset = Bytes::get_Java_u4(pc + 1);
2730           // Profile jump.
2731           BI_PROFILE_UPDATE_JUMP();
2732           address branch_pc = pc;
2733           UPDATE_PC(offset);
2734           DO_BACKEDGE_CHECKS(offset, branch_pc);
2735           CONTINUE;
2736       }
2737 
2738       /* return from a jsr or jsr_w */
2739 
2740       CASE(_ret): {
2741           // Profile ret.
2742           BI_PROFILE_UPDATE_RET(/*bci=*/((int)(intptr_t)(LOCALS_ADDR(pc[1]))));
2743           // Now, update the pc.
2744           pc = istate->method()->code_base() + (intptr_t)(LOCALS_ADDR(pc[1]));
2745           UPDATE_PC_AND_CONTINUE(0);
2746       }
2747 
2748       /* debugger breakpoint */
2749 
2750       CASE(_breakpoint): {
2751           Bytecodes::Code original_bytecode;
2752           DECACHE_STATE();
2753           SET_LAST_JAVA_FRAME();
2754           original_bytecode = InterpreterRuntime::get_original_bytecode_at(THREAD,
2755                               METHOD, pc);
2756           RESET_LAST_JAVA_FRAME();
2757           CACHE_STATE();
2758           if (THREAD->has_pending_exception()) goto handle_exception;
2759             CALL_VM(InterpreterRuntime::_breakpoint(THREAD, METHOD, pc),
2760                                                     handle_exception);
2761 
2762           opcode = (jubyte)original_bytecode;
2763           goto opcode_switch;
2764       }
2765 
2766       DEFAULT:
2767           fatal(err_msg("Unimplemented opcode %d = %s", opcode,
2768                         Bytecodes::name((Bytecodes::Code)opcode)));
2769           goto finish;
2770 
2771       } /* switch(opc) */
2772 
2773 
2774 #ifdef USELABELS
2775     check_for_exception:
2776 #endif
2777     {
2778       if (!THREAD->has_pending_exception()) {
2779         CONTINUE;
2780       }
2781       /* We will be gcsafe soon, so flush our state. */
2782       DECACHE_PC();
2783       goto handle_exception;
2784     }
2785   do_continue: ;
2786 
2787   } /* while (1) interpreter loop */
2788 
2789 
2790   // An exception exists in the thread state see whether this activation can handle it
2791   handle_exception: {
2792 
2793     HandleMarkCleaner __hmc(THREAD);
2794     Handle except_oop(THREAD, THREAD->pending_exception());
2795     // Prevent any subsequent HandleMarkCleaner in the VM
2796     // from freeing the except_oop handle.
2797     HandleMark __hm(THREAD);
2798 
2799     THREAD->clear_pending_exception();
2800     assert(except_oop(), "No exception to process");
2801     intptr_t continuation_bci;
2802     // expression stack is emptied
2803     topOfStack = istate->stack_base() - Interpreter::stackElementWords;
2804     CALL_VM(continuation_bci = (intptr_t)InterpreterRuntime::exception_handler_for_exception(THREAD, except_oop()),
2805             handle_exception);
2806 
2807     except_oop = THREAD->vm_result();
2808     THREAD->set_vm_result(NULL);
2809     if (continuation_bci >= 0) {
2810       // Place exception on top of stack
2811       SET_STACK_OBJECT(except_oop(), 0);
2812       MORE_STACK(1);
2813       pc = METHOD->code_base() + continuation_bci;
2814       if (TraceExceptions) {
2815         ttyLocker ttyl;
2816         ResourceMark rm;
2817         tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")", except_oop->print_value_string(), (void*)except_oop());
2818         tty->print_cr(" thrown in interpreter method <%s>", METHOD->print_value_string());
2819         tty->print_cr(" at bci %d, continuing at %d for thread " INTPTR_FORMAT,
2820                       istate->bcp() - (intptr_t)METHOD->code_base(),
2821                       continuation_bci, THREAD);
2822       }
2823       // for AbortVMOnException flag
2824       NOT_PRODUCT(Exceptions::debug_check_abort(except_oop));
2825 
2826       // Update profiling data.
2827       BI_PROFILE_ALIGN_TO_CURRENT_BCI();
2828       goto run;
2829     }
2830     if (TraceExceptions) {
2831       ttyLocker ttyl;
2832       ResourceMark rm;
2833       tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")", except_oop->print_value_string(), (void*)except_oop());
2834       tty->print_cr(" thrown in interpreter method <%s>", METHOD->print_value_string());
2835       tty->print_cr(" at bci %d, unwinding for thread " INTPTR_FORMAT,
2836                     istate->bcp() - (intptr_t)METHOD->code_base(),
2837                     THREAD);
2838     }
2839     // for AbortVMOnException flag
2840     NOT_PRODUCT(Exceptions::debug_check_abort(except_oop));
2841     // No handler in this activation, unwind and try again
2842     THREAD->set_pending_exception(except_oop(), NULL, 0);
2843     goto handle_return;
2844   }  // handle_exception:
2845 
2846   // Return from an interpreter invocation with the result of the interpretation
2847   // on the top of the Java Stack (or a pending exception)
2848 
2849   handle_Pop_Frame: {
2850 
2851     // We don't really do anything special here except we must be aware
2852     // that we can get here without ever locking the method (if sync).
2853     // Also we skip the notification of the exit.
2854 
2855     istate->set_msg(popping_frame);
2856     // Clear pending so while the pop is in process
2857     // we don't start another one if a call_vm is done.
2858     THREAD->clr_pop_frame_pending();
2859     // Let interpreter (only) see the we're in the process of popping a frame
2860     THREAD->set_pop_frame_in_process();
2861 
2862     goto handle_return;
2863 
2864   } // handle_Pop_Frame
2865 
2866   // ForceEarlyReturn ends a method, and returns to the caller with a return value
2867   // given by the invoker of the early return.
2868   handle_Early_Return: {
2869 
2870     istate->set_msg(early_return);
2871 
2872     // Clear expression stack.
2873     topOfStack = istate->stack_base() - Interpreter::stackElementWords;
2874 
2875     JvmtiThreadState *ts = THREAD->jvmti_thread_state();
2876 
2877     // Push the value to be returned.
2878     switch (istate->method()->result_type()) {
2879       case T_BOOLEAN:
2880       case T_SHORT:
2881       case T_BYTE:
2882       case T_CHAR:
2883       case T_INT:
2884         SET_STACK_INT(ts->earlyret_value().i, 0);
2885         MORE_STACK(1);
2886         break;
2887       case T_LONG:
2888         SET_STACK_LONG(ts->earlyret_value().j, 1);
2889         MORE_STACK(2);
2890         break;
2891       case T_FLOAT:
2892         SET_STACK_FLOAT(ts->earlyret_value().f, 0);
2893         MORE_STACK(1);
2894         break;
2895       case T_DOUBLE:
2896         SET_STACK_DOUBLE(ts->earlyret_value().d, 1);
2897         MORE_STACK(2);
2898         break;
2899       case T_ARRAY:
2900       case T_OBJECT:
2901         SET_STACK_OBJECT(ts->earlyret_oop(), 0);
2902         MORE_STACK(1);
2903         break;
2904     }
2905 
2906     ts->clr_earlyret_value();
2907     ts->set_earlyret_oop(NULL);
2908     ts->clr_earlyret_pending();
2909 
2910     // Fall through to handle_return.
2911 
2912   } // handle_Early_Return
2913 
2914   handle_return: {
2915     // A storestore barrier is required to order initialization of
2916     // final fields with publishing the reference to the object that
2917     // holds the field. Without the barrier the value of final fields
2918     // can be observed to change.
2919     OrderAccess::storestore();
2920 
2921     DECACHE_STATE();
2922 
2923     bool suppress_error = istate->msg() == popping_frame || istate->msg() == early_return;
2924     bool suppress_exit_event = THREAD->has_pending_exception() || istate->msg() == popping_frame;
2925     Handle original_exception(THREAD, THREAD->pending_exception());
2926     Handle illegal_state_oop(THREAD, NULL);
2927 
2928     // We'd like a HandleMark here to prevent any subsequent HandleMarkCleaner
2929     // in any following VM entries from freeing our live handles, but illegal_state_oop
2930     // isn't really allocated yet and so doesn't become live until later and
2931     // in unpredicatable places. Instead we must protect the places where we enter the
2932     // VM. It would be much simpler (and safer) if we could allocate a real handle with
2933     // a NULL oop in it and then overwrite the oop later as needed. This isn't
2934     // unfortunately isn't possible.
2935 
2936     THREAD->clear_pending_exception();
2937 
2938     //
2939     // As far as we are concerned we have returned. If we have a pending exception
2940     // that will be returned as this invocation's result. However if we get any
2941     // exception(s) while checking monitor state one of those IllegalMonitorStateExceptions
2942     // will be our final result (i.e. monitor exception trumps a pending exception).
2943     //
2944 
2945     // If we never locked the method (or really passed the point where we would have),
2946     // there is no need to unlock it (or look for other monitors), since that
2947     // could not have happened.
2948 
2949     if (THREAD->do_not_unlock()) {
2950 
2951       // Never locked, reset the flag now because obviously any caller must
2952       // have passed their point of locking for us to have gotten here.
2953 
2954       THREAD->clr_do_not_unlock();
2955     } else {
2956       // At this point we consider that we have returned. We now check that the
2957       // locks were properly block structured. If we find that they were not
2958       // used properly we will return with an illegal monitor exception.
2959       // The exception is checked by the caller not the callee since this
2960       // checking is considered to be part of the invocation and therefore
2961       // in the callers scope (JVM spec 8.13).
2962       //
2963       // Another weird thing to watch for is if the method was locked
2964       // recursively and then not exited properly. This means we must
2965       // examine all the entries in reverse time(and stack) order and
2966       // unlock as we find them. If we find the method monitor before
2967       // we are at the initial entry then we should throw an exception.
2968       // It is not clear the template based interpreter does this
2969       // correctly
2970 
2971       BasicObjectLock* base = istate->monitor_base();
2972       BasicObjectLock* end = (BasicObjectLock*) istate->stack_base();
2973       bool method_unlock_needed = METHOD->is_synchronized();
2974       // We know the initial monitor was used for the method don't check that
2975       // slot in the loop
2976       if (method_unlock_needed) base--;
2977 
2978       // Check all the monitors to see they are unlocked. Install exception if found to be locked.
2979       while (end < base) {
2980         oop lockee = end->obj();
2981         if (lockee != NULL) {
2982           BasicLock* lock = end->lock();
2983           markOop header = lock->displaced_header();
2984           end->set_obj(NULL);
2985 
2986           if (!lockee->mark()->has_bias_pattern()) {
2987             // If it isn't recursive we either must swap old header or call the runtime
2988             if (header != NULL) {
2989               if (Atomic::cmpxchg_ptr(header, lockee->mark_addr(), lock) != lock) {
2990                 // restore object for the slow case
2991                 end->set_obj(lockee);
2992                 {
2993                   // Prevent any HandleMarkCleaner from freeing our live handles
2994                   HandleMark __hm(THREAD);
2995                   CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(THREAD, end));
2996                 }
2997               }
2998             }
2999           }
3000           // One error is plenty
3001           if (illegal_state_oop() == NULL && !suppress_error) {
3002             {
3003               // Prevent any HandleMarkCleaner from freeing our live handles
3004               HandleMark __hm(THREAD);
3005               CALL_VM_NOCHECK(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD));
3006             }
3007             assert(THREAD->has_pending_exception(), "Lost our exception!");
3008             illegal_state_oop = THREAD->pending_exception();
3009             THREAD->clear_pending_exception();
3010           }
3011         }
3012         end++;
3013       }
3014       // Unlock the method if needed
3015       if (method_unlock_needed) {
3016         if (base->obj() == NULL) {
3017           // The method is already unlocked this is not good.
3018           if (illegal_state_oop() == NULL && !suppress_error) {
3019             {
3020               // Prevent any HandleMarkCleaner from freeing our live handles
3021               HandleMark __hm(THREAD);
3022               CALL_VM_NOCHECK(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD));
3023             }
3024             assert(THREAD->has_pending_exception(), "Lost our exception!");
3025             illegal_state_oop = THREAD->pending_exception();
3026             THREAD->clear_pending_exception();
3027           }
3028         } else {
3029           //
3030           // The initial monitor is always used for the method
3031           // However if that slot is no longer the oop for the method it was unlocked
3032           // and reused by something that wasn't unlocked!
3033           //
3034           // deopt can come in with rcvr dead because c2 knows
3035           // its value is preserved in the monitor. So we can't use locals[0] at all
3036           // and must use first monitor slot.
3037           //
3038           oop rcvr = base->obj();
3039           if (rcvr == NULL) {
3040             if (!suppress_error) {
3041               VM_JAVA_ERROR_NO_JUMP(vmSymbols::java_lang_NullPointerException(), "", note_nullCheck_trap);
3042               illegal_state_oop = THREAD->pending_exception();
3043               THREAD->clear_pending_exception();
3044             }
3045           } else if (UseHeavyMonitors) {
3046             {
3047               // Prevent any HandleMarkCleaner from freeing our live handles.
3048               HandleMark __hm(THREAD);
3049               CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(THREAD, base));
3050             }
3051             if (THREAD->has_pending_exception()) {
3052               if (!suppress_error) illegal_state_oop = THREAD->pending_exception();
3053               THREAD->clear_pending_exception();
3054             }
3055           } else {
3056             BasicLock* lock = base->lock();
3057             markOop header = lock->displaced_header();
3058             base->set_obj(NULL);
3059 
3060             if (!rcvr->mark()->has_bias_pattern()) {
3061               base->set_obj(NULL);
3062               // If it isn't recursive we either must swap old header or call the runtime
3063               if (header != NULL) {
3064                 if (Atomic::cmpxchg_ptr(header, rcvr->mark_addr(), lock) != lock) {
3065                   // restore object for the slow case
3066                   base->set_obj(rcvr);
3067                   {
3068                     // Prevent any HandleMarkCleaner from freeing our live handles
3069                     HandleMark __hm(THREAD);
3070                     CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(THREAD, base));
3071                   }
3072                   if (THREAD->has_pending_exception()) {
3073                     if (!suppress_error) illegal_state_oop = THREAD->pending_exception();
3074                     THREAD->clear_pending_exception();
3075                   }
3076                 }
3077               }
3078             }
3079           }
3080         }
3081       }
3082     }
3083     // Clear the do_not_unlock flag now.
3084     THREAD->clr_do_not_unlock();
3085 
3086     //
3087     // Notify jvmti/jvmdi
3088     //
3089     // NOTE: we do not notify a method_exit if we have a pending exception,
3090     // including an exception we generate for unlocking checks.  In the former
3091     // case, JVMDI has already been notified by our call for the exception handler
3092     // and in both cases as far as JVMDI is concerned we have already returned.
3093     // If we notify it again JVMDI will be all confused about how many frames
3094     // are still on the stack (4340444).
3095     //
3096     // NOTE Further! It turns out the the JVMTI spec in fact expects to see
3097     // method_exit events whenever we leave an activation unless it was done
3098     // for popframe. This is nothing like jvmdi. However we are passing the
3099     // tests at the moment (apparently because they are jvmdi based) so rather
3100     // than change this code and possibly fail tests we will leave it alone
3101     // (with this note) in anticipation of changing the vm and the tests
3102     // simultaneously.
3103 
3104 
3105     //
3106     suppress_exit_event = suppress_exit_event || illegal_state_oop() != NULL;
3107 
3108 
3109 
3110 #ifdef VM_JVMTI
3111       if (_jvmti_interp_events) {
3112         // Whenever JVMTI puts a thread in interp_only_mode, method
3113         // entry/exit events are sent for that thread to track stack depth.
3114         if ( !suppress_exit_event && THREAD->is_interp_only_mode() ) {
3115           {
3116             // Prevent any HandleMarkCleaner from freeing our live handles
3117             HandleMark __hm(THREAD);
3118             CALL_VM_NOCHECK(InterpreterRuntime::post_method_exit(THREAD));
3119           }
3120         }
3121       }
3122 #endif /* VM_JVMTI */
3123 
3124     //
3125     // See if we are returning any exception
3126     // A pending exception that was pending prior to a possible popping frame
3127     // overrides the popping frame.
3128     //
3129     assert(!suppress_error || (suppress_error && illegal_state_oop() == NULL), "Error was not suppressed");
3130     if (illegal_state_oop() != NULL || original_exception() != NULL) {
3131       // Inform the frame manager we have no result.
3132       istate->set_msg(throwing_exception);
3133       if (illegal_state_oop() != NULL)
3134         THREAD->set_pending_exception(illegal_state_oop(), NULL, 0);
3135       else
3136         THREAD->set_pending_exception(original_exception(), NULL, 0);
3137       UPDATE_PC_AND_RETURN(0);
3138     }
3139 
3140     if (istate->msg() == popping_frame) {
3141       // Make it simpler on the assembly code and set the message for the frame pop.
3142       // returns
3143       if (istate->prev() == NULL) {
3144         // We must be returning to a deoptimized frame (because popframe only happens between
3145         // two interpreted frames). We need to save the current arguments in C heap so that
3146         // the deoptimized frame when it restarts can copy the arguments to its expression
3147         // stack and re-execute the call. We also have to notify deoptimization that this
3148         // has occurred and to pick the preserved args copy them to the deoptimized frame's
3149         // java expression stack. Yuck.
3150         //
3151         THREAD->popframe_preserve_args(in_ByteSize(METHOD->size_of_parameters() * wordSize),
3152                                 LOCALS_SLOT(METHOD->size_of_parameters() - 1));
3153         THREAD->set_popframe_condition_bit(JavaThread::popframe_force_deopt_reexecution_bit);
3154       }
3155     } else {
3156       istate->set_msg(return_from_method);
3157     }
3158 
3159     // Normal return
3160     // Advance the pc and return to frame manager
3161     UPDATE_PC_AND_RETURN(1);
3162   } /* handle_return: */
3163 
3164 // This is really a fatal error return
3165 
3166 finish:
3167   DECACHE_TOS();
3168   DECACHE_PC();
3169 
3170   return;
3171 }
3172 
3173 /*
3174  * All the code following this point is only produced once and is not present
3175  * in the JVMTI version of the interpreter
3176 */
3177 
3178 #ifndef VM_JVMTI
3179 
3180 // This constructor should only be used to contruct the object to signal
3181 // interpreter initialization. All other instances should be created by
3182 // the frame manager.
3183 BytecodeInterpreter::BytecodeInterpreter(messages msg) {
3184   if (msg != initialize) ShouldNotReachHere();
3185   _msg = msg;
3186   _self_link = this;
3187   _prev_link = NULL;
3188 }
3189 
3190 // Inline static functions for Java Stack and Local manipulation
3191 
3192 // The implementations are platform dependent. We have to worry about alignment
3193 // issues on some machines which can change on the same platform depending on
3194 // whether it is an LP64 machine also.
3195 address BytecodeInterpreter::stack_slot(intptr_t *tos, int offset) {
3196   return (address) tos[Interpreter::expr_index_at(-offset)];
3197 }
3198 
3199 jint BytecodeInterpreter::stack_int(intptr_t *tos, int offset) {
3200   return *((jint*) &tos[Interpreter::expr_index_at(-offset)]);
3201 }
3202 
3203 jfloat BytecodeInterpreter::stack_float(intptr_t *tos, int offset) {
3204   return *((jfloat *) &tos[Interpreter::expr_index_at(-offset)]);
3205 }
3206 
3207 oop BytecodeInterpreter::stack_object(intptr_t *tos, int offset) {
3208   return cast_to_oop(tos [Interpreter::expr_index_at(-offset)]);
3209 }
3210 
3211 jdouble BytecodeInterpreter::stack_double(intptr_t *tos, int offset) {
3212   return ((VMJavaVal64*) &tos[Interpreter::expr_index_at(-offset)])->d;
3213 }
3214 
3215 jlong BytecodeInterpreter::stack_long(intptr_t *tos, int offset) {
3216   return ((VMJavaVal64 *) &tos[Interpreter::expr_index_at(-offset)])->l;
3217 }
3218 
3219 // only used for value types
3220 void BytecodeInterpreter::set_stack_slot(intptr_t *tos, address value,
3221                                                         int offset) {
3222   *((address *)&tos[Interpreter::expr_index_at(-offset)]) = value;
3223 }
3224 
3225 void BytecodeInterpreter::set_stack_int(intptr_t *tos, int value,
3226                                                        int offset) {
3227   *((jint *)&tos[Interpreter::expr_index_at(-offset)]) = value;
3228 }
3229 
3230 void BytecodeInterpreter::set_stack_float(intptr_t *tos, jfloat value,
3231                                                          int offset) {
3232   *((jfloat *)&tos[Interpreter::expr_index_at(-offset)]) = value;
3233 }
3234 
3235 void BytecodeInterpreter::set_stack_object(intptr_t *tos, oop value,
3236                                                           int offset) {
3237   *((oop *)&tos[Interpreter::expr_index_at(-offset)]) = value;
3238 }
3239 
3240 // needs to be platform dep for the 32 bit platforms.
3241 void BytecodeInterpreter::set_stack_double(intptr_t *tos, jdouble value,
3242                                                           int offset) {
3243   ((VMJavaVal64*)&tos[Interpreter::expr_index_at(-offset)])->d = value;
3244 }
3245 
3246 void BytecodeInterpreter::set_stack_double_from_addr(intptr_t *tos,
3247                                               address addr, int offset) {
3248   (((VMJavaVal64*)&tos[Interpreter::expr_index_at(-offset)])->d =
3249                         ((VMJavaVal64*)addr)->d);
3250 }
3251 
3252 void BytecodeInterpreter::set_stack_long(intptr_t *tos, jlong value,
3253                                                         int offset) {
3254   ((VMJavaVal64*)&tos[Interpreter::expr_index_at(-offset+1)])->l = 0xdeedbeeb;
3255   ((VMJavaVal64*)&tos[Interpreter::expr_index_at(-offset)])->l = value;
3256 }
3257 
3258 void BytecodeInterpreter::set_stack_long_from_addr(intptr_t *tos,
3259                                             address addr, int offset) {
3260   ((VMJavaVal64*)&tos[Interpreter::expr_index_at(-offset+1)])->l = 0xdeedbeeb;
3261   ((VMJavaVal64*)&tos[Interpreter::expr_index_at(-offset)])->l =
3262                         ((VMJavaVal64*)addr)->l;
3263 }
3264 
3265 // Locals
3266 
3267 address BytecodeInterpreter::locals_slot(intptr_t* locals, int offset) {
3268   return (address)locals[Interpreter::local_index_at(-offset)];
3269 }
3270 jint BytecodeInterpreter::locals_int(intptr_t* locals, int offset) {
3271   return (jint)locals[Interpreter::local_index_at(-offset)];
3272 }
3273 jfloat BytecodeInterpreter::locals_float(intptr_t* locals, int offset) {
3274   return (jfloat)locals[Interpreter::local_index_at(-offset)];
3275 }
3276 oop BytecodeInterpreter::locals_object(intptr_t* locals, int offset) {
3277   return cast_to_oop(locals[Interpreter::local_index_at(-offset)]);
3278 }
3279 jdouble BytecodeInterpreter::locals_double(intptr_t* locals, int offset) {
3280   return ((VMJavaVal64*)&locals[Interpreter::local_index_at(-(offset+1))])->d;
3281 }
3282 jlong BytecodeInterpreter::locals_long(intptr_t* locals, int offset) {
3283   return ((VMJavaVal64*)&locals[Interpreter::local_index_at(-(offset+1))])->l;
3284 }
3285 
3286 // Returns the address of locals value.
3287 address BytecodeInterpreter::locals_long_at(intptr_t* locals, int offset) {
3288   return ((address)&locals[Interpreter::local_index_at(-(offset+1))]);
3289 }
3290 address BytecodeInterpreter::locals_double_at(intptr_t* locals, int offset) {
3291   return ((address)&locals[Interpreter::local_index_at(-(offset+1))]);
3292 }
3293 
3294 // Used for local value or returnAddress
3295 void BytecodeInterpreter::set_locals_slot(intptr_t *locals,
3296                                    address value, int offset) {
3297   *((address*)&locals[Interpreter::local_index_at(-offset)]) = value;
3298 }
3299 void BytecodeInterpreter::set_locals_int(intptr_t *locals,
3300                                    jint value, int offset) {
3301   *((jint *)&locals[Interpreter::local_index_at(-offset)]) = value;
3302 }
3303 void BytecodeInterpreter::set_locals_float(intptr_t *locals,
3304                                    jfloat value, int offset) {
3305   *((jfloat *)&locals[Interpreter::local_index_at(-offset)]) = value;
3306 }
3307 void BytecodeInterpreter::set_locals_object(intptr_t *locals,
3308                                    oop value, int offset) {
3309   *((oop *)&locals[Interpreter::local_index_at(-offset)]) = value;
3310 }
3311 void BytecodeInterpreter::set_locals_double(intptr_t *locals,
3312                                    jdouble value, int offset) {
3313   ((VMJavaVal64*)&locals[Interpreter::local_index_at(-(offset+1))])->d = value;
3314 }
3315 void BytecodeInterpreter::set_locals_long(intptr_t *locals,
3316                                    jlong value, int offset) {
3317   ((VMJavaVal64*)&locals[Interpreter::local_index_at(-(offset+1))])->l = value;
3318 }
3319 void BytecodeInterpreter::set_locals_double_from_addr(intptr_t *locals,
3320                                    address addr, int offset) {
3321   ((VMJavaVal64*)&locals[Interpreter::local_index_at(-(offset+1))])->d = ((VMJavaVal64*)addr)->d;
3322 }
3323 void BytecodeInterpreter::set_locals_long_from_addr(intptr_t *locals,
3324                                    address addr, int offset) {
3325   ((VMJavaVal64*)&locals[Interpreter::local_index_at(-(offset+1))])->l = ((VMJavaVal64*)addr)->l;
3326 }
3327 
3328 void BytecodeInterpreter::astore(intptr_t* tos,    int stack_offset,
3329                           intptr_t* locals, int locals_offset) {
3330   intptr_t value = tos[Interpreter::expr_index_at(-stack_offset)];
3331   locals[Interpreter::local_index_at(-locals_offset)] = value;
3332 }
3333 
3334 
3335 void BytecodeInterpreter::copy_stack_slot(intptr_t *tos, int from_offset,
3336                                    int to_offset) {
3337   tos[Interpreter::expr_index_at(-to_offset)] =
3338                       (intptr_t)tos[Interpreter::expr_index_at(-from_offset)];
3339 }
3340 
3341 void BytecodeInterpreter::dup(intptr_t *tos) {
3342   copy_stack_slot(tos, -1, 0);
3343 }
3344 void BytecodeInterpreter::dup2(intptr_t *tos) {
3345   copy_stack_slot(tos, -2, 0);
3346   copy_stack_slot(tos, -1, 1);
3347 }
3348 
3349 void BytecodeInterpreter::dup_x1(intptr_t *tos) {
3350   /* insert top word two down */
3351   copy_stack_slot(tos, -1, 0);
3352   copy_stack_slot(tos, -2, -1);
3353   copy_stack_slot(tos, 0, -2);
3354 }
3355 
3356 void BytecodeInterpreter::dup_x2(intptr_t *tos) {
3357   /* insert top word three down  */
3358   copy_stack_slot(tos, -1, 0);
3359   copy_stack_slot(tos, -2, -1);
3360   copy_stack_slot(tos, -3, -2);
3361   copy_stack_slot(tos, 0, -3);
3362 }
3363 void BytecodeInterpreter::dup2_x1(intptr_t *tos) {
3364   /* insert top 2 slots three down */
3365   copy_stack_slot(tos, -1, 1);
3366   copy_stack_slot(tos, -2, 0);
3367   copy_stack_slot(tos, -3, -1);
3368   copy_stack_slot(tos, 1, -2);
3369   copy_stack_slot(tos, 0, -3);
3370 }
3371 void BytecodeInterpreter::dup2_x2(intptr_t *tos) {
3372   /* insert top 2 slots four down */
3373   copy_stack_slot(tos, -1, 1);
3374   copy_stack_slot(tos, -2, 0);
3375   copy_stack_slot(tos, -3, -1);
3376   copy_stack_slot(tos, -4, -2);
3377   copy_stack_slot(tos, 1, -3);
3378   copy_stack_slot(tos, 0, -4);
3379 }
3380 
3381 
3382 void BytecodeInterpreter::swap(intptr_t *tos) {
3383   // swap top two elements
3384   intptr_t val = tos[Interpreter::expr_index_at(1)];
3385   // Copy -2 entry to -1
3386   copy_stack_slot(tos, -2, -1);
3387   // Store saved -1 entry into -2
3388   tos[Interpreter::expr_index_at(2)] = val;
3389 }
3390 // --------------------------------------------------------------------------------
3391 // Non-product code
3392 #ifndef PRODUCT
3393 
3394 const char* BytecodeInterpreter::C_msg(BytecodeInterpreter::messages msg) {
3395   switch (msg) {
3396      case BytecodeInterpreter::no_request:  return("no_request");
3397      case BytecodeInterpreter::initialize:  return("initialize");
3398      // status message to C++ interpreter
3399      case BytecodeInterpreter::method_entry:  return("method_entry");
3400      case BytecodeInterpreter::method_resume:  return("method_resume");
3401      case BytecodeInterpreter::got_monitors:  return("got_monitors");
3402      case BytecodeInterpreter::rethrow_exception:  return("rethrow_exception");
3403      // requests to frame manager from C++ interpreter
3404      case BytecodeInterpreter::call_method:  return("call_method");
3405      case BytecodeInterpreter::return_from_method:  return("return_from_method");
3406      case BytecodeInterpreter::more_monitors:  return("more_monitors");
3407      case BytecodeInterpreter::throwing_exception:  return("throwing_exception");
3408      case BytecodeInterpreter::popping_frame:  return("popping_frame");
3409      case BytecodeInterpreter::do_osr:  return("do_osr");
3410      // deopt
3411      case BytecodeInterpreter::deopt_resume:  return("deopt_resume");
3412      case BytecodeInterpreter::deopt_resume2:  return("deopt_resume2");
3413      default: return("BAD MSG");
3414   }
3415 }
3416 void
3417 BytecodeInterpreter::print() {
3418   tty->print_cr("thread: " INTPTR_FORMAT, (uintptr_t) this->_thread);
3419   tty->print_cr("bcp: " INTPTR_FORMAT, (uintptr_t) this->_bcp);
3420   tty->print_cr("locals: " INTPTR_FORMAT, (uintptr_t) this->_locals);
3421   tty->print_cr("constants: " INTPTR_FORMAT, (uintptr_t) this->_constants);
3422   {
3423     ResourceMark rm;
3424     char *method_name = _method->name_and_sig_as_C_string();
3425     tty->print_cr("method: " INTPTR_FORMAT "[ %s ]",  (uintptr_t) this->_method, method_name);
3426   }
3427   tty->print_cr("mdx: " INTPTR_FORMAT, (uintptr_t) this->_mdx);
3428   tty->print_cr("stack: " INTPTR_FORMAT, (uintptr_t) this->_stack);
3429   tty->print_cr("msg: %s", C_msg(this->_msg));
3430   tty->print_cr("result_to_call._callee: " INTPTR_FORMAT, (uintptr_t) this->_result._to_call._callee);
3431   tty->print_cr("result_to_call._callee_entry_point: " INTPTR_FORMAT, (uintptr_t) this->_result._to_call._callee_entry_point);
3432   tty->print_cr("result_to_call._bcp_advance: %d ", this->_result._to_call._bcp_advance);
3433   tty->print_cr("osr._osr_buf: " INTPTR_FORMAT, (uintptr_t) this->_result._osr._osr_buf);
3434   tty->print_cr("osr._osr_entry: " INTPTR_FORMAT, (uintptr_t) this->_result._osr._osr_entry);
3435   tty->print_cr("prev_link: " INTPTR_FORMAT, (uintptr_t) this->_prev_link);
3436   tty->print_cr("native_mirror: " INTPTR_FORMAT, (void*) this->_oop_temp);
3437   tty->print_cr("stack_base: " INTPTR_FORMAT, (uintptr_t) this->_stack_base);
3438   tty->print_cr("stack_limit: " INTPTR_FORMAT, (uintptr_t) this->_stack_limit);
3439   tty->print_cr("monitor_base: " INTPTR_FORMAT, (uintptr_t) this->_monitor_base);
3440 #ifdef SPARC
3441   tty->print_cr("last_Java_pc: " INTPTR_FORMAT, (uintptr_t) this->_last_Java_pc);
3442   tty->print_cr("frame_bottom: " INTPTR_FORMAT, (uintptr_t) this->_frame_bottom);
3443   tty->print_cr("&native_fresult: " INTPTR_FORMAT, (uintptr_t) &this->_native_fresult);
3444   tty->print_cr("native_lresult: " INTPTR_FORMAT, (uintptr_t) this->_native_lresult);
3445 #endif
3446 #if !defined(ZERO)
3447   tty->print_cr("last_Java_fp: " INTPTR_FORMAT, (uintptr_t) this->_last_Java_fp);
3448 #endif // !ZERO
3449   tty->print_cr("self_link: " INTPTR_FORMAT, (uintptr_t) this->_self_link);
3450 }
3451 
3452 extern "C" {
3453   void PI(uintptr_t arg) {
3454     ((BytecodeInterpreter*)arg)->print();
3455   }
3456 }
3457 #endif // PRODUCT
3458 
3459 #endif // JVMTI
3460 #endif // CC_INTERP