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