src/share/vm/oops/constantPoolOop.cpp

Thu, 15 Jul 2010 18:40:45 -0700

author
jrose
date
Thu, 15 Jul 2010 18:40:45 -0700
changeset 2015
083fde3b838e
parent 1957
136b78722a08
child 2148
d257356e35f0
permissions
-rw-r--r--

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

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

mercurial