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 fast 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         }
 645         if (!success) {
 646             CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);
 647         }
 648 
 649       }
 650       THREAD->set_do_not_unlock_if_synchronized(false);
 651 
 652       // Notify jvmti.
 653       // Whenever JVMTI puts a thread in interp_only_mode, method
 654       // entry/exit events are sent for that thread to track stack depth.
 655       if (JVMTI_ENABLED && THREAD->is_interp_only_mode()) {
 656         CALL_VM(InterpreterRuntime::post_method_entry(THREAD),
 657                 handle_exception);
 658       }
 659 
 660       goto run;
 661     }
 662 
 663     case popping_frame: {
 664       // returned from a java call to pop the frame, restart the call
 665       // clear the message so we don't confuse ourselves later
 666       assert(THREAD->pop_frame_in_process(), "wrong frame pop state");
 667       istate->set_msg(no_request);
 668       THREAD->clr_pop_frame_in_process();
 669       goto run;
 670     }
 671 
 672     case method_resume: {
 673       if ((istate->_stack_base - istate->_stack_limit) != istate->method()->max_stack() + 1) {
 674         // resume
 675         os::breakpoint();
 676       }
 677       // returned from a java call, continue executing.
 678       if (THREAD->has_pending_popframe() && !THREAD->pop_frame_in_process()) {
 679         goto handle_Pop_Frame;
 680       }
 681       if (THREAD->jvmti_thread_state() &&
 682           THREAD->jvmti_thread_state()->is_earlyret_pending()) {
 683         goto handle_Early_Return;
 684       }
 685 
 686       if (THREAD->has_pending_exception()) goto handle_exception;
 687       // Update the pc by the saved amount of the invoke bytecode size
 688       UPDATE_PC(istate->bcp_advance());
 689       goto run;
 690     }
 691 
 692     case deopt_resume2: {
 693       // Returned from an opcode that will reexecute. Deopt was
 694       // a result of a PopFrame request.
 695       //
 696       goto run;
 697     }
 698 
 699     case deopt_resume: {
 700       // Returned from an opcode that has completed. The stack has
 701       // the result all we need to do is skip across the bytecode
 702       // and continue (assuming there is no exception pending)
 703       //
 704       // compute continuation length
 705       //
 706       // Note: it is possible to deopt at a return_register_finalizer opcode
 707       // because this requires entering the vm to do the registering. While the
 708       // opcode is complete we can't advance because there are no more opcodes
 709       // much like trying to deopt at a poll return. In that has we simply
 710       // get out of here
 711       //
 712       if ( Bytecodes::code_at(METHOD, pc) == Bytecodes::_return_register_finalizer) {
 713         // this will do the right thing even if an exception is pending.
 714         goto handle_return;
 715       }
 716       UPDATE_PC(Bytecodes::length_at(METHOD, pc));
 717       if (THREAD->has_pending_exception()) goto handle_exception;
 718       goto run;
 719     }
 720     case got_monitors: {
 721       // continue locking now that we have a monitor to use
 722       // we expect to find newly allocated monitor at the "top" of the monitor stack.
 723       oop lockee = STACK_OBJECT(-1);
 724       VERIFY_OOP(lockee);
 725       // derefing's lockee ought to provoke implicit null check
 726       // find a free monitor
 727       BasicObjectLock* entry = (BasicObjectLock*) istate->stack_base();
 728       assert(entry->obj() == nullptr, "Frame manager didn't allocate the monitor");
 729       entry->set_obj(lockee);
 730 
 731       bool success = false;
 732       if (LockingMode == LM_LEGACY) {
 733         // Traditional fast locking.
 734         markWord displaced = lockee->mark().set_unlocked();
 735         entry->lock()->set_displaced_header(displaced);
 736         success = true;
 737         if (lockee->cas_set_mark(markWord::from_pointer(entry), displaced) != displaced) {
 738           // Is it simple recursive case?
 739           if (THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) {
 740             entry->lock()->set_displaced_header(markWord::from_pointer(nullptr));
 741           } else {
 742             success = false;
 743           }
 744         }
 745       }
 746       if (!success) {
 747         CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
 748       }
 749 
 750       UPDATE_PC_AND_TOS(1, -1);
 751       goto run;
 752     }
 753     default: {
 754       fatal("Unexpected message from frame manager");
 755     }
 756   }
 757 
 758 run:
 759 
 760   DO_UPDATE_INSTRUCTION_COUNT(*pc)
 761   DEBUGGER_SINGLE_STEP_NOTIFY();
 762 #ifdef PREFETCH_OPCCODE
 763   opcode = *pc;  /* prefetch first opcode */
 764 #endif
 765 
 766 #ifndef USELABELS
 767   while (1)
 768 #endif
 769   {
 770 #ifndef PREFETCH_OPCCODE
 771       opcode = *pc;
 772 #endif
 773       // Seems like this happens twice per opcode. At worst this is only
 774       // need at entry to the loop.
 775       // DEBUGGER_SINGLE_STEP_NOTIFY();
 776       /* Using this labels avoids double breakpoints when quickening and
 777        * when returning from transition frames.
 778        */
 779   opcode_switch:
 780       assert(istate == orig, "Corrupted istate");
 781       /* QQQ Hmm this has knowledge of direction, ought to be a stack method */
 782       assert(topOfStack >= istate->stack_limit(), "Stack overrun");
 783       assert(topOfStack < istate->stack_base(), "Stack underrun");
 784 
 785 #ifdef USELABELS
 786       DISPATCH(opcode);
 787 #else
 788       switch (opcode)
 789 #endif
 790       {
 791       CASE(_nop):
 792           UPDATE_PC_AND_CONTINUE(1);
 793 
 794           /* Push miscellaneous constants onto the stack. */
 795 
 796       CASE(_aconst_null):
 797           SET_STACK_OBJECT(nullptr, 0);
 798           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
 799 
 800 #undef  OPC_CONST_n
 801 #define OPC_CONST_n(opcode, const_type, value)                          \
 802       CASE(opcode):                                                     \
 803           SET_STACK_ ## const_type(value, 0);                           \
 804           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
 805 
 806           OPC_CONST_n(_iconst_m1,   INT,       -1);
 807           OPC_CONST_n(_iconst_0,    INT,        0);
 808           OPC_CONST_n(_iconst_1,    INT,        1);
 809           OPC_CONST_n(_iconst_2,    INT,        2);
 810           OPC_CONST_n(_iconst_3,    INT,        3);
 811           OPC_CONST_n(_iconst_4,    INT,        4);
 812           OPC_CONST_n(_iconst_5,    INT,        5);
 813           OPC_CONST_n(_fconst_0,    FLOAT,      0.0);
 814           OPC_CONST_n(_fconst_1,    FLOAT,      1.0);
 815           OPC_CONST_n(_fconst_2,    FLOAT,      2.0);
 816 
 817 #undef  OPC_CONST2_n
 818 #define OPC_CONST2_n(opcname, value, key, kind)                         \
 819       CASE(_##opcname):                                                 \
 820       {                                                                 \
 821           SET_STACK_ ## kind(VM##key##Const##value(), 1);               \
 822           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);                         \
 823       }
 824          OPC_CONST2_n(dconst_0, Zero, double, DOUBLE);
 825          OPC_CONST2_n(dconst_1, One,  double, DOUBLE);
 826          OPC_CONST2_n(lconst_0, Zero, long, LONG);
 827          OPC_CONST2_n(lconst_1, One,  long, LONG);
 828 
 829          /* Load constant from constant pool: */
 830 
 831           /* Push a 1-byte signed integer value onto the stack. */
 832       CASE(_bipush):
 833           SET_STACK_INT((jbyte)(pc[1]), 0);
 834           UPDATE_PC_AND_TOS_AND_CONTINUE(2, 1);
 835 
 836           /* Push a 2-byte signed integer constant onto the stack. */
 837       CASE(_sipush):
 838           SET_STACK_INT((int16_t)Bytes::get_Java_u2(pc + 1), 0);
 839           UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1);
 840 
 841           /* load from local variable */
 842 
 843       CASE(_aload):
 844           VERIFY_OOP(LOCALS_OBJECT(pc[1]));
 845           SET_STACK_OBJECT(LOCALS_OBJECT(pc[1]), 0);
 846           UPDATE_PC_AND_TOS_AND_CONTINUE(2, 1);
 847 
 848       CASE(_iload):
 849       {
 850         if (REWRITE_BYTECODES) {
 851           // Attempt to rewrite iload, iload -> fast_iload2
 852           //                    iload, caload -> fast_icaload
 853           // Normal iloads will be rewritten to fast_iload to avoid checking again.
 854           switch (*(pc + 2)) {
 855             case Bytecodes::_fast_iload:
 856               REWRITE_AT_PC(Bytecodes::_fast_iload2);
 857               break;
 858             case Bytecodes::_caload:
 859               REWRITE_AT_PC(Bytecodes::_fast_icaload);
 860               break;
 861             case Bytecodes::_iload:
 862               // Wait until rewritten to _fast_iload.
 863               break;
 864             default:
 865               // Last iload in a (potential) series, don't check again.
 866               REWRITE_AT_PC(Bytecodes::_fast_iload);
 867           }
 868         }
 869         // Normal iload handling.
 870         SET_STACK_SLOT(LOCALS_SLOT(pc[1]), 0);
 871         UPDATE_PC_AND_TOS_AND_CONTINUE(2, 1);
 872       }
 873 
 874       CASE(_nofast_iload):
 875       {
 876         // Normal, non-rewritable iload handling.
 877         SET_STACK_SLOT(LOCALS_SLOT(pc[1]), 0);
 878         UPDATE_PC_AND_TOS_AND_CONTINUE(2, 1);
 879       }
 880 
 881       CASE(_fast_iload):
 882       CASE(_fload):
 883           SET_STACK_SLOT(LOCALS_SLOT(pc[1]), 0);
 884           UPDATE_PC_AND_TOS_AND_CONTINUE(2, 1);
 885 
 886       CASE(_fast_iload2):
 887           SET_STACK_SLOT(LOCALS_SLOT(pc[1]), 0);
 888           SET_STACK_SLOT(LOCALS_SLOT(pc[3]), 1);
 889           UPDATE_PC_AND_TOS_AND_CONTINUE(4, 2);
 890 
 891       CASE(_lload):
 892           SET_STACK_LONG_FROM_ADDR(LOCALS_LONG_AT(pc[1]), 1);
 893           UPDATE_PC_AND_TOS_AND_CONTINUE(2, 2);
 894 
 895       CASE(_dload):
 896           SET_STACK_DOUBLE_FROM_ADDR(LOCALS_DOUBLE_AT(pc[1]), 1);
 897           UPDATE_PC_AND_TOS_AND_CONTINUE(2, 2);
 898 
 899 #undef  OPC_LOAD_n
 900 #define OPC_LOAD_n(num)                                                 \
 901       CASE(_iload_##num):                                               \
 902       CASE(_fload_##num):                                               \
 903           SET_STACK_SLOT(LOCALS_SLOT(num), 0);                          \
 904           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);                         \
 905                                                                         \
 906       CASE(_lload_##num):                                               \
 907           SET_STACK_LONG_FROM_ADDR(LOCALS_LONG_AT(num), 1);             \
 908           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);                         \
 909       CASE(_dload_##num):                                               \
 910           SET_STACK_DOUBLE_FROM_ADDR(LOCALS_DOUBLE_AT(num), 1);         \
 911           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
 912 
 913       OPC_LOAD_n(0);
 914       OPC_LOAD_n(1);
 915       OPC_LOAD_n(2);
 916       OPC_LOAD_n(3);
 917 
 918 #undef  OPC_ALOAD_n
 919 #define OPC_ALOAD_n(num)                                                \
 920       CASE(_aload_##num): {                                             \
 921           oop obj = LOCALS_OBJECT(num);                                 \
 922           VERIFY_OOP(obj);                                              \
 923           SET_STACK_OBJECT(obj, 0);                                     \
 924           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);                         \
 925       }
 926 
 927       CASE(_aload_0):
 928       {
 929         /* Maybe rewrite if following bytecode is one of the supported _fast_Xgetfield bytecodes. */
 930         if (REWRITE_BYTECODES) {
 931           switch (*(pc + 1)) {
 932             case Bytecodes::_fast_agetfield:
 933               REWRITE_AT_PC(Bytecodes::_fast_aaccess_0);
 934               break;
 935             case Bytecodes::_fast_fgetfield:
 936               REWRITE_AT_PC(Bytecodes::_fast_faccess_0);
 937               break;
 938             case Bytecodes::_fast_igetfield:
 939               REWRITE_AT_PC(Bytecodes::_fast_iaccess_0);
 940               break;
 941             case Bytecodes::_getfield:
 942             case Bytecodes::_nofast_getfield: {
 943               /* Otherwise, do nothing here, wait until/if it gets rewritten to _fast_Xgetfield.
 944                * Unfortunately, this punishes volatile field access, because it never gets
 945                * rewritten. */
 946               break;
 947             }
 948             default:
 949               REWRITE_AT_PC(Bytecodes::_fast_aload_0);
 950               break;
 951           }
 952         }
 953         // Normal aload_0 handling.
 954         VERIFY_OOP(LOCALS_OBJECT(0));
 955         SET_STACK_OBJECT(LOCALS_OBJECT(0), 0);
 956         UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
 957       }
 958 
 959       CASE(_nofast_aload_0):
 960       {
 961         // Normal, non-rewritable aload_0 handling.
 962         VERIFY_OOP(LOCALS_OBJECT(0));
 963         SET_STACK_OBJECT(LOCALS_OBJECT(0), 0);
 964         UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
 965       }
 966 
 967       OPC_ALOAD_n(1);
 968       OPC_ALOAD_n(2);
 969       OPC_ALOAD_n(3);
 970 
 971           /* store to a local variable */
 972 
 973       CASE(_astore):
 974           astore(topOfStack, -1, locals, pc[1]);
 975           UPDATE_PC_AND_TOS_AND_CONTINUE(2, -1);
 976 
 977       CASE(_istore):
 978       CASE(_fstore):
 979           SET_LOCALS_SLOT(STACK_SLOT(-1), pc[1]);
 980           UPDATE_PC_AND_TOS_AND_CONTINUE(2, -1);
 981 
 982       CASE(_lstore):
 983           SET_LOCALS_LONG(STACK_LONG(-1), pc[1]);
 984           UPDATE_PC_AND_TOS_AND_CONTINUE(2, -2);
 985 
 986       CASE(_dstore):
 987           SET_LOCALS_DOUBLE(STACK_DOUBLE(-1), pc[1]);
 988           UPDATE_PC_AND_TOS_AND_CONTINUE(2, -2);
 989 
 990       CASE(_wide): {
 991           uint16_t reg = Bytes::get_Java_u2(pc + 2);
 992 
 993           opcode = pc[1];
 994 
 995           // Wide and it's sub-bytecode are counted as separate instructions. If we
 996           // don't account for this here, the bytecode trace skips the next bytecode.
 997           DO_UPDATE_INSTRUCTION_COUNT(opcode);
 998 
 999           switch(opcode) {
1000               case Bytecodes::_aload:
1001                   VERIFY_OOP(LOCALS_OBJECT(reg));
1002                   SET_STACK_OBJECT(LOCALS_OBJECT(reg), 0);
1003                   UPDATE_PC_AND_TOS_AND_CONTINUE(4, 1);
1004 
1005               case Bytecodes::_iload:
1006               case Bytecodes::_fload:
1007                   SET_STACK_SLOT(LOCALS_SLOT(reg), 0);
1008                   UPDATE_PC_AND_TOS_AND_CONTINUE(4, 1);
1009 
1010               case Bytecodes::_lload:
1011                   SET_STACK_LONG_FROM_ADDR(LOCALS_LONG_AT(reg), 1);
1012                   UPDATE_PC_AND_TOS_AND_CONTINUE(4, 2);
1013 
1014               case Bytecodes::_dload:
1015                   SET_STACK_DOUBLE_FROM_ADDR(LOCALS_LONG_AT(reg), 1);
1016                   UPDATE_PC_AND_TOS_AND_CONTINUE(4, 2);
1017 
1018               case Bytecodes::_astore:
1019                   astore(topOfStack, -1, locals, reg);
1020                   UPDATE_PC_AND_TOS_AND_CONTINUE(4, -1);
1021 
1022               case Bytecodes::_istore:
1023               case Bytecodes::_fstore:
1024                   SET_LOCALS_SLOT(STACK_SLOT(-1), reg);
1025                   UPDATE_PC_AND_TOS_AND_CONTINUE(4, -1);
1026 
1027               case Bytecodes::_lstore:
1028                   SET_LOCALS_LONG(STACK_LONG(-1), reg);
1029                   UPDATE_PC_AND_TOS_AND_CONTINUE(4, -2);
1030 
1031               case Bytecodes::_dstore:
1032                   SET_LOCALS_DOUBLE(STACK_DOUBLE(-1), reg);
1033                   UPDATE_PC_AND_TOS_AND_CONTINUE(4, -2);
1034 
1035               case Bytecodes::_iinc: {
1036                   int16_t offset = (int16_t)Bytes::get_Java_u2(pc+4);
1037                   // Be nice to see what this generates.... QQQ
1038                   SET_LOCALS_INT(LOCALS_INT(reg) + offset, reg);
1039                   UPDATE_PC_AND_CONTINUE(6);
1040               }
1041               case Bytecodes::_ret:
1042                   pc = istate->method()->code_base() + (intptr_t)(LOCALS_ADDR(reg));
1043                   UPDATE_PC_AND_CONTINUE(0);
1044               default:
1045                   VM_JAVA_ERROR(vmSymbols::java_lang_InternalError(), "undefined opcode");
1046           }
1047       }
1048 
1049 
1050 #undef  OPC_STORE_n
1051 #define OPC_STORE_n(num)                                                \
1052       CASE(_astore_##num):                                              \
1053           astore(topOfStack, -1, locals, num);                          \
1054           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);                        \
1055       CASE(_istore_##num):                                              \
1056       CASE(_fstore_##num):                                              \
1057           SET_LOCALS_SLOT(STACK_SLOT(-1), num);                         \
1058           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1059 
1060           OPC_STORE_n(0);
1061           OPC_STORE_n(1);
1062           OPC_STORE_n(2);
1063           OPC_STORE_n(3);
1064 
1065 #undef  OPC_DSTORE_n
1066 #define OPC_DSTORE_n(num)                                               \
1067       CASE(_dstore_##num):                                              \
1068           SET_LOCALS_DOUBLE(STACK_DOUBLE(-1), num);                     \
1069           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2);                        \
1070       CASE(_lstore_##num):                                              \
1071           SET_LOCALS_LONG(STACK_LONG(-1), num);                         \
1072           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2);
1073 
1074           OPC_DSTORE_n(0);
1075           OPC_DSTORE_n(1);
1076           OPC_DSTORE_n(2);
1077           OPC_DSTORE_n(3);
1078 
1079           /* stack pop, dup, and insert opcodes */
1080 
1081 
1082       CASE(_pop):                /* Discard the top item on the stack */
1083           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1084 
1085 
1086       CASE(_pop2):               /* Discard the top 2 items on the stack */
1087           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2);
1088 
1089 
1090       CASE(_dup):               /* Duplicate the top item on the stack */
1091           dup(topOfStack);
1092           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1093 
1094       CASE(_dup2):              /* Duplicate the top 2 items on the stack */
1095           dup2(topOfStack);
1096           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1097 
1098       CASE(_dup_x1):    /* insert top word two down */
1099           dup_x1(topOfStack);
1100           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1101 
1102       CASE(_dup_x2):    /* insert top word three down  */
1103           dup_x2(topOfStack);
1104           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1105 
1106       CASE(_dup2_x1):   /* insert top 2 slots three down */
1107           dup2_x1(topOfStack);
1108           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1109 
1110       CASE(_dup2_x2):   /* insert top 2 slots four down */
1111           dup2_x2(topOfStack);
1112           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1113 
1114       CASE(_swap): {        /* swap top two elements on the stack */
1115           swap(topOfStack);
1116           UPDATE_PC_AND_CONTINUE(1);
1117       }
1118 
1119           /* Perform various binary integer operations */
1120 
1121 #undef  OPC_INT_BINARY
1122 #define OPC_INT_BINARY(opcname, opname, test)                           \
1123       CASE(_i##opcname):                                                \
1124           if (test && (STACK_INT(-1) == 0)) {                           \
1125               VM_JAVA_ERROR(vmSymbols::java_lang_ArithmeticException(), \
1126                             "/ by zero");                               \
1127           }                                                             \
1128           SET_STACK_INT(VMint##opname(STACK_INT(-2),                    \
1129                                       STACK_INT(-1)),                   \
1130                                       -2);                              \
1131           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);                        \
1132       CASE(_l##opcname):                                                \
1133       {                                                                 \
1134           if (test) {                                                   \
1135             jlong l1 = STACK_LONG(-1);                                  \
1136             if (VMlongEqz(l1)) {                                        \
1137               VM_JAVA_ERROR(vmSymbols::java_lang_ArithmeticException(), \
1138                             "/ by long zero");                          \
1139             }                                                           \
1140           }                                                             \
1141           /* First long at (-1,-2) next long at (-3,-4) */              \
1142           SET_STACK_LONG(VMlong##opname(STACK_LONG(-3),                 \
1143                                         STACK_LONG(-1)),                \
1144                                         -3);                            \
1145           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2);                        \
1146       }
1147 
1148       OPC_INT_BINARY(add, Add, 0);
1149       OPC_INT_BINARY(sub, Sub, 0);
1150       OPC_INT_BINARY(mul, Mul, 0);
1151       OPC_INT_BINARY(and, And, 0);
1152       OPC_INT_BINARY(or,  Or,  0);
1153       OPC_INT_BINARY(xor, Xor, 0);
1154       OPC_INT_BINARY(div, Div, 1);
1155       OPC_INT_BINARY(rem, Rem, 1);
1156 
1157 
1158       /* Perform various binary floating number operations */
1159       /* On some machine/platforms/compilers div zero check can be implicit */
1160 
1161 #undef  OPC_FLOAT_BINARY
1162 #define OPC_FLOAT_BINARY(opcname, opname)                                  \
1163       CASE(_d##opcname): {                                                 \
1164           SET_STACK_DOUBLE(VMdouble##opname(STACK_DOUBLE(-3),              \
1165                                             STACK_DOUBLE(-1)),             \
1166                                             -3);                           \
1167           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2);                           \
1168       }                                                                    \
1169       CASE(_f##opcname):                                                   \
1170           SET_STACK_FLOAT(VMfloat##opname(STACK_FLOAT(-2),                 \
1171                                           STACK_FLOAT(-1)),                \
1172                                           -2);                             \
1173           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1174 
1175 
1176      OPC_FLOAT_BINARY(add, Add);
1177      OPC_FLOAT_BINARY(sub, Sub);
1178      OPC_FLOAT_BINARY(mul, Mul);
1179      OPC_FLOAT_BINARY(div, Div);
1180      OPC_FLOAT_BINARY(rem, Rem);
1181 
1182       /* Shift operations
1183        * Shift left int and long: ishl, lshl
1184        * Logical shift right int and long w/zero extension: iushr, lushr
1185        * Arithmetic shift right int and long w/sign extension: ishr, lshr
1186        */
1187 
1188 #undef  OPC_SHIFT_BINARY
1189 #define OPC_SHIFT_BINARY(opcname, opname)                               \
1190       CASE(_i##opcname):                                                \
1191          SET_STACK_INT(VMint##opname(STACK_INT(-2),                     \
1192                                      STACK_INT(-1)),                    \
1193                                      -2);                               \
1194          UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);                         \
1195       CASE(_l##opcname):                                                \
1196       {                                                                 \
1197          SET_STACK_LONG(VMlong##opname(STACK_LONG(-2),                  \
1198                                        STACK_INT(-1)),                  \
1199                                        -2);                             \
1200          UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);                         \
1201       }
1202 
1203       OPC_SHIFT_BINARY(shl, Shl);
1204       OPC_SHIFT_BINARY(shr, Shr);
1205       OPC_SHIFT_BINARY(ushr, Ushr);
1206 
1207      /* Increment local variable by constant */
1208       CASE(_iinc):
1209       {
1210           // locals[pc[1]].j.i += (jbyte)(pc[2]);
1211           SET_LOCALS_INT(LOCALS_INT(pc[1]) + (jbyte)(pc[2]), pc[1]);
1212           UPDATE_PC_AND_CONTINUE(3);
1213       }
1214 
1215      /* negate the value on the top of the stack */
1216 
1217       CASE(_ineg):
1218          SET_STACK_INT(VMintNeg(STACK_INT(-1)), -1);
1219          UPDATE_PC_AND_CONTINUE(1);
1220 
1221       CASE(_fneg):
1222          SET_STACK_FLOAT(VMfloatNeg(STACK_FLOAT(-1)), -1);
1223          UPDATE_PC_AND_CONTINUE(1);
1224 
1225       CASE(_lneg):
1226       {
1227          SET_STACK_LONG(VMlongNeg(STACK_LONG(-1)), -1);
1228          UPDATE_PC_AND_CONTINUE(1);
1229       }
1230 
1231       CASE(_dneg):
1232       {
1233          SET_STACK_DOUBLE(VMdoubleNeg(STACK_DOUBLE(-1)), -1);
1234          UPDATE_PC_AND_CONTINUE(1);
1235       }
1236 
1237       /* Conversion operations */
1238 
1239       CASE(_i2f):       /* convert top of stack int to float */
1240          SET_STACK_FLOAT(VMint2Float(STACK_INT(-1)), -1);
1241          UPDATE_PC_AND_CONTINUE(1);
1242 
1243       CASE(_i2l):       /* convert top of stack int to long */
1244       {
1245           // this is ugly QQQ
1246           jlong r = VMint2Long(STACK_INT(-1));
1247           MORE_STACK(-1); // Pop
1248           SET_STACK_LONG(r, 1);
1249 
1250           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1251       }
1252 
1253       CASE(_i2d):       /* convert top of stack int to double */
1254       {
1255           // this is ugly QQQ (why cast to jlong?? )
1256           jdouble r = (jlong)STACK_INT(-1);
1257           MORE_STACK(-1); // Pop
1258           SET_STACK_DOUBLE(r, 1);
1259 
1260           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1261       }
1262 
1263       CASE(_l2i):       /* convert top of stack long to int */
1264       {
1265           jint r = VMlong2Int(STACK_LONG(-1));
1266           MORE_STACK(-2); // Pop
1267           SET_STACK_INT(r, 0);
1268           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1269       }
1270 
1271       CASE(_l2f):   /* convert top of stack long to float */
1272       {
1273           jlong r = STACK_LONG(-1);
1274           MORE_STACK(-2); // Pop
1275           SET_STACK_FLOAT(VMlong2Float(r), 0);
1276           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1277       }
1278 
1279       CASE(_l2d):       /* convert top of stack long to double */
1280       {
1281           jlong r = STACK_LONG(-1);
1282           MORE_STACK(-2); // Pop
1283           SET_STACK_DOUBLE(VMlong2Double(r), 1);
1284           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1285       }
1286 
1287       CASE(_f2i):  /* Convert top of stack float to int */
1288           SET_STACK_INT(SharedRuntime::f2i(STACK_FLOAT(-1)), -1);
1289           UPDATE_PC_AND_CONTINUE(1);
1290 
1291       CASE(_f2l):  /* convert top of stack float to long */
1292       {
1293           jlong r = SharedRuntime::f2l(STACK_FLOAT(-1));
1294           MORE_STACK(-1); // POP
1295           SET_STACK_LONG(r, 1);
1296           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1297       }
1298 
1299       CASE(_f2d):  /* convert top of stack float to double */
1300       {
1301           jfloat f;
1302           jdouble r;
1303           f = STACK_FLOAT(-1);
1304           r = (jdouble) f;
1305           MORE_STACK(-1); // POP
1306           SET_STACK_DOUBLE(r, 1);
1307           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1308       }
1309 
1310       CASE(_d2i): /* convert top of stack double to int */
1311       {
1312           jint r1 = SharedRuntime::d2i(STACK_DOUBLE(-1));
1313           MORE_STACK(-2);
1314           SET_STACK_INT(r1, 0);
1315           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1316       }
1317 
1318       CASE(_d2f): /* convert top of stack double to float */
1319       {
1320           jfloat r1 = VMdouble2Float(STACK_DOUBLE(-1));
1321           MORE_STACK(-2);
1322           SET_STACK_FLOAT(r1, 0);
1323           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1324       }
1325 
1326       CASE(_d2l): /* convert top of stack double to long */
1327       {
1328           jlong r1 = SharedRuntime::d2l(STACK_DOUBLE(-1));
1329           MORE_STACK(-2);
1330           SET_STACK_LONG(r1, 1);
1331           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1332       }
1333 
1334       CASE(_i2b):
1335           SET_STACK_INT(VMint2Byte(STACK_INT(-1)), -1);
1336           UPDATE_PC_AND_CONTINUE(1);
1337 
1338       CASE(_i2c):
1339           SET_STACK_INT(VMint2Char(STACK_INT(-1)), -1);
1340           UPDATE_PC_AND_CONTINUE(1);
1341 
1342       CASE(_i2s):
1343           SET_STACK_INT(VMint2Short(STACK_INT(-1)), -1);
1344           UPDATE_PC_AND_CONTINUE(1);
1345 
1346       /* comparison operators */
1347 
1348 
1349 #define COMPARISON_OP(name, comparison)                                      \
1350       CASE(_if_icmp##name): {                                                \
1351           int skip = (STACK_INT(-2) comparison STACK_INT(-1))                \
1352                       ? (int16_t)Bytes::get_Java_u2(pc + 1) : 3;             \
1353           address branch_pc = pc;                                            \
1354           UPDATE_PC_AND_TOS(skip, -2);                                       \
1355           DO_BACKEDGE_CHECKS(skip, branch_pc);                               \
1356           CONTINUE;                                                          \
1357       }                                                                      \
1358       CASE(_if##name): {                                                     \
1359           int skip = (STACK_INT(-1) comparison 0)                            \
1360                       ? (int16_t)Bytes::get_Java_u2(pc + 1) : 3;             \
1361           address branch_pc = pc;                                            \
1362           UPDATE_PC_AND_TOS(skip, -1);                                       \
1363           DO_BACKEDGE_CHECKS(skip, branch_pc);                               \
1364           CONTINUE;                                                          \
1365       }
1366 
1367 #define COMPARISON_OP2(name, comparison)                                     \
1368       COMPARISON_OP(name, comparison)                                        \
1369       CASE(_if_acmp##name): {                                                \
1370           int skip = (STACK_OBJECT(-2) comparison STACK_OBJECT(-1))          \
1371                        ? (int16_t)Bytes::get_Java_u2(pc + 1) : 3;            \
1372           address branch_pc = pc;                                            \
1373           UPDATE_PC_AND_TOS(skip, -2);                                       \
1374           DO_BACKEDGE_CHECKS(skip, branch_pc);                               \
1375           CONTINUE;                                                          \
1376       }
1377 
1378 #define NULL_COMPARISON_NOT_OP(name)                                         \
1379       CASE(_if##name): {                                                     \
1380           int skip = (!(STACK_OBJECT(-1) == nullptr))                           \
1381                       ? (int16_t)Bytes::get_Java_u2(pc + 1) : 3;             \
1382           address branch_pc = pc;                                            \
1383           UPDATE_PC_AND_TOS(skip, -1);                                       \
1384           DO_BACKEDGE_CHECKS(skip, branch_pc);                               \
1385           CONTINUE;                                                          \
1386       }
1387 
1388 #define NULL_COMPARISON_OP(name)                                             \
1389       CASE(_if##name): {                                                     \
1390           int skip = ((STACK_OBJECT(-1) == nullptr))                            \
1391                       ? (int16_t)Bytes::get_Java_u2(pc + 1) : 3;             \
1392           address branch_pc = pc;                                            \
1393           UPDATE_PC_AND_TOS(skip, -1);                                       \
1394           DO_BACKEDGE_CHECKS(skip, branch_pc);                               \
1395           CONTINUE;                                                          \
1396       }
1397       COMPARISON_OP(lt, <);
1398       COMPARISON_OP(gt, >);
1399       COMPARISON_OP(le, <=);
1400       COMPARISON_OP(ge, >=);
1401       COMPARISON_OP2(eq, ==);  /* include ref comparison */
1402       COMPARISON_OP2(ne, !=);  /* include ref comparison */
1403       NULL_COMPARISON_OP(null);
1404       NULL_COMPARISON_NOT_OP(nonnull);
1405 
1406       /* Goto pc at specified offset in switch table. */
1407 
1408       CASE(_tableswitch): {
1409           jint* lpc  = (jint*)VMalignWordUp(pc+1);
1410           int32_t  key  = STACK_INT(-1);
1411           int32_t  low  = Bytes::get_Java_u4((address)&lpc[1]);
1412           int32_t  high = Bytes::get_Java_u4((address)&lpc[2]);
1413           int32_t  skip;
1414           key -= low;
1415           if (((uint32_t) key > (uint32_t)(high - low))) {
1416             skip = Bytes::get_Java_u4((address)&lpc[0]);
1417           } else {
1418             skip = Bytes::get_Java_u4((address)&lpc[key + 3]);
1419           }
1420           // Does this really need a full backedge check (osr)?
1421           address branch_pc = pc;
1422           UPDATE_PC_AND_TOS(skip, -1);
1423           DO_BACKEDGE_CHECKS(skip, branch_pc);
1424           CONTINUE;
1425       }
1426 
1427       /* Goto pc whose table entry matches specified key. */
1428 
1429       CASE(_lookupswitch): {
1430           jint* lpc  = (jint*)VMalignWordUp(pc+1);
1431           int32_t  key  = STACK_INT(-1);
1432           int32_t  skip = Bytes::get_Java_u4((address) lpc); /* default amount */
1433           int32_t  npairs = Bytes::get_Java_u4((address) &lpc[1]);
1434           while (--npairs >= 0) {
1435             lpc += 2;
1436             if (key == (int32_t)Bytes::get_Java_u4((address)lpc)) {
1437               skip = Bytes::get_Java_u4((address)&lpc[1]);
1438               break;
1439             }
1440           }
1441           address branch_pc = pc;
1442           UPDATE_PC_AND_TOS(skip, -1);
1443           DO_BACKEDGE_CHECKS(skip, branch_pc);
1444           CONTINUE;
1445       }
1446 
1447       CASE(_fcmpl):
1448       CASE(_fcmpg):
1449       {
1450           SET_STACK_INT(VMfloatCompare(STACK_FLOAT(-2),
1451                                         STACK_FLOAT(-1),
1452                                         (opcode == Bytecodes::_fcmpl ? -1 : 1)),
1453                         -2);
1454           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1455       }
1456 
1457       CASE(_dcmpl):
1458       CASE(_dcmpg):
1459       {
1460           int r = VMdoubleCompare(STACK_DOUBLE(-3),
1461                                   STACK_DOUBLE(-1),
1462                                   (opcode == Bytecodes::_dcmpl ? -1 : 1));
1463           MORE_STACK(-4); // Pop
1464           SET_STACK_INT(r, 0);
1465           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1466       }
1467 
1468       CASE(_lcmp):
1469       {
1470           int r = VMlongCompare(STACK_LONG(-3), STACK_LONG(-1));
1471           MORE_STACK(-4);
1472           SET_STACK_INT(r, 0);
1473           UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1474       }
1475 
1476 
1477       /* Return from a method */
1478 
1479       CASE(_areturn):
1480       CASE(_ireturn):
1481       CASE(_freturn):
1482       CASE(_lreturn):
1483       CASE(_dreturn):
1484       CASE(_return): {
1485           // Allow a safepoint before returning to frame manager.
1486           RETURN_SAFEPOINT;
1487           goto handle_return;
1488       }
1489 
1490       CASE(_return_register_finalizer): {
1491           oop rcvr = LOCALS_OBJECT(0);
1492           VERIFY_OOP(rcvr);
1493           if (rcvr->klass()->has_finalizer()) {
1494             CALL_VM(InterpreterRuntime::register_finalizer(THREAD, rcvr), handle_exception);
1495           }
1496           goto handle_return;
1497       }
1498 
1499       /* Array access byte-codes */
1500 
1501 #define ARRAY_INDEX_CHECK(arrObj, index)                                       \
1502       /* Two integers, the additional message, and the null-terminator */      \
1503       char message[2 * jintAsStringSize + 33];                                 \
1504       CHECK_NULL(arrObj);                                                      \
1505       if ((uint32_t)index >= (uint32_t)arrObj->length()) {                     \
1506           jio_snprintf(message, sizeof(message),                               \
1507                   "Index %d out of bounds for length %d",                      \
1508                   index, arrObj->length());                                    \
1509           VM_JAVA_ERROR(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), \
1510                         message);                                              \
1511       }
1512 
1513       /* Every array access byte-code starts out like this */
1514 //        arrayOopDesc* arrObj = (arrayOopDesc*)STACK_OBJECT(arrayOff);
1515 #define ARRAY_INTRO(arrayOff)                                                  \
1516       arrayOop arrObj = (arrayOop)STACK_OBJECT(arrayOff);                      \
1517       jint     index  = STACK_INT(arrayOff + 1);                               \
1518       ARRAY_INDEX_CHECK(arrObj, index)
1519 
1520       /* 32-bit loads. These handle conversion from < 32-bit types */
1521 #define ARRAY_LOADTO32(T, T2, format, stackRes, extra)                                \
1522       {                                                                               \
1523           ARRAY_INTRO(-2);                                                            \
1524           (void)extra;                                                                \
1525           SET_ ## stackRes(*(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)), \
1526                            -2);                                                       \
1527           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);                                      \
1528       }
1529 
1530       /* 64-bit loads */
1531 #define ARRAY_LOADTO64(T,T2, stackRes, extra)                                              \
1532       {                                                                                    \
1533           ARRAY_INTRO(-2);                                                                 \
1534           SET_ ## stackRes(*(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)), -1); \
1535           (void)extra;                                                                     \
1536           UPDATE_PC_AND_CONTINUE(1);                                                       \
1537       }
1538 
1539       CASE(_iaload):
1540           ARRAY_LOADTO32(T_INT, jint,   "%d",   STACK_INT, 0);
1541       CASE(_faload):
1542           ARRAY_LOADTO32(T_FLOAT, jfloat, "%f",   STACK_FLOAT, 0);
1543       CASE(_aaload): {
1544           ARRAY_INTRO(-2);
1545           SET_STACK_OBJECT(((objArrayOop) arrObj)->obj_at(index), -2);
1546           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1547       }
1548       CASE(_baload):
1549           ARRAY_LOADTO32(T_BYTE, jbyte,  "%d",   STACK_INT, 0);
1550       CASE(_caload):
1551           ARRAY_LOADTO32(T_CHAR,  jchar, "%d",   STACK_INT, 0);
1552       CASE(_saload):
1553           ARRAY_LOADTO32(T_SHORT, jshort, "%d",   STACK_INT, 0);
1554       CASE(_laload):
1555           ARRAY_LOADTO64(T_LONG, jlong, STACK_LONG, 0);
1556       CASE(_daload):
1557           ARRAY_LOADTO64(T_DOUBLE, jdouble, STACK_DOUBLE, 0);
1558 
1559       CASE(_fast_icaload): {
1560           // Custom fast access for iload,caload pair.
1561           arrayOop arrObj = (arrayOop) STACK_OBJECT(-1);
1562           jint index = LOCALS_INT(pc[1]);
1563           ARRAY_INDEX_CHECK(arrObj, index);
1564           SET_STACK_INT(*(jchar *)(((address) arrObj->base(T_CHAR)) + index * sizeof(jchar)), -1);
1565           UPDATE_PC_AND_TOS_AND_CONTINUE(3, 0);
1566       }
1567 
1568       /* 32-bit stores. These handle conversion to < 32-bit types */
1569 #define ARRAY_STOREFROM32(T, T2, format, stackSrc, extra)                            \
1570       {                                                                              \
1571           ARRAY_INTRO(-3);                                                           \
1572           (void)extra;                                                               \
1573           *(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)) = stackSrc( -1); \
1574           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -3);                                     \
1575       }
1576 
1577       /* 64-bit stores */
1578 #define ARRAY_STOREFROM64(T, T2, stackSrc, extra)                                    \
1579       {                                                                              \
1580           ARRAY_INTRO(-4);                                                           \
1581           (void)extra;                                                               \
1582           *(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)) = stackSrc( -1); \
1583           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -4);                                     \
1584       }
1585 
1586       CASE(_iastore):
1587           ARRAY_STOREFROM32(T_INT, jint,   "%d",   STACK_INT, 0);
1588       CASE(_fastore):
1589           ARRAY_STOREFROM32(T_FLOAT, jfloat, "%f",   STACK_FLOAT, 0);
1590       /*
1591        * This one looks different because of the assignability check
1592        */
1593       CASE(_aastore): {
1594           oop rhsObject = STACK_OBJECT(-1);
1595           VERIFY_OOP(rhsObject);
1596           ARRAY_INTRO( -3);
1597           // arrObj, index are set
1598           if (rhsObject != nullptr) {
1599             /* Check assignability of rhsObject into arrObj */
1600             Klass* rhsKlass = rhsObject->klass(); // EBX (subclass)
1601             Klass* elemKlass = ObjArrayKlass::cast(arrObj->klass())->element_klass(); // superklass EAX
1602             //
1603             // Check for compatibility. This check must not GC!!
1604             // Seems way more expensive now that we must dispatch
1605             //
1606             if (rhsKlass != elemKlass && !rhsKlass->is_subtype_of(elemKlass)) { // ebx->is...
1607               VM_JAVA_ERROR(vmSymbols::java_lang_ArrayStoreException(), "");
1608             }
1609           }
1610           ((objArrayOop) arrObj)->obj_at_put(index, rhsObject);
1611           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -3);
1612       }
1613       CASE(_bastore): {
1614           ARRAY_INTRO(-3);
1615           int item = STACK_INT(-1);
1616           // if it is a T_BOOLEAN array, mask the stored value to 0/1
1617           if (arrObj->klass() == Universe::boolArrayKlass()) {
1618             item &= 1;
1619           } else {
1620             assert(arrObj->klass() == Universe::byteArrayKlass(),
1621                    "should be byte array otherwise");
1622           }
1623           ((typeArrayOop)arrObj)->byte_at_put(index, item);
1624           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -3);
1625       }
1626       CASE(_castore):
1627           ARRAY_STOREFROM32(T_CHAR, jchar,  "%d",   STACK_INT, 0);
1628       CASE(_sastore):
1629           ARRAY_STOREFROM32(T_SHORT, jshort, "%d",   STACK_INT, 0);
1630       CASE(_lastore):
1631           ARRAY_STOREFROM64(T_LONG, jlong, STACK_LONG, 0);
1632       CASE(_dastore):
1633           ARRAY_STOREFROM64(T_DOUBLE, jdouble, STACK_DOUBLE, 0);
1634 
1635       CASE(_arraylength):
1636       {
1637           arrayOop ary = (arrayOop) STACK_OBJECT(-1);
1638           CHECK_NULL(ary);
1639           SET_STACK_INT(ary->length(), -1);
1640           UPDATE_PC_AND_CONTINUE(1);
1641       }
1642 
1643       /* monitorenter and monitorexit for locking/unlocking an object */
1644 
1645       CASE(_monitorenter): {
1646         oop lockee = STACK_OBJECT(-1);
1647         // derefing's lockee ought to provoke implicit null check
1648         CHECK_NULL(lockee);
1649         // find a free monitor or one already allocated for this object
1650         // if we find a matching object then we need a new monitor
1651         // since this is recursive enter
1652         BasicObjectLock* limit = istate->monitor_base();
1653         BasicObjectLock* most_recent = (BasicObjectLock*) istate->stack_base();
1654         BasicObjectLock* entry = nullptr;
1655         while (most_recent != limit ) {
1656           if (most_recent->obj() == nullptr) entry = most_recent;
1657           else if (most_recent->obj() == lockee) break;
1658           most_recent++;
1659         }
1660         if (entry != nullptr) {
1661           entry->set_obj(lockee);
1662 
1663           bool success = false;
1664           if (LockingMode == LM_LEGACY) {
1665             // Traditional fast locking.
1666             markWord displaced = lockee->mark().set_unlocked();
1667             entry->lock()->set_displaced_header(displaced);
1668             success = true;
1669             if (lockee->cas_set_mark(markWord::from_pointer(entry), displaced) != displaced) {
1670               // Is it simple recursive case?
1671               if (THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) {
1672                 entry->lock()->set_displaced_header(markWord::from_pointer(nullptr));
1673               } else {
1674                 success = false;
1675               }
1676             }
1677           }
1678           if (!success) {
1679             CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
1680           }
1681 
1682           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1683         } else {
1684           istate->set_msg(more_monitors);
1685           UPDATE_PC_AND_RETURN(0); // Re-execute
1686         }
1687       }
1688 
1689       CASE(_monitorexit): {
1690         oop lockee = STACK_OBJECT(-1);
1691         CHECK_NULL(lockee);
1692         // derefing's lockee ought to provoke implicit null check
1693         // find our monitor slot
1694         BasicObjectLock* limit = istate->monitor_base();
1695         BasicObjectLock* most_recent = (BasicObjectLock*) istate->stack_base();
1696         while (most_recent != limit ) {
1697           if ((most_recent)->obj() == lockee) {
1698             BasicLock* lock = most_recent->lock();
1699 
1700             bool success = false;
1701             if (LockingMode == LM_LEGACY) {
1702               // If it isn't recursive we either must swap old header or call the runtime
1703               most_recent->set_obj(nullptr);
1704               success = true;
1705               markWord header = lock->displaced_header();
1706               if (header.to_pointer() != nullptr) {
1707                 markWord old_header = markWord::encode(lock);
1708                 if (lockee->cas_set_mark(header, old_header) != old_header) {
1709                   // restore object for the slow case
1710                   most_recent->set_obj(lockee);
1711                   success = false;
1712                 }
1713               }
1714             }
1715             if (!success) {
1716               InterpreterRuntime::monitorexit(most_recent);
1717             }
1718             UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1719           }
1720           most_recent++;
1721         }
1722         // Need to throw illegal monitor state exception
1723         CALL_VM(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD), handle_exception);
1724         ShouldNotReachHere();
1725       }
1726 
1727       /* All of the non-quick opcodes. */
1728 
1729       /* -Set clobbersCpIndex true if the quickened opcode clobbers the
1730        *  constant pool index in the instruction.
1731        */
1732       CASE(_getfield):
1733       CASE(_nofast_getfield):
1734       CASE(_getstatic):
1735         {
1736           u2 index;
1737           index = Bytes::get_native_u2(pc+1);
1738           ResolvedFieldEntry* entry = cp->resolved_field_entry_at(index);
1739 
1740           // QQQ Need to make this as inlined as possible. Probably need to
1741           // split all the bytecode cases out so c++ compiler has a chance
1742           // for constant prop to fold everything possible away.
1743 
1744           // Interpreter runtime does not expect "nofast" opcodes,
1745           // prepare the vanilla opcode for it.
1746           Bytecodes::Code code = (Bytecodes::Code)opcode;
1747           if (code == Bytecodes::_nofast_getfield) {
1748             code = Bytecodes::_getfield;
1749           }
1750 
1751           if (!entry->is_resolved(code)) {
1752             CALL_VM(InterpreterRuntime::resolve_from_cache(THREAD, code),
1753                     handle_exception);
1754             entry = cp->resolved_field_entry_at(index);
1755           }
1756 
1757           oop obj;
1758           if ((Bytecodes::Code)opcode == Bytecodes::_getstatic) {
1759             Klass* k = entry->field_holder();
1760             obj = k->java_mirror();
1761             MORE_STACK(1);  // Assume single slot push
1762           } else {
1763             obj = STACK_OBJECT(-1);
1764             CHECK_NULL(obj);
1765             // Check if we can rewrite non-volatile _getfield to one of the _fast_Xgetfield.
1766             if (REWRITE_BYTECODES && !entry->is_volatile() &&
1767                   ((Bytecodes::Code)opcode != Bytecodes::_nofast_getfield)) {
1768               // Rewrite current BC to _fast_Xgetfield.
1769               REWRITE_AT_PC(fast_get_type((TosState)(entry->tos_state())));
1770             }
1771           }
1772 
1773           MAYBE_POST_FIELD_ACCESS(obj);
1774 
1775           //
1776           // Now store the result on the stack
1777           //
1778           TosState tos_type = (TosState)(entry->tos_state());
1779           int field_offset = entry->field_offset();
1780           if (entry->is_volatile()) {
1781             if (support_IRIW_for_not_multiple_copy_atomic_cpu) {
1782               OrderAccess::fence();
1783             }
1784             switch (tos_type) {
1785               case btos:
1786               case ztos:
1787                 SET_STACK_INT(obj->byte_field_acquire(field_offset), -1);
1788                 break;
1789               case ctos:
1790                 SET_STACK_INT(obj->char_field_acquire(field_offset), -1);
1791                 break;
1792               case stos:
1793                 SET_STACK_INT(obj->short_field_acquire(field_offset), -1);
1794                 break;
1795               case itos:
1796                 SET_STACK_INT(obj->int_field_acquire(field_offset), -1);
1797                 break;
1798               case ftos:
1799                 SET_STACK_FLOAT(obj->float_field_acquire(field_offset), -1);
1800                 break;
1801               case ltos:
1802                 SET_STACK_LONG(obj->long_field_acquire(field_offset), 0);
1803                 MORE_STACK(1);
1804                 break;
1805               case dtos:
1806                 SET_STACK_DOUBLE(obj->double_field_acquire(field_offset), 0);
1807                 MORE_STACK(1);
1808                 break;
1809               case atos: {
1810                 oop val = obj->obj_field_acquire(field_offset);
1811                 VERIFY_OOP(val);
1812                 SET_STACK_OBJECT(val, -1);
1813                 break;
1814               }
1815               default:
1816                 ShouldNotReachHere();
1817             }
1818           } else {
1819             switch (tos_type) {
1820               case btos:
1821               case ztos:
1822                 SET_STACK_INT(obj->byte_field(field_offset), -1);
1823                 break;
1824               case ctos:
1825                 SET_STACK_INT(obj->char_field(field_offset), -1);
1826                 break;
1827               case stos:
1828                 SET_STACK_INT(obj->short_field(field_offset), -1);
1829                 break;
1830               case itos:
1831                 SET_STACK_INT(obj->int_field(field_offset), -1);
1832                 break;
1833               case ftos:
1834                 SET_STACK_FLOAT(obj->float_field(field_offset), -1);
1835                 break;
1836               case ltos:
1837                 SET_STACK_LONG(obj->long_field(field_offset), 0);
1838                 MORE_STACK(1);
1839                 break;
1840               case dtos:
1841                 SET_STACK_DOUBLE(obj->double_field(field_offset), 0);
1842                 MORE_STACK(1);
1843                 break;
1844               case atos: {
1845                 oop val = obj->obj_field(field_offset);
1846                 VERIFY_OOP(val);
1847                 SET_STACK_OBJECT(val, -1);
1848                 break;
1849               }
1850               default:
1851                 ShouldNotReachHere();
1852             }
1853           }
1854 
1855           UPDATE_PC_AND_CONTINUE(3);
1856         }
1857 
1858       CASE(_putfield):
1859       CASE(_nofast_putfield):
1860       CASE(_putstatic):
1861         {
1862           u2 index = Bytes::get_native_u2(pc+1);
1863           ResolvedFieldEntry* entry = cp->resolved_field_entry_at(index);
1864 
1865           // Interpreter runtime does not expect "nofast" opcodes,
1866           // prepare the vanilla opcode for it.
1867           Bytecodes::Code code = (Bytecodes::Code)opcode;
1868           if (code == Bytecodes::_nofast_putfield) {
1869             code = Bytecodes::_putfield;
1870           }
1871 
1872           if (!entry->is_resolved(code)) {
1873             CALL_VM(InterpreterRuntime::resolve_from_cache(THREAD, code),
1874                     handle_exception);
1875             entry = cp->resolved_field_entry_at(index);
1876           }
1877 
1878           // QQQ Need to make this as inlined as possible. Probably need to split all the bytecode cases
1879           // out so c++ compiler has a chance for constant prop to fold everything possible away.
1880 
1881           oop obj;
1882           int count;
1883           TosState tos_type = (TosState)(entry->tos_state());
1884 
1885           count = -1;
1886           if (tos_type == ltos || tos_type == dtos) {
1887             --count;
1888           }
1889           if ((Bytecodes::Code)opcode == Bytecodes::_putstatic) {
1890             Klass* k = entry->field_holder();
1891             obj = k->java_mirror();
1892           } else {
1893             --count;
1894             obj = STACK_OBJECT(count);
1895             CHECK_NULL(obj);
1896 
1897             // Check if we can rewrite non-volatile _putfield to one of the _fast_Xputfield.
1898             if (REWRITE_BYTECODES && !entry->is_volatile() &&
1899                   ((Bytecodes::Code)opcode != Bytecodes::_nofast_putfield)) {
1900               // Rewrite current BC to _fast_Xputfield.
1901               REWRITE_AT_PC(fast_put_type((TosState)(entry->tos_state())));
1902             }
1903           }
1904 
1905           MAYBE_POST_FIELD_MODIFICATION(obj);
1906 
1907           //
1908           // Now store the result
1909           //
1910           int field_offset = entry->field_offset();
1911           if (entry->is_volatile()) {
1912             switch (tos_type) {
1913               case ztos:
1914                 obj->release_byte_field_put(field_offset, (STACK_INT(-1) & 1)); // only store LSB
1915                 break;
1916               case btos:
1917                 obj->release_byte_field_put(field_offset, STACK_INT(-1));
1918                 break;
1919               case ctos:
1920                 obj->release_char_field_put(field_offset, STACK_INT(-1));
1921                 break;
1922               case stos:
1923                 obj->release_short_field_put(field_offset, STACK_INT(-1));
1924                 break;
1925               case itos:
1926                 obj->release_int_field_put(field_offset, STACK_INT(-1));
1927                 break;
1928               case ftos:
1929                 obj->release_float_field_put(field_offset, STACK_FLOAT(-1));
1930                 break;
1931               case ltos:
1932                 obj->release_long_field_put(field_offset, STACK_LONG(-1));
1933                 break;
1934               case dtos:
1935                 obj->release_double_field_put(field_offset, STACK_DOUBLE(-1));
1936                 break;
1937               case atos: {
1938                 oop val = STACK_OBJECT(-1);
1939                 VERIFY_OOP(val);
1940                 obj->release_obj_field_put(field_offset, val);
1941                 break;
1942               }
1943               default:
1944                 ShouldNotReachHere();
1945             }
1946             OrderAccess::storeload();
1947           } else {
1948             switch (tos_type) {
1949               case ztos:
1950                 obj->byte_field_put(field_offset, (STACK_INT(-1) & 1)); // only store LSB
1951                 break;
1952               case btos:
1953                 obj->byte_field_put(field_offset, STACK_INT(-1));
1954                 break;
1955               case ctos:
1956                 obj->char_field_put(field_offset, STACK_INT(-1));
1957                 break;
1958               case stos:
1959                 obj->short_field_put(field_offset, STACK_INT(-1));
1960                 break;
1961               case itos:
1962                 obj->int_field_put(field_offset, STACK_INT(-1));
1963                 break;
1964               case ftos:
1965                 obj->float_field_put(field_offset, STACK_FLOAT(-1));
1966                 break;
1967               case ltos:
1968                 obj->long_field_put(field_offset, STACK_LONG(-1));
1969                 break;
1970               case dtos:
1971                 obj->double_field_put(field_offset, STACK_DOUBLE(-1));
1972                 break;
1973               case atos: {
1974                 oop val = STACK_OBJECT(-1);
1975                 VERIFY_OOP(val);
1976                 obj->obj_field_put(field_offset, val);
1977                 break;
1978               }
1979               default:
1980                 ShouldNotReachHere();
1981             }
1982           }
1983 
1984           UPDATE_PC_AND_TOS_AND_CONTINUE(3, count);
1985         }
1986 
1987       CASE(_new): {
1988         u2 index = Bytes::get_Java_u2(pc+1);
1989 
1990         // Attempt TLAB allocation first.
1991         //
1992         // To do this, we need to make sure:
1993         //   - klass is initialized
1994         //   - klass can be fastpath allocated (e.g. does not have finalizer)
1995         //   - TLAB accepts the allocation
1996         ConstantPool* constants = istate->method()->constants();
1997         if (UseTLAB && !constants->tag_at(index).is_unresolved_klass()) {
1998           Klass* entry = constants->resolved_klass_at(index);
1999           InstanceKlass* ik = InstanceKlass::cast(entry);
2000           if (ik->is_initialized() && ik->can_be_fastpath_allocated()) {
2001             size_t obj_size = ik->size_helper();
2002             HeapWord* result = THREAD->tlab().allocate(obj_size);
2003             if (result != nullptr) {
2004               // Initialize object field block.
2005               if (!ZeroTLAB) {
2006                 // The TLAB was not pre-zeroed, we need to clear the memory here.
2007                 size_t hdr_size = oopDesc::header_size();
2008                 Copy::fill_to_words(result + hdr_size, obj_size - hdr_size, 0);
2009               }
2010 
2011               // Initialize header, mirrors MemAllocator.
2012               oopDesc::set_mark(result, markWord::prototype());
2013               oopDesc::set_klass_gap(result, 0);
2014               oopDesc::release_set_klass(result, ik);
2015 
2016               oop obj = cast_to_oop(result);
2017 
2018               // Must prevent reordering of stores for object initialization
2019               // with stores that publish the new object.
2020               OrderAccess::storestore();
2021               SET_STACK_OBJECT(obj, 0);
2022               UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1);
2023             }
2024           }
2025         }
2026         // Slow case allocation
2027         CALL_VM(InterpreterRuntime::_new(THREAD, METHOD->constants(), index),
2028                 handle_exception);
2029         // Must prevent reordering of stores for object initialization
2030         // with stores that publish the new object.
2031         OrderAccess::storestore();
2032         SET_STACK_OBJECT(THREAD->vm_result(), 0);
2033         THREAD->set_vm_result(nullptr);
2034         UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1);
2035       }
2036       CASE(_anewarray): {
2037         u2 index = Bytes::get_Java_u2(pc+1);
2038         jint size = STACK_INT(-1);
2039         CALL_VM(InterpreterRuntime::anewarray(THREAD, METHOD->constants(), index, size),
2040                 handle_exception);
2041         // Must prevent reordering of stores for object initialization
2042         // with stores that publish the new object.
2043         OrderAccess::storestore();
2044         SET_STACK_OBJECT(THREAD->vm_result(), -1);
2045         THREAD->set_vm_result(nullptr);
2046         UPDATE_PC_AND_CONTINUE(3);
2047       }
2048       CASE(_multianewarray): {
2049         jint dims = *(pc+3);
2050         jint size = STACK_INT(-1);
2051         // stack grows down, dimensions are up!
2052         jint *dimarray =
2053                    (jint*)&topOfStack[dims * Interpreter::stackElementWords+
2054                                       Interpreter::stackElementWords-1];
2055         //adjust pointer to start of stack element
2056         CALL_VM(InterpreterRuntime::multianewarray(THREAD, dimarray),
2057                 handle_exception);
2058         // Must prevent reordering of stores for object initialization
2059         // with stores that publish the new object.
2060         OrderAccess::storestore();
2061         SET_STACK_OBJECT(THREAD->vm_result(), -dims);
2062         THREAD->set_vm_result(nullptr);
2063         UPDATE_PC_AND_TOS_AND_CONTINUE(4, -(dims-1));
2064       }
2065       CASE(_checkcast):
2066           if (STACK_OBJECT(-1) != nullptr) {
2067             VERIFY_OOP(STACK_OBJECT(-1));
2068             u2 index = Bytes::get_Java_u2(pc+1);
2069             // Constant pool may have actual klass or unresolved klass. If it is
2070             // unresolved we must resolve it.
2071             if (METHOD->constants()->tag_at(index).is_unresolved_klass()) {
2072               CALL_VM(InterpreterRuntime::quicken_io_cc(THREAD), handle_exception);
2073             }
2074             Klass* klassOf = (Klass*) METHOD->constants()->resolved_klass_at(index);
2075             Klass* objKlass = STACK_OBJECT(-1)->klass(); // ebx
2076             //
2077             // Check for compatibility. This check must not GC!!
2078             // Seems way more expensive now that we must dispatch.
2079             //
2080             if (objKlass != klassOf && !objKlass->is_subtype_of(klassOf)) {
2081               ResourceMark rm(THREAD);
2082               char* message = SharedRuntime::generate_class_cast_message(
2083                 objKlass, klassOf);
2084               VM_JAVA_ERROR(vmSymbols::java_lang_ClassCastException(), message);
2085             }
2086           }
2087           UPDATE_PC_AND_CONTINUE(3);
2088 
2089       CASE(_instanceof):
2090           if (STACK_OBJECT(-1) == nullptr) {
2091             SET_STACK_INT(0, -1);
2092           } else {
2093             VERIFY_OOP(STACK_OBJECT(-1));
2094             u2 index = Bytes::get_Java_u2(pc+1);
2095             // Constant pool may have actual klass or unresolved klass. If it is
2096             // unresolved we must resolve it.
2097             if (METHOD->constants()->tag_at(index).is_unresolved_klass()) {
2098               CALL_VM(InterpreterRuntime::quicken_io_cc(THREAD), handle_exception);
2099             }
2100             Klass* klassOf = (Klass*) METHOD->constants()->resolved_klass_at(index);
2101             Klass* objKlass = STACK_OBJECT(-1)->klass();
2102             //
2103             // Check for compatibility. This check must not GC!!
2104             // Seems way more expensive now that we must dispatch.
2105             //
2106             if ( objKlass == klassOf || objKlass->is_subtype_of(klassOf)) {
2107               SET_STACK_INT(1, -1);
2108             } else {
2109               SET_STACK_INT(0, -1);
2110             }
2111           }
2112           UPDATE_PC_AND_CONTINUE(3);
2113 
2114       CASE(_ldc_w):
2115       CASE(_ldc):
2116         {
2117           u2 index;
2118           bool wide = false;
2119           int incr = 2; // frequent case
2120           if (opcode == Bytecodes::_ldc) {
2121             index = pc[1];
2122           } else {
2123             index = Bytes::get_Java_u2(pc+1);
2124             incr = 3;
2125             wide = true;
2126           }
2127 
2128           ConstantPool* constants = METHOD->constants();
2129           switch (constants->tag_at(index).value()) {
2130           case JVM_CONSTANT_Integer:
2131             SET_STACK_INT(constants->int_at(index), 0);
2132             break;
2133 
2134           case JVM_CONSTANT_Float:
2135             SET_STACK_FLOAT(constants->float_at(index), 0);
2136             break;
2137 
2138           case JVM_CONSTANT_String:
2139             {
2140               oop result = constants->resolved_reference_at(index);
2141               if (result == nullptr) {
2142                 CALL_VM(InterpreterRuntime::resolve_ldc(THREAD, (Bytecodes::Code) opcode), handle_exception);
2143                 SET_STACK_OBJECT(THREAD->vm_result(), 0);
2144                 THREAD->set_vm_result(nullptr);
2145               } else {
2146                 VERIFY_OOP(result);
2147                 SET_STACK_OBJECT(result, 0);
2148               }
2149             break;
2150             }
2151 
2152           case JVM_CONSTANT_Class:
2153             VERIFY_OOP(constants->resolved_klass_at(index)->java_mirror());
2154             SET_STACK_OBJECT(constants->resolved_klass_at(index)->java_mirror(), 0);
2155             break;
2156 
2157           case JVM_CONSTANT_UnresolvedClass:
2158           case JVM_CONSTANT_UnresolvedClassInError:
2159             CALL_VM(InterpreterRuntime::ldc(THREAD, wide), handle_exception);
2160             SET_STACK_OBJECT(THREAD->vm_result(), 0);
2161             THREAD->set_vm_result(nullptr);
2162             break;
2163 
2164           case JVM_CONSTANT_Dynamic:
2165           case JVM_CONSTANT_DynamicInError:
2166             {
2167               CALL_VM(InterpreterRuntime::resolve_ldc(THREAD, (Bytecodes::Code) opcode), handle_exception);
2168               oop result = THREAD->vm_result();
2169               VERIFY_OOP(result);
2170 
2171               jvalue value;
2172               BasicType type = java_lang_boxing_object::get_value(result, &value);
2173               switch (type) {
2174               case T_FLOAT:   SET_STACK_FLOAT(value.f, 0); break;
2175               case T_INT:     SET_STACK_INT(value.i, 0); break;
2176               case T_SHORT:   SET_STACK_INT(value.s, 0); break;
2177               case T_BYTE:    SET_STACK_INT(value.b, 0); break;
2178               case T_CHAR:    SET_STACK_INT(value.c, 0); break;
2179               case T_BOOLEAN: SET_STACK_INT(value.z, 0); break;
2180               default:  ShouldNotReachHere();
2181               }
2182 
2183               break;
2184             }
2185 
2186           default:  ShouldNotReachHere();
2187           }
2188           UPDATE_PC_AND_TOS_AND_CONTINUE(incr, 1);
2189         }
2190 
2191       CASE(_ldc2_w):
2192         {
2193           u2 index = Bytes::get_Java_u2(pc+1);
2194 
2195           ConstantPool* constants = METHOD->constants();
2196           switch (constants->tag_at(index).value()) {
2197 
2198           case JVM_CONSTANT_Long:
2199              SET_STACK_LONG(constants->long_at(index), 1);
2200             break;
2201 
2202           case JVM_CONSTANT_Double:
2203              SET_STACK_DOUBLE(constants->double_at(index), 1);
2204             break;
2205 
2206           case JVM_CONSTANT_Dynamic:
2207           case JVM_CONSTANT_DynamicInError:
2208             {
2209               CALL_VM(InterpreterRuntime::resolve_ldc(THREAD, (Bytecodes::Code) opcode), handle_exception);
2210               oop result = THREAD->vm_result();
2211               VERIFY_OOP(result);
2212 
2213               jvalue value;
2214               BasicType type = java_lang_boxing_object::get_value(result, &value);
2215               switch (type) {
2216               case T_DOUBLE: SET_STACK_DOUBLE(value.d, 1); break;
2217               case T_LONG:   SET_STACK_LONG(value.j, 1); break;
2218               default:  ShouldNotReachHere();
2219               }
2220 
2221               break;
2222             }
2223 
2224           default:  ShouldNotReachHere();
2225           }
2226           UPDATE_PC_AND_TOS_AND_CONTINUE(3, 2);
2227         }
2228 
2229       CASE(_fast_aldc_w):
2230       CASE(_fast_aldc): {
2231         u2 index;
2232         int incr;
2233         if (opcode == Bytecodes::_fast_aldc) {
2234           index = pc[1];
2235           incr = 2;
2236         } else {
2237           index = Bytes::get_native_u2(pc+1);
2238           incr = 3;
2239         }
2240 
2241         // We are resolved if the resolved_references array contains a non-null object (CallSite, etc.)
2242         // This kind of CP cache entry does not need to match the flags byte, because
2243         // there is a 1-1 relation between bytecode type and CP entry type.
2244         ConstantPool* constants = METHOD->constants();
2245         oop result = constants->resolved_reference_at(index);
2246         if (result == nullptr) {
2247           CALL_VM(InterpreterRuntime::resolve_ldc(THREAD, (Bytecodes::Code) opcode),
2248                   handle_exception);
2249           result = THREAD->vm_result();
2250         }
2251         if (result == Universe::the_null_sentinel())
2252           result = nullptr;
2253 
2254         VERIFY_OOP(result);
2255         SET_STACK_OBJECT(result, 0);
2256         UPDATE_PC_AND_TOS_AND_CONTINUE(incr, 1);
2257       }
2258 
2259       CASE(_invokedynamic): {
2260         u4 index = Bytes::get_native_u4(pc+1);
2261         ResolvedIndyEntry* indy_info = cp->resolved_indy_entry_at(index);
2262         if (!indy_info->is_resolved()) {
2263           CALL_VM(InterpreterRuntime::resolve_from_cache(THREAD, (Bytecodes::Code)opcode),
2264                   handle_exception);
2265           indy_info = cp->resolved_indy_entry_at(index); // get resolved entry
2266         }
2267         Method* method = indy_info->method();
2268         if (VerifyOops) method->verify();
2269 
2270         if (indy_info->has_appendix()) {
2271           constantPoolHandle cp(THREAD, METHOD->constants());
2272           SET_STACK_OBJECT(cp->resolved_reference_from_indy(index), 0);
2273           MORE_STACK(1);
2274         }
2275 
2276         istate->set_msg(call_method);
2277         istate->set_callee(method);
2278         istate->set_callee_entry_point(method->from_interpreted_entry());
2279         istate->set_bcp_advance(5);
2280 
2281         UPDATE_PC_AND_RETURN(0); // I'll be back...
2282       }
2283 
2284       CASE(_invokehandle): {
2285 
2286         u2 index = Bytes::get_native_u2(pc+1);
2287         ResolvedMethodEntry* entry = cp->resolved_method_entry_at(index);
2288 
2289         if (! entry->is_resolved((Bytecodes::Code) opcode)) {
2290           CALL_VM(InterpreterRuntime::resolve_from_cache(THREAD, (Bytecodes::Code)opcode),
2291                   handle_exception);
2292           entry = cp->resolved_method_entry_at(index);
2293         }
2294 
2295         Method* method = entry->method();
2296         if (VerifyOops) method->verify();
2297 
2298         if (entry->has_appendix()) {
2299           constantPoolHandle cp(THREAD, METHOD->constants());
2300           SET_STACK_OBJECT(cp->cache()->appendix_if_resolved(entry), 0);
2301           MORE_STACK(1);
2302         }
2303 
2304         istate->set_msg(call_method);
2305         istate->set_callee(method);
2306         istate->set_callee_entry_point(method->from_interpreted_entry());
2307         istate->set_bcp_advance(3);
2308 
2309         UPDATE_PC_AND_RETURN(0); // I'll be back...
2310       }
2311 
2312       CASE(_invokeinterface): {
2313         u2 index = Bytes::get_native_u2(pc+1);
2314 
2315         // QQQ Need to make this as inlined as possible. Probably need to split all the bytecode cases
2316         // out so c++ compiler has a chance for constant prop to fold everything possible away.
2317 
2318         ResolvedMethodEntry* entry = cp->resolved_method_entry_at(index);
2319         if (!entry->is_resolved((Bytecodes::Code)opcode)) {
2320           CALL_VM(InterpreterRuntime::resolve_from_cache(THREAD, (Bytecodes::Code)opcode),
2321                   handle_exception);
2322         }
2323 
2324         istate->set_msg(call_method);
2325 
2326         // Special case of invokeinterface called for virtual method of
2327         // java.lang.Object.  See cpCache.cpp for details.
2328         Method* callee = nullptr;
2329         if (entry->is_forced_virtual()) {
2330           CHECK_NULL(STACK_OBJECT(-(entry->number_of_parameters())));
2331           if (entry->is_vfinal()) {
2332             callee = entry->method();
2333           } else {
2334             // Get receiver.
2335             int parms = entry->number_of_parameters();
2336             // Same comments as invokevirtual apply here.
2337             oop rcvr = STACK_OBJECT(-parms);
2338             VERIFY_OOP(rcvr);
2339             Klass* rcvrKlass = rcvr->klass();
2340             callee = (Method*) rcvrKlass->method_at_vtable(entry->table_index());
2341           }
2342         } else if (entry->is_vfinal()) {
2343           // private interface method invocations
2344           //
2345           // Ensure receiver class actually implements
2346           // the resolved interface class. The link resolver
2347           // does this, but only for the first time this
2348           // interface is being called.
2349           int parms = entry->number_of_parameters();
2350           oop rcvr = STACK_OBJECT(-parms);
2351           CHECK_NULL(rcvr);
2352           Klass* recv_klass = rcvr->klass();
2353           Klass* resolved_klass = entry->interface_klass();
2354           if (!recv_klass->is_subtype_of(resolved_klass)) {
2355             ResourceMark rm(THREAD);
2356             char buf[200];
2357             jio_snprintf(buf, sizeof(buf), "Class %s does not implement the requested interface %s",
2358               recv_klass->external_name(),
2359               resolved_klass->external_name());
2360             VM_JAVA_ERROR(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
2361           }
2362           callee = entry->method();
2363         }
2364         if (callee != nullptr) {
2365           istate->set_callee(callee);
2366           istate->set_callee_entry_point(callee->from_interpreted_entry());
2367           if (JVMTI_ENABLED && THREAD->is_interp_only_mode()) {
2368             istate->set_callee_entry_point(callee->interpreter_entry());
2369           }
2370           istate->set_bcp_advance(5);
2371           UPDATE_PC_AND_RETURN(0); // I'll be back...
2372         }
2373 
2374         // this could definitely be cleaned up QQQ
2375         Method *interface_method = entry->method();
2376         InstanceKlass* iclass = interface_method->method_holder();
2377 
2378         // get receiver
2379         int parms = entry->number_of_parameters();
2380         oop rcvr = STACK_OBJECT(-parms);
2381         CHECK_NULL(rcvr);
2382         InstanceKlass* int2 = (InstanceKlass*) rcvr->klass();
2383 
2384         // Receiver subtype check against resolved interface klass (REFC).
2385         {
2386           Klass* refc = entry->interface_klass();
2387           itableOffsetEntry* scan;
2388           for (scan = (itableOffsetEntry*) int2->start_of_itable();
2389                scan->interface_klass() != nullptr;
2390                scan++) {
2391             if (scan->interface_klass() == refc) {
2392               break;
2393             }
2394           }
2395           // Check that the entry is non-null.  A null entry means
2396           // that the receiver class doesn't implement the
2397           // interface, and wasn't the same as when the caller was
2398           // compiled.
2399           if (scan->interface_klass() == nullptr) {
2400             VM_JAVA_ERROR(vmSymbols::java_lang_IncompatibleClassChangeError(), "");
2401           }
2402         }
2403 
2404         itableOffsetEntry* ki = (itableOffsetEntry*) int2->start_of_itable();
2405         int i;
2406         for ( i = 0 ; i < int2->itable_length() ; i++, ki++ ) {
2407           if (ki->interface_klass() == iclass) break;
2408         }
2409         // If the interface isn't found, this class doesn't implement this
2410         // interface. The link resolver checks this but only for the first
2411         // time this interface is called.
2412         if (i == int2->itable_length()) {
2413           CALL_VM(InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose(THREAD, rcvr->klass(), iclass),
2414                   handle_exception);
2415         }
2416         int mindex = interface_method->itable_index();
2417 
2418         itableMethodEntry* im = ki->first_method_entry(rcvr->klass());
2419         callee = im[mindex].method();
2420         if (callee == nullptr) {
2421           CALL_VM(InterpreterRuntime::throw_AbstractMethodErrorVerbose(THREAD, rcvr->klass(), interface_method),
2422                   handle_exception);
2423         }
2424 
2425         istate->set_callee(callee);
2426         istate->set_callee_entry_point(callee->from_interpreted_entry());
2427         if (JVMTI_ENABLED && THREAD->is_interp_only_mode()) {
2428           istate->set_callee_entry_point(callee->interpreter_entry());
2429         }
2430         istate->set_bcp_advance(5);
2431         UPDATE_PC_AND_RETURN(0); // I'll be back...
2432       }
2433 
2434       CASE(_invokevirtual):
2435       CASE(_invokespecial):
2436       CASE(_invokestatic): {
2437         u2 index = Bytes::get_native_u2(pc+1);
2438 
2439         ResolvedMethodEntry* entry = cp->resolved_method_entry_at(index);
2440         // QQQ Need to make this as inlined as possible. Probably need to split all the bytecode cases
2441         // out so c++ compiler has a chance for constant prop to fold everything possible away.
2442 
2443         if (!entry->is_resolved((Bytecodes::Code)opcode)) {
2444           CALL_VM(InterpreterRuntime::resolve_from_cache(THREAD, (Bytecodes::Code)opcode),
2445                   handle_exception);
2446           entry = cp->resolved_method_entry_at(index);
2447         }
2448 
2449         istate->set_msg(call_method);
2450         {
2451           Method* callee;
2452           if ((Bytecodes::Code)opcode == Bytecodes::_invokevirtual) {
2453             CHECK_NULL(STACK_OBJECT(-(entry->number_of_parameters())));
2454             if (entry->is_vfinal()) {
2455               callee = entry->method();
2456               if (REWRITE_BYTECODES && !CDSConfig::is_using_archive() && !CDSConfig::is_dumping_archive()) {
2457                 // Rewrite to _fast_invokevfinal.
2458                 REWRITE_AT_PC(Bytecodes::_fast_invokevfinal);
2459               }
2460             } else {
2461               // get receiver
2462               int parms = entry->number_of_parameters();
2463               // this works but needs a resourcemark and seems to create a vtable on every call:
2464               // Method* callee = rcvr->klass()->vtable()->method_at(cache->f2_as_index());
2465               //
2466               // this fails with an assert
2467               // InstanceKlass* rcvrKlass = InstanceKlass::cast(STACK_OBJECT(-parms)->klass());
2468               // but this works
2469               oop rcvr = STACK_OBJECT(-parms);
2470               VERIFY_OOP(rcvr);
2471               Klass* rcvrKlass = rcvr->klass();
2472               /*
2473                 Executing this code in java.lang.String:
2474                     public String(char value[]) {
2475                           this.count = value.length;
2476                           this.value = (char[])value.clone();
2477                      }
2478 
2479                  a find on rcvr->klass() reports:
2480                  {type array char}{type array class}
2481                   - klass: {other class}
2482 
2483                   but using InstanceKlass::cast(STACK_OBJECT(-parms)->klass()) causes in assertion failure
2484                   because rcvr->klass()->is_instance_klass() == 0
2485                   However it seems to have a vtable in the right location. Huh?
2486                   Because vtables have the same offset for ArrayKlass and InstanceKlass.
2487               */
2488               callee = (Method*) rcvrKlass->method_at_vtable(entry->table_index());
2489             }
2490           } else {
2491             if ((Bytecodes::Code)opcode == Bytecodes::_invokespecial) {
2492               CHECK_NULL(STACK_OBJECT(-(entry->number_of_parameters())));
2493             }
2494             callee = entry->method();
2495           }
2496 
2497           istate->set_callee(callee);
2498           istate->set_callee_entry_point(callee->from_interpreted_entry());
2499           if (JVMTI_ENABLED && THREAD->is_interp_only_mode()) {
2500             istate->set_callee_entry_point(callee->interpreter_entry());
2501           }
2502           istate->set_bcp_advance(3);
2503           UPDATE_PC_AND_RETURN(0); // I'll be back...
2504         }
2505       }
2506 
2507       /* Allocate memory for a new java object. */
2508 
2509       CASE(_newarray): {
2510         BasicType atype = (BasicType) *(pc+1);
2511         jint size = STACK_INT(-1);
2512         CALL_VM(InterpreterRuntime::newarray(THREAD, atype, size),
2513                 handle_exception);
2514         // Must prevent reordering of stores for object initialization
2515         // with stores that publish the new object.
2516         OrderAccess::storestore();
2517         SET_STACK_OBJECT(THREAD->vm_result(), -1);
2518         THREAD->set_vm_result(nullptr);
2519 
2520         UPDATE_PC_AND_CONTINUE(2);
2521       }
2522 
2523       /* Throw an exception. */
2524 
2525       CASE(_athrow): {
2526           oop except_oop = STACK_OBJECT(-1);
2527           CHECK_NULL(except_oop);
2528           // set pending_exception so we use common code
2529           THREAD->set_pending_exception(except_oop, nullptr, 0);
2530           goto handle_exception;
2531       }
2532 
2533       /* goto and jsr. They are exactly the same except jsr pushes
2534        * the address of the next instruction first.
2535        */
2536 
2537       CASE(_jsr): {
2538           /* push bytecode index on stack */
2539           SET_STACK_ADDR(((address)pc - (intptr_t)(istate->method()->code_base()) + 3), 0);
2540           MORE_STACK(1);
2541           /* FALL THROUGH */
2542       }
2543 
2544       CASE(_goto):
2545       {
2546           int16_t offset = (int16_t)Bytes::get_Java_u2(pc + 1);
2547           address branch_pc = pc;
2548           UPDATE_PC(offset);
2549           DO_BACKEDGE_CHECKS(offset, branch_pc);
2550           CONTINUE;
2551       }
2552 
2553       CASE(_jsr_w): {
2554           /* push return address on the stack */
2555           SET_STACK_ADDR(((address)pc - (intptr_t)(istate->method()->code_base()) + 5), 0);
2556           MORE_STACK(1);
2557           /* FALL THROUGH */
2558       }
2559 
2560       CASE(_goto_w):
2561       {
2562           int32_t offset = Bytes::get_Java_u4(pc + 1);
2563           address branch_pc = pc;
2564           UPDATE_PC(offset);
2565           DO_BACKEDGE_CHECKS(offset, branch_pc);
2566           CONTINUE;
2567       }
2568 
2569       /* return from a jsr or jsr_w */
2570 
2571       CASE(_ret): {
2572           pc = istate->method()->code_base() + (intptr_t)(LOCALS_ADDR(pc[1]));
2573           UPDATE_PC_AND_CONTINUE(0);
2574       }
2575 
2576       /* debugger breakpoint */
2577 
2578       CASE(_breakpoint): {
2579           Bytecodes::Code original_bytecode;
2580           DECACHE_STATE();
2581           SET_LAST_JAVA_FRAME();
2582           original_bytecode = InterpreterRuntime::get_original_bytecode_at(THREAD,
2583                               METHOD, pc);
2584           RESET_LAST_JAVA_FRAME();
2585           CACHE_STATE();
2586           if (THREAD->has_pending_exception()) goto handle_exception;
2587             CALL_VM(InterpreterRuntime::_breakpoint(THREAD, METHOD, pc),
2588                                                     handle_exception);
2589 
2590           opcode = (jubyte)original_bytecode;
2591           goto opcode_switch;
2592       }
2593 
2594       CASE(_fast_agetfield): {
2595         u2 index = Bytes::get_native_u2(pc+1);
2596         ResolvedFieldEntry* entry = cp->resolved_field_entry_at(index);
2597         int field_offset = entry->field_offset();
2598 
2599         oop obj = STACK_OBJECT(-1);
2600         CHECK_NULL(obj);
2601 
2602         MAYBE_POST_FIELD_ACCESS(obj);
2603 
2604         VERIFY_OOP(obj->obj_field(field_offset));
2605         SET_STACK_OBJECT(obj->obj_field(field_offset), -1);
2606         UPDATE_PC_AND_CONTINUE(3);
2607       }
2608 
2609       CASE(_fast_bgetfield): {
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         SET_STACK_INT(obj->byte_field(field_offset), -1);
2620         UPDATE_PC_AND_CONTINUE(3);
2621       }
2622 
2623       CASE(_fast_cgetfield): {
2624         u2 index = Bytes::get_native_u2(pc+1);
2625         ResolvedFieldEntry* entry = cp->resolved_field_entry_at(index);
2626         int field_offset = entry->field_offset();
2627 
2628         oop obj = STACK_OBJECT(-1);
2629         CHECK_NULL(obj);
2630 
2631         MAYBE_POST_FIELD_ACCESS(obj);
2632 
2633         SET_STACK_INT(obj->char_field(field_offset), -1);
2634         UPDATE_PC_AND_CONTINUE(3);
2635       }
2636 
2637       CASE(_fast_dgetfield): {
2638         u2 index = Bytes::get_native_u2(pc+1);
2639         ResolvedFieldEntry* entry = cp->resolved_field_entry_at(index);
2640         int field_offset = entry->field_offset();
2641 
2642         oop obj = STACK_OBJECT(-1);
2643         CHECK_NULL(obj);
2644 
2645         MAYBE_POST_FIELD_ACCESS(obj);
2646 
2647         SET_STACK_DOUBLE(obj->double_field(field_offset), 0);
2648         MORE_STACK(1);
2649         UPDATE_PC_AND_CONTINUE(3);
2650       }
2651 
2652       CASE(_fast_fgetfield): {
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_FLOAT(obj->float_field(field_offset), -1);
2663         UPDATE_PC_AND_CONTINUE(3);
2664       }
2665 
2666       CASE(_fast_igetfield): {
2667         u2 index = Bytes::get_native_u2(pc+1);
2668         ResolvedFieldEntry* entry = cp->resolved_field_entry_at(index);
2669         int field_offset = entry->field_offset();
2670 
2671         oop obj = STACK_OBJECT(-1);
2672         CHECK_NULL(obj);
2673 
2674         MAYBE_POST_FIELD_ACCESS(obj);
2675 
2676         SET_STACK_INT(obj->int_field(field_offset), -1);
2677         UPDATE_PC_AND_CONTINUE(3);
2678       }
2679 
2680       CASE(_fast_lgetfield): {
2681         u2 index = Bytes::get_native_u2(pc+1);
2682         ResolvedFieldEntry* entry = cp->resolved_field_entry_at(index);
2683         int field_offset = entry->field_offset();
2684 
2685         oop obj = STACK_OBJECT(-1);
2686         CHECK_NULL(obj);
2687 
2688         MAYBE_POST_FIELD_ACCESS(obj);
2689 
2690         SET_STACK_LONG(obj->long_field(field_offset), 0);
2691         MORE_STACK(1);
2692         UPDATE_PC_AND_CONTINUE(3);
2693       }
2694 
2695       CASE(_fast_sgetfield): {
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_INT(obj->short_field(field_offset), -1);
2706         UPDATE_PC_AND_CONTINUE(3);
2707       }
2708 
2709       CASE(_fast_aputfield): {
2710         u2 index = Bytes::get_native_u2(pc+1);
2711         ResolvedFieldEntry* entry = cp->resolved_field_entry_at(index);
2712 
2713         oop obj = STACK_OBJECT(-2);
2714         CHECK_NULL(obj);
2715 
2716         MAYBE_POST_FIELD_MODIFICATION(obj);
2717 
2718         int field_offset = entry->field_offset();
2719         obj->obj_field_put(field_offset, STACK_OBJECT(-1));
2720 
2721         UPDATE_PC_AND_TOS_AND_CONTINUE(3, -2);
2722       }
2723 
2724       CASE(_fast_bputfield): {
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->byte_field_put(field_offset, STACK_INT(-1));
2735 
2736         UPDATE_PC_AND_TOS_AND_CONTINUE(3, -2);
2737       }
2738 
2739       CASE(_fast_zputfield): {
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) & 1)); // only store LSB
2750 
2751         UPDATE_PC_AND_TOS_AND_CONTINUE(3, -2);
2752       }
2753 
2754       CASE(_fast_cputfield): {
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->char_field_put(field_offset, STACK_INT(-1));
2765 
2766         UPDATE_PC_AND_TOS_AND_CONTINUE(3, -2);
2767       }
2768 
2769       CASE(_fast_dputfield): {
2770         u2 index = Bytes::get_native_u2(pc+1);
2771         ResolvedFieldEntry* entry = cp->resolved_field_entry_at(index);
2772 
2773         oop obj = STACK_OBJECT(-3);
2774         CHECK_NULL(obj);
2775 
2776         MAYBE_POST_FIELD_MODIFICATION(obj);
2777 
2778         int field_offset = entry->field_offset();
2779         obj->double_field_put(field_offset, STACK_DOUBLE(-1));
2780 
2781         UPDATE_PC_AND_TOS_AND_CONTINUE(3, -3);
2782       }
2783 
2784       CASE(_fast_fputfield): {
2785         u2 index = Bytes::get_native_u2(pc+1);
2786         ResolvedFieldEntry* entry = cp->resolved_field_entry_at(index);
2787 
2788         oop obj = STACK_OBJECT(-2);
2789         CHECK_NULL(obj);
2790 
2791         MAYBE_POST_FIELD_MODIFICATION(obj);
2792 
2793         int field_offset = entry->field_offset();
2794         obj->float_field_put(field_offset, STACK_FLOAT(-1));
2795 
2796         UPDATE_PC_AND_TOS_AND_CONTINUE(3, -2);
2797       }
2798 
2799       CASE(_fast_iputfield): {
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->int_field_put(field_offset, STACK_INT(-1));
2810 
2811         UPDATE_PC_AND_TOS_AND_CONTINUE(3, -2);
2812       }
2813 
2814       CASE(_fast_lputfield): {
2815         u2 index = Bytes::get_native_u2(pc+1);
2816         ResolvedFieldEntry* entry = cp->resolved_field_entry_at(index);
2817 
2818         oop obj = STACK_OBJECT(-3);
2819         CHECK_NULL(obj);
2820 
2821         MAYBE_POST_FIELD_MODIFICATION(obj);
2822 
2823         int field_offset = entry->field_offset();
2824         obj->long_field_put(field_offset, STACK_LONG(-1));
2825 
2826         UPDATE_PC_AND_TOS_AND_CONTINUE(3, -3);
2827       }
2828 
2829       CASE(_fast_sputfield): {
2830         u2 index = Bytes::get_native_u2(pc+1);
2831         ResolvedFieldEntry* entry = cp->resolved_field_entry_at(index);
2832 
2833         oop obj = STACK_OBJECT(-2);
2834         CHECK_NULL(obj);
2835 
2836         MAYBE_POST_FIELD_MODIFICATION(obj);
2837 
2838         int field_offset = entry->field_offset();
2839         obj->short_field_put(field_offset, STACK_INT(-1));
2840 
2841         UPDATE_PC_AND_TOS_AND_CONTINUE(3, -2);
2842       }
2843 
2844       CASE(_fast_aload_0): {
2845         oop obj = LOCALS_OBJECT(0);
2846         VERIFY_OOP(obj);
2847         SET_STACK_OBJECT(obj, 0);
2848         UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
2849       }
2850 
2851       CASE(_fast_aaccess_0): {
2852         u2 index = Bytes::get_native_u2(pc+2);
2853         ResolvedFieldEntry* entry = cp->resolved_field_entry_at(index);
2854         int field_offset = entry->field_offset();
2855 
2856         oop obj = LOCALS_OBJECT(0);
2857         CHECK_NULL(obj);
2858         VERIFY_OOP(obj);
2859 
2860         MAYBE_POST_FIELD_ACCESS(obj);
2861 
2862         VERIFY_OOP(obj->obj_field(field_offset));
2863         SET_STACK_OBJECT(obj->obj_field(field_offset), 0);
2864         UPDATE_PC_AND_TOS_AND_CONTINUE(4, 1);
2865       }
2866 
2867       CASE(_fast_iaccess_0): {
2868         u2 index = Bytes::get_native_u2(pc+2);
2869         ResolvedFieldEntry* entry = cp->resolved_field_entry_at(index);
2870         int field_offset = entry->field_offset();
2871 
2872         oop obj = LOCALS_OBJECT(0);
2873         CHECK_NULL(obj);
2874         VERIFY_OOP(obj);
2875 
2876         MAYBE_POST_FIELD_ACCESS(obj);
2877 
2878         SET_STACK_INT(obj->int_field(field_offset), 0);
2879         UPDATE_PC_AND_TOS_AND_CONTINUE(4, 1);
2880       }
2881 
2882       CASE(_fast_faccess_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_FLOAT(obj->float_field(field_offset), 0);
2894         UPDATE_PC_AND_TOS_AND_CONTINUE(4, 1);
2895       }
2896 
2897       CASE(_fast_invokevfinal): {
2898         u2 index = Bytes::get_native_u2(pc+1);
2899         ResolvedMethodEntry* entry = cp->resolved_method_entry_at(index);
2900 
2901         assert(entry->is_resolved(Bytecodes::_invokevirtual), "Should be resolved before rewriting");
2902 
2903         istate->set_msg(call_method);
2904 
2905         CHECK_NULL(STACK_OBJECT(-(entry->number_of_parameters())));
2906         Method* callee = entry->method();
2907         istate->set_callee(callee);
2908         if (JVMTI_ENABLED && THREAD->is_interp_only_mode()) {
2909           istate->set_callee_entry_point(callee->interpreter_entry());
2910         } else {
2911           istate->set_callee_entry_point(callee->from_interpreted_entry());
2912         }
2913         istate->set_bcp_advance(3);
2914         UPDATE_PC_AND_RETURN(0);
2915       }
2916 
2917       DEFAULT:
2918           fatal("Unimplemented opcode %d = %s", opcode,
2919                 Bytecodes::name((Bytecodes::Code)opcode));
2920           goto finish;
2921 
2922       } /* switch(opc) */
2923 
2924 
2925 #ifdef USELABELS
2926     check_for_exception:
2927 #endif
2928     {
2929       if (!THREAD->has_pending_exception()) {
2930         CONTINUE;
2931       }
2932       /* We will be gcsafe soon, so flush our state. */
2933       DECACHE_PC();
2934       goto handle_exception;
2935     }
2936   do_continue: ;
2937 
2938   } /* while (1) interpreter loop */
2939 
2940 
2941   // An exception exists in the thread state see whether this activation can handle it
2942   handle_exception: {
2943 
2944     HandleMarkCleaner __hmc(THREAD);
2945     Handle except_oop(THREAD, THREAD->pending_exception());
2946     // Prevent any subsequent HandleMarkCleaner in the VM
2947     // from freeing the except_oop handle.
2948     HandleMark __hm(THREAD);
2949 
2950     THREAD->clear_pending_exception();
2951     assert(except_oop() != nullptr, "No exception to process");
2952     intptr_t continuation_bci;
2953     // expression stack is emptied
2954     topOfStack = istate->stack_base() - Interpreter::stackElementWords;
2955     CALL_VM(continuation_bci = (intptr_t)InterpreterRuntime::exception_handler_for_exception(THREAD, except_oop()),
2956             handle_exception);
2957 
2958     except_oop = Handle(THREAD, THREAD->vm_result());
2959     THREAD->set_vm_result(nullptr);
2960     if (continuation_bci >= 0) {
2961       // Place exception on top of stack
2962       SET_STACK_OBJECT(except_oop(), 0);
2963       MORE_STACK(1);
2964       pc = METHOD->code_base() + continuation_bci;
2965       if (log_is_enabled(Info, exceptions)) {
2966         ResourceMark rm(THREAD);
2967         stringStream tempst;
2968         tempst.print("interpreter method <%s>\n"
2969                      " at bci %d, continuing at %d for thread " INTPTR_FORMAT,
2970                      METHOD->print_value_string(),
2971                      (int)(istate->bcp() - METHOD->code_base()),
2972                      (int)continuation_bci, p2i(THREAD));
2973         Exceptions::log_exception(except_oop, tempst.as_string());
2974       }
2975       // for AbortVMOnException flag
2976       Exceptions::debug_check_abort(except_oop);
2977       goto run;
2978     }
2979     if (log_is_enabled(Info, exceptions)) {
2980       ResourceMark rm;
2981       stringStream tempst;
2982       tempst.print("interpreter method <%s>\n"
2983              " at bci %d, unwinding for thread " INTPTR_FORMAT,
2984              METHOD->print_value_string(),
2985              (int)(istate->bcp() - METHOD->code_base()),
2986              p2i(THREAD));
2987       Exceptions::log_exception(except_oop, tempst.as_string());
2988     }
2989     // for AbortVMOnException flag
2990     Exceptions::debug_check_abort(except_oop);
2991 
2992     // No handler in this activation, unwind and try again
2993     THREAD->set_pending_exception(except_oop(), nullptr, 0);
2994     goto handle_return;
2995   }  // handle_exception:
2996 
2997   // Return from an interpreter invocation with the result of the interpretation
2998   // on the top of the Java Stack (or a pending exception)
2999 
3000   handle_Pop_Frame: {
3001 
3002     // We don't really do anything special here except we must be aware
3003     // that we can get here without ever locking the method (if sync).
3004     // Also we skip the notification of the exit.
3005 
3006     istate->set_msg(popping_frame);
3007     // Clear pending so while the pop is in process
3008     // we don't start another one if a call_vm is done.
3009     THREAD->clear_popframe_condition();
3010     // Let interpreter (only) see the we're in the process of popping a frame
3011     THREAD->set_pop_frame_in_process();
3012 
3013     goto handle_return;
3014 
3015   } // handle_Pop_Frame
3016 
3017   // ForceEarlyReturn ends a method, and returns to the caller with a return value
3018   // given by the invoker of the early return.
3019   handle_Early_Return: {
3020 
3021     istate->set_msg(early_return);
3022 
3023     // Clear expression stack.
3024     topOfStack = istate->stack_base() - Interpreter::stackElementWords;
3025 
3026     JvmtiThreadState *ts = THREAD->jvmti_thread_state();
3027 
3028     // Push the value to be returned.
3029     switch (istate->method()->result_type()) {
3030       case T_BOOLEAN:
3031       case T_SHORT:
3032       case T_BYTE:
3033       case T_CHAR:
3034       case T_INT:
3035         SET_STACK_INT(ts->earlyret_value().i, 0);
3036         MORE_STACK(1);
3037         break;
3038       case T_LONG:
3039         SET_STACK_LONG(ts->earlyret_value().j, 1);
3040         MORE_STACK(2);
3041         break;
3042       case T_FLOAT:
3043         SET_STACK_FLOAT(ts->earlyret_value().f, 0);
3044         MORE_STACK(1);
3045         break;
3046       case T_DOUBLE:
3047         SET_STACK_DOUBLE(ts->earlyret_value().d, 1);
3048         MORE_STACK(2);
3049         break;
3050       case T_ARRAY:
3051       case T_OBJECT:
3052         SET_STACK_OBJECT(ts->earlyret_oop(), 0);
3053         MORE_STACK(1);
3054         break;
3055       default:
3056         ShouldNotReachHere();
3057     }
3058 
3059     ts->clr_earlyret_value();
3060     ts->set_earlyret_oop(nullptr);
3061     ts->clr_earlyret_pending();
3062 
3063     // Fall through to handle_return.
3064 
3065   } // handle_Early_Return
3066 
3067   handle_return: {
3068     // A storestore barrier is required to order initialization of
3069     // final fields with publishing the reference to the object that
3070     // holds the field. Without the barrier the value of final fields
3071     // can be observed to change.
3072     OrderAccess::storestore();
3073 
3074     DECACHE_STATE();
3075 
3076     bool suppress_error = istate->msg() == popping_frame || istate->msg() == early_return;
3077     bool suppress_exit_event = THREAD->has_pending_exception() || istate->msg() == popping_frame;
3078     Handle original_exception(THREAD, THREAD->pending_exception());
3079     Handle illegal_state_oop(THREAD, nullptr);
3080 
3081     // We'd like a HandleMark here to prevent any subsequent HandleMarkCleaner
3082     // in any following VM entries from freeing our live handles, but illegal_state_oop
3083     // isn't really allocated yet and so doesn't become live until later and
3084     // in unpredictable places. Instead we must protect the places where we enter the
3085     // VM. It would be much simpler (and safer) if we could allocate a real handle with
3086     // a null oop in it and then overwrite the oop later as needed. This isn't
3087     // unfortunately isn't possible.
3088 
3089     if (THREAD->has_pending_exception()) {
3090       THREAD->clear_pending_exception();
3091     }
3092 
3093     //
3094     // As far as we are concerned we have returned. If we have a pending exception
3095     // that will be returned as this invocation's result. However if we get any
3096     // exception(s) while checking monitor state one of those IllegalMonitorStateExceptions
3097     // will be our final result (i.e. monitor exception trumps a pending exception).
3098     //
3099 
3100     // If we never locked the method (or really passed the point where we would have),
3101     // there is no need to unlock it (or look for other monitors), since that
3102     // could not have happened.
3103 
3104     if (THREAD->do_not_unlock_if_synchronized()) {
3105 
3106       // Never locked, reset the flag now because obviously any caller must
3107       // have passed their point of locking for us to have gotten here.
3108 
3109       THREAD->set_do_not_unlock_if_synchronized(false);
3110     } else {
3111       // At this point we consider that we have returned. We now check that the
3112       // locks were properly block structured. If we find that they were not
3113       // used properly we will return with an illegal monitor exception.
3114       // The exception is checked by the caller not the callee since this
3115       // checking is considered to be part of the invocation and therefore
3116       // in the callers scope (JVM spec 8.13).
3117       //
3118       // Another weird thing to watch for is if the method was locked
3119       // recursively and then not exited properly. This means we must
3120       // examine all the entries in reverse time(and stack) order and
3121       // unlock as we find them. If we find the method monitor before
3122       // we are at the initial entry then we should throw an exception.
3123       // It is not clear the template based interpreter does this
3124       // correctly
3125 
3126       BasicObjectLock* base = istate->monitor_base();
3127       BasicObjectLock* end = (BasicObjectLock*) istate->stack_base();
3128       bool method_unlock_needed = METHOD->is_synchronized();
3129       // We know the initial monitor was used for the method don't check that
3130       // slot in the loop
3131       if (method_unlock_needed) base--;
3132 
3133       // Check all the monitors to see they are unlocked. Install exception if found to be locked.
3134       while (end < base) {
3135         oop lockee = end->obj();
3136         if (lockee != nullptr) {
3137           BasicLock* lock = end->lock();
3138 
3139           bool success = false;
3140           if (LockingMode == LM_LEGACY) {
3141             markWord header = lock->displaced_header();
3142             end->set_obj(nullptr);
3143 
3144             // If it isn't recursive we either must swap old header or call the runtime
3145             success = true;
3146             if (header.to_pointer() != nullptr) {
3147               markWord old_header = markWord::encode(lock);
3148               if (lockee->cas_set_mark(header, old_header) != old_header) {
3149                 // restore object for the slow case
3150                 end->set_obj(lockee);
3151                 success = false;
3152               }
3153             }
3154           }
3155           if (!success) {
3156             InterpreterRuntime::monitorexit(end);
3157           }
3158 
3159           // One error is plenty
3160           if (illegal_state_oop() == nullptr && !suppress_error) {
3161             {
3162               // Prevent any HandleMarkCleaner from freeing our live handles
3163               HandleMark __hm(THREAD);
3164               CALL_VM_NOCHECK(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD));
3165             }
3166             assert(THREAD->has_pending_exception(), "Lost our exception!");
3167             illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
3168             THREAD->clear_pending_exception();
3169           }
3170         }
3171         end++;
3172       }
3173       // Unlock the method if needed
3174       if (method_unlock_needed) {
3175         if (base->obj() == nullptr) {
3176           // The method is already unlocked this is not good.
3177           if (illegal_state_oop() == nullptr && !suppress_error) {
3178             {
3179               // Prevent any HandleMarkCleaner from freeing our live handles
3180               HandleMark __hm(THREAD);
3181               CALL_VM_NOCHECK(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD));
3182             }
3183             assert(THREAD->has_pending_exception(), "Lost our exception!");
3184             illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
3185             THREAD->clear_pending_exception();
3186           }
3187         } else {
3188           //
3189           // The initial monitor is always used for the method
3190           // However if that slot is no longer the oop for the method it was unlocked
3191           // and reused by something that wasn't unlocked!
3192           //
3193           // deopt can come in with rcvr dead because c2 knows
3194           // its value is preserved in the monitor. So we can't use locals[0] at all
3195           // and must use first monitor slot.
3196           //
3197           oop rcvr = base->obj();
3198           if (rcvr == nullptr) {
3199             if (!suppress_error) {
3200               VM_JAVA_ERROR_NO_JUMP(vmSymbols::java_lang_NullPointerException(), "");
3201               illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
3202               THREAD->clear_pending_exception();
3203             }
3204           } else if (LockingMode != LM_LEGACY) {
3205             InterpreterRuntime::monitorexit(base);
3206             if (THREAD->has_pending_exception()) {
3207               if (!suppress_error) illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
3208               THREAD->clear_pending_exception();
3209             }
3210           } else {
3211             BasicLock* lock = base->lock();
3212             markWord header = lock->displaced_header();
3213             base->set_obj(nullptr);
3214 
3215             // If it isn't recursive we either must swap old header or call the runtime
3216             bool dec_monitor_count = true;
3217             if (header.to_pointer() != nullptr) {
3218               markWord old_header = markWord::encode(lock);
3219               if (rcvr->cas_set_mark(header, old_header) != old_header) {
3220                 // restore object for the slow case
3221                 base->set_obj(rcvr);
3222                 dec_monitor_count = false;
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               }
3229             }
3230           }
3231         }
3232       }
3233     }
3234     // Clear the do_not_unlock flag now.
3235     THREAD->set_do_not_unlock_if_synchronized(false);
3236 
3237     //
3238     // Notify jvmti/jvmdi
3239     //
3240     // NOTE: we do not notify a method_exit if we have a pending exception,
3241     // including an exception we generate for unlocking checks.  In the former
3242     // case, JVMDI has already been notified by our call for the exception handler
3243     // and in both cases as far as JVMDI is concerned we have already returned.
3244     // If we notify it again JVMDI will be all confused about how many frames
3245     // are still on the stack (4340444).
3246     //
3247     // NOTE Further! It turns out the JVMTI spec in fact expects to see
3248     // method_exit events whenever we leave an activation unless it was done
3249     // for popframe. This is nothing like jvmdi. However we are passing the
3250     // tests at the moment (apparently because they are jvmdi based) so rather
3251     // than change this code and possibly fail tests we will leave it alone
3252     // (with this note) in anticipation of changing the vm and the tests
3253     // simultaneously.
3254 
3255     suppress_exit_event = suppress_exit_event || illegal_state_oop() != nullptr;
3256 
3257     // Whenever JVMTI puts a thread in interp_only_mode, method
3258     // entry/exit events are sent for that thread to track stack depth.
3259 
3260     if (JVMTI_ENABLED && !suppress_exit_event && THREAD->is_interp_only_mode()) {
3261       // Prevent any HandleMarkCleaner from freeing our live handles
3262       HandleMark __hm(THREAD);
3263       CALL_VM_NOCHECK(InterpreterRuntime::post_method_exit(THREAD));
3264     }
3265 
3266     //
3267     // See if we are returning any exception
3268     // A pending exception that was pending prior to a possible popping frame
3269     // overrides the popping frame.
3270     //
3271     assert(!suppress_error || (suppress_error && illegal_state_oop() == nullptr), "Error was not suppressed");
3272     if (illegal_state_oop() != nullptr || original_exception() != nullptr) {
3273       // Inform the frame manager we have no result.
3274       istate->set_msg(throwing_exception);
3275       if (illegal_state_oop() != nullptr)
3276         THREAD->set_pending_exception(illegal_state_oop(), nullptr, 0);
3277       else
3278         THREAD->set_pending_exception(original_exception(), nullptr, 0);
3279       UPDATE_PC_AND_RETURN(0);
3280     }
3281 
3282     if (istate->msg() == popping_frame) {
3283       // Make it simpler on the assembly code and set the message for the frame pop.
3284       // returns
3285       if (istate->prev() == nullptr) {
3286         // We must be returning to a deoptimized frame (because popframe only happens between
3287         // two interpreted frames). We need to save the current arguments in C heap so that
3288         // the deoptimized frame when it restarts can copy the arguments to its expression
3289         // stack and re-execute the call. We also have to notify deoptimization that this
3290         // has occurred and to pick the preserved args copy them to the deoptimized frame's
3291         // java expression stack. Yuck.
3292         //
3293         THREAD->popframe_preserve_args(in_ByteSize(METHOD->size_of_parameters() * wordSize),
3294                                 LOCALS_SLOT(METHOD->size_of_parameters() - 1));
3295         THREAD->set_popframe_condition_bit(JavaThread::popframe_force_deopt_reexecution_bit);
3296       }
3297     } else {
3298       istate->set_msg(return_from_method);
3299     }
3300 
3301     // Normal return
3302     // Advance the pc and return to frame manager
3303     UPDATE_PC_AND_RETURN(1);
3304   } /* handle_return: */
3305 
3306 // This is really a fatal error return
3307 
3308 finish:
3309   DECACHE_TOS();
3310   DECACHE_PC();
3311 
3312   return;
3313 }
3314 
3315 // This constructor should only be used to construct the object to signal
3316 // interpreter initialization. All other instances should be created by
3317 // the frame manager.
3318 BytecodeInterpreter::BytecodeInterpreter(messages msg) {
3319   if (msg != initialize) ShouldNotReachHere();
3320   _msg = msg;
3321   _self_link = this;
3322   _prev_link = nullptr;
3323 }
3324 
3325 void BytecodeInterpreter::astore(intptr_t* tos,    int stack_offset,
3326                           intptr_t* locals, int locals_offset) {
3327   intptr_t value = tos[Interpreter::expr_index_at(-stack_offset)];
3328   locals[Interpreter::local_index_at(-locals_offset)] = value;
3329 }
3330 
3331 void BytecodeInterpreter::copy_stack_slot(intptr_t *tos, int from_offset,
3332                                    int to_offset) {
3333   tos[Interpreter::expr_index_at(-to_offset)] =
3334                       (intptr_t)tos[Interpreter::expr_index_at(-from_offset)];
3335 }
3336 
3337 void BytecodeInterpreter::dup(intptr_t *tos) {
3338   copy_stack_slot(tos, -1, 0);
3339 }
3340 
3341 void BytecodeInterpreter::dup2(intptr_t *tos) {
3342   copy_stack_slot(tos, -2, 0);
3343   copy_stack_slot(tos, -1, 1);
3344 }
3345 
3346 void BytecodeInterpreter::dup_x1(intptr_t *tos) {
3347   /* insert top word two down */
3348   copy_stack_slot(tos, -1, 0);
3349   copy_stack_slot(tos, -2, -1);
3350   copy_stack_slot(tos, 0, -2);
3351 }
3352 
3353 void BytecodeInterpreter::dup_x2(intptr_t *tos) {
3354   /* insert top word three down  */
3355   copy_stack_slot(tos, -1, 0);
3356   copy_stack_slot(tos, -2, -1);
3357   copy_stack_slot(tos, -3, -2);
3358   copy_stack_slot(tos, 0, -3);
3359 }
3360 void BytecodeInterpreter::dup2_x1(intptr_t *tos) {
3361   /* insert top 2 slots three down */
3362   copy_stack_slot(tos, -1, 1);
3363   copy_stack_slot(tos, -2, 0);
3364   copy_stack_slot(tos, -3, -1);
3365   copy_stack_slot(tos, 1, -2);
3366   copy_stack_slot(tos, 0, -3);
3367 }
3368 void BytecodeInterpreter::dup2_x2(intptr_t *tos) {
3369   /* insert top 2 slots four down */
3370   copy_stack_slot(tos, -1, 1);
3371   copy_stack_slot(tos, -2, 0);
3372   copy_stack_slot(tos, -3, -1);
3373   copy_stack_slot(tos, -4, -2);
3374   copy_stack_slot(tos, 1, -3);
3375   copy_stack_slot(tos, 0, -4);
3376 }
3377 
3378 
3379 void BytecodeInterpreter::swap(intptr_t *tos) {
3380   // swap top two elements
3381   intptr_t val = tos[Interpreter::expr_index_at(1)];
3382   // Copy -2 entry to -1
3383   copy_stack_slot(tos, -2, -1);
3384   // Store saved -1 entry into -2
3385   tos[Interpreter::expr_index_at(2)] = val;
3386 }
3387 // --------------------------------------------------------------------------------
3388 // Non-product code
3389 #ifndef PRODUCT
3390 
3391 const char* BytecodeInterpreter::C_msg(BytecodeInterpreter::messages msg) {
3392   switch (msg) {
3393      case BytecodeInterpreter::no_request:  return("no_request");
3394      case BytecodeInterpreter::initialize:  return("initialize");
3395      // status message to C++ interpreter
3396      case BytecodeInterpreter::method_entry:  return("method_entry");
3397      case BytecodeInterpreter::method_resume:  return("method_resume");
3398      case BytecodeInterpreter::got_monitors:  return("got_monitors");
3399      case BytecodeInterpreter::rethrow_exception:  return("rethrow_exception");
3400      // requests to frame manager from C++ interpreter
3401      case BytecodeInterpreter::call_method:  return("call_method");
3402      case BytecodeInterpreter::return_from_method:  return("return_from_method");
3403      case BytecodeInterpreter::more_monitors:  return("more_monitors");
3404      case BytecodeInterpreter::throwing_exception:  return("throwing_exception");
3405      case BytecodeInterpreter::popping_frame:  return("popping_frame");
3406      case BytecodeInterpreter::do_osr:  return("do_osr");
3407      // deopt
3408      case BytecodeInterpreter::deopt_resume:  return("deopt_resume");
3409      case BytecodeInterpreter::deopt_resume2:  return("deopt_resume2");
3410      default: return("BAD MSG");
3411   }
3412 }
3413 void
3414 BytecodeInterpreter::print() {
3415   tty->print_cr("thread: " INTPTR_FORMAT, (uintptr_t) this->_thread);
3416   tty->print_cr("bcp: " INTPTR_FORMAT, (uintptr_t) this->_bcp);
3417   tty->print_cr("locals: " INTPTR_FORMAT, (uintptr_t) this->_locals);
3418   tty->print_cr("constants: " INTPTR_FORMAT, (uintptr_t) this->_constants);
3419   {
3420     ResourceMark rm;
3421     char *method_name = _method->name_and_sig_as_C_string();
3422     tty->print_cr("method: " INTPTR_FORMAT "[ %s ]",  (uintptr_t) this->_method, method_name);
3423   }
3424   tty->print_cr("stack: " INTPTR_FORMAT, (uintptr_t) this->_stack);
3425   tty->print_cr("msg: %s", C_msg(this->_msg));
3426   tty->print_cr("result_to_call._callee: " INTPTR_FORMAT, (uintptr_t) this->_result._to_call._callee);
3427   tty->print_cr("result_to_call._callee_entry_point: " INTPTR_FORMAT, (uintptr_t) this->_result._to_call._callee_entry_point);
3428   tty->print_cr("result_to_call._bcp_advance: %d ", this->_result._to_call._bcp_advance);
3429   tty->print_cr("osr._osr_buf: " INTPTR_FORMAT, (uintptr_t) this->_result._osr._osr_buf);
3430   tty->print_cr("osr._osr_entry: " INTPTR_FORMAT, (uintptr_t) this->_result._osr._osr_entry);
3431   tty->print_cr("prev_link: " INTPTR_FORMAT, (uintptr_t) this->_prev_link);
3432   tty->print_cr("native_mirror: " INTPTR_FORMAT, (uintptr_t) p2i(this->_oop_temp));
3433   tty->print_cr("stack_base: " INTPTR_FORMAT, (uintptr_t) this->_stack_base);
3434   tty->print_cr("stack_limit: " INTPTR_FORMAT, (uintptr_t) this->_stack_limit);
3435   tty->print_cr("monitor_base: " INTPTR_FORMAT, (uintptr_t) this->_monitor_base);
3436   tty->print_cr("self_link: " INTPTR_FORMAT, (uintptr_t) this->_self_link);
3437 }
3438 
3439 extern "C" {
3440   void PI(uintptr_t arg) {
3441     ((BytecodeInterpreter*)arg)->print();
3442   }
3443 }
3444 #endif // PRODUCT