Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: openjdk/jdk
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 8aeada10
Choose a base ref
...
head repository: openjdk/jdk
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4110c13f
Choose a head ref
  • 15 commits
  • 65 files changed
  • 1 contributor

Commits on May 13, 2024

  1. Verified

    This commit was signed with the committer’s verified signature.
    IvanGoncharov Ivan Goncharov
    Copy the full SHA
    c7b9dad View commit details
  2. Final migrations, nuke old code

    liach committed May 13, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    IvanGoncharov Ivan Goncharov
    Copy the full SHA
    f5d7e3f View commit details
  3. Merge branch 'master' of https://github.com/openjdk/jdk into feature/…

    …new-generic-info
    liach committed May 13, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6f21fc9 View commit details
  4. Sealed hierarchy, fix tests

    liach committed May 13, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6a13c36 View commit details
  5. JImageReadTest

    liach committed May 13, 2024
    Copy the full SHA
    4287920 View commit details

Commits on May 17, 2024

  1. Merge branch 'master' of https://github.com/openjdk/jdk into feature/…

    …new-generic-info
    liach committed May 17, 2024
    Copy the full SHA
    c620943 View commit details

Commits on May 24, 2024

  1. Merge branch 'master' of https://github.com/openjdk/jdk into feature/…

    …new-generic-info
    liach committed May 24, 2024
    Copy the full SHA
    c5e2303 View commit details

Commits on May 30, 2024

  1. Merge branch 'master' of https://github.com/openjdk/jdk into feature/…

    …new-generic-info
    liach committed May 30, 2024
    Copy the full SHA
    9249694 View commit details
  2. Stage new tests

    liach committed May 30, 2024
    Copy the full SHA
    72d5fff View commit details

Commits on May 31, 2024

  1. Stage

    liach committed May 31, 2024
    Copy the full SHA
    049b150 View commit details
  2. Fixxes

    liach committed May 31, 2024
    Copy the full SHA
    acb983d View commit details
  3. Fix everything

    liach committed May 31, 2024
    Copy the full SHA
    253a7dd View commit details
  4. Merge branch 'master' of https://github.com/openjdk/jdk into feature/…

    …new-generic-info
    liach committed May 31, 2024
    Copy the full SHA
    4d65a14 View commit details
  5. Merge branch 'test/signature-error' into feature/new-generic-info

    liach committed May 31, 2024
    Copy the full SHA
    e9e8c44 View commit details
  6. Remove redundant try-catch in getEnclosingMethod/Constructor

    liach committed May 31, 2024
    Copy the full SHA
    4110c13 View commit details
