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