duke@435: /* coleenp@4643: * 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: #include "precompiled.hpp" stefank@2314: #include "ci/ciConstant.hpp" stefank@2314: #include "ci/ciEnv.hpp" stefank@2314: #include "ci/ciField.hpp" stefank@2314: #include "ci/ciInstance.hpp" stefank@2314: #include "ci/ciInstanceKlass.hpp" stefank@2314: #include "ci/ciMethod.hpp" stefank@2314: #include "ci/ciNullObject.hpp" minqi@4267: #include "ci/ciReplay.hpp" stefank@2314: #include "ci/ciUtilities.hpp" stefank@2314: #include "classfile/systemDictionary.hpp" stefank@2314: #include "classfile/vmSymbols.hpp" stefank@2314: #include "code/scopeDesc.hpp" stefank@2314: #include "compiler/compileBroker.hpp" stefank@2314: #include "compiler/compileLog.hpp" stefank@2314: #include "compiler/compilerOracle.hpp" stefank@2314: #include "gc_interface/collectedHeap.inline.hpp" stefank@2314: #include "interpreter/linkResolver.hpp" stefank@2314: #include "memory/allocation.inline.hpp" stefank@2314: #include "memory/oopFactory.hpp" stefank@2314: #include "memory/universe.inline.hpp" coleenp@4037: #include "oops/methodData.hpp" stefank@2314: #include "oops/objArrayKlass.hpp" stefank@2314: #include "oops/oop.inline.hpp" stefank@2314: #include "oops/oop.inline2.hpp" stefank@2314: #include "prims/jvmtiExport.hpp" stefank@2314: #include "runtime/init.hpp" stefank@2314: #include "runtime/reflection.hpp" stefank@2314: #include "runtime/sharedRuntime.hpp" stefank@2314: #include "utilities/dtrace.hpp" jprovino@4542: #include "utilities/macros.hpp" stefank@2314: #ifdef COMPILER1 stefank@2314: #include "c1/c1_Runtime1.hpp" stefank@2314: #endif stefank@2314: #ifdef COMPILER2 stefank@2314: #include "opto/runtime.hpp" stefank@2314: #endif 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: duke@435: ciObject* ciEnv::_null_object_instance; duke@435: never@1577: #define WK_KLASS_DEFN(name, ignore_s, ignore_o) ciInstanceKlass* ciEnv::_##name = NULL; never@1577: WK_KLASSES_DO(WK_KLASS_DEFN) never@1577: #undef WK_KLASS_DEFN duke@435: duke@435: ciSymbol* ciEnv::_unloaded_cisymbol = NULL; duke@435: ciInstanceKlass* ciEnv::_unloaded_ciinstance_klass = NULL; duke@435: ciObjArrayKlass* ciEnv::_unloaded_ciobjarrayklass = NULL; duke@435: duke@435: jobject ciEnv::_ArrayIndexOutOfBoundsException_handle = NULL; duke@435: jobject ciEnv::_ArrayStoreException_handle = NULL; duke@435: jobject ciEnv::_ClassCastException_handle = NULL; duke@435: duke@435: #ifndef PRODUCT duke@435: static bool firstEnv = true; duke@435: #endif /* PRODUCT */ duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciEnv::ciEnv duke@435: ciEnv::ciEnv(CompileTask* task, int system_dictionary_modification_counter) { duke@435: VM_ENTRY_MARK; duke@435: duke@435: // Set up ciEnv::current immediately, for the sake of ciObjectFactory, etc. duke@435: thread->set_env(this); duke@435: assert(ciEnv::current() == this, "sanity"); duke@435: duke@435: _oop_recorder = NULL; duke@435: _debug_info = NULL; duke@435: _dependencies = NULL; duke@435: _failure_reason = NULL; duke@435: _compilable = MethodCompilable; duke@435: _break_at_compile = false; duke@435: _compiler_data = NULL; duke@435: #ifndef PRODUCT duke@435: assert(!firstEnv, "not initialized properly"); duke@435: #endif /* !PRODUCT */ duke@435: duke@435: _system_dictionary_modification_counter = system_dictionary_modification_counter; duke@435: _num_inlined_bytecodes = 0; duke@435: assert(task == NULL || thread->task() == task, "sanity"); duke@435: _task = task; duke@435: _log = NULL; duke@435: duke@435: // Temporary buffer for creating symbols and such. duke@435: _name_buffer = NULL; duke@435: _name_buffer_len = 0; duke@435: duke@435: _arena = &_ciEnv_arena; duke@435: _factory = new (_arena) ciObjectFactory(_arena, 128); duke@435: duke@435: // Preload commonly referenced system ciObjects. duke@435: duke@435: // During VM initialization, these instances have not yet been created. duke@435: // Assertions ensure that these instances are not accessed before duke@435: // their initialization. duke@435: duke@435: assert(Universe::is_fully_initialized(), "should be complete"); duke@435: duke@435: oop o = Universe::null_ptr_exception_instance(); duke@435: assert(o != NULL, "should have been initialized"); duke@435: _NullPointerException_instance = get_object(o)->as_instance(); duke@435: o = Universe::arithmetic_exception_instance(); duke@435: assert(o != NULL, "should have been initialized"); duke@435: _ArithmeticException_instance = get_object(o)->as_instance(); duke@435: duke@435: _ArrayIndexOutOfBoundsException_instance = NULL; duke@435: _ArrayStoreException_instance = NULL; duke@435: _ClassCastException_instance = NULL; never@1515: _the_null_string = NULL; never@1515: _the_min_jint_string = NULL; duke@435: } duke@435: duke@435: ciEnv::ciEnv(Arena* arena) { duke@435: ASSERT_IN_VM; duke@435: duke@435: // Set up ciEnv::current immediately, for the sake of ciObjectFactory, etc. duke@435: CompilerThread* current_thread = CompilerThread::current(); duke@435: assert(current_thread->env() == NULL, "must be"); duke@435: current_thread->set_env(this); duke@435: assert(ciEnv::current() == this, "sanity"); duke@435: duke@435: _oop_recorder = NULL; duke@435: _debug_info = NULL; duke@435: _dependencies = NULL; duke@435: _failure_reason = NULL; duke@435: _compilable = MethodCompilable_never; duke@435: _break_at_compile = false; duke@435: _compiler_data = NULL; duke@435: #ifndef PRODUCT duke@435: assert(firstEnv, "must be first"); duke@435: firstEnv = false; duke@435: #endif /* !PRODUCT */ duke@435: duke@435: _system_dictionary_modification_counter = 0; duke@435: _num_inlined_bytecodes = 0; duke@435: _task = NULL; duke@435: _log = NULL; duke@435: duke@435: // Temporary buffer for creating symbols and such. duke@435: _name_buffer = NULL; duke@435: _name_buffer_len = 0; duke@435: duke@435: _arena = arena; duke@435: _factory = new (_arena) ciObjectFactory(_arena, 128); duke@435: duke@435: // Preload commonly referenced system ciObjects. duke@435: duke@435: // During VM initialization, these instances have not yet been created. duke@435: // Assertions ensure that these instances are not accessed before duke@435: // their initialization. duke@435: duke@435: assert(Universe::is_fully_initialized(), "must be"); duke@435: coleenp@4037: _NullPointerException_instance = NULL; coleenp@4037: _ArithmeticException_instance = NULL; duke@435: _ArrayIndexOutOfBoundsException_instance = NULL; duke@435: _ArrayStoreException_instance = NULL; duke@435: _ClassCastException_instance = NULL; never@1515: _the_null_string = NULL; never@1515: _the_min_jint_string = NULL; duke@435: } duke@435: duke@435: ciEnv::~ciEnv() { duke@435: CompilerThread* current_thread = CompilerThread::current(); coleenp@2497: _factory->remove_symbols(); coleenp@4037: // Need safepoint to clear the env on the thread. RedefineClasses might coleenp@4037: // be reading it. coleenp@4037: GUARDED_VM_ENTRY(current_thread->set_env(NULL);) duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ kvn@1215: // Cache Jvmti state kvn@1215: void ciEnv::cache_jvmti_state() { kvn@1215: VM_ENTRY_MARK; kvn@1215: // Get Jvmti capabilities under lock to get consistant values. kvn@1215: MutexLocker mu(JvmtiThreadState_lock); kvn@1215: _jvmti_can_hotswap_or_post_breakpoint = JvmtiExport::can_hotswap_or_post_breakpoint(); kvn@1215: _jvmti_can_access_local_variables = JvmtiExport::can_access_local_variables(); dcubed@1648: _jvmti_can_post_on_exceptions = JvmtiExport::can_post_on_exceptions(); kvn@1215: } kvn@1215: kvn@1215: // ------------------------------------------------------------------ kvn@1215: // Cache DTrace flags kvn@1215: void ciEnv::cache_dtrace_flags() { kvn@1215: // Need lock? kvn@1215: _dtrace_extended_probes = ExtendedDTraceProbes; kvn@1215: if (_dtrace_extended_probes) { kvn@1215: _dtrace_monitor_probes = true; kvn@1215: _dtrace_method_probes = true; kvn@1215: _dtrace_alloc_probes = true; kvn@1215: } else { kvn@1215: _dtrace_monitor_probes = DTraceMonitorProbes; kvn@1215: _dtrace_method_probes = DTraceMethodProbes; kvn@1215: _dtrace_alloc_probes = DTraceAllocProbes; kvn@1215: } kvn@1215: } kvn@1215: kvn@1215: // ------------------------------------------------------------------ duke@435: // helper for lazy exception creation coleenp@2497: ciInstance* ciEnv::get_or_create_exception(jobject& handle, Symbol* name) { duke@435: VM_ENTRY_MARK; duke@435: if (handle == NULL) { duke@435: // Cf. universe.cpp, creation of Universe::_null_ptr_exception_instance. coleenp@4037: Klass* k = SystemDictionary::find(name, Handle(), Handle(), THREAD); duke@435: jobject objh = NULL; duke@435: if (!HAS_PENDING_EXCEPTION && k != NULL) { coleenp@4037: oop obj = InstanceKlass::cast(k)->allocate_instance(THREAD); duke@435: if (!HAS_PENDING_EXCEPTION) duke@435: objh = JNIHandles::make_global(obj); duke@435: } duke@435: if (HAS_PENDING_EXCEPTION) { duke@435: CLEAR_PENDING_EXCEPTION; duke@435: } else { duke@435: handle = objh; duke@435: } duke@435: } duke@435: oop obj = JNIHandles::resolve(handle); duke@435: return obj == NULL? NULL: get_object(obj)->as_instance(); duke@435: } duke@435: duke@435: ciInstance* ciEnv::ArrayIndexOutOfBoundsException_instance() { duke@435: if (_ArrayIndexOutOfBoundsException_instance == NULL) { duke@435: _ArrayIndexOutOfBoundsException_instance duke@435: = get_or_create_exception(_ArrayIndexOutOfBoundsException_handle, coleenp@2497: vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); duke@435: } duke@435: return _ArrayIndexOutOfBoundsException_instance; duke@435: } duke@435: ciInstance* ciEnv::ArrayStoreException_instance() { duke@435: if (_ArrayStoreException_instance == NULL) { duke@435: _ArrayStoreException_instance duke@435: = get_or_create_exception(_ArrayStoreException_handle, coleenp@2497: vmSymbols::java_lang_ArrayStoreException()); duke@435: } duke@435: return _ArrayStoreException_instance; duke@435: } duke@435: ciInstance* ciEnv::ClassCastException_instance() { duke@435: if (_ClassCastException_instance == NULL) { duke@435: _ClassCastException_instance duke@435: = get_or_create_exception(_ClassCastException_handle, coleenp@2497: vmSymbols::java_lang_ClassCastException()); duke@435: } duke@435: return _ClassCastException_instance; duke@435: } duke@435: never@1515: ciInstance* ciEnv::the_null_string() { never@1515: if (_the_null_string == NULL) { never@1515: VM_ENTRY_MARK; never@1515: _the_null_string = get_object(Universe::the_null_string())->as_instance(); never@1515: } never@1515: return _the_null_string; never@1515: } never@1515: never@1515: ciInstance* ciEnv::the_min_jint_string() { never@1515: if (_the_min_jint_string == NULL) { never@1515: VM_ENTRY_MARK; never@1515: _the_min_jint_string = get_object(Universe::the_min_jint_string())->as_instance(); never@1515: } never@1515: return _the_min_jint_string; never@1515: } never@1515: duke@435: // ------------------------------------------------------------------ duke@435: // ciEnv::get_method_from_handle coleenp@4037: ciMethod* ciEnv::get_method_from_handle(Method* method) { duke@435: VM_ENTRY_MARK; coleenp@4037: return get_metadata(method)->as_method(); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciEnv::array_element_offset_in_bytes duke@435: int ciEnv::array_element_offset_in_bytes(ciArray* a_h, ciObject* o_h) { duke@435: VM_ENTRY_MARK; duke@435: objArrayOop a = (objArrayOop)a_h->get_oop(); duke@435: assert(a->is_objArray(), ""); duke@435: int length = a->length(); duke@435: oop o = o_h->get_oop(); duke@435: for (int i = 0; i < length; i++) { duke@435: if (a->obj_at(i) == o) return i; duke@435: } duke@435: return -1; duke@435: } duke@435: duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciEnv::check_klass_accessiblity duke@435: // duke@435: // Note: the logic of this method should mirror the logic of coleenp@4037: // ConstantPool::verify_constant_pool_resolve. duke@435: bool ciEnv::check_klass_accessibility(ciKlass* accessing_klass, coleenp@4037: Klass* resolved_klass) { duke@435: if (accessing_klass == NULL || !accessing_klass->is_loaded()) { duke@435: return true; duke@435: } coleenp@4037: if (accessing_klass->is_obj_array_klass()) { duke@435: accessing_klass = accessing_klass->as_obj_array_klass()->base_element_klass(); duke@435: } duke@435: if (!accessing_klass->is_instance_klass()) { duke@435: return true; duke@435: } duke@435: coleenp@4037: if (resolved_klass->oop_is_objArray()) { duke@435: // Find the element klass, if this is an array. coleenp@4142: resolved_klass = ObjArrayKlass::cast(resolved_klass)->bottom_klass(); duke@435: } coleenp@4037: if (resolved_klass->oop_is_instance()) { coleenp@4037: return Reflection::verify_class_access(accessing_klass->get_Klass(), duke@435: resolved_klass, duke@435: true); duke@435: } duke@435: return true; duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciEnv::get_klass_by_name_impl duke@435: ciKlass* ciEnv::get_klass_by_name_impl(ciKlass* accessing_klass, jrose@2982: constantPoolHandle cpool, duke@435: ciSymbol* name, duke@435: bool require_local) { duke@435: ASSERT_IN_VM; duke@435: EXCEPTION_CONTEXT; duke@435: duke@435: // Now we need to check the SystemDictionary coleenp@2497: Symbol* sym = name->get_symbol(); duke@435: if (sym->byte_at(0) == 'L' && duke@435: sym->byte_at(sym->utf8_length()-1) == ';') { duke@435: // This is a name from a signature. Strip off the trimmings. coleenp@2497: // Call recursive to keep scope of strippedsym. coleenp@2497: TempNewSymbol strippedsym = SymbolTable::new_symbol(sym->as_utf8()+1, coleenp@2497: sym->utf8_length()-2, coleenp@2497: KILL_COMPILE_ON_FATAL_(_unloaded_ciinstance_klass)); coleenp@2497: ciSymbol* strippedname = get_symbol(strippedsym); jrose@2982: return get_klass_by_name_impl(accessing_klass, cpool, strippedname, require_local); duke@435: } duke@435: duke@435: // Check for prior unloaded klass. The SystemDictionary's answers duke@435: // can vary over time but the compiler needs consistency. duke@435: ciKlass* unloaded_klass = check_get_unloaded_klass(accessing_klass, name); duke@435: if (unloaded_klass != NULL) { duke@435: if (require_local) return NULL; duke@435: return unloaded_klass; duke@435: } duke@435: duke@435: Handle loader(THREAD, (oop)NULL); duke@435: Handle domain(THREAD, (oop)NULL); duke@435: if (accessing_klass != NULL) { duke@435: loader = Handle(THREAD, accessing_klass->loader()); duke@435: domain = Handle(THREAD, accessing_klass->protection_domain()); duke@435: } duke@435: duke@435: // setup up the proper type to return on OOM duke@435: ciKlass* fail_type; duke@435: if (sym->byte_at(0) == '[') { duke@435: fail_type = _unloaded_ciobjarrayklass; duke@435: } else { duke@435: fail_type = _unloaded_ciinstance_klass; duke@435: } kamg@2467: KlassHandle found_klass; never@2551: { never@2570: ttyUnlocker ttyul; // release tty lock to avoid ordering problems never@2551: MutexLocker ml(Compile_lock); coleenp@4037: Klass* kls; never@2551: if (!require_local) { never@2551: kls = SystemDictionary::find_constrained_instance_or_array_klass(sym, loader, never@2551: KILL_COMPILE_ON_FATAL_(fail_type)); never@2551: } else { never@2551: kls = SystemDictionary::find_instance_or_array_klass(sym, loader, domain, never@2551: KILL_COMPILE_ON_FATAL_(fail_type)); never@2551: } kamg@2467: found_klass = KlassHandle(THREAD, kls); duke@435: } duke@435: duke@435: // If we fail to find an array klass, look again for its element type. duke@435: // The element type may be available either locally or via constraints. duke@435: // In either case, if we can find the element type in the system dictionary, duke@435: // we must build an array type around it. The CI requires array klasses duke@435: // to be loaded if their element klasses are loaded, except when memory duke@435: // is exhausted. duke@435: if (sym->byte_at(0) == '[' && duke@435: (sym->byte_at(1) == '[' || sym->byte_at(1) == 'L')) { duke@435: // We have an unloaded array. duke@435: // Build it on the fly if the element class exists. coleenp@2497: TempNewSymbol elem_sym = SymbolTable::new_symbol(sym->as_utf8()+1, coleenp@2497: sym->utf8_length()-1, coleenp@2497: KILL_COMPILE_ON_FATAL_(fail_type)); coleenp@2497: duke@435: // Get element ciKlass recursively. duke@435: ciKlass* elem_klass = duke@435: get_klass_by_name_impl(accessing_klass, jrose@2982: cpool, coleenp@2497: get_symbol(elem_sym), duke@435: require_local); duke@435: if (elem_klass != NULL && elem_klass->is_loaded()) { duke@435: // Now make an array for it duke@435: return ciObjArrayKlass::make_impl(elem_klass); duke@435: } duke@435: } duke@435: jrose@2982: if (found_klass() == NULL && !cpool.is_null() && cpool->has_preresolution()) { jrose@2982: // Look inside the constant pool for pre-resolved class entries. jrose@2982: for (int i = cpool->length() - 1; i >= 1; i--) { jrose@2982: if (cpool->tag_at(i).is_klass()) { coleenp@4037: Klass* kls = cpool->resolved_klass_at(i); hseigel@4278: if (kls->name() == sym) { jrose@2982: found_klass = KlassHandle(THREAD, kls); jrose@2982: break; jrose@2982: } jrose@2982: } jrose@2982: } jrose@2982: } jrose@2982: kamg@2467: if (found_klass() != NULL) { jrose@1424: // Found it. Build a CI handle. coleenp@4037: return get_klass(found_klass()); jrose@1424: } jrose@1424: duke@435: if (require_local) return NULL; twisti@3197: duke@435: // Not yet loaded into the VM, or not governed by loader constraints. duke@435: // Make a CI representative for it. duke@435: return get_unloaded_klass(accessing_klass, name); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciEnv::get_klass_by_name duke@435: ciKlass* ciEnv::get_klass_by_name(ciKlass* accessing_klass, duke@435: ciSymbol* klass_name, duke@435: bool require_local) { duke@435: GUARDED_VM_ENTRY(return get_klass_by_name_impl(accessing_klass, jrose@2982: constantPoolHandle(), duke@435: klass_name, duke@435: require_local);) duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciEnv::get_klass_by_index_impl duke@435: // duke@435: // Implementation of get_klass_by_index. twisti@1573: ciKlass* ciEnv::get_klass_by_index_impl(constantPoolHandle cpool, duke@435: int index, twisti@1573: bool& is_accessible, twisti@1573: ciInstanceKlass* accessor) { duke@435: EXCEPTION_CONTEXT; coleenp@4037: KlassHandle klass; // = NULL; coleenp@2497: Symbol* klass_name = NULL; coleenp@4037: coleenp@4037: if (cpool->tag_at(index).is_symbol()) { coleenp@4037: klass_name = cpool->symbol_at(index); coleenp@4037: } else { coleenp@4037: // Check if it's resolved if it's not a symbol constant pool entry. coleenp@4037: klass = KlassHandle(THREAD, ConstantPool::klass_at_if_loaded(cpool, index)); coleenp@4037: duke@435: if (klass.is_null()) { duke@435: // The klass has not been inserted into the constant pool. duke@435: // Try to look it up by name. duke@435: { duke@435: // We have to lock the cpool to keep the oop from being resolved duke@435: // while we are accessing it. iklam@4984: oop cplock = cpool->lock(); iklam@4984: ObjectLocker ol(cplock, THREAD, cplock != NULL); duke@435: constantTag tag = cpool->tag_at(index); duke@435: if (tag.is_klass()) { duke@435: // The klass has been inserted into the constant pool duke@435: // very recently. duke@435: klass = KlassHandle(THREAD, cpool->resolved_klass_at(index)); duke@435: } else { duke@435: assert(cpool->tag_at(index).is_unresolved_klass(), "wrong tag"); coleenp@2497: klass_name = cpool->unresolved_klass_at(index); duke@435: } duke@435: } duke@435: } coleenp@4037: } duke@435: duke@435: if (klass.is_null()) { duke@435: // Not found in constant pool. Use the name to do the lookup. duke@435: ciKlass* k = get_klass_by_name_impl(accessor, jrose@2982: cpool, coleenp@2497: get_symbol(klass_name), duke@435: false); duke@435: // Calculate accessibility the hard way. duke@435: if (!k->is_loaded()) { duke@435: is_accessible = false; duke@435: } else if (k->loader() != accessor->loader() && jrose@2982: get_klass_by_name_impl(accessor, cpool, k->name(), true) == NULL) { duke@435: // Loaded only remotely. Not linked yet. duke@435: is_accessible = false; duke@435: } else { duke@435: // Linked locally, and we must also check public/private, etc. coleenp@4037: is_accessible = check_klass_accessibility(accessor, k->get_Klass()); duke@435: } duke@435: return k; duke@435: } duke@435: duke@435: // Check for prior unloaded klass. The SystemDictionary's answers duke@435: // can vary over time but the compiler needs consistency. coleenp@4037: ciSymbol* name = get_symbol(klass()->name()); duke@435: ciKlass* unloaded_klass = check_get_unloaded_klass(accessor, name); duke@435: if (unloaded_klass != NULL) { duke@435: is_accessible = false; duke@435: return unloaded_klass; duke@435: } duke@435: duke@435: // It is known to be accessible, since it was found in the constant pool. duke@435: is_accessible = true; coleenp@4037: return get_klass(klass()); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciEnv::get_klass_by_index duke@435: // duke@435: // Get a klass from the constant pool. twisti@1573: ciKlass* ciEnv::get_klass_by_index(constantPoolHandle cpool, duke@435: int index, twisti@1573: bool& is_accessible, twisti@1573: ciInstanceKlass* accessor) { twisti@1573: GUARDED_VM_ENTRY(return get_klass_by_index_impl(cpool, index, is_accessible, accessor);) duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciEnv::get_constant_by_index_impl duke@435: // duke@435: // Implementation of get_constant_by_index(). twisti@1573: ciConstant ciEnv::get_constant_by_index_impl(constantPoolHandle cpool, jrose@1957: int pool_index, int cache_index, twisti@1573: ciInstanceKlass* accessor) { jrose@1957: bool ignore_will_link; duke@435: EXCEPTION_CONTEXT; jrose@1957: int index = pool_index; jrose@1957: if (cache_index >= 0) { jrose@1957: assert(index < 0, "only one kind of index at a time"); coleenp@4037: oop obj = cpool->resolved_references()->obj_at(cache_index); jrose@1957: if (obj != NULL) { jrose@1957: ciObject* ciobj = get_object(obj); jrose@1957: return ciConstant(T_OBJECT, ciobj); jrose@1957: } coleenp@4037: index = cpool->object_to_cp_index(cache_index); jrose@1957: } duke@435: constantTag tag = cpool->tag_at(index); duke@435: if (tag.is_int()) { duke@435: return ciConstant(T_INT, (jint)cpool->int_at(index)); duke@435: } else if (tag.is_long()) { duke@435: return ciConstant((jlong)cpool->long_at(index)); duke@435: } else if (tag.is_float()) { duke@435: return ciConstant((jfloat)cpool->float_at(index)); duke@435: } else if (tag.is_double()) { duke@435: return ciConstant((jdouble)cpool->double_at(index)); coleenp@4037: } else if (tag.is_string()) { jrose@866: oop string = NULL; coleenp@4037: assert(cache_index >= 0, "should have a cache index"); jrose@866: if (cpool->is_pseudo_string_at(index)) { coleenp@4037: string = cpool->pseudo_string_at(index, cache_index); jrose@866: } else { coleenp@4037: string = cpool->string_at(index, cache_index, THREAD); jrose@866: if (HAS_PENDING_EXCEPTION) { jrose@866: CLEAR_PENDING_EXCEPTION; jrose@866: record_out_of_memory_failure(); jrose@866: return ciConstant(); jrose@866: } duke@435: } duke@435: ciObject* constant = get_object(string); duke@435: assert (constant->is_instance(), "must be an instance, or not? "); duke@435: return ciConstant(T_OBJECT, constant); duke@435: } else if (tag.is_klass() || tag.is_unresolved_klass()) { duke@435: // 4881222: allow ldc to take a class type jrose@1957: ciKlass* klass = get_klass_by_index_impl(cpool, index, ignore_will_link, accessor); duke@435: if (HAS_PENDING_EXCEPTION) { duke@435: CLEAR_PENDING_EXCEPTION; duke@435: record_out_of_memory_failure(); duke@435: return ciConstant(); duke@435: } duke@435: assert (klass->is_instance_klass() || klass->is_array_klass(), duke@435: "must be an instance or array klass "); jrose@1957: return ciConstant(T_OBJECT, klass->java_mirror()); jrose@1957: } else if (tag.is_method_type()) { jrose@1957: // must execute Java code to link this CP entry into cache[i].f1 coleenp@2497: ciSymbol* signature = get_symbol(cpool->method_type_signature_at(index)); jrose@1957: ciObject* ciobj = get_unloaded_method_type_constant(signature); jrose@1957: return ciConstant(T_OBJECT, ciobj); jrose@1957: } else if (tag.is_method_handle()) { jrose@1957: // must execute Java code to link this CP entry into cache[i].f1 jrose@1957: int ref_kind = cpool->method_handle_ref_kind_at(index); jrose@1957: int callee_index = cpool->method_handle_klass_index_at(index); jrose@1957: ciKlass* callee = get_klass_by_index_impl(cpool, callee_index, ignore_will_link, accessor); coleenp@2497: ciSymbol* name = get_symbol(cpool->method_handle_name_ref_at(index)); coleenp@2497: ciSymbol* signature = get_symbol(cpool->method_handle_signature_ref_at(index)); jrose@1957: ciObject* ciobj = get_unloaded_method_handle_constant(callee, name, signature, ref_kind); jrose@1957: return ciConstant(T_OBJECT, ciobj); duke@435: } else { duke@435: ShouldNotReachHere(); duke@435: return ciConstant(); duke@435: } duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciEnv::get_constant_by_index duke@435: // duke@435: // Pull a constant out of the constant pool. How appropriate. duke@435: // duke@435: // Implementation note: this query is currently in no way cached. twisti@1573: ciConstant ciEnv::get_constant_by_index(constantPoolHandle cpool, jrose@1957: int pool_index, int cache_index, twisti@1573: ciInstanceKlass* accessor) { jrose@1957: GUARDED_VM_ENTRY(return get_constant_by_index_impl(cpool, pool_index, cache_index, accessor);) duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciEnv::get_field_by_index_impl duke@435: // duke@435: // Implementation of get_field_by_index. duke@435: // duke@435: // Implementation note: the results of field lookups are cached duke@435: // in the accessor klass. duke@435: ciField* ciEnv::get_field_by_index_impl(ciInstanceKlass* accessor, duke@435: int index) { duke@435: ciConstantPoolCache* cache = accessor->field_cache(); duke@435: if (cache == NULL) { duke@435: ciField* field = new (arena()) ciField(accessor, index); duke@435: return field; duke@435: } else { duke@435: ciField* field = (ciField*)cache->get(index); duke@435: if (field == NULL) { duke@435: field = new (arena()) ciField(accessor, index); duke@435: cache->insert(index, field); duke@435: } duke@435: return field; duke@435: } duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciEnv::get_field_by_index duke@435: // duke@435: // Get a field by index from a klass's constant pool. duke@435: ciField* ciEnv::get_field_by_index(ciInstanceKlass* accessor, duke@435: int index) { duke@435: GUARDED_VM_ENTRY(return get_field_by_index_impl(accessor, index);) duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciEnv::lookup_method duke@435: // duke@435: // Perform an appropriate method lookup based on accessor, holder, duke@435: // name, signature, and bytecode. coleenp@4037: Method* ciEnv::lookup_method(InstanceKlass* accessor, coleenp@4037: InstanceKlass* holder, coleenp@2497: Symbol* name, coleenp@2497: Symbol* sig, duke@435: Bytecodes::Code bc) { duke@435: EXCEPTION_CONTEXT; duke@435: KlassHandle h_accessor(THREAD, accessor); duke@435: KlassHandle h_holder(THREAD, holder); duke@435: LinkResolver::check_klass_accessability(h_accessor, h_holder, KILL_COMPILE_ON_FATAL_(NULL)); duke@435: methodHandle dest_method; duke@435: switch (bc) { duke@435: case Bytecodes::_invokestatic: duke@435: dest_method = coleenp@2497: LinkResolver::resolve_static_call_or_null(h_holder, name, sig, h_accessor); duke@435: break; duke@435: case Bytecodes::_invokespecial: duke@435: dest_method = coleenp@2497: LinkResolver::resolve_special_call_or_null(h_holder, name, sig, h_accessor); duke@435: break; duke@435: case Bytecodes::_invokeinterface: duke@435: dest_method = coleenp@2497: LinkResolver::linktime_resolve_interface_method_or_null(h_holder, name, sig, duke@435: h_accessor, true); duke@435: break; duke@435: case Bytecodes::_invokevirtual: duke@435: dest_method = coleenp@2497: LinkResolver::linktime_resolve_virtual_method_or_null(h_holder, name, sig, duke@435: h_accessor, true); duke@435: break; duke@435: default: ShouldNotReachHere(); duke@435: } duke@435: duke@435: return dest_method(); duke@435: } duke@435: duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciEnv::get_method_by_index_impl twisti@1573: ciMethod* ciEnv::get_method_by_index_impl(constantPoolHandle cpool, twisti@1573: int index, Bytecodes::Code bc, twisti@1573: ciInstanceKlass* accessor) { twisti@4021: if (bc == Bytecodes::_invokedynamic) { coleenp@4037: ConstantPoolCacheEntry* cpce = cpool->invokedynamic_cp_cache_entry_at(index); coleenp@4037: bool is_resolved = !cpce->is_f1_null(); twisti@4021: // FIXME: code generation could allow for null (unlinked) call site twisti@4021: // The call site could be made patchable as follows: twisti@4021: // Load the appendix argument from the constant pool. twisti@4021: // Test the appendix argument and jump to a known deopt routine if it is null. twisti@4021: // Jump through a patchable call site, which is initially a deopt routine. twisti@4021: // Patch the call site to the nmethod entry point of the static compiled lambda form. twisti@4021: // As with other two-component call sites, both values must be independently verified. duke@435: twisti@4021: if (is_resolved) { coleenp@4037: // Get the invoker Method* from the constant pool. coleenp@4037: // (The appendix argument, if any, will be noted in the method's signature.) coleenp@4037: Method* adapter = cpce->f1_as_method(); coleenp@4037: return get_method(adapter); twisti@4021: } duke@435: twisti@4021: // Fake a method that is equivalent to a declared method. coleenp@4037: ciInstanceKlass* holder = get_instance_klass(SystemDictionary::MethodHandle_klass()); twisti@3969: ciSymbol* name = ciSymbol::invokeBasic_name(); twisti@3197: ciSymbol* signature = get_symbol(cpool->signature_ref_at(index)); twisti@3197: return get_unloaded_method(holder, name, signature, accessor); twisti@4021: } else { twisti@4021: const int holder_index = cpool->klass_ref_index_at(index); twisti@4021: bool holder_is_accessible; twisti@4021: ciKlass* holder = get_klass_by_index_impl(cpool, holder_index, holder_is_accessible, accessor); twisti@4021: ciInstanceKlass* declared_holder = get_instance_klass_for_declared_method_holder(holder); twisti@4021: twisti@4021: // Get the method's name and signature. twisti@4021: Symbol* name_sym = cpool->name_ref_at(index); twisti@4021: Symbol* sig_sym = cpool->signature_ref_at(index); twisti@4021: twisti@4021: if (cpool->has_preresolution() twisti@4021: || (holder == ciEnv::MethodHandle_klass() && coleenp@4037: MethodHandles::is_signature_polymorphic_name(holder->get_Klass(), name_sym))) { twisti@4021: // Short-circuit lookups for JSR 292-related call sites. twisti@4021: // That is, do not rely only on name-based lookups, because they may fail twisti@4021: // if the names are not resolvable in the boot class loader (7056328). twisti@4021: switch (bc) { twisti@4021: case Bytecodes::_invokevirtual: twisti@4021: case Bytecodes::_invokeinterface: twisti@4021: case Bytecodes::_invokespecial: twisti@4021: case Bytecodes::_invokestatic: twisti@4021: { coleenp@4037: Method* m = ConstantPool::method_at_if_loaded(cpool, index); twisti@4021: if (m != NULL) { coleenp@4037: return get_method(m); twisti@4021: } twisti@4021: } twisti@4021: break; twisti@4021: } twisti@4021: } twisti@4021: twisti@4021: if (holder_is_accessible) { // Our declared holder is loaded. coleenp@4037: InstanceKlass* lookup = declared_holder->get_instanceKlass(); coleenp@4037: Method* m = lookup_method(accessor->get_instanceKlass(), lookup, name_sym, sig_sym, bc); twisti@4021: if (m != NULL && twisti@4021: (bc == Bytecodes::_invokestatic coleenp@4251: ? m->method_holder()->is_not_initialized() coleenp@4251: : !m->method_holder()->is_loaded())) { twisti@4021: m = NULL; twisti@4021: } minqi@4267: #ifdef ASSERT minqi@4267: if (m != NULL && ReplayCompiles && !ciReplay::is_loaded(m)) { minqi@4267: m = NULL; minqi@4267: } minqi@4267: #endif twisti@4021: if (m != NULL) { twisti@4021: // We found the method. coleenp@4037: return get_method(m); twisti@4021: } twisti@4021: } twisti@4021: twisti@4021: // Either the declared holder was not loaded, or the method could twisti@4021: // not be found. Create a dummy ciMethod to represent the failed twisti@4021: // lookup. twisti@4021: ciSymbol* name = get_symbol(name_sym); twisti@4021: ciSymbol* signature = get_symbol(sig_sym); twisti@4021: return get_unloaded_method(declared_holder, name, signature, accessor); twisti@1572: } twisti@1572: } twisti@1572: twisti@1572: twisti@1572: // ------------------------------------------------------------------ duke@435: // ciEnv::get_instance_klass_for_declared_method_holder duke@435: ciInstanceKlass* ciEnv::get_instance_klass_for_declared_method_holder(ciKlass* method_holder) { duke@435: // For the case of .clone(), the method holder can be a ciArrayKlass duke@435: // instead of a ciInstanceKlass. For that case simply pretend that the duke@435: // declared holder is Object.clone since that's where the call will bottom out. duke@435: // A more correct fix would trickle out through many interfaces in CI, duke@435: // requiring ciInstanceKlass* to become ciKlass* and many more places would duke@435: // require checks to make sure the expected type was found. Given that this duke@435: // only occurs for clone() the more extensive fix seems like overkill so duke@435: // instead we simply smear the array type into Object. morris@4777: guarantee(method_holder != NULL, "no method holder"); duke@435: if (method_holder->is_instance_klass()) { duke@435: return method_holder->as_instance_klass(); duke@435: } else if (method_holder->is_array_klass()) { duke@435: return current()->Object_klass(); duke@435: } else { duke@435: ShouldNotReachHere(); duke@435: } duke@435: return NULL; duke@435: } duke@435: duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciEnv::get_method_by_index twisti@1573: ciMethod* ciEnv::get_method_by_index(constantPoolHandle cpool, twisti@1573: int index, Bytecodes::Code bc, twisti@1573: ciInstanceKlass* accessor) { twisti@4021: GUARDED_VM_ENTRY(return get_method_by_index_impl(cpool, index, bc, accessor);) duke@435: } duke@435: twisti@1572: duke@435: // ------------------------------------------------------------------ duke@435: // ciEnv::name_buffer duke@435: char *ciEnv::name_buffer(int req_len) { duke@435: if (_name_buffer_len < req_len) { duke@435: if (_name_buffer == NULL) { duke@435: _name_buffer = (char*)arena()->Amalloc(sizeof(char)*req_len); duke@435: _name_buffer_len = req_len; duke@435: } else { duke@435: _name_buffer = duke@435: (char*)arena()->Arealloc(_name_buffer, _name_buffer_len, req_len); duke@435: _name_buffer_len = req_len; duke@435: } duke@435: } duke@435: return _name_buffer; duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciEnv::is_in_vm duke@435: bool ciEnv::is_in_vm() { duke@435: return JavaThread::current()->thread_state() == _thread_in_vm; duke@435: } duke@435: duke@435: bool ciEnv::system_dictionary_modification_counter_changed() { duke@435: return _system_dictionary_modification_counter != SystemDictionary::number_of_modifications(); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ twisti@3094: // ciEnv::validate_compile_task_dependencies twisti@3094: // twisti@3094: // Check for changes during compilation (e.g. class loads, evolution, twisti@3094: // breakpoints, call site invalidation). twisti@3094: void ciEnv::validate_compile_task_dependencies(ciMethod* target) { duke@435: if (failing()) return; // no need for further checks duke@435: twisti@3094: // First, check non-klass dependencies as we might return early and twisti@3094: // not check klass dependencies if the system dictionary twisti@3094: // modification counter hasn't changed (see below). twisti@3094: for (Dependencies::DepStream deps(dependencies()); deps.next(); ) { twisti@3094: if (deps.is_klass_type()) continue; // skip klass dependencies coleenp@4037: Klass* witness = deps.check_dependency(); twisti@3094: if (witness != NULL) { twisti@3094: record_failure("invalid non-klass dependency"); twisti@3094: return; twisti@3094: } twisti@3094: } duke@435: twisti@3094: // Klass dependencies must be checked when the system dictionary twisti@3094: // changes. If logging is enabled all violated dependences will be twisti@3094: // recorded in the log. In debug mode check dependencies even if twisti@3094: // the system dictionary hasn't changed to verify that no invalid twisti@3094: // dependencies were inserted. Any violated dependences in this twisti@3094: // case are dumped to the tty. duke@435: bool counter_changed = system_dictionary_modification_counter_changed(); duke@435: never@3155: bool verify_deps = trueInDebug; never@3155: if (!counter_changed && !verify_deps) return; never@3155: twisti@3094: int klass_violations = 0; duke@435: for (Dependencies::DepStream deps(dependencies()); deps.next(); ) { twisti@3094: if (!deps.is_klass_type()) continue; // skip non-klass dependencies coleenp@4037: Klass* witness = deps.check_dependency(); duke@435: if (witness != NULL) { twisti@3094: klass_violations++; never@3155: if (!counter_changed) { never@3155: // Dependence failed but counter didn't change. Log a message never@3155: // describing what failed and allow the assert at the end to never@3155: // trigger. never@3155: deps.print_dependency(witness); never@3155: } else if (xtty == NULL) { never@3155: // If we're not logging then a single violation is sufficient, never@3155: // otherwise we want to log all the dependences which were never@3155: // violated. never@3155: break; never@3155: } duke@435: } duke@435: } duke@435: twisti@3094: if (klass_violations != 0) { never@3155: #ifdef ASSERT never@3155: if (!counter_changed && !PrintCompilation) { never@3155: // Print out the compile task that failed never@3155: _task->print_line(); never@3155: } never@3155: #endif duke@435: assert(counter_changed, "failed dependencies, but counter didn't change"); duke@435: record_failure("concurrent class loading"); duke@435: } duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciEnv::register_method duke@435: void ciEnv::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@4103: bool has_wide_vectors) { duke@435: VM_ENTRY_MARK; duke@435: nmethod* nm = NULL; duke@435: { duke@435: // To prevent compile queue updates. duke@435: MutexLocker locker(MethodCompileQueue_lock, THREAD); duke@435: duke@435: // Prevent SystemDictionary::add_to_hierarchy from running duke@435: // and invalidating our dependencies until we install this method. duke@435: MutexLocker ml(Compile_lock); duke@435: kvn@1215: // Change in Jvmti state may invalidate compilation. kvn@1215: if (!failing() && kvn@1215: ( (!jvmti_can_hotswap_or_post_breakpoint() && kvn@1215: JvmtiExport::can_hotswap_or_post_breakpoint()) || kvn@1215: (!jvmti_can_access_local_variables() && kvn@1215: JvmtiExport::can_access_local_variables()) || dcubed@1648: (!jvmti_can_post_on_exceptions() && dcubed@1648: JvmtiExport::can_post_on_exceptions()) )) { kvn@1215: record_failure("Jvmti state change invalidated dependencies"); duke@435: } duke@435: kvn@1215: // Change in DTrace flags may invalidate compilation. kvn@1215: if (!failing() && kvn@1215: ( (!dtrace_extended_probes() && ExtendedDTraceProbes) || kvn@1215: (!dtrace_method_probes() && DTraceMethodProbes) || kvn@1215: (!dtrace_alloc_probes() && DTraceAllocProbes) )) { kvn@1215: record_failure("DTrace flags change invalidated dependencies"); kvn@1215: } duke@435: kvn@1215: if (!failing()) { kvn@1215: if (log() != NULL) { kvn@1215: // Log the dependencies which this compilation declares. kvn@1215: dependencies()->log_all_dependencies(); kvn@1215: } kvn@1215: kvn@1215: // Encode the dependencies now, so we can check them right away. kvn@1215: dependencies()->encode_content_bytes(); kvn@1215: twisti@3094: // Check for {class loads, evolution, breakpoints, ...} during compilation twisti@3094: validate_compile_task_dependencies(target); kvn@1215: } duke@435: coleenp@4037: methodHandle method(THREAD, target->get_Method()); duke@435: duke@435: if (failing()) { duke@435: // While not a true deoptimization, it is a preemptive decompile. coleenp@4037: MethodData* mdo = method()->method_data(); duke@435: if (mdo != NULL) { duke@435: mdo->inc_decompile_count(); duke@435: } duke@435: duke@435: // All buffers in the CodeBuffer are allocated in the CodeCache. duke@435: // If the code buffer is created on each compile attempt duke@435: // as in C2, then it must be freed. duke@435: code_buffer->free_blob(); duke@435: return; duke@435: } duke@435: duke@435: assert(offsets->value(CodeOffsets::Deopt) != -1, "must have deopt entry"); duke@435: assert(offsets->value(CodeOffsets::Exceptions) != -1, "must have exception entry"); duke@435: duke@435: nm = nmethod::new_nmethod(method, duke@435: compile_id(), duke@435: entry_bci, duke@435: offsets, duke@435: orig_pc_offset, duke@435: debug_info(), dependencies(), code_buffer, duke@435: frame_words, oop_map_set, duke@435: handler_table, inc_table, duke@435: compiler, comp_level); duke@435: duke@435: // Free codeBlobs duke@435: code_buffer->free_blob(); duke@435: duke@435: // stress test 6243940 by immediately making the method duke@435: // non-entrant behind the system's back. This has serious duke@435: // side effects on the code cache and is not meant for duke@435: // general stress testing duke@435: if (nm != NULL && StressNonEntrant) { duke@435: MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag); duke@435: NativeJump::patch_verified_entry(nm->entry_point(), nm->verified_entry_point(), duke@435: SharedRuntime::get_handle_wrong_method_stub()); duke@435: } duke@435: duke@435: if (nm == NULL) { duke@435: // The CodeCache is full. Print out warning and disable compilation. duke@435: record_failure("code cache is full"); kvn@1637: { kvn@1637: MutexUnlocker ml(Compile_lock); kvn@1637: MutexUnlocker locker(MethodCompileQueue_lock); kvn@1637: CompileBroker::handle_full_code_cache(); duke@435: } duke@435: } else { duke@435: nm->set_has_unsafe_access(has_unsafe_access); kvn@4103: nm->set_has_wide_vectors(has_wide_vectors); duke@435: duke@435: // Record successful registration. duke@435: // (Put nm into the task handle *before* publishing to the Java heap.) duke@435: if (task() != NULL) task()->set_code(nm); duke@435: duke@435: if (entry_bci == InvocationEntryBci) { iveresov@2138: if (TieredCompilation) { iveresov@2138: // If there is an old version we're done with it iveresov@2138: nmethod* old = method->code(); iveresov@2138: if (TraceMethodReplacement && old != NULL) { iveresov@2138: ResourceMark rm; iveresov@2138: char *method_name = method->name_and_sig_as_C_string(); iveresov@2138: tty->print_cr("Replacing method %s", method_name); iveresov@2138: } iveresov@2138: if (old != NULL ) { iveresov@2138: old->make_not_entrant(); iveresov@2138: } duke@435: } duke@435: if (TraceNMethodInstalls ) { duke@435: ResourceMark rm; duke@435: char *method_name = method->name_and_sig_as_C_string(); duke@435: ttyLocker ttyl; duke@435: tty->print_cr("Installing method (%d) %s ", duke@435: comp_level, duke@435: method_name); duke@435: } duke@435: // Allow the code to be executed duke@435: method->set_code(method, nm); duke@435: } else { duke@435: if (TraceNMethodInstalls ) { duke@435: ResourceMark rm; duke@435: char *method_name = method->name_and_sig_as_C_string(); duke@435: ttyLocker ttyl; duke@435: tty->print_cr("Installing osr method (%d) %s @ %d", duke@435: comp_level, duke@435: method_name, duke@435: entry_bci); duke@435: } coleenp@4251: method->method_holder()->add_osr_nmethod(nm); duke@435: duke@435: } duke@435: } duke@435: } duke@435: // JVMTI -- compiled method notification (must be done outside lock) duke@435: if (nm != NULL) { duke@435: nm->post_compiled_method_load_event(); duke@435: } duke@435: duke@435: } duke@435: duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciEnv::find_system_klass duke@435: ciKlass* ciEnv::find_system_klass(ciSymbol* klass_name) { duke@435: VM_ENTRY_MARK; jrose@2982: return get_klass_by_name_impl(NULL, constantPoolHandle(), klass_name, false); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciEnv::comp_level duke@435: int ciEnv::comp_level() { iveresov@2138: if (task() == NULL) return CompLevel_highest_tier; duke@435: return task()->comp_level(); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciEnv::compile_id duke@435: uint ciEnv::compile_id() { duke@435: if (task() == NULL) return 0; duke@435: return task()->compile_id(); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciEnv::notice_inlined_method() duke@435: void ciEnv::notice_inlined_method(ciMethod* method) { twisti@3969: _num_inlined_bytecodes += method->code_size_for_inlining(); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciEnv::num_inlined_bytecodes() duke@435: int ciEnv::num_inlined_bytecodes() const { duke@435: return _num_inlined_bytecodes; duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciEnv::record_failure() duke@435: void ciEnv::record_failure(const char* reason) { duke@435: if (log() != NULL) { duke@435: log()->elem("failure reason='%s'", reason); duke@435: } duke@435: if (_failure_reason == NULL) { duke@435: // Record the first failure reason. duke@435: _failure_reason = reason; duke@435: } duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciEnv::record_method_not_compilable() duke@435: void ciEnv::record_method_not_compilable(const char* reason, bool all_tiers) { duke@435: int new_compilable = duke@435: all_tiers ? MethodCompilable_never : MethodCompilable_not_at_tier ; duke@435: duke@435: // Only note transitions to a worse state duke@435: if (new_compilable > _compilable) { duke@435: if (log() != NULL) { duke@435: if (all_tiers) { duke@435: log()->elem("method_not_compilable"); duke@435: } else { vlivanov@4154: log()->elem("method_not_compilable_at_tier level='%d'", vlivanov@4154: current()->task()->comp_level()); duke@435: } duke@435: } duke@435: _compilable = new_compilable; duke@435: duke@435: // Reset failure reason; this one is more important. duke@435: _failure_reason = NULL; duke@435: record_failure(reason); duke@435: } duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciEnv::record_out_of_memory_failure() duke@435: void ciEnv::record_out_of_memory_failure() { duke@435: // If memory is low, we stop compiling methods. duke@435: record_method_not_compilable("out of memory"); duke@435: } minqi@4267: vlivanov@5027: void ciEnv::dump_replay_data(outputStream* out) { minqi@4267: VM_ENTRY_MARK; minqi@4267: MutexLocker ml(Compile_lock); vlivanov@4531: ResourceMark rm; minqi@4267: #if INCLUDE_JVMTI minqi@4267: out->print_cr("JvmtiExport can_access_local_variables %d", _jvmti_can_access_local_variables); minqi@4267: out->print_cr("JvmtiExport can_hotswap_or_post_breakpoint %d", _jvmti_can_hotswap_or_post_breakpoint); minqi@4267: out->print_cr("JvmtiExport can_post_on_exceptions %d", _jvmti_can_post_on_exceptions); minqi@4267: #endif // INCLUDE_JVMTI minqi@4267: minqi@4267: GrowableArray* objects = _factory->get_ci_metadata(); minqi@4267: out->print_cr("# %d ciObject found", objects->length()); minqi@4267: for (int i = 0; i < objects->length(); i++) { minqi@4267: objects->at(i)->dump_replay_data(out); minqi@4267: } iignatyev@5029: CompileTask* task = this->task(); iignatyev@5029: Method* method = task->method(); iignatyev@5029: int entry_bci = task->osr_bci(); iignatyev@5029: int comp_level = task->comp_level(); minqi@4267: // Klass holder = method->method_holder(); iignatyev@5029: out->print_cr("compile %s %s %s %d %d", minqi@4267: method->klass_name()->as_quoted_ascii(), minqi@4267: method->name()->as_quoted_ascii(), minqi@4267: method->signature()->as_quoted_ascii(), iignatyev@5029: entry_bci, comp_level); minqi@4267: out->flush(); minqi@4267: }