Path: blob/master/src/hotspot/share/ci/ciEnv.hpp
40930 views
/*1* Copyright (c) 1999, 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#ifndef SHARE_CI_CIENV_HPP25#define SHARE_CI_CIENV_HPP2627#include "ci/ciClassList.hpp"28#include "ci/ciObjectFactory.hpp"29#include "classfile/vmClassMacros.hpp"30#include "code/debugInfoRec.hpp"31#include "code/dependencies.hpp"32#include "code/exceptionHandlerTable.hpp"33#include "compiler/compilerThread.hpp"34#include "oops/methodData.hpp"35#include "runtime/thread.hpp"3637class CompileTask;38class OopMapSet;3940// ciEnv41//42// This class is the top level broker for requests from the compiler43// to the VM.44class ciEnv : StackObj {45CI_PACKAGE_ACCESS_TO4647friend class CompileBroker;48friend class Dependencies; // for get_object, during logging49friend class PrepareExtraDataClosure;5051private:52Arena* _arena; // Alias for _ciEnv_arena except in init_shared_objects()53Arena _ciEnv_arena;54ciObjectFactory* _factory;55OopRecorder* _oop_recorder;56DebugInformationRecorder* _debug_info;57Dependencies* _dependencies;58const char* _failure_reason;59bool _inc_decompile_count_on_failure;60int _compilable;61bool _break_at_compile;62int _num_inlined_bytecodes;63CompileTask* _task; // faster access to CompilerThread::task64CompileLog* _log; // faster access to CompilerThread::log65void* _compiler_data; // compiler-specific stuff, if any6667char* _name_buffer;68int _name_buffer_len;6970// Cache Jvmti state71uint64_t _jvmti_redefinition_count;72bool _jvmti_can_hotswap_or_post_breakpoint;73bool _jvmti_can_access_local_variables;74bool _jvmti_can_post_on_exceptions;75bool _jvmti_can_pop_frame;76bool _jvmti_can_get_owned_monitor_info; // includes can_get_owned_monitor_stack_depth_info77bool _jvmti_can_walk_any_space;7879// Cache DTrace flags80bool _dtrace_extended_probes;81bool _dtrace_method_probes;82bool _dtrace_alloc_probes;8384// Distinguished instances of certain ciObjects..85static ciObject* _null_object_instance;8687#define VM_CLASS_DECL(name, ignore_s) static ciInstanceKlass* _##name;88VM_CLASSES_DO(VM_CLASS_DECL)89#undef VM_CLASS_DECL9091static ciSymbol* _unloaded_cisymbol;92static ciInstanceKlass* _unloaded_ciinstance_klass;93static ciObjArrayKlass* _unloaded_ciobjarrayklass;9495static jobject _ArrayIndexOutOfBoundsException_handle;96static jobject _ArrayStoreException_handle;97static jobject _ClassCastException_handle;9899ciInstance* _NullPointerException_instance;100ciInstance* _ArithmeticException_instance;101ciInstance* _ArrayIndexOutOfBoundsException_instance;102ciInstance* _ArrayStoreException_instance;103ciInstance* _ClassCastException_instance;104105ciInstance* _the_null_string; // The Java string "null"106ciInstance* _the_min_jint_string; // The Java string "-2147483648"107108// Look up a klass by name from a particular class loader (the accessor's).109// If require_local, result must be defined in that class loader, or NULL.110// If !require_local, a result from remote class loader may be reported,111// if sufficient class loader constraints exist such that initiating112// a class loading request from the given loader is bound to return113// the class defined in the remote loader (or throw an error).114//115// Return an unloaded klass if !require_local and no class at all is found.116//117// The CI treats a klass as loaded if it is consistently defined in118// another loader, even if it hasn't yet been loaded in all loaders119// that could potentially see it via delegation.120ciKlass* get_klass_by_name(ciKlass* accessing_klass,121ciSymbol* klass_name,122bool require_local);123124// Constant pool access.125ciKlass* get_klass_by_index(const constantPoolHandle& cpool,126int klass_index,127bool& is_accessible,128ciInstanceKlass* loading_klass);129ciConstant get_constant_by_index(const constantPoolHandle& cpool,130int pool_index, int cache_index,131ciInstanceKlass* accessor);132ciField* get_field_by_index(ciInstanceKlass* loading_klass,133int field_index);134ciMethod* get_method_by_index(const constantPoolHandle& cpool,135int method_index, Bytecodes::Code bc,136ciInstanceKlass* loading_klass);137138// Implementation methods for loading and constant pool access.139ciKlass* get_klass_by_name_impl(ciKlass* accessing_klass,140const constantPoolHandle& cpool,141ciSymbol* klass_name,142bool require_local);143ciKlass* get_klass_by_index_impl(const constantPoolHandle& cpool,144int klass_index,145bool& is_accessible,146ciInstanceKlass* loading_klass);147ciConstant get_constant_by_index_impl(const constantPoolHandle& cpool,148int pool_index, int cache_index,149ciInstanceKlass* loading_klass);150ciField* get_field_by_index_impl(ciInstanceKlass* loading_klass,151int field_index);152ciMethod* get_method_by_index_impl(const constantPoolHandle& cpool,153int method_index, Bytecodes::Code bc,154ciInstanceKlass* loading_klass);155156// Helper methods157bool check_klass_accessibility(ciKlass* accessing_klass,158Klass* resolved_klass);159Method* lookup_method(ciInstanceKlass* accessor,160ciKlass* holder,161Symbol* name,162Symbol* sig,163Bytecodes::Code bc,164constantTag tag);165166// Get a ciObject from the object factory. Ensures uniqueness167// of ciObjects.168ciObject* get_object(oop o) {169if (o == NULL) {170return _null_object_instance;171} else {172return _factory->get(o);173}174}175176ciSymbol* get_symbol(Symbol* o) {177if (o == NULL) {178ShouldNotReachHere();179return NULL;180} else {181return _factory->get_symbol(o);182}183}184185ciMetadata* get_metadata(Metadata* o) {186if (o == NULL) {187return NULL;188} else {189return _factory->get_metadata(o);190}191}192193ciMetadata* cached_metadata(Metadata* o) {194return _factory->cached_metadata(o);195}196197ciInstance* get_instance(oop o) {198if (o == NULL) return NULL;199return get_object(o)->as_instance();200}201ciObjArrayKlass* get_obj_array_klass(Klass* o) {202if (o == NULL) return NULL;203return get_metadata(o)->as_obj_array_klass();204}205ciTypeArrayKlass* get_type_array_klass(Klass* o) {206if (o == NULL) return NULL;207return get_metadata(o)->as_type_array_klass();208}209ciKlass* get_klass(Klass* o) {210if (o == NULL) return NULL;211return get_metadata(o)->as_klass();212}213ciInstanceKlass* get_instance_klass(Klass* o) {214if (o == NULL) return NULL;215return get_metadata(o)->as_instance_klass();216}217ciMethod* get_method(Method* o) {218if (o == NULL) return NULL;219return get_metadata(o)->as_method();220}221ciMethodData* get_method_data(MethodData* o) {222if (o == NULL) return NULL;223return get_metadata(o)->as_method_data();224}225226ciMethod* get_method_from_handle(Method* method);227228ciInstance* get_or_create_exception(jobject& handle, Symbol* name);229230// Get a ciMethod representing either an unfound method or231// a method with an unloaded holder. Ensures uniqueness of232// the result.233ciMethod* get_unloaded_method(ciKlass* holder,234ciSymbol* name,235ciSymbol* signature,236ciInstanceKlass* accessor) {237ciInstanceKlass* declared_holder = get_instance_klass_for_declared_method_holder(holder);238return _factory->get_unloaded_method(declared_holder, name, signature, accessor);239}240241// Get a ciKlass representing an unloaded klass.242// Ensures uniqueness of the result.243ciKlass* get_unloaded_klass(ciKlass* accessing_klass,244ciSymbol* name) {245return _factory->get_unloaded_klass(accessing_klass, name, true);246}247248// Get a ciKlass representing an unloaded klass mirror.249// Result is not necessarily unique, but will be unloaded.250ciInstance* get_unloaded_klass_mirror(ciKlass* type) {251return _factory->get_unloaded_klass_mirror(type);252}253254// Get a ciInstance representing an unresolved method handle constant.255ciInstance* get_unloaded_method_handle_constant(ciKlass* holder,256ciSymbol* name,257ciSymbol* signature,258int ref_kind) {259return _factory->get_unloaded_method_handle_constant(holder, name, signature, ref_kind);260}261262// Get a ciInstance representing an unresolved method type constant.263ciInstance* get_unloaded_method_type_constant(ciSymbol* signature) {264return _factory->get_unloaded_method_type_constant(signature);265}266267// See if we already have an unloaded klass for the given name268// or return NULL if not.269ciKlass *check_get_unloaded_klass(ciKlass* accessing_klass, ciSymbol* name) {270return _factory->get_unloaded_klass(accessing_klass, name, false);271}272273// Get a ciReturnAddress corresponding to the given bci.274// Ensures uniqueness of the result.275ciReturnAddress* get_return_address(int bci) {276return _factory->get_return_address(bci);277}278279// Get a ciMethodData representing the methodData for a method280// with none.281ciMethodData* get_empty_methodData() {282return _factory->get_empty_methodData();283}284285// General utility : get a buffer of some required length.286// Used in symbol creation.287char* name_buffer(int req_len);288289// Is this thread currently in the VM state?290static bool is_in_vm();291292// Helper routine for determining the validity of a compilation with293// respect to method dependencies (e.g. concurrent class loading).294void validate_compile_task_dependencies(ciMethod* target);295public:296enum {297MethodCompilable,298MethodCompilable_not_at_tier,299MethodCompilable_never300};301302ciEnv(CompileTask* task);303// Used only during initialization of the ci304ciEnv(Arena* arena);305~ciEnv();306307OopRecorder* oop_recorder() { return _oop_recorder; }308void set_oop_recorder(OopRecorder* r) { _oop_recorder = r; }309310DebugInformationRecorder* debug_info() { return _debug_info; }311void set_debug_info(DebugInformationRecorder* i) { _debug_info = i; }312313Dependencies* dependencies() { return _dependencies; }314void set_dependencies(Dependencies* d) { _dependencies = d; }315316// This is true if the compilation is not going to produce code.317// (It is reasonable to retry failed compilations.)318bool failing() { return _failure_reason != NULL; }319320// Reason this compilation is failing, such as "too many basic blocks".321const char* failure_reason() { return _failure_reason; }322323// Return state of appropriate compilability324int compilable() { return _compilable; }325326const char* retry_message() const {327switch (_compilable) {328case ciEnv::MethodCompilable_not_at_tier:329return "retry at different tier";330case ciEnv::MethodCompilable_never:331return "not retryable";332case ciEnv::MethodCompilable:333return NULL;334default:335ShouldNotReachHere();336return NULL;337}338}339340bool break_at_compile() { return _break_at_compile; }341void set_break_at_compile(bool z) { _break_at_compile = z; }342343// Cache Jvmti state344bool cache_jvmti_state();345bool jvmti_state_changed() const;346bool should_retain_local_variables() const {347return _jvmti_can_access_local_variables || _jvmti_can_pop_frame;348}349bool jvmti_can_hotswap_or_post_breakpoint() const { return _jvmti_can_hotswap_or_post_breakpoint; }350bool jvmti_can_post_on_exceptions() const { return _jvmti_can_post_on_exceptions; }351bool jvmti_can_get_owned_monitor_info() const { return _jvmti_can_get_owned_monitor_info; }352bool jvmti_can_walk_any_space() const { return _jvmti_can_walk_any_space; }353354// Cache DTrace flags355void cache_dtrace_flags();356bool dtrace_extended_probes() const { return _dtrace_extended_probes; }357bool dtrace_method_probes() const { return _dtrace_method_probes; }358bool dtrace_alloc_probes() const { return _dtrace_alloc_probes; }359360// The compiler task which has created this env.361// May be useful to find out compile_id, comp_level, etc.362CompileTask* task() { return _task; }363364// Handy forwards to the task:365int comp_level(); // task()->comp_level()366uint compile_id(); // task()->compile_id()367368// Register the result of a compilation.369void register_method(ciMethod* target,370int entry_bci,371CodeOffsets* offsets,372int orig_pc_offset,373CodeBuffer* code_buffer,374int frame_words,375OopMapSet* oop_map_set,376ExceptionHandlerTable* handler_table,377ImplicitExceptionTable* inc_table,378AbstractCompiler* compiler,379bool has_unsafe_access,380bool has_wide_vectors,381RTMState rtm_state = NoRTM,382const GrowableArrayView<RuntimeStub*>& native_invokers = GrowableArrayView<RuntimeStub*>::EMPTY);383384385// Access to certain well known ciObjects.386#define VM_CLASS_FUNC(name, ignore_s) \387ciInstanceKlass* name() { \388return _##name;\389}390VM_CLASSES_DO(VM_CLASS_FUNC)391#undef VM_CLASS_FUNC392393ciInstance* NullPointerException_instance() {394assert(_NullPointerException_instance != NULL, "initialization problem");395return _NullPointerException_instance;396}397ciInstance* ArithmeticException_instance() {398assert(_ArithmeticException_instance != NULL, "initialization problem");399return _ArithmeticException_instance;400}401402// Lazy constructors:403ciInstance* ArrayIndexOutOfBoundsException_instance();404ciInstance* ArrayStoreException_instance();405ciInstance* ClassCastException_instance();406407ciInstance* the_null_string();408ciInstance* the_min_jint_string();409410static ciSymbol* unloaded_cisymbol() {411return _unloaded_cisymbol;412}413static ciObjArrayKlass* unloaded_ciobjarrayklass() {414return _unloaded_ciobjarrayklass;415}416static ciInstanceKlass* unloaded_ciinstance_klass() {417return _unloaded_ciinstance_klass;418}419ciInstance* unloaded_ciinstance();420421// Note: To find a class from its name string, use ciSymbol::make,422// but consider adding to vmSymbols.hpp instead.423424// converts the ciKlass* representing the holder of a method into a425// ciInstanceKlass*. This is needed since the holder of a method in426// the bytecodes could be an array type. Basically this converts427// array types into java/lang/Object and other types stay as they are.428static ciInstanceKlass* get_instance_klass_for_declared_method_holder(ciKlass* klass);429430// Access to the compile-lifetime allocation arena.431Arena* arena() { return _arena; }432433// What is the current compilation environment?434static ciEnv* current() { return CompilerThread::current()->env(); }435436// Overload with current thread argument437static ciEnv* current(CompilerThread *thread) { return thread->env(); }438439// Per-compiler data. (Used by C2 to publish the Compile* pointer.)440void* compiler_data() { return _compiler_data; }441void set_compiler_data(void* x) { _compiler_data = x; }442443// Notice that a method has been inlined in the current compile;444// used only for statistics.445void notice_inlined_method(ciMethod* method);446447// Total number of bytecodes in inlined methods in this compile448int num_inlined_bytecodes() const;449450// Output stream for logging compilation info.451CompileLog* log() { return _log; }452void set_log(CompileLog* log) { _log = log; }453454void record_failure(const char* reason); // Record failure and report later455void report_failure(const char* reason); // Report failure immediately456void record_method_not_compilable(const char* reason, bool all_tiers = false);457void record_out_of_memory_failure();458459// RedefineClasses support460void metadata_do(MetadataClosure* f) { _factory->metadata_do(f); }461462// Dump the compilation replay data for the ciEnv to the stream.463void dump_replay_data(int compile_id);464void dump_inline_data(int compile_id);465void dump_replay_data(outputStream* out);466void dump_replay_data_unsafe(outputStream* out);467void dump_compile_data(outputStream* out);468};469470#endif // SHARE_CI_CIENV_HPP471472473