annotate src/share/vm/oops/constantPoolOop.cpp @ 3582:1d7922586cf6

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