Showing with 1,090 additions and 3,546 deletions.
  1. +21 −43 src/java.base/share/classes/java/lang/Class.java
  2. +7 −17 src/java.base/share/classes/java/lang/reflect/Constructor.java
  3. +4 −4 src/java.base/share/classes/java/lang/reflect/Executable.java
  4. +5 −16 src/java.base/share/classes/java/lang/reflect/Field.java
  5. +8 −18 src/java.base/share/classes/java/lang/reflect/Method.java
  6. +6 −16 src/java.base/share/classes/java/lang/reflect/RecordComponent.java
  7. +17 −0 src/java.base/share/classes/sun/invoke/util/BytecodeDescriptor.java
  8. +6 −19 src/java.base/share/classes/sun/reflect/annotation/AnnotationParser.java
  9. +0 −137 src/java.base/share/classes/sun/reflect/generics/factory/CoreReflectionFactory.java
  10. +0 −190 src/java.base/share/classes/sun/reflect/generics/factory/GenericsFactory.java
  11. +84 −0 src/java.base/share/classes/sun/reflect/generics/info/ClassGenericInfo.java
  12. +87 −0 src/java.base/share/classes/sun/reflect/generics/info/ExecutableGenericInfo.java
  13. +23 −12 ...se/share/classes/sun/reflect/generics/{tree/ArrayTypeSignature.java → info/FieldGenericInfo.java}
  14. +106 −0 src/java.base/share/classes/sun/reflect/generics/info/GenericDeclInfo.java
  15. +181 −0 src/java.base/share/classes/sun/reflect/generics/info/GenericInfo.java
  16. +0 −634 src/java.base/share/classes/sun/reflect/generics/parser/SignatureParser.java
  17. +7 −18 ...java.base/share/classes/sun/reflect/generics/reflectiveObjects/LazyReflectiveObjectGenerator.java
  18. +13 −11 src/java.base/share/classes/sun/reflect/generics/reflectiveObjects/TypeVariableImpl.java
  19. +20 −19 src/java.base/share/classes/sun/reflect/generics/reflectiveObjects/WildcardTypeImpl.java
  20. +0 −85 src/java.base/share/classes/sun/reflect/generics/repository/AbstractRepository.java
  21. +0 −123 src/java.base/share/classes/sun/reflect/generics/repository/ClassRepository.java
  22. +0 −133 src/java.base/share/classes/sun/reflect/generics/repository/ConstructorRepository.java
  23. +0 −93 src/java.base/share/classes/sun/reflect/generics/repository/FieldRepository.java
  24. +0 −95 src/java.base/share/classes/sun/reflect/generics/repository/GenericDeclRepository.java
  25. +0 −80 src/java.base/share/classes/sun/reflect/generics/repository/MethodRepository.java
  26. +0 −97 src/java.base/share/classes/sun/reflect/generics/scope/AbstractScope.java
  27. +0 −83 src/java.base/share/classes/sun/reflect/generics/scope/ClassScope.java
  28. +0 −67 src/java.base/share/classes/sun/reflect/generics/scope/ConstructorScope.java
  29. +0 −61 src/java.base/share/classes/sun/reflect/generics/scope/DummyScope.java
  30. +0 −67 src/java.base/share/classes/sun/reflect/generics/scope/MethodScope.java
  31. +0 −33 src/java.base/share/classes/sun/reflect/generics/scope/Scope.java
  32. +0 −34 src/java.base/share/classes/sun/reflect/generics/tree/BaseType.java
  33. +0 −41 src/java.base/share/classes/sun/reflect/generics/tree/BooleanSignature.java
  34. +0 −38 src/java.base/share/classes/sun/reflect/generics/tree/BottomSignature.java
  35. +0 −41 src/java.base/share/classes/sun/reflect/generics/tree/ByteSignature.java
  36. +0 −41 src/java.base/share/classes/sun/reflect/generics/tree/CharSignature.java
  37. +0 −56 src/java.base/share/classes/sun/reflect/generics/tree/ClassSignature.java
  38. +0 −50 src/java.base/share/classes/sun/reflect/generics/tree/ClassTypeSignature.java
  39. +0 −39 src/java.base/share/classes/sun/reflect/generics/tree/DoubleSignature.java
  40. +0 −35 src/java.base/share/classes/sun/reflect/generics/tree/FieldTypeSignature.java
  41. +0 −39 src/java.base/share/classes/sun/reflect/generics/tree/FloatSignature.java
  42. +0 −55 src/java.base/share/classes/sun/reflect/generics/tree/FormalTypeParameter.java
  43. +0 −39 src/java.base/share/classes/sun/reflect/generics/tree/IntSignature.java
  44. +0 −39 src/java.base/share/classes/sun/reflect/generics/tree/LongSignature.java
  45. +0 −61 src/java.base/share/classes/sun/reflect/generics/tree/MethodTypeSignature.java
  46. +0 −28 src/java.base/share/classes/sun/reflect/generics/tree/ReturnType.java
  47. +0 −41 src/java.base/share/classes/sun/reflect/generics/tree/ShortSignature.java
  48. +0 −34 src/java.base/share/classes/sun/reflect/generics/tree/Signature.java
  49. +0 −60 src/java.base/share/classes/sun/reflect/generics/tree/SimpleClassTypeSignature.java
  50. +0 −29 src/java.base/share/classes/sun/reflect/generics/tree/Tree.java
  51. +0 −32 src/java.base/share/classes/sun/reflect/generics/tree/TypeArgument.java
  52. +0 −34 src/java.base/share/classes/sun/reflect/generics/tree/TypeSignature.java
  53. +0 −40 src/java.base/share/classes/sun/reflect/generics/tree/TypeTree.java
  54. +0 −45 src/java.base/share/classes/sun/reflect/generics/tree/TypeVariableSignature.java
  55. +0 −42 src/java.base/share/classes/sun/reflect/generics/tree/VoidDescriptor.java
  56. +0 −59 src/java.base/share/classes/sun/reflect/generics/tree/Wildcard.java
  57. +0 −218 src/java.base/share/classes/sun/reflect/generics/visitor/Reifier.java
  58. +0 −64 src/java.base/share/classes/sun/reflect/generics/visitor/TypeTreeVisitor.java
  59. +0 −34 src/java.base/share/classes/sun/reflect/generics/visitor/Visitor.java
  60. +100 −0 test/jdk/java/lang/Class/getEnclosingMethod/BadEnclosingMethodTest.java
  61. +71 −0 test/jdk/java/lang/annotation/MalformedAnnotationTest.java
  62. +169 −0 test/jdk/java/lang/reflect/Generics/MalformedSignatureTest.java
  63. +23 −5 test/jdk/java/lang/reflect/Generics/TestBadSignatures.java
  64. +130 −0 test/jdk/java/lang/reflect/Generics/TypeNotPresentInSignatureTest.java
  65. +2 −2 test/jdk/jdk/internal/jimage/JImageReadTest.java
