4545import com .oracle .svm .core .annotate .Alias ;
4646import com .oracle .svm .core .annotate .AnnotateOriginal ;
4747import com .oracle .svm .core .annotate .Delete ;
48- import com .oracle .svm .core .annotate .RecomputeFieldValue ;
49- import com .oracle .svm .core .annotate .RecomputeFieldValue .Kind ;
5048import com .oracle .svm .core .annotate .Substitute ;
5149import com .oracle .svm .core .annotate .TargetClass ;
5250import com .oracle .svm .core .annotate .TargetElement ;
5351import com .oracle .svm .core .hub .DynamicHub ;
5452import com .oracle .svm .core .hub .RuntimeClassLoading ;
53+ import com .oracle .svm .core .hub .crema .CremaSupport ;
5554import com .oracle .svm .core .imagelayer .ImageLayerBuildingSupport ;
5655import com .oracle .svm .core .invoke .Target_java_lang_invoke_MemberName ;
5756import com .oracle .svm .core .layeredimagesingleton .MultiLayeredImageSingleton ;
6160import com .oracle .svm .util .ReflectionUtil ;
6261
6362import jdk .graal .compiler .debug .GraalError ;
63+ import jdk .vm .ci .meta .ResolvedJavaField ;
6464import sun .invoke .util .VerifyAccess ;
6565
6666/**
@@ -127,7 +127,7 @@ private static void expand(Target_java_lang_invoke_MemberName self) {
127127
128128 @ Substitute
129129 private static long objectFieldOffset (Target_java_lang_invoke_MemberName self ) {
130- if (self .reflectAccess == null && self .intrinsic == null ) {
130+ if (self .reflectAccess == null && self .intrinsic == null && self . resolved == null ) {
131131 throw new InternalError ("Unresolved field" );
132132 }
133133 if (!self .isField () || self .isStatic ()) {
@@ -138,12 +138,15 @@ private static long objectFieldOffset(Target_java_lang_invoke_MemberName self) {
138138 if (self .intrinsic != null ) {
139139 return -1L ;
140140 }
141+ if (RuntimeClassLoading .isSupported () && self .resolved != null ) {
142+ return ((ResolvedJavaField ) self .resolved ).getOffset ();
143+ }
141144 return UnsafeFieldUtil .getFieldOffset (SubstrateUtil .cast (self .reflectAccess , Target_java_lang_reflect_Field .class ));
142145 }
143146
144147 @ Substitute
145148 private static long staticFieldOffset (Target_java_lang_invoke_MemberName self ) {
146- if (self .reflectAccess == null && self .intrinsic == null ) {
149+ if (self .reflectAccess == null && self .intrinsic == null && self . resolved == null ) {
147150 throw new InternalError ("Unresolved field" );
148151 }
149152 if (!self .isField () || !self .isStatic ()) {
@@ -153,17 +156,23 @@ private static long staticFieldOffset(Target_java_lang_invoke_MemberName self) {
153156 if (self .intrinsic != null ) {
154157 return -1L ;
155158 }
159+ if (RuntimeClassLoading .isSupported () && self .resolved != null ) {
160+ return ((ResolvedJavaField ) self .resolved ).getOffset ();
161+ }
156162 return UnsafeFieldUtil .getFieldOffset (SubstrateUtil .cast (self .reflectAccess , Target_java_lang_reflect_Field .class ));
157163 }
158164
159165 @ Substitute
160166 private static Object staticFieldBase (Target_java_lang_invoke_MemberName self ) {
161- if (self .reflectAccess == null ) {
167+ if (self .reflectAccess == null && self . resolved == null ) {
162168 throw new InternalError ("Unresolved field" );
163169 }
164170 if (!self .isField () || !self .isStatic ()) {
165171 throw new InternalError ("Static field required" );
166172 }
173+ if (RuntimeClassLoading .isSupported () && self .resolved != null ) {
174+ return CremaSupport .singleton ().getStaticStorage ((ResolvedJavaField ) self .resolved );
175+ }
167176 Field field = (Field ) self .reflectAccess ;
168177 int layerNumber ;
169178 if (ImageLayerBuildingSupport .buildingImageLayer ()) {
@@ -209,7 +218,7 @@ public static Target_java_lang_invoke_MemberName resolve(Target_java_lang_invoke
209218 throws LinkageError , ClassNotFoundException {
210219 Class <?> declaringClass = self .getDeclaringClass ();
211220 Target_java_lang_invoke_MemberName resolved = Util_java_lang_invoke_MethodHandleNatives .resolve (self , caller , speculativeResolve );
212- assert resolved == null || resolved .reflectAccess != null || resolved .intrinsic != null ;
221+ assert resolved == null || resolved .reflectAccess != null || resolved .intrinsic != null || resolved . resolved != null ;
213222 if (resolved != null && resolved .reflectAccess != null && caller != null &&
214223 !Util_java_lang_invoke_MethodHandleNatives .verifyAccess (declaringClass , resolved .reflectAccess .getDeclaringClass (), resolved .reflectAccess .getModifiers (), caller ,
215224 lookupMode )) {
@@ -317,14 +326,24 @@ private static void forceAccess(AccessibleObject target) {
317326
318327 @ SuppressWarnings ("unused" )
319328 public static Target_java_lang_invoke_MemberName resolve (Target_java_lang_invoke_MemberName self , Class <?> caller , boolean speculativeResolve )
320- throws LinkageError , ClassNotFoundException {
321- if (self .reflectAccess != null || self .intrinsic != null ) {
322- return self ;
323- }
329+ throws LinkageError {
324330 Class <?> declaringClass = self .getDeclaringClass ();
325331 if (declaringClass == null ) {
326332 return null ;
327333 }
334+ if (RuntimeClassLoading .isSupported ()) {
335+ try {
336+ return CremaSupport .singleton ().resolveMemberName (self , caller );
337+ } catch (Throwable t ) {
338+ if (speculativeResolve ) {
339+ return null ;
340+ }
341+ throw t ;
342+ }
343+ }
344+ if (self .reflectAccess != null || self .intrinsic != null ) {
345+ return self ;
346+ }
328347
329348 /* Intrinsic methods */
330349 self .intrinsic = MethodHandleIntrinsicImpl .resolve (self );
@@ -397,30 +416,3 @@ static boolean verifyAccess(Class<?> refc, Class<?> defc, int mods, Class<?> loo
397416 }
398417 }
399418}
400-
401- @ TargetClass (className = "java.lang.invoke.MethodHandleNatives" , innerClass = "Constants" )
402- final class Target_java_lang_invoke_MethodHandleNatives_Constants {
403- // Checkstyle: stop
404- @ Alias @ RecomputeFieldValue (isFinal = true , kind = Kind .None ) static int MN_IS_METHOD ;
405- @ Alias @ RecomputeFieldValue (isFinal = true , kind = Kind .None ) static int MN_IS_CONSTRUCTOR ;
406- @ Alias @ RecomputeFieldValue (isFinal = true , kind = Kind .None ) static int MN_IS_FIELD ;
407- @ Alias @ RecomputeFieldValue (isFinal = true , kind = Kind .None ) static int MN_IS_TYPE ;
408- @ Alias @ RecomputeFieldValue (isFinal = true , kind = Kind .None ) static int MN_CALLER_SENSITIVE ;
409- @ Alias @ RecomputeFieldValue (isFinal = true , kind = Kind .None ) static int MN_REFERENCE_KIND_SHIFT ;
410-
411- /**
412- * Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.
413- */
414- @ Alias @ RecomputeFieldValue (isFinal = true , kind = Kind .None ) static byte REF_NONE ; // null
415- @ Alias @ RecomputeFieldValue (isFinal = true , kind = Kind .None ) static byte REF_getField ;
416- @ Alias @ RecomputeFieldValue (isFinal = true , kind = Kind .None ) static byte REF_getStatic ;
417- @ Alias @ RecomputeFieldValue (isFinal = true , kind = Kind .None ) static byte REF_putField ;
418- @ Alias @ RecomputeFieldValue (isFinal = true , kind = Kind .None ) static byte REF_putStatic ;
419- @ Alias @ RecomputeFieldValue (isFinal = true , kind = Kind .None ) static byte REF_invokeVirtual ;
420- @ Alias @ RecomputeFieldValue (isFinal = true , kind = Kind .None ) static byte REF_invokeStatic ;
421- @ Alias @ RecomputeFieldValue (isFinal = true , kind = Kind .None ) static byte REF_invokeSpecial ;
422- @ Alias @ RecomputeFieldValue (isFinal = true , kind = Kind .None ) static byte REF_newInvokeSpecial ;
423- @ Alias @ RecomputeFieldValue (isFinal = true , kind = Kind .None ) static byte REF_invokeInterface ;
424- @ Alias @ RecomputeFieldValue (isFinal = true , kind = Kind .None ) static byte REF_LIMIT ;
425- // Checkstyle: resume
426- }
0 commit comments