< prev index next >

src/hotspot/share/oops/constantPool.cpp

Print this page

  36 #include "classfile/systemDictionary.hpp"
  37 #include "classfile/systemDictionaryShared.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/fieldStreams.inline.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/fieldDescriptor.inline.hpp"
  65 #include "runtime/handles.inline.hpp"
  66 #include "runtime/init.hpp"
  67 #include "runtime/javaCalls.hpp"
  68 #include "runtime/javaThread.inline.hpp"
  69 #include "runtime/perfData.hpp"
  70 #include "runtime/signature.hpp"
  71 #include "runtime/vframe.inline.hpp"
  72 #include "utilities/checkedCast.hpp"
  73 #include "utilities/copy.hpp"
  74 
  75 ConstantPool* ConstantPool::allocate(ClassLoaderData* loader_data, int length, TRAPS) {

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

 622       Symbol* s = vfst.method()->method_holder()->source_file_name();
 623       if (s != nullptr) {
 624         source_file = s->as_C_string();
 625       }
 626     }
 627   }
 628   if (k != this_cp->pool_holder()) {
 629     // only print something if the classes are different
 630     if (source_file != nullptr) {
 631       log_debug(class, resolve)("%s %s %s:%d",
 632                  this_cp->pool_holder()->external_name(),
 633                  k->external_name(), source_file, line_number);
 634     } else {
 635       log_debug(class, resolve)("%s %s",
 636                  this_cp->pool_holder()->external_name(),
 637                  k->external_name());
 638     }
 639   }
 640 }
 641 






 642 Klass* ConstantPool::klass_at_impl(const constantPoolHandle& this_cp, int cp_index,
 643                                    TRAPS) {
 644   JavaThread* javaThread = THREAD;
 645 
 646   // A resolved constantPool entry will contain a Klass*, otherwise a Symbol*.
 647   // It is not safe to rely on the tag bit's here, since we don't have a lock, and
 648   // the entry and tag is not updated atomically.
 649   CPKlassSlot kslot = this_cp->klass_slot_at(cp_index);
 650   int resolved_klass_index = kslot.resolved_klass_index();
 651   int name_index = kslot.name_index();
 652   assert(this_cp->tag_at(name_index).is_symbol(), "sanity");
 653 
 654   // The tag must be JVM_CONSTANT_Class in order to read the correct value from
 655   // the unresolved_klasses() array.
 656   if (this_cp->tag_at(cp_index).is_klass()) {
 657     Klass* klass = this_cp->resolved_klasses()->at(resolved_klass_index);
 658     if (klass != nullptr) {
 659       return klass;
 660     }
 661   }
 662 
 663   // This tag doesn't change back to unresolved class unless at a safepoint.
 664   if (this_cp->tag_at(cp_index).is_unresolved_klass_in_error()) {
 665     // The original attempt to resolve this constant pool entry failed so find the
 666     // class of the original error and throw another error of the same class
 667     // (JVMS 5.4.3).
 668     // If there is a detail message, pass that detail message to the error.
 669     // The JVMS does not strictly require us to duplicate the same detail message,
 670     // or any internal exception fields such as cause or stacktrace.  But since the
 671     // detail message is often a class name or other literal string, we will repeat it
 672     // if we can find it in the symbol table.
 673     throw_resolution_error(this_cp, cp_index, CHECK_NULL);
 674     ShouldNotReachHere();
 675   }
 676 
 677   HandleMark hm(THREAD);
 678   Handle mirror_handle;
 679   Symbol* name = this_cp->symbol_at(name_index);

 680   Handle loader (THREAD, this_cp->pool_holder()->class_loader());
 681 
 682   Klass* k;
 683   {
 684     // Turn off the single stepping while doing class resolution
 685     JvmtiHideSingleStepping jhss(javaThread);
 686     k = SystemDictionary::resolve_or_fail(name, loader, true, THREAD);
 687   } //  JvmtiHideSingleStepping jhss(javaThread);



 688 
 689   if (!HAS_PENDING_EXCEPTION) {
 690     // preserve the resolved klass from unloading
 691     mirror_handle = Handle(THREAD, k->java_mirror());
 692     // Do access check for klasses
 693     verify_constant_pool_resolve(this_cp, k, THREAD);
 694   }
 695 
















 696   // Failed to resolve class. We must record the errors so that subsequent attempts
 697   // to resolve this constant pool entry fail with the same error (JVMS 5.4.3).
 698   if (HAS_PENDING_EXCEPTION) {
 699     save_and_throw_exception(this_cp, cp_index, constantTag(JVM_CONSTANT_UnresolvedClass), CHECK_NULL);
 700     // If CHECK_NULL above doesn't return the exception, that means that
 701     // some other thread has beaten us and has resolved the class.
 702     // To preserve old behavior, we return the resolved class.
 703     Klass* klass = this_cp->resolved_klasses()->at(resolved_klass_index);
 704     assert(klass != nullptr, "must be resolved if exception was cleared");
 705     return klass;
 706   }
 707 
 708   // logging for class+resolve.
 709   if (log_is_enabled(Debug, class, resolve)){
 710     trace_class_resolution(this_cp, k);
 711   }
 712 
 713   Klass** adr = this_cp->resolved_klasses()->adr_at(resolved_klass_index);
 714   Atomic::release_store(adr, k);
 715   // The interpreter assumes when the tag is stored, the klass is resolved

  36 #include "classfile/systemDictionary.hpp"
  37 #include "classfile/systemDictionaryShared.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/fieldStreams.inline.hpp"
  56 #include "oops/flatArrayKlass.hpp"
  57 #include "oops/instanceKlass.hpp"
  58 #include "oops/klass.inline.hpp"
  59 #include "oops/objArrayKlass.hpp"
  60 #include "oops/objArrayOop.inline.hpp"
  61 #include "oops/oop.inline.hpp"
  62 #include "oops/typeArrayOop.inline.hpp"
  63 #include "prims/jvmtiExport.hpp"
  64 #include "runtime/atomic.hpp"
  65 #include "runtime/fieldDescriptor.inline.hpp"
  66 #include "runtime/handles.inline.hpp"
  67 #include "runtime/init.hpp"
  68 #include "runtime/javaCalls.hpp"
  69 #include "runtime/javaThread.inline.hpp"
  70 #include "runtime/perfData.hpp"
  71 #include "runtime/signature.hpp"
  72 #include "runtime/vframe.inline.hpp"
  73 #include "utilities/checkedCast.hpp"
  74 #include "utilities/copy.hpp"
  75 
  76 ConstantPool* ConstantPool::allocate(ClassLoaderData* loader_data, int length, TRAPS) {

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

 623       Symbol* s = vfst.method()->method_holder()->source_file_name();
 624       if (s != nullptr) {
 625         source_file = s->as_C_string();
 626       }
 627     }
 628   }
 629   if (k != this_cp->pool_holder()) {
 630     // only print something if the classes are different
 631     if (source_file != nullptr) {
 632       log_debug(class, resolve)("%s %s %s:%d",
 633                  this_cp->pool_holder()->external_name(),
 634                  k->external_name(), source_file, line_number);
 635     } else {
 636       log_debug(class, resolve)("%s %s",
 637                  this_cp->pool_holder()->external_name(),
 638                  k->external_name());
 639     }
 640   }
 641 }
 642 
 643 void check_is_inline_type(Klass* k, TRAPS) {
 644   if (!k->is_inline_klass()) {
 645     THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
 646   }
 647 }
 648 
 649 Klass* ConstantPool::klass_at_impl(const constantPoolHandle& this_cp, int cp_index,
 650                                    TRAPS) {
 651   JavaThread* javaThread = THREAD;
 652 
 653   // A resolved constantPool entry will contain a Klass*, otherwise a Symbol*.
 654   // It is not safe to rely on the tag bit's here, since we don't have a lock, and
 655   // the entry and tag is not updated atomically.
 656   CPKlassSlot kslot = this_cp->klass_slot_at(cp_index);
 657   int resolved_klass_index = kslot.resolved_klass_index();
 658   int name_index = kslot.name_index();
 659   assert(this_cp->tag_at(name_index).is_symbol(), "sanity");
 660 
 661   // The tag must be JVM_CONSTANT_Class in order to read the correct value from
 662   // the unresolved_klasses() array.
 663   if (this_cp->tag_at(cp_index).is_klass()) {
 664     Klass* klass = this_cp->resolved_klasses()->at(resolved_klass_index);
 665     if (klass != nullptr) {
 666       return klass;
 667     }
 668   }
 669 
 670   // This tag doesn't change back to unresolved class unless at a safepoint.
 671   if (this_cp->tag_at(cp_index).is_unresolved_klass_in_error()) {
 672     // The original attempt to resolve this constant pool entry failed so find the
 673     // class of the original error and throw another error of the same class
 674     // (JVMS 5.4.3).
 675     // If there is a detail message, pass that detail message to the error.
 676     // The JVMS does not strictly require us to duplicate the same detail message,
 677     // or any internal exception fields such as cause or stacktrace.  But since the
 678     // detail message is often a class name or other literal string, we will repeat it
 679     // if we can find it in the symbol table.
 680     throw_resolution_error(this_cp, cp_index, CHECK_NULL);
 681     ShouldNotReachHere();
 682   }
 683 
 684   HandleMark hm(THREAD);
 685   Handle mirror_handle;
 686   Symbol* name = this_cp->symbol_at(name_index);
 687   bool inline_type_signature = false;
 688   Handle loader (THREAD, this_cp->pool_holder()->class_loader());
 689 
 690   Klass* k;
 691   {
 692     // Turn off the single stepping while doing class resolution
 693     JvmtiHideSingleStepping jhss(javaThread);
 694     k = SystemDictionary::resolve_or_fail(name, loader, true, THREAD);
 695   } //  JvmtiHideSingleStepping jhss(javaThread);
 696   if (inline_type_signature) {
 697     name->decrement_refcount();
 698   }
 699 
 700   if (!HAS_PENDING_EXCEPTION) {
 701     // preserve the resolved klass from unloading
 702     mirror_handle = Handle(THREAD, k->java_mirror());
 703     // Do access check for klasses
 704     verify_constant_pool_resolve(this_cp, k, THREAD);
 705   }
 706 
 707   if (!HAS_PENDING_EXCEPTION && inline_type_signature) {
 708     check_is_inline_type(k, THREAD);
 709   }
 710 
 711   if (!HAS_PENDING_EXCEPTION) {
 712     Klass* bottom_klass = nullptr;
 713     if (k->is_objArray_klass()) {
 714       bottom_klass = ObjArrayKlass::cast(k)->bottom_klass();
 715       assert(bottom_klass != nullptr, "Should be set");
 716       assert(bottom_klass->is_instance_klass() || bottom_klass->is_typeArray_klass(), "Sanity check");
 717     } else if (k->is_flatArray_klass()) {
 718       bottom_klass = FlatArrayKlass::cast(k)->element_klass();
 719       assert(bottom_klass != nullptr, "Should be set");
 720     }
 721   }
 722 
 723   // Failed to resolve class. We must record the errors so that subsequent attempts
 724   // to resolve this constant pool entry fail with the same error (JVMS 5.4.3).
 725   if (HAS_PENDING_EXCEPTION) {
 726     save_and_throw_exception(this_cp, cp_index, constantTag(JVM_CONSTANT_UnresolvedClass), CHECK_NULL);
 727     // If CHECK_NULL above doesn't return the exception, that means that
 728     // some other thread has beaten us and has resolved the class.
 729     // To preserve old behavior, we return the resolved class.
 730     Klass* klass = this_cp->resolved_klasses()->at(resolved_klass_index);
 731     assert(klass != nullptr, "must be resolved if exception was cleared");
 732     return klass;
 733   }
 734 
 735   // logging for class+resolve.
 736   if (log_is_enabled(Debug, class, resolve)){
 737     trace_class_resolution(this_cp, k);
 738   }
 739 
 740   Klass** adr = this_cp->resolved_klasses()->adr_at(resolved_klass_index);
 741   Atomic::release_store(adr, k);
 742   // The interpreter assumes when the tag is stored, the klass is resolved
< prev index next >