Skip to content
Permalink
Browse files
8274299: Make Method/Constructor/Field accessors @stable
Reviewed-by: redestad, mchung
  • Loading branch information
Peter Levart committed Oct 5, 2021
1 parent 1459180 commit 7ad74d82d7117113dd73966a0dd96168adfd6463
Showing 13 changed files with 747 additions and 84 deletions.
@@ -30,6 +30,7 @@
import jdk.internal.reflect.ConstructorAccessor;
import jdk.internal.reflect.Reflection;
import jdk.internal.vm.annotation.ForceInline;
import jdk.internal.vm.annotation.Stable;
import sun.reflect.annotation.TypeAnnotation;
import sun.reflect.annotation.TypeAnnotationParser;
import sun.reflect.generics.repository.ConstructorRepository;
@@ -62,10 +63,12 @@
* @since 1.1
*/
public final class Constructor<T> extends Executable {
@Stable
private Class<T> clazz;
private int slot;
private Class<?>[] parameterTypes;
private Class<?>[] exceptionTypes;
@Stable
private int modifiers;
// Generics and annotations support
private transient String signature;
@@ -94,7 +97,8 @@ ConstructorRepository getGenericInfo() {
return genericInfo; //return cached repository
}

private volatile ConstructorAccessor constructorAccessor;
@Stable
private ConstructorAccessor constructorAccessor;
// For sharing of ConstructorAccessors. This branching structure
// is currently only two levels deep (i.e., one root Constructor
// and potentially many Constructor objects pointing to it.)
@@ -491,7 +495,7 @@ T newInstanceWithCaller(Object[] args, boolean checkAccess, Class<?> caller)
if ((clazz.getModifiers() & Modifier.ENUM) != 0)
throw new IllegalArgumentException("Cannot reflectively create enum objects");

ConstructorAccessor ca = constructorAccessor; // read volatile
ConstructorAccessor ca = constructorAccessor; // read @Stable
if (ca == null) {
ca = acquireConstructorAccessor();
}
@@ -532,8 +536,8 @@ public boolean isSynthetic() {
private ConstructorAccessor acquireConstructorAccessor() {
// First check to see if one has been created yet, and take it
// if so.
ConstructorAccessor tmp = null;
if (root != null) tmp = root.getConstructorAccessor();
Constructor<?> root = this.root;
ConstructorAccessor tmp = root == null ? null : root.getConstructorAccessor();
if (tmp != null) {
constructorAccessor = tmp;
} else {
@@ -556,6 +560,7 @@ ConstructorAccessor getConstructorAccessor() {
void setConstructorAccessor(ConstructorAccessor accessor) {
constructorAccessor = accessor;
// Propagate up
Constructor<?> root = this.root;
if (root != null) {
root.setConstructorAccessor(accessor);
}

1 comment on commit 7ad74d8

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 7ad74d8 Oct 5, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.