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