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