src/share/vm/interpreter/bytecodeInterpreter.cpp

Wed, 31 Jan 2018 19:24:57 -0500

author
dbuck
date
Wed, 31 Jan 2018 19:24:57 -0500
changeset 9289
427b2fb1944f
parent 8429
8f58998958ca
child 8604
04d83ba48607
child 9110
56123fdca84a
permissions
-rw-r--r--

8189170: Add option to disable stack overflow checking in primordial thread for use with JNI_CreateJavaJVM
Reviewed-by: dcubed

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

mercurial