1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/interpreter/bytecodeInterpreter.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,3492 @@ 1.4 +/* 1.5 + * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +// no precompiled headers 1.29 +#include "classfile/vmSymbols.hpp" 1.30 +#include "gc_interface/collectedHeap.hpp" 1.31 +#include "interpreter/bytecodeHistogram.hpp" 1.32 +#include "interpreter/bytecodeInterpreter.hpp" 1.33 +#include "interpreter/bytecodeInterpreter.inline.hpp" 1.34 +#include "interpreter/bytecodeInterpreterProfiling.hpp" 1.35 +#include "interpreter/interpreter.hpp" 1.36 +#include "interpreter/interpreterRuntime.hpp" 1.37 +#include "memory/resourceArea.hpp" 1.38 +#include "oops/methodCounters.hpp" 1.39 +#include "oops/objArrayKlass.hpp" 1.40 +#include "oops/oop.inline.hpp" 1.41 +#include "prims/jvmtiExport.hpp" 1.42 +#include "prims/jvmtiThreadState.hpp" 1.43 +#include "runtime/biasedLocking.hpp" 1.44 +#include "runtime/frame.inline.hpp" 1.45 +#include "runtime/handles.inline.hpp" 1.46 +#include "runtime/interfaceSupport.hpp" 1.47 +#include "runtime/sharedRuntime.hpp" 1.48 +#include "runtime/threadCritical.hpp" 1.49 +#include "utilities/exceptions.hpp" 1.50 +#ifdef TARGET_OS_ARCH_linux_x86 1.51 +# include "orderAccess_linux_x86.inline.hpp" 1.52 +#endif 1.53 +#ifdef TARGET_OS_ARCH_linux_sparc 1.54 +# include "orderAccess_linux_sparc.inline.hpp" 1.55 +#endif 1.56 +#ifdef TARGET_OS_ARCH_linux_zero 1.57 +# include "orderAccess_linux_zero.inline.hpp" 1.58 +#endif 1.59 +#ifdef TARGET_OS_ARCH_solaris_x86 1.60 +# include "orderAccess_solaris_x86.inline.hpp" 1.61 +#endif 1.62 +#ifdef TARGET_OS_ARCH_solaris_sparc 1.63 +# include "orderAccess_solaris_sparc.inline.hpp" 1.64 +#endif 1.65 +#ifdef TARGET_OS_ARCH_windows_x86 1.66 +# include "orderAccess_windows_x86.inline.hpp" 1.67 +#endif 1.68 +#ifdef TARGET_OS_ARCH_linux_arm 1.69 +# include "orderAccess_linux_arm.inline.hpp" 1.70 +#endif 1.71 +#ifdef TARGET_OS_ARCH_linux_ppc 1.72 +# include "orderAccess_linux_ppc.inline.hpp" 1.73 +#endif 1.74 +#ifdef TARGET_OS_ARCH_aix_ppc 1.75 +# include "orderAccess_aix_ppc.inline.hpp" 1.76 +#endif 1.77 +#ifdef TARGET_OS_ARCH_bsd_x86 1.78 +# include "orderAccess_bsd_x86.inline.hpp" 1.79 +#endif 1.80 +#ifdef TARGET_OS_ARCH_bsd_zero 1.81 +# include "orderAccess_bsd_zero.inline.hpp" 1.82 +#endif 1.83 + 1.84 + 1.85 +// no precompiled headers 1.86 +#ifdef CC_INTERP 1.87 + 1.88 +/* 1.89 + * USELABELS - If using GCC, then use labels for the opcode dispatching 1.90 + * rather -then a switch statement. This improves performance because it 1.91 + * gives us the oportunity to have the instructions that calculate the 1.92 + * next opcode to jump to be intermixed with the rest of the instructions 1.93 + * that implement the opcode (see UPDATE_PC_AND_TOS_AND_CONTINUE macro). 1.94 + */ 1.95 +#undef USELABELS 1.96 +#ifdef __GNUC__ 1.97 +/* 1.98 + ASSERT signifies debugging. It is much easier to step thru bytecodes if we 1.99 + don't use the computed goto approach. 1.100 +*/ 1.101 +#ifndef ASSERT 1.102 +#define USELABELS 1.103 +#endif 1.104 +#endif 1.105 + 1.106 +#undef CASE 1.107 +#ifdef USELABELS 1.108 +#define CASE(opcode) opc ## opcode 1.109 +#define DEFAULT opc_default 1.110 +#else 1.111 +#define CASE(opcode) case Bytecodes:: opcode 1.112 +#define DEFAULT default 1.113 +#endif 1.114 + 1.115 +/* 1.116 + * PREFETCH_OPCCODE - Some compilers do better if you prefetch the next 1.117 + * opcode before going back to the top of the while loop, rather then having 1.118 + * the top of the while loop handle it. This provides a better opportunity 1.119 + * for instruction scheduling. Some compilers just do this prefetch 1.120 + * automatically. Some actually end up with worse performance if you 1.121 + * force the prefetch. Solaris gcc seems to do better, but cc does worse. 1.122 + */ 1.123 +#undef PREFETCH_OPCCODE 1.124 +#define PREFETCH_OPCCODE 1.125 + 1.126 +/* 1.127 + Interpreter safepoint: it is expected that the interpreter will have no live 1.128 + handles of its own creation live at an interpreter safepoint. Therefore we 1.129 + run a HandleMarkCleaner and trash all handles allocated in the call chain 1.130 + since the JavaCalls::call_helper invocation that initiated the chain. 1.131 + There really shouldn't be any handles remaining to trash but this is cheap 1.132 + in relation to a safepoint. 1.133 +*/ 1.134 +#define SAFEPOINT \ 1.135 + if ( SafepointSynchronize::is_synchronizing()) { \ 1.136 + { \ 1.137 + /* zap freed handles rather than GC'ing them */ \ 1.138 + HandleMarkCleaner __hmc(THREAD); \ 1.139 + } \ 1.140 + CALL_VM(SafepointSynchronize::block(THREAD), handle_exception); \ 1.141 + } 1.142 + 1.143 +/* 1.144 + * VM_JAVA_ERROR - Macro for throwing a java exception from 1.145 + * the interpreter loop. Should really be a CALL_VM but there 1.146 + * is no entry point to do the transition to vm so we just 1.147 + * do it by hand here. 1.148 + */ 1.149 +#define VM_JAVA_ERROR_NO_JUMP(name, msg, note_a_trap) \ 1.150 + DECACHE_STATE(); \ 1.151 + SET_LAST_JAVA_FRAME(); \ 1.152 + { \ 1.153 + InterpreterRuntime::note_a_trap(THREAD, istate->method(), BCI()); \ 1.154 + ThreadInVMfromJava trans(THREAD); \ 1.155 + Exceptions::_throw_msg(THREAD, __FILE__, __LINE__, name, msg); \ 1.156 + } \ 1.157 + RESET_LAST_JAVA_FRAME(); \ 1.158 + CACHE_STATE(); 1.159 + 1.160 +// Normal throw of a java error. 1.161 +#define VM_JAVA_ERROR(name, msg, note_a_trap) \ 1.162 + VM_JAVA_ERROR_NO_JUMP(name, msg, note_a_trap) \ 1.163 + goto handle_exception; 1.164 + 1.165 +#ifdef PRODUCT 1.166 +#define DO_UPDATE_INSTRUCTION_COUNT(opcode) 1.167 +#else 1.168 +#define DO_UPDATE_INSTRUCTION_COUNT(opcode) \ 1.169 +{ \ 1.170 + BytecodeCounter::_counter_value++; \ 1.171 + BytecodeHistogram::_counters[(Bytecodes::Code)opcode]++; \ 1.172 + if (StopInterpreterAt && StopInterpreterAt == BytecodeCounter::_counter_value) os::breakpoint(); \ 1.173 + if (TraceBytecodes) { \ 1.174 + CALL_VM((void)SharedRuntime::trace_bytecode(THREAD, 0, \ 1.175 + topOfStack[Interpreter::expr_index_at(1)], \ 1.176 + topOfStack[Interpreter::expr_index_at(2)]), \ 1.177 + handle_exception); \ 1.178 + } \ 1.179 +} 1.180 +#endif 1.181 + 1.182 +#undef DEBUGGER_SINGLE_STEP_NOTIFY 1.183 +#ifdef VM_JVMTI 1.184 +/* NOTE: (kbr) This macro must be called AFTER the PC has been 1.185 + incremented. JvmtiExport::at_single_stepping_point() may cause a 1.186 + breakpoint opcode to get inserted at the current PC to allow the 1.187 + debugger to coalesce single-step events. 1.188 + 1.189 + As a result if we call at_single_stepping_point() we refetch opcode 1.190 + to get the current opcode. This will override any other prefetching 1.191 + that might have occurred. 1.192 +*/ 1.193 +#define DEBUGGER_SINGLE_STEP_NOTIFY() \ 1.194 +{ \ 1.195 + if (_jvmti_interp_events) { \ 1.196 + if (JvmtiExport::should_post_single_step()) { \ 1.197 + DECACHE_STATE(); \ 1.198 + SET_LAST_JAVA_FRAME(); \ 1.199 + ThreadInVMfromJava trans(THREAD); \ 1.200 + JvmtiExport::at_single_stepping_point(THREAD, \ 1.201 + istate->method(), \ 1.202 + pc); \ 1.203 + RESET_LAST_JAVA_FRAME(); \ 1.204 + CACHE_STATE(); \ 1.205 + if (THREAD->pop_frame_pending() && \ 1.206 + !THREAD->pop_frame_in_process()) { \ 1.207 + goto handle_Pop_Frame; \ 1.208 + } \ 1.209 + if (THREAD->jvmti_thread_state() && \ 1.210 + THREAD->jvmti_thread_state()->is_earlyret_pending()) { \ 1.211 + goto handle_Early_Return; \ 1.212 + } \ 1.213 + opcode = *pc; \ 1.214 + } \ 1.215 + } \ 1.216 +} 1.217 +#else 1.218 +#define DEBUGGER_SINGLE_STEP_NOTIFY() 1.219 +#endif 1.220 + 1.221 +/* 1.222 + * CONTINUE - Macro for executing the next opcode. 1.223 + */ 1.224 +#undef CONTINUE 1.225 +#ifdef USELABELS 1.226 +// Have to do this dispatch this way in C++ because otherwise gcc complains about crossing an 1.227 +// initialization (which is is the initialization of the table pointer...) 1.228 +#define DISPATCH(opcode) goto *(void*)dispatch_table[opcode] 1.229 +#define CONTINUE { \ 1.230 + opcode = *pc; \ 1.231 + DO_UPDATE_INSTRUCTION_COUNT(opcode); \ 1.232 + DEBUGGER_SINGLE_STEP_NOTIFY(); \ 1.233 + DISPATCH(opcode); \ 1.234 + } 1.235 +#else 1.236 +#ifdef PREFETCH_OPCCODE 1.237 +#define CONTINUE { \ 1.238 + opcode = *pc; \ 1.239 + DO_UPDATE_INSTRUCTION_COUNT(opcode); \ 1.240 + DEBUGGER_SINGLE_STEP_NOTIFY(); \ 1.241 + continue; \ 1.242 + } 1.243 +#else 1.244 +#define CONTINUE { \ 1.245 + DO_UPDATE_INSTRUCTION_COUNT(opcode); \ 1.246 + DEBUGGER_SINGLE_STEP_NOTIFY(); \ 1.247 + continue; \ 1.248 + } 1.249 +#endif 1.250 +#endif 1.251 + 1.252 + 1.253 +#define UPDATE_PC(opsize) {pc += opsize; } 1.254 +/* 1.255 + * UPDATE_PC_AND_TOS - Macro for updating the pc and topOfStack. 1.256 + */ 1.257 +#undef UPDATE_PC_AND_TOS 1.258 +#define UPDATE_PC_AND_TOS(opsize, stack) \ 1.259 + {pc += opsize; MORE_STACK(stack); } 1.260 + 1.261 +/* 1.262 + * UPDATE_PC_AND_TOS_AND_CONTINUE - Macro for updating the pc and topOfStack, 1.263 + * and executing the next opcode. It's somewhat similar to the combination 1.264 + * of UPDATE_PC_AND_TOS and CONTINUE, but with some minor optimizations. 1.265 + */ 1.266 +#undef UPDATE_PC_AND_TOS_AND_CONTINUE 1.267 +#ifdef USELABELS 1.268 +#define UPDATE_PC_AND_TOS_AND_CONTINUE(opsize, stack) { \ 1.269 + pc += opsize; opcode = *pc; MORE_STACK(stack); \ 1.270 + DO_UPDATE_INSTRUCTION_COUNT(opcode); \ 1.271 + DEBUGGER_SINGLE_STEP_NOTIFY(); \ 1.272 + DISPATCH(opcode); \ 1.273 + } 1.274 + 1.275 +#define UPDATE_PC_AND_CONTINUE(opsize) { \ 1.276 + pc += opsize; opcode = *pc; \ 1.277 + DO_UPDATE_INSTRUCTION_COUNT(opcode); \ 1.278 + DEBUGGER_SINGLE_STEP_NOTIFY(); \ 1.279 + DISPATCH(opcode); \ 1.280 + } 1.281 +#else 1.282 +#ifdef PREFETCH_OPCCODE 1.283 +#define UPDATE_PC_AND_TOS_AND_CONTINUE(opsize, stack) { \ 1.284 + pc += opsize; opcode = *pc; MORE_STACK(stack); \ 1.285 + DO_UPDATE_INSTRUCTION_COUNT(opcode); \ 1.286 + DEBUGGER_SINGLE_STEP_NOTIFY(); \ 1.287 + goto do_continue; \ 1.288 + } 1.289 + 1.290 +#define UPDATE_PC_AND_CONTINUE(opsize) { \ 1.291 + pc += opsize; opcode = *pc; \ 1.292 + DO_UPDATE_INSTRUCTION_COUNT(opcode); \ 1.293 + DEBUGGER_SINGLE_STEP_NOTIFY(); \ 1.294 + goto do_continue; \ 1.295 + } 1.296 +#else 1.297 +#define UPDATE_PC_AND_TOS_AND_CONTINUE(opsize, stack) { \ 1.298 + pc += opsize; MORE_STACK(stack); \ 1.299 + DO_UPDATE_INSTRUCTION_COUNT(opcode); \ 1.300 + DEBUGGER_SINGLE_STEP_NOTIFY(); \ 1.301 + goto do_continue; \ 1.302 + } 1.303 + 1.304 +#define UPDATE_PC_AND_CONTINUE(opsize) { \ 1.305 + pc += opsize; \ 1.306 + DO_UPDATE_INSTRUCTION_COUNT(opcode); \ 1.307 + DEBUGGER_SINGLE_STEP_NOTIFY(); \ 1.308 + goto do_continue; \ 1.309 + } 1.310 +#endif /* PREFETCH_OPCCODE */ 1.311 +#endif /* USELABELS */ 1.312 + 1.313 +// About to call a new method, update the save the adjusted pc and return to frame manager 1.314 +#define UPDATE_PC_AND_RETURN(opsize) \ 1.315 + DECACHE_TOS(); \ 1.316 + istate->set_bcp(pc+opsize); \ 1.317 + return; 1.318 + 1.319 + 1.320 +#define METHOD istate->method() 1.321 +#define GET_METHOD_COUNTERS(res) \ 1.322 + res = METHOD->method_counters(); \ 1.323 + if (res == NULL) { \ 1.324 + CALL_VM(res = InterpreterRuntime::build_method_counters(THREAD, METHOD), handle_exception); \ 1.325 + } 1.326 + 1.327 +#define OSR_REQUEST(res, branch_pc) \ 1.328 + CALL_VM(res=InterpreterRuntime::frequency_counter_overflow(THREAD, branch_pc), handle_exception); 1.329 +/* 1.330 + * For those opcodes that need to have a GC point on a backwards branch 1.331 + */ 1.332 + 1.333 +// Backedge counting is kind of strange. The asm interpreter will increment 1.334 +// the backedge counter as a separate counter but it does it's comparisons 1.335 +// to the sum (scaled) of invocation counter and backedge count to make 1.336 +// a decision. Seems kind of odd to sum them together like that 1.337 + 1.338 +// skip is delta from current bcp/bci for target, branch_pc is pre-branch bcp 1.339 + 1.340 + 1.341 +#define DO_BACKEDGE_CHECKS(skip, branch_pc) \ 1.342 + if ((skip) <= 0) { \ 1.343 + MethodCounters* mcs; \ 1.344 + GET_METHOD_COUNTERS(mcs); \ 1.345 + if (UseLoopCounter) { \ 1.346 + bool do_OSR = UseOnStackReplacement; \ 1.347 + mcs->backedge_counter()->increment(); \ 1.348 + if (ProfileInterpreter) { \ 1.349 + BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception); \ 1.350 + /* Check for overflow against MDO count. */ \ 1.351 + do_OSR = do_OSR \ 1.352 + && (mdo_last_branch_taken_count >= (uint)InvocationCounter::InterpreterBackwardBranchLimit)\ 1.353 + /* When ProfileInterpreter is on, the backedge_count comes */ \ 1.354 + /* from the methodDataOop, which value does not get reset on */ \ 1.355 + /* the call to frequency_counter_overflow(). To avoid */ \ 1.356 + /* excessive calls to the overflow routine while the method is */ \ 1.357 + /* being compiled, add a second test to make sure the overflow */ \ 1.358 + /* function is called only once every overflow_frequency. */ \ 1.359 + && (!(mdo_last_branch_taken_count & 1023)); \ 1.360 + } else { \ 1.361 + /* check for overflow of backedge counter */ \ 1.362 + do_OSR = do_OSR \ 1.363 + && mcs->invocation_counter()->reached_InvocationLimit(mcs->backedge_counter()); \ 1.364 + } \ 1.365 + if (do_OSR) { \ 1.366 + nmethod* osr_nmethod; \ 1.367 + OSR_REQUEST(osr_nmethod, branch_pc); \ 1.368 + if (osr_nmethod != NULL && osr_nmethod->osr_entry_bci() != InvalidOSREntryBci) { \ 1.369 + intptr_t* buf; \ 1.370 + /* Call OSR migration with last java frame only, no checks. */ \ 1.371 + CALL_VM_NAKED_LJF(buf=SharedRuntime::OSR_migration_begin(THREAD)); \ 1.372 + istate->set_msg(do_osr); \ 1.373 + istate->set_osr_buf((address)buf); \ 1.374 + istate->set_osr_entry(osr_nmethod->osr_entry()); \ 1.375 + return; \ 1.376 + } \ 1.377 + } \ 1.378 + } /* UseCompiler ... */ \ 1.379 + SAFEPOINT; \ 1.380 + } 1.381 + 1.382 +/* 1.383 + * For those opcodes that need to have a GC point on a backwards branch 1.384 + */ 1.385 + 1.386 +/* 1.387 + * Macros for caching and flushing the interpreter state. Some local 1.388 + * variables need to be flushed out to the frame before we do certain 1.389 + * things (like pushing frames or becomming gc safe) and some need to 1.390 + * be recached later (like after popping a frame). We could use one 1.391 + * macro to cache or decache everything, but this would be less then 1.392 + * optimal because we don't always need to cache or decache everything 1.393 + * because some things we know are already cached or decached. 1.394 + */ 1.395 +#undef DECACHE_TOS 1.396 +#undef CACHE_TOS 1.397 +#undef CACHE_PREV_TOS 1.398 +#define DECACHE_TOS() istate->set_stack(topOfStack); 1.399 + 1.400 +#define CACHE_TOS() topOfStack = (intptr_t *)istate->stack(); 1.401 + 1.402 +#undef DECACHE_PC 1.403 +#undef CACHE_PC 1.404 +#define DECACHE_PC() istate->set_bcp(pc); 1.405 +#define CACHE_PC() pc = istate->bcp(); 1.406 +#define CACHE_CP() cp = istate->constants(); 1.407 +#define CACHE_LOCALS() locals = istate->locals(); 1.408 +#undef CACHE_FRAME 1.409 +#define CACHE_FRAME() 1.410 + 1.411 +// BCI() returns the current bytecode-index. 1.412 +#undef BCI 1.413 +#define BCI() ((int)(intptr_t)(pc - (intptr_t)istate->method()->code_base())) 1.414 + 1.415 +/* 1.416 + * CHECK_NULL - Macro for throwing a NullPointerException if the object 1.417 + * passed is a null ref. 1.418 + * On some architectures/platforms it should be possible to do this implicitly 1.419 + */ 1.420 +#undef CHECK_NULL 1.421 +#define CHECK_NULL(obj_) \ 1.422 + if ((obj_) == NULL) { \ 1.423 + VM_JAVA_ERROR(vmSymbols::java_lang_NullPointerException(), NULL, note_nullCheck_trap); \ 1.424 + } \ 1.425 + VERIFY_OOP(obj_) 1.426 + 1.427 +#define VMdoubleConstZero() 0.0 1.428 +#define VMdoubleConstOne() 1.0 1.429 +#define VMlongConstZero() (max_jlong-max_jlong) 1.430 +#define VMlongConstOne() ((max_jlong-max_jlong)+1) 1.431 + 1.432 +/* 1.433 + * Alignment 1.434 + */ 1.435 +#define VMalignWordUp(val) (((uintptr_t)(val) + 3) & ~3) 1.436 + 1.437 +// Decache the interpreter state that interpreter modifies directly (i.e. GC is indirect mod) 1.438 +#define DECACHE_STATE() DECACHE_PC(); DECACHE_TOS(); 1.439 + 1.440 +// Reload interpreter state after calling the VM or a possible GC 1.441 +#define CACHE_STATE() \ 1.442 + CACHE_TOS(); \ 1.443 + CACHE_PC(); \ 1.444 + CACHE_CP(); \ 1.445 + CACHE_LOCALS(); 1.446 + 1.447 +// Call the VM with last java frame only. 1.448 +#define CALL_VM_NAKED_LJF(func) \ 1.449 + DECACHE_STATE(); \ 1.450 + SET_LAST_JAVA_FRAME(); \ 1.451 + func; \ 1.452 + RESET_LAST_JAVA_FRAME(); \ 1.453 + CACHE_STATE(); 1.454 + 1.455 +// Call the VM. Don't check for pending exceptions. 1.456 +#define CALL_VM_NOCHECK(func) \ 1.457 + CALL_VM_NAKED_LJF(func) \ 1.458 + if (THREAD->pop_frame_pending() && \ 1.459 + !THREAD->pop_frame_in_process()) { \ 1.460 + goto handle_Pop_Frame; \ 1.461 + } \ 1.462 + if (THREAD->jvmti_thread_state() && \ 1.463 + THREAD->jvmti_thread_state()->is_earlyret_pending()) { \ 1.464 + goto handle_Early_Return; \ 1.465 + } 1.466 + 1.467 +// Call the VM and check for pending exceptions 1.468 +#define CALL_VM(func, label) { \ 1.469 + CALL_VM_NOCHECK(func); \ 1.470 + if (THREAD->has_pending_exception()) goto label; \ 1.471 + } 1.472 + 1.473 +/* 1.474 + * BytecodeInterpreter::run(interpreterState istate) 1.475 + * BytecodeInterpreter::runWithChecks(interpreterState istate) 1.476 + * 1.477 + * The real deal. This is where byte codes actually get interpreted. 1.478 + * Basically it's a big while loop that iterates until we return from 1.479 + * the method passed in. 1.480 + * 1.481 + * The runWithChecks is used if JVMTI is enabled. 1.482 + * 1.483 + */ 1.484 +#if defined(VM_JVMTI) 1.485 +void 1.486 +BytecodeInterpreter::runWithChecks(interpreterState istate) { 1.487 +#else 1.488 +void 1.489 +BytecodeInterpreter::run(interpreterState istate) { 1.490 +#endif 1.491 + 1.492 + // In order to simplify some tests based on switches set at runtime 1.493 + // we invoke the interpreter a single time after switches are enabled 1.494 + // and set simpler to to test variables rather than method calls or complex 1.495 + // boolean expressions. 1.496 + 1.497 + static int initialized = 0; 1.498 + static int checkit = 0; 1.499 + static intptr_t* c_addr = NULL; 1.500 + static intptr_t c_value; 1.501 + 1.502 + if (checkit && *c_addr != c_value) { 1.503 + os::breakpoint(); 1.504 + } 1.505 +#ifdef VM_JVMTI 1.506 + static bool _jvmti_interp_events = 0; 1.507 +#endif 1.508 + 1.509 + static int _compiling; // (UseCompiler || CountCompiledCalls) 1.510 + 1.511 +#ifdef ASSERT 1.512 + if (istate->_msg != initialize) { 1.513 + // We have a problem here if we are running with a pre-hsx24 JDK (for example during bootstrap) 1.514 + // because in that case, EnableInvokeDynamic is true by default but will be later switched off 1.515 + // if java_lang_invoke_MethodHandle::compute_offsets() detects that the JDK only has the classes 1.516 + // for the old JSR292 implementation. 1.517 + // This leads to a situation where 'istate->_stack_limit' always accounts for 1.518 + // methodOopDesc::extra_stack_entries() because it is computed in 1.519 + // CppInterpreterGenerator::generate_compute_interpreter_state() which was generated while 1.520 + // EnableInvokeDynamic was still true. On the other hand, istate->_method->max_stack() doesn't 1.521 + // account for extra_stack_entries() anymore because at the time when it is called 1.522 + // EnableInvokeDynamic was already set to false. 1.523 + // So we have a second version of the assertion which handles the case where EnableInvokeDynamic was 1.524 + // switched off because of the wrong classes. 1.525 + if (EnableInvokeDynamic || FLAG_IS_CMDLINE(EnableInvokeDynamic)) { 1.526 + assert(labs(istate->_stack_base - istate->_stack_limit) == (istate->_method->max_stack() + 1), "bad stack limit"); 1.527 + } else { 1.528 + const int extra_stack_entries = Method::extra_stack_entries_for_jsr292; 1.529 + assert(labs(istate->_stack_base - istate->_stack_limit) == (istate->_method->max_stack() + extra_stack_entries 1.530 + + 1), "bad stack limit"); 1.531 + } 1.532 +#ifndef SHARK 1.533 + IA32_ONLY(assert(istate->_stack_limit == istate->_thread->last_Java_sp() + 1, "wrong")); 1.534 +#endif // !SHARK 1.535 + } 1.536 + // Verify linkages. 1.537 + interpreterState l = istate; 1.538 + do { 1.539 + assert(l == l->_self_link, "bad link"); 1.540 + l = l->_prev_link; 1.541 + } while (l != NULL); 1.542 + // Screwups with stack management usually cause us to overwrite istate 1.543 + // save a copy so we can verify it. 1.544 + interpreterState orig = istate; 1.545 +#endif 1.546 + 1.547 + register intptr_t* topOfStack = (intptr_t *)istate->stack(); /* access with STACK macros */ 1.548 + register address pc = istate->bcp(); 1.549 + register jubyte opcode; 1.550 + register intptr_t* locals = istate->locals(); 1.551 + register ConstantPoolCache* cp = istate->constants(); // method()->constants()->cache() 1.552 +#ifdef LOTS_OF_REGS 1.553 + register JavaThread* THREAD = istate->thread(); 1.554 +#else 1.555 +#undef THREAD 1.556 +#define THREAD istate->thread() 1.557 +#endif 1.558 + 1.559 +#ifdef USELABELS 1.560 + const static void* const opclabels_data[256] = { 1.561 +/* 0x00 */ &&opc_nop, &&opc_aconst_null,&&opc_iconst_m1,&&opc_iconst_0, 1.562 +/* 0x04 */ &&opc_iconst_1,&&opc_iconst_2, &&opc_iconst_3, &&opc_iconst_4, 1.563 +/* 0x08 */ &&opc_iconst_5,&&opc_lconst_0, &&opc_lconst_1, &&opc_fconst_0, 1.564 +/* 0x0C */ &&opc_fconst_1,&&opc_fconst_2, &&opc_dconst_0, &&opc_dconst_1, 1.565 + 1.566 +/* 0x10 */ &&opc_bipush, &&opc_sipush, &&opc_ldc, &&opc_ldc_w, 1.567 +/* 0x14 */ &&opc_ldc2_w, &&opc_iload, &&opc_lload, &&opc_fload, 1.568 +/* 0x18 */ &&opc_dload, &&opc_aload, &&opc_iload_0,&&opc_iload_1, 1.569 +/* 0x1C */ &&opc_iload_2,&&opc_iload_3,&&opc_lload_0,&&opc_lload_1, 1.570 + 1.571 +/* 0x20 */ &&opc_lload_2,&&opc_lload_3,&&opc_fload_0,&&opc_fload_1, 1.572 +/* 0x24 */ &&opc_fload_2,&&opc_fload_3,&&opc_dload_0,&&opc_dload_1, 1.573 +/* 0x28 */ &&opc_dload_2,&&opc_dload_3,&&opc_aload_0,&&opc_aload_1, 1.574 +/* 0x2C */ &&opc_aload_2,&&opc_aload_3,&&opc_iaload, &&opc_laload, 1.575 + 1.576 +/* 0x30 */ &&opc_faload, &&opc_daload, &&opc_aaload, &&opc_baload, 1.577 +/* 0x34 */ &&opc_caload, &&opc_saload, &&opc_istore, &&opc_lstore, 1.578 +/* 0x38 */ &&opc_fstore, &&opc_dstore, &&opc_astore, &&opc_istore_0, 1.579 +/* 0x3C */ &&opc_istore_1,&&opc_istore_2,&&opc_istore_3,&&opc_lstore_0, 1.580 + 1.581 +/* 0x40 */ &&opc_lstore_1,&&opc_lstore_2,&&opc_lstore_3,&&opc_fstore_0, 1.582 +/* 0x44 */ &&opc_fstore_1,&&opc_fstore_2,&&opc_fstore_3,&&opc_dstore_0, 1.583 +/* 0x48 */ &&opc_dstore_1,&&opc_dstore_2,&&opc_dstore_3,&&opc_astore_0, 1.584 +/* 0x4C */ &&opc_astore_1,&&opc_astore_2,&&opc_astore_3,&&opc_iastore, 1.585 + 1.586 +/* 0x50 */ &&opc_lastore,&&opc_fastore,&&opc_dastore,&&opc_aastore, 1.587 +/* 0x54 */ &&opc_bastore,&&opc_castore,&&opc_sastore,&&opc_pop, 1.588 +/* 0x58 */ &&opc_pop2, &&opc_dup, &&opc_dup_x1, &&opc_dup_x2, 1.589 +/* 0x5C */ &&opc_dup2, &&opc_dup2_x1,&&opc_dup2_x2,&&opc_swap, 1.590 + 1.591 +/* 0x60 */ &&opc_iadd,&&opc_ladd,&&opc_fadd,&&opc_dadd, 1.592 +/* 0x64 */ &&opc_isub,&&opc_lsub,&&opc_fsub,&&opc_dsub, 1.593 +/* 0x68 */ &&opc_imul,&&opc_lmul,&&opc_fmul,&&opc_dmul, 1.594 +/* 0x6C */ &&opc_idiv,&&opc_ldiv,&&opc_fdiv,&&opc_ddiv, 1.595 + 1.596 +/* 0x70 */ &&opc_irem, &&opc_lrem, &&opc_frem,&&opc_drem, 1.597 +/* 0x74 */ &&opc_ineg, &&opc_lneg, &&opc_fneg,&&opc_dneg, 1.598 +/* 0x78 */ &&opc_ishl, &&opc_lshl, &&opc_ishr,&&opc_lshr, 1.599 +/* 0x7C */ &&opc_iushr,&&opc_lushr,&&opc_iand,&&opc_land, 1.600 + 1.601 +/* 0x80 */ &&opc_ior, &&opc_lor,&&opc_ixor,&&opc_lxor, 1.602 +/* 0x84 */ &&opc_iinc,&&opc_i2l,&&opc_i2f, &&opc_i2d, 1.603 +/* 0x88 */ &&opc_l2i, &&opc_l2f,&&opc_l2d, &&opc_f2i, 1.604 +/* 0x8C */ &&opc_f2l, &&opc_f2d,&&opc_d2i, &&opc_d2l, 1.605 + 1.606 +/* 0x90 */ &&opc_d2f, &&opc_i2b, &&opc_i2c, &&opc_i2s, 1.607 +/* 0x94 */ &&opc_lcmp, &&opc_fcmpl,&&opc_fcmpg,&&opc_dcmpl, 1.608 +/* 0x98 */ &&opc_dcmpg,&&opc_ifeq, &&opc_ifne, &&opc_iflt, 1.609 +/* 0x9C */ &&opc_ifge, &&opc_ifgt, &&opc_ifle, &&opc_if_icmpeq, 1.610 + 1.611 +/* 0xA0 */ &&opc_if_icmpne,&&opc_if_icmplt,&&opc_if_icmpge, &&opc_if_icmpgt, 1.612 +/* 0xA4 */ &&opc_if_icmple,&&opc_if_acmpeq,&&opc_if_acmpne, &&opc_goto, 1.613 +/* 0xA8 */ &&opc_jsr, &&opc_ret, &&opc_tableswitch,&&opc_lookupswitch, 1.614 +/* 0xAC */ &&opc_ireturn, &&opc_lreturn, &&opc_freturn, &&opc_dreturn, 1.615 + 1.616 +/* 0xB0 */ &&opc_areturn, &&opc_return, &&opc_getstatic, &&opc_putstatic, 1.617 +/* 0xB4 */ &&opc_getfield, &&opc_putfield, &&opc_invokevirtual,&&opc_invokespecial, 1.618 +/* 0xB8 */ &&opc_invokestatic,&&opc_invokeinterface,&&opc_invokedynamic,&&opc_new, 1.619 +/* 0xBC */ &&opc_newarray, &&opc_anewarray, &&opc_arraylength, &&opc_athrow, 1.620 + 1.621 +/* 0xC0 */ &&opc_checkcast, &&opc_instanceof, &&opc_monitorenter, &&opc_monitorexit, 1.622 +/* 0xC4 */ &&opc_wide, &&opc_multianewarray, &&opc_ifnull, &&opc_ifnonnull, 1.623 +/* 0xC8 */ &&opc_goto_w, &&opc_jsr_w, &&opc_breakpoint, &&opc_default, 1.624 +/* 0xCC */ &&opc_default, &&opc_default, &&opc_default, &&opc_default, 1.625 + 1.626 +/* 0xD0 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default, 1.627 +/* 0xD4 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default, 1.628 +/* 0xD8 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default, 1.629 +/* 0xDC */ &&opc_default, &&opc_default, &&opc_default, &&opc_default, 1.630 + 1.631 +/* 0xE0 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default, 1.632 +/* 0xE4 */ &&opc_default, &&opc_fast_aldc, &&opc_fast_aldc_w, &&opc_return_register_finalizer, 1.633 +/* 0xE8 */ &&opc_invokehandle,&&opc_default, &&opc_default, &&opc_default, 1.634 +/* 0xEC */ &&opc_default, &&opc_default, &&opc_default, &&opc_default, 1.635 + 1.636 +/* 0xF0 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default, 1.637 +/* 0xF4 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default, 1.638 +/* 0xF8 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default, 1.639 +/* 0xFC */ &&opc_default, &&opc_default, &&opc_default, &&opc_default 1.640 + }; 1.641 + register uintptr_t *dispatch_table = (uintptr_t*)&opclabels_data[0]; 1.642 +#endif /* USELABELS */ 1.643 + 1.644 +#ifdef ASSERT 1.645 + // this will trigger a VERIFY_OOP on entry 1.646 + if (istate->msg() != initialize && ! METHOD->is_static()) { 1.647 + oop rcvr = LOCALS_OBJECT(0); 1.648 + VERIFY_OOP(rcvr); 1.649 + } 1.650 +#endif 1.651 +// #define HACK 1.652 +#ifdef HACK 1.653 + bool interesting = false; 1.654 +#endif // HACK 1.655 + 1.656 + /* QQQ this should be a stack method so we don't know actual direction */ 1.657 + guarantee(istate->msg() == initialize || 1.658 + topOfStack >= istate->stack_limit() && 1.659 + topOfStack < istate->stack_base(), 1.660 + "Stack top out of range"); 1.661 + 1.662 +#ifdef CC_INTERP_PROFILE 1.663 + // MethodData's last branch taken count. 1.664 + uint mdo_last_branch_taken_count = 0; 1.665 +#else 1.666 + const uint mdo_last_branch_taken_count = 0; 1.667 +#endif 1.668 + 1.669 + switch (istate->msg()) { 1.670 + case initialize: { 1.671 + if (initialized++) ShouldNotReachHere(); // Only one initialize call. 1.672 + _compiling = (UseCompiler || CountCompiledCalls); 1.673 +#ifdef VM_JVMTI 1.674 + _jvmti_interp_events = JvmtiExport::can_post_interpreter_events(); 1.675 +#endif 1.676 + return; 1.677 + } 1.678 + break; 1.679 + case method_entry: { 1.680 + THREAD->set_do_not_unlock(); 1.681 + // count invocations 1.682 + assert(initialized, "Interpreter not initialized"); 1.683 + if (_compiling) { 1.684 + MethodCounters* mcs; 1.685 + GET_METHOD_COUNTERS(mcs); 1.686 + if (ProfileInterpreter) { 1.687 + METHOD->increment_interpreter_invocation_count(THREAD); 1.688 + } 1.689 + mcs->invocation_counter()->increment(); 1.690 + if (mcs->invocation_counter()->reached_InvocationLimit(mcs->backedge_counter())) { 1.691 + CALL_VM((void)InterpreterRuntime::frequency_counter_overflow(THREAD, NULL), handle_exception); 1.692 + // We no longer retry on a counter overflow. 1.693 + } 1.694 + // Get or create profile data. Check for pending (async) exceptions. 1.695 + BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception); 1.696 + SAFEPOINT; 1.697 + } 1.698 + 1.699 + if ((istate->_stack_base - istate->_stack_limit) != istate->method()->max_stack() + 1) { 1.700 + // initialize 1.701 + os::breakpoint(); 1.702 + } 1.703 + 1.704 +#ifdef HACK 1.705 + { 1.706 + ResourceMark rm; 1.707 + char *method_name = istate->method()->name_and_sig_as_C_string(); 1.708 + if (strstr(method_name, "runThese$TestRunner.run()V") != NULL) { 1.709 + tty->print_cr("entering: depth %d bci: %d", 1.710 + (istate->_stack_base - istate->_stack), 1.711 + istate->_bcp - istate->_method->code_base()); 1.712 + interesting = true; 1.713 + } 1.714 + } 1.715 +#endif // HACK 1.716 + 1.717 + // Lock method if synchronized. 1.718 + if (METHOD->is_synchronized()) { 1.719 + // oop rcvr = locals[0].j.r; 1.720 + oop rcvr; 1.721 + if (METHOD->is_static()) { 1.722 + rcvr = METHOD->constants()->pool_holder()->java_mirror(); 1.723 + } else { 1.724 + rcvr = LOCALS_OBJECT(0); 1.725 + VERIFY_OOP(rcvr); 1.726 + } 1.727 + // The initial monitor is ours for the taking. 1.728 + // Monitor not filled in frame manager any longer as this caused race condition with biased locking. 1.729 + BasicObjectLock* mon = &istate->monitor_base()[-1]; 1.730 + mon->set_obj(rcvr); 1.731 + bool success = false; 1.732 + uintptr_t epoch_mask_in_place = (uintptr_t)markOopDesc::epoch_mask_in_place; 1.733 + markOop mark = rcvr->mark(); 1.734 + intptr_t hash = (intptr_t) markOopDesc::no_hash; 1.735 + // Implies UseBiasedLocking. 1.736 + if (mark->has_bias_pattern()) { 1.737 + uintptr_t thread_ident; 1.738 + uintptr_t anticipated_bias_locking_value; 1.739 + thread_ident = (uintptr_t)istate->thread(); 1.740 + anticipated_bias_locking_value = 1.741 + (((uintptr_t)rcvr->klass()->prototype_header() | thread_ident) ^ (uintptr_t)mark) & 1.742 + ~((uintptr_t) markOopDesc::age_mask_in_place); 1.743 + 1.744 + if (anticipated_bias_locking_value == 0) { 1.745 + // Already biased towards this thread, nothing to do. 1.746 + if (PrintBiasedLockingStatistics) { 1.747 + (* BiasedLocking::biased_lock_entry_count_addr())++; 1.748 + } 1.749 + success = true; 1.750 + } else if ((anticipated_bias_locking_value & markOopDesc::biased_lock_mask_in_place) != 0) { 1.751 + // Try to revoke bias. 1.752 + markOop header = rcvr->klass()->prototype_header(); 1.753 + if (hash != markOopDesc::no_hash) { 1.754 + header = header->copy_set_hash(hash); 1.755 + } 1.756 + if (Atomic::cmpxchg_ptr(header, rcvr->mark_addr(), mark) == mark) { 1.757 + if (PrintBiasedLockingStatistics) 1.758 + (*BiasedLocking::revoked_lock_entry_count_addr())++; 1.759 + } 1.760 + } else if ((anticipated_bias_locking_value & epoch_mask_in_place) != 0) { 1.761 + // Try to rebias. 1.762 + markOop new_header = (markOop) ( (intptr_t) rcvr->klass()->prototype_header() | thread_ident); 1.763 + if (hash != markOopDesc::no_hash) { 1.764 + new_header = new_header->copy_set_hash(hash); 1.765 + } 1.766 + if (Atomic::cmpxchg_ptr((void*)new_header, rcvr->mark_addr(), mark) == mark) { 1.767 + if (PrintBiasedLockingStatistics) { 1.768 + (* BiasedLocking::rebiased_lock_entry_count_addr())++; 1.769 + } 1.770 + } else { 1.771 + CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception); 1.772 + } 1.773 + success = true; 1.774 + } else { 1.775 + // Try to bias towards thread in case object is anonymously biased. 1.776 + markOop header = (markOop) ((uintptr_t) mark & 1.777 + ((uintptr_t)markOopDesc::biased_lock_mask_in_place | 1.778 + (uintptr_t)markOopDesc::age_mask_in_place | epoch_mask_in_place)); 1.779 + if (hash != markOopDesc::no_hash) { 1.780 + header = header->copy_set_hash(hash); 1.781 + } 1.782 + markOop new_header = (markOop) ((uintptr_t) header | thread_ident); 1.783 + // Debugging hint. 1.784 + DEBUG_ONLY(mon->lock()->set_displaced_header((markOop) (uintptr_t) 0xdeaddead);) 1.785 + if (Atomic::cmpxchg_ptr((void*)new_header, rcvr->mark_addr(), header) == header) { 1.786 + if (PrintBiasedLockingStatistics) { 1.787 + (* BiasedLocking::anonymously_biased_lock_entry_count_addr())++; 1.788 + } 1.789 + } else { 1.790 + CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception); 1.791 + } 1.792 + success = true; 1.793 + } 1.794 + } 1.795 + 1.796 + // Traditional lightweight locking. 1.797 + if (!success) { 1.798 + markOop displaced = rcvr->mark()->set_unlocked(); 1.799 + mon->lock()->set_displaced_header(displaced); 1.800 + bool call_vm = UseHeavyMonitors; 1.801 + if (call_vm || Atomic::cmpxchg_ptr(mon, rcvr->mark_addr(), displaced) != displaced) { 1.802 + // Is it simple recursive case? 1.803 + if (!call_vm && THREAD->is_lock_owned((address) displaced->clear_lock_bits())) { 1.804 + mon->lock()->set_displaced_header(NULL); 1.805 + } else { 1.806 + CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception); 1.807 + } 1.808 + } 1.809 + } 1.810 + } 1.811 + THREAD->clr_do_not_unlock(); 1.812 + 1.813 + // Notify jvmti 1.814 +#ifdef VM_JVMTI 1.815 + if (_jvmti_interp_events) { 1.816 + // Whenever JVMTI puts a thread in interp_only_mode, method 1.817 + // entry/exit events are sent for that thread to track stack depth. 1.818 + if (THREAD->is_interp_only_mode()) { 1.819 + CALL_VM(InterpreterRuntime::post_method_entry(THREAD), 1.820 + handle_exception); 1.821 + } 1.822 + } 1.823 +#endif /* VM_JVMTI */ 1.824 + 1.825 + goto run; 1.826 + } 1.827 + 1.828 + case popping_frame: { 1.829 + // returned from a java call to pop the frame, restart the call 1.830 + // clear the message so we don't confuse ourselves later 1.831 + assert(THREAD->pop_frame_in_process(), "wrong frame pop state"); 1.832 + istate->set_msg(no_request); 1.833 + if (_compiling) { 1.834 + // Set MDX back to the ProfileData of the invoke bytecode that will be 1.835 + // restarted. 1.836 + SET_MDX(NULL); 1.837 + BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception); 1.838 + } 1.839 + THREAD->clr_pop_frame_in_process(); 1.840 + goto run; 1.841 + } 1.842 + 1.843 + case method_resume: { 1.844 + if ((istate->_stack_base - istate->_stack_limit) != istate->method()->max_stack() + 1) { 1.845 + // resume 1.846 + os::breakpoint(); 1.847 + } 1.848 +#ifdef HACK 1.849 + { 1.850 + ResourceMark rm; 1.851 + char *method_name = istate->method()->name_and_sig_as_C_string(); 1.852 + if (strstr(method_name, "runThese$TestRunner.run()V") != NULL) { 1.853 + tty->print_cr("resume: depth %d bci: %d", 1.854 + (istate->_stack_base - istate->_stack) , 1.855 + istate->_bcp - istate->_method->code_base()); 1.856 + interesting = true; 1.857 + } 1.858 + } 1.859 +#endif // HACK 1.860 + // returned from a java call, continue executing. 1.861 + if (THREAD->pop_frame_pending() && !THREAD->pop_frame_in_process()) { 1.862 + goto handle_Pop_Frame; 1.863 + } 1.864 + if (THREAD->jvmti_thread_state() && 1.865 + THREAD->jvmti_thread_state()->is_earlyret_pending()) { 1.866 + goto handle_Early_Return; 1.867 + } 1.868 + 1.869 + if (THREAD->has_pending_exception()) goto handle_exception; 1.870 + // Update the pc by the saved amount of the invoke bytecode size 1.871 + UPDATE_PC(istate->bcp_advance()); 1.872 + 1.873 + if (_compiling) { 1.874 + // Get or create profile data. Check for pending (async) exceptions. 1.875 + BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception); 1.876 + } 1.877 + goto run; 1.878 + } 1.879 + 1.880 + case deopt_resume2: { 1.881 + // Returned from an opcode that will reexecute. Deopt was 1.882 + // a result of a PopFrame request. 1.883 + // 1.884 + 1.885 + if (_compiling) { 1.886 + // Get or create profile data. Check for pending (async) exceptions. 1.887 + BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception); 1.888 + } 1.889 + goto run; 1.890 + } 1.891 + 1.892 + case deopt_resume: { 1.893 + // Returned from an opcode that has completed. The stack has 1.894 + // the result all we need to do is skip across the bytecode 1.895 + // and continue (assuming there is no exception pending) 1.896 + // 1.897 + // compute continuation length 1.898 + // 1.899 + // Note: it is possible to deopt at a return_register_finalizer opcode 1.900 + // because this requires entering the vm to do the registering. While the 1.901 + // opcode is complete we can't advance because there are no more opcodes 1.902 + // much like trying to deopt at a poll return. In that has we simply 1.903 + // get out of here 1.904 + // 1.905 + if ( Bytecodes::code_at(METHOD, pc) == Bytecodes::_return_register_finalizer) { 1.906 + // this will do the right thing even if an exception is pending. 1.907 + goto handle_return; 1.908 + } 1.909 + UPDATE_PC(Bytecodes::length_at(METHOD, pc)); 1.910 + if (THREAD->has_pending_exception()) goto handle_exception; 1.911 + 1.912 + if (_compiling) { 1.913 + // Get or create profile data. Check for pending (async) exceptions. 1.914 + BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception); 1.915 + } 1.916 + goto run; 1.917 + } 1.918 + case got_monitors: { 1.919 + // continue locking now that we have a monitor to use 1.920 + // we expect to find newly allocated monitor at the "top" of the monitor stack. 1.921 + oop lockee = STACK_OBJECT(-1); 1.922 + VERIFY_OOP(lockee); 1.923 + // derefing's lockee ought to provoke implicit null check 1.924 + // find a free monitor 1.925 + BasicObjectLock* entry = (BasicObjectLock*) istate->stack_base(); 1.926 + assert(entry->obj() == NULL, "Frame manager didn't allocate the monitor"); 1.927 + entry->set_obj(lockee); 1.928 + bool success = false; 1.929 + uintptr_t epoch_mask_in_place = (uintptr_t)markOopDesc::epoch_mask_in_place; 1.930 + 1.931 + markOop mark = lockee->mark(); 1.932 + intptr_t hash = (intptr_t) markOopDesc::no_hash; 1.933 + // implies UseBiasedLocking 1.934 + if (mark->has_bias_pattern()) { 1.935 + uintptr_t thread_ident; 1.936 + uintptr_t anticipated_bias_locking_value; 1.937 + thread_ident = (uintptr_t)istate->thread(); 1.938 + anticipated_bias_locking_value = 1.939 + (((uintptr_t)lockee->klass()->prototype_header() | thread_ident) ^ (uintptr_t)mark) & 1.940 + ~((uintptr_t) markOopDesc::age_mask_in_place); 1.941 + 1.942 + if (anticipated_bias_locking_value == 0) { 1.943 + // already biased towards this thread, nothing to do 1.944 + if (PrintBiasedLockingStatistics) { 1.945 + (* BiasedLocking::biased_lock_entry_count_addr())++; 1.946 + } 1.947 + success = true; 1.948 + } else if ((anticipated_bias_locking_value & markOopDesc::biased_lock_mask_in_place) != 0) { 1.949 + // try revoke bias 1.950 + markOop header = lockee->klass()->prototype_header(); 1.951 + if (hash != markOopDesc::no_hash) { 1.952 + header = header->copy_set_hash(hash); 1.953 + } 1.954 + if (Atomic::cmpxchg_ptr(header, lockee->mark_addr(), mark) == mark) { 1.955 + if (PrintBiasedLockingStatistics) { 1.956 + (*BiasedLocking::revoked_lock_entry_count_addr())++; 1.957 + } 1.958 + } 1.959 + } else if ((anticipated_bias_locking_value & epoch_mask_in_place) !=0) { 1.960 + // try rebias 1.961 + markOop new_header = (markOop) ( (intptr_t) lockee->klass()->prototype_header() | thread_ident); 1.962 + if (hash != markOopDesc::no_hash) { 1.963 + new_header = new_header->copy_set_hash(hash); 1.964 + } 1.965 + if (Atomic::cmpxchg_ptr((void*)new_header, lockee->mark_addr(), mark) == mark) { 1.966 + if (PrintBiasedLockingStatistics) { 1.967 + (* BiasedLocking::rebiased_lock_entry_count_addr())++; 1.968 + } 1.969 + } else { 1.970 + CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception); 1.971 + } 1.972 + success = true; 1.973 + } else { 1.974 + // try to bias towards thread in case object is anonymously biased 1.975 + markOop header = (markOop) ((uintptr_t) mark & ((uintptr_t)markOopDesc::biased_lock_mask_in_place | 1.976 + (uintptr_t)markOopDesc::age_mask_in_place | epoch_mask_in_place)); 1.977 + if (hash != markOopDesc::no_hash) { 1.978 + header = header->copy_set_hash(hash); 1.979 + } 1.980 + markOop new_header = (markOop) ((uintptr_t) header | thread_ident); 1.981 + // debugging hint 1.982 + DEBUG_ONLY(entry->lock()->set_displaced_header((markOop) (uintptr_t) 0xdeaddead);) 1.983 + if (Atomic::cmpxchg_ptr((void*)new_header, lockee->mark_addr(), header) == header) { 1.984 + if (PrintBiasedLockingStatistics) { 1.985 + (* BiasedLocking::anonymously_biased_lock_entry_count_addr())++; 1.986 + } 1.987 + } else { 1.988 + CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception); 1.989 + } 1.990 + success = true; 1.991 + } 1.992 + } 1.993 + 1.994 + // traditional lightweight locking 1.995 + if (!success) { 1.996 + markOop displaced = lockee->mark()->set_unlocked(); 1.997 + entry->lock()->set_displaced_header(displaced); 1.998 + bool call_vm = UseHeavyMonitors; 1.999 + if (call_vm || Atomic::cmpxchg_ptr(entry, lockee->mark_addr(), displaced) != displaced) { 1.1000 + // Is it simple recursive case? 1.1001 + if (!call_vm && THREAD->is_lock_owned((address) displaced->clear_lock_bits())) { 1.1002 + entry->lock()->set_displaced_header(NULL); 1.1003 + } else { 1.1004 + CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception); 1.1005 + } 1.1006 + } 1.1007 + } 1.1008 + UPDATE_PC_AND_TOS(1, -1); 1.1009 + goto run; 1.1010 + } 1.1011 + default: { 1.1012 + fatal("Unexpected message from frame manager"); 1.1013 + } 1.1014 + } 1.1015 + 1.1016 +run: 1.1017 + 1.1018 + DO_UPDATE_INSTRUCTION_COUNT(*pc) 1.1019 + DEBUGGER_SINGLE_STEP_NOTIFY(); 1.1020 +#ifdef PREFETCH_OPCCODE 1.1021 + opcode = *pc; /* prefetch first opcode */ 1.1022 +#endif 1.1023 + 1.1024 +#ifndef USELABELS 1.1025 + while (1) 1.1026 +#endif 1.1027 + { 1.1028 +#ifndef PREFETCH_OPCCODE 1.1029 + opcode = *pc; 1.1030 +#endif 1.1031 + // Seems like this happens twice per opcode. At worst this is only 1.1032 + // need at entry to the loop. 1.1033 + // DEBUGGER_SINGLE_STEP_NOTIFY(); 1.1034 + /* Using this labels avoids double breakpoints when quickening and 1.1035 + * when returing from transition frames. 1.1036 + */ 1.1037 + opcode_switch: 1.1038 + assert(istate == orig, "Corrupted istate"); 1.1039 + /* QQQ Hmm this has knowledge of direction, ought to be a stack method */ 1.1040 + assert(topOfStack >= istate->stack_limit(), "Stack overrun"); 1.1041 + assert(topOfStack < istate->stack_base(), "Stack underrun"); 1.1042 + 1.1043 +#ifdef USELABELS 1.1044 + DISPATCH(opcode); 1.1045 +#else 1.1046 + switch (opcode) 1.1047 +#endif 1.1048 + { 1.1049 + CASE(_nop): 1.1050 + UPDATE_PC_AND_CONTINUE(1); 1.1051 + 1.1052 + /* Push miscellaneous constants onto the stack. */ 1.1053 + 1.1054 + CASE(_aconst_null): 1.1055 + SET_STACK_OBJECT(NULL, 0); 1.1056 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1); 1.1057 + 1.1058 +#undef OPC_CONST_n 1.1059 +#define OPC_CONST_n(opcode, const_type, value) \ 1.1060 + CASE(opcode): \ 1.1061 + SET_STACK_ ## const_type(value, 0); \ 1.1062 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1); 1.1063 + 1.1064 + OPC_CONST_n(_iconst_m1, INT, -1); 1.1065 + OPC_CONST_n(_iconst_0, INT, 0); 1.1066 + OPC_CONST_n(_iconst_1, INT, 1); 1.1067 + OPC_CONST_n(_iconst_2, INT, 2); 1.1068 + OPC_CONST_n(_iconst_3, INT, 3); 1.1069 + OPC_CONST_n(_iconst_4, INT, 4); 1.1070 + OPC_CONST_n(_iconst_5, INT, 5); 1.1071 + OPC_CONST_n(_fconst_0, FLOAT, 0.0); 1.1072 + OPC_CONST_n(_fconst_1, FLOAT, 1.0); 1.1073 + OPC_CONST_n(_fconst_2, FLOAT, 2.0); 1.1074 + 1.1075 +#undef OPC_CONST2_n 1.1076 +#define OPC_CONST2_n(opcname, value, key, kind) \ 1.1077 + CASE(_##opcname): \ 1.1078 + { \ 1.1079 + SET_STACK_ ## kind(VM##key##Const##value(), 1); \ 1.1080 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2); \ 1.1081 + } 1.1082 + OPC_CONST2_n(dconst_0, Zero, double, DOUBLE); 1.1083 + OPC_CONST2_n(dconst_1, One, double, DOUBLE); 1.1084 + OPC_CONST2_n(lconst_0, Zero, long, LONG); 1.1085 + OPC_CONST2_n(lconst_1, One, long, LONG); 1.1086 + 1.1087 + /* Load constant from constant pool: */ 1.1088 + 1.1089 + /* Push a 1-byte signed integer value onto the stack. */ 1.1090 + CASE(_bipush): 1.1091 + SET_STACK_INT((jbyte)(pc[1]), 0); 1.1092 + UPDATE_PC_AND_TOS_AND_CONTINUE(2, 1); 1.1093 + 1.1094 + /* Push a 2-byte signed integer constant onto the stack. */ 1.1095 + CASE(_sipush): 1.1096 + SET_STACK_INT((int16_t)Bytes::get_Java_u2(pc + 1), 0); 1.1097 + UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1); 1.1098 + 1.1099 + /* load from local variable */ 1.1100 + 1.1101 + CASE(_aload): 1.1102 + VERIFY_OOP(LOCALS_OBJECT(pc[1])); 1.1103 + SET_STACK_OBJECT(LOCALS_OBJECT(pc[1]), 0); 1.1104 + UPDATE_PC_AND_TOS_AND_CONTINUE(2, 1); 1.1105 + 1.1106 + CASE(_iload): 1.1107 + CASE(_fload): 1.1108 + SET_STACK_SLOT(LOCALS_SLOT(pc[1]), 0); 1.1109 + UPDATE_PC_AND_TOS_AND_CONTINUE(2, 1); 1.1110 + 1.1111 + CASE(_lload): 1.1112 + SET_STACK_LONG_FROM_ADDR(LOCALS_LONG_AT(pc[1]), 1); 1.1113 + UPDATE_PC_AND_TOS_AND_CONTINUE(2, 2); 1.1114 + 1.1115 + CASE(_dload): 1.1116 + SET_STACK_DOUBLE_FROM_ADDR(LOCALS_DOUBLE_AT(pc[1]), 1); 1.1117 + UPDATE_PC_AND_TOS_AND_CONTINUE(2, 2); 1.1118 + 1.1119 +#undef OPC_LOAD_n 1.1120 +#define OPC_LOAD_n(num) \ 1.1121 + CASE(_aload_##num): \ 1.1122 + VERIFY_OOP(LOCALS_OBJECT(num)); \ 1.1123 + SET_STACK_OBJECT(LOCALS_OBJECT(num), 0); \ 1.1124 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1); \ 1.1125 + \ 1.1126 + CASE(_iload_##num): \ 1.1127 + CASE(_fload_##num): \ 1.1128 + SET_STACK_SLOT(LOCALS_SLOT(num), 0); \ 1.1129 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1); \ 1.1130 + \ 1.1131 + CASE(_lload_##num): \ 1.1132 + SET_STACK_LONG_FROM_ADDR(LOCALS_LONG_AT(num), 1); \ 1.1133 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2); \ 1.1134 + CASE(_dload_##num): \ 1.1135 + SET_STACK_DOUBLE_FROM_ADDR(LOCALS_DOUBLE_AT(num), 1); \ 1.1136 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2); 1.1137 + 1.1138 + OPC_LOAD_n(0); 1.1139 + OPC_LOAD_n(1); 1.1140 + OPC_LOAD_n(2); 1.1141 + OPC_LOAD_n(3); 1.1142 + 1.1143 + /* store to a local variable */ 1.1144 + 1.1145 + CASE(_astore): 1.1146 + astore(topOfStack, -1, locals, pc[1]); 1.1147 + UPDATE_PC_AND_TOS_AND_CONTINUE(2, -1); 1.1148 + 1.1149 + CASE(_istore): 1.1150 + CASE(_fstore): 1.1151 + SET_LOCALS_SLOT(STACK_SLOT(-1), pc[1]); 1.1152 + UPDATE_PC_AND_TOS_AND_CONTINUE(2, -1); 1.1153 + 1.1154 + CASE(_lstore): 1.1155 + SET_LOCALS_LONG(STACK_LONG(-1), pc[1]); 1.1156 + UPDATE_PC_AND_TOS_AND_CONTINUE(2, -2); 1.1157 + 1.1158 + CASE(_dstore): 1.1159 + SET_LOCALS_DOUBLE(STACK_DOUBLE(-1), pc[1]); 1.1160 + UPDATE_PC_AND_TOS_AND_CONTINUE(2, -2); 1.1161 + 1.1162 + CASE(_wide): { 1.1163 + uint16_t reg = Bytes::get_Java_u2(pc + 2); 1.1164 + 1.1165 + opcode = pc[1]; 1.1166 + 1.1167 + // Wide and it's sub-bytecode are counted as separate instructions. If we 1.1168 + // don't account for this here, the bytecode trace skips the next bytecode. 1.1169 + DO_UPDATE_INSTRUCTION_COUNT(opcode); 1.1170 + 1.1171 + switch(opcode) { 1.1172 + case Bytecodes::_aload: 1.1173 + VERIFY_OOP(LOCALS_OBJECT(reg)); 1.1174 + SET_STACK_OBJECT(LOCALS_OBJECT(reg), 0); 1.1175 + UPDATE_PC_AND_TOS_AND_CONTINUE(4, 1); 1.1176 + 1.1177 + case Bytecodes::_iload: 1.1178 + case Bytecodes::_fload: 1.1179 + SET_STACK_SLOT(LOCALS_SLOT(reg), 0); 1.1180 + UPDATE_PC_AND_TOS_AND_CONTINUE(4, 1); 1.1181 + 1.1182 + case Bytecodes::_lload: 1.1183 + SET_STACK_LONG_FROM_ADDR(LOCALS_LONG_AT(reg), 1); 1.1184 + UPDATE_PC_AND_TOS_AND_CONTINUE(4, 2); 1.1185 + 1.1186 + case Bytecodes::_dload: 1.1187 + SET_STACK_DOUBLE_FROM_ADDR(LOCALS_LONG_AT(reg), 1); 1.1188 + UPDATE_PC_AND_TOS_AND_CONTINUE(4, 2); 1.1189 + 1.1190 + case Bytecodes::_astore: 1.1191 + astore(topOfStack, -1, locals, reg); 1.1192 + UPDATE_PC_AND_TOS_AND_CONTINUE(4, -1); 1.1193 + 1.1194 + case Bytecodes::_istore: 1.1195 + case Bytecodes::_fstore: 1.1196 + SET_LOCALS_SLOT(STACK_SLOT(-1), reg); 1.1197 + UPDATE_PC_AND_TOS_AND_CONTINUE(4, -1); 1.1198 + 1.1199 + case Bytecodes::_lstore: 1.1200 + SET_LOCALS_LONG(STACK_LONG(-1), reg); 1.1201 + UPDATE_PC_AND_TOS_AND_CONTINUE(4, -2); 1.1202 + 1.1203 + case Bytecodes::_dstore: 1.1204 + SET_LOCALS_DOUBLE(STACK_DOUBLE(-1), reg); 1.1205 + UPDATE_PC_AND_TOS_AND_CONTINUE(4, -2); 1.1206 + 1.1207 + case Bytecodes::_iinc: { 1.1208 + int16_t offset = (int16_t)Bytes::get_Java_u2(pc+4); 1.1209 + // Be nice to see what this generates.... QQQ 1.1210 + SET_LOCALS_INT(LOCALS_INT(reg) + offset, reg); 1.1211 + UPDATE_PC_AND_CONTINUE(6); 1.1212 + } 1.1213 + case Bytecodes::_ret: 1.1214 + // Profile ret. 1.1215 + BI_PROFILE_UPDATE_RET(/*bci=*/((int)(intptr_t)(LOCALS_ADDR(reg)))); 1.1216 + // Now, update the pc. 1.1217 + pc = istate->method()->code_base() + (intptr_t)(LOCALS_ADDR(reg)); 1.1218 + UPDATE_PC_AND_CONTINUE(0); 1.1219 + default: 1.1220 + VM_JAVA_ERROR(vmSymbols::java_lang_InternalError(), "undefined opcode", note_no_trap); 1.1221 + } 1.1222 + } 1.1223 + 1.1224 + 1.1225 +#undef OPC_STORE_n 1.1226 +#define OPC_STORE_n(num) \ 1.1227 + CASE(_astore_##num): \ 1.1228 + astore(topOfStack, -1, locals, num); \ 1.1229 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); \ 1.1230 + CASE(_istore_##num): \ 1.1231 + CASE(_fstore_##num): \ 1.1232 + SET_LOCALS_SLOT(STACK_SLOT(-1), num); \ 1.1233 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); 1.1234 + 1.1235 + OPC_STORE_n(0); 1.1236 + OPC_STORE_n(1); 1.1237 + OPC_STORE_n(2); 1.1238 + OPC_STORE_n(3); 1.1239 + 1.1240 +#undef OPC_DSTORE_n 1.1241 +#define OPC_DSTORE_n(num) \ 1.1242 + CASE(_dstore_##num): \ 1.1243 + SET_LOCALS_DOUBLE(STACK_DOUBLE(-1), num); \ 1.1244 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2); \ 1.1245 + CASE(_lstore_##num): \ 1.1246 + SET_LOCALS_LONG(STACK_LONG(-1), num); \ 1.1247 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2); 1.1248 + 1.1249 + OPC_DSTORE_n(0); 1.1250 + OPC_DSTORE_n(1); 1.1251 + OPC_DSTORE_n(2); 1.1252 + OPC_DSTORE_n(3); 1.1253 + 1.1254 + /* stack pop, dup, and insert opcodes */ 1.1255 + 1.1256 + 1.1257 + CASE(_pop): /* Discard the top item on the stack */ 1.1258 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); 1.1259 + 1.1260 + 1.1261 + CASE(_pop2): /* Discard the top 2 items on the stack */ 1.1262 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2); 1.1263 + 1.1264 + 1.1265 + CASE(_dup): /* Duplicate the top item on the stack */ 1.1266 + dup(topOfStack); 1.1267 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1); 1.1268 + 1.1269 + CASE(_dup2): /* Duplicate the top 2 items on the stack */ 1.1270 + dup2(topOfStack); 1.1271 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2); 1.1272 + 1.1273 + CASE(_dup_x1): /* insert top word two down */ 1.1274 + dup_x1(topOfStack); 1.1275 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1); 1.1276 + 1.1277 + CASE(_dup_x2): /* insert top word three down */ 1.1278 + dup_x2(topOfStack); 1.1279 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1); 1.1280 + 1.1281 + CASE(_dup2_x1): /* insert top 2 slots three down */ 1.1282 + dup2_x1(topOfStack); 1.1283 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2); 1.1284 + 1.1285 + CASE(_dup2_x2): /* insert top 2 slots four down */ 1.1286 + dup2_x2(topOfStack); 1.1287 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2); 1.1288 + 1.1289 + CASE(_swap): { /* swap top two elements on the stack */ 1.1290 + swap(topOfStack); 1.1291 + UPDATE_PC_AND_CONTINUE(1); 1.1292 + } 1.1293 + 1.1294 + /* Perform various binary integer operations */ 1.1295 + 1.1296 +#undef OPC_INT_BINARY 1.1297 +#define OPC_INT_BINARY(opcname, opname, test) \ 1.1298 + CASE(_i##opcname): \ 1.1299 + if (test && (STACK_INT(-1) == 0)) { \ 1.1300 + VM_JAVA_ERROR(vmSymbols::java_lang_ArithmeticException(), \ 1.1301 + "/ by zero", note_div0Check_trap); \ 1.1302 + } \ 1.1303 + SET_STACK_INT(VMint##opname(STACK_INT(-2), \ 1.1304 + STACK_INT(-1)), \ 1.1305 + -2); \ 1.1306 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); \ 1.1307 + CASE(_l##opcname): \ 1.1308 + { \ 1.1309 + if (test) { \ 1.1310 + jlong l1 = STACK_LONG(-1); \ 1.1311 + if (VMlongEqz(l1)) { \ 1.1312 + VM_JAVA_ERROR(vmSymbols::java_lang_ArithmeticException(), \ 1.1313 + "/ by long zero", note_div0Check_trap); \ 1.1314 + } \ 1.1315 + } \ 1.1316 + /* First long at (-1,-2) next long at (-3,-4) */ \ 1.1317 + SET_STACK_LONG(VMlong##opname(STACK_LONG(-3), \ 1.1318 + STACK_LONG(-1)), \ 1.1319 + -3); \ 1.1320 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2); \ 1.1321 + } 1.1322 + 1.1323 + OPC_INT_BINARY(add, Add, 0); 1.1324 + OPC_INT_BINARY(sub, Sub, 0); 1.1325 + OPC_INT_BINARY(mul, Mul, 0); 1.1326 + OPC_INT_BINARY(and, And, 0); 1.1327 + OPC_INT_BINARY(or, Or, 0); 1.1328 + OPC_INT_BINARY(xor, Xor, 0); 1.1329 + OPC_INT_BINARY(div, Div, 1); 1.1330 + OPC_INT_BINARY(rem, Rem, 1); 1.1331 + 1.1332 + 1.1333 + /* Perform various binary floating number operations */ 1.1334 + /* On some machine/platforms/compilers div zero check can be implicit */ 1.1335 + 1.1336 +#undef OPC_FLOAT_BINARY 1.1337 +#define OPC_FLOAT_BINARY(opcname, opname) \ 1.1338 + CASE(_d##opcname): { \ 1.1339 + SET_STACK_DOUBLE(VMdouble##opname(STACK_DOUBLE(-3), \ 1.1340 + STACK_DOUBLE(-1)), \ 1.1341 + -3); \ 1.1342 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2); \ 1.1343 + } \ 1.1344 + CASE(_f##opcname): \ 1.1345 + SET_STACK_FLOAT(VMfloat##opname(STACK_FLOAT(-2), \ 1.1346 + STACK_FLOAT(-1)), \ 1.1347 + -2); \ 1.1348 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); 1.1349 + 1.1350 + 1.1351 + OPC_FLOAT_BINARY(add, Add); 1.1352 + OPC_FLOAT_BINARY(sub, Sub); 1.1353 + OPC_FLOAT_BINARY(mul, Mul); 1.1354 + OPC_FLOAT_BINARY(div, Div); 1.1355 + OPC_FLOAT_BINARY(rem, Rem); 1.1356 + 1.1357 + /* Shift operations 1.1358 + * Shift left int and long: ishl, lshl 1.1359 + * Logical shift right int and long w/zero extension: iushr, lushr 1.1360 + * Arithmetic shift right int and long w/sign extension: ishr, lshr 1.1361 + */ 1.1362 + 1.1363 +#undef OPC_SHIFT_BINARY 1.1364 +#define OPC_SHIFT_BINARY(opcname, opname) \ 1.1365 + CASE(_i##opcname): \ 1.1366 + SET_STACK_INT(VMint##opname(STACK_INT(-2), \ 1.1367 + STACK_INT(-1)), \ 1.1368 + -2); \ 1.1369 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); \ 1.1370 + CASE(_l##opcname): \ 1.1371 + { \ 1.1372 + SET_STACK_LONG(VMlong##opname(STACK_LONG(-2), \ 1.1373 + STACK_INT(-1)), \ 1.1374 + -2); \ 1.1375 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); \ 1.1376 + } 1.1377 + 1.1378 + OPC_SHIFT_BINARY(shl, Shl); 1.1379 + OPC_SHIFT_BINARY(shr, Shr); 1.1380 + OPC_SHIFT_BINARY(ushr, Ushr); 1.1381 + 1.1382 + /* Increment local variable by constant */ 1.1383 + CASE(_iinc): 1.1384 + { 1.1385 + // locals[pc[1]].j.i += (jbyte)(pc[2]); 1.1386 + SET_LOCALS_INT(LOCALS_INT(pc[1]) + (jbyte)(pc[2]), pc[1]); 1.1387 + UPDATE_PC_AND_CONTINUE(3); 1.1388 + } 1.1389 + 1.1390 + /* negate the value on the top of the stack */ 1.1391 + 1.1392 + CASE(_ineg): 1.1393 + SET_STACK_INT(VMintNeg(STACK_INT(-1)), -1); 1.1394 + UPDATE_PC_AND_CONTINUE(1); 1.1395 + 1.1396 + CASE(_fneg): 1.1397 + SET_STACK_FLOAT(VMfloatNeg(STACK_FLOAT(-1)), -1); 1.1398 + UPDATE_PC_AND_CONTINUE(1); 1.1399 + 1.1400 + CASE(_lneg): 1.1401 + { 1.1402 + SET_STACK_LONG(VMlongNeg(STACK_LONG(-1)), -1); 1.1403 + UPDATE_PC_AND_CONTINUE(1); 1.1404 + } 1.1405 + 1.1406 + CASE(_dneg): 1.1407 + { 1.1408 + SET_STACK_DOUBLE(VMdoubleNeg(STACK_DOUBLE(-1)), -1); 1.1409 + UPDATE_PC_AND_CONTINUE(1); 1.1410 + } 1.1411 + 1.1412 + /* Conversion operations */ 1.1413 + 1.1414 + CASE(_i2f): /* convert top of stack int to float */ 1.1415 + SET_STACK_FLOAT(VMint2Float(STACK_INT(-1)), -1); 1.1416 + UPDATE_PC_AND_CONTINUE(1); 1.1417 + 1.1418 + CASE(_i2l): /* convert top of stack int to long */ 1.1419 + { 1.1420 + // this is ugly QQQ 1.1421 + jlong r = VMint2Long(STACK_INT(-1)); 1.1422 + MORE_STACK(-1); // Pop 1.1423 + SET_STACK_LONG(r, 1); 1.1424 + 1.1425 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2); 1.1426 + } 1.1427 + 1.1428 + CASE(_i2d): /* convert top of stack int to double */ 1.1429 + { 1.1430 + // this is ugly QQQ (why cast to jlong?? ) 1.1431 + jdouble r = (jlong)STACK_INT(-1); 1.1432 + MORE_STACK(-1); // Pop 1.1433 + SET_STACK_DOUBLE(r, 1); 1.1434 + 1.1435 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2); 1.1436 + } 1.1437 + 1.1438 + CASE(_l2i): /* convert top of stack long to int */ 1.1439 + { 1.1440 + jint r = VMlong2Int(STACK_LONG(-1)); 1.1441 + MORE_STACK(-2); // Pop 1.1442 + SET_STACK_INT(r, 0); 1.1443 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1); 1.1444 + } 1.1445 + 1.1446 + CASE(_l2f): /* convert top of stack long to float */ 1.1447 + { 1.1448 + jlong r = STACK_LONG(-1); 1.1449 + MORE_STACK(-2); // Pop 1.1450 + SET_STACK_FLOAT(VMlong2Float(r), 0); 1.1451 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1); 1.1452 + } 1.1453 + 1.1454 + CASE(_l2d): /* convert top of stack long to double */ 1.1455 + { 1.1456 + jlong r = STACK_LONG(-1); 1.1457 + MORE_STACK(-2); // Pop 1.1458 + SET_STACK_DOUBLE(VMlong2Double(r), 1); 1.1459 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2); 1.1460 + } 1.1461 + 1.1462 + CASE(_f2i): /* Convert top of stack float to int */ 1.1463 + SET_STACK_INT(SharedRuntime::f2i(STACK_FLOAT(-1)), -1); 1.1464 + UPDATE_PC_AND_CONTINUE(1); 1.1465 + 1.1466 + CASE(_f2l): /* convert top of stack float to long */ 1.1467 + { 1.1468 + jlong r = SharedRuntime::f2l(STACK_FLOAT(-1)); 1.1469 + MORE_STACK(-1); // POP 1.1470 + SET_STACK_LONG(r, 1); 1.1471 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2); 1.1472 + } 1.1473 + 1.1474 + CASE(_f2d): /* convert top of stack float to double */ 1.1475 + { 1.1476 + jfloat f; 1.1477 + jdouble r; 1.1478 + f = STACK_FLOAT(-1); 1.1479 + r = (jdouble) f; 1.1480 + MORE_STACK(-1); // POP 1.1481 + SET_STACK_DOUBLE(r, 1); 1.1482 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2); 1.1483 + } 1.1484 + 1.1485 + CASE(_d2i): /* convert top of stack double to int */ 1.1486 + { 1.1487 + jint r1 = SharedRuntime::d2i(STACK_DOUBLE(-1)); 1.1488 + MORE_STACK(-2); 1.1489 + SET_STACK_INT(r1, 0); 1.1490 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1); 1.1491 + } 1.1492 + 1.1493 + CASE(_d2f): /* convert top of stack double to float */ 1.1494 + { 1.1495 + jfloat r1 = VMdouble2Float(STACK_DOUBLE(-1)); 1.1496 + MORE_STACK(-2); 1.1497 + SET_STACK_FLOAT(r1, 0); 1.1498 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1); 1.1499 + } 1.1500 + 1.1501 + CASE(_d2l): /* convert top of stack double to long */ 1.1502 + { 1.1503 + jlong r1 = SharedRuntime::d2l(STACK_DOUBLE(-1)); 1.1504 + MORE_STACK(-2); 1.1505 + SET_STACK_LONG(r1, 1); 1.1506 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2); 1.1507 + } 1.1508 + 1.1509 + CASE(_i2b): 1.1510 + SET_STACK_INT(VMint2Byte(STACK_INT(-1)), -1); 1.1511 + UPDATE_PC_AND_CONTINUE(1); 1.1512 + 1.1513 + CASE(_i2c): 1.1514 + SET_STACK_INT(VMint2Char(STACK_INT(-1)), -1); 1.1515 + UPDATE_PC_AND_CONTINUE(1); 1.1516 + 1.1517 + CASE(_i2s): 1.1518 + SET_STACK_INT(VMint2Short(STACK_INT(-1)), -1); 1.1519 + UPDATE_PC_AND_CONTINUE(1); 1.1520 + 1.1521 + /* comparison operators */ 1.1522 + 1.1523 + 1.1524 +#define COMPARISON_OP(name, comparison) \ 1.1525 + CASE(_if_icmp##name): { \ 1.1526 + const bool cmp = (STACK_INT(-2) comparison STACK_INT(-1)); \ 1.1527 + int skip = cmp \ 1.1528 + ? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \ 1.1529 + address branch_pc = pc; \ 1.1530 + /* Profile branch. */ \ 1.1531 + BI_PROFILE_UPDATE_BRANCH(/*is_taken=*/cmp); \ 1.1532 + UPDATE_PC_AND_TOS(skip, -2); \ 1.1533 + DO_BACKEDGE_CHECKS(skip, branch_pc); \ 1.1534 + CONTINUE; \ 1.1535 + } \ 1.1536 + CASE(_if##name): { \ 1.1537 + const bool cmp = (STACK_INT(-1) comparison 0); \ 1.1538 + int skip = cmp \ 1.1539 + ? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \ 1.1540 + address branch_pc = pc; \ 1.1541 + /* Profile branch. */ \ 1.1542 + BI_PROFILE_UPDATE_BRANCH(/*is_taken=*/cmp); \ 1.1543 + UPDATE_PC_AND_TOS(skip, -1); \ 1.1544 + DO_BACKEDGE_CHECKS(skip, branch_pc); \ 1.1545 + CONTINUE; \ 1.1546 + } 1.1547 + 1.1548 +#define COMPARISON_OP2(name, comparison) \ 1.1549 + COMPARISON_OP(name, comparison) \ 1.1550 + CASE(_if_acmp##name): { \ 1.1551 + const bool cmp = (STACK_OBJECT(-2) comparison STACK_OBJECT(-1)); \ 1.1552 + int skip = cmp \ 1.1553 + ? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \ 1.1554 + address branch_pc = pc; \ 1.1555 + /* Profile branch. */ \ 1.1556 + BI_PROFILE_UPDATE_BRANCH(/*is_taken=*/cmp); \ 1.1557 + UPDATE_PC_AND_TOS(skip, -2); \ 1.1558 + DO_BACKEDGE_CHECKS(skip, branch_pc); \ 1.1559 + CONTINUE; \ 1.1560 + } 1.1561 + 1.1562 +#define NULL_COMPARISON_NOT_OP(name) \ 1.1563 + CASE(_if##name): { \ 1.1564 + const bool cmp = (!(STACK_OBJECT(-1) == NULL)); \ 1.1565 + int skip = cmp \ 1.1566 + ? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \ 1.1567 + address branch_pc = pc; \ 1.1568 + /* Profile branch. */ \ 1.1569 + BI_PROFILE_UPDATE_BRANCH(/*is_taken=*/cmp); \ 1.1570 + UPDATE_PC_AND_TOS(skip, -1); \ 1.1571 + DO_BACKEDGE_CHECKS(skip, branch_pc); \ 1.1572 + CONTINUE; \ 1.1573 + } 1.1574 + 1.1575 +#define NULL_COMPARISON_OP(name) \ 1.1576 + CASE(_if##name): { \ 1.1577 + const bool cmp = ((STACK_OBJECT(-1) == NULL)); \ 1.1578 + int skip = cmp \ 1.1579 + ? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \ 1.1580 + address branch_pc = pc; \ 1.1581 + /* Profile branch. */ \ 1.1582 + BI_PROFILE_UPDATE_BRANCH(/*is_taken=*/cmp); \ 1.1583 + UPDATE_PC_AND_TOS(skip, -1); \ 1.1584 + DO_BACKEDGE_CHECKS(skip, branch_pc); \ 1.1585 + CONTINUE; \ 1.1586 + } 1.1587 + COMPARISON_OP(lt, <); 1.1588 + COMPARISON_OP(gt, >); 1.1589 + COMPARISON_OP(le, <=); 1.1590 + COMPARISON_OP(ge, >=); 1.1591 + COMPARISON_OP2(eq, ==); /* include ref comparison */ 1.1592 + COMPARISON_OP2(ne, !=); /* include ref comparison */ 1.1593 + NULL_COMPARISON_OP(null); 1.1594 + NULL_COMPARISON_NOT_OP(nonnull); 1.1595 + 1.1596 + /* Goto pc at specified offset in switch table. */ 1.1597 + 1.1598 + CASE(_tableswitch): { 1.1599 + jint* lpc = (jint*)VMalignWordUp(pc+1); 1.1600 + int32_t key = STACK_INT(-1); 1.1601 + int32_t low = Bytes::get_Java_u4((address)&lpc[1]); 1.1602 + int32_t high = Bytes::get_Java_u4((address)&lpc[2]); 1.1603 + int32_t skip; 1.1604 + key -= low; 1.1605 + if (((uint32_t) key > (uint32_t)(high - low))) { 1.1606 + key = -1; 1.1607 + skip = Bytes::get_Java_u4((address)&lpc[0]); 1.1608 + } else { 1.1609 + skip = Bytes::get_Java_u4((address)&lpc[key + 3]); 1.1610 + } 1.1611 + // Profile switch. 1.1612 + BI_PROFILE_UPDATE_SWITCH(/*switch_index=*/key); 1.1613 + // Does this really need a full backedge check (osr)? 1.1614 + address branch_pc = pc; 1.1615 + UPDATE_PC_AND_TOS(skip, -1); 1.1616 + DO_BACKEDGE_CHECKS(skip, branch_pc); 1.1617 + CONTINUE; 1.1618 + } 1.1619 + 1.1620 + /* Goto pc whose table entry matches specified key. */ 1.1621 + 1.1622 + CASE(_lookupswitch): { 1.1623 + jint* lpc = (jint*)VMalignWordUp(pc+1); 1.1624 + int32_t key = STACK_INT(-1); 1.1625 + int32_t skip = Bytes::get_Java_u4((address) lpc); /* default amount */ 1.1626 + // Remember index. 1.1627 + int index = -1; 1.1628 + int newindex = 0; 1.1629 + int32_t npairs = Bytes::get_Java_u4((address) &lpc[1]); 1.1630 + while (--npairs >= 0) { 1.1631 + lpc += 2; 1.1632 + if (key == (int32_t)Bytes::get_Java_u4((address)lpc)) { 1.1633 + skip = Bytes::get_Java_u4((address)&lpc[1]); 1.1634 + index = newindex; 1.1635 + break; 1.1636 + } 1.1637 + newindex += 1; 1.1638 + } 1.1639 + // Profile switch. 1.1640 + BI_PROFILE_UPDATE_SWITCH(/*switch_index=*/index); 1.1641 + address branch_pc = pc; 1.1642 + UPDATE_PC_AND_TOS(skip, -1); 1.1643 + DO_BACKEDGE_CHECKS(skip, branch_pc); 1.1644 + CONTINUE; 1.1645 + } 1.1646 + 1.1647 + CASE(_fcmpl): 1.1648 + CASE(_fcmpg): 1.1649 + { 1.1650 + SET_STACK_INT(VMfloatCompare(STACK_FLOAT(-2), 1.1651 + STACK_FLOAT(-1), 1.1652 + (opcode == Bytecodes::_fcmpl ? -1 : 1)), 1.1653 + -2); 1.1654 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); 1.1655 + } 1.1656 + 1.1657 + CASE(_dcmpl): 1.1658 + CASE(_dcmpg): 1.1659 + { 1.1660 + int r = VMdoubleCompare(STACK_DOUBLE(-3), 1.1661 + STACK_DOUBLE(-1), 1.1662 + (opcode == Bytecodes::_dcmpl ? -1 : 1)); 1.1663 + MORE_STACK(-4); // Pop 1.1664 + SET_STACK_INT(r, 0); 1.1665 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1); 1.1666 + } 1.1667 + 1.1668 + CASE(_lcmp): 1.1669 + { 1.1670 + int r = VMlongCompare(STACK_LONG(-3), STACK_LONG(-1)); 1.1671 + MORE_STACK(-4); 1.1672 + SET_STACK_INT(r, 0); 1.1673 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1); 1.1674 + } 1.1675 + 1.1676 + 1.1677 + /* Return from a method */ 1.1678 + 1.1679 + CASE(_areturn): 1.1680 + CASE(_ireturn): 1.1681 + CASE(_freturn): 1.1682 + { 1.1683 + // Allow a safepoint before returning to frame manager. 1.1684 + SAFEPOINT; 1.1685 + 1.1686 + goto handle_return; 1.1687 + } 1.1688 + 1.1689 + CASE(_lreturn): 1.1690 + CASE(_dreturn): 1.1691 + { 1.1692 + // Allow a safepoint before returning to frame manager. 1.1693 + SAFEPOINT; 1.1694 + goto handle_return; 1.1695 + } 1.1696 + 1.1697 + CASE(_return_register_finalizer): { 1.1698 + 1.1699 + oop rcvr = LOCALS_OBJECT(0); 1.1700 + VERIFY_OOP(rcvr); 1.1701 + if (rcvr->klass()->has_finalizer()) { 1.1702 + CALL_VM(InterpreterRuntime::register_finalizer(THREAD, rcvr), handle_exception); 1.1703 + } 1.1704 + goto handle_return; 1.1705 + } 1.1706 + CASE(_return): { 1.1707 + 1.1708 + // Allow a safepoint before returning to frame manager. 1.1709 + SAFEPOINT; 1.1710 + goto handle_return; 1.1711 + } 1.1712 + 1.1713 + /* Array access byte-codes */ 1.1714 + 1.1715 + /* Every array access byte-code starts out like this */ 1.1716 +// arrayOopDesc* arrObj = (arrayOopDesc*)STACK_OBJECT(arrayOff); 1.1717 +#define ARRAY_INTRO(arrayOff) \ 1.1718 + arrayOop arrObj = (arrayOop)STACK_OBJECT(arrayOff); \ 1.1719 + jint index = STACK_INT(arrayOff + 1); \ 1.1720 + char message[jintAsStringSize]; \ 1.1721 + CHECK_NULL(arrObj); \ 1.1722 + if ((uint32_t)index >= (uint32_t)arrObj->length()) { \ 1.1723 + sprintf(message, "%d", index); \ 1.1724 + VM_JAVA_ERROR(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), \ 1.1725 + message, note_rangeCheck_trap); \ 1.1726 + } 1.1727 + 1.1728 + /* 32-bit loads. These handle conversion from < 32-bit types */ 1.1729 +#define ARRAY_LOADTO32(T, T2, format, stackRes, extra) \ 1.1730 + { \ 1.1731 + ARRAY_INTRO(-2); \ 1.1732 + (void)extra; \ 1.1733 + SET_ ## stackRes(*(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)), \ 1.1734 + -2); \ 1.1735 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); \ 1.1736 + } 1.1737 + 1.1738 + /* 64-bit loads */ 1.1739 +#define ARRAY_LOADTO64(T,T2, stackRes, extra) \ 1.1740 + { \ 1.1741 + ARRAY_INTRO(-2); \ 1.1742 + SET_ ## stackRes(*(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)), -1); \ 1.1743 + (void)extra; \ 1.1744 + UPDATE_PC_AND_CONTINUE(1); \ 1.1745 + } 1.1746 + 1.1747 + CASE(_iaload): 1.1748 + ARRAY_LOADTO32(T_INT, jint, "%d", STACK_INT, 0); 1.1749 + CASE(_faload): 1.1750 + ARRAY_LOADTO32(T_FLOAT, jfloat, "%f", STACK_FLOAT, 0); 1.1751 + CASE(_aaload): { 1.1752 + ARRAY_INTRO(-2); 1.1753 + SET_STACK_OBJECT(((objArrayOop) arrObj)->obj_at(index), -2); 1.1754 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); 1.1755 + } 1.1756 + CASE(_baload): 1.1757 + ARRAY_LOADTO32(T_BYTE, jbyte, "%d", STACK_INT, 0); 1.1758 + CASE(_caload): 1.1759 + ARRAY_LOADTO32(T_CHAR, jchar, "%d", STACK_INT, 0); 1.1760 + CASE(_saload): 1.1761 + ARRAY_LOADTO32(T_SHORT, jshort, "%d", STACK_INT, 0); 1.1762 + CASE(_laload): 1.1763 + ARRAY_LOADTO64(T_LONG, jlong, STACK_LONG, 0); 1.1764 + CASE(_daload): 1.1765 + ARRAY_LOADTO64(T_DOUBLE, jdouble, STACK_DOUBLE, 0); 1.1766 + 1.1767 + /* 32-bit stores. These handle conversion to < 32-bit types */ 1.1768 +#define ARRAY_STOREFROM32(T, T2, format, stackSrc, extra) \ 1.1769 + { \ 1.1770 + ARRAY_INTRO(-3); \ 1.1771 + (void)extra; \ 1.1772 + *(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)) = stackSrc( -1); \ 1.1773 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, -3); \ 1.1774 + } 1.1775 + 1.1776 + /* 64-bit stores */ 1.1777 +#define ARRAY_STOREFROM64(T, T2, stackSrc, extra) \ 1.1778 + { \ 1.1779 + ARRAY_INTRO(-4); \ 1.1780 + (void)extra; \ 1.1781 + *(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)) = stackSrc( -1); \ 1.1782 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, -4); \ 1.1783 + } 1.1784 + 1.1785 + CASE(_iastore): 1.1786 + ARRAY_STOREFROM32(T_INT, jint, "%d", STACK_INT, 0); 1.1787 + CASE(_fastore): 1.1788 + ARRAY_STOREFROM32(T_FLOAT, jfloat, "%f", STACK_FLOAT, 0); 1.1789 + /* 1.1790 + * This one looks different because of the assignability check 1.1791 + */ 1.1792 + CASE(_aastore): { 1.1793 + oop rhsObject = STACK_OBJECT(-1); 1.1794 + VERIFY_OOP(rhsObject); 1.1795 + ARRAY_INTRO( -3); 1.1796 + // arrObj, index are set 1.1797 + if (rhsObject != NULL) { 1.1798 + /* Check assignability of rhsObject into arrObj */ 1.1799 + Klass* rhsKlass = rhsObject->klass(); // EBX (subclass) 1.1800 + Klass* elemKlass = ObjArrayKlass::cast(arrObj->klass())->element_klass(); // superklass EAX 1.1801 + // 1.1802 + // Check for compatibilty. This check must not GC!! 1.1803 + // Seems way more expensive now that we must dispatch 1.1804 + // 1.1805 + if (rhsKlass != elemKlass && !rhsKlass->is_subtype_of(elemKlass)) { // ebx->is... 1.1806 + // Decrement counter if subtype check failed. 1.1807 + BI_PROFILE_SUBTYPECHECK_FAILED(rhsKlass); 1.1808 + VM_JAVA_ERROR(vmSymbols::java_lang_ArrayStoreException(), "", note_arrayCheck_trap); 1.1809 + } 1.1810 + // Profile checkcast with null_seen and receiver. 1.1811 + BI_PROFILE_UPDATE_CHECKCAST(/*null_seen=*/false, rhsKlass); 1.1812 + } else { 1.1813 + // Profile checkcast with null_seen and receiver. 1.1814 + BI_PROFILE_UPDATE_CHECKCAST(/*null_seen=*/true, NULL); 1.1815 + } 1.1816 + ((objArrayOop) arrObj)->obj_at_put(index, rhsObject); 1.1817 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, -3); 1.1818 + } 1.1819 + CASE(_bastore): 1.1820 + ARRAY_STOREFROM32(T_BYTE, jbyte, "%d", STACK_INT, 0); 1.1821 + CASE(_castore): 1.1822 + ARRAY_STOREFROM32(T_CHAR, jchar, "%d", STACK_INT, 0); 1.1823 + CASE(_sastore): 1.1824 + ARRAY_STOREFROM32(T_SHORT, jshort, "%d", STACK_INT, 0); 1.1825 + CASE(_lastore): 1.1826 + ARRAY_STOREFROM64(T_LONG, jlong, STACK_LONG, 0); 1.1827 + CASE(_dastore): 1.1828 + ARRAY_STOREFROM64(T_DOUBLE, jdouble, STACK_DOUBLE, 0); 1.1829 + 1.1830 + CASE(_arraylength): 1.1831 + { 1.1832 + arrayOop ary = (arrayOop) STACK_OBJECT(-1); 1.1833 + CHECK_NULL(ary); 1.1834 + SET_STACK_INT(ary->length(), -1); 1.1835 + UPDATE_PC_AND_CONTINUE(1); 1.1836 + } 1.1837 + 1.1838 + /* monitorenter and monitorexit for locking/unlocking an object */ 1.1839 + 1.1840 + CASE(_monitorenter): { 1.1841 + oop lockee = STACK_OBJECT(-1); 1.1842 + // derefing's lockee ought to provoke implicit null check 1.1843 + CHECK_NULL(lockee); 1.1844 + // find a free monitor or one already allocated for this object 1.1845 + // if we find a matching object then we need a new monitor 1.1846 + // since this is recursive enter 1.1847 + BasicObjectLock* limit = istate->monitor_base(); 1.1848 + BasicObjectLock* most_recent = (BasicObjectLock*) istate->stack_base(); 1.1849 + BasicObjectLock* entry = NULL; 1.1850 + while (most_recent != limit ) { 1.1851 + if (most_recent->obj() == NULL) entry = most_recent; 1.1852 + else if (most_recent->obj() == lockee) break; 1.1853 + most_recent++; 1.1854 + } 1.1855 + if (entry != NULL) { 1.1856 + entry->set_obj(lockee); 1.1857 + int success = false; 1.1858 + uintptr_t epoch_mask_in_place = (uintptr_t)markOopDesc::epoch_mask_in_place; 1.1859 + 1.1860 + markOop mark = lockee->mark(); 1.1861 + intptr_t hash = (intptr_t) markOopDesc::no_hash; 1.1862 + // implies UseBiasedLocking 1.1863 + if (mark->has_bias_pattern()) { 1.1864 + uintptr_t thread_ident; 1.1865 + uintptr_t anticipated_bias_locking_value; 1.1866 + thread_ident = (uintptr_t)istate->thread(); 1.1867 + anticipated_bias_locking_value = 1.1868 + (((uintptr_t)lockee->klass()->prototype_header() | thread_ident) ^ (uintptr_t)mark) & 1.1869 + ~((uintptr_t) markOopDesc::age_mask_in_place); 1.1870 + 1.1871 + if (anticipated_bias_locking_value == 0) { 1.1872 + // already biased towards this thread, nothing to do 1.1873 + if (PrintBiasedLockingStatistics) { 1.1874 + (* BiasedLocking::biased_lock_entry_count_addr())++; 1.1875 + } 1.1876 + success = true; 1.1877 + } 1.1878 + else if ((anticipated_bias_locking_value & markOopDesc::biased_lock_mask_in_place) != 0) { 1.1879 + // try revoke bias 1.1880 + markOop header = lockee->klass()->prototype_header(); 1.1881 + if (hash != markOopDesc::no_hash) { 1.1882 + header = header->copy_set_hash(hash); 1.1883 + } 1.1884 + if (Atomic::cmpxchg_ptr(header, lockee->mark_addr(), mark) == mark) { 1.1885 + if (PrintBiasedLockingStatistics) 1.1886 + (*BiasedLocking::revoked_lock_entry_count_addr())++; 1.1887 + } 1.1888 + } 1.1889 + else if ((anticipated_bias_locking_value & epoch_mask_in_place) !=0) { 1.1890 + // try rebias 1.1891 + markOop new_header = (markOop) ( (intptr_t) lockee->klass()->prototype_header() | thread_ident); 1.1892 + if (hash != markOopDesc::no_hash) { 1.1893 + new_header = new_header->copy_set_hash(hash); 1.1894 + } 1.1895 + if (Atomic::cmpxchg_ptr((void*)new_header, lockee->mark_addr(), mark) == mark) { 1.1896 + if (PrintBiasedLockingStatistics) 1.1897 + (* BiasedLocking::rebiased_lock_entry_count_addr())++; 1.1898 + } 1.1899 + else { 1.1900 + CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception); 1.1901 + } 1.1902 + success = true; 1.1903 + } 1.1904 + else { 1.1905 + // try to bias towards thread in case object is anonymously biased 1.1906 + markOop header = (markOop) ((uintptr_t) mark & ((uintptr_t)markOopDesc::biased_lock_mask_in_place | 1.1907 + (uintptr_t)markOopDesc::age_mask_in_place | 1.1908 + epoch_mask_in_place)); 1.1909 + if (hash != markOopDesc::no_hash) { 1.1910 + header = header->copy_set_hash(hash); 1.1911 + } 1.1912 + markOop new_header = (markOop) ((uintptr_t) header | thread_ident); 1.1913 + // debugging hint 1.1914 + DEBUG_ONLY(entry->lock()->set_displaced_header((markOop) (uintptr_t) 0xdeaddead);) 1.1915 + if (Atomic::cmpxchg_ptr((void*)new_header, lockee->mark_addr(), header) == header) { 1.1916 + if (PrintBiasedLockingStatistics) 1.1917 + (* BiasedLocking::anonymously_biased_lock_entry_count_addr())++; 1.1918 + } 1.1919 + else { 1.1920 + CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception); 1.1921 + } 1.1922 + success = true; 1.1923 + } 1.1924 + } 1.1925 + 1.1926 + // traditional lightweight locking 1.1927 + if (!success) { 1.1928 + markOop displaced = lockee->mark()->set_unlocked(); 1.1929 + entry->lock()->set_displaced_header(displaced); 1.1930 + bool call_vm = UseHeavyMonitors; 1.1931 + if (call_vm || Atomic::cmpxchg_ptr(entry, lockee->mark_addr(), displaced) != displaced) { 1.1932 + // Is it simple recursive case? 1.1933 + if (!call_vm && THREAD->is_lock_owned((address) displaced->clear_lock_bits())) { 1.1934 + entry->lock()->set_displaced_header(NULL); 1.1935 + } else { 1.1936 + CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception); 1.1937 + } 1.1938 + } 1.1939 + } 1.1940 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); 1.1941 + } else { 1.1942 + istate->set_msg(more_monitors); 1.1943 + UPDATE_PC_AND_RETURN(0); // Re-execute 1.1944 + } 1.1945 + } 1.1946 + 1.1947 + CASE(_monitorexit): { 1.1948 + oop lockee = STACK_OBJECT(-1); 1.1949 + CHECK_NULL(lockee); 1.1950 + // derefing's lockee ought to provoke implicit null check 1.1951 + // find our monitor slot 1.1952 + BasicObjectLock* limit = istate->monitor_base(); 1.1953 + BasicObjectLock* most_recent = (BasicObjectLock*) istate->stack_base(); 1.1954 + while (most_recent != limit ) { 1.1955 + if ((most_recent)->obj() == lockee) { 1.1956 + BasicLock* lock = most_recent->lock(); 1.1957 + markOop header = lock->displaced_header(); 1.1958 + most_recent->set_obj(NULL); 1.1959 + if (!lockee->mark()->has_bias_pattern()) { 1.1960 + bool call_vm = UseHeavyMonitors; 1.1961 + // If it isn't recursive we either must swap old header or call the runtime 1.1962 + if (header != NULL || call_vm) { 1.1963 + if (call_vm || Atomic::cmpxchg_ptr(header, lockee->mark_addr(), lock) != lock) { 1.1964 + // restore object for the slow case 1.1965 + most_recent->set_obj(lockee); 1.1966 + CALL_VM(InterpreterRuntime::monitorexit(THREAD, most_recent), handle_exception); 1.1967 + } 1.1968 + } 1.1969 + } 1.1970 + UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); 1.1971 + } 1.1972 + most_recent++; 1.1973 + } 1.1974 + // Need to throw illegal monitor state exception 1.1975 + CALL_VM(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD), handle_exception); 1.1976 + ShouldNotReachHere(); 1.1977 + } 1.1978 + 1.1979 + /* All of the non-quick opcodes. */ 1.1980 + 1.1981 + /* -Set clobbersCpIndex true if the quickened opcode clobbers the 1.1982 + * constant pool index in the instruction. 1.1983 + */ 1.1984 + CASE(_getfield): 1.1985 + CASE(_getstatic): 1.1986 + { 1.1987 + u2 index; 1.1988 + ConstantPoolCacheEntry* cache; 1.1989 + index = Bytes::get_native_u2(pc+1); 1.1990 + 1.1991 + // QQQ Need to make this as inlined as possible. Probably need to 1.1992 + // split all the bytecode cases out so c++ compiler has a chance 1.1993 + // for constant prop to fold everything possible away. 1.1994 + 1.1995 + cache = cp->entry_at(index); 1.1996 + if (!cache->is_resolved((Bytecodes::Code)opcode)) { 1.1997 + CALL_VM(InterpreterRuntime::resolve_get_put(THREAD, (Bytecodes::Code)opcode), 1.1998 + handle_exception); 1.1999 + cache = cp->entry_at(index); 1.2000 + } 1.2001 + 1.2002 +#ifdef VM_JVMTI 1.2003 + if (_jvmti_interp_events) { 1.2004 + int *count_addr; 1.2005 + oop obj; 1.2006 + // Check to see if a field modification watch has been set 1.2007 + // before we take the time to call into the VM. 1.2008 + count_addr = (int *)JvmtiExport::get_field_access_count_addr(); 1.2009 + if ( *count_addr > 0 ) { 1.2010 + if ((Bytecodes::Code)opcode == Bytecodes::_getstatic) { 1.2011 + obj = (oop)NULL; 1.2012 + } else { 1.2013 + obj = (oop) STACK_OBJECT(-1); 1.2014 + VERIFY_OOP(obj); 1.2015 + } 1.2016 + CALL_VM(InterpreterRuntime::post_field_access(THREAD, 1.2017 + obj, 1.2018 + cache), 1.2019 + handle_exception); 1.2020 + } 1.2021 + } 1.2022 +#endif /* VM_JVMTI */ 1.2023 + 1.2024 + oop obj; 1.2025 + if ((Bytecodes::Code)opcode == Bytecodes::_getstatic) { 1.2026 + Klass* k = cache->f1_as_klass(); 1.2027 + obj = k->java_mirror(); 1.2028 + MORE_STACK(1); // Assume single slot push 1.2029 + } else { 1.2030 + obj = (oop) STACK_OBJECT(-1); 1.2031 + CHECK_NULL(obj); 1.2032 + } 1.2033 + 1.2034 + // 1.2035 + // Now store the result on the stack 1.2036 + // 1.2037 + TosState tos_type = cache->flag_state(); 1.2038 + int field_offset = cache->f2_as_index(); 1.2039 + if (cache->is_volatile()) { 1.2040 + if (support_IRIW_for_not_multiple_copy_atomic_cpu) { 1.2041 + OrderAccess::fence(); 1.2042 + } 1.2043 + if (tos_type == atos) { 1.2044 + VERIFY_OOP(obj->obj_field_acquire(field_offset)); 1.2045 + SET_STACK_OBJECT(obj->obj_field_acquire(field_offset), -1); 1.2046 + } else if (tos_type == itos) { 1.2047 + SET_STACK_INT(obj->int_field_acquire(field_offset), -1); 1.2048 + } else if (tos_type == ltos) { 1.2049 + SET_STACK_LONG(obj->long_field_acquire(field_offset), 0); 1.2050 + MORE_STACK(1); 1.2051 + } else if (tos_type == btos) { 1.2052 + SET_STACK_INT(obj->byte_field_acquire(field_offset), -1); 1.2053 + } else if (tos_type == ctos) { 1.2054 + SET_STACK_INT(obj->char_field_acquire(field_offset), -1); 1.2055 + } else if (tos_type == stos) { 1.2056 + SET_STACK_INT(obj->short_field_acquire(field_offset), -1); 1.2057 + } else if (tos_type == ftos) { 1.2058 + SET_STACK_FLOAT(obj->float_field_acquire(field_offset), -1); 1.2059 + } else { 1.2060 + SET_STACK_DOUBLE(obj->double_field_acquire(field_offset), 0); 1.2061 + MORE_STACK(1); 1.2062 + } 1.2063 + } else { 1.2064 + if (tos_type == atos) { 1.2065 + VERIFY_OOP(obj->obj_field(field_offset)); 1.2066 + SET_STACK_OBJECT(obj->obj_field(field_offset), -1); 1.2067 + } else if (tos_type == itos) { 1.2068 + SET_STACK_INT(obj->int_field(field_offset), -1); 1.2069 + } else if (tos_type == ltos) { 1.2070 + SET_STACK_LONG(obj->long_field(field_offset), 0); 1.2071 + MORE_STACK(1); 1.2072 + } else if (tos_type == btos) { 1.2073 + SET_STACK_INT(obj->byte_field(field_offset), -1); 1.2074 + } else if (tos_type == ctos) { 1.2075 + SET_STACK_INT(obj->char_field(field_offset), -1); 1.2076 + } else if (tos_type == stos) { 1.2077 + SET_STACK_INT(obj->short_field(field_offset), -1); 1.2078 + } else if (tos_type == ftos) { 1.2079 + SET_STACK_FLOAT(obj->float_field(field_offset), -1); 1.2080 + } else { 1.2081 + SET_STACK_DOUBLE(obj->double_field(field_offset), 0); 1.2082 + MORE_STACK(1); 1.2083 + } 1.2084 + } 1.2085 + 1.2086 + UPDATE_PC_AND_CONTINUE(3); 1.2087 + } 1.2088 + 1.2089 + CASE(_putfield): 1.2090 + CASE(_putstatic): 1.2091 + { 1.2092 + u2 index = Bytes::get_native_u2(pc+1); 1.2093 + ConstantPoolCacheEntry* cache = cp->entry_at(index); 1.2094 + if (!cache->is_resolved((Bytecodes::Code)opcode)) { 1.2095 + CALL_VM(InterpreterRuntime::resolve_get_put(THREAD, (Bytecodes::Code)opcode), 1.2096 + handle_exception); 1.2097 + cache = cp->entry_at(index); 1.2098 + } 1.2099 + 1.2100 +#ifdef VM_JVMTI 1.2101 + if (_jvmti_interp_events) { 1.2102 + int *count_addr; 1.2103 + oop obj; 1.2104 + // Check to see if a field modification watch has been set 1.2105 + // before we take the time to call into the VM. 1.2106 + count_addr = (int *)JvmtiExport::get_field_modification_count_addr(); 1.2107 + if ( *count_addr > 0 ) { 1.2108 + if ((Bytecodes::Code)opcode == Bytecodes::_putstatic) { 1.2109 + obj = (oop)NULL; 1.2110 + } 1.2111 + else { 1.2112 + if (cache->is_long() || cache->is_double()) { 1.2113 + obj = (oop) STACK_OBJECT(-3); 1.2114 + } else { 1.2115 + obj = (oop) STACK_OBJECT(-2); 1.2116 + } 1.2117 + VERIFY_OOP(obj); 1.2118 + } 1.2119 + 1.2120 + CALL_VM(InterpreterRuntime::post_field_modification(THREAD, 1.2121 + obj, 1.2122 + cache, 1.2123 + (jvalue *)STACK_SLOT(-1)), 1.2124 + handle_exception); 1.2125 + } 1.2126 + } 1.2127 +#endif /* VM_JVMTI */ 1.2128 + 1.2129 + // QQQ Need to make this as inlined as possible. Probably need to split all the bytecode cases 1.2130 + // out so c++ compiler has a chance for constant prop to fold everything possible away. 1.2131 + 1.2132 + oop obj; 1.2133 + int count; 1.2134 + TosState tos_type = cache->flag_state(); 1.2135 + 1.2136 + count = -1; 1.2137 + if (tos_type == ltos || tos_type == dtos) { 1.2138 + --count; 1.2139 + } 1.2140 + if ((Bytecodes::Code)opcode == Bytecodes::_putstatic) { 1.2141 + Klass* k = cache->f1_as_klass(); 1.2142 + obj = k->java_mirror(); 1.2143 + } else { 1.2144 + --count; 1.2145 + obj = (oop) STACK_OBJECT(count); 1.2146 + CHECK_NULL(obj); 1.2147 + } 1.2148 + 1.2149 + // 1.2150 + // Now store the result 1.2151 + // 1.2152 + int field_offset = cache->f2_as_index(); 1.2153 + if (cache->is_volatile()) { 1.2154 + if (tos_type == itos) { 1.2155 + obj->release_int_field_put(field_offset, STACK_INT(-1)); 1.2156 + } else if (tos_type == atos) { 1.2157 + VERIFY_OOP(STACK_OBJECT(-1)); 1.2158 + obj->release_obj_field_put(field_offset, STACK_OBJECT(-1)); 1.2159 + } else if (tos_type == btos) { 1.2160 + obj->release_byte_field_put(field_offset, STACK_INT(-1)); 1.2161 + } else if (tos_type == ltos) { 1.2162 + obj->release_long_field_put(field_offset, STACK_LONG(-1)); 1.2163 + } else if (tos_type == ctos) { 1.2164 + obj->release_char_field_put(field_offset, STACK_INT(-1)); 1.2165 + } else if (tos_type == stos) { 1.2166 + obj->release_short_field_put(field_offset, STACK_INT(-1)); 1.2167 + } else if (tos_type == ftos) { 1.2168 + obj->release_float_field_put(field_offset, STACK_FLOAT(-1)); 1.2169 + } else { 1.2170 + obj->release_double_field_put(field_offset, STACK_DOUBLE(-1)); 1.2171 + } 1.2172 + OrderAccess::storeload(); 1.2173 + } else { 1.2174 + if (tos_type == itos) { 1.2175 + obj->int_field_put(field_offset, STACK_INT(-1)); 1.2176 + } else if (tos_type == atos) { 1.2177 + VERIFY_OOP(STACK_OBJECT(-1)); 1.2178 + obj->obj_field_put(field_offset, STACK_OBJECT(-1)); 1.2179 + } else if (tos_type == btos) { 1.2180 + obj->byte_field_put(field_offset, STACK_INT(-1)); 1.2181 + } else if (tos_type == ltos) { 1.2182 + obj->long_field_put(field_offset, STACK_LONG(-1)); 1.2183 + } else if (tos_type == ctos) { 1.2184 + obj->char_field_put(field_offset, STACK_INT(-1)); 1.2185 + } else if (tos_type == stos) { 1.2186 + obj->short_field_put(field_offset, STACK_INT(-1)); 1.2187 + } else if (tos_type == ftos) { 1.2188 + obj->float_field_put(field_offset, STACK_FLOAT(-1)); 1.2189 + } else { 1.2190 + obj->double_field_put(field_offset, STACK_DOUBLE(-1)); 1.2191 + } 1.2192 + } 1.2193 + 1.2194 + UPDATE_PC_AND_TOS_AND_CONTINUE(3, count); 1.2195 + } 1.2196 + 1.2197 + CASE(_new): { 1.2198 + u2 index = Bytes::get_Java_u2(pc+1); 1.2199 + ConstantPool* constants = istate->method()->constants(); 1.2200 + if (!constants->tag_at(index).is_unresolved_klass()) { 1.2201 + // Make sure klass is initialized and doesn't have a finalizer 1.2202 + Klass* entry = constants->slot_at(index).get_klass(); 1.2203 + assert(entry->is_klass(), "Should be resolved klass"); 1.2204 + Klass* k_entry = (Klass*) entry; 1.2205 + assert(k_entry->oop_is_instance(), "Should be InstanceKlass"); 1.2206 + InstanceKlass* ik = (InstanceKlass*) k_entry; 1.2207 + if ( ik->is_initialized() && ik->can_be_fastpath_allocated() ) { 1.2208 + size_t obj_size = ik->size_helper(); 1.2209 + oop result = NULL; 1.2210 + // If the TLAB isn't pre-zeroed then we'll have to do it 1.2211 + bool need_zero = !ZeroTLAB; 1.2212 + if (UseTLAB) { 1.2213 + result = (oop) THREAD->tlab().allocate(obj_size); 1.2214 + } 1.2215 + // Disable non-TLAB-based fast-path, because profiling requires that all 1.2216 + // allocations go through InterpreterRuntime::_new() if THREAD->tlab().allocate 1.2217 + // returns NULL. 1.2218 +#ifndef CC_INTERP_PROFILE 1.2219 + if (result == NULL) { 1.2220 + need_zero = true; 1.2221 + // Try allocate in shared eden 1.2222 + retry: 1.2223 + HeapWord* compare_to = *Universe::heap()->top_addr(); 1.2224 + HeapWord* new_top = compare_to + obj_size; 1.2225 + if (new_top <= *Universe::heap()->end_addr()) { 1.2226 + if (Atomic::cmpxchg_ptr(new_top, Universe::heap()->top_addr(), compare_to) != compare_to) { 1.2227 + goto retry; 1.2228 + } 1.2229 + result = (oop) compare_to; 1.2230 + } 1.2231 + } 1.2232 +#endif 1.2233 + if (result != NULL) { 1.2234 + // Initialize object (if nonzero size and need) and then the header 1.2235 + if (need_zero ) { 1.2236 + HeapWord* to_zero = (HeapWord*) result + sizeof(oopDesc) / oopSize; 1.2237 + obj_size -= sizeof(oopDesc) / oopSize; 1.2238 + if (obj_size > 0 ) { 1.2239 + memset(to_zero, 0, obj_size * HeapWordSize); 1.2240 + } 1.2241 + } 1.2242 + if (UseBiasedLocking) { 1.2243 + result->set_mark(ik->prototype_header()); 1.2244 + } else { 1.2245 + result->set_mark(markOopDesc::prototype()); 1.2246 + } 1.2247 + result->set_klass_gap(0); 1.2248 + result->set_klass(k_entry); 1.2249 + // Must prevent reordering of stores for object initialization 1.2250 + // with stores that publish the new object. 1.2251 + OrderAccess::storestore(); 1.2252 + SET_STACK_OBJECT(result, 0); 1.2253 + UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1); 1.2254 + } 1.2255 + } 1.2256 + } 1.2257 + // Slow case allocation 1.2258 + CALL_VM(InterpreterRuntime::_new(THREAD, METHOD->constants(), index), 1.2259 + handle_exception); 1.2260 + // Must prevent reordering of stores for object initialization 1.2261 + // with stores that publish the new object. 1.2262 + OrderAccess::storestore(); 1.2263 + SET_STACK_OBJECT(THREAD->vm_result(), 0); 1.2264 + THREAD->set_vm_result(NULL); 1.2265 + UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1); 1.2266 + } 1.2267 + CASE(_anewarray): { 1.2268 + u2 index = Bytes::get_Java_u2(pc+1); 1.2269 + jint size = STACK_INT(-1); 1.2270 + CALL_VM(InterpreterRuntime::anewarray(THREAD, METHOD->constants(), index, size), 1.2271 + handle_exception); 1.2272 + // Must prevent reordering of stores for object initialization 1.2273 + // with stores that publish the new object. 1.2274 + OrderAccess::storestore(); 1.2275 + SET_STACK_OBJECT(THREAD->vm_result(), -1); 1.2276 + THREAD->set_vm_result(NULL); 1.2277 + UPDATE_PC_AND_CONTINUE(3); 1.2278 + } 1.2279 + CASE(_multianewarray): { 1.2280 + jint dims = *(pc+3); 1.2281 + jint size = STACK_INT(-1); 1.2282 + // stack grows down, dimensions are up! 1.2283 + jint *dimarray = 1.2284 + (jint*)&topOfStack[dims * Interpreter::stackElementWords+ 1.2285 + Interpreter::stackElementWords-1]; 1.2286 + //adjust pointer to start of stack element 1.2287 + CALL_VM(InterpreterRuntime::multianewarray(THREAD, dimarray), 1.2288 + handle_exception); 1.2289 + // Must prevent reordering of stores for object initialization 1.2290 + // with stores that publish the new object. 1.2291 + OrderAccess::storestore(); 1.2292 + SET_STACK_OBJECT(THREAD->vm_result(), -dims); 1.2293 + THREAD->set_vm_result(NULL); 1.2294 + UPDATE_PC_AND_TOS_AND_CONTINUE(4, -(dims-1)); 1.2295 + } 1.2296 + CASE(_checkcast): 1.2297 + if (STACK_OBJECT(-1) != NULL) { 1.2298 + VERIFY_OOP(STACK_OBJECT(-1)); 1.2299 + u2 index = Bytes::get_Java_u2(pc+1); 1.2300 + // Constant pool may have actual klass or unresolved klass. If it is 1.2301 + // unresolved we must resolve it. 1.2302 + if (METHOD->constants()->tag_at(index).is_unresolved_klass()) { 1.2303 + CALL_VM(InterpreterRuntime::quicken_io_cc(THREAD), handle_exception); 1.2304 + } 1.2305 + Klass* klassOf = (Klass*) METHOD->constants()->slot_at(index).get_klass(); 1.2306 + Klass* objKlass = STACK_OBJECT(-1)->klass(); // ebx 1.2307 + // 1.2308 + // Check for compatibilty. This check must not GC!! 1.2309 + // Seems way more expensive now that we must dispatch. 1.2310 + // 1.2311 + if (objKlass != klassOf && !objKlass->is_subtype_of(klassOf)) { 1.2312 + // Decrement counter at checkcast. 1.2313 + BI_PROFILE_SUBTYPECHECK_FAILED(objKlass); 1.2314 + ResourceMark rm(THREAD); 1.2315 + const char* objName = objKlass->external_name(); 1.2316 + const char* klassName = klassOf->external_name(); 1.2317 + char* message = SharedRuntime::generate_class_cast_message( 1.2318 + objName, klassName); 1.2319 + VM_JAVA_ERROR(vmSymbols::java_lang_ClassCastException(), message, note_classCheck_trap); 1.2320 + } 1.2321 + // Profile checkcast with null_seen and receiver. 1.2322 + BI_PROFILE_UPDATE_CHECKCAST(/*null_seen=*/false, objKlass); 1.2323 + } else { 1.2324 + // Profile checkcast with null_seen and receiver. 1.2325 + BI_PROFILE_UPDATE_CHECKCAST(/*null_seen=*/true, NULL); 1.2326 + } 1.2327 + UPDATE_PC_AND_CONTINUE(3); 1.2328 + 1.2329 + CASE(_instanceof): 1.2330 + if (STACK_OBJECT(-1) == NULL) { 1.2331 + SET_STACK_INT(0, -1); 1.2332 + // Profile instanceof with null_seen and receiver. 1.2333 + BI_PROFILE_UPDATE_INSTANCEOF(/*null_seen=*/true, NULL); 1.2334 + } else { 1.2335 + VERIFY_OOP(STACK_OBJECT(-1)); 1.2336 + u2 index = Bytes::get_Java_u2(pc+1); 1.2337 + // Constant pool may have actual klass or unresolved klass. If it is 1.2338 + // unresolved we must resolve it. 1.2339 + if (METHOD->constants()->tag_at(index).is_unresolved_klass()) { 1.2340 + CALL_VM(InterpreterRuntime::quicken_io_cc(THREAD), handle_exception); 1.2341 + } 1.2342 + Klass* klassOf = (Klass*) METHOD->constants()->slot_at(index).get_klass(); 1.2343 + Klass* objKlass = STACK_OBJECT(-1)->klass(); 1.2344 + // 1.2345 + // Check for compatibilty. This check must not GC!! 1.2346 + // Seems way more expensive now that we must dispatch. 1.2347 + // 1.2348 + if ( objKlass == klassOf || objKlass->is_subtype_of(klassOf)) { 1.2349 + SET_STACK_INT(1, -1); 1.2350 + } else { 1.2351 + SET_STACK_INT(0, -1); 1.2352 + // Decrement counter at checkcast. 1.2353 + BI_PROFILE_SUBTYPECHECK_FAILED(objKlass); 1.2354 + } 1.2355 + // Profile instanceof with null_seen and receiver. 1.2356 + BI_PROFILE_UPDATE_INSTANCEOF(/*null_seen=*/false, objKlass); 1.2357 + } 1.2358 + UPDATE_PC_AND_CONTINUE(3); 1.2359 + 1.2360 + CASE(_ldc_w): 1.2361 + CASE(_ldc): 1.2362 + { 1.2363 + u2 index; 1.2364 + bool wide = false; 1.2365 + int incr = 2; // frequent case 1.2366 + if (opcode == Bytecodes::_ldc) { 1.2367 + index = pc[1]; 1.2368 + } else { 1.2369 + index = Bytes::get_Java_u2(pc+1); 1.2370 + incr = 3; 1.2371 + wide = true; 1.2372 + } 1.2373 + 1.2374 + ConstantPool* constants = METHOD->constants(); 1.2375 + switch (constants->tag_at(index).value()) { 1.2376 + case JVM_CONSTANT_Integer: 1.2377 + SET_STACK_INT(constants->int_at(index), 0); 1.2378 + break; 1.2379 + 1.2380 + case JVM_CONSTANT_Float: 1.2381 + SET_STACK_FLOAT(constants->float_at(index), 0); 1.2382 + break; 1.2383 + 1.2384 + case JVM_CONSTANT_String: 1.2385 + { 1.2386 + oop result = constants->resolved_references()->obj_at(index); 1.2387 + if (result == NULL) { 1.2388 + CALL_VM(InterpreterRuntime::resolve_ldc(THREAD, (Bytecodes::Code) opcode), handle_exception); 1.2389 + SET_STACK_OBJECT(THREAD->vm_result(), 0); 1.2390 + THREAD->set_vm_result(NULL); 1.2391 + } else { 1.2392 + VERIFY_OOP(result); 1.2393 + SET_STACK_OBJECT(result, 0); 1.2394 + } 1.2395 + break; 1.2396 + } 1.2397 + 1.2398 + case JVM_CONSTANT_Class: 1.2399 + VERIFY_OOP(constants->resolved_klass_at(index)->java_mirror()); 1.2400 + SET_STACK_OBJECT(constants->resolved_klass_at(index)->java_mirror(), 0); 1.2401 + break; 1.2402 + 1.2403 + case JVM_CONSTANT_UnresolvedClass: 1.2404 + case JVM_CONSTANT_UnresolvedClassInError: 1.2405 + CALL_VM(InterpreterRuntime::ldc(THREAD, wide), handle_exception); 1.2406 + SET_STACK_OBJECT(THREAD->vm_result(), 0); 1.2407 + THREAD->set_vm_result(NULL); 1.2408 + break; 1.2409 + 1.2410 + default: ShouldNotReachHere(); 1.2411 + } 1.2412 + UPDATE_PC_AND_TOS_AND_CONTINUE(incr, 1); 1.2413 + } 1.2414 + 1.2415 + CASE(_ldc2_w): 1.2416 + { 1.2417 + u2 index = Bytes::get_Java_u2(pc+1); 1.2418 + 1.2419 + ConstantPool* constants = METHOD->constants(); 1.2420 + switch (constants->tag_at(index).value()) { 1.2421 + 1.2422 + case JVM_CONSTANT_Long: 1.2423 + SET_STACK_LONG(constants->long_at(index), 1); 1.2424 + break; 1.2425 + 1.2426 + case JVM_CONSTANT_Double: 1.2427 + SET_STACK_DOUBLE(constants->double_at(index), 1); 1.2428 + break; 1.2429 + default: ShouldNotReachHere(); 1.2430 + } 1.2431 + UPDATE_PC_AND_TOS_AND_CONTINUE(3, 2); 1.2432 + } 1.2433 + 1.2434 + CASE(_fast_aldc_w): 1.2435 + CASE(_fast_aldc): { 1.2436 + u2 index; 1.2437 + int incr; 1.2438 + if (opcode == Bytecodes::_fast_aldc) { 1.2439 + index = pc[1]; 1.2440 + incr = 2; 1.2441 + } else { 1.2442 + index = Bytes::get_native_u2(pc+1); 1.2443 + incr = 3; 1.2444 + } 1.2445 + 1.2446 + // We are resolved if the f1 field contains a non-null object (CallSite, etc.) 1.2447 + // This kind of CP cache entry does not need to match the flags byte, because 1.2448 + // there is a 1-1 relation between bytecode type and CP entry type. 1.2449 + ConstantPool* constants = METHOD->constants(); 1.2450 + oop result = constants->resolved_references()->obj_at(index); 1.2451 + if (result == NULL) { 1.2452 + CALL_VM(InterpreterRuntime::resolve_ldc(THREAD, (Bytecodes::Code) opcode), 1.2453 + handle_exception); 1.2454 + result = THREAD->vm_result(); 1.2455 + } 1.2456 + 1.2457 + VERIFY_OOP(result); 1.2458 + SET_STACK_OBJECT(result, 0); 1.2459 + UPDATE_PC_AND_TOS_AND_CONTINUE(incr, 1); 1.2460 + } 1.2461 + 1.2462 + CASE(_invokedynamic): { 1.2463 + 1.2464 + if (!EnableInvokeDynamic) { 1.2465 + // We should not encounter this bytecode if !EnableInvokeDynamic. 1.2466 + // The verifier will stop it. However, if we get past the verifier, 1.2467 + // this will stop the thread in a reasonable way, without crashing the JVM. 1.2468 + CALL_VM(InterpreterRuntime::throw_IncompatibleClassChangeError(THREAD), 1.2469 + handle_exception); 1.2470 + ShouldNotReachHere(); 1.2471 + } 1.2472 + 1.2473 + u4 index = Bytes::get_native_u4(pc+1); 1.2474 + ConstantPoolCacheEntry* cache = cp->constant_pool()->invokedynamic_cp_cache_entry_at(index); 1.2475 + 1.2476 + // We are resolved if the resolved_references field contains a non-null object (CallSite, etc.) 1.2477 + // This kind of CP cache entry does not need to match the flags byte, because 1.2478 + // there is a 1-1 relation between bytecode type and CP entry type. 1.2479 + if (! cache->is_resolved((Bytecodes::Code) opcode)) { 1.2480 + CALL_VM(InterpreterRuntime::resolve_invokedynamic(THREAD), 1.2481 + handle_exception); 1.2482 + cache = cp->constant_pool()->invokedynamic_cp_cache_entry_at(index); 1.2483 + } 1.2484 + 1.2485 + Method* method = cache->f1_as_method(); 1.2486 + if (VerifyOops) method->verify(); 1.2487 + 1.2488 + if (cache->has_appendix()) { 1.2489 + ConstantPool* constants = METHOD->constants(); 1.2490 + SET_STACK_OBJECT(cache->appendix_if_resolved(constants), 0); 1.2491 + MORE_STACK(1); 1.2492 + } 1.2493 + 1.2494 + istate->set_msg(call_method); 1.2495 + istate->set_callee(method); 1.2496 + istate->set_callee_entry_point(method->from_interpreted_entry()); 1.2497 + istate->set_bcp_advance(5); 1.2498 + 1.2499 + // Invokedynamic has got a call counter, just like an invokestatic -> increment! 1.2500 + BI_PROFILE_UPDATE_CALL(); 1.2501 + 1.2502 + UPDATE_PC_AND_RETURN(0); // I'll be back... 1.2503 + } 1.2504 + 1.2505 + CASE(_invokehandle): { 1.2506 + 1.2507 + if (!EnableInvokeDynamic) { 1.2508 + ShouldNotReachHere(); 1.2509 + } 1.2510 + 1.2511 + u2 index = Bytes::get_native_u2(pc+1); 1.2512 + ConstantPoolCacheEntry* cache = cp->entry_at(index); 1.2513 + 1.2514 + if (! cache->is_resolved((Bytecodes::Code) opcode)) { 1.2515 + CALL_VM(InterpreterRuntime::resolve_invokehandle(THREAD), 1.2516 + handle_exception); 1.2517 + cache = cp->entry_at(index); 1.2518 + } 1.2519 + 1.2520 + Method* method = cache->f1_as_method(); 1.2521 + if (VerifyOops) method->verify(); 1.2522 + 1.2523 + if (cache->has_appendix()) { 1.2524 + ConstantPool* constants = METHOD->constants(); 1.2525 + SET_STACK_OBJECT(cache->appendix_if_resolved(constants), 0); 1.2526 + MORE_STACK(1); 1.2527 + } 1.2528 + 1.2529 + istate->set_msg(call_method); 1.2530 + istate->set_callee(method); 1.2531 + istate->set_callee_entry_point(method->from_interpreted_entry()); 1.2532 + istate->set_bcp_advance(3); 1.2533 + 1.2534 + // Invokehandle has got a call counter, just like a final call -> increment! 1.2535 + BI_PROFILE_UPDATE_FINALCALL(); 1.2536 + 1.2537 + UPDATE_PC_AND_RETURN(0); // I'll be back... 1.2538 + } 1.2539 + 1.2540 + CASE(_invokeinterface): { 1.2541 + u2 index = Bytes::get_native_u2(pc+1); 1.2542 + 1.2543 + // QQQ Need to make this as inlined as possible. Probably need to split all the bytecode cases 1.2544 + // out so c++ compiler has a chance for constant prop to fold everything possible away. 1.2545 + 1.2546 + ConstantPoolCacheEntry* cache = cp->entry_at(index); 1.2547 + if (!cache->is_resolved((Bytecodes::Code)opcode)) { 1.2548 + CALL_VM(InterpreterRuntime::resolve_invoke(THREAD, (Bytecodes::Code)opcode), 1.2549 + handle_exception); 1.2550 + cache = cp->entry_at(index); 1.2551 + } 1.2552 + 1.2553 + istate->set_msg(call_method); 1.2554 + 1.2555 + // Special case of invokeinterface called for virtual method of 1.2556 + // java.lang.Object. See cpCacheOop.cpp for details. 1.2557 + // This code isn't produced by javac, but could be produced by 1.2558 + // another compliant java compiler. 1.2559 + if (cache->is_forced_virtual()) { 1.2560 + Method* callee; 1.2561 + CHECK_NULL(STACK_OBJECT(-(cache->parameter_size()))); 1.2562 + if (cache->is_vfinal()) { 1.2563 + callee = cache->f2_as_vfinal_method(); 1.2564 + // Profile 'special case of invokeinterface' final call. 1.2565 + BI_PROFILE_UPDATE_FINALCALL(); 1.2566 + } else { 1.2567 + // Get receiver. 1.2568 + int parms = cache->parameter_size(); 1.2569 + // Same comments as invokevirtual apply here. 1.2570 + oop rcvr = STACK_OBJECT(-parms); 1.2571 + VERIFY_OOP(rcvr); 1.2572 + InstanceKlass* rcvrKlass = (InstanceKlass*)rcvr->klass(); 1.2573 + callee = (Method*) rcvrKlass->start_of_vtable()[ cache->f2_as_index()]; 1.2574 + // Profile 'special case of invokeinterface' virtual call. 1.2575 + BI_PROFILE_UPDATE_VIRTUALCALL(rcvr->klass()); 1.2576 + } 1.2577 + istate->set_callee(callee); 1.2578 + istate->set_callee_entry_point(callee->from_interpreted_entry()); 1.2579 +#ifdef VM_JVMTI 1.2580 + if (JvmtiExport::can_post_interpreter_events() && THREAD->is_interp_only_mode()) { 1.2581 + istate->set_callee_entry_point(callee->interpreter_entry()); 1.2582 + } 1.2583 +#endif /* VM_JVMTI */ 1.2584 + istate->set_bcp_advance(5); 1.2585 + UPDATE_PC_AND_RETURN(0); // I'll be back... 1.2586 + } 1.2587 + 1.2588 + // this could definitely be cleaned up QQQ 1.2589 + Method* callee; 1.2590 + Klass* iclass = cache->f1_as_klass(); 1.2591 + // InstanceKlass* interface = (InstanceKlass*) iclass; 1.2592 + // get receiver 1.2593 + int parms = cache->parameter_size(); 1.2594 + oop rcvr = STACK_OBJECT(-parms); 1.2595 + CHECK_NULL(rcvr); 1.2596 + InstanceKlass* int2 = (InstanceKlass*) rcvr->klass(); 1.2597 + itableOffsetEntry* ki = (itableOffsetEntry*) int2->start_of_itable(); 1.2598 + int i; 1.2599 + for ( i = 0 ; i < int2->itable_length() ; i++, ki++ ) { 1.2600 + if (ki->interface_klass() == iclass) break; 1.2601 + } 1.2602 + // If the interface isn't found, this class doesn't implement this 1.2603 + // interface. The link resolver checks this but only for the first 1.2604 + // time this interface is called. 1.2605 + if (i == int2->itable_length()) { 1.2606 + VM_JAVA_ERROR(vmSymbols::java_lang_IncompatibleClassChangeError(), "", note_no_trap); 1.2607 + } 1.2608 + int mindex = cache->f2_as_index(); 1.2609 + itableMethodEntry* im = ki->first_method_entry(rcvr->klass()); 1.2610 + callee = im[mindex].method(); 1.2611 + if (callee == NULL) { 1.2612 + VM_JAVA_ERROR(vmSymbols::java_lang_AbstractMethodError(), "", note_no_trap); 1.2613 + } 1.2614 + 1.2615 + // Profile virtual call. 1.2616 + BI_PROFILE_UPDATE_VIRTUALCALL(rcvr->klass()); 1.2617 + 1.2618 + istate->set_callee(callee); 1.2619 + istate->set_callee_entry_point(callee->from_interpreted_entry()); 1.2620 +#ifdef VM_JVMTI 1.2621 + if (JvmtiExport::can_post_interpreter_events() && THREAD->is_interp_only_mode()) { 1.2622 + istate->set_callee_entry_point(callee->interpreter_entry()); 1.2623 + } 1.2624 +#endif /* VM_JVMTI */ 1.2625 + istate->set_bcp_advance(5); 1.2626 + UPDATE_PC_AND_RETURN(0); // I'll be back... 1.2627 + } 1.2628 + 1.2629 + CASE(_invokevirtual): 1.2630 + CASE(_invokespecial): 1.2631 + CASE(_invokestatic): { 1.2632 + u2 index = Bytes::get_native_u2(pc+1); 1.2633 + 1.2634 + ConstantPoolCacheEntry* cache = cp->entry_at(index); 1.2635 + // QQQ Need to make this as inlined as possible. Probably need to split all the bytecode cases 1.2636 + // out so c++ compiler has a chance for constant prop to fold everything possible away. 1.2637 + 1.2638 + if (!cache->is_resolved((Bytecodes::Code)opcode)) { 1.2639 + CALL_VM(InterpreterRuntime::resolve_invoke(THREAD, (Bytecodes::Code)opcode), 1.2640 + handle_exception); 1.2641 + cache = cp->entry_at(index); 1.2642 + } 1.2643 + 1.2644 + istate->set_msg(call_method); 1.2645 + { 1.2646 + Method* callee; 1.2647 + if ((Bytecodes::Code)opcode == Bytecodes::_invokevirtual) { 1.2648 + CHECK_NULL(STACK_OBJECT(-(cache->parameter_size()))); 1.2649 + if (cache->is_vfinal()) { 1.2650 + callee = cache->f2_as_vfinal_method(); 1.2651 + // Profile final call. 1.2652 + BI_PROFILE_UPDATE_FINALCALL(); 1.2653 + } else { 1.2654 + // get receiver 1.2655 + int parms = cache->parameter_size(); 1.2656 + // this works but needs a resourcemark and seems to create a vtable on every call: 1.2657 + // Method* callee = rcvr->klass()->vtable()->method_at(cache->f2_as_index()); 1.2658 + // 1.2659 + // this fails with an assert 1.2660 + // InstanceKlass* rcvrKlass = InstanceKlass::cast(STACK_OBJECT(-parms)->klass()); 1.2661 + // but this works 1.2662 + oop rcvr = STACK_OBJECT(-parms); 1.2663 + VERIFY_OOP(rcvr); 1.2664 + InstanceKlass* rcvrKlass = (InstanceKlass*)rcvr->klass(); 1.2665 + /* 1.2666 + Executing this code in java.lang.String: 1.2667 + public String(char value[]) { 1.2668 + this.count = value.length; 1.2669 + this.value = (char[])value.clone(); 1.2670 + } 1.2671 + 1.2672 + a find on rcvr->klass() reports: 1.2673 + {type array char}{type array class} 1.2674 + - klass: {other class} 1.2675 + 1.2676 + but using InstanceKlass::cast(STACK_OBJECT(-parms)->klass()) causes in assertion failure 1.2677 + because rcvr->klass()->oop_is_instance() == 0 1.2678 + However it seems to have a vtable in the right location. Huh? 1.2679 + 1.2680 + */ 1.2681 + callee = (Method*) rcvrKlass->start_of_vtable()[ cache->f2_as_index()]; 1.2682 + // Profile virtual call. 1.2683 + BI_PROFILE_UPDATE_VIRTUALCALL(rcvr->klass()); 1.2684 + } 1.2685 + } else { 1.2686 + if ((Bytecodes::Code)opcode == Bytecodes::_invokespecial) { 1.2687 + CHECK_NULL(STACK_OBJECT(-(cache->parameter_size()))); 1.2688 + } 1.2689 + callee = cache->f1_as_method(); 1.2690 + 1.2691 + // Profile call. 1.2692 + BI_PROFILE_UPDATE_CALL(); 1.2693 + } 1.2694 + 1.2695 + istate->set_callee(callee); 1.2696 + istate->set_callee_entry_point(callee->from_interpreted_entry()); 1.2697 +#ifdef VM_JVMTI 1.2698 + if (JvmtiExport::can_post_interpreter_events() && THREAD->is_interp_only_mode()) { 1.2699 + istate->set_callee_entry_point(callee->interpreter_entry()); 1.2700 + } 1.2701 +#endif /* VM_JVMTI */ 1.2702 + istate->set_bcp_advance(3); 1.2703 + UPDATE_PC_AND_RETURN(0); // I'll be back... 1.2704 + } 1.2705 + } 1.2706 + 1.2707 + /* Allocate memory for a new java object. */ 1.2708 + 1.2709 + CASE(_newarray): { 1.2710 + BasicType atype = (BasicType) *(pc+1); 1.2711 + jint size = STACK_INT(-1); 1.2712 + CALL_VM(InterpreterRuntime::newarray(THREAD, atype, size), 1.2713 + handle_exception); 1.2714 + // Must prevent reordering of stores for object initialization 1.2715 + // with stores that publish the new object. 1.2716 + OrderAccess::storestore(); 1.2717 + SET_STACK_OBJECT(THREAD->vm_result(), -1); 1.2718 + THREAD->set_vm_result(NULL); 1.2719 + 1.2720 + UPDATE_PC_AND_CONTINUE(2); 1.2721 + } 1.2722 + 1.2723 + /* Throw an exception. */ 1.2724 + 1.2725 + CASE(_athrow): { 1.2726 + oop except_oop = STACK_OBJECT(-1); 1.2727 + CHECK_NULL(except_oop); 1.2728 + // set pending_exception so we use common code 1.2729 + THREAD->set_pending_exception(except_oop, NULL, 0); 1.2730 + goto handle_exception; 1.2731 + } 1.2732 + 1.2733 + /* goto and jsr. They are exactly the same except jsr pushes 1.2734 + * the address of the next instruction first. 1.2735 + */ 1.2736 + 1.2737 + CASE(_jsr): { 1.2738 + /* push bytecode index on stack */ 1.2739 + SET_STACK_ADDR(((address)pc - (intptr_t)(istate->method()->code_base()) + 3), 0); 1.2740 + MORE_STACK(1); 1.2741 + /* FALL THROUGH */ 1.2742 + } 1.2743 + 1.2744 + CASE(_goto): 1.2745 + { 1.2746 + int16_t offset = (int16_t)Bytes::get_Java_u2(pc + 1); 1.2747 + // Profile jump. 1.2748 + BI_PROFILE_UPDATE_JUMP(); 1.2749 + address branch_pc = pc; 1.2750 + UPDATE_PC(offset); 1.2751 + DO_BACKEDGE_CHECKS(offset, branch_pc); 1.2752 + CONTINUE; 1.2753 + } 1.2754 + 1.2755 + CASE(_jsr_w): { 1.2756 + /* push return address on the stack */ 1.2757 + SET_STACK_ADDR(((address)pc - (intptr_t)(istate->method()->code_base()) + 5), 0); 1.2758 + MORE_STACK(1); 1.2759 + /* FALL THROUGH */ 1.2760 + } 1.2761 + 1.2762 + CASE(_goto_w): 1.2763 + { 1.2764 + int32_t offset = Bytes::get_Java_u4(pc + 1); 1.2765 + // Profile jump. 1.2766 + BI_PROFILE_UPDATE_JUMP(); 1.2767 + address branch_pc = pc; 1.2768 + UPDATE_PC(offset); 1.2769 + DO_BACKEDGE_CHECKS(offset, branch_pc); 1.2770 + CONTINUE; 1.2771 + } 1.2772 + 1.2773 + /* return from a jsr or jsr_w */ 1.2774 + 1.2775 + CASE(_ret): { 1.2776 + // Profile ret. 1.2777 + BI_PROFILE_UPDATE_RET(/*bci=*/((int)(intptr_t)(LOCALS_ADDR(pc[1])))); 1.2778 + // Now, update the pc. 1.2779 + pc = istate->method()->code_base() + (intptr_t)(LOCALS_ADDR(pc[1])); 1.2780 + UPDATE_PC_AND_CONTINUE(0); 1.2781 + } 1.2782 + 1.2783 + /* debugger breakpoint */ 1.2784 + 1.2785 + CASE(_breakpoint): { 1.2786 + Bytecodes::Code original_bytecode; 1.2787 + DECACHE_STATE(); 1.2788 + SET_LAST_JAVA_FRAME(); 1.2789 + original_bytecode = InterpreterRuntime::get_original_bytecode_at(THREAD, 1.2790 + METHOD, pc); 1.2791 + RESET_LAST_JAVA_FRAME(); 1.2792 + CACHE_STATE(); 1.2793 + if (THREAD->has_pending_exception()) goto handle_exception; 1.2794 + CALL_VM(InterpreterRuntime::_breakpoint(THREAD, METHOD, pc), 1.2795 + handle_exception); 1.2796 + 1.2797 + opcode = (jubyte)original_bytecode; 1.2798 + goto opcode_switch; 1.2799 + } 1.2800 + 1.2801 + DEFAULT: 1.2802 + fatal(err_msg("Unimplemented opcode %d = %s", opcode, 1.2803 + Bytecodes::name((Bytecodes::Code)opcode))); 1.2804 + goto finish; 1.2805 + 1.2806 + } /* switch(opc) */ 1.2807 + 1.2808 + 1.2809 +#ifdef USELABELS 1.2810 + check_for_exception: 1.2811 +#endif 1.2812 + { 1.2813 + if (!THREAD->has_pending_exception()) { 1.2814 + CONTINUE; 1.2815 + } 1.2816 + /* We will be gcsafe soon, so flush our state. */ 1.2817 + DECACHE_PC(); 1.2818 + goto handle_exception; 1.2819 + } 1.2820 + do_continue: ; 1.2821 + 1.2822 + } /* while (1) interpreter loop */ 1.2823 + 1.2824 + 1.2825 + // An exception exists in the thread state see whether this activation can handle it 1.2826 + handle_exception: { 1.2827 + 1.2828 + HandleMarkCleaner __hmc(THREAD); 1.2829 + Handle except_oop(THREAD, THREAD->pending_exception()); 1.2830 + // Prevent any subsequent HandleMarkCleaner in the VM 1.2831 + // from freeing the except_oop handle. 1.2832 + HandleMark __hm(THREAD); 1.2833 + 1.2834 + THREAD->clear_pending_exception(); 1.2835 + assert(except_oop(), "No exception to process"); 1.2836 + intptr_t continuation_bci; 1.2837 + // expression stack is emptied 1.2838 + topOfStack = istate->stack_base() - Interpreter::stackElementWords; 1.2839 + CALL_VM(continuation_bci = (intptr_t)InterpreterRuntime::exception_handler_for_exception(THREAD, except_oop()), 1.2840 + handle_exception); 1.2841 + 1.2842 + except_oop = THREAD->vm_result(); 1.2843 + THREAD->set_vm_result(NULL); 1.2844 + if (continuation_bci >= 0) { 1.2845 + // Place exception on top of stack 1.2846 + SET_STACK_OBJECT(except_oop(), 0); 1.2847 + MORE_STACK(1); 1.2848 + pc = METHOD->code_base() + continuation_bci; 1.2849 + if (TraceExceptions) { 1.2850 + ttyLocker ttyl; 1.2851 + ResourceMark rm; 1.2852 + tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")", except_oop->print_value_string(), (void*)except_oop()); 1.2853 + tty->print_cr(" thrown in interpreter method <%s>", METHOD->print_value_string()); 1.2854 + tty->print_cr(" at bci %d, continuing at %d for thread " INTPTR_FORMAT, 1.2855 + istate->bcp() - (intptr_t)METHOD->code_base(), 1.2856 + continuation_bci, THREAD); 1.2857 + } 1.2858 + // for AbortVMOnException flag 1.2859 + NOT_PRODUCT(Exceptions::debug_check_abort(except_oop)); 1.2860 + 1.2861 + // Update profiling data. 1.2862 + BI_PROFILE_ALIGN_TO_CURRENT_BCI(); 1.2863 + goto run; 1.2864 + } 1.2865 + if (TraceExceptions) { 1.2866 + ttyLocker ttyl; 1.2867 + ResourceMark rm; 1.2868 + tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")", except_oop->print_value_string(), (void*)except_oop()); 1.2869 + tty->print_cr(" thrown in interpreter method <%s>", METHOD->print_value_string()); 1.2870 + tty->print_cr(" at bci %d, unwinding for thread " INTPTR_FORMAT, 1.2871 + istate->bcp() - (intptr_t)METHOD->code_base(), 1.2872 + THREAD); 1.2873 + } 1.2874 + // for AbortVMOnException flag 1.2875 + NOT_PRODUCT(Exceptions::debug_check_abort(except_oop)); 1.2876 + // No handler in this activation, unwind and try again 1.2877 + THREAD->set_pending_exception(except_oop(), NULL, 0); 1.2878 + goto handle_return; 1.2879 + } // handle_exception: 1.2880 + 1.2881 + // Return from an interpreter invocation with the result of the interpretation 1.2882 + // on the top of the Java Stack (or a pending exception) 1.2883 + 1.2884 + handle_Pop_Frame: { 1.2885 + 1.2886 + // We don't really do anything special here except we must be aware 1.2887 + // that we can get here without ever locking the method (if sync). 1.2888 + // Also we skip the notification of the exit. 1.2889 + 1.2890 + istate->set_msg(popping_frame); 1.2891 + // Clear pending so while the pop is in process 1.2892 + // we don't start another one if a call_vm is done. 1.2893 + THREAD->clr_pop_frame_pending(); 1.2894 + // Let interpreter (only) see the we're in the process of popping a frame 1.2895 + THREAD->set_pop_frame_in_process(); 1.2896 + 1.2897 + goto handle_return; 1.2898 + 1.2899 + } // handle_Pop_Frame 1.2900 + 1.2901 + // ForceEarlyReturn ends a method, and returns to the caller with a return value 1.2902 + // given by the invoker of the early return. 1.2903 + handle_Early_Return: { 1.2904 + 1.2905 + istate->set_msg(early_return); 1.2906 + 1.2907 + // Clear expression stack. 1.2908 + topOfStack = istate->stack_base() - Interpreter::stackElementWords; 1.2909 + 1.2910 + JvmtiThreadState *ts = THREAD->jvmti_thread_state(); 1.2911 + 1.2912 + // Push the value to be returned. 1.2913 + switch (istate->method()->result_type()) { 1.2914 + case T_BOOLEAN: 1.2915 + case T_SHORT: 1.2916 + case T_BYTE: 1.2917 + case T_CHAR: 1.2918 + case T_INT: 1.2919 + SET_STACK_INT(ts->earlyret_value().i, 0); 1.2920 + MORE_STACK(1); 1.2921 + break; 1.2922 + case T_LONG: 1.2923 + SET_STACK_LONG(ts->earlyret_value().j, 1); 1.2924 + MORE_STACK(2); 1.2925 + break; 1.2926 + case T_FLOAT: 1.2927 + SET_STACK_FLOAT(ts->earlyret_value().f, 0); 1.2928 + MORE_STACK(1); 1.2929 + break; 1.2930 + case T_DOUBLE: 1.2931 + SET_STACK_DOUBLE(ts->earlyret_value().d, 1); 1.2932 + MORE_STACK(2); 1.2933 + break; 1.2934 + case T_ARRAY: 1.2935 + case T_OBJECT: 1.2936 + SET_STACK_OBJECT(ts->earlyret_oop(), 0); 1.2937 + MORE_STACK(1); 1.2938 + break; 1.2939 + } 1.2940 + 1.2941 + ts->clr_earlyret_value(); 1.2942 + ts->set_earlyret_oop(NULL); 1.2943 + ts->clr_earlyret_pending(); 1.2944 + 1.2945 + // Fall through to handle_return. 1.2946 + 1.2947 + } // handle_Early_Return 1.2948 + 1.2949 + handle_return: { 1.2950 + // A storestore barrier is required to order initialization of 1.2951 + // final fields with publishing the reference to the object that 1.2952 + // holds the field. Without the barrier the value of final fields 1.2953 + // can be observed to change. 1.2954 + OrderAccess::storestore(); 1.2955 + 1.2956 + DECACHE_STATE(); 1.2957 + 1.2958 + bool suppress_error = istate->msg() == popping_frame || istate->msg() == early_return; 1.2959 + bool suppress_exit_event = THREAD->has_pending_exception() || istate->msg() == popping_frame; 1.2960 + Handle original_exception(THREAD, THREAD->pending_exception()); 1.2961 + Handle illegal_state_oop(THREAD, NULL); 1.2962 + 1.2963 + // We'd like a HandleMark here to prevent any subsequent HandleMarkCleaner 1.2964 + // in any following VM entries from freeing our live handles, but illegal_state_oop 1.2965 + // isn't really allocated yet and so doesn't become live until later and 1.2966 + // in unpredicatable places. Instead we must protect the places where we enter the 1.2967 + // VM. It would be much simpler (and safer) if we could allocate a real handle with 1.2968 + // a NULL oop in it and then overwrite the oop later as needed. This isn't 1.2969 + // unfortunately isn't possible. 1.2970 + 1.2971 + THREAD->clear_pending_exception(); 1.2972 + 1.2973 + // 1.2974 + // As far as we are concerned we have returned. If we have a pending exception 1.2975 + // that will be returned as this invocation's result. However if we get any 1.2976 + // exception(s) while checking monitor state one of those IllegalMonitorStateExceptions 1.2977 + // will be our final result (i.e. monitor exception trumps a pending exception). 1.2978 + // 1.2979 + 1.2980 + // If we never locked the method (or really passed the point where we would have), 1.2981 + // there is no need to unlock it (or look for other monitors), since that 1.2982 + // could not have happened. 1.2983 + 1.2984 + if (THREAD->do_not_unlock()) { 1.2985 + 1.2986 + // Never locked, reset the flag now because obviously any caller must 1.2987 + // have passed their point of locking for us to have gotten here. 1.2988 + 1.2989 + THREAD->clr_do_not_unlock(); 1.2990 + } else { 1.2991 + // At this point we consider that we have returned. We now check that the 1.2992 + // locks were properly block structured. If we find that they were not 1.2993 + // used properly we will return with an illegal monitor exception. 1.2994 + // The exception is checked by the caller not the callee since this 1.2995 + // checking is considered to be part of the invocation and therefore 1.2996 + // in the callers scope (JVM spec 8.13). 1.2997 + // 1.2998 + // Another weird thing to watch for is if the method was locked 1.2999 + // recursively and then not exited properly. This means we must 1.3000 + // examine all the entries in reverse time(and stack) order and 1.3001 + // unlock as we find them. If we find the method monitor before 1.3002 + // we are at the initial entry then we should throw an exception. 1.3003 + // It is not clear the template based interpreter does this 1.3004 + // correctly 1.3005 + 1.3006 + BasicObjectLock* base = istate->monitor_base(); 1.3007 + BasicObjectLock* end = (BasicObjectLock*) istate->stack_base(); 1.3008 + bool method_unlock_needed = METHOD->is_synchronized(); 1.3009 + // We know the initial monitor was used for the method don't check that 1.3010 + // slot in the loop 1.3011 + if (method_unlock_needed) base--; 1.3012 + 1.3013 + // Check all the monitors to see they are unlocked. Install exception if found to be locked. 1.3014 + while (end < base) { 1.3015 + oop lockee = end->obj(); 1.3016 + if (lockee != NULL) { 1.3017 + BasicLock* lock = end->lock(); 1.3018 + markOop header = lock->displaced_header(); 1.3019 + end->set_obj(NULL); 1.3020 + 1.3021 + if (!lockee->mark()->has_bias_pattern()) { 1.3022 + // If it isn't recursive we either must swap old header or call the runtime 1.3023 + if (header != NULL) { 1.3024 + if (Atomic::cmpxchg_ptr(header, lockee->mark_addr(), lock) != lock) { 1.3025 + // restore object for the slow case 1.3026 + end->set_obj(lockee); 1.3027 + { 1.3028 + // Prevent any HandleMarkCleaner from freeing our live handles 1.3029 + HandleMark __hm(THREAD); 1.3030 + CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(THREAD, end)); 1.3031 + } 1.3032 + } 1.3033 + } 1.3034 + } 1.3035 + // One error is plenty 1.3036 + if (illegal_state_oop() == NULL && !suppress_error) { 1.3037 + { 1.3038 + // Prevent any HandleMarkCleaner from freeing our live handles 1.3039 + HandleMark __hm(THREAD); 1.3040 + CALL_VM_NOCHECK(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD)); 1.3041 + } 1.3042 + assert(THREAD->has_pending_exception(), "Lost our exception!"); 1.3043 + illegal_state_oop = THREAD->pending_exception(); 1.3044 + THREAD->clear_pending_exception(); 1.3045 + } 1.3046 + } 1.3047 + end++; 1.3048 + } 1.3049 + // Unlock the method if needed 1.3050 + if (method_unlock_needed) { 1.3051 + if (base->obj() == NULL) { 1.3052 + // The method is already unlocked this is not good. 1.3053 + if (illegal_state_oop() == NULL && !suppress_error) { 1.3054 + { 1.3055 + // Prevent any HandleMarkCleaner from freeing our live handles 1.3056 + HandleMark __hm(THREAD); 1.3057 + CALL_VM_NOCHECK(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD)); 1.3058 + } 1.3059 + assert(THREAD->has_pending_exception(), "Lost our exception!"); 1.3060 + illegal_state_oop = THREAD->pending_exception(); 1.3061 + THREAD->clear_pending_exception(); 1.3062 + } 1.3063 + } else { 1.3064 + // 1.3065 + // The initial monitor is always used for the method 1.3066 + // However if that slot is no longer the oop for the method it was unlocked 1.3067 + // and reused by something that wasn't unlocked! 1.3068 + // 1.3069 + // deopt can come in with rcvr dead because c2 knows 1.3070 + // its value is preserved in the monitor. So we can't use locals[0] at all 1.3071 + // and must use first monitor slot. 1.3072 + // 1.3073 + oop rcvr = base->obj(); 1.3074 + if (rcvr == NULL) { 1.3075 + if (!suppress_error) { 1.3076 + VM_JAVA_ERROR_NO_JUMP(vmSymbols::java_lang_NullPointerException(), "", note_nullCheck_trap); 1.3077 + illegal_state_oop = THREAD->pending_exception(); 1.3078 + THREAD->clear_pending_exception(); 1.3079 + } 1.3080 + } else if (UseHeavyMonitors) { 1.3081 + { 1.3082 + // Prevent any HandleMarkCleaner from freeing our live handles. 1.3083 + HandleMark __hm(THREAD); 1.3084 + CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(THREAD, base)); 1.3085 + } 1.3086 + if (THREAD->has_pending_exception()) { 1.3087 + if (!suppress_error) illegal_state_oop = THREAD->pending_exception(); 1.3088 + THREAD->clear_pending_exception(); 1.3089 + } 1.3090 + } else { 1.3091 + BasicLock* lock = base->lock(); 1.3092 + markOop header = lock->displaced_header(); 1.3093 + base->set_obj(NULL); 1.3094 + 1.3095 + if (!rcvr->mark()->has_bias_pattern()) { 1.3096 + base->set_obj(NULL); 1.3097 + // If it isn't recursive we either must swap old header or call the runtime 1.3098 + if (header != NULL) { 1.3099 + if (Atomic::cmpxchg_ptr(header, rcvr->mark_addr(), lock) != lock) { 1.3100 + // restore object for the slow case 1.3101 + base->set_obj(rcvr); 1.3102 + { 1.3103 + // Prevent any HandleMarkCleaner from freeing our live handles 1.3104 + HandleMark __hm(THREAD); 1.3105 + CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(THREAD, base)); 1.3106 + } 1.3107 + if (THREAD->has_pending_exception()) { 1.3108 + if (!suppress_error) illegal_state_oop = THREAD->pending_exception(); 1.3109 + THREAD->clear_pending_exception(); 1.3110 + } 1.3111 + } 1.3112 + } 1.3113 + } 1.3114 + } 1.3115 + } 1.3116 + } 1.3117 + } 1.3118 + // Clear the do_not_unlock flag now. 1.3119 + THREAD->clr_do_not_unlock(); 1.3120 + 1.3121 + // 1.3122 + // Notify jvmti/jvmdi 1.3123 + // 1.3124 + // NOTE: we do not notify a method_exit if we have a pending exception, 1.3125 + // including an exception we generate for unlocking checks. In the former 1.3126 + // case, JVMDI has already been notified by our call for the exception handler 1.3127 + // and in both cases as far as JVMDI is concerned we have already returned. 1.3128 + // If we notify it again JVMDI will be all confused about how many frames 1.3129 + // are still on the stack (4340444). 1.3130 + // 1.3131 + // NOTE Further! It turns out the the JVMTI spec in fact expects to see 1.3132 + // method_exit events whenever we leave an activation unless it was done 1.3133 + // for popframe. This is nothing like jvmdi. However we are passing the 1.3134 + // tests at the moment (apparently because they are jvmdi based) so rather 1.3135 + // than change this code and possibly fail tests we will leave it alone 1.3136 + // (with this note) in anticipation of changing the vm and the tests 1.3137 + // simultaneously. 1.3138 + 1.3139 + 1.3140 + // 1.3141 + suppress_exit_event = suppress_exit_event || illegal_state_oop() != NULL; 1.3142 + 1.3143 + 1.3144 + 1.3145 +#ifdef VM_JVMTI 1.3146 + if (_jvmti_interp_events) { 1.3147 + // Whenever JVMTI puts a thread in interp_only_mode, method 1.3148 + // entry/exit events are sent for that thread to track stack depth. 1.3149 + if ( !suppress_exit_event && THREAD->is_interp_only_mode() ) { 1.3150 + { 1.3151 + // Prevent any HandleMarkCleaner from freeing our live handles 1.3152 + HandleMark __hm(THREAD); 1.3153 + CALL_VM_NOCHECK(InterpreterRuntime::post_method_exit(THREAD)); 1.3154 + } 1.3155 + } 1.3156 + } 1.3157 +#endif /* VM_JVMTI */ 1.3158 + 1.3159 + // 1.3160 + // See if we are returning any exception 1.3161 + // A pending exception that was pending prior to a possible popping frame 1.3162 + // overrides the popping frame. 1.3163 + // 1.3164 + assert(!suppress_error || (suppress_error && illegal_state_oop() == NULL), "Error was not suppressed"); 1.3165 + if (illegal_state_oop() != NULL || original_exception() != NULL) { 1.3166 + // Inform the frame manager we have no result. 1.3167 + istate->set_msg(throwing_exception); 1.3168 + if (illegal_state_oop() != NULL) 1.3169 + THREAD->set_pending_exception(illegal_state_oop(), NULL, 0); 1.3170 + else 1.3171 + THREAD->set_pending_exception(original_exception(), NULL, 0); 1.3172 + UPDATE_PC_AND_RETURN(0); 1.3173 + } 1.3174 + 1.3175 + if (istate->msg() == popping_frame) { 1.3176 + // Make it simpler on the assembly code and set the message for the frame pop. 1.3177 + // returns 1.3178 + if (istate->prev() == NULL) { 1.3179 + // We must be returning to a deoptimized frame (because popframe only happens between 1.3180 + // two interpreted frames). We need to save the current arguments in C heap so that 1.3181 + // the deoptimized frame when it restarts can copy the arguments to its expression 1.3182 + // stack and re-execute the call. We also have to notify deoptimization that this 1.3183 + // has occurred and to pick the preserved args copy them to the deoptimized frame's 1.3184 + // java expression stack. Yuck. 1.3185 + // 1.3186 + THREAD->popframe_preserve_args(in_ByteSize(METHOD->size_of_parameters() * wordSize), 1.3187 + LOCALS_SLOT(METHOD->size_of_parameters() - 1)); 1.3188 + THREAD->set_popframe_condition_bit(JavaThread::popframe_force_deopt_reexecution_bit); 1.3189 + } 1.3190 + } else { 1.3191 + istate->set_msg(return_from_method); 1.3192 + } 1.3193 + 1.3194 + // Normal return 1.3195 + // Advance the pc and return to frame manager 1.3196 + UPDATE_PC_AND_RETURN(1); 1.3197 + } /* handle_return: */ 1.3198 + 1.3199 +// This is really a fatal error return 1.3200 + 1.3201 +finish: 1.3202 + DECACHE_TOS(); 1.3203 + DECACHE_PC(); 1.3204 + 1.3205 + return; 1.3206 +} 1.3207 + 1.3208 +/* 1.3209 + * All the code following this point is only produced once and is not present 1.3210 + * in the JVMTI version of the interpreter 1.3211 +*/ 1.3212 + 1.3213 +#ifndef VM_JVMTI 1.3214 + 1.3215 +// This constructor should only be used to contruct the object to signal 1.3216 +// interpreter initialization. All other instances should be created by 1.3217 +// the frame manager. 1.3218 +BytecodeInterpreter::BytecodeInterpreter(messages msg) { 1.3219 + if (msg != initialize) ShouldNotReachHere(); 1.3220 + _msg = msg; 1.3221 + _self_link = this; 1.3222 + _prev_link = NULL; 1.3223 +} 1.3224 + 1.3225 +// Inline static functions for Java Stack and Local manipulation 1.3226 + 1.3227 +// The implementations are platform dependent. We have to worry about alignment 1.3228 +// issues on some machines which can change on the same platform depending on 1.3229 +// whether it is an LP64 machine also. 1.3230 +address BytecodeInterpreter::stack_slot(intptr_t *tos, int offset) { 1.3231 + return (address) tos[Interpreter::expr_index_at(-offset)]; 1.3232 +} 1.3233 + 1.3234 +jint BytecodeInterpreter::stack_int(intptr_t *tos, int offset) { 1.3235 + return *((jint*) &tos[Interpreter::expr_index_at(-offset)]); 1.3236 +} 1.3237 + 1.3238 +jfloat BytecodeInterpreter::stack_float(intptr_t *tos, int offset) { 1.3239 + return *((jfloat *) &tos[Interpreter::expr_index_at(-offset)]); 1.3240 +} 1.3241 + 1.3242 +oop BytecodeInterpreter::stack_object(intptr_t *tos, int offset) { 1.3243 + return cast_to_oop(tos [Interpreter::expr_index_at(-offset)]); 1.3244 +} 1.3245 + 1.3246 +jdouble BytecodeInterpreter::stack_double(intptr_t *tos, int offset) { 1.3247 + return ((VMJavaVal64*) &tos[Interpreter::expr_index_at(-offset)])->d; 1.3248 +} 1.3249 + 1.3250 +jlong BytecodeInterpreter::stack_long(intptr_t *tos, int offset) { 1.3251 + return ((VMJavaVal64 *) &tos[Interpreter::expr_index_at(-offset)])->l; 1.3252 +} 1.3253 + 1.3254 +// only used for value types 1.3255 +void BytecodeInterpreter::set_stack_slot(intptr_t *tos, address value, 1.3256 + int offset) { 1.3257 + *((address *)&tos[Interpreter::expr_index_at(-offset)]) = value; 1.3258 +} 1.3259 + 1.3260 +void BytecodeInterpreter::set_stack_int(intptr_t *tos, int value, 1.3261 + int offset) { 1.3262 + *((jint *)&tos[Interpreter::expr_index_at(-offset)]) = value; 1.3263 +} 1.3264 + 1.3265 +void BytecodeInterpreter::set_stack_float(intptr_t *tos, jfloat value, 1.3266 + int offset) { 1.3267 + *((jfloat *)&tos[Interpreter::expr_index_at(-offset)]) = value; 1.3268 +} 1.3269 + 1.3270 +void BytecodeInterpreter::set_stack_object(intptr_t *tos, oop value, 1.3271 + int offset) { 1.3272 + *((oop *)&tos[Interpreter::expr_index_at(-offset)]) = value; 1.3273 +} 1.3274 + 1.3275 +// needs to be platform dep for the 32 bit platforms. 1.3276 +void BytecodeInterpreter::set_stack_double(intptr_t *tos, jdouble value, 1.3277 + int offset) { 1.3278 + ((VMJavaVal64*)&tos[Interpreter::expr_index_at(-offset)])->d = value; 1.3279 +} 1.3280 + 1.3281 +void BytecodeInterpreter::set_stack_double_from_addr(intptr_t *tos, 1.3282 + address addr, int offset) { 1.3283 + (((VMJavaVal64*)&tos[Interpreter::expr_index_at(-offset)])->d = 1.3284 + ((VMJavaVal64*)addr)->d); 1.3285 +} 1.3286 + 1.3287 +void BytecodeInterpreter::set_stack_long(intptr_t *tos, jlong value, 1.3288 + int offset) { 1.3289 + ((VMJavaVal64*)&tos[Interpreter::expr_index_at(-offset+1)])->l = 0xdeedbeeb; 1.3290 + ((VMJavaVal64*)&tos[Interpreter::expr_index_at(-offset)])->l = value; 1.3291 +} 1.3292 + 1.3293 +void BytecodeInterpreter::set_stack_long_from_addr(intptr_t *tos, 1.3294 + address addr, int offset) { 1.3295 + ((VMJavaVal64*)&tos[Interpreter::expr_index_at(-offset+1)])->l = 0xdeedbeeb; 1.3296 + ((VMJavaVal64*)&tos[Interpreter::expr_index_at(-offset)])->l = 1.3297 + ((VMJavaVal64*)addr)->l; 1.3298 +} 1.3299 + 1.3300 +// Locals 1.3301 + 1.3302 +address BytecodeInterpreter::locals_slot(intptr_t* locals, int offset) { 1.3303 + return (address)locals[Interpreter::local_index_at(-offset)]; 1.3304 +} 1.3305 +jint BytecodeInterpreter::locals_int(intptr_t* locals, int offset) { 1.3306 + return (jint)locals[Interpreter::local_index_at(-offset)]; 1.3307 +} 1.3308 +jfloat BytecodeInterpreter::locals_float(intptr_t* locals, int offset) { 1.3309 + return (jfloat)locals[Interpreter::local_index_at(-offset)]; 1.3310 +} 1.3311 +oop BytecodeInterpreter::locals_object(intptr_t* locals, int offset) { 1.3312 + return cast_to_oop(locals[Interpreter::local_index_at(-offset)]); 1.3313 +} 1.3314 +jdouble BytecodeInterpreter::locals_double(intptr_t* locals, int offset) { 1.3315 + return ((VMJavaVal64*)&locals[Interpreter::local_index_at(-(offset+1))])->d; 1.3316 +} 1.3317 +jlong BytecodeInterpreter::locals_long(intptr_t* locals, int offset) { 1.3318 + return ((VMJavaVal64*)&locals[Interpreter::local_index_at(-(offset+1))])->l; 1.3319 +} 1.3320 + 1.3321 +// Returns the address of locals value. 1.3322 +address BytecodeInterpreter::locals_long_at(intptr_t* locals, int offset) { 1.3323 + return ((address)&locals[Interpreter::local_index_at(-(offset+1))]); 1.3324 +} 1.3325 +address BytecodeInterpreter::locals_double_at(intptr_t* locals, int offset) { 1.3326 + return ((address)&locals[Interpreter::local_index_at(-(offset+1))]); 1.3327 +} 1.3328 + 1.3329 +// Used for local value or returnAddress 1.3330 +void BytecodeInterpreter::set_locals_slot(intptr_t *locals, 1.3331 + address value, int offset) { 1.3332 + *((address*)&locals[Interpreter::local_index_at(-offset)]) = value; 1.3333 +} 1.3334 +void BytecodeInterpreter::set_locals_int(intptr_t *locals, 1.3335 + jint value, int offset) { 1.3336 + *((jint *)&locals[Interpreter::local_index_at(-offset)]) = value; 1.3337 +} 1.3338 +void BytecodeInterpreter::set_locals_float(intptr_t *locals, 1.3339 + jfloat value, int offset) { 1.3340 + *((jfloat *)&locals[Interpreter::local_index_at(-offset)]) = value; 1.3341 +} 1.3342 +void BytecodeInterpreter::set_locals_object(intptr_t *locals, 1.3343 + oop value, int offset) { 1.3344 + *((oop *)&locals[Interpreter::local_index_at(-offset)]) = value; 1.3345 +} 1.3346 +void BytecodeInterpreter::set_locals_double(intptr_t *locals, 1.3347 + jdouble value, int offset) { 1.3348 + ((VMJavaVal64*)&locals[Interpreter::local_index_at(-(offset+1))])->d = value; 1.3349 +} 1.3350 +void BytecodeInterpreter::set_locals_long(intptr_t *locals, 1.3351 + jlong value, int offset) { 1.3352 + ((VMJavaVal64*)&locals[Interpreter::local_index_at(-(offset+1))])->l = value; 1.3353 +} 1.3354 +void BytecodeInterpreter::set_locals_double_from_addr(intptr_t *locals, 1.3355 + address addr, int offset) { 1.3356 + ((VMJavaVal64*)&locals[Interpreter::local_index_at(-(offset+1))])->d = ((VMJavaVal64*)addr)->d; 1.3357 +} 1.3358 +void BytecodeInterpreter::set_locals_long_from_addr(intptr_t *locals, 1.3359 + address addr, int offset) { 1.3360 + ((VMJavaVal64*)&locals[Interpreter::local_index_at(-(offset+1))])->l = ((VMJavaVal64*)addr)->l; 1.3361 +} 1.3362 + 1.3363 +void BytecodeInterpreter::astore(intptr_t* tos, int stack_offset, 1.3364 + intptr_t* locals, int locals_offset) { 1.3365 + intptr_t value = tos[Interpreter::expr_index_at(-stack_offset)]; 1.3366 + locals[Interpreter::local_index_at(-locals_offset)] = value; 1.3367 +} 1.3368 + 1.3369 + 1.3370 +void BytecodeInterpreter::copy_stack_slot(intptr_t *tos, int from_offset, 1.3371 + int to_offset) { 1.3372 + tos[Interpreter::expr_index_at(-to_offset)] = 1.3373 + (intptr_t)tos[Interpreter::expr_index_at(-from_offset)]; 1.3374 +} 1.3375 + 1.3376 +void BytecodeInterpreter::dup(intptr_t *tos) { 1.3377 + copy_stack_slot(tos, -1, 0); 1.3378 +} 1.3379 +void BytecodeInterpreter::dup2(intptr_t *tos) { 1.3380 + copy_stack_slot(tos, -2, 0); 1.3381 + copy_stack_slot(tos, -1, 1); 1.3382 +} 1.3383 + 1.3384 +void BytecodeInterpreter::dup_x1(intptr_t *tos) { 1.3385 + /* insert top word two down */ 1.3386 + copy_stack_slot(tos, -1, 0); 1.3387 + copy_stack_slot(tos, -2, -1); 1.3388 + copy_stack_slot(tos, 0, -2); 1.3389 +} 1.3390 + 1.3391 +void BytecodeInterpreter::dup_x2(intptr_t *tos) { 1.3392 + /* insert top word three down */ 1.3393 + copy_stack_slot(tos, -1, 0); 1.3394 + copy_stack_slot(tos, -2, -1); 1.3395 + copy_stack_slot(tos, -3, -2); 1.3396 + copy_stack_slot(tos, 0, -3); 1.3397 +} 1.3398 +void BytecodeInterpreter::dup2_x1(intptr_t *tos) { 1.3399 + /* insert top 2 slots three down */ 1.3400 + copy_stack_slot(tos, -1, 1); 1.3401 + copy_stack_slot(tos, -2, 0); 1.3402 + copy_stack_slot(tos, -3, -1); 1.3403 + copy_stack_slot(tos, 1, -2); 1.3404 + copy_stack_slot(tos, 0, -3); 1.3405 +} 1.3406 +void BytecodeInterpreter::dup2_x2(intptr_t *tos) { 1.3407 + /* insert top 2 slots four down */ 1.3408 + copy_stack_slot(tos, -1, 1); 1.3409 + copy_stack_slot(tos, -2, 0); 1.3410 + copy_stack_slot(tos, -3, -1); 1.3411 + copy_stack_slot(tos, -4, -2); 1.3412 + copy_stack_slot(tos, 1, -3); 1.3413 + copy_stack_slot(tos, 0, -4); 1.3414 +} 1.3415 + 1.3416 + 1.3417 +void BytecodeInterpreter::swap(intptr_t *tos) { 1.3418 + // swap top two elements 1.3419 + intptr_t val = tos[Interpreter::expr_index_at(1)]; 1.3420 + // Copy -2 entry to -1 1.3421 + copy_stack_slot(tos, -2, -1); 1.3422 + // Store saved -1 entry into -2 1.3423 + tos[Interpreter::expr_index_at(2)] = val; 1.3424 +} 1.3425 +// -------------------------------------------------------------------------------- 1.3426 +// Non-product code 1.3427 +#ifndef PRODUCT 1.3428 + 1.3429 +const char* BytecodeInterpreter::C_msg(BytecodeInterpreter::messages msg) { 1.3430 + switch (msg) { 1.3431 + case BytecodeInterpreter::no_request: return("no_request"); 1.3432 + case BytecodeInterpreter::initialize: return("initialize"); 1.3433 + // status message to C++ interpreter 1.3434 + case BytecodeInterpreter::method_entry: return("method_entry"); 1.3435 + case BytecodeInterpreter::method_resume: return("method_resume"); 1.3436 + case BytecodeInterpreter::got_monitors: return("got_monitors"); 1.3437 + case BytecodeInterpreter::rethrow_exception: return("rethrow_exception"); 1.3438 + // requests to frame manager from C++ interpreter 1.3439 + case BytecodeInterpreter::call_method: return("call_method"); 1.3440 + case BytecodeInterpreter::return_from_method: return("return_from_method"); 1.3441 + case BytecodeInterpreter::more_monitors: return("more_monitors"); 1.3442 + case BytecodeInterpreter::throwing_exception: return("throwing_exception"); 1.3443 + case BytecodeInterpreter::popping_frame: return("popping_frame"); 1.3444 + case BytecodeInterpreter::do_osr: return("do_osr"); 1.3445 + // deopt 1.3446 + case BytecodeInterpreter::deopt_resume: return("deopt_resume"); 1.3447 + case BytecodeInterpreter::deopt_resume2: return("deopt_resume2"); 1.3448 + default: return("BAD MSG"); 1.3449 + } 1.3450 +} 1.3451 +void 1.3452 +BytecodeInterpreter::print() { 1.3453 + tty->print_cr("thread: " INTPTR_FORMAT, (uintptr_t) this->_thread); 1.3454 + tty->print_cr("bcp: " INTPTR_FORMAT, (uintptr_t) this->_bcp); 1.3455 + tty->print_cr("locals: " INTPTR_FORMAT, (uintptr_t) this->_locals); 1.3456 + tty->print_cr("constants: " INTPTR_FORMAT, (uintptr_t) this->_constants); 1.3457 + { 1.3458 + ResourceMark rm; 1.3459 + char *method_name = _method->name_and_sig_as_C_string(); 1.3460 + tty->print_cr("method: " INTPTR_FORMAT "[ %s ]", (uintptr_t) this->_method, method_name); 1.3461 + } 1.3462 + tty->print_cr("mdx: " INTPTR_FORMAT, (uintptr_t) this->_mdx); 1.3463 + tty->print_cr("stack: " INTPTR_FORMAT, (uintptr_t) this->_stack); 1.3464 + tty->print_cr("msg: %s", C_msg(this->_msg)); 1.3465 + tty->print_cr("result_to_call._callee: " INTPTR_FORMAT, (uintptr_t) this->_result._to_call._callee); 1.3466 + tty->print_cr("result_to_call._callee_entry_point: " INTPTR_FORMAT, (uintptr_t) this->_result._to_call._callee_entry_point); 1.3467 + tty->print_cr("result_to_call._bcp_advance: %d ", this->_result._to_call._bcp_advance); 1.3468 + tty->print_cr("osr._osr_buf: " INTPTR_FORMAT, (uintptr_t) this->_result._osr._osr_buf); 1.3469 + tty->print_cr("osr._osr_entry: " INTPTR_FORMAT, (uintptr_t) this->_result._osr._osr_entry); 1.3470 + tty->print_cr("prev_link: " INTPTR_FORMAT, (uintptr_t) this->_prev_link); 1.3471 + tty->print_cr("native_mirror: " INTPTR_FORMAT, (void*) this->_oop_temp); 1.3472 + tty->print_cr("stack_base: " INTPTR_FORMAT, (uintptr_t) this->_stack_base); 1.3473 + tty->print_cr("stack_limit: " INTPTR_FORMAT, (uintptr_t) this->_stack_limit); 1.3474 + tty->print_cr("monitor_base: " INTPTR_FORMAT, (uintptr_t) this->_monitor_base); 1.3475 +#ifdef SPARC 1.3476 + tty->print_cr("last_Java_pc: " INTPTR_FORMAT, (uintptr_t) this->_last_Java_pc); 1.3477 + tty->print_cr("frame_bottom: " INTPTR_FORMAT, (uintptr_t) this->_frame_bottom); 1.3478 + tty->print_cr("&native_fresult: " INTPTR_FORMAT, (uintptr_t) &this->_native_fresult); 1.3479 + tty->print_cr("native_lresult: " INTPTR_FORMAT, (uintptr_t) this->_native_lresult); 1.3480 +#endif 1.3481 +#if !defined(ZERO) 1.3482 + tty->print_cr("last_Java_fp: " INTPTR_FORMAT, (uintptr_t) this->_last_Java_fp); 1.3483 +#endif // !ZERO 1.3484 + tty->print_cr("self_link: " INTPTR_FORMAT, (uintptr_t) this->_self_link); 1.3485 +} 1.3486 + 1.3487 +extern "C" { 1.3488 + void PI(uintptr_t arg) { 1.3489 + ((BytecodeInterpreter*)arg)->print(); 1.3490 + } 1.3491 +} 1.3492 +#endif // PRODUCT 1.3493 + 1.3494 +#endif // JVMTI 1.3495 +#endif // CC_INTERP