aoqi@0: /* aoqi@0: * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "ci/ciConstant.hpp" aoqi@0: #include "ci/ciEnv.hpp" aoqi@0: #include "ci/ciField.hpp" aoqi@0: #include "ci/ciInstance.hpp" aoqi@0: #include "ci/ciInstanceKlass.hpp" aoqi@0: #include "ci/ciMethod.hpp" aoqi@0: #include "ci/ciNullObject.hpp" aoqi@0: #include "ci/ciReplay.hpp" aoqi@0: #include "ci/ciUtilities.hpp" aoqi@0: #include "classfile/systemDictionary.hpp" aoqi@0: #include "classfile/vmSymbols.hpp" aoqi@0: #include "code/scopeDesc.hpp" aoqi@0: #include "compiler/compileBroker.hpp" aoqi@0: #include "compiler/compileLog.hpp" aoqi@0: #include "compiler/compilerOracle.hpp" aoqi@0: #include "gc_interface/collectedHeap.inline.hpp" aoqi@0: #include "interpreter/linkResolver.hpp" aoqi@0: #include "memory/allocation.inline.hpp" aoqi@0: #include "memory/oopFactory.hpp" aoqi@0: #include "memory/universe.inline.hpp" aoqi@0: #include "oops/methodData.hpp" aoqi@0: #include "oops/objArrayKlass.hpp" aoqi@0: #include "oops/oop.inline.hpp" aoqi@0: #include "oops/oop.inline2.hpp" aoqi@0: #include "prims/jvmtiExport.hpp" aoqi@0: #include "runtime/init.hpp" aoqi@0: #include "runtime/reflection.hpp" aoqi@0: #include "runtime/sharedRuntime.hpp" goetz@6911: #include "runtime/thread.inline.hpp" aoqi@0: #include "utilities/dtrace.hpp" aoqi@0: #include "utilities/macros.hpp" aoqi@0: #ifdef COMPILER1 aoqi@0: #include "c1/c1_Runtime1.hpp" aoqi@0: #endif aoqi@0: #ifdef COMPILER2 aoqi@0: #include "opto/runtime.hpp" aoqi@0: #endif aoqi@0: aoqi@0: // ciEnv aoqi@0: // aoqi@0: // This class is the top level broker for requests from the compiler aoqi@0: // to the VM. aoqi@0: aoqi@0: ciObject* ciEnv::_null_object_instance; aoqi@0: aoqi@0: #define WK_KLASS_DEFN(name, ignore_s, ignore_o) ciInstanceKlass* ciEnv::_##name = NULL; aoqi@0: WK_KLASSES_DO(WK_KLASS_DEFN) aoqi@0: #undef WK_KLASS_DEFN aoqi@0: aoqi@0: ciSymbol* ciEnv::_unloaded_cisymbol = NULL; aoqi@0: ciInstanceKlass* ciEnv::_unloaded_ciinstance_klass = NULL; aoqi@0: ciObjArrayKlass* ciEnv::_unloaded_ciobjarrayklass = NULL; aoqi@0: aoqi@0: jobject ciEnv::_ArrayIndexOutOfBoundsException_handle = NULL; aoqi@0: jobject ciEnv::_ArrayStoreException_handle = NULL; aoqi@0: jobject ciEnv::_ClassCastException_handle = NULL; aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: static bool firstEnv = true; aoqi@0: #endif /* PRODUCT */ aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::ciEnv zgu@7074: ciEnv::ciEnv(CompileTask* task, int system_dictionary_modification_counter) zgu@7074: : _ciEnv_arena(mtCompiler) { aoqi@0: VM_ENTRY_MARK; aoqi@0: aoqi@0: // Set up ciEnv::current immediately, for the sake of ciObjectFactory, etc. aoqi@0: thread->set_env(this); aoqi@0: assert(ciEnv::current() == this, "sanity"); aoqi@0: aoqi@0: _oop_recorder = NULL; aoqi@0: _debug_info = NULL; aoqi@0: _dependencies = NULL; aoqi@0: _failure_reason = NULL; aoqi@0: _compilable = MethodCompilable; aoqi@0: _break_at_compile = false; aoqi@0: _compiler_data = NULL; aoqi@0: #ifndef PRODUCT aoqi@0: assert(!firstEnv, "not initialized properly"); aoqi@0: #endif /* !PRODUCT */ aoqi@0: aoqi@0: _system_dictionary_modification_counter = system_dictionary_modification_counter; aoqi@0: _num_inlined_bytecodes = 0; aoqi@0: assert(task == NULL || thread->task() == task, "sanity"); aoqi@0: _task = task; aoqi@0: _log = NULL; aoqi@0: aoqi@0: // Temporary buffer for creating symbols and such. aoqi@0: _name_buffer = NULL; aoqi@0: _name_buffer_len = 0; aoqi@0: aoqi@0: _arena = &_ciEnv_arena; aoqi@0: _factory = new (_arena) ciObjectFactory(_arena, 128); aoqi@0: aoqi@0: // Preload commonly referenced system ciObjects. aoqi@0: aoqi@0: // During VM initialization, these instances have not yet been created. aoqi@0: // Assertions ensure that these instances are not accessed before aoqi@0: // their initialization. aoqi@0: aoqi@0: assert(Universe::is_fully_initialized(), "should be complete"); aoqi@0: aoqi@0: oop o = Universe::null_ptr_exception_instance(); aoqi@0: assert(o != NULL, "should have been initialized"); aoqi@0: _NullPointerException_instance = get_object(o)->as_instance(); aoqi@0: o = Universe::arithmetic_exception_instance(); aoqi@0: assert(o != NULL, "should have been initialized"); aoqi@0: _ArithmeticException_instance = get_object(o)->as_instance(); aoqi@0: aoqi@0: _ArrayIndexOutOfBoundsException_instance = NULL; aoqi@0: _ArrayStoreException_instance = NULL; aoqi@0: _ClassCastException_instance = NULL; aoqi@0: _the_null_string = NULL; aoqi@0: _the_min_jint_string = NULL; aoqi@0: } aoqi@0: zgu@7074: ciEnv::ciEnv(Arena* arena) : _ciEnv_arena(mtCompiler) { aoqi@0: ASSERT_IN_VM; aoqi@0: aoqi@0: // Set up ciEnv::current immediately, for the sake of ciObjectFactory, etc. aoqi@0: CompilerThread* current_thread = CompilerThread::current(); aoqi@0: assert(current_thread->env() == NULL, "must be"); aoqi@0: current_thread->set_env(this); aoqi@0: assert(ciEnv::current() == this, "sanity"); aoqi@0: aoqi@0: _oop_recorder = NULL; aoqi@0: _debug_info = NULL; aoqi@0: _dependencies = NULL; aoqi@0: _failure_reason = NULL; aoqi@0: _compilable = MethodCompilable_never; aoqi@0: _break_at_compile = false; aoqi@0: _compiler_data = NULL; aoqi@0: #ifndef PRODUCT aoqi@0: assert(firstEnv, "must be first"); aoqi@0: firstEnv = false; aoqi@0: #endif /* !PRODUCT */ aoqi@0: aoqi@0: _system_dictionary_modification_counter = 0; aoqi@0: _num_inlined_bytecodes = 0; aoqi@0: _task = NULL; aoqi@0: _log = NULL; aoqi@0: aoqi@0: // Temporary buffer for creating symbols and such. aoqi@0: _name_buffer = NULL; aoqi@0: _name_buffer_len = 0; aoqi@0: aoqi@0: _arena = arena; aoqi@0: _factory = new (_arena) ciObjectFactory(_arena, 128); aoqi@0: aoqi@0: // Preload commonly referenced system ciObjects. aoqi@0: aoqi@0: // During VM initialization, these instances have not yet been created. aoqi@0: // Assertions ensure that these instances are not accessed before aoqi@0: // their initialization. aoqi@0: aoqi@0: assert(Universe::is_fully_initialized(), "must be"); aoqi@0: aoqi@0: _NullPointerException_instance = NULL; aoqi@0: _ArithmeticException_instance = NULL; aoqi@0: _ArrayIndexOutOfBoundsException_instance = NULL; aoqi@0: _ArrayStoreException_instance = NULL; aoqi@0: _ClassCastException_instance = NULL; aoqi@0: _the_null_string = NULL; aoqi@0: _the_min_jint_string = NULL; aoqi@0: } aoqi@0: aoqi@0: ciEnv::~ciEnv() { aoqi@0: CompilerThread* current_thread = CompilerThread::current(); aoqi@0: _factory->remove_symbols(); aoqi@0: // Need safepoint to clear the env on the thread. RedefineClasses might aoqi@0: // be reading it. aoqi@0: GUARDED_VM_ENTRY(current_thread->set_env(NULL);) aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // Cache Jvmti state aoqi@0: void ciEnv::cache_jvmti_state() { aoqi@0: VM_ENTRY_MARK; aoqi@0: // Get Jvmti capabilities under lock to get consistant values. aoqi@0: MutexLocker mu(JvmtiThreadState_lock); aoqi@0: _jvmti_can_hotswap_or_post_breakpoint = JvmtiExport::can_hotswap_or_post_breakpoint(); aoqi@0: _jvmti_can_access_local_variables = JvmtiExport::can_access_local_variables(); aoqi@0: _jvmti_can_post_on_exceptions = JvmtiExport::can_post_on_exceptions(); aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // Cache DTrace flags aoqi@0: void ciEnv::cache_dtrace_flags() { aoqi@0: // Need lock? aoqi@0: _dtrace_extended_probes = ExtendedDTraceProbes; aoqi@0: if (_dtrace_extended_probes) { aoqi@0: _dtrace_monitor_probes = true; aoqi@0: _dtrace_method_probes = true; aoqi@0: _dtrace_alloc_probes = true; aoqi@0: } else { aoqi@0: _dtrace_monitor_probes = DTraceMonitorProbes; aoqi@0: _dtrace_method_probes = DTraceMethodProbes; aoqi@0: _dtrace_alloc_probes = DTraceAllocProbes; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // helper for lazy exception creation aoqi@0: ciInstance* ciEnv::get_or_create_exception(jobject& handle, Symbol* name) { aoqi@0: VM_ENTRY_MARK; aoqi@0: if (handle == NULL) { aoqi@0: // Cf. universe.cpp, creation of Universe::_null_ptr_exception_instance. aoqi@0: Klass* k = SystemDictionary::find(name, Handle(), Handle(), THREAD); aoqi@0: jobject objh = NULL; aoqi@0: if (!HAS_PENDING_EXCEPTION && k != NULL) { aoqi@0: oop obj = InstanceKlass::cast(k)->allocate_instance(THREAD); aoqi@0: if (!HAS_PENDING_EXCEPTION) aoqi@0: objh = JNIHandles::make_global(obj); aoqi@0: } aoqi@0: if (HAS_PENDING_EXCEPTION) { aoqi@0: CLEAR_PENDING_EXCEPTION; aoqi@0: } else { aoqi@0: handle = objh; aoqi@0: } aoqi@0: } aoqi@0: oop obj = JNIHandles::resolve(handle); aoqi@0: return obj == NULL? NULL: get_object(obj)->as_instance(); aoqi@0: } aoqi@0: aoqi@0: ciInstance* ciEnv::ArrayIndexOutOfBoundsException_instance() { aoqi@0: if (_ArrayIndexOutOfBoundsException_instance == NULL) { aoqi@0: _ArrayIndexOutOfBoundsException_instance aoqi@0: = get_or_create_exception(_ArrayIndexOutOfBoundsException_handle, aoqi@0: vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); aoqi@0: } aoqi@0: return _ArrayIndexOutOfBoundsException_instance; aoqi@0: } aoqi@0: ciInstance* ciEnv::ArrayStoreException_instance() { aoqi@0: if (_ArrayStoreException_instance == NULL) { aoqi@0: _ArrayStoreException_instance aoqi@0: = get_or_create_exception(_ArrayStoreException_handle, aoqi@0: vmSymbols::java_lang_ArrayStoreException()); aoqi@0: } aoqi@0: return _ArrayStoreException_instance; aoqi@0: } aoqi@0: ciInstance* ciEnv::ClassCastException_instance() { aoqi@0: if (_ClassCastException_instance == NULL) { aoqi@0: _ClassCastException_instance aoqi@0: = get_or_create_exception(_ClassCastException_handle, aoqi@0: vmSymbols::java_lang_ClassCastException()); aoqi@0: } aoqi@0: return _ClassCastException_instance; aoqi@0: } aoqi@0: aoqi@0: ciInstance* ciEnv::the_null_string() { aoqi@0: if (_the_null_string == NULL) { aoqi@0: VM_ENTRY_MARK; aoqi@0: _the_null_string = get_object(Universe::the_null_string())->as_instance(); aoqi@0: } aoqi@0: return _the_null_string; aoqi@0: } aoqi@0: aoqi@0: ciInstance* ciEnv::the_min_jint_string() { aoqi@0: if (_the_min_jint_string == NULL) { aoqi@0: VM_ENTRY_MARK; aoqi@0: _the_min_jint_string = get_object(Universe::the_min_jint_string())->as_instance(); aoqi@0: } aoqi@0: return _the_min_jint_string; aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::get_method_from_handle aoqi@0: ciMethod* ciEnv::get_method_from_handle(Method* method) { aoqi@0: VM_ENTRY_MARK; aoqi@0: return get_metadata(method)->as_method(); aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::array_element_offset_in_bytes aoqi@0: int ciEnv::array_element_offset_in_bytes(ciArray* a_h, ciObject* o_h) { aoqi@0: VM_ENTRY_MARK; aoqi@0: objArrayOop a = (objArrayOop)a_h->get_oop(); aoqi@0: assert(a->is_objArray(), ""); aoqi@0: int length = a->length(); aoqi@0: oop o = o_h->get_oop(); aoqi@0: for (int i = 0; i < length; i++) { aoqi@0: if (a->obj_at(i) == o) return i; aoqi@0: } aoqi@0: return -1; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::check_klass_accessiblity aoqi@0: // aoqi@0: // Note: the logic of this method should mirror the logic of aoqi@0: // ConstantPool::verify_constant_pool_resolve. aoqi@0: bool ciEnv::check_klass_accessibility(ciKlass* accessing_klass, aoqi@0: Klass* resolved_klass) { aoqi@0: if (accessing_klass == NULL || !accessing_klass->is_loaded()) { aoqi@0: return true; aoqi@0: } aoqi@0: if (accessing_klass->is_obj_array_klass()) { aoqi@0: accessing_klass = accessing_klass->as_obj_array_klass()->base_element_klass(); aoqi@0: } aoqi@0: if (!accessing_klass->is_instance_klass()) { aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: if (resolved_klass->oop_is_objArray()) { aoqi@0: // Find the element klass, if this is an array. aoqi@0: resolved_klass = ObjArrayKlass::cast(resolved_klass)->bottom_klass(); aoqi@0: } aoqi@0: if (resolved_klass->oop_is_instance()) { aoqi@0: return Reflection::verify_class_access(accessing_klass->get_Klass(), aoqi@0: resolved_klass, aoqi@0: true); aoqi@0: } aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::get_klass_by_name_impl aoqi@0: ciKlass* ciEnv::get_klass_by_name_impl(ciKlass* accessing_klass, aoqi@0: constantPoolHandle cpool, aoqi@0: ciSymbol* name, aoqi@0: bool require_local) { aoqi@0: ASSERT_IN_VM; aoqi@0: EXCEPTION_CONTEXT; aoqi@0: aoqi@0: // Now we need to check the SystemDictionary aoqi@0: Symbol* sym = name->get_symbol(); aoqi@0: if (sym->byte_at(0) == 'L' && aoqi@0: sym->byte_at(sym->utf8_length()-1) == ';') { aoqi@0: // This is a name from a signature. Strip off the trimmings. aoqi@0: // Call recursive to keep scope of strippedsym. aoqi@0: TempNewSymbol strippedsym = SymbolTable::new_symbol(sym->as_utf8()+1, aoqi@0: sym->utf8_length()-2, aoqi@0: KILL_COMPILE_ON_FATAL_(_unloaded_ciinstance_klass)); aoqi@0: ciSymbol* strippedname = get_symbol(strippedsym); aoqi@0: return get_klass_by_name_impl(accessing_klass, cpool, strippedname, require_local); aoqi@0: } aoqi@0: aoqi@0: // Check for prior unloaded klass. The SystemDictionary's answers aoqi@0: // can vary over time but the compiler needs consistency. aoqi@0: ciKlass* unloaded_klass = check_get_unloaded_klass(accessing_klass, name); aoqi@0: if (unloaded_klass != NULL) { aoqi@0: if (require_local) return NULL; aoqi@0: return unloaded_klass; aoqi@0: } aoqi@0: aoqi@0: Handle loader(THREAD, (oop)NULL); aoqi@0: Handle domain(THREAD, (oop)NULL); aoqi@0: if (accessing_klass != NULL) { aoqi@0: loader = Handle(THREAD, accessing_klass->loader()); aoqi@0: domain = Handle(THREAD, accessing_klass->protection_domain()); aoqi@0: } aoqi@0: aoqi@0: // setup up the proper type to return on OOM aoqi@0: ciKlass* fail_type; aoqi@0: if (sym->byte_at(0) == '[') { aoqi@0: fail_type = _unloaded_ciobjarrayklass; aoqi@0: } else { aoqi@0: fail_type = _unloaded_ciinstance_klass; aoqi@0: } aoqi@0: KlassHandle found_klass; aoqi@0: { aoqi@0: ttyUnlocker ttyul; // release tty lock to avoid ordering problems aoqi@0: MutexLocker ml(Compile_lock); aoqi@0: Klass* kls; aoqi@0: if (!require_local) { aoqi@0: kls = SystemDictionary::find_constrained_instance_or_array_klass(sym, loader, aoqi@0: KILL_COMPILE_ON_FATAL_(fail_type)); aoqi@0: } else { aoqi@0: kls = SystemDictionary::find_instance_or_array_klass(sym, loader, domain, aoqi@0: KILL_COMPILE_ON_FATAL_(fail_type)); aoqi@0: } aoqi@0: found_klass = KlassHandle(THREAD, kls); aoqi@0: } aoqi@0: aoqi@0: // If we fail to find an array klass, look again for its element type. aoqi@0: // The element type may be available either locally or via constraints. aoqi@0: // In either case, if we can find the element type in the system dictionary, aoqi@0: // we must build an array type around it. The CI requires array klasses aoqi@0: // to be loaded if their element klasses are loaded, except when memory aoqi@0: // is exhausted. aoqi@0: if (sym->byte_at(0) == '[' && aoqi@0: (sym->byte_at(1) == '[' || sym->byte_at(1) == 'L')) { aoqi@0: // We have an unloaded array. aoqi@0: // Build it on the fly if the element class exists. aoqi@0: TempNewSymbol elem_sym = SymbolTable::new_symbol(sym->as_utf8()+1, aoqi@0: sym->utf8_length()-1, aoqi@0: KILL_COMPILE_ON_FATAL_(fail_type)); aoqi@0: aoqi@0: // Get element ciKlass recursively. aoqi@0: ciKlass* elem_klass = aoqi@0: get_klass_by_name_impl(accessing_klass, aoqi@0: cpool, aoqi@0: get_symbol(elem_sym), aoqi@0: require_local); aoqi@0: if (elem_klass != NULL && elem_klass->is_loaded()) { aoqi@0: // Now make an array for it aoqi@0: return ciObjArrayKlass::make_impl(elem_klass); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: if (found_klass() == NULL && !cpool.is_null() && cpool->has_preresolution()) { aoqi@0: // Look inside the constant pool for pre-resolved class entries. aoqi@0: for (int i = cpool->length() - 1; i >= 1; i--) { aoqi@0: if (cpool->tag_at(i).is_klass()) { aoqi@0: Klass* kls = cpool->resolved_klass_at(i); aoqi@0: if (kls->name() == sym) { aoqi@0: found_klass = KlassHandle(THREAD, kls); aoqi@0: break; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: if (found_klass() != NULL) { aoqi@0: // Found it. Build a CI handle. aoqi@0: return get_klass(found_klass()); aoqi@0: } aoqi@0: aoqi@0: if (require_local) return NULL; aoqi@0: aoqi@0: // Not yet loaded into the VM, or not governed by loader constraints. aoqi@0: // Make a CI representative for it. aoqi@0: return get_unloaded_klass(accessing_klass, name); aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::get_klass_by_name aoqi@0: ciKlass* ciEnv::get_klass_by_name(ciKlass* accessing_klass, aoqi@0: ciSymbol* klass_name, aoqi@0: bool require_local) { aoqi@0: GUARDED_VM_ENTRY(return get_klass_by_name_impl(accessing_klass, aoqi@0: constantPoolHandle(), aoqi@0: klass_name, aoqi@0: require_local);) aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::get_klass_by_index_impl aoqi@0: // aoqi@0: // Implementation of get_klass_by_index. aoqi@0: ciKlass* ciEnv::get_klass_by_index_impl(constantPoolHandle cpool, aoqi@0: int index, aoqi@0: bool& is_accessible, aoqi@0: ciInstanceKlass* accessor) { aoqi@0: EXCEPTION_CONTEXT; aoqi@0: KlassHandle klass; // = NULL; aoqi@0: Symbol* klass_name = NULL; aoqi@0: aoqi@0: if (cpool->tag_at(index).is_symbol()) { aoqi@0: klass_name = cpool->symbol_at(index); aoqi@0: } else { aoqi@0: // Check if it's resolved if it's not a symbol constant pool entry. aoqi@0: klass = KlassHandle(THREAD, ConstantPool::klass_at_if_loaded(cpool, index)); aoqi@0: aoqi@0: if (klass.is_null()) { aoqi@0: // The klass has not been inserted into the constant pool. aoqi@0: // Try to look it up by name. aoqi@0: { aoqi@0: // We have to lock the cpool to keep the oop from being resolved aoqi@0: // while we are accessing it. aoqi@0: MonitorLockerEx ml(cpool->lock()); aoqi@0: constantTag tag = cpool->tag_at(index); aoqi@0: if (tag.is_klass()) { aoqi@0: // The klass has been inserted into the constant pool aoqi@0: // very recently. aoqi@0: klass = KlassHandle(THREAD, cpool->resolved_klass_at(index)); aoqi@0: } else { aoqi@0: assert(cpool->tag_at(index).is_unresolved_klass(), "wrong tag"); aoqi@0: klass_name = cpool->unresolved_klass_at(index); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: if (klass.is_null()) { aoqi@0: // Not found in constant pool. Use the name to do the lookup. aoqi@0: ciKlass* k = get_klass_by_name_impl(accessor, aoqi@0: cpool, aoqi@0: get_symbol(klass_name), aoqi@0: false); aoqi@0: // Calculate accessibility the hard way. aoqi@0: if (!k->is_loaded()) { aoqi@0: is_accessible = false; aoqi@0: } else if (k->loader() != accessor->loader() && aoqi@0: get_klass_by_name_impl(accessor, cpool, k->name(), true) == NULL) { aoqi@0: // Loaded only remotely. Not linked yet. aoqi@0: is_accessible = false; aoqi@0: } else { aoqi@0: // Linked locally, and we must also check public/private, etc. aoqi@0: is_accessible = check_klass_accessibility(accessor, k->get_Klass()); aoqi@0: } aoqi@0: return k; aoqi@0: } aoqi@0: aoqi@0: // Check for prior unloaded klass. The SystemDictionary's answers aoqi@0: // can vary over time but the compiler needs consistency. aoqi@0: ciSymbol* name = get_symbol(klass()->name()); aoqi@0: ciKlass* unloaded_klass = check_get_unloaded_klass(accessor, name); aoqi@0: if (unloaded_klass != NULL) { aoqi@0: is_accessible = false; aoqi@0: return unloaded_klass; aoqi@0: } aoqi@0: aoqi@0: // It is known to be accessible, since it was found in the constant pool. aoqi@0: is_accessible = true; aoqi@0: return get_klass(klass()); aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::get_klass_by_index aoqi@0: // aoqi@0: // Get a klass from the constant pool. aoqi@0: ciKlass* ciEnv::get_klass_by_index(constantPoolHandle cpool, aoqi@0: int index, aoqi@0: bool& is_accessible, aoqi@0: ciInstanceKlass* accessor) { aoqi@0: GUARDED_VM_ENTRY(return get_klass_by_index_impl(cpool, index, is_accessible, accessor);) aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::get_constant_by_index_impl aoqi@0: // aoqi@0: // Implementation of get_constant_by_index(). aoqi@0: ciConstant ciEnv::get_constant_by_index_impl(constantPoolHandle cpool, aoqi@0: int pool_index, int cache_index, aoqi@0: ciInstanceKlass* accessor) { aoqi@0: bool ignore_will_link; aoqi@0: EXCEPTION_CONTEXT; aoqi@0: int index = pool_index; aoqi@0: if (cache_index >= 0) { aoqi@0: assert(index < 0, "only one kind of index at a time"); aoqi@0: oop obj = cpool->resolved_references()->obj_at(cache_index); aoqi@0: if (obj != NULL) { aoqi@0: ciObject* ciobj = get_object(obj); vlivanov@7288: if (ciobj->is_array()) { vlivanov@7288: return ciConstant(T_ARRAY, ciobj); vlivanov@7288: } else { vlivanov@7288: assert(ciobj->is_instance(), "should be an instance"); vlivanov@7288: return ciConstant(T_OBJECT, ciobj); vlivanov@7288: } aoqi@0: } aoqi@0: index = cpool->object_to_cp_index(cache_index); aoqi@0: } aoqi@0: constantTag tag = cpool->tag_at(index); aoqi@0: if (tag.is_int()) { aoqi@0: return ciConstant(T_INT, (jint)cpool->int_at(index)); aoqi@0: } else if (tag.is_long()) { aoqi@0: return ciConstant((jlong)cpool->long_at(index)); aoqi@0: } else if (tag.is_float()) { aoqi@0: return ciConstant((jfloat)cpool->float_at(index)); aoqi@0: } else if (tag.is_double()) { aoqi@0: return ciConstant((jdouble)cpool->double_at(index)); aoqi@0: } else if (tag.is_string()) { aoqi@0: oop string = NULL; aoqi@0: assert(cache_index >= 0, "should have a cache index"); aoqi@0: if (cpool->is_pseudo_string_at(index)) { aoqi@0: string = cpool->pseudo_string_at(index, cache_index); aoqi@0: } else { aoqi@0: string = cpool->string_at(index, cache_index, THREAD); aoqi@0: if (HAS_PENDING_EXCEPTION) { aoqi@0: CLEAR_PENDING_EXCEPTION; aoqi@0: record_out_of_memory_failure(); aoqi@0: return ciConstant(); aoqi@0: } aoqi@0: } aoqi@0: ciObject* constant = get_object(string); vlivanov@7288: if (constant->is_array()) { vlivanov@7288: return ciConstant(T_ARRAY, constant); vlivanov@7288: } else { vlivanov@7288: assert (constant->is_instance(), "must be an instance, or not? "); vlivanov@7288: return ciConstant(T_OBJECT, constant); vlivanov@7288: } aoqi@0: } else if (tag.is_klass() || tag.is_unresolved_klass()) { aoqi@0: // 4881222: allow ldc to take a class type aoqi@0: ciKlass* klass = get_klass_by_index_impl(cpool, index, ignore_will_link, accessor); aoqi@0: if (HAS_PENDING_EXCEPTION) { aoqi@0: CLEAR_PENDING_EXCEPTION; aoqi@0: record_out_of_memory_failure(); aoqi@0: return ciConstant(); aoqi@0: } aoqi@0: assert (klass->is_instance_klass() || klass->is_array_klass(), aoqi@0: "must be an instance or array klass "); aoqi@0: return ciConstant(T_OBJECT, klass->java_mirror()); aoqi@0: } else if (tag.is_method_type()) { aoqi@0: // must execute Java code to link this CP entry into cache[i].f1 aoqi@0: ciSymbol* signature = get_symbol(cpool->method_type_signature_at(index)); aoqi@0: ciObject* ciobj = get_unloaded_method_type_constant(signature); aoqi@0: return ciConstant(T_OBJECT, ciobj); aoqi@0: } else if (tag.is_method_handle()) { aoqi@0: // must execute Java code to link this CP entry into cache[i].f1 aoqi@0: int ref_kind = cpool->method_handle_ref_kind_at(index); aoqi@0: int callee_index = cpool->method_handle_klass_index_at(index); aoqi@0: ciKlass* callee = get_klass_by_index_impl(cpool, callee_index, ignore_will_link, accessor); aoqi@0: ciSymbol* name = get_symbol(cpool->method_handle_name_ref_at(index)); aoqi@0: ciSymbol* signature = get_symbol(cpool->method_handle_signature_ref_at(index)); aoqi@0: ciObject* ciobj = get_unloaded_method_handle_constant(callee, name, signature, ref_kind); aoqi@0: return ciConstant(T_OBJECT, ciobj); aoqi@0: } else { aoqi@0: ShouldNotReachHere(); aoqi@0: return ciConstant(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::get_constant_by_index aoqi@0: // aoqi@0: // Pull a constant out of the constant pool. How appropriate. aoqi@0: // aoqi@0: // Implementation note: this query is currently in no way cached. aoqi@0: ciConstant ciEnv::get_constant_by_index(constantPoolHandle cpool, aoqi@0: int pool_index, int cache_index, aoqi@0: ciInstanceKlass* accessor) { aoqi@0: GUARDED_VM_ENTRY(return get_constant_by_index_impl(cpool, pool_index, cache_index, accessor);) aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::get_field_by_index_impl aoqi@0: // aoqi@0: // Implementation of get_field_by_index. aoqi@0: // aoqi@0: // Implementation note: the results of field lookups are cached aoqi@0: // in the accessor klass. aoqi@0: ciField* ciEnv::get_field_by_index_impl(ciInstanceKlass* accessor, aoqi@0: int index) { aoqi@0: ciConstantPoolCache* cache = accessor->field_cache(); aoqi@0: if (cache == NULL) { aoqi@0: ciField* field = new (arena()) ciField(accessor, index); aoqi@0: return field; aoqi@0: } else { aoqi@0: ciField* field = (ciField*)cache->get(index); aoqi@0: if (field == NULL) { aoqi@0: field = new (arena()) ciField(accessor, index); aoqi@0: cache->insert(index, field); aoqi@0: } aoqi@0: return field; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::get_field_by_index aoqi@0: // aoqi@0: // Get a field by index from a klass's constant pool. aoqi@0: ciField* ciEnv::get_field_by_index(ciInstanceKlass* accessor, aoqi@0: int index) { aoqi@0: GUARDED_VM_ENTRY(return get_field_by_index_impl(accessor, index);) aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::lookup_method aoqi@0: // aoqi@0: // Perform an appropriate method lookup based on accessor, holder, aoqi@0: // name, signature, and bytecode. aoqi@0: Method* ciEnv::lookup_method(InstanceKlass* accessor, aoqi@0: InstanceKlass* holder, aoqi@0: Symbol* name, aoqi@0: Symbol* sig, aoqi@0: Bytecodes::Code bc) { aoqi@0: EXCEPTION_CONTEXT; aoqi@0: KlassHandle h_accessor(THREAD, accessor); aoqi@0: KlassHandle h_holder(THREAD, holder); aoqi@0: LinkResolver::check_klass_accessability(h_accessor, h_holder, KILL_COMPILE_ON_FATAL_(NULL)); aoqi@0: methodHandle dest_method; aoqi@0: switch (bc) { aoqi@0: case Bytecodes::_invokestatic: aoqi@0: dest_method = aoqi@0: LinkResolver::resolve_static_call_or_null(h_holder, name, sig, h_accessor); aoqi@0: break; aoqi@0: case Bytecodes::_invokespecial: aoqi@0: dest_method = aoqi@0: LinkResolver::resolve_special_call_or_null(h_holder, name, sig, h_accessor); aoqi@0: break; aoqi@0: case Bytecodes::_invokeinterface: aoqi@0: dest_method = aoqi@0: LinkResolver::linktime_resolve_interface_method_or_null(h_holder, name, sig, aoqi@0: h_accessor, true); aoqi@0: break; aoqi@0: case Bytecodes::_invokevirtual: aoqi@0: dest_method = aoqi@0: LinkResolver::linktime_resolve_virtual_method_or_null(h_holder, name, sig, aoqi@0: h_accessor, true); aoqi@0: break; aoqi@0: default: ShouldNotReachHere(); aoqi@0: } aoqi@0: aoqi@0: return dest_method(); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::get_method_by_index_impl aoqi@0: ciMethod* ciEnv::get_method_by_index_impl(constantPoolHandle cpool, aoqi@0: int index, Bytecodes::Code bc, aoqi@0: ciInstanceKlass* accessor) { aoqi@0: if (bc == Bytecodes::_invokedynamic) { aoqi@0: ConstantPoolCacheEntry* cpce = cpool->invokedynamic_cp_cache_entry_at(index); aoqi@0: bool is_resolved = !cpce->is_f1_null(); aoqi@0: // FIXME: code generation could allow for null (unlinked) call site aoqi@0: // The call site could be made patchable as follows: aoqi@0: // Load the appendix argument from the constant pool. aoqi@0: // Test the appendix argument and jump to a known deopt routine if it is null. aoqi@0: // Jump through a patchable call site, which is initially a deopt routine. aoqi@0: // Patch the call site to the nmethod entry point of the static compiled lambda form. aoqi@0: // As with other two-component call sites, both values must be independently verified. aoqi@0: aoqi@0: if (is_resolved) { aoqi@0: // Get the invoker Method* from the constant pool. aoqi@0: // (The appendix argument, if any, will be noted in the method's signature.) aoqi@0: Method* adapter = cpce->f1_as_method(); aoqi@0: return get_method(adapter); aoqi@0: } aoqi@0: aoqi@0: // Fake a method that is equivalent to a declared method. aoqi@0: ciInstanceKlass* holder = get_instance_klass(SystemDictionary::MethodHandle_klass()); aoqi@0: ciSymbol* name = ciSymbol::invokeBasic_name(); aoqi@0: ciSymbol* signature = get_symbol(cpool->signature_ref_at(index)); aoqi@0: return get_unloaded_method(holder, name, signature, accessor); aoqi@0: } else { aoqi@0: const int holder_index = cpool->klass_ref_index_at(index); aoqi@0: bool holder_is_accessible; aoqi@0: ciKlass* holder = get_klass_by_index_impl(cpool, holder_index, holder_is_accessible, accessor); aoqi@0: ciInstanceKlass* declared_holder = get_instance_klass_for_declared_method_holder(holder); aoqi@0: aoqi@0: // Get the method's name and signature. aoqi@0: Symbol* name_sym = cpool->name_ref_at(index); aoqi@0: Symbol* sig_sym = cpool->signature_ref_at(index); aoqi@0: aoqi@0: if (cpool->has_preresolution() aoqi@0: || (holder == ciEnv::MethodHandle_klass() && aoqi@0: MethodHandles::is_signature_polymorphic_name(holder->get_Klass(), name_sym))) { aoqi@0: // Short-circuit lookups for JSR 292-related call sites. aoqi@0: // That is, do not rely only on name-based lookups, because they may fail aoqi@0: // if the names are not resolvable in the boot class loader (7056328). aoqi@0: switch (bc) { aoqi@0: case Bytecodes::_invokevirtual: aoqi@0: case Bytecodes::_invokeinterface: aoqi@0: case Bytecodes::_invokespecial: aoqi@0: case Bytecodes::_invokestatic: aoqi@0: { aoqi@0: Method* m = ConstantPool::method_at_if_loaded(cpool, index); aoqi@0: if (m != NULL) { aoqi@0: return get_method(m); aoqi@0: } aoqi@0: } aoqi@0: break; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: if (holder_is_accessible) { // Our declared holder is loaded. aoqi@0: InstanceKlass* lookup = declared_holder->get_instanceKlass(); aoqi@0: Method* m = lookup_method(accessor->get_instanceKlass(), lookup, name_sym, sig_sym, bc); aoqi@0: if (m != NULL && aoqi@0: (bc == Bytecodes::_invokestatic aoqi@0: ? m->method_holder()->is_not_initialized() aoqi@0: : !m->method_holder()->is_loaded())) { aoqi@0: m = NULL; aoqi@0: } aoqi@0: #ifdef ASSERT aoqi@0: if (m != NULL && ReplayCompiles && !ciReplay::is_loaded(m)) { aoqi@0: m = NULL; aoqi@0: } aoqi@0: #endif aoqi@0: if (m != NULL) { aoqi@0: // We found the method. aoqi@0: return get_method(m); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Either the declared holder was not loaded, or the method could aoqi@0: // not be found. Create a dummy ciMethod to represent the failed aoqi@0: // lookup. aoqi@0: ciSymbol* name = get_symbol(name_sym); aoqi@0: ciSymbol* signature = get_symbol(sig_sym); aoqi@0: return get_unloaded_method(declared_holder, name, signature, accessor); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::get_instance_klass_for_declared_method_holder aoqi@0: ciInstanceKlass* ciEnv::get_instance_klass_for_declared_method_holder(ciKlass* method_holder) { aoqi@0: // For the case of .clone(), the method holder can be a ciArrayKlass aoqi@0: // instead of a ciInstanceKlass. For that case simply pretend that the aoqi@0: // declared holder is Object.clone since that's where the call will bottom out. aoqi@0: // A more correct fix would trickle out through many interfaces in CI, aoqi@0: // requiring ciInstanceKlass* to become ciKlass* and many more places would aoqi@0: // require checks to make sure the expected type was found. Given that this aoqi@0: // only occurs for clone() the more extensive fix seems like overkill so aoqi@0: // instead we simply smear the array type into Object. aoqi@0: guarantee(method_holder != NULL, "no method holder"); aoqi@0: if (method_holder->is_instance_klass()) { aoqi@0: return method_holder->as_instance_klass(); aoqi@0: } else if (method_holder->is_array_klass()) { aoqi@0: return current()->Object_klass(); aoqi@0: } else { aoqi@0: ShouldNotReachHere(); aoqi@0: } aoqi@0: return NULL; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::get_method_by_index aoqi@0: ciMethod* ciEnv::get_method_by_index(constantPoolHandle cpool, aoqi@0: int index, Bytecodes::Code bc, aoqi@0: ciInstanceKlass* accessor) { aoqi@0: GUARDED_VM_ENTRY(return get_method_by_index_impl(cpool, index, bc, accessor);) aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::name_buffer aoqi@0: char *ciEnv::name_buffer(int req_len) { aoqi@0: if (_name_buffer_len < req_len) { aoqi@0: if (_name_buffer == NULL) { aoqi@0: _name_buffer = (char*)arena()->Amalloc(sizeof(char)*req_len); aoqi@0: _name_buffer_len = req_len; aoqi@0: } else { aoqi@0: _name_buffer = aoqi@0: (char*)arena()->Arealloc(_name_buffer, _name_buffer_len, req_len); aoqi@0: _name_buffer_len = req_len; aoqi@0: } aoqi@0: } aoqi@0: return _name_buffer; aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::is_in_vm aoqi@0: bool ciEnv::is_in_vm() { aoqi@0: return JavaThread::current()->thread_state() == _thread_in_vm; aoqi@0: } aoqi@0: aoqi@0: bool ciEnv::system_dictionary_modification_counter_changed() { aoqi@0: return _system_dictionary_modification_counter != SystemDictionary::number_of_modifications(); aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::validate_compile_task_dependencies aoqi@0: // aoqi@0: // Check for changes during compilation (e.g. class loads, evolution, aoqi@0: // breakpoints, call site invalidation). aoqi@0: void ciEnv::validate_compile_task_dependencies(ciMethod* target) { aoqi@0: if (failing()) return; // no need for further checks aoqi@0: aoqi@0: // First, check non-klass dependencies as we might return early and aoqi@0: // not check klass dependencies if the system dictionary aoqi@0: // modification counter hasn't changed (see below). aoqi@0: for (Dependencies::DepStream deps(dependencies()); deps.next(); ) { aoqi@0: if (deps.is_klass_type()) continue; // skip klass dependencies aoqi@0: Klass* witness = deps.check_dependency(); aoqi@0: if (witness != NULL) { aoqi@0: record_failure("invalid non-klass dependency"); aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Klass dependencies must be checked when the system dictionary aoqi@0: // changes. If logging is enabled all violated dependences will be aoqi@0: // recorded in the log. In debug mode check dependencies even if aoqi@0: // the system dictionary hasn't changed to verify that no invalid aoqi@0: // dependencies were inserted. Any violated dependences in this aoqi@0: // case are dumped to the tty. aoqi@0: bool counter_changed = system_dictionary_modification_counter_changed(); aoqi@0: aoqi@0: bool verify_deps = trueInDebug; aoqi@0: if (!counter_changed && !verify_deps) return; aoqi@0: aoqi@0: int klass_violations = 0; aoqi@0: for (Dependencies::DepStream deps(dependencies()); deps.next(); ) { aoqi@0: if (!deps.is_klass_type()) continue; // skip non-klass dependencies aoqi@0: Klass* witness = deps.check_dependency(); aoqi@0: if (witness != NULL) { aoqi@0: klass_violations++; aoqi@0: if (!counter_changed) { aoqi@0: // Dependence failed but counter didn't change. Log a message aoqi@0: // describing what failed and allow the assert at the end to aoqi@0: // trigger. aoqi@0: deps.print_dependency(witness); aoqi@0: } else if (xtty == NULL) { aoqi@0: // If we're not logging then a single violation is sufficient, aoqi@0: // otherwise we want to log all the dependences which were aoqi@0: // violated. aoqi@0: break; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: if (klass_violations != 0) { aoqi@0: #ifdef ASSERT aoqi@0: if (!counter_changed && !PrintCompilation) { aoqi@0: // Print out the compile task that failed aoqi@0: _task->print_line(); aoqi@0: } aoqi@0: #endif aoqi@0: assert(counter_changed, "failed dependencies, but counter didn't change"); aoqi@0: record_failure("concurrent class loading"); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::register_method aoqi@0: void ciEnv::register_method(ciMethod* target, aoqi@0: int entry_bci, aoqi@0: CodeOffsets* offsets, aoqi@0: int orig_pc_offset, aoqi@0: CodeBuffer* code_buffer, aoqi@0: int frame_words, aoqi@0: OopMapSet* oop_map_set, aoqi@0: ExceptionHandlerTable* handler_table, aoqi@0: ImplicitExceptionTable* inc_table, aoqi@0: AbstractCompiler* compiler, aoqi@0: int comp_level, aoqi@0: bool has_unsafe_access, aoqi@0: bool has_wide_vectors, aoqi@0: RTMState rtm_state) { aoqi@0: VM_ENTRY_MARK; aoqi@0: nmethod* nm = NULL; aoqi@0: { aoqi@0: // To prevent compile queue updates. aoqi@0: MutexLocker locker(MethodCompileQueue_lock, THREAD); aoqi@0: aoqi@0: // Prevent SystemDictionary::add_to_hierarchy from running aoqi@0: // and invalidating our dependencies until we install this method. aoqi@0: // No safepoints are allowed. Otherwise, class redefinition can occur in between. aoqi@0: MutexLocker ml(Compile_lock); aoqi@0: No_Safepoint_Verifier nsv; aoqi@0: aoqi@0: // Change in Jvmti state may invalidate compilation. aoqi@0: if (!failing() && aoqi@0: ( (!jvmti_can_hotswap_or_post_breakpoint() && aoqi@0: JvmtiExport::can_hotswap_or_post_breakpoint()) || aoqi@0: (!jvmti_can_access_local_variables() && aoqi@0: JvmtiExport::can_access_local_variables()) || aoqi@0: (!jvmti_can_post_on_exceptions() && aoqi@0: JvmtiExport::can_post_on_exceptions()) )) { aoqi@0: record_failure("Jvmti state change invalidated dependencies"); aoqi@0: } aoqi@0: aoqi@0: // Change in DTrace flags may invalidate compilation. aoqi@0: if (!failing() && aoqi@0: ( (!dtrace_extended_probes() && ExtendedDTraceProbes) || aoqi@0: (!dtrace_method_probes() && DTraceMethodProbes) || aoqi@0: (!dtrace_alloc_probes() && DTraceAllocProbes) )) { aoqi@0: record_failure("DTrace flags change invalidated dependencies"); aoqi@0: } aoqi@0: aoqi@0: if (!failing()) { aoqi@0: if (log() != NULL) { aoqi@0: // Log the dependencies which this compilation declares. aoqi@0: dependencies()->log_all_dependencies(); aoqi@0: } aoqi@0: aoqi@0: // Encode the dependencies now, so we can check them right away. aoqi@0: dependencies()->encode_content_bytes(); aoqi@0: aoqi@0: // Check for {class loads, evolution, breakpoints, ...} during compilation aoqi@0: validate_compile_task_dependencies(target); aoqi@0: } aoqi@0: aoqi@0: methodHandle method(THREAD, target->get_Method()); aoqi@0: aoqi@0: #if INCLUDE_RTM_OPT aoqi@0: if (!failing() && (rtm_state != NoRTM) && aoqi@0: (method()->method_data() != NULL) && aoqi@0: (method()->method_data()->rtm_state() != rtm_state)) { aoqi@0: // Preemptive decompile if rtm state was changed. aoqi@0: record_failure("RTM state change invalidated rtm code"); aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: if (failing()) { aoqi@0: // While not a true deoptimization, it is a preemptive decompile. aoqi@0: MethodData* mdo = method()->method_data(); aoqi@0: if (mdo != NULL) { aoqi@0: mdo->inc_decompile_count(); aoqi@0: } aoqi@0: aoqi@0: // All buffers in the CodeBuffer are allocated in the CodeCache. aoqi@0: // If the code buffer is created on each compile attempt aoqi@0: // as in C2, then it must be freed. aoqi@0: code_buffer->free_blob(); aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: assert(offsets->value(CodeOffsets::Deopt) != -1, "must have deopt entry"); aoqi@0: assert(offsets->value(CodeOffsets::Exceptions) != -1, "must have exception entry"); aoqi@0: aoqi@0: nm = nmethod::new_nmethod(method, aoqi@0: compile_id(), aoqi@0: entry_bci, aoqi@0: offsets, aoqi@0: orig_pc_offset, aoqi@0: debug_info(), dependencies(), code_buffer, aoqi@0: frame_words, oop_map_set, aoqi@0: handler_table, inc_table, aoqi@0: compiler, comp_level); aoqi@0: // Free codeBlobs aoqi@0: code_buffer->free_blob(); aoqi@0: aoqi@0: if (nm != NULL) { aoqi@0: nm->set_has_unsafe_access(has_unsafe_access); aoqi@0: nm->set_has_wide_vectors(has_wide_vectors); aoqi@0: #if INCLUDE_RTM_OPT aoqi@0: nm->set_rtm_state(rtm_state); aoqi@0: #endif aoqi@0: aoqi@0: // Record successful registration. aoqi@0: // (Put nm into the task handle *before* publishing to the Java heap.) aoqi@0: if (task() != NULL) { aoqi@0: task()->set_code(nm); aoqi@0: } aoqi@0: aoqi@0: if (entry_bci == InvocationEntryBci) { aoqi@0: if (TieredCompilation) { aoqi@0: // If there is an old version we're done with it aoqi@0: nmethod* old = method->code(); aoqi@0: if (TraceMethodReplacement && old != NULL) { aoqi@0: ResourceMark rm; aoqi@0: char *method_name = method->name_and_sig_as_C_string(); aoqi@0: tty->print_cr("Replacing method %s", method_name); aoqi@0: } aoqi@0: if (old != NULL) { aoqi@0: old->make_not_entrant(); aoqi@0: } aoqi@0: } aoqi@0: if (TraceNMethodInstalls) { aoqi@0: ResourceMark rm; aoqi@0: char *method_name = method->name_and_sig_as_C_string(); aoqi@0: ttyLocker ttyl; aoqi@0: tty->print_cr("Installing method (%d) %s ", aoqi@0: comp_level, aoqi@0: method_name); aoqi@0: } aoqi@0: // Allow the code to be executed aoqi@0: method->set_code(method, nm); aoqi@0: } else { aoqi@0: if (TraceNMethodInstalls) { aoqi@0: ResourceMark rm; aoqi@0: char *method_name = method->name_and_sig_as_C_string(); aoqi@0: ttyLocker ttyl; aoqi@0: tty->print_cr("Installing osr method (%d) %s @ %d", aoqi@0: comp_level, aoqi@0: method_name, aoqi@0: entry_bci); aoqi@0: } aoqi@0: method->method_holder()->add_osr_nmethod(nm); aoqi@0: } aoqi@0: } aoqi@0: } // safepoints are allowed again aoqi@0: aoqi@0: if (nm != NULL) { aoqi@0: // JVMTI -- compiled method notification (must be done outside lock) aoqi@0: nm->post_compiled_method_load_event(); aoqi@0: } else { aoqi@0: // The CodeCache is full. Print out warning and disable compilation. aoqi@0: record_failure("code cache is full"); aoqi@0: CompileBroker::handle_full_code_cache(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::find_system_klass aoqi@0: ciKlass* ciEnv::find_system_klass(ciSymbol* klass_name) { aoqi@0: VM_ENTRY_MARK; aoqi@0: return get_klass_by_name_impl(NULL, constantPoolHandle(), klass_name, false); aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::comp_level aoqi@0: int ciEnv::comp_level() { aoqi@0: if (task() == NULL) return CompLevel_highest_tier; aoqi@0: return task()->comp_level(); aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::compile_id aoqi@0: uint ciEnv::compile_id() { aoqi@0: if (task() == NULL) return 0; aoqi@0: return task()->compile_id(); aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::notice_inlined_method() aoqi@0: void ciEnv::notice_inlined_method(ciMethod* method) { aoqi@0: _num_inlined_bytecodes += method->code_size_for_inlining(); aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::num_inlined_bytecodes() aoqi@0: int ciEnv::num_inlined_bytecodes() const { aoqi@0: return _num_inlined_bytecodes; aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::record_failure() aoqi@0: void ciEnv::record_failure(const char* reason) { aoqi@0: if (_failure_reason == NULL) { aoqi@0: // Record the first failure reason. aoqi@0: _failure_reason = reason; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::record_method_not_compilable() aoqi@0: void ciEnv::record_method_not_compilable(const char* reason, bool all_tiers) { aoqi@0: int new_compilable = aoqi@0: all_tiers ? MethodCompilable_never : MethodCompilable_not_at_tier ; aoqi@0: aoqi@0: // Only note transitions to a worse state aoqi@0: if (new_compilable > _compilable) { aoqi@0: if (log() != NULL) { aoqi@0: if (all_tiers) { aoqi@0: log()->elem("method_not_compilable"); aoqi@0: } else { aoqi@0: log()->elem("method_not_compilable_at_tier level='%d'", aoqi@0: current()->task()->comp_level()); aoqi@0: } aoqi@0: } aoqi@0: _compilable = new_compilable; aoqi@0: aoqi@0: // Reset failure reason; this one is more important. aoqi@0: _failure_reason = NULL; aoqi@0: record_failure(reason); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::record_out_of_memory_failure() aoqi@0: void ciEnv::record_out_of_memory_failure() { aoqi@0: // If memory is low, we stop compiling methods. aoqi@0: record_method_not_compilable("out of memory"); aoqi@0: } aoqi@0: aoqi@0: ciInstance* ciEnv::unloaded_ciinstance() { aoqi@0: GUARDED_VM_ENTRY(return _factory->get_unloaded_object_constant();) aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciEnv::dump_replay_data* aoqi@0: aoqi@0: // Don't change thread state and acquire any locks. aoqi@0: // Safe to call from VM error reporter. aoqi@0: aoqi@0: void ciEnv::dump_compile_data(outputStream* out) { aoqi@0: CompileTask* task = this->task(); aoqi@0: Method* method = task->method(); aoqi@0: int entry_bci = task->osr_bci(); aoqi@0: int comp_level = task->comp_level(); aoqi@0: out->print("compile %s %s %s %d %d", aoqi@0: method->klass_name()->as_quoted_ascii(), aoqi@0: method->name()->as_quoted_ascii(), aoqi@0: method->signature()->as_quoted_ascii(), aoqi@0: entry_bci, comp_level); aoqi@0: if (compiler_data() != NULL) { aoqi@0: if (is_c2_compile(comp_level)) { // C2 or Shark aoqi@0: #ifdef COMPILER2 aoqi@0: // Dump C2 inlining data. aoqi@0: ((Compile*)compiler_data())->dump_inline_data(out); aoqi@0: #endif aoqi@0: } else if (is_c1_compile(comp_level)) { // C1 aoqi@0: #ifdef COMPILER1 aoqi@0: // Dump C1 inlining data. aoqi@0: ((Compilation*)compiler_data())->dump_inline_data(out); aoqi@0: #endif aoqi@0: } aoqi@0: } aoqi@0: out->cr(); aoqi@0: } aoqi@0: aoqi@0: void ciEnv::dump_replay_data_unsafe(outputStream* out) { aoqi@0: ResourceMark rm; aoqi@0: #if INCLUDE_JVMTI aoqi@0: out->print_cr("JvmtiExport can_access_local_variables %d", _jvmti_can_access_local_variables); aoqi@0: out->print_cr("JvmtiExport can_hotswap_or_post_breakpoint %d", _jvmti_can_hotswap_or_post_breakpoint); aoqi@0: out->print_cr("JvmtiExport can_post_on_exceptions %d", _jvmti_can_post_on_exceptions); aoqi@0: #endif // INCLUDE_JVMTI aoqi@0: aoqi@0: GrowableArray* objects = _factory->get_ci_metadata(); aoqi@0: out->print_cr("# %d ciObject found", objects->length()); aoqi@0: for (int i = 0; i < objects->length(); i++) { aoqi@0: objects->at(i)->dump_replay_data(out); aoqi@0: } aoqi@0: dump_compile_data(out); aoqi@0: out->flush(); aoqi@0: } aoqi@0: aoqi@0: void ciEnv::dump_replay_data(outputStream* out) { aoqi@0: GUARDED_VM_ENTRY( aoqi@0: MutexLocker ml(Compile_lock); aoqi@0: dump_replay_data_unsafe(out); aoqi@0: ) aoqi@0: } aoqi@0: aoqi@0: void ciEnv::dump_replay_data(int compile_id) { aoqi@0: static char buffer[O_BUFLEN]; aoqi@0: int ret = jio_snprintf(buffer, O_BUFLEN, "replay_pid%p_compid%d.log", os::current_process_id(), compile_id); aoqi@0: if (ret > 0) { aoqi@0: int fd = open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666); aoqi@0: if (fd != -1) { aoqi@0: FILE* replay_data_file = os::open(fd, "w"); aoqi@0: if (replay_data_file != NULL) { aoqi@0: fileStream replay_data_stream(replay_data_file, /*need_close=*/true); aoqi@0: dump_replay_data(&replay_data_stream); aoqi@0: tty->print_cr("# Compiler replay data is saved as: %s", buffer); aoqi@0: } else { aoqi@0: tty->print_cr("# Can't open file to dump replay data."); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void ciEnv::dump_inline_data(int compile_id) { aoqi@0: static char buffer[O_BUFLEN]; aoqi@0: int ret = jio_snprintf(buffer, O_BUFLEN, "inline_pid%p_compid%d.log", os::current_process_id(), compile_id); aoqi@0: if (ret > 0) { aoqi@0: int fd = open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666); aoqi@0: if (fd != -1) { aoqi@0: FILE* inline_data_file = os::open(fd, "w"); aoqi@0: if (inline_data_file != NULL) { aoqi@0: fileStream replay_data_stream(inline_data_file, /*need_close=*/true); aoqi@0: GUARDED_VM_ENTRY( aoqi@0: MutexLocker ml(Compile_lock); aoqi@0: dump_compile_data(&replay_data_stream); aoqi@0: ) aoqi@0: replay_data_stream.flush(); aoqi@0: tty->print("# Compiler inline data is saved as: "); aoqi@0: tty->print_cr("%s", buffer); aoqi@0: } else { aoqi@0: tty->print_cr("# Can't open file to dump inline data."); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: }