< prev index next >

src/hotspot/share/oops/constantPool.cpp

Print this page

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

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

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

 485       Symbol* s = vfst.method()->method_holder()->source_file_name();
 486       if (s != nullptr) {
 487         source_file = s->as_C_string();
 488       }
 489     }
 490   }
 491   if (k != this_cp->pool_holder()) {
 492     // only print something if the classes are different
 493     if (source_file != nullptr) {
 494       log_debug(class, resolve)("%s %s %s:%d",
 495                  this_cp->pool_holder()->external_name(),
 496                  k->external_name(), source_file, line_number);
 497     } else {
 498       log_debug(class, resolve)("%s %s",
 499                  this_cp->pool_holder()->external_name(),
 500                  k->external_name());
 501     }
 502   }
 503 }
 504 






 505 Klass* ConstantPool::klass_at_impl(const constantPoolHandle& this_cp, int cp_index,
 506                                    TRAPS) {
 507   JavaThread* javaThread = THREAD;
 508 
 509   // A resolved constantPool entry will contain a Klass*, otherwise a Symbol*.
 510   // It is not safe to rely on the tag bit's here, since we don't have a lock, and
 511   // the entry and tag is not updated atomically.
 512   CPKlassSlot kslot = this_cp->klass_slot_at(cp_index);
 513   int resolved_klass_index = kslot.resolved_klass_index();
 514   int name_index = kslot.name_index();
 515   assert(this_cp->tag_at(name_index).is_symbol(), "sanity");
 516 
 517   // The tag must be JVM_CONSTANT_Class in order to read the correct value from
 518   // the unresolved_klasses() array.
 519   if (this_cp->tag_at(cp_index).is_klass()) {
 520     Klass* klass = this_cp->resolved_klasses()->at(resolved_klass_index);
 521     if (klass != nullptr) {
 522       return klass;
 523     }
 524   }
 525 
 526   // This tag doesn't change back to unresolved class unless at a safepoint.
 527   if (this_cp->tag_at(cp_index).is_unresolved_klass_in_error()) {
 528     // The original attempt to resolve this constant pool entry failed so find the
 529     // class of the original error and throw another error of the same class
 530     // (JVMS 5.4.3).
 531     // If there is a detail message, pass that detail message to the error.
 532     // The JVMS does not strictly require us to duplicate the same detail message,
 533     // or any internal exception fields such as cause or stacktrace.  But since the
 534     // detail message is often a class name or other literal string, we will repeat it
 535     // if we can find it in the symbol table.
 536     throw_resolution_error(this_cp, cp_index, CHECK_NULL);
 537     ShouldNotReachHere();
 538   }
 539 
 540   HandleMark hm(THREAD);
 541   Handle mirror_handle;
 542   Symbol* name = this_cp->symbol_at(name_index);

 543   Handle loader (THREAD, this_cp->pool_holder()->class_loader());
 544   Handle protection_domain (THREAD, this_cp->pool_holder()->protection_domain());
 545 
 546   Klass* k;
 547   {
 548     // Turn off the single stepping while doing class resolution
 549     JvmtiHideSingleStepping jhss(javaThread);
 550     k = SystemDictionary::resolve_or_fail(name, loader, protection_domain, true, THREAD);
 551   } //  JvmtiHideSingleStepping jhss(javaThread);



 552 
 553   if (!HAS_PENDING_EXCEPTION) {
 554     // preserve the resolved klass from unloading
 555     mirror_handle = Handle(THREAD, k->java_mirror());
 556     // Do access check for klasses
 557     verify_constant_pool_resolve(this_cp, k, THREAD);
 558   }
 559 
















 560   // Failed to resolve class. We must record the errors so that subsequent attempts
 561   // to resolve this constant pool entry fail with the same error (JVMS 5.4.3).
 562   if (HAS_PENDING_EXCEPTION) {
 563     save_and_throw_exception(this_cp, cp_index, constantTag(JVM_CONSTANT_UnresolvedClass), CHECK_NULL);
 564     // If CHECK_NULL above doesn't return the exception, that means that
 565     // some other thread has beaten us and has resolved the class.
 566     // To preserve old behavior, we return the resolved class.
 567     Klass* klass = this_cp->resolved_klasses()->at(resolved_klass_index);
 568     assert(klass != nullptr, "must be resolved if exception was cleared");
 569     return klass;
 570   }
 571 
 572   // logging for class+resolve.
 573   if (log_is_enabled(Debug, class, resolve)){
 574     trace_class_resolution(this_cp, k);
 575   }
 576 
 577   Klass** adr = this_cp->resolved_klasses()->adr_at(resolved_klass_index);
 578   Atomic::release_store(adr, k);
 579   // The interpreter assumes when the tag is stored, the klass is resolved

  34 #include "classfile/metadataOnStackMark.hpp"
  35 #include "classfile/stringTable.hpp"
  36 #include "classfile/systemDictionary.hpp"
  37 #include "classfile/vmClasses.hpp"
  38 #include "classfile/vmSymbols.hpp"
  39 #include "code/codeCache.hpp"
  40 #include "interpreter/bootstrapInfo.hpp"
  41 #include "interpreter/linkResolver.hpp"
  42 #include "jvm.h"
  43 #include "logging/log.hpp"
  44 #include "logging/logStream.hpp"
  45 #include "memory/allocation.inline.hpp"
  46 #include "memory/metadataFactory.hpp"
  47 #include "memory/metaspaceClosure.hpp"
  48 #include "memory/oopFactory.hpp"
  49 #include "memory/resourceArea.hpp"
  50 #include "memory/universe.hpp"
  51 #include "oops/array.hpp"
  52 #include "oops/constantPool.inline.hpp"
  53 #include "oops/cpCache.inline.hpp"
  54 #include "oops/flatArrayKlass.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.hpp"
  67 #include "runtime/signature.hpp"
  68 #include "runtime/vframe.inline.hpp"
  69 #include "utilities/checkedCast.hpp"
  70 #include "utilities/copy.hpp"
  71 
  72 ConstantPool* ConstantPool::allocate(ClassLoaderData* loader_data, int length, TRAPS) {
  73   Array<u1>* tags = MetadataFactory::new_array<u1>(loader_data, length, 0, CHECK_NULL);
  74   int size = ConstantPool::size(length);

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

 486       Symbol* s = vfst.method()->method_holder()->source_file_name();
 487       if (s != nullptr) {
 488         source_file = s->as_C_string();
 489       }
 490     }
 491   }
 492   if (k != this_cp->pool_holder()) {
 493     // only print something if the classes are different
 494     if (source_file != nullptr) {
 495       log_debug(class, resolve)("%s %s %s:%d",
 496                  this_cp->pool_holder()->external_name(),
 497                  k->external_name(), source_file, line_number);
 498     } else {
 499       log_debug(class, resolve)("%s %s",
 500                  this_cp->pool_holder()->external_name(),
 501                  k->external_name());
 502     }
 503   }
 504 }
 505 
 506 void check_is_inline_type(Klass* k, TRAPS) {
 507   if (!k->is_inline_klass()) {
 508     THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
 509   }
 510 }
 511 
 512 Klass* ConstantPool::klass_at_impl(const constantPoolHandle& this_cp, int cp_index,
 513                                    TRAPS) {
 514   JavaThread* javaThread = THREAD;
 515 
 516   // A resolved constantPool entry will contain a Klass*, otherwise a Symbol*.
 517   // It is not safe to rely on the tag bit's here, since we don't have a lock, and
 518   // the entry and tag is not updated atomically.
 519   CPKlassSlot kslot = this_cp->klass_slot_at(cp_index);
 520   int resolved_klass_index = kslot.resolved_klass_index();
 521   int name_index = kslot.name_index();
 522   assert(this_cp->tag_at(name_index).is_symbol(), "sanity");
 523 
 524   // The tag must be JVM_CONSTANT_Class in order to read the correct value from
 525   // the unresolved_klasses() array.
 526   if (this_cp->tag_at(cp_index).is_klass()) {
 527     Klass* klass = this_cp->resolved_klasses()->at(resolved_klass_index);
 528     if (klass != nullptr) {
 529       return klass;
 530     }
 531   }
 532 
 533   // This tag doesn't change back to unresolved class unless at a safepoint.
 534   if (this_cp->tag_at(cp_index).is_unresolved_klass_in_error()) {
 535     // The original attempt to resolve this constant pool entry failed so find the
 536     // class of the original error and throw another error of the same class
 537     // (JVMS 5.4.3).
 538     // If there is a detail message, pass that detail message to the error.
 539     // The JVMS does not strictly require us to duplicate the same detail message,
 540     // or any internal exception fields such as cause or stacktrace.  But since the
 541     // detail message is often a class name or other literal string, we will repeat it
 542     // if we can find it in the symbol table.
 543     throw_resolution_error(this_cp, cp_index, CHECK_NULL);
 544     ShouldNotReachHere();
 545   }
 546 
 547   HandleMark hm(THREAD);
 548   Handle mirror_handle;
 549   Symbol* name = this_cp->symbol_at(name_index);
 550   bool inline_type_signature = false;
 551   Handle loader (THREAD, this_cp->pool_holder()->class_loader());
 552   Handle protection_domain (THREAD, this_cp->pool_holder()->protection_domain());
 553 
 554   Klass* k;
 555   {
 556     // Turn off the single stepping while doing class resolution
 557     JvmtiHideSingleStepping jhss(javaThread);
 558     k = SystemDictionary::resolve_or_fail(name, loader, protection_domain, true, THREAD);
 559   } //  JvmtiHideSingleStepping jhss(javaThread);
 560   if (inline_type_signature) {
 561     name->decrement_refcount();
 562   }
 563 
 564   if (!HAS_PENDING_EXCEPTION) {
 565     // preserve the resolved klass from unloading
 566     mirror_handle = Handle(THREAD, k->java_mirror());
 567     // Do access check for klasses
 568     verify_constant_pool_resolve(this_cp, k, THREAD);
 569   }
 570 
 571   if (!HAS_PENDING_EXCEPTION && inline_type_signature) {
 572     check_is_inline_type(k, THREAD);
 573   }
 574 
 575   if (!HAS_PENDING_EXCEPTION) {
 576     Klass* bottom_klass = nullptr;
 577     if (k->is_objArray_klass()) {
 578       bottom_klass = ObjArrayKlass::cast(k)->bottom_klass();
 579       assert(bottom_klass != nullptr, "Should be set");
 580       assert(bottom_klass->is_instance_klass() || bottom_klass->is_typeArray_klass(), "Sanity check");
 581     } else if (k->is_flatArray_klass()) {
 582       bottom_klass = FlatArrayKlass::cast(k)->element_klass();
 583       assert(bottom_klass != nullptr, "Should be set");
 584     }
 585   }
 586 
 587   // Failed to resolve class. We must record the errors so that subsequent attempts
 588   // to resolve this constant pool entry fail with the same error (JVMS 5.4.3).
 589   if (HAS_PENDING_EXCEPTION) {
 590     save_and_throw_exception(this_cp, cp_index, constantTag(JVM_CONSTANT_UnresolvedClass), CHECK_NULL);
 591     // If CHECK_NULL above doesn't return the exception, that means that
 592     // some other thread has beaten us and has resolved the class.
 593     // To preserve old behavior, we return the resolved class.
 594     Klass* klass = this_cp->resolved_klasses()->at(resolved_klass_index);
 595     assert(klass != nullptr, "must be resolved if exception was cleared");
 596     return klass;
 597   }
 598 
 599   // logging for class+resolve.
 600   if (log_is_enabled(Debug, class, resolve)){
 601     trace_class_resolution(this_cp, k);
 602   }
 603 
 604   Klass** adr = this_cp->resolved_klasses()->adr_at(resolved_klass_index);
 605   Atomic::release_store(adr, k);
 606   // The interpreter assumes when the tag is stored, the klass is resolved
< prev index next >