< prev index next >

src/hotspot/share/cds/lambdaFormInvokers.cpp

Print this page
@@ -21,10 +21,11 @@
   * questions.
   *
   */
  
  #include "cds/archiveBuilder.hpp"
+ #include "cds/cdsConfig.hpp"
  #include "cds/lambdaFormInvokers.hpp"
  #include "cds/metaspaceShared.hpp"
  #include "cds/regeneratedClasses.hpp"
  #include "classfile/classFileStream.hpp"
  #include "classfile/classLoadInfo.hpp"

@@ -87,31 +88,19 @@
      log_info(cds)("Regenerate MethodHandle Holder classes...done");
    }
  };
  
  void LambdaFormInvokers::regenerate_holder_classes(TRAPS) {
+   if (!CDSConfig::is_dumping_regenerated_lambdaform_invokers()) {
+     return;
+   }
    PrintLambdaFormMessage plm;
    if (_lambdaform_lines == nullptr || _lambdaform_lines->length() == 0) {
      log_info(cds)("Nothing to regenerate for holder classes");
      return;
    }
  
-   if (CDSConfig::is_dumping_static_archive() && CDSConfig::is_dumping_invokedynamic()) {
-     // Work around JDK-8310831, as some methods in lambda form holder classes may not get generated.
-     log_info(cds)("Archived MethodHandles may refer to lambda form holder classes. Cannot regenerate.");
-     return;
-   }
- 
-   if (CDSConfig::is_dumping_dynamic_archive() && CDSConfig::is_dumping_aot_linked_classes() &&
-       CDSConfig::is_using_aot_linked_classes()) {
-     // The base archive may have some pre-resolved CP entries that point to the lambda form holder
-     // classes in the base archive. If we generate new versions of these classes, those CP entries
-     // will be pointing to invalid classes.
-     log_info(cds)("Base archive already has aot-linked lambda form holder classes. Cannot regenerate.");
-     return;
-   }
- 
    ResourceMark rm(THREAD);
  
    Symbol* cds_name  = vmSymbols::jdk_internal_misc_CDS();
    Klass*  cds_klass = SystemDictionary::resolve_or_null(cds_name, THREAD);
    guarantee(cds_klass != nullptr, "jdk/internal/misc/CDS must exist!");

@@ -179,11 +168,13 @@
        int len = h_bytes->length();
        // make a copy of class bytes so GC will not affect us.
        char *buf = NEW_RESOURCE_ARRAY(char, len);
        memcpy(buf, (char*)h_bytes->byte_at_addr(0), len);
        ClassFileStream st((u1*)buf, len, nullptr);
-       regenerate_class(class_name, st, CHECK);
+       if (!CDSConfig::is_dumping_invokedynamic() /* work around JDK-8310831 */) {
+         regenerate_class(class_name, st, CHECK);
+       }
      }
    }
  }
  
  void LambdaFormInvokers::regenerate_class(char* class_name, ClassFileStream& st, TRAPS) {

@@ -243,11 +234,11 @@
            index++;
          }
        }
        assert(index == count, "Should match");
      }
-     log_debug(cds)("Total LF lines stored into static archive: %d", count);
+     log_debug(cds)("Total LF lines stored into %s: %d", CDSConfig::type_of_archive_being_written(), count);
    }
  }
  
  void LambdaFormInvokers::read_static_archive_invokers() {
    if (_static_archive_invokers != nullptr) {

@@ -255,16 +246,22 @@
        u4 offset = _static_archive_invokers->at(i);
        Array<char>* line = ArchiveUtils::offset_to_archived_address<Array<char>*>(offset);
        char* str = line->adr_at(0);
        append(str);
      }
-     log_debug(cds)("Total LF lines read from static archive: %d", _static_archive_invokers->length());
+     log_debug(cds)("Total LF lines read from %s: %d", CDSConfig::type_of_archive_being_loaded(), _static_archive_invokers->length());
    }
  }
  
  void LambdaFormInvokers::serialize(SerializeClosure* soc) {
    soc->do_ptr(&_static_archive_invokers);
    if (soc->reading() && CDSConfig::is_dumping_final_static_archive()) {
-     LambdaFormInvokers::read_static_archive_invokers();
+     if (!CDSConfig::is_dumping_aot_linked_classes()) {
+       // See CDSConfig::is_dumping_regenerated_lambdaform_invokers() -- a dynamic archive can
+       // regenerate lambda form invokers only if the base archive does not contain aot-linked classes.
+       // If so, we copy the contents of _static_archive_invokers (from the preimage) into
+       //_lambdaform_lines, which will be written as _static_archive_invokers into final static archive.
+       LambdaFormInvokers::read_static_archive_invokers();
+     }
      _static_archive_invokers = nullptr;
    }
  }
< prev index next >