comparison src/share/vm/interpreter/bytecodeInterpreter.cpp @ 0:a61af66fc99e jdk7-b24

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