Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/ci/ciEnv.hpp
32285 views
/*1* Copyright (c) 1999, 2013, 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_CI_CIENV_HPP25#define SHARE_VM_CI_CIENV_HPP2627#include "ci/ciClassList.hpp"28#include "ci/ciObjectFactory.hpp"29#include "classfile/systemDictionary.hpp"30#include "code/debugInfoRec.hpp"31#include "code/dependencies.hpp"32#include "code/exceptionHandlerTable.hpp"33#include "compiler/oopMap.hpp"34#include "runtime/thread.hpp"3536class CompileTask;3738// ciEnv39//40// This class is the top level broker for requests from the compiler41// to the VM.42class ciEnv : StackObj {43CI_PACKAGE_ACCESS_TO4445friend class CompileBroker;46friend class Dependencies; // for get_object, during logging4748private:49Arena* _arena; // Alias for _ciEnv_arena except in init_shared_objects()50Arena _ciEnv_arena;51int _system_dictionary_modification_counter;52ciObjectFactory* _factory;53OopRecorder* _oop_recorder;54DebugInformationRecorder* _debug_info;55Dependencies* _dependencies;56const char* _failure_reason;57int _compilable;58bool _break_at_compile;59int _num_inlined_bytecodes;60CompileTask* _task; // faster access to CompilerThread::task61CompileLog* _log; // faster access to CompilerThread::log62void* _compiler_data; // compiler-specific stuff, if any6364char* _name_buffer;65int _name_buffer_len;6667// Cache Jvmti state68bool _jvmti_can_hotswap_or_post_breakpoint;69bool _jvmti_can_access_local_variables;70bool _jvmti_can_post_on_exceptions;71bool _jvmti_can_pop_frame;7273// Cache DTrace flags74bool _dtrace_extended_probes;75bool _dtrace_monitor_probes;76bool _dtrace_method_probes;77bool _dtrace_alloc_probes;7879// Distinguished instances of certain ciObjects..80static ciObject* _null_object_instance;8182#define WK_KLASS_DECL(name, ignore_s, ignore_o) static ciInstanceKlass* _##name;83WK_KLASSES_DO(WK_KLASS_DECL)84#undef WK_KLASS_DECL8586static ciSymbol* _unloaded_cisymbol;87static ciInstanceKlass* _unloaded_ciinstance_klass;88static ciObjArrayKlass* _unloaded_ciobjarrayklass;8990static jobject _ArrayIndexOutOfBoundsException_handle;91static jobject _ArrayStoreException_handle;92static jobject _ClassCastException_handle;9394ciInstance* _NullPointerException_instance;95ciInstance* _ArithmeticException_instance;96ciInstance* _ArrayIndexOutOfBoundsException_instance;97ciInstance* _ArrayStoreException_instance;98ciInstance* _ClassCastException_instance;99100ciInstance* _the_null_string; // The Java string "null"101ciInstance* _the_min_jint_string; // The Java string "-2147483648"102103// Look up a klass by name from a particular class loader (the accessor's).104// If require_local, result must be defined in that class loader, or NULL.105// If !require_local, a result from remote class loader may be reported,106// if sufficient class loader constraints exist such that initiating107// a class loading request from the given loader is bound to return108// the class defined in the remote loader (or throw an error).109//110// Return an unloaded klass if !require_local and no class at all is found.111//112// The CI treats a klass as loaded if it is consistently defined in113// another loader, even if it hasn't yet been loaded in all loaders114// that could potentially see it via delegation.115ciKlass* get_klass_by_name(ciKlass* accessing_klass,116ciSymbol* klass_name,117bool require_local);118119// Constant pool access.120ciKlass* get_klass_by_index(constantPoolHandle cpool,121int klass_index,122bool& is_accessible,123ciInstanceKlass* loading_klass);124ciConstant get_constant_by_index(constantPoolHandle cpool,125int pool_index, int cache_index,126ciInstanceKlass* accessor);127ciField* get_field_by_index(ciInstanceKlass* loading_klass,128int field_index);129ciMethod* get_method_by_index(constantPoolHandle cpool,130int method_index, Bytecodes::Code bc,131ciInstanceKlass* loading_klass);132133// Implementation methods for loading and constant pool access.134ciKlass* get_klass_by_name_impl(ciKlass* accessing_klass,135constantPoolHandle cpool,136ciSymbol* klass_name,137bool require_local);138ciKlass* get_klass_by_index_impl(constantPoolHandle cpool,139int klass_index,140bool& is_accessible,141ciInstanceKlass* loading_klass);142ciConstant get_constant_by_index_impl(constantPoolHandle cpool,143int pool_index, int cache_index,144ciInstanceKlass* loading_klass);145ciField* get_field_by_index_impl(ciInstanceKlass* loading_klass,146int field_index);147ciMethod* get_method_by_index_impl(constantPoolHandle cpool,148int method_index, Bytecodes::Code bc,149ciInstanceKlass* loading_klass);150151// Helper methods152bool check_klass_accessibility(ciKlass* accessing_klass,153Klass* resolved_klass);154Method* lookup_method(InstanceKlass* accessor,155InstanceKlass* holder,156Symbol* name,157Symbol* sig,158Bytecodes::Code bc);159160// Get a ciObject from the object factory. Ensures uniqueness161// of ciObjects.162ciObject* get_object(oop o) {163if (o == NULL) {164return _null_object_instance;165} else {166return _factory->get(o);167}168}169170ciSymbol* get_symbol(Symbol* o) {171if (o == NULL) {172ShouldNotReachHere();173return NULL;174} else {175return _factory->get_symbol(o);176}177}178179ciMetadata* get_metadata(Metadata* o) {180if (o == NULL) {181return NULL;182} else {183return _factory->get_metadata(o);184}185}186187void ensure_metadata_alive(ciMetadata* m) {188_factory->ensure_metadata_alive(m);189}190191ciInstance* get_instance(oop o) {192if (o == NULL) return NULL;193return get_object(o)->as_instance();194}195ciObjArrayKlass* get_obj_array_klass(Klass* o) {196if (o == NULL) return NULL;197return get_metadata(o)->as_obj_array_klass();198}199ciTypeArrayKlass* get_type_array_klass(Klass* o) {200if (o == NULL) return NULL;201return get_metadata(o)->as_type_array_klass();202}203ciKlass* get_klass(Klass* o) {204if (o == NULL) return NULL;205return get_metadata(o)->as_klass();206}207ciInstanceKlass* get_instance_klass(Klass* o) {208if (o == NULL) return NULL;209return get_metadata(o)->as_instance_klass();210}211ciMethod* get_method(Method* o) {212if (o == NULL) return NULL;213return get_metadata(o)->as_method();214}215ciMethodData* get_method_data(MethodData* o) {216if (o == NULL) return NULL;217return get_metadata(o)->as_method_data();218}219220ciMethod* get_method_from_handle(Method* method);221222ciInstance* get_or_create_exception(jobject& handle, Symbol* name);223224// Get a ciMethod representing either an unfound method or225// a method with an unloaded holder. Ensures uniqueness of226// the result.227ciMethod* get_unloaded_method(ciInstanceKlass* holder,228ciSymbol* name,229ciSymbol* signature,230ciInstanceKlass* accessor) {231return _factory->get_unloaded_method(holder, name, signature, accessor);232}233234// Get a ciKlass representing an unloaded klass.235// Ensures uniqueness of the result.236ciKlass* get_unloaded_klass(ciKlass* accessing_klass,237ciSymbol* name) {238return _factory->get_unloaded_klass(accessing_klass, name, true);239}240241// Get a ciKlass representing an unloaded klass mirror.242// Result is not necessarily unique, but will be unloaded.243ciInstance* get_unloaded_klass_mirror(ciKlass* type) {244return _factory->get_unloaded_klass_mirror(type);245}246247// Get a ciInstance representing an unresolved method handle constant.248ciInstance* get_unloaded_method_handle_constant(ciKlass* holder,249ciSymbol* name,250ciSymbol* signature,251int ref_kind) {252return _factory->get_unloaded_method_handle_constant(holder, name, signature, ref_kind);253}254255// Get a ciInstance representing an unresolved method type constant.256ciInstance* get_unloaded_method_type_constant(ciSymbol* signature) {257return _factory->get_unloaded_method_type_constant(signature);258}259260// See if we already have an unloaded klass for the given name261// or return NULL if not.262ciKlass *check_get_unloaded_klass(ciKlass* accessing_klass, ciSymbol* name) {263return _factory->get_unloaded_klass(accessing_klass, name, false);264}265266// Get a ciReturnAddress corresponding to the given bci.267// Ensures uniqueness of the result.268ciReturnAddress* get_return_address(int bci) {269return _factory->get_return_address(bci);270}271272// Get a ciMethodData representing the methodData for a method273// with none.274ciMethodData* get_empty_methodData() {275return _factory->get_empty_methodData();276}277278// General utility : get a buffer of some required length.279// Used in symbol creation.280char* name_buffer(int req_len);281282// Is this thread currently in the VM state?283static bool is_in_vm();284285// Helper routine for determining the validity of a compilation with286// respect to method dependencies (e.g. concurrent class loading).287void validate_compile_task_dependencies(ciMethod* target);288289public:290enum {291MethodCompilable,292MethodCompilable_not_at_tier,293MethodCompilable_never294};295296ciEnv(CompileTask* task, int system_dictionary_modification_counter);297// Used only during initialization of the ci298ciEnv(Arena* arena);299~ciEnv();300301OopRecorder* oop_recorder() { return _oop_recorder; }302void set_oop_recorder(OopRecorder* r) { _oop_recorder = r; }303304DebugInformationRecorder* debug_info() { return _debug_info; }305void set_debug_info(DebugInformationRecorder* i) { _debug_info = i; }306307Dependencies* dependencies() { return _dependencies; }308void set_dependencies(Dependencies* d) { _dependencies = d; }309310// This is true if the compilation is not going to produce code.311// (It is reasonable to retry failed compilations.)312bool failing() { return _failure_reason != NULL; }313314// Reason this compilation is failing, such as "too many basic blocks".315const char* failure_reason() { return _failure_reason; }316317// Return state of appropriate compilability318int compilable() { return _compilable; }319320const char* retry_message() const {321switch (_compilable) {322case ciEnv::MethodCompilable_not_at_tier:323return "retry at different tier";324case ciEnv::MethodCompilable_never:325return "not retryable";326case ciEnv::MethodCompilable:327return NULL;328default:329ShouldNotReachHere();330return NULL;331}332}333334bool break_at_compile() { return _break_at_compile; }335void set_break_at_compile(bool z) { _break_at_compile = z; }336337// Cache Jvmti state338void cache_jvmti_state();339bool jvmti_state_changed() const;340bool should_retain_local_variables() const;341bool jvmti_can_hotswap_or_post_breakpoint() const { return _jvmti_can_hotswap_or_post_breakpoint; }342bool jvmti_can_post_on_exceptions() const { return _jvmti_can_post_on_exceptions; }343344// Cache DTrace flags345void cache_dtrace_flags();346bool dtrace_extended_probes() const { return _dtrace_extended_probes; }347bool dtrace_monitor_probes() const { return _dtrace_monitor_probes; }348bool dtrace_method_probes() const { return _dtrace_method_probes; }349bool dtrace_alloc_probes() const { return _dtrace_alloc_probes; }350351// The compiler task which has created this env.352// May be useful to find out compile_id, comp_level, etc.353CompileTask* task() { return _task; }354// Handy forwards to the task:355int comp_level(); // task()->comp_level()356uint compile_id(); // task()->compile_id()357358// Register the result of a compilation.359void register_method(ciMethod* target,360int entry_bci,361CodeOffsets* offsets,362int orig_pc_offset,363CodeBuffer* code_buffer,364int frame_words,365OopMapSet* oop_map_set,366ExceptionHandlerTable* handler_table,367ImplicitExceptionTable* inc_table,368AbstractCompiler* compiler,369int comp_level,370bool has_unsafe_access,371bool has_wide_vectors,372RTMState rtm_state = NoRTM);373374375// Access to certain well known ciObjects.376#define WK_KLASS_FUNC(name, ignore_s, ignore_o) \377ciInstanceKlass* name() { \378return _##name;\379}380WK_KLASSES_DO(WK_KLASS_FUNC)381#undef WK_KLASS_FUNC382383ciInstance* NullPointerException_instance() {384assert(_NullPointerException_instance != NULL, "initialization problem");385return _NullPointerException_instance;386}387ciInstance* ArithmeticException_instance() {388assert(_ArithmeticException_instance != NULL, "initialization problem");389return _ArithmeticException_instance;390}391392// Lazy constructors:393ciInstance* ArrayIndexOutOfBoundsException_instance();394ciInstance* ArrayStoreException_instance();395ciInstance* ClassCastException_instance();396397ciInstance* the_null_string();398ciInstance* the_min_jint_string();399400static ciSymbol* unloaded_cisymbol() {401return _unloaded_cisymbol;402}403static ciObjArrayKlass* unloaded_ciobjarrayklass() {404return _unloaded_ciobjarrayklass;405}406static ciInstanceKlass* unloaded_ciinstance_klass() {407return _unloaded_ciinstance_klass;408}409ciInstance* unloaded_ciinstance();410411ciKlass* find_system_klass(ciSymbol* klass_name);412// Note: To find a class from its name string, use ciSymbol::make,413// but consider adding to vmSymbols.hpp instead.414415// converts the ciKlass* representing the holder of a method into a416// ciInstanceKlass*. This is needed since the holder of a method in417// the bytecodes could be an array type. Basically this converts418// array types into java/lang/Object and other types stay as they are.419static ciInstanceKlass* get_instance_klass_for_declared_method_holder(ciKlass* klass);420421// Return the machine-level offset of o, which must be an element of a.422// This may be used to form constant-loading expressions in lieu of simpler encodings.423int array_element_offset_in_bytes(ciArray* a, ciObject* o);424425// Access to the compile-lifetime allocation arena.426Arena* arena() { return _arena; }427428// What is the current compilation environment?429static ciEnv* current() { return CompilerThread::current()->env(); }430431// Overload with current thread argument432static ciEnv* current(CompilerThread *thread) { return thread->env(); }433434// Per-compiler data. (Used by C2 to publish the Compile* pointer.)435void* compiler_data() { return _compiler_data; }436void set_compiler_data(void* x) { _compiler_data = x; }437438// Notice that a method has been inlined in the current compile;439// used only for statistics.440void notice_inlined_method(ciMethod* method);441442// Total number of bytecodes in inlined methods in this compile443int num_inlined_bytecodes() const;444445// Output stream for logging compilation info.446CompileLog* log() { return _log; }447void set_log(CompileLog* log) { _log = log; }448449// Check for changes to the system dictionary during compilation450bool system_dictionary_modification_counter_changed();451452void record_failure(const char* reason);453void record_method_not_compilable(const char* reason, bool all_tiers = true);454void record_out_of_memory_failure();455456// RedefineClasses support457void metadata_do(void f(Metadata*)) { _factory->metadata_do(f); }458459// Dump the compilation replay data for the ciEnv to the stream.460void dump_replay_data(int compile_id);461void dump_inline_data(int compile_id);462void dump_replay_data(outputStream* out);463void dump_replay_data_unsafe(outputStream* out);464void dump_compile_data(outputStream* out);465};466467#endif // SHARE_VM_CI_CIENV_HPP468469470