annotate src/share/vm/oops/constantPoolOop.cpp @ 1524:136b78722a08

6939203: JSR 292 needs method handle constants Summary: Add new CP types CONSTANT_MethodHandle, CONSTANT_MethodType; extend 'ldc' bytecode. Reviewed-by: twisti, never
author jrose
date Wed, 09 Jun 2010 18:50:45 -0700
parents e9ff18c4ace7
children 083fde3b838e
rev   line source
duke@0 1 /*
jrose@1500 2 * Copyright (c) 1997, 2010, 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
duke@0 25 # include "incls/_precompiled.incl"
duke@0 26 # include "incls/_constantPoolOop.cpp.incl"
duke@0 27
jrose@431 28 void constantPoolOopDesc::set_flag_at(FlagBit fb) {
jrose@431 29 const int MAX_STATE_CHANGES = 2;
jrose@431 30 for (int i = MAX_STATE_CHANGES + 10; i > 0; i--) {
jrose@431 31 int oflags = _flags;
jrose@431 32 int nflags = oflags | (1 << (int)fb);
jrose@431 33 if (Atomic::cmpxchg(nflags, &_flags, oflags) == oflags)
jrose@431 34 return;
jrose@431 35 }
jrose@431 36 assert(false, "failed to cmpxchg flags");
jrose@431 37 _flags |= (1 << (int)fb); // better than nothing
jrose@431 38 }
jrose@431 39
duke@0 40 klassOop constantPoolOopDesc::klass_at_impl(constantPoolHandle this_oop, int which, TRAPS) {
duke@0 41 // A resolved constantPool entry will contain a klassOop, otherwise a symbolOop.
duke@0 42 // 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 43 // tag is not updated atomicly.
duke@0 44 oop entry = *(this_oop->obj_at_addr(which));
duke@0 45 if (entry->is_klass()) {
duke@0 46 // Already resolved - return entry.
duke@0 47 return (klassOop)entry;
duke@0 48 }
duke@0 49
duke@0 50 // Acquire lock on constant oop while doing update. After we get the lock, we check if another object
duke@0 51 // already has updated the object
duke@0 52 assert(THREAD->is_Java_thread(), "must be a Java thread");
duke@0 53 bool do_resolve = false;
duke@0 54 bool in_error = false;
duke@0 55
duke@0 56 symbolHandle name;
duke@0 57 Handle loader;
duke@0 58 { ObjectLocker ol(this_oop, THREAD);
duke@0 59
duke@0 60 if (this_oop->tag_at(which).is_unresolved_klass()) {
duke@0 61 if (this_oop->tag_at(which).is_unresolved_klass_in_error()) {
duke@0 62 in_error = true;
duke@0 63 } else {
duke@0 64 do_resolve = true;
duke@0 65 name = symbolHandle(THREAD, this_oop->unresolved_klass_at(which));
duke@0 66 loader = Handle(THREAD, instanceKlass::cast(this_oop->pool_holder())->class_loader());
duke@0 67 }
duke@0 68 }
duke@0 69 } // unlocking constantPool
duke@0 70
duke@0 71
duke@0 72 // The original attempt to resolve this constant pool entry failed so find the
duke@0 73 // original error and throw it again (JVMS 5.4.3).
duke@0 74 if (in_error) {
duke@0 75 symbolOop error = SystemDictionary::find_resolution_error(this_oop, which);
duke@0 76 guarantee(error != (symbolOop)NULL, "tag mismatch with resolution error table");
duke@0 77 ResourceMark rm;
duke@0 78 // exception text will be the class name
duke@0 79 const char* className = this_oop->unresolved_klass_at(which)->as_C_string();
duke@0 80 THROW_MSG_0(error, className);
duke@0 81 }
duke@0 82
duke@0 83 if (do_resolve) {
duke@0 84 // this_oop must be unlocked during resolve_or_fail
duke@0 85 oop protection_domain = Klass::cast(this_oop->pool_holder())->protection_domain();
duke@0 86 Handle h_prot (THREAD, protection_domain);
duke@0 87 klassOop k_oop = SystemDictionary::resolve_or_fail(name, loader, h_prot, true, THREAD);
duke@0 88 KlassHandle k;
duke@0 89 if (!HAS_PENDING_EXCEPTION) {
duke@0 90 k = KlassHandle(THREAD, k_oop);
duke@0 91 // Do access check for klasses
duke@0 92 verify_constant_pool_resolve(this_oop, k, THREAD);
duke@0 93 }
duke@0 94
duke@0 95 // Failed to resolve class. We must record the errors so that subsequent attempts
duke@0 96 // to resolve this constant pool entry fail with the same error (JVMS 5.4.3).
duke@0 97 if (HAS_PENDING_EXCEPTION) {
duke@0 98 ResourceMark rm;
duke@0 99 symbolHandle error(PENDING_EXCEPTION->klass()->klass_part()->name());
duke@0 100
duke@0 101 bool throw_orig_error = false;
duke@0 102 {
duke@0 103 ObjectLocker ol (this_oop, THREAD);
duke@0 104
duke@0 105 // some other thread has beaten us and has resolved the class.
duke@0 106 if (this_oop->tag_at(which).is_klass()) {
duke@0 107 CLEAR_PENDING_EXCEPTION;
duke@0 108 entry = this_oop->resolved_klass_at(which);
duke@0 109 return (klassOop)entry;
duke@0 110 }
duke@0 111
duke@0 112 if (!PENDING_EXCEPTION->
never@1142 113 is_a(SystemDictionary::LinkageError_klass())) {
duke@0 114 // Just throw the exception and don't prevent these classes from
duke@0 115 // being loaded due to virtual machine errors like StackOverflow
duke@0 116 // and OutOfMemoryError, etc, or if the thread was hit by stop()
duke@0 117 // Needs clarification to section 5.4.3 of the VM spec (see 6308271)
duke@0 118 }
duke@0 119 else if (!this_oop->tag_at(which).is_unresolved_klass_in_error()) {
duke@0 120 SystemDictionary::add_resolution_error(this_oop, which, error);
duke@0 121 this_oop->tag_at_put(which, JVM_CONSTANT_UnresolvedClassInError);
duke@0 122 } else {
duke@0 123 // some other thread has put the class in error state.
duke@0 124 error = symbolHandle(SystemDictionary::find_resolution_error(this_oop, which));
duke@0 125 assert(!error.is_null(), "checking");
duke@0 126 throw_orig_error = true;
duke@0 127 }
duke@0 128 } // unlocked
duke@0 129
duke@0 130 if (throw_orig_error) {
duke@0 131 CLEAR_PENDING_EXCEPTION;
duke@0 132 ResourceMark rm;
duke@0 133 const char* className = this_oop->unresolved_klass_at(which)->as_C_string();
duke@0 134 THROW_MSG_0(error, className);
duke@0 135 }
duke@0 136
duke@0 137 return 0;
duke@0 138 }
duke@0 139
duke@0 140 if (TraceClassResolution && !k()->klass_part()->oop_is_array()) {
duke@0 141 // skip resolving the constant pool so that this code get's
duke@0 142 // called the next time some bytecodes refer to this class.
duke@0 143 ResourceMark rm;
duke@0 144 int line_number = -1;
duke@0 145 const char * source_file = NULL;
duke@0 146 if (JavaThread::current()->has_last_Java_frame()) {
duke@0 147 // try to identify the method which called this function.
duke@0 148 vframeStream vfst(JavaThread::current());
duke@0 149 if (!vfst.at_end()) {
duke@0 150 line_number = vfst.method()->line_number_from_bci(vfst.bci());
duke@0 151 symbolOop s = instanceKlass::cast(vfst.method()->method_holder())->source_file_name();
duke@0 152 if (s != NULL) {
duke@0 153 source_file = s->as_C_string();
duke@0 154 }
duke@0 155 }
duke@0 156 }
duke@0 157 if (k() != this_oop->pool_holder()) {
duke@0 158 // only print something if the classes are different
duke@0 159 if (source_file != NULL) {
duke@0 160 tty->print("RESOLVE %s %s %s:%d\n",
duke@0 161 instanceKlass::cast(this_oop->pool_holder())->external_name(),
duke@0 162 instanceKlass::cast(k())->external_name(), source_file, line_number);
duke@0 163 } else {
duke@0 164 tty->print("RESOLVE %s %s\n",
duke@0 165 instanceKlass::cast(this_oop->pool_holder())->external_name(),
duke@0 166 instanceKlass::cast(k())->external_name());
duke@0 167 }
duke@0 168 }
duke@0 169 return k();
duke@0 170 } else {
duke@0 171 ObjectLocker ol (this_oop, THREAD);
duke@0 172 // Only updated constant pool - if it is resolved.
duke@0 173 do_resolve = this_oop->tag_at(which).is_unresolved_klass();
duke@0 174 if (do_resolve) {
duke@0 175 this_oop->klass_at_put(which, k());
duke@0 176 }
duke@0 177 }
duke@0 178 }
duke@0 179
duke@0 180 entry = this_oop->resolved_klass_at(which);
duke@0 181 assert(entry->is_klass(), "must be resolved at this point");
duke@0 182 return (klassOop)entry;
duke@0 183 }
duke@0 184
duke@0 185
duke@0 186 // Does not update constantPoolOop - to avoid any exception throwing. Used
duke@0 187 // by compiler and exception handling. Also used to avoid classloads for
duke@0 188 // instanceof operations. Returns NULL if the class has not been loaded or
duke@0 189 // if the verification of constant pool failed
duke@0 190 klassOop constantPoolOopDesc::klass_at_if_loaded(constantPoolHandle this_oop, int which) {
duke@0 191 oop entry = *this_oop->obj_at_addr(which);
duke@0 192 if (entry->is_klass()) {
duke@0 193 return (klassOop)entry;
duke@0 194 } else {
duke@0 195 assert(entry->is_symbol(), "must be either symbol or klass");
duke@0 196 Thread *thread = Thread::current();
duke@0 197 symbolHandle name (thread, (symbolOop)entry);
duke@0 198 oop loader = instanceKlass::cast(this_oop->pool_holder())->class_loader();
duke@0 199 oop protection_domain = Klass::cast(this_oop->pool_holder())->protection_domain();
duke@0 200 Handle h_prot (thread, protection_domain);
duke@0 201 Handle h_loader (thread, loader);
duke@0 202 klassOop k = SystemDictionary::find(name, h_loader, h_prot, thread);
duke@0 203
duke@0 204 if (k != NULL) {
duke@0 205 // Make sure that resolving is legal
duke@0 206 EXCEPTION_MARK;
duke@0 207 KlassHandle klass(THREAD, k);
duke@0 208 // return NULL if verification fails
duke@0 209 verify_constant_pool_resolve(this_oop, klass, THREAD);
duke@0 210 if (HAS_PENDING_EXCEPTION) {
duke@0 211 CLEAR_PENDING_EXCEPTION;
duke@0 212 return NULL;
duke@0 213 }
duke@0 214 return klass();
duke@0 215 } else {
duke@0 216 return k;
duke@0 217 }
duke@0 218 }
duke@0 219 }
duke@0 220
duke@0 221
duke@0 222 klassOop constantPoolOopDesc::klass_ref_at_if_loaded(constantPoolHandle this_oop, int which) {
duke@0 223 return klass_at_if_loaded(this_oop, this_oop->klass_ref_index_at(which));
duke@0 224 }
duke@0 225
duke@0 226
duke@0 227 // This is an interface for the compiler that allows accessing non-resolved entries
duke@0 228 // in the constant pool - but still performs the validations tests. Must be used
duke@0 229 // in a pre-parse of the compiler - to determine what it can do and not do.
duke@0 230 // Note: We cannot update the ConstantPool from the vm_thread.
duke@0 231 klassOop constantPoolOopDesc::klass_ref_at_if_loaded_check(constantPoolHandle this_oop, int index, TRAPS) {
duke@0 232 int which = this_oop->klass_ref_index_at(index);
duke@0 233 oop entry = *this_oop->obj_at_addr(which);
duke@0 234 if (entry->is_klass()) {
duke@0 235 return (klassOop)entry;
duke@0 236 } else {
duke@0 237 assert(entry->is_symbol(), "must be either symbol or klass");
duke@0 238 symbolHandle name (THREAD, (symbolOop)entry);
duke@0 239 oop loader = instanceKlass::cast(this_oop->pool_holder())->class_loader();
duke@0 240 oop protection_domain = Klass::cast(this_oop->pool_holder())->protection_domain();
duke@0 241 Handle h_loader(THREAD, loader);
duke@0 242 Handle h_prot (THREAD, protection_domain);
duke@0 243 KlassHandle k(THREAD, SystemDictionary::find(name, h_loader, h_prot, THREAD));
duke@0 244
duke@0 245 // Do access check for klasses
duke@0 246 if( k.not_null() ) verify_constant_pool_resolve(this_oop, k, CHECK_NULL);
duke@0 247 return k();
duke@0 248 }
duke@0 249 }
duke@0 250
duke@0 251
jrose@726 252 symbolOop constantPoolOopDesc::impl_name_ref_at(int which, bool uncached) {
jrose@726 253 int name_index = name_ref_index_at(impl_name_and_type_ref_index_at(which, uncached));
duke@0 254 return symbol_at(name_index);
duke@0 255 }
duke@0 256
duke@0 257
jrose@726 258 symbolOop constantPoolOopDesc::impl_signature_ref_at(int which, bool uncached) {
jrose@726 259 int signature_index = signature_ref_index_at(impl_name_and_type_ref_index_at(which, uncached));
duke@0 260 return symbol_at(signature_index);
duke@0 261 }
duke@0 262
duke@0 263
jrose@726 264 int constantPoolOopDesc::impl_name_and_type_ref_index_at(int which, bool uncached) {
jrose@1059 265 int i = which;
jrose@1059 266 if (!uncached && cache() != NULL) {
jrose@1059 267 if (constantPoolCacheOopDesc::is_secondary_index(which))
jrose@1059 268 // Invokedynamic indexes are always processed in native order
jrose@1059 269 // so there is no question of reading a native u2 in Java order here.
jrose@1059 270 return cache()->main_entry_at(which)->constant_pool_index();
jrose@1059 271 // change byte-ordering and go via cache
jrose@1059 272 i = remap_instruction_operand_from_cache(which);
jrose@1059 273 } else {
jrose@1059 274 if (tag_at(which).is_name_and_type())
jrose@1059 275 // invokedynamic index is a simple name-and-type
jrose@1059 276 return which;
jrose@1059 277 }
jrose@1059 278 assert(tag_at(i).is_field_or_method(), "Corrupted constant pool");
jrose@1059 279 jint ref_index = *int_at_addr(i);
duke@0 280 return extract_high_short_from_int(ref_index);
duke@0 281 }
duke@0 282
duke@0 283
jrose@726 284 int constantPoolOopDesc::impl_klass_ref_index_at(int which, bool uncached) {
jrose@1059 285 guarantee(!constantPoolCacheOopDesc::is_secondary_index(which),
jrose@1059 286 "an invokedynamic instruction does not have a klass");
jrose@1059 287 int i = which;
jrose@1059 288 if (!uncached && cache() != NULL) {
jrose@1059 289 // change byte-ordering and go via cache
jrose@1059 290 i = remap_instruction_operand_from_cache(which);
jrose@1059 291 }
jrose@1059 292 assert(tag_at(i).is_field_or_method(), "Corrupted constant pool");
jrose@1059 293 jint ref_index = *int_at_addr(i);
duke@0 294 return extract_low_short_from_int(ref_index);
duke@0 295 }
duke@0 296
duke@0 297
jrose@726 298
jrose@1059 299 int constantPoolOopDesc::remap_instruction_operand_from_cache(int operand) {
jrose@1486 300 int cpc_index = operand;
jrose@1486 301 DEBUG_ONLY(cpc_index -= CPCACHE_INDEX_TAG);
jrose@1486 302 assert((int)(u2)cpc_index == cpc_index, "clean u2");
jrose@1059 303 int member_index = cache()->entry_at(cpc_index)->constant_pool_index();
jrose@1059 304 return member_index;
jrose@726 305 }
jrose@726 306
jrose@726 307
duke@0 308 void constantPoolOopDesc::verify_constant_pool_resolve(constantPoolHandle this_oop, KlassHandle k, TRAPS) {
duke@0 309 if (k->oop_is_instance() || k->oop_is_objArray()) {
duke@0 310 instanceKlassHandle holder (THREAD, this_oop->pool_holder());
duke@0 311 klassOop elem_oop = k->oop_is_instance() ? k() : objArrayKlass::cast(k())->bottom_klass();
duke@0 312 KlassHandle element (THREAD, elem_oop);
duke@0 313
duke@0 314 // The element type could be a typeArray - we only need the access check if it is
duke@0 315 // an reference to another class
duke@0 316 if (element->oop_is_instance()) {
duke@0 317 LinkResolver::check_klass_accessability(holder, element, CHECK);
duke@0 318 }
duke@0 319 }
duke@0 320 }
duke@0 321
duke@0 322
jrose@726 323 int constantPoolOopDesc::name_ref_index_at(int which_nt) {
jrose@726 324 jint ref_index = name_and_type_at(which_nt);
duke@0 325 return extract_low_short_from_int(ref_index);
duke@0 326 }
duke@0 327
duke@0 328
jrose@726 329 int constantPoolOopDesc::signature_ref_index_at(int which_nt) {
jrose@726 330 jint ref_index = name_and_type_at(which_nt);
duke@0 331 return extract_high_short_from_int(ref_index);
duke@0 332 }
duke@0 333
duke@0 334
duke@0 335 klassOop constantPoolOopDesc::klass_ref_at(int which, TRAPS) {
duke@0 336 return klass_at(klass_ref_index_at(which), CHECK_NULL);
duke@0 337 }
duke@0 338
duke@0 339
duke@0 340 symbolOop constantPoolOopDesc::klass_name_at(int which) {
duke@0 341 assert(tag_at(which).is_unresolved_klass() || tag_at(which).is_klass(),
duke@0 342 "Corrupted constant pool");
duke@0 343 // A resolved constantPool entry will contain a klassOop, otherwise a symbolOop.
duke@0 344 // 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 345 // tag is not updated atomicly.
duke@0 346 oop entry = *(obj_at_addr(which));
duke@0 347 if (entry->is_klass()) {
duke@0 348 // Already resolved - return entry's name.
duke@0 349 return klassOop(entry)->klass_part()->name();
duke@0 350 } else {
duke@0 351 assert(entry->is_symbol(), "must be either symbol or klass");
duke@0 352 return (symbolOop)entry;
duke@0 353 }
duke@0 354 }
duke@0 355
duke@0 356 symbolOop constantPoolOopDesc::klass_ref_at_noresolve(int which) {
duke@0 357 jint ref_index = klass_ref_index_at(which);
duke@0 358 return klass_at_noresolve(ref_index);
duke@0 359 }
duke@0 360
jrose@1524 361 symbolOop constantPoolOopDesc::uncached_klass_ref_at_noresolve(int which) {
jrose@1524 362 jint ref_index = uncached_klass_ref_index_at(which);
jrose@1524 363 return klass_at_noresolve(ref_index);
jrose@1524 364 }
jrose@1524 365
duke@0 366 char* constantPoolOopDesc::string_at_noresolve(int which) {
duke@0 367 // Test entry type in case string is resolved while in here.
duke@0 368 oop entry = *(obj_at_addr(which));
duke@0 369 if (entry->is_symbol()) {
duke@0 370 return ((symbolOop)entry)->as_C_string();
jrose@431 371 } else if (java_lang_String::is_instance(entry)) {
jrose@431 372 return java_lang_String::as_utf8_string(entry);
duke@0 373 } else {
jrose@431 374 return (char*)"<pseudo-string>";
duke@0 375 }
duke@0 376 }
duke@0 377
duke@0 378
duke@0 379 BasicType constantPoolOopDesc::basic_type_for_signature_at(int which) {
duke@0 380 return FieldType::basic_type(symbol_at(which));
duke@0 381 }
duke@0 382
duke@0 383
duke@0 384 void constantPoolOopDesc::resolve_string_constants_impl(constantPoolHandle this_oop, TRAPS) {
duke@0 385 for (int index = 1; index < this_oop->length(); index++) { // Index 0 is unused
duke@0 386 if (this_oop->tag_at(index).is_unresolved_string()) {
duke@0 387 this_oop->string_at(index, CHECK);
duke@0 388 }
duke@0 389 }
duke@0 390 }
duke@0 391
jrose@1524 392 oop constantPoolOopDesc::resolve_constant_at_impl(constantPoolHandle this_oop, int index, int cache_index, TRAPS) {
jrose@1524 393 oop result_oop = NULL;
jrose@1524 394 if (cache_index >= 0) {
jrose@1524 395 assert(index < 0, "only one kind of index at a time");
jrose@1524 396 ConstantPoolCacheEntry* cpc_entry = this_oop->cache()->entry_at(cache_index);
jrose@1524 397 result_oop = cpc_entry->f1();
jrose@1524 398 if (result_oop != NULL) {
jrose@1524 399 return result_oop; // that was easy...
jrose@1524 400 }
jrose@1524 401 index = cpc_entry->constant_pool_index();
jrose@1524 402 }
jrose@1524 403
jrose@1524 404 int tag_value = this_oop->tag_at(index).value();
jrose@1524 405 switch (tag_value) {
jrose@1524 406
jrose@1524 407 case JVM_CONSTANT_UnresolvedClass:
jrose@1524 408 case JVM_CONSTANT_UnresolvedClassInError:
jrose@1524 409 case JVM_CONSTANT_Class:
jrose@1524 410 {
jrose@1524 411 klassOop resolved = klass_at_impl(this_oop, index, CHECK_NULL);
jrose@1524 412 // ldc wants the java mirror.
jrose@1524 413 result_oop = resolved->klass_part()->java_mirror();
jrose@1524 414 break;
jrose@1524 415 }
jrose@1524 416
jrose@1524 417 case JVM_CONSTANT_String:
jrose@1524 418 case JVM_CONSTANT_UnresolvedString:
jrose@1524 419 if (this_oop->is_pseudo_string_at(index)) {
jrose@1524 420 result_oop = this_oop->pseudo_string_at(index);
jrose@1524 421 break;
jrose@1524 422 }
jrose@1524 423 result_oop = string_at_impl(this_oop, index, CHECK_NULL);
jrose@1524 424 break;
jrose@1524 425
jrose@1524 426 case JVM_CONSTANT_Object:
jrose@1524 427 result_oop = this_oop->object_at(index);
jrose@1524 428 break;
jrose@1524 429
jrose@1524 430 case JVM_CONSTANT_MethodHandle:
jrose@1524 431 {
jrose@1524 432 int ref_kind = this_oop->method_handle_ref_kind_at(index);
jrose@1524 433 int callee_index = this_oop->method_handle_klass_index_at(index);
jrose@1524 434 symbolHandle name(THREAD, this_oop->method_handle_name_ref_at(index));
jrose@1524 435 symbolHandle signature(THREAD, this_oop->method_handle_signature_ref_at(index));
jrose@1524 436 if (PrintMiscellaneous)
jrose@1524 437 tty->print_cr("resolve JVM_CONSTANT_MethodHandle:%d [%d/%d/%d] %s.%s",
jrose@1524 438 ref_kind, index, this_oop->method_handle_index_at(index),
jrose@1524 439 callee_index, name->as_C_string(), signature->as_C_string());
jrose@1524 440 KlassHandle callee;
jrose@1524 441 { klassOop k = klass_at_impl(this_oop, callee_index, CHECK_NULL);
jrose@1524 442 callee = KlassHandle(THREAD, k);
jrose@1524 443 }
jrose@1524 444 KlassHandle klass(THREAD, this_oop->pool_holder());
jrose@1524 445 Handle value = SystemDictionary::link_method_handle_constant(klass, ref_kind,
jrose@1524 446 callee, name, signature,
jrose@1524 447 CHECK_NULL);
jrose@1524 448 result_oop = value();
jrose@1524 449 // FIXME: Uniquify errors, using SystemDictionary::find_resolution_error.
jrose@1524 450 break;
jrose@1524 451 }
jrose@1524 452
jrose@1524 453 case JVM_CONSTANT_MethodType:
jrose@1524 454 {
jrose@1524 455 symbolHandle signature(THREAD, this_oop->method_type_signature_at(index));
jrose@1524 456 if (PrintMiscellaneous)
jrose@1524 457 tty->print_cr("resolve JVM_CONSTANT_MethodType [%d/%d] %s",
jrose@1524 458 index, this_oop->method_type_index_at(index),
jrose@1524 459 signature->as_C_string());
jrose@1524 460 KlassHandle klass(THREAD, this_oop->pool_holder());
jrose@1524 461 bool ignore_is_on_bcp = false;
jrose@1524 462 Handle value = SystemDictionary::find_method_handle_type(signature,
jrose@1524 463 klass,
jrose@1524 464 ignore_is_on_bcp,
jrose@1524 465 CHECK_NULL);
jrose@1524 466 result_oop = value();
jrose@1524 467 // FIXME: Uniquify errors, using SystemDictionary::find_resolution_error.
jrose@1524 468 break;
jrose@1524 469 }
jrose@1524 470
jrose@1524 471 /* maybe some day
jrose@1524 472 case JVM_CONSTANT_Integer:
jrose@1524 473 case JVM_CONSTANT_Float:
jrose@1524 474 case JVM_CONSTANT_Long:
jrose@1524 475 case JVM_CONSTANT_Double:
jrose@1524 476 result_oop = java_lang_boxing_object::create(...);
jrose@1524 477 break;
jrose@1524 478 */
jrose@1524 479
jrose@1524 480 default:
jrose@1524 481 DEBUG_ONLY( tty->print_cr("*** %p: tag at CP[%d/%d] = %d",
jrose@1524 482 this_oop(), index, cache_index, tag_value) );
jrose@1524 483 assert(false, "unexpected constant tag");
jrose@1524 484 break;
jrose@1524 485 }
jrose@1524 486
jrose@1524 487 if (cache_index >= 0) {
jrose@1524 488 // Cache the oop here also.
jrose@1524 489 Handle result(THREAD, result_oop);
jrose@1524 490 result_oop = NULL; // safety
jrose@1524 491 ObjectLocker ol(this_oop, THREAD);
jrose@1524 492 ConstantPoolCacheEntry* cpc_entry = this_oop->cache()->entry_at(cache_index);
jrose@1524 493 oop result_oop2 = cpc_entry->f1();
jrose@1524 494 if (result_oop2 != NULL) {
jrose@1524 495 // Race condition: May already be filled in while we were trying to lock.
jrose@1524 496 return result_oop2;
jrose@1524 497 }
jrose@1524 498 cpc_entry->set_f1(result());
jrose@1524 499 return result();
jrose@1524 500 } else {
jrose@1524 501 return result_oop;
jrose@1524 502 }
jrose@1524 503 }
jrose@1524 504
duke@0 505 oop constantPoolOopDesc::string_at_impl(constantPoolHandle this_oop, int which, TRAPS) {
duke@0 506 oop entry = *(this_oop->obj_at_addr(which));
duke@0 507 if (entry->is_symbol()) {
duke@0 508 ObjectLocker ol(this_oop, THREAD);
duke@0 509 if (this_oop->tag_at(which).is_unresolved_string()) {
duke@0 510 // Intern string
duke@0 511 symbolOop sym = this_oop->unresolved_string_at(which);
duke@0 512 entry = StringTable::intern(sym, CHECK_(constantPoolOop(NULL)));
duke@0 513 this_oop->string_at_put(which, entry);
duke@0 514 } else {
duke@0 515 // Another thread beat us and interned string, read string from constant pool
duke@0 516 entry = this_oop->resolved_string_at(which);
duke@0 517 }
duke@0 518 }
duke@0 519 assert(java_lang_String::is_instance(entry), "must be string");
duke@0 520 return entry;
duke@0 521 }
duke@0 522
duke@0 523
jrose@431 524 bool constantPoolOopDesc::is_pseudo_string_at(int which) {
jrose@431 525 oop entry = *(obj_at_addr(which));
jrose@431 526 if (entry->is_symbol())
jrose@431 527 // Not yet resolved, but it will resolve to a string.
jrose@431 528 return false;
jrose@431 529 else if (java_lang_String::is_instance(entry))
jrose@431 530 return false; // actually, it might be a non-interned or non-perm string
jrose@431 531 else
jrose@431 532 // truly pseudo
jrose@431 533 return true;
jrose@431 534 }
jrose@431 535
jrose@431 536
duke@0 537 bool constantPoolOopDesc::klass_name_at_matches(instanceKlassHandle k,
duke@0 538 int which) {
duke@0 539 // Names are interned, so we can compare symbolOops directly
duke@0 540 symbolOop cp_name = klass_name_at(which);
duke@0 541 return (cp_name == k->name());
duke@0 542 }
duke@0 543
duke@0 544
duke@0 545 int constantPoolOopDesc::pre_resolve_shared_klasses(TRAPS) {
duke@0 546 ResourceMark rm;
duke@0 547 int count = 0;
duke@0 548 for (int index = 1; index < tags()->length(); index++) { // Index 0 is unused
duke@0 549 if (tag_at(index).is_unresolved_string()) {
duke@0 550 // Intern string
duke@0 551 symbolOop sym = unresolved_string_at(index);
duke@0 552 oop entry = StringTable::intern(sym, CHECK_(-1));
duke@0 553 string_at_put(index, entry);
duke@0 554 }
duke@0 555 }
duke@0 556 return count;
duke@0 557 }
duke@0 558
duke@0 559
duke@0 560 // Iterate over symbols which are used as class, field, method names and
duke@0 561 // signatures (in preparation for writing to the shared archive).
duke@0 562
duke@0 563 void constantPoolOopDesc::shared_symbols_iterate(OopClosure* closure) {
duke@0 564 for (int index = 1; index < length(); index++) { // Index 0 is unused
duke@0 565 switch (tag_at(index).value()) {
duke@0 566
duke@0 567 case JVM_CONSTANT_UnresolvedClass:
duke@0 568 closure->do_oop(obj_at_addr(index));
duke@0 569 break;
duke@0 570
duke@0 571 case JVM_CONSTANT_NameAndType:
duke@0 572 {
duke@0 573 int i = *int_at_addr(index);
duke@0 574 closure->do_oop(obj_at_addr((unsigned)i >> 16));
duke@0 575 closure->do_oop(obj_at_addr((unsigned)i & 0xffff));
duke@0 576 }
duke@0 577 break;
duke@0 578
duke@0 579 case JVM_CONSTANT_Class:
duke@0 580 case JVM_CONSTANT_InterfaceMethodref:
duke@0 581 case JVM_CONSTANT_Fieldref:
duke@0 582 case JVM_CONSTANT_Methodref:
duke@0 583 case JVM_CONSTANT_Integer:
duke@0 584 case JVM_CONSTANT_Float:
duke@0 585 // Do nothing! Not an oop.
duke@0 586 // These constant types do not reference symbols at this point.
duke@0 587 break;
duke@0 588
duke@0 589 case JVM_CONSTANT_String:
duke@0 590 // Do nothing! Not a symbol.
duke@0 591 break;
duke@0 592
duke@0 593 case JVM_CONSTANT_UnresolvedString:
duke@0 594 case JVM_CONSTANT_Utf8:
duke@0 595 // These constants are symbols, but unless these symbols are
duke@0 596 // actually to be used for something, we don't want to mark them.
duke@0 597 break;
duke@0 598
duke@0 599 case JVM_CONSTANT_Long:
duke@0 600 case JVM_CONSTANT_Double:
duke@0 601 // Do nothing! Not an oop. (But takes two pool entries.)
duke@0 602 ++index;
duke@0 603 break;
duke@0 604
duke@0 605 default:
duke@0 606 ShouldNotReachHere();
duke@0 607 break;
duke@0 608 }
duke@0 609 }
duke@0 610 }
duke@0 611
duke@0 612
duke@0 613 // Iterate over the [one] tags array (in preparation for writing to the
duke@0 614 // shared archive).
duke@0 615
duke@0 616 void constantPoolOopDesc::shared_tags_iterate(OopClosure* closure) {
duke@0 617 closure->do_oop(tags_addr());
duke@0 618 }
duke@0 619
duke@0 620
duke@0 621 // Iterate over String objects (in preparation for writing to the shared
duke@0 622 // archive).
duke@0 623
duke@0 624 void constantPoolOopDesc::shared_strings_iterate(OopClosure* closure) {
duke@0 625 for (int index = 1; index < length(); index++) { // Index 0 is unused
duke@0 626 switch (tag_at(index).value()) {
duke@0 627
duke@0 628 case JVM_CONSTANT_UnresolvedClass:
duke@0 629 case JVM_CONSTANT_NameAndType:
duke@0 630 // Do nothing! Not a String.
duke@0 631 break;
duke@0 632
duke@0 633 case JVM_CONSTANT_Class:
duke@0 634 case JVM_CONSTANT_InterfaceMethodref:
duke@0 635 case JVM_CONSTANT_Fieldref:
duke@0 636 case JVM_CONSTANT_Methodref:
duke@0 637 case JVM_CONSTANT_Integer:
duke@0 638 case JVM_CONSTANT_Float:
duke@0 639 // Do nothing! Not an oop.
duke@0 640 // These constant types do not reference symbols at this point.
duke@0 641 break;
duke@0 642
duke@0 643 case JVM_CONSTANT_String:
duke@0 644 closure->do_oop(obj_at_addr(index));
duke@0 645 break;
duke@0 646
duke@0 647 case JVM_CONSTANT_UnresolvedString:
duke@0 648 case JVM_CONSTANT_Utf8:
duke@0 649 // These constants are symbols, but unless these symbols are
duke@0 650 // actually to be used for something, we don't want to mark them.
duke@0 651 break;
duke@0 652
duke@0 653 case JVM_CONSTANT_Long:
duke@0 654 case JVM_CONSTANT_Double:
duke@0 655 // Do nothing! Not an oop. (But takes two pool entries.)
duke@0 656 ++index;
duke@0 657 break;
duke@0 658
duke@0 659 default:
duke@0 660 ShouldNotReachHere();
duke@0 661 break;
duke@0 662 }
duke@0 663 }
duke@0 664 }
duke@0 665
duke@0 666
duke@0 667 // Compare this constant pool's entry at index1 to the constant pool
duke@0 668 // cp2's entry at index2.
duke@0 669 bool constantPoolOopDesc::compare_entry_to(int index1, constantPoolHandle cp2,
duke@0 670 int index2, TRAPS) {
duke@0 671
duke@0 672 jbyte t1 = tag_at(index1).value();
duke@0 673 jbyte t2 = cp2->tag_at(index2).value();
duke@0 674
duke@0 675
duke@0 676 // JVM_CONSTANT_UnresolvedClassInError is equal to JVM_CONSTANT_UnresolvedClass
duke@0 677 // when comparing
duke@0 678 if (t1 == JVM_CONSTANT_UnresolvedClassInError) {
duke@0 679 t1 = JVM_CONSTANT_UnresolvedClass;
duke@0 680 }
duke@0 681 if (t2 == JVM_CONSTANT_UnresolvedClassInError) {
duke@0 682 t2 = JVM_CONSTANT_UnresolvedClass;
duke@0 683 }
duke@0 684
duke@0 685 if (t1 != t2) {
duke@0 686 // Not the same entry type so there is nothing else to check. Note
duke@0 687 // that this style of checking will consider resolved/unresolved
duke@0 688 // class pairs and resolved/unresolved string pairs as different.
duke@0 689 // From the constantPoolOop API point of view, this is correct
duke@0 690 // behavior. See constantPoolKlass::merge() to see how this plays
duke@0 691 // out in the context of constantPoolOop merging.
duke@0 692 return false;
duke@0 693 }
duke@0 694
duke@0 695 switch (t1) {
duke@0 696 case JVM_CONSTANT_Class:
duke@0 697 {
duke@0 698 klassOop k1 = klass_at(index1, CHECK_false);
duke@0 699 klassOop k2 = cp2->klass_at(index2, CHECK_false);
duke@0 700 if (k1 == k2) {
duke@0 701 return true;
duke@0 702 }
duke@0 703 } break;
duke@0 704
duke@0 705 case JVM_CONSTANT_ClassIndex:
duke@0 706 {
duke@0 707 int recur1 = klass_index_at(index1);
duke@0 708 int recur2 = cp2->klass_index_at(index2);
duke@0 709 bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
duke@0 710 if (match) {
duke@0 711 return true;
duke@0 712 }
duke@0 713 } break;
duke@0 714
duke@0 715 case JVM_CONSTANT_Double:
duke@0 716 {
duke@0 717 jdouble d1 = double_at(index1);
duke@0 718 jdouble d2 = cp2->double_at(index2);
duke@0 719 if (d1 == d2) {
duke@0 720 return true;
duke@0 721 }
duke@0 722 } break;
duke@0 723
duke@0 724 case JVM_CONSTANT_Fieldref:
duke@0 725 case JVM_CONSTANT_InterfaceMethodref:
duke@0 726 case JVM_CONSTANT_Methodref:
duke@0 727 {
duke@0 728 int recur1 = uncached_klass_ref_index_at(index1);
duke@0 729 int recur2 = cp2->uncached_klass_ref_index_at(index2);
duke@0 730 bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
duke@0 731 if (match) {
duke@0 732 recur1 = uncached_name_and_type_ref_index_at(index1);
duke@0 733 recur2 = cp2->uncached_name_and_type_ref_index_at(index2);
duke@0 734 match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
duke@0 735 if (match) {
duke@0 736 return true;
duke@0 737 }
duke@0 738 }
duke@0 739 } break;
duke@0 740
duke@0 741 case JVM_CONSTANT_Float:
duke@0 742 {
duke@0 743 jfloat f1 = float_at(index1);
duke@0 744 jfloat f2 = cp2->float_at(index2);
duke@0 745 if (f1 == f2) {
duke@0 746 return true;
duke@0 747 }
duke@0 748 } break;
duke@0 749
duke@0 750 case JVM_CONSTANT_Integer:
duke@0 751 {
duke@0 752 jint i1 = int_at(index1);
duke@0 753 jint i2 = cp2->int_at(index2);
duke@0 754 if (i1 == i2) {
duke@0 755 return true;
duke@0 756 }
duke@0 757 } break;
duke@0 758
duke@0 759 case JVM_CONSTANT_Long:
duke@0 760 {
duke@0 761 jlong l1 = long_at(index1);
duke@0 762 jlong l2 = cp2->long_at(index2);
duke@0 763 if (l1 == l2) {
duke@0 764 return true;
duke@0 765 }
duke@0 766 } break;
duke@0 767
duke@0 768 case JVM_CONSTANT_NameAndType:
duke@0 769 {
duke@0 770 int recur1 = name_ref_index_at(index1);
duke@0 771 int recur2 = cp2->name_ref_index_at(index2);
duke@0 772 bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
duke@0 773 if (match) {
duke@0 774 recur1 = signature_ref_index_at(index1);
duke@0 775 recur2 = cp2->signature_ref_index_at(index2);
duke@0 776 match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
duke@0 777 if (match) {
duke@0 778 return true;
duke@0 779 }
duke@0 780 }
duke@0 781 } break;
duke@0 782
duke@0 783 case JVM_CONSTANT_String:
duke@0 784 {
duke@0 785 oop s1 = string_at(index1, CHECK_false);
duke@0 786 oop s2 = cp2->string_at(index2, CHECK_false);
duke@0 787 if (s1 == s2) {
duke@0 788 return true;
duke@0 789 }
duke@0 790 } break;
duke@0 791
duke@0 792 case JVM_CONSTANT_StringIndex:
duke@0 793 {
duke@0 794 int recur1 = string_index_at(index1);
duke@0 795 int recur2 = cp2->string_index_at(index2);
duke@0 796 bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
duke@0 797 if (match) {
duke@0 798 return true;
duke@0 799 }
duke@0 800 } break;
duke@0 801
duke@0 802 case JVM_CONSTANT_UnresolvedClass:
duke@0 803 {
duke@0 804 symbolOop k1 = unresolved_klass_at(index1);
duke@0 805 symbolOop k2 = cp2->unresolved_klass_at(index2);
duke@0 806 if (k1 == k2) {
duke@0 807 return true;
duke@0 808 }
duke@0 809 } break;
duke@0 810
jrose@1524 811 case JVM_CONSTANT_MethodType:
jrose@1524 812 {
jrose@1524 813 int k1 = method_type_index_at(index1);
jrose@1524 814 int k2 = cp2->method_type_index_at(index2);
jrose@1524 815 if (k1 == k2) {
jrose@1524 816 return true;
jrose@1524 817 }
jrose@1524 818 } break;
jrose@1524 819
jrose@1524 820 case JVM_CONSTANT_MethodHandle:
jrose@1524 821 {
jrose@1524 822 int k1 = method_handle_ref_kind_at(index1);
jrose@1524 823 int k2 = cp2->method_handle_ref_kind_at(index2);
jrose@1524 824 if (k1 == k2) {
jrose@1524 825 int i1 = method_handle_index_at(index1);
jrose@1524 826 int i2 = cp2->method_handle_index_at(index2);
jrose@1524 827 if (i1 == i2) {
jrose@1524 828 return true;
jrose@1524 829 }
jrose@1524 830 }
jrose@1524 831 } break;
jrose@1524 832
duke@0 833 case JVM_CONSTANT_UnresolvedString:
duke@0 834 {
duke@0 835 symbolOop s1 = unresolved_string_at(index1);
duke@0 836 symbolOop s2 = cp2->unresolved_string_at(index2);
duke@0 837 if (s1 == s2) {
duke@0 838 return true;
duke@0 839 }
duke@0 840 } break;
duke@0 841
duke@0 842 case JVM_CONSTANT_Utf8:
duke@0 843 {
duke@0 844 symbolOop s1 = symbol_at(index1);
duke@0 845 symbolOop s2 = cp2->symbol_at(index2);
duke@0 846 if (s1 == s2) {
duke@0 847 return true;
duke@0 848 }
duke@0 849 } break;
duke@0 850
duke@0 851 // Invalid is used as the tag for the second constant pool entry
duke@0 852 // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
duke@0 853 // not be seen by itself.
duke@0 854 case JVM_CONSTANT_Invalid: // fall through
duke@0 855
duke@0 856 default:
duke@0 857 ShouldNotReachHere();
duke@0 858 break;
duke@0 859 }
duke@0 860
duke@0 861 return false;
duke@0 862 } // end compare_entry_to()
duke@0 863
duke@0 864
duke@0 865 // Copy this constant pool's entries at start_i to end_i (inclusive)
duke@0 866 // to the constant pool to_cp's entries starting at to_i. A total of
duke@0 867 // (end_i - start_i) + 1 entries are copied.
duke@0 868 void constantPoolOopDesc::copy_cp_to(int start_i, int end_i,
duke@0 869 constantPoolHandle to_cp, int to_i, TRAPS) {
duke@0 870
duke@0 871 int dest_i = to_i; // leave original alone for debug purposes
duke@0 872
duke@0 873 for (int src_i = start_i; src_i <= end_i; /* see loop bottom */ ) {
duke@0 874 copy_entry_to(src_i, to_cp, dest_i, CHECK);
duke@0 875
duke@0 876 switch (tag_at(src_i).value()) {
duke@0 877 case JVM_CONSTANT_Double:
duke@0 878 case JVM_CONSTANT_Long:
duke@0 879 // double and long take two constant pool entries
duke@0 880 src_i += 2;
duke@0 881 dest_i += 2;
duke@0 882 break;
duke@0 883
duke@0 884 default:
duke@0 885 // all others take one constant pool entry
duke@0 886 src_i++;
duke@0 887 dest_i++;
duke@0 888 break;
duke@0 889 }
duke@0 890 }
duke@0 891 } // end copy_cp_to()
duke@0 892
duke@0 893
duke@0 894 // Copy this constant pool's entry at from_i to the constant pool
duke@0 895 // to_cp's entry at to_i.
duke@0 896 void constantPoolOopDesc::copy_entry_to(int from_i, constantPoolHandle to_cp,
duke@0 897 int to_i, TRAPS) {
duke@0 898
duke@0 899 switch (tag_at(from_i).value()) {
duke@0 900 case JVM_CONSTANT_Class:
duke@0 901 {
duke@0 902 klassOop k = klass_at(from_i, CHECK);
duke@0 903 to_cp->klass_at_put(to_i, k);
duke@0 904 } break;
duke@0 905
duke@0 906 case JVM_CONSTANT_ClassIndex:
duke@0 907 {
duke@0 908 jint ki = klass_index_at(from_i);
duke@0 909 to_cp->klass_index_at_put(to_i, ki);
duke@0 910 } break;
duke@0 911
duke@0 912 case JVM_CONSTANT_Double:
duke@0 913 {
duke@0 914 jdouble d = double_at(from_i);
duke@0 915 to_cp->double_at_put(to_i, d);
duke@0 916 // double takes two constant pool entries so init second entry's tag
duke@0 917 to_cp->tag_at_put(to_i + 1, JVM_CONSTANT_Invalid);
duke@0 918 } break;
duke@0 919
duke@0 920 case JVM_CONSTANT_Fieldref:
duke@0 921 {
duke@0 922 int class_index = uncached_klass_ref_index_at(from_i);
duke@0 923 int name_and_type_index = uncached_name_and_type_ref_index_at(from_i);
duke@0 924 to_cp->field_at_put(to_i, class_index, name_and_type_index);
duke@0 925 } break;
duke@0 926
duke@0 927 case JVM_CONSTANT_Float:
duke@0 928 {
duke@0 929 jfloat f = float_at(from_i);
duke@0 930 to_cp->float_at_put(to_i, f);
duke@0 931 } break;
duke@0 932
duke@0 933 case JVM_CONSTANT_Integer:
duke@0 934 {
duke@0 935 jint i = int_at(from_i);
duke@0 936 to_cp->int_at_put(to_i, i);
duke@0 937 } break;
duke@0 938
duke@0 939 case JVM_CONSTANT_InterfaceMethodref:
duke@0 940 {
duke@0 941 int class_index = uncached_klass_ref_index_at(from_i);
duke@0 942 int name_and_type_index = uncached_name_and_type_ref_index_at(from_i);
duke@0 943 to_cp->interface_method_at_put(to_i, class_index, name_and_type_index);
duke@0 944 } break;
duke@0 945
duke@0 946 case JVM_CONSTANT_Long:
duke@0 947 {
duke@0 948 jlong l = long_at(from_i);
duke@0 949 to_cp->long_at_put(to_i, l);
duke@0 950 // long takes two constant pool entries so init second entry's tag
duke@0 951 to_cp->tag_at_put(to_i + 1, JVM_CONSTANT_Invalid);
duke@0 952 } break;
duke@0 953
duke@0 954 case JVM_CONSTANT_Methodref:
duke@0 955 {
duke@0 956 int class_index = uncached_klass_ref_index_at(from_i);
duke@0 957 int name_and_type_index = uncached_name_and_type_ref_index_at(from_i);
duke@0 958 to_cp->method_at_put(to_i, class_index, name_and_type_index);
duke@0 959 } break;
duke@0 960
duke@0 961 case JVM_CONSTANT_NameAndType:
duke@0 962 {
duke@0 963 int name_ref_index = name_ref_index_at(from_i);
duke@0 964 int signature_ref_index = signature_ref_index_at(from_i);
duke@0 965 to_cp->name_and_type_at_put(to_i, name_ref_index, signature_ref_index);
duke@0 966 } break;
duke@0 967
duke@0 968 case JVM_CONSTANT_String:
duke@0 969 {
duke@0 970 oop s = string_at(from_i, CHECK);
duke@0 971 to_cp->string_at_put(to_i, s);
duke@0 972 } break;
duke@0 973
duke@0 974 case JVM_CONSTANT_StringIndex:
duke@0 975 {
duke@0 976 jint si = string_index_at(from_i);
duke@0 977 to_cp->string_index_at_put(to_i, si);
duke@0 978 } break;
duke@0 979
duke@0 980 case JVM_CONSTANT_UnresolvedClass:
duke@0 981 {
duke@0 982 symbolOop k = unresolved_klass_at(from_i);
duke@0 983 to_cp->unresolved_klass_at_put(to_i, k);
duke@0 984 } break;
duke@0 985
duke@0 986 case JVM_CONSTANT_UnresolvedClassInError:
duke@0 987 {
duke@0 988 symbolOop k = unresolved_klass_at(from_i);
duke@0 989 to_cp->unresolved_klass_at_put(to_i, k);
duke@0 990 to_cp->tag_at_put(to_i, JVM_CONSTANT_UnresolvedClassInError);
duke@0 991 } break;
duke@0 992
duke@0 993
duke@0 994 case JVM_CONSTANT_UnresolvedString:
duke@0 995 {
duke@0 996 symbolOop s = unresolved_string_at(from_i);
duke@0 997 to_cp->unresolved_string_at_put(to_i, s);
duke@0 998 } break;
duke@0 999
duke@0 1000 case JVM_CONSTANT_Utf8:
duke@0 1001 {
duke@0 1002 symbolOop s = symbol_at(from_i);
duke@0 1003 to_cp->symbol_at_put(to_i, s);
duke@0 1004 } break;
duke@0 1005
jrose@1524 1006 case JVM_CONSTANT_MethodType:
jrose@1524 1007 {
jrose@1524 1008 jint k = method_type_index_at(from_i);
jrose@1524 1009 to_cp->method_type_index_at_put(to_i, k);
jrose@1524 1010 } break;
jrose@1524 1011
jrose@1524 1012 case JVM_CONSTANT_MethodHandle:
jrose@1524 1013 {
jrose@1524 1014 int k1 = method_handle_ref_kind_at(from_i);
jrose@1524 1015 int k2 = method_handle_index_at(from_i);
jrose@1524 1016 to_cp->method_handle_index_at_put(to_i, k1, k2);
jrose@1524 1017 } break;
jrose@1524 1018
duke@0 1019 // Invalid is used as the tag for the second constant pool entry
duke@0 1020 // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
duke@0 1021 // not be seen by itself.
duke@0 1022 case JVM_CONSTANT_Invalid: // fall through
duke@0 1023
duke@0 1024 default:
duke@0 1025 {
duke@0 1026 jbyte bad_value = tag_at(from_i).value(); // leave a breadcrumb
duke@0 1027 ShouldNotReachHere();
duke@0 1028 } break;
duke@0 1029 }
duke@0 1030 } // end copy_entry_to()
duke@0 1031
duke@0 1032
duke@0 1033 // Search constant pool search_cp for an entry that matches this
duke@0 1034 // constant pool's entry at pattern_i. Returns the index of a
duke@0 1035 // matching entry or zero (0) if there is no matching entry.
duke@0 1036 int constantPoolOopDesc::find_matching_entry(int pattern_i,
duke@0 1037 constantPoolHandle search_cp, TRAPS) {
duke@0 1038
duke@0 1039 // index zero (0) is not used
duke@0 1040 for (int i = 1; i < search_cp->length(); i++) {
duke@0 1041 bool found = compare_entry_to(pattern_i, search_cp, i, CHECK_0);
duke@0 1042 if (found) {
duke@0 1043 return i;
duke@0 1044 }
duke@0 1045 }
duke@0 1046
duke@0 1047 return 0; // entry not found; return unused index zero (0)
duke@0 1048 } // end find_matching_entry()
duke@0 1049
duke@0 1050
duke@0 1051 #ifndef PRODUCT
duke@0 1052
duke@0 1053 const char* constantPoolOopDesc::printable_name_at(int which) {
duke@0 1054
duke@0 1055 constantTag tag = tag_at(which);
duke@0 1056
duke@0 1057 if (tag.is_unresolved_string() || tag.is_string()) {
duke@0 1058 return string_at_noresolve(which);
duke@0 1059 } else if (tag.is_klass() || tag.is_unresolved_klass()) {
duke@0 1060 return klass_name_at(which)->as_C_string();
duke@0 1061 } else if (tag.is_symbol()) {
duke@0 1062 return symbol_at(which)->as_C_string();
duke@0 1063 }
duke@0 1064 return "";
duke@0 1065 }
duke@0 1066
duke@0 1067 #endif // PRODUCT
duke@0 1068
duke@0 1069
duke@0 1070 // JVMTI GetConstantPool support
duke@0 1071
duke@0 1072 // For temporary use until code is stable.
duke@0 1073 #define DBG(code)
duke@0 1074
duke@0 1075 static const char* WARN_MSG = "Must not be such entry!";
duke@0 1076
duke@0 1077 static void print_cpool_bytes(jint cnt, u1 *bytes) {
duke@0 1078 jint size = 0;
duke@0 1079 u2 idx1, idx2;
duke@0 1080
duke@0 1081 for (jint idx = 1; idx < cnt; idx++) {
duke@0 1082 jint ent_size = 0;
duke@0 1083 u1 tag = *bytes++;
duke@0 1084 size++; // count tag
duke@0 1085
duke@0 1086 printf("const #%03d, tag: %02d ", idx, tag);
duke@0 1087 switch(tag) {
duke@0 1088 case JVM_CONSTANT_Invalid: {
duke@0 1089 printf("Invalid");
duke@0 1090 break;
duke@0 1091 }
duke@0 1092 case JVM_CONSTANT_Unicode: {
duke@0 1093 printf("Unicode %s", WARN_MSG);
duke@0 1094 break;
duke@0 1095 }
duke@0 1096 case JVM_CONSTANT_Utf8: {
duke@0 1097 u2 len = Bytes::get_Java_u2(bytes);
duke@0 1098 char str[128];
duke@0 1099 if (len > 127) {
duke@0 1100 len = 127;
duke@0 1101 }
duke@0 1102 strncpy(str, (char *) (bytes+2), len);
duke@0 1103 str[len] = '\0';
duke@0 1104 printf("Utf8 \"%s\"", str);
duke@0 1105 ent_size = 2 + len;
duke@0 1106 break;
duke@0 1107 }
duke@0 1108 case JVM_CONSTANT_Integer: {
duke@0 1109 u4 val = Bytes::get_Java_u4(bytes);
duke@0 1110 printf("int %d", *(int *) &val);
duke@0 1111 ent_size = 4;
duke@0 1112 break;
duke@0 1113 }
duke@0 1114 case JVM_CONSTANT_Float: {
duke@0 1115 u4 val = Bytes::get_Java_u4(bytes);
duke@0 1116 printf("float %5.3ff", *(float *) &val);
duke@0 1117 ent_size = 4;
duke@0 1118 break;
duke@0 1119 }
duke@0 1120 case JVM_CONSTANT_Long: {
duke@0 1121 u8 val = Bytes::get_Java_u8(bytes);
xlu@513 1122 printf("long "INT64_FORMAT, *(jlong *) &val);
duke@0 1123 ent_size = 8;
duke@0 1124 idx++; // Long takes two cpool slots
duke@0 1125 break;
duke@0 1126 }
duke@0 1127 case JVM_CONSTANT_Double: {
duke@0 1128 u8 val = Bytes::get_Java_u8(bytes);
duke@0 1129 printf("double %5.3fd", *(jdouble *)&val);
duke@0 1130 ent_size = 8;
duke@0 1131 idx++; // Double takes two cpool slots
duke@0 1132 break;
duke@0 1133 }
duke@0 1134 case JVM_CONSTANT_Class: {
duke@0 1135 idx1 = Bytes::get_Java_u2(bytes);
duke@0 1136 printf("class #%03d", idx1);
duke@0 1137 ent_size = 2;
duke@0 1138 break;
duke@0 1139 }
duke@0 1140 case JVM_CONSTANT_String: {
duke@0 1141 idx1 = Bytes::get_Java_u2(bytes);
duke@0 1142 printf("String #%03d", idx1);
duke@0 1143 ent_size = 2;
duke@0 1144 break;
duke@0 1145 }
duke@0 1146 case JVM_CONSTANT_Fieldref: {
duke@0 1147 idx1 = Bytes::get_Java_u2(bytes);
duke@0 1148 idx2 = Bytes::get_Java_u2(bytes+2);
duke@0 1149 printf("Field #%03d, #%03d", (int) idx1, (int) idx2);
duke@0 1150 ent_size = 4;
duke@0 1151 break;
duke@0 1152 }
duke@0 1153 case JVM_CONSTANT_Methodref: {
duke@0 1154 idx1 = Bytes::get_Java_u2(bytes);
duke@0 1155 idx2 = Bytes::get_Java_u2(bytes+2);
duke@0 1156 printf("Method #%03d, #%03d", idx1, idx2);
duke@0 1157 ent_size = 4;
duke@0 1158 break;
duke@0 1159 }
duke@0 1160 case JVM_CONSTANT_InterfaceMethodref: {
duke@0 1161 idx1 = Bytes::get_Java_u2(bytes);
duke@0 1162 idx2 = Bytes::get_Java_u2(bytes+2);
duke@0 1163 printf("InterfMethod #%03d, #%03d", idx1, idx2);
duke@0 1164 ent_size = 4;
duke@0 1165 break;
duke@0 1166 }
duke@0 1167 case JVM_CONSTANT_NameAndType: {
duke@0 1168 idx1 = Bytes::get_Java_u2(bytes);
duke@0 1169 idx2 = Bytes::get_Java_u2(bytes+2);
duke@0 1170 printf("NameAndType #%03d, #%03d", idx1, idx2);
duke@0 1171 ent_size = 4;
duke@0 1172 break;
duke@0 1173 }
duke@0 1174 case JVM_CONSTANT_ClassIndex: {
duke@0 1175 printf("ClassIndex %s", WARN_MSG);
duke@0 1176 break;
duke@0 1177 }
duke@0 1178 case JVM_CONSTANT_UnresolvedClass: {
duke@0 1179 printf("UnresolvedClass: %s", WARN_MSG);
duke@0 1180 break;
duke@0 1181 }
duke@0 1182 case JVM_CONSTANT_UnresolvedClassInError: {
duke@0 1183 printf("UnresolvedClassInErr: %s", WARN_MSG);
duke@0 1184 break;
duke@0 1185 }
duke@0 1186 case JVM_CONSTANT_StringIndex: {
duke@0 1187 printf("StringIndex: %s", WARN_MSG);
duke@0 1188 break;
duke@0 1189 }
duke@0 1190 case JVM_CONSTANT_UnresolvedString: {
duke@0 1191 printf("UnresolvedString: %s", WARN_MSG);
duke@0 1192 break;
duke@0 1193 }
duke@0 1194 }
duke@0 1195 printf(";\n");
duke@0 1196 bytes += ent_size;
duke@0 1197 size += ent_size;
duke@0 1198 }
duke@0 1199 printf("Cpool size: %d\n", size);
duke@0 1200 fflush(0);
duke@0 1201 return;
duke@0 1202 } /* end print_cpool_bytes */
duke@0 1203
duke@0 1204
duke@0 1205 // Returns size of constant pool entry.
duke@0 1206 jint constantPoolOopDesc::cpool_entry_size(jint idx) {
duke@0 1207 switch(tag_at(idx).value()) {
duke@0 1208 case JVM_CONSTANT_Invalid:
duke@0 1209 case JVM_CONSTANT_Unicode:
duke@0 1210 return 1;
duke@0 1211
duke@0 1212 case JVM_CONSTANT_Utf8:
duke@0 1213 return 3 + symbol_at(idx)->utf8_length();
duke@0 1214
duke@0 1215 case JVM_CONSTANT_Class:
duke@0 1216 case JVM_CONSTANT_String:
duke@0 1217 case JVM_CONSTANT_ClassIndex:
duke@0 1218 case JVM_CONSTANT_UnresolvedClass:
duke@0 1219 case JVM_CONSTANT_UnresolvedClassInError:
duke@0 1220 case JVM_CONSTANT_StringIndex:
duke@0 1221 case JVM_CONSTANT_UnresolvedString:
jrose@1524 1222 case JVM_CONSTANT_MethodType:
duke@0 1223 return 3;
duke@0 1224
jrose@1524 1225 case JVM_CONSTANT_MethodHandle:
jrose@1524 1226 return 4; //tag, ref_kind, ref_index
jrose@1524 1227
duke@0 1228 case JVM_CONSTANT_Integer:
duke@0 1229 case JVM_CONSTANT_Float:
duke@0 1230 case JVM_CONSTANT_Fieldref:
duke@0 1231 case JVM_CONSTANT_Methodref:
duke@0 1232 case JVM_CONSTANT_InterfaceMethodref:
duke@0 1233 case JVM_CONSTANT_NameAndType:
duke@0 1234 return 5;
duke@0 1235
duke@0 1236 case JVM_CONSTANT_Long:
duke@0 1237 case JVM_CONSTANT_Double:
duke@0 1238 return 9;
duke@0 1239 }
duke@0 1240 assert(false, "cpool_entry_size: Invalid constant pool entry tag");
duke@0 1241 return 1;
duke@0 1242 } /* end cpool_entry_size */
duke@0 1243
duke@0 1244
duke@0 1245 // SymbolHashMap is used to find a constant pool index from a string.
duke@0 1246 // This function fills in SymbolHashMaps, one for utf8s and one for
duke@0 1247 // class names, returns size of the cpool raw bytes.
duke@0 1248 jint constantPoolOopDesc::hash_entries_to(SymbolHashMap *symmap,
duke@0 1249 SymbolHashMap *classmap) {
duke@0 1250 jint size = 0;
duke@0 1251
duke@0 1252 for (u2 idx = 1; idx < length(); idx++) {
duke@0 1253 u2 tag = tag_at(idx).value();
duke@0 1254 size += cpool_entry_size(idx);
duke@0 1255
duke@0 1256 switch(tag) {
duke@0 1257 case JVM_CONSTANT_Utf8: {
duke@0 1258 symbolOop sym = symbol_at(idx);
duke@0 1259 symmap->add_entry(sym, idx);
duke@0 1260 DBG(printf("adding symbol entry %s = %d\n", sym->as_utf8(), idx));
duke@0 1261 break;
duke@0 1262 }
duke@0 1263 case JVM_CONSTANT_Class:
duke@0 1264 case JVM_CONSTANT_UnresolvedClass:
duke@0 1265 case JVM_CONSTANT_UnresolvedClassInError: {
duke@0 1266 symbolOop sym = klass_name_at(idx);
duke@0 1267 classmap->add_entry(sym, idx);
duke@0 1268 DBG(printf("adding class entry %s = %d\n", sym->as_utf8(), idx));
duke@0 1269 break;
duke@0 1270 }
duke@0 1271 case JVM_CONSTANT_Long:
duke@0 1272 case JVM_CONSTANT_Double: {
duke@0 1273 idx++; // Both Long and Double take two cpool slots
duke@0 1274 break;
duke@0 1275 }
duke@0 1276 }
duke@0 1277 }
duke@0 1278 return size;
duke@0 1279 } /* end hash_utf8_entries_to */
duke@0 1280
duke@0 1281
duke@0 1282 // Copy cpool bytes.
duke@0 1283 // Returns:
duke@0 1284 // 0, in case of OutOfMemoryError
duke@0 1285 // -1, in case of internal error
duke@0 1286 // > 0, count of the raw cpool bytes that have been copied
duke@0 1287 int constantPoolOopDesc::copy_cpool_bytes(int cpool_size,
duke@0 1288 SymbolHashMap* tbl,
duke@0 1289 unsigned char *bytes) {
duke@0 1290 u2 idx1, idx2;
duke@0 1291 jint size = 0;
duke@0 1292 jint cnt = length();
duke@0 1293 unsigned char *start_bytes = bytes;
duke@0 1294
duke@0 1295 for (jint idx = 1; idx < cnt; idx++) {
duke@0 1296 u1 tag = tag_at(idx).value();
duke@0 1297 jint ent_size = cpool_entry_size(idx);
duke@0 1298
duke@0 1299 assert(size + ent_size <= cpool_size, "Size mismatch");
duke@0 1300
duke@0 1301 *bytes = tag;
duke@0 1302 DBG(printf("#%03hd tag=%03hd, ", idx, tag));
duke@0 1303 switch(tag) {
duke@0 1304 case JVM_CONSTANT_Invalid: {
duke@0 1305 DBG(printf("JVM_CONSTANT_Invalid"));
duke@0 1306 break;
duke@0 1307 }
duke@0 1308 case JVM_CONSTANT_Unicode: {
duke@0 1309 assert(false, "Wrong constant pool tag: JVM_CONSTANT_Unicode");
duke@0 1310 DBG(printf("JVM_CONSTANT_Unicode"));
duke@0 1311 break;
duke@0 1312 }
duke@0 1313 case JVM_CONSTANT_Utf8: {
duke@0 1314 symbolOop sym = symbol_at(idx);
duke@0 1315 char* str = sym->as_utf8();
duke@0 1316 // Warning! It's crashing on x86 with len = sym->utf8_length()
duke@0 1317 int len = (int) strlen(str);
duke@0 1318 Bytes::put_Java_u2((address) (bytes+1), (u2) len);
duke@0 1319 for (int i = 0; i < len; i++) {
duke@0 1320 bytes[3+i] = (u1) str[i];
duke@0 1321 }
duke@0 1322 DBG(printf("JVM_CONSTANT_Utf8: %s ", str));
duke@0 1323 break;
duke@0 1324 }
duke@0 1325 case JVM_CONSTANT_Integer: {
duke@0 1326 jint val = int_at(idx);
duke@0 1327 Bytes::put_Java_u4((address) (bytes+1), *(u4*)&val);
duke@0 1328 break;
duke@0 1329 }
duke@0 1330 case JVM_CONSTANT_Float: {
duke@0 1331 jfloat val = float_at(idx);
duke@0 1332 Bytes::put_Java_u4((address) (bytes+1), *(u4*)&val);
duke@0 1333 break;
duke@0 1334 }
duke@0 1335 case JVM_CONSTANT_Long: {
duke@0 1336 jlong val = long_at(idx);
duke@0 1337 Bytes::put_Java_u8((address) (bytes+1), *(u8*)&val);
duke@0 1338 idx++; // Long takes two cpool slots
duke@0 1339 break;
duke@0 1340 }
duke@0 1341 case JVM_CONSTANT_Double: {
duke@0 1342 jdouble val = double_at(idx);
duke@0 1343 Bytes::put_Java_u8((address) (bytes+1), *(u8*)&val);
duke@0 1344 idx++; // Double takes two cpool slots
duke@0 1345 break;
duke@0 1346 }
duke@0 1347 case JVM_CONSTANT_Class:
duke@0 1348 case JVM_CONSTANT_UnresolvedClass:
duke@0 1349 case JVM_CONSTANT_UnresolvedClassInError: {
duke@0 1350 *bytes = JVM_CONSTANT_Class;
duke@0 1351 symbolOop sym = klass_name_at(idx);
duke@0 1352 idx1 = tbl->symbol_to_value(sym);
duke@0 1353 assert(idx1 != 0, "Have not found a hashtable entry");
duke@0 1354 Bytes::put_Java_u2((address) (bytes+1), idx1);
duke@0 1355 DBG(printf("JVM_CONSTANT_Class: idx=#%03hd, %s", idx1, sym->as_utf8()));
duke@0 1356 break;
duke@0 1357 }
duke@0 1358 case JVM_CONSTANT_String: {
duke@0 1359 unsigned int hash;
duke@0 1360 char *str = string_at_noresolve(idx);
duke@0 1361 symbolOop sym = SymbolTable::lookup_only(str, (int) strlen(str), hash);
thurka@773 1362 if (sym == NULL) {
thurka@773 1363 // sym can be NULL if string refers to incorrectly encoded JVM_CONSTANT_Utf8
thurka@773 1364 // this can happen with JVM TI; see CR 6839599 for more details
thurka@773 1365 oop string = *(obj_at_addr(idx));
thurka@773 1366 assert(java_lang_String::is_instance(string),"Not a String");
thurka@773 1367 DBG(printf("Error #%03hd tag=%03hd\n", idx, tag));
thurka@773 1368 idx1 = 0;
thurka@773 1369 for (int j = 0; j < tbl->table_size() && idx1 == 0; j++) {
thurka@773 1370 for (SymbolHashMapEntry* cur = tbl->bucket(j); cur != NULL; cur = cur->next()) {
thurka@773 1371 int length;
thurka@773 1372 sym = cur->symbol();
thurka@773 1373 jchar* chars = sym->as_unicode(length);
thurka@773 1374 if (java_lang_String::equals(string, chars, length)) {
thurka@773 1375 idx1 = cur->value();
thurka@773 1376 DBG(printf("Index found: %d\n",idx1));
thurka@773 1377 break;
thurka@773 1378 }
thurka@773 1379 }
thurka@773 1380 }
thurka@773 1381 } else {
thurka@773 1382 idx1 = tbl->symbol_to_value(sym);
thurka@773 1383 }
duke@0 1384 assert(idx1 != 0, "Have not found a hashtable entry");
duke@0 1385 Bytes::put_Java_u2((address) (bytes+1), idx1);
duke@0 1386 DBG(printf("JVM_CONSTANT_String: idx=#%03hd, %s", idx1, str));
duke@0 1387 break;
duke@0 1388 }
duke@0 1389 case JVM_CONSTANT_UnresolvedString: {
duke@0 1390 *bytes = JVM_CONSTANT_String;
duke@0 1391 symbolOop sym = unresolved_string_at(idx);
duke@0 1392 idx1 = tbl->symbol_to_value(sym);
duke@0 1393 assert(idx1 != 0, "Have not found a hashtable entry");
duke@0 1394 Bytes::put_Java_u2((address) (bytes+1), idx1);
duke@0 1395 DBG(char *str = sym->as_utf8());
duke@0 1396 DBG(printf("JVM_CONSTANT_UnresolvedString: idx=#%03hd, %s", idx1, str));
duke@0 1397 break;
duke@0 1398 }
duke@0 1399 case JVM_CONSTANT_Fieldref:
duke@0 1400 case JVM_CONSTANT_Methodref:
duke@0 1401 case JVM_CONSTANT_InterfaceMethodref: {
duke@0 1402 idx1 = uncached_klass_ref_index_at(idx);
duke@0 1403 idx2 = uncached_name_and_type_ref_index_at(idx);
duke@0 1404 Bytes::put_Java_u2((address) (bytes+1), idx1);
duke@0 1405 Bytes::put_Java_u2((address) (bytes+3), idx2);
duke@0 1406 DBG(printf("JVM_CONSTANT_Methodref: %hd %hd", idx1, idx2));
duke@0 1407 break;
duke@0 1408 }
duke@0 1409 case JVM_CONSTANT_NameAndType: {
duke@0 1410 idx1 = name_ref_index_at(idx);
duke@0 1411 idx2 = signature_ref_index_at(idx);
duke@0 1412 Bytes::put_Java_u2((address) (bytes+1), idx1);
duke@0 1413 Bytes::put_Java_u2((address) (bytes+3), idx2);
duke@0 1414 DBG(printf("JVM_CONSTANT_NameAndType: %hd %hd", idx1, idx2));
duke@0 1415 break;
duke@0 1416 }
duke@0 1417 case JVM_CONSTANT_ClassIndex: {
duke@0 1418 *bytes = JVM_CONSTANT_Class;
duke@0 1419 idx1 = klass_index_at(idx);
duke@0 1420 Bytes::put_Java_u2((address) (bytes+1), idx1);
duke@0 1421 DBG(printf("JVM_CONSTANT_ClassIndex: %hd", idx1));
duke@0 1422 break;
duke@0 1423 }
duke@0 1424 case JVM_CONSTANT_StringIndex: {
duke@0 1425 *bytes = JVM_CONSTANT_String;
duke@0 1426 idx1 = string_index_at(idx);
duke@0 1427 Bytes::put_Java_u2((address) (bytes+1), idx1);
duke@0 1428 DBG(printf("JVM_CONSTANT_StringIndex: %hd", idx1));
duke@0 1429 break;
duke@0 1430 }
jrose@1524 1431 case JVM_CONSTANT_MethodHandle: {
jrose@1524 1432 *bytes = JVM_CONSTANT_MethodHandle;
jrose@1524 1433 int kind = method_handle_ref_kind_at(idx);
jrose@1524 1434 idx1 = method_handle_index_at(idx);
jrose@1524 1435 *(bytes+1) = (unsigned char) kind;
jrose@1524 1436 Bytes::put_Java_u2((address) (bytes+2), idx1);
jrose@1524 1437 DBG(printf("JVM_CONSTANT_MethodHandle: %d %hd", kind, idx1));
jrose@1524 1438 break;
jrose@1524 1439 }
jrose@1524 1440 case JVM_CONSTANT_MethodType: {
jrose@1524 1441 *bytes = JVM_CONSTANT_MethodType;
jrose@1524 1442 idx1 = method_type_index_at(idx);
jrose@1524 1443 Bytes::put_Java_u2((address) (bytes+1), idx1);
jrose@1524 1444 DBG(printf("JVM_CONSTANT_MethodType: %hd", idx1));
jrose@1524 1445 break;
jrose@1524 1446 }
duke@0 1447 }
duke@0 1448 DBG(printf("\n"));
duke@0 1449 bytes += ent_size;
duke@0 1450 size += ent_size;
duke@0 1451 }
duke@0 1452 assert(size == cpool_size, "Size mismatch");
duke@0 1453
duke@0 1454 // Keep temorarily for debugging until it's stable.
duke@0 1455 DBG(print_cpool_bytes(cnt, start_bytes));
duke@0 1456 return (int)(bytes - start_bytes);
duke@0 1457 } /* end copy_cpool_bytes */
duke@0 1458
duke@0 1459
duke@0 1460 void SymbolHashMap::add_entry(symbolOop sym, u2 value) {
duke@0 1461 char *str = sym->as_utf8();
duke@0 1462 unsigned int hash = compute_hash(str, sym->utf8_length());
duke@0 1463 unsigned int index = hash % table_size();
duke@0 1464
duke@0 1465 // check if already in map
duke@0 1466 // we prefer the first entry since it is more likely to be what was used in
duke@0 1467 // the class file
duke@0 1468 for (SymbolHashMapEntry *en = bucket(index); en != NULL; en = en->next()) {
duke@0 1469 assert(en->symbol() != NULL, "SymbolHashMapEntry symbol is NULL");
duke@0 1470 if (en->hash() == hash && en->symbol() == sym) {
duke@0 1471 return; // already there
duke@0 1472 }
duke@0 1473 }
duke@0 1474
duke@0 1475 SymbolHashMapEntry* entry = new SymbolHashMapEntry(hash, sym, value);
duke@0 1476 entry->set_next(bucket(index));
duke@0 1477 _buckets[index].set_entry(entry);
duke@0 1478 assert(entry->symbol() != NULL, "SymbolHashMapEntry symbol is NULL");
duke@0 1479 }
duke@0 1480
duke@0 1481 SymbolHashMapEntry* SymbolHashMap::find_entry(symbolOop sym) {
duke@0 1482 assert(sym != NULL, "SymbolHashMap::find_entry - symbol is NULL");
duke@0 1483 char *str = sym->as_utf8();
duke@0 1484 int len = sym->utf8_length();
duke@0 1485 unsigned int hash = SymbolHashMap::compute_hash(str, len);
duke@0 1486 unsigned int index = hash % table_size();
duke@0 1487 for (SymbolHashMapEntry *en = bucket(index); en != NULL; en = en->next()) {
duke@0 1488 assert(en->symbol() != NULL, "SymbolHashMapEntry symbol is NULL");
duke@0 1489 if (en->hash() == hash && en->symbol() == sym) {
duke@0 1490 return en;
duke@0 1491 }
duke@0 1492 }
duke@0 1493 return NULL;
duke@0 1494 }