use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class SnippetTemplate method bind.
/**
* Gets the instantiation-time bindings to this template's parameters.
*
* @return the map that will be used to bind arguments to parameters when inlining this template
*/
private EconomicMap<Node, Node> bind(StructuredGraph replaceeGraph, MetaAccessProvider metaAccess, Arguments args) {
EconomicMap<Node, Node> replacements = EconomicMap.create(Equivalence.IDENTITY);
assert args.info.getParameterCount() == parameters.length : "number of args (" + args.info.getParameterCount() + ") != number of parameters (" + parameters.length + ")";
for (int i = 0; i < parameters.length; i++) {
Object parameter = parameters[i];
assert parameter != null : this + " has no parameter named " + args.info.getParameterName(i);
Object argument = args.values[i];
if (parameter instanceof ParameterNode) {
if (argument instanceof ValueNode) {
replacements.put((ParameterNode) parameter, (ValueNode) argument);
} else {
JavaKind kind = ((ParameterNode) parameter).getStackKind();
assert argument != null || kind == JavaKind.Object : this + " cannot accept null for non-object parameter named " + args.info.getParameterName(i);
JavaConstant constant = forBoxed(argument, kind);
replacements.put((ParameterNode) parameter, ConstantNode.forConstant(constant, metaAccess, replaceeGraph));
}
} else if (parameter instanceof ParameterNode[]) {
ParameterNode[] params = (ParameterNode[]) parameter;
Varargs varargs = (Varargs) argument;
int length = params.length;
List<?> list = null;
Object array = null;
if (varargs.value instanceof List) {
list = (List<?>) varargs.value;
assert list.size() == length : length + " != " + list.size();
} else {
array = varargs.value;
assert array != null && array.getClass().isArray();
assert Array.getLength(array) == length : length + " != " + Array.getLength(array);
}
for (int j = 0; j < length; j++) {
ParameterNode param = params[j];
assert param != null;
Object value = list != null ? list.get(j) : Array.get(array, j);
if (value instanceof ValueNode) {
replacements.put(param, (ValueNode) value);
} else {
JavaConstant constant = forBoxed(value, param.getStackKind());
ConstantNode element = ConstantNode.forConstant(constant, metaAccess, replaceeGraph);
replacements.put(param, element);
}
}
} else {
assert parameter.equals(CONSTANT_PARAMETER) || parameter.equals(UNUSED_PARAMETER) : "unexpected entry for parameter: " + args.info.getParameterName(i) + " -> " + parameter;
}
}
return replacements;
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class StandardGraphBuilderPlugins method registerStringPlugins.
private static void registerStringPlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider, SnippetReflectionProvider snippetReflection) {
final Registration r = new Registration(plugins, String.class, bytecodeProvider);
r.register1("hashCode", Receiver.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
if (receiver.isConstant()) {
String s = snippetReflection.asObject(String.class, (JavaConstant) receiver.get().asConstant());
b.addPush(JavaKind.Int, b.add(ConstantNode.forInt(s.hashCode())));
return true;
}
return false;
}
});
if (Java8OrEarlier) {
r.registerMethodSubstitution(StringSubstitutions.class, "equals", Receiver.class, Object.class);
r.register7("indexOf", char[].class, int.class, int.class, char[].class, int.class, int.class, int.class, new StringIndexOfConstantPlugin());
Registration sr = new Registration(plugins, StringSubstitutions.class);
sr.register1("getValue", String.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
ResolvedJavaField field = b.getMetaAccess().lookupJavaField(STRING_VALUE_FIELD);
b.addPush(JavaKind.Object, LoadFieldNode.create(b.getConstantFieldProvider(), b.getConstantReflection(), b.getMetaAccess(), b.getOptions(), b.getAssumptions(), value, field, false, false));
return true;
}
});
}
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class MethodHandleNode method maybeCastArgument.
/**
* Inserts a node to cast the argument at index to the given type if the given type is more
* concrete than the argument type.
*
* @param adder
* @param index of the argument to be cast
* @param type the type the argument should be cast to
*/
private static void maybeCastArgument(GraphAdder adder, ValueNode[] arguments, int index, JavaType type) {
ValueNode argument = arguments[index];
if (type instanceof ResolvedJavaType && !((ResolvedJavaType) type).isJavaLangObject()) {
Assumptions assumptions = adder.getAssumptions();
TypeReference targetType = TypeReference.create(assumptions, (ResolvedJavaType) type);
/*
* When an argument is a Word type, we can have a mismatch of primitive/object types
* here. Not inserting a PiNode is a safe fallback, and Word types need no additional
* type information anyway.
*/
if (targetType != null && !targetType.getType().isPrimitive() && !argument.getStackKind().isPrimitive()) {
ResolvedJavaType argumentType = StampTool.typeOrNull(argument.stamp(NodeView.DEFAULT));
if (argumentType == null || (argumentType.isAssignableFrom(targetType.getType()) && !argumentType.equals(targetType.getType()))) {
LogicNode inst = InstanceOfNode.createAllowNull(targetType, argument, null, null);
assert !inst.isAlive();
if (!inst.isTautology()) {
inst = adder.add(inst);
AnchoringNode guardAnchor = adder.getGuardAnchor();
DeoptimizationReason reason = DeoptimizationReason.ClassCastException;
DeoptimizationAction action = DeoptimizationAction.InvalidateRecompile;
JavaConstant speculation = JavaConstant.NULL_POINTER;
GuardingNode guard;
if (guardAnchor == null) {
FixedGuardNode fixedGuard = adder.add(new FixedGuardNode(inst, reason, action, speculation, false));
guard = fixedGuard;
} else {
GuardNode newGuard = adder.add(new GuardNode(inst, guardAnchor, reason, action, false, speculation));
adder.add(new ValueAnchorNode(newGuard));
guard = newGuard;
}
ValueNode valueNode = adder.add(PiNode.create(argument, StampFactory.object(targetType), guard.asNode()));
arguments[index] = valueNode;
}
}
}
}
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class PartialEvaluator method getDecision.
private static TruffleInliningPlan.Decision getDecision(TruffleInliningPlan inlining, JavaConstant callNode) {
TruffleInliningPlan.Decision decision = inlining.findDecision(callNode);
if (decision == null) {
JavaConstant target = getRuntime().getCallTargetForCallNode(callNode);
PerformanceInformationHandler.reportDecisionIsNull(target, callNode);
} else if (!decision.isTargetStable()) {
JavaConstant target = getRuntime().getCallTargetForCallNode(callNode);
PerformanceInformationHandler.reportCallTargetChanged(target, callNode, decision);
return null;
}
return decision;
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class ArrayEqualsNode method arrayEquals.
private static boolean arrayEquals(ConstantReflectionProvider constantReflection, JavaConstant a, JavaConstant b, int len) {
for (int i = 0; i < len; i++) {
JavaConstant aElem = constantReflection.readArrayElement(a, i);
JavaConstant bElem = constantReflection.readArrayElement(b, i);
if (!constantReflection.constantEquals(aElem, bElem) && !(isNaNFloat(aElem) && isNaNFloat(bElem))) {
return false;
}
}
return true;
}
Aggregations