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