Path: blob/master/src/hotspot/share/jvmci/jvmciCodeInstaller.hpp
40949 views
/*1* Copyright (c) 2011, 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*/2223#ifndef SHARE_JVMCI_JVMCICODEINSTALLER_HPP24#define SHARE_JVMCI_JVMCICODEINSTALLER_HPP2526#include "code/debugInfoRec.hpp"27#include "code/exceptionHandlerTable.hpp"28#include "code/nativeInst.hpp"29#include "jvmci/jvmci.hpp"30#include "jvmci/jvmciEnv.hpp"3132class CodeMetadata {33public:34CodeMetadata() {}3536CodeBlob* get_code_blob() const { return _cb; }3738PcDesc* get_pc_desc() const { return _pc_desc; }39int get_nr_pc_desc() const { return _nr_pc_desc; }4041u_char* get_scopes_desc() const { return _scopes_desc; }42int get_scopes_size() const { return _nr_scopes_desc; }4344ExceptionHandlerTable* get_exception_table() { return _exception_table; }4546ImplicitExceptionTable* get_implicit_exception_table() { return _implicit_exception_table; }4748void set_pc_desc(PcDesc* desc, int count) {49_pc_desc = desc;50_nr_pc_desc = count;51}5253void set_scopes(u_char* scopes, int size) {54_scopes_desc = scopes;55_nr_scopes_desc = size;56}5758void set_exception_table(ExceptionHandlerTable* table) {59_exception_table = table;60}6162void set_implicit_exception_table(ImplicitExceptionTable* table) {63_implicit_exception_table = table;64}6566private:67CodeBlob* _cb;68PcDesc* _pc_desc;69int _nr_pc_desc;7071u_char* _scopes_desc;72int _nr_scopes_desc;7374ExceptionHandlerTable* _exception_table;75ImplicitExceptionTable* _implicit_exception_table;76};7778/*79* This class handles the conversion from a InstalledCode to a CodeBlob or an nmethod.80*/81class CodeInstaller : public StackObj {82friend class JVMCIVMStructs;83private:84enum MarkId {85INVALID_MARK,86VERIFIED_ENTRY,87UNVERIFIED_ENTRY,88OSR_ENTRY,89EXCEPTION_HANDLER_ENTRY,90DEOPT_HANDLER_ENTRY,91FRAME_COMPLETE,92INVOKEINTERFACE,93INVOKEVIRTUAL,94INVOKESTATIC,95INVOKESPECIAL,96INLINE_INVOKE,97POLL_NEAR,98POLL_RETURN_NEAR,99POLL_FAR,100POLL_RETURN_FAR,101CARD_TABLE_ADDRESS,102CARD_TABLE_SHIFT,103HEAP_TOP_ADDRESS,104HEAP_END_ADDRESS,105NARROW_KLASS_BASE_ADDRESS,106NARROW_OOP_BASE_ADDRESS,107CRC_TABLE_ADDRESS,108LOG_OF_HEAP_REGION_GRAIN_BYTES,109INLINE_CONTIGUOUS_ALLOCATION_SUPPORTED,110DEOPT_MH_HANDLER_ENTRY,111VERIFY_OOPS,112VERIFY_OOP_BITS,113VERIFY_OOP_MASK,114VERIFY_OOP_COUNT_ADDRESS,115INVOKE_INVALID = -1116};117118Arena _arena;119JVMCIEnv* _jvmci_env;120121JVMCIPrimitiveArray _data_section_handle;122JVMCIObjectArray _data_section_patches_handle;123JVMCIObjectArray _sites_handle;124#ifndef PRODUCT125JVMCIObjectArray _comments_handle;126#endif127JVMCIPrimitiveArray _code_handle;128JVMCIObject _word_kind_handle;129130CodeOffsets _offsets;131132jint _code_size;133jint _total_frame_size;134jint _orig_pc_offset;135jint _parameter_count;136jint _constants_size;137138bool _has_wide_vector;139140MarkId _next_call_type;141address _invoke_mark_pc;142143CodeSection* _instructions;144CodeSection* _constants;145146OopRecorder* _oop_recorder;147DebugInformationRecorder* _debug_recorder;148Dependencies* _dependencies;149ExceptionHandlerTable _exception_handler_table;150ImplicitExceptionTable _implicit_exception_table;151bool _has_auto_box;152153static ConstantOopWriteValue* _oop_null_scope_value;154static ConstantIntValue* _int_m1_scope_value;155static ConstantIntValue* _int_0_scope_value;156static ConstantIntValue* _int_1_scope_value;157static ConstantIntValue* _int_2_scope_value;158static LocationValue* _illegal_value;159static MarkerValue* _virtual_byte_array_marker;160161jint pd_next_offset(NativeInstruction* inst, jint pc_offset, JVMCIObject method, JVMCI_TRAPS);162void pd_patch_OopConstant(int pc_offset, JVMCIObject constant, JVMCI_TRAPS);163void pd_patch_MetaspaceConstant(int pc_offset, JVMCIObject constant, JVMCI_TRAPS);164void pd_patch_DataSectionReference(int pc_offset, int data_offset, JVMCI_TRAPS);165void pd_relocate_ForeignCall(NativeInstruction* inst, jlong foreign_call_destination, JVMCI_TRAPS);166void pd_relocate_JavaMethod(CodeBuffer &cbuf, JVMCIObject method, jint pc_offset, JVMCI_TRAPS);167void pd_relocate_poll(address pc, jint mark, JVMCI_TRAPS);168169JVMCIObjectArray sites() { return _sites_handle; }170JVMCIPrimitiveArray code() { return _code_handle; }171JVMCIPrimitiveArray data_section() { return _data_section_handle; }172JVMCIObjectArray data_section_patches() { return _data_section_patches_handle; }173#ifndef PRODUCT174JVMCIObjectArray comments() { return _comments_handle; }175#endif176JVMCIObject word_kind() { return _word_kind_handle; }177178public:179180CodeInstaller(JVMCIEnv* jvmci_env) :181_arena(mtJVMCI),182_jvmci_env(jvmci_env),183_has_auto_box(false) {}184185JVMCI::CodeInstallResult install(JVMCICompiler* compiler,186JVMCIObject target,187JVMCIObject compiled_code,188CodeBlob*& cb,189JVMCIObject installed_code,190FailedSpeculation** failed_speculations,191char* speculations,192int speculations_len,193JVMCI_TRAPS);194195JVMCIEnv* jvmci_env() { return _jvmci_env; }196JVMCIRuntime* runtime() { return _jvmci_env->runtime(); }197198static address runtime_call_target_address(oop runtime_call);199static VMReg get_hotspot_reg(jint jvmciRegisterNumber, JVMCI_TRAPS);200static bool is_general_purpose_reg(VMReg hotspotRegister);201202const OopMapSet* oopMapSet() const { return _debug_recorder->_oopmaps; }203204protected:205Location::Type get_oop_type(JVMCIObject value);206ScopeValue* get_scope_value(JVMCIObject value, BasicType type, GrowableArray<ScopeValue*>* objects, ScopeValue* &second, JVMCI_TRAPS);207MonitorValue* get_monitor_value(JVMCIObject value, GrowableArray<ScopeValue*>* objects, JVMCI_TRAPS);208209void* record_metadata_reference(CodeSection* section, address dest, JVMCIObject constant, JVMCI_TRAPS);210#ifdef _LP64211narrowKlass record_narrow_metadata_reference(CodeSection* section, address dest, JVMCIObject constant, JVMCI_TRAPS);212#endif213214// extract the fields of the HotSpotCompiledCode215void initialize_fields(JVMCIObject target, JVMCIObject compiled_code, JVMCI_TRAPS);216void initialize_dependencies(JVMCIObject compiled_code, OopRecorder* oop_recorder, JVMCI_TRAPS);217218int estimate_stubs_size(JVMCI_TRAPS);219220// perform data and call relocation on the CodeBuffer221JVMCI::CodeInstallResult initialize_buffer(CodeBuffer& buffer, bool check_size, JVMCI_TRAPS);222223void assumption_NoFinalizableSubclass(JVMCIObject assumption);224void assumption_ConcreteSubtype(JVMCIObject assumption);225void assumption_LeafType(JVMCIObject assumption);226void assumption_ConcreteMethod(JVMCIObject assumption);227void assumption_CallSiteTargetValue(JVMCIObject assumption, JVMCI_TRAPS);228229void site_Safepoint(CodeBuffer& buffer, jint pc_offset, JVMCIObject site, JVMCI_TRAPS);230void site_Infopoint(CodeBuffer& buffer, jint pc_offset, JVMCIObject site, JVMCI_TRAPS);231void site_Call(CodeBuffer& buffer, jint pc_offset, JVMCIObject site, JVMCI_TRAPS);232void site_DataPatch(CodeBuffer& buffer, jint pc_offset, JVMCIObject site, JVMCI_TRAPS);233void site_Mark(CodeBuffer& buffer, jint pc_offset, JVMCIObject site, JVMCI_TRAPS);234void site_ExceptionHandler(jint pc_offset, JVMCIObject site);235236OopMap* create_oop_map(JVMCIObject debug_info, JVMCI_TRAPS);237238VMReg getVMRegFromLocation(JVMCIObject location, int total_frame_size, JVMCI_TRAPS);239240/**241* Specifies the level of detail to record for a scope.242*/243enum ScopeMode {244// Only record a method and BCI245BytecodePosition,246// Record a method, bci and JVM frame state247FullFrame248};249250int map_jvmci_bci(int bci);251252void record_scope(jint pc_offset, JVMCIObject debug_info, ScopeMode scope_mode, bool is_mh_invoke, bool return_oop, JVMCI_TRAPS);253void record_scope(jint pc_offset, JVMCIObject debug_info, ScopeMode scope_mode, JVMCI_TRAPS) {254record_scope(pc_offset, debug_info, scope_mode, false /* is_mh_invoke */, false /* return_oop */, JVMCIENV);255}256void record_scope(jint pc_offset, JVMCIObject position, ScopeMode scope_mode, GrowableArray<ScopeValue*>* objects, bool is_mh_invoke, bool return_oop, JVMCI_TRAPS);257void record_object_value(ObjectValue* sv, JVMCIObject value, GrowableArray<ScopeValue*>* objects, JVMCI_TRAPS);258259GrowableArray<ScopeValue*>* record_virtual_objects(JVMCIObject debug_info, JVMCI_TRAPS);260261int estimateStubSpace(int static_call_stubs);262};263264#endif // SHARE_JVMCI_JVMCICODEINSTALLER_HPP265266267