< prev index next >

src/hotspot/share/cds/classListWriter.cpp

Print this page
*** 22,18 ***
--- 22,25 ---
   *
   */
  
  #include "precompiled.hpp"
  #include "cds/cds_globals.hpp"
+ #include "cds/classListParser.hpp"
  #include "cds/classListWriter.hpp"
+ #include "cds/classPrelinker.hpp"
+ #include "cds/lambdaFormInvokers.inline.hpp"
  #include "classfile/classFileStream.hpp"
  #include "classfile/classLoader.hpp"
  #include "classfile/classLoaderData.hpp"
+ #include "classfile/classLoaderDataGraph.hpp"
  #include "classfile/moduleEntry.hpp"
+ #include "classfile/symbolTable.hpp"
  #include "classfile/systemDictionaryShared.hpp"
  #include "memory/resourceArea.hpp"
+ #include "oops/constantPool.inline.hpp"
  #include "oops/instanceKlass.hpp"
+ #include "runtime/javaCalls.hpp"
  #include "runtime/mutexLocker.hpp"
  
  fileStream* ClassListWriter::_classlist_file = nullptr;
  
  void ClassListWriter::init() {

*** 123,13 ***
      if (!SystemDictionaryShared::add_unregistered_class(Thread::current(), (InstanceKlass*)k)) {
        return;
      }
    }
  
