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