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