Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8304164: jdk/classfile/CorpusTest.java still fails after JDK-8303910 #13037

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -110,6 +110,10 @@ public boolean isAssignableFrom(ClassDesc thisClass, ClassDesc fromClass) {

public static final class CachedClassHierarchyResolver implements ClassHierarchyResolver {

//this instance should never appear in the cache nor leak out
private static final ClassHierarchyResolver.ClassHierarchyInfo NOPE =
new ClassHierarchyResolver.ClassHierarchyInfo(null, false, null);

private final Function<ClassDesc, InputStream> streamProvider;
private final Map<ClassDesc, ClassHierarchyResolver.ClassHierarchyInfo> resolvedCache;

@@ -124,9 +128,11 @@ public CachedClassHierarchyResolver(Function<ClassDesc, InputStream> classStream
// empty ClInfo is stored in case of an exception to avoid repeated scanning failures
@Override
public ClassHierarchyResolver.ClassHierarchyInfo getClassInfo(ClassDesc classDesc) {
var res = resolvedCache.get(classDesc);
//additional test for null value is important to avoid repeated resolution attempts
if (res == null && !resolvedCache.containsKey(classDesc)) {
//using NOPE to distinguish between null value and non-existent record in the cache
//this code is on JDK bootstrap critical path, so cannot use lambdas here
var res = resolvedCache.getOrDefault(classDesc, NOPE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolvedCache is a Collections.synchronizedMap backed by a HashMap. So the getOrDefault() (internally) synchronizes on the resolvedCache instance itself and thus this operation would be thread safe in context of access to this cache in rest of this code. So what you propose here looks good to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

if (res == NOPE) {
res = null;
var ci = streamProvider.apply(classDesc);
if (ci != null) {
try (var in = new DataInputStream(new BufferedInputStream(ci))) {