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