Path: blob/master/src/hotspot/share/interpreter/zero/bytecodeInterpreter.hpp
40957 views
/*1* Copyright (c) 2002, 2020, 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_INTERPRETER_BYTECODEINTERPRETER_HPP25#define SHARE_INTERPRETER_BYTECODEINTERPRETER_HPP2627#include "memory/allocation.hpp"28#include "oops/method.hpp"29#include "runtime/basicLock.hpp"30#include "runtime/frame.hpp"31#include "runtime/globals.hpp"32#include "utilities/globalDefinitions.hpp"33#include "utilities/macros.hpp"3435// JavaStack Implementation36#define MORE_STACK(count) \37(topOfStack -= ((count) * Interpreter::stackElementWords))3839// CVM definitions find hotspot equivalents...4041class InterpreterMacroAssembler;4243union VMJavaVal64 {44jlong l;45jdouble d;46uint32_t v[2];47};484950typedef class BytecodeInterpreter* interpreterState;5152struct call_message {53class Method* _callee; // method to call during call_method request54address _callee_entry_point; // address to jump to for call_method request55int _bcp_advance; // size of the invoke bytecode operation56};5758struct osr_message {59address _osr_buf; // the osr buffer60address _osr_entry; // the entry to the osr method61};6263struct osr_result {64nmethod* nm; // osr nmethod65address return_addr; // osr blob return address66};6768// Result returned to frame manager69union frame_manager_message {70call_message _to_call; // describes callee71osr_message _osr; // describes the osr72osr_result _osr_result; // result of OSR request73};7475class BytecodeInterpreter : StackObj {76friend class SharedRuntime;77friend class AbstractInterpreterGenerator;78friend class ZeroInterpreterGenerator;79friend class InterpreterMacroAssembler;80friend class frame;81friend class VMStructs;8283public:84enum messages {85no_request = 0, // unused86initialize, // Perform one time interpreter initializations (assumes all switches set)87// status message to C++ interpreter88method_entry, // initial method entry to interpreter89method_resume, // frame manager response to return_from_method request (assuming a frame to resume)90deopt_resume, // returning from a native call into a deopted frame91deopt_resume2, // deopt resume as a result of a PopFrame92got_monitors, // frame manager response to more_monitors request93rethrow_exception, // unwinding and throwing exception94// requests to frame manager from C++ interpreter95call_method, // request for new frame from interpreter, manager responds with method_entry96return_from_method, // request from interpreter to unwind, manager responds with method_continue97more_monitors, // need a new monitor98throwing_exception, // unwind stack and rethrow99popping_frame, // unwind call and retry call100do_osr, // request this invocation be OSR's101early_return // early return as commanded by jvmti102};103104private:105JavaThread* _thread; // the vm's java thread pointer106address _bcp; // instruction pointer107intptr_t* _locals; // local variable pointer108ConstantPoolCache* _constants; // constant pool cache109Method* _method; // method being executed110oop _mirror; // mirror to klass containing method111intptr_t* _stack; // expression stack112messages _msg; // frame manager <-> interpreter message113frame_manager_message _result; // result to frame manager114interpreterState _prev_link; // previous interpreter state115oop _oop_temp; // mirror for interpreted native, null otherwise116intptr_t* _stack_base; // base of expression stack117intptr_t* _stack_limit; // limit of expression stack118BasicObjectLock* _monitor_base; // base of monitors on the native stack119120121public:122// Constructor is only used by the initialization step. All other instances are created123// by the frame manager.124BytecodeInterpreter(messages msg);125126//127// Deoptimization support128//129static void layout_interpreterState(interpreterState to_fill,130frame* caller,131frame* interpreter_frame,132Method* method,133intptr_t* locals,134intptr_t* stack,135intptr_t* stack_base,136intptr_t* monitor_base,137intptr_t* frame_bottom,138bool top_frame);139140/*141* Generic 32-bit wide "Java slot" definition. This type occurs142* in operand stacks, Java locals, object fields, constant pools.143*/144union VMJavaVal32 {145jint i;146jfloat f;147class oopDesc* r;148uint32_t raw;149};150151/*152* Generic 64-bit Java value definition153*/154union VMJavaVal64 {155jlong l;156jdouble d;157uint32_t v[2];158};159160/*161* Generic 32-bit wide "Java slot" definition. This type occurs162* in Java locals, object fields, constant pools, and163* operand stacks (as a CVMStackVal32).164*/165typedef union VMSlotVal32 {166VMJavaVal32 j; /* For "Java" values */167address a; /* a return created by jsr or jsr_w */168} VMSlotVal32;169170171/*172* Generic 32-bit wide stack slot definition.173*/174union VMStackVal32 {175VMJavaVal32 j; /* For "Java" values */176VMSlotVal32 s; /* any value from a "slot" or locals[] */177};178179inline JavaThread* thread() { return _thread; }180181inline address bcp() { return _bcp; }182inline void set_bcp(address new_bcp) { _bcp = new_bcp; }183184inline intptr_t* locals() { return _locals; }185186inline ConstantPoolCache* constants() { return _constants; }187inline Method* method() { return _method; }188189inline messages msg() { return _msg; }190inline void set_msg(messages new_msg) { _msg = new_msg; }191192inline Method* callee() { return _result._to_call._callee; }193inline void set_callee(Method* new_callee) { _result._to_call._callee = new_callee; }194inline void set_callee_entry_point(address entry) { _result._to_call._callee_entry_point = entry; }195inline void set_osr_buf(address buf) { _result._osr._osr_buf = buf; }196inline void set_osr_entry(address entry) { _result._osr._osr_entry = entry; }197inline int bcp_advance() { return _result._to_call._bcp_advance; }198inline void set_bcp_advance(int count) { _result._to_call._bcp_advance = count; }199200inline interpreterState prev() { return _prev_link; }201202inline intptr_t* stack() { return _stack; }203inline void set_stack(intptr_t* new_stack) { _stack = new_stack; }204205206inline intptr_t* stack_base() { return _stack_base; }207inline intptr_t* stack_limit() { return _stack_limit; }208209inline BasicObjectLock* monitor_base() { return _monitor_base; }210211/*212* 64-bit Arithmetic:213*214* The functions below follow the semantics of the215* ladd, land, ldiv, lmul, lor, lxor, and lrem bytecodes,216* respectively.217*/218219static jlong VMlongAdd(jlong op1, jlong op2);220static jlong VMlongAnd(jlong op1, jlong op2);221static jlong VMlongDiv(jlong op1, jlong op2);222static jlong VMlongMul(jlong op1, jlong op2);223static jlong VMlongOr (jlong op1, jlong op2);224static jlong VMlongSub(jlong op1, jlong op2);225static jlong VMlongXor(jlong op1, jlong op2);226static jlong VMlongRem(jlong op1, jlong op2);227228/*229* Shift:230*231* The functions below follow the semantics of the232* lushr, lshl, and lshr bytecodes, respectively.233*/234235static jlong VMlongUshr(jlong op1, jint op2);236static jlong VMlongShl (jlong op1, jint op2);237static jlong VMlongShr (jlong op1, jint op2);238239/*240* Unary:241*242* Return the negation of "op" (-op), according to243* the semantics of the lneg bytecode.244*/245246static jlong VMlongNeg(jlong op);247248/*249* Return the complement of "op" (~op)250*/251252static jlong VMlongNot(jlong op);253254255/*256* Comparisons to 0:257*/258259static int32_t VMlongLtz(jlong op); /* op <= 0 */260static int32_t VMlongGez(jlong op); /* op >= 0 */261static int32_t VMlongEqz(jlong op); /* op == 0 */262263/*264* Between operands:265*/266267static int32_t VMlongEq(jlong op1, jlong op2); /* op1 == op2 */268static int32_t VMlongNe(jlong op1, jlong op2); /* op1 != op2 */269static int32_t VMlongGe(jlong op1, jlong op2); /* op1 >= op2 */270static int32_t VMlongLe(jlong op1, jlong op2); /* op1 <= op2 */271static int32_t VMlongLt(jlong op1, jlong op2); /* op1 < op2 */272static int32_t VMlongGt(jlong op1, jlong op2); /* op1 > op2 */273274/*275* Comparisons (returning an jint value: 0, 1, or -1)276*277* Between operands:278*279* Compare "op1" and "op2" according to the semantics of the280* "lcmp" bytecode.281*/282283static int32_t VMlongCompare(jlong op1, jlong op2);284285/*286* Convert int to long, according to "i2l" bytecode semantics287*/288static jlong VMint2Long(jint val);289290/*291* Convert long to int, according to "l2i" bytecode semantics292*/293static jint VMlong2Int(jlong val);294295/*296* Convert long to float, according to "l2f" bytecode semantics297*/298static jfloat VMlong2Float(jlong val);299300/*301* Convert long to double, according to "l2d" bytecode semantics302*/303static jdouble VMlong2Double(jlong val);304305/*306* Java floating-point float value manipulation.307*308* The result argument is, once again, an lvalue.309*310* Arithmetic:311*312* The functions below follow the semantics of the313* fadd, fsub, fmul, fdiv, and frem bytecodes,314* respectively.315*/316317static jfloat VMfloatAdd(jfloat op1, jfloat op2);318static jfloat VMfloatSub(jfloat op1, jfloat op2);319static jfloat VMfloatMul(jfloat op1, jfloat op2);320static jfloat VMfloatDiv(jfloat op1, jfloat op2);321static jfloat VMfloatRem(jfloat op1, jfloat op2);322323/*324* Unary:325*326* Return the negation of "op" (-op), according to327* the semantics of the fneg bytecode.328*/329330static jfloat VMfloatNeg(jfloat op);331332/*333* Comparisons (returning an int value: 0, 1, or -1)334*335* Between operands:336*337* Compare "op1" and "op2" according to the semantics of the338* "fcmpl" (direction is -1) or "fcmpg" (direction is 1) bytecodes.339*/340341static int32_t VMfloatCompare(jfloat op1, jfloat op2,342int32_t direction);343/*344* Conversion:345*/346347/*348* Convert float to double, according to "f2d" bytecode semantics349*/350351static jdouble VMfloat2Double(jfloat op);352353/*354******************************************355* Java double floating-point manipulation.356******************************************357*358* The result argument is, once again, an lvalue.359*360* Conversions:361*/362363/*364* Convert double to int, according to "d2i" bytecode semantics365*/366367static jint VMdouble2Int(jdouble val);368369/*370* Convert double to float, according to "d2f" bytecode semantics371*/372373static jfloat VMdouble2Float(jdouble val);374375/*376* Convert int to double, according to "i2d" bytecode semantics377*/378379static jdouble VMint2Double(jint val);380381/*382* Arithmetic:383*384* The functions below follow the semantics of the385* dadd, dsub, ddiv, dmul, and drem bytecodes, respectively.386*/387388static jdouble VMdoubleAdd(jdouble op1, jdouble op2);389static jdouble VMdoubleSub(jdouble op1, jdouble op2);390static jdouble VMdoubleDiv(jdouble op1, jdouble op2);391static jdouble VMdoubleMul(jdouble op1, jdouble op2);392static jdouble VMdoubleRem(jdouble op1, jdouble op2);393394/*395* Unary:396*397* Return the negation of "op" (-op), according to398* the semantics of the dneg bytecode.399*/400401static jdouble VMdoubleNeg(jdouble op);402403/*404* Comparisons (returning an int32_t value: 0, 1, or -1)405*406* Between operands:407*408* Compare "op1" and "op2" according to the semantics of the409* "dcmpl" (direction is -1) or "dcmpg" (direction is 1) bytecodes.410*/411412static int32_t VMdoubleCompare(jdouble op1, jdouble op2, int32_t direction);413414/*415* Copy two typeless 32-bit words from one location to another.416* This is semantically equivalent to:417*418* to[0] = from[0];419* to[1] = from[1];420*421* but this interface is provided for those platforms that could422* optimize this into a single 64-bit transfer.423*/424425static void VMmemCopy64(uint32_t to[2], const uint32_t from[2]);426427428// Arithmetic operations429430/*431* Java arithmetic methods.432* The functions below follow the semantics of the433* iadd, isub, imul, idiv, irem, iand, ior, ixor,434* and ineg bytecodes, respectively.435*/436437static jint VMintAdd(jint op1, jint op2);438static jint VMintSub(jint op1, jint op2);439static jint VMintMul(jint op1, jint op2);440static jint VMintDiv(jint op1, jint op2);441static jint VMintRem(jint op1, jint op2);442static jint VMintAnd(jint op1, jint op2);443static jint VMintOr (jint op1, jint op2);444static jint VMintXor(jint op1, jint op2);445446/*447* Shift Operation:448* The functions below follow the semantics of the449* iushr, ishl, and ishr bytecodes, respectively.450*/451452static juint VMintUshr(jint op, jint num);453static jint VMintShl (jint op, jint num);454static jint VMintShr (jint op, jint num);455456/*457* Unary Operation:458*459* Return the negation of "op" (-op), according to460* the semantics of the ineg bytecode.461*/462463static jint VMintNeg(jint op);464465/*466* Int Conversions:467*/468469/*470* Convert int to float, according to "i2f" bytecode semantics471*/472473static jfloat VMint2Float(jint val);474475/*476* Convert int to byte, according to "i2b" bytecode semantics477*/478479static jbyte VMint2Byte(jint val);480481/*482* Convert int to char, according to "i2c" bytecode semantics483*/484485static jchar VMint2Char(jint val);486487/*488* Convert int to short, according to "i2s" bytecode semantics489*/490491static jshort VMint2Short(jint val);492493/*=========================================================================494* Bytecode interpreter operations495*=======================================================================*/496497static void dup(intptr_t *tos);498static void dup2(intptr_t *tos);499static void dup_x1(intptr_t *tos); /* insert top word two down */500static void dup_x2(intptr_t *tos); /* insert top word three down */501static void dup2_x1(intptr_t *tos); /* insert top 2 slots three down */502static void dup2_x2(intptr_t *tos); /* insert top 2 slots four down */503static void swap(intptr_t *tos); /* swap top two elements */504505template<bool JVMTI_ENABLED>506static void run(interpreterState istate);507508static void astore(intptr_t* topOfStack, int stack_offset,509intptr_t* locals, int locals_offset);510511// Support for dup and swap512static void copy_stack_slot(intptr_t *tos, int from_offset, int to_offset);513514#ifndef PRODUCT515static const char* C_msg(BytecodeInterpreter::messages msg);516void print();517#endif // PRODUCT518519# include "bytecodeInterpreter_zero.hpp"520521}; // BytecodeInterpreter522523#endif // SHARE_INTERPRETER_BYTECODEINTERPRETER_HPP524525526