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