use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.
the class BasicArrayCopyNode method virtualize.
@Override
public void virtualize(VirtualizerTool tool) {
ValueNode sourcePosition = tool.getAlias(getSourcePosition());
ValueNode destinationPosition = tool.getAlias(getDestinationPosition());
ValueNode replacedLength = tool.getAlias(getLength());
if (sourcePosition.isConstant() && destinationPosition.isConstant() && replacedLength.isConstant()) {
int srcPosInt = sourcePosition.asJavaConstant().asInt();
int destPosInt = destinationPosition.asJavaConstant().asInt();
int len = replacedLength.asJavaConstant().asInt();
ValueNode destAlias = tool.getAlias(getDestination());
if (destAlias instanceof VirtualArrayNode) {
VirtualArrayNode destVirtual = (VirtualArrayNode) destAlias;
if (len < 0 || !checkBounds(destPosInt, len, destVirtual)) {
return;
}
ValueNode srcAlias = tool.getAlias(getSource());
if (srcAlias instanceof VirtualObjectNode) {
if (!(srcAlias instanceof VirtualArrayNode)) {
return;
}
VirtualArrayNode srcVirtual = (VirtualArrayNode) srcAlias;
if (destVirtual.componentType().getJavaKind() != srcVirtual.componentType().getJavaKind()) {
return;
}
if (!checkBounds(srcPosInt, len, srcVirtual)) {
return;
}
if (!checkEntryTypes(srcPosInt, len, srcVirtual, destVirtual.type().getComponentType(), tool)) {
return;
}
for (int i = 0; i < len; i++) {
tool.setVirtualEntry(destVirtual, destPosInt + i, tool.getEntry(srcVirtual, srcPosInt + i));
}
tool.delete();
DebugContext debug = getDebug();
if (debug.isLogEnabled()) {
debug.log("virtualized arraycopy(%s, %d, %s, %d, %d)", getSource(), srcPosInt, getDestination(), destPosInt, len);
}
} else {
ResolvedJavaType sourceType = StampTool.typeOrNull(srcAlias);
if (sourceType == null || !sourceType.isArray()) {
return;
}
ResolvedJavaType sourceComponentType = sourceType.getComponentType();
ResolvedJavaType destComponentType = destVirtual.type().getComponentType();
if (!sourceComponentType.equals(destComponentType)) {
return;
}
for (int i = 0; i < len; i++) {
LoadIndexedNode load = new LoadIndexedNode(graph().getAssumptions(), srcAlias, ConstantNode.forInt(i + srcPosInt, graph()), destComponentType.getJavaKind());
tool.addNode(load);
tool.setVirtualEntry(destVirtual, destPosInt + i, load);
}
tool.delete();
}
}
}
}
use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.
the class BasicObjectCloneNode method virtualize.
@Override
public void virtualize(VirtualizerTool tool) {
ValueNode originalAlias = tool.getAlias(getObject());
if (originalAlias instanceof VirtualObjectNode) {
VirtualObjectNode originalVirtual = (VirtualObjectNode) originalAlias;
if (originalVirtual.type().isCloneableWithAllocation()) {
ValueNode[] newEntryState = new ValueNode[originalVirtual.entryCount()];
for (int i = 0; i < newEntryState.length; i++) {
newEntryState[i] = tool.getEntry(originalVirtual, i);
}
VirtualObjectNode newVirtual = originalVirtual.duplicate();
tool.createVirtualObject(newVirtual, newEntryState, Collections.<MonitorIdNode>emptyList(), false);
tool.replaceWithVirtual(newVirtual);
}
} else {
ResolvedJavaType type = getConcreteType(originalAlias.stamp(NodeView.DEFAULT));
if (type != null && !type.isArray()) {
VirtualInstanceNode newVirtual = createVirtualInstanceNode(type, true);
ResolvedJavaField[] fields = newVirtual.getFields();
ValueNode[] state = new ValueNode[fields.length];
final LoadFieldNode[] loads = new LoadFieldNode[fields.length];
for (int i = 0; i < fields.length; i++) {
state[i] = loads[i] = genLoadFieldNode(graph().getAssumptions(), originalAlias, fields[i]);
tool.addNode(loads[i]);
}
tool.createVirtualObject(newVirtual, state, Collections.<MonitorIdNode>emptyList(), false);
tool.replaceWithVirtual(newVirtual);
}
}
}
use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.
the class UncheckedInterfaceProviderTest method test.
@Test
public void test() {
StructuredGraph graph = parseEager("snippet", StructuredGraph.AllowAssumptions.YES);
for (BlackholeNode b : graph.getNodes().filter(BlackholeNode.class)) {
Assert.assertThat(b.getValue(), is(instanceOf(UncheckedInterfaceProvider.class)));
Stamp uncheckedStamp = ((UncheckedInterfaceProvider) b.getValue()).uncheckedStamp();
String context = b.getValue().toString(Verbosity.Debugger);
Assert.assertNotNull(context, uncheckedStamp);
ResolvedJavaType uncheckedType = StampTool.typeOrNull(uncheckedStamp);
ResolvedJavaType type = StampTool.typeOrNull(b.getValue());
Assert.assertEquals(context, arrayDepth(type), arrayDepth(uncheckedType));
Assert.assertTrue(context + ": " + type, type == null || type.getElementalType().isJavaLangObject());
Assert.assertNotNull(context, uncheckedType);
Assert.assertTrue(context, uncheckedType.getElementalType().isInterface());
}
}
use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.
the class UncheckedInterfaceProviderTest method arrayDepth.
private static int arrayDepth(ResolvedJavaType type) {
int depth = 0;
ResolvedJavaType t = type;
while (t != null && t.isArray()) {
depth += 1;
t = t.getComponentType();
}
return depth;
}
use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.
the class MarkUnsafeAccessTest method testCompiled.
@Test
public void testCompiled() throws IOException {
ResolvedJavaMethod getMethod = asResolvedJavaMethod(getMethod(ByteBuffer.class, "get", new Class<?>[] {}));
ResolvedJavaType mbbClass = getMetaAccess().lookupJavaType(MappedByteBuffer.class);
ResolvedJavaMethod getMethodImpl = mbbClass.findUniqueConcreteMethod(getMethod).getResult();
Assert.assertNotNull(getMethodImpl);
StructuredGraph graph = parseForCompile(getMethodImpl);
HighTierContext highContext = getDefaultHighTierContext();
new CanonicalizerPhase().apply(graph, highContext);
new InliningPhase(new InlineEverythingPolicy(), new CanonicalizerPhase()).apply(graph, highContext);
InstalledCode compiledCode = getCode(getMethodImpl, graph);
testMappedByteBuffer(mbb -> {
try {
return (byte) compiledCode.executeVarargs(mbb);
} catch (InvalidInstalledCodeException e) {
Assert.fail();
return 0;
}
});
}
Aggregations