Skip to content

Commit

Permalink
[EagerAppCDS] fix bug caused by using lambda in ClassLoader.java
Browse files Browse the repository at this point in the history
Summary: Don't use lambda in ClassLoader.java since jvm may fail during
initializing.

Testing: aqavit test

Reviewers: lingjun-cg, yuleil

Issue: #603
  • Loading branch information
jia-wei-tang committed Dec 13, 2023
1 parent ec6f074 commit 426b064
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
6 changes: 3 additions & 3 deletions jdk/src/share/classes/java/lang/ClassLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <tt>ClassLoader</tt> is an abstract class. Given the <a
Expand Down Expand Up @@ -1710,10 +1710,10 @@ protected Package definePackage(String name, String specTitle,
if (pkg != null) {
throw new IllegalArgumentException(name);
}
final Package new_pkg = new Package(name, specTitle, specVersion, specVendor,
pkg= new Package(name, specTitle, specVersion, specVendor,
implTitle, implVersion, implVendor,
sealBase, this);
if (packages.computeIfAbsent(name, key -> new_pkg) != new_pkg) {
if (packages.putIfAbsent(name, pkg) != null) {
throw new IllegalArgumentException(name);
}
return pkg;
Expand Down
6 changes: 2 additions & 4 deletions jdk/test/java/lang/invoke/lambda/LogGeneratedClassesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down Expand Up @@ -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");
}
}

0 comments on commit 426b064

Please sign in to comment.