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