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