Skip to content

Commit

Permalink
Rename ClassLoaderRelation to RetentionDirection; it is better self-d…
Browse files Browse the repository at this point in the history
…ocumenting this way.
  • Loading branch information
szegedi committed Jan 10, 2021
1 parent cb399d7 commit 81bf988
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/jdk.dynalink/share/classes/jdk/dynalink/BiClassValue.java
Expand Up @@ -157,10 +157,10 @@ private static final class BiClassValuesRoot<T> extends ClassValue<BiClassValues
}
}

private enum ClassLoaderRelation {
DESCENDANT,
ANCESTOR,
UNRELATED
private enum RetentionDirection {
FORWARD,
REVERSE,
NEITHER
}

private final BiClassValuesRoot<T> root = new BiClassValuesRoot<>();
Expand All @@ -186,14 +186,14 @@ final T get(final Class<?> c1, final Class<?> c2) {
}

// Value is uncached, compute it and cache if possible.
switch (getClassLoaderRelation(c1, c2)) {
case DESCENDANT:
switch (getRetentionDirection(c1, c2)) {
case FORWARD:
// loader of c1 can see loader of c2, store value for (c1, c2) in cv1's forward map
return cv1.computeForward(c2, cy -> compute.apply(c1, cy));
case ANCESTOR:
case REVERSE:
// loader of c2 can see loader of c1, store value for (c1, c2) in cv2's reverse map
return cv2.computeReverse(c1, cx -> compute.apply(cx, c2));
case UNRELATED:
case NEITHER:
// Class loaders are unrelated; compute and return uncached.
return compute.apply(c1, c2);
default:
Expand All @@ -204,16 +204,16 @@ final T get(final Class<?> c1, final Class<?> c2) {
private static final AccessControlContext GET_CLASS_LOADER_CONTEXT =
AccessControlContextFactory.createAccessControlContext("getClassLoader");

private static ClassLoaderRelation getClassLoaderRelation(Class<?> from, Class<?> to) {
return AccessController.doPrivileged((PrivilegedAction<ClassLoaderRelation>) () -> {
private static RetentionDirection getRetentionDirection(Class<?> from, Class<?> to) {
return AccessController.doPrivileged((PrivilegedAction<RetentionDirection>) () -> {
final ClassLoader cl1 = from.getClassLoader();
final ClassLoader cl2 = to.getClassLoader();
if (canReferenceDirectly(cl1, cl2)) {
return ClassLoaderRelation.DESCENDANT;
return RetentionDirection.FORWARD;
} else if (canReferenceDirectly(cl2, cl1)) {
return ClassLoaderRelation.ANCESTOR;
return RetentionDirection.REVERSE;
}
return ClassLoaderRelation.UNRELATED;
return RetentionDirection.NEITHER;
}, GET_CLASS_LOADER_CONTEXT);
}
}

0 comments on commit 81bf988

Please sign in to comment.