|
28 | 28 | import java.util.Arrays; |
29 | 29 | import java.util.Iterator; |
30 | 30 |
|
31 | | -import jdk.graal.compiler.core.common.calc.FloatConvert; |
32 | | -import jdk.graal.compiler.core.common.type.StampFactory; |
33 | | -import jdk.graal.compiler.debug.DebugContext; |
34 | | -import jdk.graal.compiler.graph.NodeSourcePosition; |
35 | | -import jdk.graal.compiler.nodes.CallTargetNode.InvokeKind; |
36 | | -import jdk.graal.compiler.nodes.ConstantNode; |
37 | | -import jdk.graal.compiler.nodes.DeadEndNode; |
38 | | -import jdk.graal.compiler.nodes.FrameState; |
39 | | -import jdk.graal.compiler.nodes.InvokeWithExceptionNode; |
40 | | -import jdk.graal.compiler.nodes.ParameterNode; |
41 | | -import jdk.graal.compiler.nodes.StructuredGraph; |
42 | | -import jdk.graal.compiler.nodes.ValueNode; |
43 | | -import jdk.graal.compiler.nodes.calc.FloatConvertNode; |
44 | | -import jdk.graal.compiler.nodes.calc.IntegerEqualsNode; |
45 | | -import jdk.graal.compiler.nodes.calc.SignExtendNode; |
46 | | -import jdk.graal.compiler.nodes.calc.ZeroExtendNode; |
47 | | -import jdk.graal.compiler.nodes.extended.BranchProbabilityNode; |
48 | | -import jdk.graal.compiler.nodes.java.ExceptionObjectNode; |
49 | 31 | import org.graalvm.nativeimage.Isolate; |
50 | 32 | import org.graalvm.nativeimage.IsolateThread; |
51 | 33 | import org.graalvm.nativeimage.c.constant.CEnum; |
|
58 | 40 | import com.oracle.graal.pointsto.infrastructure.WrappedJavaMethod; |
59 | 41 | import com.oracle.graal.pointsto.meta.AnalysisMetaAccess; |
60 | 42 | import com.oracle.graal.pointsto.meta.AnalysisMethod; |
| 43 | +import com.oracle.graal.pointsto.meta.AnalysisType; |
61 | 44 | import com.oracle.graal.pointsto.meta.HostedProviders; |
62 | 45 | import com.oracle.svm.core.SubstrateUtil; |
63 | 46 | import com.oracle.svm.core.Uninterruptible; |
|
81 | 64 | import com.oracle.svm.hosted.phases.CInterfaceEnumTool; |
82 | 65 | import com.oracle.svm.hosted.phases.HostedGraphKit; |
83 | 66 |
|
| 67 | +import jdk.graal.compiler.core.common.calc.FloatConvert; |
| 68 | +import jdk.graal.compiler.core.common.type.StampFactory; |
| 69 | +import jdk.graal.compiler.debug.DebugContext; |
| 70 | +import jdk.graal.compiler.graph.NodeSourcePosition; |
| 71 | +import jdk.graal.compiler.nodes.ConstantNode; |
| 72 | +import jdk.graal.compiler.nodes.DeadEndNode; |
| 73 | +import jdk.graal.compiler.nodes.FrameState; |
| 74 | +import jdk.graal.compiler.nodes.InvokeWithExceptionNode; |
| 75 | +import jdk.graal.compiler.nodes.ParameterNode; |
| 76 | +import jdk.graal.compiler.nodes.StructuredGraph; |
| 77 | +import jdk.graal.compiler.nodes.ValueNode; |
| 78 | +import jdk.graal.compiler.nodes.CallTargetNode.InvokeKind; |
| 79 | +import jdk.graal.compiler.nodes.calc.FloatConvertNode; |
| 80 | +import jdk.graal.compiler.nodes.calc.IntegerEqualsNode; |
| 81 | +import jdk.graal.compiler.nodes.calc.SignExtendNode; |
| 82 | +import jdk.graal.compiler.nodes.calc.ZeroExtendNode; |
| 83 | +import jdk.graal.compiler.nodes.extended.BranchProbabilityNode; |
| 84 | +import jdk.graal.compiler.nodes.java.ExceptionObjectNode; |
84 | 85 | import jdk.vm.ci.code.BytecodeFrame; |
85 | 86 | import jdk.vm.ci.meta.ConstantPool; |
86 | 87 | import jdk.vm.ci.meta.JavaKind; |
87 | 88 | import jdk.vm.ci.meta.JavaType; |
88 | 89 | import jdk.vm.ci.meta.MetaAccessProvider; |
89 | 90 | import jdk.vm.ci.meta.ResolvedJavaMethod; |
90 | 91 | import jdk.vm.ci.meta.ResolvedJavaType; |
| 92 | +import jdk.vm.ci.meta.Signature; |
91 | 93 |
|
92 | 94 | public final class CEntryPointCallStubMethod extends EntryPointCallStubMethod { |
93 | 95 | static CEntryPointCallStubMethod create(AnalysisMethod targetMethod, CEntryPointData entryPointData, AnalysisMetaAccess metaAccess) { |
94 | | - ResolvedJavaMethod unwrappedMethod = targetMethod.getWrapped(); |
95 | 96 | MetaAccessProvider unwrappedMetaAccess = metaAccess.getWrapped(); |
96 | 97 | ResolvedJavaType declaringClass = unwrappedMetaAccess.lookupJavaType(IsolateEnterStub.class); |
97 | 98 | ConstantPool constantPool = IsolateEnterStub.getConstantPool(unwrappedMetaAccess); |
98 | | - return new CEntryPointCallStubMethod(entryPointData, unwrappedMethod, declaringClass, constantPool); |
| 99 | + return new CEntryPointCallStubMethod(entryPointData, targetMethod, declaringClass, constantPool, metaAccess.getUniverse().getWordKind(), unwrappedMetaAccess); |
99 | 100 | } |
100 | 101 |
|
101 | 102 | private static final JavaKind cEnumParameterKind = JavaKind.Int; |
102 | 103 |
|
103 | 104 | private final CEntryPointData entryPointData; |
104 | 105 | private final ResolvedJavaMethod targetMethod; |
| 106 | + private final Signature targetSignature; |
105 | 107 |
|
106 | | - private CEntryPointCallStubMethod(CEntryPointData entryPointData, ResolvedJavaMethod targetMethod, ResolvedJavaType holderClass, ConstantPool holderConstantPool) { |
107 | | - super(SubstrateUtil.uniqueStubName(targetMethod), holderClass, targetMethod.getSignature(), holderConstantPool); |
| 108 | + private CEntryPointCallStubMethod(CEntryPointData entryPointData, AnalysisMethod targetMethod, ResolvedJavaType holderClass, ConstantPool holderConstantPool, JavaKind wordKind, |
| 109 | + MetaAccessProvider metaAccess) { |
| 110 | + super(SubstrateUtil.uniqueStubName(targetMethod.getWrapped()), holderClass, createSignature(targetMethod, wordKind, metaAccess), holderConstantPool); |
108 | 111 | this.entryPointData = entryPointData; |
109 | | - this.targetMethod = targetMethod; |
| 112 | + this.targetMethod = targetMethod.getWrapped(); |
| 113 | + this.targetSignature = targetMethod.getSignature(); |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * This method creates a new signature for the stub in which all @CEnum values are converted |
| 118 | + * into their corresponding primitive type. In correspondence to how the @CEnum values are |
| 119 | + * actually handled, parameters are transformed to the type specified by cEnumParameterKind and |
| 120 | + * return type is transformed into the word type. |
| 121 | + * |
| 122 | + * @see CEnum |
| 123 | + * @see CEntryPointCallStubMethod#adaptParameterTypes(HostedProviders, NativeLibraries, |
| 124 | + * HostedGraphKit, JavaType[], JavaType[]) |
| 125 | + * @see CEntryPointCallStubMethod#adaptReturnValue(ResolvedJavaMethod, HostedProviders, Purpose, |
| 126 | + * HostedGraphKit, ValueNode) |
| 127 | + */ |
| 128 | + private static SimpleSignature createSignature(AnalysisMethod targetMethod, JavaKind wordKind, MetaAccessProvider metaAccess) { |
| 129 | + JavaType[] paramTypes = Arrays.stream(targetMethod.toParameterTypes()) |
| 130 | + .map(it -> ((AnalysisType) it)) |
| 131 | + .map(type -> type.getAnnotation(CEnum.class) != null ? metaAccess.lookupJavaType(cEnumParameterKind.toJavaClass()) : type.getWrapped()) |
| 132 | + .toArray(JavaType[]::new); |
| 133 | + ResolvedJavaType returnType = ((AnalysisType) targetMethod.getSignature().getReturnType(null)).getWrapped(); |
| 134 | + if (returnType.getAnnotation(CEnum.class) != null) { |
| 135 | + returnType = metaAccess.lookupJavaType(wordKind.toJavaClass()); |
| 136 | + } |
| 137 | + return new SimpleSignature(paramTypes, returnType); |
110 | 138 | } |
111 | 139 |
|
112 | 140 | @Override |
@@ -145,7 +173,7 @@ public StructuredGraph buildGraph(DebugContext debug, ResolvedJavaMethod method, |
145 | 173 | NativeLibraries nativeLibraries = CEntryPointCallStubSupport.singleton().getNativeLibraries(); |
146 | 174 | HostedGraphKit kit = new HostedGraphKit(debug, providers, method, purpose); |
147 | 175 |
|
148 | | - JavaType[] parameterTypes = method.toParameterTypes(); |
| 176 | + JavaType[] parameterTypes = targetSignature.toParameterTypes(null); |
149 | 177 | JavaType[] parameterLoadTypes = Arrays.copyOf(parameterTypes, parameterTypes.length); |
150 | 178 | EnumInfo[] parameterEnumInfos; |
151 | 179 |
|
@@ -336,8 +364,8 @@ private EnumInfo[] adaptParameterTypes(HostedProviders providers, NativeLibrarie |
336 | 364 | assert !matchingNodes.hasNext() && parameterNode.usages().filter(n -> n != initialState).isEmpty(); |
337 | 365 | parameterNode.setStamp(StampFactory.forKind(cEnumParameterKind)); |
338 | 366 | } else { |
339 | | - throw UserError.abort("Entry point method parameter types are restricted to primitive types, word types and enumerations (@%s): %s", |
340 | | - CEnum.class.getSimpleName(), targetMethod); |
| 367 | + throw UserError.abort("Entry point method parameter types are restricted to primitive types, word types and enumerations (@%s): %s, given type was %s", |
| 368 | + CEnum.class.getSimpleName(), targetMethod, parameterTypes[i]); |
341 | 369 | } |
342 | 370 | } |
343 | 371 | } |
@@ -550,7 +578,7 @@ private ValueNode adaptReturnValue(ResolvedJavaMethod method, HostedProviders pr |
550 | 578 | if (returnValue.getStackKind().isPrimitive()) { |
551 | 579 | return returnValue; |
552 | 580 | } |
553 | | - JavaType returnType = method.getSignature().getReturnType(null); |
| 581 | + JavaType returnType = targetSignature.getReturnType(null); |
554 | 582 | NativeLibraries nativeLibraries = CEntryPointCallStubSupport.singleton().getNativeLibraries(); |
555 | 583 | ElementInfo typeInfo = nativeLibraries.findElementInfo((ResolvedJavaType) returnType); |
556 | 584 | if (typeInfo instanceof EnumInfo) { |
|
0 commit comments