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