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 8, 2023
1 parent b09c6e0 commit 64e5be6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 10 additions & 2 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 @@ -1713,7 +1713,15 @@ protected Package definePackage(String name, String specTitle,
final Package new_pkg = new Package(name, specTitle, specVersion, specVendor,
implTitle, implVersion, implVendor,
sealBase, this);
if (packages.computeIfAbsent(name, key -> new_pkg) != new_pkg) {

Function getNewPkg = new Function<Object, Object>() {
@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;
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 64e5be6

Please sign in to comment.