< prev index next >

src/hotspot/share/oops/constantPool.cpp

Print this page




  32 #include "classfile/vmSymbols.hpp"
  33 #include "interpreter/bootstrapInfo.hpp"
  34 #include "interpreter/linkResolver.hpp"
  35 #include "memory/allocation.inline.hpp"
  36 #include "memory/heapInspection.hpp"
  37 #include "memory/heapShared.hpp"
  38 #include "memory/metadataFactory.hpp"
  39 #include "memory/metaspaceClosure.hpp"
  40 #include "memory/metaspaceShared.hpp"
  41 #include "memory/oopFactory.hpp"
  42 #include "memory/resourceArea.hpp"
  43 #include "memory/universe.hpp"
  44 #include "oops/array.hpp"
  45 #include "oops/constantPool.inline.hpp"
  46 #include "oops/cpCache.inline.hpp"
  47 #include "oops/instanceKlass.hpp"
  48 #include "oops/objArrayKlass.hpp"
  49 #include "oops/objArrayOop.inline.hpp"
  50 #include "oops/oop.inline.hpp"
  51 #include "oops/typeArrayOop.inline.hpp"

  52 #include "runtime/fieldType.hpp"
  53 #include "runtime/handles.inline.hpp"
  54 #include "runtime/init.hpp"
  55 #include "runtime/javaCalls.hpp"
  56 #include "runtime/signature.hpp"
  57 #include "runtime/thread.inline.hpp"
  58 #include "runtime/vframe.inline.hpp"
  59 #include "utilities/copy.hpp"
  60 
  61 ConstantPool* ConstantPool::allocate(ClassLoaderData* loader_data, int length, TRAPS) {
  62   Array<u1>* tags = MetadataFactory::new_array<u1>(loader_data, length, 0, CHECK_NULL);
  63   int size = ConstantPool::size(length);
  64   return new (loader_data, size, MetaspaceObj::ConstantPoolType, THREAD) ConstantPool(tags);
  65 }
  66 
  67 #ifdef ASSERT
  68 
  69 // MetaspaceObj allocation invariant is calloc equivalent memory
  70 // simple verification of this here (JVM_CONSTANT_Invalid == 0 )
  71 static bool tag_array_is_zero_initialized(Array<u1>* tags) {


 195   assert(resolved_klasses() == NULL, "sanity");
 196   Array<Klass*>* rk = MetadataFactory::new_array<Klass*>(loader_data, num_klasses, CHECK);
 197   set_resolved_klasses(rk);
 198 }
 199 
 200 void ConstantPool::initialize_unresolved_klasses(ClassLoaderData* loader_data, TRAPS) {
 201   int len = length();
 202   int num_klasses = 0;
 203   for (int i = 1; i <len; i++) {
 204     switch (tag_at(i).value()) {
 205     case JVM_CONSTANT_ClassIndex:
 206       {
 207         const int class_index = klass_index_at(i);
 208         unresolved_klass_at_put(i, class_index, num_klasses++);
 209       }
 210       break;
 211 #ifndef PRODUCT
 212     case JVM_CONSTANT_Class:
 213     case JVM_CONSTANT_UnresolvedClass:
 214     case JVM_CONSTANT_UnresolvedClassInError:
 215       // All of these should have been reverted back to ClassIndex before calling
 216       // this function.
 217       ShouldNotReachHere();
 218 #endif
 219     }
 220   }
 221   allocate_resolved_klasses(loader_data, num_klasses, THREAD);
 222 }
 223 
 224 // Unsafe anonymous class support:
 225 void ConstantPool::klass_at_put(int class_index, int name_index, int resolved_klass_index, Klass* k, Symbol* name) {
 226   assert(is_within_bounds(class_index), "index out of bounds");
 227   assert(is_within_bounds(name_index), "index out of bounds");
 228   assert((resolved_klass_index & 0xffff0000) == 0, "must be");
 229   *int_at_addr(class_index) =
 230     build_int_from_shorts((jushort)resolved_klass_index, (jushort)name_index);
 231 
 232   symbol_at_put(name_index, name);
 233   name->increment_refcount();
 234   Klass** adr = resolved_klasses()->adr_at(resolved_klass_index);
 235   OrderAccess::release_store(adr, k);
 236 
 237   // The interpreter assumes when the tag is stored, the klass is resolved
 238   // and the Klass* non-NULL, so we need hardware store ordering here.

 239   if (k != NULL) {
 240     release_tag_at_put(class_index, JVM_CONSTANT_Class);
 241   } else {
 242     release_tag_at_put(class_index, JVM_CONSTANT_UnresolvedClass);
 243   }
 244 }
 245 
 246 // Unsafe anonymous class support:
 247 void ConstantPool::klass_at_put(int class_index, Klass* k) {
 248   assert(k != NULL, "must be valid klass");
 249   CPKlassSlot kslot = klass_slot_at(class_index);
 250   int resolved_klass_index = kslot.resolved_klass_index();
 251   Klass** adr = resolved_klasses()->adr_at(resolved_klass_index);
 252   OrderAccess::release_store(adr, k);
 253 
 254   // The interpreter assumes when the tag is stored, the klass is resolved
 255   // and the Klass* non-NULL, so we need hardware store ordering here.

 256   release_tag_at_put(class_index, JVM_CONSTANT_Class);
 257 }
 258 
 259 #if INCLUDE_CDS_JAVA_HEAP
 260 // Archive the resolved references
 261 void ConstantPool::archive_resolved_references(Thread* THREAD) {
 262   if (_cache == NULL) {
 263     return; // nothing to do
 264   }
 265 
 266   InstanceKlass *ik = pool_holder();
 267   if (!(ik->is_shared_boot_class() || ik->is_shared_platform_class() ||
 268         ik->is_shared_app_class())) {
 269     // Archiving resolved references for classes from non-builtin loaders
 270     // is not yet supported.
 271     set_resolved_references(NULL);
 272     return;
 273   }
 274 
 275   objArrayOop rr = resolved_references();


 436       Symbol* s = vfst.method()->method_holder()->source_file_name();
 437       if (s != NULL) {
 438         source_file = s->as_C_string();
 439       }
 440     }
 441   }
 442   if (k != this_cp->pool_holder()) {
 443     // only print something if the classes are different
 444     if (source_file != NULL) {
 445       log_debug(class, resolve)("%s %s %s:%d",
 446                  this_cp->pool_holder()->external_name(),
 447                  k->external_name(), source_file, line_number);
 448     } else {
 449       log_debug(class, resolve)("%s %s",
 450                  this_cp->pool_holder()->external_name(),
 451                  k->external_name());
 452     }
 453   }
 454 }
 455 






 456 Klass* ConstantPool::klass_at_impl(const constantPoolHandle& this_cp, int which,
 457                                    bool save_resolution_error, TRAPS) {
 458   assert(THREAD->is_Java_thread(), "must be a Java thread");
 459   JavaThread* javaThread = (JavaThread*)THREAD;
 460 
 461   // A resolved constantPool entry will contain a Klass*, otherwise a Symbol*.
 462   // It is not safe to rely on the tag bit's here, since we don't have a lock, and
 463   // the entry and tag is not updated atomicly.
 464   CPKlassSlot kslot = this_cp->klass_slot_at(which);
 465   int resolved_klass_index = kslot.resolved_klass_index();
 466   int name_index = kslot.name_index();
 467   assert(this_cp->tag_at(name_index).is_symbol(), "sanity");
 468 
 469   Klass* klass = this_cp->resolved_klasses()->at(resolved_klass_index);
 470   if (klass != NULL) {
 471     return klass;
 472   }
 473 
 474   // This tag doesn't change back to unresolved class unless at a safepoint.
 475   if (this_cp->tag_at(which).is_unresolved_klass_in_error()) {
 476     // The original attempt to resolve this constant pool entry failed so find the
 477     // class of the original error and throw another error of the same class
 478     // (JVMS 5.4.3).
 479     // If there is a detail message, pass that detail message to the error.
 480     // The JVMS does not strictly require us to duplicate the same detail message,
 481     // or any internal exception fields such as cause or stacktrace.  But since the
 482     // detail message is often a class name or other literal string, we will repeat it
 483     // if we can find it in the symbol table.
 484     throw_resolution_error(this_cp, which, CHECK_NULL);
 485     ShouldNotReachHere();
 486   }
 487 
 488   Handle mirror_handle;
 489   Symbol* name = this_cp->symbol_at(name_index);





 490   Handle loader (THREAD, this_cp->pool_holder()->class_loader());
 491   Handle protection_domain (THREAD, this_cp->pool_holder()->protection_domain());
 492 
 493   Klass* k;
 494   {
 495     // Turn off the single stepping while doing class resolution
 496     JvmtiHideSingleStepping jhss(javaThread);
 497     k = SystemDictionary::resolve_or_fail(name, loader, protection_domain, true, THREAD);
 498   } //  JvmtiHideSingleStepping jhss(javaThread);



 499 
 500   if (!HAS_PENDING_EXCEPTION) {
 501     // preserve the resolved klass from unloading
 502     mirror_handle = Handle(THREAD, k->java_mirror());
 503     // Do access check for klasses
 504     verify_constant_pool_resolve(this_cp, k, THREAD);
 505   }
 506 
















 507   // Failed to resolve class. We must record the errors so that subsequent attempts
 508   // to resolve this constant pool entry fail with the same error (JVMS 5.4.3).
 509   if (HAS_PENDING_EXCEPTION) {
 510     if (save_resolution_error) {
 511       save_and_throw_exception(this_cp, which, constantTag(JVM_CONSTANT_UnresolvedClass), CHECK_NULL);
 512       // If CHECK_NULL above doesn't return the exception, that means that
 513       // some other thread has beaten us and has resolved the class.
 514       // To preserve old behavior, we return the resolved class.
 515       klass = this_cp->resolved_klasses()->at(resolved_klass_index);
 516       assert(klass != NULL, "must be resolved if exception was cleared");
 517       return klass;
 518     } else {
 519       return NULL;  // return the pending exception
 520     }
 521   }
 522 
 523   // logging for class+resolve.
 524   if (log_is_enabled(Debug, class, resolve)){
 525     trace_class_resolution(this_cp, k);
 526   }
 527   Klass** adr = this_cp->resolved_klasses()->adr_at(resolved_klass_index);
 528   OrderAccess::release_store(adr, k);
 529   // The interpreter assumes when the tag is stored, the klass is resolved
 530   // and the Klass* stored in _resolved_klasses is non-NULL, so we need
 531   // hardware store ordering here.
 532   this_cp->release_tag_at_put(which, JVM_CONSTANT_Class);




 533   return k;
 534 }
 535 
 536 
 537 // Does not update ConstantPool* - to avoid any exception throwing. Used
 538 // by compiler and exception handling.  Also used to avoid classloads for
 539 // instanceof operations. Returns NULL if the class has not been loaded or
 540 // if the verification of constant pool failed
 541 Klass* ConstantPool::klass_at_if_loaded(const constantPoolHandle& this_cp, int which) {
 542   CPKlassSlot kslot = this_cp->klass_slot_at(which);
 543   int resolved_klass_index = kslot.resolved_klass_index();
 544   int name_index = kslot.name_index();
 545   assert(this_cp->tag_at(name_index).is_symbol(), "sanity");
 546 
 547   Klass* k = this_cp->resolved_klasses()->at(resolved_klass_index);
 548   if (k != NULL) {
 549     return k;
 550   } else {
 551     Thread *thread = Thread::current();
 552     Symbol* name = this_cp->symbol_at(name_index);


1829       case JVM_CONSTANT_Long: {
1830         u8 val = Bytes::get_Java_u8(bytes);
1831         printf("long         " INT64_FORMAT, (int64_t) *(jlong *) &val);
1832         ent_size = 8;
1833         idx++; // Long takes two cpool slots
1834         break;
1835       }
1836       case JVM_CONSTANT_Double: {
1837         u8 val = Bytes::get_Java_u8(bytes);
1838         printf("double       %5.3fd", *(jdouble *)&val);
1839         ent_size = 8;
1840         idx++; // Double takes two cpool slots
1841         break;
1842       }
1843       case JVM_CONSTANT_Class: {
1844         idx1 = Bytes::get_Java_u2(bytes);
1845         printf("class        #%03d", idx1);
1846         ent_size = 2;
1847         break;
1848       }






1849       case JVM_CONSTANT_String: {
1850         idx1 = Bytes::get_Java_u2(bytes);
1851         printf("String       #%03d", idx1);
1852         ent_size = 2;
1853         break;
1854       }
1855       case JVM_CONSTANT_Fieldref: {
1856         idx1 = Bytes::get_Java_u2(bytes);
1857         idx2 = Bytes::get_Java_u2(bytes+2);
1858         printf("Field        #%03d, #%03d", (int) idx1, (int) idx2);
1859         ent_size = 4;
1860         break;
1861       }
1862       case JVM_CONSTANT_Methodref: {
1863         idx1 = Bytes::get_Java_u2(bytes);
1864         idx2 = Bytes::get_Java_u2(bytes+2);
1865         printf("Method       #%03d, #%03d", idx1, idx2);
1866         ent_size = 4;
1867         break;
1868       }


1871         idx2 = Bytes::get_Java_u2(bytes+2);
1872         printf("InterfMethod #%03d, #%03d", idx1, idx2);
1873         ent_size = 4;
1874         break;
1875       }
1876       case JVM_CONSTANT_NameAndType: {
1877         idx1 = Bytes::get_Java_u2(bytes);
1878         idx2 = Bytes::get_Java_u2(bytes+2);
1879         printf("NameAndType  #%03d, #%03d", idx1, idx2);
1880         ent_size = 4;
1881         break;
1882       }
1883       case JVM_CONSTANT_ClassIndex: {
1884         printf("ClassIndex  %s", WARN_MSG);
1885         break;
1886       }
1887       case JVM_CONSTANT_UnresolvedClass: {
1888         printf("UnresolvedClass: %s", WARN_MSG);
1889         break;
1890       }




1891       case JVM_CONSTANT_UnresolvedClassInError: {
1892         printf("UnresolvedClassInErr: %s", WARN_MSG);
1893         break;
1894       }
1895       case JVM_CONSTANT_StringIndex: {
1896         printf("StringIndex: %s", WARN_MSG);
1897         break;
1898       }
1899     }
1900     printf(";\n");
1901     bytes += ent_size;
1902     size  += ent_size;
1903   }
1904   printf("Cpool size: %d\n", size);
1905   fflush(0);
1906   return;
1907 } /* end print_cpool_bytes */
1908 
1909 
1910 // Returns size of constant pool entry.


