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