Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/runtime/frame.hpp
32285 views
/*1* Copyright (c) 1997, 2018, 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_RUNTIME_FRAME_HPP25#define SHARE_VM_RUNTIME_FRAME_HPP2627#include "oops/method.hpp"28#include "runtime/basicLock.hpp"29#include "runtime/monitorChunk.hpp"30#include "runtime/registerMap.hpp"31#include "utilities/top.hpp"32#ifdef COMPILER233#if defined ADGLOBALS_MD_HPP34# include ADGLOBALS_MD_HPP35#elif defined TARGET_ARCH_MODEL_x86_3236# include "adfiles/adGlobals_x86_32.hpp"37#elif defined TARGET_ARCH_MODEL_x86_6438# include "adfiles/adGlobals_x86_64.hpp"39#elif defined TARGET_ARCH_MODEL_aarch3240# include "adfiles/adGlobals_aarch32.hpp"41#elif defined TARGET_ARCH_MODEL_aarch6442# include "adfiles/adGlobals_aarch64.hpp"43#elif defined TARGET_ARCH_MODEL_sparc44# include "adfiles/adGlobals_sparc.hpp"45#elif defined TARGET_ARCH_MODEL_zero46# include "adfiles/adGlobals_zero.hpp"47#elif defined TARGET_ARCH_MODEL_ppc_6448# include "adfiles/adGlobals_ppc_64.hpp"49#endif50#endif // COMPILER251#ifdef TARGET_ARCH_zero52# include "stack_zero.hpp"53#endif5455typedef class BytecodeInterpreter* interpreterState;5657class CodeBlob;58class FrameValues;59class vframeArray;606162// A frame represents a physical stack frame (an activation). Frames63// can be C or Java frames, and the Java frames can be interpreted or64// compiled. In contrast, vframes represent source-level activations,65// so that one physical frame can correspond to multiple source level66// frames because of inlining.6768class frame VALUE_OBJ_CLASS_SPEC {69private:70// Instance variables:71intptr_t* _sp; // stack pointer (from Thread::last_Java_sp)72address _pc; // program counter (the next instruction after the call)7374CodeBlob* _cb; // CodeBlob that "owns" pc75enum deopt_state {76not_deoptimized,77is_deoptimized,78unknown79};8081deopt_state _deopt_state;8283public:84// Constructors85frame();8687#ifndef PRODUCT88// This is a generic constructor which is only used by pns() in debug.cpp.89// pns (i.e. print native stack) uses this constructor to create a starting90// frame for stack walking. The implementation of this constructor is platform91// dependent (i.e. SPARC doesn't need an 'fp' argument an will ignore it) but92// we want to keep the signature generic because pns() is shared code.93frame(void* sp, void* fp, void* pc);94#endif9596// Accessors9798// pc: Returns the pc at which this frame will continue normally.99// It must point at the beginning of the next instruction to execute.100address pc() const { return _pc; }101102// This returns the pc that if you were in the debugger you'd see. Not103// the idealized value in the frame object. This undoes the magic conversion104// that happens for deoptimized frames. In addition it makes the value the105// hardware would want to see in the native frame. The only user (at this point)106// is deoptimization. It likely no one else should ever use it.107address raw_pc() const;108109void set_pc( address newpc );110111intptr_t* sp() const { return _sp; }112void set_sp( intptr_t* newsp ) { _sp = newsp; }113114115CodeBlob* cb() const { return _cb; }116117// patching operations118void patch_pc(Thread* thread, address pc);119120// Every frame needs to return a unique id which distinguishes it from all other frames.121// For sparc and ia32 use sp. ia64 can have memory frames that are empty so multiple frames122// will have identical sp values. For ia64 the bsp (fp) value will serve. No real frame123// should have an id() of NULL so it is a distinguishing value for an unmatchable frame.124// We also have relationals which allow comparing a frame to anoth frame's id() allow125// us to distinguish younger (more recent activation) from older (less recent activations)126// A NULL id is only valid when comparing for equality.127128intptr_t* id(void) const;129bool is_younger(intptr_t* id) const;130bool is_older(intptr_t* id) const;131132// testers133134// Compares for strict equality. Rarely used or needed.135// It can return a different result than f1.id() == f2.id()136bool equal(frame other) const;137138// type testers139bool is_interpreted_frame() const;140bool is_java_frame() const;141bool is_entry_frame() const; // Java frame called from C?142bool is_stub_frame() const;143bool is_ignored_frame() const;144bool is_native_frame() const;145bool is_runtime_frame() const;146bool is_compiled_frame() const;147bool is_safepoint_blob_frame() const;148bool is_deoptimized_frame() const;149150// testers151bool is_first_frame() const; // oldest frame? (has no sender)152bool is_first_java_frame() const; // same for Java frame153154bool is_interpreted_frame_valid(JavaThread* thread) const; // performs sanity checks on interpreted frames.155156// tells whether this frame is marked for deoptimization157bool should_be_deoptimized() const;158159// tells whether this frame can be deoptimized160bool can_be_deoptimized() const;161162// returns the frame size in stack slots163int frame_size(RegisterMap* map) const;164165// returns the sending frame166frame sender(RegisterMap* map) const;167168// for Profiling - acting on another frame. walks sender frames169// if valid.170frame profile_find_Java_sender_frame(JavaThread *thread);171bool safe_for_sender(JavaThread *thread);172173// returns the sender, but skips conversion frames174frame real_sender(RegisterMap* map) const;175176// returns the the sending Java frame, skipping any intermediate C frames177// NB: receiver must not be first frame178frame java_sender() const;179180private:181// Helper methods for better factored code in frame::sender182frame sender_for_compiled_frame(RegisterMap* map) const;183frame sender_for_entry_frame(RegisterMap* map) const;184frame sender_for_interpreter_frame(RegisterMap* map) const;185frame sender_for_native_frame(RegisterMap* map) const;186187bool is_entry_frame_valid(JavaThread* thread) const;188189// All frames:190191// A low-level interface for vframes:192193public:194195intptr_t* addr_at(int index) const { return &fp()[index]; }196intptr_t at(int index) const { return *addr_at(index); }197198// accessors for locals199oop obj_at(int offset) const { return *obj_at_addr(offset); }200void obj_at_put(int offset, oop value) { *obj_at_addr(offset) = value; }201202jint int_at(int offset) const { return *int_at_addr(offset); }203void int_at_put(int offset, jint value) { *int_at_addr(offset) = value; }204205oop* obj_at_addr(int offset) const { return (oop*) addr_at(offset); }206207oop* adjusted_obj_at_addr(Method* method, int index) { return obj_at_addr(adjust_offset(method, index)); }208209private:210jint* int_at_addr(int offset) const { return (jint*) addr_at(offset); }211212public:213// Link (i.e., the pointer to the previous frame)214intptr_t* link() const;215void set_link(intptr_t* addr);216217// Return address218address sender_pc() const;219220// Support for deoptimization221void deoptimize(JavaThread* thread);222223// The frame's original SP, before any extension by an interpreted callee;224// used for packing debug info into vframeArray objects and vframeArray lookup.225intptr_t* unextended_sp() const;226227// returns the stack pointer of the calling frame228intptr_t* sender_sp() const;229230// Returns the real 'frame pointer' for the current frame.231// This is the value expected by the platform ABI when it defines a232// frame pointer register. It may differ from the effective value of233// the FP register when that register is used in the JVM for other234// purposes (like compiled frames on some platforms).235// On other platforms, it is defined so that the stack area used by236// this frame goes from real_fp() to sp().237intptr_t* real_fp() const;238239// Deoptimization info, if needed (platform dependent).240// Stored in the initial_info field of the unroll info, to be used by241// the platform dependent deoptimization blobs.242intptr_t *initial_deoptimization_info();243244// Interpreter frames:245246private:247intptr_t** interpreter_frame_locals_addr() const;248intptr_t* interpreter_frame_bcx_addr() const;249intptr_t* interpreter_frame_mdx_addr() const;250251public:252// Locals253254// The _at version returns a pointer because the address is used for GC.255intptr_t* interpreter_frame_local_at(int index) const;256257void interpreter_frame_set_locals(intptr_t* locs);258259// byte code index/pointer (use these functions for unchecked frame access only!)260intptr_t interpreter_frame_bcx() const { return *interpreter_frame_bcx_addr(); }261void interpreter_frame_set_bcx(intptr_t bcx);262263// byte code index264jint interpreter_frame_bci() const;265void interpreter_frame_set_bci(jint bci);266267// byte code pointer268address interpreter_frame_bcp() const;269void interpreter_frame_set_bcp(address bcp);270271// Unchecked access to the method data index/pointer.272// Only use this if you know what you are doing.273intptr_t interpreter_frame_mdx() const { return *interpreter_frame_mdx_addr(); }274void interpreter_frame_set_mdx(intptr_t mdx);275276// method data pointer277address interpreter_frame_mdp() const;278void interpreter_frame_set_mdp(address dp);279280// Find receiver out of caller's (compiled) argument list281oop retrieve_receiver(RegisterMap *reg_map);282283// Return the monitor owner and BasicLock for compiled synchronized284// native methods so that biased locking can revoke the receiver's285// bias if necessary. This is also used by JVMTI's GetLocalInstance method286// (via VM_GetReceiver) to retrieve the receiver from a native wrapper frame.287BasicLock* get_native_monitor();288oop get_native_receiver();289290// Find receiver for an invoke when arguments are just pushed on stack (i.e., callee stack-frame is291// not setup)292oop interpreter_callee_receiver(Symbol* signature) { return *interpreter_callee_receiver_addr(signature); }293294295oop* interpreter_callee_receiver_addr(Symbol* signature);296297298// expression stack (may go up or down, direction == 1 or -1)299public:300intptr_t* interpreter_frame_expression_stack() const;301static jint interpreter_frame_expression_stack_direction();302303// The _at version returns a pointer because the address is used for GC.304intptr_t* interpreter_frame_expression_stack_at(jint offset) const;305306// top of expression stack307intptr_t* interpreter_frame_tos_at(jint offset) const;308intptr_t* interpreter_frame_tos_address() const;309310311jint interpreter_frame_expression_stack_size() const;312313intptr_t* interpreter_frame_sender_sp() const;314315#ifndef CC_INTERP316// template based interpreter deoptimization support317void set_interpreter_frame_sender_sp(intptr_t* sender_sp);318void interpreter_frame_set_monitor_end(BasicObjectLock* value);319#endif // CC_INTERP320321// Address of the temp oop in the frame. Needed as GC root.322oop* interpreter_frame_temp_oop_addr() const;323324// BasicObjectLocks:325//326// interpreter_frame_monitor_begin is higher in memory than interpreter_frame_monitor_end327// Interpreter_frame_monitor_begin points to one element beyond the oldest one,328// interpreter_frame_monitor_end points to the youngest one, or if there are none,329// it points to one beyond where the first element will be.330// interpreter_frame_monitor_size reports the allocation size of a monitor in the interpreter stack.331// this value is >= BasicObjectLock::size(), and may be rounded up332333BasicObjectLock* interpreter_frame_monitor_begin() const;334BasicObjectLock* interpreter_frame_monitor_end() const;335BasicObjectLock* next_monitor_in_interpreter_frame(BasicObjectLock* current) const;336BasicObjectLock* previous_monitor_in_interpreter_frame(BasicObjectLock* current) const;337static int interpreter_frame_monitor_size();338339void interpreter_frame_verify_monitor(BasicObjectLock* value) const;340341// Tells whether the current interpreter_frame frame pointer342// corresponds to the old compiled/deoptimized fp343// The receiver used to be a top level frame344bool interpreter_frame_equals_unpacked_fp(intptr_t* fp);345346// Return/result value from this interpreter frame347// If the method return type is T_OBJECT or T_ARRAY populates oop_result348// For other (non-T_VOID) the appropriate field in the jvalue is populated349// with the result value.350// Should only be called when at method exit when the method is not351// exiting due to an exception.352BasicType interpreter_frame_result(oop* oop_result, jvalue* value_result);353354public:355// Method & constant pool cache356Method* interpreter_frame_method() const;357void interpreter_frame_set_method(Method* method);358Method** interpreter_frame_method_addr() const;359ConstantPoolCache** interpreter_frame_cache_addr() const;360361public:362// Entry frames363JavaCallWrapper* entry_frame_call_wrapper() const { return *entry_frame_call_wrapper_addr(); }364JavaCallWrapper* entry_frame_call_wrapper_if_safe(JavaThread* thread) const;365JavaCallWrapper** entry_frame_call_wrapper_addr() const;366intptr_t* entry_frame_argument_at(int offset) const;367368// tells whether there is another chunk of Delta stack above369bool entry_frame_is_first() const;370371// Compiled frames:372373public:374// Given the index of a local, and the number of argument words375// in this stack frame, tell which word of the stack frame to find376// the local in. Arguments are stored above the ofp/rpc pair,377// while other locals are stored below it.378// Since monitors (BasicLock blocks) are also assigned indexes,379// but may have different storage requirements, their presence380// can also affect the calculation of offsets.381static int local_offset_for_compiler(int local_index, int nof_args, int max_nof_locals, int max_nof_monitors);382383// Given the index of a monitor, etc., tell which word of the384// stack frame contains the start of the BasicLock block.385// Note that the local index by convention is the __higher__386// of the two indexes allocated to the block.387static int monitor_offset_for_compiler(int local_index, int nof_args, int max_nof_locals, int max_nof_monitors);388389// Tell the smallest value that local_offset_for_compiler will attain.390// This is used to help determine how much stack frame to allocate.391static int min_local_offset_for_compiler(int nof_args, int max_nof_locals, int max_nof_monitors);392393// Tells if this register must be spilled during a call.394// On Intel, all registers are smashed by calls.395static bool volatile_across_calls(Register reg);396397398// Safepoints399400public:401oop saved_oop_result(RegisterMap* map) const;402void set_saved_oop_result(RegisterMap* map, oop obj);403404// For debugging405private:406const char* print_name() const;407408void describe_pd(FrameValues& values, int frame_no);409410public:411void print_value() const { print_value_on(tty,NULL); }412void print_value_on(outputStream* st, JavaThread *thread) const;413void print_on(outputStream* st) const;414void interpreter_frame_print_on(outputStream* st) const;415void print_on_error(outputStream* st, char* buf, int buflen, bool verbose = false) const;416static void print_C_frame(outputStream* st, char* buf, int buflen, address pc);417418// Add annotated descriptions of memory locations belonging to this frame to values419void describe(FrameValues& values, int frame_no);420421// Conversion from an VMReg to physical stack location422oop* oopmapreg_to_location(VMReg reg, const RegisterMap* regmap) const;423424// Oops-do's425void oops_compiled_arguments_do(Symbol* signature, bool has_receiver, bool has_appendix, const RegisterMap* reg_map, OopClosure* f);426void oops_interpreted_do(OopClosure* f, CLDClosure* cld_f, const RegisterMap* map, bool query_oop_map_cache = true);427428private:429void oops_interpreted_arguments_do(Symbol* signature, bool has_receiver, OopClosure* f);430431// Iteration of oops432void oops_do_internal(OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf, RegisterMap* map, bool use_interpreter_oop_map_cache);433void oops_entry_do(OopClosure* f, const RegisterMap* map);434void oops_code_blob_do(OopClosure* f, CodeBlobClosure* cf, const RegisterMap* map);435int adjust_offset(Method* method, int index); // helper for above fn436public:437// Memory management438void oops_do(OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf, RegisterMap* map) { oops_do_internal(f, cld_f, cf, map, true); }439void nmethods_do(CodeBlobClosure* cf);440441// RedefineClasses support for finding live interpreted methods on the stack442void metadata_do(void f(Metadata*));443444void gc_prologue();445void gc_epilogue();446void pd_gc_epilog();447448# ifdef ENABLE_ZAP_DEAD_LOCALS449private:450class CheckValueClosure: public OopClosure {451public:452void do_oop(oop* p);453void do_oop(narrowOop* p) { ShouldNotReachHere(); }454};455static CheckValueClosure _check_value;456457class CheckOopClosure: public OopClosure {458public:459void do_oop(oop* p);460void do_oop(narrowOop* p) { ShouldNotReachHere(); }461};462static CheckOopClosure _check_oop;463464static void check_derived_oop(oop* base, oop* derived);465466class ZapDeadClosure: public OopClosure {467public:468void do_oop(oop* p);469void do_oop(narrowOop* p) { ShouldNotReachHere(); }470};471static ZapDeadClosure _zap_dead;472473public:474// Zapping475void zap_dead_locals (JavaThread* thread, const RegisterMap* map);476void zap_dead_interpreted_locals(JavaThread* thread, const RegisterMap* map);477void zap_dead_compiled_locals (JavaThread* thread, const RegisterMap* map);478void zap_dead_entry_locals (JavaThread* thread, const RegisterMap* map);479void zap_dead_deoptimized_locals(JavaThread* thread, const RegisterMap* map);480# endif481// Verification482void verify(const RegisterMap* map);483static bool verify_return_pc(address x);484static bool is_bci(intptr_t bcx);485// Usage:486// assert(frame::verify_return_pc(return_address), "must be a return pc");487488int pd_oop_map_offset_adjustment() const;489490#ifdef TARGET_ARCH_x86491# include "frame_x86.hpp"492#endif493#ifdef TARGET_ARCH_aarch32494# include "frame_aarch32.hpp"495#endif496#ifdef TARGET_ARCH_aarch64497# include "frame_aarch64.hpp"498#endif499#ifdef TARGET_ARCH_sparc500# include "frame_sparc.hpp"501#endif502#ifdef TARGET_ARCH_zero503# include "frame_zero.hpp"504#endif505#ifdef TARGET_ARCH_arm506# include "frame_arm.hpp"507#endif508#ifdef TARGET_ARCH_ppc509# include "frame_ppc.hpp"510#endif511512};513514#ifndef PRODUCT515// A simple class to describe a location on the stack516class FrameValue VALUE_OBJ_CLASS_SPEC {517public:518intptr_t* location;519char* description;520int owner;521int priority;522};523524525// A collection of described stack values that can print a symbolic526// description of the stack memory. Interpreter frame values can be527// in the caller frames so all the values are collected first and then528// sorted before being printed.529class FrameValues {530private:531GrowableArray<FrameValue> _values;532533static int compare(FrameValue* a, FrameValue* b) {534if (a->location == b->location) {535return a->priority - b->priority;536}537return a->location - b->location;538}539540public:541// Used by frame functions to describe locations.542void describe(int owner, intptr_t* location, const char* description, int priority = 0);543544#ifdef ASSERT545void validate();546#endif547void print(JavaThread* thread);548};549550#endif551552//553// StackFrameStream iterates through the frames of a thread starting from554// top most frame. It automatically takes care of updating the location of555// all (callee-saved) registers. Notice: If a thread is stopped at556// a safepoint, all registers are saved, not only the callee-saved ones.557//558// Use:559//560// for(StackFrameStream fst(thread); !fst.is_done(); fst.next()) {561// ...562// }563//564class StackFrameStream : public StackObj {565private:566frame _fr;567RegisterMap _reg_map;568bool _is_done;569public:570StackFrameStream(JavaThread *thread, bool update = true);571572// Iteration573bool is_done() { return (_is_done) ? true : (_is_done = _fr.is_first_frame(), false); }574void next() { if (!_is_done) _fr = _fr.sender(&_reg_map); }575576// Query577frame *current() { return &_fr; }578RegisterMap* register_map() { return &_reg_map; }579};580581#endif // SHARE_VM_RUNTIME_FRAME_HPP582583584