mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2026-01-24 09:20:50 +01:00
8142422: Smaller Dynalink API adjustments
Reviewed-by: hannesw, sundar
This commit is contained in:
@@ -139,7 +139,7 @@ import java.util.Objects;
|
||||
* {@code SET_ELEMENT}; other standard operations should not be combined. The
|
||||
* constructor will allow any combination of operations, though.
|
||||
*/
|
||||
public class CompositeOperation implements Operation {
|
||||
public final class CompositeOperation implements Operation {
|
||||
private final Operation[] operations;
|
||||
|
||||
/**
|
||||
@@ -228,10 +228,10 @@ public class CompositeOperation implements Operation {
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (obj == null || obj.getClass() != CompositeOperation.class) {
|
||||
return false;
|
||||
if (obj instanceof CompositeOperation) {
|
||||
return Arrays.equals(operations, ((CompositeOperation)obj).operations);
|
||||
}
|
||||
return Arrays.equals(operations, ((CompositeOperation)obj).operations);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -137,7 +137,7 @@ public final class DynamicLinkerFactory {
|
||||
* Default value for {@link #setUnstableRelinkThreshold(int) unstable relink
|
||||
* threshold}.
|
||||
*/
|
||||
public static final int DEFAULT_UNSTABLE_RELINK_THRESHOLD = 8;
|
||||
private static final int DEFAULT_UNSTABLE_RELINK_THRESHOLD = 8;
|
||||
|
||||
private boolean classLoaderExplicitlySet = false;
|
||||
private ClassLoader classLoader;
|
||||
@@ -272,7 +272,7 @@ public final class DynamicLinkerFactory {
|
||||
/**
|
||||
* Sets the unstable relink threshold; the number of times a call site is
|
||||
* relinked after which it will be considered unstable, and subsequent link
|
||||
* requests for it will indicate this.
|
||||
* requests for it will indicate this. Defaults to 8 when not set explicitly.
|
||||
* @param unstableRelinkThreshold the new threshold. Must not be less than
|
||||
* zero. The value of zero means that call sites will never be considered
|
||||
* unstable.
|
||||
|
||||
@@ -98,7 +98,7 @@ import java.util.Objects;
|
||||
* the documentation for all {@link StandardOperation} members describes how
|
||||
* they are affected by being incorporated into a named operation.
|
||||
*/
|
||||
public class NamedOperation implements Operation {
|
||||
public final class NamedOperation implements Operation {
|
||||
private final Operation baseOperation;
|
||||
private final Object name;
|
||||
|
||||
@@ -145,13 +145,11 @@ public class NamedOperation implements Operation {
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
} else if(obj.getClass() != NamedOperation.class) {
|
||||
return false;
|
||||
if (obj instanceof NamedOperation) {
|
||||
final NamedOperation other = (NamedOperation)obj;
|
||||
return baseOperation.equals(other.baseOperation) && name.equals(other.name);
|
||||
}
|
||||
final NamedOperation other = (NamedOperation)obj;
|
||||
return baseOperation.equals(other.baseOperation) && name.equals(other.name);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -93,11 +93,11 @@ import java.lang.reflect.Member;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import jdk.internal.dynalink.CallSiteDescriptor;
|
||||
import jdk.internal.dynalink.CompositeOperation;
|
||||
import jdk.internal.dynalink.NamedOperation;
|
||||
@@ -200,20 +200,20 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
||||
|
||||
abstract FacetIntrospector createFacetIntrospector();
|
||||
|
||||
Collection<String> getReadablePropertyNames() {
|
||||
Set<String> getReadablePropertyNames() {
|
||||
return getUnmodifiableKeys(propertyGetters);
|
||||
}
|
||||
|
||||
Collection<String> getWritablePropertyNames() {
|
||||
Set<String> getWritablePropertyNames() {
|
||||
return getUnmodifiableKeys(propertySetters);
|
||||
}
|
||||
|
||||
Collection<String> getMethodNames() {
|
||||
Set<String> getMethodNames() {
|
||||
return getUnmodifiableKeys(methods);
|
||||
}
|
||||
|
||||
private static Collection<String> getUnmodifiableKeys(final Map<String, ?> m) {
|
||||
return Collections.unmodifiableCollection(m.keySet());
|
||||
private static Set<String> getUnmodifiableKeys(final Map<String, ?> m) {
|
||||
return Collections.unmodifiableSet(m.keySet());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -416,9 +416,7 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
||||
return new GuardedInvocationComponent(invocation, getClassGuard(type), clazz, ValidationType.EXACT_CLASS);
|
||||
}
|
||||
|
||||
SingleDynamicMethod getConstructorMethod(final String signature) {
|
||||
return null;
|
||||
}
|
||||
abstract SingleDynamicMethod getConstructorMethod(final String signature);
|
||||
|
||||
private MethodHandle getAssignableGuard(final MethodType type) {
|
||||
return Guards.asType(assignableGuard, type);
|
||||
|
||||
@@ -152,6 +152,11 @@ class BeanLinker extends AbstractJavaLinker implements TypeBasedGuardingDynamicL
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
SingleDynamicMethod getConstructorMethod(final String signature) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static final MethodHandle GET_LIST_ELEMENT = Lookup.PUBLIC.findVirtual(List.class, "get",
|
||||
MethodType.methodType(Object.class, int.class));
|
||||
|
||||
|
||||
@@ -84,8 +84,8 @@
|
||||
package jdk.internal.dynalink.beans;
|
||||
|
||||
import java.lang.invoke.MethodHandles.Lookup;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import jdk.internal.dynalink.DynamicLinkerFactory;
|
||||
import jdk.internal.dynalink.StandardOperation;
|
||||
import jdk.internal.dynalink.linker.GuardedInvocation;
|
||||
@@ -229,11 +229,11 @@ public class BeansLinker implements GuardingDynamicLinker {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of names of all readable instance properties of a class.
|
||||
* Returns a set of names of all readable instance properties of a class.
|
||||
* @param clazz the class
|
||||
* @return a collection of names of all readable instance properties of a class.
|
||||
* @return a set of names of all readable instance properties of a class.
|
||||
*/
|
||||
public static Collection<String> getReadableInstancePropertyNames(final Class<?> clazz) {
|
||||
public static Set<String> getReadableInstancePropertyNames(final Class<?> clazz) {
|
||||
final TypeBasedGuardingDynamicLinker linker = getLinkerForClass(clazz);
|
||||
if(linker instanceof BeanLinker) {
|
||||
return ((BeanLinker)linker).getReadablePropertyNames();
|
||||
@@ -242,11 +242,11 @@ public class BeansLinker implements GuardingDynamicLinker {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of names of all writable instance properties of a class.
|
||||
* Returns a set of names of all writable instance properties of a class.
|
||||
* @param clazz the class
|
||||
* @return a collection of names of all writable instance properties of a class.
|
||||
* @return a set of names of all writable instance properties of a class.
|
||||
*/
|
||||
public static Collection<String> getWritableInstancePropertyNames(final Class<?> clazz) {
|
||||
public static Set<String> getWritableInstancePropertyNames(final Class<?> clazz) {
|
||||
final TypeBasedGuardingDynamicLinker linker = getLinkerForClass(clazz);
|
||||
if(linker instanceof BeanLinker) {
|
||||
return ((BeanLinker)linker).getWritablePropertyNames();
|
||||
@@ -255,11 +255,11 @@ public class BeansLinker implements GuardingDynamicLinker {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of names of all instance methods of a class.
|
||||
* Returns a set of names of all instance methods of a class.
|
||||
* @param clazz the class
|
||||
* @return a collection of names of all instance methods of a class.
|
||||
* @return a set of names of all instance methods of a class.
|
||||
*/
|
||||
public static Collection<String> getInstanceMethodNames(final Class<?> clazz) {
|
||||
public static Set<String> getInstanceMethodNames(final Class<?> clazz) {
|
||||
final TypeBasedGuardingDynamicLinker linker = getLinkerForClass(clazz);
|
||||
if(linker instanceof BeanLinker) {
|
||||
return ((BeanLinker)linker).getMethodNames();
|
||||
@@ -268,29 +268,29 @@ public class BeansLinker implements GuardingDynamicLinker {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of names of all readable static properties of a class.
|
||||
* Returns a set of names of all readable static properties of a class.
|
||||
* @param clazz the class
|
||||
* @return a collection of names of all readable static properties of a class.
|
||||
* @return a set of names of all readable static properties of a class.
|
||||
*/
|
||||
public static Collection<String> getReadableStaticPropertyNames(final Class<?> clazz) {
|
||||
public static Set<String> getReadableStaticPropertyNames(final Class<?> clazz) {
|
||||
return StaticClassLinker.getReadableStaticPropertyNames(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of names of all writable static properties of a class.
|
||||
* Returns a set of names of all writable static properties of a class.
|
||||
* @param clazz the class
|
||||
* @return a collection of names of all writable static properties of a class.
|
||||
* @return a set of names of all writable static properties of a class.
|
||||
*/
|
||||
public static Collection<String> getWritableStaticPropertyNames(final Class<?> clazz) {
|
||||
public static Set<String> getWritableStaticPropertyNames(final Class<?> clazz) {
|
||||
return StaticClassLinker.getWritableStaticPropertyNames(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of names of all static methods of a class.
|
||||
* Returns a set of names of all static methods of a class.
|
||||
* @param clazz the class
|
||||
* @return a collection of names of all static methods of a class.
|
||||
* @return a set of names of all static methods of a class.
|
||||
*/
|
||||
public static Collection<String> getStaticMethodNames(final Class<?> clazz) {
|
||||
public static Set<String> getStaticMethodNames(final Class<?> clazz) {
|
||||
return StaticClassLinker.getStaticMethodNames(clazz);
|
||||
}
|
||||
|
||||
|
||||
@@ -136,6 +136,10 @@ public final class StaticClass implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* The runtime {@code Class} object whose static members this
|
||||
* {@code StaticClass} represents.
|
||||
*/
|
||||
private final Class<?> clazz;
|
||||
|
||||
/*private*/ StaticClass(final Class<?> clazz) {
|
||||
@@ -164,6 +168,11 @@ public final class StaticClass implements Serializable {
|
||||
return "StaticClass[" + clazz.getName() + "]";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@link #forClass(Class)} for the underlying {@code clazz} field
|
||||
* ensuring that deserialization doesn't create non-canonical instances.
|
||||
* @return {@link #forClass(Class)} for the underlying {@code clazz} field.
|
||||
*/
|
||||
private Object readResolve() {
|
||||
return forClass(clazz);
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import jdk.internal.dynalink.CallSiteDescriptor;
|
||||
import jdk.internal.dynalink.NamedOperation;
|
||||
import jdk.internal.dynalink.StandardOperation;
|
||||
@@ -171,15 +171,15 @@ class StaticClassLinker implements TypeBasedGuardingDynamicLinker {
|
||||
return linkers.get(clazz).getConstructorMethod(signature);
|
||||
}
|
||||
|
||||
static Collection<String> getReadableStaticPropertyNames(final Class<?> clazz) {
|
||||
static Set<String> getReadableStaticPropertyNames(final Class<?> clazz) {
|
||||
return linkers.get(clazz).getReadablePropertyNames();
|
||||
}
|
||||
|
||||
static Collection<String> getWritableStaticPropertyNames(final Class<?> clazz) {
|
||||
static Set<String> getWritableStaticPropertyNames(final Class<?> clazz) {
|
||||
return linkers.get(clazz).getWritablePropertyNames();
|
||||
}
|
||||
|
||||
static Collection<String> getStaticMethodNames(final Class<?> clazz) {
|
||||
static Set<String> getStaticMethodNames(final Class<?> clazz) {
|
||||
return linkers.get(clazz).getMethodNames();
|
||||
}
|
||||
|
||||
|
||||
@@ -83,7 +83,6 @@
|
||||
|
||||
package jdk.internal.dynalink.linker.support;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@@ -97,9 +96,7 @@ import jdk.internal.dynalink.linker.LinkerServices;
|
||||
* other guarding dynamic linkers in its
|
||||
* {@link #getGuardedInvocation(LinkRequest, LinkerServices)}.
|
||||
*/
|
||||
public class CompositeGuardingDynamicLinker implements GuardingDynamicLinker, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
public class CompositeGuardingDynamicLinker implements GuardingDynamicLinker {
|
||||
|
||||
private final GuardingDynamicLinker[] linkers;
|
||||
|
||||
|
||||
@@ -83,7 +83,6 @@
|
||||
|
||||
package jdk.internal.dynalink.linker.support;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -102,9 +101,7 @@ import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker;
|
||||
* type is encountered, the linking is delegated to those linkers only, speeding
|
||||
* up dispatch.
|
||||
*/
|
||||
public class CompositeTypeBasedGuardingDynamicLinker implements TypeBasedGuardingDynamicLinker, Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public class CompositeTypeBasedGuardingDynamicLinker implements TypeBasedGuardingDynamicLinker {
|
||||
// Using a separate static class instance so there's no strong reference from the class value back to the composite
|
||||
// linker.
|
||||
private static class ClassToLinker extends ClassValue<List<TypeBasedGuardingDynamicLinker>> {
|
||||
|
||||
@@ -94,7 +94,7 @@ import jdk.internal.dynalink.linker.MethodTypeConversionStrategy;
|
||||
/**
|
||||
* Various static utility methods for working with Java types.
|
||||
*/
|
||||
public class TypeUtilities {
|
||||
public final class TypeUtilities {
|
||||
static final Class<Object> OBJECT_CLASS = Object.class;
|
||||
|
||||
private TypeUtilities() {
|
||||
|
||||
Reference in New Issue
Block a user