Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/interpreter/bytecodeInterpreter.hpp
32285 views
/*1* Copyright (c) 2002, 2012, 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#ifndef SHARE_VM_INTERPRETER_BYTECODEINTERPRETER_HPP25#define SHARE_VM_INTERPRETER_BYTECODEINTERPRETER_HPP2627#include "memory/allocation.hpp"28#include "oops/methodData.hpp"29#include "oops/method.hpp"30#include "runtime/basicLock.hpp"31#include "runtime/frame.hpp"32#include "runtime/globals.hpp"33#include "utilities/globalDefinitions.hpp"34#ifdef TARGET_ARCH_x8635# include "bytes_x86.hpp"36#endif37#ifdef TARGET_ARCH_aarch3238# include "bytes_aarch32.hpp"39#endif40#ifdef TARGET_ARCH_aarch6441# include "bytes_aarch64.hpp"42#endif43#ifdef TARGET_ARCH_sparc44# include "bytes_sparc.hpp"45#endif46#ifdef TARGET_ARCH_zero47# include "bytes_zero.hpp"48#endif49#ifdef TARGET_ARCH_arm50# include "bytes_arm.hpp"51#endif52#ifdef TARGET_ARCH_ppc53# include "bytes_ppc.hpp"54#endif5556#ifdef CC_INTERP5758// JavaStack Implementation59#define MORE_STACK(count) \60(topOfStack -= ((count) * Interpreter::stackElementWords))6162// CVM definitions find hotspot equivalents...6364union VMJavaVal64 {65jlong l;66jdouble d;67uint32_t v[2];68};697071typedef class BytecodeInterpreter* interpreterState;7273struct call_message {74class Method* _callee; // method to call during call_method request75address _callee_entry_point; // address to jump to for call_method request76int _bcp_advance; // size of the invoke bytecode operation77};7879struct osr_message {80address _osr_buf; // the osr buffer81address _osr_entry; // the entry to the osr method82};8384struct osr_result {85nmethod* nm; // osr nmethod86address return_addr; // osr blob return address87};8889// Result returned to frame manager90union frame_manager_message {91call_message _to_call; // describes callee92osr_message _osr; // describes the osr93osr_result _osr_result; // result of OSR request94};9596class BytecodeInterpreter : StackObj {97friend class SharedRuntime;98friend class AbstractInterpreterGenerator;99friend class CppInterpreterGenerator;100friend class InterpreterGenerator;101friend class InterpreterMacroAssembler;102friend class frame;103friend class VMStructs;104105public:106enum messages {107no_request = 0, // unused108initialize, // Perform one time interpreter initializations (assumes all switches set)109// status message to C++ interpreter110method_entry, // initial method entry to interpreter111method_resume, // frame manager response to return_from_method request (assuming a frame to resume)112deopt_resume, // returning from a native call into a deopted frame113deopt_resume2, // deopt resume as a result of a PopFrame114got_monitors, // frame manager response to more_monitors request115rethrow_exception, // unwinding and throwing exception116// requests to frame manager from C++ interpreter117call_method, // request for new frame from interpreter, manager responds with method_entry118return_from_method, // request from interpreter to unwind, manager responds with method_continue119more_monitors, // need a new monitor120throwing_exception, // unwind stack and rethrow121popping_frame, // unwind call and retry call122do_osr, // request this invocation be OSR's123early_return // early return as commanded by jvmti124};125126private:127JavaThread* _thread; // the vm's java thread pointer128address _bcp; // instruction pointer129intptr_t* _locals; // local variable pointer130ConstantPoolCache* _constants; // constant pool cache131Method* _method; // method being executed132DataLayout* _mdx; // compiler profiling data for current bytecode133intptr_t* _stack; // expression stack134messages _msg; // frame manager <-> interpreter message135frame_manager_message _result; // result to frame manager136interpreterState _prev_link; // previous interpreter state137oop _oop_temp; // mirror for interpreted native, null otherwise138intptr_t* _stack_base; // base of expression stack139intptr_t* _stack_limit; // limit of expression stack140BasicObjectLock* _monitor_base; // base of monitors on the native stack141142143public:144// Constructor is only used by the initialization step. All other instances are created145// by the frame manager.146BytecodeInterpreter(messages msg);147148//149// Deoptimization support150//151static void layout_interpreterState(interpreterState to_fill,152frame* caller,153frame* interpreter_frame,154Method* method,155intptr_t* locals,156intptr_t* stack,157intptr_t* stack_base,158intptr_t* monitor_base,159intptr_t* frame_bottom,160bool top_frame);161162/*163* Generic 32-bit wide "Java slot" definition. This type occurs164* in operand stacks, Java locals, object fields, constant pools.165*/166union VMJavaVal32 {167jint i;168jfloat f;169class oopDesc* r;170uint32_t raw;171};172173/*174* Generic 64-bit Java value definition175*/176union VMJavaVal64 {177jlong l;178jdouble d;179uint32_t v[2];180};181182/*183* Generic 32-bit wide "Java slot" definition. This type occurs184* in Java locals, object fields, constant pools, and185* operand stacks (as a CVMStackVal32).186*/187typedef union VMSlotVal32 {188VMJavaVal32 j; /* For "Java" values */189address a; /* a return created by jsr or jsr_w */190} VMSlotVal32;191192193/*194* Generic 32-bit wide stack slot definition.195*/196union VMStackVal32 {197VMJavaVal32 j; /* For "Java" values */198VMSlotVal32 s; /* any value from a "slot" or locals[] */199};200201inline JavaThread* thread() { return _thread; }202203inline address bcp() { return _bcp; }204inline void set_bcp(address new_bcp) { _bcp = new_bcp; }205206inline intptr_t* locals() { return _locals; }207208inline ConstantPoolCache* constants() { return _constants; }209inline Method* method() { return _method; }210inline DataLayout* mdx() { return _mdx; }211inline void set_mdx(DataLayout *new_mdx) { _mdx = new_mdx; }212213inline messages msg() { return _msg; }214inline void set_msg(messages new_msg) { _msg = new_msg; }215216inline Method* callee() { return _result._to_call._callee; }217inline void set_callee(Method* new_callee) { _result._to_call._callee = new_callee; }218inline void set_callee_entry_point(address entry) { _result._to_call._callee_entry_point = entry; }219inline void set_osr_buf(address buf) { _result._osr._osr_buf = buf; }220inline void set_osr_entry(address entry) { _result._osr._osr_entry = entry; }221inline int bcp_advance() { return _result._to_call._bcp_advance; }222inline void set_bcp_advance(int count) { _result._to_call._bcp_advance = count; }223224inline interpreterState prev() { return _prev_link; }225226inline intptr_t* stack() { return _stack; }227inline void set_stack(intptr_t* new_stack) { _stack = new_stack; }228229230inline intptr_t* stack_base() { return _stack_base; }231inline intptr_t* stack_limit() { return _stack_limit; }232233inline BasicObjectLock* monitor_base() { return _monitor_base; }234235/*236* 64-bit Arithmetic:237*238* The functions below follow the semantics of the239* ladd, land, ldiv, lmul, lor, lxor, and lrem bytecodes,240* respectively.241*/242243static jlong VMlongAdd(jlong op1, jlong op2);244static jlong VMlongAnd(jlong op1, jlong op2);245static jlong VMlongDiv(jlong op1, jlong op2);246static jlong VMlongMul(jlong op1, jlong op2);247static jlong VMlongOr (jlong op1, jlong op2);248static jlong VMlongSub(jlong op1, jlong op2);249static jlong VMlongXor(jlong op1, jlong op2);250static jlong VMlongRem(jlong op1, jlong op2);251252/*253* Shift:254*255* The functions below follow the semantics of the256* lushr, lshl, and lshr bytecodes, respectively.257*/258259static jlong VMlongUshr(jlong op1, jint op2);260static jlong VMlongShl (jlong op1, jint op2);261static jlong VMlongShr (jlong op1, jint op2);262263/*264* Unary:265*266* Return the negation of "op" (-op), according to267* the semantics of the lneg bytecode.268*/269270static jlong VMlongNeg(jlong op);271272/*273* Return the complement of "op" (~op)274*/275276static jlong VMlongNot(jlong op);277278279/*280* Comparisons to 0:281*/282283static int32_t VMlongLtz(jlong op); /* op <= 0 */284static int32_t VMlongGez(jlong op); /* op >= 0 */285static int32_t VMlongEqz(jlong op); /* op == 0 */286287/*288* Between operands:289*/290291static int32_t VMlongEq(jlong op1, jlong op2); /* op1 == op2 */292static int32_t VMlongNe(jlong op1, jlong op2); /* op1 != op2 */293static int32_t VMlongGe(jlong op1, jlong op2); /* op1 >= op2 */294static int32_t VMlongLe(jlong op1, jlong op2); /* op1 <= op2 */295static int32_t VMlongLt(jlong op1, jlong op2); /* op1 < op2 */296static int32_t VMlongGt(jlong op1, jlong op2); /* op1 > op2 */297298/*299* Comparisons (returning an jint value: 0, 1, or -1)300*301* Between operands:302*303* Compare "op1" and "op2" according to the semantics of the304* "lcmp" bytecode.305*/306307static int32_t VMlongCompare(jlong op1, jlong op2);308309/*310* Convert int to long, according to "i2l" bytecode semantics311*/312static jlong VMint2Long(jint val);313314/*315* Convert long to int, according to "l2i" bytecode semantics316*/317static jint VMlong2Int(jlong val);318319/*320* Convert long to float, according to "l2f" bytecode semantics321*/322static jfloat VMlong2Float(jlong val);323324/*325* Convert long to double, according to "l2d" bytecode semantics326*/327static jdouble VMlong2Double(jlong val);328329/*330* Java floating-point float value manipulation.331*332* The result argument is, once again, an lvalue.333*334* Arithmetic:335*336* The functions below follow the semantics of the337* fadd, fsub, fmul, fdiv, and frem bytecodes,338* respectively.339*/340341static jfloat VMfloatAdd(jfloat op1, jfloat op2);342static jfloat VMfloatSub(jfloat op1, jfloat op2);343static jfloat VMfloatMul(jfloat op1, jfloat op2);344static jfloat VMfloatDiv(jfloat op1, jfloat op2);345static jfloat VMfloatRem(jfloat op1, jfloat op2);346347/*348* Unary:349*350* Return the negation of "op" (-op), according to351* the semantics of the fneg bytecode.352*/353354static jfloat VMfloatNeg(jfloat op);355356/*357* Comparisons (returning an int value: 0, 1, or -1)358*359* Between operands:360*361* Compare "op1" and "op2" according to the semantics of the362* "fcmpl" (direction is -1) or "fcmpg" (direction is 1) bytecodes.363*/364365static int32_t VMfloatCompare(jfloat op1, jfloat op2,366int32_t direction);367/*368* Conversion:369*/370371/*372* Convert float to double, according to "f2d" bytecode semantics373*/374375static jdouble VMfloat2Double(jfloat op);376377/*378******************************************379* Java double floating-point manipulation.380******************************************381*382* The result argument is, once again, an lvalue.383*384* Conversions:385*/386387/*388* Convert double to int, according to "d2i" bytecode semantics389*/390391static jint VMdouble2Int(jdouble val);392393/*394* Convert double to float, according to "d2f" bytecode semantics395*/396397static jfloat VMdouble2Float(jdouble val);398399/*400* Convert int to double, according to "i2d" bytecode semantics401*/402403static jdouble VMint2Double(jint val);404405/*406* Arithmetic:407*408* The functions below follow the semantics of the409* dadd, dsub, ddiv, dmul, and drem bytecodes, respectively.410*/411412static jdouble VMdoubleAdd(jdouble op1, jdouble op2);413static jdouble VMdoubleSub(jdouble op1, jdouble op2);414static jdouble VMdoubleDiv(jdouble op1, jdouble op2);415static jdouble VMdoubleMul(jdouble op1, jdouble op2);416static jdouble VMdoubleRem(jdouble op1, jdouble op2);417418/*419* Unary:420*421* Return the negation of "op" (-op), according to422* the semantics of the dneg bytecode.423*/424425static jdouble VMdoubleNeg(jdouble op);426427/*428* Comparisons (returning an int32_t value: 0, 1, or -1)429*430* Between operands:431*432* Compare "op1" and "op2" according to the semantics of the433* "dcmpl" (direction is -1) or "dcmpg" (direction is 1) bytecodes.434*/435436static int32_t VMdoubleCompare(jdouble op1, jdouble op2, int32_t direction);437438/*439* Copy two typeless 32-bit words from one location to another.440* This is semantically equivalent to:441*442* to[0] = from[0];443* to[1] = from[1];444*445* but this interface is provided for those platforms that could446* optimize this into a single 64-bit transfer.447*/448449static void VMmemCopy64(uint32_t to[2], const uint32_t from[2]);450451452// Arithmetic operations453454/*455* Java arithmetic methods.456* The functions below follow the semantics of the457* iadd, isub, imul, idiv, irem, iand, ior, ixor,458* and ineg bytecodes, respectively.459*/460461static jint VMintAdd(jint op1, jint op2);462static jint VMintSub(jint op1, jint op2);463static jint VMintMul(jint op1, jint op2);464static jint VMintDiv(jint op1, jint op2);465static jint VMintRem(jint op1, jint op2);466static jint VMintAnd(jint op1, jint op2);467static jint VMintOr (jint op1, jint op2);468static jint VMintXor(jint op1, jint op2);469470/*471* Shift Operation:472* The functions below follow the semantics of the473* iushr, ishl, and ishr bytecodes, respectively.474*/475476static juint VMintUshr(jint op, jint num);477static jint VMintShl (jint op, jint num);478static jint VMintShr (jint op, jint num);479480/*481* Unary Operation:482*483* Return the negation of "op" (-op), according to484* the semantics of the ineg bytecode.485*/486487static jint VMintNeg(jint op);488489/*490* Int Conversions:491*/492493/*494* Convert int to float, according to "i2f" bytecode semantics495*/496497static jfloat VMint2Float(jint val);498499/*500* Convert int to byte, according to "i2b" bytecode semantics501*/502503static jbyte VMint2Byte(jint val);504505/*506* Convert int to char, according to "i2c" bytecode semantics507*/508509static jchar VMint2Char(jint val);510511/*512* Convert int to short, according to "i2s" bytecode semantics513*/514515static jshort VMint2Short(jint val);516517/*=========================================================================518* Bytecode interpreter operations519*=======================================================================*/520521static void dup(intptr_t *tos);522static void dup2(intptr_t *tos);523static void dup_x1(intptr_t *tos); /* insert top word two down */524static void dup_x2(intptr_t *tos); /* insert top word three down */525static void dup2_x1(intptr_t *tos); /* insert top 2 slots three down */526static void dup2_x2(intptr_t *tos); /* insert top 2 slots four down */527static void swap(intptr_t *tos); /* swap top two elements */528529// umm don't like this method modifies its object530531// The Interpreter used when532static void run(interpreterState istate);533// The interpreter used if JVMTI needs interpreter events534static void runWithChecks(interpreterState istate);535static void End_Of_Interpreter(void);536537// Inline static functions for Java Stack and Local manipulation538539static address stack_slot(intptr_t *tos, int offset);540static jint stack_int(intptr_t *tos, int offset);541static jfloat stack_float(intptr_t *tos, int offset);542static oop stack_object(intptr_t *tos, int offset);543static jdouble stack_double(intptr_t *tos, int offset);544static jlong stack_long(intptr_t *tos, int offset);545546// only used for value types547static void set_stack_slot(intptr_t *tos, address value, int offset);548static void set_stack_int(intptr_t *tos, int value, int offset);549static void set_stack_float(intptr_t *tos, jfloat value, int offset);550static void set_stack_object(intptr_t *tos, oop value, int offset);551552// needs to be platform dep for the 32 bit platforms.553static void set_stack_double(intptr_t *tos, jdouble value, int offset);554static void set_stack_long(intptr_t *tos, jlong value, int offset);555556static void set_stack_double_from_addr(intptr_t *tos, address addr, int offset);557static void set_stack_long_from_addr(intptr_t *tos, address addr, int offset);558559// Locals560561static address locals_slot(intptr_t* locals, int offset);562static jint locals_int(intptr_t* locals, int offset);563static jfloat locals_float(intptr_t* locals, int offset);564static oop locals_object(intptr_t* locals, int offset);565static jdouble locals_double(intptr_t* locals, int offset);566static jlong locals_long(intptr_t* locals, int offset);567568static address locals_long_at(intptr_t* locals, int offset);569static address locals_double_at(intptr_t* locals, int offset);570571static void set_locals_slot(intptr_t *locals, address value, int offset);572static void set_locals_int(intptr_t *locals, jint value, int offset);573static void set_locals_float(intptr_t *locals, jfloat value, int offset);574static void set_locals_object(intptr_t *locals, oop value, int offset);575static void set_locals_double(intptr_t *locals, jdouble value, int offset);576static void set_locals_long(intptr_t *locals, jlong value, int offset);577static void set_locals_double_from_addr(intptr_t *locals,578address addr, int offset);579static void set_locals_long_from_addr(intptr_t *locals,580address addr, int offset);581582static void astore(intptr_t* topOfStack, int stack_offset,583intptr_t* locals, int locals_offset);584585// Support for dup and swap586static void copy_stack_slot(intptr_t *tos, int from_offset, int to_offset);587588#ifndef PRODUCT589static const char* C_msg(BytecodeInterpreter::messages msg);590void print();591#endif // PRODUCT592593// Platform fields/methods594#ifdef TARGET_ARCH_x86595# include "bytecodeInterpreter_x86.hpp"596#endif597#ifdef TARGET_ARCH_aarch32598# include "bytecodeInterpreter_aarch32.hpp"599#endif600#ifdef TARGET_ARCH_aarch64601# include "bytecodeInterpreter_aarch64.hpp"602#endif603#ifdef TARGET_ARCH_sparc604# include "bytecodeInterpreter_sparc.hpp"605#endif606#ifdef TARGET_ARCH_zero607# include "bytecodeInterpreter_zero.hpp"608#endif609#ifdef TARGET_ARCH_arm610# include "bytecodeInterpreter_arm.hpp"611#endif612#ifdef TARGET_ARCH_ppc613# include "bytecodeInterpreter_ppc.hpp"614#endif615616617}; // BytecodeInterpreter618619#endif // CC_INTERP620621#endif // SHARE_VM_INTERPRETER_BYTECODEINTERPRETER_HPP622623624