src/share/vm/oops/constantPool.cpp

Thu, 04 Apr 2019 17:56:29 +0800

author
aoqi
date
Thu, 04 Apr 2019 17:56:29 +0800
changeset 9572
624a0741915c
parent 9550
270570f695e0
parent 9448
73d689add964
child 10015
eb7ce841ccec
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
fmatte@9344 2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "classfile/classLoaderData.hpp"
aoqi@0 27 #include "classfile/javaClasses.hpp"
aoqi@0 28 #include "classfile/metadataOnStackMark.hpp"
aoqi@0 29 #include "classfile/symbolTable.hpp"
aoqi@0 30 #include "classfile/systemDictionary.hpp"
aoqi@0 31 #include "classfile/vmSymbols.hpp"
aoqi@0 32 #include "interpreter/linkResolver.hpp"
aoqi@0 33 #include "memory/heapInspection.hpp"
aoqi@0 34 #include "memory/metadataFactory.hpp"
aoqi@0 35 #include "memory/oopFactory.hpp"
aoqi@0 36 #include "oops/constantPool.hpp"
aoqi@0 37 #include "oops/instanceKlass.hpp"
aoqi@0 38 #include "oops/objArrayKlass.hpp"
aoqi@0 39 #include "runtime/fieldType.hpp"
aoqi@0 40 #include "runtime/init.hpp"
aoqi@0 41 #include "runtime/javaCalls.hpp"
aoqi@0 42 #include "runtime/signature.hpp"
aoqi@0 43 #include "runtime/vframe.hpp"
aoqi@0 44
aoqi@0 45 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
aoqi@0 46
aoqi@0 47 ConstantPool* ConstantPool::allocate(ClassLoaderData* loader_data, int length, TRAPS) {
aoqi@0 48 // Tags are RW but comment below applies to tags also.
aoqi@0 49 Array<u1>* tags = MetadataFactory::new_writeable_array<u1>(loader_data, length, 0, CHECK_NULL);
aoqi@0 50
aoqi@0 51 int size = ConstantPool::size(length);
aoqi@0 52
aoqi@0 53 // CDS considerations:
aoqi@0 54 // Allocate read-write but may be able to move to read-only at dumping time
aoqi@0 55 // if all the klasses are resolved. The only other field that is writable is
aoqi@0 56 // the resolved_references array, which is recreated at startup time.
aoqi@0 57 // But that could be moved to InstanceKlass (although a pain to access from
aoqi@0 58 // assembly code). Maybe it could be moved to the cpCache which is RW.
aoqi@0 59 return new (loader_data, size, false, MetaspaceObj::ConstantPoolType, THREAD) ConstantPool(tags);
aoqi@0 60 }
aoqi@0 61
aoqi@0 62 ConstantPool::ConstantPool(Array<u1>* tags) {
aoqi@0 63 set_length(tags->length());
aoqi@0 64 set_tags(NULL);
aoqi@0 65 set_cache(NULL);
aoqi@0 66 set_reference_map(NULL);
aoqi@0 67 set_resolved_references(NULL);
aoqi@0 68 set_operands(NULL);
aoqi@0 69 set_pool_holder(NULL);
aoqi@0 70 set_flags(0);
aoqi@0 71
aoqi@0 72 // only set to non-zero if constant pool is merged by RedefineClasses
aoqi@0 73 set_version(0);
aoqi@0 74 set_lock(new Monitor(Monitor::nonleaf + 2, "A constant pool lock"));
aoqi@0 75
aoqi@0 76 // initialize tag array
aoqi@0 77 int length = tags->length();
aoqi@0 78 for (int index = 0; index < length; index++) {
aoqi@0 79 tags->at_put(index, JVM_CONSTANT_Invalid);
aoqi@0 80 }
aoqi@0 81 set_tags(tags);
aoqi@0 82 }
aoqi@0 83
aoqi@0 84 void ConstantPool::deallocate_contents(ClassLoaderData* loader_data) {
aoqi@0 85 MetadataFactory::free_metadata(loader_data, cache());
aoqi@0 86 set_cache(NULL);
aoqi@0 87 MetadataFactory::free_array<u2>(loader_data, reference_map());
aoqi@0 88 set_reference_map(NULL);
aoqi@0 89
aoqi@0 90 MetadataFactory::free_array<jushort>(loader_data, operands());
aoqi@0 91 set_operands(NULL);
aoqi@0 92
aoqi@0 93 release_C_heap_structures();
aoqi@0 94
aoqi@0 95 // free tag array
aoqi@0 96 MetadataFactory::free_array<u1>(loader_data, tags());
aoqi@0 97 set_tags(NULL);
aoqi@0 98 }
aoqi@0 99
aoqi@0 100 void ConstantPool::release_C_heap_structures() {
aoqi@0 101 // walk constant pool and decrement symbol reference counts
aoqi@0 102 unreference_symbols();
aoqi@0 103
aoqi@0 104 delete _lock;
aoqi@0 105 set_lock(NULL);
aoqi@0 106 }
aoqi@0 107
aoqi@0 108 objArrayOop ConstantPool::resolved_references() const {
aoqi@0 109 return (objArrayOop)JNIHandles::resolve(_resolved_references);
aoqi@0 110 }
aoqi@0 111
fmatte@9344 112 // Called from outside constant pool resolution where a resolved_reference array
fmatte@9344 113 // may not be present.
fmatte@9344 114 objArrayOop ConstantPool::resolved_references_or_null() const {
fmatte@9344 115 if (_cache == NULL) {
fmatte@9344 116 return NULL;
fmatte@9344 117 } else {
fmatte@9344 118 return (objArrayOop)JNIHandles::resolve(_resolved_references);
fmatte@9344 119 }
fmatte@9344 120 }
fmatte@9344 121
aoqi@0 122 // Create resolved_references array and mapping array for original cp indexes
aoqi@0 123 // The ldc bytecode was rewritten to have the resolved reference array index so need a way
aoqi@0 124 // to map it back for resolving and some unlikely miscellaneous uses.
aoqi@0 125 // The objects created by invokedynamic are appended to this list.
aoqi@0 126 void ConstantPool::initialize_resolved_references(ClassLoaderData* loader_data,
aoqi@0 127 intStack reference_map,
aoqi@0 128 int constant_pool_map_length,
aoqi@0 129 TRAPS) {
aoqi@0 130 // Initialized the resolved object cache.
aoqi@0 131 int map_length = reference_map.length();
aoqi@0 132 if (map_length > 0) {
aoqi@0 133 // Only need mapping back to constant pool entries. The map isn't used for
aoqi@0 134 // invokedynamic resolved_reference entries. For invokedynamic entries,
aoqi@0 135 // the constant pool cache index has the mapping back to both the constant
aoqi@0 136 // pool and to the resolved reference index.
aoqi@0 137 if (constant_pool_map_length > 0) {
aoqi@0 138 Array<u2>* om = MetadataFactory::new_array<u2>(loader_data, constant_pool_map_length, CHECK);
aoqi@0 139
aoqi@0 140 for (int i = 0; i < constant_pool_map_length; i++) {
aoqi@0 141 int x = reference_map.at(i);
aoqi@0 142 assert(x == (int)(jushort) x, "klass index is too big");
aoqi@0 143 om->at_put(i, (jushort)x);
aoqi@0 144 }
aoqi@0 145 set_reference_map(om);
aoqi@0 146 }
aoqi@0 147
aoqi@0 148 // Create Java array for holding resolved strings, methodHandles,
aoqi@0 149 // methodTypes, invokedynamic and invokehandle appendix objects, etc.
aoqi@0 150 objArrayOop stom = oopFactory::new_objArray(SystemDictionary::Object_klass(), map_length, CHECK);
aoqi@0 151 Handle refs_handle (THREAD, (oop)stom); // must handleize.
aoqi@0 152 set_resolved_references(loader_data->add_handle(refs_handle));
aoqi@0 153 }
aoqi@0 154 }
aoqi@0 155
aoqi@0 156 // CDS support. Create a new resolved_references array.
aoqi@0 157 void ConstantPool::restore_unshareable_info(TRAPS) {
aoqi@0 158
aoqi@0 159 // Only create the new resolved references array and lock if it hasn't been
aoqi@0 160 // attempted before
aoqi@0 161 if (resolved_references() != NULL) return;
aoqi@0 162
aoqi@0 163 // restore the C++ vtable from the shared archive
aoqi@0 164 restore_vtable();
aoqi@0 165
aoqi@0 166 if (SystemDictionary::Object_klass_loaded()) {
aoqi@0 167 // Recreate the object array and add to ClassLoaderData.
aoqi@0 168 int map_length = resolved_reference_length();
aoqi@0 169 if (map_length > 0) {
aoqi@0 170 objArrayOop stom = oopFactory::new_objArray(SystemDictionary::Object_klass(), map_length, CHECK);
aoqi@0 171 Handle refs_handle (THREAD, (oop)stom); // must handleize.
aoqi@0 172
aoqi@0 173 ClassLoaderData* loader_data = pool_holder()->class_loader_data();
aoqi@0 174 set_resolved_references(loader_data->add_handle(refs_handle));
aoqi@0 175 }
aoqi@0 176
aoqi@0 177 // Also need to recreate the mutex. Make sure this matches the constructor
aoqi@0 178 set_lock(new Monitor(Monitor::nonleaf + 2, "A constant pool lock"));
aoqi@0 179 }
aoqi@0 180 }
aoqi@0 181
aoqi@0 182 void ConstantPool::remove_unshareable_info() {
aoqi@0 183 // Resolved references are not in the shared archive.
aoqi@0 184 // Save the length for restoration. It is not necessarily the same length
aoqi@0 185 // as reference_map.length() if invokedynamic is saved.
aoqi@0 186 set_resolved_reference_length(
aoqi@0 187 resolved_references() != NULL ? resolved_references()->length() : 0);
aoqi@0 188 set_resolved_references(NULL);
aoqi@0 189 set_lock(NULL);
aoqi@0 190 }
aoqi@0 191
aoqi@0 192 int ConstantPool::cp_to_object_index(int cp_index) {
aoqi@0 193 // this is harder don't do this so much.
aoqi@0 194 int i = reference_map()->find(cp_index);
aoqi@0 195 // We might not find the index for jsr292 call.
aoqi@0 196 return (i < 0) ? _no_index_sentinel : i;
aoqi@0 197 }
aoqi@0 198
aoqi@0 199 Klass* ConstantPool::klass_at_impl(constantPoolHandle this_oop, int which, TRAPS) {
aoqi@0 200 // A resolved constantPool entry will contain a Klass*, otherwise a Symbol*.
aoqi@0 201 // It is not safe to rely on the tag bit's here, since we don't have a lock, and the entry and
aoqi@0 202 // tag is not updated atomicly.
aoqi@0 203
aoqi@0 204 CPSlot entry = this_oop->slot_at(which);
aoqi@0 205 if (entry.is_resolved()) {
aoqi@0 206 assert(entry.get_klass()->is_klass(), "must be");
aoqi@0 207 // Already resolved - return entry.
aoqi@0 208 return entry.get_klass();
aoqi@0 209 }
aoqi@0 210
aoqi@0 211 // Acquire lock on constant oop while doing update. After we get the lock, we check if another object
aoqi@0 212 // already has updated the object
aoqi@0 213 assert(THREAD->is_Java_thread(), "must be a Java thread");
aoqi@0 214 bool do_resolve = false;
aoqi@0 215 bool in_error = false;
aoqi@0 216
aoqi@0 217 // Create a handle for the mirror. This will preserve the resolved class
aoqi@0 218 // until the loader_data is registered.
aoqi@0 219 Handle mirror_handle;
aoqi@0 220
aoqi@0 221 Symbol* name = NULL;
aoqi@0 222 Handle loader;
aoqi@0 223 { MonitorLockerEx ml(this_oop->lock());
aoqi@0 224
aoqi@0 225 if (this_oop->tag_at(which).is_unresolved_klass()) {
aoqi@0 226 if (this_oop->tag_at(which).is_unresolved_klass_in_error()) {
aoqi@0 227 in_error = true;
aoqi@0 228 } else {
aoqi@0 229 do_resolve = true;
aoqi@0 230 name = this_oop->unresolved_klass_at(which);
aoqi@0 231 loader = Handle(THREAD, this_oop->pool_holder()->class_loader());
aoqi@0 232 }
aoqi@0 233 }
aoqi@0 234 } // unlocking constantPool
aoqi@0 235
aoqi@0 236
aoqi@0 237 // The original attempt to resolve this constant pool entry failed so find the
aoqi@0 238 // original error and throw it again (JVMS 5.4.3).
aoqi@0 239 if (in_error) {
aoqi@0 240 Symbol* error = SystemDictionary::find_resolution_error(this_oop, which);
aoqi@0 241 guarantee(error != (Symbol*)NULL, "tag mismatch with resolution error table");
aoqi@0 242 ResourceMark rm;
aoqi@0 243 // exception text will be the class name
aoqi@0 244 const char* className = this_oop->unresolved_klass_at(which)->as_C_string();
aoqi@0 245 THROW_MSG_0(error, className);
aoqi@0 246 }
aoqi@0 247
aoqi@0 248 if (do_resolve) {
aoqi@0 249 // this_oop must be unlocked during resolve_or_fail
aoqi@0 250 oop protection_domain = this_oop->pool_holder()->protection_domain();
aoqi@0 251 Handle h_prot (THREAD, protection_domain);
aoqi@0 252 Klass* k_oop = SystemDictionary::resolve_or_fail(name, loader, h_prot, true, THREAD);
aoqi@0 253 KlassHandle k;
aoqi@0 254 if (!HAS_PENDING_EXCEPTION) {
aoqi@0 255 k = KlassHandle(THREAD, k_oop);
aoqi@0 256 // preserve the resolved klass.
aoqi@0 257 mirror_handle = Handle(THREAD, k_oop->java_mirror());
aoqi@0 258 // Do access check for klasses
aoqi@0 259 verify_constant_pool_resolve(this_oop, k, THREAD);
aoqi@0 260 }
aoqi@0 261
aoqi@0 262 // Failed to resolve class. We must record the errors so that subsequent attempts
aoqi@0 263 // to resolve this constant pool entry fail with the same error (JVMS 5.4.3).
aoqi@0 264 if (HAS_PENDING_EXCEPTION) {
aoqi@0 265 ResourceMark rm;
aoqi@0 266 Symbol* error = PENDING_EXCEPTION->klass()->name();
aoqi@0 267
aoqi@0 268 bool throw_orig_error = false;
aoqi@0 269 {
aoqi@0 270 MonitorLockerEx ml(this_oop->lock());
aoqi@0 271
aoqi@0 272 // some other thread has beaten us and has resolved the class.
aoqi@0 273 if (this_oop->tag_at(which).is_klass()) {
aoqi@0 274 CLEAR_PENDING_EXCEPTION;
aoqi@0 275 entry = this_oop->resolved_klass_at(which);
aoqi@0 276 return entry.get_klass();
aoqi@0 277 }
aoqi@0 278
aoqi@0 279 if (!PENDING_EXCEPTION->
aoqi@0 280 is_a(SystemDictionary::LinkageError_klass())) {
aoqi@0 281 // Just throw the exception and don't prevent these classes from
aoqi@0 282 // being loaded due to virtual machine errors like StackOverflow
aoqi@0 283 // and OutOfMemoryError, etc, or if the thread was hit by stop()
aoqi@0 284 // Needs clarification to section 5.4.3 of the VM spec (see 6308271)
aoqi@0 285 }
aoqi@0 286 else if (!this_oop->tag_at(which).is_unresolved_klass_in_error()) {
aoqi@0 287 SystemDictionary::add_resolution_error(this_oop, which, error);
aoqi@0 288 this_oop->tag_at_put(which, JVM_CONSTANT_UnresolvedClassInError);
aoqi@0 289 } else {
aoqi@0 290 // some other thread has put the class in error state.
aoqi@0 291 error = SystemDictionary::find_resolution_error(this_oop, which);
aoqi@0 292 assert(error != NULL, "checking");
aoqi@0 293 throw_orig_error = true;
aoqi@0 294 }
aoqi@0 295 } // unlocked
aoqi@0 296
aoqi@0 297 if (throw_orig_error) {
aoqi@0 298 CLEAR_PENDING_EXCEPTION;
aoqi@0 299 ResourceMark rm;
aoqi@0 300 const char* className = this_oop->unresolved_klass_at(which)->as_C_string();
aoqi@0 301 THROW_MSG_0(error, className);
aoqi@0 302 }
aoqi@0 303
aoqi@0 304 return 0;
aoqi@0 305 }
aoqi@0 306
aoqi@0 307 if (TraceClassResolution && !k()->oop_is_array()) {
aoqi@0 308 // skip resolving the constant pool so that this code get's
aoqi@0 309 // called the next time some bytecodes refer to this class.
aoqi@0 310 ResourceMark rm;
aoqi@0 311 int line_number = -1;
aoqi@0 312 const char * source_file = NULL;
aoqi@0 313 if (JavaThread::current()->has_last_Java_frame()) {
aoqi@0 314 // try to identify the method which called this function.
aoqi@0 315 vframeStream vfst(JavaThread::current());
aoqi@0 316 if (!vfst.at_end()) {
aoqi@0 317 line_number = vfst.method()->line_number_from_bci(vfst.bci());
aoqi@0 318 Symbol* s = vfst.method()->method_holder()->source_file_name();
aoqi@0 319 if (s != NULL) {
aoqi@0 320 source_file = s->as_C_string();
aoqi@0 321 }
aoqi@0 322 }
aoqi@0 323 }
aoqi@0 324 if (k() != this_oop->pool_holder()) {
aoqi@0 325 // only print something if the classes are different
aoqi@0 326 if (source_file != NULL) {
aoqi@0 327 tty->print("RESOLVE %s %s %s:%d\n",
aoqi@0 328 this_oop->pool_holder()->external_name(),
aoqi@0 329 InstanceKlass::cast(k())->external_name(), source_file, line_number);
aoqi@0 330 } else {
aoqi@0 331 tty->print("RESOLVE %s %s\n",
aoqi@0 332 this_oop->pool_holder()->external_name(),
aoqi@0 333 InstanceKlass::cast(k())->external_name());
aoqi@0 334 }
aoqi@0 335 }
aoqi@0 336 return k();
aoqi@0 337 } else {
aoqi@0 338 MonitorLockerEx ml(this_oop->lock());
aoqi@0 339 // Only updated constant pool - if it is resolved.
aoqi@0 340 do_resolve = this_oop->tag_at(which).is_unresolved_klass();
aoqi@0 341 if (do_resolve) {
aoqi@0 342 this_oop->klass_at_put(which, k());
aoqi@0 343 }
aoqi@0 344 }
aoqi@0 345 }
aoqi@0 346
aoqi@0 347 entry = this_oop->resolved_klass_at(which);
aoqi@0 348 assert(entry.is_resolved() && entry.get_klass()->is_klass(), "must be resolved at this point");
aoqi@0 349 return entry.get_klass();
aoqi@0 350 }
aoqi@0 351
aoqi@0 352
aoqi@0 353 // Does not update ConstantPool* - to avoid any exception throwing. Used
aoqi@0 354 // by compiler and exception handling. Also used to avoid classloads for
aoqi@0 355 // instanceof operations. Returns NULL if the class has not been loaded or
aoqi@0 356 // if the verification of constant pool failed
aoqi@0 357 Klass* ConstantPool::klass_at_if_loaded(constantPoolHandle this_oop, int which) {
aoqi@0 358 CPSlot entry = this_oop->slot_at(which);
aoqi@0 359 if (entry.is_resolved()) {
aoqi@0 360 assert(entry.get_klass()->is_klass(), "must be");
aoqi@0 361 return entry.get_klass();
aoqi@0 362 } else {
aoqi@0 363 assert(entry.is_unresolved(), "must be either symbol or klass");
aoqi@0 364 Thread *thread = Thread::current();
aoqi@0 365 Symbol* name = entry.get_symbol();
aoqi@0 366 oop loader = this_oop->pool_holder()->class_loader();
aoqi@0 367 oop protection_domain = this_oop->pool_holder()->protection_domain();
aoqi@0 368 Handle h_prot (thread, protection_domain);
aoqi@0 369 Handle h_loader (thread, loader);
aoqi@0 370 Klass* k = SystemDictionary::find(name, h_loader, h_prot, thread);
aoqi@0 371
aoqi@0 372 if (k != NULL) {
aoqi@0 373 // Make sure that resolving is legal
aoqi@0 374 EXCEPTION_MARK;
aoqi@0 375 KlassHandle klass(THREAD, k);
aoqi@0 376 // return NULL if verification fails
aoqi@0 377 verify_constant_pool_resolve(this_oop, klass, THREAD);
aoqi@0 378 if (HAS_PENDING_EXCEPTION) {
aoqi@0 379 CLEAR_PENDING_EXCEPTION;
aoqi@0 380 return NULL;
aoqi@0 381 }
aoqi@0 382 return klass();
aoqi@0 383 } else {
aoqi@0 384 return k;
aoqi@0 385 }
aoqi@0 386 }
aoqi@0 387 }
aoqi@0 388
aoqi@0 389
aoqi@0 390 Klass* ConstantPool::klass_ref_at_if_loaded(constantPoolHandle this_oop, int which) {
aoqi@0 391 return klass_at_if_loaded(this_oop, this_oop->klass_ref_index_at(which));
aoqi@0 392 }
aoqi@0 393
aoqi@0 394
aoqi@0 395 Method* ConstantPool::method_at_if_loaded(constantPoolHandle cpool,
aoqi@0 396 int which) {
aoqi@0 397 if (cpool->cache() == NULL) return NULL; // nothing to load yet
aoqi@0 398 int cache_index = decode_cpcache_index(which, true);
aoqi@0 399 if (!(cache_index >= 0 && cache_index < cpool->cache()->length())) {
aoqi@0 400 // FIXME: should be an assert
aoqi@0 401 if (PrintMiscellaneous && (Verbose||WizardMode)) {
aoqi@0 402 tty->print_cr("bad operand %d in:", which); cpool->print();
aoqi@0 403 }
aoqi@0 404 return NULL;
aoqi@0 405 }
aoqi@0 406 ConstantPoolCacheEntry* e = cpool->cache()->entry_at(cache_index);
aoqi@0 407 return e->method_if_resolved(cpool);
aoqi@0 408 }
aoqi@0 409
aoqi@0 410
aoqi@0 411 bool ConstantPool::has_appendix_at_if_loaded(constantPoolHandle cpool, int which) {
aoqi@0 412 if (cpool->cache() == NULL) return false; // nothing to load yet
aoqi@0 413 int cache_index = decode_cpcache_index(which, true);
aoqi@0 414 ConstantPoolCacheEntry* e = cpool->cache()->entry_at(cache_index);
aoqi@0 415 return e->has_appendix();
aoqi@0 416 }
aoqi@0 417
aoqi@0 418 oop ConstantPool::appendix_at_if_loaded(constantPoolHandle cpool, int which) {
aoqi@0 419 if (cpool->cache() == NULL) return NULL; // nothing to load yet
aoqi@0 420 int cache_index = decode_cpcache_index(which, true);
aoqi@0 421 ConstantPoolCacheEntry* e = cpool->cache()->entry_at(cache_index);
aoqi@0 422 return e->appendix_if_resolved(cpool);
aoqi@0 423 }
aoqi@0 424
aoqi@0 425
aoqi@0 426 bool ConstantPool::has_method_type_at_if_loaded(constantPoolHandle cpool, int which) {
aoqi@0 427 if (cpool->cache() == NULL) return false; // nothing to load yet
aoqi@0 428 int cache_index = decode_cpcache_index(which, true);
aoqi@0 429 ConstantPoolCacheEntry* e = cpool->cache()->entry_at(cache_index);
aoqi@0 430 return e->has_method_type();
aoqi@0 431 }
aoqi@0 432
aoqi@0 433 oop ConstantPool::method_type_at_if_loaded(constantPoolHandle cpool, int which) {
aoqi@0 434 if (cpool->cache() == NULL) return NULL; // nothing to load yet
aoqi@0 435 int cache_index = decode_cpcache_index(which, true);
aoqi@0 436 ConstantPoolCacheEntry* e = cpool->cache()->entry_at(cache_index);
aoqi@0 437 return e->method_type_if_resolved(cpool);
aoqi@0 438 }
aoqi@0 439
aoqi@0 440
aoqi@0 441 Symbol* ConstantPool::impl_name_ref_at(int which, bool uncached) {
aoqi@0 442 int name_index = name_ref_index_at(impl_name_and_type_ref_index_at(which, uncached));
aoqi@0 443 return symbol_at(name_index);
aoqi@0 444 }
aoqi@0 445
aoqi@0 446
aoqi@0 447 Symbol* ConstantPool::impl_signature_ref_at(int which, bool uncached) {
aoqi@0 448 int signature_index = signature_ref_index_at(impl_name_and_type_ref_index_at(which, uncached));
aoqi@0 449 return symbol_at(signature_index);
aoqi@0 450 }
aoqi@0 451
aoqi@0 452
aoqi@0 453 int ConstantPool::impl_name_and_type_ref_index_at(int which, bool uncached) {
aoqi@0 454 int i = which;
aoqi@0 455 if (!uncached && cache() != NULL) {
aoqi@0 456 if (ConstantPool::is_invokedynamic_index(which)) {
aoqi@0 457 // Invokedynamic index is index into resolved_references
aoqi@0 458 int pool_index = invokedynamic_cp_cache_entry_at(which)->constant_pool_index();
aoqi@0 459 pool_index = invoke_dynamic_name_and_type_ref_index_at(pool_index);
aoqi@0 460 assert(tag_at(pool_index).is_name_and_type(), "");
aoqi@0 461 return pool_index;
aoqi@0 462 }
aoqi@0 463 // change byte-ordering and go via cache
aoqi@0 464 i = remap_instruction_operand_from_cache(which);
aoqi@0 465 } else {
aoqi@0 466 if (tag_at(which).is_invoke_dynamic()) {
aoqi@0 467 int pool_index = invoke_dynamic_name_and_type_ref_index_at(which);
aoqi@0 468 assert(tag_at(pool_index).is_name_and_type(), "");
aoqi@0 469 return pool_index;
aoqi@0 470 }
aoqi@0 471 }
aoqi@0 472 assert(tag_at(i).is_field_or_method(), "Corrupted constant pool");
aoqi@0 473 assert(!tag_at(i).is_invoke_dynamic(), "Must be handled above");
aoqi@0 474 jint ref_index = *int_at_addr(i);
aoqi@0 475 return extract_high_short_from_int(ref_index);
aoqi@0 476 }
aoqi@0 477
aoqi@0 478
aoqi@0 479 int ConstantPool::impl_klass_ref_index_at(int which, bool uncached) {
aoqi@0 480 guarantee(!ConstantPool::is_invokedynamic_index(which),
aoqi@0 481 "an invokedynamic instruction does not have a klass");
aoqi@0 482 int i = which;
aoqi@0 483 if (!uncached && cache() != NULL) {
aoqi@0 484 // change byte-ordering and go via cache
aoqi@0 485 i = remap_instruction_operand_from_cache(which);
aoqi@0 486 }
aoqi@0 487 assert(tag_at(i).is_field_or_method(), "Corrupted constant pool");
aoqi@0 488 jint ref_index = *int_at_addr(i);
aoqi@0 489 return extract_low_short_from_int(ref_index);
aoqi@0 490 }
aoqi@0 491
aoqi@0 492
aoqi@0 493
aoqi@0 494 int ConstantPool::remap_instruction_operand_from_cache(int operand) {
aoqi@0 495 int cpc_index = operand;
aoqi@0 496 DEBUG_ONLY(cpc_index -= CPCACHE_INDEX_TAG);
aoqi@0 497 assert((int)(u2)cpc_index == cpc_index, "clean u2");
aoqi@0 498 int member_index = cache()->entry_at(cpc_index)->constant_pool_index();
aoqi@0 499 return member_index;
aoqi@0 500 }
aoqi@0 501
aoqi@0 502
aoqi@0 503 void ConstantPool::verify_constant_pool_resolve(constantPoolHandle this_oop, KlassHandle k, TRAPS) {
aoqi@0 504 if (k->oop_is_instance() || k->oop_is_objArray()) {
aoqi@0 505 instanceKlassHandle holder (THREAD, this_oop->pool_holder());
aoqi@0 506 Klass* elem_oop = k->oop_is_instance() ? k() : ObjArrayKlass::cast(k())->bottom_klass();
aoqi@0 507 KlassHandle element (THREAD, elem_oop);
aoqi@0 508
aoqi@0 509 // The element type could be a typeArray - we only need the access check if it is
aoqi@0 510 // an reference to another class
aoqi@0 511 if (element->oop_is_instance()) {
aoqi@0 512 LinkResolver::check_klass_accessability(holder, element, CHECK);
aoqi@0 513 }
aoqi@0 514 }
aoqi@0 515 }
aoqi@0 516
aoqi@0 517
aoqi@0 518 int ConstantPool::name_ref_index_at(int which_nt) {
aoqi@0 519 jint ref_index = name_and_type_at(which_nt);
aoqi@0 520 return extract_low_short_from_int(ref_index);
aoqi@0 521 }
aoqi@0 522
aoqi@0 523
aoqi@0 524 int ConstantPool::signature_ref_index_at(int which_nt) {
aoqi@0 525 jint ref_index = name_and_type_at(which_nt);
aoqi@0 526 return extract_high_short_from_int(ref_index);
aoqi@0 527 }
aoqi@0 528
aoqi@0 529
aoqi@0 530 Klass* ConstantPool::klass_ref_at(int which, TRAPS) {
phh@9507 531 return klass_at(klass_ref_index_at(which), THREAD);
aoqi@0 532 }
aoqi@0 533
aoqi@0 534
aoqi@0 535 Symbol* ConstantPool::klass_name_at(int which) {
aoqi@0 536 assert(tag_at(which).is_unresolved_klass() || tag_at(which).is_klass(),
aoqi@0 537 "Corrupted constant pool");
aoqi@0 538 // A resolved constantPool entry will contain a Klass*, otherwise a Symbol*.
aoqi@0 539 // It is not safe to rely on the tag bit's here, since we don't have a lock, and the entry and
aoqi@0 540 // tag is not updated atomicly.
aoqi@0 541 CPSlot entry = slot_at(which);
aoqi@0 542 if (entry.is_resolved()) {
aoqi@0 543 // Already resolved - return entry's name.
aoqi@0 544 assert(entry.get_klass()->is_klass(), "must be");
aoqi@0 545 return entry.get_klass()->name();
aoqi@0 546 } else {
aoqi@0 547 assert(entry.is_unresolved(), "must be either symbol or klass");
aoqi@0 548 return entry.get_symbol();
aoqi@0 549 }
aoqi@0 550 }
aoqi@0 551
aoqi@0 552 Symbol* ConstantPool::klass_ref_at_noresolve(int which) {
aoqi@0 553 jint ref_index = klass_ref_index_at(which);
aoqi@0 554 return klass_at_noresolve(ref_index);
aoqi@0 555 }
aoqi@0 556
aoqi@0 557 Symbol* ConstantPool::uncached_klass_ref_at_noresolve(int which) {
aoqi@0 558 jint ref_index = uncached_klass_ref_index_at(which);
aoqi@0 559 return klass_at_noresolve(ref_index);
aoqi@0 560 }
aoqi@0 561
aoqi@0 562 char* ConstantPool::string_at_noresolve(int which) {
aoqi@0 563 Symbol* s = unresolved_string_at(which);
aoqi@0 564 if (s == NULL) {
aoqi@0 565 return (char*)"<pseudo-string>";
aoqi@0 566 } else {
aoqi@0 567 return unresolved_string_at(which)->as_C_string();
aoqi@0 568 }
aoqi@0 569 }
aoqi@0 570
aoqi@0 571 BasicType ConstantPool::basic_type_for_signature_at(int which) {
aoqi@0 572 return FieldType::basic_type(symbol_at(which));
aoqi@0 573 }
aoqi@0 574
aoqi@0 575
aoqi@0 576 void ConstantPool::resolve_string_constants_impl(constantPoolHandle this_oop, TRAPS) {
aoqi@0 577 for (int index = 1; index < this_oop->length(); index++) { // Index 0 is unused
aoqi@0 578 if (this_oop->tag_at(index).is_string()) {
aoqi@0 579 this_oop->string_at(index, CHECK);
aoqi@0 580 }
aoqi@0 581 }
aoqi@0 582 }
aoqi@0 583
aoqi@0 584 // Resolve all the classes in the constant pool. If they are all resolved,
aoqi@0 585 // the constant pool is read-only. Enhancement: allocate cp entries to
aoqi@0 586 // another metaspace, and copy to read-only or read-write space if this
aoqi@0 587 // bit is set.
aoqi@0 588 bool ConstantPool::resolve_class_constants(TRAPS) {
aoqi@0 589 constantPoolHandle cp(THREAD, this);
aoqi@0 590 for (int index = 1; index < length(); index++) { // Index 0 is unused
aoqi@0 591 if (tag_at(index).is_unresolved_klass() &&
aoqi@0 592 klass_at_if_loaded(cp, index) == NULL) {
aoqi@0 593 return false;
aoqi@0 594 }
aoqi@0 595 }
aoqi@0 596 // set_preresolution(); or some bit for future use
aoqi@0 597 return true;
aoqi@0 598 }
aoqi@0 599
aoqi@0 600 // If resolution for MethodHandle or MethodType fails, save the exception
aoqi@0 601 // in the resolution error table, so that the same exception is thrown again.
aoqi@0 602 void ConstantPool::save_and_throw_exception(constantPoolHandle this_oop, int which,
aoqi@0 603 int tag, TRAPS) {
aoqi@0 604 ResourceMark rm;
aoqi@0 605 Symbol* error = PENDING_EXCEPTION->klass()->name();
aoqi@0 606 MonitorLockerEx ml(this_oop->lock()); // lock cpool to change tag.
aoqi@0 607
aoqi@0 608 int error_tag = (tag == JVM_CONSTANT_MethodHandle) ?
aoqi@0 609 JVM_CONSTANT_MethodHandleInError : JVM_CONSTANT_MethodTypeInError;
aoqi@0 610
aoqi@0 611 if (!PENDING_EXCEPTION->
aoqi@0 612 is_a(SystemDictionary::LinkageError_klass())) {
aoqi@0 613 // Just throw the exception and don't prevent these classes from
aoqi@0 614 // being loaded due to virtual machine errors like StackOverflow
aoqi@0 615 // and OutOfMemoryError, etc, or if the thread was hit by stop()
aoqi@0 616 // Needs clarification to section 5.4.3 of the VM spec (see 6308271)
aoqi@0 617
aoqi@0 618 } else if (this_oop->tag_at(which).value() != error_tag) {
aoqi@0 619 SystemDictionary::add_resolution_error(this_oop, which, error);
aoqi@0 620 this_oop->tag_at_put(which, error_tag);
aoqi@0 621 } else {
aoqi@0 622 // some other thread has put the class in error state.
aoqi@0 623 error = SystemDictionary::find_resolution_error(this_oop, which);
aoqi@0 624 assert(error != NULL, "checking");
aoqi@0 625 CLEAR_PENDING_EXCEPTION;
aoqi@0 626 THROW_MSG(error, "");
aoqi@0 627 }
aoqi@0 628 }
aoqi@0 629
aoqi@0 630
aoqi@0 631 // Called to resolve constants in the constant pool and return an oop.
aoqi@0 632 // Some constant pool entries cache their resolved oop. This is also
aoqi@0 633 // called to create oops from constants to use in arguments for invokedynamic
aoqi@0 634 oop ConstantPool::resolve_constant_at_impl(constantPoolHandle this_oop, int index, int cache_index, TRAPS) {
aoqi@0 635 oop result_oop = NULL;
aoqi@0 636 Handle throw_exception;
aoqi@0 637
aoqi@0 638 if (cache_index == _possible_index_sentinel) {
aoqi@0 639 // It is possible that this constant is one which is cached in the objects.
aoqi@0 640 // We'll do a linear search. This should be OK because this usage is rare.
aoqi@0 641 assert(index > 0, "valid index");
aoqi@0 642 cache_index = this_oop->cp_to_object_index(index);
aoqi@0 643 }
aoqi@0 644 assert(cache_index == _no_index_sentinel || cache_index >= 0, "");
aoqi@0 645 assert(index == _no_index_sentinel || index >= 0, "");
aoqi@0 646
aoqi@0 647 if (cache_index >= 0) {
aoqi@0 648 result_oop = this_oop->resolved_references()->obj_at(cache_index);
aoqi@0 649 if (result_oop != NULL) {
aoqi@0 650 return result_oop;
aoqi@0 651 // That was easy...
aoqi@0 652 }
aoqi@0 653 index = this_oop->object_to_cp_index(cache_index);
aoqi@0 654 }
aoqi@0 655
aoqi@0 656 jvalue prim_value; // temp used only in a few cases below
aoqi@0 657
aoqi@0 658 int tag_value = this_oop->tag_at(index).value();
aoqi@0 659
aoqi@0 660 switch (tag_value) {
aoqi@0 661
aoqi@0 662 case JVM_CONSTANT_UnresolvedClass:
aoqi@0 663 case JVM_CONSTANT_UnresolvedClassInError:
aoqi@0 664 case JVM_CONSTANT_Class:
aoqi@0 665 {
aoqi@0 666 assert(cache_index == _no_index_sentinel, "should not have been set");
aoqi@0 667 Klass* resolved = klass_at_impl(this_oop, index, CHECK_NULL);
aoqi@0 668 // ldc wants the java mirror.
aoqi@0 669 result_oop = resolved->java_mirror();
aoqi@0 670 break;
aoqi@0 671 }
aoqi@0 672
aoqi@0 673 case JVM_CONSTANT_String:
aoqi@0 674 assert(cache_index != _no_index_sentinel, "should have been set");
aoqi@0 675 if (this_oop->is_pseudo_string_at(index)) {
aoqi@0 676 result_oop = this_oop->pseudo_string_at(index, cache_index);
aoqi@0 677 break;
aoqi@0 678 }
aoqi@0 679 result_oop = string_at_impl(this_oop, index, cache_index, CHECK_NULL);
aoqi@0 680 break;
aoqi@0 681
aoqi@0 682 case JVM_CONSTANT_MethodHandleInError:
aoqi@0 683 case JVM_CONSTANT_MethodTypeInError:
aoqi@0 684 {
aoqi@0 685 Symbol* error = SystemDictionary::find_resolution_error(this_oop, index);
aoqi@0 686 guarantee(error != (Symbol*)NULL, "tag mismatch with resolution error table");
aoqi@0 687 ResourceMark rm;
aoqi@0 688 THROW_MSG_0(error, "");
aoqi@0 689 break;
aoqi@0 690 }
aoqi@0 691
aoqi@0 692 case JVM_CONSTANT_MethodHandle:
aoqi@0 693 {
aoqi@0 694 int ref_kind = this_oop->method_handle_ref_kind_at(index);
aoqi@0 695 int callee_index = this_oop->method_handle_klass_index_at(index);
aoqi@0 696 Symbol* name = this_oop->method_handle_name_ref_at(index);
aoqi@0 697 Symbol* signature = this_oop->method_handle_signature_ref_at(index);
aoqi@0 698 if (PrintMiscellaneous)
aoqi@0 699 tty->print_cr("resolve JVM_CONSTANT_MethodHandle:%d [%d/%d/%d] %s.%s",
aoqi@0 700 ref_kind, index, this_oop->method_handle_index_at(index),
aoqi@0 701 callee_index, name->as_C_string(), signature->as_C_string());
aoqi@0 702 KlassHandle callee;
aoqi@0 703 { Klass* k = klass_at_impl(this_oop, callee_index, CHECK_NULL);
aoqi@0 704 callee = KlassHandle(THREAD, k);
aoqi@0 705 }
aoqi@0 706 KlassHandle klass(THREAD, this_oop->pool_holder());
aoqi@0 707 Handle value = SystemDictionary::link_method_handle_constant(klass, ref_kind,
aoqi@0 708 callee, name, signature,
aoqi@0 709 THREAD);
aoqi@0 710 result_oop = value();
aoqi@0 711 if (HAS_PENDING_EXCEPTION) {
aoqi@0 712 save_and_throw_exception(this_oop, index, tag_value, CHECK_NULL);
aoqi@0 713 }
aoqi@0 714 break;
aoqi@0 715 }
aoqi@0 716
aoqi@0 717 case JVM_CONSTANT_MethodType:
aoqi@0 718 {
aoqi@0 719 Symbol* signature = this_oop->method_type_signature_at(index);
aoqi@0 720 if (PrintMiscellaneous)
aoqi@0 721 tty->print_cr("resolve JVM_CONSTANT_MethodType [%d/%d] %s",
aoqi@0 722 index, this_oop->method_type_index_at(index),
aoqi@0 723 signature->as_C_string());
aoqi@0 724 KlassHandle klass(THREAD, this_oop->pool_holder());
aoqi@0 725 Handle value = SystemDictionary::find_method_handle_type(signature, klass, THREAD);
aoqi@0 726 result_oop = value();
aoqi@0 727 if (HAS_PENDING_EXCEPTION) {
aoqi@0 728 save_and_throw_exception(this_oop, index, tag_value, CHECK_NULL);
aoqi@0 729 }
aoqi@0 730 break;
aoqi@0 731 }
aoqi@0 732
aoqi@0 733 case JVM_CONSTANT_Integer:
aoqi@0 734 assert(cache_index == _no_index_sentinel, "should not have been set");
aoqi@0 735 prim_value.i = this_oop->int_at(index);
aoqi@0 736 result_oop = java_lang_boxing_object::create(T_INT, &prim_value, CHECK_NULL);
aoqi@0 737 break;
aoqi@0 738
aoqi@0 739 case JVM_CONSTANT_Float:
aoqi@0 740 assert(cache_index == _no_index_sentinel, "should not have been set");
aoqi@0 741 prim_value.f = this_oop->float_at(index);
aoqi@0 742 result_oop = java_lang_boxing_object::create(T_FLOAT, &prim_value, CHECK_NULL);
aoqi@0 743 break;
aoqi@0 744
aoqi@0 745 case JVM_CONSTANT_Long:
aoqi@0 746 assert(cache_index == _no_index_sentinel, "should not have been set");
aoqi@0 747 prim_value.j = this_oop->long_at(index);
aoqi@0 748 result_oop = java_lang_boxing_object::create(T_LONG, &prim_value, CHECK_NULL);
aoqi@0 749 break;
aoqi@0 750
aoqi@0 751 case JVM_CONSTANT_Double:
aoqi@0 752 assert(cache_index == _no_index_sentinel, "should not have been set");
aoqi@0 753 prim_value.d = this_oop->double_at(index);
aoqi@0 754 result_oop = java_lang_boxing_object::create(T_DOUBLE, &prim_value, CHECK_NULL);
aoqi@0 755 break;
aoqi@0 756
aoqi@0 757 default:
aoqi@0 758 DEBUG_ONLY( tty->print_cr("*** %p: tag at CP[%d/%d] = %d",
aoqi@0 759 this_oop(), index, cache_index, tag_value) );
aoqi@0 760 assert(false, "unexpected constant tag");
aoqi@0 761 break;
aoqi@0 762 }
aoqi@0 763
aoqi@0 764 if (cache_index >= 0) {
aoqi@0 765 // Cache the oop here also.
aoqi@0 766 Handle result_handle(THREAD, result_oop);
aoqi@0 767 MonitorLockerEx ml(this_oop->lock()); // don't know if we really need this
aoqi@0 768 oop result = this_oop->resolved_references()->obj_at(cache_index);
aoqi@0 769 // Benign race condition: resolved_references may already be filled in while we were trying to lock.
aoqi@0 770 // The important thing here is that all threads pick up the same result.
aoqi@0 771 // It doesn't matter which racing thread wins, as long as only one
aoqi@0 772 // result is used by all threads, and all future queries.
aoqi@0 773 // That result may be either a resolved constant or a failure exception.
aoqi@0 774 if (result == NULL) {
aoqi@0 775 this_oop->resolved_references()->obj_at_put(cache_index, result_handle());
aoqi@0 776 return result_handle();
aoqi@0 777 } else {
aoqi@0 778 // Return the winning thread's result. This can be different than
aoqi@0 779 // result_handle() for MethodHandles.
aoqi@0 780 return result;
aoqi@0 781 }
aoqi@0 782 } else {
aoqi@0 783 return result_oop;
aoqi@0 784 }
aoqi@0 785 }
aoqi@0 786
aoqi@0 787 oop ConstantPool::uncached_string_at(int which, TRAPS) {
aoqi@0 788 Symbol* sym = unresolved_string_at(which);
aoqi@0 789 oop str = StringTable::intern(sym, CHECK_(NULL));
aoqi@0 790 assert(java_lang_String::is_instance(str), "must be string");
aoqi@0 791 return str;
aoqi@0 792 }
aoqi@0 793
aoqi@0 794
aoqi@0 795 oop ConstantPool::resolve_bootstrap_specifier_at_impl(constantPoolHandle this_oop, int index, TRAPS) {
aoqi@0 796 assert(this_oop->tag_at(index).is_invoke_dynamic(), "Corrupted constant pool");
aoqi@0 797
aoqi@0 798 Handle bsm;
aoqi@0 799 int argc;
aoqi@0 800 {
aoqi@0 801 // JVM_CONSTANT_InvokeDynamic is an ordered pair of [bootm, name&type], plus optional arguments
aoqi@0 802 // The bootm, being a JVM_CONSTANT_MethodHandle, has its own cache entry.
aoqi@0 803 // It is accompanied by the optional arguments.
aoqi@0 804 int bsm_index = this_oop->invoke_dynamic_bootstrap_method_ref_index_at(index);
aoqi@0 805 oop bsm_oop = this_oop->resolve_possibly_cached_constant_at(bsm_index, CHECK_NULL);
aoqi@0 806 if (!java_lang_invoke_MethodHandle::is_instance(bsm_oop)) {
aoqi@0 807 THROW_MSG_NULL(vmSymbols::java_lang_LinkageError(), "BSM not an MethodHandle");
aoqi@0 808 }
aoqi@0 809
aoqi@0 810 // Extract the optional static arguments.
aoqi@0 811 argc = this_oop->invoke_dynamic_argument_count_at(index);
aoqi@0 812 if (argc == 0) return bsm_oop;
aoqi@0 813
aoqi@0 814 bsm = Handle(THREAD, bsm_oop);
aoqi@0 815 }
aoqi@0 816
aoqi@0 817 objArrayHandle info;
aoqi@0 818 {
aoqi@0 819 objArrayOop info_oop = oopFactory::new_objArray(SystemDictionary::Object_klass(), 1+argc, CHECK_NULL);
aoqi@0 820 info = objArrayHandle(THREAD, info_oop);
aoqi@0 821 }
aoqi@0 822
aoqi@0 823 info->obj_at_put(0, bsm());
aoqi@0 824 for (int i = 0; i < argc; i++) {
aoqi@0 825 int arg_index = this_oop->invoke_dynamic_argument_index_at(index, i);
aoqi@0 826 oop arg_oop = this_oop->resolve_possibly_cached_constant_at(arg_index, CHECK_NULL);
aoqi@0 827 info->obj_at_put(1+i, arg_oop);
aoqi@0 828 }
aoqi@0 829
aoqi@0 830 return info();
aoqi@0 831 }
aoqi@0 832
aoqi@0 833 oop ConstantPool::string_at_impl(constantPoolHandle this_oop, int which, int obj_index, TRAPS) {
aoqi@0 834 // If the string has already been interned, this entry will be non-null
aoqi@0 835 oop str = this_oop->resolved_references()->obj_at(obj_index);
aoqi@0 836 if (str != NULL) return str;
aoqi@0 837 Symbol* sym = this_oop->unresolved_string_at(which);
aoqi@0 838 str = StringTable::intern(sym, CHECK_(NULL));
aoqi@0 839 this_oop->string_at_put(which, obj_index, str);
aoqi@0 840 assert(java_lang_String::is_instance(str), "must be string");
aoqi@0 841 return str;
aoqi@0 842 }
aoqi@0 843
aoqi@0 844
aoqi@0 845 bool ConstantPool::klass_name_at_matches(instanceKlassHandle k,
aoqi@0 846 int which) {
aoqi@0 847 // Names are interned, so we can compare Symbol*s directly
aoqi@0 848 Symbol* cp_name = klass_name_at(which);
aoqi@0 849 return (cp_name == k->name());
aoqi@0 850 }
aoqi@0 851
aoqi@0 852
aoqi@0 853 // Iterate over symbols and decrement ones which are Symbol*s.
aoqi@0 854 // This is done during GC so do not need to lock constantPool unless we
aoqi@0 855 // have per-thread safepoints.
aoqi@0 856 // Only decrement the UTF8 symbols. Unresolved classes and strings point to
aoqi@0 857 // these symbols but didn't increment the reference count.
aoqi@0 858 void ConstantPool::unreference_symbols() {
aoqi@0 859 for (int index = 1; index < length(); index++) { // Index 0 is unused
aoqi@0 860 constantTag tag = tag_at(index);
aoqi@0 861 if (tag.is_symbol()) {
aoqi@0 862 symbol_at(index)->decrement_refcount();
aoqi@0 863 }
aoqi@0 864 }
aoqi@0 865 }
aoqi@0 866
aoqi@0 867
aoqi@0 868 // Compare this constant pool's entry at index1 to the constant pool
aoqi@0 869 // cp2's entry at index2.
aoqi@0 870 bool ConstantPool::compare_entry_to(int index1, constantPoolHandle cp2,
aoqi@0 871 int index2, TRAPS) {
aoqi@0 872
aoqi@0 873 // The error tags are equivalent to non-error tags when comparing
aoqi@0 874 jbyte t1 = tag_at(index1).non_error_value();
aoqi@0 875 jbyte t2 = cp2->tag_at(index2).non_error_value();
aoqi@0 876
aoqi@0 877 if (t1 != t2) {
aoqi@0 878 // Not the same entry type so there is nothing else to check. Note
aoqi@0 879 // that this style of checking will consider resolved/unresolved
aoqi@0 880 // class pairs as different.
aoqi@0 881 // From the ConstantPool* API point of view, this is correct
aoqi@0 882 // behavior. See VM_RedefineClasses::merge_constant_pools() to see how this
aoqi@0 883 // plays out in the context of ConstantPool* merging.
aoqi@0 884 return false;
aoqi@0 885 }
aoqi@0 886
aoqi@0 887 switch (t1) {
aoqi@0 888 case JVM_CONSTANT_Class:
aoqi@0 889 {
aoqi@0 890 Klass* k1 = klass_at(index1, CHECK_false);
aoqi@0 891 Klass* k2 = cp2->klass_at(index2, CHECK_false);
aoqi@0 892 if (k1 == k2) {
aoqi@0 893 return true;
aoqi@0 894 }
aoqi@0 895 } break;
aoqi@0 896
aoqi@0 897 case JVM_CONSTANT_ClassIndex:
aoqi@0 898 {
aoqi@0 899 int recur1 = klass_index_at(index1);
aoqi@0 900 int recur2 = cp2->klass_index_at(index2);
aoqi@0 901 bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
aoqi@0 902 if (match) {
aoqi@0 903 return true;
aoqi@0 904 }
aoqi@0 905 } break;
aoqi@0 906
aoqi@0 907 case JVM_CONSTANT_Double:
aoqi@0 908 {
aoqi@0 909 jdouble d1 = double_at(index1);
aoqi@0 910 jdouble d2 = cp2->double_at(index2);
aoqi@0 911 if (d1 == d2) {
aoqi@0 912 return true;
aoqi@0 913 }
aoqi@0 914 } break;
aoqi@0 915
aoqi@0 916 case JVM_CONSTANT_Fieldref:
aoqi@0 917 case JVM_CONSTANT_InterfaceMethodref:
aoqi@0 918 case JVM_CONSTANT_Methodref:
aoqi@0 919 {
aoqi@0 920 int recur1 = uncached_klass_ref_index_at(index1);
aoqi@0 921 int recur2 = cp2->uncached_klass_ref_index_at(index2);
aoqi@0 922 bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
aoqi@0 923 if (match) {
aoqi@0 924 recur1 = uncached_name_and_type_ref_index_at(index1);
aoqi@0 925 recur2 = cp2->uncached_name_and_type_ref_index_at(index2);
aoqi@0 926 match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
aoqi@0 927 if (match) {
aoqi@0 928 return true;
aoqi@0 929 }
aoqi@0 930 }
aoqi@0 931 } break;
aoqi@0 932
aoqi@0 933 case JVM_CONSTANT_Float:
aoqi@0 934 {
aoqi@0 935 jfloat f1 = float_at(index1);
aoqi@0 936 jfloat f2 = cp2->float_at(index2);
aoqi@0 937 if (f1 == f2) {
aoqi@0 938 return true;
aoqi@0 939 }
aoqi@0 940 } break;
aoqi@0 941
aoqi@0 942 case JVM_CONSTANT_Integer:
aoqi@0 943 {
aoqi@0 944 jint i1 = int_at(index1);
aoqi@0 945 jint i2 = cp2->int_at(index2);
aoqi@0 946 if (i1 == i2) {
aoqi@0 947 return true;
aoqi@0 948 }
aoqi@0 949 } break;
aoqi@0 950
aoqi@0 951 case JVM_CONSTANT_Long:
aoqi@0 952 {
aoqi@0 953 jlong l1 = long_at(index1);
aoqi@0 954 jlong l2 = cp2->long_at(index2);
aoqi@0 955 if (l1 == l2) {
aoqi@0 956 return true;
aoqi@0 957 }
aoqi@0 958 } break;
aoqi@0 959
aoqi@0 960 case JVM_CONSTANT_NameAndType:
aoqi@0 961 {
aoqi@0 962 int recur1 = name_ref_index_at(index1);
aoqi@0 963 int recur2 = cp2->name_ref_index_at(index2);
aoqi@0 964 bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
aoqi@0 965 if (match) {
aoqi@0 966 recur1 = signature_ref_index_at(index1);
aoqi@0 967 recur2 = cp2->signature_ref_index_at(index2);
aoqi@0 968 match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
aoqi@0 969 if (match) {
aoqi@0 970 return true;
aoqi@0 971 }
aoqi@0 972 }
aoqi@0 973 } break;
aoqi@0 974
aoqi@0 975 case JVM_CONSTANT_StringIndex:
aoqi@0 976 {
aoqi@0 977 int recur1 = string_index_at(index1);
aoqi@0 978 int recur2 = cp2->string_index_at(index2);
aoqi@0 979 bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
aoqi@0 980 if (match) {
aoqi@0 981 return true;
aoqi@0 982 }
aoqi@0 983 } break;
aoqi@0 984
aoqi@0 985 case JVM_CONSTANT_UnresolvedClass:
aoqi@0 986 {
aoqi@0 987 Symbol* k1 = unresolved_klass_at(index1);
aoqi@0 988 Symbol* k2 = cp2->unresolved_klass_at(index2);
aoqi@0 989 if (k1 == k2) {
aoqi@0 990 return true;
aoqi@0 991 }
aoqi@0 992 } break;
aoqi@0 993
aoqi@0 994 case JVM_CONSTANT_MethodType:
aoqi@0 995 {
aoqi@0 996 int k1 = method_type_index_at_error_ok(index1);
aoqi@0 997 int k2 = cp2->method_type_index_at_error_ok(index2);
aoqi@0 998 bool match = compare_entry_to(k1, cp2, k2, CHECK_false);
aoqi@0 999 if (match) {
aoqi@0 1000 return true;
aoqi@0 1001 }
aoqi@0 1002 } break;
aoqi@0 1003
aoqi@0 1004 case JVM_CONSTANT_MethodHandle:
aoqi@0 1005 {
aoqi@0 1006 int k1 = method_handle_ref_kind_at_error_ok(index1);
aoqi@0 1007 int k2 = cp2->method_handle_ref_kind_at_error_ok(index2);
aoqi@0 1008 if (k1 == k2) {
aoqi@0 1009 int i1 = method_handle_index_at_error_ok(index1);
aoqi@0 1010 int i2 = cp2->method_handle_index_at_error_ok(index2);
aoqi@0 1011 bool match = compare_entry_to(i1, cp2, i2, CHECK_false);
aoqi@0 1012 if (match) {
aoqi@0 1013 return true;
aoqi@0 1014 }
aoqi@0 1015 }
aoqi@0 1016 } break;
aoqi@0 1017
aoqi@0 1018 case JVM_CONSTANT_InvokeDynamic:
aoqi@0 1019 {
aoqi@0 1020 int k1 = invoke_dynamic_name_and_type_ref_index_at(index1);
aoqi@0 1021 int k2 = cp2->invoke_dynamic_name_and_type_ref_index_at(index2);
aoqi@0 1022 int i1 = invoke_dynamic_bootstrap_specifier_index(index1);
aoqi@0 1023 int i2 = cp2->invoke_dynamic_bootstrap_specifier_index(index2);
aoqi@0 1024 // separate statements and variables because CHECK_false is used
aoqi@0 1025 bool match_entry = compare_entry_to(k1, cp2, k2, CHECK_false);
aoqi@0 1026 bool match_operand = compare_operand_to(i1, cp2, i2, CHECK_false);
aoqi@0 1027 return (match_entry && match_operand);
aoqi@0 1028 } break;
aoqi@0 1029
aoqi@0 1030 case JVM_CONSTANT_String:
aoqi@0 1031 {
aoqi@0 1032 Symbol* s1 = unresolved_string_at(index1);
aoqi@0 1033 Symbol* s2 = cp2->unresolved_string_at(index2);
aoqi@0 1034 if (s1 == s2) {
aoqi@0 1035 return true;
aoqi@0 1036 }
aoqi@0 1037 } break;
aoqi@0 1038
aoqi@0 1039 case JVM_CONSTANT_Utf8:
aoqi@0 1040 {
aoqi@0 1041 Symbol* s1 = symbol_at(index1);
aoqi@0 1042 Symbol* s2 = cp2->symbol_at(index2);
aoqi@0 1043 if (s1 == s2) {
aoqi@0 1044 return true;
aoqi@0 1045 }
aoqi@0 1046 } break;
aoqi@0 1047
aoqi@0 1048 // Invalid is used as the tag for the second constant pool entry
aoqi@0 1049 // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
aoqi@0 1050 // not be seen by itself.
aoqi@0 1051 case JVM_CONSTANT_Invalid: // fall through
aoqi@0 1052
aoqi@0 1053 default:
aoqi@0 1054 ShouldNotReachHere();
aoqi@0 1055 break;
aoqi@0 1056 }
aoqi@0 1057
aoqi@0 1058 return false;
aoqi@0 1059 } // end compare_entry_to()
aoqi@0 1060
aoqi@0 1061
aoqi@0 1062 // Resize the operands array with delta_len and delta_size.
aoqi@0 1063 // Used in RedefineClasses for CP merge.
aoqi@0 1064 void ConstantPool::resize_operands(int delta_len, int delta_size, TRAPS) {
aoqi@0 1065 int old_len = operand_array_length(operands());
aoqi@0 1066 int new_len = old_len + delta_len;
aoqi@0 1067 int min_len = (delta_len > 0) ? old_len : new_len;
aoqi@0 1068
aoqi@0 1069 int old_size = operands()->length();
aoqi@0 1070 int new_size = old_size + delta_size;
aoqi@0 1071 int min_size = (delta_size > 0) ? old_size : new_size;
aoqi@0 1072
aoqi@0 1073 ClassLoaderData* loader_data = pool_holder()->class_loader_data();
aoqi@0 1074 Array<u2>* new_ops = MetadataFactory::new_array<u2>(loader_data, new_size, CHECK);
aoqi@0 1075
aoqi@0 1076 // Set index in the resized array for existing elements only
aoqi@0 1077 for (int idx = 0; idx < min_len; idx++) {
aoqi@0 1078 int offset = operand_offset_at(idx); // offset in original array
aoqi@0 1079 operand_offset_at_put(new_ops, idx, offset + 2*delta_len); // offset in resized array
aoqi@0 1080 }
aoqi@0 1081 // Copy the bootstrap specifiers only
aoqi@0 1082 Copy::conjoint_memory_atomic(operands()->adr_at(2*old_len),
aoqi@0 1083 new_ops->adr_at(2*new_len),
aoqi@0 1084 (min_size - 2*min_len) * sizeof(u2));
aoqi@0 1085 // Explicitly deallocate old operands array.
aoqi@0 1086 // Note, it is not needed for 7u backport.
aoqi@0 1087 if ( operands() != NULL) { // the safety check
aoqi@0 1088 MetadataFactory::free_array<u2>(loader_data, operands());
aoqi@0 1089 }
aoqi@0 1090 set_operands(new_ops);
aoqi@0 1091 } // end resize_operands()
aoqi@0 1092
aoqi@0 1093
aoqi@0 1094 // Extend the operands array with the length and size of the ext_cp operands.
aoqi@0 1095 // Used in RedefineClasses for CP merge.
aoqi@0 1096 void ConstantPool::extend_operands(constantPoolHandle ext_cp, TRAPS) {
aoqi@0 1097 int delta_len = operand_array_length(ext_cp->operands());
aoqi@0 1098 if (delta_len == 0) {
aoqi@0 1099 return; // nothing to do
aoqi@0 1100 }
aoqi@0 1101 int delta_size = ext_cp->operands()->length();
aoqi@0 1102
aoqi@0 1103 assert(delta_len > 0 && delta_size > 0, "extended operands array must be bigger");
aoqi@0 1104
aoqi@0 1105 if (operand_array_length(operands()) == 0) {
aoqi@0 1106 ClassLoaderData* loader_data = pool_holder()->class_loader_data();
aoqi@0 1107 Array<u2>* new_ops = MetadataFactory::new_array<u2>(loader_data, delta_size, CHECK);
aoqi@0 1108 // The first element index defines the offset of second part
aoqi@0 1109 operand_offset_at_put(new_ops, 0, 2*delta_len); // offset in new array
aoqi@0 1110 set_operands(new_ops);
aoqi@0 1111 } else {
aoqi@0 1112 resize_operands(delta_len, delta_size, CHECK);
aoqi@0 1113 }
aoqi@0 1114
aoqi@0 1115 } // end extend_operands()
aoqi@0 1116
aoqi@0 1117
aoqi@0 1118 // Shrink the operands array to a smaller array with new_len length.
aoqi@0 1119 // Used in RedefineClasses for CP merge.
aoqi@0 1120 void ConstantPool::shrink_operands(int new_len, TRAPS) {
aoqi@0 1121 int old_len = operand_array_length(operands());
aoqi@0 1122 if (new_len == old_len) {
aoqi@0 1123 return; // nothing to do
aoqi@0 1124 }
aoqi@0 1125 assert(new_len < old_len, "shrunken operands array must be smaller");
aoqi@0 1126
aoqi@0 1127 int free_base = operand_next_offset_at(new_len - 1);
aoqi@0 1128 int delta_len = new_len - old_len;
aoqi@0 1129 int delta_size = 2*delta_len + free_base - operands()->length();
aoqi@0 1130
aoqi@0 1131 resize_operands(delta_len, delta_size, CHECK);
aoqi@0 1132
aoqi@0 1133 } // end shrink_operands()
aoqi@0 1134
aoqi@0 1135
aoqi@0 1136 void ConstantPool::copy_operands(constantPoolHandle from_cp,
aoqi@0 1137 constantPoolHandle to_cp,
aoqi@0 1138 TRAPS) {
aoqi@0 1139
aoqi@0 1140 int from_oplen = operand_array_length(from_cp->operands());
aoqi@0 1141 int old_oplen = operand_array_length(to_cp->operands());
aoqi@0 1142 if (from_oplen != 0) {
aoqi@0 1143 ClassLoaderData* loader_data = to_cp->pool_holder()->class_loader_data();
aoqi@0 1144 // append my operands to the target's operands array
aoqi@0 1145 if (old_oplen == 0) {
aoqi@0 1146 // Can't just reuse from_cp's operand list because of deallocation issues
aoqi@0 1147 int len = from_cp->operands()->length();
aoqi@0 1148 Array<u2>* new_ops = MetadataFactory::new_array<u2>(loader_data, len, CHECK);
aoqi@0 1149 Copy::conjoint_memory_atomic(
aoqi@0 1150 from_cp->operands()->adr_at(0), new_ops->adr_at(0), len * sizeof(u2));
aoqi@0 1151 to_cp->set_operands(new_ops);
aoqi@0 1152 } else {
aoqi@0 1153 int old_len = to_cp->operands()->length();
aoqi@0 1154 int from_len = from_cp->operands()->length();
aoqi@0 1155 int old_off = old_oplen * sizeof(u2);
aoqi@0 1156 int from_off = from_oplen * sizeof(u2);
aoqi@0 1157 // Use the metaspace for the destination constant pool
aoqi@0 1158 Array<u2>* new_operands = MetadataFactory::new_array<u2>(loader_data, old_len + from_len, CHECK);
aoqi@0 1159 int fillp = 0, len = 0;
aoqi@0 1160 // first part of dest
aoqi@0 1161 Copy::conjoint_memory_atomic(to_cp->operands()->adr_at(0),
aoqi@0 1162 new_operands->adr_at(fillp),
aoqi@0 1163 (len = old_off) * sizeof(u2));
aoqi@0 1164 fillp += len;
aoqi@0 1165 // first part of src
aoqi@0 1166 Copy::conjoint_memory_atomic(from_cp->operands()->adr_at(0),
aoqi@0 1167 new_operands->adr_at(fillp),
aoqi@0 1168 (len = from_off) * sizeof(u2));
aoqi@0 1169 fillp += len;
aoqi@0 1170 // second part of dest
aoqi@0 1171 Copy::conjoint_memory_atomic(to_cp->operands()->adr_at(old_off),
aoqi@0 1172 new_operands->adr_at(fillp),
aoqi@0 1173 (len = old_len - old_off) * sizeof(u2));
aoqi@0 1174 fillp += len;
aoqi@0 1175 // second part of src
aoqi@0 1176 Copy::conjoint_memory_atomic(from_cp->operands()->adr_at(from_off),
aoqi@0 1177 new_operands->adr_at(fillp),
aoqi@0 1178 (len = from_len - from_off) * sizeof(u2));
aoqi@0 1179 fillp += len;
aoqi@0 1180 assert(fillp == new_operands->length(), "");
aoqi@0 1181
aoqi@0 1182 // Adjust indexes in the first part of the copied operands array.
aoqi@0 1183 for (int j = 0; j < from_oplen; j++) {
aoqi@0 1184 int offset = operand_offset_at(new_operands, old_oplen + j);
aoqi@0 1185 assert(offset == operand_offset_at(from_cp->operands(), j), "correct copy");
aoqi@0 1186 offset += old_len; // every new tuple is preceded by old_len extra u2's
aoqi@0 1187 operand_offset_at_put(new_operands, old_oplen + j, offset);
aoqi@0 1188 }
aoqi@0 1189
aoqi@0 1190 // replace target operands array with combined array
aoqi@0 1191 to_cp->set_operands(new_operands);
aoqi@0 1192 }
aoqi@0 1193 }
aoqi@0 1194 } // end copy_operands()
aoqi@0 1195
aoqi@0 1196
aoqi@0 1197 // Copy this constant pool's entries at start_i to end_i (inclusive)
aoqi@0 1198 // to the constant pool to_cp's entries starting at to_i. A total of
aoqi@0 1199 // (end_i - start_i) + 1 entries are copied.
aoqi@0 1200 void ConstantPool::copy_cp_to_impl(constantPoolHandle from_cp, int start_i, int end_i,
aoqi@0 1201 constantPoolHandle to_cp, int to_i, TRAPS) {
aoqi@0 1202
aoqi@0 1203
aoqi@0 1204 int dest_i = to_i; // leave original alone for debug purposes
aoqi@0 1205
aoqi@0 1206 for (int src_i = start_i; src_i <= end_i; /* see loop bottom */ ) {
aoqi@0 1207 copy_entry_to(from_cp, src_i, to_cp, dest_i, CHECK);
aoqi@0 1208
aoqi@0 1209 switch (from_cp->tag_at(src_i).value()) {
aoqi@0 1210 case JVM_CONSTANT_Double:
aoqi@0 1211 case JVM_CONSTANT_Long:
aoqi@0 1212 // double and long take two constant pool entries
aoqi@0 1213 src_i += 2;
aoqi@0 1214 dest_i += 2;
aoqi@0 1215 break;
aoqi@0 1216
aoqi@0 1217 default:
aoqi@0 1218 // all others take one constant pool entry
aoqi@0 1219 src_i++;
aoqi@0 1220 dest_i++;
aoqi@0 1221 break;
aoqi@0 1222 }
aoqi@0 1223 }
aoqi@0 1224 copy_operands(from_cp, to_cp, CHECK);
aoqi@0 1225
aoqi@0 1226 } // end copy_cp_to_impl()
aoqi@0 1227
aoqi@0 1228
aoqi@0 1229 // Copy this constant pool's entry at from_i to the constant pool
aoqi@0 1230 // to_cp's entry at to_i.
aoqi@0 1231 void ConstantPool::copy_entry_to(constantPoolHandle from_cp, int from_i,
aoqi@0 1232 constantPoolHandle to_cp, int to_i,
aoqi@0 1233 TRAPS) {
aoqi@0 1234
aoqi@0 1235 int tag = from_cp->tag_at(from_i).value();
aoqi@0 1236 switch (tag) {
aoqi@0 1237 case JVM_CONSTANT_Class:
aoqi@0 1238 {
aoqi@0 1239 Klass* k = from_cp->klass_at(from_i, CHECK);
aoqi@0 1240 to_cp->klass_at_put(to_i, k);
aoqi@0 1241 } break;
aoqi@0 1242
aoqi@0 1243 case JVM_CONSTANT_ClassIndex:
aoqi@0 1244 {
aoqi@0 1245 jint ki = from_cp->klass_index_at(from_i);
aoqi@0 1246 to_cp->klass_index_at_put(to_i, ki);
aoqi@0 1247 } break;
aoqi@0 1248
aoqi@0 1249 case JVM_CONSTANT_Double:
aoqi@0 1250 {
aoqi@0 1251 jdouble d = from_cp->double_at(from_i);
aoqi@0 1252 to_cp->double_at_put(to_i, d);
aoqi@0 1253 // double takes two constant pool entries so init second entry's tag
aoqi@0 1254 to_cp->tag_at_put(to_i + 1, JVM_CONSTANT_Invalid);
aoqi@0 1255 } break;
aoqi@0 1256
aoqi@0 1257 case JVM_CONSTANT_Fieldref:
aoqi@0 1258 {
aoqi@0 1259 int class_index = from_cp->uncached_klass_ref_index_at(from_i);
aoqi@0 1260 int name_and_type_index = from_cp->uncached_name_and_type_ref_index_at(from_i);
aoqi@0 1261 to_cp->field_at_put(to_i, class_index, name_and_type_index);
aoqi@0 1262 } break;
aoqi@0 1263
aoqi@0 1264 case JVM_CONSTANT_Float:
aoqi@0 1265 {
aoqi@0 1266 jfloat f = from_cp->float_at(from_i);
aoqi@0 1267 to_cp->float_at_put(to_i, f);
aoqi@0 1268 } break;
aoqi@0 1269
aoqi@0 1270 case JVM_CONSTANT_Integer:
aoqi@0 1271 {
aoqi@0 1272 jint i = from_cp->int_at(from_i);
aoqi@0 1273 to_cp->int_at_put(to_i, i);
aoqi@0 1274 } break;
aoqi@0 1275
aoqi@0 1276 case JVM_CONSTANT_InterfaceMethodref:
aoqi@0 1277 {
aoqi@0 1278 int class_index = from_cp->uncached_klass_ref_index_at(from_i);
aoqi@0 1279 int name_and_type_index = from_cp->uncached_name_and_type_ref_index_at(from_i);
aoqi@0 1280 to_cp->interface_method_at_put(to_i, class_index, name_and_type_index);
aoqi@0 1281 } break;
aoqi@0 1282
aoqi@0 1283 case JVM_CONSTANT_Long:
aoqi@0 1284 {
aoqi@0 1285 jlong l = from_cp->long_at(from_i);
aoqi@0 1286 to_cp->long_at_put(to_i, l);
aoqi@0 1287 // long takes two constant pool entries so init second entry's tag
aoqi@0 1288 to_cp->tag_at_put(to_i + 1, JVM_CONSTANT_Invalid);
aoqi@0 1289 } break;
aoqi@0 1290
aoqi@0 1291 case JVM_CONSTANT_Methodref:
aoqi@0 1292 {
aoqi@0 1293 int class_index = from_cp->uncached_klass_ref_index_at(from_i);
aoqi@0 1294 int name_and_type_index = from_cp->uncached_name_and_type_ref_index_at(from_i);
aoqi@0 1295 to_cp->method_at_put(to_i, class_index, name_and_type_index);
aoqi@0 1296 } break;
aoqi@0 1297
aoqi@0 1298 case JVM_CONSTANT_NameAndType:
aoqi@0 1299 {
aoqi@0 1300 int name_ref_index = from_cp->name_ref_index_at(from_i);
aoqi@0 1301 int signature_ref_index = from_cp->signature_ref_index_at(from_i);
aoqi@0 1302 to_cp->name_and_type_at_put(to_i, name_ref_index, signature_ref_index);
aoqi@0 1303 } break;
aoqi@0 1304
aoqi@0 1305 case JVM_CONSTANT_StringIndex:
aoqi@0 1306 {
aoqi@0 1307 jint si = from_cp->string_index_at(from_i);
aoqi@0 1308 to_cp->string_index_at_put(to_i, si);
aoqi@0 1309 } break;
aoqi@0 1310
aoqi@0 1311 case JVM_CONSTANT_UnresolvedClass:
aoqi@0 1312 case JVM_CONSTANT_UnresolvedClassInError:
aoqi@0 1313 {
aoqi@0 1314 // Can be resolved after checking tag, so check the slot first.
aoqi@0 1315 CPSlot entry = from_cp->slot_at(from_i);
aoqi@0 1316 if (entry.is_resolved()) {
aoqi@0 1317 assert(entry.get_klass()->is_klass(), "must be");
aoqi@0 1318 // Already resolved
aoqi@0 1319 to_cp->klass_at_put(to_i, entry.get_klass());
aoqi@0 1320 } else {
aoqi@0 1321 to_cp->unresolved_klass_at_put(to_i, entry.get_symbol());
aoqi@0 1322 }
aoqi@0 1323 } break;
aoqi@0 1324
aoqi@0 1325 case JVM_CONSTANT_String:
aoqi@0 1326 {
aoqi@0 1327 Symbol* s = from_cp->unresolved_string_at(from_i);
aoqi@0 1328 to_cp->unresolved_string_at_put(to_i, s);
aoqi@0 1329 } break;
aoqi@0 1330
aoqi@0 1331 case JVM_CONSTANT_Utf8:
aoqi@0 1332 {
aoqi@0 1333 Symbol* s = from_cp->symbol_at(from_i);
aoqi@0 1334 // Need to increase refcount, the old one will be thrown away and deferenced
aoqi@0 1335 s->increment_refcount();
aoqi@0 1336 to_cp->symbol_at_put(to_i, s);
aoqi@0 1337 } break;
aoqi@0 1338
aoqi@0 1339 case JVM_CONSTANT_MethodType:
aoqi@0 1340 case JVM_CONSTANT_MethodTypeInError:
aoqi@0 1341 {
aoqi@0 1342 jint k = from_cp->method_type_index_at_error_ok(from_i);
aoqi@0 1343 to_cp->method_type_index_at_put(to_i, k);
aoqi@0 1344 } break;
aoqi@0 1345
aoqi@0 1346 case JVM_CONSTANT_MethodHandle:
aoqi@0 1347 case JVM_CONSTANT_MethodHandleInError:
aoqi@0 1348 {
aoqi@0 1349 int k1 = from_cp->method_handle_ref_kind_at_error_ok(from_i);
aoqi@0 1350 int k2 = from_cp->method_handle_index_at_error_ok(from_i);
aoqi@0 1351 to_cp->method_handle_index_at_put(to_i, k1, k2);
aoqi@0 1352 } break;
aoqi@0 1353
aoqi@0 1354 case JVM_CONSTANT_InvokeDynamic:
aoqi@0 1355 {
aoqi@0 1356 int k1 = from_cp->invoke_dynamic_bootstrap_specifier_index(from_i);
aoqi@0 1357 int k2 = from_cp->invoke_dynamic_name_and_type_ref_index_at(from_i);
aoqi@0 1358 k1 += operand_array_length(to_cp->operands()); // to_cp might already have operands
aoqi@0 1359 to_cp->invoke_dynamic_at_put(to_i, k1, k2);
aoqi@0 1360 } break;
aoqi@0 1361
aoqi@0 1362 // Invalid is used as the tag for the second constant pool entry
aoqi@0 1363 // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
aoqi@0 1364 // not be seen by itself.
aoqi@0 1365 case JVM_CONSTANT_Invalid: // fall through
aoqi@0 1366
aoqi@0 1367 default:
aoqi@0 1368 {
aoqi@0 1369 ShouldNotReachHere();
aoqi@0 1370 } break;
aoqi@0 1371 }
aoqi@0 1372 } // end copy_entry_to()
aoqi@0 1373
aoqi@0 1374
aoqi@0 1375 // Search constant pool search_cp for an entry that matches this
aoqi@0 1376 // constant pool's entry at pattern_i. Returns the index of a
aoqi@0 1377 // matching entry or zero (0) if there is no matching entry.
aoqi@0 1378 int ConstantPool::find_matching_entry(int pattern_i,
aoqi@0 1379 constantPoolHandle search_cp, TRAPS) {
aoqi@0 1380
aoqi@0 1381 // index zero (0) is not used
aoqi@0 1382 for (int i = 1; i < search_cp->length(); i++) {
aoqi@0 1383 bool found = compare_entry_to(pattern_i, search_cp, i, CHECK_0);
aoqi@0 1384 if (found) {
aoqi@0 1385 return i;
aoqi@0 1386 }
aoqi@0 1387 }
aoqi@0 1388
aoqi@0 1389 return 0; // entry not found; return unused index zero (0)
aoqi@0 1390 } // end find_matching_entry()
aoqi@0 1391
aoqi@0 1392
aoqi@0 1393 // Compare this constant pool's bootstrap specifier at idx1 to the constant pool
aoqi@0 1394 // cp2's bootstrap specifier at idx2.
aoqi@0 1395 bool ConstantPool::compare_operand_to(int idx1, constantPoolHandle cp2, int idx2, TRAPS) {
aoqi@0 1396 int k1 = operand_bootstrap_method_ref_index_at(idx1);
aoqi@0 1397 int k2 = cp2->operand_bootstrap_method_ref_index_at(idx2);
aoqi@0 1398 bool match = compare_entry_to(k1, cp2, k2, CHECK_false);
aoqi@0 1399
aoqi@0 1400 if (!match) {
aoqi@0 1401 return false;
aoqi@0 1402 }
aoqi@0 1403 int argc = operand_argument_count_at(idx1);
aoqi@0 1404 if (argc == cp2->operand_argument_count_at(idx2)) {
aoqi@0 1405 for (int j = 0; j < argc; j++) {
aoqi@0 1406 k1 = operand_argument_index_at(idx1, j);
aoqi@0 1407 k2 = cp2->operand_argument_index_at(idx2, j);
aoqi@0 1408 match = compare_entry_to(k1, cp2, k2, CHECK_false);
aoqi@0 1409 if (!match) {
aoqi@0 1410 return false;
aoqi@0 1411 }
aoqi@0 1412 }
aoqi@0 1413 return true; // got through loop; all elements equal
aoqi@0 1414 }
aoqi@0 1415 return false;
aoqi@0 1416 } // end compare_operand_to()
aoqi@0 1417
aoqi@0 1418 // Search constant pool search_cp for a bootstrap specifier that matches
aoqi@0 1419 // this constant pool's bootstrap specifier at pattern_i index.
aoqi@0 1420 // Return the index of a matching bootstrap specifier or (-1) if there is no match.
aoqi@0 1421 int ConstantPool::find_matching_operand(int pattern_i,
aoqi@0 1422 constantPoolHandle search_cp, int search_len, TRAPS) {
aoqi@0 1423 for (int i = 0; i < search_len; i++) {
aoqi@0 1424 bool found = compare_operand_to(pattern_i, search_cp, i, CHECK_(-1));
aoqi@0 1425 if (found) {
aoqi@0 1426 return i;
aoqi@0 1427 }
aoqi@0 1428 }
aoqi@0 1429 return -1; // bootstrap specifier not found; return unused index (-1)
aoqi@0 1430 } // end find_matching_operand()
aoqi@0 1431
aoqi@0 1432
aoqi@0 1433 #ifndef PRODUCT
aoqi@0 1434
aoqi@0 1435 const char* ConstantPool::printable_name_at(int which) {
aoqi@0 1436
aoqi@0 1437 constantTag tag = tag_at(which);
aoqi@0 1438
aoqi@0 1439 if (tag.is_string()) {
aoqi@0 1440 return string_at_noresolve(which);
aoqi@0 1441 } else if (tag.is_klass() || tag.is_unresolved_klass()) {
aoqi@0 1442 return klass_name_at(which)->as_C_string();
aoqi@0 1443 } else if (tag.is_symbol()) {
aoqi@0 1444 return symbol_at(which)->as_C_string();
aoqi@0 1445 }
aoqi@0 1446 return "";
aoqi@0 1447 }
aoqi@0 1448
aoqi@0 1449 #endif // PRODUCT
aoqi@0 1450
aoqi@0 1451
aoqi@0 1452 // JVMTI GetConstantPool support
aoqi@0 1453
aoqi@0 1454 // For debugging of constant pool
aoqi@0 1455 const bool debug_cpool = false;
aoqi@0 1456
aoqi@0 1457 #define DBG(code) do { if (debug_cpool) { (code); } } while(0)
aoqi@0 1458
aoqi@0 1459 static void print_cpool_bytes(jint cnt, u1 *bytes) {
aoqi@0 1460 const char* WARN_MSG = "Must not be such entry!";
aoqi@0 1461 jint size = 0;
aoqi@0 1462 u2 idx1, idx2;
aoqi@0 1463
aoqi@0 1464 for (jint idx = 1; idx < cnt; idx++) {
aoqi@0 1465 jint ent_size = 0;
aoqi@0 1466 u1 tag = *bytes++;
aoqi@0 1467 size++; // count tag
aoqi@0 1468
aoqi@0 1469 printf("const #%03d, tag: %02d ", idx, tag);
aoqi@0 1470 switch(tag) {
aoqi@0 1471 case JVM_CONSTANT_Invalid: {
aoqi@0 1472 printf("Invalid");
aoqi@0 1473 break;
aoqi@0 1474 }
aoqi@0 1475 case JVM_CONSTANT_Unicode: {
aoqi@0 1476 printf("Unicode %s", WARN_MSG);
aoqi@0 1477 break;
aoqi@0 1478 }
aoqi@0 1479 case JVM_CONSTANT_Utf8: {
aoqi@0 1480 u2 len = Bytes::get_Java_u2(bytes);
aoqi@0 1481 char str[128];
aoqi@0 1482 if (len > 127) {
aoqi@0 1483 len = 127;
aoqi@0 1484 }
aoqi@0 1485 strncpy(str, (char *) (bytes+2), len);
aoqi@0 1486 str[len] = '\0';
aoqi@0 1487 printf("Utf8 \"%s\"", str);
aoqi@0 1488 ent_size = 2 + len;
aoqi@0 1489 break;
aoqi@0 1490 }
aoqi@0 1491 case JVM_CONSTANT_Integer: {
aoqi@0 1492 u4 val = Bytes::get_Java_u4(bytes);
aoqi@0 1493 printf("int %d", *(int *) &val);
aoqi@0 1494 ent_size = 4;
aoqi@0 1495 break;
aoqi@0 1496 }
aoqi@0 1497 case JVM_CONSTANT_Float: {
aoqi@0 1498 u4 val = Bytes::get_Java_u4(bytes);
aoqi@0 1499 printf("float %5.3ff", *(float *) &val);
aoqi@0 1500 ent_size = 4;
aoqi@0 1501 break;
aoqi@0 1502 }
aoqi@0 1503 case JVM_CONSTANT_Long: {
aoqi@0 1504 u8 val = Bytes::get_Java_u8(bytes);
kevinw@9327 1505 printf("long " INT64_FORMAT, (int64_t) *(jlong *) &val);
aoqi@0 1506 ent_size = 8;
aoqi@0 1507 idx++; // Long takes two cpool slots
aoqi@0 1508 break;
aoqi@0 1509 }
aoqi@0 1510 case JVM_CONSTANT_Double: {
aoqi@0 1511 u8 val = Bytes::get_Java_u8(bytes);
aoqi@0 1512 printf("double %5.3fd", *(jdouble *)&val);
aoqi@0 1513 ent_size = 8;
aoqi@0 1514 idx++; // Double takes two cpool slots
aoqi@0 1515 break;
aoqi@0 1516 }
aoqi@0 1517 case JVM_CONSTANT_Class: {
aoqi@0 1518 idx1 = Bytes::get_Java_u2(bytes);
aoqi@0 1519 printf("class #%03d", idx1);
aoqi@0 1520 ent_size = 2;
aoqi@0 1521 break;
aoqi@0 1522 }
aoqi@0 1523 case JVM_CONSTANT_String: {
aoqi@0 1524 idx1 = Bytes::get_Java_u2(bytes);
aoqi@0 1525 printf("String #%03d", idx1);
aoqi@0 1526 ent_size = 2;
aoqi@0 1527 break;
aoqi@0 1528 }
aoqi@0 1529 case JVM_CONSTANT_Fieldref: {
aoqi@0 1530 idx1 = Bytes::get_Java_u2(bytes);
aoqi@0 1531 idx2 = Bytes::get_Java_u2(bytes+2);
aoqi@0 1532 printf("Field #%03d, #%03d", (int) idx1, (int) idx2);
aoqi@0 1533 ent_size = 4;
aoqi@0 1534 break;
aoqi@0 1535 }
aoqi@0 1536 case JVM_CONSTANT_Methodref: {
aoqi@0 1537 idx1 = Bytes::get_Java_u2(bytes);
aoqi@0 1538 idx2 = Bytes::get_Java_u2(bytes+2);
aoqi@0 1539 printf("Method #%03d, #%03d", idx1, idx2);
aoqi@0 1540 ent_size = 4;
aoqi@0 1541 break;
aoqi@0 1542 }
aoqi@0 1543 case JVM_CONSTANT_InterfaceMethodref: {
aoqi@0 1544 idx1 = Bytes::get_Java_u2(bytes);
aoqi@0 1545 idx2 = Bytes::get_Java_u2(bytes+2);
aoqi@0 1546 printf("InterfMethod #%03d, #%03d", idx1, idx2);
aoqi@0 1547 ent_size = 4;
aoqi@0 1548 break;
aoqi@0 1549 }
aoqi@0 1550 case JVM_CONSTANT_NameAndType: {
aoqi@0 1551 idx1 = Bytes::get_Java_u2(bytes);
aoqi@0 1552 idx2 = Bytes::get_Java_u2(bytes+2);
aoqi@0 1553 printf("NameAndType #%03d, #%03d", idx1, idx2);
aoqi@0 1554 ent_size = 4;
aoqi@0 1555 break;
aoqi@0 1556 }
aoqi@0 1557 case JVM_CONSTANT_ClassIndex: {
aoqi@0 1558 printf("ClassIndex %s", WARN_MSG);
aoqi@0 1559 break;
aoqi@0 1560 }
aoqi@0 1561 case JVM_CONSTANT_UnresolvedClass: {
aoqi@0 1562 printf("UnresolvedClass: %s", WARN_MSG);
aoqi@0 1563 break;
aoqi@0 1564 }
aoqi@0 1565 case JVM_CONSTANT_UnresolvedClassInError: {
aoqi@0 1566 printf("UnresolvedClassInErr: %s", WARN_MSG);
aoqi@0 1567 break;
aoqi@0 1568 }
aoqi@0 1569 case JVM_CONSTANT_StringIndex: {
aoqi@0 1570 printf("StringIndex: %s", WARN_MSG);
aoqi@0 1571 break;
aoqi@0 1572 }
aoqi@0 1573 }
aoqi@0 1574 printf(";\n");
aoqi@0 1575 bytes += ent_size;
aoqi@0 1576 size += ent_size;
aoqi@0 1577 }
aoqi@0 1578 printf("Cpool size: %d\n", size);
aoqi@0 1579 fflush(0);
aoqi@0 1580 return;
aoqi@0 1581 } /* end print_cpool_bytes */
aoqi@0 1582
aoqi@0 1583
aoqi@0 1584 // Returns size of constant pool entry.
aoqi@0 1585 jint ConstantPool::cpool_entry_size(jint idx) {
aoqi@0 1586 switch(tag_at(idx).value()) {
aoqi@0 1587 case JVM_CONSTANT_Invalid:
aoqi@0 1588 case JVM_CONSTANT_Unicode:
aoqi@0 1589 return 1;
aoqi@0 1590
aoqi@0 1591 case JVM_CONSTANT_Utf8:
aoqi@0 1592 return 3 + symbol_at(idx)->utf8_length();
aoqi@0 1593
aoqi@0 1594 case JVM_CONSTANT_Class:
aoqi@0 1595 case JVM_CONSTANT_String:
aoqi@0 1596 case JVM_CONSTANT_ClassIndex:
aoqi@0 1597 case JVM_CONSTANT_UnresolvedClass:
aoqi@0 1598 case JVM_CONSTANT_UnresolvedClassInError:
aoqi@0 1599 case JVM_CONSTANT_StringIndex:
aoqi@0 1600 case JVM_CONSTANT_MethodType:
aoqi@0 1601 case JVM_CONSTANT_MethodTypeInError:
aoqi@0 1602 return 3;
aoqi@0 1603
aoqi@0 1604 case JVM_CONSTANT_MethodHandle:
aoqi@0 1605 case JVM_CONSTANT_MethodHandleInError:
aoqi@0 1606 return 4; //tag, ref_kind, ref_index
aoqi@0 1607
aoqi@0 1608 case JVM_CONSTANT_Integer:
aoqi@0 1609 case JVM_CONSTANT_Float:
aoqi@0 1610 case JVM_CONSTANT_Fieldref:
aoqi@0 1611 case JVM_CONSTANT_Methodref:
aoqi@0 1612 case JVM_CONSTANT_InterfaceMethodref:
aoqi@0 1613 case JVM_CONSTANT_NameAndType:
aoqi@0 1614 return 5;
aoqi@0 1615
aoqi@0 1616 case JVM_CONSTANT_InvokeDynamic:
aoqi@0 1617 // u1 tag, u2 bsm, u2 nt
aoqi@0 1618 return 5;
aoqi@0 1619
aoqi@0 1620 case JVM_CONSTANT_Long:
aoqi@0 1621 case JVM_CONSTANT_Double:
aoqi@0 1622 return 9;
aoqi@0 1623 }
aoqi@0 1624 assert(false, "cpool_entry_size: Invalid constant pool entry tag");
aoqi@0 1625 return 1;
aoqi@0 1626 } /* end cpool_entry_size */
aoqi@0 1627
aoqi@0 1628
aoqi@0 1629 // SymbolHashMap is used to find a constant pool index from a string.
aoqi@0 1630 // This function fills in SymbolHashMaps, one for utf8s and one for
aoqi@0 1631 // class names, returns size of the cpool raw bytes.
aoqi@0 1632 jint ConstantPool::hash_entries_to(SymbolHashMap *symmap,
aoqi@0 1633 SymbolHashMap *classmap) {
aoqi@0 1634 jint size = 0;
aoqi@0 1635
aoqi@0 1636 for (u2 idx = 1; idx < length(); idx++) {
aoqi@0 1637 u2 tag = tag_at(idx).value();
aoqi@0 1638 size += cpool_entry_size(idx);
aoqi@0 1639
aoqi@0 1640 switch(tag) {
aoqi@0 1641 case JVM_CONSTANT_Utf8: {
aoqi@0 1642 Symbol* sym = symbol_at(idx);
aoqi@0 1643 symmap->add_entry(sym, idx);
aoqi@0 1644 DBG(printf("adding symbol entry %s = %d\n", sym->as_utf8(), idx));
aoqi@0 1645 break;
aoqi@0 1646 }
aoqi@0 1647 case JVM_CONSTANT_Class:
aoqi@0 1648 case JVM_CONSTANT_UnresolvedClass:
aoqi@0 1649 case JVM_CONSTANT_UnresolvedClassInError: {
aoqi@0 1650 Symbol* sym = klass_name_at(idx);
aoqi@0 1651 classmap->add_entry(sym, idx);
aoqi@0 1652 DBG(printf("adding class entry %s = %d\n", sym->as_utf8(), idx));
aoqi@0 1653 break;
aoqi@0 1654 }
aoqi@0 1655 case JVM_CONSTANT_Long:
aoqi@0 1656 case JVM_CONSTANT_Double: {
aoqi@0 1657 idx++; // Both Long and Double take two cpool slots
aoqi@0 1658 break;
aoqi@0 1659 }
aoqi@0 1660 }
aoqi@0 1661 }
aoqi@0 1662 return size;
aoqi@0 1663 } /* end hash_utf8_entries_to */
aoqi@0 1664
aoqi@0 1665
aoqi@0 1666 // Copy cpool bytes.
aoqi@0 1667 // Returns:
aoqi@0 1668 // 0, in case of OutOfMemoryError
aoqi@0 1669 // -1, in case of internal error
aoqi@0 1670 // > 0, count of the raw cpool bytes that have been copied
aoqi@0 1671 int ConstantPool::copy_cpool_bytes(int cpool_size,
aoqi@0 1672 SymbolHashMap* tbl,
aoqi@0 1673 unsigned char *bytes) {
aoqi@0 1674 u2 idx1, idx2;
aoqi@0 1675 jint size = 0;
aoqi@0 1676 jint cnt = length();
aoqi@0 1677 unsigned char *start_bytes = bytes;
aoqi@0 1678
aoqi@0 1679 for (jint idx = 1; idx < cnt; idx++) {
aoqi@0 1680 u1 tag = tag_at(idx).value();
aoqi@0 1681 jint ent_size = cpool_entry_size(idx);
aoqi@0 1682
aoqi@0 1683 assert(size + ent_size <= cpool_size, "Size mismatch");
aoqi@0 1684
aoqi@0 1685 *bytes = tag;
aoqi@0 1686 DBG(printf("#%03hd tag=%03hd, ", idx, tag));
aoqi@0 1687 switch(tag) {
aoqi@0 1688 case JVM_CONSTANT_Invalid: {
aoqi@0 1689 DBG(printf("JVM_CONSTANT_Invalid"));
aoqi@0 1690 break;
aoqi@0 1691 }
aoqi@0 1692 case JVM_CONSTANT_Unicode: {
aoqi@0 1693 assert(false, "Wrong constant pool tag: JVM_CONSTANT_Unicode");
aoqi@0 1694 DBG(printf("JVM_CONSTANT_Unicode"));
aoqi@0 1695 break;
aoqi@0 1696 }
aoqi@0 1697 case JVM_CONSTANT_Utf8: {
aoqi@0 1698 Symbol* sym = symbol_at(idx);
aoqi@0 1699 char* str = sym->as_utf8();
aoqi@0 1700 // Warning! It's crashing on x86 with len = sym->utf8_length()
aoqi@0 1701 int len = (int) strlen(str);
aoqi@0 1702 Bytes::put_Java_u2((address) (bytes+1), (u2) len);
aoqi@0 1703 for (int i = 0; i < len; i++) {
aoqi@0 1704 bytes[3+i] = (u1) str[i];
aoqi@0 1705 }
aoqi@0 1706 DBG(printf("JVM_CONSTANT_Utf8: %s ", str));
aoqi@0 1707 break;
aoqi@0 1708 }
aoqi@0 1709 case JVM_CONSTANT_Integer: {
aoqi@0 1710 jint val = int_at(idx);
aoqi@0 1711 Bytes::put_Java_u4((address) (bytes+1), *(u4*)&val);
aoqi@0 1712 break;
aoqi@0 1713 }
aoqi@0 1714 case JVM_CONSTANT_Float: {
aoqi@0 1715 jfloat val = float_at(idx);
aoqi@0 1716 Bytes::put_Java_u4((address) (bytes+1), *(u4*)&val);
aoqi@0 1717 break;
aoqi@0 1718 }
aoqi@0 1719 case JVM_CONSTANT_Long: {
aoqi@0 1720 jlong val = long_at(idx);
aoqi@0 1721 Bytes::put_Java_u8((address) (bytes+1), *(u8*)&val);
aoqi@0 1722 idx++; // Long takes two cpool slots
aoqi@0 1723 break;
aoqi@0 1724 }
aoqi@0 1725 case JVM_CONSTANT_Double: {
aoqi@0 1726 jdouble val = double_at(idx);
aoqi@0 1727 Bytes::put_Java_u8((address) (bytes+1), *(u8*)&val);
aoqi@0 1728 idx++; // Double takes two cpool slots
aoqi@0 1729 break;
aoqi@0 1730 }
aoqi@0 1731 case JVM_CONSTANT_Class:
aoqi@0 1732 case JVM_CONSTANT_UnresolvedClass:
aoqi@0 1733 case JVM_CONSTANT_UnresolvedClassInError: {
aoqi@0 1734 *bytes = JVM_CONSTANT_Class;
aoqi@0 1735 Symbol* sym = klass_name_at(idx);
aoqi@0 1736 idx1 = tbl->symbol_to_value(sym);
aoqi@0 1737 assert(idx1 != 0, "Have not found a hashtable entry");
aoqi@0 1738 Bytes::put_Java_u2((address) (bytes+1), idx1);
aoqi@0 1739 DBG(printf("JVM_CONSTANT_Class: idx=#%03hd, %s", idx1, sym->as_utf8()));
aoqi@0 1740 break;
aoqi@0 1741 }
aoqi@0 1742 case JVM_CONSTANT_String: {
aoqi@0 1743 *bytes = JVM_CONSTANT_String;
aoqi@0 1744 Symbol* sym = unresolved_string_at(idx);
aoqi@0 1745 idx1 = tbl->symbol_to_value(sym);
aoqi@0 1746 assert(idx1 != 0, "Have not found a hashtable entry");
aoqi@0 1747 Bytes::put_Java_u2((address) (bytes+1), idx1);
aoqi@0 1748 DBG(printf("JVM_CONSTANT_String: idx=#%03hd, %s", idx1, sym->as_utf8()));
aoqi@0 1749 break;
aoqi@0 1750 }
aoqi@0 1751 case JVM_CONSTANT_Fieldref:
aoqi@0 1752 case JVM_CONSTANT_Methodref:
aoqi@0 1753 case JVM_CONSTANT_InterfaceMethodref: {
aoqi@0 1754 idx1 = uncached_klass_ref_index_at(idx);
aoqi@0 1755 idx2 = uncached_name_and_type_ref_index_at(idx);
aoqi@0 1756 Bytes::put_Java_u2((address) (bytes+1), idx1);
aoqi@0 1757 Bytes::put_Java_u2((address) (bytes+3), idx2);
aoqi@0 1758 DBG(printf("JVM_CONSTANT_Methodref: %hd %hd", idx1, idx2));
aoqi@0 1759 break;
aoqi@0 1760 }
aoqi@0 1761 case JVM_CONSTANT_NameAndType: {
aoqi@0 1762 idx1 = name_ref_index_at(idx);
aoqi@0 1763 idx2 = signature_ref_index_at(idx);
aoqi@0 1764 Bytes::put_Java_u2((address) (bytes+1), idx1);
aoqi@0 1765 Bytes::put_Java_u2((address) (bytes+3), idx2);
aoqi@0 1766 DBG(printf("JVM_CONSTANT_NameAndType: %hd %hd", idx1, idx2));
aoqi@0 1767 break;
aoqi@0 1768 }
aoqi@0 1769 case JVM_CONSTANT_ClassIndex: {
aoqi@0 1770 *bytes = JVM_CONSTANT_Class;
aoqi@0 1771 idx1 = klass_index_at(idx);
aoqi@0 1772 Bytes::put_Java_u2((address) (bytes+1), idx1);
aoqi@0 1773 DBG(printf("JVM_CONSTANT_ClassIndex: %hd", idx1));
aoqi@0 1774 break;
aoqi@0 1775 }
aoqi@0 1776 case JVM_CONSTANT_StringIndex: {
aoqi@0 1777 *bytes = JVM_CONSTANT_String;
aoqi@0 1778 idx1 = string_index_at(idx);
aoqi@0 1779 Bytes::put_Java_u2((address) (bytes+1), idx1);
aoqi@0 1780 DBG(printf("JVM_CONSTANT_StringIndex: %hd", idx1));
aoqi@0 1781 break;
aoqi@0 1782 }
aoqi@0 1783 case JVM_CONSTANT_MethodHandle:
aoqi@0 1784 case JVM_CONSTANT_MethodHandleInError: {
aoqi@0 1785 *bytes = JVM_CONSTANT_MethodHandle;
aoqi@0 1786 int kind = method_handle_ref_kind_at_error_ok(idx);
aoqi@0 1787 idx1 = method_handle_index_at_error_ok(idx);
aoqi@0 1788 *(bytes+1) = (unsigned char) kind;
aoqi@0 1789 Bytes::put_Java_u2((address) (bytes+2), idx1);
aoqi@0 1790 DBG(printf("JVM_CONSTANT_MethodHandle: %d %hd", kind, idx1));
aoqi@0 1791 break;
aoqi@0 1792 }
aoqi@0 1793 case JVM_CONSTANT_MethodType:
aoqi@0 1794 case JVM_CONSTANT_MethodTypeInError: {
aoqi@0 1795 *bytes = JVM_CONSTANT_MethodType;
aoqi@0 1796 idx1 = method_type_index_at_error_ok(idx);
aoqi@0 1797 Bytes::put_Java_u2((address) (bytes+1), idx1);
aoqi@0 1798 DBG(printf("JVM_CONSTANT_MethodType: %hd", idx1));
aoqi@0 1799 break;
aoqi@0 1800 }
aoqi@0 1801 case JVM_CONSTANT_InvokeDynamic: {
aoqi@0 1802 *bytes = tag;
aoqi@0 1803 idx1 = extract_low_short_from_int(*int_at_addr(idx));
aoqi@0 1804 idx2 = extract_high_short_from_int(*int_at_addr(idx));
aoqi@0 1805 assert(idx2 == invoke_dynamic_name_and_type_ref_index_at(idx), "correct half of u4");
aoqi@0 1806 Bytes::put_Java_u2((address) (bytes+1), idx1);
aoqi@0 1807 Bytes::put_Java_u2((address) (bytes+3), idx2);
aoqi@0 1808 DBG(printf("JVM_CONSTANT_InvokeDynamic: %hd %hd", idx1, idx2));
aoqi@0 1809 break;
aoqi@0 1810 }
aoqi@0 1811 }
aoqi@0 1812 DBG(printf("\n"));
aoqi@0 1813 bytes += ent_size;
aoqi@0 1814 size += ent_size;
aoqi@0 1815 }
aoqi@0 1816 assert(size == cpool_size, "Size mismatch");
aoqi@0 1817
aoqi@0 1818 // Keep temorarily for debugging until it's stable.
aoqi@0 1819 DBG(print_cpool_bytes(cnt, start_bytes));
aoqi@0 1820 return (int)(bytes - start_bytes);
aoqi@0 1821 } /* end copy_cpool_bytes */
aoqi@0 1822
aoqi@0 1823 #undef DBG
aoqi@0 1824
aoqi@0 1825
aoqi@0 1826 void ConstantPool::set_on_stack(const bool value) {
aoqi@0 1827 if (value) {
stefank@7333 1828 int old_flags = *const_cast<volatile int *>(&_flags);
stefank@7333 1829 while ((old_flags & _on_stack) == 0) {
stefank@7333 1830 int new_flags = old_flags | _on_stack;
stefank@7333 1831 int result = Atomic::cmpxchg(new_flags, &_flags, old_flags);
stefank@7333 1832
stefank@7333 1833 if (result == old_flags) {
stefank@7333 1834 // Succeeded.
stefank@7333 1835 MetadataOnStackMark::record(this, Thread::current());
stefank@7333 1836 return;
stefank@7333 1837 }
stefank@7333 1838 old_flags = result;
stefank@7333 1839 }
aoqi@0 1840 } else {
stefank@7333 1841 // Clearing is done single-threadedly.
aoqi@0 1842 _flags &= ~_on_stack;
aoqi@0 1843 }
aoqi@0 1844 }
aoqi@0 1845
aoqi@0 1846 // JSR 292 support for patching constant pool oops after the class is linked and
aoqi@0 1847 // the oop array for resolved references are created.
aoqi@0 1848 // We can't do this during classfile parsing, which is how the other indexes are
aoqi@0 1849 // patched. The other patches are applied early for some error checking
aoqi@0 1850 // so only defer the pseudo_strings.
aoqi@0 1851 void ConstantPool::patch_resolved_references(
aoqi@0 1852 GrowableArray<Handle>* cp_patches) {
aoqi@0 1853 assert(EnableInvokeDynamic, "");
aoqi@0 1854 for (int index = 1; index < cp_patches->length(); index++) { // Index 0 is unused
aoqi@0 1855 Handle patch = cp_patches->at(index);
aoqi@0 1856 if (patch.not_null()) {
aoqi@0 1857 assert (tag_at(index).is_string(), "should only be string left");
aoqi@0 1858 // Patching a string means pre-resolving it.
aoqi@0 1859 // The spelling in the constant pool is ignored.
aoqi@0 1860 // The constant reference may be any object whatever.
aoqi@0 1861 // If it is not a real interned string, the constant is referred
aoqi@0 1862 // to as a "pseudo-string", and must be presented to the CP
aoqi@0 1863 // explicitly, because it may require scavenging.
aoqi@0 1864 int obj_index = cp_to_object_index(index);
aoqi@0 1865 pseudo_string_at_put(index, obj_index, patch());
aoqi@0 1866 DEBUG_ONLY(cp_patches->at_put(index, Handle());)
aoqi@0 1867 }
aoqi@0 1868 }
aoqi@0 1869 #ifdef ASSERT
aoqi@0 1870 // Ensure that all the patches have been used.
aoqi@0 1871 for (int index = 0; index < cp_patches->length(); index++) {
aoqi@0 1872 assert(cp_patches->at(index).is_null(),
aoqi@0 1873 err_msg("Unused constant pool patch at %d in class file %s",
aoqi@0 1874 index,
aoqi@0 1875 pool_holder()->external_name()));
aoqi@0 1876 }
aoqi@0 1877 #endif // ASSERT
aoqi@0 1878 }
aoqi@0 1879
aoqi@0 1880 #ifndef PRODUCT
aoqi@0 1881
aoqi@0 1882 // CompileTheWorld support. Preload all classes loaded references in the passed in constantpool
aoqi@0 1883 void ConstantPool::preload_and_initialize_all_classes(ConstantPool* obj, TRAPS) {
aoqi@0 1884 guarantee(obj->is_constantPool(), "object must be constant pool");
aoqi@0 1885 constantPoolHandle cp(THREAD, (ConstantPool*)obj);
aoqi@0 1886 guarantee(cp->pool_holder() != NULL, "must be fully loaded");
aoqi@0 1887
aoqi@0 1888 for (int i = 0; i< cp->length(); i++) {
aoqi@0 1889 if (cp->tag_at(i).is_unresolved_klass()) {
aoqi@0 1890 // This will force loading of the class
aoqi@0 1891 Klass* klass = cp->klass_at(i, CHECK);
aoqi@0 1892 if (klass->oop_is_instance()) {
aoqi@0 1893 // Force initialization of class
aoqi@0 1894 InstanceKlass::cast(klass)->initialize(CHECK);
aoqi@0 1895 }
aoqi@0 1896 }
aoqi@0 1897 }
aoqi@0 1898 }
aoqi@0 1899
aoqi@0 1900 #endif
aoqi@0 1901
aoqi@0 1902
aoqi@0 1903 // Printing
aoqi@0 1904
aoqi@0 1905 void ConstantPool::print_on(outputStream* st) const {
aoqi@0 1906 EXCEPTION_MARK;
aoqi@0 1907 assert(is_constantPool(), "must be constantPool");
aoqi@0 1908 st->print_cr("%s", internal_name());
aoqi@0 1909 if (flags() != 0) {
aoqi@0 1910 st->print(" - flags: 0x%x", flags());
aoqi@0 1911 if (has_preresolution()) st->print(" has_preresolution");
aoqi@0 1912 if (on_stack()) st->print(" on_stack");
aoqi@0 1913 st->cr();
aoqi@0 1914 }
aoqi@0 1915 if (pool_holder() != NULL) {
aoqi@0 1916 st->print_cr(" - holder: " INTPTR_FORMAT, pool_holder());
aoqi@0 1917 }
aoqi@0 1918 st->print_cr(" - cache: " INTPTR_FORMAT, cache());
aoqi@0 1919 st->print_cr(" - resolved_references: " INTPTR_FORMAT, (void *)resolved_references());
aoqi@0 1920 st->print_cr(" - reference_map: " INTPTR_FORMAT, reference_map());
aoqi@0 1921
aoqi@0 1922 for (int index = 1; index < length(); index++) { // Index 0 is unused
aoqi@0 1923 ((ConstantPool*)this)->print_entry_on(index, st);
aoqi@0 1924 switch (tag_at(index).value()) {
aoqi@0 1925 case JVM_CONSTANT_Long :
aoqi@0 1926 case JVM_CONSTANT_Double :
aoqi@0 1927 index++; // Skip entry following eigth-byte constant
aoqi@0 1928 }
aoqi@0 1929
aoqi@0 1930 }
aoqi@0 1931 st->cr();
aoqi@0 1932 }
aoqi@0 1933
aoqi@0 1934 // Print one constant pool entry
aoqi@0 1935 void ConstantPool::print_entry_on(const int index, outputStream* st) {
aoqi@0 1936 EXCEPTION_MARK;
aoqi@0 1937 st->print(" - %3d : ", index);
aoqi@0 1938 tag_at(index).print_on(st);
aoqi@0 1939 st->print(" : ");
aoqi@0 1940 switch (tag_at(index).value()) {
aoqi@0 1941 case JVM_CONSTANT_Class :
aoqi@0 1942 { Klass* k = klass_at(index, CATCH);
aoqi@0 1943 guarantee(k != NULL, "need klass");
aoqi@0 1944 k->print_value_on(st);
aoqi@0 1945 st->print(" {0x%lx}", (address)k);
aoqi@0 1946 }
aoqi@0 1947 break;
aoqi@0 1948 case JVM_CONSTANT_Fieldref :
aoqi@0 1949 case JVM_CONSTANT_Methodref :
aoqi@0 1950 case JVM_CONSTANT_InterfaceMethodref :
aoqi@0 1951 st->print("klass_index=%d", uncached_klass_ref_index_at(index));
aoqi@0 1952 st->print(" name_and_type_index=%d", uncached_name_and_type_ref_index_at(index));
aoqi@0 1953 break;
aoqi@0 1954 case JVM_CONSTANT_String :
aoqi@0 1955 if (is_pseudo_string_at(index)) {
aoqi@0 1956 oop anObj = pseudo_string_at(index);
aoqi@0 1957 anObj->print_value_on(st);
aoqi@0 1958 st->print(" {0x%lx}", (address)anObj);
aoqi@0 1959 } else {
aoqi@0 1960 unresolved_string_at(index)->print_value_on(st);
aoqi@0 1961 }
aoqi@0 1962 break;
aoqi@0 1963 case JVM_CONSTANT_Integer :
aoqi@0 1964 st->print("%d", int_at(index));
aoqi@0 1965 break;
aoqi@0 1966 case JVM_CONSTANT_Float :
aoqi@0 1967 st->print("%f", float_at(index));
aoqi@0 1968 break;
aoqi@0 1969 case JVM_CONSTANT_Long :
aoqi@0 1970 st->print_jlong(long_at(index));
aoqi@0 1971 break;
aoqi@0 1972 case JVM_CONSTANT_Double :
aoqi@0 1973 st->print("%lf", double_at(index));
aoqi@0 1974 break;
aoqi@0 1975 case JVM_CONSTANT_NameAndType :
aoqi@0 1976 st->print("name_index=%d", name_ref_index_at(index));
aoqi@0 1977 st->print(" signature_index=%d", signature_ref_index_at(index));
aoqi@0 1978 break;
aoqi@0 1979 case JVM_CONSTANT_Utf8 :
aoqi@0 1980 symbol_at(index)->print_value_on(st);
aoqi@0 1981 break;
aoqi@0 1982 case JVM_CONSTANT_UnresolvedClass : // fall-through
aoqi@0 1983 case JVM_CONSTANT_UnresolvedClassInError: {
aoqi@0 1984 // unresolved_klass_at requires lock or safe world.
aoqi@0 1985 CPSlot entry = slot_at(index);
aoqi@0 1986 if (entry.is_resolved()) {
aoqi@0 1987 entry.get_klass()->print_value_on(st);
aoqi@0 1988 } else {
aoqi@0 1989 entry.get_symbol()->print_value_on(st);
aoqi@0 1990 }
aoqi@0 1991 }
aoqi@0 1992 break;
aoqi@0 1993 case JVM_CONSTANT_MethodHandle :
aoqi@0 1994 case JVM_CONSTANT_MethodHandleInError :
aoqi@0 1995 st->print("ref_kind=%d", method_handle_ref_kind_at_error_ok(index));
aoqi@0 1996 st->print(" ref_index=%d", method_handle_index_at_error_ok(index));
aoqi@0 1997 break;
aoqi@0 1998 case JVM_CONSTANT_MethodType :
aoqi@0 1999 case JVM_CONSTANT_MethodTypeInError :
aoqi@0 2000 st->print("signature_index=%d", method_type_index_at_error_ok(index));
aoqi@0 2001 break;
aoqi@0 2002 case JVM_CONSTANT_InvokeDynamic :
aoqi@0 2003 {
aoqi@0 2004 st->print("bootstrap_method_index=%d", invoke_dynamic_bootstrap_method_ref_index_at(index));
aoqi@0 2005 st->print(" name_and_type_index=%d", invoke_dynamic_name_and_type_ref_index_at(index));
aoqi@0 2006 int argc = invoke_dynamic_argument_count_at(index);
aoqi@0 2007 if (argc > 0) {
aoqi@0 2008 for (int arg_i = 0; arg_i < argc; arg_i++) {
aoqi@0 2009 int arg = invoke_dynamic_argument_index_at(index, arg_i);
aoqi@0 2010 st->print((arg_i == 0 ? " arguments={%d" : ", %d"), arg);
aoqi@0 2011 }
aoqi@0 2012 st->print("}");
aoqi@0 2013 }
aoqi@0 2014 }
aoqi@0 2015 break;
aoqi@0 2016 default:
aoqi@0 2017 ShouldNotReachHere();
aoqi@0 2018 break;
aoqi@0 2019 }
aoqi@0 2020 st->cr();
aoqi@0 2021 }
aoqi@0 2022
aoqi@0 2023 void ConstantPool::print_value_on(outputStream* st) const {
aoqi@0 2024 assert(is_constantPool(), "must be constantPool");
aoqi@0 2025 st->print("constant pool [%d]", length());
aoqi@0 2026 if (has_preresolution()) st->print("/preresolution");
aoqi@0 2027 if (operands() != NULL) st->print("/operands[%d]", operands()->length());
aoqi@0 2028 print_address_on(st);
aoqi@0 2029 st->print(" for ");
aoqi@0 2030 pool_holder()->print_value_on(st);
aoqi@0 2031 if (pool_holder() != NULL) {
aoqi@0 2032 bool extra = (pool_holder()->constants() != this);
aoqi@0 2033 if (extra) st->print(" (extra)");
aoqi@0 2034 }
aoqi@0 2035 if (cache() != NULL) {
aoqi@0 2036 st->print(" cache=" PTR_FORMAT, cache());
aoqi@0 2037 }
aoqi@0 2038 }
aoqi@0 2039
aoqi@0 2040 #if INCLUDE_SERVICES
aoqi@0 2041 // Size Statistics
aoqi@0 2042 void ConstantPool::collect_statistics(KlassSizeStats *sz) const {
aoqi@0 2043 sz->_cp_all_bytes += (sz->_cp_bytes = sz->count(this));
aoqi@0 2044 sz->_cp_all_bytes += (sz->_cp_tags_bytes = sz->count_array(tags()));
aoqi@0 2045 sz->_cp_all_bytes += (sz->_cp_cache_bytes = sz->count(cache()));
aoqi@0 2046 sz->_cp_all_bytes += (sz->_cp_operands_bytes = sz->count_array(operands()));
aoqi@0 2047 sz->_cp_all_bytes += (sz->_cp_refmap_bytes = sz->count_array(reference_map()));
aoqi@0 2048
aoqi@0 2049 sz->_ro_bytes += sz->_cp_operands_bytes + sz->_cp_tags_bytes +
aoqi@0 2050 sz->_cp_refmap_bytes;
aoqi@0 2051 sz->_rw_bytes += sz->_cp_bytes + sz->_cp_cache_bytes;
aoqi@0 2052 }
aoqi@0 2053 #endif // INCLUDE_SERVICES
aoqi@0 2054
aoqi@0 2055 // Verification
aoqi@0 2056
aoqi@0 2057 void ConstantPool::verify_on(outputStream* st) {
aoqi@0 2058 guarantee(is_constantPool(), "object must be constant pool");
aoqi@0 2059 for (int i = 0; i< length(); i++) {
aoqi@0 2060 constantTag tag = tag_at(i);
aoqi@0 2061 CPSlot entry = slot_at(i);
aoqi@0 2062 if (tag.is_klass()) {
aoqi@0 2063 if (entry.is_resolved()) {
aoqi@0 2064 guarantee(entry.get_klass()->is_klass(), "should be klass");
aoqi@0 2065 }
aoqi@0 2066 } else if (tag.is_unresolved_klass()) {
aoqi@0 2067 if (entry.is_resolved()) {
aoqi@0 2068 guarantee(entry.get_klass()->is_klass(), "should be klass");
aoqi@0 2069 }
aoqi@0 2070 } else if (tag.is_symbol()) {
aoqi@0 2071 guarantee(entry.get_symbol()->refcount() != 0, "should have nonzero reference count");
aoqi@0 2072 } else if (tag.is_string()) {
aoqi@0 2073 guarantee(entry.get_symbol()->refcount() != 0, "should have nonzero reference count");
aoqi@0 2074 }
aoqi@0 2075 }
aoqi@0 2076 if (cache() != NULL) {
aoqi@0 2077 // Note: cache() can be NULL before a class is completely setup or
aoqi@0 2078 // in temporary constant pools used during constant pool merging
aoqi@0 2079 guarantee(cache()->is_constantPoolCache(), "should be constant pool cache");
aoqi@0 2080 }
aoqi@0 2081 if (pool_holder() != NULL) {
aoqi@0 2082 // Note: pool_holder() can be NULL in temporary constant pools
aoqi@0 2083 // used during constant pool merging
aoqi@0 2084 guarantee(pool_holder()->is_klass(), "should be klass");
aoqi@0 2085 }
aoqi@0 2086 }
aoqi@0 2087
aoqi@0 2088
aoqi@0 2089 void SymbolHashMap::add_entry(Symbol* sym, u2 value) {
aoqi@0 2090 char *str = sym->as_utf8();
aoqi@0 2091 unsigned int hash = compute_hash(str, sym->utf8_length());
aoqi@0 2092 unsigned int index = hash % table_size();
aoqi@0 2093
aoqi@0 2094 // check if already in map
aoqi@0 2095 // we prefer the first entry since it is more likely to be what was used in
aoqi@0 2096 // the class file
aoqi@0 2097 for (SymbolHashMapEntry *en = bucket(index); en != NULL; en = en->next()) {
aoqi@0 2098 assert(en->symbol() != NULL, "SymbolHashMapEntry symbol is NULL");
aoqi@0 2099 if (en->hash() == hash && en->symbol() == sym) {
aoqi@0 2100 return; // already there
aoqi@0 2101 }
aoqi@0 2102 }
aoqi@0 2103
aoqi@0 2104 SymbolHashMapEntry* entry = new SymbolHashMapEntry(hash, sym, value);
aoqi@0 2105 entry->set_next(bucket(index));
aoqi@0 2106 _buckets[index].set_entry(entry);
aoqi@0 2107 assert(entry->symbol() != NULL, "SymbolHashMapEntry symbol is NULL");
aoqi@0 2108 }
aoqi@0 2109
aoqi@0 2110 SymbolHashMapEntry* SymbolHashMap::find_entry(Symbol* sym) {
aoqi@0 2111 assert(sym != NULL, "SymbolHashMap::find_entry - symbol is NULL");
aoqi@0 2112 char *str = sym->as_utf8();
aoqi@0 2113 int len = sym->utf8_length();
aoqi@0 2114 unsigned int hash = SymbolHashMap::compute_hash(str, len);
aoqi@0 2115 unsigned int index = hash % table_size();
aoqi@0 2116 for (SymbolHashMapEntry *en = bucket(index); en != NULL; en = en->next()) {
aoqi@0 2117 assert(en->symbol() != NULL, "SymbolHashMapEntry symbol is NULL");
aoqi@0 2118 if (en->hash() == hash && en->symbol() == sym) {
aoqi@0 2119 return en;
aoqi@0 2120 }
aoqi@0 2121 }
aoqi@0 2122 return NULL;
aoqi@0 2123 }

mercurial