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