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