use of jdk.vm.ci.meta.JavaKind in project graal by oracle.
the class JNIFunctionTablesFeature method buildFunctionsInitializer.
private JNIStructFunctionsInitializer<JNINativeInterface> buildFunctionsInitializer(CompilationAccessImpl access, CFunctionPointer unimplemented) {
Class<JNIFunctions> clazz = JNIFunctions.class;
HostedType functions = access.getMetaAccess().lookupJavaType(clazz);
HostedMethod[] methods = functions.getDeclaredMethods();
int index = 0;
int count = methods.length + generatedMethods.length;
// Call, CallStatic, CallNonvirtual: for each return value kind: array, va_list, varargs
// NewObject: array, va_list, varargs
count += (jniKinds.size() * 3 + 1) * 3;
int[] offsets = new int[count];
CFunctionPointer[] pointers = new CFunctionPointer[offsets.length];
for (HostedMethod method : methods) {
StructFieldInfo field = findFieldFor(functionTableMetadata, method.getName());
offsets[index] = field.getOffsetInfo().getProperty();
pointers[index] = getStubFunctionPointer(access, method);
index++;
}
for (ResolvedJavaMethod accessor : generatedMethods) {
StructFieldInfo field = findFieldFor(functionTableMetadata, accessor.getName());
AnalysisUniverse analysisUniverse = access.getUniverse().getBigBang().getUniverse();
AnalysisMethod analysisMethod = analysisUniverse.lookup(accessor);
HostedMethod hostedMethod = access.getUniverse().lookup(analysisMethod);
offsets[index] = field.getOffsetInfo().getProperty();
pointers[index] = MethodPointer.factory(hostedMethod);
index++;
}
for (CallVariant variant : CallVariant.values()) {
CFunctionPointer trampoline = prepareCallTrampoline(access, variant, false);
String suffix = (variant == CallVariant.ARRAY) ? "A" : ((variant == CallVariant.VA_LIST) ? "V" : "");
CFunctionPointer nonvirtualTrampoline = prepareCallTrampoline(access, variant, true);
for (JavaKind kind : jniKinds) {
String[] prefixes = { "Call", "CallStatic" };
for (String prefix : prefixes) {
StructFieldInfo field = findFieldFor(functionTableMetadata, prefix + kind.name() + "Method" + suffix);
offsets[index] = field.getOffsetInfo().getProperty();
pointers[index] = trampoline;
index++;
}
StructFieldInfo field = findFieldFor(functionTableMetadata, "CallNonvirtual" + kind.name() + "Method" + suffix);
offsets[index] = field.getOffsetInfo().getProperty();
pointers[index] = nonvirtualTrampoline;
index++;
}
StructFieldInfo field = findFieldFor(functionTableMetadata, "NewObject" + suffix);
offsets[index] = field.getOffsetInfo().getProperty();
pointers[index] = trampoline;
index++;
}
VMError.guarantee(index == offsets.length && index == pointers.length);
return new JNIStructFunctionsInitializer<>(JNINativeInterface.class, offsets, pointers, unimplemented);
}
use of jdk.vm.ci.meta.JavaKind in project graal by oracle.
the class ReflectionSubstitutionType method fillArgsArray.
private static void fillArgsArray(HostedGraphKit graphKit, ValueNode argumentArray, int receiverOffset, ValueNode[] args, Class<?>[] argTypes) {
for (int i = 0; i < argTypes.length; i++) {
JavaKind argKind = JavaKind.fromJavaClass(argTypes[i]);
ValueNode arg = graphKit.createLoadIndexed(argumentArray, i, JavaKind.Object);
if (argKind.isPrimitive()) {
arg = createCheckcast(graphKit, arg, graphKit.getMetaAccess().lookupJavaType(argKind.toBoxedJavaClass()), true);
arg = graphKit.createUnboxing(arg, argKind);
} else {
arg = createCheckcast(graphKit, arg, graphKit.getMetaAccess().lookupJavaType(argTypes[i]), false);
}
args[i + receiverOffset] = arg;
}
}
use of jdk.vm.ci.meta.JavaKind in project graal by oracle.
the class JNIFieldAccessorMethod method buildGraph.
@Override
public StructuredGraph buildGraph(DebugContext debug, ResolvedJavaMethod method, HostedProviders providers, Purpose purpose) {
JNIGraphKit kit = new JNIGraphKit(debug, providers, method);
StructuredGraph graph = kit.getGraph();
FrameStateBuilder state = new FrameStateBuilder(null, method, graph);
state.initializeForMethodStart(null, true, providers.getGraphBuilderPlugins());
ValueNode vmThread = kit.loadLocal(0, signature.getParameterKind(0));
kit.append(new CEntryPointEnterNode(EnterAction.Enter, vmThread));
List<ValueNode> arguments = kit.loadArguments(signature.toParameterTypes(null));
ValueNode object;
if (isStatic) {
if (fieldKind.isPrimitive()) {
object = kit.getStaticPrimitiveFieldsArray();
} else {
object = kit.getStaticObjectFieldsArray();
}
} else {
ValueNode handle = arguments.get(1);
object = kit.unboxHandle(handle);
}
ValueNode fieldId = arguments.get(2);
ValueNode offset = kit.getFieldOffsetFromId(fieldId);
ValueNode returnValue;
if (isSetter) {
// void
returnValue = null;
ValueNode newValue = arguments.get(3);
if (fieldKind.isObject()) {
newValue = kit.unboxHandle(newValue);
}
kit.append(new RawStoreNode(object, offset, newValue, fieldKind, LocationIdentity.ANY_LOCATION));
} else {
returnValue = kit.append(new RawLoadNode(object, offset, fieldKind, LocationIdentity.ANY_LOCATION));
if (fieldKind.isObject()) {
returnValue = kit.boxObjectInLocalHandle(returnValue);
}
}
kit.append(new CEntryPointLeaveNode(LeaveAction.Leave));
JavaKind returnKind = isSetter ? JavaKind.Void : fieldKind;
kit.createReturn(returnValue, returnKind);
assert graph.verify();
return graph;
}
use of jdk.vm.ci.meta.JavaKind in project graal by oracle.
the class AArch64FloatArithmeticSnippets method lower.
public void lower(RemNode node, LoweringTool tool) {
JavaKind kind = node.stamp(NodeView.DEFAULT).getStackKind();
assert kind == JavaKind.Float || kind == JavaKind.Double;
if (node instanceof SafeNode) {
// We already introduced the necessary checks, nothing to do.
return;
}
SnippetTemplate.SnippetInfo snippet = kind == JavaKind.Float ? frem : drem;
StructuredGraph graph = node.graph();
Arguments args = new Arguments(snippet, graph.getGuardsStage(), tool.getLoweringStage());
args.add("x", node.getX());
args.add("y", node.getY());
template(node, args).instantiate(providers.getMetaAccess(), node, SnippetTemplate.DEFAULT_REPLACER, tool, args);
}
use of jdk.vm.ci.meta.JavaKind in project graal by oracle.
the class AArch64IntegerArithmeticSnippets method lower.
public void lower(FixedBinaryNode node, LoweringTool tool) {
JavaKind kind = node.stamp(NodeView.DEFAULT).getStackKind();
assert kind == JavaKind.Int || kind == JavaKind.Long;
SnippetTemplate.SnippetInfo snippet;
if (node instanceof SafeNode) {
// We already introduced the zero division check, nothing to do.
return;
} else if (node instanceof SignedDivNode) {
snippet = kind == JavaKind.Int ? idiv : ldiv;
} else if (node instanceof SignedRemNode) {
snippet = kind == JavaKind.Int ? irem : lrem;
} else if (node instanceof UnsignedDivNode) {
snippet = kind == JavaKind.Int ? uidiv : uldiv;
} else if (node instanceof UnsignedRemNode) {
snippet = kind == JavaKind.Int ? uirem : ulrem;
} else {
throw GraalError.shouldNotReachHere();
}
StructuredGraph graph = node.graph();
Arguments args = new Arguments(snippet, graph.getGuardsStage(), tool.getLoweringStage());
args.add("x", node.getX());
args.add("y", node.getY());
template(node, args).instantiate(providers.getMetaAccess(), node, SnippetTemplate.DEFAULT_REPLACER, args);
}
Aggregations