use of jdk.vm.ci.meta.JavaKind in project graal by oracle.
the class SubstrateGraphKit method returnStamp.
private Stamp returnStamp(Signature signature) {
JavaType returnType = signature.getReturnType(null);
JavaKind returnKind = signature.getReturnKind();
if (returnKind == JavaKind.Object && returnType instanceof ResolvedJavaType) {
return StampFactory.object(TypeReference.createTrustedWithoutAssumptions((ResolvedJavaType) returnType));
} else {
return getLoweringProvider().loadStamp(StampFactory.forKind(returnKind), signature.getReturnKind());
}
}
use of jdk.vm.ci.meta.JavaKind 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.JavaKind in project graal by oracle.
the class UnsafeEATest method testEscapeAnalysis.
@Override
protected void testEscapeAnalysis(String snippet, JavaConstant expectedConstantResult, boolean iterativeEscapeAnalysis) {
// Exercise both a graph containing UnsafeAccessNodes and one which has been possibly been
// canonicalized into AccessFieldNodes.
testingUnsafe = true;
super.testEscapeAnalysis(snippet, expectedConstantResult, iterativeEscapeAnalysis);
testingUnsafe = false;
super.testEscapeAnalysis(snippet, expectedConstantResult, iterativeEscapeAnalysis);
if (expectedConstantResult != null) {
// Check that a compiled version of this method returns the same value if we expect a
// constant result.
ResolvedJavaMethod method = getResolvedJavaMethod(snippet);
JavaKind[] javaKinds = method.getSignature().toParameterKinds(false);
Object[] args = new Object[javaKinds.length];
int i = 0;
for (JavaKind k : javaKinds) {
args[i++] = JavaConstant.defaultForKind(k).asBoxedPrimitive();
}
Result result = executeExpected(method, null, args);
assertTrue(result.returnValue.equals(expectedConstantResult.asBoxedPrimitive()));
}
}
use of jdk.vm.ci.meta.JavaKind in project graal by oracle.
the class QueryResultParser method visitConstantInfo.
@Override
protected void visitConstantInfo(ConstantInfo constantInfo) {
TargetDescription target = nativeLibs.getTarget();
switch(constantInfo.getKind()) {
case INTEGER:
parseIntegerProperty(constantInfo.getSizeInfo());
parseSignedness(constantInfo.getSignednessInfo());
parseIntegerConstantValue(constantInfo.getValueInfo());
/*
* From the point of view of the C compiler, plain #define constants have the type
* int and therefore size 4. But sometimes we want to access such values as short or
* byte to avoid casts. Check the actual value of the constant, and if it fits the
* declared type of the constant, then change the actual size to the declared size.
*/
ResolvedJavaMethod method = (ResolvedJavaMethod) constantInfo.getAnnotatedElement();
ResolvedJavaType returnType = (ResolvedJavaType) method.getSignature().getReturnType(method.getDeclaringClass());
JavaKind returnKind = returnType.getJavaKind();
if (returnKind == JavaKind.Object) {
returnKind = target.wordJavaKind;
}
int declaredSize = target.arch.getPlatformKind(returnKind).getSizeInBytes();
int actualSize = constantInfo.getSizeInfo().getProperty();
if (declaredSize != actualSize) {
long value = (long) constantInfo.getValueInfo().getProperty();
if (value >= returnKind.getMinValue() && value <= returnKind.getMaxValue()) {
constantInfo.getSizeInfo().setProperty(declaredSize);
}
}
break;
case POINTER:
parseIntegerProperty(constantInfo.getSizeInfo());
parseIntegerConstantValue(constantInfo.getValueInfo());
break;
case FLOAT:
parseIntegerProperty(constantInfo.getSizeInfo());
parseFloatValue(constantInfo.getValueInfo());
break;
case STRING:
parseStringValue(constantInfo.getValueInfo());
break;
case BYTEARRAY:
parseByteArrayValue(constantInfo.getValueInfo());
break;
default:
throw shouldNotReachHere();
}
}
use of jdk.vm.ci.meta.JavaKind in project graal by oracle.
the class BytecodeParser method genGetField.
private void genGetField(ResolvedJavaField resolvedField, ValueNode receiver) {
if (!parsingIntrinsic() && GeneratePIC.getValue(getOptions())) {
graph.recordField(resolvedField);
}
for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) {
if (plugin.handleLoadField(this, receiver, resolvedField)) {
return;
}
}
ValueNode fieldRead = append(genLoadField(receiver, resolvedField));
if (resolvedField.getDeclaringClass().getName().equals("Ljava/lang/ref/Reference;") && resolvedField.getName().equals("referent")) {
LocationIdentity referentIdentity = new FieldLocationIdentity(resolvedField);
append(new MembarNode(0, referentIdentity));
}
JavaKind fieldKind = resolvedField.getJavaKind();
if (resolvedField.isVolatile() && fieldRead instanceof LoadFieldNode) {
StateSplitProxyNode readProxy = append(genVolatileFieldReadProxy(fieldRead));
frameState.push(fieldKind, readProxy);
readProxy.setStateAfter(frameState.create(stream.nextBCI(), readProxy));
} else {
frameState.push(fieldKind, fieldRead);
}
}
Aggregations