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