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