annotate src/share/vm/oops/constantPoolOop.cpp @ 1583:083fde3b838e

6964498: JSR 292 invokedynamic sites need local bootstrap methods Summary: Add JVM_CONSTANT_InvokeDynamic records to constant pool to determine per-instruction BSMs. Reviewed-by: twisti
author jrose
date Thu, 15 Jul 2010 18:40:45 -0700
parents 136b78722a08
children d257356e35f0
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@1583 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@1583 270 int pool_index = cache()->main_entry_at(which)->constant_pool_index();
jrose@1583 271 if (tag_at(pool_index).is_invoke_dynamic())
jrose@1583 272 pool_index = invoke_dynamic_name_and_type_ref_index_at(pool_index);
jrose@1583 273 assert(tag_at(pool_index).is_name_and_type(), "");
jrose@1583 274 return pool_index;
jrose@1583 275 }
jrose@1059 276 // change byte-ordering and go via cache
jrose@1059 277 i = remap_instruction_operand_from_cache(which);
jrose@1059 278 } else {
jrose@1059 279 if (tag_at(which).is_name_and_type())
jrose@1059 280 // invokedynamic index is a simple name-and-type
jrose@1059 281 return which;
jrose@1059 282 }
jrose@1059 283 assert(tag_at(i).is_field_or_method(), "Corrupted constant pool");
jrose@1059 284 jint ref_index = *int_at_addr(i);
duke@0 285 return extract_high_short_from_int(ref_index);
duke@0 286 }
duke@0 287
duke@0 288
jrose@726 289 int constantPoolOopDesc::impl_klass_ref_index_at(int which, bool uncached) {
jrose@1059 290 guarantee(!constantPoolCacheOopDesc::is_secondary_index(which),
jrose@1059 291 "an invokedynamic instruction does not have a klass");
jrose@1059 292 int i = which;
jrose@1059 293 if (!uncached && cache() != NULL) {
jrose@1059 294 // change byte-ordering and go via cache
jrose@1059 295 i = remap_instruction_operand_from_cache(which);
jrose@1059 296 }
jrose@1059 297 assert(tag_at(i).is_field_or_method(), "Corrupted constant pool");
jrose@1059 298 jint ref_index = *int_at_addr(i);
duke@0 299 return extract_low_short_from_int(ref_index);
duke@0 300 }
duke@0 301
duke@0 302
jrose@726 303
jrose@1059 304 int constantPoolOopDesc::remap_instruction_operand_from_cache(int operand) {
jrose@1486 305 int cpc_index = operand;
jrose@1486 306 DEBUG_ONLY(cpc_index -= CPCACHE_INDEX_TAG);
jrose@1486 307 assert((int)(u2)cpc_index == cpc_index, "clean u2");
jrose@1059 308 int member_index = cache()->entry_at(cpc_index)->constant_pool_index();
jrose@1059 309 return member_index;
jrose@726 310 }
jrose@726 311
jrose@726 312
duke@0 313 void constantPoolOopDesc::verify_constant_pool_resolve(constantPoolHandle this_oop, KlassHandle k, TRAPS) {
duke@0 314 if (k->oop_is_instance() || k->oop_is_objArray()) {
duke@0 315 instanceKlassHandle holder (THREAD, this_oop->pool_holder());
duke@0 316 klassOop elem_oop = k->oop_is_instance() ? k() : objArrayKlass::cast(k())->bottom_klass();
duke@0 317 KlassHandle element (THREAD, elem_oop);
duke@0 318
duke@0 319 // The element type could be a typeArray - we only need the access check if it is
duke@0 320 // an reference to another class
duke@0 321 if (element->oop_is_instance()) {
duke@0 322 LinkResolver::check_klass_accessability(holder, element, CHECK);
duke@0 323 }
duke@0 324 }
duke@0 325 }
duke@0 326
duke@0 327
jrose@726 328 int constantPoolOopDesc::name_ref_index_at(int which_nt) {
jrose@726 329 jint ref_index = name_and_type_at(which_nt);
duke@0 330 return extract_low_short_from_int(ref_index);
duke@0 331 }
duke@0 332
duke@0 333
jrose@726 334 int constantPoolOopDesc::signature_ref_index_at(int which_nt) {
jrose@726 335 jint ref_index = name_and_type_at(which_nt);
duke@0 336 return extract_high_short_from_int(ref_index);
duke@0 337 }
duke@0 338
duke@0 339
duke@0 340 klassOop constantPoolOopDesc::klass_ref_at(int which, TRAPS) {
duke@0 341 return klass_at(klass_ref_index_at(which), CHECK_NULL);
duke@0 342 }
duke@0 343
duke@0 344
duke@0 345 symbolOop constantPoolOopDesc::klass_name_at(int which) {
duke@0 346 assert(tag_at(which).is_unresolved_klass() || tag_at(which).is_klass(),
duke@0 347 "Corrupted constant pool");
duke@0 348 // A resolved constantPool entry will contain a klassOop, otherwise a symbolOop.
duke@0 349 // 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 350 // tag is not updated atomicly.
duke@0 351 oop entry = *(obj_at_addr(which));
duke@0 352 if (entry->is_klass()) {
duke@0 353 // Already resolved - return entry's name.
duke@0 354 return klassOop(entry)->klass_part()->name();
duke@0 355 } else {
duke@0 356 assert(entry->is_symbol(), "must be either symbol or klass");
duke@0 357 return (symbolOop)entry;
duke@0 358 }
duke@0 359 }
duke@0 360
duke@0 361 symbolOop constantPoolOopDesc::klass_ref_at_noresolve(int which) {
duke@0 362 jint ref_index = klass_ref_index_at(which);
duke@0 363 return klass_at_noresolve(ref_index);
duke@0 364 }
duke@0 365
jrose@1524 366 symbolOop constantPoolOopDesc::uncached_klass_ref_at_noresolve(int which) {
jrose@1524 367 jint ref_index = uncached_klass_ref_index_at(which);
jrose@1524 368 return klass_at_noresolve(ref_index);
jrose@1524 369 }
jrose@1524 370
duke@0 371 char* constantPoolOopDesc::string_at_noresolve(int which) {
duke@0 372 // Test entry type in case string is resolved while in here.
duke@0 373 oop entry = *(obj_at_addr(which));
duke@0 374 if (entry->is_symbol()) {
duke@0 375 return ((symbolOop)entry)->as_C_string();
jrose@431 376 } else if (java_lang_String::is_instance(entry)) {
jrose@431 377 return java_lang_String::as_utf8_string(entry);
duke@0 378 } else {
jrose@431 379 return (char*)"<pseudo-string>";
duke@0 380 }
duke@0 381 }
duke@0 382
duke@0 383
duke@0 384 BasicType constantPoolOopDesc::basic_type_for_signature_at(int which) {
duke@0 385 return FieldType::basic_type(symbol_at(which));
duke@0 386 }
duke@0 387
duke@0 388
duke@0 389 void constantPoolOopDesc::resolve_string_constants_impl(constantPoolHandle this_oop, TRAPS) {
duke@0 390 for (int index = 1; index < this_oop->length(); index++) { // Index 0 is unused
duke@0 391 if (this_oop->tag_at(index).is_unresolved_string()) {
duke@0 392 this_oop->string_at(index, CHECK);
duke@0 393 }
duke@0 394 }
duke@0 395 }
duke@0 396
jrose@1524 397 oop constantPoolOopDesc::resolve_constant_at_impl(constantPoolHandle this_oop, int index, int cache_index, TRAPS) {
jrose@1524 398 oop result_oop = NULL;
jrose@1524 399 if (cache_index >= 0) {
jrose@1524 400 assert(index < 0, "only one kind of index at a time");
jrose@1524 401 ConstantPoolCacheEntry* cpc_entry = this_oop->cache()->entry_at(cache_index);
jrose@1524 402 result_oop = cpc_entry->f1();
jrose@1524 403 if (result_oop != NULL) {
jrose@1524 404 return result_oop; // that was easy...
jrose@1524 405 }
jrose@1524 406 index = cpc_entry->constant_pool_index();
jrose@1524 407 }
jrose@1524 408
jrose@1524 409 int tag_value = this_oop->tag_at(index).value();
jrose@1524 410 switch (tag_value) {
jrose@1524 411
jrose@1524 412 case JVM_CONSTANT_UnresolvedClass:
jrose@1524 413 case JVM_CONSTANT_UnresolvedClassInError:
jrose@1524 414 case JVM_CONSTANT_Class:
jrose@1524 415 {
jrose@1524 416 klassOop resolved = klass_at_impl(this_oop, index, CHECK_NULL);
jrose@1524 417 // ldc wants the java mirror.
jrose@1524 418 result_oop = resolved->klass_part()->java_mirror();
jrose@1524 419 break;
jrose@1524 420 }
jrose@1524 421
jrose@1524 422 case JVM_CONSTANT_String:
jrose@1524 423 case JVM_CONSTANT_UnresolvedString:
jrose@1524 424 if (this_oop->is_pseudo_string_at(index)) {
jrose@1524 425 result_oop = this_oop->pseudo_string_at(index);
jrose@1524 426 break;
jrose@1524 427 }
jrose@1524 428 result_oop = string_at_impl(this_oop, index, CHECK_NULL);
jrose@1524 429 break;
jrose@1524 430
jrose@1524 431 case JVM_CONSTANT_Object:
jrose@1524 432 result_oop = this_oop->object_at(index);
jrose@1524 433 break;
jrose@1524 434
jrose@1524 435 case JVM_CONSTANT_MethodHandle:
jrose@1524 436 {
jrose@1524 437 int ref_kind = this_oop->method_handle_ref_kind_at(index);
jrose@1524 438 int callee_index = this_oop->method_handle_klass_index_at(index);
jrose@1524 439 symbolHandle name(THREAD, this_oop->method_handle_name_ref_at(index));
jrose@1524 440 symbolHandle signature(THREAD, this_oop->method_handle_signature_ref_at(index));
jrose@1524 441 if (PrintMiscellaneous)
jrose@1524 442 tty->print_cr("resolve JVM_CONSTANT_MethodHandle:%d [%d/%d/%d] %s.%s",
jrose@1524 443 ref_kind, index, this_oop->method_handle_index_at(index),
jrose@1524 444 callee_index, name->as_C_string(), signature->as_C_string());
jrose@1524 445 KlassHandle callee;
jrose@1524 446 { klassOop k = klass_at_impl(this_oop, callee_index, CHECK_NULL);
jrose@1524 447 callee = KlassHandle(THREAD, k);
jrose@1524 448 }
jrose@1524 449 KlassHandle klass(THREAD, this_oop->pool_holder());
jrose@1524 450 Handle value = SystemDictionary::link_method_handle_constant(klass, ref_kind,
jrose@1524 451 callee, name, signature,
jrose@1524 452 CHECK_NULL);
jrose@1524 453 result_oop = value();
jrose@1524 454 // FIXME: Uniquify errors, using SystemDictionary::find_resolution_error.
jrose@1524 455 break;
jrose@1524 456 }
jrose@1524 457
jrose@1524 458 case JVM_CONSTANT_MethodType:
jrose@1524 459 {
jrose@1524 460 symbolHandle signature(THREAD, this_oop->method_type_signature_at(index));
jrose@1524 461 if (PrintMiscellaneous)
jrose@1524 462 tty->print_cr("resolve JVM_CONSTANT_MethodType [%d/%d] %s",
jrose@1524 463 index, this_oop->method_type_index_at(index),
jrose@1524 464 signature->as_C_string());
jrose@1524 465 KlassHandle klass(THREAD, this_oop->pool_holder());
jrose@1524 466 bool ignore_is_on_bcp = false;
jrose@1524 467 Handle value = SystemDictionary::find_method_handle_type(signature,
jrose@1524 468 klass,
jrose@1524 469 ignore_is_on_bcp,
jrose@1524 470 CHECK_NULL);
jrose@1524 471 result_oop = value();
jrose@1524 472 // FIXME: Uniquify errors, using SystemDictionary::find_resolution_error.
jrose@1524 473 break;
jrose@1524 474 }
jrose@1524 475
jrose@1524 476 /* maybe some day
jrose@1524 477 case JVM_CONSTANT_Integer:
jrose@1524 478 case JVM_CONSTANT_Float:
jrose@1524 479 case JVM_CONSTANT_Long:
jrose@1524 480 case JVM_CONSTANT_Double:
jrose@1524 481 result_oop = java_lang_boxing_object::create(...);
jrose@1524 482 break;
jrose@1524 483 */
jrose@1524 484
jrose@1524 485 default:
jrose@1524 486 DEBUG_ONLY( tty->print_cr("*** %p: tag at CP[%d/%d] = %d",
jrose@1524 487 this_oop(), index, cache_index, tag_value) );
jrose@1524 488 assert(false, "unexpected constant tag");
jrose@1524 489 break;
jrose@1524 490 }
jrose@1524 491
jrose@1524 492 if (cache_index >= 0) {
jrose@1524 493 // Cache the oop here also.
jrose@1524 494 Handle result(THREAD, result_oop);
jrose@1524 495 result_oop = NULL; // safety
jrose@1524 496 ObjectLocker ol(this_oop, THREAD);
jrose@1524 497 ConstantPoolCacheEntry* cpc_entry = this_oop->cache()->entry_at(cache_index);
jrose@1524 498 oop result_oop2 = cpc_entry->f1();
jrose@1524 499 if (result_oop2 != NULL) {
jrose@1524 500 // Race condition: May already be filled in while we were trying to lock.
jrose@1524 501 return result_oop2;
jrose@1524 502 }
jrose@1524 503 cpc_entry->set_f1(result());
jrose@1524 504 return result();
jrose@1524 505 } else {
jrose@1524 506 return result_oop;
jrose@1524 507 }
jrose@1524 508 }
jrose@1524 509
duke@0 510 oop constantPoolOopDesc::string_at_impl(constantPoolHandle this_oop, int which, TRAPS) {
duke@0 511 oop entry = *(this_oop->obj_at_addr(which));
duke@0 512 if (entry->is_symbol()) {
duke@0 513 ObjectLocker ol(this_oop, THREAD);
duke@0 514 if (this_oop->tag_at(which).is_unresolved_string()) {
duke@0 515 // Intern string
duke@0 516 symbolOop sym = this_oop->unresolved_string_at(which);
duke@0 517 entry = StringTable::intern(sym, CHECK_(constantPoolOop(NULL)));
duke@0 518 this_oop->string_at_put(which, entry);
duke@0 519 } else {
duke@0 520 // Another thread beat us and interned string, read string from constant pool
duke@0 521 entry = this_oop->resolved_string_at(which);
duke@0 522 }
duke@0 523 }
duke@0 524 assert(java_lang_String::is_instance(entry), "must be string");
duke@0 525 return entry;
duke@0 526 }
duke@0 527
duke@0 528
jrose@431 529 bool constantPoolOopDesc::is_pseudo_string_at(int which) {
jrose@431 530 oop entry = *(obj_at_addr(which));
jrose@431 531 if (entry->is_symbol())
jrose@431 532 // Not yet resolved, but it will resolve to a string.
jrose@431 533 return false;
jrose@431 534 else if (java_lang_String::is_instance(entry))
jrose@431 535 return false; // actually, it might be a non-interned or non-perm string
jrose@431 536 else
jrose@431 537 // truly pseudo
jrose@431 538 return true;
jrose@431 539 }
jrose@431 540
jrose@431 541
duke@0 542 bool constantPoolOopDesc::klass_name_at_matches(instanceKlassHandle k,
duke@0 543 int which) {
duke@0 544 // Names are interned, so we can compare symbolOops directly
duke@0 545 symbolOop cp_name = klass_name_at(which);
duke@0 546 return (cp_name == k->name());
duke@0 547 }
duke@0 548
duke@0 549
duke@0 550 int constantPoolOopDesc::pre_resolve_shared_klasses(TRAPS) {
duke@0 551 ResourceMark rm;
duke@0 552 int count = 0;
duke@0 553 for (int index = 1; index < tags()->length(); index++) { // Index 0 is unused
duke@0 554 if (tag_at(index).is_unresolved_string()) {
duke@0 555 // Intern string
duke@0 556 symbolOop sym = unresolved_string_at(index);
duke@0 557 oop entry = StringTable::intern(sym, CHECK_(-1));
duke@0 558 string_at_put(index, entry);
duke@0 559 }
duke@0 560 }
duke@0 561 return count;
duke@0 562 }
duke@0 563
duke@0 564
duke@0 565 // Iterate over symbols which are used as class, field, method names and
duke@0 566 // signatures (in preparation for writing to the shared archive).
duke@0 567
duke@0 568 void constantPoolOopDesc::shared_symbols_iterate(OopClosure* closure) {
duke@0 569 for (int index = 1; index < length(); index++) { // Index 0 is unused
duke@0 570 switch (tag_at(index).value()) {
duke@0 571
duke@0 572 case JVM_CONSTANT_UnresolvedClass:
duke@0 573 closure->do_oop(obj_at_addr(index));
duke@0 574 break;
duke@0 575
duke@0 576 case JVM_CONSTANT_NameAndType:
duke@0 577 {
duke@0 578 int i = *int_at_addr(index);
duke@0 579 closure->do_oop(obj_at_addr((unsigned)i >> 16));
duke@0 580 closure->do_oop(obj_at_addr((unsigned)i & 0xffff));
duke@0 581 }
duke@0 582 break;
duke@0 583
duke@0 584 case JVM_CONSTANT_Class:
duke@0 585 case JVM_CONSTANT_InterfaceMethodref:
duke@0 586 case JVM_CONSTANT_Fieldref:
duke@0 587 case JVM_CONSTANT_Methodref:
duke@0 588 case JVM_CONSTANT_Integer:
duke@0 589 case JVM_CONSTANT_Float:
duke@0 590 // Do nothing! Not an oop.
duke@0 591 // These constant types do not reference symbols at this point.
duke@0 592 break;
duke@0 593
duke@0 594 case JVM_CONSTANT_String:
duke@0 595 // Do nothing! Not a symbol.
duke@0 596 break;
duke@0 597
duke@0 598 case JVM_CONSTANT_UnresolvedString:
duke@0 599 case JVM_CONSTANT_Utf8:
duke@0 600 // These constants are symbols, but unless these symbols are
duke@0 601 // actually to be used for something, we don't want to mark them.
duke@0 602 break;
duke@0 603
duke@0 604 case JVM_CONSTANT_Long:
duke@0 605 case JVM_CONSTANT_Double:
duke@0 606 // Do nothing! Not an oop. (But takes two pool entries.)
duke@0 607 ++index;
duke@0 608 break;
duke@0 609
duke@0 610 default:
duke@0 611 ShouldNotReachHere();
duke@0 612 break;
duke@0 613 }
duke@0 614 }
duke@0 615 }
duke@0 616
duke@0 617
duke@0 618 // Iterate over the [one] tags array (in preparation for writing to the
duke@0 619 // shared archive).
duke@0 620
duke@0 621 void constantPoolOopDesc::shared_tags_iterate(OopClosure* closure) {
duke@0 622 closure->do_oop(tags_addr());
duke@0 623 }
duke@0 624
duke@0 625
duke@0 626 // Iterate over String objects (in preparation for writing to the shared
duke@0 627 // archive).
duke@0 628
duke@0 629 void constantPoolOopDesc::shared_strings_iterate(OopClosure* closure) {
duke@0 630 for (int index = 1; index < length(); index++) { // Index 0 is unused
duke@0 631 switch (tag_at(index).value()) {
duke@0 632
duke@0 633 case JVM_CONSTANT_UnresolvedClass:
duke@0 634 case JVM_CONSTANT_NameAndType:
duke@0 635 // Do nothing! Not a String.
duke@0 636 break;
duke@0 637
duke@0 638 case JVM_CONSTANT_Class:
duke@0 639 case JVM_CONSTANT_InterfaceMethodref:
duke@0 640 case JVM_CONSTANT_Fieldref:
duke@0 641 case JVM_CONSTANT_Methodref:
duke@0 642 case JVM_CONSTANT_Integer:
duke@0 643 case JVM_CONSTANT_Float:
duke@0 644 // Do nothing! Not an oop.
duke@0 645 // These constant types do not reference symbols at this point.
duke@0 646 break;
duke@0 647
duke@0 648 case JVM_CONSTANT_String:
duke@0 649 closure->do_oop(obj_at_addr(index));
duke@0 650 break;
duke@0 651
duke@0 652 case JVM_CONSTANT_UnresolvedString:
duke@0 653 case JVM_CONSTANT_Utf8:
duke@0 654 // These constants are symbols, but unless these symbols are
duke@0 655 // actually to be used for something, we don't want to mark them.
duke@0 656 break;
duke@0 657
duke@0 658 case JVM_CONSTANT_Long:
duke@0 659 case JVM_CONSTANT_Double:
duke@0 660 // Do nothing! Not an oop. (But takes two pool entries.)
duke@0 661 ++index;
duke@0 662 break;
duke@0 663
duke@0 664 default:
duke@0 665 ShouldNotReachHere();
duke@0 666 break;
duke@0 667 }
duke@0 668 }
duke@0 669 }
duke@0 670
duke@0 671
duke@0 672 // Compare this constant pool's entry at index1 to the constant pool
duke@0 673 // cp2's entry at index2.
duke@0 674 bool constantPoolOopDesc::compare_entry_to(int index1, constantPoolHandle cp2,
duke@0 675 int index2, TRAPS) {
duke@0 676
duke@0 677 jbyte t1 = tag_at(index1).value();
duke@0 678 jbyte t2 = cp2->tag_at(index2).value();
duke@0 679
duke@0 680
duke@0 681 // JVM_CONSTANT_UnresolvedClassInError is equal to JVM_CONSTANT_UnresolvedClass
duke@0 682 // when comparing
duke@0 683 if (t1 == JVM_CONSTANT_UnresolvedClassInError) {
duke@0 684 t1 = JVM_CONSTANT_UnresolvedClass;
duke@0 685 }
duke@0 686 if (t2 == JVM_CONSTANT_UnresolvedClassInError) {
duke@0 687 t2 = JVM_CONSTANT_UnresolvedClass;
duke@0 688 }
duke@0 689
duke@0 690 if (t1 != t2) {
duke@0 691 // Not the same entry type so there is nothing else to check. Note
duke@0 692 // that this style of checking will consider resolved/unresolved
duke@0 693 // class pairs and resolved/unresolved string pairs as different.
duke@0 694 // From the constantPoolOop API point of view, this is correct
duke@0 695 // behavior. See constantPoolKlass::merge() to see how this plays
duke@0 696 // out in the context of constantPoolOop merging.
duke@0 697 return false;
duke@0 698 }
duke@0 699
duke@0 700 switch (t1) {
duke@0 701 case JVM_CONSTANT_Class:
duke@0 702 {
duke@0 703 klassOop k1 = klass_at(index1, CHECK_false);
duke@0 704 klassOop k2 = cp2->klass_at(index2, CHECK_false);
duke@0 705 if (k1 == k2) {
duke@0 706 return true;
duke@0 707 }
duke@0 708 } break;
duke@0 709
duke@0 710 case JVM_CONSTANT_ClassIndex:
duke@0 711 {
duke@0 712 int recur1 = klass_index_at(index1);
duke@0 713 int recur2 = cp2->klass_index_at(index2);
duke@0 714 bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
duke@0 715 if (match) {
duke@0 716 return true;
duke@0 717 }
duke@0 718 } break;
duke@0 719
duke@0 720 case JVM_CONSTANT_Double:
duke@0 721 {
duke@0 722 jdouble d1 = double_at(index1);
duke@0 723 jdouble d2 = cp2->double_at(index2);
duke@0 724 if (d1 == d2) {
duke@0 725 return true;
duke@0 726 }
duke@0 727 } break;
duke@0 728
duke@0 729 case JVM_CONSTANT_Fieldref:
duke@0 730 case JVM_CONSTANT_InterfaceMethodref:
duke@0 731 case JVM_CONSTANT_Methodref:
duke@0 732 {
duke@0 733 int recur1 = uncached_klass_ref_index_at(index1);
duke@0 734 int recur2 = cp2->uncached_klass_ref_index_at(index2);
duke@0 735 bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
duke@0 736 if (match) {
duke@0 737 recur1 = uncached_name_and_type_ref_index_at(index1);
duke@0 738 recur2 = cp2->uncached_name_and_type_ref_index_at(index2);
duke@0 739 match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
duke@0 740 if (match) {
duke@0 741 return true;
duke@0 742 }
duke@0 743 }
duke@0 744 } break;
duke@0 745
duke@0 746 case JVM_CONSTANT_Float:
duke@0 747 {
duke@0 748 jfloat f1 = float_at(index1);
duke@0 749 jfloat f2 = cp2->float_at(index2);
duke@0 750 if (f1 == f2) {
duke@0 751 return true;
duke@0 752 }
duke@0 753 } break;
duke@0 754
duke@0 755 case JVM_CONSTANT_Integer:
duke@0 756 {
duke@0 757 jint i1 = int_at(index1);
duke@0 758 jint i2 = cp2->int_at(index2);
duke@0 759 if (i1 == i2) {
duke@0 760 return true;
duke@0 761 }
duke@0 762 } break;
duke@0 763
duke@0 764 case JVM_CONSTANT_Long:
duke@0 765 {
duke@0 766 jlong l1 = long_at(index1);
duke@0 767 jlong l2 = cp2->long_at(index2);
duke@0 768 if (l1 == l2) {
duke@0 769 return true;
duke@0 770 }
duke@0 771 } break;
duke@0 772
duke@0 773 case JVM_CONSTANT_NameAndType:
duke@0 774 {
duke@0 775 int recur1 = name_ref_index_at(index1);
duke@0 776 int recur2 = cp2->name_ref_index_at(index2);
duke@0 777 bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
duke@0 778 if (match) {
duke@0 779 recur1 = signature_ref_index_at(index1);
duke@0 780 recur2 = cp2->signature_ref_index_at(index2);
duke@0 781 match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
duke@0 782 if (match) {
duke@0 783 return true;
duke@0 784 }
duke@0 785 }
duke@0 786 } break;
duke@0 787
duke@0 788 case JVM_CONSTANT_String:
duke@0 789 {
duke@0 790 oop s1 = string_at(index1, CHECK_false);
duke@0 791 oop s2 = cp2->string_at(index2, CHECK_false);
duke@0 792 if (s1 == s2) {
duke@0 793 return true;
duke@0 794 }
duke@0 795 } break;
duke@0 796
duke@0 797 case JVM_CONSTANT_StringIndex:
duke@0 798 {
duke@0 799 int recur1 = string_index_at(index1);
duke@0 800 int recur2 = cp2->string_index_at(index2);
duke@0 801 bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
duke@0 802 if (match) {
duke@0 803 return true;
duke@0 804 }
duke@0 805 } break;
duke@0 806
duke@0 807 case JVM_CONSTANT_UnresolvedClass:
duke@0 808 {
duke@0 809 symbolOop k1 = unresolved_klass_at(index1);
duke@0 810 symbolOop k2 = cp2->unresolved_klass_at(index2);
duke@0 811 if (k1 == k2) {
duke@0 812 return true;
duke@0 813 }
duke@0 814 } break;
duke@0 815
jrose@1524 816 case JVM_CONSTANT_MethodType:
jrose@1524 817 {
jrose@1524 818 int k1 = method_type_index_at(index1);
jrose@1524 819 int k2 = cp2->method_type_index_at(index2);
jrose@1524 820 if (k1 == k2) {
jrose@1524 821 return true;
jrose@1524 822 }
jrose@1524 823 } break;
jrose@1524 824
jrose@1524 825 case JVM_CONSTANT_MethodHandle:
jrose@1524 826 {
jrose@1524 827 int k1 = method_handle_ref_kind_at(index1);
jrose@1524 828 int k2 = cp2->method_handle_ref_kind_at(index2);
jrose@1524 829 if (k1 == k2) {
jrose@1524 830 int i1 = method_handle_index_at(index1);
jrose@1524 831 int i2 = cp2->method_handle_index_at(index2);
jrose@1524 832 if (i1 == i2) {
jrose@1524 833 return true;
jrose@1524 834 }
jrose@1524 835 }
jrose@1524 836 } break;
jrose@1524 837
jrose@1583 838 case JVM_CONSTANT_InvokeDynamic:
jrose@1583 839 {
jrose@1583 840 int k1 = invoke_dynamic_bootstrap_method_ref_index_at(index1);
jrose@1583 841 int k2 = cp2->invoke_dynamic_bootstrap_method_ref_index_at(index2);
jrose@1583 842 if (k1 == k2) {
jrose@1583 843 int i1 = invoke_dynamic_name_and_type_ref_index_at(index1);
jrose@1583 844 int i2 = cp2->invoke_dynamic_name_and_type_ref_index_at(index2);
jrose@1583 845 if (i1 == i2) {
jrose@1583 846 return true;
jrose@1583 847 }
jrose@1583 848 }
jrose@1583 849 } break;
jrose@1583 850
duke@0 851 case JVM_CONSTANT_UnresolvedString:
duke@0 852 {
duke@0 853 symbolOop s1 = unresolved_string_at(index1);
duke@0 854 symbolOop s2 = cp2->unresolved_string_at(index2);
duke@0 855 if (s1 == s2) {
duke@0 856 return true;
duke@0 857 }
duke@0 858 } break;
duke@0 859
duke@0 860 case JVM_CONSTANT_Utf8:
duke@0 861 {
duke@0 862 symbolOop s1 = symbol_at(index1);
duke@0 863 symbolOop s2 = cp2->symbol_at(index2);
duke@0 864 if (s1 == s2) {
duke@0 865 return true;
duke@0 866 }
duke@0 867 } break;
duke@0 868
duke@0 869 // Invalid is used as the tag for the second constant pool entry
duke@0 870 // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
duke@0 871 // not be seen by itself.
duke@0 872 case JVM_CONSTANT_Invalid: // fall through
duke@0 873
duke@0 874 default:
duke@0 875 ShouldNotReachHere();
duke@0 876 break;
duke@0 877 }
duke@0 878
duke@0 879 return false;
duke@0 880 } // end compare_entry_to()
duke@0 881
duke@0 882
duke@0 883 // Copy this constant pool's entries at start_i to end_i (inclusive)
duke@0 884 // to the constant pool to_cp's entries starting at to_i. A total of
duke@0 885 // (end_i - start_i) + 1 entries are copied.
duke@0 886 void constantPoolOopDesc::copy_cp_to(int start_i, int end_i,
duke@0 887 constantPoolHandle to_cp, int to_i, TRAPS) {
duke@0 888
duke@0 889 int dest_i = to_i; // leave original alone for debug purposes
duke@0 890
duke@0 891 for (int src_i = start_i; src_i <= end_i; /* see loop bottom */ ) {
duke@0 892 copy_entry_to(src_i, to_cp, dest_i, CHECK);
duke@0 893
duke@0 894 switch (tag_at(src_i).value()) {
duke@0 895 case JVM_CONSTANT_Double:
duke@0 896 case JVM_CONSTANT_Long:
duke@0 897 // double and long take two constant pool entries
duke@0 898 src_i += 2;
duke@0 899 dest_i += 2;
duke@0 900 break;
duke@0 901
duke@0 902 default:
duke@0 903 // all others take one constant pool entry
duke@0 904 src_i++;
duke@0 905 dest_i++;
duke@0 906 break;
duke@0 907 }
duke@0 908 }
duke@0 909 } // end copy_cp_to()
duke@0 910
duke@0 911
duke@0 912 // Copy this constant pool's entry at from_i to the constant pool
duke@0 913 // to_cp's entry at to_i.
duke@0 914 void constantPoolOopDesc::copy_entry_to(int from_i, constantPoolHandle to_cp,
duke@0 915 int to_i, TRAPS) {
duke@0 916
duke@0 917 switch (tag_at(from_i).value()) {
duke@0 918 case JVM_CONSTANT_Class:
duke@0 919 {
duke@0 920 klassOop k = klass_at(from_i, CHECK);
duke@0 921 to_cp->klass_at_put(to_i, k);
duke@0 922 } break;
duke@0 923
duke@0 924 case JVM_CONSTANT_ClassIndex:
duke@0 925 {
duke@0 926 jint ki = klass_index_at(from_i);
duke@0 927 to_cp->klass_index_at_put(to_i, ki);
duke@0 928 } break;
duke@0 929
duke@0 930 case JVM_CONSTANT_Double:
duke@0 931 {
duke@0 932 jdouble d = double_at(from_i);
duke@0 933 to_cp->double_at_put(to_i, d);
duke@0 934 // double takes two constant pool entries so init second entry's tag
duke@0 935 to_cp->tag_at_put(to_i + 1, JVM_CONSTANT_Invalid);
duke@0 936 } break;
duke@0 937
duke@0 938 case JVM_CONSTANT_Fieldref:
duke@0 939 {
duke@0 940 int class_index = uncached_klass_ref_index_at(from_i);
duke@0 941 int name_and_type_index = uncached_name_and_type_ref_index_at(from_i);
duke@0 942 to_cp->field_at_put(to_i, class_index, name_and_type_index);
duke@0 943 } break;
duke@0 944
duke@0 945 case JVM_CONSTANT_Float:
duke@0 946 {
duke@0 947 jfloat f = float_at(from_i);
duke@0 948 to_cp->float_at_put(to_i, f);
duke@0 949 } break;
duke@0 950
duke@0 951 case JVM_CONSTANT_Integer:
duke@0 952 {
duke@0 953 jint i = int_at(from_i);
duke@0 954 to_cp->int_at_put(to_i, i);
duke@0 955 } break;
duke@0 956
duke@0 957 case JVM_CONSTANT_InterfaceMethodref:
duke@0 958 {
duke@0 959 int class_index = uncached_klass_ref_index_at(from_i);
duke@0 960 int name_and_type_index = uncached_name_and_type_ref_index_at(from_i);
duke@0 961 to_cp->interface_method_at_put(to_i, class_index, name_and_type_index);
duke@0 962 } break;
duke@0 963
duke@0 964 case JVM_CONSTANT_Long:
duke@0 965 {
duke@0 966 jlong l = long_at(from_i);
duke@0 967 to_cp->long_at_put(to_i, l);
duke@0 968 // long takes two constant pool entries so init second entry's tag
duke@0 969 to_cp->tag_at_put(to_i + 1, JVM_CONSTANT_Invalid);
duke@0 970 } break;
duke@0 971
duke@0 972 case JVM_CONSTANT_Methodref:
duke@0 973 {
duke@0 974 int class_index = uncached_klass_ref_index_at(from_i);
duke@0 975 int name_and_type_index = uncached_name_and_type_ref_index_at(from_i);
duke@0 976 to_cp->method_at_put(to_i, class_index, name_and_type_index);
duke@0 977 } break;
duke@0 978
duke@0 979 case JVM_CONSTANT_NameAndType:
duke@0 980 {
duke@0 981 int name_ref_index = name_ref_index_at(from_i);
duke@0 982 int signature_ref_index = signature_ref_index_at(from_i);
duke@0 983 to_cp->name_and_type_at_put(to_i, name_ref_index, signature_ref_index);
duke@0 984 } break;
duke@0 985
duke@0 986 case JVM_CONSTANT_String:
duke@0 987 {
duke@0 988 oop s = string_at(from_i, CHECK);
duke@0 989 to_cp->string_at_put(to_i, s);
duke@0 990 } break;
duke@0 991
duke@0 992 case JVM_CONSTANT_StringIndex:
duke@0 993 {
duke@0 994 jint si = string_index_at(from_i);
duke@0 995 to_cp->string_index_at_put(to_i, si);
duke@0 996 } break;
duke@0 997
duke@0 998 case JVM_CONSTANT_UnresolvedClass:
duke@0 999 {
duke@0 1000 symbolOop k = unresolved_klass_at(from_i);
duke@0 1001 to_cp->unresolved_klass_at_put(to_i, k);
duke@0 1002 } break;
duke@0 1003
duke@0 1004 case JVM_CONSTANT_UnresolvedClassInError:
duke@0 1005 {
duke@0 1006 symbolOop k = unresolved_klass_at(from_i);
duke@0 1007 to_cp->unresolved_klass_at_put(to_i, k);
duke@0 1008 to_cp->tag_at_put(to_i, JVM_CONSTANT_UnresolvedClassInError);
duke@0 1009 } break;
duke@0 1010
duke@0 1011
duke@0 1012 case JVM_CONSTANT_UnresolvedString:
duke@0 1013 {
duke@0 1014 symbolOop s = unresolved_string_at(from_i);
duke@0 1015 to_cp->unresolved_string_at_put(to_i, s);
duke@0 1016 } break;
duke@0 1017
duke@0 1018 case JVM_CONSTANT_Utf8:
duke@0 1019 {
duke@0 1020 symbolOop s = symbol_at(from_i);
duke@0 1021 to_cp->symbol_at_put(to_i, s);
duke@0 1022 } break;
duke@0 1023
jrose@1524 1024 case JVM_CONSTANT_MethodType:
jrose@1524 1025 {
jrose@1524 1026 jint k = method_type_index_at(from_i);
jrose@1524 1027 to_cp->method_type_index_at_put(to_i, k);
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(from_i);
jrose@1524 1033 int k2 = method_handle_index_at(from_i);
jrose@1524 1034 to_cp->method_handle_index_at_put(to_i, k1, k2);
jrose@1524 1035 } break;
jrose@1524 1036
jrose@1583 1037 case JVM_CONSTANT_InvokeDynamic:
jrose@1583 1038 {
jrose@1583 1039 int k1 = invoke_dynamic_bootstrap_method_ref_index_at(from_i);
jrose@1583 1040 int k2 = invoke_dynamic_name_and_type_ref_index_at(from_i);
jrose@1583 1041 to_cp->invoke_dynamic_at_put(to_i, k1, k2);
jrose@1583 1042 } break;
jrose@1583 1043
duke@0 1044 // Invalid is used as the tag for the second constant pool entry
duke@0 1045 // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
duke@0 1046 // not be seen by itself.
duke@0 1047 case JVM_CONSTANT_Invalid: // fall through
duke@0 1048
duke@0 1049 default:
duke@0 1050 {
duke@0 1051 jbyte bad_value = tag_at(from_i).value(); // leave a breadcrumb
duke@0 1052 ShouldNotReachHere();
duke@0 1053 } break;
duke@0 1054 }
duke@0 1055 } // end copy_entry_to()
duke@0 1056
duke@0 1057
duke@0 1058 // Search constant pool search_cp for an entry that matches this
duke@0 1059 // constant pool's entry at pattern_i. Returns the index of a
duke@0 1060 // matching entry or zero (0) if there is no matching entry.
duke@0 1061 int constantPoolOopDesc::find_matching_entry(int pattern_i,
duke@0 1062 constantPoolHandle search_cp, TRAPS) {
duke@0 1063
duke@0 1064 // index zero (0) is not used
duke@0 1065 for (int i = 1; i < search_cp->length(); i++) {
duke@0 1066 bool found = compare_entry_to(pattern_i, search_cp, i, CHECK_0);
duke@0 1067 if (found) {
duke@0 1068 return i;
duke@0 1069 }
duke@0 1070 }
duke@0 1071
duke@0 1072 return 0; // entry not found; return unused index zero (0)
duke@0 1073 } // end find_matching_entry()
duke@0 1074
duke@0 1075
duke@0 1076 #ifndef PRODUCT
duke@0 1077
duke@0 1078 const char* constantPoolOopDesc::printable_name_at(int which) {
duke@0 1079
duke@0 1080 constantTag tag = tag_at(which);
duke@0 1081
duke@0 1082 if (tag.is_unresolved_string() || tag.is_string()) {
duke@0 1083 return string_at_noresolve(which);
duke@0 1084 } else if (tag.is_klass() || tag.is_unresolved_klass()) {
duke@0 1085 return klass_name_at(which)->as_C_string();
duke@0 1086 } else if (tag.is_symbol()) {
duke@0 1087 return symbol_at(which)->as_C_string();
duke@0 1088 }
duke@0 1089 return "";
duke@0 1090 }
duke@0 1091
duke@0 1092 #endif // PRODUCT
duke@0 1093
duke@0 1094
duke@0 1095 // JVMTI GetConstantPool support
duke@0 1096
duke@0 1097 // For temporary use until code is stable.
duke@0 1098 #define DBG(code)
duke@0 1099
duke@0 1100 static const char* WARN_MSG = "Must not be such entry!";
duke@0 1101
duke@0 1102 static void print_cpool_bytes(jint cnt, u1 *bytes) {
duke@0 1103 jint size = 0;
duke@0 1104 u2 idx1, idx2;
duke@0 1105
duke@0 1106 for (jint idx = 1; idx < cnt; idx++) {
duke@0 1107 jint ent_size = 0;
duke@0 1108 u1 tag = *bytes++;
duke@0 1109 size++; // count tag
duke@0 1110
duke@0 1111 printf("const #%03d, tag: %02d ", idx, tag);
duke@0 1112 switch(tag) {
duke@0 1113 case JVM_CONSTANT_Invalid: {
duke@0 1114 printf("Invalid");
duke@0 1115 break;
duke@0 1116 }
duke@0 1117 case JVM_CONSTANT_Unicode: {
duke@0 1118 printf("Unicode %s", WARN_MSG);
duke@0 1119 break;
duke@0 1120 }
duke@0 1121 case JVM_CONSTANT_Utf8: {
duke@0 1122 u2 len = Bytes::get_Java_u2(bytes);
duke@0 1123 char str[128];
duke@0 1124 if (len > 127) {
duke@0 1125 len = 127;
duke@0 1126 }
duke@0 1127 strncpy(str, (char *) (bytes+2), len);
duke@0 1128 str[len] = '\0';
duke@0 1129 printf("Utf8 \"%s\"", str);
duke@0 1130 ent_size = 2 + len;
duke@0 1131 break;
duke@0 1132 }
duke@0 1133 case JVM_CONSTANT_Integer: {
duke@0 1134 u4 val = Bytes::get_Java_u4(bytes);
duke@0 1135 printf("int %d", *(int *) &val);
duke@0 1136 ent_size = 4;
duke@0 1137 break;
duke@0 1138 }
duke@0 1139 case JVM_CONSTANT_Float: {
duke@0 1140 u4 val = Bytes::get_Java_u4(bytes);
duke@0 1141 printf("float %5.3ff", *(float *) &val);
duke@0 1142 ent_size = 4;
duke@0 1143 break;
duke@0 1144 }
duke@0 1145 case JVM_CONSTANT_Long: {
duke@0 1146 u8 val = Bytes::get_Java_u8(bytes);
xlu@513 1147 printf("long "INT64_FORMAT, *(jlong *) &val);
duke@0 1148 ent_size = 8;
duke@0 1149 idx++; // Long takes two cpool slots
duke@0 1150 break;
duke@0 1151 }
duke@0 1152 case JVM_CONSTANT_Double: {
duke@0 1153 u8 val = Bytes::get_Java_u8(bytes);
duke@0 1154 printf("double %5.3fd", *(jdouble *)&val);
duke@0 1155 ent_size = 8;
duke@0 1156 idx++; // Double takes two cpool slots
duke@0 1157 break;
duke@0 1158 }
duke@0 1159 case JVM_CONSTANT_Class: {
duke@0 1160 idx1 = Bytes::get_Java_u2(bytes);
duke@0 1161 printf("class #%03d", idx1);
duke@0 1162 ent_size = 2;
duke@0 1163 break;
duke@0 1164 }
duke@0 1165 case JVM_CONSTANT_String: {
duke@0 1166 idx1 = Bytes::get_Java_u2(bytes);
duke@0 1167 printf("String #%03d", idx1);
duke@0 1168 ent_size = 2;
duke@0 1169 break;
duke@0 1170 }
duke@0 1171 case JVM_CONSTANT_Fieldref: {
duke@0 1172 idx1 = Bytes::get_Java_u2(bytes);
duke@0 1173 idx2 = Bytes::get_Java_u2(bytes+2);
duke@0 1174 printf("Field #%03d, #%03d", (int) idx1, (int) idx2);
duke@0 1175 ent_size = 4;
duke@0 1176 break;
duke@0 1177 }
duke@0 1178 case JVM_CONSTANT_Methodref: {
duke@0 1179 idx1 = Bytes::get_Java_u2(bytes);
duke@0 1180 idx2 = Bytes::get_Java_u2(bytes+2);
duke@0 1181 printf("Method #%03d, #%03d", idx1, idx2);
duke@0 1182 ent_size = 4;
duke@0 1183 break;
duke@0 1184 }
duke@0 1185 case JVM_CONSTANT_InterfaceMethodref: {
duke@0 1186 idx1 = Bytes::get_Java_u2(bytes);
duke@0 1187 idx2 = Bytes::get_Java_u2(bytes+2);
duke@0 1188 printf("InterfMethod #%03d, #%03d", idx1, idx2);
duke@0 1189 ent_size = 4;
duke@0 1190 break;
duke@0 1191 }
duke@0 1192 case JVM_CONSTANT_NameAndType: {
duke@0 1193 idx1 = Bytes::get_Java_u2(bytes);
duke@0 1194 idx2 = Bytes::get_Java_u2(bytes+2);
duke@0 1195 printf("NameAndType #%03d, #%03d", idx1, idx2);
duke@0 1196 ent_size = 4;
duke@0 1197 break;
duke@0 1198 }
duke@0 1199 case JVM_CONSTANT_ClassIndex: {
duke@0 1200 printf("ClassIndex %s", WARN_MSG);
duke@0 1201 break;
duke@0 1202 }
duke@0 1203 case JVM_CONSTANT_UnresolvedClass: {
duke@0 1204 printf("UnresolvedClass: %s", WARN_MSG);
duke@0 1205 break;
duke@0 1206 }
duke@0 1207 case JVM_CONSTANT_UnresolvedClassInError: {
duke@0 1208 printf("UnresolvedClassInErr: %s", WARN_MSG);
duke@0 1209 break;
duke@0 1210 }
duke@0 1211 case JVM_CONSTANT_StringIndex: {
duke@0 1212 printf("StringIndex: %s", WARN_MSG);
duke@0 1213 break;
duke@0 1214 }
duke@0 1215 case JVM_CONSTANT_UnresolvedString: {
duke@0 1216 printf("UnresolvedString: %s", WARN_MSG);
duke@0 1217 break;
duke@0 1218 }
duke@0 1219 }
duke@0 1220 printf(";\n");
duke@0 1221 bytes += ent_size;
duke@0 1222 size += ent_size;
duke@0 1223 }
duke@0 1224 printf("Cpool size: %d\n", size);
duke@0 1225 fflush(0);
duke@0 1226 return;
duke@0 1227 } /* end print_cpool_bytes */
duke@0 1228
duke@0 1229
duke@0 1230 // Returns size of constant pool entry.
duke@0 1231 jint constantPoolOopDesc::cpool_entry_size(jint idx) {
duke@0 1232 switch(tag_at(idx).value()) {
duke@0 1233 case JVM_CONSTANT_Invalid:
duke@0 1234 case JVM_CONSTANT_Unicode:
duke@0 1235 return 1;
duke@0 1236
duke@0 1237 case JVM_CONSTANT_Utf8:
duke@0 1238 return 3 + symbol_at(idx)->utf8_length();
duke@0 1239
duke@0 1240 case JVM_CONSTANT_Class:
duke@0 1241 case JVM_CONSTANT_String:
duke@0 1242 case JVM_CONSTANT_ClassIndex:
duke@0 1243 case JVM_CONSTANT_UnresolvedClass:
duke@0 1244 case JVM_CONSTANT_UnresolvedClassInError:
duke@0 1245 case JVM_CONSTANT_StringIndex:
duke@0 1246 case JVM_CONSTANT_UnresolvedString:
jrose@1524 1247 case JVM_CONSTANT_MethodType:
duke@0 1248 return 3;
duke@0 1249
jrose@1524 1250 case JVM_CONSTANT_MethodHandle:
jrose@1524 1251 return 4; //tag, ref_kind, ref_index
jrose@1524 1252
duke@0 1253 case JVM_CONSTANT_Integer:
duke@0 1254 case JVM_CONSTANT_Float:
duke@0 1255 case JVM_CONSTANT_Fieldref:
duke@0 1256 case JVM_CONSTANT_Methodref:
duke@0 1257 case JVM_CONSTANT_InterfaceMethodref:
duke@0 1258 case JVM_CONSTANT_NameAndType:
jrose@1583 1259 case JVM_CONSTANT_InvokeDynamic:
duke@0 1260 return 5;
duke@0 1261
duke@0 1262 case JVM_CONSTANT_Long:
duke@0 1263 case JVM_CONSTANT_Double:
duke@0 1264 return 9;
duke@0 1265 }
duke@0 1266 assert(false, "cpool_entry_size: Invalid constant pool entry tag");
duke@0 1267 return 1;
duke@0 1268 } /* end cpool_entry_size */
duke@0 1269
duke@0 1270
duke@0 1271 // SymbolHashMap is used to find a constant pool index from a string.
duke@0 1272 // This function fills in SymbolHashMaps, one for utf8s and one for
duke@0 1273 // class names, returns size of the cpool raw bytes.
duke@0 1274 jint constantPoolOopDesc::hash_entries_to(SymbolHashMap *symmap,
duke@0 1275 SymbolHashMap *classmap) {
duke@0 1276 jint size = 0;
duke@0 1277
duke@0 1278 for (u2 idx = 1; idx < length(); idx++) {
duke@0 1279 u2 tag = tag_at(idx).value();
duke@0 1280 size += cpool_entry_size(idx);
duke@0 1281
duke@0 1282 switch(tag) {
duke@0 1283 case JVM_CONSTANT_Utf8: {
duke@0 1284 symbolOop sym = symbol_at(idx);
duke@0 1285 symmap->add_entry(sym, idx);
duke@0 1286 DBG(printf("adding symbol entry %s = %d\n", sym->as_utf8(), idx));
duke@0 1287 break;
duke@0 1288 }
duke@0 1289 case JVM_CONSTANT_Class:
duke@0 1290 case JVM_CONSTANT_UnresolvedClass:
duke@0 1291 case JVM_CONSTANT_UnresolvedClassInError: {
duke@0 1292 symbolOop sym = klass_name_at(idx);
duke@0 1293 classmap->add_entry(sym, idx);
duke@0 1294 DBG(printf("adding class entry %s = %d\n", sym->as_utf8(), idx));
duke@0 1295 break;
duke@0 1296 }
duke@0 1297 case JVM_CONSTANT_Long:
duke@0 1298 case JVM_CONSTANT_Double: {
duke@0 1299 idx++; // Both Long and Double take two cpool slots
duke@0 1300 break;
duke@0 1301 }
duke@0 1302 }
duke@0 1303 }
duke@0 1304 return size;
duke@0 1305 } /* end hash_utf8_entries_to */
duke@0 1306
duke@0 1307
duke@0 1308 // Copy cpool bytes.
duke@0 1309 // Returns:
duke@0 1310 // 0, in case of OutOfMemoryError
duke@0 1311 // -1, in case of internal error
duke@0 1312 // > 0, count of the raw cpool bytes that have been copied
duke@0 1313 int constantPoolOopDesc::copy_cpool_bytes(int cpool_size,
duke@0 1314 SymbolHashMap* tbl,
duke@0 1315 unsigned char *bytes) {
duke@0 1316 u2 idx1, idx2;
duke@0 1317 jint size = 0;
duke@0 1318 jint cnt = length();
duke@0 1319 unsigned char *start_bytes = bytes;
duke@0 1320
duke@0 1321 for (jint idx = 1; idx < cnt; idx++) {
duke@0 1322 u1 tag = tag_at(idx).value();
duke@0 1323 jint ent_size = cpool_entry_size(idx);
duke@0 1324
duke@0 1325 assert(size + ent_size <= cpool_size, "Size mismatch");
duke@0 1326
duke@0 1327 *bytes = tag;
duke@0 1328 DBG(printf("#%03hd tag=%03hd, ", idx, tag));
duke@0 1329 switch(tag) {
duke@0 1330 case JVM_CONSTANT_Invalid: {
duke@0 1331 DBG(printf("JVM_CONSTANT_Invalid"));
duke@0 1332 break;
duke@0 1333 }
duke@0 1334 case JVM_CONSTANT_Unicode: {
duke@0 1335 assert(false, "Wrong constant pool tag: JVM_CONSTANT_Unicode");
duke@0 1336 DBG(printf("JVM_CONSTANT_Unicode"));
duke@0 1337 break;
duke@0 1338 }
duke@0 1339 case JVM_CONSTANT_Utf8: {
duke@0 1340 symbolOop sym = symbol_at(idx);
duke@0 1341 char* str = sym->as_utf8();
duke@0 1342 // Warning! It's crashing on x86 with len = sym->utf8_length()
duke@0 1343 int len = (int) strlen(str);
duke@0 1344 Bytes::put_Java_u2((address) (bytes+1), (u2) len);
duke@0 1345 for (int i = 0; i < len; i++) {
duke@0 1346 bytes[3+i] = (u1) str[i];
duke@0 1347 }
duke@0 1348 DBG(printf("JVM_CONSTANT_Utf8: %s ", str));
duke@0 1349 break;
duke@0 1350 }
duke@0 1351 case JVM_CONSTANT_Integer: {
duke@0 1352 jint val = int_at(idx);
duke@0 1353 Bytes::put_Java_u4((address) (bytes+1), *(u4*)&val);
duke@0 1354 break;
duke@0 1355 }
duke@0 1356 case JVM_CONSTANT_Float: {
duke@0 1357 jfloat val = float_at(idx);
duke@0 1358 Bytes::put_Java_u4((address) (bytes+1), *(u4*)&val);
duke@0 1359 break;
duke@0 1360 }
duke@0 1361 case JVM_CONSTANT_Long: {
duke@0 1362 jlong val = long_at(idx);
duke@0 1363 Bytes::put_Java_u8((address) (bytes+1), *(u8*)&val);
duke@0 1364 idx++; // Long takes two cpool slots
duke@0 1365 break;
duke@0 1366 }
duke@0 1367 case JVM_CONSTANT_Double: {
duke@0 1368 jdouble val = double_at(idx);
duke@0 1369 Bytes::put_Java_u8((address) (bytes+1), *(u8*)&val);
duke@0 1370 idx++; // Double takes two cpool slots
duke@0 1371 break;
duke@0 1372 }
duke@0 1373 case JVM_CONSTANT_Class:
duke@0 1374 case JVM_CONSTANT_UnresolvedClass:
duke@0 1375 case JVM_CONSTANT_UnresolvedClassInError: {
duke@0 1376 *bytes = JVM_CONSTANT_Class;
duke@0 1377 symbolOop sym = klass_name_at(idx);
duke@0 1378 idx1 = tbl->symbol_to_value(sym);
duke@0 1379 assert(idx1 != 0, "Have not found a hashtable entry");
duke@0 1380 Bytes::put_Java_u2((address) (bytes+1), idx1);
duke@0 1381 DBG(printf("JVM_CONSTANT_Class: idx=#%03hd, %s", idx1, sym->as_utf8()));
duke@0 1382 break;
duke@0 1383 }
duke@0 1384 case JVM_CONSTANT_String: {
duke@0 1385 unsigned int hash;
duke@0 1386 char *str = string_at_noresolve(idx);
duke@0 1387 symbolOop sym = SymbolTable::lookup_only(str, (int) strlen(str), hash);
thurka@773 1388 if (sym == NULL) {
thurka@773 1389 // sym can be NULL if string refers to incorrectly encoded JVM_CONSTANT_Utf8
thurka@773 1390 // this can happen with JVM TI; see CR 6839599 for more details
thurka@773 1391 oop string = *(obj_at_addr(idx));
thurka@773 1392 assert(java_lang_String::is_instance(string),"Not a String");
thurka@773 1393 DBG(printf("Error #%03hd tag=%03hd\n", idx, tag));
thurka@773 1394 idx1 = 0;
thurka@773 1395 for (int j = 0; j < tbl->table_size() && idx1 == 0; j++) {
thurka@773 1396 for (SymbolHashMapEntry* cur = tbl->bucket(j); cur != NULL; cur = cur->next()) {
thurka@773 1397 int length;
thurka@773 1398 sym = cur->symbol();
thurka@773 1399 jchar* chars = sym->as_unicode(length);
thurka@773 1400 if (java_lang_String::equals(string, chars, length)) {
thurka@773 1401 idx1 = cur->value();
thurka@773 1402 DBG(printf("Index found: %d\n",idx1));
thurka@773 1403 break;
thurka@773 1404 }
thurka@773 1405 }
thurka@773 1406 }
thurka@773 1407 } else {
thurka@773 1408 idx1 = tbl->symbol_to_value(sym);
thurka@773 1409 }
duke@0 1410 assert(idx1 != 0, "Have not found a hashtable entry");
duke@0 1411 Bytes::put_Java_u2((address) (bytes+1), idx1);
duke@0 1412 DBG(printf("JVM_CONSTANT_String: idx=#%03hd, %s", idx1, str));
duke@0 1413 break;
duke@0 1414 }
duke@0 1415 case JVM_CONSTANT_UnresolvedString: {
duke@0 1416 *bytes = JVM_CONSTANT_String;
duke@0 1417 symbolOop sym = unresolved_string_at(idx);
duke@0 1418 idx1 = tbl->symbol_to_value(sym);
duke@0 1419 assert(idx1 != 0, "Have not found a hashtable entry");
duke@0 1420 Bytes::put_Java_u2((address) (bytes+1), idx1);
duke@0 1421 DBG(char *str = sym->as_utf8());
duke@0 1422 DBG(printf("JVM_CONSTANT_UnresolvedString: idx=#%03hd, %s", idx1, str));
duke@0 1423 break;
duke@0 1424 }
duke@0 1425 case JVM_CONSTANT_Fieldref:
duke@0 1426 case JVM_CONSTANT_Methodref:
duke@0 1427 case JVM_CONSTANT_InterfaceMethodref: {
duke@0 1428 idx1 = uncached_klass_ref_index_at(idx);
duke@0 1429 idx2 = uncached_name_and_type_ref_index_at(idx);
duke@0 1430 Bytes::put_Java_u2((address) (bytes+1), idx1);
duke@0 1431 Bytes::put_Java_u2((address) (bytes+3), idx2);
duke@0 1432 DBG(printf("JVM_CONSTANT_Methodref: %hd %hd", idx1, idx2));
duke@0 1433 break;
duke@0 1434 }
duke@0 1435 case JVM_CONSTANT_NameAndType: {
duke@0 1436 idx1 = name_ref_index_at(idx);
duke@0 1437 idx2 = signature_ref_index_at(idx);
duke@0 1438 Bytes::put_Java_u2((address) (bytes+1), idx1);
duke@0 1439 Bytes::put_Java_u2((address) (bytes+3), idx2);
duke@0 1440 DBG(printf("JVM_CONSTANT_NameAndType: %hd %hd", idx1, idx2));
duke@0 1441 break;
duke@0 1442 }
duke@0 1443 case JVM_CONSTANT_ClassIndex: {
duke@0 1444 *bytes = JVM_CONSTANT_Class;
duke@0 1445 idx1 = klass_index_at(idx);
duke@0 1446 Bytes::put_Java_u2((address) (bytes+1), idx1);
duke@0 1447 DBG(printf("JVM_CONSTANT_ClassIndex: %hd", idx1));
duke@0 1448 break;
duke@0 1449 }
duke@0 1450 case JVM_CONSTANT_StringIndex: {
duke@0 1451 *bytes = JVM_CONSTANT_String;
duke@0 1452 idx1 = string_index_at(idx);
duke@0 1453 Bytes::put_Java_u2((address) (bytes+1), idx1);
duke@0 1454 DBG(printf("JVM_CONSTANT_StringIndex: %hd", idx1));
duke@0 1455 break;
duke@0 1456 }
jrose@1524 1457 case JVM_CONSTANT_MethodHandle: {
jrose@1524 1458 *bytes = JVM_CONSTANT_MethodHandle;
jrose@1524 1459 int kind = method_handle_ref_kind_at(idx);
jrose@1524 1460 idx1 = method_handle_index_at(idx);
jrose@1524 1461 *(bytes+1) = (unsigned char) kind;
jrose@1524 1462 Bytes::put_Java_u2((address) (bytes+2), idx1);
jrose@1524 1463 DBG(printf("JVM_CONSTANT_MethodHandle: %d %hd", kind, idx1));
jrose@1524 1464 break;
jrose@1524 1465 }
jrose@1524 1466 case JVM_CONSTANT_MethodType: {
jrose@1524 1467 *bytes = JVM_CONSTANT_MethodType;
jrose@1524 1468 idx1 = method_type_index_at(idx);
jrose@1524 1469 Bytes::put_Java_u2((address) (bytes+1), idx1);
jrose@1524 1470 DBG(printf("JVM_CONSTANT_MethodType: %hd", idx1));
jrose@1524 1471 break;
jrose@1524 1472 }
jrose@1583 1473 case JVM_CONSTANT_InvokeDynamic: {
jrose@1583 1474 *bytes = JVM_CONSTANT_InvokeDynamic;
jrose@1583 1475 idx1 = invoke_dynamic_bootstrap_method_ref_index_at(idx);
jrose@1583 1476 idx2 = invoke_dynamic_name_and_type_ref_index_at(idx);
jrose@1583 1477 Bytes::put_Java_u2((address) (bytes+1), idx1);
jrose@1583 1478 Bytes::put_Java_u2((address) (bytes+3), idx2);
jrose@1583 1479 DBG(printf("JVM_CONSTANT_InvokeDynamic: %hd %hd", idx1, idx2));
jrose@1583 1480 break;
jrose@1583 1481 }
duke@0 1482 }
duke@0 1483 DBG(printf("\n"));
duke@0 1484 bytes += ent_size;
duke@0 1485 size += ent_size;
duke@0 1486 }
duke@0 1487 assert(size == cpool_size, "Size mismatch");
duke@0 1488
duke@0 1489 // Keep temorarily for debugging until it's stable.
duke@0 1490 DBG(print_cpool_bytes(cnt, start_bytes));
duke@0 1491 return (int)(bytes - start_bytes);
duke@0 1492 } /* end copy_cpool_bytes */
duke@0 1493
duke@0 1494
duke@0 1495 void SymbolHashMap::add_entry(symbolOop sym, u2 value) {
duke@0 1496 char *str = sym->as_utf8();
duke@0 1497 unsigned int hash = compute_hash(str, sym->utf8_length());
duke@0 1498 unsigned int index = hash % table_size();
duke@0 1499
duke@0 1500 // check if already in map
duke@0 1501 // we prefer the first entry since it is more likely to be what was used in
duke@0 1502 // the class file
duke@0 1503 for (SymbolHashMapEntry *en = bucket(index); en != NULL; en = en->next()) {
duke@0 1504 assert(en->symbol() != NULL, "SymbolHashMapEntry symbol is NULL");
duke@0 1505 if (en->hash() == hash && en->symbol() == sym) {
duke@0 1506 return; // already there
duke@0 1507 }
duke@0 1508 }
duke@0 1509
duke@0 1510 SymbolHashMapEntry* entry = new SymbolHashMapEntry(hash, sym, value);
duke@0 1511 entry->set_next(bucket(index));
duke@0 1512 _buckets[index].set_entry(entry);
duke@0 1513 assert(entry->symbol() != NULL, "SymbolHashMapEntry symbol is NULL");
duke@0 1514 }
duke@0 1515
duke@0 1516 SymbolHashMapEntry* SymbolHashMap::find_entry(symbolOop sym) {
duke@0 1517 assert(sym != NULL, "SymbolHashMap::find_entry - symbol is NULL");
duke@0 1518 char *str = sym->as_utf8();
duke@0 1519 int len = sym->utf8_length();
duke@0 1520 unsigned int hash = SymbolHashMap::compute_hash(str, len);
duke@0 1521 unsigned int index = hash % table_size();
duke@0 1522 for (SymbolHashMapEntry *en = bucket(index); en != NULL; en = en->next()) {
duke@0 1523 assert(en->symbol() != NULL, "SymbolHashMapEntry symbol is NULL");
duke@0 1524 if (en->hash() == hash && en->symbol() == sym) {
duke@0 1525 return en;
duke@0 1526 }
duke@0 1527 }
duke@0 1528 return NULL;
duke@0 1529 }