Wed, 25 Jan 2012 17:40:51 -0500
7132690: InstanceKlass:_reference_type should be u1 type
Summary: Change InstanceKlass::_reference_type to u1 type.
Reviewed-by: dholmes, coleenp, acorn
Contributed-by: Jiangli Zhou <jiangli.zhou@oracle.com>
duke@435 | 1 | /* |
never@2658 | 2 | * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "classfile/javaClasses.hpp" |
stefank@2314 | 27 | #include "classfile/symbolTable.hpp" |
stefank@2314 | 28 | #include "classfile/systemDictionary.hpp" |
stefank@2314 | 29 | #include "classfile/vmSymbols.hpp" |
stefank@2314 | 30 | #include "interpreter/linkResolver.hpp" |
stefank@2314 | 31 | #include "memory/oopFactory.hpp" |
stefank@2314 | 32 | #include "memory/universe.inline.hpp" |
stefank@2314 | 33 | #include "oops/constantPoolOop.hpp" |
stefank@2314 | 34 | #include "oops/instanceKlass.hpp" |
stefank@2314 | 35 | #include "oops/objArrayKlass.hpp" |
stefank@2314 | 36 | #include "oops/oop.inline.hpp" |
stefank@2314 | 37 | #include "runtime/fieldType.hpp" |
stefank@2314 | 38 | #include "runtime/init.hpp" |
stefank@2314 | 39 | #include "runtime/signature.hpp" |
stefank@2314 | 40 | #include "runtime/vframe.hpp" |
duke@435 | 41 | |
jrose@866 | 42 | void constantPoolOopDesc::set_flag_at(FlagBit fb) { |
jrose@866 | 43 | const int MAX_STATE_CHANGES = 2; |
jrose@866 | 44 | for (int i = MAX_STATE_CHANGES + 10; i > 0; i--) { |
jrose@866 | 45 | int oflags = _flags; |
jrose@866 | 46 | int nflags = oflags | (1 << (int)fb); |
jrose@866 | 47 | if (Atomic::cmpxchg(nflags, &_flags, oflags) == oflags) |
jrose@866 | 48 | return; |
jrose@866 | 49 | } |
jrose@866 | 50 | assert(false, "failed to cmpxchg flags"); |
jrose@866 | 51 | _flags |= (1 << (int)fb); // better than nothing |
jrose@866 | 52 | } |
jrose@866 | 53 | |
duke@435 | 54 | klassOop constantPoolOopDesc::klass_at_impl(constantPoolHandle this_oop, int which, TRAPS) { |
coleenp@2497 | 55 | // A resolved constantPool entry will contain a klassOop, otherwise a Symbol*. |
duke@435 | 56 | // 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 | 57 | // tag is not updated atomicly. |
coleenp@2497 | 58 | CPSlot entry = this_oop->slot_at(which); |
coleenp@2497 | 59 | if (entry.is_oop()) { |
coleenp@2497 | 60 | assert(entry.get_oop()->is_klass(), "must be"); |
duke@435 | 61 | // Already resolved - return entry. |
coleenp@2497 | 62 | return (klassOop)entry.get_oop(); |
duke@435 | 63 | } |
duke@435 | 64 | |
duke@435 | 65 | // Acquire lock on constant oop while doing update. After we get the lock, we check if another object |
duke@435 | 66 | // already has updated the object |
duke@435 | 67 | assert(THREAD->is_Java_thread(), "must be a Java thread"); |
duke@435 | 68 | bool do_resolve = false; |
duke@435 | 69 | bool in_error = false; |
duke@435 | 70 | |
coleenp@2497 | 71 | Symbol* name = NULL; |
duke@435 | 72 | Handle loader; |
duke@435 | 73 | { ObjectLocker ol(this_oop, THREAD); |
duke@435 | 74 | |
duke@435 | 75 | if (this_oop->tag_at(which).is_unresolved_klass()) { |
duke@435 | 76 | if (this_oop->tag_at(which).is_unresolved_klass_in_error()) { |
duke@435 | 77 | in_error = true; |
duke@435 | 78 | } else { |
duke@435 | 79 | do_resolve = true; |
coleenp@2497 | 80 | name = this_oop->unresolved_klass_at(which); |
duke@435 | 81 | loader = Handle(THREAD, instanceKlass::cast(this_oop->pool_holder())->class_loader()); |
duke@435 | 82 | } |
duke@435 | 83 | } |
duke@435 | 84 | } // unlocking constantPool |
duke@435 | 85 | |
duke@435 | 86 | |
duke@435 | 87 | // The original attempt to resolve this constant pool entry failed so find the |
duke@435 | 88 | // original error and throw it again (JVMS 5.4.3). |
duke@435 | 89 | if (in_error) { |
coleenp@2497 | 90 | Symbol* error = SystemDictionary::find_resolution_error(this_oop, which); |
coleenp@2497 | 91 | guarantee(error != (Symbol*)NULL, "tag mismatch with resolution error table"); |
duke@435 | 92 | ResourceMark rm; |
duke@435 | 93 | // exception text will be the class name |
duke@435 | 94 | const char* className = this_oop->unresolved_klass_at(which)->as_C_string(); |
duke@435 | 95 | THROW_MSG_0(error, className); |
duke@435 | 96 | } |
duke@435 | 97 | |
duke@435 | 98 | if (do_resolve) { |
duke@435 | 99 | // this_oop must be unlocked during resolve_or_fail |
duke@435 | 100 | oop protection_domain = Klass::cast(this_oop->pool_holder())->protection_domain(); |
duke@435 | 101 | Handle h_prot (THREAD, protection_domain); |
duke@435 | 102 | klassOop k_oop = SystemDictionary::resolve_or_fail(name, loader, h_prot, true, THREAD); |
duke@435 | 103 | KlassHandle k; |
duke@435 | 104 | if (!HAS_PENDING_EXCEPTION) { |
duke@435 | 105 | k = KlassHandle(THREAD, k_oop); |
duke@435 | 106 | // Do access check for klasses |
duke@435 | 107 | verify_constant_pool_resolve(this_oop, k, THREAD); |
duke@435 | 108 | } |
duke@435 | 109 | |
duke@435 | 110 | // Failed to resolve class. We must record the errors so that subsequent attempts |
duke@435 | 111 | // to resolve this constant pool entry fail with the same error (JVMS 5.4.3). |
duke@435 | 112 | if (HAS_PENDING_EXCEPTION) { |
duke@435 | 113 | ResourceMark rm; |
coleenp@2497 | 114 | Symbol* error = PENDING_EXCEPTION->klass()->klass_part()->name(); |
duke@435 | 115 | |
duke@435 | 116 | bool throw_orig_error = false; |
duke@435 | 117 | { |
duke@435 | 118 | ObjectLocker ol (this_oop, THREAD); |
duke@435 | 119 | |
duke@435 | 120 | // some other thread has beaten us and has resolved the class. |
duke@435 | 121 | if (this_oop->tag_at(which).is_klass()) { |
duke@435 | 122 | CLEAR_PENDING_EXCEPTION; |
duke@435 | 123 | entry = this_oop->resolved_klass_at(which); |
coleenp@2497 | 124 | return (klassOop)entry.get_oop(); |
duke@435 | 125 | } |
duke@435 | 126 | |
duke@435 | 127 | if (!PENDING_EXCEPTION-> |
never@1577 | 128 | is_a(SystemDictionary::LinkageError_klass())) { |
duke@435 | 129 | // Just throw the exception and don't prevent these classes from |
duke@435 | 130 | // being loaded due to virtual machine errors like StackOverflow |
duke@435 | 131 | // and OutOfMemoryError, etc, or if the thread was hit by stop() |
duke@435 | 132 | // Needs clarification to section 5.4.3 of the VM spec (see 6308271) |
duke@435 | 133 | } |
duke@435 | 134 | else if (!this_oop->tag_at(which).is_unresolved_klass_in_error()) { |
duke@435 | 135 | SystemDictionary::add_resolution_error(this_oop, which, error); |
duke@435 | 136 | this_oop->tag_at_put(which, JVM_CONSTANT_UnresolvedClassInError); |
duke@435 | 137 | } else { |
duke@435 | 138 | // some other thread has put the class in error state. |
coleenp@2497 | 139 | error = SystemDictionary::find_resolution_error(this_oop, which); |
coleenp@2497 | 140 | assert(error != NULL, "checking"); |
duke@435 | 141 | throw_orig_error = true; |
duke@435 | 142 | } |
duke@435 | 143 | } // unlocked |
duke@435 | 144 | |
duke@435 | 145 | if (throw_orig_error) { |
duke@435 | 146 | CLEAR_PENDING_EXCEPTION; |
duke@435 | 147 | ResourceMark rm; |
duke@435 | 148 | const char* className = this_oop->unresolved_klass_at(which)->as_C_string(); |
duke@435 | 149 | THROW_MSG_0(error, className); |
duke@435 | 150 | } |
duke@435 | 151 | |
duke@435 | 152 | return 0; |
duke@435 | 153 | } |
duke@435 | 154 | |
duke@435 | 155 | if (TraceClassResolution && !k()->klass_part()->oop_is_array()) { |
duke@435 | 156 | // skip resolving the constant pool so that this code get's |
duke@435 | 157 | // called the next time some bytecodes refer to this class. |
duke@435 | 158 | ResourceMark rm; |
duke@435 | 159 | int line_number = -1; |
duke@435 | 160 | const char * source_file = NULL; |
duke@435 | 161 | if (JavaThread::current()->has_last_Java_frame()) { |
duke@435 | 162 | // try to identify the method which called this function. |
duke@435 | 163 | vframeStream vfst(JavaThread::current()); |
duke@435 | 164 | if (!vfst.at_end()) { |
duke@435 | 165 | line_number = vfst.method()->line_number_from_bci(vfst.bci()); |
coleenp@2497 | 166 | Symbol* s = instanceKlass::cast(vfst.method()->method_holder())->source_file_name(); |
duke@435 | 167 | if (s != NULL) { |
duke@435 | 168 | source_file = s->as_C_string(); |
duke@435 | 169 | } |
duke@435 | 170 | } |
duke@435 | 171 | } |
duke@435 | 172 | if (k() != this_oop->pool_holder()) { |
duke@435 | 173 | // only print something if the classes are different |
duke@435 | 174 | if (source_file != NULL) { |
duke@435 | 175 | tty->print("RESOLVE %s %s %s:%d\n", |
duke@435 | 176 | instanceKlass::cast(this_oop->pool_holder())->external_name(), |
duke@435 | 177 | instanceKlass::cast(k())->external_name(), source_file, line_number); |
duke@435 | 178 | } else { |
duke@435 | 179 | tty->print("RESOLVE %s %s\n", |
duke@435 | 180 | instanceKlass::cast(this_oop->pool_holder())->external_name(), |
duke@435 | 181 | instanceKlass::cast(k())->external_name()); |
duke@435 | 182 | } |
duke@435 | 183 | } |
duke@435 | 184 | return k(); |
duke@435 | 185 | } else { |
duke@435 | 186 | ObjectLocker ol (this_oop, THREAD); |
duke@435 | 187 | // Only updated constant pool - if it is resolved. |
duke@435 | 188 | do_resolve = this_oop->tag_at(which).is_unresolved_klass(); |
duke@435 | 189 | if (do_resolve) { |
duke@435 | 190 | this_oop->klass_at_put(which, k()); |
duke@435 | 191 | } |
duke@435 | 192 | } |
duke@435 | 193 | } |
duke@435 | 194 | |
duke@435 | 195 | entry = this_oop->resolved_klass_at(which); |
coleenp@2497 | 196 | assert(entry.is_oop() && entry.get_oop()->is_klass(), "must be resolved at this point"); |
coleenp@2497 | 197 | return (klassOop)entry.get_oop(); |
duke@435 | 198 | } |
duke@435 | 199 | |
duke@435 | 200 | |
duke@435 | 201 | // Does not update constantPoolOop - to avoid any exception throwing. Used |
duke@435 | 202 | // by compiler and exception handling. Also used to avoid classloads for |
duke@435 | 203 | // instanceof operations. Returns NULL if the class has not been loaded or |
duke@435 | 204 | // if the verification of constant pool failed |
duke@435 | 205 | klassOop constantPoolOopDesc::klass_at_if_loaded(constantPoolHandle this_oop, int which) { |
coleenp@2497 | 206 | CPSlot entry = this_oop->slot_at(which); |
coleenp@2497 | 207 | if (entry.is_oop()) { |
coleenp@2497 | 208 | assert(entry.get_oop()->is_klass(), "must be"); |
coleenp@2497 | 209 | return (klassOop)entry.get_oop(); |
duke@435 | 210 | } else { |
coleenp@2497 | 211 | assert(entry.is_metadata(), "must be either symbol or klass"); |
duke@435 | 212 | Thread *thread = Thread::current(); |
coleenp@2497 | 213 | Symbol* name = entry.get_symbol(); |
duke@435 | 214 | oop loader = instanceKlass::cast(this_oop->pool_holder())->class_loader(); |
duke@435 | 215 | oop protection_domain = Klass::cast(this_oop->pool_holder())->protection_domain(); |
duke@435 | 216 | Handle h_prot (thread, protection_domain); |
duke@435 | 217 | Handle h_loader (thread, loader); |
duke@435 | 218 | klassOop k = SystemDictionary::find(name, h_loader, h_prot, thread); |
duke@435 | 219 | |
duke@435 | 220 | if (k != NULL) { |
duke@435 | 221 | // Make sure that resolving is legal |
duke@435 | 222 | EXCEPTION_MARK; |
duke@435 | 223 | KlassHandle klass(THREAD, k); |
duke@435 | 224 | // return NULL if verification fails |
duke@435 | 225 | verify_constant_pool_resolve(this_oop, klass, THREAD); |
duke@435 | 226 | if (HAS_PENDING_EXCEPTION) { |
duke@435 | 227 | CLEAR_PENDING_EXCEPTION; |
duke@435 | 228 | return NULL; |
duke@435 | 229 | } |
duke@435 | 230 | return klass(); |
duke@435 | 231 | } else { |
duke@435 | 232 | return k; |
duke@435 | 233 | } |
duke@435 | 234 | } |
duke@435 | 235 | } |
duke@435 | 236 | |
duke@435 | 237 | |
duke@435 | 238 | klassOop constantPoolOopDesc::klass_ref_at_if_loaded(constantPoolHandle this_oop, int which) { |
duke@435 | 239 | return klass_at_if_loaded(this_oop, this_oop->klass_ref_index_at(which)); |
duke@435 | 240 | } |
duke@435 | 241 | |
duke@435 | 242 | |
duke@435 | 243 | // This is an interface for the compiler that allows accessing non-resolved entries |
duke@435 | 244 | // in the constant pool - but still performs the validations tests. Must be used |
duke@435 | 245 | // in a pre-parse of the compiler - to determine what it can do and not do. |
duke@435 | 246 | // Note: We cannot update the ConstantPool from the vm_thread. |
duke@435 | 247 | klassOop constantPoolOopDesc::klass_ref_at_if_loaded_check(constantPoolHandle this_oop, int index, TRAPS) { |
duke@435 | 248 | int which = this_oop->klass_ref_index_at(index); |
coleenp@2497 | 249 | CPSlot entry = this_oop->slot_at(which); |
coleenp@2497 | 250 | if (entry.is_oop()) { |
coleenp@2497 | 251 | assert(entry.get_oop()->is_klass(), "must be"); |
coleenp@2497 | 252 | return (klassOop)entry.get_oop(); |
duke@435 | 253 | } else { |
coleenp@2497 | 254 | assert(entry.is_metadata(), "must be either symbol or klass"); |
coleenp@2497 | 255 | Symbol* name = entry.get_symbol(); |
duke@435 | 256 | oop loader = instanceKlass::cast(this_oop->pool_holder())->class_loader(); |
duke@435 | 257 | oop protection_domain = Klass::cast(this_oop->pool_holder())->protection_domain(); |
duke@435 | 258 | Handle h_loader(THREAD, loader); |
duke@435 | 259 | Handle h_prot (THREAD, protection_domain); |
duke@435 | 260 | KlassHandle k(THREAD, SystemDictionary::find(name, h_loader, h_prot, THREAD)); |
duke@435 | 261 | |
duke@435 | 262 | // Do access check for klasses |
duke@435 | 263 | if( k.not_null() ) verify_constant_pool_resolve(this_oop, k, CHECK_NULL); |
duke@435 | 264 | return k(); |
duke@435 | 265 | } |
duke@435 | 266 | } |
duke@435 | 267 | |
duke@435 | 268 | |
jrose@2982 | 269 | methodOop constantPoolOopDesc::method_at_if_loaded(constantPoolHandle cpool, |
jrose@2982 | 270 | int which, Bytecodes::Code invoke_code) { |
jrose@2982 | 271 | assert(!constantPoolCacheOopDesc::is_secondary_index(which), "no indy instruction here"); |
jrose@2982 | 272 | if (cpool->cache() == NULL) return false; // nothing to load yet |
jrose@2982 | 273 | int cache_index = which - CPCACHE_INDEX_TAG; |
jrose@2982 | 274 | if (!(cache_index >= 0 && cache_index < cpool->cache()->length())) { |
jrose@2982 | 275 | if (PrintMiscellaneous && (Verbose||WizardMode)) { |
jrose@2982 | 276 | tty->print_cr("bad operand %d for %d in:", which, invoke_code); cpool->print(); |
jrose@2982 | 277 | } |
jrose@2982 | 278 | return NULL; |
jrose@2982 | 279 | } |
jrose@2982 | 280 | ConstantPoolCacheEntry* e = cpool->cache()->entry_at(cache_index); |
jrose@2982 | 281 | if (invoke_code != Bytecodes::_illegal) |
jrose@2982 | 282 | return e->get_method_if_resolved(invoke_code, cpool); |
jrose@2982 | 283 | Bytecodes::Code bc; |
jrose@2982 | 284 | if ((bc = e->bytecode_1()) != (Bytecodes::Code)0) |
jrose@2982 | 285 | return e->get_method_if_resolved(bc, cpool); |
jrose@2982 | 286 | if ((bc = e->bytecode_2()) != (Bytecodes::Code)0) |
jrose@2982 | 287 | return e->get_method_if_resolved(bc, cpool); |
jrose@2982 | 288 | return NULL; |
jrose@2982 | 289 | } |
jrose@2982 | 290 | |
jrose@2982 | 291 | |
coleenp@2497 | 292 | Symbol* constantPoolOopDesc::impl_name_ref_at(int which, bool uncached) { |
jrose@1161 | 293 | int name_index = name_ref_index_at(impl_name_and_type_ref_index_at(which, uncached)); |
duke@435 | 294 | return symbol_at(name_index); |
duke@435 | 295 | } |
duke@435 | 296 | |
duke@435 | 297 | |
coleenp@2497 | 298 | Symbol* constantPoolOopDesc::impl_signature_ref_at(int which, bool uncached) { |
jrose@1161 | 299 | int signature_index = signature_ref_index_at(impl_name_and_type_ref_index_at(which, uncached)); |
duke@435 | 300 | return symbol_at(signature_index); |
duke@435 | 301 | } |
duke@435 | 302 | |
duke@435 | 303 | |
jrose@1161 | 304 | int constantPoolOopDesc::impl_name_and_type_ref_index_at(int which, bool uncached) { |
jrose@1494 | 305 | int i = which; |
jrose@1494 | 306 | if (!uncached && cache() != NULL) { |
jrose@2015 | 307 | if (constantPoolCacheOopDesc::is_secondary_index(which)) { |
jrose@2265 | 308 | // Invokedynamic index. |
jrose@2015 | 309 | int pool_index = cache()->main_entry_at(which)->constant_pool_index(); |
jrose@2742 | 310 | pool_index = invoke_dynamic_name_and_type_ref_index_at(pool_index); |
jrose@2015 | 311 | assert(tag_at(pool_index).is_name_and_type(), ""); |
jrose@2015 | 312 | return pool_index; |
jrose@2015 | 313 | } |
jrose@1494 | 314 | // change byte-ordering and go via cache |
jrose@1494 | 315 | i = remap_instruction_operand_from_cache(which); |
jrose@1494 | 316 | } else { |
jrose@2268 | 317 | if (tag_at(which).is_invoke_dynamic()) { |
jrose@2268 | 318 | int pool_index = invoke_dynamic_name_and_type_ref_index_at(which); |
jrose@2268 | 319 | assert(tag_at(pool_index).is_name_and_type(), ""); |
jrose@2268 | 320 | return pool_index; |
jrose@2268 | 321 | } |
jrose@1494 | 322 | } |
jrose@1494 | 323 | assert(tag_at(i).is_field_or_method(), "Corrupted constant pool"); |
jrose@2268 | 324 | assert(!tag_at(i).is_invoke_dynamic(), "Must be handled above"); |
jrose@1494 | 325 | jint ref_index = *int_at_addr(i); |
duke@435 | 326 | return extract_high_short_from_int(ref_index); |
duke@435 | 327 | } |
duke@435 | 328 | |
duke@435 | 329 | |
jrose@1161 | 330 | int constantPoolOopDesc::impl_klass_ref_index_at(int which, bool uncached) { |
jrose@1494 | 331 | guarantee(!constantPoolCacheOopDesc::is_secondary_index(which), |
jrose@1494 | 332 | "an invokedynamic instruction does not have a klass"); |
jrose@1494 | 333 | int i = which; |
jrose@1494 | 334 | if (!uncached && cache() != NULL) { |
jrose@1494 | 335 | // change byte-ordering and go via cache |
jrose@1494 | 336 | i = remap_instruction_operand_from_cache(which); |
jrose@1494 | 337 | } |
jrose@1494 | 338 | assert(tag_at(i).is_field_or_method(), "Corrupted constant pool"); |
jrose@1494 | 339 | jint ref_index = *int_at_addr(i); |
duke@435 | 340 | return extract_low_short_from_int(ref_index); |
duke@435 | 341 | } |
duke@435 | 342 | |
duke@435 | 343 | |
jrose@1161 | 344 | |
jrose@1494 | 345 | int constantPoolOopDesc::remap_instruction_operand_from_cache(int operand) { |
jrose@1920 | 346 | int cpc_index = operand; |
jrose@1920 | 347 | DEBUG_ONLY(cpc_index -= CPCACHE_INDEX_TAG); |
jrose@1920 | 348 | assert((int)(u2)cpc_index == cpc_index, "clean u2"); |
jrose@1494 | 349 | int member_index = cache()->entry_at(cpc_index)->constant_pool_index(); |
jrose@1494 | 350 | return member_index; |
jrose@1161 | 351 | } |
jrose@1161 | 352 | |
jrose@1161 | 353 | |
duke@435 | 354 | void constantPoolOopDesc::verify_constant_pool_resolve(constantPoolHandle this_oop, KlassHandle k, TRAPS) { |
duke@435 | 355 | if (k->oop_is_instance() || k->oop_is_objArray()) { |
duke@435 | 356 | instanceKlassHandle holder (THREAD, this_oop->pool_holder()); |
duke@435 | 357 | klassOop elem_oop = k->oop_is_instance() ? k() : objArrayKlass::cast(k())->bottom_klass(); |
duke@435 | 358 | KlassHandle element (THREAD, elem_oop); |
duke@435 | 359 | |
duke@435 | 360 | // The element type could be a typeArray - we only need the access check if it is |
duke@435 | 361 | // an reference to another class |
duke@435 | 362 | if (element->oop_is_instance()) { |
duke@435 | 363 | LinkResolver::check_klass_accessability(holder, element, CHECK); |
duke@435 | 364 | } |
duke@435 | 365 | } |
duke@435 | 366 | } |
duke@435 | 367 | |
duke@435 | 368 | |
jrose@1161 | 369 | int constantPoolOopDesc::name_ref_index_at(int which_nt) { |
jrose@1161 | 370 | jint ref_index = name_and_type_at(which_nt); |
duke@435 | 371 | return extract_low_short_from_int(ref_index); |
duke@435 | 372 | } |
duke@435 | 373 | |
duke@435 | 374 | |
jrose@1161 | 375 | int constantPoolOopDesc::signature_ref_index_at(int which_nt) { |
jrose@1161 | 376 | jint ref_index = name_and_type_at(which_nt); |
duke@435 | 377 | return extract_high_short_from_int(ref_index); |
duke@435 | 378 | } |
duke@435 | 379 | |
duke@435 | 380 | |
duke@435 | 381 | klassOop constantPoolOopDesc::klass_ref_at(int which, TRAPS) { |
duke@435 | 382 | return klass_at(klass_ref_index_at(which), CHECK_NULL); |
duke@435 | 383 | } |
duke@435 | 384 | |
duke@435 | 385 | |
coleenp@2497 | 386 | Symbol* constantPoolOopDesc::klass_name_at(int which) { |
duke@435 | 387 | assert(tag_at(which).is_unresolved_klass() || tag_at(which).is_klass(), |
duke@435 | 388 | "Corrupted constant pool"); |
coleenp@2497 | 389 | // A resolved constantPool entry will contain a klassOop, otherwise a Symbol*. |
duke@435 | 390 | // 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 | 391 | // tag is not updated atomicly. |
coleenp@2497 | 392 | CPSlot entry = slot_at(which); |
coleenp@2497 | 393 | if (entry.is_oop()) { |
duke@435 | 394 | // Already resolved - return entry's name. |
coleenp@2497 | 395 | assert(entry.get_oop()->is_klass(), "must be"); |
coleenp@2497 | 396 | return klassOop(entry.get_oop())->klass_part()->name(); |
duke@435 | 397 | } else { |
coleenp@2497 | 398 | assert(entry.is_metadata(), "must be either symbol or klass"); |
coleenp@2497 | 399 | return entry.get_symbol(); |
duke@435 | 400 | } |
duke@435 | 401 | } |
duke@435 | 402 | |
coleenp@2497 | 403 | Symbol* constantPoolOopDesc::klass_ref_at_noresolve(int which) { |
duke@435 | 404 | jint ref_index = klass_ref_index_at(which); |
duke@435 | 405 | return klass_at_noresolve(ref_index); |
duke@435 | 406 | } |
duke@435 | 407 | |
coleenp@2497 | 408 | Symbol* constantPoolOopDesc::uncached_klass_ref_at_noresolve(int which) { |
jrose@1957 | 409 | jint ref_index = uncached_klass_ref_index_at(which); |
jrose@1957 | 410 | return klass_at_noresolve(ref_index); |
jrose@1957 | 411 | } |
jrose@1957 | 412 | |
duke@435 | 413 | char* constantPoolOopDesc::string_at_noresolve(int which) { |
duke@435 | 414 | // Test entry type in case string is resolved while in here. |
coleenp@2497 | 415 | CPSlot entry = slot_at(which); |
coleenp@2497 | 416 | if (entry.is_metadata()) { |
coleenp@2497 | 417 | return (entry.get_symbol())->as_C_string(); |
coleenp@2497 | 418 | } else if (java_lang_String::is_instance(entry.get_oop())) { |
coleenp@2497 | 419 | return java_lang_String::as_utf8_string(entry.get_oop()); |
duke@435 | 420 | } else { |
jrose@866 | 421 | return (char*)"<pseudo-string>"; |
duke@435 | 422 | } |
duke@435 | 423 | } |
duke@435 | 424 | |
duke@435 | 425 | |
duke@435 | 426 | BasicType constantPoolOopDesc::basic_type_for_signature_at(int which) { |
duke@435 | 427 | return FieldType::basic_type(symbol_at(which)); |
duke@435 | 428 | } |
duke@435 | 429 | |
duke@435 | 430 | |
duke@435 | 431 | void constantPoolOopDesc::resolve_string_constants_impl(constantPoolHandle this_oop, TRAPS) { |
duke@435 | 432 | for (int index = 1; index < this_oop->length(); index++) { // Index 0 is unused |
duke@435 | 433 | if (this_oop->tag_at(index).is_unresolved_string()) { |
duke@435 | 434 | this_oop->string_at(index, CHECK); |
duke@435 | 435 | } |
duke@435 | 436 | } |
duke@435 | 437 | } |
duke@435 | 438 | |
jrose@2268 | 439 | // A resolved constant value in the CP cache is represented as a non-null |
jrose@2268 | 440 | // value. As a special case, this value can be a 'systemObjArray' |
jrose@2268 | 441 | // which masks an exception object to throw. |
jrose@2268 | 442 | // This allows a MethodHandle constant reference to throw a consistent |
jrose@2268 | 443 | // exception every time, if it fails to resolve. |
jrose@2268 | 444 | static oop decode_exception_from_f1(oop result_oop, TRAPS) { |
jrose@2268 | 445 | if (result_oop->klass() != Universe::systemObjArrayKlassObj()) |
jrose@2268 | 446 | return result_oop; |
jrose@2268 | 447 | |
jrose@2268 | 448 | // Special cases here: Masked null, saved exception. |
jrose@2268 | 449 | objArrayOop sys_array = (objArrayOop) result_oop; |
jrose@2268 | 450 | assert(sys_array->length() == 1, "bad system array"); |
jrose@2268 | 451 | if (sys_array->length() == 1) { |
jrose@2268 | 452 | THROW_OOP_(sys_array->obj_at(0), NULL); |
jrose@2268 | 453 | } |
jrose@2268 | 454 | return NULL; |
jrose@2268 | 455 | } |
jrose@2268 | 456 | |
jrose@1957 | 457 | oop constantPoolOopDesc::resolve_constant_at_impl(constantPoolHandle this_oop, int index, int cache_index, TRAPS) { |
jrose@1957 | 458 | oop result_oop = NULL; |
jrose@2268 | 459 | Handle throw_exception; |
jrose@2268 | 460 | |
jrose@2268 | 461 | if (cache_index == _possible_index_sentinel) { |
jrose@2268 | 462 | // It is possible that this constant is one which is cached in the CP cache. |
jrose@2268 | 463 | // We'll do a linear search. This should be OK because this usage is rare. |
jrose@2268 | 464 | assert(index > 0, "valid index"); |
jrose@2268 | 465 | constantPoolCacheOop cache = this_oop()->cache(); |
jrose@2268 | 466 | for (int i = 0, len = cache->length(); i < len; i++) { |
jrose@2268 | 467 | ConstantPoolCacheEntry* cpc_entry = cache->entry_at(i); |
jrose@2268 | 468 | if (!cpc_entry->is_secondary_entry() && cpc_entry->constant_pool_index() == index) { |
jrose@2268 | 469 | // Switch the query to use this CPC entry. |
jrose@2268 | 470 | cache_index = i; |
jrose@2268 | 471 | index = _no_index_sentinel; |
jrose@2268 | 472 | break; |
jrose@2268 | 473 | } |
jrose@2268 | 474 | } |
jrose@2268 | 475 | if (cache_index == _possible_index_sentinel) |
jrose@2268 | 476 | cache_index = _no_index_sentinel; // not found |
jrose@2268 | 477 | } |
jrose@2268 | 478 | assert(cache_index == _no_index_sentinel || cache_index >= 0, ""); |
jrose@2268 | 479 | assert(index == _no_index_sentinel || index >= 0, ""); |
jrose@2268 | 480 | |
jrose@1957 | 481 | if (cache_index >= 0) { |
jrose@2268 | 482 | assert(index == _no_index_sentinel, "only one kind of index at a time"); |
jrose@1957 | 483 | ConstantPoolCacheEntry* cpc_entry = this_oop->cache()->entry_at(cache_index); |
jrose@1957 | 484 | result_oop = cpc_entry->f1(); |
jrose@1957 | 485 | if (result_oop != NULL) { |
jrose@2268 | 486 | return decode_exception_from_f1(result_oop, THREAD); |
jrose@2268 | 487 | // That was easy... |
jrose@1957 | 488 | } |
jrose@1957 | 489 | index = cpc_entry->constant_pool_index(); |
jrose@1957 | 490 | } |
jrose@1957 | 491 | |
jrose@2268 | 492 | jvalue prim_value; // temp used only in a few cases below |
jrose@2268 | 493 | |
jrose@1957 | 494 | int tag_value = this_oop->tag_at(index).value(); |
jrose@1957 | 495 | switch (tag_value) { |
jrose@1957 | 496 | |
jrose@1957 | 497 | case JVM_CONSTANT_UnresolvedClass: |
jrose@1957 | 498 | case JVM_CONSTANT_UnresolvedClassInError: |
jrose@1957 | 499 | case JVM_CONSTANT_Class: |
jrose@1957 | 500 | { |
jrose@1957 | 501 | klassOop resolved = klass_at_impl(this_oop, index, CHECK_NULL); |
jrose@1957 | 502 | // ldc wants the java mirror. |
never@2658 | 503 | result_oop = resolved->java_mirror(); |
jrose@1957 | 504 | break; |
jrose@1957 | 505 | } |
jrose@1957 | 506 | |
jrose@1957 | 507 | case JVM_CONSTANT_String: |
jrose@1957 | 508 | case JVM_CONSTANT_UnresolvedString: |
jrose@1957 | 509 | if (this_oop->is_pseudo_string_at(index)) { |
jrose@1957 | 510 | result_oop = this_oop->pseudo_string_at(index); |
jrose@1957 | 511 | break; |
jrose@1957 | 512 | } |
jrose@1957 | 513 | result_oop = string_at_impl(this_oop, index, CHECK_NULL); |
jrose@1957 | 514 | break; |
jrose@1957 | 515 | |
jrose@1957 | 516 | case JVM_CONSTANT_Object: |
jrose@1957 | 517 | result_oop = this_oop->object_at(index); |
jrose@1957 | 518 | break; |
jrose@1957 | 519 | |
jrose@1957 | 520 | case JVM_CONSTANT_MethodHandle: |
jrose@1957 | 521 | { |
jrose@1957 | 522 | int ref_kind = this_oop->method_handle_ref_kind_at(index); |
jrose@1957 | 523 | int callee_index = this_oop->method_handle_klass_index_at(index); |
coleenp@2497 | 524 | Symbol* name = this_oop->method_handle_name_ref_at(index); |
coleenp@2497 | 525 | Symbol* signature = this_oop->method_handle_signature_ref_at(index); |
jrose@1957 | 526 | if (PrintMiscellaneous) |
jrose@1957 | 527 | tty->print_cr("resolve JVM_CONSTANT_MethodHandle:%d [%d/%d/%d] %s.%s", |
jrose@1957 | 528 | ref_kind, index, this_oop->method_handle_index_at(index), |
jrose@1957 | 529 | callee_index, name->as_C_string(), signature->as_C_string()); |
jrose@1957 | 530 | KlassHandle callee; |
jrose@1957 | 531 | { klassOop k = klass_at_impl(this_oop, callee_index, CHECK_NULL); |
jrose@1957 | 532 | callee = KlassHandle(THREAD, k); |
jrose@1957 | 533 | } |
jrose@1957 | 534 | KlassHandle klass(THREAD, this_oop->pool_holder()); |
jrose@1957 | 535 | Handle value = SystemDictionary::link_method_handle_constant(klass, ref_kind, |
jrose@1957 | 536 | callee, name, signature, |
jrose@2268 | 537 | THREAD); |
jrose@2268 | 538 | if (HAS_PENDING_EXCEPTION) { |
jrose@2268 | 539 | throw_exception = Handle(THREAD, PENDING_EXCEPTION); |
jrose@2268 | 540 | CLEAR_PENDING_EXCEPTION; |
jrose@2268 | 541 | break; |
jrose@2268 | 542 | } |
jrose@1957 | 543 | result_oop = value(); |
jrose@2268 | 544 | assert(result_oop != NULL, ""); |
jrose@1957 | 545 | break; |
jrose@1957 | 546 | } |
jrose@1957 | 547 | |
jrose@1957 | 548 | case JVM_CONSTANT_MethodType: |
jrose@1957 | 549 | { |
coleenp@2497 | 550 | Symbol* signature = this_oop->method_type_signature_at(index); |
jrose@1957 | 551 | if (PrintMiscellaneous) |
jrose@1957 | 552 | tty->print_cr("resolve JVM_CONSTANT_MethodType [%d/%d] %s", |
jrose@1957 | 553 | index, this_oop->method_type_index_at(index), |
jrose@1957 | 554 | signature->as_C_string()); |
jrose@1957 | 555 | KlassHandle klass(THREAD, this_oop->pool_holder()); |
jrose@1957 | 556 | bool ignore_is_on_bcp = false; |
jrose@1957 | 557 | Handle value = SystemDictionary::find_method_handle_type(signature, |
jrose@1957 | 558 | klass, |
jrose@2148 | 559 | false, |
jrose@1957 | 560 | ignore_is_on_bcp, |
jrose@2268 | 561 | THREAD); |
jrose@2268 | 562 | if (HAS_PENDING_EXCEPTION) { |
jrose@2268 | 563 | throw_exception = Handle(THREAD, PENDING_EXCEPTION); |
jrose@2268 | 564 | CLEAR_PENDING_EXCEPTION; |
jrose@2268 | 565 | break; |
jrose@2268 | 566 | } |
jrose@1957 | 567 | result_oop = value(); |
jrose@2268 | 568 | assert(result_oop != NULL, ""); |
jrose@1957 | 569 | break; |
jrose@1957 | 570 | } |
jrose@1957 | 571 | |
jrose@1957 | 572 | case JVM_CONSTANT_Integer: |
jrose@2268 | 573 | prim_value.i = this_oop->int_at(index); |
jrose@2268 | 574 | result_oop = java_lang_boxing_object::create(T_INT, &prim_value, CHECK_NULL); |
jrose@2268 | 575 | break; |
jrose@2268 | 576 | |
jrose@1957 | 577 | case JVM_CONSTANT_Float: |
jrose@2268 | 578 | prim_value.f = this_oop->float_at(index); |
jrose@2268 | 579 | result_oop = java_lang_boxing_object::create(T_FLOAT, &prim_value, CHECK_NULL); |
jrose@2268 | 580 | break; |
jrose@2268 | 581 | |
jrose@1957 | 582 | case JVM_CONSTANT_Long: |
jrose@2268 | 583 | prim_value.j = this_oop->long_at(index); |
jrose@2268 | 584 | result_oop = java_lang_boxing_object::create(T_LONG, &prim_value, CHECK_NULL); |
jrose@2268 | 585 | break; |
jrose@2268 | 586 | |
jrose@1957 | 587 | case JVM_CONSTANT_Double: |
jrose@2268 | 588 | prim_value.d = this_oop->double_at(index); |
jrose@2268 | 589 | result_oop = java_lang_boxing_object::create(T_DOUBLE, &prim_value, CHECK_NULL); |
jrose@1957 | 590 | break; |
jrose@1957 | 591 | |
jrose@1957 | 592 | default: |
jrose@1957 | 593 | DEBUG_ONLY( tty->print_cr("*** %p: tag at CP[%d/%d] = %d", |
jrose@1957 | 594 | this_oop(), index, cache_index, tag_value) ); |
jrose@1957 | 595 | assert(false, "unexpected constant tag"); |
jrose@1957 | 596 | break; |
jrose@1957 | 597 | } |
jrose@1957 | 598 | |
jrose@1957 | 599 | if (cache_index >= 0) { |
jrose@1957 | 600 | // Cache the oop here also. |
jrose@2268 | 601 | if (throw_exception.not_null()) { |
jrose@2268 | 602 | objArrayOop sys_array = oopFactory::new_system_objArray(1, CHECK_NULL); |
jrose@2268 | 603 | sys_array->obj_at_put(0, throw_exception()); |
jrose@2268 | 604 | result_oop = sys_array; |
jrose@2268 | 605 | throw_exception = Handle(); // be tidy |
jrose@2268 | 606 | } |
jrose@2268 | 607 | Handle result_handle(THREAD, result_oop); |
jrose@1957 | 608 | result_oop = NULL; // safety |
jrose@1957 | 609 | ObjectLocker ol(this_oop, THREAD); |
jrose@1957 | 610 | ConstantPoolCacheEntry* cpc_entry = this_oop->cache()->entry_at(cache_index); |
jrose@2268 | 611 | result_oop = cpc_entry->f1(); |
jrose@2268 | 612 | // Benign race condition: f1 may already be filled in while we were trying to lock. |
jrose@2268 | 613 | // The important thing here is that all threads pick up the same result. |
jrose@2268 | 614 | // It doesn't matter which racing thread wins, as long as only one |
jrose@2268 | 615 | // result is used by all threads, and all future queries. |
jrose@2268 | 616 | // That result may be either a resolved constant or a failure exception. |
jrose@2268 | 617 | if (result_oop == NULL) { |
jrose@2268 | 618 | result_oop = result_handle(); |
jrose@2268 | 619 | cpc_entry->set_f1(result_oop); |
jrose@1957 | 620 | } |
jrose@2268 | 621 | return decode_exception_from_f1(result_oop, THREAD); |
jrose@1957 | 622 | } else { |
jrose@2268 | 623 | if (throw_exception.not_null()) { |
jrose@2268 | 624 | THROW_HANDLE_(throw_exception, NULL); |
jrose@2268 | 625 | } |
jrose@1957 | 626 | return result_oop; |
jrose@1957 | 627 | } |
jrose@1957 | 628 | } |
jrose@1957 | 629 | |
duke@435 | 630 | oop constantPoolOopDesc::string_at_impl(constantPoolHandle this_oop, int which, TRAPS) { |
coleenp@2497 | 631 | oop str = NULL; |
coleenp@2497 | 632 | CPSlot entry = this_oop->slot_at(which); |
coleenp@2497 | 633 | if (entry.is_metadata()) { |
duke@435 | 634 | ObjectLocker ol(this_oop, THREAD); |
duke@435 | 635 | if (this_oop->tag_at(which).is_unresolved_string()) { |
duke@435 | 636 | // Intern string |
coleenp@2497 | 637 | Symbol* sym = this_oop->unresolved_string_at(which); |
coleenp@2497 | 638 | str = StringTable::intern(sym, CHECK_(constantPoolOop(NULL))); |
coleenp@2497 | 639 | this_oop->string_at_put(which, str); |
duke@435 | 640 | } else { |
duke@435 | 641 | // Another thread beat us and interned string, read string from constant pool |
coleenp@2497 | 642 | str = this_oop->resolved_string_at(which); |
duke@435 | 643 | } |
coleenp@2497 | 644 | } else { |
coleenp@2497 | 645 | str = entry.get_oop(); |
duke@435 | 646 | } |
coleenp@2497 | 647 | assert(java_lang_String::is_instance(str), "must be string"); |
coleenp@2497 | 648 | return str; |
duke@435 | 649 | } |
duke@435 | 650 | |
duke@435 | 651 | |
jrose@866 | 652 | bool constantPoolOopDesc::is_pseudo_string_at(int which) { |
coleenp@2497 | 653 | CPSlot entry = slot_at(which); |
coleenp@2497 | 654 | if (entry.is_metadata()) |
jrose@866 | 655 | // Not yet resolved, but it will resolve to a string. |
jrose@866 | 656 | return false; |
coleenp@2497 | 657 | else if (java_lang_String::is_instance(entry.get_oop())) |
jrose@866 | 658 | return false; // actually, it might be a non-interned or non-perm string |
jrose@866 | 659 | else |
jrose@866 | 660 | // truly pseudo |
jrose@866 | 661 | return true; |
jrose@866 | 662 | } |
jrose@866 | 663 | |
jrose@866 | 664 | |
duke@435 | 665 | bool constantPoolOopDesc::klass_name_at_matches(instanceKlassHandle k, |
duke@435 | 666 | int which) { |
coleenp@2497 | 667 | // Names are interned, so we can compare Symbol*s directly |
coleenp@2497 | 668 | Symbol* cp_name = klass_name_at(which); |
duke@435 | 669 | return (cp_name == k->name()); |
duke@435 | 670 | } |
duke@435 | 671 | |
duke@435 | 672 | |
duke@435 | 673 | int constantPoolOopDesc::pre_resolve_shared_klasses(TRAPS) { |
duke@435 | 674 | ResourceMark rm; |
duke@435 | 675 | int count = 0; |
duke@435 | 676 | for (int index = 1; index < tags()->length(); index++) { // Index 0 is unused |
duke@435 | 677 | if (tag_at(index).is_unresolved_string()) { |
duke@435 | 678 | // Intern string |
coleenp@2497 | 679 | Symbol* sym = unresolved_string_at(index); |
duke@435 | 680 | oop entry = StringTable::intern(sym, CHECK_(-1)); |
duke@435 | 681 | string_at_put(index, entry); |
duke@435 | 682 | } |
duke@435 | 683 | } |
duke@435 | 684 | return count; |
duke@435 | 685 | } |
duke@435 | 686 | |
coleenp@2497 | 687 | // Iterate over symbols and decrement ones which are Symbol*s. |
coleenp@2497 | 688 | // This is done during GC so do not need to lock constantPool unless we |
coleenp@2497 | 689 | // have per-thread safepoints. |
coleenp@2497 | 690 | // Only decrement the UTF8 symbols. Unresolved classes and strings point to |
coleenp@2497 | 691 | // these symbols but didn't increment the reference count. |
coleenp@2497 | 692 | void constantPoolOopDesc::unreference_symbols() { |
coleenp@2497 | 693 | for (int index = 1; index < length(); index++) { // Index 0 is unused |
coleenp@2497 | 694 | constantTag tag = tag_at(index); |
coleenp@2497 | 695 | if (tag.is_symbol()) { |
coleenp@2497 | 696 | symbol_at(index)->decrement_refcount(); |
coleenp@2497 | 697 | } |
coleenp@2497 | 698 | } |
coleenp@2497 | 699 | } |
duke@435 | 700 | |
duke@435 | 701 | // Iterate over symbols which are used as class, field, method names and |
duke@435 | 702 | // signatures (in preparation for writing to the shared archive). |
duke@435 | 703 | |
coleenp@2497 | 704 | void constantPoolOopDesc::shared_symbols_iterate(SymbolClosure* closure) { |
duke@435 | 705 | for (int index = 1; index < length(); index++) { // Index 0 is unused |
duke@435 | 706 | switch (tag_at(index).value()) { |
duke@435 | 707 | |
duke@435 | 708 | case JVM_CONSTANT_UnresolvedClass: |
coleenp@2497 | 709 | case JVM_CONSTANT_UnresolvedString: |
coleenp@2497 | 710 | case JVM_CONSTANT_Utf8: |
coleenp@2497 | 711 | assert(slot_at(index).is_metadata(), "must be symbol"); |
coleenp@2497 | 712 | closure->do_symbol(symbol_at_addr(index)); |
duke@435 | 713 | break; |
duke@435 | 714 | |
duke@435 | 715 | case JVM_CONSTANT_NameAndType: |
duke@435 | 716 | { |
duke@435 | 717 | int i = *int_at_addr(index); |
coleenp@2497 | 718 | closure->do_symbol(symbol_at_addr((unsigned)i >> 16)); |
coleenp@2497 | 719 | closure->do_symbol(symbol_at_addr((unsigned)i & 0xffff)); |
duke@435 | 720 | } |
duke@435 | 721 | break; |
duke@435 | 722 | |
duke@435 | 723 | case JVM_CONSTANT_Class: |
duke@435 | 724 | case JVM_CONSTANT_InterfaceMethodref: |
duke@435 | 725 | case JVM_CONSTANT_Fieldref: |
duke@435 | 726 | case JVM_CONSTANT_Methodref: |
duke@435 | 727 | case JVM_CONSTANT_Integer: |
duke@435 | 728 | case JVM_CONSTANT_Float: |
duke@435 | 729 | // Do nothing! Not an oop. |
duke@435 | 730 | // These constant types do not reference symbols at this point. |
duke@435 | 731 | break; |
duke@435 | 732 | |
duke@435 | 733 | case JVM_CONSTANT_String: |
duke@435 | 734 | // Do nothing! Not a symbol. |
duke@435 | 735 | break; |
duke@435 | 736 | |
duke@435 | 737 | case JVM_CONSTANT_Long: |
duke@435 | 738 | case JVM_CONSTANT_Double: |
duke@435 | 739 | // Do nothing! Not an oop. (But takes two pool entries.) |
duke@435 | 740 | ++index; |
duke@435 | 741 | break; |
duke@435 | 742 | |
duke@435 | 743 | default: |
duke@435 | 744 | ShouldNotReachHere(); |
duke@435 | 745 | break; |
duke@435 | 746 | } |
duke@435 | 747 | } |
duke@435 | 748 | } |
duke@435 | 749 | |
duke@435 | 750 | |
duke@435 | 751 | // Iterate over the [one] tags array (in preparation for writing to the |
duke@435 | 752 | // shared archive). |
duke@435 | 753 | |
duke@435 | 754 | void constantPoolOopDesc::shared_tags_iterate(OopClosure* closure) { |
duke@435 | 755 | closure->do_oop(tags_addr()); |
jrose@2268 | 756 | closure->do_oop(operands_addr()); |
duke@435 | 757 | } |
duke@435 | 758 | |
duke@435 | 759 | |
duke@435 | 760 | // Iterate over String objects (in preparation for writing to the shared |
duke@435 | 761 | // archive). |
duke@435 | 762 | |
duke@435 | 763 | void constantPoolOopDesc::shared_strings_iterate(OopClosure* closure) { |
duke@435 | 764 | for (int index = 1; index < length(); index++) { // Index 0 is unused |
duke@435 | 765 | switch (tag_at(index).value()) { |
duke@435 | 766 | |
duke@435 | 767 | case JVM_CONSTANT_UnresolvedClass: |
duke@435 | 768 | case JVM_CONSTANT_NameAndType: |
duke@435 | 769 | // Do nothing! Not a String. |
duke@435 | 770 | break; |
duke@435 | 771 | |
duke@435 | 772 | case JVM_CONSTANT_Class: |
duke@435 | 773 | case JVM_CONSTANT_InterfaceMethodref: |
duke@435 | 774 | case JVM_CONSTANT_Fieldref: |
duke@435 | 775 | case JVM_CONSTANT_Methodref: |
duke@435 | 776 | case JVM_CONSTANT_Integer: |
duke@435 | 777 | case JVM_CONSTANT_Float: |
duke@435 | 778 | // Do nothing! Not an oop. |
duke@435 | 779 | // These constant types do not reference symbols at this point. |
duke@435 | 780 | break; |
duke@435 | 781 | |
duke@435 | 782 | case JVM_CONSTANT_String: |
coleenp@2497 | 783 | closure->do_oop(obj_at_addr_raw(index)); |
duke@435 | 784 | break; |
duke@435 | 785 | |
duke@435 | 786 | case JVM_CONSTANT_UnresolvedString: |
duke@435 | 787 | case JVM_CONSTANT_Utf8: |
duke@435 | 788 | // These constants are symbols, but unless these symbols are |
duke@435 | 789 | // actually to be used for something, we don't want to mark them. |
duke@435 | 790 | break; |
duke@435 | 791 | |
duke@435 | 792 | case JVM_CONSTANT_Long: |
duke@435 | 793 | case JVM_CONSTANT_Double: |
duke@435 | 794 | // Do nothing! Not an oop. (But takes two pool entries.) |
duke@435 | 795 | ++index; |
duke@435 | 796 | break; |
duke@435 | 797 | |
duke@435 | 798 | default: |
duke@435 | 799 | ShouldNotReachHere(); |
duke@435 | 800 | break; |
duke@435 | 801 | } |
duke@435 | 802 | } |
duke@435 | 803 | } |
duke@435 | 804 | |
duke@435 | 805 | |
duke@435 | 806 | // Compare this constant pool's entry at index1 to the constant pool |
duke@435 | 807 | // cp2's entry at index2. |
duke@435 | 808 | bool constantPoolOopDesc::compare_entry_to(int index1, constantPoolHandle cp2, |
duke@435 | 809 | int index2, TRAPS) { |
duke@435 | 810 | |
duke@435 | 811 | jbyte t1 = tag_at(index1).value(); |
duke@435 | 812 | jbyte t2 = cp2->tag_at(index2).value(); |
duke@435 | 813 | |
duke@435 | 814 | |
duke@435 | 815 | // JVM_CONSTANT_UnresolvedClassInError is equal to JVM_CONSTANT_UnresolvedClass |
duke@435 | 816 | // when comparing |
duke@435 | 817 | if (t1 == JVM_CONSTANT_UnresolvedClassInError) { |
duke@435 | 818 | t1 = JVM_CONSTANT_UnresolvedClass; |
duke@435 | 819 | } |
duke@435 | 820 | if (t2 == JVM_CONSTANT_UnresolvedClassInError) { |
duke@435 | 821 | t2 = JVM_CONSTANT_UnresolvedClass; |
duke@435 | 822 | } |
duke@435 | 823 | |
duke@435 | 824 | if (t1 != t2) { |
duke@435 | 825 | // Not the same entry type so there is nothing else to check. Note |
duke@435 | 826 | // that this style of checking will consider resolved/unresolved |
duke@435 | 827 | // class pairs and resolved/unresolved string pairs as different. |
duke@435 | 828 | // From the constantPoolOop API point of view, this is correct |
duke@435 | 829 | // behavior. See constantPoolKlass::merge() to see how this plays |
duke@435 | 830 | // out in the context of constantPoolOop merging. |
duke@435 | 831 | return false; |
duke@435 | 832 | } |
duke@435 | 833 | |
duke@435 | 834 | switch (t1) { |
duke@435 | 835 | case JVM_CONSTANT_Class: |
duke@435 | 836 | { |
duke@435 | 837 | klassOop k1 = klass_at(index1, CHECK_false); |
duke@435 | 838 | klassOop k2 = cp2->klass_at(index2, CHECK_false); |
duke@435 | 839 | if (k1 == k2) { |
duke@435 | 840 | return true; |
duke@435 | 841 | } |
duke@435 | 842 | } break; |
duke@435 | 843 | |
duke@435 | 844 | case JVM_CONSTANT_ClassIndex: |
duke@435 | 845 | { |
duke@435 | 846 | int recur1 = klass_index_at(index1); |
duke@435 | 847 | int recur2 = cp2->klass_index_at(index2); |
duke@435 | 848 | bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false); |
duke@435 | 849 | if (match) { |
duke@435 | 850 | return true; |
duke@435 | 851 | } |
duke@435 | 852 | } break; |
duke@435 | 853 | |
duke@435 | 854 | case JVM_CONSTANT_Double: |
duke@435 | 855 | { |
duke@435 | 856 | jdouble d1 = double_at(index1); |
duke@435 | 857 | jdouble d2 = cp2->double_at(index2); |
duke@435 | 858 | if (d1 == d2) { |
duke@435 | 859 | return true; |
duke@435 | 860 | } |
duke@435 | 861 | } break; |
duke@435 | 862 | |
duke@435 | 863 | case JVM_CONSTANT_Fieldref: |
duke@435 | 864 | case JVM_CONSTANT_InterfaceMethodref: |
duke@435 | 865 | case JVM_CONSTANT_Methodref: |
duke@435 | 866 | { |
duke@435 | 867 | int recur1 = uncached_klass_ref_index_at(index1); |
duke@435 | 868 | int recur2 = cp2->uncached_klass_ref_index_at(index2); |
duke@435 | 869 | bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false); |
duke@435 | 870 | if (match) { |
duke@435 | 871 | recur1 = uncached_name_and_type_ref_index_at(index1); |
duke@435 | 872 | recur2 = cp2->uncached_name_and_type_ref_index_at(index2); |
duke@435 | 873 | match = compare_entry_to(recur1, cp2, recur2, CHECK_false); |
duke@435 | 874 | if (match) { |
duke@435 | 875 | return true; |
duke@435 | 876 | } |
duke@435 | 877 | } |
duke@435 | 878 | } break; |
duke@435 | 879 | |
duke@435 | 880 | case JVM_CONSTANT_Float: |
duke@435 | 881 | { |
duke@435 | 882 | jfloat f1 = float_at(index1); |
duke@435 | 883 | jfloat f2 = cp2->float_at(index2); |
duke@435 | 884 | if (f1 == f2) { |
duke@435 | 885 | return true; |
duke@435 | 886 | } |
duke@435 | 887 | } break; |
duke@435 | 888 | |
duke@435 | 889 | case JVM_CONSTANT_Integer: |
duke@435 | 890 | { |
duke@435 | 891 | jint i1 = int_at(index1); |
duke@435 | 892 | jint i2 = cp2->int_at(index2); |
duke@435 | 893 | if (i1 == i2) { |
duke@435 | 894 | return true; |
duke@435 | 895 | } |
duke@435 | 896 | } break; |
duke@435 | 897 | |
duke@435 | 898 | case JVM_CONSTANT_Long: |
duke@435 | 899 | { |
duke@435 | 900 | jlong l1 = long_at(index1); |
duke@435 | 901 | jlong l2 = cp2->long_at(index2); |
duke@435 | 902 | if (l1 == l2) { |
duke@435 | 903 | return true; |
duke@435 | 904 | } |
duke@435 | 905 | } break; |
duke@435 | 906 | |
duke@435 | 907 | case JVM_CONSTANT_NameAndType: |
duke@435 | 908 | { |
duke@435 | 909 | int recur1 = name_ref_index_at(index1); |
duke@435 | 910 | int recur2 = cp2->name_ref_index_at(index2); |
duke@435 | 911 | bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false); |
duke@435 | 912 | if (match) { |
duke@435 | 913 | recur1 = signature_ref_index_at(index1); |
duke@435 | 914 | recur2 = cp2->signature_ref_index_at(index2); |
duke@435 | 915 | match = compare_entry_to(recur1, cp2, recur2, CHECK_false); |
duke@435 | 916 | if (match) { |
duke@435 | 917 | return true; |
duke@435 | 918 | } |
duke@435 | 919 | } |
duke@435 | 920 | } break; |
duke@435 | 921 | |
duke@435 | 922 | case JVM_CONSTANT_String: |
duke@435 | 923 | { |
duke@435 | 924 | oop s1 = string_at(index1, CHECK_false); |
duke@435 | 925 | oop s2 = cp2->string_at(index2, CHECK_false); |
duke@435 | 926 | if (s1 == s2) { |
duke@435 | 927 | return true; |
duke@435 | 928 | } |
duke@435 | 929 | } break; |
duke@435 | 930 | |
duke@435 | 931 | case JVM_CONSTANT_StringIndex: |
duke@435 | 932 | { |
duke@435 | 933 | int recur1 = string_index_at(index1); |
duke@435 | 934 | int recur2 = cp2->string_index_at(index2); |
duke@435 | 935 | bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false); |
duke@435 | 936 | if (match) { |
duke@435 | 937 | return true; |
duke@435 | 938 | } |
duke@435 | 939 | } break; |
duke@435 | 940 | |
duke@435 | 941 | case JVM_CONSTANT_UnresolvedClass: |
duke@435 | 942 | { |
coleenp@2497 | 943 | Symbol* k1 = unresolved_klass_at(index1); |
coleenp@2497 | 944 | Symbol* k2 = cp2->unresolved_klass_at(index2); |
duke@435 | 945 | if (k1 == k2) { |
duke@435 | 946 | return true; |
duke@435 | 947 | } |
duke@435 | 948 | } break; |
duke@435 | 949 | |
jrose@1957 | 950 | case JVM_CONSTANT_MethodType: |
jrose@1957 | 951 | { |
jrose@1957 | 952 | int k1 = method_type_index_at(index1); |
jrose@1957 | 953 | int k2 = cp2->method_type_index_at(index2); |
jrose@2353 | 954 | bool match = compare_entry_to(k1, cp2, k2, CHECK_false); |
jrose@2353 | 955 | if (match) { |
jrose@1957 | 956 | return true; |
jrose@1957 | 957 | } |
jrose@1957 | 958 | } break; |
jrose@1957 | 959 | |
jrose@1957 | 960 | case JVM_CONSTANT_MethodHandle: |
jrose@1957 | 961 | { |
jrose@1957 | 962 | int k1 = method_handle_ref_kind_at(index1); |
jrose@1957 | 963 | int k2 = cp2->method_handle_ref_kind_at(index2); |
jrose@1957 | 964 | if (k1 == k2) { |
jrose@1957 | 965 | int i1 = method_handle_index_at(index1); |
jrose@1957 | 966 | int i2 = cp2->method_handle_index_at(index2); |
jrose@2353 | 967 | bool match = compare_entry_to(i1, cp2, i2, CHECK_false); |
jrose@2353 | 968 | if (match) { |
jrose@1957 | 969 | return true; |
jrose@1957 | 970 | } |
jrose@1957 | 971 | } |
jrose@1957 | 972 | } break; |
jrose@1957 | 973 | |
jrose@2015 | 974 | case JVM_CONSTANT_InvokeDynamic: |
jrose@2015 | 975 | { |
jrose@2353 | 976 | int k1 = invoke_dynamic_bootstrap_method_ref_index_at(index1); |
jrose@2353 | 977 | int k2 = cp2->invoke_dynamic_bootstrap_method_ref_index_at(index2); |
jrose@2353 | 978 | bool match = compare_entry_to(k1, cp2, k2, CHECK_false); |
jrose@2353 | 979 | if (!match) return false; |
jrose@2353 | 980 | k1 = invoke_dynamic_name_and_type_ref_index_at(index1); |
jrose@2353 | 981 | k2 = cp2->invoke_dynamic_name_and_type_ref_index_at(index2); |
jrose@2353 | 982 | match = compare_entry_to(k1, cp2, k2, CHECK_false); |
jrose@2353 | 983 | if (!match) return false; |
jrose@2353 | 984 | int argc = invoke_dynamic_argument_count_at(index1); |
jrose@2353 | 985 | if (argc == cp2->invoke_dynamic_argument_count_at(index2)) { |
jrose@2353 | 986 | for (int j = 0; j < argc; j++) { |
jrose@2353 | 987 | k1 = invoke_dynamic_argument_index_at(index1, j); |
jrose@2353 | 988 | k2 = cp2->invoke_dynamic_argument_index_at(index2, j); |
jrose@2353 | 989 | match = compare_entry_to(k1, cp2, k2, CHECK_false); |
jrose@2353 | 990 | if (!match) return false; |
jrose@2268 | 991 | } |
jrose@2353 | 992 | return true; // got through loop; all elements equal |
jrose@2015 | 993 | } |
jrose@2015 | 994 | } break; |
jrose@2015 | 995 | |
duke@435 | 996 | case JVM_CONSTANT_UnresolvedString: |
duke@435 | 997 | { |
coleenp@2497 | 998 | Symbol* s1 = unresolved_string_at(index1); |
coleenp@2497 | 999 | Symbol* s2 = cp2->unresolved_string_at(index2); |
duke@435 | 1000 | if (s1 == s2) { |
duke@435 | 1001 | return true; |
duke@435 | 1002 | } |
duke@435 | 1003 | } break; |
duke@435 | 1004 | |
duke@435 | 1005 | case JVM_CONSTANT_Utf8: |
duke@435 | 1006 | { |
coleenp@2497 | 1007 | Symbol* s1 = symbol_at(index1); |
coleenp@2497 | 1008 | Symbol* s2 = cp2->symbol_at(index2); |
duke@435 | 1009 | if (s1 == s2) { |
duke@435 | 1010 | return true; |
duke@435 | 1011 | } |
duke@435 | 1012 | } break; |
duke@435 | 1013 | |
duke@435 | 1014 | // Invalid is used as the tag for the second constant pool entry |
duke@435 | 1015 | // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should |
duke@435 | 1016 | // not be seen by itself. |
duke@435 | 1017 | case JVM_CONSTANT_Invalid: // fall through |
duke@435 | 1018 | |
duke@435 | 1019 | default: |
duke@435 | 1020 | ShouldNotReachHere(); |
duke@435 | 1021 | break; |
duke@435 | 1022 | } |
duke@435 | 1023 | |
duke@435 | 1024 | return false; |
duke@435 | 1025 | } // end compare_entry_to() |
duke@435 | 1026 | |
duke@435 | 1027 | |
duke@435 | 1028 | // Copy this constant pool's entries at start_i to end_i (inclusive) |
duke@435 | 1029 | // to the constant pool to_cp's entries starting at to_i. A total of |
duke@435 | 1030 | // (end_i - start_i) + 1 entries are copied. |
jrose@2353 | 1031 | void constantPoolOopDesc::copy_cp_to_impl(constantPoolHandle from_cp, int start_i, int end_i, |
duke@435 | 1032 | constantPoolHandle to_cp, int to_i, TRAPS) { |
duke@435 | 1033 | |
duke@435 | 1034 | int dest_i = to_i; // leave original alone for debug purposes |
duke@435 | 1035 | |
jrose@2353 | 1036 | for (int src_i = start_i; src_i <= end_i; /* see loop bottom */ ) { |
jrose@2353 | 1037 | copy_entry_to(from_cp, src_i, to_cp, dest_i, CHECK); |
jrose@2268 | 1038 | |
jrose@2353 | 1039 | switch (from_cp->tag_at(src_i).value()) { |
duke@435 | 1040 | case JVM_CONSTANT_Double: |
duke@435 | 1041 | case JVM_CONSTANT_Long: |
duke@435 | 1042 | // double and long take two constant pool entries |
duke@435 | 1043 | src_i += 2; |
duke@435 | 1044 | dest_i += 2; |
duke@435 | 1045 | break; |
duke@435 | 1046 | |
duke@435 | 1047 | default: |
duke@435 | 1048 | // all others take one constant pool entry |
duke@435 | 1049 | src_i++; |
duke@435 | 1050 | dest_i++; |
duke@435 | 1051 | break; |
duke@435 | 1052 | } |
duke@435 | 1053 | } |
jrose@2353 | 1054 | |
jrose@2353 | 1055 | int from_oplen = operand_array_length(from_cp->operands()); |
jrose@2353 | 1056 | int old_oplen = operand_array_length(to_cp->operands()); |
jrose@2353 | 1057 | if (from_oplen != 0) { |
jrose@2353 | 1058 | // append my operands to the target's operands array |
jrose@2353 | 1059 | if (old_oplen == 0) { |
jrose@2353 | 1060 | to_cp->set_operands(from_cp->operands()); // reuse; do not merge |
jrose@2353 | 1061 | } else { |
jrose@2353 | 1062 | int old_len = to_cp->operands()->length(); |
jrose@2353 | 1063 | int from_len = from_cp->operands()->length(); |
jrose@2353 | 1064 | int old_off = old_oplen * sizeof(u2); |
jrose@2353 | 1065 | int from_off = from_oplen * sizeof(u2); |
jrose@2353 | 1066 | typeArrayHandle new_operands = oopFactory::new_permanent_shortArray(old_len + from_len, CHECK); |
jrose@2353 | 1067 | int fillp = 0, len = 0; |
jrose@2353 | 1068 | // first part of dest |
jrose@2353 | 1069 | Copy::conjoint_memory_atomic(to_cp->operands()->short_at_addr(0), |
jrose@2353 | 1070 | new_operands->short_at_addr(fillp), |
jrose@2353 | 1071 | (len = old_off) * sizeof(u2)); |
jrose@2353 | 1072 | fillp += len; |
jrose@2353 | 1073 | // first part of src |
jrose@2353 | 1074 | Copy::conjoint_memory_atomic(to_cp->operands()->short_at_addr(0), |
jrose@2353 | 1075 | new_operands->short_at_addr(fillp), |
jrose@2353 | 1076 | (len = from_off) * sizeof(u2)); |
jrose@2353 | 1077 | fillp += len; |
jrose@2353 | 1078 | // second part of dest |
jrose@2353 | 1079 | Copy::conjoint_memory_atomic(to_cp->operands()->short_at_addr(old_off), |
jrose@2353 | 1080 | new_operands->short_at_addr(fillp), |
jrose@2353 | 1081 | (len = old_len - old_off) * sizeof(u2)); |
jrose@2353 | 1082 | fillp += len; |
jrose@2353 | 1083 | // second part of src |
jrose@2353 | 1084 | Copy::conjoint_memory_atomic(to_cp->operands()->short_at_addr(from_off), |
jrose@2353 | 1085 | new_operands->short_at_addr(fillp), |
jrose@2353 | 1086 | (len = from_len - from_off) * sizeof(u2)); |
jrose@2353 | 1087 | fillp += len; |
jrose@2353 | 1088 | assert(fillp == new_operands->length(), ""); |
jrose@2353 | 1089 | |
jrose@2353 | 1090 | // Adjust indexes in the first part of the copied operands array. |
jrose@2353 | 1091 | for (int j = 0; j < from_oplen; j++) { |
jrose@2353 | 1092 | int offset = operand_offset_at(new_operands(), old_oplen + j); |
jrose@2353 | 1093 | assert(offset == operand_offset_at(from_cp->operands(), j), "correct copy"); |
jrose@2353 | 1094 | offset += old_len; // every new tuple is preceded by old_len extra u2's |
jrose@2353 | 1095 | operand_offset_at_put(new_operands(), old_oplen + j, offset); |
jrose@2353 | 1096 | } |
jrose@2353 | 1097 | |
jrose@2353 | 1098 | // replace target operands array with combined array |
jrose@2353 | 1099 | to_cp->set_operands(new_operands()); |
jrose@2353 | 1100 | } |
jrose@2353 | 1101 | } |
jrose@2353 | 1102 | |
duke@435 | 1103 | } // end copy_cp_to() |
duke@435 | 1104 | |
duke@435 | 1105 | |
duke@435 | 1106 | // Copy this constant pool's entry at from_i to the constant pool |
duke@435 | 1107 | // to_cp's entry at to_i. |
jrose@2353 | 1108 | void constantPoolOopDesc::copy_entry_to(constantPoolHandle from_cp, int from_i, |
jrose@2353 | 1109 | constantPoolHandle to_cp, int to_i, |
jrose@2353 | 1110 | TRAPS) { |
duke@435 | 1111 | |
jrose@2353 | 1112 | int tag = from_cp->tag_at(from_i).value(); |
jrose@2353 | 1113 | switch (tag) { |
duke@435 | 1114 | case JVM_CONSTANT_Class: |
duke@435 | 1115 | { |
jrose@2353 | 1116 | klassOop k = from_cp->klass_at(from_i, CHECK); |
duke@435 | 1117 | to_cp->klass_at_put(to_i, k); |
duke@435 | 1118 | } break; |
duke@435 | 1119 | |
duke@435 | 1120 | case JVM_CONSTANT_ClassIndex: |
duke@435 | 1121 | { |
jrose@2353 | 1122 | jint ki = from_cp->klass_index_at(from_i); |
duke@435 | 1123 | to_cp->klass_index_at_put(to_i, ki); |
duke@435 | 1124 | } break; |
duke@435 | 1125 | |
duke@435 | 1126 | case JVM_CONSTANT_Double: |
duke@435 | 1127 | { |
jrose@2353 | 1128 | jdouble d = from_cp->double_at(from_i); |
duke@435 | 1129 | to_cp->double_at_put(to_i, d); |
duke@435 | 1130 | // double takes two constant pool entries so init second entry's tag |
duke@435 | 1131 | to_cp->tag_at_put(to_i + 1, JVM_CONSTANT_Invalid); |
duke@435 | 1132 | } break; |
duke@435 | 1133 | |
duke@435 | 1134 | case JVM_CONSTANT_Fieldref: |
duke@435 | 1135 | { |
jrose@2353 | 1136 | int class_index = from_cp->uncached_klass_ref_index_at(from_i); |
jrose@2353 | 1137 | int name_and_type_index = from_cp->uncached_name_and_type_ref_index_at(from_i); |
duke@435 | 1138 | to_cp->field_at_put(to_i, class_index, name_and_type_index); |
duke@435 | 1139 | } break; |
duke@435 | 1140 | |
duke@435 | 1141 | case JVM_CONSTANT_Float: |
duke@435 | 1142 | { |
jrose@2353 | 1143 | jfloat f = from_cp->float_at(from_i); |
duke@435 | 1144 | to_cp->float_at_put(to_i, f); |
duke@435 | 1145 | } break; |
duke@435 | 1146 | |
duke@435 | 1147 | case JVM_CONSTANT_Integer: |
duke@435 | 1148 | { |
jrose@2353 | 1149 | jint i = from_cp->int_at(from_i); |
duke@435 | 1150 | to_cp->int_at_put(to_i, i); |
duke@435 | 1151 | } break; |
duke@435 | 1152 | |
duke@435 | 1153 | case JVM_CONSTANT_InterfaceMethodref: |
duke@435 | 1154 | { |
jrose@2353 | 1155 | int class_index = from_cp->uncached_klass_ref_index_at(from_i); |
jrose@2353 | 1156 | int name_and_type_index = from_cp->uncached_name_and_type_ref_index_at(from_i); |
duke@435 | 1157 | to_cp->interface_method_at_put(to_i, class_index, name_and_type_index); |
duke@435 | 1158 | } break; |
duke@435 | 1159 | |
duke@435 | 1160 | case JVM_CONSTANT_Long: |
duke@435 | 1161 | { |
jrose@2353 | 1162 | jlong l = from_cp->long_at(from_i); |
duke@435 | 1163 | to_cp->long_at_put(to_i, l); |
duke@435 | 1164 | // long takes two constant pool entries so init second entry's tag |
duke@435 | 1165 | to_cp->tag_at_put(to_i + 1, JVM_CONSTANT_Invalid); |
duke@435 | 1166 | } break; |
duke@435 | 1167 | |
duke@435 | 1168 | case JVM_CONSTANT_Methodref: |
duke@435 | 1169 | { |
jrose@2353 | 1170 | int class_index = from_cp->uncached_klass_ref_index_at(from_i); |
jrose@2353 | 1171 | int name_and_type_index = from_cp->uncached_name_and_type_ref_index_at(from_i); |
duke@435 | 1172 | to_cp->method_at_put(to_i, class_index, name_and_type_index); |
duke@435 | 1173 | } break; |
duke@435 | 1174 | |
duke@435 | 1175 | case JVM_CONSTANT_NameAndType: |
duke@435 | 1176 | { |
jrose@2353 | 1177 | int name_ref_index = from_cp->name_ref_index_at(from_i); |
jrose@2353 | 1178 | int signature_ref_index = from_cp->signature_ref_index_at(from_i); |
duke@435 | 1179 | to_cp->name_and_type_at_put(to_i, name_ref_index, signature_ref_index); |
duke@435 | 1180 | } break; |
duke@435 | 1181 | |
duke@435 | 1182 | case JVM_CONSTANT_String: |
duke@435 | 1183 | { |
jrose@2353 | 1184 | oop s = from_cp->string_at(from_i, CHECK); |
duke@435 | 1185 | to_cp->string_at_put(to_i, s); |
duke@435 | 1186 | } break; |
duke@435 | 1187 | |
duke@435 | 1188 | case JVM_CONSTANT_StringIndex: |
duke@435 | 1189 | { |
jrose@2353 | 1190 | jint si = from_cp->string_index_at(from_i); |
duke@435 | 1191 | to_cp->string_index_at_put(to_i, si); |
duke@435 | 1192 | } break; |
duke@435 | 1193 | |
duke@435 | 1194 | case JVM_CONSTANT_UnresolvedClass: |
duke@435 | 1195 | { |
coleenp@2614 | 1196 | // Can be resolved after checking tag, so check the slot first. |
coleenp@2614 | 1197 | CPSlot entry = from_cp->slot_at(from_i); |
coleenp@2614 | 1198 | if (entry.is_oop()) { |
coleenp@2614 | 1199 | assert(entry.get_oop()->is_klass(), "must be"); |
coleenp@2614 | 1200 | // Already resolved |
coleenp@2614 | 1201 | to_cp->klass_at_put(to_i, (klassOop)entry.get_oop()); |
coleenp@2614 | 1202 | } else { |
coleenp@2614 | 1203 | to_cp->unresolved_klass_at_put(to_i, entry.get_symbol()); |
coleenp@2614 | 1204 | } |
duke@435 | 1205 | } break; |
duke@435 | 1206 | |
duke@435 | 1207 | case JVM_CONSTANT_UnresolvedClassInError: |
duke@435 | 1208 | { |
coleenp@2497 | 1209 | Symbol* k = from_cp->unresolved_klass_at(from_i); |
duke@435 | 1210 | to_cp->unresolved_klass_at_put(to_i, k); |
duke@435 | 1211 | to_cp->tag_at_put(to_i, JVM_CONSTANT_UnresolvedClassInError); |
duke@435 | 1212 | } break; |
duke@435 | 1213 | |
duke@435 | 1214 | |
duke@435 | 1215 | case JVM_CONSTANT_UnresolvedString: |
duke@435 | 1216 | { |
coleenp@2614 | 1217 | // Can be resolved after checking tag, so check the slot first. |
coleenp@2614 | 1218 | CPSlot entry = from_cp->slot_at(from_i); |
coleenp@2614 | 1219 | if (entry.is_oop()) { |
coleenp@2614 | 1220 | // Already resolved (either string or pseudo-string) |
coleenp@2614 | 1221 | to_cp->string_at_put(to_i, entry.get_oop()); |
coleenp@2614 | 1222 | } else { |
coleenp@2614 | 1223 | to_cp->unresolved_string_at_put(to_i, entry.get_symbol()); |
coleenp@2614 | 1224 | } |
duke@435 | 1225 | } break; |
duke@435 | 1226 | |
duke@435 | 1227 | case JVM_CONSTANT_Utf8: |
duke@435 | 1228 | { |
coleenp@2497 | 1229 | Symbol* s = from_cp->symbol_at(from_i); |
duke@435 | 1230 | to_cp->symbol_at_put(to_i, s); |
coleenp@2497 | 1231 | // This constantPool has the same lifetime as the original, so don't |
coleenp@2497 | 1232 | // increase reference counts for the copy. |
duke@435 | 1233 | } break; |
duke@435 | 1234 | |
jrose@1957 | 1235 | case JVM_CONSTANT_MethodType: |
jrose@1957 | 1236 | { |
jrose@2353 | 1237 | jint k = from_cp->method_type_index_at(from_i); |
jrose@1957 | 1238 | to_cp->method_type_index_at_put(to_i, k); |
jrose@1957 | 1239 | } break; |
jrose@1957 | 1240 | |
jrose@1957 | 1241 | case JVM_CONSTANT_MethodHandle: |
jrose@1957 | 1242 | { |
jrose@2353 | 1243 | int k1 = from_cp->method_handle_ref_kind_at(from_i); |
jrose@2353 | 1244 | int k2 = from_cp->method_handle_index_at(from_i); |
jrose@1957 | 1245 | to_cp->method_handle_index_at_put(to_i, k1, k2); |
jrose@1957 | 1246 | } break; |
jrose@1957 | 1247 | |
jrose@2015 | 1248 | case JVM_CONSTANT_InvokeDynamic: |
jrose@2015 | 1249 | { |
jrose@2353 | 1250 | int k1 = from_cp->invoke_dynamic_bootstrap_specifier_index(from_i); |
jrose@2353 | 1251 | int k2 = from_cp->invoke_dynamic_name_and_type_ref_index_at(from_i); |
jrose@2353 | 1252 | k1 += operand_array_length(to_cp->operands()); // to_cp might already have operands |
jrose@2353 | 1253 | to_cp->invoke_dynamic_at_put(to_i, k1, k2); |
jrose@2015 | 1254 | } break; |
jrose@2015 | 1255 | |
duke@435 | 1256 | // Invalid is used as the tag for the second constant pool entry |
duke@435 | 1257 | // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should |
duke@435 | 1258 | // not be seen by itself. |
duke@435 | 1259 | case JVM_CONSTANT_Invalid: // fall through |
duke@435 | 1260 | |
duke@435 | 1261 | default: |
duke@435 | 1262 | { |
duke@435 | 1263 | ShouldNotReachHere(); |
duke@435 | 1264 | } break; |
duke@435 | 1265 | } |
duke@435 | 1266 | } // end copy_entry_to() |
duke@435 | 1267 | |
duke@435 | 1268 | |
duke@435 | 1269 | // Search constant pool search_cp for an entry that matches this |
duke@435 | 1270 | // constant pool's entry at pattern_i. Returns the index of a |
duke@435 | 1271 | // matching entry or zero (0) if there is no matching entry. |
duke@435 | 1272 | int constantPoolOopDesc::find_matching_entry(int pattern_i, |
duke@435 | 1273 | constantPoolHandle search_cp, TRAPS) { |
duke@435 | 1274 | |
duke@435 | 1275 | // index zero (0) is not used |
duke@435 | 1276 | for (int i = 1; i < search_cp->length(); i++) { |
duke@435 | 1277 | bool found = compare_entry_to(pattern_i, search_cp, i, CHECK_0); |
duke@435 | 1278 | if (found) { |
duke@435 | 1279 | return i; |
duke@435 | 1280 | } |
duke@435 | 1281 | } |
duke@435 | 1282 | |
duke@435 | 1283 | return 0; // entry not found; return unused index zero (0) |
duke@435 | 1284 | } // end find_matching_entry() |
duke@435 | 1285 | |
duke@435 | 1286 | |
duke@435 | 1287 | #ifndef PRODUCT |
duke@435 | 1288 | |
duke@435 | 1289 | const char* constantPoolOopDesc::printable_name_at(int which) { |
duke@435 | 1290 | |
duke@435 | 1291 | constantTag tag = tag_at(which); |
duke@435 | 1292 | |
duke@435 | 1293 | if (tag.is_unresolved_string() || tag.is_string()) { |
duke@435 | 1294 | return string_at_noresolve(which); |
duke@435 | 1295 | } else if (tag.is_klass() || tag.is_unresolved_klass()) { |
duke@435 | 1296 | return klass_name_at(which)->as_C_string(); |
duke@435 | 1297 | } else if (tag.is_symbol()) { |
duke@435 | 1298 | return symbol_at(which)->as_C_string(); |
duke@435 | 1299 | } |
duke@435 | 1300 | return ""; |
duke@435 | 1301 | } |
duke@435 | 1302 | |
duke@435 | 1303 | #endif // PRODUCT |
duke@435 | 1304 | |
duke@435 | 1305 | |
duke@435 | 1306 | // JVMTI GetConstantPool support |
duke@435 | 1307 | |
duke@435 | 1308 | // For temporary use until code is stable. |
duke@435 | 1309 | #define DBG(code) |
duke@435 | 1310 | |
duke@435 | 1311 | static const char* WARN_MSG = "Must not be such entry!"; |
duke@435 | 1312 | |
duke@435 | 1313 | static void print_cpool_bytes(jint cnt, u1 *bytes) { |
duke@435 | 1314 | jint size = 0; |
duke@435 | 1315 | u2 idx1, idx2; |
duke@435 | 1316 | |
duke@435 | 1317 | for (jint idx = 1; idx < cnt; idx++) { |
duke@435 | 1318 | jint ent_size = 0; |
duke@435 | 1319 | u1 tag = *bytes++; |
duke@435 | 1320 | size++; // count tag |
duke@435 | 1321 | |
duke@435 | 1322 | printf("const #%03d, tag: %02d ", idx, tag); |
duke@435 | 1323 | switch(tag) { |
duke@435 | 1324 | case JVM_CONSTANT_Invalid: { |
duke@435 | 1325 | printf("Invalid"); |
duke@435 | 1326 | break; |
duke@435 | 1327 | } |
duke@435 | 1328 | case JVM_CONSTANT_Unicode: { |
duke@435 | 1329 | printf("Unicode %s", WARN_MSG); |
duke@435 | 1330 | break; |
duke@435 | 1331 | } |
duke@435 | 1332 | case JVM_CONSTANT_Utf8: { |
duke@435 | 1333 | u2 len = Bytes::get_Java_u2(bytes); |
duke@435 | 1334 | char str[128]; |
duke@435 | 1335 | if (len > 127) { |
duke@435 | 1336 | len = 127; |
duke@435 | 1337 | } |
duke@435 | 1338 | strncpy(str, (char *) (bytes+2), len); |
duke@435 | 1339 | str[len] = '\0'; |
duke@435 | 1340 | printf("Utf8 \"%s\"", str); |
duke@435 | 1341 | ent_size = 2 + len; |
duke@435 | 1342 | break; |
duke@435 | 1343 | } |
duke@435 | 1344 | case JVM_CONSTANT_Integer: { |
duke@435 | 1345 | u4 val = Bytes::get_Java_u4(bytes); |
duke@435 | 1346 | printf("int %d", *(int *) &val); |
duke@435 | 1347 | ent_size = 4; |
duke@435 | 1348 | break; |
duke@435 | 1349 | } |
duke@435 | 1350 | case JVM_CONSTANT_Float: { |
duke@435 | 1351 | u4 val = Bytes::get_Java_u4(bytes); |
duke@435 | 1352 | printf("float %5.3ff", *(float *) &val); |
duke@435 | 1353 | ent_size = 4; |
duke@435 | 1354 | break; |
duke@435 | 1355 | } |
duke@435 | 1356 | case JVM_CONSTANT_Long: { |
duke@435 | 1357 | u8 val = Bytes::get_Java_u8(bytes); |
never@3156 | 1358 | printf("long "INT64_FORMAT, (int64_t) *(jlong *) &val); |
duke@435 | 1359 | ent_size = 8; |
duke@435 | 1360 | idx++; // Long takes two cpool slots |
duke@435 | 1361 | break; |
duke@435 | 1362 | } |
duke@435 | 1363 | case JVM_CONSTANT_Double: { |
duke@435 | 1364 | u8 val = Bytes::get_Java_u8(bytes); |
duke@435 | 1365 | printf("double %5.3fd", *(jdouble *)&val); |
duke@435 | 1366 | ent_size = 8; |
duke@435 | 1367 | idx++; // Double takes two cpool slots |
duke@435 | 1368 | break; |
duke@435 | 1369 | } |
duke@435 | 1370 | case JVM_CONSTANT_Class: { |
duke@435 | 1371 | idx1 = Bytes::get_Java_u2(bytes); |
duke@435 | 1372 | printf("class #%03d", idx1); |
duke@435 | 1373 | ent_size = 2; |
duke@435 | 1374 | break; |
duke@435 | 1375 | } |
duke@435 | 1376 | case JVM_CONSTANT_String: { |
duke@435 | 1377 | idx1 = Bytes::get_Java_u2(bytes); |
duke@435 | 1378 | printf("String #%03d", idx1); |
duke@435 | 1379 | ent_size = 2; |
duke@435 | 1380 | break; |
duke@435 | 1381 | } |
duke@435 | 1382 | case JVM_CONSTANT_Fieldref: { |
duke@435 | 1383 | idx1 = Bytes::get_Java_u2(bytes); |
duke@435 | 1384 | idx2 = Bytes::get_Java_u2(bytes+2); |
duke@435 | 1385 | printf("Field #%03d, #%03d", (int) idx1, (int) idx2); |
duke@435 | 1386 | ent_size = 4; |
duke@435 | 1387 | break; |
duke@435 | 1388 | } |
duke@435 | 1389 | case JVM_CONSTANT_Methodref: { |
duke@435 | 1390 | idx1 = Bytes::get_Java_u2(bytes); |
duke@435 | 1391 | idx2 = Bytes::get_Java_u2(bytes+2); |
duke@435 | 1392 | printf("Method #%03d, #%03d", idx1, idx2); |
duke@435 | 1393 | ent_size = 4; |
duke@435 | 1394 | break; |
duke@435 | 1395 | } |
duke@435 | 1396 | case JVM_CONSTANT_InterfaceMethodref: { |
duke@435 | 1397 | idx1 = Bytes::get_Java_u2(bytes); |
duke@435 | 1398 | idx2 = Bytes::get_Java_u2(bytes+2); |
duke@435 | 1399 | printf("InterfMethod #%03d, #%03d", idx1, idx2); |
duke@435 | 1400 | ent_size = 4; |
duke@435 | 1401 | break; |
duke@435 | 1402 | } |
duke@435 | 1403 | case JVM_CONSTANT_NameAndType: { |
duke@435 | 1404 | idx1 = Bytes::get_Java_u2(bytes); |
duke@435 | 1405 | idx2 = Bytes::get_Java_u2(bytes+2); |
duke@435 | 1406 | printf("NameAndType #%03d, #%03d", idx1, idx2); |
duke@435 | 1407 | ent_size = 4; |
duke@435 | 1408 | break; |
duke@435 | 1409 | } |
duke@435 | 1410 | case JVM_CONSTANT_ClassIndex: { |
duke@435 | 1411 | printf("ClassIndex %s", WARN_MSG); |
duke@435 | 1412 | break; |
duke@435 | 1413 | } |
duke@435 | 1414 | case JVM_CONSTANT_UnresolvedClass: { |
duke@435 | 1415 | printf("UnresolvedClass: %s", WARN_MSG); |
duke@435 | 1416 | break; |
duke@435 | 1417 | } |
duke@435 | 1418 | case JVM_CONSTANT_UnresolvedClassInError: { |
duke@435 | 1419 | printf("UnresolvedClassInErr: %s", WARN_MSG); |
duke@435 | 1420 | break; |
duke@435 | 1421 | } |
duke@435 | 1422 | case JVM_CONSTANT_StringIndex: { |
duke@435 | 1423 | printf("StringIndex: %s", WARN_MSG); |
duke@435 | 1424 | break; |
duke@435 | 1425 | } |
duke@435 | 1426 | case JVM_CONSTANT_UnresolvedString: { |
duke@435 | 1427 | printf("UnresolvedString: %s", WARN_MSG); |
duke@435 | 1428 | break; |
duke@435 | 1429 | } |
duke@435 | 1430 | } |
duke@435 | 1431 | printf(";\n"); |
duke@435 | 1432 | bytes += ent_size; |
duke@435 | 1433 | size += ent_size; |
duke@435 | 1434 | } |
duke@435 | 1435 | printf("Cpool size: %d\n", size); |
duke@435 | 1436 | fflush(0); |
duke@435 | 1437 | return; |
duke@435 | 1438 | } /* end print_cpool_bytes */ |
duke@435 | 1439 | |
duke@435 | 1440 | |
duke@435 | 1441 | // Returns size of constant pool entry. |
duke@435 | 1442 | jint constantPoolOopDesc::cpool_entry_size(jint idx) { |
duke@435 | 1443 | switch(tag_at(idx).value()) { |
duke@435 | 1444 | case JVM_CONSTANT_Invalid: |
duke@435 | 1445 | case JVM_CONSTANT_Unicode: |
duke@435 | 1446 | return 1; |
duke@435 | 1447 | |
duke@435 | 1448 | case JVM_CONSTANT_Utf8: |
duke@435 | 1449 | return 3 + symbol_at(idx)->utf8_length(); |
duke@435 | 1450 | |
duke@435 | 1451 | case JVM_CONSTANT_Class: |
duke@435 | 1452 | case JVM_CONSTANT_String: |
duke@435 | 1453 | case JVM_CONSTANT_ClassIndex: |
duke@435 | 1454 | case JVM_CONSTANT_UnresolvedClass: |
duke@435 | 1455 | case JVM_CONSTANT_UnresolvedClassInError: |
duke@435 | 1456 | case JVM_CONSTANT_StringIndex: |
duke@435 | 1457 | case JVM_CONSTANT_UnresolvedString: |
jrose@1957 | 1458 | case JVM_CONSTANT_MethodType: |
duke@435 | 1459 | return 3; |
duke@435 | 1460 | |
jrose@1957 | 1461 | case JVM_CONSTANT_MethodHandle: |
jrose@1957 | 1462 | return 4; //tag, ref_kind, ref_index |
jrose@1957 | 1463 | |
duke@435 | 1464 | case JVM_CONSTANT_Integer: |
duke@435 | 1465 | case JVM_CONSTANT_Float: |
duke@435 | 1466 | case JVM_CONSTANT_Fieldref: |
duke@435 | 1467 | case JVM_CONSTANT_Methodref: |
duke@435 | 1468 | case JVM_CONSTANT_InterfaceMethodref: |
duke@435 | 1469 | case JVM_CONSTANT_NameAndType: |
jrose@2268 | 1470 | return 5; |
jrose@2268 | 1471 | |
jrose@2015 | 1472 | case JVM_CONSTANT_InvokeDynamic: |
jrose@2353 | 1473 | // u1 tag, u2 bsm, u2 nt |
jrose@2353 | 1474 | return 5; |
duke@435 | 1475 | |
duke@435 | 1476 | case JVM_CONSTANT_Long: |
duke@435 | 1477 | case JVM_CONSTANT_Double: |
duke@435 | 1478 | return 9; |
duke@435 | 1479 | } |
duke@435 | 1480 | assert(false, "cpool_entry_size: Invalid constant pool entry tag"); |
duke@435 | 1481 | return 1; |
duke@435 | 1482 | } /* end cpool_entry_size */ |
duke@435 | 1483 | |
duke@435 | 1484 | |
duke@435 | 1485 | // SymbolHashMap is used to find a constant pool index from a string. |
duke@435 | 1486 | // This function fills in SymbolHashMaps, one for utf8s and one for |
duke@435 | 1487 | // class names, returns size of the cpool raw bytes. |
duke@435 | 1488 | jint constantPoolOopDesc::hash_entries_to(SymbolHashMap *symmap, |
duke@435 | 1489 | SymbolHashMap *classmap) { |
duke@435 | 1490 | jint size = 0; |
duke@435 | 1491 | |
duke@435 | 1492 | for (u2 idx = 1; idx < length(); idx++) { |
duke@435 | 1493 | u2 tag = tag_at(idx).value(); |
duke@435 | 1494 | size += cpool_entry_size(idx); |
duke@435 | 1495 | |
duke@435 | 1496 | switch(tag) { |
duke@435 | 1497 | case JVM_CONSTANT_Utf8: { |
coleenp@2497 | 1498 | Symbol* sym = symbol_at(idx); |
duke@435 | 1499 | symmap->add_entry(sym, idx); |
duke@435 | 1500 | DBG(printf("adding symbol entry %s = %d\n", sym->as_utf8(), idx)); |
duke@435 | 1501 | break; |
duke@435 | 1502 | } |
duke@435 | 1503 | case JVM_CONSTANT_Class: |
duke@435 | 1504 | case JVM_CONSTANT_UnresolvedClass: |
duke@435 | 1505 | case JVM_CONSTANT_UnresolvedClassInError: { |
coleenp@2497 | 1506 | Symbol* sym = klass_name_at(idx); |
duke@435 | 1507 | classmap->add_entry(sym, idx); |
duke@435 | 1508 | DBG(printf("adding class entry %s = %d\n", sym->as_utf8(), idx)); |
duke@435 | 1509 | break; |
duke@435 | 1510 | } |
duke@435 | 1511 | case JVM_CONSTANT_Long: |
duke@435 | 1512 | case JVM_CONSTANT_Double: { |
duke@435 | 1513 | idx++; // Both Long and Double take two cpool slots |
duke@435 | 1514 | break; |
duke@435 | 1515 | } |
duke@435 | 1516 | } |
duke@435 | 1517 | } |
duke@435 | 1518 | return size; |
duke@435 | 1519 | } /* end hash_utf8_entries_to */ |
duke@435 | 1520 | |
duke@435 | 1521 | |
duke@435 | 1522 | // Copy cpool bytes. |
duke@435 | 1523 | // Returns: |
duke@435 | 1524 | // 0, in case of OutOfMemoryError |
duke@435 | 1525 | // -1, in case of internal error |
duke@435 | 1526 | // > 0, count of the raw cpool bytes that have been copied |
duke@435 | 1527 | int constantPoolOopDesc::copy_cpool_bytes(int cpool_size, |
duke@435 | 1528 | SymbolHashMap* tbl, |
duke@435 | 1529 | unsigned char *bytes) { |
duke@435 | 1530 | u2 idx1, idx2; |
duke@435 | 1531 | jint size = 0; |
duke@435 | 1532 | jint cnt = length(); |
duke@435 | 1533 | unsigned char *start_bytes = bytes; |
duke@435 | 1534 | |
duke@435 | 1535 | for (jint idx = 1; idx < cnt; idx++) { |
duke@435 | 1536 | u1 tag = tag_at(idx).value(); |
duke@435 | 1537 | jint ent_size = cpool_entry_size(idx); |
duke@435 | 1538 | |
duke@435 | 1539 | assert(size + ent_size <= cpool_size, "Size mismatch"); |
duke@435 | 1540 | |
duke@435 | 1541 | *bytes = tag; |
duke@435 | 1542 | DBG(printf("#%03hd tag=%03hd, ", idx, tag)); |
duke@435 | 1543 | switch(tag) { |
duke@435 | 1544 | case JVM_CONSTANT_Invalid: { |
duke@435 | 1545 | DBG(printf("JVM_CONSTANT_Invalid")); |
duke@435 | 1546 | break; |
duke@435 | 1547 | } |
duke@435 | 1548 | case JVM_CONSTANT_Unicode: { |
duke@435 | 1549 | assert(false, "Wrong constant pool tag: JVM_CONSTANT_Unicode"); |
duke@435 | 1550 | DBG(printf("JVM_CONSTANT_Unicode")); |
duke@435 | 1551 | break; |
duke@435 | 1552 | } |
duke@435 | 1553 | case JVM_CONSTANT_Utf8: { |
coleenp@2497 | 1554 | Symbol* sym = symbol_at(idx); |
duke@435 | 1555 | char* str = sym->as_utf8(); |
duke@435 | 1556 | // Warning! It's crashing on x86 with len = sym->utf8_length() |
duke@435 | 1557 | int len = (int) strlen(str); |
duke@435 | 1558 | Bytes::put_Java_u2((address) (bytes+1), (u2) len); |
duke@435 | 1559 | for (int i = 0; i < len; i++) { |
duke@435 | 1560 | bytes[3+i] = (u1) str[i]; |
duke@435 | 1561 | } |
duke@435 | 1562 | DBG(printf("JVM_CONSTANT_Utf8: %s ", str)); |
duke@435 | 1563 | break; |
duke@435 | 1564 | } |
duke@435 | 1565 | case JVM_CONSTANT_Integer: { |
duke@435 | 1566 | jint val = int_at(idx); |
duke@435 | 1567 | Bytes::put_Java_u4((address) (bytes+1), *(u4*)&val); |
duke@435 | 1568 | break; |
duke@435 | 1569 | } |
duke@435 | 1570 | case JVM_CONSTANT_Float: { |
duke@435 | 1571 | jfloat val = float_at(idx); |
duke@435 | 1572 | Bytes::put_Java_u4((address) (bytes+1), *(u4*)&val); |
duke@435 | 1573 | break; |
duke@435 | 1574 | } |
duke@435 | 1575 | case JVM_CONSTANT_Long: { |
duke@435 | 1576 | jlong val = long_at(idx); |
duke@435 | 1577 | Bytes::put_Java_u8((address) (bytes+1), *(u8*)&val); |
duke@435 | 1578 | idx++; // Long takes two cpool slots |
duke@435 | 1579 | break; |
duke@435 | 1580 | } |
duke@435 | 1581 | case JVM_CONSTANT_Double: { |
duke@435 | 1582 | jdouble val = double_at(idx); |
duke@435 | 1583 | Bytes::put_Java_u8((address) (bytes+1), *(u8*)&val); |
duke@435 | 1584 | idx++; // Double takes two cpool slots |
duke@435 | 1585 | break; |
duke@435 | 1586 | } |
duke@435 | 1587 | case JVM_CONSTANT_Class: |
duke@435 | 1588 | case JVM_CONSTANT_UnresolvedClass: |
duke@435 | 1589 | case JVM_CONSTANT_UnresolvedClassInError: { |
duke@435 | 1590 | *bytes = JVM_CONSTANT_Class; |
coleenp@2497 | 1591 | Symbol* sym = klass_name_at(idx); |
duke@435 | 1592 | idx1 = tbl->symbol_to_value(sym); |
duke@435 | 1593 | assert(idx1 != 0, "Have not found a hashtable entry"); |
duke@435 | 1594 | Bytes::put_Java_u2((address) (bytes+1), idx1); |
duke@435 | 1595 | DBG(printf("JVM_CONSTANT_Class: idx=#%03hd, %s", idx1, sym->as_utf8())); |
duke@435 | 1596 | break; |
duke@435 | 1597 | } |
duke@435 | 1598 | case JVM_CONSTANT_String: { |
duke@435 | 1599 | unsigned int hash; |
duke@435 | 1600 | char *str = string_at_noresolve(idx); |
coleenp@2497 | 1601 | TempNewSymbol sym = SymbolTable::lookup_only(str, (int) strlen(str), hash); |
thurka@1208 | 1602 | if (sym == NULL) { |
thurka@1208 | 1603 | // sym can be NULL if string refers to incorrectly encoded JVM_CONSTANT_Utf8 |
thurka@1208 | 1604 | // this can happen with JVM TI; see CR 6839599 for more details |
coleenp@2497 | 1605 | oop string = *(obj_at_addr_raw(idx)); |
thurka@1208 | 1606 | assert(java_lang_String::is_instance(string),"Not a String"); |
thurka@1208 | 1607 | DBG(printf("Error #%03hd tag=%03hd\n", idx, tag)); |
thurka@1208 | 1608 | idx1 = 0; |
thurka@1208 | 1609 | for (int j = 0; j < tbl->table_size() && idx1 == 0; j++) { |
thurka@1208 | 1610 | for (SymbolHashMapEntry* cur = tbl->bucket(j); cur != NULL; cur = cur->next()) { |
thurka@1208 | 1611 | int length; |
coleenp@2497 | 1612 | Symbol* s = cur->symbol(); |
coleenp@2497 | 1613 | jchar* chars = s->as_unicode(length); |
thurka@1208 | 1614 | if (java_lang_String::equals(string, chars, length)) { |
thurka@1208 | 1615 | idx1 = cur->value(); |
thurka@1208 | 1616 | DBG(printf("Index found: %d\n",idx1)); |
thurka@1208 | 1617 | break; |
thurka@1208 | 1618 | } |
thurka@1208 | 1619 | } |
thurka@1208 | 1620 | } |
thurka@1208 | 1621 | } else { |
thurka@1208 | 1622 | idx1 = tbl->symbol_to_value(sym); |
thurka@1208 | 1623 | } |
duke@435 | 1624 | assert(idx1 != 0, "Have not found a hashtable entry"); |
duke@435 | 1625 | Bytes::put_Java_u2((address) (bytes+1), idx1); |
duke@435 | 1626 | DBG(printf("JVM_CONSTANT_String: idx=#%03hd, %s", idx1, str)); |
duke@435 | 1627 | break; |
duke@435 | 1628 | } |
duke@435 | 1629 | case JVM_CONSTANT_UnresolvedString: { |
duke@435 | 1630 | *bytes = JVM_CONSTANT_String; |
coleenp@2497 | 1631 | Symbol* sym = unresolved_string_at(idx); |
duke@435 | 1632 | idx1 = tbl->symbol_to_value(sym); |
duke@435 | 1633 | assert(idx1 != 0, "Have not found a hashtable entry"); |
duke@435 | 1634 | Bytes::put_Java_u2((address) (bytes+1), idx1); |
duke@435 | 1635 | DBG(char *str = sym->as_utf8()); |
duke@435 | 1636 | DBG(printf("JVM_CONSTANT_UnresolvedString: idx=#%03hd, %s", idx1, str)); |
duke@435 | 1637 | break; |
duke@435 | 1638 | } |
duke@435 | 1639 | case JVM_CONSTANT_Fieldref: |
duke@435 | 1640 | case JVM_CONSTANT_Methodref: |
duke@435 | 1641 | case JVM_CONSTANT_InterfaceMethodref: { |
duke@435 | 1642 | idx1 = uncached_klass_ref_index_at(idx); |
duke@435 | 1643 | idx2 = uncached_name_and_type_ref_index_at(idx); |
duke@435 | 1644 | Bytes::put_Java_u2((address) (bytes+1), idx1); |
duke@435 | 1645 | Bytes::put_Java_u2((address) (bytes+3), idx2); |
duke@435 | 1646 | DBG(printf("JVM_CONSTANT_Methodref: %hd %hd", idx1, idx2)); |
duke@435 | 1647 | break; |
duke@435 | 1648 | } |
duke@435 | 1649 | case JVM_CONSTANT_NameAndType: { |
duke@435 | 1650 | idx1 = name_ref_index_at(idx); |
duke@435 | 1651 | idx2 = signature_ref_index_at(idx); |
duke@435 | 1652 | Bytes::put_Java_u2((address) (bytes+1), idx1); |
duke@435 | 1653 | Bytes::put_Java_u2((address) (bytes+3), idx2); |
duke@435 | 1654 | DBG(printf("JVM_CONSTANT_NameAndType: %hd %hd", idx1, idx2)); |
duke@435 | 1655 | break; |
duke@435 | 1656 | } |
duke@435 | 1657 | case JVM_CONSTANT_ClassIndex: { |
duke@435 | 1658 | *bytes = JVM_CONSTANT_Class; |
duke@435 | 1659 | idx1 = klass_index_at(idx); |
duke@435 | 1660 | Bytes::put_Java_u2((address) (bytes+1), idx1); |
duke@435 | 1661 | DBG(printf("JVM_CONSTANT_ClassIndex: %hd", idx1)); |
duke@435 | 1662 | break; |
duke@435 | 1663 | } |
duke@435 | 1664 | case JVM_CONSTANT_StringIndex: { |
duke@435 | 1665 | *bytes = JVM_CONSTANT_String; |
duke@435 | 1666 | idx1 = string_index_at(idx); |
duke@435 | 1667 | Bytes::put_Java_u2((address) (bytes+1), idx1); |
duke@435 | 1668 | DBG(printf("JVM_CONSTANT_StringIndex: %hd", idx1)); |
duke@435 | 1669 | break; |
duke@435 | 1670 | } |
jrose@1957 | 1671 | case JVM_CONSTANT_MethodHandle: { |
jrose@1957 | 1672 | *bytes = JVM_CONSTANT_MethodHandle; |
jrose@1957 | 1673 | int kind = method_handle_ref_kind_at(idx); |
jrose@1957 | 1674 | idx1 = method_handle_index_at(idx); |
jrose@1957 | 1675 | *(bytes+1) = (unsigned char) kind; |
jrose@1957 | 1676 | Bytes::put_Java_u2((address) (bytes+2), idx1); |
jrose@1957 | 1677 | DBG(printf("JVM_CONSTANT_MethodHandle: %d %hd", kind, idx1)); |
jrose@1957 | 1678 | break; |
jrose@1957 | 1679 | } |
jrose@1957 | 1680 | case JVM_CONSTANT_MethodType: { |
jrose@1957 | 1681 | *bytes = JVM_CONSTANT_MethodType; |
jrose@1957 | 1682 | idx1 = method_type_index_at(idx); |
jrose@1957 | 1683 | Bytes::put_Java_u2((address) (bytes+1), idx1); |
jrose@1957 | 1684 | DBG(printf("JVM_CONSTANT_MethodType: %hd", idx1)); |
jrose@1957 | 1685 | break; |
jrose@1957 | 1686 | } |
jrose@2015 | 1687 | case JVM_CONSTANT_InvokeDynamic: { |
jrose@2353 | 1688 | *bytes = tag; |
jrose@2353 | 1689 | idx1 = extract_low_short_from_int(*int_at_addr(idx)); |
jrose@2353 | 1690 | idx2 = extract_high_short_from_int(*int_at_addr(idx)); |
jrose@2353 | 1691 | assert(idx2 == invoke_dynamic_name_and_type_ref_index_at(idx), "correct half of u4"); |
jrose@2015 | 1692 | Bytes::put_Java_u2((address) (bytes+1), idx1); |
jrose@2015 | 1693 | Bytes::put_Java_u2((address) (bytes+3), idx2); |
jrose@2353 | 1694 | DBG(printf("JVM_CONSTANT_InvokeDynamic: %hd %hd", idx1, idx2)); |
jrose@2015 | 1695 | break; |
jrose@2015 | 1696 | } |
duke@435 | 1697 | } |
duke@435 | 1698 | DBG(printf("\n")); |
duke@435 | 1699 | bytes += ent_size; |
duke@435 | 1700 | size += ent_size; |
duke@435 | 1701 | } |
duke@435 | 1702 | assert(size == cpool_size, "Size mismatch"); |
duke@435 | 1703 | |
duke@435 | 1704 | // Keep temorarily for debugging until it's stable. |
duke@435 | 1705 | DBG(print_cpool_bytes(cnt, start_bytes)); |
duke@435 | 1706 | return (int)(bytes - start_bytes); |
duke@435 | 1707 | } /* end copy_cpool_bytes */ |
duke@435 | 1708 | |
duke@435 | 1709 | |
coleenp@2497 | 1710 | void SymbolHashMap::add_entry(Symbol* sym, u2 value) { |
duke@435 | 1711 | char *str = sym->as_utf8(); |
duke@435 | 1712 | unsigned int hash = compute_hash(str, sym->utf8_length()); |
duke@435 | 1713 | unsigned int index = hash % table_size(); |
duke@435 | 1714 | |
duke@435 | 1715 | // check if already in map |
duke@435 | 1716 | // we prefer the first entry since it is more likely to be what was used in |
duke@435 | 1717 | // the class file |
duke@435 | 1718 | for (SymbolHashMapEntry *en = bucket(index); en != NULL; en = en->next()) { |
duke@435 | 1719 | assert(en->symbol() != NULL, "SymbolHashMapEntry symbol is NULL"); |
duke@435 | 1720 | if (en->hash() == hash && en->symbol() == sym) { |
duke@435 | 1721 | return; // already there |
duke@435 | 1722 | } |
duke@435 | 1723 | } |
duke@435 | 1724 | |
duke@435 | 1725 | SymbolHashMapEntry* entry = new SymbolHashMapEntry(hash, sym, value); |
duke@435 | 1726 | entry->set_next(bucket(index)); |
duke@435 | 1727 | _buckets[index].set_entry(entry); |
duke@435 | 1728 | assert(entry->symbol() != NULL, "SymbolHashMapEntry symbol is NULL"); |
duke@435 | 1729 | } |
duke@435 | 1730 | |
coleenp@2497 | 1731 | SymbolHashMapEntry* SymbolHashMap::find_entry(Symbol* sym) { |
duke@435 | 1732 | assert(sym != NULL, "SymbolHashMap::find_entry - symbol is NULL"); |
duke@435 | 1733 | char *str = sym->as_utf8(); |
duke@435 | 1734 | int len = sym->utf8_length(); |
duke@435 | 1735 | unsigned int hash = SymbolHashMap::compute_hash(str, len); |
duke@435 | 1736 | unsigned int index = hash % table_size(); |
duke@435 | 1737 | for (SymbolHashMapEntry *en = bucket(index); en != NULL; en = en->next()) { |
duke@435 | 1738 | assert(en->symbol() != NULL, "SymbolHashMapEntry symbol is NULL"); |
duke@435 | 1739 | if (en->hash() == hash && en->symbol() == sym) { |
duke@435 | 1740 | return en; |
duke@435 | 1741 | } |
duke@435 | 1742 | } |
duke@435 | 1743 | return NULL; |
duke@435 | 1744 | } |