43 * Abstract class for a plugin generated for a method annotated by {@link NodeIntrinsic} or |
43 * Abstract class for a plugin generated for a method annotated by {@link NodeIntrinsic} or |
44 * {@link Fold}. |
44 * {@link Fold}. |
45 */ |
45 */ |
46 public abstract class GeneratedInvocationPlugin implements InvocationPlugin { |
46 public abstract class GeneratedInvocationPlugin implements InvocationPlugin { |
47 |
47 |
|
48 private ResolvedJavaMethod executeMethod; |
|
49 |
48 /** |
50 /** |
49 * Gets the class of the annotation for which this plugin was generated. |
51 * Gets the class of the annotation for which this plugin was generated. |
50 */ |
52 */ |
51 public abstract Class<? extends Annotation> getSource(); |
53 public abstract Class<? extends Annotation> getSource(); |
52 |
54 |
67 protected boolean checkInjectedArgument(GraphBuilderContext b, ValueNode arg, ResolvedJavaMethod foldAnnotatedMethod) { |
69 protected boolean checkInjectedArgument(GraphBuilderContext b, ValueNode arg, ResolvedJavaMethod foldAnnotatedMethod) { |
68 if (arg.isNullConstant()) { |
70 if (arg.isNullConstant()) { |
69 return true; |
71 return true; |
70 } |
72 } |
71 |
73 |
72 if (IS_IN_NATIVE_IMAGE || IS_BUILDING_NATIVE_IMAGE) { |
74 if (IS_IN_NATIVE_IMAGE) { |
73 // The reflection here is problematic for SVM. |
75 // The reflection here is problematic for SVM. |
74 return true; |
76 return true; |
75 } |
77 } |
76 |
78 |
77 MetaAccessProvider metaAccess = b.getMetaAccess(); |
79 if (b.getMethod().equals(foldAnnotatedMethod)) { |
78 ResolvedJavaMethod executeMethod = metaAccess.lookupJavaMethod(getExecuteMethod()); |
80 return false; |
79 ResolvedJavaType thisClass = metaAccess.lookupJavaType(getClass()); |
81 } |
80 ResolvedJavaMethod thisExecuteMethod = thisClass.resolveConcreteMethod(executeMethod, thisClass); |
82 |
|
83 ResolvedJavaMethod thisExecuteMethod = getExecutedMethod(b); |
81 if (b.getMethod().equals(thisExecuteMethod)) { |
84 if (b.getMethod().equals(thisExecuteMethod)) { |
82 // The "execute" method of this plugin is itself being compiled. In (only) this context, |
85 // The "execute" method of this plugin is itself being compiled. In (only) this context, |
83 // the injected argument of the call to the @Fold annotated method will be non-null. |
86 // the injected argument of the call to the @Fold annotated method will be non-null. |
|
87 if (IS_BUILDING_NATIVE_IMAGE) { |
|
88 return false; |
|
89 } |
84 return true; |
90 return true; |
85 } |
91 } |
86 throw new AssertionError("must pass null to injected argument of " + foldAnnotatedMethod.format("%H.%n(%p)") + ", not " + arg); |
92 throw new AssertionError("must pass null to injected argument of " + foldAnnotatedMethod.format("%H.%n(%p)") + ", not " + arg); |
|
93 } |
|
94 |
|
95 private ResolvedJavaMethod getExecutedMethod(GraphBuilderContext b) { |
|
96 if (executeMethod == null) { |
|
97 MetaAccessProvider metaAccess = b.getMetaAccess(); |
|
98 ResolvedJavaMethod baseMethod = metaAccess.lookupJavaMethod(getExecuteMethod()); |
|
99 ResolvedJavaType thisClass = metaAccess.lookupJavaType(getClass()); |
|
100 executeMethod = thisClass.resolveConcreteMethod(baseMethod, thisClass); |
|
101 } |
|
102 return executeMethod; |
87 } |
103 } |
88 |
104 |
89 private static Method getExecuteMethod() { |
105 private static Method getExecuteMethod() { |
90 try { |
106 try { |
91 return GeneratedInvocationPlugin.class.getMethod("execute", GraphBuilderContext.class, ResolvedJavaMethod.class, InvocationPlugin.Receiver.class, ValueNode[].class); |
107 return GeneratedInvocationPlugin.class.getMethod("execute", GraphBuilderContext.class, ResolvedJavaMethod.class, InvocationPlugin.Receiver.class, ValueNode[].class); |