use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.
the class BytecodeParser method emitCheckForInvokeSuperSpecial.
/**
* Checks that the class of the receiver of an {@link Bytecodes#INVOKESPECIAL} in a method
* declared in an interface (i.e., a default method) is assignable to the interface. If not,
* then deoptimize so that the interpreter can throw an {@link IllegalAccessError}.
*
* This is a check not performed by the verifier and so must be performed at runtime.
*
* @param args arguments to an {@link Bytecodes#INVOKESPECIAL} implementing a direct call to a
* method in a super class
*/
protected void emitCheckForInvokeSuperSpecial(ValueNode[] args) {
ResolvedJavaType callingClass = method.getDeclaringClass();
if (callingClass.getHostClass() != null) {
callingClass = callingClass.getHostClass();
}
if (callingClass.isInterface()) {
ValueNode receiver = args[0];
TypeReference checkedType = TypeReference.createTrusted(graph.getAssumptions(), callingClass);
LogicNode condition = genUnique(createInstanceOf(checkedType, receiver, null));
FixedGuardNode fixedGuard = append(new FixedGuardNode(condition, ClassCastException, None, false));
args[0] = append(PiNode.create(receiver, StampFactory.object(checkedType, true), fixedGuard));
}
}
use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.
the class SubstrateAMD64RegisterConfig method getCallingConvention.
@Override
public CallingConvention getCallingConvention(Type t, JavaType returnType, JavaType[] parameterTypes, ValueKindFactory<?> valueKindFactory) {
SubstrateCallingConventionType type = (SubstrateCallingConventionType) t;
boolean isEntryPoint = type.nativeABI && !type.outgoing;
AllocatableValue[] locations = new AllocatableValue[parameterTypes.length];
int currentGeneral = 0;
int currentXMM = 0;
/*
* We have to reserve a slot between return address and outgoing parameters for the deopt
* frame handle. Exception: calls to native methods.
*/
int currentStackOffset = (type.nativeABI ? 0 : target.wordSize);
JavaKind[] kinds = new JavaKind[locations.length];
for (int i = 0; i < parameterTypes.length; i++) {
JavaKind kind = ObjectLayout.getCallSignatureKind(isEntryPoint, (ResolvedJavaType) parameterTypes[i], metaAccess, target);
kinds[i] = kind;
switch(kind) {
case Byte:
case Boolean:
case Short:
case Char:
case Int:
case Long:
case Object:
if (currentGeneral < generalParameterRegs.size()) {
Register register = generalParameterRegs.get(currentGeneral++);
locations[i] = register.asValue(valueKindFactory.getValueKind(kind.getStackKind()));
}
break;
case Float:
case Double:
if (currentXMM < xmmParameterRegs.size()) {
Register register = xmmParameterRegs.get(currentXMM++);
locations[i] = register.asValue(valueKindFactory.getValueKind(kind));
}
break;
default:
throw shouldNotReachHere();
}
if (locations[i] == null) {
ValueKind<?> valueKind = valueKindFactory.getValueKind(kind.getStackKind());
locations[i] = StackSlot.get(valueKind, currentStackOffset, !type.outgoing);
currentStackOffset += Math.max(valueKind.getPlatformKind().getSizeInBytes(), target.wordSize);
}
}
JavaKind returnKind = returnType == null ? JavaKind.Void : ObjectLayout.getCallSignatureKind(isEntryPoint, (ResolvedJavaType) returnType, metaAccess, target);
AllocatableValue returnLocation = returnKind == JavaKind.Void ? Value.ILLEGAL : getReturnRegister(returnKind).asValue(valueKindFactory.getValueKind(returnKind.getStackKind()));
return new SubstrateCallingConvention(type, kinds, currentStackOffset, returnLocation, locations);
}
use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.
the class SubstrateArraysCopyOfNode method virtualize.
@Override
public void virtualize(VirtualizerTool tool) {
if (!newArrayType.isConstant()) {
/*
* This is an object array copy. If the new array type is not a constant then it cannot
* be vitualized.
*/
return;
}
/* from index is always 0 for Arrays.copyOf. */
ValueNode from = ConstantNode.forInt(0);
ResolvedJavaType newComponentType = tool.getConstantReflectionProvider().asJavaType(newArrayType.asConstant()).getComponentType();
GraphUtil.virtualizeArrayCopy(tool, original, originalLength, newLength, from, newComponentType, JavaKind.Object, graph(), (componentType, length) -> new SubstrateVirtualArrayNode(componentType, length));
}
use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.
the class DefaultJavaLoweringProvider method lowerStoreIndexedNode.
protected void lowerStoreIndexedNode(StoreIndexedNode storeIndexed, LoweringTool tool) {
StructuredGraph graph = storeIndexed.graph();
ValueNode value = storeIndexed.value();
ValueNode array = storeIndexed.array();
array = this.createNullCheckedValue(array, storeIndexed, tool);
GuardingNode boundsCheck = getBoundsCheck(storeIndexed, array, tool);
JavaKind elementKind = storeIndexed.elementKind();
LogicNode condition = null;
if (elementKind == JavaKind.Object && !StampTool.isPointerAlwaysNull(value)) {
/* Array store check. */
TypeReference arrayType = StampTool.typeReferenceOrNull(array);
if (arrayType != null && arrayType.isExact()) {
ResolvedJavaType elementType = arrayType.getType().getComponentType();
if (!elementType.isJavaLangObject()) {
TypeReference typeReference = TypeReference.createTrusted(storeIndexed.graph().getAssumptions(), elementType);
LogicNode typeTest = graph.addOrUniqueWithInputs(InstanceOfNode.create(typeReference, value));
condition = LogicNode.or(graph.unique(IsNullNode.create(value)), typeTest, GraalDirectives.UNLIKELY_PROBABILITY);
}
} else {
/*
* The guard on the read hub should be the null check of the array that was
* introduced earlier.
*/
ValueNode arrayClass = createReadHub(graph, array, tool);
ValueNode componentHub = createReadArrayComponentHub(graph, arrayClass, storeIndexed);
LogicNode typeTest = graph.unique(InstanceOfDynamicNode.create(graph.getAssumptions(), tool.getConstantReflection(), componentHub, value, false));
condition = LogicNode.or(graph.unique(IsNullNode.create(value)), typeTest, GraalDirectives.UNLIKELY_PROBABILITY);
}
}
AddressNode address = createArrayIndexAddress(graph, array, elementKind, storeIndexed.index(), boundsCheck);
WriteNode memoryWrite = graph.add(new WriteNode(address, NamedLocationIdentity.getArrayLocation(elementKind), implicitStoreConvert(graph, elementKind, value), arrayStoreBarrierType(storeIndexed.elementKind())));
memoryWrite.setGuard(boundsCheck);
if (condition != null) {
tool.createGuard(storeIndexed, condition, DeoptimizationReason.ArrayStoreException, DeoptimizationAction.InvalidateReprofile);
}
memoryWrite.setStateAfter(storeIndexed.stateAfter());
graph.replaceFixedWithFixed(storeIndexed, memoryWrite);
}
use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.
the class PEGraphDecoder method canonicalizeFixedNode.
@SuppressWarnings("try")
@Override
protected Node canonicalizeFixedNode(MethodScope s, Node node) {
PEMethodScope methodScope = (PEMethodScope) s;
Node replacedNode = node;
if (nodePlugins != null && nodePlugins.length > 0) {
if (node instanceof LoadFieldNode) {
LoadFieldNode loadFieldNode = (LoadFieldNode) node;
PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(methodScope, loadFieldNode);
ResolvedJavaField field = loadFieldNode.field();
if (loadFieldNode.isStatic()) {
for (NodePlugin nodePlugin : nodePlugins) {
if (nodePlugin.handleLoadStaticField(graphBuilderContext, field)) {
replacedNode = graphBuilderContext.pushedNode;
break;
}
}
} else {
ValueNode object = loadFieldNode.object();
for (NodePlugin nodePlugin : nodePlugins) {
if (nodePlugin.handleLoadField(graphBuilderContext, object, field)) {
replacedNode = graphBuilderContext.pushedNode;
break;
}
}
}
} else if (node instanceof StoreFieldNode) {
StoreFieldNode storeFieldNode = (StoreFieldNode) node;
PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(methodScope, storeFieldNode);
ResolvedJavaField field = storeFieldNode.field();
if (storeFieldNode.isStatic()) {
ValueNode value = storeFieldNode.value();
for (NodePlugin nodePlugin : nodePlugins) {
if (nodePlugin.handleStoreStaticField(graphBuilderContext, field, value)) {
replacedNode = graphBuilderContext.pushedNode;
break;
}
}
} else {
ValueNode object = storeFieldNode.object();
ValueNode value = storeFieldNode.value();
for (NodePlugin nodePlugin : nodePlugins) {
if (nodePlugin.handleStoreField(graphBuilderContext, object, field, value)) {
replacedNode = graphBuilderContext.pushedNode;
break;
}
}
}
} else if (node instanceof LoadIndexedNode) {
LoadIndexedNode loadIndexedNode = (LoadIndexedNode) node;
PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(methodScope, loadIndexedNode);
ValueNode array = loadIndexedNode.array();
ValueNode index = loadIndexedNode.index();
for (NodePlugin nodePlugin : nodePlugins) {
if (nodePlugin.handleLoadIndexed(graphBuilderContext, array, index, loadIndexedNode.elementKind())) {
replacedNode = graphBuilderContext.pushedNode;
break;
}
}
} else if (node instanceof StoreIndexedNode) {
StoreIndexedNode storeIndexedNode = (StoreIndexedNode) node;
PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(methodScope, storeIndexedNode);
ValueNode array = storeIndexedNode.array();
ValueNode index = storeIndexedNode.index();
ValueNode value = storeIndexedNode.value();
for (NodePlugin nodePlugin : nodePlugins) {
if (nodePlugin.handleStoreIndexed(graphBuilderContext, array, index, storeIndexedNode.elementKind(), value)) {
replacedNode = graphBuilderContext.pushedNode;
break;
}
}
} else if (node instanceof NewInstanceNode) {
NewInstanceNode newInstanceNode = (NewInstanceNode) node;
PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(methodScope, newInstanceNode);
ResolvedJavaType type = newInstanceNode.instanceClass();
for (NodePlugin nodePlugin : nodePlugins) {
if (nodePlugin.handleNewInstance(graphBuilderContext, type)) {
replacedNode = graphBuilderContext.pushedNode;
break;
}
}
} else if (node instanceof NewArrayNode) {
NewArrayNode newArrayNode = (NewArrayNode) node;
PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(methodScope, newArrayNode);
ResolvedJavaType elementType = newArrayNode.elementType();
ValueNode length = newArrayNode.length();
for (NodePlugin nodePlugin : nodePlugins) {
if (nodePlugin.handleNewArray(graphBuilderContext, elementType, length)) {
replacedNode = graphBuilderContext.pushedNode;
break;
}
}
} else if (node instanceof NewMultiArrayNode) {
NewMultiArrayNode newArrayNode = (NewMultiArrayNode) node;
PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(methodScope, newArrayNode);
ResolvedJavaType elementType = newArrayNode.type();
ValueNode[] dimensions = newArrayNode.dimensions().toArray(new ValueNode[0]);
for (NodePlugin nodePlugin : nodePlugins) {
if (nodePlugin.handleNewMultiArray(graphBuilderContext, elementType, dimensions)) {
replacedNode = graphBuilderContext.pushedNode;
break;
}
}
}
}
return super.canonicalizeFixedNode(methodScope, replacedNode);
}
Aggregations