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