Path: blob/master/src/hotspot/share/interpreter/zero/bytecodeInterpreter.cpp
66644 views
/*1* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324// no precompiled headers25#include "jvm_io.h"26#include "classfile/javaClasses.hpp"27#include "classfile/vmSymbols.hpp"28#include "gc/shared/collectedHeap.hpp"29#include "gc/shared/threadLocalAllocBuffer.inline.hpp"30#include "gc/shared/tlab_globals.hpp"31#include "interpreter/bytecodeHistogram.hpp"32#include "interpreter/zero/bytecodeInterpreter.inline.hpp"33#include "interpreter/interpreter.hpp"34#include "interpreter/interpreterRuntime.hpp"35#include "logging/log.hpp"36#include "memory/resourceArea.hpp"37#include "memory/universe.hpp"38#include "oops/constantPool.inline.hpp"39#include "oops/cpCache.inline.hpp"40#include "oops/instanceKlass.inline.hpp"41#include "oops/klass.inline.hpp"42#include "oops/method.inline.hpp"43#include "oops/methodCounters.hpp"44#include "oops/objArrayKlass.hpp"45#include "oops/objArrayOop.inline.hpp"46#include "oops/oop.inline.hpp"47#include "oops/typeArrayOop.inline.hpp"48#include "prims/jvmtiExport.hpp"49#include "prims/jvmtiThreadState.hpp"50#include "runtime/atomic.hpp"51#include "runtime/frame.inline.hpp"52#include "runtime/handles.inline.hpp"53#include "runtime/interfaceSupport.inline.hpp"54#include "runtime/orderAccess.hpp"55#include "runtime/sharedRuntime.hpp"56#include "runtime/threadCritical.hpp"57#include "utilities/debug.hpp"58#include "utilities/exceptions.hpp"59#include "utilities/macros.hpp"6061// no precompiled headers6263/*64* USELABELS - If using GCC, then use labels for the opcode dispatching65* rather -then a switch statement. This improves performance because it66* gives us the opportunity to have the instructions that calculate the67* next opcode to jump to be intermixed with the rest of the instructions68* that implement the opcode (see UPDATE_PC_AND_TOS_AND_CONTINUE macro).69*/70#undef USELABELS71#ifdef __GNUC__72/*73ASSERT signifies debugging. It is much easier to step thru bytecodes if we74don't use the computed goto approach.75*/76#ifndef ASSERT77#define USELABELS78#endif79#endif8081#undef CASE82#ifdef USELABELS83#define CASE(opcode) opc ## opcode84#define DEFAULT opc_default85#else86#define CASE(opcode) case Bytecodes:: opcode87#define DEFAULT default88#endif8990/*91* PREFETCH_OPCCODE - Some compilers do better if you prefetch the next92* opcode before going back to the top of the while loop, rather then having93* the top of the while loop handle it. This provides a better opportunity94* for instruction scheduling. Some compilers just do this prefetch95* automatically. Some actually end up with worse performance if you96* force the prefetch. Solaris gcc seems to do better, but cc does worse.97*/98#undef PREFETCH_OPCCODE99#define PREFETCH_OPCCODE100101/*102Interpreter safepoint: it is expected that the interpreter will have no live103handles of its own creation live at an interpreter safepoint. Therefore we104run a HandleMarkCleaner and trash all handles allocated in the call chain105since the JavaCalls::call_helper invocation that initiated the chain.106There really shouldn't be any handles remaining to trash but this is cheap107in relation to a safepoint.108*/109#define RETURN_SAFEPOINT \110if (SafepointMechanism::should_process(THREAD)) { \111HandleMarkCleaner __hmc(THREAD); \112CALL_VM(SafepointMechanism::process_if_requested_with_exit_check(THREAD, true /* check asyncs */), \113handle_exception); \114} \115116/*117* VM_JAVA_ERROR - Macro for throwing a java exception from118* the interpreter loop. Should really be a CALL_VM but there119* is no entry point to do the transition to vm so we just120* do it by hand here.121*/122#define VM_JAVA_ERROR_NO_JUMP(name, msg) \123DECACHE_STATE(); \124SET_LAST_JAVA_FRAME(); \125{ \126ThreadInVMfromJava trans(THREAD); \127Exceptions::_throw_msg(THREAD, __FILE__, __LINE__, name, msg); \128} \129RESET_LAST_JAVA_FRAME(); \130CACHE_STATE();131132// Normal throw of a java error.133#define VM_JAVA_ERROR(name, msg) \134VM_JAVA_ERROR_NO_JUMP(name, msg) \135goto handle_exception;136137#ifdef PRODUCT138#define DO_UPDATE_INSTRUCTION_COUNT(opcode)139#else140#define DO_UPDATE_INSTRUCTION_COUNT(opcode) \141{ \142if (PrintBytecodeHistogram) { \143BytecodeHistogram::_counters[(Bytecodes::Code)opcode]++; \144} \145if (CountBytecodes || TraceBytecodes || StopInterpreterAt > 0) { \146BytecodeCounter::_counter_value++; \147if (StopInterpreterAt == BytecodeCounter::_counter_value) { \148os::breakpoint(); \149} \150if (TraceBytecodes) { \151CALL_VM((void)InterpreterRuntime::trace_bytecode(THREAD, 0, \152topOfStack[Interpreter::expr_index_at(1)], \153topOfStack[Interpreter::expr_index_at(2)]), \154handle_exception); \155} \156} \157}158#endif159160#undef DEBUGGER_SINGLE_STEP_NOTIFY161#if INCLUDE_JVMTI162/* NOTE: (kbr) This macro must be called AFTER the PC has been163incremented. JvmtiExport::at_single_stepping_point() may cause a164breakpoint opcode to get inserted at the current PC to allow the165debugger to coalesce single-step events.166167As a result if we call at_single_stepping_point() we refetch opcode168to get the current opcode. This will override any other prefetching169that might have occurred.170*/171#define DEBUGGER_SINGLE_STEP_NOTIFY() \172{ \173if (JVMTI_ENABLED && JvmtiExport::should_post_single_step()) { \174DECACHE_STATE(); \175SET_LAST_JAVA_FRAME(); \176ThreadInVMfromJava trans(THREAD); \177JvmtiExport::at_single_stepping_point(THREAD, \178istate->method(), \179pc); \180RESET_LAST_JAVA_FRAME(); \181CACHE_STATE(); \182if (THREAD->has_pending_popframe() && \183!THREAD->pop_frame_in_process()) { \184goto handle_Pop_Frame; \185} \186if (THREAD->jvmti_thread_state() && \187THREAD->jvmti_thread_state()->is_earlyret_pending()) { \188goto handle_Early_Return; \189} \190opcode = *pc; \191} \192}193#else194#define DEBUGGER_SINGLE_STEP_NOTIFY()195#endif // INCLUDE_JVMTI196197/*198* CONTINUE - Macro for executing the next opcode.199*/200#undef CONTINUE201#ifdef USELABELS202// Have to do this dispatch this way in C++ because otherwise gcc complains about crossing an203// initialization (which is is the initialization of the table pointer...)204#define DISPATCH(opcode) goto *(void*)dispatch_table[opcode]205#define CONTINUE { \206opcode = *pc; \207DO_UPDATE_INSTRUCTION_COUNT(opcode); \208DEBUGGER_SINGLE_STEP_NOTIFY(); \209DISPATCH(opcode); \210}211#else212#ifdef PREFETCH_OPCCODE213#define CONTINUE { \214opcode = *pc; \215DO_UPDATE_INSTRUCTION_COUNT(opcode); \216DEBUGGER_SINGLE_STEP_NOTIFY(); \217continue; \218}219#else220#define CONTINUE { \221DO_UPDATE_INSTRUCTION_COUNT(opcode); \222DEBUGGER_SINGLE_STEP_NOTIFY(); \223continue; \224}225#endif226#endif227228229#define UPDATE_PC(opsize) {pc += opsize; }230/*231* UPDATE_PC_AND_TOS - Macro for updating the pc and topOfStack.232*/233#undef UPDATE_PC_AND_TOS234#define UPDATE_PC_AND_TOS(opsize, stack) \235{pc += opsize; MORE_STACK(stack); }236237/*238* UPDATE_PC_AND_TOS_AND_CONTINUE - Macro for updating the pc and topOfStack,239* and executing the next opcode. It's somewhat similar to the combination240* of UPDATE_PC_AND_TOS and CONTINUE, but with some minor optimizations.241*/242#undef UPDATE_PC_AND_TOS_AND_CONTINUE243#ifdef USELABELS244#define UPDATE_PC_AND_TOS_AND_CONTINUE(opsize, stack) { \245pc += opsize; opcode = *pc; MORE_STACK(stack); \246DO_UPDATE_INSTRUCTION_COUNT(opcode); \247DEBUGGER_SINGLE_STEP_NOTIFY(); \248DISPATCH(opcode); \249}250251#define UPDATE_PC_AND_CONTINUE(opsize) { \252pc += opsize; opcode = *pc; \253DO_UPDATE_INSTRUCTION_COUNT(opcode); \254DEBUGGER_SINGLE_STEP_NOTIFY(); \255DISPATCH(opcode); \256}257#else258#ifdef PREFETCH_OPCCODE259#define UPDATE_PC_AND_TOS_AND_CONTINUE(opsize, stack) { \260pc += opsize; opcode = *pc; MORE_STACK(stack); \261DO_UPDATE_INSTRUCTION_COUNT(opcode); \262DEBUGGER_SINGLE_STEP_NOTIFY(); \263goto do_continue; \264}265266#define UPDATE_PC_AND_CONTINUE(opsize) { \267pc += opsize; opcode = *pc; \268DO_UPDATE_INSTRUCTION_COUNT(opcode); \269DEBUGGER_SINGLE_STEP_NOTIFY(); \270goto do_continue; \271}272#else273#define UPDATE_PC_AND_TOS_AND_CONTINUE(opsize, stack) { \274pc += opsize; MORE_STACK(stack); \275DO_UPDATE_INSTRUCTION_COUNT(opcode); \276DEBUGGER_SINGLE_STEP_NOTIFY(); \277goto do_continue; \278}279280#define UPDATE_PC_AND_CONTINUE(opsize) { \281pc += opsize; \282DO_UPDATE_INSTRUCTION_COUNT(opcode); \283DEBUGGER_SINGLE_STEP_NOTIFY(); \284goto do_continue; \285}286#endif /* PREFETCH_OPCCODE */287#endif /* USELABELS */288289// About to call a new method, update the save the adjusted pc and return to frame manager290#define UPDATE_PC_AND_RETURN(opsize) \291DECACHE_TOS(); \292istate->set_bcp(pc+opsize); \293return;294295296#define METHOD istate->method()297#define GET_METHOD_COUNTERS(res)298#define DO_BACKEDGE_CHECKS(skip, branch_pc)299300/*301* For those opcodes that need to have a GC point on a backwards branch302*/303304/*305* Macros for caching and flushing the interpreter state. Some local306* variables need to be flushed out to the frame before we do certain307* things (like pushing frames or becomming gc safe) and some need to308* be recached later (like after popping a frame). We could use one309* macro to cache or decache everything, but this would be less then310* optimal because we don't always need to cache or decache everything311* because some things we know are already cached or decached.312*/313#undef DECACHE_TOS314#undef CACHE_TOS315#undef CACHE_PREV_TOS316#define DECACHE_TOS() istate->set_stack(topOfStack);317318#define CACHE_TOS() topOfStack = (intptr_t *)istate->stack();319320#undef DECACHE_PC321#undef CACHE_PC322#define DECACHE_PC() istate->set_bcp(pc);323#define CACHE_PC() pc = istate->bcp();324#define CACHE_CP() cp = istate->constants();325#define CACHE_LOCALS() locals = istate->locals();326#undef CACHE_FRAME327#define CACHE_FRAME()328329// BCI() returns the current bytecode-index.330#undef BCI331#define BCI() ((int)(intptr_t)(pc - (intptr_t)istate->method()->code_base()))332333/*334* CHECK_NULL - Macro for throwing a NullPointerException if the object335* passed is a null ref.336* On some architectures/platforms it should be possible to do this implicitly337*/338#undef CHECK_NULL339#define CHECK_NULL(obj_) \340if ((obj_) == NULL) { \341VM_JAVA_ERROR(vmSymbols::java_lang_NullPointerException(), NULL); \342} \343VERIFY_OOP(obj_)344345#define VMdoubleConstZero() 0.0346#define VMdoubleConstOne() 1.0347#define VMlongConstZero() (max_jlong-max_jlong)348#define VMlongConstOne() ((max_jlong-max_jlong)+1)349350/*351* Alignment352*/353#define VMalignWordUp(val) (((uintptr_t)(val) + 3) & ~3)354355// Decache the interpreter state that interpreter modifies directly (i.e. GC is indirect mod)356#define DECACHE_STATE() DECACHE_PC(); DECACHE_TOS();357358// Reload interpreter state after calling the VM or a possible GC359#define CACHE_STATE() \360CACHE_TOS(); \361CACHE_PC(); \362CACHE_CP(); \363CACHE_LOCALS();364365// Call the VM with last java frame only.366#define CALL_VM_NAKED_LJF(func) \367DECACHE_STATE(); \368SET_LAST_JAVA_FRAME(); \369func; \370RESET_LAST_JAVA_FRAME(); \371CACHE_STATE();372373// Call the VM. Don't check for pending exceptions.374#define CALL_VM_NOCHECK(func) \375CALL_VM_NAKED_LJF(func) \376if (THREAD->has_pending_popframe() && \377!THREAD->pop_frame_in_process()) { \378goto handle_Pop_Frame; \379} \380if (THREAD->jvmti_thread_state() && \381THREAD->jvmti_thread_state()->is_earlyret_pending()) { \382goto handle_Early_Return; \383}384385// Call the VM and check for pending exceptions386#define CALL_VM(func, label) { \387CALL_VM_NOCHECK(func); \388if (THREAD->has_pending_exception()) goto label; \389}390391/*392* BytecodeInterpreter::run(interpreterState istate)393*394* The real deal. This is where byte codes actually get interpreted.395* Basically it's a big while loop that iterates until we return from396* the method passed in.397*/398399// Instantiate two variants of the method for future linking.400template void BytecodeInterpreter::run<true>(interpreterState istate);401template void BytecodeInterpreter::run<false>(interpreterState istate);402403template<bool JVMTI_ENABLED>404void BytecodeInterpreter::run(interpreterState istate) {405intptr_t* topOfStack = (intptr_t *)istate->stack(); /* access with STACK macros */406address pc = istate->bcp();407jubyte opcode;408intptr_t* locals = istate->locals();409ConstantPoolCache* cp = istate->constants(); // method()->constants()->cache()410#ifdef LOTS_OF_REGS411JavaThread* THREAD = istate->thread();412#else413#undef THREAD414#define THREAD istate->thread()415#endif416417#ifdef ASSERT418assert(labs(istate->stack_base() - istate->stack_limit()) == (istate->method()->max_stack() + 1),419"Bad stack limit");420/* QQQ this should be a stack method so we don't know actual direction */421assert(topOfStack >= istate->stack_limit() && topOfStack < istate->stack_base(),422"Stack top out of range");423424// Verify linkages.425interpreterState l = istate;426do {427assert(l == l->_self_link, "bad link");428l = l->_prev_link;429} while (l != NULL);430// Screwups with stack management usually cause us to overwrite istate431// save a copy so we can verify it.432interpreterState orig = istate;433#endif434435#ifdef USELABELS436const static void* const opclabels_data[256] = {437/* 0x00 */ &&opc_nop, &&opc_aconst_null, &&opc_iconst_m1, &&opc_iconst_0,438/* 0x04 */ &&opc_iconst_1, &&opc_iconst_2, &&opc_iconst_3, &&opc_iconst_4,439/* 0x08 */ &&opc_iconst_5, &&opc_lconst_0, &&opc_lconst_1, &&opc_fconst_0,440/* 0x0C */ &&opc_fconst_1, &&opc_fconst_2, &&opc_dconst_0, &&opc_dconst_1,441442/* 0x10 */ &&opc_bipush, &&opc_sipush, &&opc_ldc, &&opc_ldc_w,443/* 0x14 */ &&opc_ldc2_w, &&opc_iload, &&opc_lload, &&opc_fload,444/* 0x18 */ &&opc_dload, &&opc_aload, &&opc_iload_0, &&opc_iload_1,445/* 0x1C */ &&opc_iload_2, &&opc_iload_3, &&opc_lload_0, &&opc_lload_1,446447/* 0x20 */ &&opc_lload_2, &&opc_lload_3, &&opc_fload_0, &&opc_fload_1,448/* 0x24 */ &&opc_fload_2, &&opc_fload_3, &&opc_dload_0, &&opc_dload_1,449/* 0x28 */ &&opc_dload_2, &&opc_dload_3, &&opc_aload_0, &&opc_aload_1,450/* 0x2C */ &&opc_aload_2, &&opc_aload_3, &&opc_iaload, &&opc_laload,451452/* 0x30 */ &&opc_faload, &&opc_daload, &&opc_aaload, &&opc_baload,453/* 0x34 */ &&opc_caload, &&opc_saload, &&opc_istore, &&opc_lstore,454/* 0x38 */ &&opc_fstore, &&opc_dstore, &&opc_astore, &&opc_istore_0,455/* 0x3C */ &&opc_istore_1, &&opc_istore_2, &&opc_istore_3, &&opc_lstore_0,456457/* 0x40 */ &&opc_lstore_1, &&opc_lstore_2, &&opc_lstore_3, &&opc_fstore_0,458/* 0x44 */ &&opc_fstore_1, &&opc_fstore_2, &&opc_fstore_3, &&opc_dstore_0,459/* 0x48 */ &&opc_dstore_1, &&opc_dstore_2, &&opc_dstore_3, &&opc_astore_0,460/* 0x4C */ &&opc_astore_1, &&opc_astore_2, &&opc_astore_3, &&opc_iastore,461462/* 0x50 */ &&opc_lastore, &&opc_fastore, &&opc_dastore, &&opc_aastore,463/* 0x54 */ &&opc_bastore, &&opc_castore, &&opc_sastore, &&opc_pop,464/* 0x58 */ &&opc_pop2, &&opc_dup, &&opc_dup_x1, &&opc_dup_x2,465/* 0x5C */ &&opc_dup2, &&opc_dup2_x1, &&opc_dup2_x2, &&opc_swap,466467/* 0x60 */ &&opc_iadd, &&opc_ladd, &&opc_fadd, &&opc_dadd,468/* 0x64 */ &&opc_isub, &&opc_lsub, &&opc_fsub, &&opc_dsub,469/* 0x68 */ &&opc_imul, &&opc_lmul, &&opc_fmul, &&opc_dmul,470/* 0x6C */ &&opc_idiv, &&opc_ldiv, &&opc_fdiv, &&opc_ddiv,471472/* 0x70 */ &&opc_irem, &&opc_lrem, &&opc_frem, &&opc_drem,473/* 0x74 */ &&opc_ineg, &&opc_lneg, &&opc_fneg, &&opc_dneg,474/* 0x78 */ &&opc_ishl, &&opc_lshl, &&opc_ishr, &&opc_lshr,475/* 0x7C */ &&opc_iushr, &&opc_lushr, &&opc_iand, &&opc_land,476477/* 0x80 */ &&opc_ior, &&opc_lor, &&opc_ixor, &&opc_lxor,478/* 0x84 */ &&opc_iinc, &&opc_i2l, &&opc_i2f, &&opc_i2d,479/* 0x88 */ &&opc_l2i, &&opc_l2f, &&opc_l2d, &&opc_f2i,480/* 0x8C */ &&opc_f2l, &&opc_f2d, &&opc_d2i, &&opc_d2l,481482/* 0x90 */ &&opc_d2f, &&opc_i2b, &&opc_i2c, &&opc_i2s,483/* 0x94 */ &&opc_lcmp, &&opc_fcmpl, &&opc_fcmpg, &&opc_dcmpl,484/* 0x98 */ &&opc_dcmpg, &&opc_ifeq, &&opc_ifne, &&opc_iflt,485/* 0x9C */ &&opc_ifge, &&opc_ifgt, &&opc_ifle, &&opc_if_icmpeq,486487/* 0xA0 */ &&opc_if_icmpne, &&opc_if_icmplt, &&opc_if_icmpge, &&opc_if_icmpgt,488/* 0xA4 */ &&opc_if_icmple, &&opc_if_acmpeq, &&opc_if_acmpne, &&opc_goto,489/* 0xA8 */ &&opc_jsr, &&opc_ret, &&opc_tableswitch, &&opc_lookupswitch,490/* 0xAC */ &&opc_ireturn, &&opc_lreturn, &&opc_freturn, &&opc_dreturn,491492/* 0xB0 */ &&opc_areturn, &&opc_return, &&opc_getstatic, &&opc_putstatic,493/* 0xB4 */ &&opc_getfield, &&opc_putfield, &&opc_invokevirtual, &&opc_invokespecial,494/* 0xB8 */ &&opc_invokestatic, &&opc_invokeinterface, &&opc_invokedynamic, &&opc_new,495/* 0xBC */ &&opc_newarray, &&opc_anewarray, &&opc_arraylength, &&opc_athrow,496497/* 0xC0 */ &&opc_checkcast, &&opc_instanceof, &&opc_monitorenter, &&opc_monitorexit,498/* 0xC4 */ &&opc_wide, &&opc_multianewarray, &&opc_ifnull, &&opc_ifnonnull,499/* 0xC8 */ &&opc_goto_w, &&opc_jsr_w, &&opc_breakpoint, &&opc_default,500/* 0xCC */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,501502/* 0xD0 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,503/* 0xD4 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,504/* 0xD8 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,505/* 0xDC */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,506507/* 0xE0 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,508/* 0xE4 */ &&opc_default, &&opc_default, &&opc_fast_aldc, &&opc_fast_aldc_w,509/* 0xE8 */ &&opc_return_register_finalizer,510&&opc_invokehandle, &&opc_default, &&opc_default,511/* 0xEC */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,512513/* 0xF0 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,514/* 0xF4 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,515/* 0xF8 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,516/* 0xFC */ &&opc_default, &&opc_default, &&opc_default, &&opc_default517};518uintptr_t *dispatch_table = (uintptr_t*)&opclabels_data[0];519#endif /* USELABELS */520521switch (istate->msg()) {522case initialize: {523ShouldNotCallThis();524return;525}526case method_entry: {527THREAD->set_do_not_unlock();528529// Lock method if synchronized.530if (METHOD->is_synchronized()) {531// oop rcvr = locals[0].j.r;532oop rcvr;533if (METHOD->is_static()) {534rcvr = METHOD->constants()->pool_holder()->java_mirror();535} else {536rcvr = LOCALS_OBJECT(0);537VERIFY_OOP(rcvr);538}539540// The initial monitor is ours for the taking.541// Monitor not filled in frame manager any longer as this caused race condition with biased locking.542BasicObjectLock* mon = &istate->monitor_base()[-1];543mon->set_obj(rcvr);544545assert(!UseBiasedLocking, "Not implemented");546547// Traditional lightweight locking.548markWord displaced = rcvr->mark().set_unlocked();549mon->lock()->set_displaced_header(displaced);550bool call_vm = UseHeavyMonitors;551if (call_vm || rcvr->cas_set_mark(markWord::from_pointer(mon), displaced) != displaced) {552// Is it simple recursive case?553if (!call_vm && THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) {554mon->lock()->set_displaced_header(markWord::from_pointer(NULL));555} else {556CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);557}558}559}560THREAD->clr_do_not_unlock();561562// Notify jvmti.563// Whenever JVMTI puts a thread in interp_only_mode, method564// entry/exit events are sent for that thread to track stack depth.565if (JVMTI_ENABLED && THREAD->is_interp_only_mode()) {566CALL_VM(InterpreterRuntime::post_method_entry(THREAD),567handle_exception);568}569570goto run;571}572573case popping_frame: {574// returned from a java call to pop the frame, restart the call575// clear the message so we don't confuse ourselves later576assert(THREAD->pop_frame_in_process(), "wrong frame pop state");577istate->set_msg(no_request);578THREAD->clr_pop_frame_in_process();579goto run;580}581582case method_resume: {583if ((istate->_stack_base - istate->_stack_limit) != istate->method()->max_stack() + 1) {584// resume585os::breakpoint();586}587// returned from a java call, continue executing.588if (THREAD->has_pending_popframe() && !THREAD->pop_frame_in_process()) {589goto handle_Pop_Frame;590}591if (THREAD->jvmti_thread_state() &&592THREAD->jvmti_thread_state()->is_earlyret_pending()) {593goto handle_Early_Return;594}595596if (THREAD->has_pending_exception()) goto handle_exception;597// Update the pc by the saved amount of the invoke bytecode size598UPDATE_PC(istate->bcp_advance());599goto run;600}601602case deopt_resume2: {603// Returned from an opcode that will reexecute. Deopt was604// a result of a PopFrame request.605//606goto run;607}608609case deopt_resume: {610// Returned from an opcode that has completed. The stack has611// the result all we need to do is skip across the bytecode612// and continue (assuming there is no exception pending)613//614// compute continuation length615//616// Note: it is possible to deopt at a return_register_finalizer opcode617// because this requires entering the vm to do the registering. While the618// opcode is complete we can't advance because there are no more opcodes619// much like trying to deopt at a poll return. In that has we simply620// get out of here621//622if ( Bytecodes::code_at(METHOD, pc) == Bytecodes::_return_register_finalizer) {623// this will do the right thing even if an exception is pending.624goto handle_return;625}626UPDATE_PC(Bytecodes::length_at(METHOD, pc));627if (THREAD->has_pending_exception()) goto handle_exception;628goto run;629}630case got_monitors: {631// continue locking now that we have a monitor to use632// we expect to find newly allocated monitor at the "top" of the monitor stack.633oop lockee = STACK_OBJECT(-1);634VERIFY_OOP(lockee);635// derefing's lockee ought to provoke implicit null check636// find a free monitor637BasicObjectLock* entry = (BasicObjectLock*) istate->stack_base();638assert(entry->obj() == NULL, "Frame manager didn't allocate the monitor");639entry->set_obj(lockee);640641assert(!UseBiasedLocking, "Not implemented");642643// traditional lightweight locking644markWord displaced = lockee->mark().set_unlocked();645entry->lock()->set_displaced_header(displaced);646bool call_vm = UseHeavyMonitors;647if (call_vm || lockee->cas_set_mark(markWord::from_pointer(entry), displaced) != displaced) {648// Is it simple recursive case?649if (!call_vm && THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) {650entry->lock()->set_displaced_header(markWord::from_pointer(NULL));651} else {652CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);653}654}655UPDATE_PC_AND_TOS(1, -1);656goto run;657}658default: {659fatal("Unexpected message from frame manager");660}661}662663run:664665DO_UPDATE_INSTRUCTION_COUNT(*pc)666DEBUGGER_SINGLE_STEP_NOTIFY();667#ifdef PREFETCH_OPCCODE668opcode = *pc; /* prefetch first opcode */669#endif670671#ifndef USELABELS672while (1)673#endif674{675#ifndef PREFETCH_OPCCODE676opcode = *pc;677#endif678// Seems like this happens twice per opcode. At worst this is only679// need at entry to the loop.680// DEBUGGER_SINGLE_STEP_NOTIFY();681/* Using this labels avoids double breakpoints when quickening and682* when returing from transition frames.683*/684opcode_switch:685assert(istate == orig, "Corrupted istate");686/* QQQ Hmm this has knowledge of direction, ought to be a stack method */687assert(topOfStack >= istate->stack_limit(), "Stack overrun");688assert(topOfStack < istate->stack_base(), "Stack underrun");689690#ifdef USELABELS691DISPATCH(opcode);692#else693switch (opcode)694#endif695{696CASE(_nop):697UPDATE_PC_AND_CONTINUE(1);698699/* Push miscellaneous constants onto the stack. */700701CASE(_aconst_null):702SET_STACK_OBJECT(NULL, 0);703UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);704705#undef OPC_CONST_n706#define OPC_CONST_n(opcode, const_type, value) \707CASE(opcode): \708SET_STACK_ ## const_type(value, 0); \709UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);710711OPC_CONST_n(_iconst_m1, INT, -1);712OPC_CONST_n(_iconst_0, INT, 0);713OPC_CONST_n(_iconst_1, INT, 1);714OPC_CONST_n(_iconst_2, INT, 2);715OPC_CONST_n(_iconst_3, INT, 3);716OPC_CONST_n(_iconst_4, INT, 4);717OPC_CONST_n(_iconst_5, INT, 5);718OPC_CONST_n(_fconst_0, FLOAT, 0.0);719OPC_CONST_n(_fconst_1, FLOAT, 1.0);720OPC_CONST_n(_fconst_2, FLOAT, 2.0);721722#undef OPC_CONST2_n723#define OPC_CONST2_n(opcname, value, key, kind) \724CASE(_##opcname): \725{ \726SET_STACK_ ## kind(VM##key##Const##value(), 1); \727UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2); \728}729OPC_CONST2_n(dconst_0, Zero, double, DOUBLE);730OPC_CONST2_n(dconst_1, One, double, DOUBLE);731OPC_CONST2_n(lconst_0, Zero, long, LONG);732OPC_CONST2_n(lconst_1, One, long, LONG);733734/* Load constant from constant pool: */735736/* Push a 1-byte signed integer value onto the stack. */737CASE(_bipush):738SET_STACK_INT((jbyte)(pc[1]), 0);739UPDATE_PC_AND_TOS_AND_CONTINUE(2, 1);740741/* Push a 2-byte signed integer constant onto the stack. */742CASE(_sipush):743SET_STACK_INT((int16_t)Bytes::get_Java_u2(pc + 1), 0);744UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1);745746/* load from local variable */747748CASE(_aload):749VERIFY_OOP(LOCALS_OBJECT(pc[1]));750SET_STACK_OBJECT(LOCALS_OBJECT(pc[1]), 0);751UPDATE_PC_AND_TOS_AND_CONTINUE(2, 1);752753CASE(_iload):754CASE(_fload):755SET_STACK_SLOT(LOCALS_SLOT(pc[1]), 0);756UPDATE_PC_AND_TOS_AND_CONTINUE(2, 1);757758CASE(_lload):759SET_STACK_LONG_FROM_ADDR(LOCALS_LONG_AT(pc[1]), 1);760UPDATE_PC_AND_TOS_AND_CONTINUE(2, 2);761762CASE(_dload):763SET_STACK_DOUBLE_FROM_ADDR(LOCALS_DOUBLE_AT(pc[1]), 1);764UPDATE_PC_AND_TOS_AND_CONTINUE(2, 2);765766#undef OPC_LOAD_n767#define OPC_LOAD_n(num) \768CASE(_aload_##num): \769VERIFY_OOP(LOCALS_OBJECT(num)); \770SET_STACK_OBJECT(LOCALS_OBJECT(num), 0); \771UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1); \772\773CASE(_iload_##num): \774CASE(_fload_##num): \775SET_STACK_SLOT(LOCALS_SLOT(num), 0); \776UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1); \777\778CASE(_lload_##num): \779SET_STACK_LONG_FROM_ADDR(LOCALS_LONG_AT(num), 1); \780UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2); \781CASE(_dload_##num): \782SET_STACK_DOUBLE_FROM_ADDR(LOCALS_DOUBLE_AT(num), 1); \783UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);784785OPC_LOAD_n(0);786OPC_LOAD_n(1);787OPC_LOAD_n(2);788OPC_LOAD_n(3);789790/* store to a local variable */791792CASE(_astore):793astore(topOfStack, -1, locals, pc[1]);794UPDATE_PC_AND_TOS_AND_CONTINUE(2, -1);795796CASE(_istore):797CASE(_fstore):798SET_LOCALS_SLOT(STACK_SLOT(-1), pc[1]);799UPDATE_PC_AND_TOS_AND_CONTINUE(2, -1);800801CASE(_lstore):802SET_LOCALS_LONG(STACK_LONG(-1), pc[1]);803UPDATE_PC_AND_TOS_AND_CONTINUE(2, -2);804805CASE(_dstore):806SET_LOCALS_DOUBLE(STACK_DOUBLE(-1), pc[1]);807UPDATE_PC_AND_TOS_AND_CONTINUE(2, -2);808809CASE(_wide): {810uint16_t reg = Bytes::get_Java_u2(pc + 2);811812opcode = pc[1];813814// Wide and it's sub-bytecode are counted as separate instructions. If we815// don't account for this here, the bytecode trace skips the next bytecode.816DO_UPDATE_INSTRUCTION_COUNT(opcode);817818switch(opcode) {819case Bytecodes::_aload:820VERIFY_OOP(LOCALS_OBJECT(reg));821SET_STACK_OBJECT(LOCALS_OBJECT(reg), 0);822UPDATE_PC_AND_TOS_AND_CONTINUE(4, 1);823824case Bytecodes::_iload:825case Bytecodes::_fload:826SET_STACK_SLOT(LOCALS_SLOT(reg), 0);827UPDATE_PC_AND_TOS_AND_CONTINUE(4, 1);828829case Bytecodes::_lload:830SET_STACK_LONG_FROM_ADDR(LOCALS_LONG_AT(reg), 1);831UPDATE_PC_AND_TOS_AND_CONTINUE(4, 2);832833case Bytecodes::_dload:834SET_STACK_DOUBLE_FROM_ADDR(LOCALS_LONG_AT(reg), 1);835UPDATE_PC_AND_TOS_AND_CONTINUE(4, 2);836837case Bytecodes::_astore:838astore(topOfStack, -1, locals, reg);839UPDATE_PC_AND_TOS_AND_CONTINUE(4, -1);840841case Bytecodes::_istore:842case Bytecodes::_fstore:843SET_LOCALS_SLOT(STACK_SLOT(-1), reg);844UPDATE_PC_AND_TOS_AND_CONTINUE(4, -1);845846case Bytecodes::_lstore:847SET_LOCALS_LONG(STACK_LONG(-1), reg);848UPDATE_PC_AND_TOS_AND_CONTINUE(4, -2);849850case Bytecodes::_dstore:851SET_LOCALS_DOUBLE(STACK_DOUBLE(-1), reg);852UPDATE_PC_AND_TOS_AND_CONTINUE(4, -2);853854case Bytecodes::_iinc: {855int16_t offset = (int16_t)Bytes::get_Java_u2(pc+4);856// Be nice to see what this generates.... QQQ857SET_LOCALS_INT(LOCALS_INT(reg) + offset, reg);858UPDATE_PC_AND_CONTINUE(6);859}860case Bytecodes::_ret:861pc = istate->method()->code_base() + (intptr_t)(LOCALS_ADDR(reg));862UPDATE_PC_AND_CONTINUE(0);863default:864VM_JAVA_ERROR(vmSymbols::java_lang_InternalError(), "undefined opcode");865}866}867868869#undef OPC_STORE_n870#define OPC_STORE_n(num) \871CASE(_astore_##num): \872astore(topOfStack, -1, locals, num); \873UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); \874CASE(_istore_##num): \875CASE(_fstore_##num): \876SET_LOCALS_SLOT(STACK_SLOT(-1), num); \877UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);878879OPC_STORE_n(0);880OPC_STORE_n(1);881OPC_STORE_n(2);882OPC_STORE_n(3);883884#undef OPC_DSTORE_n885#define OPC_DSTORE_n(num) \886CASE(_dstore_##num): \887SET_LOCALS_DOUBLE(STACK_DOUBLE(-1), num); \888UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2); \889CASE(_lstore_##num): \890SET_LOCALS_LONG(STACK_LONG(-1), num); \891UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2);892893OPC_DSTORE_n(0);894OPC_DSTORE_n(1);895OPC_DSTORE_n(2);896OPC_DSTORE_n(3);897898/* stack pop, dup, and insert opcodes */899900901CASE(_pop): /* Discard the top item on the stack */902UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);903904905CASE(_pop2): /* Discard the top 2 items on the stack */906UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2);907908909CASE(_dup): /* Duplicate the top item on the stack */910dup(topOfStack);911UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);912913CASE(_dup2): /* Duplicate the top 2 items on the stack */914dup2(topOfStack);915UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);916917CASE(_dup_x1): /* insert top word two down */918dup_x1(topOfStack);919UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);920921CASE(_dup_x2): /* insert top word three down */922dup_x2(topOfStack);923UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);924925CASE(_dup2_x1): /* insert top 2 slots three down */926dup2_x1(topOfStack);927UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);928929CASE(_dup2_x2): /* insert top 2 slots four down */930dup2_x2(topOfStack);931UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);932933CASE(_swap): { /* swap top two elements on the stack */934swap(topOfStack);935UPDATE_PC_AND_CONTINUE(1);936}937938/* Perform various binary integer operations */939940#undef OPC_INT_BINARY941#define OPC_INT_BINARY(opcname, opname, test) \942CASE(_i##opcname): \943if (test && (STACK_INT(-1) == 0)) { \944VM_JAVA_ERROR(vmSymbols::java_lang_ArithmeticException(), \945"/ by zero"); \946} \947SET_STACK_INT(VMint##opname(STACK_INT(-2), \948STACK_INT(-1)), \949-2); \950UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); \951CASE(_l##opcname): \952{ \953if (test) { \954jlong l1 = STACK_LONG(-1); \955if (VMlongEqz(l1)) { \956VM_JAVA_ERROR(vmSymbols::java_lang_ArithmeticException(), \957"/ by long zero"); \958} \959} \960/* First long at (-1,-2) next long at (-3,-4) */ \961SET_STACK_LONG(VMlong##opname(STACK_LONG(-3), \962STACK_LONG(-1)), \963-3); \964UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2); \965}966967OPC_INT_BINARY(add, Add, 0);968OPC_INT_BINARY(sub, Sub, 0);969OPC_INT_BINARY(mul, Mul, 0);970OPC_INT_BINARY(and, And, 0);971OPC_INT_BINARY(or, Or, 0);972OPC_INT_BINARY(xor, Xor, 0);973OPC_INT_BINARY(div, Div, 1);974OPC_INT_BINARY(rem, Rem, 1);975976977/* Perform various binary floating number operations */978/* On some machine/platforms/compilers div zero check can be implicit */979980#undef OPC_FLOAT_BINARY981#define OPC_FLOAT_BINARY(opcname, opname) \982CASE(_d##opcname): { \983SET_STACK_DOUBLE(VMdouble##opname(STACK_DOUBLE(-3), \984STACK_DOUBLE(-1)), \985-3); \986UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2); \987} \988CASE(_f##opcname): \989SET_STACK_FLOAT(VMfloat##opname(STACK_FLOAT(-2), \990STACK_FLOAT(-1)), \991-2); \992UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);993994995OPC_FLOAT_BINARY(add, Add);996OPC_FLOAT_BINARY(sub, Sub);997OPC_FLOAT_BINARY(mul, Mul);998OPC_FLOAT_BINARY(div, Div);999OPC_FLOAT_BINARY(rem, Rem);10001001/* Shift operations1002* Shift left int and long: ishl, lshl1003* Logical shift right int and long w/zero extension: iushr, lushr1004* Arithmetic shift right int and long w/sign extension: ishr, lshr1005*/10061007#undef OPC_SHIFT_BINARY1008#define OPC_SHIFT_BINARY(opcname, opname) \1009CASE(_i##opcname): \1010SET_STACK_INT(VMint##opname(STACK_INT(-2), \1011STACK_INT(-1)), \1012-2); \1013UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); \1014CASE(_l##opcname): \1015{ \1016SET_STACK_LONG(VMlong##opname(STACK_LONG(-2), \1017STACK_INT(-1)), \1018-2); \1019UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); \1020}10211022OPC_SHIFT_BINARY(shl, Shl);1023OPC_SHIFT_BINARY(shr, Shr);1024OPC_SHIFT_BINARY(ushr, Ushr);10251026/* Increment local variable by constant */1027CASE(_iinc):1028{1029// locals[pc[1]].j.i += (jbyte)(pc[2]);1030SET_LOCALS_INT(LOCALS_INT(pc[1]) + (jbyte)(pc[2]), pc[1]);1031UPDATE_PC_AND_CONTINUE(3);1032}10331034/* negate the value on the top of the stack */10351036CASE(_ineg):1037SET_STACK_INT(VMintNeg(STACK_INT(-1)), -1);1038UPDATE_PC_AND_CONTINUE(1);10391040CASE(_fneg):1041SET_STACK_FLOAT(VMfloatNeg(STACK_FLOAT(-1)), -1);1042UPDATE_PC_AND_CONTINUE(1);10431044CASE(_lneg):1045{1046SET_STACK_LONG(VMlongNeg(STACK_LONG(-1)), -1);1047UPDATE_PC_AND_CONTINUE(1);1048}10491050CASE(_dneg):1051{1052SET_STACK_DOUBLE(VMdoubleNeg(STACK_DOUBLE(-1)), -1);1053UPDATE_PC_AND_CONTINUE(1);1054}10551056/* Conversion operations */10571058CASE(_i2f): /* convert top of stack int to float */1059SET_STACK_FLOAT(VMint2Float(STACK_INT(-1)), -1);1060UPDATE_PC_AND_CONTINUE(1);10611062CASE(_i2l): /* convert top of stack int to long */1063{1064// this is ugly QQQ1065jlong r = VMint2Long(STACK_INT(-1));1066MORE_STACK(-1); // Pop1067SET_STACK_LONG(r, 1);10681069UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);1070}10711072CASE(_i2d): /* convert top of stack int to double */1073{1074// this is ugly QQQ (why cast to jlong?? )1075jdouble r = (jlong)STACK_INT(-1);1076MORE_STACK(-1); // Pop1077SET_STACK_DOUBLE(r, 1);10781079UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);1080}10811082CASE(_l2i): /* convert top of stack long to int */1083{1084jint r = VMlong2Int(STACK_LONG(-1));1085MORE_STACK(-2); // Pop1086SET_STACK_INT(r, 0);1087UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);1088}10891090CASE(_l2f): /* convert top of stack long to float */1091{1092jlong r = STACK_LONG(-1);1093MORE_STACK(-2); // Pop1094SET_STACK_FLOAT(VMlong2Float(r), 0);1095UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);1096}10971098CASE(_l2d): /* convert top of stack long to double */1099{1100jlong r = STACK_LONG(-1);1101MORE_STACK(-2); // Pop1102SET_STACK_DOUBLE(VMlong2Double(r), 1);1103UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);1104}11051106CASE(_f2i): /* Convert top of stack float to int */1107SET_STACK_INT(SharedRuntime::f2i(STACK_FLOAT(-1)), -1);1108UPDATE_PC_AND_CONTINUE(1);11091110CASE(_f2l): /* convert top of stack float to long */1111{1112jlong r = SharedRuntime::f2l(STACK_FLOAT(-1));1113MORE_STACK(-1); // POP1114SET_STACK_LONG(r, 1);1115UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);1116}11171118CASE(_f2d): /* convert top of stack float to double */1119{1120jfloat f;1121jdouble r;1122f = STACK_FLOAT(-1);1123r = (jdouble) f;1124MORE_STACK(-1); // POP1125SET_STACK_DOUBLE(r, 1);1126UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);1127}11281129CASE(_d2i): /* convert top of stack double to int */1130{1131jint r1 = SharedRuntime::d2i(STACK_DOUBLE(-1));1132MORE_STACK(-2);1133SET_STACK_INT(r1, 0);1134UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);1135}11361137CASE(_d2f): /* convert top of stack double to float */1138{1139jfloat r1 = VMdouble2Float(STACK_DOUBLE(-1));1140MORE_STACK(-2);1141SET_STACK_FLOAT(r1, 0);1142UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);1143}11441145CASE(_d2l): /* convert top of stack double to long */1146{1147jlong r1 = SharedRuntime::d2l(STACK_DOUBLE(-1));1148MORE_STACK(-2);1149SET_STACK_LONG(r1, 1);1150UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);1151}11521153CASE(_i2b):1154SET_STACK_INT(VMint2Byte(STACK_INT(-1)), -1);1155UPDATE_PC_AND_CONTINUE(1);11561157CASE(_i2c):1158SET_STACK_INT(VMint2Char(STACK_INT(-1)), -1);1159UPDATE_PC_AND_CONTINUE(1);11601161CASE(_i2s):1162SET_STACK_INT(VMint2Short(STACK_INT(-1)), -1);1163UPDATE_PC_AND_CONTINUE(1);11641165/* comparison operators */116611671168#define COMPARISON_OP(name, comparison) \1169CASE(_if_icmp##name): { \1170int skip = (STACK_INT(-2) comparison STACK_INT(-1)) \1171? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \1172address branch_pc = pc; \1173UPDATE_PC_AND_TOS(skip, -2); \1174DO_BACKEDGE_CHECKS(skip, branch_pc); \1175CONTINUE; \1176} \1177CASE(_if##name): { \1178int skip = (STACK_INT(-1) comparison 0) \1179? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \1180address branch_pc = pc; \1181UPDATE_PC_AND_TOS(skip, -1); \1182DO_BACKEDGE_CHECKS(skip, branch_pc); \1183CONTINUE; \1184}11851186#define COMPARISON_OP2(name, comparison) \1187COMPARISON_OP(name, comparison) \1188CASE(_if_acmp##name): { \1189int skip = (STACK_OBJECT(-2) comparison STACK_OBJECT(-1)) \1190? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \1191address branch_pc = pc; \1192UPDATE_PC_AND_TOS(skip, -2); \1193DO_BACKEDGE_CHECKS(skip, branch_pc); \1194CONTINUE; \1195}11961197#define NULL_COMPARISON_NOT_OP(name) \1198CASE(_if##name): { \1199int skip = (!(STACK_OBJECT(-1) == NULL)) \1200? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \1201address branch_pc = pc; \1202UPDATE_PC_AND_TOS(skip, -1); \1203DO_BACKEDGE_CHECKS(skip, branch_pc); \1204CONTINUE; \1205}12061207#define NULL_COMPARISON_OP(name) \1208CASE(_if##name): { \1209int skip = ((STACK_OBJECT(-1) == NULL)) \1210? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \1211address branch_pc = pc; \1212UPDATE_PC_AND_TOS(skip, -1); \1213DO_BACKEDGE_CHECKS(skip, branch_pc); \1214CONTINUE; \1215}1216COMPARISON_OP(lt, <);1217COMPARISON_OP(gt, >);1218COMPARISON_OP(le, <=);1219COMPARISON_OP(ge, >=);1220COMPARISON_OP2(eq, ==); /* include ref comparison */1221COMPARISON_OP2(ne, !=); /* include ref comparison */1222NULL_COMPARISON_OP(null);1223NULL_COMPARISON_NOT_OP(nonnull);12241225/* Goto pc at specified offset in switch table. */12261227CASE(_tableswitch): {1228jint* lpc = (jint*)VMalignWordUp(pc+1);1229int32_t key = STACK_INT(-1);1230int32_t low = Bytes::get_Java_u4((address)&lpc[1]);1231int32_t high = Bytes::get_Java_u4((address)&lpc[2]);1232int32_t skip;1233key -= low;1234if (((uint32_t) key > (uint32_t)(high - low))) {1235skip = Bytes::get_Java_u4((address)&lpc[0]);1236} else {1237skip = Bytes::get_Java_u4((address)&lpc[key + 3]);1238}1239// Does this really need a full backedge check (osr)?1240address branch_pc = pc;1241UPDATE_PC_AND_TOS(skip, -1);1242DO_BACKEDGE_CHECKS(skip, branch_pc);1243CONTINUE;1244}12451246/* Goto pc whose table entry matches specified key. */12471248CASE(_lookupswitch): {1249jint* lpc = (jint*)VMalignWordUp(pc+1);1250int32_t key = STACK_INT(-1);1251int32_t skip = Bytes::get_Java_u4((address) lpc); /* default amount */1252int32_t npairs = Bytes::get_Java_u4((address) &lpc[1]);1253while (--npairs >= 0) {1254lpc += 2;1255if (key == (int32_t)Bytes::get_Java_u4((address)lpc)) {1256skip = Bytes::get_Java_u4((address)&lpc[1]);1257break;1258}1259}1260address branch_pc = pc;1261UPDATE_PC_AND_TOS(skip, -1);1262DO_BACKEDGE_CHECKS(skip, branch_pc);1263CONTINUE;1264}12651266CASE(_fcmpl):1267CASE(_fcmpg):1268{1269SET_STACK_INT(VMfloatCompare(STACK_FLOAT(-2),1270STACK_FLOAT(-1),1271(opcode == Bytecodes::_fcmpl ? -1 : 1)),1272-2);1273UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);1274}12751276CASE(_dcmpl):1277CASE(_dcmpg):1278{1279int r = VMdoubleCompare(STACK_DOUBLE(-3),1280STACK_DOUBLE(-1),1281(opcode == Bytecodes::_dcmpl ? -1 : 1));1282MORE_STACK(-4); // Pop1283SET_STACK_INT(r, 0);1284UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);1285}12861287CASE(_lcmp):1288{1289int r = VMlongCompare(STACK_LONG(-3), STACK_LONG(-1));1290MORE_STACK(-4);1291SET_STACK_INT(r, 0);1292UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);1293}129412951296/* Return from a method */12971298CASE(_areturn):1299CASE(_ireturn):1300CASE(_freturn):1301CASE(_lreturn):1302CASE(_dreturn):1303CASE(_return): {1304// Allow a safepoint before returning to frame manager.1305RETURN_SAFEPOINT;1306goto handle_return;1307}13081309CASE(_return_register_finalizer): {1310oop rcvr = LOCALS_OBJECT(0);1311VERIFY_OOP(rcvr);1312if (rcvr->klass()->has_finalizer()) {1313CALL_VM(InterpreterRuntime::register_finalizer(THREAD, rcvr), handle_exception);1314}1315goto handle_return;1316}13171318/* Array access byte-codes */13191320/* Every array access byte-code starts out like this */1321// arrayOopDesc* arrObj = (arrayOopDesc*)STACK_OBJECT(arrayOff);1322#define ARRAY_INTRO(arrayOff) \1323arrayOop arrObj = (arrayOop)STACK_OBJECT(arrayOff); \1324jint index = STACK_INT(arrayOff + 1); \1325/* Two integers, the additional message, and the null-terminator */ \1326char message[2 * jintAsStringSize + 33]; \1327CHECK_NULL(arrObj); \1328if ((uint32_t)index >= (uint32_t)arrObj->length()) { \1329jio_snprintf(message, sizeof(message), \1330"Index %d out of bounds for length %d", \1331index, arrObj->length()); \1332VM_JAVA_ERROR(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), \1333message); \1334}13351336/* 32-bit loads. These handle conversion from < 32-bit types */1337#define ARRAY_LOADTO32(T, T2, format, stackRes, extra) \1338{ \1339ARRAY_INTRO(-2); \1340(void)extra; \1341SET_ ## stackRes(*(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)), \1342-2); \1343UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); \1344}13451346/* 64-bit loads */1347#define ARRAY_LOADTO64(T,T2, stackRes, extra) \1348{ \1349ARRAY_INTRO(-2); \1350SET_ ## stackRes(*(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)), -1); \1351(void)extra; \1352UPDATE_PC_AND_CONTINUE(1); \1353}13541355CASE(_iaload):1356ARRAY_LOADTO32(T_INT, jint, "%d", STACK_INT, 0);1357CASE(_faload):1358ARRAY_LOADTO32(T_FLOAT, jfloat, "%f", STACK_FLOAT, 0);1359CASE(_aaload): {1360ARRAY_INTRO(-2);1361SET_STACK_OBJECT(((objArrayOop) arrObj)->obj_at(index), -2);1362UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);1363}1364CASE(_baload):1365ARRAY_LOADTO32(T_BYTE, jbyte, "%d", STACK_INT, 0);1366CASE(_caload):1367ARRAY_LOADTO32(T_CHAR, jchar, "%d", STACK_INT, 0);1368CASE(_saload):1369ARRAY_LOADTO32(T_SHORT, jshort, "%d", STACK_INT, 0);1370CASE(_laload):1371ARRAY_LOADTO64(T_LONG, jlong, STACK_LONG, 0);1372CASE(_daload):1373ARRAY_LOADTO64(T_DOUBLE, jdouble, STACK_DOUBLE, 0);13741375/* 32-bit stores. These handle conversion to < 32-bit types */1376#define ARRAY_STOREFROM32(T, T2, format, stackSrc, extra) \1377{ \1378ARRAY_INTRO(-3); \1379(void)extra; \1380*(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)) = stackSrc( -1); \1381UPDATE_PC_AND_TOS_AND_CONTINUE(1, -3); \1382}13831384/* 64-bit stores */1385#define ARRAY_STOREFROM64(T, T2, stackSrc, extra) \1386{ \1387ARRAY_INTRO(-4); \1388(void)extra; \1389*(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)) = stackSrc( -1); \1390UPDATE_PC_AND_TOS_AND_CONTINUE(1, -4); \1391}13921393CASE(_iastore):1394ARRAY_STOREFROM32(T_INT, jint, "%d", STACK_INT, 0);1395CASE(_fastore):1396ARRAY_STOREFROM32(T_FLOAT, jfloat, "%f", STACK_FLOAT, 0);1397/*1398* This one looks different because of the assignability check1399*/1400CASE(_aastore): {1401oop rhsObject = STACK_OBJECT(-1);1402VERIFY_OOP(rhsObject);1403ARRAY_INTRO( -3);1404// arrObj, index are set1405if (rhsObject != NULL) {1406/* Check assignability of rhsObject into arrObj */1407Klass* rhsKlass = rhsObject->klass(); // EBX (subclass)1408Klass* elemKlass = ObjArrayKlass::cast(arrObj->klass())->element_klass(); // superklass EAX1409//1410// Check for compatibilty. This check must not GC!!1411// Seems way more expensive now that we must dispatch1412//1413if (rhsKlass != elemKlass && !rhsKlass->is_subtype_of(elemKlass)) { // ebx->is...1414VM_JAVA_ERROR(vmSymbols::java_lang_ArrayStoreException(), "");1415}1416}1417((objArrayOop) arrObj)->obj_at_put(index, rhsObject);1418UPDATE_PC_AND_TOS_AND_CONTINUE(1, -3);1419}1420CASE(_bastore): {1421ARRAY_INTRO(-3);1422int item = STACK_INT(-1);1423// if it is a T_BOOLEAN array, mask the stored value to 0/11424if (arrObj->klass() == Universe::boolArrayKlassObj()) {1425item &= 1;1426} else {1427assert(arrObj->klass() == Universe::byteArrayKlassObj(),1428"should be byte array otherwise");1429}1430((typeArrayOop)arrObj)->byte_at_put(index, item);1431UPDATE_PC_AND_TOS_AND_CONTINUE(1, -3);1432}1433CASE(_castore):1434ARRAY_STOREFROM32(T_CHAR, jchar, "%d", STACK_INT, 0);1435CASE(_sastore):1436ARRAY_STOREFROM32(T_SHORT, jshort, "%d", STACK_INT, 0);1437CASE(_lastore):1438ARRAY_STOREFROM64(T_LONG, jlong, STACK_LONG, 0);1439CASE(_dastore):1440ARRAY_STOREFROM64(T_DOUBLE, jdouble, STACK_DOUBLE, 0);14411442CASE(_arraylength):1443{1444arrayOop ary = (arrayOop) STACK_OBJECT(-1);1445CHECK_NULL(ary);1446SET_STACK_INT(ary->length(), -1);1447UPDATE_PC_AND_CONTINUE(1);1448}14491450/* monitorenter and monitorexit for locking/unlocking an object */14511452CASE(_monitorenter): {1453oop lockee = STACK_OBJECT(-1);1454// derefing's lockee ought to provoke implicit null check1455CHECK_NULL(lockee);1456// find a free monitor or one already allocated for this object1457// if we find a matching object then we need a new monitor1458// since this is recursive enter1459BasicObjectLock* limit = istate->monitor_base();1460BasicObjectLock* most_recent = (BasicObjectLock*) istate->stack_base();1461BasicObjectLock* entry = NULL;1462while (most_recent != limit ) {1463if (most_recent->obj() == NULL) entry = most_recent;1464else if (most_recent->obj() == lockee) break;1465most_recent++;1466}1467if (entry != NULL) {1468entry->set_obj(lockee);14691470assert(!UseBiasedLocking, "Not implemented");14711472// traditional lightweight locking1473markWord displaced = lockee->mark().set_unlocked();1474entry->lock()->set_displaced_header(displaced);1475bool call_vm = UseHeavyMonitors;1476if (call_vm || lockee->cas_set_mark(markWord::from_pointer(entry), displaced) != displaced) {1477// Is it simple recursive case?1478if (!call_vm && THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) {1479entry->lock()->set_displaced_header(markWord::from_pointer(NULL));1480} else {1481CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);1482}1483}1484UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);1485} else {1486istate->set_msg(more_monitors);1487UPDATE_PC_AND_RETURN(0); // Re-execute1488}1489}14901491CASE(_monitorexit): {1492oop lockee = STACK_OBJECT(-1);1493CHECK_NULL(lockee);1494// derefing's lockee ought to provoke implicit null check1495// find our monitor slot1496BasicObjectLock* limit = istate->monitor_base();1497BasicObjectLock* most_recent = (BasicObjectLock*) istate->stack_base();1498while (most_recent != limit ) {1499if ((most_recent)->obj() == lockee) {1500BasicLock* lock = most_recent->lock();1501markWord header = lock->displaced_header();1502most_recent->set_obj(NULL);15031504assert(!UseBiasedLocking, "Not implemented");15051506// If it isn't recursive we either must swap old header or call the runtime1507bool call_vm = UseHeavyMonitors;1508if (header.to_pointer() != NULL || call_vm) {1509markWord old_header = markWord::encode(lock);1510if (call_vm || lockee->cas_set_mark(header, old_header) != old_header) {1511// restore object for the slow case1512most_recent->set_obj(lockee);1513InterpreterRuntime::monitorexit(most_recent);1514}1515}1516UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);1517}1518most_recent++;1519}1520// Need to throw illegal monitor state exception1521CALL_VM(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD), handle_exception);1522ShouldNotReachHere();1523}15241525/* All of the non-quick opcodes. */15261527/* -Set clobbersCpIndex true if the quickened opcode clobbers the1528* constant pool index in the instruction.1529*/1530CASE(_getfield):1531CASE(_getstatic):1532{1533u2 index;1534ConstantPoolCacheEntry* cache;1535index = Bytes::get_native_u2(pc+1);15361537// QQQ Need to make this as inlined as possible. Probably need to1538// split all the bytecode cases out so c++ compiler has a chance1539// for constant prop to fold everything possible away.15401541cache = cp->entry_at(index);1542if (!cache->is_resolved((Bytecodes::Code)opcode)) {1543CALL_VM(InterpreterRuntime::resolve_from_cache(THREAD, (Bytecodes::Code)opcode),1544handle_exception);1545cache = cp->entry_at(index);1546}15471548if (JVMTI_ENABLED) {1549int *count_addr;1550oop obj;1551// Check to see if a field modification watch has been set1552// before we take the time to call into the VM.1553count_addr = (int *)JvmtiExport::get_field_access_count_addr();1554if ( *count_addr > 0 ) {1555if ((Bytecodes::Code)opcode == Bytecodes::_getstatic) {1556obj = NULL;1557} else {1558obj = STACK_OBJECT(-1);1559VERIFY_OOP(obj);1560}1561CALL_VM(InterpreterRuntime::post_field_access(THREAD,1562obj,1563cache),1564handle_exception);1565}1566}15671568oop obj;1569if ((Bytecodes::Code)opcode == Bytecodes::_getstatic) {1570Klass* k = cache->f1_as_klass();1571obj = k->java_mirror();1572MORE_STACK(1); // Assume single slot push1573} else {1574obj = STACK_OBJECT(-1);1575CHECK_NULL(obj);1576}15771578//1579// Now store the result on the stack1580//1581TosState tos_type = cache->flag_state();1582int field_offset = cache->f2_as_index();1583if (cache->is_volatile()) {1584if (support_IRIW_for_not_multiple_copy_atomic_cpu) {1585OrderAccess::fence();1586}1587switch (tos_type) {1588case btos:1589case ztos:1590SET_STACK_INT(obj->byte_field_acquire(field_offset), -1);1591break;1592case ctos:1593SET_STACK_INT(obj->char_field_acquire(field_offset), -1);1594break;1595case stos:1596SET_STACK_INT(obj->short_field_acquire(field_offset), -1);1597break;1598case itos:1599SET_STACK_INT(obj->int_field_acquire(field_offset), -1);1600break;1601case ftos:1602SET_STACK_FLOAT(obj->float_field_acquire(field_offset), -1);1603break;1604case ltos:1605SET_STACK_LONG(obj->long_field_acquire(field_offset), 0);1606MORE_STACK(1);1607break;1608case dtos:1609SET_STACK_DOUBLE(obj->double_field_acquire(field_offset), 0);1610MORE_STACK(1);1611break;1612case atos: {1613oop val = obj->obj_field_acquire(field_offset);1614VERIFY_OOP(val);1615SET_STACK_OBJECT(val, -1);1616break;1617}1618default:1619ShouldNotReachHere();1620}1621} else {1622switch (tos_type) {1623case btos:1624case ztos:1625SET_STACK_INT(obj->byte_field(field_offset), -1);1626break;1627case ctos:1628SET_STACK_INT(obj->char_field(field_offset), -1);1629break;1630case stos:1631SET_STACK_INT(obj->short_field(field_offset), -1);1632break;1633case itos:1634SET_STACK_INT(obj->int_field(field_offset), -1);1635break;1636case ftos:1637SET_STACK_FLOAT(obj->float_field(field_offset), -1);1638break;1639case ltos:1640SET_STACK_LONG(obj->long_field(field_offset), 0);1641MORE_STACK(1);1642break;1643case dtos:1644SET_STACK_DOUBLE(obj->double_field(field_offset), 0);1645MORE_STACK(1);1646break;1647case atos: {1648oop val = obj->obj_field(field_offset);1649VERIFY_OOP(val);1650SET_STACK_OBJECT(val, -1);1651break;1652}1653default:1654ShouldNotReachHere();1655}1656}16571658UPDATE_PC_AND_CONTINUE(3);1659}16601661CASE(_putfield):1662CASE(_putstatic):1663{1664u2 index = Bytes::get_native_u2(pc+1);1665ConstantPoolCacheEntry* cache = cp->entry_at(index);1666if (!cache->is_resolved((Bytecodes::Code)opcode)) {1667CALL_VM(InterpreterRuntime::resolve_from_cache(THREAD, (Bytecodes::Code)opcode),1668handle_exception);1669cache = cp->entry_at(index);1670}16711672if (JVMTI_ENABLED) {1673int *count_addr;1674oop obj;1675// Check to see if a field modification watch has been set1676// before we take the time to call into the VM.1677count_addr = (int *)JvmtiExport::get_field_modification_count_addr();1678if ( *count_addr > 0 ) {1679if ((Bytecodes::Code)opcode == Bytecodes::_putstatic) {1680obj = NULL;1681}1682else {1683if (cache->is_long() || cache->is_double()) {1684obj = STACK_OBJECT(-3);1685} else {1686obj = STACK_OBJECT(-2);1687}1688VERIFY_OOP(obj);1689}16901691CALL_VM(InterpreterRuntime::post_field_modification(THREAD,1692obj,1693cache,1694(jvalue *)STACK_SLOT(-1)),1695handle_exception);1696}1697}16981699// QQQ Need to make this as inlined as possible. Probably need to split all the bytecode cases1700// out so c++ compiler has a chance for constant prop to fold everything possible away.17011702oop obj;1703int count;1704TosState tos_type = cache->flag_state();17051706count = -1;1707if (tos_type == ltos || tos_type == dtos) {1708--count;1709}1710if ((Bytecodes::Code)opcode == Bytecodes::_putstatic) {1711Klass* k = cache->f1_as_klass();1712obj = k->java_mirror();1713} else {1714--count;1715obj = STACK_OBJECT(count);1716CHECK_NULL(obj);1717}17181719//1720// Now store the result1721//1722int field_offset = cache->f2_as_index();1723if (cache->is_volatile()) {1724switch (tos_type) {1725case ztos:1726obj->release_byte_field_put(field_offset, (STACK_INT(-1) & 1)); // only store LSB1727break;1728case btos:1729obj->release_byte_field_put(field_offset, STACK_INT(-1));1730break;1731case ctos:1732obj->release_char_field_put(field_offset, STACK_INT(-1));1733break;1734case stos:1735obj->release_short_field_put(field_offset, STACK_INT(-1));1736break;1737case itos:1738obj->release_int_field_put(field_offset, STACK_INT(-1));1739break;1740case ftos:1741obj->release_float_field_put(field_offset, STACK_FLOAT(-1));1742break;1743case ltos:1744obj->release_long_field_put(field_offset, STACK_LONG(-1));1745break;1746case dtos:1747obj->release_double_field_put(field_offset, STACK_DOUBLE(-1));1748break;1749case atos: {1750oop val = STACK_OBJECT(-1);1751VERIFY_OOP(val);1752obj->release_obj_field_put(field_offset, val);1753break;1754}1755default:1756ShouldNotReachHere();1757}1758OrderAccess::storeload();1759} else {1760switch (tos_type) {1761case ztos:1762obj->byte_field_put(field_offset, (STACK_INT(-1) & 1)); // only store LSB1763break;1764case btos:1765obj->byte_field_put(field_offset, STACK_INT(-1));1766break;1767case ctos:1768obj->char_field_put(field_offset, STACK_INT(-1));1769break;1770case stos:1771obj->short_field_put(field_offset, STACK_INT(-1));1772break;1773case itos:1774obj->int_field_put(field_offset, STACK_INT(-1));1775break;1776case ftos:1777obj->float_field_put(field_offset, STACK_FLOAT(-1));1778break;1779case ltos:1780obj->long_field_put(field_offset, STACK_LONG(-1));1781break;1782case dtos:1783obj->double_field_put(field_offset, STACK_DOUBLE(-1));1784break;1785case atos: {1786oop val = STACK_OBJECT(-1);1787VERIFY_OOP(val);1788obj->obj_field_put(field_offset, val);1789break;1790}1791default:1792ShouldNotReachHere();1793}1794}17951796UPDATE_PC_AND_TOS_AND_CONTINUE(3, count);1797}17981799CASE(_new): {1800u2 index = Bytes::get_Java_u2(pc+1);18011802// Attempt TLAB allocation first.1803//1804// To do this, we need to make sure:1805// - klass is initialized1806// - klass can be fastpath allocated (e.g. does not have finalizer)1807// - TLAB accepts the allocation1808ConstantPool* constants = istate->method()->constants();1809if (UseTLAB && !constants->tag_at(index).is_unresolved_klass()) {1810Klass* entry = constants->resolved_klass_at(index);1811InstanceKlass* ik = InstanceKlass::cast(entry);1812if (ik->is_initialized() && ik->can_be_fastpath_allocated()) {1813size_t obj_size = ik->size_helper();1814HeapWord* result = THREAD->tlab().allocate(obj_size);1815if (result != NULL) {1816// Initialize object field block:1817// - if TLAB is pre-zeroed, we can skip this path1818// - in debug mode, ThreadLocalAllocBuffer::allocate mangles1819// this area, and we still need to initialize it1820if (DEBUG_ONLY(true ||) !ZeroTLAB) {1821size_t hdr_size = oopDesc::header_size();1822Copy::fill_to_words(result + hdr_size, obj_size - hdr_size, 0);1823}18241825oop obj = cast_to_oop(result);18261827// Initialize header1828assert(!UseBiasedLocking, "Not implemented");1829obj->set_mark(markWord::prototype());1830obj->set_klass_gap(0);1831obj->set_klass(ik);18321833// Must prevent reordering of stores for object initialization1834// with stores that publish the new object.1835OrderAccess::storestore();1836SET_STACK_OBJECT(obj, 0);1837UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1);1838}1839}1840}1841// Slow case allocation1842CALL_VM(InterpreterRuntime::_new(THREAD, METHOD->constants(), index),1843handle_exception);1844// Must prevent reordering of stores for object initialization1845// with stores that publish the new object.1846OrderAccess::storestore();1847SET_STACK_OBJECT(THREAD->vm_result(), 0);1848THREAD->set_vm_result(NULL);1849UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1);1850}1851CASE(_anewarray): {1852u2 index = Bytes::get_Java_u2(pc+1);1853jint size = STACK_INT(-1);1854CALL_VM(InterpreterRuntime::anewarray(THREAD, METHOD->constants(), index, size),1855handle_exception);1856// Must prevent reordering of stores for object initialization1857// with stores that publish the new object.1858OrderAccess::storestore();1859SET_STACK_OBJECT(THREAD->vm_result(), -1);1860THREAD->set_vm_result(NULL);1861UPDATE_PC_AND_CONTINUE(3);1862}1863CASE(_multianewarray): {1864jint dims = *(pc+3);1865jint size = STACK_INT(-1);1866// stack grows down, dimensions are up!1867jint *dimarray =1868(jint*)&topOfStack[dims * Interpreter::stackElementWords+1869Interpreter::stackElementWords-1];1870//adjust pointer to start of stack element1871CALL_VM(InterpreterRuntime::multianewarray(THREAD, dimarray),1872handle_exception);1873// Must prevent reordering of stores for object initialization1874// with stores that publish the new object.1875OrderAccess::storestore();1876SET_STACK_OBJECT(THREAD->vm_result(), -dims);1877THREAD->set_vm_result(NULL);1878UPDATE_PC_AND_TOS_AND_CONTINUE(4, -(dims-1));1879}1880CASE(_checkcast):1881if (STACK_OBJECT(-1) != NULL) {1882VERIFY_OOP(STACK_OBJECT(-1));1883u2 index = Bytes::get_Java_u2(pc+1);1884// Constant pool may have actual klass or unresolved klass. If it is1885// unresolved we must resolve it.1886if (METHOD->constants()->tag_at(index).is_unresolved_klass()) {1887CALL_VM(InterpreterRuntime::quicken_io_cc(THREAD), handle_exception);1888}1889Klass* klassOf = (Klass*) METHOD->constants()->resolved_klass_at(index);1890Klass* objKlass = STACK_OBJECT(-1)->klass(); // ebx1891//1892// Check for compatibilty. This check must not GC!!1893// Seems way more expensive now that we must dispatch.1894//1895if (objKlass != klassOf && !objKlass->is_subtype_of(klassOf)) {1896ResourceMark rm(THREAD);1897char* message = SharedRuntime::generate_class_cast_message(1898objKlass, klassOf);1899VM_JAVA_ERROR(vmSymbols::java_lang_ClassCastException(), message);1900}1901}1902UPDATE_PC_AND_CONTINUE(3);19031904CASE(_instanceof):1905if (STACK_OBJECT(-1) == NULL) {1906SET_STACK_INT(0, -1);1907} else {1908VERIFY_OOP(STACK_OBJECT(-1));1909u2 index = Bytes::get_Java_u2(pc+1);1910// Constant pool may have actual klass or unresolved klass. If it is1911// unresolved we must resolve it.1912if (METHOD->constants()->tag_at(index).is_unresolved_klass()) {1913CALL_VM(InterpreterRuntime::quicken_io_cc(THREAD), handle_exception);1914}1915Klass* klassOf = (Klass*) METHOD->constants()->resolved_klass_at(index);1916Klass* objKlass = STACK_OBJECT(-1)->klass();1917//1918// Check for compatibilty. This check must not GC!!1919// Seems way more expensive now that we must dispatch.1920//1921if ( objKlass == klassOf || objKlass->is_subtype_of(klassOf)) {1922SET_STACK_INT(1, -1);1923} else {1924SET_STACK_INT(0, -1);1925}1926}1927UPDATE_PC_AND_CONTINUE(3);19281929CASE(_ldc_w):1930CASE(_ldc):1931{1932u2 index;1933bool wide = false;1934int incr = 2; // frequent case1935if (opcode == Bytecodes::_ldc) {1936index = pc[1];1937} else {1938index = Bytes::get_Java_u2(pc+1);1939incr = 3;1940wide = true;1941}19421943ConstantPool* constants = METHOD->constants();1944switch (constants->tag_at(index).value()) {1945case JVM_CONSTANT_Integer:1946SET_STACK_INT(constants->int_at(index), 0);1947break;19481949case JVM_CONSTANT_Float:1950SET_STACK_FLOAT(constants->float_at(index), 0);1951break;19521953case JVM_CONSTANT_String:1954{1955oop result = constants->resolved_references()->obj_at(index);1956if (result == NULL) {1957CALL_VM(InterpreterRuntime::resolve_ldc(THREAD, (Bytecodes::Code) opcode), handle_exception);1958SET_STACK_OBJECT(THREAD->vm_result(), 0);1959THREAD->set_vm_result(NULL);1960} else {1961VERIFY_OOP(result);1962SET_STACK_OBJECT(result, 0);1963}1964break;1965}19661967case JVM_CONSTANT_Class:1968VERIFY_OOP(constants->resolved_klass_at(index)->java_mirror());1969SET_STACK_OBJECT(constants->resolved_klass_at(index)->java_mirror(), 0);1970break;19711972case JVM_CONSTANT_UnresolvedClass:1973case JVM_CONSTANT_UnresolvedClassInError:1974CALL_VM(InterpreterRuntime::ldc(THREAD, wide), handle_exception);1975SET_STACK_OBJECT(THREAD->vm_result(), 0);1976THREAD->set_vm_result(NULL);1977break;19781979case JVM_CONSTANT_Dynamic:1980case JVM_CONSTANT_DynamicInError:1981{1982CALL_VM(InterpreterRuntime::resolve_ldc(THREAD, (Bytecodes::Code) opcode), handle_exception);1983oop result = THREAD->vm_result();1984VERIFY_OOP(result);19851986jvalue value;1987BasicType type = java_lang_boxing_object::get_value(result, &value);1988switch (type) {1989case T_FLOAT: SET_STACK_FLOAT(value.f, 0); break;1990case T_INT: SET_STACK_INT(value.i, 0); break;1991case T_SHORT: SET_STACK_INT(value.s, 0); break;1992case T_BYTE: SET_STACK_INT(value.b, 0); break;1993case T_CHAR: SET_STACK_INT(value.c, 0); break;1994case T_BOOLEAN: SET_STACK_INT(value.z, 0); break;1995default: ShouldNotReachHere();1996}19971998break;1999}20002001default: ShouldNotReachHere();2002}2003UPDATE_PC_AND_TOS_AND_CONTINUE(incr, 1);2004}20052006CASE(_ldc2_w):2007{2008u2 index = Bytes::get_Java_u2(pc+1);20092010ConstantPool* constants = METHOD->constants();2011switch (constants->tag_at(index).value()) {20122013case JVM_CONSTANT_Long:2014SET_STACK_LONG(constants->long_at(index), 1);2015break;20162017case JVM_CONSTANT_Double:2018SET_STACK_DOUBLE(constants->double_at(index), 1);2019break;20202021case JVM_CONSTANT_Dynamic:2022case JVM_CONSTANT_DynamicInError:2023{2024CALL_VM(InterpreterRuntime::resolve_ldc(THREAD, (Bytecodes::Code) opcode), handle_exception);2025oop result = THREAD->vm_result();2026VERIFY_OOP(result);20272028jvalue value;2029BasicType type = java_lang_boxing_object::get_value(result, &value);2030switch (type) {2031case T_DOUBLE: SET_STACK_DOUBLE(value.d, 1); break;2032case T_LONG: SET_STACK_LONG(value.j, 1); break;2033default: ShouldNotReachHere();2034}20352036break;2037}20382039default: ShouldNotReachHere();2040}2041UPDATE_PC_AND_TOS_AND_CONTINUE(3, 2);2042}20432044CASE(_fast_aldc_w):2045CASE(_fast_aldc): {2046u2 index;2047int incr;2048if (opcode == Bytecodes::_fast_aldc) {2049index = pc[1];2050incr = 2;2051} else {2052index = Bytes::get_native_u2(pc+1);2053incr = 3;2054}20552056// We are resolved if the resolved_references array contains a non-null object (CallSite, etc.)2057// This kind of CP cache entry does not need to match the flags byte, because2058// there is a 1-1 relation between bytecode type and CP entry type.2059ConstantPool* constants = METHOD->constants();2060oop result = constants->resolved_references()->obj_at(index);2061if (result == NULL) {2062CALL_VM(InterpreterRuntime::resolve_ldc(THREAD, (Bytecodes::Code) opcode),2063handle_exception);2064result = THREAD->vm_result();2065}2066if (result == Universe::the_null_sentinel())2067result = NULL;20682069VERIFY_OOP(result);2070SET_STACK_OBJECT(result, 0);2071UPDATE_PC_AND_TOS_AND_CONTINUE(incr, 1);2072}20732074CASE(_invokedynamic): {20752076u4 index = Bytes::get_native_u4(pc+1);2077ConstantPoolCacheEntry* cache = cp->constant_pool()->invokedynamic_cp_cache_entry_at(index);20782079// We are resolved if the resolved_references array contains a non-null object (CallSite, etc.)2080// This kind of CP cache entry does not need to match the flags byte, because2081// there is a 1-1 relation between bytecode type and CP entry type.2082if (! cache->is_resolved((Bytecodes::Code) opcode)) {2083CALL_VM(InterpreterRuntime::resolve_from_cache(THREAD, (Bytecodes::Code)opcode),2084handle_exception);2085cache = cp->constant_pool()->invokedynamic_cp_cache_entry_at(index);2086}20872088Method* method = cache->f1_as_method();2089if (VerifyOops) method->verify();20902091if (cache->has_appendix()) {2092constantPoolHandle cp(THREAD, METHOD->constants());2093SET_STACK_OBJECT(cache->appendix_if_resolved(cp), 0);2094MORE_STACK(1);2095}20962097istate->set_msg(call_method);2098istate->set_callee(method);2099istate->set_callee_entry_point(method->from_interpreted_entry());2100istate->set_bcp_advance(5);21012102UPDATE_PC_AND_RETURN(0); // I'll be back...2103}21042105CASE(_invokehandle): {21062107u2 index = Bytes::get_native_u2(pc+1);2108ConstantPoolCacheEntry* cache = cp->entry_at(index);21092110if (! cache->is_resolved((Bytecodes::Code) opcode)) {2111CALL_VM(InterpreterRuntime::resolve_from_cache(THREAD, (Bytecodes::Code)opcode),2112handle_exception);2113cache = cp->entry_at(index);2114}21152116Method* method = cache->f1_as_method();2117if (VerifyOops) method->verify();21182119if (cache->has_appendix()) {2120constantPoolHandle cp(THREAD, METHOD->constants());2121SET_STACK_OBJECT(cache->appendix_if_resolved(cp), 0);2122MORE_STACK(1);2123}21242125istate->set_msg(call_method);2126istate->set_callee(method);2127istate->set_callee_entry_point(method->from_interpreted_entry());2128istate->set_bcp_advance(3);21292130UPDATE_PC_AND_RETURN(0); // I'll be back...2131}21322133CASE(_invokeinterface): {2134u2 index = Bytes::get_native_u2(pc+1);21352136// QQQ Need to make this as inlined as possible. Probably need to split all the bytecode cases2137// out so c++ compiler has a chance for constant prop to fold everything possible away.21382139ConstantPoolCacheEntry* cache = cp->entry_at(index);2140if (!cache->is_resolved((Bytecodes::Code)opcode)) {2141CALL_VM(InterpreterRuntime::resolve_from_cache(THREAD, (Bytecodes::Code)opcode),2142handle_exception);2143cache = cp->entry_at(index);2144}21452146istate->set_msg(call_method);21472148// Special case of invokeinterface called for virtual method of2149// java.lang.Object. See cpCache.cpp for details.2150Method* callee = NULL;2151if (cache->is_forced_virtual()) {2152CHECK_NULL(STACK_OBJECT(-(cache->parameter_size())));2153if (cache->is_vfinal()) {2154callee = cache->f2_as_vfinal_method();2155} else {2156// Get receiver.2157int parms = cache->parameter_size();2158// Same comments as invokevirtual apply here.2159oop rcvr = STACK_OBJECT(-parms);2160VERIFY_OOP(rcvr);2161Klass* rcvrKlass = rcvr->klass();2162callee = (Method*) rcvrKlass->method_at_vtable(cache->f2_as_index());2163}2164} else if (cache->is_vfinal()) {2165// private interface method invocations2166//2167// Ensure receiver class actually implements2168// the resolved interface class. The link resolver2169// does this, but only for the first time this2170// interface is being called.2171int parms = cache->parameter_size();2172oop rcvr = STACK_OBJECT(-parms);2173CHECK_NULL(rcvr);2174Klass* recv_klass = rcvr->klass();2175Klass* resolved_klass = cache->f1_as_klass();2176if (!recv_klass->is_subtype_of(resolved_klass)) {2177ResourceMark rm(THREAD);2178char buf[200];2179jio_snprintf(buf, sizeof(buf), "Class %s does not implement the requested interface %s",2180recv_klass->external_name(),2181resolved_klass->external_name());2182VM_JAVA_ERROR(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);2183}2184callee = cache->f2_as_vfinal_method();2185}2186if (callee != NULL) {2187istate->set_callee(callee);2188istate->set_callee_entry_point(callee->from_interpreted_entry());2189if (JVMTI_ENABLED && THREAD->is_interp_only_mode()) {2190istate->set_callee_entry_point(callee->interpreter_entry());2191}2192istate->set_bcp_advance(5);2193UPDATE_PC_AND_RETURN(0); // I'll be back...2194}21952196// this could definitely be cleaned up QQQ2197Method *interface_method = cache->f2_as_interface_method();2198InstanceKlass* iclass = interface_method->method_holder();21992200// get receiver2201int parms = cache->parameter_size();2202oop rcvr = STACK_OBJECT(-parms);2203CHECK_NULL(rcvr);2204InstanceKlass* int2 = (InstanceKlass*) rcvr->klass();22052206// Receiver subtype check against resolved interface klass (REFC).2207{2208Klass* refc = cache->f1_as_klass();2209itableOffsetEntry* scan;2210for (scan = (itableOffsetEntry*) int2->start_of_itable();2211scan->interface_klass() != NULL;2212scan++) {2213if (scan->interface_klass() == refc) {2214break;2215}2216}2217// Check that the entry is non-null. A null entry means2218// that the receiver class doesn't implement the2219// interface, and wasn't the same as when the caller was2220// compiled.2221if (scan->interface_klass() == NULL) {2222VM_JAVA_ERROR(vmSymbols::java_lang_IncompatibleClassChangeError(), "");2223}2224}22252226itableOffsetEntry* ki = (itableOffsetEntry*) int2->start_of_itable();2227int i;2228for ( i = 0 ; i < int2->itable_length() ; i++, ki++ ) {2229if (ki->interface_klass() == iclass) break;2230}2231// If the interface isn't found, this class doesn't implement this2232// interface. The link resolver checks this but only for the first2233// time this interface is called.2234if (i == int2->itable_length()) {2235CALL_VM(InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose(THREAD, rcvr->klass(), iclass),2236handle_exception);2237}2238int mindex = interface_method->itable_index();22392240itableMethodEntry* im = ki->first_method_entry(rcvr->klass());2241callee = im[mindex].method();2242if (callee == NULL) {2243CALL_VM(InterpreterRuntime::throw_AbstractMethodErrorVerbose(THREAD, rcvr->klass(), interface_method),2244handle_exception);2245}22462247istate->set_callee(callee);2248istate->set_callee_entry_point(callee->from_interpreted_entry());2249if (JVMTI_ENABLED && THREAD->is_interp_only_mode()) {2250istate->set_callee_entry_point(callee->interpreter_entry());2251}2252istate->set_bcp_advance(5);2253UPDATE_PC_AND_RETURN(0); // I'll be back...2254}22552256CASE(_invokevirtual):2257CASE(_invokespecial):2258CASE(_invokestatic): {2259u2 index = Bytes::get_native_u2(pc+1);22602261ConstantPoolCacheEntry* cache = cp->entry_at(index);2262// QQQ Need to make this as inlined as possible. Probably need to split all the bytecode cases2263// out so c++ compiler has a chance for constant prop to fold everything possible away.22642265if (!cache->is_resolved((Bytecodes::Code)opcode)) {2266CALL_VM(InterpreterRuntime::resolve_from_cache(THREAD, (Bytecodes::Code)opcode),2267handle_exception);2268cache = cp->entry_at(index);2269}22702271istate->set_msg(call_method);2272{2273Method* callee;2274if ((Bytecodes::Code)opcode == Bytecodes::_invokevirtual) {2275CHECK_NULL(STACK_OBJECT(-(cache->parameter_size())));2276if (cache->is_vfinal()) {2277callee = cache->f2_as_vfinal_method();2278} else {2279// get receiver2280int parms = cache->parameter_size();2281// this works but needs a resourcemark and seems to create a vtable on every call:2282// Method* callee = rcvr->klass()->vtable()->method_at(cache->f2_as_index());2283//2284// this fails with an assert2285// InstanceKlass* rcvrKlass = InstanceKlass::cast(STACK_OBJECT(-parms)->klass());2286// but this works2287oop rcvr = STACK_OBJECT(-parms);2288VERIFY_OOP(rcvr);2289Klass* rcvrKlass = rcvr->klass();2290/*2291Executing this code in java.lang.String:2292public String(char value[]) {2293this.count = value.length;2294this.value = (char[])value.clone();2295}22962297a find on rcvr->klass() reports:2298{type array char}{type array class}2299- klass: {other class}23002301but using InstanceKlass::cast(STACK_OBJECT(-parms)->klass()) causes in assertion failure2302because rcvr->klass()->is_instance_klass() == 02303However it seems to have a vtable in the right location. Huh?2304Because vtables have the same offset for ArrayKlass and InstanceKlass.2305*/2306callee = (Method*) rcvrKlass->method_at_vtable(cache->f2_as_index());2307}2308} else {2309if ((Bytecodes::Code)opcode == Bytecodes::_invokespecial) {2310CHECK_NULL(STACK_OBJECT(-(cache->parameter_size())));2311}2312callee = cache->f1_as_method();2313}23142315istate->set_callee(callee);2316istate->set_callee_entry_point(callee->from_interpreted_entry());2317if (JVMTI_ENABLED && THREAD->is_interp_only_mode()) {2318istate->set_callee_entry_point(callee->interpreter_entry());2319}2320istate->set_bcp_advance(3);2321UPDATE_PC_AND_RETURN(0); // I'll be back...2322}2323}23242325/* Allocate memory for a new java object. */23262327CASE(_newarray): {2328BasicType atype = (BasicType) *(pc+1);2329jint size = STACK_INT(-1);2330CALL_VM(InterpreterRuntime::newarray(THREAD, atype, size),2331handle_exception);2332// Must prevent reordering of stores for object initialization2333// with stores that publish the new object.2334OrderAccess::storestore();2335SET_STACK_OBJECT(THREAD->vm_result(), -1);2336THREAD->set_vm_result(NULL);23372338UPDATE_PC_AND_CONTINUE(2);2339}23402341/* Throw an exception. */23422343CASE(_athrow): {2344oop except_oop = STACK_OBJECT(-1);2345CHECK_NULL(except_oop);2346// set pending_exception so we use common code2347THREAD->set_pending_exception(except_oop, NULL, 0);2348goto handle_exception;2349}23502351/* goto and jsr. They are exactly the same except jsr pushes2352* the address of the next instruction first.2353*/23542355CASE(_jsr): {2356/* push bytecode index on stack */2357SET_STACK_ADDR(((address)pc - (intptr_t)(istate->method()->code_base()) + 3), 0);2358MORE_STACK(1);2359/* FALL THROUGH */2360}23612362CASE(_goto):2363{2364int16_t offset = (int16_t)Bytes::get_Java_u2(pc + 1);2365address branch_pc = pc;2366UPDATE_PC(offset);2367DO_BACKEDGE_CHECKS(offset, branch_pc);2368CONTINUE;2369}23702371CASE(_jsr_w): {2372/* push return address on the stack */2373SET_STACK_ADDR(((address)pc - (intptr_t)(istate->method()->code_base()) + 5), 0);2374MORE_STACK(1);2375/* FALL THROUGH */2376}23772378CASE(_goto_w):2379{2380int32_t offset = Bytes::get_Java_u4(pc + 1);2381address branch_pc = pc;2382UPDATE_PC(offset);2383DO_BACKEDGE_CHECKS(offset, branch_pc);2384CONTINUE;2385}23862387/* return from a jsr or jsr_w */23882389CASE(_ret): {2390pc = istate->method()->code_base() + (intptr_t)(LOCALS_ADDR(pc[1]));2391UPDATE_PC_AND_CONTINUE(0);2392}23932394/* debugger breakpoint */23952396CASE(_breakpoint): {2397Bytecodes::Code original_bytecode;2398DECACHE_STATE();2399SET_LAST_JAVA_FRAME();2400original_bytecode = InterpreterRuntime::get_original_bytecode_at(THREAD,2401METHOD, pc);2402RESET_LAST_JAVA_FRAME();2403CACHE_STATE();2404if (THREAD->has_pending_exception()) goto handle_exception;2405CALL_VM(InterpreterRuntime::_breakpoint(THREAD, METHOD, pc),2406handle_exception);24072408opcode = (jubyte)original_bytecode;2409goto opcode_switch;2410}24112412DEFAULT:2413fatal("Unimplemented opcode %d = %s", opcode,2414Bytecodes::name((Bytecodes::Code)opcode));2415goto finish;24162417} /* switch(opc) */241824192420#ifdef USELABELS2421check_for_exception:2422#endif2423{2424if (!THREAD->has_pending_exception()) {2425CONTINUE;2426}2427/* We will be gcsafe soon, so flush our state. */2428DECACHE_PC();2429goto handle_exception;2430}2431do_continue: ;24322433} /* while (1) interpreter loop */243424352436// An exception exists in the thread state see whether this activation can handle it2437handle_exception: {24382439HandleMarkCleaner __hmc(THREAD);2440Handle except_oop(THREAD, THREAD->pending_exception());2441// Prevent any subsequent HandleMarkCleaner in the VM2442// from freeing the except_oop handle.2443HandleMark __hm(THREAD);24442445THREAD->clear_pending_exception();2446assert(except_oop() != NULL, "No exception to process");2447intptr_t continuation_bci;2448// expression stack is emptied2449topOfStack = istate->stack_base() - Interpreter::stackElementWords;2450CALL_VM(continuation_bci = (intptr_t)InterpreterRuntime::exception_handler_for_exception(THREAD, except_oop()),2451handle_exception);24522453except_oop = Handle(THREAD, THREAD->vm_result());2454THREAD->set_vm_result(NULL);2455if (continuation_bci >= 0) {2456// Place exception on top of stack2457SET_STACK_OBJECT(except_oop(), 0);2458MORE_STACK(1);2459pc = METHOD->code_base() + continuation_bci;2460if (log_is_enabled(Info, exceptions)) {2461ResourceMark rm(THREAD);2462stringStream tempst;2463tempst.print("interpreter method <%s>\n"2464" at bci %d, continuing at %d for thread " INTPTR_FORMAT,2465METHOD->print_value_string(),2466(int)(istate->bcp() - METHOD->code_base()),2467(int)continuation_bci, p2i(THREAD));2468Exceptions::log_exception(except_oop, tempst.as_string());2469}2470// for AbortVMOnException flag2471Exceptions::debug_check_abort(except_oop);2472goto run;2473}2474if (log_is_enabled(Info, exceptions)) {2475ResourceMark rm;2476stringStream tempst;2477tempst.print("interpreter method <%s>\n"2478" at bci %d, unwinding for thread " INTPTR_FORMAT,2479METHOD->print_value_string(),2480(int)(istate->bcp() - METHOD->code_base()),2481p2i(THREAD));2482Exceptions::log_exception(except_oop, tempst.as_string());2483}2484// for AbortVMOnException flag2485Exceptions::debug_check_abort(except_oop);24862487// No handler in this activation, unwind and try again2488THREAD->set_pending_exception(except_oop(), NULL, 0);2489goto handle_return;2490} // handle_exception:24912492// Return from an interpreter invocation with the result of the interpretation2493// on the top of the Java Stack (or a pending exception)24942495handle_Pop_Frame: {24962497// We don't really do anything special here except we must be aware2498// that we can get here without ever locking the method (if sync).2499// Also we skip the notification of the exit.25002501istate->set_msg(popping_frame);2502// Clear pending so while the pop is in process2503// we don't start another one if a call_vm is done.2504THREAD->clear_popframe_condition();2505// Let interpreter (only) see the we're in the process of popping a frame2506THREAD->set_pop_frame_in_process();25072508goto handle_return;25092510} // handle_Pop_Frame25112512// ForceEarlyReturn ends a method, and returns to the caller with a return value2513// given by the invoker of the early return.2514handle_Early_Return: {25152516istate->set_msg(early_return);25172518// Clear expression stack.2519topOfStack = istate->stack_base() - Interpreter::stackElementWords;25202521JvmtiThreadState *ts = THREAD->jvmti_thread_state();25222523// Push the value to be returned.2524switch (istate->method()->result_type()) {2525case T_BOOLEAN:2526case T_SHORT:2527case T_BYTE:2528case T_CHAR:2529case T_INT:2530SET_STACK_INT(ts->earlyret_value().i, 0);2531MORE_STACK(1);2532break;2533case T_LONG:2534SET_STACK_LONG(ts->earlyret_value().j, 1);2535MORE_STACK(2);2536break;2537case T_FLOAT:2538SET_STACK_FLOAT(ts->earlyret_value().f, 0);2539MORE_STACK(1);2540break;2541case T_DOUBLE:2542SET_STACK_DOUBLE(ts->earlyret_value().d, 1);2543MORE_STACK(2);2544break;2545case T_ARRAY:2546case T_OBJECT:2547SET_STACK_OBJECT(ts->earlyret_oop(), 0);2548MORE_STACK(1);2549break;2550default:2551ShouldNotReachHere();2552}25532554ts->clr_earlyret_value();2555ts->set_earlyret_oop(NULL);2556ts->clr_earlyret_pending();25572558// Fall through to handle_return.25592560} // handle_Early_Return25612562handle_return: {2563// A storestore barrier is required to order initialization of2564// final fields with publishing the reference to the object that2565// holds the field. Without the barrier the value of final fields2566// can be observed to change.2567OrderAccess::storestore();25682569DECACHE_STATE();25702571bool suppress_error = istate->msg() == popping_frame || istate->msg() == early_return;2572bool suppress_exit_event = THREAD->has_pending_exception() || istate->msg() == popping_frame;2573Handle original_exception(THREAD, THREAD->pending_exception());2574Handle illegal_state_oop(THREAD, NULL);25752576// We'd like a HandleMark here to prevent any subsequent HandleMarkCleaner2577// in any following VM entries from freeing our live handles, but illegal_state_oop2578// isn't really allocated yet and so doesn't become live until later and2579// in unpredicatable places. Instead we must protect the places where we enter the2580// VM. It would be much simpler (and safer) if we could allocate a real handle with2581// a NULL oop in it and then overwrite the oop later as needed. This isn't2582// unfortunately isn't possible.25832584if (THREAD->has_pending_exception()) {2585THREAD->clear_pending_exception();2586}25872588//2589// As far as we are concerned we have returned. If we have a pending exception2590// that will be returned as this invocation's result. However if we get any2591// exception(s) while checking monitor state one of those IllegalMonitorStateExceptions2592// will be our final result (i.e. monitor exception trumps a pending exception).2593//25942595// If we never locked the method (or really passed the point where we would have),2596// there is no need to unlock it (or look for other monitors), since that2597// could not have happened.25982599if (THREAD->do_not_unlock()) {26002601// Never locked, reset the flag now because obviously any caller must2602// have passed their point of locking for us to have gotten here.26032604THREAD->clr_do_not_unlock();2605} else {2606// At this point we consider that we have returned. We now check that the2607// locks were properly block structured. If we find that they were not2608// used properly we will return with an illegal monitor exception.2609// The exception is checked by the caller not the callee since this2610// checking is considered to be part of the invocation and therefore2611// in the callers scope (JVM spec 8.13).2612//2613// Another weird thing to watch for is if the method was locked2614// recursively and then not exited properly. This means we must2615// examine all the entries in reverse time(and stack) order and2616// unlock as we find them. If we find the method monitor before2617// we are at the initial entry then we should throw an exception.2618// It is not clear the template based interpreter does this2619// correctly26202621BasicObjectLock* base = istate->monitor_base();2622BasicObjectLock* end = (BasicObjectLock*) istate->stack_base();2623bool method_unlock_needed = METHOD->is_synchronized();2624// We know the initial monitor was used for the method don't check that2625// slot in the loop2626if (method_unlock_needed) base--;26272628// Check all the monitors to see they are unlocked. Install exception if found to be locked.2629while (end < base) {2630oop lockee = end->obj();2631if (lockee != NULL) {2632BasicLock* lock = end->lock();2633markWord header = lock->displaced_header();2634end->set_obj(NULL);26352636assert(!UseBiasedLocking, "Not implemented");26372638// If it isn't recursive we either must swap old header or call the runtime2639if (header.to_pointer() != NULL) {2640markWord old_header = markWord::encode(lock);2641if (lockee->cas_set_mark(header, old_header) != old_header) {2642// restore object for the slow case2643end->set_obj(lockee);2644InterpreterRuntime::monitorexit(end);2645}2646}26472648// One error is plenty2649if (illegal_state_oop() == NULL && !suppress_error) {2650{2651// Prevent any HandleMarkCleaner from freeing our live handles2652HandleMark __hm(THREAD);2653CALL_VM_NOCHECK(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD));2654}2655assert(THREAD->has_pending_exception(), "Lost our exception!");2656illegal_state_oop = Handle(THREAD, THREAD->pending_exception());2657THREAD->clear_pending_exception();2658}2659}2660end++;2661}2662// Unlock the method if needed2663if (method_unlock_needed) {2664if (base->obj() == NULL) {2665// The method is already unlocked this is not good.2666if (illegal_state_oop() == NULL && !suppress_error) {2667{2668// Prevent any HandleMarkCleaner from freeing our live handles2669HandleMark __hm(THREAD);2670CALL_VM_NOCHECK(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD));2671}2672assert(THREAD->has_pending_exception(), "Lost our exception!");2673illegal_state_oop = Handle(THREAD, THREAD->pending_exception());2674THREAD->clear_pending_exception();2675}2676} else {2677//2678// The initial monitor is always used for the method2679// However if that slot is no longer the oop for the method it was unlocked2680// and reused by something that wasn't unlocked!2681//2682// deopt can come in with rcvr dead because c2 knows2683// its value is preserved in the monitor. So we can't use locals[0] at all2684// and must use first monitor slot.2685//2686oop rcvr = base->obj();2687if (rcvr == NULL) {2688if (!suppress_error) {2689VM_JAVA_ERROR_NO_JUMP(vmSymbols::java_lang_NullPointerException(), "");2690illegal_state_oop = Handle(THREAD, THREAD->pending_exception());2691THREAD->clear_pending_exception();2692}2693} else if (UseHeavyMonitors) {2694InterpreterRuntime::monitorexit(base);2695if (THREAD->has_pending_exception()) {2696if (!suppress_error) illegal_state_oop = Handle(THREAD, THREAD->pending_exception());2697THREAD->clear_pending_exception();2698}2699} else {2700BasicLock* lock = base->lock();2701markWord header = lock->displaced_header();2702base->set_obj(NULL);27032704assert(!UseBiasedLocking, "Not implemented");27052706// If it isn't recursive we either must swap old header or call the runtime2707if (header.to_pointer() != NULL) {2708markWord old_header = markWord::encode(lock);2709if (rcvr->cas_set_mark(header, old_header) != old_header) {2710// restore object for the slow case2711base->set_obj(rcvr);2712InterpreterRuntime::monitorexit(base);2713if (THREAD->has_pending_exception()) {2714if (!suppress_error) illegal_state_oop = Handle(THREAD, THREAD->pending_exception());2715THREAD->clear_pending_exception();2716}2717}2718}2719}2720}2721}2722}2723// Clear the do_not_unlock flag now.2724THREAD->clr_do_not_unlock();27252726//2727// Notify jvmti/jvmdi2728//2729// NOTE: we do not notify a method_exit if we have a pending exception,2730// including an exception we generate for unlocking checks. In the former2731// case, JVMDI has already been notified by our call for the exception handler2732// and in both cases as far as JVMDI is concerned we have already returned.2733// If we notify it again JVMDI will be all confused about how many frames2734// are still on the stack (4340444).2735//2736// NOTE Further! It turns out the the JVMTI spec in fact expects to see2737// method_exit events whenever we leave an activation unless it was done2738// for popframe. This is nothing like jvmdi. However we are passing the2739// tests at the moment (apparently because they are jvmdi based) so rather2740// than change this code and possibly fail tests we will leave it alone2741// (with this note) in anticipation of changing the vm and the tests2742// simultaneously.27432744suppress_exit_event = suppress_exit_event || illegal_state_oop() != NULL;27452746// Whenever JVMTI puts a thread in interp_only_mode, method2747// entry/exit events are sent for that thread to track stack depth.27482749if (JVMTI_ENABLED && !suppress_exit_event && THREAD->is_interp_only_mode()) {2750// Prevent any HandleMarkCleaner from freeing our live handles2751HandleMark __hm(THREAD);2752CALL_VM_NOCHECK(InterpreterRuntime::post_method_exit(THREAD));2753}27542755//2756// See if we are returning any exception2757// A pending exception that was pending prior to a possible popping frame2758// overrides the popping frame.2759//2760assert(!suppress_error || (suppress_error && illegal_state_oop() == NULL), "Error was not suppressed");2761if (illegal_state_oop() != NULL || original_exception() != NULL) {2762// Inform the frame manager we have no result.2763istate->set_msg(throwing_exception);2764if (illegal_state_oop() != NULL)2765THREAD->set_pending_exception(illegal_state_oop(), NULL, 0);2766else2767THREAD->set_pending_exception(original_exception(), NULL, 0);2768UPDATE_PC_AND_RETURN(0);2769}27702771if (istate->msg() == popping_frame) {2772// Make it simpler on the assembly code and set the message for the frame pop.2773// returns2774if (istate->prev() == NULL) {2775// We must be returning to a deoptimized frame (because popframe only happens between2776// two interpreted frames). We need to save the current arguments in C heap so that2777// the deoptimized frame when it restarts can copy the arguments to its expression2778// stack and re-execute the call. We also have to notify deoptimization that this2779// has occurred and to pick the preserved args copy them to the deoptimized frame's2780// java expression stack. Yuck.2781//2782THREAD->popframe_preserve_args(in_ByteSize(METHOD->size_of_parameters() * wordSize),2783LOCALS_SLOT(METHOD->size_of_parameters() - 1));2784THREAD->set_popframe_condition_bit(JavaThread::popframe_force_deopt_reexecution_bit);2785}2786} else {2787istate->set_msg(return_from_method);2788}27892790// Normal return2791// Advance the pc and return to frame manager2792UPDATE_PC_AND_RETURN(1);2793} /* handle_return: */27942795// This is really a fatal error return27962797finish:2798DECACHE_TOS();2799DECACHE_PC();28002801return;2802}28032804// This constructor should only be used to contruct the object to signal2805// interpreter initialization. All other instances should be created by2806// the frame manager.2807BytecodeInterpreter::BytecodeInterpreter(messages msg) {2808if (msg != initialize) ShouldNotReachHere();2809_msg = msg;2810_self_link = this;2811_prev_link = NULL;2812}28132814void BytecodeInterpreter::astore(intptr_t* tos, int stack_offset,2815intptr_t* locals, int locals_offset) {2816intptr_t value = tos[Interpreter::expr_index_at(-stack_offset)];2817locals[Interpreter::local_index_at(-locals_offset)] = value;2818}28192820void BytecodeInterpreter::copy_stack_slot(intptr_t *tos, int from_offset,2821int to_offset) {2822tos[Interpreter::expr_index_at(-to_offset)] =2823(intptr_t)tos[Interpreter::expr_index_at(-from_offset)];2824}28252826void BytecodeInterpreter::dup(intptr_t *tos) {2827copy_stack_slot(tos, -1, 0);2828}28292830void BytecodeInterpreter::dup2(intptr_t *tos) {2831copy_stack_slot(tos, -2, 0);2832copy_stack_slot(tos, -1, 1);2833}28342835void BytecodeInterpreter::dup_x1(intptr_t *tos) {2836/* insert top word two down */2837copy_stack_slot(tos, -1, 0);2838copy_stack_slot(tos, -2, -1);2839copy_stack_slot(tos, 0, -2);2840}28412842void BytecodeInterpreter::dup_x2(intptr_t *tos) {2843/* insert top word three down */2844copy_stack_slot(tos, -1, 0);2845copy_stack_slot(tos, -2, -1);2846copy_stack_slot(tos, -3, -2);2847copy_stack_slot(tos, 0, -3);2848}2849void BytecodeInterpreter::dup2_x1(intptr_t *tos) {2850/* insert top 2 slots three down */2851copy_stack_slot(tos, -1, 1);2852copy_stack_slot(tos, -2, 0);2853copy_stack_slot(tos, -3, -1);2854copy_stack_slot(tos, 1, -2);2855copy_stack_slot(tos, 0, -3);2856}2857void BytecodeInterpreter::dup2_x2(intptr_t *tos) {2858/* insert top 2 slots four down */2859copy_stack_slot(tos, -1, 1);2860copy_stack_slot(tos, -2, 0);2861copy_stack_slot(tos, -3, -1);2862copy_stack_slot(tos, -4, -2);2863copy_stack_slot(tos, 1, -3);2864copy_stack_slot(tos, 0, -4);2865}286628672868void BytecodeInterpreter::swap(intptr_t *tos) {2869// swap top two elements2870intptr_t val = tos[Interpreter::expr_index_at(1)];2871// Copy -2 entry to -12872copy_stack_slot(tos, -2, -1);2873// Store saved -1 entry into -22874tos[Interpreter::expr_index_at(2)] = val;2875}2876// --------------------------------------------------------------------------------2877// Non-product code2878#ifndef PRODUCT28792880const char* BytecodeInterpreter::C_msg(BytecodeInterpreter::messages msg) {2881switch (msg) {2882case BytecodeInterpreter::no_request: return("no_request");2883case BytecodeInterpreter::initialize: return("initialize");2884// status message to C++ interpreter2885case BytecodeInterpreter::method_entry: return("method_entry");2886case BytecodeInterpreter::method_resume: return("method_resume");2887case BytecodeInterpreter::got_monitors: return("got_monitors");2888case BytecodeInterpreter::rethrow_exception: return("rethrow_exception");2889// requests to frame manager from C++ interpreter2890case BytecodeInterpreter::call_method: return("call_method");2891case BytecodeInterpreter::return_from_method: return("return_from_method");2892case BytecodeInterpreter::more_monitors: return("more_monitors");2893case BytecodeInterpreter::throwing_exception: return("throwing_exception");2894case BytecodeInterpreter::popping_frame: return("popping_frame");2895case BytecodeInterpreter::do_osr: return("do_osr");2896// deopt2897case BytecodeInterpreter::deopt_resume: return("deopt_resume");2898case BytecodeInterpreter::deopt_resume2: return("deopt_resume2");2899default: return("BAD MSG");2900}2901}2902void2903BytecodeInterpreter::print() {2904tty->print_cr("thread: " INTPTR_FORMAT, (uintptr_t) this->_thread);2905tty->print_cr("bcp: " INTPTR_FORMAT, (uintptr_t) this->_bcp);2906tty->print_cr("locals: " INTPTR_FORMAT, (uintptr_t) this->_locals);2907tty->print_cr("constants: " INTPTR_FORMAT, (uintptr_t) this->_constants);2908{2909ResourceMark rm;2910char *method_name = _method->name_and_sig_as_C_string();2911tty->print_cr("method: " INTPTR_FORMAT "[ %s ]", (uintptr_t) this->_method, method_name);2912}2913tty->print_cr("stack: " INTPTR_FORMAT, (uintptr_t) this->_stack);2914tty->print_cr("msg: %s", C_msg(this->_msg));2915tty->print_cr("result_to_call._callee: " INTPTR_FORMAT, (uintptr_t) this->_result._to_call._callee);2916tty->print_cr("result_to_call._callee_entry_point: " INTPTR_FORMAT, (uintptr_t) this->_result._to_call._callee_entry_point);2917tty->print_cr("result_to_call._bcp_advance: %d ", this->_result._to_call._bcp_advance);2918tty->print_cr("osr._osr_buf: " INTPTR_FORMAT, (uintptr_t) this->_result._osr._osr_buf);2919tty->print_cr("osr._osr_entry: " INTPTR_FORMAT, (uintptr_t) this->_result._osr._osr_entry);2920tty->print_cr("prev_link: " INTPTR_FORMAT, (uintptr_t) this->_prev_link);2921tty->print_cr("native_mirror: " INTPTR_FORMAT, (uintptr_t) p2i(this->_oop_temp));2922tty->print_cr("stack_base: " INTPTR_FORMAT, (uintptr_t) this->_stack_base);2923tty->print_cr("stack_limit: " INTPTR_FORMAT, (uintptr_t) this->_stack_limit);2924tty->print_cr("monitor_base: " INTPTR_FORMAT, (uintptr_t) this->_monitor_base);2925tty->print_cr("self_link: " INTPTR_FORMAT, (uintptr_t) this->_self_link);2926}29272928extern "C" {2929void PI(uintptr_t arg) {2930((BytecodeInterpreter*)arg)->print();2931}2932}2933#endif // PRODUCT293429352936