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