use of jdk.vm.ci.meta.MetaAccessProvider in project graal by oracle.
the class ReplacementsImpl method getSubstitution.
@Override
public StructuredGraph getSubstitution(ResolvedJavaMethod method, int invokeBci, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition) {
StructuredGraph result;
InvocationPlugin plugin = graphBuilderPlugins.getInvocationPlugins().lookupInvocation(method);
if (plugin != null && (!plugin.inlineOnly() || invokeBci >= 0)) {
MetaAccessProvider metaAccess = providers.getMetaAccess();
if (plugin instanceof MethodSubstitutionPlugin) {
MethodSubstitutionPlugin msPlugin = (MethodSubstitutionPlugin) plugin;
ResolvedJavaMethod substitute = msPlugin.getSubstitute(metaAccess);
StructuredGraph graph = UseSnippetGraphCache.getValue(options) ? graphs.get(substitute) : null;
if (graph == null || graph.trackNodeSourcePosition() != trackNodeSourcePosition) {
try (DebugContext debug = openDebugContext("Substitution_", method)) {
graph = makeGraph(debug, msPlugin.getBytecodeProvider(), substitute, null, method, trackNodeSourcePosition, replaceePosition);
if (!UseSnippetGraphCache.getValue(options)) {
return graph;
}
graph.freeze();
graphs.putIfAbsent(substitute, graph);
graph = graphs.get(substitute);
}
}
assert graph.isFrozen();
result = graph;
} else {
Bytecode code = new ResolvedJavaMethodBytecode(method);
ConstantReflectionProvider constantReflection = providers.getConstantReflection();
ConstantFieldProvider constantFieldProvider = providers.getConstantFieldProvider();
StampProvider stampProvider = providers.getStampProvider();
try (DebugContext debug = openDebugContext("Substitution_", method)) {
result = new IntrinsicGraphBuilder(options, debug, metaAccess, constantReflection, constantFieldProvider, stampProvider, code, invokeBci).buildGraph(plugin);
}
}
} else {
result = null;
}
return result;
}
use of jdk.vm.ci.meta.MetaAccessProvider in project graal by oracle.
the class TruffleCompilerImpl method getSkippedExceptionTypes.
private ResolvedJavaType[] getSkippedExceptionTypes(TruffleCompilerRuntime runtime) {
final MetaAccessProvider metaAccess = providers.getMetaAccess();
ResolvedJavaType[] head = metaAccess.lookupJavaTypes(new Class<?>[] { ArithmeticException.class, IllegalArgumentException.class, VirtualMachineError.class, IndexOutOfBoundsException.class, ClassCastException.class, BufferUnderflowException.class, BufferOverflowException.class });
ResolvedJavaType[] tail = { runtime.resolveType(metaAccess, "com.oracle.truffle.api.nodes.UnexpectedResultException"), runtime.resolveType(metaAccess, "com.oracle.truffle.api.nodes.SlowPathException") };
ResolvedJavaType[] skippedExceptionTypes = new ResolvedJavaType[head.length + tail.length];
System.arraycopy(head, 0, skippedExceptionTypes, 0, head.length);
System.arraycopy(tail, 0, skippedExceptionTypes, head.length, tail.length);
return skippedExceptionTypes;
}
use of jdk.vm.ci.meta.MetaAccessProvider in project graal by oracle.
the class HotSpotTruffleRuntime method getTruffleCallBoundaryMethods.
@Override
public synchronized Iterable<ResolvedJavaMethod> getTruffleCallBoundaryMethods() {
if (truffleCallBoundaryMethods == null) {
truffleCallBoundaryMethods = new ArrayList<>();
MetaAccessProvider metaAccess = getMetaAccess();
ResolvedJavaType type = metaAccess.lookupJavaType(OptimizedCallTarget.class);
for (ResolvedJavaMethod method : type.getDeclaredMethods()) {
if (method.getAnnotation(TruffleCallBoundary.class) != null) {
truffleCallBoundaryMethods.add(method);
}
}
}
return truffleCallBoundaryMethods;
}
use of jdk.vm.ci.meta.MetaAccessProvider in project graal by oracle.
the class CFunctionCallStubMethod method adaptSignatureAndConvertArguments.
private static Signature adaptSignatureAndConvertArguments(ResolvedJavaMethod method, HostedProviders providers, NativeLibraries nativeLibraries, HostedGraphKit kit, Signature signature, List<ValueNode> arguments) {
MetaAccessProvider metaAccess = providers.getMetaAccess();
JavaType returnType = signature.getReturnType(null);
JavaType[] parameterTypes = signature.toParameterTypes(null);
for (int i = 0; i < parameterTypes.length; i++) {
if (!isPrimitiveOrWord(providers, parameterTypes[i])) {
ElementInfo typeInfo = nativeLibraries.findElementInfo(parameterTypes[i]);
if (typeInfo instanceof EnumInfo) {
UserError.guarantee(typeInfo.getChildren().stream().anyMatch(EnumValueInfo.class::isInstance), "Enum class " + returnType.toJavaName() + " needs a method that is annotated with @" + CEnumValue.class.getSimpleName() + " because it is used as a parameter of a method annotated with @" + CFunction.class.getSimpleName() + ": " + method.format("%H.%n(%p)"));
ValueNode argumentValue = arguments.get(i);
IsNullNode isNull = kit.unique(new IsNullNode(argumentValue));
kit.startIf(isNull, BranchProbabilityNode.VERY_SLOW_PATH_PROBABILITY);
kit.thenPart();
ResolvedJavaType enumExceptionType = metaAccess.lookupJavaType(RuntimeException.class);
NewInstanceNode enumException = kit.append(new NewInstanceNode(enumExceptionType, true));
Iterator<ResolvedJavaMethod> enumExceptionCtor = Arrays.stream(enumExceptionType.getDeclaredConstructors()).filter(c -> c.getSignature().getParameterCount(false) == 1 && c.getSignature().getParameterType(0, null).equals(metaAccess.lookupJavaType(String.class))).iterator();
ConstantNode enumExceptionMessage = kit.createConstant(kit.getConstantReflection().forString("null return value cannot be converted to a C enum value"), JavaKind.Object);
kit.createJavaCallWithExceptionAndUnwind(InvokeKind.Special, enumExceptionCtor.next(), enumException, enumExceptionMessage);
assert !enumExceptionCtor.hasNext();
kit.append(new UnwindNode(enumException));
kit.endIf();
CInterfaceEnumTool tool = new CInterfaceEnumTool(metaAccess, providers.getSnippetReflection());
argumentValue = tool.createEnumValueInvoke(kit, (EnumInfo) typeInfo, cEnumKind, argumentValue);
arguments.set(i, argumentValue);
parameterTypes[i] = metaAccess.lookupJavaType(cEnumKind.toJavaClass());
} else {
throw UserError.abort("@" + CFunction.class.getSimpleName() + " parameter types are restricted to primitive types, word types and enumerations (@" + CEnum.class.getSimpleName() + "): " + method.format("%H.%n(%p)"));
}
}
}
if (!isPrimitiveOrWord(providers, returnType)) {
// Assume enum: actual checks and conversion are in adaptReturnValue()
returnType = providers.getWordTypes().getWordImplType();
}
JavaType actualReturnType = returnType;
return new Signature() {
@Override
public int getParameterCount(boolean receiver) {
return parameterTypes.length;
}
@Override
public JavaType getParameterType(int index, ResolvedJavaType accessingClass) {
return parameterTypes[index];
}
@Override
public JavaType getReturnType(ResolvedJavaType accessingClass) {
return actualReturnType;
}
};
}
use of jdk.vm.ci.meta.MetaAccessProvider in project graal by oracle.
the class ObjectEqualsNode method virtualize.
@Override
public void virtualize(VirtualizerTool tool) {
ValueNode xAlias = tool.getAlias(getX());
ValueNode yAlias = tool.getAlias(getY());
VirtualObjectNode xVirtual = xAlias instanceof VirtualObjectNode ? (VirtualObjectNode) xAlias : null;
VirtualObjectNode yVirtual = yAlias instanceof VirtualObjectNode ? (VirtualObjectNode) yAlias : null;
if (xVirtual != null && yVirtual == null) {
virtualizeNonVirtualComparison(xVirtual, yAlias, tool);
} else if (xVirtual == null && yVirtual != null) {
virtualizeNonVirtualComparison(yVirtual, xAlias, tool);
} else if (xVirtual != null && yVirtual != null) {
if (xVirtual.hasIdentity() ^ yVirtual.hasIdentity()) {
/*
* One of the two objects has identity, the other doesn't. In code, this looks like
* "Integer.valueOf(a) == new Integer(b)", which is always false.
*
* In other words: an object created via valueOf can never be equal to one created
* by new in the same compilation unit.
*/
tool.replaceWithValue(LogicConstantNode.contradiction(graph()));
} else if (!xVirtual.hasIdentity() && !yVirtual.hasIdentity()) {
ResolvedJavaType type = xVirtual.type();
if (type.equals(yVirtual.type())) {
MetaAccessProvider metaAccess = tool.getMetaAccessProvider();
if (type.equals(metaAccess.lookupJavaType(Integer.class)) || type.equals(metaAccess.lookupJavaType(Long.class))) {
// both are virtual without identity: check contents
assert xVirtual.entryCount() == 1 && yVirtual.entryCount() == 1;
assert xVirtual.entryKind(0).getStackKind() == JavaKind.Int || xVirtual.entryKind(0) == JavaKind.Long;
IntegerEqualsNode equals = new IntegerEqualsNode(tool.getEntry(xVirtual, 0), tool.getEntry(yVirtual, 0));
tool.addNode(equals);
tool.replaceWithValue(equals);
}
}
} else {
// both are virtual with identity: check if they refer to the same object
tool.replaceWithValue(LogicConstantNode.forBoolean(xVirtual == yVirtual, graph()));
}
}
}
Aggregations