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