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