!   // filter out java/lang/invoke/BoundMethodHandle$Species...
!   if (cfs != nullptr && cfs->source() != nullptr && strcmp(cfs->source(), "_ClassSpecializer_generateConcreteSpeciesCode") == 0) {
!     return;
    }
  
    {
      InstanceKlass* super = k->java_super();
      if (super != nullptr && !has_id(super)) {
--- 130,19 ---
      if (!SystemDictionaryShared::add_unregistered_class(Thread::current(), (InstanceKlass*)k)) {
        return;
      }
    }
  
!   if (cfs != nullptr && cfs->source() != nullptr) {
!     if (strcmp(cfs->source(), "_ClassSpecializer_generateConcreteSpeciesCode") == 0) {
!       return;
+     }
+ 
+     if (strncmp(cfs->source(), "__", 2) == 0) {
+       // generated class: __dynamic_proxy__, __JVM_LookupDefineClass__, etc
+       return;
+     }
    }
  
    {
      InstanceKlass* super = k->java_super();
      if (super != nullptr && !has_id(super)) {

*** 187,5 ***
--- 200,198 ---
  void ClassListWriter::delete_classlist() {
    if (_classlist_file != nullptr) {
      delete _classlist_file;
    }
  }
+ 
+ class ClassListWriter::WriteResolveConstantsCLDClosure : public CLDClosure {
+ public:
+   void do_cld(ClassLoaderData* cld) {
+     for (Klass* klass = cld->klasses(); klass != nullptr; klass = klass->next_link()) {
+       if (klass->is_instance_klass()) {
+         write_resolved_constants_for(InstanceKlass::cast(klass));
+       }
+     }
+   }
+ };
+ 
+ 
+ void ClassListWriter::write_resolved_constants() {
+   if (!is_enabled()) {
+     return;
+   }
+   MutexLocker lock(ClassLoaderDataGraph_lock);
+   MutexLocker lock2(ClassListFile_lock, Mutex::_no_safepoint_check_flag);
+ 
+   WriteResolveConstantsCLDClosure closure;
+   ClassLoaderDataGraph::loaded_cld_do(&closure);
+ }
+ 
+ void ClassListWriter::write_reflection_data() {
+   if (!is_enabled()) {
+     return;
+   }
+   auto collector = [&] (const InstanceKlass* ik, int id) {
+     write_reflection_data_for(const_cast<InstanceKlass*>(ik));
+   };
+   _id_table->iterate_all(collector);
+ }
+ 
+ void ClassListWriter::write_reflection_data_for(InstanceKlass* ik) {
+   ResourceMark rm;
+   outputStream* stream = _classlist_file;
+   if (!SystemDictionaryShared::is_builtin_loader(ik->class_loader_data()) || ik->is_hidden()) {
+     return; // ignore
+   }
+   if (java_lang_Class::has_reflection_data(ik->java_mirror())) {
+     EXCEPTION_MARK;
+     int rd_flags = ClassPrelinker::class_reflection_data_flags(ik, THREAD);
+     if (!HAS_PENDING_EXCEPTION) {
+       // We can't hold the lock when doing the upcall inside class_reflection_data_flags()
+       MutexLocker lock2(ClassListFile_lock, Mutex::_no_safepoint_check_flag);
+       stream->print_cr("%s %s %d", ClassListParser::CLASS_REFLECTION_DATA_TAG, ik->name()->as_C_string(), rd_flags);
+     }
+   }
+ }
+ 
+ void ClassListWriter::write_resolved_constants_for(InstanceKlass* ik) {
+   if (!SystemDictionaryShared::is_builtin_loader(ik->class_loader_data()) ||
+       ik->is_hidden()) {
+     return;
+   }
+   //if (LambdaFormInvokers::may_be_regenerated_class(ik->name())) {
+   //  return;
+   //}
+   if (!has_id(ik)) { // do not resolve CP for classes loaded by custom loaders.
+     return;
+   }
+ 
+   ResourceMark rm;
+   ConstantPool* cp = ik->constants();
+   GrowableArray<bool> list(cp->length(), cp->length(), false);
+ 
+   for (int cp_index = 1; cp_index < cp->length(); cp_index++) { // Index 0 is unused
+     switch (cp->tag_at(cp_index).value()) {
+     case JVM_CONSTANT_Class:
+       {
+         Klass* k = cp->resolved_klass_at(cp_index);
+         if (k->is_instance_klass()) {
+           list.at_put(cp_index, true);
+         }
+       }
+       break;
+     }
+   }
+ 
+   if (cp->cache() != nullptr) {
+     Array<ResolvedIndyEntry>* indy_entries = cp->cache()->resolved_indy_entries();
+     if (indy_entries != nullptr) {
+       for (int i = 0; i < indy_entries->length(); i++) {
+         ResolvedIndyEntry* rie = indy_entries->adr_at(i);
+         int cp_index = rie->constant_pool_index();
+         if (rie->is_resolved()) {
+           list.at_put(cp_index, true);
+         }
+       }
+     }
+ 
+     Array<ResolvedFieldEntry>* field_entries = cp->cache()->resolved_field_entries();
+     if (field_entries != nullptr) {
+       for (int i = 0; i < field_entries->length(); i++) {
+         ResolvedFieldEntry* rfe = field_entries->adr_at(i);
+         if (rfe->is_resolved(Bytecodes::_getstatic) ||
+             rfe->is_resolved(Bytecodes::_putstatic) ||
+             rfe->is_resolved(Bytecodes::_getfield) ||
+             rfe->is_resolved(Bytecodes::_putfield)) {
+           list.at_put(rfe->constant_pool_index(), true);
+         }
+       }
+     }
+ 
+     Array<ResolvedMethodEntry>* method_entries = cp->cache()->resolved_method_entries();
+     if (method_entries != nullptr) {
+       for (int i = 0; i < method_entries->length(); i++) {
+         ResolvedMethodEntry* rme = method_entries->adr_at(i);
+         if (rme->is_resolved(Bytecodes::_invokevirtual) ||
+             rme->is_resolved(Bytecodes::_invokespecial) ||
+             rme->is_resolved(Bytecodes::_invokeinterface) ||
+             rme->is_resolved(Bytecodes::_invokestatic) ||
+             rme->is_resolved(Bytecodes::_invokehandle)) {
+           list.at_put(rme->constant_pool_index(), true);
+         }
+       }
+     }
+   }
+ 
+   if (list.length() > 0) {
+     outputStream* stream = _classlist_file;
+     stream->print("@cp %s", ik->name()->as_C_string());
+     for (int i = 0; i < list.length(); i++) {
+       if (list.at(i)) {
+         constantTag cp_tag = cp->tag_at(i).value();
+         switch (cp_tag.value()) {
+ //          case JVM_CONSTANT_UnresolvedClass:        break;
+ //          case JVM_CONSTANT_UnresolvedClassInError: break;
+           case JVM_CONSTANT_Class:                  break;
+           case JVM_CONSTANT_Fieldref:               break;
+           case JVM_CONSTANT_Methodref:              break;
+           case JVM_CONSTANT_InterfaceMethodref:     break;
+           case JVM_CONSTANT_InvokeDynamic:          break;
+ 
+           default:
+             log_warning(cds, resolve)("Unsupported constant pool index %d: %s (type=%d)",
+                                       i, cp_tag.internal_name(), cp_tag.value());
+         }
+ 
+         stream->print(" %d", i);
+       }
+     }
+     stream->cr();
+   }
+ }
+ 
+ void ClassListWriter::write_loader_negative_lookup_cache_for(oop loader, const char* loader_type) {
+   TempNewSymbol method = SymbolTable::new_symbol("negativeLookupCacheContents");
+   TempNewSymbol signature = SymbolTable::new_symbol("()Ljava/lang/String;");
+ 
+   EXCEPTION_MARK;
+   HandleMark hm(THREAD);
+ 
+   JavaValue result(T_OBJECT);
+   JavaCalls::call_virtual(&result,
+                           Handle(THREAD, loader),
+                           loader->klass(),
+                           method,
+                           signature,
+                           CHECK);
+ 
+   if (HAS_PENDING_EXCEPTION) {
+     log_warning(cds)("Error during BuiltinClassLoader::negativeLookupCacheContents() call for %s loader", loader_type);
+     CLEAR_PENDING_EXCEPTION;
+     return;
+   } else if (result.get_oop() == nullptr) {
+     return;
+   }
+ 
+   ResourceMark rm;
+   const char* cache_contents = java_lang_String::as_utf8_string(result.get_oop());
+   log_debug(cds)("%s loader negative cache: %s", loader_type, cache_contents);
+ 
+   outputStream* stream = _classlist_file;
+   const size_t buffer_size = strlen(ClassListParser::LOADER_NEGATIVE_CACHE_TAG) + 1 /* for space*/
+                     + strlen(loader_type) + 1 /* for space */ + strlen(cache_contents) + 1 /* for null character */;
+   char* buffer = NEW_C_HEAP_ARRAY(char, buffer_size, mtInternal);
+   _classlist_file->set_scratch_buffer(buffer, buffer_size);
+   MutexLocker lock2(ClassListFile_lock, Mutex::_no_safepoint_check_flag);
+   stream->print("%s %s %s", ClassListParser::LOADER_NEGATIVE_CACHE_TAG, loader_type, cache_contents);
+   stream->cr();
+   _classlist_file->set_scratch_buffer(nullptr, 0);
+ }
+ 
+ void ClassListWriter::write_loader_negative_lookup_cache() {
+   if (!is_enabled()) {
+     return;
+   }
+ 
+   write_loader_negative_lookup_cache_for(SystemDictionary::java_platform_loader(), "platform");
+   write_loader_negative_lookup_cache_for(SystemDictionary::java_system_loader(), "app");
+ }
< prev index next >