2042       case JVM_CONSTANT_Float: {
2043         jfloat val = float_at(idx);
2044         Bytes::put_Java_u4((address) (bytes+1), *(u4*)&val);
2045         break;
2046       }
2047       case JVM_CONSTANT_Long: {
2048         jlong val = long_at(idx);
2049         Bytes::put_Java_u8((address) (bytes+1), *(u8*)&val);
2050         idx++;             // Long takes two cpool slots
2051         break;
2052       }
2053       case JVM_CONSTANT_Double: {
2054         jdouble val = double_at(idx);
2055         Bytes::put_Java_u8((address) (bytes+1), *(u8*)&val);
2056         idx++;             // Double takes two cpool slots
2057         break;
2058       }
2059       case JVM_CONSTANT_Class:
2060       case JVM_CONSTANT_UnresolvedClass:
2061       case JVM_CONSTANT_UnresolvedClassInError: {

2062         *bytes = JVM_CONSTANT_Class;
2063         Symbol* sym = klass_name_at(idx);
2064         idx1 = tbl->symbol_to_value(sym);
2065         assert(idx1 != 0, "Have not found a hashtable entry");
2066         Bytes::put_Java_u2((address) (bytes+1), idx1);
2067         DBG(printf("JVM_CONSTANT_Class: idx=#%03hd, %s", idx1, sym->as_utf8()));
2068         break;
2069       }
2070       case JVM_CONSTANT_String: {
2071         *bytes = JVM_CONSTANT_String;
2072         Symbol* sym = unresolved_string_at(idx);
2073         idx1 = tbl->symbol_to_value(sym);
2074         assert(idx1 != 0, "Have not found a hashtable entry");
2075         Bytes::put_Java_u2((address) (bytes+1), idx1);
2076         DBG(printf("JVM_CONSTANT_String: idx=#%03hd, %s", idx1, sym->as_utf8()));
2077         break;
2078       }
2079       case JVM_CONSTANT_Fieldref:
2080       case JVM_CONSTANT_Methodref:
2081       case JVM_CONSTANT_InterfaceMethodref: {




  32 #include "classfile/vmSymbols.hpp"
  33 #include "interpreter/bootstrapInfo.hpp"
  34 #include "interpreter/linkResolver.hpp"
  35 #include "memory/allocation.inline.hpp"
  36 #include "memory/heapInspection.hpp"
  37 #include "memory/heapShared.hpp"
  38 #include "memory/metadataFactory.hpp"
  39 #include "memory/metaspaceClosure.hpp"
  40 #include "memory/metaspaceShared.hpp"
  41 #include "memory/oopFactory.hpp"
  42 #include "memory/resourceArea.hpp"
  43 #include "memory/universe.hpp"
  44 #include "oops/array.hpp"
  45 #include "oops/constantPool.inline.hpp"
  46 #include "oops/cpCache.inline.hpp"
  47 #include "oops/instanceKlass.hpp"
  48 #include "oops/objArrayKlass.hpp"
  49 #include "oops/objArrayOop.inline.hpp"
  50 #include "oops/oop.inline.hpp"
  51 #include "oops/typeArrayOop.inline.hpp"
  52 #include "oops/valueArrayKlass.hpp"
  53 #include "runtime/fieldType.hpp"
  54 #include "runtime/handles.inline.hpp"
  55 #include "runtime/init.hpp"
  56 #include "runtime/javaCalls.hpp"
  57 #include "runtime/signature.hpp"
  58 #include "runtime/thread.inline.hpp"
  59 #include "runtime/vframe.inline.hpp"
  60 #include "utilities/copy.hpp"
  61 
  62 ConstantPool* ConstantPool::allocate(ClassLoaderData* loader_data, int length, TRAPS) {
  63   Array<u1>* tags = MetadataFactory::new_array<u1>(loader_data, length, 0, CHECK_NULL);
  64   int size = ConstantPool::size(length);
  65   return new (loader_data, size, MetaspaceObj::ConstantPoolType, THREAD) ConstantPool(tags);
  66 }
  67 
  68 #ifdef ASSERT
  69 
  70 // MetaspaceObj allocation invariant is calloc equivalent memory
  71 // simple verification of this here (JVM_CONSTANT_Invalid == 0 )
  72 static bool tag_array_is_zero_initialized(Array<u1>* tags) {


 196   assert(resolved_klasses() == NULL, "sanity");
 197   Array<Klass*>* rk = MetadataFactory::new_array<Klass*>(loader_data, num_klasses, CHECK);
 198   set_resolved_klasses(rk);
 199 }
 200 
 201 void ConstantPool::initialize_unresolved_klasses(ClassLoaderData* loader_data, TRAPS) {
 202   int len = length();
 203   int num_klasses = 0;
 204   for (int i = 1; i <len; i++) {
 205     switch (tag_at(i).value()) {
 206     case JVM_CONSTANT_ClassIndex:
 207       {
 208         const int class_index = klass_index_at(i);
 209         unresolved_klass_at_put(i, class_index, num_klasses++);
 210       }
 211       break;
 212 #ifndef PRODUCT
 213     case JVM_CONSTANT_Class:
 214     case JVM_CONSTANT_UnresolvedClass:
 215     case JVM_CONSTANT_UnresolvedClassInError:
 216       // All of these should have been reverted back to Unresolved before calling
 217       // this function.
 218       ShouldNotReachHere();
 219 #endif
 220     }
 221   }
 222   allocate_resolved_klasses(loader_data, num_klasses, THREAD);
 223 }
 224 
 225 // Unsafe anonymous class support:
 226 void ConstantPool::klass_at_put(int class_index, int name_index, int resolved_klass_index, Klass* k, Symbol* name) {
 227   assert(is_within_bounds(class_index), "index out of bounds");
 228   assert(is_within_bounds(name_index), "index out of bounds");
 229   assert((resolved_klass_index & 0xffff0000) == 0, "must be");
 230   *int_at_addr(class_index) =
 231     build_int_from_shorts((jushort)resolved_klass_index, (jushort)name_index);
 232 
 233   symbol_at_put(name_index, name);
 234   name->increment_refcount();
 235   Klass** adr = resolved_klasses()->adr_at(resolved_klass_index);
 236   OrderAccess::release_store(adr, k);
 237 
 238   // The interpreter assumes when the tag is stored, the klass is resolved
 239   // and the Klass* non-NULL, so we need hardware store ordering here.
 240   jbyte qdesc_bit = (name->is_Q_signature()) ? (jbyte) JVM_CONSTANT_QDescBit : 0;
 241   if (k != NULL) {
 242     release_tag_at_put(class_index, JVM_CONSTANT_Class | qdesc_bit);
 243   } else {
 244     release_tag_at_put(class_index, JVM_CONSTANT_UnresolvedClass | qdesc_bit);
 245   }
 246 }
 247 
 248 // Unsafe anonymous class support:
 249 void ConstantPool::klass_at_put(int class_index, Klass* k) {
 250   assert(k != NULL, "must be valid klass");
 251   CPKlassSlot kslot = klass_slot_at(class_index);
 252   int resolved_klass_index = kslot.resolved_klass_index();
 253   Klass** adr = resolved_klasses()->adr_at(resolved_klass_index);
 254   OrderAccess::release_store(adr, k);
 255 
 256   // The interpreter assumes when the tag is stored, the klass is resolved
 257   // and the Klass* non-NULL, so we need hardware store ordering here.
 258   assert(!k->name()->is_Q_signature(), "Q-type without JVM_CONSTANT_QDescBit");
 259   release_tag_at_put(class_index, JVM_CONSTANT_Class);
 260 }
 261 
 262 #if INCLUDE_CDS_JAVA_HEAP
 263 // Archive the resolved references
 264 void ConstantPool::archive_resolved_references(Thread* THREAD) {
 265   if (_cache == NULL) {
 266     return; // nothing to do
 267   }
 268 
 269   InstanceKlass *ik = pool_holder();
 270   if (!(ik->is_shared_boot_class() || ik->is_shared_platform_class() ||
 271         ik->is_shared_app_class())) {
 272     // Archiving resolved references for classes from non-builtin loaders
 273     // is not yet supported.
 274     set_resolved_references(NULL);
 275     return;
 276   }
 277 
 278   objArrayOop rr = resolved_references();


 439       Symbol* s = vfst.method()->method_holder()->source_file_name();
 440       if (s != NULL) {
 441         source_file = s->as_C_string();
 442       }
 443     }
 444   }
 445   if (k != this_cp->pool_holder()) {
 446     // only print something if the classes are different
 447     if (source_file != NULL) {
 448       log_debug(class, resolve)("%s %s %s:%d",
 449                  this_cp->pool_holder()->external_name(),
 450                  k->external_name(), source_file, line_number);
 451     } else {
 452       log_debug(class, resolve)("%s %s",
 453                  this_cp->pool_holder()->external_name(),
 454                  k->external_name());
 455     }
 456   }
 457 }
 458 
 459 void check_is_value_type(Klass* k, TRAPS) {
 460   if (!k->is_value()) {
 461     THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
 462   }
 463 }
 464 
 465 Klass* ConstantPool::klass_at_impl(const constantPoolHandle& this_cp, int which,
 466                                    bool save_resolution_error, TRAPS) {
 467   assert(THREAD->is_Java_thread(), "must be a Java thread");
 468   JavaThread* javaThread = (JavaThread*)THREAD;
 469 
 470   // A resolved constantPool entry will contain a Klass*, otherwise a Symbol*.
 471   // It is not safe to rely on the tag bit's here, since we don't have a lock, and
 472   // the entry and tag is not updated atomicly.
 473   CPKlassSlot kslot = this_cp->klass_slot_at(which);
 474   int resolved_klass_index = kslot.resolved_klass_index();
 475   int name_index = kslot.name_index();
 476   assert(this_cp->tag_at(name_index).is_symbol(), "sanity");
 477 
 478   Klass* klass = this_cp->resolved_klasses()->at(resolved_klass_index);
 479   if (klass != NULL) {
 480     return klass;
 481   }
 482 
 483   // This tag doesn't change back to unresolved class unless at a safepoint.
 484   if (this_cp->tag_at(which).is_unresolved_klass_in_error()) {
 485     // The original attempt to resolve this constant pool entry failed so find the
 486     // class of the original error and throw another error of the same class
 487     // (JVMS 5.4.3).
 488     // If there is a detail message, pass that detail message to the error.
 489     // The JVMS does not strictly require us to duplicate the same detail message,
 490     // or any internal exception fields such as cause or stacktrace.  But since the
 491     // detail message is often a class name or other literal string, we will repeat it
 492     // if we can find it in the symbol table.
 493     throw_resolution_error(this_cp, which, CHECK_NULL);
 494     ShouldNotReachHere();
 495   }
 496 
 497   Handle mirror_handle;
 498   Symbol* name = this_cp->symbol_at(name_index);
 499   bool value_type_signature = false;
 500   if (name->is_Q_signature()) {
 501     name = name->fundamental_name(THREAD);
 502     value_type_signature = true;
 503   }
 504   Handle loader (THREAD, this_cp->pool_holder()->class_loader());
 505   Handle protection_domain (THREAD, this_cp->pool_holder()->protection_domain());
 506 
 507   Klass* k;
 508   {
 509     // Turn off the single stepping while doing class resolution
 510     JvmtiHideSingleStepping jhss(javaThread);
 511     k = SystemDictionary::resolve_or_fail(name, loader, protection_domain, true, THREAD);
 512   } //  JvmtiHideSingleStepping jhss(javaThread);
 513   if (value_type_signature) {
 514     name->decrement_refcount();
 515   }
 516 
 517   if (!HAS_PENDING_EXCEPTION) {
 518     // preserve the resolved klass from unloading
 519     mirror_handle = Handle(THREAD, k->java_mirror());
 520     // Do access check for klasses
 521     verify_constant_pool_resolve(this_cp, k, THREAD);
 522   }
 523 
 524   if (!HAS_PENDING_EXCEPTION && value_type_signature) {
 525     check_is_value_type(k, THREAD);
 526   }
 527 
 528   if (!HAS_PENDING_EXCEPTION) {
 529     Klass* bottom_klass = NULL;
 530     if (k->is_objArray_klass()) {
 531       bottom_klass = ObjArrayKlass::cast(k)->bottom_klass();
 532       assert(bottom_klass != NULL, "Should be set");
 533       assert(bottom_klass->is_instance_klass() || bottom_klass->is_typeArray_klass(), "Sanity check");
 534     } else if (k->is_valueArray_klass()) {
 535       bottom_klass = ValueArrayKlass::cast(k)->element_klass();
 536       assert(bottom_klass != NULL, "Should be set");
 537     }
 538   }
 539 
 540   // Failed to resolve class. We must record the errors so that subsequent attempts
 541   // to resolve this constant pool entry fail with the same error (JVMS 5.4.3).
 542   if (HAS_PENDING_EXCEPTION) {
 543     if (save_resolution_error) {
 544       save_and_throw_exception(this_cp, which, constantTag(JVM_CONSTANT_UnresolvedClass), CHECK_NULL);
 545       // If CHECK_NULL above doesn't return the exception, that means that
 546       // some other thread has beaten us and has resolved the class.
 547       // To preserve old behavior, we return the resolved class.
 548       klass = this_cp->resolved_klasses()->at(resolved_klass_index);
 549       assert(klass != NULL, "must be resolved if exception was cleared");
 550       return klass;
 551     } else {
 552       return NULL;  // return the pending exception
 553     }
 554   }
 555 
 556   // logging for class+resolve.
 557   if (log_is_enabled(Debug, class, resolve)){
 558     trace_class_resolution(this_cp, k);
 559   }
 560   Klass** adr = this_cp->resolved_klasses()->adr_at(resolved_klass_index);
 561   OrderAccess::release_store(adr, k);
 562   // The interpreter assumes when the tag is stored, the klass is resolved
 563   // and the Klass* stored in _resolved_klasses is non-NULL, so we need
 564   // hardware store ordering here.
 565   jbyte tag = JVM_CONSTANT_Class;
 566   if (this_cp->tag_at(which).is_Qdescriptor_klass()) {
 567     tag |= JVM_CONSTANT_QDescBit;
 568   }
 569   this_cp->release_tag_at_put(which, tag);
 570   return k;
 571 }
 572 
 573 
 574 // Does not update ConstantPool* - to avoid any exception throwing. Used
 575 // by compiler and exception handling.  Also used to avoid classloads for
 576 // instanceof operations. Returns NULL if the class has not been loaded or
 577 // if the verification of constant pool failed
 578 Klass* ConstantPool::klass_at_if_loaded(const constantPoolHandle& this_cp, int which) {
 579   CPKlassSlot kslot = this_cp->klass_slot_at(which);
 580   int resolved_klass_index = kslot.resolved_klass_index();
 581   int name_index = kslot.name_index();
 582   assert(this_cp->tag_at(name_index).is_symbol(), "sanity");
 583 
 584   Klass* k = this_cp->resolved_klasses()->at(resolved_klass_index);
 585   if (k != NULL) {
 586     return k;
 587   } else {
 588     Thread *thread = Thread::current();
 589     Symbol* name = this_cp->symbol_at(name_index);


1866       case JVM_CONSTANT_Long: {
1867         u8 val = Bytes::get_Java_u8(bytes);
1868         printf("long         " INT64_FORMAT, (int64_t) *(jlong *) &val);
1869         ent_size = 8;
1870         idx++; // Long takes two cpool slots
1871         break;
1872       }
1873       case JVM_CONSTANT_Double: {
1874         u8 val = Bytes::get_Java_u8(bytes);
1875         printf("double       %5.3fd", *(jdouble *)&val);
1876         ent_size = 8;
1877         idx++; // Double takes two cpool slots
1878         break;
1879       }
1880       case JVM_CONSTANT_Class: {
1881         idx1 = Bytes::get_Java_u2(bytes);
1882         printf("class        #%03d", idx1);
1883         ent_size = 2;
1884         break;
1885       }
1886       case (JVM_CONSTANT_Class | JVM_CONSTANT_QDescBit): {
1887         idx1 = Bytes::get_Java_u2(bytes);
1888         printf("qclass        #%03d", idx1);
1889         ent_size = 2;
1890         break;
1891       }
1892       case JVM_CONSTANT_String: {
1893         idx1 = Bytes::get_Java_u2(bytes);
1894         printf("String       #%03d", idx1);
1895         ent_size = 2;
1896         break;
1897       }
1898       case JVM_CONSTANT_Fieldref: {
1899         idx1 = Bytes::get_Java_u2(bytes);
1900         idx2 = Bytes::get_Java_u2(bytes+2);
1901         printf("Field        #%03d, #%03d", (int) idx1, (int) idx2);
1902         ent_size = 4;
1903         break;
1904       }
1905       case JVM_CONSTANT_Methodref: {
1906         idx1 = Bytes::get_Java_u2(bytes);
1907         idx2 = Bytes::get_Java_u2(bytes+2);
1908         printf("Method       #%03d, #%03d", idx1, idx2);
1909         ent_size = 4;
1910         break;
1911       }


1914         idx2 = Bytes::get_Java_u2(bytes+2);
1915         printf("InterfMethod #%03d, #%03d", idx1, idx2);
1916         ent_size = 4;
1917         break;
1918       }
1919       case JVM_CONSTANT_NameAndType: {
1920         idx1 = Bytes::get_Java_u2(bytes);
1921         idx2 = Bytes::get_Java_u2(bytes+2);
1922         printf("NameAndType  #%03d, #%03d", idx1, idx2);
1923         ent_size = 4;
1924         break;
1925       }
1926       case JVM_CONSTANT_ClassIndex: {
1927         printf("ClassIndex  %s", WARN_MSG);
1928         break;
1929       }
1930       case JVM_CONSTANT_UnresolvedClass: {
1931         printf("UnresolvedClass: %s", WARN_MSG);
1932         break;
1933       }
1934       case (JVM_CONSTANT_UnresolvedClass | JVM_CONSTANT_QDescBit): {
1935         printf("UnresolvedQClass: %s", WARN_MSG);
1936         break;
1937       }
1938       case JVM_CONSTANT_UnresolvedClassInError: {
1939         printf("UnresolvedClassInErr: %s", WARN_MSG);
1940         break;
1941       }
1942       case JVM_CONSTANT_StringIndex: {
1943         printf("StringIndex: %s", WARN_MSG);
1944         break;
1945       }
1946     }
1947     printf(";\n");
1948     bytes += ent_size;
1949     size  += ent_size;
1950   }
1951   printf("Cpool size: %d\n", size);
1952   fflush(0);
1953   return;
1954 } /* end print_cpool_bytes */
1955 
1956 
1957 // Returns size of constant pool entry.


