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