src/share/vm/oops/constantPoolOop.cpp

Tue, 08 Feb 2011 12:33:19 +0100

author
stefank
date
Tue, 08 Feb 2011 12:33:19 +0100
changeset 2534
e5383553fd4e
parent 2497
3582bf76420e
child 2614
fbbeec6dad2d
permissions
-rw-r--r--

7014851: Remove unused parallel compaction code
Summary: Removed.
Reviewed-by: jcoomes, brutisso

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

mercurial