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