8888public final class DynamicHub implements JavaKind .FormatWithToString , AnnotatedElement , java .lang .reflect .Type , GenericDeclaration , Serializable ,
8989 Target_java_lang_invoke_TypeDescriptor_OfField , Target_java_lang_constant_Constable {
9090
91- /** Marker value for {@link #classLoader}. */
92- static final Object NO_CLASS_LOADER = new Object ();
93-
9491 @ Substitute //
9592 private static final Class <?>[] EMPTY_CLASS_ARRAY = new Class <?>[0 ];
9693
@@ -272,11 +269,6 @@ public final class DynamicHub implements JavaKind.FormatWithToString, AnnotatedE
272269 */
273270 private ClassInitializationInfo classInitializationInfo ;
274271
275- /**
276- * Classloader used for loading this class during image-build time.
277- */
278- private final Object classLoader ;
279-
280272 /**
281273 * Array containing this type's type check id information. During a type check, a requested
282274 * column of this array is read to determine if this value fits within the range of ids which
@@ -305,7 +297,7 @@ public void setModule(Module module) {
305297 this .module = module ;
306298 }
307299
308- private final LazyFinalReference < DynamicHubCompanion > companion = new LazyFinalReference <>(() -> new DynamicHubCompanion ( this )) ;
300+ private final DynamicHubCompanion companion ;
309301
310302 @ Platforms (Platform .HOSTED_ONLY .class )
311303 public DynamicHub (Class <?> hostedJavaClass , String name , HubType hubType , ReferenceType referenceType , Object isLocalClass , Object isAnonymousClass , DynamicHub superType , DynamicHub componentHub ,
@@ -321,7 +313,6 @@ public DynamicHub(Class<?> hostedJavaClass, String name, HubType hubType, Refere
321313 this .componentType = componentHub ;
322314 this .sourceFileName = sourceFileName ;
323315 this .modifiers = modifiers ;
324- this .classLoader = PredefinedClassesSupport .isPredefined (hostedJavaClass ) ? NO_CLASS_LOADER : classLoader ;
325316 this .nestHost = nestHost ;
326317
327318 this .flags = NumUtil .safeToUByte (makeFlag (IS_PRIMITIVE_FLAG_BIT , hostedJavaClass .isPrimitive ()) |
@@ -332,6 +323,8 @@ public DynamicHub(Class<?> hostedJavaClass, String name, HubType hubType, Refere
332323 makeFlag (HAS_DEFAULT_METHODS_FLAG_BIT , hasDefaultMethods ) |
333324 makeFlag (DECLARES_DEFAULT_METHODS_FLAG_BIT , declaresDefaultMethods ) |
334325 makeFlag (IS_SEALED_FLAG_BIT , isSealed ));
326+
327+ this .companion = new DynamicHubCompanion (hostedJavaClass , classLoader );
335328 }
336329
337330 @ Platforms (Platform .HOSTED_ONLY .class )
@@ -560,6 +553,10 @@ public static DynamicHub fromClass(Class<?> clazz) {
560553 return SubstrateUtil .cast (clazz , DynamicHub .class );
561554 }
562555
556+ public DynamicHubCompanion getCompanion () {
557+ return companion ;
558+ }
559+
563560 /*
564561 * Note that this method must be a static method and not an instance method, otherwise null
565562 * values cannot be converted.
@@ -696,18 +693,15 @@ public InputStream getResourceAsStream(String resourceName) {
696693
697694 @ Substitute
698695 private ClassLoader getClassLoader0 () {
699- if (classLoader == NO_CLASS_LOADER ) {
700- return companion .get ().getClassLoader ();
701- }
702- return (ClassLoader ) classLoader ;
696+ return companion .getClassLoader ();
703697 }
704698
705699 public boolean isLoaded () {
706- return classLoader != NO_CLASS_LOADER || ( companion .isPresent () && companion . get (). hasClassLoader () );
700+ return companion .hasClassLoader ();
707701 }
708702
709703 void setClassLoaderAtRuntime (ClassLoader loader ) {
710- companion .get (). setClassLoader (loader );
704+ companion .setClassLoader (loader );
711705 }
712706
713707 @ Substitute
@@ -1066,7 +1060,7 @@ private Method getMethod(@SuppressWarnings("hiding") String name, Class<?>... pa
10661060 * The original code of getMethods() does a recursive search to avoid creating objects for
10671061 * all public methods. We prepare them during the image build and can just iterate here.
10681062 */
1069- Method method = searchMethods (companion .get (). getCompleteReflectionData ().publicMethods , name , parameterTypes );
1063+ Method method = searchMethods (companion .getCompleteReflectionData (this ).publicMethods , name , parameterTypes );
10701064 if (method == null ) {
10711065 throw new NoSuchMethodException (describeMethod (getName () + "." + name + "(" , parameterTypes , ")" ));
10721066 }
@@ -1112,7 +1106,8 @@ private Class<?>[] getClasses() {
11121106
11131107 @ Substitute
11141108 private Constructor <?>[] privateGetDeclaredConstructors (boolean publicOnly ) {
1115- return publicOnly ? companion .get ().getCompleteReflectionData ().publicConstructors : companion .get ().getCompleteReflectionData ().declaredConstructors ;
1109+ ReflectionData reflectionData = companion .getCompleteReflectionData (this );
1110+ return publicOnly ? reflectionData .publicConstructors : reflectionData .declaredConstructors ;
11161111 }
11171112
11181113 @ Substitute
@@ -1122,7 +1117,8 @@ private Field[] privateGetDeclaredFields(boolean publicOnly) {
11221117
11231118 @ Substitute
11241119 private Method [] privateGetDeclaredMethods (boolean publicOnly ) {
1125- return publicOnly ? companion .get ().getCompleteReflectionData ().declaredPublicMethods : companion .get ().getCompleteReflectionData ().declaredMethods ;
1120+ ReflectionData reflectionData = companion .getCompleteReflectionData (this );
1121+ return publicOnly ? reflectionData .declaredPublicMethods : reflectionData .declaredMethods ;
11261122 }
11271123
11281124 @ Substitute
@@ -1132,7 +1128,7 @@ private Field[] privateGetPublicFields() {
11321128
11331129 @ Substitute
11341130 Method [] privateGetPublicMethods () {
1135- return companion .get (). getCompleteReflectionData ().publicMethods ;
1131+ return companion .getCompleteReflectionData (this ).publicMethods ;
11361132 }
11371133
11381134 @ KeepOriginal
@@ -1292,7 +1288,7 @@ public String getPackageName() {
12921288 if (SubstrateUtil .HOSTED ) { // avoid eager initialization in image heap
12931289 return computePackageName ();
12941290 }
1295- return companion .get (). getPackageName ();
1291+ return companion .getPackageName (this );
12961292 }
12971293
12981294 String computePackageName () {
@@ -1330,7 +1326,7 @@ public Object[] getSigners() {
13301326
13311327 @ Substitute
13321328 public ProtectionDomain getProtectionDomain () {
1333- return companion .get (). getProtectionDomain ();
1329+ return companion .getProtectionDomain ();
13341330 }
13351331
13361332 @ TargetElement (onlyWith = JDK17OrLater .class )
@@ -1340,7 +1336,7 @@ private ProtectionDomain protectionDomain() {
13401336 }
13411337
13421338 void setProtectionDomainAtRuntime (ProtectionDomain protectionDomain ) {
1343- companion .get (). setProtectionDomain (protectionDomain );
1339+ companion .setProtectionDomain (protectionDomain );
13441340 }
13451341
13461342 @ Substitute
0 commit comments