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