< prev index next >

src/hotspot/share/oops/constantPool.cpp

Print this page

  35 #include "classfile/metadataOnStackMark.hpp"
  36 #include "classfile/stringTable.hpp"
  37 #include "classfile/systemDictionary.hpp"
  38 #include "classfile/vmClasses.hpp"
  39 #include "classfile/vmSymbols.hpp"
  40 #include "code/codeCache.hpp"
  41 #include "interpreter/bootstrapInfo.hpp"
  42 #include "interpreter/linkResolver.hpp"
  43 #include "jvm.h"
  44 #include "logging/log.hpp"
  45 #include "logging/logStream.hpp"
  46 #include "memory/allocation.inline.hpp"
  47 #include "memory/metadataFactory.hpp"
  48 #include "memory/metaspaceClosure.hpp"
  49 #include "memory/oopFactory.hpp"
  50 #include "memory/resourceArea.hpp"
  51 #include "memory/universe.hpp"
  52 #include "oops/array.hpp"
  53 #include "oops/constantPool.inline.hpp"
  54 #include "oops/cpCache.inline.hpp"

  55 #include "oops/instanceKlass.hpp"
  56 #include "oops/klass.inline.hpp"
  57 #include "oops/objArrayKlass.hpp"
  58 #include "oops/objArrayOop.inline.hpp"
  59 #include "oops/oop.inline.hpp"
  60 #include "oops/typeArrayOop.inline.hpp"
  61 #include "prims/jvmtiExport.hpp"
  62 #include "runtime/atomic.hpp"
  63 #include "runtime/handles.inline.hpp"
  64 #include "runtime/init.hpp"
  65 #include "runtime/javaCalls.hpp"
  66 #include "runtime/javaThread.inline.hpp"
  67 #include "runtime/perfData.hpp"
  68 #include "runtime/signature.hpp"
  69 #include "runtime/vframe.inline.hpp"
  70 #include "utilities/checkedCast.hpp"
  71 #include "utilities/copy.hpp"
  72 
  73 ConstantPool* ConstantPool::allocate(ClassLoaderData* loader_data, int length, TRAPS) {
  74   Array<u1>* tags = MetadataFactory::new_array<u1>(loader_data, length, 0, CHECK_NULL);

 243   assert(resolved_klasses() == nullptr, "sanity");
 244   Array<Klass*>* rk = MetadataFactory::new_array<Klass*>(loader_data, num_klasses, CHECK);
 245   set_resolved_klasses(rk);
 246 }
 247 
 248 void ConstantPool::initialize_unresolved_klasses(ClassLoaderData* loader_data, TRAPS) {
 249   int len = length();
 250   int num_klasses = 0;
 251   for (int i = 1; i <len; i++) {
 252     switch (tag_at(i).value()) {
 253     case JVM_CONSTANT_ClassIndex:
 254       {
 255         const int class_index = klass_index_at(i);
 256         unresolved_klass_at_put(i, class_index, num_klasses++);
 257       }
 258       break;
 259 #ifndef PRODUCT
 260     case JVM_CONSTANT_Class:
 261     case JVM_CONSTANT_UnresolvedClass:
 262     case JVM_CONSTANT_UnresolvedClassInError:
 263       // All of these should have been reverted back to ClassIndex before calling
 264       // this function.
 265       ShouldNotReachHere();
 266 #endif
 267     }
 268   }
 269   allocate_resolved_klasses(loader_data, num_klasses, THREAD);
 270 }
 271 
 272 // Hidden class support:
 273 void ConstantPool::klass_at_put(int class_index, Klass* k) {
 274   assert(k != nullptr, "must be valid klass");
 275   CPKlassSlot kslot = klass_slot_at(class_index);
 276   int resolved_klass_index = kslot.resolved_klass_index();
 277   Klass** adr = resolved_klasses()->adr_at(resolved_klass_index);
 278   Atomic::release_store(adr, k);
 279 
 280   // The interpreter assumes when the tag is stored, the klass is resolved
 281   // and the Klass* non-null, so we need hardware store ordering here.
 282   release_tag_at_put(class_index, JVM_CONSTANT_Class);
 283 }

 534       Symbol* s = vfst.method()->method_holder()->source_file_name();
 535       if (s != nullptr) {
 536         source_file = s->as_C_string();
 537       }
 538     }
 539   }
 540   if (k != this_cp->pool_holder()) {
 541     // only print something if the classes are different
 542     if (source_file != nullptr) {
 543       log_debug(class, resolve)("%s %s %s:%d",
 544                  this_cp->pool_holder()->external_name(),
 545                  k->external_name(), source_file, line_number);
 546     } else {
 547       log_debug(class, resolve)("%s %s",
 548                  this_cp->pool_holder()->external_name(),
 549                  k->external_name());
 550     }
 551   }
 552 }
 553 






 554 Klass* ConstantPool::klass_at_impl(const constantPoolHandle& this_cp, int cp_index,
 555                                    TRAPS) {
 556   JavaThread* javaThread = THREAD;
 557 
 558   // A resolved constantPool entry will contain a Klass*, otherwise a Symbol*.
 559   // It is not safe to rely on the tag bit's here, since we don't have a lock, and
 560   // the entry and tag is not updated atomically.
 561   CPKlassSlot kslot = this_cp->klass_slot_at(cp_index);
 562   int resolved_klass_index = kslot.resolved_klass_index();
 563   int name_index = kslot.name_index();
 564   assert(this_cp->tag_at(name_index).is_symbol(), "sanity");
 565 
 566   // The tag must be JVM_CONSTANT_Class in order to read the correct value from
 567   // the unresolved_klasses() array.
 568   if (this_cp->tag_at(cp_index).is_klass()) {
 569     Klass* klass = this_cp->resolved_klasses()->at(resolved_klass_index);
 570     if (klass != nullptr) {
 571       return klass;
 572     }
 573   }
 574 
 575   // This tag doesn't change back to unresolved class unless at a safepoint.
 576   if (this_cp->tag_at(cp_index).is_unresolved_klass_in_error()) {
 577     // The original attempt to resolve this constant pool entry failed so find the
 578     // class of the original error and throw another error of the same class
 579     // (JVMS 5.4.3).
 580     // If there is a detail message, pass that detail message to the error.
 581     // The JVMS does not strictly require us to duplicate the same detail message,
 582     // or any internal exception fields such as cause or stacktrace.  But since the
 583     // detail message is often a class name or other literal string, we will repeat it
 584     // if we can find it in the symbol table.
 585     throw_resolution_error(this_cp, cp_index, CHECK_NULL);
 586     ShouldNotReachHere();
 587   }
 588 
 589   HandleMark hm(THREAD);
 590   Handle mirror_handle;
 591   Symbol* name = this_cp->symbol_at(name_index);

 592   Handle loader (THREAD, this_cp->pool_holder()->class_loader());
 593   Handle protection_domain (THREAD, this_cp->pool_holder()->protection_domain());
 594 
 595   Klass* k;
 596   {
 597     // Turn off the single stepping while doing class resolution
 598     JvmtiHideSingleStepping jhss(javaThread);
 599     k = SystemDictionary::resolve_or_fail(name, loader, protection_domain, true, THREAD);
 600   } //  JvmtiHideSingleStepping jhss(javaThread);



 601 
 602   if (!HAS_PENDING_EXCEPTION) {
 603     // preserve the resolved klass from unloading
 604     mirror_handle = Handle(THREAD, k->java_mirror());
 605     // Do access check for klasses
 606     verify_constant_pool_resolve(this_cp, k, THREAD);
 607   }
 608 
















 609   // Failed to resolve class. We must record the errors so that subsequent attempts
 610   // to resolve this constant pool entry fail with the same error (JVMS 5.4.3).
 611   if (HAS_PENDING_EXCEPTION) {
 612     save_and_throw_exception(this_cp, cp_index, constantTag(JVM_CONSTANT_UnresolvedClass), CHECK_NULL);
 613     // If CHECK_NULL above doesn't return the exception, that means that
 614     // some other thread has beaten us and has resolved the class.
 615     // To preserve old behavior, we return the resolved class.
 616     Klass* klass = this_cp->resolved_klasses()->at(resolved_klass_index);
 617     assert(klass != nullptr, "must be resolved if exception was cleared");
 618     return klass;
 619   }
 620 
 621   // logging for class+resolve.
 622   if (log_is_enabled(Debug, class, resolve)){
 623     trace_class_resolution(this_cp, k);
 624   }
 625 
 626   Klass** adr = this_cp->resolved_klasses()->adr_at(resolved_klass_index);
 627   Atomic::release_store(adr, k);
 628   // The interpreter assumes when the tag is stored, the klass is resolved

  35 #include "classfile/metadataOnStackMark.hpp"
  36 #include "classfile/stringTable.hpp"
  37 #include "classfile/systemDictionary.hpp"
  38 #include "classfile/vmClasses.hpp"
  39 #include "classfile/vmSymbols.hpp"
  40 #include "code/codeCache.hpp"
  41 #include "interpreter/bootstrapInfo.hpp"
  42 #include "interpreter/linkResolver.hpp"
  43 #include "jvm.h"
  44 #include "logging/log.hpp"
  45 #include "logging/logStream.hpp"
  46 #include "memory/allocation.inline.hpp"
  47 #include "memory/metadataFactory.hpp"
  48 #include "memory/metaspaceClosure.hpp"
  49 #include "memory/oopFactory.hpp"
  50 #include "memory/resourceArea.hpp"
  51 #include "memory/universe.hpp"
  52 #include "oops/array.hpp"
  53 #include "oops/constantPool.inline.hpp"
  54 #include "oops/cpCache.inline.hpp"
  55 #include "oops/flatArrayKlass.hpp"
  56 #include "oops/instanceKlass.hpp"
  57 #include "oops/klass.inline.hpp"
  58 #include "oops/objArrayKlass.hpp"
  59 #include "oops/objArrayOop.inline.hpp"
  60 #include "oops/oop.inline.hpp"
  61 #include "oops/typeArrayOop.inline.hpp"
  62 #include "prims/jvmtiExport.hpp"
  63 #include "runtime/atomic.hpp"
  64 #include "runtime/handles.inline.hpp"
  65 #include "runtime/init.hpp"
  66 #include "runtime/javaCalls.hpp"
  67 #include "runtime/javaThread.inline.hpp"
  68 #include "runtime/perfData.hpp"
  69 #include "runtime/signature.hpp"
  70 #include "runtime/vframe.inline.hpp"
  71 #include "utilities/checkedCast.hpp"
  72 #include "utilities/copy.hpp"
  73 
  74 ConstantPool* ConstantPool::allocate(ClassLoaderData* loader_data, int length, TRAPS) {
  75   Array<u1>* tags = MetadataFactory::new_array<u1>(loader_data, length, 0, CHECK_NULL);

 244   assert(resolved_klasses() == nullptr, "sanity");
 245   Array<Klass*>* rk = MetadataFactory::new_array<Klass*>(loader_data, num_klasses, CHECK);
 246   set_resolved_klasses(rk);
 247 }
 248 
 249 void ConstantPool::initialize_unresolved_klasses(ClassLoaderData* loader_data, TRAPS) {
 250   int len = length();
 251   int num_klasses = 0;
 252   for (int i = 1; i <len; i++) {
 253     switch (tag_at(i).value()) {
 254     case JVM_CONSTANT_ClassIndex:
 255       {
 256         const int class_index = klass_index_at(i);
 257         unresolved_klass_at_put(i, class_index, num_klasses++);
 258       }
 259       break;
 260 #ifndef PRODUCT
 261     case JVM_CONSTANT_Class:
 262     case JVM_CONSTANT_UnresolvedClass:
 263     case JVM_CONSTANT_UnresolvedClassInError:
 264       // All of these should have been reverted back to Unresolved before calling
 265       // this function.
 266       ShouldNotReachHere();
 267 #endif
 268     }
 269   }
 270   allocate_resolved_klasses(loader_data, num_klasses, THREAD);
 271 }
 272 
 273 // Hidden class support:
 274 void ConstantPool::klass_at_put(int class_index, Klass* k) {
 275   assert(k != nullptr, "must be valid klass");
 276   CPKlassSlot kslot = klass_slot_at(class_index);
 277   int resolved_klass_index = kslot.resolved_klass_index();
 278   Klass** adr = resolved_klasses()->adr_at(resolved_klass_index);
 279   Atomic::release_store(adr, k);
 280 
 281   // The interpreter assumes when the tag is stored, the klass is resolved
 282   // and the Klass* non-null, so we need hardware store ordering here.
 283   release_tag_at_put(class_index, JVM_CONSTANT_Class);
 284 }

 535       Symbol* s = vfst.method()->method_holder()->source_file_name();
 536       if (s != nullptr) {
 537         source_file = s->as_C_string();
 538       }
 539     }
 540   }
 541   if (k != this_cp->pool_holder()) {
 542     // only print something if the classes are different
 543     if (source_file != nullptr) {
 544       log_debug(class, resolve)("%s %s %s:%d",
 545                  this_cp->pool_holder()->external_name(),
 546                  k->external_name(), source_file, line_number);
 547     } else {
 548       log_debug(class, resolve)("%s %s",
 549                  this_cp->pool_holder()->external_name(),
 550                  k->external_name());
 551     }
 552   }
 553 }
 554 
 555 void check_is_inline_type(Klass* k, TRAPS) {
 556   if (!k->is_inline_klass()) {
 557     THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
 558   }
 559 }
 560 
 561 Klass* ConstantPool::klass_at_impl(const constantPoolHandle& this_cp, int cp_index,
 562                                    TRAPS) {
 563   JavaThread* javaThread = THREAD;
 564 
 565   // A resolved constantPool entry will contain a Klass*, otherwise a Symbol*.
 566   // It is not safe to rely on the tag bit's here, since we don't have a lock, and
 567   // the entry and tag is not updated atomically.
 568   CPKlassSlot kslot = this_cp->klass_slot_at(cp_index);
 569   int resolved_klass_index = kslot.resolved_klass_index();
 570   int name_index = kslot.name_index();
 571   assert(this_cp->tag_at(name_index).is_symbol(), "sanity");
 572 
 573   // The tag must be JVM_CONSTANT_Class in order to read the correct value from
 574   // the unresolved_klasses() array.
 575   if (this_cp->tag_at(cp_index).is_klass()) {
 576     Klass* klass = this_cp->resolved_klasses()->at(resolved_klass_index);
 577     if (klass != nullptr) {
 578       return klass;
 579     }
 580   }
 581 
 582   // This tag doesn't change back to unresolved class unless at a safepoint.
 583   if (this_cp->tag_at(cp_index).is_unresolved_klass_in_error()) {
 584     // The original attempt to resolve this constant pool entry failed so find the
 585     // class of the original error and throw another error of the same class
 586     // (JVMS 5.4.3).
 587     // If there is a detail message, pass that detail message to the error.
 588     // The JVMS does not strictly require us to duplicate the same detail message,
 589     // or any internal exception fields such as cause or stacktrace.  But since the
 590     // detail message is often a class name or other literal string, we will repeat it
 591     // if we can find it in the symbol table.
 592     throw_resolution_error(this_cp, cp_index, CHECK_NULL);
 593     ShouldNotReachHere();
 594   }
 595 
 596   HandleMark hm(THREAD);
 597   Handle mirror_handle;
 598   Symbol* name = this_cp->symbol_at(name_index);
 599   bool inline_type_signature = false;
 600   Handle loader (THREAD, this_cp->pool_holder()->class_loader());
 601   Handle protection_domain (THREAD, this_cp->pool_holder()->protection_domain());
 602 
 603   Klass* k;
 604   {
 605     // Turn off the single stepping while doing class resolution
 606     JvmtiHideSingleStepping jhss(javaThread);
 607     k = SystemDictionary::resolve_or_fail(name, loader, protection_domain, true, THREAD);
 608   } //  JvmtiHideSingleStepping jhss(javaThread);
 609   if (inline_type_signature) {
 610     name->decrement_refcount();
 611   }
 612 
 613   if (!HAS_PENDING_EXCEPTION) {
 614     // preserve the resolved klass from unloading
 615     mirror_handle = Handle(THREAD, k->java_mirror());
 616     // Do access check for klasses
 617     verify_constant_pool_resolve(this_cp, k, THREAD);
 618   }
 619 
 620   if (!HAS_PENDING_EXCEPTION && inline_type_signature) {
 621     check_is_inline_type(k, THREAD);
 622   }
 623 
 624   if (!HAS_PENDING_EXCEPTION) {
 625     Klass* bottom_klass = nullptr;
 626     if (k->is_objArray_klass()) {
 627       bottom_klass = ObjArrayKlass::cast(k)->bottom_klass();
 628       assert(bottom_klass != nullptr, "Should be set");
 629       assert(bottom_klass->is_instance_klass() || bottom_klass->is_typeArray_klass(), "Sanity check");
 630     } else if (k->is_flatArray_klass()) {
 631       bottom_klass = FlatArrayKlass::cast(k)->element_klass();
 632       assert(bottom_klass != nullptr, "Should be set");
 633     }
 634   }
 635 
 636   // Failed to resolve class. We must record the errors so that subsequent attempts
 637   // to resolve this constant pool entry fail with the same error (JVMS 5.4.3).
 638   if (HAS_PENDING_EXCEPTION) {
 639     save_and_throw_exception(this_cp, cp_index, constantTag(JVM_CONSTANT_UnresolvedClass), CHECK_NULL);
 640     // If CHECK_NULL above doesn't return the exception, that means that
 641     // some other thread has beaten us and has resolved the class.
 642     // To preserve old behavior, we return the resolved class.
 643     Klass* klass = this_cp->resolved_klasses()->at(resolved_klass_index);
 644     assert(klass != nullptr, "must be resolved if exception was cleared");
 645     return klass;
 646   }
 647 
 648   // logging for class+resolve.
 649   if (log_is_enabled(Debug, class, resolve)){
 650     trace_class_resolution(this_cp, k);
 651   }
 652 
 653   Klass** adr = this_cp->resolved_klasses()->adr_at(resolved_klass_index);
 654   Atomic::release_store(adr, k);
 655   // The interpreter assumes when the tag is stored, the klass is resolved
< prev index next >