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