From 64e5be60c579fa0f363535decc3a3e048aedce84 Mon Sep 17 00:00:00 2001 From: Jiawei_Tang Date: Fri, 8 Dec 2023 10:58:26 +0800 Subject: [PATCH] [EagerAppCDS] fix bug caused by using lambda in ClassLoader.java Summary: don't use lambda in ClassLoader.java since jvm may fail during initializing Testing: aqavit test Reviewers: lingjun-cg, yuleil Issue: https://github.com/dragonwell-project/dragonwell8/issues/603 --- jdk/src/share/classes/java/lang/ClassLoader.java | 12 ++++++++++-- .../lang/invoke/lambda/LogGeneratedClassesTest.java | 6 ++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/jdk/src/share/classes/java/lang/ClassLoader.java b/jdk/src/share/classes/java/lang/ClassLoader.java index 9aeb53e324e..4fde2ba53a8 100644 --- a/jdk/src/share/classes/java/lang/ClassLoader.java +++ b/jdk/src/share/classes/java/lang/ClassLoader.java @@ -48,7 +48,7 @@ import java.security.cert.Certificate; import java.util.*; import java.util.concurrent.ConcurrentHashMap; - +import java.util.function.Function; /** * A class loader is an object that is responsible for loading classes. The * class ClassLoader is an abstract class. Given the new_pkg) != new_pkg) { + + Function getNewPkg = new Function() { + @Override + public java.lang.Object apply(java.lang.Object t) { + return new_pkg; + } + }; + + if (packages.computeIfAbsent(name, getNewPkg) != new_pkg) { throw new IllegalArgumentException(name); } return pkg; diff --git a/jdk/test/java/lang/invoke/lambda/LogGeneratedClassesTest.java b/jdk/test/java/lang/invoke/lambda/LogGeneratedClassesTest.java index a169a3db283..33acc50d667 100644 --- a/jdk/test/java/lang/invoke/lambda/LogGeneratedClassesTest.java +++ b/jdk/test/java/lang/invoke/lambda/LogGeneratedClassesTest.java @@ -125,8 +125,7 @@ public void testLogging() throws IOException { "-Djava.security.manager", "com.example.TestLambda"); // dump/com/example + 2 class files - // dump/java/lang + 1 class file - assertEquals(Files.walk(Paths.get("dump")).count(), 8, "Two lambda captured"); + assertEquals(Files.walk(Paths.get("dump")).count(), 5, "Two lambda captured"); tr.assertZero("Should still return 0"); } @@ -237,8 +236,7 @@ public void testLoggingException() throws IOException { .count(), 2, "show error each capture"); // dumpLong/com/example/nosense/nosense - // dumpLong/java/lang + 1 file - assertEquals(Files.walk(Paths.get("dumpLong")).count(), 8, "Two lambda captured failed to log"); + assertEquals(Files.walk(Paths.get("dumpLong")).count(), 5, "Two lambda captured failed to log"); tr.assertZero("Should still return 0"); } }