From 78094fcf904d2999b8eaefe3195da1ab157727ed Mon Sep 17 00:00:00 2001 From: kuenking111 Date: Wed, 20 Dec 2023 15:28:41 +0800 Subject: [PATCH] Fix an error caused by anonymous when AppCDS generates jsa --- ...sed-by-anonymous-when-AppCDS-generat.patch | 111 ++++++++++++++++++ openjdk-1.8.0.spec | 7 +- 2 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 Fix-an-error-caused-by-anonymous-when-AppCDS-generat.patch diff --git a/Fix-an-error-caused-by-anonymous-when-AppCDS-generat.patch b/Fix-an-error-caused-by-anonymous-when-AppCDS-generat.patch new file mode 100644 index 0000000..6b88b2b --- /dev/null +++ b/Fix-an-error-caused-by-anonymous-when-AppCDS-generat.patch @@ -0,0 +1,111 @@ +From: l00803608 +Subject: Fix an error caused by anonymous when AppCDS generates jsa +--- + hotspot/src/share/vm/classfile/dictionary.hpp | 1 + + hotspot/src/share/vm/classfile/systemDictionary.cpp | 13 ++++++++++++- + hotspot/src/share/vm/classfile/systemDictionary.hpp | 1 + + hotspot/src/share/vm/memory/metaspaceShared.cpp | 8 ++++---- + hotspot/src/share/vm/prims/unsafe.cpp | 6 ------ + 5 files changed, 18 insertions(+), 11 deletions(-) + +diff --git a/hotspot/src/share/vm/classfile/dictionary.hpp b/hotspot/src/share/vm/classfile/dictionary.hpp +index 8a88fa2e4..e5d98184b 100644 +--- a/hotspot/src/share/vm/classfile/dictionary.hpp ++++ b/hotspot/src/share/vm/classfile/dictionary.hpp +@@ -394,6 +394,7 @@ class SymbolPropertyEntry : public HashtableEntry { + // MethodHandle.invoke(S)T, for all signatures (S)T. + class SymbolPropertyTable : public Hashtable { + friend class VMStructs; ++ friend class SystemDictionary; + private: + SymbolPropertyEntry* bucket(int i) { + return (SymbolPropertyEntry*) Hashtable::bucket(i); +diff --git a/hotspot/src/share/vm/classfile/systemDictionary.cpp b/hotspot/src/share/vm/classfile/systemDictionary.cpp +index c8f66e830..59ab829c7 100644 +--- a/hotspot/src/share/vm/classfile/systemDictionary.cpp ++++ b/hotspot/src/share/vm/classfile/systemDictionary.cpp +@@ -1031,7 +1031,6 @@ Klass* SystemDictionary::parse_stream(Symbol* class_name, + // as the host_klass + assert(EnableInvokeDynamic, ""); + guarantee(host_klass->class_loader() == class_loader(), "should be the same"); +- guarantee(!DumpSharedSpaces, "must not create anonymous classes when dumping"); + loader_data = ClassLoaderData::anonymous_class_loader_data(class_loader(), CHECK_NULL); + loader_data->record_dependency(host_klass(), CHECK_NULL); + } else { +@@ -1498,6 +1497,18 @@ instanceKlassHandle SystemDictionary::load_shared_class(instanceKlassHandle ik, + } + return ik; + } ++ ++void SystemDictionary::clear_invoke_method_table() { ++ SymbolPropertyEntry* spe = NULL; ++ for (int index = 0; index < _invoke_method_table->table_size(); index++) { ++ SymbolPropertyEntry* p = _invoke_method_table->bucket(index); ++ while (p != NULL) { ++ spe = p; ++ p = p->next(); ++ _invoke_method_table->free_entry(spe); ++ } ++ } ++} + #endif // INCLUDE_CDS + + instanceKlassHandle SystemDictionary::load_instance_class(Symbol* class_name, Handle class_loader, TRAPS) { +diff --git a/hotspot/src/share/vm/classfile/systemDictionary.hpp b/hotspot/src/share/vm/classfile/systemDictionary.hpp +index e39c1de62..83ca3794b 100644 +--- a/hotspot/src/share/vm/classfile/systemDictionary.hpp ++++ b/hotspot/src/share/vm/classfile/systemDictionary.hpp +@@ -652,6 +652,7 @@ public: + static bool is_ext_class_loader(Handle class_loader); + static bool is_app_class_loader(Handle class_loader); + static bool is_builtin_loader(Handle class_loader); ++ static void clear_invoke_method_table(); + + protected: + static Klass* find_shared_class(Symbol* class_name); +diff --git a/hotspot/src/share/vm/memory/metaspaceShared.cpp b/hotspot/src/share/vm/memory/metaspaceShared.cpp +index eea79cc09..1576f4fbc 100644 +--- a/hotspot/src/share/vm/memory/metaspaceShared.cpp ++++ b/hotspot/src/share/vm/memory/metaspaceShared.cpp +@@ -793,6 +793,10 @@ void MetaspaceShared::preload_and_dump(TRAPS) { + link_and_cleanup_shared_classes(CATCH); + tty->print_cr("Rewriting and linking classes: done"); + ++ tty->print("clear _invoke_method_table ..."); ++ SystemDictionary::clear_invoke_method_table(); ++ tty->print_cr(" done"); ++ + // At this point, many classes have been loaded. + // Gather systemDictionary classes in a global array and do everything to + // that so we don't have to walk the SystemDictionary again. +@@ -829,10 +833,6 @@ int MetaspaceShared::preload_and_dump(const char * class_list_path, + TempNewSymbol class_name_symbol = SymbolTable::new_permanent_symbol(class_name, THREAD); + guarantee(!HAS_PENDING_EXCEPTION, "Exception creating a symbol."); + +- // If preload_and_dump has anonymous class failed ,pls del this class_name in classlist +- if (TraceClassLoading) { +- tty->print_cr("preload_and_dump start: %s", class_name); +- } + Handle loader = UseAppCDS ? SystemDictionary::java_system_loader() : Handle(); + Klass* klass = SystemDictionary::resolve_or_null(class_name_symbol, + loader, +diff --git a/hotspot/src/share/vm/prims/unsafe.cpp b/hotspot/src/share/vm/prims/unsafe.cpp +index d6c33dd33..f1bd5799d 100644 +--- a/hotspot/src/share/vm/prims/unsafe.cpp ++++ b/hotspot/src/share/vm/prims/unsafe.cpp +@@ -1040,12 +1040,6 @@ Unsafe_DefineAnonymousClass_impl(JNIEnv *env, + HeapWord* *temp_alloc, + TRAPS) { + +- if (DumpSharedSpaces) { +- tty->print_cr("failed: must not create anonymous classes when dumping."); +- tty->print_cr("Please delete the last class_name prefixed with \"preload_and_dump start\" from -XX:SharedClassListFile to avoid anonymous classes."); +- JVM_Halt(0); +- } +- + if (UsePerfData) { + ClassLoader::unsafe_defineClassCallCounter()->inc(); + } +-- +2.19.1 + diff --git a/openjdk-1.8.0.spec b/openjdk-1.8.0.spec index eb0b024..02c2131 100644 --- a/openjdk-1.8.0.spec +++ b/openjdk-1.8.0.spec @@ -925,7 +925,7 @@ Provides: java-%{javaver}-%{origin}-accessibility%{?1} = %{epoch}:%{version}-%{r Name: java-%{javaver}-%{origin} Version: %{javaver}.%{updatever}.%{buildver} -Release: 2 +Release: 3 # java-1.5.0-ibm from jpackage.org set Epoch to 1 for unknown reasons # and this change was brought into RHEL-4. java-1.5.0-ibm packages # also included the epoch in their virtual provides. This created a @@ -1287,6 +1287,7 @@ Patch405: 8148470-Metadata-print-routines-should-not-print-to-.patch Patch406: 8293344-JDK-8242181-broke-stack-printing-for-non-att.patch Patch407: 8278794-Infinite-loop-in-DeflaterOutputStream.finish.patch Patch408: 8312065-Socket.connect-does-not-timeout-when-profili.patch +Patch409: Fix-an-error-caused-by-anonymous-when-AppCDS-generat.patch ############################################# # @@ -1900,6 +1901,7 @@ pushd %{top_level_dir_name} %patch406 -p1 %patch407 -p1 %patch408 -p1 +%patch409 -p1 %ifarch riscv64 %patch2000 -p1 @@ -2543,6 +2545,9 @@ require "copy_jdk_configs.lua" %endif %changelog +* Wed Dec 20 2023 kuenking111 - 1:1.8.0.392-b08.4 +- Add Fix-an-error-caused-by-anonymous-when-AppCDS-generat.patch + * Mon Oct 30 2023 kuenking111 - 1:1.8.0.392-b08.2 - remove add-8142508-To-bring-j.u.z.ZipFile-s-native-implemen.patch - remove add-8226530-ZipFile-reads-wrong-entry-size-from-ZIP6.patch -- Gitee