duke@435: /* never@2658: * Copyright (c) 1997, 2011, 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 "classfile/javaClasses.hpp" stefank@2314: #include "classfile/symbolTable.hpp" stefank@2314: #include "classfile/systemDictionary.hpp" stefank@2314: #include "classfile/vmSymbols.hpp" stefank@2314: #include "interpreter/linkResolver.hpp" stefank@2314: #include "memory/oopFactory.hpp" stefank@2314: #include "memory/universe.inline.hpp" stefank@2314: #include "oops/constantPoolOop.hpp" stefank@2314: #include "oops/instanceKlass.hpp" stefank@2314: #include "oops/objArrayKlass.hpp" stefank@2314: #include "oops/oop.inline.hpp" stefank@2314: #include "runtime/fieldType.hpp" stefank@2314: #include "runtime/init.hpp" stefank@2314: #include "runtime/signature.hpp" stefank@2314: #include "runtime/vframe.hpp" duke@435: jrose@866: void constantPoolOopDesc::set_flag_at(FlagBit fb) { jrose@866: const int MAX_STATE_CHANGES = 2; jrose@866: for (int i = MAX_STATE_CHANGES + 10; i > 0; i--) { jrose@866: int oflags = _flags; jrose@866: int nflags = oflags | (1 << (int)fb); jrose@866: if (Atomic::cmpxchg(nflags, &_flags, oflags) == oflags) jrose@866: return; jrose@866: } jrose@866: assert(false, "failed to cmpxchg flags"); jrose@866: _flags |= (1 << (int)fb); // better than nothing jrose@866: } jrose@866: duke@435: klassOop constantPoolOopDesc::klass_at_impl(constantPoolHandle this_oop, int which, TRAPS) { coleenp@2497: // A resolved constantPool entry will contain a klassOop, otherwise a Symbol*. duke@435: // It is not safe to rely on the tag bit's here, since we don't have a lock, and the entry and duke@435: // tag is not updated atomicly. coleenp@2497: CPSlot entry = this_oop->slot_at(which); coleenp@2497: if (entry.is_oop()) { coleenp@2497: assert(entry.get_oop()->is_klass(), "must be"); duke@435: // Already resolved - return entry. coleenp@2497: return (klassOop)entry.get_oop(); duke@435: } duke@435: duke@435: // Acquire lock on constant oop while doing update. After we get the lock, we check if another object duke@435: // already has updated the object duke@435: assert(THREAD->is_Java_thread(), "must be a Java thread"); duke@435: bool do_resolve = false; duke@435: bool in_error = false; duke@435: coleenp@2497: Symbol* name = NULL; duke@435: Handle loader; duke@435: { ObjectLocker ol(this_oop, THREAD); duke@435: duke@435: if (this_oop->tag_at(which).is_unresolved_klass()) { duke@435: if (this_oop->tag_at(which).is_unresolved_klass_in_error()) { duke@435: in_error = true; duke@435: } else { duke@435: do_resolve = true; coleenp@2497: name = this_oop->unresolved_klass_at(which); duke@435: loader = Handle(THREAD, instanceKlass::cast(this_oop->pool_holder())->class_loader()); duke@435: } duke@435: } duke@435: } // unlocking constantPool duke@435: duke@435: duke@435: // The original attempt to resolve this constant pool entry failed so find the duke@435: // original error and throw it again (JVMS 5.4.3). duke@435: if (in_error) { coleenp@2497: Symbol* error = SystemDictionary::find_resolution_error(this_oop, which); coleenp@2497: guarantee(error != (Symbol*)NULL, "tag mismatch with resolution error table"); duke@435: ResourceMark rm; duke@435: // exception text will be the class name duke@435: const char* className = this_oop->unresolved_klass_at(which)->as_C_string(); duke@435: THROW_MSG_0(error, className); duke@435: } duke@435: duke@435: if (do_resolve) { duke@435: // this_oop must be unlocked during resolve_or_fail duke@435: oop protection_domain = Klass::cast(this_oop->pool_holder())->protection_domain(); duke@435: Handle h_prot (THREAD, protection_domain); duke@435: klassOop k_oop = SystemDictionary::resolve_or_fail(name, loader, h_prot, true, THREAD); duke@435: KlassHandle k; duke@435: if (!HAS_PENDING_EXCEPTION) { duke@435: k = KlassHandle(THREAD, k_oop); duke@435: // Do access check for klasses duke@435: verify_constant_pool_resolve(this_oop, k, THREAD); duke@435: } duke@435: duke@435: // Failed to resolve class. We must record the errors so that subsequent attempts duke@435: // to resolve this constant pool entry fail with the same error (JVMS 5.4.3). duke@435: if (HAS_PENDING_EXCEPTION) { duke@435: ResourceMark rm; coleenp@2497: Symbol* error = PENDING_EXCEPTION->klass()->klass_part()->name(); duke@435: duke@435: bool throw_orig_error = false; duke@435: { duke@435: ObjectLocker ol (this_oop, THREAD); duke@435: duke@435: // some other thread has beaten us and has resolved the class. duke@435: if (this_oop->tag_at(which).is_klass()) { duke@435: CLEAR_PENDING_EXCEPTION; duke@435: entry = this_oop->resolved_klass_at(which); coleenp@2497: return (klassOop)entry.get_oop(); duke@435: } duke@435: duke@435: if (!PENDING_EXCEPTION-> never@1577: is_a(SystemDictionary::LinkageError_klass())) { duke@435: // Just throw the exception and don't prevent these classes from duke@435: // being loaded due to virtual machine errors like StackOverflow duke@435: // and OutOfMemoryError, etc, or if the thread was hit by stop() duke@435: // Needs clarification to section 5.4.3 of the VM spec (see 6308271) duke@435: } duke@435: else if (!this_oop->tag_at(which).is_unresolved_klass_in_error()) { duke@435: SystemDictionary::add_resolution_error(this_oop, which, error); duke@435: this_oop->tag_at_put(which, JVM_CONSTANT_UnresolvedClassInError); duke@435: } else { duke@435: // some other thread has put the class in error state. coleenp@2497: error = SystemDictionary::find_resolution_error(this_oop, which); coleenp@2497: assert(error != NULL, "checking"); duke@435: throw_orig_error = true; duke@435: } duke@435: } // unlocked duke@435: duke@435: if (throw_orig_error) { duke@435: CLEAR_PENDING_EXCEPTION; duke@435: ResourceMark rm; duke@435: const char* className = this_oop->unresolved_klass_at(which)->as_C_string(); duke@435: THROW_MSG_0(error, className); duke@435: } duke@435: duke@435: return 0; duke@435: } duke@435: duke@435: if (TraceClassResolution && !k()->klass_part()->oop_is_array()) { duke@435: // skip resolving the constant pool so that this code get's duke@435: // called the next time some bytecodes refer to this class. duke@435: ResourceMark rm; duke@435: int line_number = -1; duke@435: const char * source_file = NULL; duke@435: if (JavaThread::current()->has_last_Java_frame()) { duke@435: // try to identify the method which called this function. duke@435: vframeStream vfst(JavaThread::current()); duke@435: if (!vfst.at_end()) { duke@435: line_number = vfst.method()->line_number_from_bci(vfst.bci()); coleenp@2497: Symbol* s = instanceKlass::cast(vfst.method()->method_holder())->source_file_name(); duke@435: if (s != NULL) { duke@435: source_file = s->as_C_string(); duke@435: } duke@435: } duke@435: } duke@435: if (k() != this_oop->pool_holder()) { duke@435: // only print something if the classes are different duke@435: if (source_file != NULL) { duke@435: tty->print("RESOLVE %s %s %s:%d\n", duke@435: instanceKlass::cast(this_oop->pool_holder())->external_name(), duke@435: instanceKlass::cast(k())->external_name(), source_file, line_number); duke@435: } else { duke@435: tty->print("RESOLVE %s %s\n", duke@435: instanceKlass::cast(this_oop->pool_holder())->external_name(), duke@435: instanceKlass::cast(k())->external_name()); duke@435: } duke@435: } duke@435: return k(); duke@435: } else { duke@435: ObjectLocker ol (this_oop, THREAD); duke@435: // Only updated constant pool - if it is resolved. duke@435: do_resolve = this_oop->tag_at(which).is_unresolved_klass(); duke@435: if (do_resolve) { duke@435: this_oop->klass_at_put(which, k()); duke@435: } duke@435: } duke@435: } duke@435: duke@435: entry = this_oop->resolved_klass_at(which); coleenp@2497: assert(entry.is_oop() && entry.get_oop()->is_klass(), "must be resolved at this point"); coleenp@2497: return (klassOop)entry.get_oop(); duke@435: } duke@435: duke@435: duke@435: // Does not update constantPoolOop - to avoid any exception throwing. Used duke@435: // by compiler and exception handling. Also used to avoid classloads for duke@435: // instanceof operations. Returns NULL if the class has not been loaded or duke@435: // if the verification of constant pool failed duke@435: klassOop constantPoolOopDesc::klass_at_if_loaded(constantPoolHandle this_oop, int which) { coleenp@2497: CPSlot entry = this_oop->slot_at(which); coleenp@2497: if (entry.is_oop()) { coleenp@2497: assert(entry.get_oop()->is_klass(), "must be"); coleenp@2497: return (klassOop)entry.get_oop(); duke@435: } else { coleenp@2497: assert(entry.is_metadata(), "must be either symbol or klass"); duke@435: Thread *thread = Thread::current(); coleenp@2497: Symbol* name = entry.get_symbol(); duke@435: oop loader = instanceKlass::cast(this_oop->pool_holder())->class_loader(); duke@435: oop protection_domain = Klass::cast(this_oop->pool_holder())->protection_domain(); duke@435: Handle h_prot (thread, protection_domain); duke@435: Handle h_loader (thread, loader); duke@435: klassOop k = SystemDictionary::find(name, h_loader, h_prot, thread); duke@435: duke@435: if (k != NULL) { duke@435: // Make sure that resolving is legal duke@435: EXCEPTION_MARK; duke@435: KlassHandle klass(THREAD, k); duke@435: // return NULL if verification fails duke@435: verify_constant_pool_resolve(this_oop, klass, THREAD); duke@435: if (HAS_PENDING_EXCEPTION) { duke@435: CLEAR_PENDING_EXCEPTION; duke@435: return NULL; duke@435: } duke@435: return klass(); duke@435: } else { duke@435: return k; duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: klassOop constantPoolOopDesc::klass_ref_at_if_loaded(constantPoolHandle this_oop, int which) { duke@435: return klass_at_if_loaded(this_oop, this_oop->klass_ref_index_at(which)); duke@435: } duke@435: duke@435: duke@435: // This is an interface for the compiler that allows accessing non-resolved entries duke@435: // in the constant pool - but still performs the validations tests. Must be used duke@435: // in a pre-parse of the compiler - to determine what it can do and not do. duke@435: // Note: We cannot update the ConstantPool from the vm_thread. duke@435: klassOop constantPoolOopDesc::klass_ref_at_if_loaded_check(constantPoolHandle this_oop, int index, TRAPS) { duke@435: int which = this_oop->klass_ref_index_at(index); coleenp@2497: CPSlot entry = this_oop->slot_at(which); coleenp@2497: if (entry.is_oop()) { coleenp@2497: assert(entry.get_oop()->is_klass(), "must be"); coleenp@2497: return (klassOop)entry.get_oop(); duke@435: } else { coleenp@2497: assert(entry.is_metadata(), "must be either symbol or klass"); coleenp@2497: Symbol* name = entry.get_symbol(); duke@435: oop loader = instanceKlass::cast(this_oop->pool_holder())->class_loader(); duke@435: oop protection_domain = Klass::cast(this_oop->pool_holder())->protection_domain(); duke@435: Handle h_loader(THREAD, loader); duke@435: Handle h_prot (THREAD, protection_domain); duke@435: KlassHandle k(THREAD, SystemDictionary::find(name, h_loader, h_prot, THREAD)); duke@435: duke@435: // Do access check for klasses duke@435: if( k.not_null() ) verify_constant_pool_resolve(this_oop, k, CHECK_NULL); duke@435: return k(); duke@435: } duke@435: } duke@435: duke@435: jrose@2982: methodOop constantPoolOopDesc::method_at_if_loaded(constantPoolHandle cpool, jrose@2982: int which, Bytecodes::Code invoke_code) { jrose@2982: assert(!constantPoolCacheOopDesc::is_secondary_index(which), "no indy instruction here"); jrose@2982: if (cpool->cache() == NULL) return false; // nothing to load yet jrose@2982: int cache_index = which - CPCACHE_INDEX_TAG; jrose@2982: if (!(cache_index >= 0 && cache_index < cpool->cache()->length())) { jrose@2982: if (PrintMiscellaneous && (Verbose||WizardMode)) { jrose@2982: tty->print_cr("bad operand %d for %d in:", which, invoke_code); cpool->print(); jrose@2982: } jrose@2982: return NULL; jrose@2982: } jrose@2982: ConstantPoolCacheEntry* e = cpool->cache()->entry_at(cache_index); jrose@2982: if (invoke_code != Bytecodes::_illegal) jrose@2982: return e->get_method_if_resolved(invoke_code, cpool); jrose@2982: Bytecodes::Code bc; jrose@2982: if ((bc = e->bytecode_1()) != (Bytecodes::Code)0) jrose@2982: return e->get_method_if_resolved(bc, cpool); jrose@2982: if ((bc = e->bytecode_2()) != (Bytecodes::Code)0) jrose@2982: return e->get_method_if_resolved(bc, cpool); jrose@2982: return NULL; jrose@2982: } jrose@2982: jrose@2982: coleenp@2497: Symbol* constantPoolOopDesc::impl_name_ref_at(int which, bool uncached) { jrose@1161: int name_index = name_ref_index_at(impl_name_and_type_ref_index_at(which, uncached)); duke@435: return symbol_at(name_index); duke@435: } duke@435: duke@435: coleenp@2497: Symbol* constantPoolOopDesc::impl_signature_ref_at(int which, bool uncached) { jrose@1161: int signature_index = signature_ref_index_at(impl_name_and_type_ref_index_at(which, uncached)); duke@435: return symbol_at(signature_index); duke@435: } duke@435: duke@435: jrose@1161: int constantPoolOopDesc::impl_name_and_type_ref_index_at(int which, bool uncached) { jrose@1494: int i = which; jrose@1494: if (!uncached && cache() != NULL) { jrose@2015: if (constantPoolCacheOopDesc::is_secondary_index(which)) { jrose@2265: // Invokedynamic index. jrose@2015: int pool_index = cache()->main_entry_at(which)->constant_pool_index(); jrose@2742: pool_index = invoke_dynamic_name_and_type_ref_index_at(pool_index); jrose@2015: assert(tag_at(pool_index).is_name_and_type(), ""); jrose@2015: return pool_index; jrose@2015: } jrose@1494: // change byte-ordering and go via cache jrose@1494: i = remap_instruction_operand_from_cache(which); jrose@1494: } else { jrose@2268: if (tag_at(which).is_invoke_dynamic()) { jrose@2268: int pool_index = invoke_dynamic_name_and_type_ref_index_at(which); jrose@2268: assert(tag_at(pool_index).is_name_and_type(), ""); jrose@2268: return pool_index; jrose@2268: } jrose@1494: } jrose@1494: assert(tag_at(i).is_field_or_method(), "Corrupted constant pool"); jrose@2268: assert(!tag_at(i).is_invoke_dynamic(), "Must be handled above"); jrose@1494: jint ref_index = *int_at_addr(i); duke@435: return extract_high_short_from_int(ref_index); duke@435: } duke@435: duke@435: jrose@1161: int constantPoolOopDesc::impl_klass_ref_index_at(int which, bool uncached) { jrose@1494: guarantee(!constantPoolCacheOopDesc::is_secondary_index(which), jrose@1494: "an invokedynamic instruction does not have a klass"); jrose@1494: int i = which; jrose@1494: if (!uncached && cache() != NULL) { jrose@1494: // change byte-ordering and go via cache jrose@1494: i = remap_instruction_operand_from_cache(which); jrose@1494: } jrose@1494: assert(tag_at(i).is_field_or_method(), "Corrupted constant pool"); jrose@1494: jint ref_index = *int_at_addr(i); duke@435: return extract_low_short_from_int(ref_index); duke@435: } duke@435: duke@435: jrose@1161: jrose@1494: int constantPoolOopDesc::remap_instruction_operand_from_cache(int operand) { jrose@1920: int cpc_index = operand; jrose@1920: DEBUG_ONLY(cpc_index -= CPCACHE_INDEX_TAG); jrose@1920: assert((int)(u2)cpc_index == cpc_index, "clean u2"); jrose@1494: int member_index = cache()->entry_at(cpc_index)->constant_pool_index(); jrose@1494: return member_index; jrose@1161: } jrose@1161: jrose@1161: duke@435: void constantPoolOopDesc::verify_constant_pool_resolve(constantPoolHandle this_oop, KlassHandle k, TRAPS) { duke@435: if (k->oop_is_instance() || k->oop_is_objArray()) { duke@435: instanceKlassHandle holder (THREAD, this_oop->pool_holder()); duke@435: klassOop elem_oop = k->oop_is_instance() ? k() : objArrayKlass::cast(k())->bottom_klass(); duke@435: KlassHandle element (THREAD, elem_oop); duke@435: duke@435: // The element type could be a typeArray - we only need the access check if it is duke@435: // an reference to another class duke@435: if (element->oop_is_instance()) { duke@435: LinkResolver::check_klass_accessability(holder, element, CHECK); duke@435: } duke@435: } duke@435: } duke@435: duke@435: jrose@1161: int constantPoolOopDesc::name_ref_index_at(int which_nt) { jrose@1161: jint ref_index = name_and_type_at(which_nt); duke@435: return extract_low_short_from_int(ref_index); duke@435: } duke@435: duke@435: jrose@1161: int constantPoolOopDesc::signature_ref_index_at(int which_nt) { jrose@1161: jint ref_index = name_and_type_at(which_nt); duke@435: return extract_high_short_from_int(ref_index); duke@435: } duke@435: duke@435: duke@435: klassOop constantPoolOopDesc::klass_ref_at(int which, TRAPS) { duke@435: return klass_at(klass_ref_index_at(which), CHECK_NULL); duke@435: } duke@435: duke@435: coleenp@2497: Symbol* constantPoolOopDesc::klass_name_at(int which) { duke@435: assert(tag_at(which).is_unresolved_klass() || tag_at(which).is_klass(), duke@435: "Corrupted constant pool"); coleenp@2497: // A resolved constantPool entry will contain a klassOop, otherwise a Symbol*. duke@435: // It is not safe to rely on the tag bit's here, since we don't have a lock, and the entry and duke@435: // tag is not updated atomicly. coleenp@2497: CPSlot entry = slot_at(which); coleenp@2497: if (entry.is_oop()) { duke@435: // Already resolved - return entry's name. coleenp@2497: assert(entry.get_oop()->is_klass(), "must be"); coleenp@2497: return klassOop(entry.get_oop())->klass_part()->name(); duke@435: } else { coleenp@2497: assert(entry.is_metadata(), "must be either symbol or klass"); coleenp@2497: return entry.get_symbol(); duke@435: } duke@435: } duke@435: coleenp@2497: Symbol* constantPoolOopDesc::klass_ref_at_noresolve(int which) { duke@435: jint ref_index = klass_ref_index_at(which); duke@435: return klass_at_noresolve(ref_index); duke@435: } duke@435: coleenp@2497: Symbol* constantPoolOopDesc::uncached_klass_ref_at_noresolve(int which) { jrose@1957: jint ref_index = uncached_klass_ref_index_at(which); jrose@1957: return klass_at_noresolve(ref_index); jrose@1957: } jrose@1957: duke@435: char* constantPoolOopDesc::string_at_noresolve(int which) { duke@435: // Test entry type in case string is resolved while in here. coleenp@2497: CPSlot entry = slot_at(which); coleenp@2497: if (entry.is_metadata()) { coleenp@2497: return (entry.get_symbol())->as_C_string(); coleenp@2497: } else if (java_lang_String::is_instance(entry.get_oop())) { coleenp@2497: return java_lang_String::as_utf8_string(entry.get_oop()); duke@435: } else { jrose@866: return (char*)""; duke@435: } duke@435: } duke@435: duke@435: duke@435: BasicType constantPoolOopDesc::basic_type_for_signature_at(int which) { duke@435: return FieldType::basic_type(symbol_at(which)); duke@435: } duke@435: duke@435: duke@435: void constantPoolOopDesc::resolve_string_constants_impl(constantPoolHandle this_oop, TRAPS) { duke@435: for (int index = 1; index < this_oop->length(); index++) { // Index 0 is unused duke@435: if (this_oop->tag_at(index).is_unresolved_string()) { duke@435: this_oop->string_at(index, CHECK); duke@435: } duke@435: } duke@435: } duke@435: jrose@2268: // A resolved constant value in the CP cache is represented as a non-null jrose@2268: // value. As a special case, this value can be a 'systemObjArray' jrose@2268: // which masks an exception object to throw. jrose@2268: // This allows a MethodHandle constant reference to throw a consistent jrose@2268: // exception every time, if it fails to resolve. jrose@2268: static oop decode_exception_from_f1(oop result_oop, TRAPS) { jrose@2268: if (result_oop->klass() != Universe::systemObjArrayKlassObj()) jrose@2268: return result_oop; jrose@2268: jrose@2268: // Special cases here: Masked null, saved exception. jrose@2268: objArrayOop sys_array = (objArrayOop) result_oop; jrose@2268: assert(sys_array->length() == 1, "bad system array"); jrose@2268: if (sys_array->length() == 1) { jrose@2268: THROW_OOP_(sys_array->obj_at(0), NULL); jrose@2268: } jrose@2268: return NULL; jrose@2268: } jrose@2268: jrose@1957: oop constantPoolOopDesc::resolve_constant_at_impl(constantPoolHandle this_oop, int index, int cache_index, TRAPS) { jrose@1957: oop result_oop = NULL; jrose@2268: Handle throw_exception; jrose@2268: jrose@2268: if (cache_index == _possible_index_sentinel) { jrose@2268: // It is possible that this constant is one which is cached in the CP cache. jrose@2268: // We'll do a linear search. This should be OK because this usage is rare. jrose@2268: assert(index > 0, "valid index"); jrose@2268: constantPoolCacheOop cache = this_oop()->cache(); jrose@2268: for (int i = 0, len = cache->length(); i < len; i++) { jrose@2268: ConstantPoolCacheEntry* cpc_entry = cache->entry_at(i); jrose@2268: if (!cpc_entry->is_secondary_entry() && cpc_entry->constant_pool_index() == index) { jrose@2268: // Switch the query to use this CPC entry. jrose@2268: cache_index = i; jrose@2268: index = _no_index_sentinel; jrose@2268: break; jrose@2268: } jrose@2268: } jrose@2268: if (cache_index == _possible_index_sentinel) jrose@2268: cache_index = _no_index_sentinel; // not found jrose@2268: } jrose@2268: assert(cache_index == _no_index_sentinel || cache_index >= 0, ""); jrose@2268: assert(index == _no_index_sentinel || index >= 0, ""); jrose@2268: jrose@1957: if (cache_index >= 0) { jrose@2268: assert(index == _no_index_sentinel, "only one kind of index at a time"); jrose@1957: ConstantPoolCacheEntry* cpc_entry = this_oop->cache()->entry_at(cache_index); jrose@1957: result_oop = cpc_entry->f1(); jrose@1957: if (result_oop != NULL) { jrose@2268: return decode_exception_from_f1(result_oop, THREAD); jrose@2268: // That was easy... jrose@1957: } jrose@1957: index = cpc_entry->constant_pool_index(); jrose@1957: } jrose@1957: jrose@2268: jvalue prim_value; // temp used only in a few cases below jrose@2268: jrose@1957: int tag_value = this_oop->tag_at(index).value(); jrose@1957: switch (tag_value) { jrose@1957: jrose@1957: case JVM_CONSTANT_UnresolvedClass: jrose@1957: case JVM_CONSTANT_UnresolvedClassInError: jrose@1957: case JVM_CONSTANT_Class: jrose@1957: { jrose@1957: klassOop resolved = klass_at_impl(this_oop, index, CHECK_NULL); jrose@1957: // ldc wants the java mirror. never@2658: result_oop = resolved->java_mirror(); jrose@1957: break; jrose@1957: } jrose@1957: jrose@1957: case JVM_CONSTANT_String: jrose@1957: case JVM_CONSTANT_UnresolvedString: jrose@1957: if (this_oop->is_pseudo_string_at(index)) { jrose@1957: result_oop = this_oop->pseudo_string_at(index); jrose@1957: break; jrose@1957: } jrose@1957: result_oop = string_at_impl(this_oop, index, CHECK_NULL); jrose@1957: break; jrose@1957: jrose@1957: case JVM_CONSTANT_Object: jrose@1957: result_oop = this_oop->object_at(index); jrose@1957: break; jrose@1957: jrose@1957: case JVM_CONSTANT_MethodHandle: jrose@1957: { jrose@1957: int ref_kind = this_oop->method_handle_ref_kind_at(index); jrose@1957: int callee_index = this_oop->method_handle_klass_index_at(index); coleenp@2497: Symbol* name = this_oop->method_handle_name_ref_at(index); coleenp@2497: Symbol* signature = this_oop->method_handle_signature_ref_at(index); jrose@1957: if (PrintMiscellaneous) jrose@1957: tty->print_cr("resolve JVM_CONSTANT_MethodHandle:%d [%d/%d/%d] %s.%s", jrose@1957: ref_kind, index, this_oop->method_handle_index_at(index), jrose@1957: callee_index, name->as_C_string(), signature->as_C_string()); jrose@1957: KlassHandle callee; jrose@1957: { klassOop k = klass_at_impl(this_oop, callee_index, CHECK_NULL); jrose@1957: callee = KlassHandle(THREAD, k); jrose@1957: } jrose@1957: KlassHandle klass(THREAD, this_oop->pool_holder()); jrose@1957: Handle value = SystemDictionary::link_method_handle_constant(klass, ref_kind, jrose@1957: callee, name, signature, jrose@2268: THREAD); jrose@2268: if (HAS_PENDING_EXCEPTION) { jrose@2268: throw_exception = Handle(THREAD, PENDING_EXCEPTION); jrose@2268: CLEAR_PENDING_EXCEPTION; jrose@2268: break; jrose@2268: } jrose@1957: result_oop = value(); jrose@2268: assert(result_oop != NULL, ""); jrose@1957: break; jrose@1957: } jrose@1957: jrose@1957: case JVM_CONSTANT_MethodType: jrose@1957: { coleenp@2497: Symbol* signature = this_oop->method_type_signature_at(index); jrose@1957: if (PrintMiscellaneous) jrose@1957: tty->print_cr("resolve JVM_CONSTANT_MethodType [%d/%d] %s", jrose@1957: index, this_oop->method_type_index_at(index), jrose@1957: signature->as_C_string()); jrose@1957: KlassHandle klass(THREAD, this_oop->pool_holder()); jrose@1957: bool ignore_is_on_bcp = false; jrose@1957: Handle value = SystemDictionary::find_method_handle_type(signature, jrose@1957: klass, jrose@2148: false, jrose@1957: ignore_is_on_bcp, jrose@2268: THREAD); jrose@2268: if (HAS_PENDING_EXCEPTION) { jrose@2268: throw_exception = Handle(THREAD, PENDING_EXCEPTION); jrose@2268: CLEAR_PENDING_EXCEPTION; jrose@2268: break; jrose@2268: } jrose@1957: result_oop = value(); jrose@2268: assert(result_oop != NULL, ""); jrose@1957: break; jrose@1957: } jrose@1957: jrose@1957: case JVM_CONSTANT_Integer: jrose@2268: prim_value.i = this_oop->int_at(index); jrose@2268: result_oop = java_lang_boxing_object::create(T_INT, &prim_value, CHECK_NULL); jrose@2268: break; jrose@2268: jrose@1957: case JVM_CONSTANT_Float: jrose@2268: prim_value.f = this_oop->float_at(index); jrose@2268: result_oop = java_lang_boxing_object::create(T_FLOAT, &prim_value, CHECK_NULL); jrose@2268: break; jrose@2268: jrose@1957: case JVM_CONSTANT_Long: jrose@2268: prim_value.j = this_oop->long_at(index); jrose@2268: result_oop = java_lang_boxing_object::create(T_LONG, &prim_value, CHECK_NULL); jrose@2268: break; jrose@2268: jrose@1957: case JVM_CONSTANT_Double: jrose@2268: prim_value.d = this_oop->double_at(index); jrose@2268: result_oop = java_lang_boxing_object::create(T_DOUBLE, &prim_value, CHECK_NULL); jrose@1957: break; jrose@1957: jrose@1957: default: jrose@1957: DEBUG_ONLY( tty->print_cr("*** %p: tag at CP[%d/%d] = %d", jrose@1957: this_oop(), index, cache_index, tag_value) ); jrose@1957: assert(false, "unexpected constant tag"); jrose@1957: break; jrose@1957: } jrose@1957: jrose@1957: if (cache_index >= 0) { jrose@1957: // Cache the oop here also. jrose@2268: if (throw_exception.not_null()) { jrose@2268: objArrayOop sys_array = oopFactory::new_system_objArray(1, CHECK_NULL); jrose@2268: sys_array->obj_at_put(0, throw_exception()); jrose@2268: result_oop = sys_array; jrose@2268: throw_exception = Handle(); // be tidy jrose@2268: } jrose@2268: Handle result_handle(THREAD, result_oop); jrose@1957: result_oop = NULL; // safety jrose@1957: ObjectLocker ol(this_oop, THREAD); jrose@1957: ConstantPoolCacheEntry* cpc_entry = this_oop->cache()->entry_at(cache_index); jrose@2268: result_oop = cpc_entry->f1(); jrose@2268: // Benign race condition: f1 may already be filled in while we were trying to lock. jrose@2268: // The important thing here is that all threads pick up the same result. jrose@2268: // It doesn't matter which racing thread wins, as long as only one jrose@2268: // result is used by all threads, and all future queries. jrose@2268: // That result may be either a resolved constant or a failure exception. jrose@2268: if (result_oop == NULL) { jrose@2268: result_oop = result_handle(); jrose@2268: cpc_entry->set_f1(result_oop); jrose@1957: } jrose@2268: return decode_exception_from_f1(result_oop, THREAD); jrose@1957: } else { jrose@2268: if (throw_exception.not_null()) { jrose@2268: THROW_HANDLE_(throw_exception, NULL); jrose@2268: } jrose@1957: return result_oop; jrose@1957: } jrose@1957: } jrose@1957: duke@435: oop constantPoolOopDesc::string_at_impl(constantPoolHandle this_oop, int which, TRAPS) { coleenp@2497: oop str = NULL; coleenp@2497: CPSlot entry = this_oop->slot_at(which); coleenp@2497: if (entry.is_metadata()) { duke@435: ObjectLocker ol(this_oop, THREAD); duke@435: if (this_oop->tag_at(which).is_unresolved_string()) { duke@435: // Intern string coleenp@2497: Symbol* sym = this_oop->unresolved_string_at(which); coleenp@2497: str = StringTable::intern(sym, CHECK_(constantPoolOop(NULL))); coleenp@2497: this_oop->string_at_put(which, str); duke@435: } else { duke@435: // Another thread beat us and interned string, read string from constant pool coleenp@2497: str = this_oop->resolved_string_at(which); duke@435: } coleenp@2497: } else { coleenp@2497: str = entry.get_oop(); duke@435: } coleenp@2497: assert(java_lang_String::is_instance(str), "must be string"); coleenp@2497: return str; duke@435: } duke@435: duke@435: jrose@866: bool constantPoolOopDesc::is_pseudo_string_at(int which) { coleenp@2497: CPSlot entry = slot_at(which); coleenp@2497: if (entry.is_metadata()) jrose@866: // Not yet resolved, but it will resolve to a string. jrose@866: return false; coleenp@2497: else if (java_lang_String::is_instance(entry.get_oop())) jrose@866: return false; // actually, it might be a non-interned or non-perm string jrose@866: else jrose@866: // truly pseudo jrose@866: return true; jrose@866: } jrose@866: jrose@866: duke@435: bool constantPoolOopDesc::klass_name_at_matches(instanceKlassHandle k, duke@435: int which) { coleenp@2497: // Names are interned, so we can compare Symbol*s directly coleenp@2497: Symbol* cp_name = klass_name_at(which); duke@435: return (cp_name == k->name()); duke@435: } duke@435: duke@435: duke@435: int constantPoolOopDesc::pre_resolve_shared_klasses(TRAPS) { duke@435: ResourceMark rm; duke@435: int count = 0; duke@435: for (int index = 1; index < tags()->length(); index++) { // Index 0 is unused duke@435: if (tag_at(index).is_unresolved_string()) { duke@435: // Intern string coleenp@2497: Symbol* sym = unresolved_string_at(index); duke@435: oop entry = StringTable::intern(sym, CHECK_(-1)); duke@435: string_at_put(index, entry); duke@435: } duke@435: } duke@435: return count; duke@435: } duke@435: coleenp@2497: // Iterate over symbols and decrement ones which are Symbol*s. coleenp@2497: // This is done during GC so do not need to lock constantPool unless we coleenp@2497: // have per-thread safepoints. coleenp@2497: // Only decrement the UTF8 symbols. Unresolved classes and strings point to coleenp@2497: // these symbols but didn't increment the reference count. coleenp@2497: void constantPoolOopDesc::unreference_symbols() { coleenp@2497: for (int index = 1; index < length(); index++) { // Index 0 is unused coleenp@2497: constantTag tag = tag_at(index); coleenp@2497: if (tag.is_symbol()) { coleenp@2497: symbol_at(index)->decrement_refcount(); coleenp@2497: } coleenp@2497: } coleenp@2497: } duke@435: duke@435: // Iterate over symbols which are used as class, field, method names and duke@435: // signatures (in preparation for writing to the shared archive). duke@435: coleenp@2497: void constantPoolOopDesc::shared_symbols_iterate(SymbolClosure* closure) { duke@435: for (int index = 1; index < length(); index++) { // Index 0 is unused duke@435: switch (tag_at(index).value()) { duke@435: duke@435: case JVM_CONSTANT_UnresolvedClass: coleenp@2497: case JVM_CONSTANT_UnresolvedString: coleenp@2497: case JVM_CONSTANT_Utf8: coleenp@2497: assert(slot_at(index).is_metadata(), "must be symbol"); coleenp@2497: closure->do_symbol(symbol_at_addr(index)); duke@435: break; duke@435: duke@435: case JVM_CONSTANT_NameAndType: duke@435: { duke@435: int i = *int_at_addr(index); coleenp@2497: closure->do_symbol(symbol_at_addr((unsigned)i >> 16)); coleenp@2497: closure->do_symbol(symbol_at_addr((unsigned)i & 0xffff)); duke@435: } duke@435: break; duke@435: duke@435: case JVM_CONSTANT_Class: duke@435: case JVM_CONSTANT_InterfaceMethodref: duke@435: case JVM_CONSTANT_Fieldref: duke@435: case JVM_CONSTANT_Methodref: duke@435: case JVM_CONSTANT_Integer: duke@435: case JVM_CONSTANT_Float: duke@435: // Do nothing! Not an oop. duke@435: // These constant types do not reference symbols at this point. duke@435: break; duke@435: duke@435: case JVM_CONSTANT_String: duke@435: // Do nothing! Not a symbol. duke@435: break; duke@435: duke@435: case JVM_CONSTANT_Long: duke@435: case JVM_CONSTANT_Double: duke@435: // Do nothing! Not an oop. (But takes two pool entries.) duke@435: ++index; duke@435: break; duke@435: duke@435: default: duke@435: ShouldNotReachHere(); duke@435: break; duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: // Iterate over the [one] tags array (in preparation for writing to the duke@435: // shared archive). duke@435: duke@435: void constantPoolOopDesc::shared_tags_iterate(OopClosure* closure) { duke@435: closure->do_oop(tags_addr()); jrose@2268: closure->do_oop(operands_addr()); duke@435: } duke@435: duke@435: duke@435: // Iterate over String objects (in preparation for writing to the shared duke@435: // archive). duke@435: duke@435: void constantPoolOopDesc::shared_strings_iterate(OopClosure* closure) { duke@435: for (int index = 1; index < length(); index++) { // Index 0 is unused duke@435: switch (tag_at(index).value()) { duke@435: duke@435: case JVM_CONSTANT_UnresolvedClass: duke@435: case JVM_CONSTANT_NameAndType: duke@435: // Do nothing! Not a String. duke@435: break; duke@435: duke@435: case JVM_CONSTANT_Class: duke@435: case JVM_CONSTANT_InterfaceMethodref: duke@435: case JVM_CONSTANT_Fieldref: duke@435: case JVM_CONSTANT_Methodref: duke@435: case JVM_CONSTANT_Integer: duke@435: case JVM_CONSTANT_Float: duke@435: // Do nothing! Not an oop. duke@435: // These constant types do not reference symbols at this point. duke@435: break; duke@435: duke@435: case JVM_CONSTANT_String: coleenp@2497: closure->do_oop(obj_at_addr_raw(index)); duke@435: break; duke@435: duke@435: case JVM_CONSTANT_UnresolvedString: duke@435: case JVM_CONSTANT_Utf8: duke@435: // These constants are symbols, but unless these symbols are duke@435: // actually to be used for something, we don't want to mark them. duke@435: break; duke@435: duke@435: case JVM_CONSTANT_Long: duke@435: case JVM_CONSTANT_Double: duke@435: // Do nothing! Not an oop. (But takes two pool entries.) duke@435: ++index; duke@435: break; duke@435: duke@435: default: duke@435: ShouldNotReachHere(); duke@435: break; duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: // Compare this constant pool's entry at index1 to the constant pool duke@435: // cp2's entry at index2. duke@435: bool constantPoolOopDesc::compare_entry_to(int index1, constantPoolHandle cp2, duke@435: int index2, TRAPS) { duke@435: duke@435: jbyte t1 = tag_at(index1).value(); duke@435: jbyte t2 = cp2->tag_at(index2).value(); duke@435: duke@435: duke@435: // JVM_CONSTANT_UnresolvedClassInError is equal to JVM_CONSTANT_UnresolvedClass duke@435: // when comparing duke@435: if (t1 == JVM_CONSTANT_UnresolvedClassInError) { duke@435: t1 = JVM_CONSTANT_UnresolvedClass; duke@435: } duke@435: if (t2 == JVM_CONSTANT_UnresolvedClassInError) { duke@435: t2 = JVM_CONSTANT_UnresolvedClass; duke@435: } duke@435: duke@435: if (t1 != t2) { duke@435: // Not the same entry type so there is nothing else to check. Note duke@435: // that this style of checking will consider resolved/unresolved duke@435: // class pairs and resolved/unresolved string pairs as different. duke@435: // From the constantPoolOop API point of view, this is correct duke@435: // behavior. See constantPoolKlass::merge() to see how this plays duke@435: // out in the context of constantPoolOop merging. duke@435: return false; duke@435: } duke@435: duke@435: switch (t1) { duke@435: case JVM_CONSTANT_Class: duke@435: { duke@435: klassOop k1 = klass_at(index1, CHECK_false); duke@435: klassOop k2 = cp2->klass_at(index2, CHECK_false); duke@435: if (k1 == k2) { duke@435: return true; duke@435: } duke@435: } break; duke@435: duke@435: case JVM_CONSTANT_ClassIndex: duke@435: { duke@435: int recur1 = klass_index_at(index1); duke@435: int recur2 = cp2->klass_index_at(index2); duke@435: bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false); duke@435: if (match) { duke@435: return true; duke@435: } duke@435: } break; duke@435: duke@435: case JVM_CONSTANT_Double: duke@435: { duke@435: jdouble d1 = double_at(index1); duke@435: jdouble d2 = cp2->double_at(index2); duke@435: if (d1 == d2) { duke@435: return true; duke@435: } duke@435: } break; duke@435: duke@435: case JVM_CONSTANT_Fieldref: duke@435: case JVM_CONSTANT_InterfaceMethodref: duke@435: case JVM_CONSTANT_Methodref: duke@435: { duke@435: int recur1 = uncached_klass_ref_index_at(index1); duke@435: int recur2 = cp2->uncached_klass_ref_index_at(index2); duke@435: bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false); duke@435: if (match) { duke@435: recur1 = uncached_name_and_type_ref_index_at(index1); duke@435: recur2 = cp2->uncached_name_and_type_ref_index_at(index2); duke@435: match = compare_entry_to(recur1, cp2, recur2, CHECK_false); duke@435: if (match) { duke@435: return true; duke@435: } duke@435: } duke@435: } break; duke@435: duke@435: case JVM_CONSTANT_Float: duke@435: { duke@435: jfloat f1 = float_at(index1); duke@435: jfloat f2 = cp2->float_at(index2); duke@435: if (f1 == f2) { duke@435: return true; duke@435: } duke@435: } break; duke@435: duke@435: case JVM_CONSTANT_Integer: duke@435: { duke@435: jint i1 = int_at(index1); duke@435: jint i2 = cp2->int_at(index2); duke@435: if (i1 == i2) { duke@435: return true; duke@435: } duke@435: } break; duke@435: duke@435: case JVM_CONSTANT_Long: duke@435: { duke@435: jlong l1 = long_at(index1); duke@435: jlong l2 = cp2->long_at(index2); duke@435: if (l1 == l2) { duke@435: return true; duke@435: } duke@435: } break; duke@435: duke@435: case JVM_CONSTANT_NameAndType: duke@435: { duke@435: int recur1 = name_ref_index_at(index1); duke@435: int recur2 = cp2->name_ref_index_at(index2); duke@435: bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false); duke@435: if (match) { duke@435: recur1 = signature_ref_index_at(index1); duke@435: recur2 = cp2->signature_ref_index_at(index2); duke@435: match = compare_entry_to(recur1, cp2, recur2, CHECK_false); duke@435: if (match) { duke@435: return true; duke@435: } duke@435: } duke@435: } break; duke@435: duke@435: case JVM_CONSTANT_String: duke@435: { duke@435: oop s1 = string_at(index1, CHECK_false); duke@435: oop s2 = cp2->string_at(index2, CHECK_false); duke@435: if (s1 == s2) { duke@435: return true; duke@435: } duke@435: } break; duke@435: duke@435: case JVM_CONSTANT_StringIndex: duke@435: { duke@435: int recur1 = string_index_at(index1); duke@435: int recur2 = cp2->string_index_at(index2); duke@435: bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false); duke@435: if (match) { duke@435: return true; duke@435: } duke@435: } break; duke@435: duke@435: case JVM_CONSTANT_UnresolvedClass: duke@435: { coleenp@2497: Symbol* k1 = unresolved_klass_at(index1); coleenp@2497: Symbol* k2 = cp2->unresolved_klass_at(index2); duke@435: if (k1 == k2) { duke@435: return true; duke@435: } duke@435: } break; duke@435: jrose@1957: case JVM_CONSTANT_MethodType: jrose@1957: { jrose@1957: int k1 = method_type_index_at(index1); jrose@1957: int k2 = cp2->method_type_index_at(index2); jrose@2353: bool match = compare_entry_to(k1, cp2, k2, CHECK_false); jrose@2353: if (match) { jrose@1957: return true; jrose@1957: } jrose@1957: } break; jrose@1957: jrose@1957: case JVM_CONSTANT_MethodHandle: jrose@1957: { jrose@1957: int k1 = method_handle_ref_kind_at(index1); jrose@1957: int k2 = cp2->method_handle_ref_kind_at(index2); jrose@1957: if (k1 == k2) { jrose@1957: int i1 = method_handle_index_at(index1); jrose@1957: int i2 = cp2->method_handle_index_at(index2); jrose@2353: bool match = compare_entry_to(i1, cp2, i2, CHECK_false); jrose@2353: if (match) { jrose@1957: return true; jrose@1957: } jrose@1957: } jrose@1957: } break; jrose@1957: jrose@2015: case JVM_CONSTANT_InvokeDynamic: jrose@2015: { jrose@2353: int k1 = invoke_dynamic_bootstrap_method_ref_index_at(index1); jrose@2353: int k2 = cp2->invoke_dynamic_bootstrap_method_ref_index_at(index2); jrose@2353: bool match = compare_entry_to(k1, cp2, k2, CHECK_false); jrose@2353: if (!match) return false; jrose@2353: k1 = invoke_dynamic_name_and_type_ref_index_at(index1); jrose@2353: k2 = cp2->invoke_dynamic_name_and_type_ref_index_at(index2); jrose@2353: match = compare_entry_to(k1, cp2, k2, CHECK_false); jrose@2353: if (!match) return false; jrose@2353: int argc = invoke_dynamic_argument_count_at(index1); jrose@2353: if (argc == cp2->invoke_dynamic_argument_count_at(index2)) { jrose@2353: for (int j = 0; j < argc; j++) { jrose@2353: k1 = invoke_dynamic_argument_index_at(index1, j); jrose@2353: k2 = cp2->invoke_dynamic_argument_index_at(index2, j); jrose@2353: match = compare_entry_to(k1, cp2, k2, CHECK_false); jrose@2353: if (!match) return false; jrose@2268: } jrose@2353: return true; // got through loop; all elements equal jrose@2015: } jrose@2015: } break; jrose@2015: duke@435: case JVM_CONSTANT_UnresolvedString: duke@435: { coleenp@2497: Symbol* s1 = unresolved_string_at(index1); coleenp@2497: Symbol* s2 = cp2->unresolved_string_at(index2); duke@435: if (s1 == s2) { duke@435: return true; duke@435: } duke@435: } break; duke@435: duke@435: case JVM_CONSTANT_Utf8: duke@435: { coleenp@2497: Symbol* s1 = symbol_at(index1); coleenp@2497: Symbol* s2 = cp2->symbol_at(index2); duke@435: if (s1 == s2) { duke@435: return true; duke@435: } duke@435: } break; duke@435: duke@435: // Invalid is used as the tag for the second constant pool entry duke@435: // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should duke@435: // not be seen by itself. duke@435: case JVM_CONSTANT_Invalid: // fall through duke@435: duke@435: default: duke@435: ShouldNotReachHere(); duke@435: break; duke@435: } duke@435: duke@435: return false; duke@435: } // end compare_entry_to() duke@435: duke@435: duke@435: // Copy this constant pool's entries at start_i to end_i (inclusive) duke@435: // to the constant pool to_cp's entries starting at to_i. A total of duke@435: // (end_i - start_i) + 1 entries are copied. jrose@2353: void constantPoolOopDesc::copy_cp_to_impl(constantPoolHandle from_cp, int start_i, int end_i, duke@435: constantPoolHandle to_cp, int to_i, TRAPS) { duke@435: duke@435: int dest_i = to_i; // leave original alone for debug purposes duke@435: jrose@2353: for (int src_i = start_i; src_i <= end_i; /* see loop bottom */ ) { jrose@2353: copy_entry_to(from_cp, src_i, to_cp, dest_i, CHECK); jrose@2268: jrose@2353: switch (from_cp->tag_at(src_i).value()) { duke@435: case JVM_CONSTANT_Double: duke@435: case JVM_CONSTANT_Long: duke@435: // double and long take two constant pool entries duke@435: src_i += 2; duke@435: dest_i += 2; duke@435: break; duke@435: duke@435: default: duke@435: // all others take one constant pool entry duke@435: src_i++; duke@435: dest_i++; duke@435: break; duke@435: } duke@435: } jrose@2353: jrose@2353: int from_oplen = operand_array_length(from_cp->operands()); jrose@2353: int old_oplen = operand_array_length(to_cp->operands()); jrose@2353: if (from_oplen != 0) { jrose@2353: // append my operands to the target's operands array jrose@2353: if (old_oplen == 0) { jrose@2353: to_cp->set_operands(from_cp->operands()); // reuse; do not merge jrose@2353: } else { jrose@2353: int old_len = to_cp->operands()->length(); jrose@2353: int from_len = from_cp->operands()->length(); jrose@2353: int old_off = old_oplen * sizeof(u2); jrose@2353: int from_off = from_oplen * sizeof(u2); jrose@2353: typeArrayHandle new_operands = oopFactory::new_permanent_shortArray(old_len + from_len, CHECK); jrose@2353: int fillp = 0, len = 0; jrose@2353: // first part of dest jrose@2353: Copy::conjoint_memory_atomic(to_cp->operands()->short_at_addr(0), jrose@2353: new_operands->short_at_addr(fillp), jrose@2353: (len = old_off) * sizeof(u2)); jrose@2353: fillp += len; jrose@2353: // first part of src jrose@2353: Copy::conjoint_memory_atomic(to_cp->operands()->short_at_addr(0), jrose@2353: new_operands->short_at_addr(fillp), jrose@2353: (len = from_off) * sizeof(u2)); jrose@2353: fillp += len; jrose@2353: // second part of dest jrose@2353: Copy::conjoint_memory_atomic(to_cp->operands()->short_at_addr(old_off), jrose@2353: new_operands->short_at_addr(fillp), jrose@2353: (len = old_len - old_off) * sizeof(u2)); jrose@2353: fillp += len; jrose@2353: // second part of src jrose@2353: Copy::conjoint_memory_atomic(to_cp->operands()->short_at_addr(from_off), jrose@2353: new_operands->short_at_addr(fillp), jrose@2353: (len = from_len - from_off) * sizeof(u2)); jrose@2353: fillp += len; jrose@2353: assert(fillp == new_operands->length(), ""); jrose@2353: jrose@2353: // Adjust indexes in the first part of the copied operands array. jrose@2353: for (int j = 0; j < from_oplen; j++) { jrose@2353: int offset = operand_offset_at(new_operands(), old_oplen + j); jrose@2353: assert(offset == operand_offset_at(from_cp->operands(), j), "correct copy"); jrose@2353: offset += old_len; // every new tuple is preceded by old_len extra u2's jrose@2353: operand_offset_at_put(new_operands(), old_oplen + j, offset); jrose@2353: } jrose@2353: jrose@2353: // replace target operands array with combined array jrose@2353: to_cp->set_operands(new_operands()); jrose@2353: } jrose@2353: } jrose@2353: duke@435: } // end copy_cp_to() duke@435: duke@435: duke@435: // Copy this constant pool's entry at from_i to the constant pool duke@435: // to_cp's entry at to_i. jrose@2353: void constantPoolOopDesc::copy_entry_to(constantPoolHandle from_cp, int from_i, jrose@2353: constantPoolHandle to_cp, int to_i, jrose@2353: TRAPS) { duke@435: jrose@2353: int tag = from_cp->tag_at(from_i).value(); jrose@2353: switch (tag) { duke@435: case JVM_CONSTANT_Class: duke@435: { jrose@2353: klassOop k = from_cp->klass_at(from_i, CHECK); duke@435: to_cp->klass_at_put(to_i, k); duke@435: } break; duke@435: duke@435: case JVM_CONSTANT_ClassIndex: duke@435: { jrose@2353: jint ki = from_cp->klass_index_at(from_i); duke@435: to_cp->klass_index_at_put(to_i, ki); duke@435: } break; duke@435: duke@435: case JVM_CONSTANT_Double: duke@435: { jrose@2353: jdouble d = from_cp->double_at(from_i); duke@435: to_cp->double_at_put(to_i, d); duke@435: // double takes two constant pool entries so init second entry's tag duke@435: to_cp->tag_at_put(to_i + 1, JVM_CONSTANT_Invalid); duke@435: } break; duke@435: duke@435: case JVM_CONSTANT_Fieldref: duke@435: { jrose@2353: int class_index = from_cp->uncached_klass_ref_index_at(from_i); jrose@2353: int name_and_type_index = from_cp->uncached_name_and_type_ref_index_at(from_i); duke@435: to_cp->field_at_put(to_i, class_index, name_and_type_index); duke@435: } break; duke@435: duke@435: case JVM_CONSTANT_Float: duke@435: { jrose@2353: jfloat f = from_cp->float_at(from_i); duke@435: to_cp->float_at_put(to_i, f); duke@435: } break; duke@435: duke@435: case JVM_CONSTANT_Integer: duke@435: { jrose@2353: jint i = from_cp->int_at(from_i); duke@435: to_cp->int_at_put(to_i, i); duke@435: } break; duke@435: duke@435: case JVM_CONSTANT_InterfaceMethodref: duke@435: { jrose@2353: int class_index = from_cp->uncached_klass_ref_index_at(from_i); jrose@2353: int name_and_type_index = from_cp->uncached_name_and_type_ref_index_at(from_i); duke@435: to_cp->interface_method_at_put(to_i, class_index, name_and_type_index); duke@435: } break; duke@435: duke@435: case JVM_CONSTANT_Long: duke@435: { jrose@2353: jlong l = from_cp->long_at(from_i); duke@435: to_cp->long_at_put(to_i, l); duke@435: // long takes two constant pool entries so init second entry's tag duke@435: to_cp->tag_at_put(to_i + 1, JVM_CONSTANT_Invalid); duke@435: } break; duke@435: duke@435: case JVM_CONSTANT_Methodref: duke@435: { jrose@2353: int class_index = from_cp->uncached_klass_ref_index_at(from_i); jrose@2353: int name_and_type_index = from_cp->uncached_name_and_type_ref_index_at(from_i); duke@435: to_cp->method_at_put(to_i, class_index, name_and_type_index); duke@435: } break; duke@435: duke@435: case JVM_CONSTANT_NameAndType: duke@435: { jrose@2353: int name_ref_index = from_cp->name_ref_index_at(from_i); jrose@2353: int signature_ref_index = from_cp->signature_ref_index_at(from_i); duke@435: to_cp->name_and_type_at_put(to_i, name_ref_index, signature_ref_index); duke@435: } break; duke@435: duke@435: case JVM_CONSTANT_String: duke@435: { jrose@2353: oop s = from_cp->string_at(from_i, CHECK); duke@435: to_cp->string_at_put(to_i, s); duke@435: } break; duke@435: duke@435: case JVM_CONSTANT_StringIndex: duke@435: { jrose@2353: jint si = from_cp->string_index_at(from_i); duke@435: to_cp->string_index_at_put(to_i, si); duke@435: } break; duke@435: duke@435: case JVM_CONSTANT_UnresolvedClass: duke@435: { coleenp@2614: // Can be resolved after checking tag, so check the slot first. coleenp@2614: CPSlot entry = from_cp->slot_at(from_i); coleenp@2614: if (entry.is_oop()) { coleenp@2614: assert(entry.get_oop()->is_klass(), "must be"); coleenp@2614: // Already resolved coleenp@2614: to_cp->klass_at_put(to_i, (klassOop)entry.get_oop()); coleenp@2614: } else { coleenp@2614: to_cp->unresolved_klass_at_put(to_i, entry.get_symbol()); coleenp@2614: } duke@435: } break; duke@435: duke@435: case JVM_CONSTANT_UnresolvedClassInError: duke@435: { coleenp@2497: Symbol* k = from_cp->unresolved_klass_at(from_i); duke@435: to_cp->unresolved_klass_at_put(to_i, k); duke@435: to_cp->tag_at_put(to_i, JVM_CONSTANT_UnresolvedClassInError); duke@435: } break; duke@435: duke@435: duke@435: case JVM_CONSTANT_UnresolvedString: duke@435: { coleenp@2614: // Can be resolved after checking tag, so check the slot first. coleenp@2614: CPSlot entry = from_cp->slot_at(from_i); coleenp@2614: if (entry.is_oop()) { coleenp@2614: // Already resolved (either string or pseudo-string) coleenp@2614: to_cp->string_at_put(to_i, entry.get_oop()); coleenp@2614: } else { coleenp@2614: to_cp->unresolved_string_at_put(to_i, entry.get_symbol()); coleenp@2614: } duke@435: } break; duke@435: duke@435: case JVM_CONSTANT_Utf8: duke@435: { coleenp@2497: Symbol* s = from_cp->symbol_at(from_i); duke@435: to_cp->symbol_at_put(to_i, s); coleenp@2497: // This constantPool has the same lifetime as the original, so don't coleenp@2497: // increase reference counts for the copy. duke@435: } break; duke@435: jrose@1957: case JVM_CONSTANT_MethodType: jrose@1957: { jrose@2353: jint k = from_cp->method_type_index_at(from_i); jrose@1957: to_cp->method_type_index_at_put(to_i, k); jrose@1957: } break; jrose@1957: jrose@1957: case JVM_CONSTANT_MethodHandle: jrose@1957: { jrose@2353: int k1 = from_cp->method_handle_ref_kind_at(from_i); jrose@2353: int k2 = from_cp->method_handle_index_at(from_i); jrose@1957: to_cp->method_handle_index_at_put(to_i, k1, k2); jrose@1957: } break; jrose@1957: jrose@2015: case JVM_CONSTANT_InvokeDynamic: jrose@2015: { jrose@2353: int k1 = from_cp->invoke_dynamic_bootstrap_specifier_index(from_i); jrose@2353: int k2 = from_cp->invoke_dynamic_name_and_type_ref_index_at(from_i); jrose@2353: k1 += operand_array_length(to_cp->operands()); // to_cp might already have operands jrose@2353: to_cp->invoke_dynamic_at_put(to_i, k1, k2); jrose@2015: } break; jrose@2015: duke@435: // Invalid is used as the tag for the second constant pool entry duke@435: // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should duke@435: // not be seen by itself. duke@435: case JVM_CONSTANT_Invalid: // fall through duke@435: duke@435: default: duke@435: { duke@435: ShouldNotReachHere(); duke@435: } break; duke@435: } duke@435: } // end copy_entry_to() duke@435: duke@435: duke@435: // Search constant pool search_cp for an entry that matches this duke@435: // constant pool's entry at pattern_i. Returns the index of a duke@435: // matching entry or zero (0) if there is no matching entry. duke@435: int constantPoolOopDesc::find_matching_entry(int pattern_i, duke@435: constantPoolHandle search_cp, TRAPS) { duke@435: duke@435: // index zero (0) is not used duke@435: for (int i = 1; i < search_cp->length(); i++) { duke@435: bool found = compare_entry_to(pattern_i, search_cp, i, CHECK_0); duke@435: if (found) { duke@435: return i; duke@435: } duke@435: } duke@435: duke@435: return 0; // entry not found; return unused index zero (0) duke@435: } // end find_matching_entry() duke@435: duke@435: duke@435: #ifndef PRODUCT duke@435: duke@435: const char* constantPoolOopDesc::printable_name_at(int which) { duke@435: duke@435: constantTag tag = tag_at(which); duke@435: duke@435: if (tag.is_unresolved_string() || tag.is_string()) { duke@435: return string_at_noresolve(which); duke@435: } else if (tag.is_klass() || tag.is_unresolved_klass()) { duke@435: return klass_name_at(which)->as_C_string(); duke@435: } else if (tag.is_symbol()) { duke@435: return symbol_at(which)->as_C_string(); duke@435: } duke@435: return ""; duke@435: } duke@435: duke@435: #endif // PRODUCT duke@435: duke@435: duke@435: // JVMTI GetConstantPool support duke@435: duke@435: // For temporary use until code is stable. duke@435: #define DBG(code) duke@435: duke@435: static const char* WARN_MSG = "Must not be such entry!"; duke@435: duke@435: static void print_cpool_bytes(jint cnt, u1 *bytes) { duke@435: jint size = 0; duke@435: u2 idx1, idx2; duke@435: duke@435: for (jint idx = 1; idx < cnt; idx++) { duke@435: jint ent_size = 0; duke@435: u1 tag = *bytes++; duke@435: size++; // count tag duke@435: duke@435: printf("const #%03d, tag: %02d ", idx, tag); duke@435: switch(tag) { duke@435: case JVM_CONSTANT_Invalid: { duke@435: printf("Invalid"); duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_Unicode: { duke@435: printf("Unicode %s", WARN_MSG); duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_Utf8: { duke@435: u2 len = Bytes::get_Java_u2(bytes); duke@435: char str[128]; duke@435: if (len > 127) { duke@435: len = 127; duke@435: } duke@435: strncpy(str, (char *) (bytes+2), len); duke@435: str[len] = '\0'; duke@435: printf("Utf8 \"%s\"", str); duke@435: ent_size = 2 + len; duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_Integer: { duke@435: u4 val = Bytes::get_Java_u4(bytes); duke@435: printf("int %d", *(int *) &val); duke@435: ent_size = 4; duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_Float: { duke@435: u4 val = Bytes::get_Java_u4(bytes); duke@435: printf("float %5.3ff", *(float *) &val); duke@435: ent_size = 4; duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_Long: { duke@435: u8 val = Bytes::get_Java_u8(bytes); never@3156: printf("long "INT64_FORMAT, (int64_t) *(jlong *) &val); duke@435: ent_size = 8; duke@435: idx++; // Long takes two cpool slots duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_Double: { duke@435: u8 val = Bytes::get_Java_u8(bytes); duke@435: printf("double %5.3fd", *(jdouble *)&val); duke@435: ent_size = 8; duke@435: idx++; // Double takes two cpool slots duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_Class: { duke@435: idx1 = Bytes::get_Java_u2(bytes); duke@435: printf("class #%03d", idx1); duke@435: ent_size = 2; duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_String: { duke@435: idx1 = Bytes::get_Java_u2(bytes); duke@435: printf("String #%03d", idx1); duke@435: ent_size = 2; duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_Fieldref: { duke@435: idx1 = Bytes::get_Java_u2(bytes); duke@435: idx2 = Bytes::get_Java_u2(bytes+2); duke@435: printf("Field #%03d, #%03d", (int) idx1, (int) idx2); duke@435: ent_size = 4; duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_Methodref: { duke@435: idx1 = Bytes::get_Java_u2(bytes); duke@435: idx2 = Bytes::get_Java_u2(bytes+2); duke@435: printf("Method #%03d, #%03d", idx1, idx2); duke@435: ent_size = 4; duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_InterfaceMethodref: { duke@435: idx1 = Bytes::get_Java_u2(bytes); duke@435: idx2 = Bytes::get_Java_u2(bytes+2); duke@435: printf("InterfMethod #%03d, #%03d", idx1, idx2); duke@435: ent_size = 4; duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_NameAndType: { duke@435: idx1 = Bytes::get_Java_u2(bytes); duke@435: idx2 = Bytes::get_Java_u2(bytes+2); duke@435: printf("NameAndType #%03d, #%03d", idx1, idx2); duke@435: ent_size = 4; duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_ClassIndex: { duke@435: printf("ClassIndex %s", WARN_MSG); duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_UnresolvedClass: { duke@435: printf("UnresolvedClass: %s", WARN_MSG); duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_UnresolvedClassInError: { duke@435: printf("UnresolvedClassInErr: %s", WARN_MSG); duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_StringIndex: { duke@435: printf("StringIndex: %s", WARN_MSG); duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_UnresolvedString: { duke@435: printf("UnresolvedString: %s", WARN_MSG); duke@435: break; duke@435: } duke@435: } duke@435: printf(";\n"); duke@435: bytes += ent_size; duke@435: size += ent_size; duke@435: } duke@435: printf("Cpool size: %d\n", size); duke@435: fflush(0); duke@435: return; duke@435: } /* end print_cpool_bytes */ duke@435: duke@435: duke@435: // Returns size of constant pool entry. duke@435: jint constantPoolOopDesc::cpool_entry_size(jint idx) { duke@435: switch(tag_at(idx).value()) { duke@435: case JVM_CONSTANT_Invalid: duke@435: case JVM_CONSTANT_Unicode: duke@435: return 1; duke@435: duke@435: case JVM_CONSTANT_Utf8: duke@435: return 3 + symbol_at(idx)->utf8_length(); duke@435: duke@435: case JVM_CONSTANT_Class: duke@435: case JVM_CONSTANT_String: duke@435: case JVM_CONSTANT_ClassIndex: duke@435: case JVM_CONSTANT_UnresolvedClass: duke@435: case JVM_CONSTANT_UnresolvedClassInError: duke@435: case JVM_CONSTANT_StringIndex: duke@435: case JVM_CONSTANT_UnresolvedString: jrose@1957: case JVM_CONSTANT_MethodType: duke@435: return 3; duke@435: jrose@1957: case JVM_CONSTANT_MethodHandle: jrose@1957: return 4; //tag, ref_kind, ref_index jrose@1957: duke@435: case JVM_CONSTANT_Integer: duke@435: case JVM_CONSTANT_Float: duke@435: case JVM_CONSTANT_Fieldref: duke@435: case JVM_CONSTANT_Methodref: duke@435: case JVM_CONSTANT_InterfaceMethodref: duke@435: case JVM_CONSTANT_NameAndType: jrose@2268: return 5; jrose@2268: jrose@2015: case JVM_CONSTANT_InvokeDynamic: jrose@2353: // u1 tag, u2 bsm, u2 nt jrose@2353: return 5; duke@435: duke@435: case JVM_CONSTANT_Long: duke@435: case JVM_CONSTANT_Double: duke@435: return 9; duke@435: } duke@435: assert(false, "cpool_entry_size: Invalid constant pool entry tag"); duke@435: return 1; duke@435: } /* end cpool_entry_size */ duke@435: duke@435: duke@435: // SymbolHashMap is used to find a constant pool index from a string. duke@435: // This function fills in SymbolHashMaps, one for utf8s and one for duke@435: // class names, returns size of the cpool raw bytes. duke@435: jint constantPoolOopDesc::hash_entries_to(SymbolHashMap *symmap, duke@435: SymbolHashMap *classmap) { duke@435: jint size = 0; duke@435: duke@435: for (u2 idx = 1; idx < length(); idx++) { duke@435: u2 tag = tag_at(idx).value(); duke@435: size += cpool_entry_size(idx); duke@435: duke@435: switch(tag) { duke@435: case JVM_CONSTANT_Utf8: { coleenp@2497: Symbol* sym = symbol_at(idx); duke@435: symmap->add_entry(sym, idx); duke@435: DBG(printf("adding symbol entry %s = %d\n", sym->as_utf8(), idx)); duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_Class: duke@435: case JVM_CONSTANT_UnresolvedClass: duke@435: case JVM_CONSTANT_UnresolvedClassInError: { coleenp@2497: Symbol* sym = klass_name_at(idx); duke@435: classmap->add_entry(sym, idx); duke@435: DBG(printf("adding class entry %s = %d\n", sym->as_utf8(), idx)); duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_Long: duke@435: case JVM_CONSTANT_Double: { duke@435: idx++; // Both Long and Double take two cpool slots duke@435: break; duke@435: } duke@435: } duke@435: } duke@435: return size; duke@435: } /* end hash_utf8_entries_to */ duke@435: duke@435: duke@435: // Copy cpool bytes. duke@435: // Returns: duke@435: // 0, in case of OutOfMemoryError duke@435: // -1, in case of internal error duke@435: // > 0, count of the raw cpool bytes that have been copied duke@435: int constantPoolOopDesc::copy_cpool_bytes(int cpool_size, duke@435: SymbolHashMap* tbl, duke@435: unsigned char *bytes) { duke@435: u2 idx1, idx2; duke@435: jint size = 0; duke@435: jint cnt = length(); duke@435: unsigned char *start_bytes = bytes; duke@435: duke@435: for (jint idx = 1; idx < cnt; idx++) { duke@435: u1 tag = tag_at(idx).value(); duke@435: jint ent_size = cpool_entry_size(idx); duke@435: duke@435: assert(size + ent_size <= cpool_size, "Size mismatch"); duke@435: duke@435: *bytes = tag; duke@435: DBG(printf("#%03hd tag=%03hd, ", idx, tag)); duke@435: switch(tag) { duke@435: case JVM_CONSTANT_Invalid: { duke@435: DBG(printf("JVM_CONSTANT_Invalid")); duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_Unicode: { duke@435: assert(false, "Wrong constant pool tag: JVM_CONSTANT_Unicode"); duke@435: DBG(printf("JVM_CONSTANT_Unicode")); duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_Utf8: { coleenp@2497: Symbol* sym = symbol_at(idx); duke@435: char* str = sym->as_utf8(); duke@435: // Warning! It's crashing on x86 with len = sym->utf8_length() duke@435: int len = (int) strlen(str); duke@435: Bytes::put_Java_u2((address) (bytes+1), (u2) len); duke@435: for (int i = 0; i < len; i++) { duke@435: bytes[3+i] = (u1) str[i]; duke@435: } duke@435: DBG(printf("JVM_CONSTANT_Utf8: %s ", str)); duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_Integer: { duke@435: jint val = int_at(idx); duke@435: Bytes::put_Java_u4((address) (bytes+1), *(u4*)&val); duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_Float: { duke@435: jfloat val = float_at(idx); duke@435: Bytes::put_Java_u4((address) (bytes+1), *(u4*)&val); duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_Long: { duke@435: jlong val = long_at(idx); duke@435: Bytes::put_Java_u8((address) (bytes+1), *(u8*)&val); duke@435: idx++; // Long takes two cpool slots duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_Double: { duke@435: jdouble val = double_at(idx); duke@435: Bytes::put_Java_u8((address) (bytes+1), *(u8*)&val); duke@435: idx++; // Double takes two cpool slots duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_Class: duke@435: case JVM_CONSTANT_UnresolvedClass: duke@435: case JVM_CONSTANT_UnresolvedClassInError: { duke@435: *bytes = JVM_CONSTANT_Class; coleenp@2497: Symbol* sym = klass_name_at(idx); duke@435: idx1 = tbl->symbol_to_value(sym); duke@435: assert(idx1 != 0, "Have not found a hashtable entry"); duke@435: Bytes::put_Java_u2((address) (bytes+1), idx1); duke@435: DBG(printf("JVM_CONSTANT_Class: idx=#%03hd, %s", idx1, sym->as_utf8())); duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_String: { duke@435: unsigned int hash; duke@435: char *str = string_at_noresolve(idx); coleenp@2497: TempNewSymbol sym = SymbolTable::lookup_only(str, (int) strlen(str), hash); thurka@1208: if (sym == NULL) { thurka@1208: // sym can be NULL if string refers to incorrectly encoded JVM_CONSTANT_Utf8 thurka@1208: // this can happen with JVM TI; see CR 6839599 for more details coleenp@2497: oop string = *(obj_at_addr_raw(idx)); thurka@1208: assert(java_lang_String::is_instance(string),"Not a String"); thurka@1208: DBG(printf("Error #%03hd tag=%03hd\n", idx, tag)); thurka@1208: idx1 = 0; thurka@1208: for (int j = 0; j < tbl->table_size() && idx1 == 0; j++) { thurka@1208: for (SymbolHashMapEntry* cur = tbl->bucket(j); cur != NULL; cur = cur->next()) { thurka@1208: int length; coleenp@2497: Symbol* s = cur->symbol(); coleenp@2497: jchar* chars = s->as_unicode(length); thurka@1208: if (java_lang_String::equals(string, chars, length)) { thurka@1208: idx1 = cur->value(); thurka@1208: DBG(printf("Index found: %d\n",idx1)); thurka@1208: break; thurka@1208: } thurka@1208: } thurka@1208: } thurka@1208: } else { thurka@1208: idx1 = tbl->symbol_to_value(sym); thurka@1208: } duke@435: assert(idx1 != 0, "Have not found a hashtable entry"); duke@435: Bytes::put_Java_u2((address) (bytes+1), idx1); duke@435: DBG(printf("JVM_CONSTANT_String: idx=#%03hd, %s", idx1, str)); duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_UnresolvedString: { duke@435: *bytes = JVM_CONSTANT_String; coleenp@2497: Symbol* sym = unresolved_string_at(idx); duke@435: idx1 = tbl->symbol_to_value(sym); duke@435: assert(idx1 != 0, "Have not found a hashtable entry"); duke@435: Bytes::put_Java_u2((address) (bytes+1), idx1); duke@435: DBG(char *str = sym->as_utf8()); duke@435: DBG(printf("JVM_CONSTANT_UnresolvedString: idx=#%03hd, %s", idx1, str)); duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_Fieldref: duke@435: case JVM_CONSTANT_Methodref: duke@435: case JVM_CONSTANT_InterfaceMethodref: { duke@435: idx1 = uncached_klass_ref_index_at(idx); duke@435: idx2 = uncached_name_and_type_ref_index_at(idx); duke@435: Bytes::put_Java_u2((address) (bytes+1), idx1); duke@435: Bytes::put_Java_u2((address) (bytes+3), idx2); duke@435: DBG(printf("JVM_CONSTANT_Methodref: %hd %hd", idx1, idx2)); duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_NameAndType: { duke@435: idx1 = name_ref_index_at(idx); duke@435: idx2 = signature_ref_index_at(idx); duke@435: Bytes::put_Java_u2((address) (bytes+1), idx1); duke@435: Bytes::put_Java_u2((address) (bytes+3), idx2); duke@435: DBG(printf("JVM_CONSTANT_NameAndType: %hd %hd", idx1, idx2)); duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_ClassIndex: { duke@435: *bytes = JVM_CONSTANT_Class; duke@435: idx1 = klass_index_at(idx); duke@435: Bytes::put_Java_u2((address) (bytes+1), idx1); duke@435: DBG(printf("JVM_CONSTANT_ClassIndex: %hd", idx1)); duke@435: break; duke@435: } duke@435: case JVM_CONSTANT_StringIndex: { duke@435: *bytes = JVM_CONSTANT_String; duke@435: idx1 = string_index_at(idx); duke@435: Bytes::put_Java_u2((address) (bytes+1), idx1); duke@435: DBG(printf("JVM_CONSTANT_StringIndex: %hd", idx1)); duke@435: break; duke@435: } jrose@1957: case JVM_CONSTANT_MethodHandle: { jrose@1957: *bytes = JVM_CONSTANT_MethodHandle; jrose@1957: int kind = method_handle_ref_kind_at(idx); jrose@1957: idx1 = method_handle_index_at(idx); jrose@1957: *(bytes+1) = (unsigned char) kind; jrose@1957: Bytes::put_Java_u2((address) (bytes+2), idx1); jrose@1957: DBG(printf("JVM_CONSTANT_MethodHandle: %d %hd", kind, idx1)); jrose@1957: break; jrose@1957: } jrose@1957: case JVM_CONSTANT_MethodType: { jrose@1957: *bytes = JVM_CONSTANT_MethodType; jrose@1957: idx1 = method_type_index_at(idx); jrose@1957: Bytes::put_Java_u2((address) (bytes+1), idx1); jrose@1957: DBG(printf("JVM_CONSTANT_MethodType: %hd", idx1)); jrose@1957: break; jrose@1957: } jrose@2015: case JVM_CONSTANT_InvokeDynamic: { jrose@2353: *bytes = tag; jrose@2353: idx1 = extract_low_short_from_int(*int_at_addr(idx)); jrose@2353: idx2 = extract_high_short_from_int(*int_at_addr(idx)); jrose@2353: assert(idx2 == invoke_dynamic_name_and_type_ref_index_at(idx), "correct half of u4"); jrose@2015: Bytes::put_Java_u2((address) (bytes+1), idx1); jrose@2015: Bytes::put_Java_u2((address) (bytes+3), idx2); jrose@2353: DBG(printf("JVM_CONSTANT_InvokeDynamic: %hd %hd", idx1, idx2)); jrose@2015: break; jrose@2015: } duke@435: } duke@435: DBG(printf("\n")); duke@435: bytes += ent_size; duke@435: size += ent_size; duke@435: } duke@435: assert(size == cpool_size, "Size mismatch"); duke@435: duke@435: // Keep temorarily for debugging until it's stable. duke@435: DBG(print_cpool_bytes(cnt, start_bytes)); duke@435: return (int)(bytes - start_bytes); duke@435: } /* end copy_cpool_bytes */ duke@435: duke@435: coleenp@2497: void SymbolHashMap::add_entry(Symbol* sym, u2 value) { duke@435: char *str = sym->as_utf8(); duke@435: unsigned int hash = compute_hash(str, sym->utf8_length()); duke@435: unsigned int index = hash % table_size(); duke@435: duke@435: // check if already in map duke@435: // we prefer the first entry since it is more likely to be what was used in duke@435: // the class file duke@435: for (SymbolHashMapEntry *en = bucket(index); en != NULL; en = en->next()) { duke@435: assert(en->symbol() != NULL, "SymbolHashMapEntry symbol is NULL"); duke@435: if (en->hash() == hash && en->symbol() == sym) { duke@435: return; // already there duke@435: } duke@435: } duke@435: duke@435: SymbolHashMapEntry* entry = new SymbolHashMapEntry(hash, sym, value); duke@435: entry->set_next(bucket(index)); duke@435: _buckets[index].set_entry(entry); duke@435: assert(entry->symbol() != NULL, "SymbolHashMapEntry symbol is NULL"); duke@435: } duke@435: coleenp@2497: SymbolHashMapEntry* SymbolHashMap::find_entry(Symbol* sym) { duke@435: assert(sym != NULL, "SymbolHashMap::find_entry - symbol is NULL"); duke@435: char *str = sym->as_utf8(); duke@435: int len = sym->utf8_length(); duke@435: unsigned int hash = SymbolHashMap::compute_hash(str, len); duke@435: unsigned int index = hash % table_size(); duke@435: for (SymbolHashMapEntry *en = bucket(index); en != NULL; en = en->next()) { duke@435: assert(en->symbol() != NULL, "SymbolHashMapEntry symbol is NULL"); duke@435: if (en->hash() == hash && en->symbol() == sym) { duke@435: return en; duke@435: } duke@435: } duke@435: return NULL; duke@435: }