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