Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8274299: Make Method/Constructor/Field accessors @stable
Reviewed-by: redestad, mchung
  • Loading branch information
Peter Levart committed Oct 5, 2021
1 parent 1459180 commit 7ad74d8
Show file tree
Hide file tree
Showing 13 changed files with 747 additions and 84 deletions.
13 changes: 9 additions & 4 deletions src/java.base/share/classes/java/lang/reflect/Constructor.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.)
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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 {
Expand All @@ -556,6 +560,7 @@ ConstructorAccessor getConstructorAccessor() {
void setConstructorAccessor(ConstructorAccessor accessor) {
constructorAccessor = accessor;
// Propagate up
Constructor<?> root = this.root;
if (root != null) {
root.setConstructorAccessor(accessor);
}
Expand Down

1 comment on commit 7ad74d8

@openjdk-notifier
Copy link

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.