duke@435: /* mikael@6198: * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_CI_CIENV_HPP stefank@2314: #define SHARE_VM_CI_CIENV_HPP stefank@2314: stefank@2314: #include "ci/ciClassList.hpp" stefank@2314: #include "ci/ciObjectFactory.hpp" stefank@2314: #include "classfile/systemDictionary.hpp" stefank@2314: #include "code/debugInfoRec.hpp" stefank@2314: #include "code/dependencies.hpp" stefank@2314: #include "code/exceptionHandlerTable.hpp" stefank@2314: #include "compiler/oopMap.hpp" stefank@2314: #include "runtime/thread.hpp" stefank@2314: duke@435: class CompileTask; duke@435: duke@435: // ciEnv duke@435: // duke@435: // This class is the top level broker for requests from the compiler duke@435: // to the VM. duke@435: class ciEnv : StackObj { duke@435: CI_PACKAGE_ACCESS_TO duke@435: duke@435: friend class CompileBroker; duke@435: friend class Dependencies; // for get_object, during logging duke@435: duke@435: private: duke@435: Arena* _arena; // Alias for _ciEnv_arena except in init_shared_objects() duke@435: Arena _ciEnv_arena; duke@435: int _system_dictionary_modification_counter; duke@435: ciObjectFactory* _factory; duke@435: OopRecorder* _oop_recorder; duke@435: DebugInformationRecorder* _debug_info; duke@435: Dependencies* _dependencies; duke@435: const char* _failure_reason; duke@435: int _compilable; duke@435: bool _break_at_compile; duke@435: int _num_inlined_bytecodes; duke@435: CompileTask* _task; // faster access to CompilerThread::task duke@435: CompileLog* _log; // faster access to CompilerThread::log duke@435: void* _compiler_data; // compiler-specific stuff, if any duke@435: duke@435: char* _name_buffer; duke@435: int _name_buffer_len; duke@435: kvn@1215: // Cache Jvmti state kvn@1215: bool _jvmti_can_hotswap_or_post_breakpoint; kvn@1215: bool _jvmti_can_access_local_variables; dcubed@1648: bool _jvmti_can_post_on_exceptions; kvn@1215: kvn@1215: // Cache DTrace flags kvn@1215: bool _dtrace_extended_probes; kvn@1215: bool _dtrace_monitor_probes; kvn@1215: bool _dtrace_method_probes; kvn@1215: bool _dtrace_alloc_probes; kvn@1215: duke@435: // Distinguished instances of certain ciObjects.. duke@435: static ciObject* _null_object_instance; duke@435: never@1577: #define WK_KLASS_DECL(name, ignore_s, ignore_o) static ciInstanceKlass* _##name; never@1577: WK_KLASSES_DO(WK_KLASS_DECL) never@1577: #undef WK_KLASS_DECL duke@435: duke@435: static ciSymbol* _unloaded_cisymbol; duke@435: static ciInstanceKlass* _unloaded_ciinstance_klass; duke@435: static ciObjArrayKlass* _unloaded_ciobjarrayklass; duke@435: duke@435: static jobject _ArrayIndexOutOfBoundsException_handle; duke@435: static jobject _ArrayStoreException_handle; duke@435: static jobject _ClassCastException_handle; duke@435: duke@435: ciInstance* _NullPointerException_instance; duke@435: ciInstance* _ArithmeticException_instance; duke@435: ciInstance* _ArrayIndexOutOfBoundsException_instance; duke@435: ciInstance* _ArrayStoreException_instance; duke@435: ciInstance* _ClassCastException_instance; duke@435: never@1515: ciInstance* _the_null_string; // The Java string "null" never@1515: ciInstance* _the_min_jint_string; // The Java string "-2147483648" never@1515: duke@435: // Look up a klass by name from a particular class loader (the accessor's). duke@435: // If require_local, result must be defined in that class loader, or NULL. duke@435: // If !require_local, a result from remote class loader may be reported, duke@435: // if sufficient class loader constraints exist such that initiating duke@435: // a class loading request from the given loader is bound to return duke@435: // the class defined in the remote loader (or throw an error). duke@435: // duke@435: // Return an unloaded klass if !require_local and no class at all is found. duke@435: // duke@435: // The CI treats a klass as loaded if it is consistently defined in duke@435: // another loader, even if it hasn't yet been loaded in all loaders duke@435: // that could potentially see it via delegation. duke@435: ciKlass* get_klass_by_name(ciKlass* accessing_klass, duke@435: ciSymbol* klass_name, duke@435: bool require_local); duke@435: duke@435: // Constant pool access. twisti@1573: ciKlass* get_klass_by_index(constantPoolHandle cpool, duke@435: int klass_index, twisti@1573: bool& is_accessible, twisti@1573: ciInstanceKlass* loading_klass); twisti@1573: ciConstant get_constant_by_index(constantPoolHandle cpool, jrose@1957: int pool_index, int cache_index, twisti@1573: ciInstanceKlass* accessor); duke@435: ciField* get_field_by_index(ciInstanceKlass* loading_klass, duke@435: int field_index); twisti@1573: ciMethod* get_method_by_index(constantPoolHandle cpool, twisti@1573: int method_index, Bytecodes::Code bc, twisti@1573: ciInstanceKlass* loading_klass); duke@435: duke@435: // Implementation methods for loading and constant pool access. duke@435: ciKlass* get_klass_by_name_impl(ciKlass* accessing_klass, jrose@2982: constantPoolHandle cpool, duke@435: ciSymbol* klass_name, duke@435: bool require_local); twisti@1573: ciKlass* get_klass_by_index_impl(constantPoolHandle cpool, duke@435: int klass_index, twisti@1573: bool& is_accessible, twisti@1573: ciInstanceKlass* loading_klass); twisti@1573: ciConstant get_constant_by_index_impl(constantPoolHandle cpool, jrose@1957: int pool_index, int cache_index, twisti@1573: ciInstanceKlass* loading_klass); duke@435: ciField* get_field_by_index_impl(ciInstanceKlass* loading_klass, duke@435: int field_index); twisti@1573: ciMethod* get_method_by_index_impl(constantPoolHandle cpool, twisti@1573: int method_index, Bytecodes::Code bc, twisti@1573: ciInstanceKlass* loading_klass); duke@435: duke@435: // Helper methods duke@435: bool check_klass_accessibility(ciKlass* accessing_klass, coleenp@4037: Klass* resolved_klass); coleenp@4037: Method* lookup_method(InstanceKlass* accessor, coleenp@4037: InstanceKlass* holder, coleenp@2497: Symbol* name, coleenp@2497: Symbol* sig, duke@435: Bytecodes::Code bc); duke@435: duke@435: // Get a ciObject from the object factory. Ensures uniqueness duke@435: // of ciObjects. duke@435: ciObject* get_object(oop o) { duke@435: if (o == NULL) { duke@435: return _null_object_instance; duke@435: } else { duke@435: return _factory->get(o); duke@435: } duke@435: } duke@435: coleenp@2497: ciSymbol* get_symbol(Symbol* o) { coleenp@2497: if (o == NULL) { coleenp@2497: ShouldNotReachHere(); coleenp@2497: return NULL; coleenp@2497: } else { coleenp@2497: return _factory->get_symbol(o); coleenp@2497: } coleenp@2497: } coleenp@2497: coleenp@4037: ciMetadata* get_metadata(Metadata* o) { coleenp@4037: if (o == NULL) { coleenp@4037: return NULL; coleenp@4037: } else { coleenp@4037: return _factory->get_metadata(o); coleenp@4037: } coleenp@4037: } coleenp@4037: stefank@6992: void ensure_metadata_alive(ciMetadata* m) { stefank@6992: _factory->ensure_metadata_alive(m); stefank@6992: } stefank@6992: coleenp@4037: ciInstance* get_instance(oop o) { coleenp@4037: if (o == NULL) return NULL; coleenp@4037: return get_object(o)->as_instance(); coleenp@4037: } coleenp@4037: ciObjArrayKlass* get_obj_array_klass(Klass* o) { coleenp@4037: if (o == NULL) return NULL; coleenp@4037: return get_metadata(o)->as_obj_array_klass(); coleenp@4037: } coleenp@4037: ciTypeArrayKlass* get_type_array_klass(Klass* o) { coleenp@4037: if (o == NULL) return NULL; coleenp@4037: return get_metadata(o)->as_type_array_klass(); coleenp@4037: } coleenp@4037: ciKlass* get_klass(Klass* o) { coleenp@4037: if (o == NULL) return NULL; coleenp@4037: return get_metadata(o)->as_klass(); coleenp@4037: } coleenp@4037: ciInstanceKlass* get_instance_klass(Klass* o) { coleenp@4037: if (o == NULL) return NULL; coleenp@4037: return get_metadata(o)->as_instance_klass(); coleenp@4037: } coleenp@4037: ciMethod* get_method(Method* o) { coleenp@4037: if (o == NULL) return NULL; coleenp@4037: return get_metadata(o)->as_method(); coleenp@4037: } coleenp@4037: ciMethodData* get_method_data(MethodData* o) { coleenp@4037: if (o == NULL) return NULL; coleenp@4037: return get_metadata(o)->as_method_data(); coleenp@4037: } coleenp@4037: coleenp@4037: ciMethod* get_method_from_handle(Method* method); duke@435: coleenp@2497: ciInstance* get_or_create_exception(jobject& handle, Symbol* name); duke@435: duke@435: // Get a ciMethod representing either an unfound method or duke@435: // a method with an unloaded holder. Ensures uniqueness of duke@435: // the result. duke@435: ciMethod* get_unloaded_method(ciInstanceKlass* holder, duke@435: ciSymbol* name, twisti@3197: ciSymbol* signature, twisti@3197: ciInstanceKlass* accessor) { twisti@3197: return _factory->get_unloaded_method(holder, name, signature, accessor); duke@435: } duke@435: duke@435: // Get a ciKlass representing an unloaded klass. duke@435: // Ensures uniqueness of the result. twisti@3197: ciKlass* get_unloaded_klass(ciKlass* accessing_klass, duke@435: ciSymbol* name) { duke@435: return _factory->get_unloaded_klass(accessing_klass, name, true); duke@435: } duke@435: jrose@1957: // Get a ciKlass representing an unloaded klass mirror. jrose@1957: // Result is not necessarily unique, but will be unloaded. jrose@1957: ciInstance* get_unloaded_klass_mirror(ciKlass* type) { jrose@1957: return _factory->get_unloaded_klass_mirror(type); jrose@1957: } jrose@1957: jrose@1957: // Get a ciInstance representing an unresolved method handle constant. jrose@1957: ciInstance* get_unloaded_method_handle_constant(ciKlass* holder, jrose@1957: ciSymbol* name, jrose@1957: ciSymbol* signature, jrose@1957: int ref_kind) { jrose@1957: return _factory->get_unloaded_method_handle_constant(holder, name, signature, ref_kind); jrose@1957: } jrose@1957: jrose@1957: // Get a ciInstance representing an unresolved method type constant. jrose@1957: ciInstance* get_unloaded_method_type_constant(ciSymbol* signature) { jrose@1957: return _factory->get_unloaded_method_type_constant(signature); jrose@1957: } jrose@1957: duke@435: // See if we already have an unloaded klass for the given name duke@435: // or return NULL if not. twisti@3197: ciKlass *check_get_unloaded_klass(ciKlass* accessing_klass, ciSymbol* name) { duke@435: return _factory->get_unloaded_klass(accessing_klass, name, false); duke@435: } duke@435: duke@435: // Get a ciReturnAddress corresponding to the given bci. duke@435: // Ensures uniqueness of the result. duke@435: ciReturnAddress* get_return_address(int bci) { duke@435: return _factory->get_return_address(bci); duke@435: } duke@435: duke@435: // Get a ciMethodData representing the methodData for a method duke@435: // with none. duke@435: ciMethodData* get_empty_methodData() { duke@435: return _factory->get_empty_methodData(); duke@435: } duke@435: duke@435: // General utility : get a buffer of some required length. duke@435: // Used in symbol creation. duke@435: char* name_buffer(int req_len); duke@435: duke@435: // Is this thread currently in the VM state? duke@435: static bool is_in_vm(); duke@435: twisti@3094: // Helper routine for determining the validity of a compilation with twisti@3094: // respect to method dependencies (e.g. concurrent class loading). twisti@3094: void validate_compile_task_dependencies(ciMethod* target); duke@435: duke@435: public: duke@435: enum { duke@435: MethodCompilable, duke@435: MethodCompilable_not_at_tier, duke@435: MethodCompilable_never duke@435: }; duke@435: duke@435: ciEnv(CompileTask* task, int system_dictionary_modification_counter); duke@435: // Used only during initialization of the ci duke@435: ciEnv(Arena* arena); duke@435: ~ciEnv(); duke@435: duke@435: OopRecorder* oop_recorder() { return _oop_recorder; } duke@435: void set_oop_recorder(OopRecorder* r) { _oop_recorder = r; } duke@435: duke@435: DebugInformationRecorder* debug_info() { return _debug_info; } duke@435: void set_debug_info(DebugInformationRecorder* i) { _debug_info = i; } duke@435: duke@435: Dependencies* dependencies() { return _dependencies; } duke@435: void set_dependencies(Dependencies* d) { _dependencies = d; } duke@435: duke@435: // This is true if the compilation is not going to produce code. duke@435: // (It is reasonable to retry failed compilations.) duke@435: bool failing() { return _failure_reason != NULL; } duke@435: duke@435: // Reason this compilation is failing, such as "too many basic blocks". duke@435: const char* failure_reason() { return _failure_reason; } duke@435: duke@435: // Return state of appropriate compilability duke@435: int compilable() { return _compilable; } duke@435: never@3499: const char* retry_message() const { never@3499: switch (_compilable) { never@3499: case ciEnv::MethodCompilable_not_at_tier: never@3499: return "retry at different tier"; never@3499: case ciEnv::MethodCompilable_never: never@3499: return "not retryable"; never@3499: case ciEnv::MethodCompilable: never@3499: return NULL; never@3499: default: never@3499: ShouldNotReachHere(); never@3499: return NULL; never@3499: } never@3499: } never@3499: duke@435: bool break_at_compile() { return _break_at_compile; } duke@435: void set_break_at_compile(bool z) { _break_at_compile = z; } duke@435: kvn@1215: // Cache Jvmti state kvn@1215: void cache_jvmti_state(); kvn@1215: bool jvmti_can_hotswap_or_post_breakpoint() const { return _jvmti_can_hotswap_or_post_breakpoint; } kvn@1215: bool jvmti_can_access_local_variables() const { return _jvmti_can_access_local_variables; } dcubed@1648: bool jvmti_can_post_on_exceptions() const { return _jvmti_can_post_on_exceptions; } kvn@1215: kvn@1215: // Cache DTrace flags kvn@1215: void cache_dtrace_flags(); kvn@1215: bool dtrace_extended_probes() const { return _dtrace_extended_probes; } kvn@1215: bool dtrace_monitor_probes() const { return _dtrace_monitor_probes; } kvn@1215: bool dtrace_method_probes() const { return _dtrace_method_probes; } kvn@1215: bool dtrace_alloc_probes() const { return _dtrace_alloc_probes; } kvn@1215: duke@435: // The compiler task which has created this env. duke@435: // May be useful to find out compile_id, comp_level, etc. duke@435: CompileTask* task() { return _task; } duke@435: // Handy forwards to the task: duke@435: int comp_level(); // task()->comp_level() duke@435: uint compile_id(); // task()->compile_id() duke@435: duke@435: // Register the result of a compilation. duke@435: void register_method(ciMethod* target, duke@435: int entry_bci, duke@435: CodeOffsets* offsets, duke@435: int orig_pc_offset, duke@435: CodeBuffer* code_buffer, duke@435: int frame_words, duke@435: OopMapSet* oop_map_set, duke@435: ExceptionHandlerTable* handler_table, duke@435: ImplicitExceptionTable* inc_table, duke@435: AbstractCompiler* compiler, duke@435: int comp_level, kvn@4103: bool has_unsafe_access, kvn@6429: bool has_wide_vectors, kvn@6429: RTMState rtm_state = NoRTM); duke@435: duke@435: duke@435: // Access to certain well known ciObjects. never@1577: #define WK_KLASS_FUNC(name, ignore_s, ignore_o) \ never@1577: ciInstanceKlass* name() { \ never@1577: return _##name;\ duke@435: } never@1577: WK_KLASSES_DO(WK_KLASS_FUNC) never@1577: #undef WK_KLASS_FUNC never@1577: duke@435: ciInstance* NullPointerException_instance() { duke@435: assert(_NullPointerException_instance != NULL, "initialization problem"); duke@435: return _NullPointerException_instance; duke@435: } duke@435: ciInstance* ArithmeticException_instance() { duke@435: assert(_ArithmeticException_instance != NULL, "initialization problem"); duke@435: return _ArithmeticException_instance; duke@435: } duke@435: duke@435: // Lazy constructors: duke@435: ciInstance* ArrayIndexOutOfBoundsException_instance(); duke@435: ciInstance* ArrayStoreException_instance(); duke@435: ciInstance* ClassCastException_instance(); duke@435: never@1515: ciInstance* the_null_string(); never@1515: ciInstance* the_min_jint_string(); never@1515: duke@435: static ciSymbol* unloaded_cisymbol() { duke@435: return _unloaded_cisymbol; duke@435: } duke@435: static ciObjArrayKlass* unloaded_ciobjarrayklass() { duke@435: return _unloaded_ciobjarrayklass; duke@435: } duke@435: static ciInstanceKlass* unloaded_ciinstance_klass() { duke@435: return _unloaded_ciinstance_klass; duke@435: } roland@5628: ciInstance* unloaded_ciinstance(); duke@435: duke@435: ciKlass* find_system_klass(ciSymbol* klass_name); duke@435: // Note: To find a class from its name string, use ciSymbol::make, duke@435: // but consider adding to vmSymbols.hpp instead. duke@435: duke@435: // converts the ciKlass* representing the holder of a method into a duke@435: // ciInstanceKlass*. This is needed since the holder of a method in duke@435: // the bytecodes could be an array type. Basically this converts duke@435: // array types into java/lang/Object and other types stay as they are. duke@435: static ciInstanceKlass* get_instance_klass_for_declared_method_holder(ciKlass* klass); duke@435: duke@435: // Return the machine-level offset of o, which must be an element of a. duke@435: // This may be used to form constant-loading expressions in lieu of simpler encodings. duke@435: int array_element_offset_in_bytes(ciArray* a, ciObject* o); duke@435: duke@435: // Access to the compile-lifetime allocation arena. duke@435: Arena* arena() { return _arena; } duke@435: duke@435: // What is the current compilation environment? duke@435: static ciEnv* current() { return CompilerThread::current()->env(); } duke@435: duke@435: // Overload with current thread argument duke@435: static ciEnv* current(CompilerThread *thread) { return thread->env(); } duke@435: duke@435: // Per-compiler data. (Used by C2 to publish the Compile* pointer.) duke@435: void* compiler_data() { return _compiler_data; } duke@435: void set_compiler_data(void* x) { _compiler_data = x; } duke@435: duke@435: // Notice that a method has been inlined in the current compile; duke@435: // used only for statistics. duke@435: void notice_inlined_method(ciMethod* method); duke@435: duke@435: // Total number of bytecodes in inlined methods in this compile duke@435: int num_inlined_bytecodes() const; duke@435: duke@435: // Output stream for logging compilation info. duke@435: CompileLog* log() { return _log; } duke@435: void set_log(CompileLog* log) { _log = log; } duke@435: duke@435: // Check for changes to the system dictionary during compilation duke@435: bool system_dictionary_modification_counter_changed(); duke@435: duke@435: void record_failure(const char* reason); duke@435: void record_method_not_compilable(const char* reason, bool all_tiers = true); duke@435: void record_out_of_memory_failure(); coleenp@4037: coleenp@4037: // RedefineClasses support coleenp@4037: void metadata_do(void f(Metadata*)) { _factory->metadata_do(f); } minqi@4267: minqi@4267: // Dump the compilation replay data for the ciEnv to the stream. kvn@6217: void dump_replay_data(int compile_id); kvn@6217: void dump_inline_data(int compile_id); minqi@4267: void dump_replay_data(outputStream* out); vlivanov@5904: void dump_replay_data_unsafe(outputStream* out); kvn@6217: void dump_compile_data(outputStream* out); duke@435: }; stefank@2314: stefank@2314: #endif // SHARE_VM_CI_CIENV_HPP