64 changes: 21 additions & 43 deletions src/java.base/share/classes/java/lang/Class.java
Original file line number Diff line number Diff line change
@@ -85,13 +85,10 @@
import jdk.internal.vm.annotation.IntrinsicCandidate;
import jdk.internal.vm.annotation.Stable;

import sun.invoke.util.BytecodeDescriptor;
import sun.invoke.util.Wrapper;
import sun.reflect.generics.factory.CoreReflectionFactory;
import sun.reflect.generics.factory.GenericsFactory;
import sun.reflect.generics.repository.ClassRepository;
import sun.reflect.generics.repository.MethodRepository;
import sun.reflect.generics.repository.ConstructorRepository;
import sun.reflect.generics.scope.ClassScope;
import sun.reflect.generics.info.ClassGenericInfo;
import sun.reflect.generics.info.GenericInfo;
import sun.security.util.SecurityConstants;
import sun.reflect.annotation.*;
import sun.reflect.misc.ReflectUtil;
@@ -1134,9 +1131,9 @@ Object getClassData() {
*/
@SuppressWarnings("unchecked")
public TypeVariable<Class<T>>[] getTypeParameters() {
ClassRepository info = getGenericInfo();
var info = getGenericInfo();
if (info != null)
return (TypeVariable<Class<T>>[])info.getTypeParameters();
return info.getTypeVariables();
else
return (TypeVariable<Class<T>>[])new TypeVariable<?>[0];
}
@@ -1188,7 +1185,7 @@ public TypeVariable<Class<T>>[] getTypeParameters() {
* @since 1.5
*/
public Type getGenericSuperclass() {
ClassRepository info = getGenericInfo();
var info = getGenericInfo();
if (info == null) {
return getSuperclass();
}
@@ -1381,7 +1378,7 @@ private Class<?>[] getInterfaces(boolean cloneArray) {
* @since 1.5
*/
public Type[] getGenericInterfaces() {
ClassRepository info = getGenericInfo();
var info = getGenericInfo();
return (info == null) ? getInterfaces() : info.getSuperInterfaces();
}

@@ -1564,17 +1561,10 @@ public Method getEnclosingMethod() throws SecurityException {
if (!enclosingInfo.isMethod())
return null;

MethodRepository typeInfo = MethodRepository.make(enclosingInfo.getDescriptor(),
getFactory());
Class<?> returnType = toClass(typeInfo.getReturnType());
Type [] parameterTypes = typeInfo.getParameterTypes();
Class<?>[] parameterClasses = new Class<?>[parameterTypes.length];

// Convert Types to Classes; returned types *should*
// be class objects since the methodDescriptor's used
// don't have generics information
for(int i = 0; i < parameterClasses.length; i++)
parameterClasses[i] = toClass(parameterTypes[i]);
// Descriptor already validated by VM
List<Class<?>> types = BytecodeDescriptor.parseMethod(enclosingInfo.getDescriptor(), getClassLoader());
Class<?> returnType = types.removeLast();
Class<?>[] parameterClasses = types.toArray(GenericInfo.EMPTY_CLASS_ARRAY);

// Perform access check
final Class<?> enclosingCandidate = enclosingInfo.getEnclosingClass();
@@ -1720,16 +1710,10 @@ public Constructor<?> getEnclosingConstructor() throws SecurityException {
if (!enclosingInfo.isConstructor())
return null;

ConstructorRepository typeInfo = ConstructorRepository.make(enclosingInfo.getDescriptor(),
getFactory());
Type [] parameterTypes = typeInfo.getParameterTypes();
Class<?>[] parameterClasses = new Class<?>[parameterTypes.length];

// Convert Types to Classes; returned types *should*
// be class objects since the methodDescriptor's used
// don't have generics information
for(int i = 0; i < parameterClasses.length; i++)
parameterClasses[i] = toClass(parameterTypes[i]);
// Descriptor already validated by VM
List<Class<?>> types = BytecodeDescriptor.parseMethod(enclosingInfo.getDescriptor(), getClassLoader());
types.removeLast();
Class<?>[] parameterClasses = types.toArray(GenericInfo.EMPTY_CLASS_ARRAY);

// Perform access check
final Class<?> enclosingCandidate = enclosingInfo.getEnclosingClass();
@@ -3491,28 +3475,22 @@ private ReflectionData<T> newReflectionData(SoftReference<ReflectionData<T>> old
private native String getGenericSignature0();

// Generic info repository; lazily initialized
private transient volatile ClassRepository genericInfo;

// accessor for factory
private GenericsFactory getFactory() {
// create scope and factory
return CoreReflectionFactory.make(this, ClassScope.make(this));
}
private transient volatile @Stable ClassGenericInfo<T> genericInfo;

// accessor for generic info repository;
// generic info is lazily initialized
private ClassRepository getGenericInfo() {
ClassRepository genericInfo = this.genericInfo;
private ClassGenericInfo<T> getGenericInfo() {
var genericInfo = this.genericInfo;
if (genericInfo == null) {
String signature = getGenericSignature0();
if (signature == null) {
genericInfo = ClassRepository.NONE;
genericInfo = ClassGenericInfo.dummy();
} else {
genericInfo = ClassRepository.make(signature, getFactory());
genericInfo = new ClassGenericInfo<>(this, signature);
}
this.genericInfo = genericInfo;
}
return (genericInfo != ClassRepository.NONE) ? genericInfo : null;
return (genericInfo != ClassGenericInfo.dummy()) ? genericInfo : null;
}

// Annotations handling
24 changes: 7 additions & 17 deletions src/java.base/share/classes/java/lang/reflect/Constructor.java
Original file line number Diff line number Diff line change
@@ -34,11 +34,8 @@
import jdk.internal.vm.annotation.Stable;
import sun.reflect.annotation.TypeAnnotation;
import sun.reflect.annotation.TypeAnnotationParser;
import sun.reflect.generics.repository.ConstructorRepository;
import sun.reflect.generics.repository.GenericDeclRepository;
import sun.reflect.generics.factory.CoreReflectionFactory;
import sun.reflect.generics.factory.GenericsFactory;
import sun.reflect.generics.scope.ConstructorScope;
import sun.reflect.generics.info.ExecutableGenericInfo;
import sun.reflect.generics.info.GenericInfo;
import java.lang.annotation.Annotation;
import java.lang.annotation.AnnotationFormatError;
import java.util.StringJoiner;
@@ -73,27 +70,20 @@ public final class Constructor<T> extends Executable {
// Generics and annotations support
private final transient String signature;
// generic info repository; lazily initialized
private transient volatile ConstructorRepository genericInfo;
private transient volatile ExecutableGenericInfo<Constructor<T>> genericInfo;
private final byte[] annotations;
private final byte[] parameterAnnotations;

// Generics infrastructure
// Accessor for factory
private GenericsFactory getFactory() {
// create scope and factory
return CoreReflectionFactory.make(this, ConstructorScope.make(this));
}

// Accessor for generic info repository
@Override
ConstructorRepository getGenericInfo() {
ExecutableGenericInfo<Constructor<T>> getGenericInfo() {
var genericInfo = this.genericInfo;
// lazily initialize repository if necessary
if (genericInfo == null) {
// create and cache generic info repository
genericInfo =
ConstructorRepository.make(getSignature(),
getFactory());
genericInfo = new ExecutableGenericInfo<>(this, getSignature());
this.genericInfo = genericInfo;
}
return genericInfo; //return cached repository
@@ -245,9 +235,9 @@ public int getModifiers() {
@SuppressWarnings({"rawtypes", "unchecked"})
public TypeVariable<Constructor<T>>[] getTypeParameters() {
if (getSignature() != null) {
return (TypeVariable<Constructor<T>>[])getGenericInfo().getTypeParameters();
return getGenericInfo().getTypeVariables();
} else
return (TypeVariable<Constructor<T>>[])GenericDeclRepository.EMPTY_TYPE_VARS;
return (TypeVariable<Constructor<T>>[]) GenericInfo.EMPTY_TYPE_VARS;
}


8 changes: 4 additions & 4 deletions src/java.base/share/classes/java/lang/reflect/Executable.java
Original file line number Diff line number Diff line change
@@ -39,8 +39,8 @@
import sun.reflect.annotation.AnnotationSupport;
import sun.reflect.annotation.TypeAnnotationParser;
import sun.reflect.annotation.TypeAnnotation;
import sun.reflect.generics.info.ExecutableGenericInfo;
import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;
import sun.reflect.generics.repository.ConstructorRepository;

/**
* A shared superclass for the common functionality of {@link Method}
@@ -67,7 +67,7 @@ public abstract sealed class Executable extends AccessibleObject
*/
abstract boolean hasGenericInformation();

abstract ConstructorRepository getGenericInfo();
abstract ExecutableGenericInfo<?> getGenericInfo();

boolean equalParamTypes(Class<?>[] params1, Class<?>[] params2) {
/* Avoid unnecessary cloning */
@@ -331,7 +331,7 @@ public Set<AccessFlag> accessFlags() {
@SuppressWarnings("doclint:reference") // cross-module links
public Type[] getGenericParameterTypes() {
if (hasGenericInformation())
return getGenericInfo().getParameterTypes();
return getGenericInfo().getParameters();
else
return getParameterTypes();
}
@@ -533,7 +533,7 @@ byte[] getTypeAnnotationBytes() {
public Type[] getGenericExceptionTypes() {
Type[] result;
if (hasGenericInformation() &&
((result = getGenericInfo().getExceptionTypes()).length > 0))
((result = getGenericInfo().getExceptions()).length > 0))
return result;
else
return getExceptionTypes();
21 changes: 5 additions & 16 deletions src/java.base/share/classes/java/lang/reflect/Field.java
Original file line number Diff line number Diff line change
@@ -31,10 +31,7 @@
import jdk.internal.reflect.Reflection;
import jdk.internal.vm.annotation.ForceInline;
import jdk.internal.vm.annotation.Stable;
import sun.reflect.generics.repository.FieldRepository;
import sun.reflect.generics.factory.CoreReflectionFactory;
import sun.reflect.generics.factory.GenericsFactory;
import sun.reflect.generics.scope.ClassScope;
import sun.reflect.generics.info.FieldGenericInfo;
import java.lang.annotation.Annotation;
import java.util.Map;
import java.util.Set;
@@ -77,7 +74,7 @@ class Field extends AccessibleObject implements Member {
// Generics and annotations support
private final transient String signature;
// generic info repository; lazily initialized
private transient volatile FieldRepository genericInfo;
private transient volatile FieldGenericInfo genericInfo;
private final byte[] annotations;
// Cached field accessor created without override
@Stable
@@ -97,21 +94,13 @@ class Field extends AccessibleObject implements Member {

private String getGenericSignature() {return signature;}

// Accessor for factory
private GenericsFactory getFactory() {
Class<?> c = getDeclaringClass();
// create scope and factory
return CoreReflectionFactory.make(c, ClassScope.make(c));
}

// Accessor for generic info repository
private FieldRepository getGenericInfo() {
private FieldGenericInfo getGenericInfo() {
var genericInfo = this.genericInfo;
// lazily initialize repository if necessary
if (genericInfo == null) {
// create and cache generic info repository
genericInfo = FieldRepository.make(getGenericSignature(),
getFactory());
genericInfo = new FieldGenericInfo(getDeclaringClass(), getGenericSignature());
this.genericInfo = genericInfo;
}
return genericInfo; //return cached repository
@@ -291,7 +280,7 @@ public Class<?> getType() {
*/
public Type getGenericType() {
if (getGenericSignature() != null)
return getGenericInfo().getGenericType();
return getGenericInfo().getType();
else
return getType();
}
26 changes: 8 additions & 18 deletions src/java.base/share/classes/java/lang/reflect/Method.java
Original file line number Diff line number Diff line change
@@ -36,11 +36,8 @@
import jdk.internal.vm.annotation.Stable;
import sun.reflect.annotation.ExceptionProxy;
import sun.reflect.annotation.TypeNotPresentExceptionProxy;
import sun.reflect.generics.repository.GenericDeclRepository;
import sun.reflect.generics.repository.MethodRepository;
import sun.reflect.generics.factory.CoreReflectionFactory;
import sun.reflect.generics.factory.GenericsFactory;
import sun.reflect.generics.scope.MethodScope;
import sun.reflect.generics.info.ExecutableGenericInfo;
import sun.reflect.generics.info.GenericInfo;
import sun.reflect.annotation.AnnotationType;
import sun.reflect.annotation.AnnotationParser;
import java.lang.annotation.Annotation;
@@ -82,7 +79,7 @@ public final class Method extends Executable {
// Generics and annotations support
private final transient String signature;
// generic info repository; lazily initialized
private transient volatile MethodRepository genericInfo;
private transient volatile ExecutableGenericInfo<Method> genericInfo;
private final byte[] annotations;
private final byte[] parameterAnnotations;
private final byte[] annotationDefault;
@@ -99,21 +96,14 @@ public final class Method extends Executable {
// Generics infrastructure
private String getGenericSignature() {return signature;}

// Accessor for factory
private GenericsFactory getFactory() {
// create scope and factory
return CoreReflectionFactory.make(this, MethodScope.make(this));
}

// Accessor for generic info repository
@Override
MethodRepository getGenericInfo() {
ExecutableGenericInfo<Method> getGenericInfo() {
var genericInfo = this.genericInfo;
// lazily initialize repository if necessary
if (genericInfo == null) {
// create and cache generic info repository
genericInfo = MethodRepository.make(getGenericSignature(),
getFactory());
genericInfo = new ExecutableGenericInfo<>(this, getGenericSignature());
this.genericInfo = genericInfo;
}
return genericInfo; //return cached repository
@@ -255,9 +245,9 @@ public int getModifiers() {
@SuppressWarnings({"rawtypes", "unchecked"})
public TypeVariable<Method>[] getTypeParameters() {
if (getGenericSignature() != null)
return (TypeVariable<Method>[])getGenericInfo().getTypeParameters();
return getGenericInfo().getTypeVariables();
else
return (TypeVariable<Method>[])GenericDeclRepository.EMPTY_TYPE_VARS;
return (TypeVariable<Method>[]) GenericInfo.EMPTY_TYPE_VARS;
}

/**
@@ -296,7 +286,7 @@ public Class<?> getReturnType() {
*/
public Type getGenericReturnType() {
if (getGenericSignature() != null) {
return getGenericInfo().getReturnType();
return getGenericInfo().getResult();
} else { return getReturnType();}
}

Loading