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