Path: blob/master/src/hotspot/share/interpreter/zero/bytecodeInterpreter.cpp
40957 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 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) {405406// In order to simplify some tests based on switches set at runtime407// we invoke the interpreter a single time after switches are enabled408// and set simpler to to test variables rather than method calls or complex409// boolean expressions.410411static int initialized = 0;412static int checkit = 0;413static intptr_t* c_addr = NULL;414static intptr_t c_value;415416if (checkit && *c_addr != c_value) {417os::breakpoint();418}419420#ifdef ASSERT421if (istate->_msg != initialize) {422assert(labs(istate->_stack_base - istate->_stack_limit) == (istate->_method->max_stack() + 1), "bad stack limit");423}424// 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#endif434435intptr_t* topOfStack = (intptr_t *)istate->stack(); /* access with STACK macros */436address pc = istate->bcp();437jubyte opcode;438intptr_t* locals = istate->locals();439ConstantPoolCache* cp = istate->constants(); // method()->constants()->cache()440#ifdef LOTS_OF_REGS441JavaThread* THREAD = istate->thread();442#else443#undef THREAD444#define THREAD istate->thread()445#endif446447#ifdef USELABELS448const static void* const opclabels_data[256] = {449/* 0x00 */ &&opc_nop, &&opc_aconst_null,&&opc_iconst_m1,&&opc_iconst_0,450/* 0x04 */ &&opc_iconst_1,&&opc_iconst_2, &&opc_iconst_3, &&opc_iconst_4,451/* 0x08 */ &&opc_iconst_5,&&opc_lconst_0, &&opc_lconst_1, &&opc_fconst_0,452/* 0x0C */ &&opc_fconst_1,&&opc_fconst_2, &&opc_dconst_0, &&opc_dconst_1,453454/* 0x10 */ &&opc_bipush, &&opc_sipush, &&opc_ldc, &&opc_ldc_w,455/* 0x14 */ &&opc_ldc2_w, &&opc_iload, &&opc_lload, &&opc_fload,456/* 0x18 */ &&opc_dload, &&opc_aload, &&opc_iload_0,&&opc_iload_1,457/* 0x1C */ &&opc_iload_2,&&opc_iload_3,&&opc_lload_0,&&opc_lload_1,458459/* 0x20 */ &&opc_lload_2,&&opc_lload_3,&&opc_fload_0,&&opc_fload_1,460/* 0x24 */ &&opc_fload_2,&&opc_fload_3,&&opc_dload_0,&&opc_dload_1,461/* 0x28 */ &&opc_dload_2,&&opc_dload_3,&&opc_aload_0,&&opc_aload_1,462/* 0x2C */ &&opc_aload_2,&&opc_aload_3,&&opc_iaload, &&opc_laload,463464/* 0x30 */ &&opc_faload, &&opc_daload, &&opc_aaload, &&opc_baload,465/* 0x34 */ &&opc_caload, &&opc_saload, &&opc_istore, &&opc_lstore,466/* 0x38 */ &&opc_fstore, &&opc_dstore, &&opc_astore, &&opc_istore_0,467/* 0x3C */ &&opc_istore_1,&&opc_istore_2,&&opc_istore_3,&&opc_lstore_0,468469/* 0x40 */ &&opc_lstore_1,&&opc_lstore_2,&&opc_lstore_3,&&opc_fstore_0,470/* 0x44 */ &&opc_fstore_1,&&opc_fstore_2,&&opc_fstore_3,&&opc_dstore_0,471/* 0x48 */ &&opc_dstore_1,&&opc_dstore_2,&&opc_dstore_3,&&opc_astore_0,472/* 0x4C */ &&opc_astore_1,&&opc_astore_2,&&opc_astore_3,&&opc_iastore,473474/* 0x50 */ &&opc_lastore,&&opc_fastore,&&opc_dastore,&&opc_aastore,475/* 0x54 */ &&opc_bastore,&&opc_castore,&&opc_sastore,&&opc_pop,476/* 0x58 */ &&opc_pop2, &&opc_dup, &&opc_dup_x1, &&opc_dup_x2,477/* 0x5C */ &&opc_dup2, &&opc_dup2_x1,&&opc_dup2_x2,&&opc_swap,478479/* 0x60 */ &&opc_iadd,&&opc_ladd,&&opc_fadd,&&opc_dadd,480/* 0x64 */ &&opc_isub,&&opc_lsub,&&opc_fsub,&&opc_dsub,481/* 0x68 */ &&opc_imul,&&opc_lmul,&&opc_fmul,&&opc_dmul,482/* 0x6C */ &&opc_idiv,&&opc_ldiv,&&opc_fdiv,&&opc_ddiv,483484/* 0x70 */ &&opc_irem, &&opc_lrem, &&opc_frem,&&opc_drem,485/* 0x74 */ &&opc_ineg, &&opc_lneg, &&opc_fneg,&&opc_dneg,486/* 0x78 */ &&opc_ishl, &&opc_lshl, &&opc_ishr,&&opc_lshr,487/* 0x7C */ &&opc_iushr,&&opc_lushr,&&opc_iand,&&opc_land,488489/* 0x80 */ &&opc_ior, &&opc_lor,&&opc_ixor,&&opc_lxor,490/* 0x84 */ &&opc_iinc,&&opc_i2l,&&opc_i2f, &&opc_i2d,491/* 0x88 */ &&opc_l2i, &&opc_l2f,&&opc_l2d, &&opc_f2i,492/* 0x8C */ &&opc_f2l, &&opc_f2d,&&opc_d2i, &&opc_d2l,493494/* 0x90 */ &&opc_d2f, &&opc_i2b, &&opc_i2c, &&opc_i2s,495/* 0x94 */ &&opc_lcmp, &&opc_fcmpl,&&opc_fcmpg,&&opc_dcmpl,496/* 0x98 */ &&opc_dcmpg,&&opc_ifeq, &&opc_ifne, &&opc_iflt,497/* 0x9C */ &&opc_ifge, &&opc_ifgt, &&opc_ifle, &&opc_if_icmpeq,498499/* 0xA0 */ &&opc_if_icmpne,&&opc_if_icmplt,&&opc_if_icmpge, &&opc_if_icmpgt,500/* 0xA4 */ &&opc_if_icmple,&&opc_if_acmpeq,&&opc_if_acmpne, &&opc_goto,501/* 0xA8 */ &&opc_jsr, &&opc_ret, &&opc_tableswitch,&&opc_lookupswitch,502/* 0xAC */ &&opc_ireturn, &&opc_lreturn, &&opc_freturn, &&opc_dreturn,503504/* 0xB0 */ &&opc_areturn, &&opc_return, &&opc_getstatic, &&opc_putstatic,505/* 0xB4 */ &&opc_getfield, &&opc_putfield, &&opc_invokevirtual,&&opc_invokespecial,506/* 0xB8 */ &&opc_invokestatic,&&opc_invokeinterface,&&opc_invokedynamic,&&opc_new,507/* 0xBC */ &&opc_newarray, &&opc_anewarray, &&opc_arraylength, &&opc_athrow,508509/* 0xC0 */ &&opc_checkcast, &&opc_instanceof, &&opc_monitorenter, &&opc_monitorexit,510/* 0xC4 */ &&opc_wide, &&opc_multianewarray, &&opc_ifnull, &&opc_ifnonnull,511/* 0xC8 */ &&opc_goto_w, &&opc_jsr_w, &&opc_breakpoint, &&opc_default,512/* 0xCC */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,513514/* 0xD0 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,515/* 0xD4 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,516/* 0xD8 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,517/* 0xDC */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,518519/* 0xE0 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,520/* 0xE4 */ &&opc_default, &&opc_default, &&opc_fast_aldc, &&opc_fast_aldc_w,521/* 0xE8 */ &&opc_return_register_finalizer,522&&opc_invokehandle, &&opc_default, &&opc_default,523/* 0xEC */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,524525/* 0xF0 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,526/* 0xF4 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,527/* 0xF8 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,528/* 0xFC */ &&opc_default, &&opc_default, &&opc_default, &&opc_default529};530uintptr_t *dispatch_table = (uintptr_t*)&opclabels_data[0];531#endif /* USELABELS */532533#ifdef ASSERT534// this will trigger a VERIFY_OOP on entry535if (istate->msg() != initialize && ! METHOD->is_static()) {536oop rcvr = LOCALS_OBJECT(0);537VERIFY_OOP(rcvr);538}539#endif540541/* QQQ this should be a stack method so we don't know actual direction */542guarantee(istate->msg() == initialize ||543topOfStack >= istate->stack_limit() &&544topOfStack < istate->stack_base(),545"Stack top out of range");546547assert(!UseCompiler, "Zero does not support compilers");548assert(!CountCompiledCalls, "Zero does not support counting compiled calls");549550switch (istate->msg()) {551case initialize: {552if (initialized++) ShouldNotReachHere(); // Only one initialize call.553return;554}555break;556case method_entry: {557THREAD->set_do_not_unlock();558// count invocations559assert(initialized, "Interpreter not initialized");560561if ((istate->_stack_base - istate->_stack_limit) != istate->method()->max_stack() + 1) {562// initialize563os::breakpoint();564}565566// Lock method if synchronized.567if (METHOD->is_synchronized()) {568// oop rcvr = locals[0].j.r;569oop rcvr;570if (METHOD->is_static()) {571rcvr = METHOD->constants()->pool_holder()->java_mirror();572} else {573rcvr = LOCALS_OBJECT(0);574VERIFY_OOP(rcvr);575}576577// The initial monitor is ours for the taking.578// Monitor not filled in frame manager any longer as this caused race condition with biased locking.579BasicObjectLock* mon = &istate->monitor_base()[-1];580mon->set_obj(rcvr);581582assert(!UseBiasedLocking, "Not implemented");583584// Traditional lightweight locking.585markWord displaced = rcvr->mark().set_unlocked();586mon->lock()->set_displaced_header(displaced);587bool call_vm = UseHeavyMonitors;588if (call_vm || rcvr->cas_set_mark(markWord::from_pointer(mon), displaced) != displaced) {589// Is it simple recursive case?590if (!call_vm && THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) {591mon->lock()->set_displaced_header(markWord::from_pointer(NULL));592} else {593CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);594}595}596}597THREAD->clr_do_not_unlock();598599// Notify jvmti.600// Whenever JVMTI puts a thread in interp_only_mode, method601// entry/exit events are sent for that thread to track stack depth.602if (JVMTI_ENABLED && THREAD->is_interp_only_mode()) {603CALL_VM(InterpreterRuntime::post_method_entry(THREAD),604handle_exception);605}606607goto run;608}609610case popping_frame: {611// returned from a java call to pop the frame, restart the call612// clear the message so we don't confuse ourselves later613assert(THREAD->pop_frame_in_process(), "wrong frame pop state");614istate->set_msg(no_request);615THREAD->clr_pop_frame_in_process();616goto run;617}618619case method_resume: {620if ((istate->_stack_base - istate->_stack_limit) != istate->method()->max_stack() + 1) {621// resume622os::breakpoint();623}624// returned from a java call, continue executing.625if (THREAD->has_pending_popframe() && !THREAD->pop_frame_in_process()) {626goto handle_Pop_Frame;627}628if (THREAD->jvmti_thread_state() &&629THREAD->jvmti_thread_state()->is_earlyret_pending()) {630goto handle_Early_Return;631}632633if (THREAD->has_pending_exception()) goto handle_exception;634// Update the pc by the saved amount of the invoke bytecode size635UPDATE_PC(istate->bcp_advance());636goto run;637}638639case deopt_resume2: {640// Returned from an opcode that will reexecute. Deopt was641// a result of a PopFrame request.642//643goto run;644}645646case deopt_resume: {647// Returned from an opcode that has completed. The stack has648// the result all we need to do is skip across the bytecode649// and continue (assuming there is no exception pending)650//651// compute continuation length652//653// Note: it is possible to deopt at a return_register_finalizer opcode654// because this requires entering the vm to do the registering. While the655// opcode is complete we can't advance because there are no more opcodes656// much like trying to deopt at a poll return. In that has we simply657// get out of here658//659if ( Bytecodes::code_at(METHOD, pc) == Bytecodes::_return_register_finalizer) {660// this will do the right thing even if an exception is pending.661goto handle_return;662}663UPDATE_PC(Bytecodes::length_at(METHOD, pc));664if (THREAD->has_pending_exception()) goto handle_exception;665goto run;666}667case got_monitors: {668// continue locking now that we have a monitor to use669// we expect to find newly allocated monitor at the "top" of the monitor stack.670oop lockee = STACK_OBJECT(-1);671VERIFY_OOP(lockee);672// derefing's lockee ought to provoke implicit null check673// find a free monitor674BasicObjectLock* entry = (BasicObjectLock*) istate->stack_base();675assert(entry->obj() == NULL, "Frame manager didn't allocate the monitor");676entry->set_obj(lockee);677678assert(!UseBiasedLocking, "Not implemented");679680// traditional lightweight locking681markWord displaced = lockee->mark().set_unlocked();682entry->lock()->set_displaced_header(displaced);683bool call_vm = UseHeavyMonitors;684if (call_vm || lockee->cas_set_mark(markWord::from_pointer(entry), displaced) != displaced) {685// Is it simple recursive case?686if (!call_vm && THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) {687entry->lock()->set_displaced_header(markWord::from_pointer(NULL));688} else {689CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);690}691}692UPDATE_PC_AND_TOS(1, -1);693goto run;694}695default: {696fatal("Unexpected message from frame manager");697}698}699700run:701702DO_UPDATE_INSTRUCTION_COUNT(*pc)703DEBUGGER_SINGLE_STEP_NOTIFY();704#ifdef PREFETCH_OPCCODE705opcode = *pc; /* prefetch first opcode */706#endif707708#ifndef USELABELS709while (1)710#endif711{712#ifndef PREFETCH_OPCCODE713opcode = *pc;714#endif715// Seems like this happens twice per opcode. At worst this is only716// need at entry to the loop.717// DEBUGGER_SINGLE_STEP_NOTIFY();718/* Using this labels avoids double breakpoints when quickening and719* when returing from transition frames.720*/721opcode_switch:722assert(istate == orig, "Corrupted istate");723/* QQQ Hmm this has knowledge of direction, ought to be a stack method */724assert(topOfStack >= istate->stack_limit(), "Stack overrun");725assert(topOfStack < istate->stack_base(), "Stack underrun");726727#ifdef USELABELS728DISPATCH(opcode);729#else730switch (opcode)731#endif732{733CASE(_nop):734UPDATE_PC_AND_CONTINUE(1);735736/* Push miscellaneous constants onto the stack. */737738CASE(_aconst_null):739SET_STACK_OBJECT(NULL, 0);740UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);741742#undef OPC_CONST_n743#define OPC_CONST_n(opcode, const_type, value) \744CASE(opcode): \745SET_STACK_ ## const_type(value, 0); \746UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);747748OPC_CONST_n(_iconst_m1, INT, -1);749OPC_CONST_n(_iconst_0, INT, 0);750OPC_CONST_n(_iconst_1, INT, 1);751OPC_CONST_n(_iconst_2, INT, 2);752OPC_CONST_n(_iconst_3, INT, 3);753OPC_CONST_n(_iconst_4, INT, 4);754OPC_CONST_n(_iconst_5, INT, 5);755OPC_CONST_n(_fconst_0, FLOAT, 0.0);756OPC_CONST_n(_fconst_1, FLOAT, 1.0);757OPC_CONST_n(_fconst_2, FLOAT, 2.0);758759#undef OPC_CONST2_n760#define OPC_CONST2_n(opcname, value, key, kind) \761CASE(_##opcname): \762{ \763SET_STACK_ ## kind(VM##key##Const##value(), 1); \764UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2); \765}766OPC_CONST2_n(dconst_0, Zero, double, DOUBLE);767OPC_CONST2_n(dconst_1, One, double, DOUBLE);768OPC_CONST2_n(lconst_0, Zero, long, LONG);769OPC_CONST2_n(lconst_1, One, long, LONG);770771/* Load constant from constant pool: */772773/* Push a 1-byte signed integer value onto the stack. */774CASE(_bipush):775SET_STACK_INT((jbyte)(pc[1]), 0);776UPDATE_PC_AND_TOS_AND_CONTINUE(2, 1);777778/* Push a 2-byte signed integer constant onto the stack. */779CASE(_sipush):780SET_STACK_INT((int16_t)Bytes::get_Java_u2(pc + 1), 0);781UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1);782783/* load from local variable */784785CASE(_aload):786VERIFY_OOP(LOCALS_OBJECT(pc[1]));787SET_STACK_OBJECT(LOCALS_OBJECT(pc[1]), 0);788UPDATE_PC_AND_TOS_AND_CONTINUE(2, 1);789790CASE(_iload):791CASE(_fload):792SET_STACK_SLOT(LOCALS_SLOT(pc[1]), 0);793UPDATE_PC_AND_TOS_AND_CONTINUE(2, 1);794795CASE(_lload):796SET_STACK_LONG_FROM_ADDR(LOCALS_LONG_AT(pc[1]), 1);797UPDATE_PC_AND_TOS_AND_CONTINUE(2, 2);798799CASE(_dload):800SET_STACK_DOUBLE_FROM_ADDR(LOCALS_DOUBLE_AT(pc[1]), 1);801UPDATE_PC_AND_TOS_AND_CONTINUE(2, 2);802803#undef OPC_LOAD_n804#define OPC_LOAD_n(num) \805CASE(_aload_##num): \806VERIFY_OOP(LOCALS_OBJECT(num)); \807SET_STACK_OBJECT(LOCALS_OBJECT(num), 0); \808UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1); \809\810CASE(_iload_##num): \811CASE(_fload_##num): \812SET_STACK_SLOT(LOCALS_SLOT(num), 0); \813UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1); \814\815CASE(_lload_##num): \816SET_STACK_LONG_FROM_ADDR(LOCALS_LONG_AT(num), 1); \817UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2); \818CASE(_dload_##num): \819SET_STACK_DOUBLE_FROM_ADDR(LOCALS_DOUBLE_AT(num), 1); \820UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);821822OPC_LOAD_n(0);823OPC_LOAD_n(1);824OPC_LOAD_n(2);825OPC_LOAD_n(3);826827/* store to a local variable */828829CASE(_astore):830astore(topOfStack, -1, locals, pc[1]);831UPDATE_PC_AND_TOS_AND_CONTINUE(2, -1);832833CASE(_istore):834CASE(_fstore):835SET_LOCALS_SLOT(STACK_SLOT(-1), pc[1]);836UPDATE_PC_AND_TOS_AND_CONTINUE(2, -1);837838CASE(_lstore):839SET_LOCALS_LONG(STACK_LONG(-1), pc[1]);840UPDATE_PC_AND_TOS_AND_CONTINUE(2, -2);841842CASE(_dstore):843SET_LOCALS_DOUBLE(STACK_DOUBLE(-1), pc[1]);844UPDATE_PC_AND_TOS_AND_CONTINUE(2, -2);845846CASE(_wide): {847uint16_t reg = Bytes::get_Java_u2(pc + 2);848849opcode = pc[1];850851// Wide and it's sub-bytecode are counted as separate instructions. If we852// don't account for this here, the bytecode trace skips the next bytecode.853DO_UPDATE_INSTRUCTION_COUNT(opcode);854855switch(opcode) {856case Bytecodes::_aload:857VERIFY_OOP(LOCALS_OBJECT(reg));858SET_STACK_OBJECT(LOCALS_OBJECT(reg), 0);859UPDATE_PC_AND_TOS_AND_CONTINUE(4, 1);860861case Bytecodes::_iload:862case Bytecodes::_fload:863SET_STACK_SLOT(LOCALS_SLOT(reg), 0);864UPDATE_PC_AND_TOS_AND_CONTINUE(4, 1);865866case Bytecodes::_lload:867SET_STACK_LONG_FROM_ADDR(LOCALS_LONG_AT(reg), 1);868UPDATE_PC_AND_TOS_AND_CONTINUE(4, 2);869870case Bytecodes::_dload:871SET_STACK_DOUBLE_FROM_ADDR(LOCALS_LONG_AT(reg), 1);872UPDATE_PC_AND_TOS_AND_CONTINUE(4, 2);873874case Bytecodes::_astore:875astore(topOfStack, -1, locals, reg);876UPDATE_PC_AND_TOS_AND_CONTINUE(4, -1);877878case Bytecodes::_istore:879case Bytecodes::_fstore:880SET_LOCALS_SLOT(STACK_SLOT(-1), reg);881UPDATE_PC_AND_TOS_AND_CONTINUE(4, -1);882883case Bytecodes::_lstore:884SET_LOCALS_LONG(STACK_LONG(-1), reg);885UPDATE_PC_AND_TOS_AND_CONTINUE(4, -2);886887case Bytecodes::_dstore:888SET_LOCALS_DOUBLE(STACK_DOUBLE(-1), reg);889UPDATE_PC_AND_TOS_AND_CONTINUE(4, -2);890891case Bytecodes::_iinc: {892int16_t offset = (int16_t)Bytes::get_Java_u2(pc+4);893// Be nice to see what this generates.... QQQ894SET_LOCALS_INT(LOCALS_INT(reg) + offset, reg);895UPDATE_PC_AND_CONTINUE(6);896}897case Bytecodes::_ret:898pc = istate->method()->code_base() + (intptr_t)(LOCALS_ADDR(reg));899UPDATE_PC_AND_CONTINUE(0);900default:901VM_JAVA_ERROR(vmSymbols::java_lang_InternalError(), "undefined opcode");902}903}904905906#undef OPC_STORE_n907#define OPC_STORE_n(num) \908CASE(_astore_##num): \909astore(topOfStack, -1, locals, num); \910UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); \911CASE(_istore_##num): \912CASE(_fstore_##num): \913SET_LOCALS_SLOT(STACK_SLOT(-1), num); \914UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);915916OPC_STORE_n(0);917OPC_STORE_n(1);918OPC_STORE_n(2);919OPC_STORE_n(3);920921#undef OPC_DSTORE_n922#define OPC_DSTORE_n(num) \923CASE(_dstore_##num): \924SET_LOCALS_DOUBLE(STACK_DOUBLE(-1), num); \925UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2); \926CASE(_lstore_##num): \927SET_LOCALS_LONG(STACK_LONG(-1), num); \928UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2);929930OPC_DSTORE_n(0);931OPC_DSTORE_n(1);932OPC_DSTORE_n(2);933OPC_DSTORE_n(3);934935/* stack pop, dup, and insert opcodes */936937938CASE(_pop): /* Discard the top item on the stack */939UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);940941942CASE(_pop2): /* Discard the top 2 items on the stack */943UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2);944945946CASE(_dup): /* Duplicate the top item on the stack */947dup(topOfStack);948UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);949950CASE(_dup2): /* Duplicate the top 2 items on the stack */951dup2(topOfStack);952UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);953954CASE(_dup_x1): /* insert top word two down */955dup_x1(topOfStack);956UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);957958CASE(_dup_x2): /* insert top word three down */959dup_x2(topOfStack);960UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);961962CASE(_dup2_x1): /* insert top 2 slots three down */963dup2_x1(topOfStack);964UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);965966CASE(_dup2_x2): /* insert top 2 slots four down */967dup2_x2(topOfStack);968UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);969970CASE(_swap): { /* swap top two elements on the stack */971swap(topOfStack);972UPDATE_PC_AND_CONTINUE(1);973}974975/* Perform various binary integer operations */976977#undef OPC_INT_BINARY978#define OPC_INT_BINARY(opcname, opname, test) \979CASE(_i##opcname): \980if (test && (STACK_INT(-1) == 0)) { \981VM_JAVA_ERROR(vmSymbols::java_lang_ArithmeticException(), \982"/ by zero"); \983} \984SET_STACK_INT(VMint##opname(STACK_INT(-2), \985STACK_INT(-1)), \986-2); \987UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); \988CASE(_l##opcname): \989{ \990if (test) { \991jlong l1 = STACK_LONG(-1); \992if (VMlongEqz(l1)) { \993VM_JAVA_ERROR(vmSymbols::java_lang_ArithmeticException(), \994"/ by long zero"); \995} \996} \997/* First long at (-1,-2) next long at (-3,-4) */ \998SET_STACK_LONG(VMlong##opname(STACK_LONG(-3), \999STACK_LONG(-1)), \1000-3); \1001UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2); \1002}10031004OPC_INT_BINARY(add, Add, 0);1005OPC_INT_BINARY(sub, Sub, 0);1006OPC_INT_BINARY(mul, Mul, 0);1007OPC_INT_BINARY(and, And, 0);1008OPC_INT_BINARY(or, Or, 0);1009OPC_INT_BINARY(xor, Xor, 0);1010OPC_INT_BINARY(div, Div, 1);1011OPC_INT_BINARY(rem, Rem, 1);101210131014/* Perform various binary floating number operations */1015/* On some machine/platforms/compilers div zero check can be implicit */10161017#undef OPC_FLOAT_BINARY1018#define OPC_FLOAT_BINARY(opcname, opname) \1019CASE(_d##opcname): { \1020SET_STACK_DOUBLE(VMdouble##opname(STACK_DOUBLE(-3), \1021STACK_DOUBLE(-1)), \1022-3); \1023UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2); \1024} \1025CASE(_f##opcname): \1026SET_STACK_FLOAT(VMfloat##opname(STACK_FLOAT(-2), \1027STACK_FLOAT(-1)), \1028-2); \1029UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);103010311032OPC_FLOAT_BINARY(add, Add);1033OPC_FLOAT_BINARY(sub, Sub);1034OPC_FLOAT_BINARY(mul, Mul);1035OPC_FLOAT_BINARY(div, Div);1036OPC_FLOAT_BINARY(rem, Rem);10371038/* Shift operations1039* Shift left int and long: ishl, lshl1040* Logical shift right int and long w/zero extension: iushr, lushr1041* Arithmetic shift right int and long w/sign extension: ishr, lshr1042*/10431044#undef OPC_SHIFT_BINARY1045#define OPC_SHIFT_BINARY(opcname, opname) \1046CASE(_i##opcname): \1047SET_STACK_INT(VMint##opname(STACK_INT(-2), \1048STACK_INT(-1)), \1049-2); \1050UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); \1051CASE(_l##opcname): \1052{ \1053SET_STACK_LONG(VMlong##opname(STACK_LONG(-2), \1054STACK_INT(-1)), \1055-2); \1056UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); \1057}10581059OPC_SHIFT_BINARY(shl, Shl);1060OPC_SHIFT_BINARY(shr, Shr);1061OPC_SHIFT_BINARY(ushr, Ushr);10621063/* Increment local variable by constant */1064CASE(_iinc):1065{1066// locals[pc[1]].j.i += (jbyte)(pc[2]);1067SET_LOCALS_INT(LOCALS_INT(pc[1]) + (jbyte)(pc[2]), pc[1]);1068UPDATE_PC_AND_CONTINUE(3);1069}10701071/* negate the value on the top of the stack */10721073CASE(_ineg):1074SET_STACK_INT(VMintNeg(STACK_INT(-1)), -1);1075UPDATE_PC_AND_CONTINUE(1);10761077CASE(_fneg):1078SET_STACK_FLOAT(VMfloatNeg(STACK_FLOAT(-1)), -1);1079UPDATE_PC_AND_CONTINUE(1);10801081CASE(_lneg):1082{1083SET_STACK_LONG(VMlongNeg(STACK_LONG(-1)), -1);1084UPDATE_PC_AND_CONTINUE(1);1085}10861087CASE(_dneg):1088{1089SET_STACK_DOUBLE(VMdoubleNeg(STACK_DOUBLE(-1)), -1);1090UPDATE_PC_AND_CONTINUE(1);1091}10921093/* Conversion operations */10941095CASE(_i2f): /* convert top of stack int to float */1096SET_STACK_FLOAT(VMint2Float(STACK_INT(-1)), -1);1097UPDATE_PC_AND_CONTINUE(1);10981099CASE(_i2l): /* convert top of stack int to long */1100{1101// this is ugly QQQ1102jlong r = VMint2Long(STACK_INT(-1));1103MORE_STACK(-1); // Pop1104SET_STACK_LONG(r, 1);11051106UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);1107}11081109CASE(_i2d): /* convert top of stack int to double */1110{1111// this is ugly QQQ (why cast to jlong?? )1112jdouble r = (jlong)STACK_INT(-1);1113MORE_STACK(-1); // Pop1114SET_STACK_DOUBLE(r, 1);11151116UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);1117}11181119CASE(_l2i): /* convert top of stack long to int */1120{1121jint r = VMlong2Int(STACK_LONG(-1));1122MORE_STACK(-2); // Pop1123SET_STACK_INT(r, 0);1124UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);1125}11261127CASE(_l2f): /* convert top of stack long to float */1128{1129jlong r = STACK_LONG(-1);1130MORE_STACK(-2); // Pop1131SET_STACK_FLOAT(VMlong2Float(r), 0);1132UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);1133}11341135CASE(_l2d): /* convert top of stack long to double */1136{1137jlong r = STACK_LONG(-1);1138MORE_STACK(-2); // Pop1139SET_STACK_DOUBLE(VMlong2Double(r), 1);1140UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);1141}11421143CASE(_f2i): /* Convert top of stack float to int */1144SET_STACK_INT(SharedRuntime::f2i(STACK_FLOAT(-1)), -1);1145UPDATE_PC_AND_CONTINUE(1);11461147CASE(_f2l): /* convert top of stack float to long */1148{1149jlong r = SharedRuntime::f2l(STACK_FLOAT(-1));1150MORE_STACK(-1); // POP1151SET_STACK_LONG(r, 1);1152UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);1153}11541155CASE(_f2d): /* convert top of stack float to double */1156{1157jfloat f;1158jdouble r;1159f = STACK_FLOAT(-1);1160r = (jdouble) f;1161MORE_STACK(-1); // POP1162SET_STACK_DOUBLE(r, 1);1163UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);1164}11651166CASE(_d2i): /* convert top of stack double to int */1167{1168jint r1 = SharedRuntime::d2i(STACK_DOUBLE(-1));1169MORE_STACK(-2);1170SET_STACK_INT(r1, 0);1171UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);1172}11731174CASE(_d2f): /* convert top of stack double to float */1175{1176jfloat r1 = VMdouble2Float(STACK_DOUBLE(-1));1177MORE_STACK(-2);1178SET_STACK_FLOAT(r1, 0);1179UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);1180}11811182CASE(_d2l): /* convert top of stack double to long */1183{1184jlong r1 = SharedRuntime::d2l(STACK_DOUBLE(-1));1185MORE_STACK(-2);1186SET_STACK_LONG(r1, 1);1187UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);1188}11891190CASE(_i2b):1191SET_STACK_INT(VMint2Byte(STACK_INT(-1)), -1);1192UPDATE_PC_AND_CONTINUE(1);11931194CASE(_i2c):1195SET_STACK_INT(VMint2Char(STACK_INT(-1)), -1);1196UPDATE_PC_AND_CONTINUE(1);11971198CASE(_i2s):1199SET_STACK_INT(VMint2Short(STACK_INT(-1)), -1);1200UPDATE_PC_AND_CONTINUE(1);12011202/* comparison operators */120312041205#define COMPARISON_OP(name, comparison) \1206CASE(_if_icmp##name): { \1207int skip = (STACK_INT(-2) comparison STACK_INT(-1)) \1208? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \1209address branch_pc = pc; \1210UPDATE_PC_AND_TOS(skip, -2); \1211DO_BACKEDGE_CHECKS(skip, branch_pc); \1212CONTINUE; \1213} \1214CASE(_if##name): { \1215int skip = (STACK_INT(-1) comparison 0) \1216? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \1217address branch_pc = pc; \1218UPDATE_PC_AND_TOS(skip, -1); \1219DO_BACKEDGE_CHECKS(skip, branch_pc); \1220CONTINUE; \1221}12221223#define COMPARISON_OP2(name, comparison) \1224COMPARISON_OP(name, comparison) \1225CASE(_if_acmp##name): { \1226int skip = (STACK_OBJECT(-2) comparison STACK_OBJECT(-1)) \1227? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \1228address branch_pc = pc; \1229UPDATE_PC_AND_TOS(skip, -2); \1230DO_BACKEDGE_CHECKS(skip, branch_pc); \1231CONTINUE; \1232}12331234#define NULL_COMPARISON_NOT_OP(name) \1235CASE(_if##name): { \1236int skip = (!(STACK_OBJECT(-1) == NULL)) \1237? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \1238address branch_pc = pc; \1239UPDATE_PC_AND_TOS(skip, -1); \1240DO_BACKEDGE_CHECKS(skip, branch_pc); \1241CONTINUE; \1242}12431244#define NULL_COMPARISON_OP(name) \1245CASE(_if##name): { \1246int skip = ((STACK_OBJECT(-1) == NULL)) \1247? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \1248address branch_pc = pc; \1249UPDATE_PC_AND_TOS(skip, -1); \1250DO_BACKEDGE_CHECKS(skip, branch_pc); \1251CONTINUE; \1252}1253COMPARISON_OP(lt, <);1254COMPARISON_OP(gt, >);1255COMPARISON_OP(le, <=);1256COMPARISON_OP(ge, >=);1257COMPARISON_OP2(eq, ==); /* include ref comparison */1258COMPARISON_OP2(ne, !=); /* include ref comparison */1259NULL_COMPARISON_OP(null);1260NULL_COMPARISON_NOT_OP(nonnull);12611262/* Goto pc at specified offset in switch table. */12631264CASE(_tableswitch): {1265jint* lpc = (jint*)VMalignWordUp(pc+1);1266int32_t key = STACK_INT(-1);1267int32_t low = Bytes::get_Java_u4((address)&lpc[1]);1268int32_t high = Bytes::get_Java_u4((address)&lpc[2]);1269int32_t skip;1270key -= low;1271if (((uint32_t) key > (uint32_t)(high - low))) {1272skip = Bytes::get_Java_u4((address)&lpc[0]);1273} else {1274skip = Bytes::get_Java_u4((address)&lpc[key + 3]);1275}1276// Does this really need a full backedge check (osr)?1277address branch_pc = pc;1278UPDATE_PC_AND_TOS(skip, -1);1279DO_BACKEDGE_CHECKS(skip, branch_pc);1280CONTINUE;1281}12821283/* Goto pc whose table entry matches specified key. */12841285CASE(_lookupswitch): {1286jint* lpc = (jint*)VMalignWordUp(pc+1);1287int32_t key = STACK_INT(-1);1288int32_t skip = Bytes::get_Java_u4((address) lpc); /* default amount */1289int32_t npairs = Bytes::get_Java_u4((address) &lpc[1]);1290while (--npairs >= 0) {1291lpc += 2;1292if (key == (int32_t)Bytes::get_Java_u4((address)lpc)) {1293skip = Bytes::get_Java_u4((address)&lpc[1]);1294break;1295}1296}1297address branch_pc = pc;1298UPDATE_PC_AND_TOS(skip, -1);1299DO_BACKEDGE_CHECKS(skip, branch_pc);1300CONTINUE;1301}13021303CASE(_fcmpl):1304CASE(_fcmpg):1305{1306SET_STACK_INT(VMfloatCompare(STACK_FLOAT(-2),1307STACK_FLOAT(-1),1308(opcode == Bytecodes::_fcmpl ? -1 : 1)),1309-2);1310UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);1311}13121313CASE(_dcmpl):1314CASE(_dcmpg):1315{1316int r = VMdoubleCompare(STACK_DOUBLE(-3),1317STACK_DOUBLE(-1),1318(opcode == Bytecodes::_dcmpl ? -1 : 1));1319MORE_STACK(-4); // Pop1320SET_STACK_INT(r, 0);1321UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);1322}13231324CASE(_lcmp):1325{1326int r = VMlongCompare(STACK_LONG(-3), STACK_LONG(-1));1327MORE_STACK(-4);1328SET_STACK_INT(r, 0);1329UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);1330}133113321333/* Return from a method */13341335CASE(_areturn):1336CASE(_ireturn):1337CASE(_freturn):1338{1339// Allow a safepoint before returning to frame manager.1340SAFEPOINT;13411342goto handle_return;1343}13441345CASE(_lreturn):1346CASE(_dreturn):1347{1348// Allow a safepoint before returning to frame manager.1349SAFEPOINT;1350goto handle_return;1351}13521353CASE(_return_register_finalizer): {13541355oop rcvr = LOCALS_OBJECT(0);1356VERIFY_OOP(rcvr);1357if (rcvr->klass()->has_finalizer()) {1358CALL_VM(InterpreterRuntime::register_finalizer(THREAD, rcvr), handle_exception);1359}1360goto handle_return;1361}1362CASE(_return): {13631364// Allow a safepoint before returning to frame manager.1365SAFEPOINT;1366goto handle_return;1367}13681369/* Array access byte-codes */13701371/* Every array access byte-code starts out like this */1372// arrayOopDesc* arrObj = (arrayOopDesc*)STACK_OBJECT(arrayOff);1373#define ARRAY_INTRO(arrayOff) \1374arrayOop arrObj = (arrayOop)STACK_OBJECT(arrayOff); \1375jint index = STACK_INT(arrayOff + 1); \1376/* Two integers, the additional message, and the null-terminator */ \1377char message[2 * jintAsStringSize + 33]; \1378CHECK_NULL(arrObj); \1379if ((uint32_t)index >= (uint32_t)arrObj->length()) { \1380jio_snprintf(message, sizeof(message), \1381"Index %d out of bounds for length %d", \1382index, arrObj->length()); \1383VM_JAVA_ERROR(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), \1384message); \1385}13861387/* 32-bit loads. These handle conversion from < 32-bit types */1388#define ARRAY_LOADTO32(T, T2, format, stackRes, extra) \1389{ \1390ARRAY_INTRO(-2); \1391(void)extra; \1392SET_ ## stackRes(*(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)), \1393-2); \1394UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); \1395}13961397/* 64-bit loads */1398#define ARRAY_LOADTO64(T,T2, stackRes, extra) \1399{ \1400ARRAY_INTRO(-2); \1401SET_ ## stackRes(*(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)), -1); \1402(void)extra; \1403UPDATE_PC_AND_CONTINUE(1); \1404}14051406CASE(_iaload):1407ARRAY_LOADTO32(T_INT, jint, "%d", STACK_INT, 0);1408CASE(_faload):1409ARRAY_LOADTO32(T_FLOAT, jfloat, "%f", STACK_FLOAT, 0);1410CASE(_aaload): {1411ARRAY_INTRO(-2);1412SET_STACK_OBJECT(((objArrayOop) arrObj)->obj_at(index), -2);1413UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);1414}1415CASE(_baload):1416ARRAY_LOADTO32(T_BYTE, jbyte, "%d", STACK_INT, 0);1417CASE(_caload):1418ARRAY_LOADTO32(T_CHAR, jchar, "%d", STACK_INT, 0);1419CASE(_saload):1420ARRAY_LOADTO32(T_SHORT, jshort, "%d", STACK_INT, 0);1421CASE(_laload):1422ARRAY_LOADTO64(T_LONG, jlong, STACK_LONG, 0);1423CASE(_daload):1424ARRAY_LOADTO64(T_DOUBLE, jdouble, STACK_DOUBLE, 0);14251426/* 32-bit stores. These handle conversion to < 32-bit types */1427#define ARRAY_STOREFROM32(T, T2, format, stackSrc, extra) \1428{ \1429ARRAY_INTRO(-3); \1430(void)extra; \1431*(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)) = stackSrc( -1); \1432UPDATE_PC_AND_TOS_AND_CONTINUE(1, -3); \1433}14341435/* 64-bit stores */1436#define ARRAY_STOREFROM64(T, T2, stackSrc, extra) \1437{ \1438ARRAY_INTRO(-4); \1439(void)extra; \1440*(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)) = stackSrc( -1); \1441UPDATE_PC_AND_TOS_AND_CONTINUE(1, -4); \1442}14431444CASE(_iastore):1445ARRAY_STOREFROM32(T_INT, jint, "%d", STACK_INT, 0);1446CASE(_fastore):1447ARRAY_STOREFROM32(T_FLOAT, jfloat, "%f", STACK_FLOAT, 0);1448/*1449* This one looks different because of the assignability check1450*/1451CASE(_aastore): {1452oop rhsObject = STACK_OBJECT(-1);1453VERIFY_OOP(rhsObject);1454ARRAY_INTRO( -3);1455// arrObj, index are set1456if (rhsObject != NULL) {1457/* Check assignability of rhsObject into arrObj */1458Klass* rhsKlass = rhsObject->klass(); // EBX (subclass)1459Klass* elemKlass = ObjArrayKlass::cast(arrObj->klass())->element_klass(); // superklass EAX1460//1461// Check for compatibilty. This check must not GC!!1462// Seems way more expensive now that we must dispatch1463//1464if (rhsKlass != elemKlass && !rhsKlass->is_subtype_of(elemKlass)) { // ebx->is...1465VM_JAVA_ERROR(vmSymbols::java_lang_ArrayStoreException(), "");1466}1467}1468((objArrayOop) arrObj)->obj_at_put(index, rhsObject);1469UPDATE_PC_AND_TOS_AND_CONTINUE(1, -3);1470}1471CASE(_bastore): {1472ARRAY_INTRO(-3);1473int item = STACK_INT(-1);1474// if it is a T_BOOLEAN array, mask the stored value to 0/11475if (arrObj->klass() == Universe::boolArrayKlassObj()) {1476item &= 1;1477} else {1478assert(arrObj->klass() == Universe::byteArrayKlassObj(),1479"should be byte array otherwise");1480}1481((typeArrayOop)arrObj)->byte_at_put(index, item);1482UPDATE_PC_AND_TOS_AND_CONTINUE(1, -3);1483}1484CASE(_castore):1485ARRAY_STOREFROM32(T_CHAR, jchar, "%d", STACK_INT, 0);1486CASE(_sastore):1487ARRAY_STOREFROM32(T_SHORT, jshort, "%d", STACK_INT, 0);1488CASE(_lastore):1489ARRAY_STOREFROM64(T_LONG, jlong, STACK_LONG, 0);1490CASE(_dastore):1491ARRAY_STOREFROM64(T_DOUBLE, jdouble, STACK_DOUBLE, 0);14921493CASE(_arraylength):1494{1495arrayOop ary = (arrayOop) STACK_OBJECT(-1);1496CHECK_NULL(ary);1497SET_STACK_INT(ary->length(), -1);1498UPDATE_PC_AND_CONTINUE(1);1499}15001501/* monitorenter and monitorexit for locking/unlocking an object */15021503CASE(_monitorenter): {1504oop lockee = STACK_OBJECT(-1);1505// derefing's lockee ought to provoke implicit null check1506CHECK_NULL(lockee);1507// find a free monitor or one already allocated for this object1508// if we find a matching object then we need a new monitor1509// since this is recursive enter1510BasicObjectLock* limit = istate->monitor_base();1511BasicObjectLock* most_recent = (BasicObjectLock*) istate->stack_base();1512BasicObjectLock* entry = NULL;1513while (most_recent != limit ) {1514if (most_recent->obj() == NULL) entry = most_recent;1515else if (most_recent->obj() == lockee) break;1516most_recent++;1517}1518if (entry != NULL) {1519entry->set_obj(lockee);15201521assert(!UseBiasedLocking, "Not implemented");15221523// traditional lightweight locking1524markWord displaced = lockee->mark().set_unlocked();1525entry->lock()->set_displaced_header(displaced);1526bool call_vm = UseHeavyMonitors;1527if (call_vm || lockee->cas_set_mark(markWord::from_pointer(entry), displaced) != displaced) {1528// Is it simple recursive case?1529if (!call_vm && THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) {1530entry->lock()->set_displaced_header(markWord::from_pointer(NULL));1531} else {1532CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);1533}1534}1535UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);1536} else {1537istate->set_msg(more_monitors);1538UPDATE_PC_AND_RETURN(0); // Re-execute1539}1540}15411542CASE(_monitorexit): {1543oop lockee = STACK_OBJECT(-1);1544CHECK_NULL(lockee);1545// derefing's lockee ought to provoke implicit null check1546// find our monitor slot1547BasicObjectLock* limit = istate->monitor_base();1548BasicObjectLock* most_recent = (BasicObjectLock*) istate->stack_base();1549while (most_recent != limit ) {1550if ((most_recent)->obj() == lockee) {1551BasicLock* lock = most_recent->lock();1552markWord header = lock->displaced_header();1553most_recent->set_obj(NULL);15541555assert(!UseBiasedLocking, "Not implemented");15561557// If it isn't recursive we either must swap old header or call the runtime1558bool call_vm = UseHeavyMonitors;1559if (header.to_pointer() != NULL || call_vm) {1560markWord old_header = markWord::encode(lock);1561if (call_vm || lockee->cas_set_mark(header, old_header) != old_header) {1562// restore object for the slow case1563most_recent->set_obj(lockee);1564InterpreterRuntime::monitorexit(most_recent);1565}1566}1567UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);1568}1569most_recent++;1570}1571// Need to throw illegal monitor state exception1572CALL_VM(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD), handle_exception);1573ShouldNotReachHere();1574}15751576/* All of the non-quick opcodes. */15771578/* -Set clobbersCpIndex true if the quickened opcode clobbers the1579* constant pool index in the instruction.1580*/1581CASE(_getfield):1582CASE(_getstatic):1583{1584u2 index;1585ConstantPoolCacheEntry* cache;1586index = Bytes::get_native_u2(pc+1);15871588// QQQ Need to make this as inlined as possible. Probably need to1589// split all the bytecode cases out so c++ compiler has a chance1590// for constant prop to fold everything possible away.15911592cache = cp->entry_at(index);1593if (!cache->is_resolved((Bytecodes::Code)opcode)) {1594CALL_VM(InterpreterRuntime::resolve_from_cache(THREAD, (Bytecodes::Code)opcode),1595handle_exception);1596cache = cp->entry_at(index);1597}15981599if (JVMTI_ENABLED) {1600int *count_addr;1601oop obj;1602// Check to see if a field modification watch has been set1603// before we take the time to call into the VM.1604count_addr = (int *)JvmtiExport::get_field_access_count_addr();1605if ( *count_addr > 0 ) {1606if ((Bytecodes::Code)opcode == Bytecodes::_getstatic) {1607obj = NULL;1608} else {1609obj = STACK_OBJECT(-1);1610VERIFY_OOP(obj);1611}1612CALL_VM(InterpreterRuntime::post_field_access(THREAD,1613obj,1614cache),1615handle_exception);1616}1617}16181619oop obj;1620if ((Bytecodes::Code)opcode == Bytecodes::_getstatic) {1621Klass* k = cache->f1_as_klass();1622obj = k->java_mirror();1623MORE_STACK(1); // Assume single slot push1624} else {1625obj = STACK_OBJECT(-1);1626CHECK_NULL(obj);1627}16281629//1630// Now store the result on the stack1631//1632TosState tos_type = cache->flag_state();1633int field_offset = cache->f2_as_index();1634if (cache->is_volatile()) {1635if (support_IRIW_for_not_multiple_copy_atomic_cpu) {1636OrderAccess::fence();1637}1638switch (tos_type) {1639case btos:1640case ztos:1641SET_STACK_INT(obj->byte_field_acquire(field_offset), -1);1642break;1643case ctos:1644SET_STACK_INT(obj->char_field_acquire(field_offset), -1);1645break;1646case stos:1647SET_STACK_INT(obj->short_field_acquire(field_offset), -1);1648break;1649case itos:1650SET_STACK_INT(obj->int_field_acquire(field_offset), -1);1651break;1652case ftos:1653SET_STACK_FLOAT(obj->float_field_acquire(field_offset), -1);1654break;1655case ltos:1656SET_STACK_LONG(obj->long_field_acquire(field_offset), 0);1657MORE_STACK(1);1658break;1659case dtos:1660SET_STACK_DOUBLE(obj->double_field_acquire(field_offset), 0);1661MORE_STACK(1);1662break;1663case atos: {1664oop val = obj->obj_field_acquire(field_offset);1665VERIFY_OOP(val);1666SET_STACK_OBJECT(val, -1);1667break;1668}1669default:1670ShouldNotReachHere();1671}1672} else {1673switch (tos_type) {1674case btos:1675case ztos:1676SET_STACK_INT(obj->byte_field(field_offset), -1);1677break;1678case ctos:1679SET_STACK_INT(obj->char_field(field_offset), -1);1680break;1681case stos:1682SET_STACK_INT(obj->short_field(field_offset), -1);1683break;1684case itos:1685SET_STACK_INT(obj->int_field(field_offset), -1);1686break;1687case ftos:1688SET_STACK_FLOAT(obj->float_field(field_offset), -1);1689break;1690case ltos:1691SET_STACK_LONG(obj->long_field(field_offset), 0);1692MORE_STACK(1);1693break;1694case dtos:1695SET_STACK_DOUBLE(obj->double_field(field_offset), 0);1696MORE_STACK(1);1697break;1698case atos: {1699oop val = obj->obj_field(field_offset);1700VERIFY_OOP(val);1701SET_STACK_OBJECT(val, -1);1702break;1703}1704default:1705ShouldNotReachHere();1706}1707}17081709UPDATE_PC_AND_CONTINUE(3);1710}17111712CASE(_putfield):1713CASE(_putstatic):1714{1715u2 index = Bytes::get_native_u2(pc+1);1716ConstantPoolCacheEntry* cache = cp->entry_at(index);1717if (!cache->is_resolved((Bytecodes::Code)opcode)) {1718CALL_VM(InterpreterRuntime::resolve_from_cache(THREAD, (Bytecodes::Code)opcode),1719handle_exception);1720cache = cp->entry_at(index);1721}17221723if (JVMTI_ENABLED) {1724int *count_addr;1725oop obj;1726// Check to see if a field modification watch has been set1727// before we take the time to call into the VM.1728count_addr = (int *)JvmtiExport::get_field_modification_count_addr();1729if ( *count_addr > 0 ) {1730if ((Bytecodes::Code)opcode == Bytecodes::_putstatic) {1731obj = NULL;1732}1733else {1734if (cache->is_long() || cache->is_double()) {1735obj = STACK_OBJECT(-3);1736} else {1737obj = STACK_OBJECT(-2);1738}1739VERIFY_OOP(obj);1740}17411742CALL_VM(InterpreterRuntime::post_field_modification(THREAD,1743obj,1744cache,1745(jvalue *)STACK_SLOT(-1)),1746handle_exception);1747}1748}17491750// QQQ Need to make this as inlined as possible. Probably need to split all the bytecode cases1751// out so c++ compiler has a chance for constant prop to fold everything possible away.17521753oop obj;1754int count;1755TosState tos_type = cache->flag_state();17561757count = -1;1758if (tos_type == ltos || tos_type == dtos) {1759--count;1760}1761if ((Bytecodes::Code)opcode == Bytecodes::_putstatic) {1762Klass* k = cache->f1_as_klass();1763obj = k->java_mirror();1764} else {1765--count;1766obj = STACK_OBJECT(count);1767CHECK_NULL(obj);1768}17691770//1771// Now store the result1772//1773int field_offset = cache->f2_as_index();1774if (cache->is_volatile()) {1775switch (tos_type) {1776case ztos:1777obj->release_byte_field_put(field_offset, (STACK_INT(-1) & 1)); // only store LSB1778break;1779case btos:1780obj->release_byte_field_put(field_offset, STACK_INT(-1));1781break;1782case ctos:1783obj->release_char_field_put(field_offset, STACK_INT(-1));1784break;1785case stos:1786obj->release_short_field_put(field_offset, STACK_INT(-1));1787break;1788case itos:1789obj->release_int_field_put(field_offset, STACK_INT(-1));1790break;1791case ftos:1792obj->release_float_field_put(field_offset, STACK_FLOAT(-1));1793break;1794case ltos:1795obj->release_long_field_put(field_offset, STACK_LONG(-1));1796break;1797case dtos:1798obj->release_double_field_put(field_offset, STACK_DOUBLE(-1));1799break;1800case atos: {1801oop val = STACK_OBJECT(-1);1802VERIFY_OOP(val);1803obj->release_obj_field_put(field_offset, val);1804break;1805}1806default:1807ShouldNotReachHere();1808}1809OrderAccess::storeload();1810} else {1811switch (tos_type) {1812case ztos:1813obj->byte_field_put(field_offset, (STACK_INT(-1) & 1)); // only store LSB1814break;1815case btos:1816obj->byte_field_put(field_offset, STACK_INT(-1));1817break;1818case ctos:1819obj->char_field_put(field_offset, STACK_INT(-1));1820break;1821case stos:1822obj->short_field_put(field_offset, STACK_INT(-1));1823break;1824case itos:1825obj->int_field_put(field_offset, STACK_INT(-1));1826break;1827case ftos:1828obj->float_field_put(field_offset, STACK_FLOAT(-1));1829break;1830case ltos:1831obj->long_field_put(field_offset, STACK_LONG(-1));1832break;1833case dtos:1834obj->double_field_put(field_offset, STACK_DOUBLE(-1));1835break;1836case atos: {1837oop val = STACK_OBJECT(-1);1838VERIFY_OOP(val);1839obj->obj_field_put(field_offset, val);1840break;1841}1842default:1843ShouldNotReachHere();1844}1845}18461847UPDATE_PC_AND_TOS_AND_CONTINUE(3, count);1848}18491850CASE(_new): {1851u2 index = Bytes::get_Java_u2(pc+1);18521853// Attempt TLAB allocation first.1854//1855// To do this, we need to make sure:1856// - klass is initialized1857// - klass can be fastpath allocated (e.g. does not have finalizer)1858// - TLAB accepts the allocation1859ConstantPool* constants = istate->method()->constants();1860if (UseTLAB && !constants->tag_at(index).is_unresolved_klass()) {1861Klass* entry = constants->resolved_klass_at(index);1862InstanceKlass* ik = InstanceKlass::cast(entry);1863if (ik->is_initialized() && ik->can_be_fastpath_allocated()) {1864size_t obj_size = ik->size_helper();1865HeapWord* result = THREAD->tlab().allocate(obj_size);1866if (result != NULL) {1867// Initialize object field block:1868// - if TLAB is pre-zeroed, we can skip this path1869// - in debug mode, ThreadLocalAllocBuffer::allocate mangles1870// this area, and we still need to initialize it1871if (DEBUG_ONLY(true ||) !ZeroTLAB) {1872size_t hdr_size = oopDesc::header_size();1873Copy::fill_to_words(result + hdr_size, obj_size - hdr_size, 0);1874}18751876oop obj = cast_to_oop(result);18771878// Initialize header1879assert(!UseBiasedLocking, "Not implemented");1880obj->set_mark(markWord::prototype());1881obj->set_klass_gap(0);1882obj->set_klass(ik);18831884// Must prevent reordering of stores for object initialization1885// with stores that publish the new object.1886OrderAccess::storestore();1887SET_STACK_OBJECT(obj, 0);1888UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1);1889}1890}1891}1892// Slow case allocation1893CALL_VM(InterpreterRuntime::_new(THREAD, METHOD->constants(), index),1894handle_exception);1895// Must prevent reordering of stores for object initialization1896// with stores that publish the new object.1897OrderAccess::storestore();1898SET_STACK_OBJECT(THREAD->vm_result(), 0);1899THREAD->set_vm_result(NULL);1900UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1);1901}1902CASE(_anewarray): {1903u2 index = Bytes::get_Java_u2(pc+1);1904jint size = STACK_INT(-1);1905CALL_VM(InterpreterRuntime::anewarray(THREAD, METHOD->constants(), index, size),1906handle_exception);1907// Must prevent reordering of stores for object initialization1908// with stores that publish the new object.1909OrderAccess::storestore();1910SET_STACK_OBJECT(THREAD->vm_result(), -1);1911THREAD->set_vm_result(NULL);1912UPDATE_PC_AND_CONTINUE(3);1913}1914CASE(_multianewarray): {1915jint dims = *(pc+3);1916jint size = STACK_INT(-1);1917// stack grows down, dimensions are up!1918jint *dimarray =1919(jint*)&topOfStack[dims * Interpreter::stackElementWords+1920Interpreter::stackElementWords-1];1921//adjust pointer to start of stack element1922CALL_VM(InterpreterRuntime::multianewarray(THREAD, dimarray),1923handle_exception);1924// Must prevent reordering of stores for object initialization1925// with stores that publish the new object.1926OrderAccess::storestore();1927SET_STACK_OBJECT(THREAD->vm_result(), -dims);1928THREAD->set_vm_result(NULL);1929UPDATE_PC_AND_TOS_AND_CONTINUE(4, -(dims-1));1930}1931CASE(_checkcast):1932if (STACK_OBJECT(-1) != NULL) {1933VERIFY_OOP(STACK_OBJECT(-1));1934u2 index = Bytes::get_Java_u2(pc+1);1935// Constant pool may have actual klass or unresolved klass. If it is1936// unresolved we must resolve it.1937if (METHOD->constants()->tag_at(index).is_unresolved_klass()) {1938CALL_VM(InterpreterRuntime::quicken_io_cc(THREAD), handle_exception);1939}1940Klass* klassOf = (Klass*) METHOD->constants()->resolved_klass_at(index);1941Klass* objKlass = STACK_OBJECT(-1)->klass(); // ebx1942//1943// Check for compatibilty. This check must not GC!!1944// Seems way more expensive now that we must dispatch.1945//1946if (objKlass != klassOf && !objKlass->is_subtype_of(klassOf)) {1947ResourceMark rm(THREAD);1948char* message = SharedRuntime::generate_class_cast_message(1949objKlass, klassOf);1950VM_JAVA_ERROR(vmSymbols::java_lang_ClassCastException(), message);1951}1952}1953UPDATE_PC_AND_CONTINUE(3);19541955CASE(_instanceof):1956if (STACK_OBJECT(-1) == NULL) {1957SET_STACK_INT(0, -1);1958} else {1959VERIFY_OOP(STACK_OBJECT(-1));1960u2 index = Bytes::get_Java_u2(pc+1);1961// Constant pool may have actual klass or unresolved klass. If it is1962// unresolved we must resolve it.1963if (METHOD->constants()->tag_at(index).is_unresolved_klass()) {1964CALL_VM(InterpreterRuntime::quicken_io_cc(THREAD), handle_exception);1965}1966Klass* klassOf = (Klass*) METHOD->constants()->resolved_klass_at(index);1967Klass* objKlass = STACK_OBJECT(-1)->klass();1968//1969// Check for compatibilty. This check must not GC!!1970// Seems way more expensive now that we must dispatch.1971//1972if ( objKlass == klassOf || objKlass->is_subtype_of(klassOf)) {1973SET_STACK_INT(1, -1);1974} else {1975SET_STACK_INT(0, -1);1976}1977}1978UPDATE_PC_AND_CONTINUE(3);19791980CASE(_ldc_w):1981CASE(_ldc):1982{1983u2 index;1984bool wide = false;1985int incr = 2; // frequent case1986if (opcode == Bytecodes::_ldc) {1987index = pc[1];1988} else {1989index = Bytes::get_Java_u2(pc+1);1990incr = 3;1991wide = true;1992}19931994ConstantPool* constants = METHOD->constants();1995switch (constants->tag_at(index).value()) {1996case JVM_CONSTANT_Integer:1997SET_STACK_INT(constants->int_at(index), 0);1998break;19992000case JVM_CONSTANT_Float:2001SET_STACK_FLOAT(constants->float_at(index), 0);2002break;20032004case JVM_CONSTANT_String:2005{2006oop result = constants->resolved_references()->obj_at(index);2007if (result == NULL) {2008CALL_VM(InterpreterRuntime::resolve_ldc(THREAD, (Bytecodes::Code) opcode), handle_exception);2009SET_STACK_OBJECT(THREAD->vm_result(), 0);2010THREAD->set_vm_result(NULL);2011} else {2012VERIFY_OOP(result);2013SET_STACK_OBJECT(result, 0);2014}2015break;2016}20172018case JVM_CONSTANT_Class:2019VERIFY_OOP(constants->resolved_klass_at(index)->java_mirror());2020SET_STACK_OBJECT(constants->resolved_klass_at(index)->java_mirror(), 0);2021break;20222023case JVM_CONSTANT_UnresolvedClass:2024case JVM_CONSTANT_UnresolvedClassInError:2025CALL_VM(InterpreterRuntime::ldc(THREAD, wide), handle_exception);2026SET_STACK_OBJECT(THREAD->vm_result(), 0);2027THREAD->set_vm_result(NULL);2028break;20292030case JVM_CONSTANT_Dynamic:2031case JVM_CONSTANT_DynamicInError:2032{2033CALL_VM(InterpreterRuntime::resolve_ldc(THREAD, (Bytecodes::Code) opcode), handle_exception);2034oop result = THREAD->vm_result();2035VERIFY_OOP(result);20362037jvalue value;2038BasicType type = java_lang_boxing_object::get_value(result, &value);2039switch (type) {2040case T_FLOAT: SET_STACK_FLOAT(value.f, 0); break;2041case T_INT: SET_STACK_INT(value.i, 0); break;2042case T_SHORT: SET_STACK_INT(value.s, 0); break;2043case T_BYTE: SET_STACK_INT(value.b, 0); break;2044case T_CHAR: SET_STACK_INT(value.c, 0); break;2045case T_BOOLEAN: SET_STACK_INT(value.z, 0); break;2046default: ShouldNotReachHere();2047}20482049break;2050}20512052default: ShouldNotReachHere();2053}2054UPDATE_PC_AND_TOS_AND_CONTINUE(incr, 1);2055}20562057CASE(_ldc2_w):2058{2059u2 index = Bytes::get_Java_u2(pc+1);20602061ConstantPool* constants = METHOD->constants();2062switch (constants->tag_at(index).value()) {20632064case JVM_CONSTANT_Long:2065SET_STACK_LONG(constants->long_at(index), 1);2066break;20672068case JVM_CONSTANT_Double:2069SET_STACK_DOUBLE(constants->double_at(index), 1);2070break;20712072case JVM_CONSTANT_Dynamic:2073case JVM_CONSTANT_DynamicInError:2074{2075CALL_VM(InterpreterRuntime::resolve_ldc(THREAD, (Bytecodes::Code) opcode), handle_exception);2076oop result = THREAD->vm_result();2077VERIFY_OOP(result);20782079jvalue value;2080BasicType type = java_lang_boxing_object::get_value(result, &value);2081switch (type) {2082case T_DOUBLE: SET_STACK_DOUBLE(value.d, 1); break;2083case T_LONG: SET_STACK_LONG(value.j, 1); break;2084default: ShouldNotReachHere();2085}20862087break;2088}20892090default: ShouldNotReachHere();2091}2092UPDATE_PC_AND_TOS_AND_CONTINUE(3, 2);2093}20942095CASE(_fast_aldc_w):2096CASE(_fast_aldc): {2097u2 index;2098int incr;2099if (opcode == Bytecodes::_fast_aldc) {2100index = pc[1];2101incr = 2;2102} else {2103index = Bytes::get_native_u2(pc+1);2104incr = 3;2105}21062107// We are resolved if the resolved_references array contains a non-null object (CallSite, etc.)2108// This kind of CP cache entry does not need to match the flags byte, because2109// there is a 1-1 relation between bytecode type and CP entry type.2110ConstantPool* constants = METHOD->constants();2111oop result = constants->resolved_references()->obj_at(index);2112if (result == NULL) {2113CALL_VM(InterpreterRuntime::resolve_ldc(THREAD, (Bytecodes::Code) opcode),2114handle_exception);2115result = THREAD->vm_result();2116}2117if (result == Universe::the_null_sentinel())2118result = NULL;21192120VERIFY_OOP(result);2121SET_STACK_OBJECT(result, 0);2122UPDATE_PC_AND_TOS_AND_CONTINUE(incr, 1);2123}21242125CASE(_invokedynamic): {21262127u4 index = Bytes::get_native_u4(pc+1);2128ConstantPoolCacheEntry* cache = cp->constant_pool()->invokedynamic_cp_cache_entry_at(index);21292130// We are resolved if the resolved_references array contains a non-null object (CallSite, etc.)2131// This kind of CP cache entry does not need to match the flags byte, because2132// there is a 1-1 relation between bytecode type and CP entry type.2133if (! cache->is_resolved((Bytecodes::Code) opcode)) {2134CALL_VM(InterpreterRuntime::resolve_from_cache(THREAD, (Bytecodes::Code)opcode),2135handle_exception);2136cache = cp->constant_pool()->invokedynamic_cp_cache_entry_at(index);2137}21382139Method* method = cache->f1_as_method();2140if (VerifyOops) method->verify();21412142if (cache->has_appendix()) {2143constantPoolHandle cp(THREAD, METHOD->constants());2144SET_STACK_OBJECT(cache->appendix_if_resolved(cp), 0);2145MORE_STACK(1);2146}21472148istate->set_msg(call_method);2149istate->set_callee(method);2150istate->set_callee_entry_point(method->from_interpreted_entry());2151istate->set_bcp_advance(5);21522153UPDATE_PC_AND_RETURN(0); // I'll be back...2154}21552156CASE(_invokehandle): {21572158u2 index = Bytes::get_native_u2(pc+1);2159ConstantPoolCacheEntry* cache = cp->entry_at(index);21602161if (! cache->is_resolved((Bytecodes::Code) opcode)) {2162CALL_VM(InterpreterRuntime::resolve_from_cache(THREAD, (Bytecodes::Code)opcode),2163handle_exception);2164cache = cp->entry_at(index);2165}21662167Method* method = cache->f1_as_method();2168if (VerifyOops) method->verify();21692170if (cache->has_appendix()) {2171constantPoolHandle cp(THREAD, METHOD->constants());2172SET_STACK_OBJECT(cache->appendix_if_resolved(cp), 0);2173MORE_STACK(1);2174}21752176istate->set_msg(call_method);2177istate->set_callee(method);2178istate->set_callee_entry_point(method->from_interpreted_entry());2179istate->set_bcp_advance(3);21802181UPDATE_PC_AND_RETURN(0); // I'll be back...2182}21832184CASE(_invokeinterface): {2185u2 index = Bytes::get_native_u2(pc+1);21862187// QQQ Need to make this as inlined as possible. Probably need to split all the bytecode cases2188// out so c++ compiler has a chance for constant prop to fold everything possible away.21892190ConstantPoolCacheEntry* cache = cp->entry_at(index);2191if (!cache->is_resolved((Bytecodes::Code)opcode)) {2192CALL_VM(InterpreterRuntime::resolve_from_cache(THREAD, (Bytecodes::Code)opcode),2193handle_exception);2194cache = cp->entry_at(index);2195}21962197istate->set_msg(call_method);21982199// Special case of invokeinterface called for virtual method of2200// java.lang.Object. See cpCache.cpp for details.2201Method* callee = NULL;2202if (cache->is_forced_virtual()) {2203CHECK_NULL(STACK_OBJECT(-(cache->parameter_size())));2204if (cache->is_vfinal()) {2205callee = cache->f2_as_vfinal_method();2206} else {2207// Get receiver.2208int parms = cache->parameter_size();2209// Same comments as invokevirtual apply here.2210oop rcvr = STACK_OBJECT(-parms);2211VERIFY_OOP(rcvr);2212Klass* rcvrKlass = rcvr->klass();2213callee = (Method*) rcvrKlass->method_at_vtable(cache->f2_as_index());2214}2215} else if (cache->is_vfinal()) {2216// private interface method invocations2217//2218// Ensure receiver class actually implements2219// the resolved interface class. The link resolver2220// does this, but only for the first time this2221// interface is being called.2222int parms = cache->parameter_size();2223oop rcvr = STACK_OBJECT(-parms);2224CHECK_NULL(rcvr);2225Klass* recv_klass = rcvr->klass();2226Klass* resolved_klass = cache->f1_as_klass();2227if (!recv_klass->is_subtype_of(resolved_klass)) {2228ResourceMark rm(THREAD);2229char buf[200];2230jio_snprintf(buf, sizeof(buf), "Class %s does not implement the requested interface %s",2231recv_klass->external_name(),2232resolved_klass->external_name());2233VM_JAVA_ERROR(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);2234}2235callee = cache->f2_as_vfinal_method();2236}2237if (callee != NULL) {2238istate->set_callee(callee);2239istate->set_callee_entry_point(callee->from_interpreted_entry());2240if (JVMTI_ENABLED && THREAD->is_interp_only_mode()) {2241istate->set_callee_entry_point(callee->interpreter_entry());2242}2243istate->set_bcp_advance(5);2244UPDATE_PC_AND_RETURN(0); // I'll be back...2245}22462247// this could definitely be cleaned up QQQ2248Method *interface_method = cache->f2_as_interface_method();2249InstanceKlass* iclass = interface_method->method_holder();22502251// get receiver2252int parms = cache->parameter_size();2253oop rcvr = STACK_OBJECT(-parms);2254CHECK_NULL(rcvr);2255InstanceKlass* int2 = (InstanceKlass*) rcvr->klass();22562257// Receiver subtype check against resolved interface klass (REFC).2258{2259Klass* refc = cache->f1_as_klass();2260itableOffsetEntry* scan;2261for (scan = (itableOffsetEntry*) int2->start_of_itable();2262scan->interface_klass() != NULL;2263scan++) {2264if (scan->interface_klass() == refc) {2265break;2266}2267}2268// Check that the entry is non-null. A null entry means2269// that the receiver class doesn't implement the2270// interface, and wasn't the same as when the caller was2271// compiled.2272if (scan->interface_klass() == NULL) {2273VM_JAVA_ERROR(vmSymbols::java_lang_IncompatibleClassChangeError(), "");2274}2275}22762277itableOffsetEntry* ki = (itableOffsetEntry*) int2->start_of_itable();2278int i;2279for ( i = 0 ; i < int2->itable_length() ; i++, ki++ ) {2280if (ki->interface_klass() == iclass) break;2281}2282// If the interface isn't found, this class doesn't implement this2283// interface. The link resolver checks this but only for the first2284// time this interface is called.2285if (i == int2->itable_length()) {2286CALL_VM(InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose(THREAD, rcvr->klass(), iclass),2287handle_exception);2288}2289int mindex = interface_method->itable_index();22902291itableMethodEntry* im = ki->first_method_entry(rcvr->klass());2292callee = im[mindex].method();2293if (callee == NULL) {2294CALL_VM(InterpreterRuntime::throw_AbstractMethodErrorVerbose(THREAD, rcvr->klass(), interface_method),2295handle_exception);2296}22972298istate->set_callee(callee);2299istate->set_callee_entry_point(callee->from_interpreted_entry());2300if (JVMTI_ENABLED && THREAD->is_interp_only_mode()) {2301istate->set_callee_entry_point(callee->interpreter_entry());2302}2303istate->set_bcp_advance(5);2304UPDATE_PC_AND_RETURN(0); // I'll be back...2305}23062307CASE(_invokevirtual):2308CASE(_invokespecial):2309CASE(_invokestatic): {2310u2 index = Bytes::get_native_u2(pc+1);23112312ConstantPoolCacheEntry* cache = cp->entry_at(index);2313// QQQ Need to make this as inlined as possible. Probably need to split all the bytecode cases2314// out so c++ compiler has a chance for constant prop to fold everything possible away.23152316if (!cache->is_resolved((Bytecodes::Code)opcode)) {2317CALL_VM(InterpreterRuntime::resolve_from_cache(THREAD, (Bytecodes::Code)opcode),2318handle_exception);2319cache = cp->entry_at(index);2320}23212322istate->set_msg(call_method);2323{2324Method* callee;2325if ((Bytecodes::Code)opcode == Bytecodes::_invokevirtual) {2326CHECK_NULL(STACK_OBJECT(-(cache->parameter_size())));2327if (cache->is_vfinal()) {2328callee = cache->f2_as_vfinal_method();2329} else {2330// get receiver2331int parms = cache->parameter_size();2332// this works but needs a resourcemark and seems to create a vtable on every call:2333// Method* callee = rcvr->klass()->vtable()->method_at(cache->f2_as_index());2334//2335// this fails with an assert2336// InstanceKlass* rcvrKlass = InstanceKlass::cast(STACK_OBJECT(-parms)->klass());2337// but this works2338oop rcvr = STACK_OBJECT(-parms);2339VERIFY_OOP(rcvr);2340Klass* rcvrKlass = rcvr->klass();2341/*2342Executing this code in java.lang.String:2343public String(char value[]) {2344this.count = value.length;2345this.value = (char[])value.clone();2346}23472348a find on rcvr->klass() reports:2349{type array char}{type array class}2350- klass: {other class}23512352but using InstanceKlass::cast(STACK_OBJECT(-parms)->klass()) causes in assertion failure2353because rcvr->klass()->is_instance_klass() == 02354However it seems to have a vtable in the right location. Huh?2355Because vtables have the same offset for ArrayKlass and InstanceKlass.2356*/2357callee = (Method*) rcvrKlass->method_at_vtable(cache->f2_as_index());2358}2359} else {2360if ((Bytecodes::Code)opcode == Bytecodes::_invokespecial) {2361CHECK_NULL(STACK_OBJECT(-(cache->parameter_size())));2362}2363callee = cache->f1_as_method();2364}23652366istate->set_callee(callee);2367istate->set_callee_entry_point(callee->from_interpreted_entry());2368if (JVMTI_ENABLED && THREAD->is_interp_only_mode()) {2369istate->set_callee_entry_point(callee->interpreter_entry());2370}2371istate->set_bcp_advance(3);2372UPDATE_PC_AND_RETURN(0); // I'll be back...2373}2374}23752376/* Allocate memory for a new java object. */23772378CASE(_newarray): {2379BasicType atype = (BasicType) *(pc+1);2380jint size = STACK_INT(-1);2381CALL_VM(InterpreterRuntime::newarray(THREAD, atype, size),2382handle_exception);2383// Must prevent reordering of stores for object initialization2384// with stores that publish the new object.2385OrderAccess::storestore();2386SET_STACK_OBJECT(THREAD->vm_result(), -1);2387THREAD->set_vm_result(NULL);23882389UPDATE_PC_AND_CONTINUE(2);2390}23912392/* Throw an exception. */23932394CASE(_athrow): {2395oop except_oop = STACK_OBJECT(-1);2396CHECK_NULL(except_oop);2397// set pending_exception so we use common code2398THREAD->set_pending_exception(except_oop, NULL, 0);2399goto handle_exception;2400}24012402/* goto and jsr. They are exactly the same except jsr pushes2403* the address of the next instruction first.2404*/24052406CASE(_jsr): {2407/* push bytecode index on stack */2408SET_STACK_ADDR(((address)pc - (intptr_t)(istate->method()->code_base()) + 3), 0);2409MORE_STACK(1);2410/* FALL THROUGH */2411}24122413CASE(_goto):2414{2415int16_t offset = (int16_t)Bytes::get_Java_u2(pc + 1);2416address branch_pc = pc;2417UPDATE_PC(offset);2418DO_BACKEDGE_CHECKS(offset, branch_pc);2419CONTINUE;2420}24212422CASE(_jsr_w): {2423/* push return address on the stack */2424SET_STACK_ADDR(((address)pc - (intptr_t)(istate->method()->code_base()) + 5), 0);2425MORE_STACK(1);2426/* FALL THROUGH */2427}24282429CASE(_goto_w):2430{2431int32_t offset = Bytes::get_Java_u4(pc + 1);2432address branch_pc = pc;2433UPDATE_PC(offset);2434DO_BACKEDGE_CHECKS(offset, branch_pc);2435CONTINUE;2436}24372438/* return from a jsr or jsr_w */24392440CASE(_ret): {2441pc = istate->method()->code_base() + (intptr_t)(LOCALS_ADDR(pc[1]));2442UPDATE_PC_AND_CONTINUE(0);2443}24442445/* debugger breakpoint */24462447CASE(_breakpoint): {2448Bytecodes::Code original_bytecode;2449DECACHE_STATE();2450SET_LAST_JAVA_FRAME();2451original_bytecode = InterpreterRuntime::get_original_bytecode_at(THREAD,2452METHOD, pc);2453RESET_LAST_JAVA_FRAME();2454CACHE_STATE();2455if (THREAD->has_pending_exception()) goto handle_exception;2456CALL_VM(InterpreterRuntime::_breakpoint(THREAD, METHOD, pc),2457handle_exception);24582459opcode = (jubyte)original_bytecode;2460goto opcode_switch;2461}24622463DEFAULT:2464fatal("Unimplemented opcode %d = %s", opcode,2465Bytecodes::name((Bytecodes::Code)opcode));2466goto finish;24672468} /* switch(opc) */246924702471#ifdef USELABELS2472check_for_exception:2473#endif2474{2475if (!THREAD->has_pending_exception()) {2476CONTINUE;2477}2478/* We will be gcsafe soon, so flush our state. */2479DECACHE_PC();2480goto handle_exception;2481}2482do_continue: ;24832484} /* while (1) interpreter loop */248524862487// An exception exists in the thread state see whether this activation can handle it2488handle_exception: {24892490HandleMarkCleaner __hmc(THREAD);2491Handle except_oop(THREAD, THREAD->pending_exception());2492// Prevent any subsequent HandleMarkCleaner in the VM2493// from freeing the except_oop handle.2494HandleMark __hm(THREAD);24952496THREAD->clear_pending_exception();2497assert(except_oop() != NULL, "No exception to process");2498intptr_t continuation_bci;2499// expression stack is emptied2500topOfStack = istate->stack_base() - Interpreter::stackElementWords;2501CALL_VM(continuation_bci = (intptr_t)InterpreterRuntime::exception_handler_for_exception(THREAD, except_oop()),2502handle_exception);25032504except_oop = Handle(THREAD, THREAD->vm_result());2505THREAD->set_vm_result(NULL);2506if (continuation_bci >= 0) {2507// Place exception on top of stack2508SET_STACK_OBJECT(except_oop(), 0);2509MORE_STACK(1);2510pc = METHOD->code_base() + continuation_bci;2511if (log_is_enabled(Info, exceptions)) {2512ResourceMark rm(THREAD);2513stringStream tempst;2514tempst.print("interpreter method <%s>\n"2515" at bci %d, continuing at %d for thread " INTPTR_FORMAT,2516METHOD->print_value_string(),2517(int)(istate->bcp() - METHOD->code_base()),2518(int)continuation_bci, p2i(THREAD));2519Exceptions::log_exception(except_oop, tempst.as_string());2520}2521// for AbortVMOnException flag2522Exceptions::debug_check_abort(except_oop);2523goto run;2524}2525if (log_is_enabled(Info, exceptions)) {2526ResourceMark rm;2527stringStream tempst;2528tempst.print("interpreter method <%s>\n"2529" at bci %d, unwinding for thread " INTPTR_FORMAT,2530METHOD->print_value_string(),2531(int)(istate->bcp() - METHOD->code_base()),2532p2i(THREAD));2533Exceptions::log_exception(except_oop, tempst.as_string());2534}2535// for AbortVMOnException flag2536Exceptions::debug_check_abort(except_oop);25372538// No handler in this activation, unwind and try again2539THREAD->set_pending_exception(except_oop(), NULL, 0);2540goto handle_return;2541} // handle_exception:25422543// Return from an interpreter invocation with the result of the interpretation2544// on the top of the Java Stack (or a pending exception)25452546handle_Pop_Frame: {25472548// We don't really do anything special here except we must be aware2549// that we can get here without ever locking the method (if sync).2550// Also we skip the notification of the exit.25512552istate->set_msg(popping_frame);2553// Clear pending so while the pop is in process2554// we don't start another one if a call_vm is done.2555THREAD->clear_popframe_condition();2556// Let interpreter (only) see the we're in the process of popping a frame2557THREAD->set_pop_frame_in_process();25582559goto handle_return;25602561} // handle_Pop_Frame25622563// ForceEarlyReturn ends a method, and returns to the caller with a return value2564// given by the invoker of the early return.2565handle_Early_Return: {25662567istate->set_msg(early_return);25682569// Clear expression stack.2570topOfStack = istate->stack_base() - Interpreter::stackElementWords;25712572JvmtiThreadState *ts = THREAD->jvmti_thread_state();25732574// Push the value to be returned.2575switch (istate->method()->result_type()) {2576case T_BOOLEAN:2577case T_SHORT:2578case T_BYTE:2579case T_CHAR:2580case T_INT:2581SET_STACK_INT(ts->earlyret_value().i, 0);2582MORE_STACK(1);2583break;2584case T_LONG:2585SET_STACK_LONG(ts->earlyret_value().j, 1);2586MORE_STACK(2);2587break;2588case T_FLOAT:2589SET_STACK_FLOAT(ts->earlyret_value().f, 0);2590MORE_STACK(1);2591break;2592case T_DOUBLE:2593SET_STACK_DOUBLE(ts->earlyret_value().d, 1);2594MORE_STACK(2);2595break;2596case T_ARRAY:2597case T_OBJECT:2598SET_STACK_OBJECT(ts->earlyret_oop(), 0);2599MORE_STACK(1);2600break;2601}26022603ts->clr_earlyret_value();2604ts->set_earlyret_oop(NULL);2605ts->clr_earlyret_pending();26062607// Fall through to handle_return.26082609} // handle_Early_Return26102611handle_return: {2612// A storestore barrier is required to order initialization of2613// final fields with publishing the reference to the object that2614// holds the field. Without the barrier the value of final fields2615// can be observed to change.2616OrderAccess::storestore();26172618DECACHE_STATE();26192620bool suppress_error = istate->msg() == popping_frame || istate->msg() == early_return;2621bool suppress_exit_event = THREAD->has_pending_exception() || istate->msg() == popping_frame;2622Handle original_exception(THREAD, THREAD->pending_exception());2623Handle illegal_state_oop(THREAD, NULL);26242625// We'd like a HandleMark here to prevent any subsequent HandleMarkCleaner2626// in any following VM entries from freeing our live handles, but illegal_state_oop2627// isn't really allocated yet and so doesn't become live until later and2628// in unpredicatable places. Instead we must protect the places where we enter the2629// VM. It would be much simpler (and safer) if we could allocate a real handle with2630// a NULL oop in it and then overwrite the oop later as needed. This isn't2631// unfortunately isn't possible.26322633if (THREAD->has_pending_exception()) {2634THREAD->clear_pending_exception();2635}26362637//2638// As far as we are concerned we have returned. If we have a pending exception2639// that will be returned as this invocation's result. However if we get any2640// exception(s) while checking monitor state one of those IllegalMonitorStateExceptions2641// will be our final result (i.e. monitor exception trumps a pending exception).2642//26432644// If we never locked the method (or really passed the point where we would have),2645// there is no need to unlock it (or look for other monitors), since that2646// could not have happened.26472648if (THREAD->do_not_unlock()) {26492650// Never locked, reset the flag now because obviously any caller must2651// have passed their point of locking for us to have gotten here.26522653THREAD->clr_do_not_unlock();2654} else {2655// At this point we consider that we have returned. We now check that the2656// locks were properly block structured. If we find that they were not2657// used properly we will return with an illegal monitor exception.2658// The exception is checked by the caller not the callee since this2659// checking is considered to be part of the invocation and therefore2660// in the callers scope (JVM spec 8.13).2661//2662// Another weird thing to watch for is if the method was locked2663// recursively and then not exited properly. This means we must2664// examine all the entries in reverse time(and stack) order and2665// unlock as we find them. If we find the method monitor before2666// we are at the initial entry then we should throw an exception.2667// It is not clear the template based interpreter does this2668// correctly26692670BasicObjectLock* base = istate->monitor_base();2671BasicObjectLock* end = (BasicObjectLock*) istate->stack_base();2672bool method_unlock_needed = METHOD->is_synchronized();2673// We know the initial monitor was used for the method don't check that2674// slot in the loop2675if (method_unlock_needed) base--;26762677// Check all the monitors to see they are unlocked. Install exception if found to be locked.2678while (end < base) {2679oop lockee = end->obj();2680if (lockee != NULL) {2681BasicLock* lock = end->lock();2682markWord header = lock->displaced_header();2683end->set_obj(NULL);26842685assert(!UseBiasedLocking, "Not implemented");26862687// If it isn't recursive we either must swap old header or call the runtime2688if (header.to_pointer() != NULL) {2689markWord old_header = markWord::encode(lock);2690if (lockee->cas_set_mark(header, old_header) != old_header) {2691// restore object for the slow case2692end->set_obj(lockee);2693InterpreterRuntime::monitorexit(end);2694}2695}26962697// One error is plenty2698if (illegal_state_oop() == NULL && !suppress_error) {2699{2700// Prevent any HandleMarkCleaner from freeing our live handles2701HandleMark __hm(THREAD);2702CALL_VM_NOCHECK(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD));2703}2704assert(THREAD->has_pending_exception(), "Lost our exception!");2705illegal_state_oop = Handle(THREAD, THREAD->pending_exception());2706THREAD->clear_pending_exception();2707}2708}2709end++;2710}2711// Unlock the method if needed2712if (method_unlock_needed) {2713if (base->obj() == NULL) {2714// The method is already unlocked this is not good.2715if (illegal_state_oop() == NULL && !suppress_error) {2716{2717// Prevent any HandleMarkCleaner from freeing our live handles2718HandleMark __hm(THREAD);2719CALL_VM_NOCHECK(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD));2720}2721assert(THREAD->has_pending_exception(), "Lost our exception!");2722illegal_state_oop = Handle(THREAD, THREAD->pending_exception());2723THREAD->clear_pending_exception();2724}2725} else {2726//2727// The initial monitor is always used for the method2728// However if that slot is no longer the oop for the method it was unlocked2729// and reused by something that wasn't unlocked!2730//2731// deopt can come in with rcvr dead because c2 knows2732// its value is preserved in the monitor. So we can't use locals[0] at all2733// and must use first monitor slot.2734//2735oop rcvr = base->obj();2736if (rcvr == NULL) {2737if (!suppress_error) {2738VM_JAVA_ERROR_NO_JUMP(vmSymbols::java_lang_NullPointerException(), "");2739illegal_state_oop = Handle(THREAD, THREAD->pending_exception());2740THREAD->clear_pending_exception();2741}2742} else if (UseHeavyMonitors) {2743InterpreterRuntime::monitorexit(base);2744if (THREAD->has_pending_exception()) {2745if (!suppress_error) illegal_state_oop = Handle(THREAD, THREAD->pending_exception());2746THREAD->clear_pending_exception();2747}2748} else {2749BasicLock* lock = base->lock();2750markWord header = lock->displaced_header();2751base->set_obj(NULL);27522753assert(!UseBiasedLocking, "Not implemented");27542755// If it isn't recursive we either must swap old header or call the runtime2756if (header.to_pointer() != NULL) {2757markWord old_header = markWord::encode(lock);2758if (rcvr->cas_set_mark(header, old_header) != old_header) {2759// restore object for the slow case2760base->set_obj(rcvr);2761InterpreterRuntime::monitorexit(base);2762if (THREAD->has_pending_exception()) {2763if (!suppress_error) illegal_state_oop = Handle(THREAD, THREAD->pending_exception());2764THREAD->clear_pending_exception();2765}2766}2767}2768}2769}2770}2771}2772// Clear the do_not_unlock flag now.2773THREAD->clr_do_not_unlock();27742775//2776// Notify jvmti/jvmdi2777//2778// NOTE: we do not notify a method_exit if we have a pending exception,2779// including an exception we generate for unlocking checks. In the former2780// case, JVMDI has already been notified by our call for the exception handler2781// and in both cases as far as JVMDI is concerned we have already returned.2782// If we notify it again JVMDI will be all confused about how many frames2783// are still on the stack (4340444).2784//2785// NOTE Further! It turns out the the JVMTI spec in fact expects to see2786// method_exit events whenever we leave an activation unless it was done2787// for popframe. This is nothing like jvmdi. However we are passing the2788// tests at the moment (apparently because they are jvmdi based) so rather2789// than change this code and possibly fail tests we will leave it alone2790// (with this note) in anticipation of changing the vm and the tests2791// simultaneously.27922793suppress_exit_event = suppress_exit_event || illegal_state_oop() != NULL;27942795// Whenever JVMTI puts a thread in interp_only_mode, method2796// entry/exit events are sent for that thread to track stack depth.27972798if (JVMTI_ENABLED && !suppress_exit_event && THREAD->is_interp_only_mode()) {2799// Prevent any HandleMarkCleaner from freeing our live handles2800HandleMark __hm(THREAD);2801CALL_VM_NOCHECK(InterpreterRuntime::post_method_exit(THREAD));2802}28032804//2805// See if we are returning any exception2806// A pending exception that was pending prior to a possible popping frame2807// overrides the popping frame.2808//2809assert(!suppress_error || (suppress_error && illegal_state_oop() == NULL), "Error was not suppressed");2810if (illegal_state_oop() != NULL || original_exception() != NULL) {2811// Inform the frame manager we have no result.2812istate->set_msg(throwing_exception);2813if (illegal_state_oop() != NULL)2814THREAD->set_pending_exception(illegal_state_oop(), NULL, 0);2815else2816THREAD->set_pending_exception(original_exception(), NULL, 0);2817UPDATE_PC_AND_RETURN(0);2818}28192820if (istate->msg() == popping_frame) {2821// Make it simpler on the assembly code and set the message for the frame pop.2822// returns2823if (istate->prev() == NULL) {2824// We must be returning to a deoptimized frame (because popframe only happens between2825// two interpreted frames). We need to save the current arguments in C heap so that2826// the deoptimized frame when it restarts can copy the arguments to its expression2827// stack and re-execute the call. We also have to notify deoptimization that this2828// has occurred and to pick the preserved args copy them to the deoptimized frame's2829// java expression stack. Yuck.2830//2831THREAD->popframe_preserve_args(in_ByteSize(METHOD->size_of_parameters() * wordSize),2832LOCALS_SLOT(METHOD->size_of_parameters() - 1));2833THREAD->set_popframe_condition_bit(JavaThread::popframe_force_deopt_reexecution_bit);2834}2835} else {2836istate->set_msg(return_from_method);2837}28382839// Normal return2840// Advance the pc and return to frame manager2841UPDATE_PC_AND_RETURN(1);2842} /* handle_return: */28432844// This is really a fatal error return28452846finish:2847DECACHE_TOS();2848DECACHE_PC();28492850return;2851}28522853// This constructor should only be used to contruct the object to signal2854// interpreter initialization. All other instances should be created by2855// the frame manager.2856BytecodeInterpreter::BytecodeInterpreter(messages msg) {2857if (msg != initialize) ShouldNotReachHere();2858_msg = msg;2859_self_link = this;2860_prev_link = NULL;2861}28622863void BytecodeInterpreter::astore(intptr_t* tos, int stack_offset,2864intptr_t* locals, int locals_offset) {2865intptr_t value = tos[Interpreter::expr_index_at(-stack_offset)];2866locals[Interpreter::local_index_at(-locals_offset)] = value;2867}28682869void BytecodeInterpreter::copy_stack_slot(intptr_t *tos, int from_offset,2870int to_offset) {2871tos[Interpreter::expr_index_at(-to_offset)] =2872(intptr_t)tos[Interpreter::expr_index_at(-from_offset)];2873}28742875void BytecodeInterpreter::dup(intptr_t *tos) {2876copy_stack_slot(tos, -1, 0);2877}28782879void BytecodeInterpreter::dup2(intptr_t *tos) {2880copy_stack_slot(tos, -2, 0);2881copy_stack_slot(tos, -1, 1);2882}28832884void BytecodeInterpreter::dup_x1(intptr_t *tos) {2885/* insert top word two down */2886copy_stack_slot(tos, -1, 0);2887copy_stack_slot(tos, -2, -1);2888copy_stack_slot(tos, 0, -2);2889}28902891void BytecodeInterpreter::dup_x2(intptr_t *tos) {2892/* insert top word three down */2893copy_stack_slot(tos, -1, 0);2894copy_stack_slot(tos, -2, -1);2895copy_stack_slot(tos, -3, -2);2896copy_stack_slot(tos, 0, -3);2897}2898void BytecodeInterpreter::dup2_x1(intptr_t *tos) {2899/* insert top 2 slots three down */2900copy_stack_slot(tos, -1, 1);2901copy_stack_slot(tos, -2, 0);2902copy_stack_slot(tos, -3, -1);2903copy_stack_slot(tos, 1, -2);2904copy_stack_slot(tos, 0, -3);2905}2906void BytecodeInterpreter::dup2_x2(intptr_t *tos) {2907/* insert top 2 slots four down */2908copy_stack_slot(tos, -1, 1);2909copy_stack_slot(tos, -2, 0);2910copy_stack_slot(tos, -3, -1);2911copy_stack_slot(tos, -4, -2);2912copy_stack_slot(tos, 1, -3);2913copy_stack_slot(tos, 0, -4);2914}291529162917void BytecodeInterpreter::swap(intptr_t *tos) {2918// swap top two elements2919intptr_t val = tos[Interpreter::expr_index_at(1)];2920// Copy -2 entry to -12921copy_stack_slot(tos, -2, -1);2922// Store saved -1 entry into -22923tos[Interpreter::expr_index_at(2)] = val;2924}2925// --------------------------------------------------------------------------------2926// Non-product code2927#ifndef PRODUCT29282929const char* BytecodeInterpreter::C_msg(BytecodeInterpreter::messages msg) {2930switch (msg) {2931case BytecodeInterpreter::no_request: return("no_request");2932case BytecodeInterpreter::initialize: return("initialize");2933// status message to C++ interpreter2934case BytecodeInterpreter::method_entry: return("method_entry");2935case BytecodeInterpreter::method_resume: return("method_resume");2936case BytecodeInterpreter::got_monitors: return("got_monitors");2937case BytecodeInterpreter::rethrow_exception: return("rethrow_exception");2938// requests to frame manager from C++ interpreter2939case BytecodeInterpreter::call_method: return("call_method");2940case BytecodeInterpreter::return_from_method: return("return_from_method");2941case BytecodeInterpreter::more_monitors: return("more_monitors");2942case BytecodeInterpreter::throwing_exception: return("throwing_exception");2943case BytecodeInterpreter::popping_frame: return("popping_frame");2944case BytecodeInterpreter::do_osr: return("do_osr");2945// deopt2946case BytecodeInterpreter::deopt_resume: return("deopt_resume");2947case BytecodeInterpreter::deopt_resume2: return("deopt_resume2");2948default: return("BAD MSG");2949}2950}2951void2952BytecodeInterpreter::print() {2953tty->print_cr("thread: " INTPTR_FORMAT, (uintptr_t) this->_thread);2954tty->print_cr("bcp: " INTPTR_FORMAT, (uintptr_t) this->_bcp);2955tty->print_cr("locals: " INTPTR_FORMAT, (uintptr_t) this->_locals);2956tty->print_cr("constants: " INTPTR_FORMAT, (uintptr_t) this->_constants);2957{2958ResourceMark rm;2959char *method_name = _method->name_and_sig_as_C_string();2960tty->print_cr("method: " INTPTR_FORMAT "[ %s ]", (uintptr_t) this->_method, method_name);2961}2962tty->print_cr("stack: " INTPTR_FORMAT, (uintptr_t) this->_stack);2963tty->print_cr("msg: %s", C_msg(this->_msg));2964tty->print_cr("result_to_call._callee: " INTPTR_FORMAT, (uintptr_t) this->_result._to_call._callee);2965tty->print_cr("result_to_call._callee_entry_point: " INTPTR_FORMAT, (uintptr_t) this->_result._to_call._callee_entry_point);2966tty->print_cr("result_to_call._bcp_advance: %d ", this->_result._to_call._bcp_advance);2967tty->print_cr("osr._osr_buf: " INTPTR_FORMAT, (uintptr_t) this->_result._osr._osr_buf);2968tty->print_cr("osr._osr_entry: " INTPTR_FORMAT, (uintptr_t) this->_result._osr._osr_entry);2969tty->print_cr("prev_link: " INTPTR_FORMAT, (uintptr_t) this->_prev_link);2970tty->print_cr("native_mirror: " INTPTR_FORMAT, (uintptr_t) p2i(this->_oop_temp));2971tty->print_cr("stack_base: " INTPTR_FORMAT, (uintptr_t) this->_stack_base);2972tty->print_cr("stack_limit: " INTPTR_FORMAT, (uintptr_t) this->_stack_limit);2973tty->print_cr("monitor_base: " INTPTR_FORMAT, (uintptr_t) this->_monitor_base);2974tty->print_cr("self_link: " INTPTR_FORMAT, (uintptr_t) this->_self_link);2975}29762977extern "C" {2978void PI(uintptr_t arg) {2979((BytecodeInterpreter*)arg)->print();2980}2981}2982#endif // PRODUCT298329842985