2089       case JVM_CONSTANT_Float: {
2090         jfloat val = float_at(idx);
2091         Bytes::put_Java_u4((address) (bytes+1), *(u4*)&val);
2092         break;
2093       }
2094       case JVM_CONSTANT_Long: {
2095         jlong val = long_at(idx);
2096         Bytes::put_Java_u8((address) (bytes+1), *(u8*)&val);
2097         idx++;             // Long takes two cpool slots
2098         break;
2099       }
2100       case JVM_CONSTANT_Double: {
2101         jdouble val = double_at(idx);
2102         Bytes::put_Java_u8((address) (bytes+1), *(u8*)&val);
2103         idx++;             // Double takes two cpool slots
2104         break;
2105       }
2106       case JVM_CONSTANT_Class:
2107       case JVM_CONSTANT_UnresolvedClass:
2108       case JVM_CONSTANT_UnresolvedClassInError: {
2109         assert(!tag_at(idx).is_Qdescriptor_klass(), "Failed to encode QDesc");
2110         *bytes = JVM_CONSTANT_Class;
2111         Symbol* sym = klass_name_at(idx);
2112         idx1 = tbl->symbol_to_value(sym);
2113         assert(idx1 != 0, "Have not found a hashtable entry");
2114         Bytes::put_Java_u2((address) (bytes+1), idx1);
2115         DBG(printf("JVM_CONSTANT_Class: idx=#%03hd, %s", idx1, sym->as_utf8()));
2116         break;
2117       }
2118       case JVM_CONSTANT_String: {
2119         *bytes = JVM_CONSTANT_String;
2120         Symbol* sym = unresolved_string_at(idx);
2121         idx1 = tbl->symbol_to_value(sym);
2122         assert(idx1 != 0, "Have not found a hashtable entry");
2123         Bytes::put_Java_u2((address) (bytes+1), idx1);
2124         DBG(printf("JVM_CONSTANT_String: idx=#%03hd, %s", idx1, sym->as_utf8()));
2125         break;
2126       }
2127       case JVM_CONSTANT_Fieldref:
2128       case JVM_CONSTANT_Methodref:
2129       case JVM_CONSTANT_InterfaceMethodref: {


< prev index next >