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