duke@435: /* dcubed@1648: * Copyright 1999-2010 Sun Microsystems, Inc. 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: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: 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: static ciMethodKlass* _method_klass_instance; duke@435: static ciSymbolKlass* _symbol_klass_instance; duke@435: static ciKlassKlass* _klass_klass_instance; duke@435: static ciInstanceKlassKlass* _instance_klass_klass_instance; duke@435: static ciTypeArrayKlassKlass* _type_array_klass_klass_instance; duke@435: static ciObjArrayKlassKlass* _obj_array_klass_klass_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, twisti@1573: int constant_index, twisti@1573: ciInstanceKlass* accessor); duke@435: bool is_unresolved_string(ciInstanceKlass* loading_klass, duke@435: int constant_index) const; duke@435: bool is_unresolved_klass(ciInstanceKlass* loading_klass, duke@435: int constant_index) const; 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, 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, twisti@1573: int constant_index, twisti@1573: ciInstanceKlass* loading_klass); duke@435: bool is_unresolved_string_impl (instanceKlass* loading_klass, duke@435: int constant_index) const; duke@435: bool is_unresolved_klass_impl (instanceKlass* loading_klass, duke@435: int constant_index) const; 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); twisti@1573: ciMethod* get_fake_invokedynamic_method_impl(constantPoolHandle cpool, twisti@1572: int index, Bytecodes::Code bc); duke@435: duke@435: // Helper methods duke@435: bool check_klass_accessibility(ciKlass* accessing_klass, duke@435: klassOop resolved_klassOop); duke@435: methodOop lookup_method(instanceKlass* accessor, duke@435: instanceKlass* holder, duke@435: symbolOop name, duke@435: symbolOop 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: duke@435: ciMethod* get_method_from_handle(jobject method); duke@435: duke@435: ciInstance* get_or_create_exception(jobject& handle, symbolHandle 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, duke@435: ciSymbol* signature) { duke@435: return _factory->get_unloaded_method(holder, name, signature); duke@435: } duke@435: duke@435: // Get a ciKlass representing an unloaded klass. duke@435: // Ensures uniqueness of the result. duke@435: 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: duke@435: // See if we already have an unloaded klass for the given name duke@435: // or return NULL if not. duke@435: 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: duke@435: // Helper routine for determining the validity of a compilation duke@435: // with respect to concurrent class loading. duke@435: void check_for_system_dictionary_modification(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: 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, duke@435: bool has_debug_info = true, duke@435: bool has_unsafe_access = false); 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: } 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: // Use this to make a holder for non-perm compile time constants. jrose@1424: // The resulting array is guaranteed to satisfy "can_be_constant". jrose@1424: ciArray* make_system_array(GrowableArray* objects); 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(); duke@435: };