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