use of jdk.vm.ci.meta.ResolvedJavaField in project graal by oracle.
the class UnsafeAccessNode method canonical.
@Override
public Node canonical(CanonicalizerTool tool) {
if (!isAnyLocationForced() && getLocationIdentity().isAny()) {
if (offset().isConstant()) {
long constantOffset = offset().asJavaConstant().asLong();
// Try to canonicalize to a field access.
ResolvedJavaType receiverType = StampTool.typeOrNull(object());
if (receiverType != null) {
ResolvedJavaField field = receiverType.findInstanceFieldWithOffset(constantOffset, accessKind());
// never a valid access of an arbitrary address.
if (field != null && field.getJavaKind() == this.accessKind()) {
assert !graph().isAfterFloatingReadPhase() : "cannot add more precise memory location after floating read phase";
return cloneAsFieldAccess(graph().getAssumptions(), field);
}
}
}
ResolvedJavaType receiverType = StampTool.typeOrNull(object());
// Try to build a better location identity.
if (receiverType != null && receiverType.isArray()) {
LocationIdentity identity = NamedLocationIdentity.getArrayLocation(receiverType.getComponentType().getJavaKind());
assert !graph().isAfterFloatingReadPhase() : "cannot add more precise memory location after floating read phase";
return cloneAsArrayAccess(offset(), identity);
}
}
return this;
}
use of jdk.vm.ci.meta.ResolvedJavaField in project graal by oracle.
the class NewFrameNode method virtualize.
@Override
public void virtualize(VirtualizerTool tool) {
ResolvedJavaType frameType = stamp(NodeView.DEFAULT).javaType(tool.getMetaAccessProvider());
ResolvedJavaField[] frameFields = frameType.getInstanceFields(true);
ResolvedJavaField descriptorField = findField(frameFields, "descriptor");
ResolvedJavaField argumentsField = findField(frameFields, "arguments");
ResolvedJavaField localsField = findField(frameFields, "locals");
ResolvedJavaField primitiveLocalsField = findField(frameFields, "primitiveLocals");
ResolvedJavaField tagsField = findField(frameFields, "tags");
ValueNode[] objectArrayEntryState = new ValueNode[frameSize];
ValueNode[] primitiveArrayEntryState = new ValueNode[frameSize];
ValueNode[] tagArrayEntryState = new ValueNode[frameSize];
if (frameSize > 0) {
Arrays.fill(objectArrayEntryState, frameDefaultValue);
if (virtualFrameTagArray != null) {
Arrays.fill(tagArrayEntryState, smallIntConstants.get(0));
}
if (virtualFramePrimitiveArray != null) {
for (int i = 0; i < frameSize; i++) {
JavaKind kind = frameSlotKinds[i];
if (kind == null) {
kind = JavaKind.Int;
}
primitiveArrayEntryState[i] = ConstantNode.defaultForKind(kind, graph());
}
}
}
tool.createVirtualObject(virtualFrameObjectArray, objectArrayEntryState, Collections.<MonitorIdNode>emptyList(), false);
if (virtualFramePrimitiveArray != null) {
tool.createVirtualObject(virtualFramePrimitiveArray, primitiveArrayEntryState, Collections.<MonitorIdNode>emptyList(), false);
}
if (virtualFrameTagArray != null) {
tool.createVirtualObject(virtualFrameTagArray, tagArrayEntryState, Collections.<MonitorIdNode>emptyList(), false);
}
assert frameFields.length == 5 || frameFields.length == 3;
ValueNode[] frameEntryState = new ValueNode[frameFields.length];
List<ResolvedJavaField> frameFieldList = Arrays.asList(frameFields);
frameEntryState[frameFieldList.indexOf(descriptorField)] = getDescriptor();
frameEntryState[frameFieldList.indexOf(argumentsField)] = getArguments();
frameEntryState[frameFieldList.indexOf(localsField)] = virtualFrameObjectArray;
if (primitiveLocalsField != null) {
frameEntryState[frameFieldList.indexOf(primitiveLocalsField)] = virtualFramePrimitiveArray;
}
if (tagsField != null) {
frameEntryState[frameFieldList.indexOf(tagsField)] = virtualFrameTagArray;
}
/*
* The new frame is created with "ensureVirtualized" enabled, so that it cannot be
* materialized. This can only be lifted by a AllowMaterializeNode, which corresponds to a
* frame.materialize() call.
*/
tool.createVirtualObject(virtualFrame, frameEntryState, Collections.<MonitorIdNode>emptyList(), true);
tool.replaceWithVirtual(virtualFrame);
}
use of jdk.vm.ci.meta.ResolvedJavaField in project graal by oracle.
the class ObjectCloneNode method getLoweredSnippetGraph.
@Override
@SuppressWarnings("try")
protected StructuredGraph getLoweredSnippetGraph(LoweringTool tool) {
ResolvedJavaType type = StampTool.typeOrNull(getObject());
if (type != null) {
if (type.isArray()) {
Method method = ObjectCloneSnippets.arrayCloneMethods.get(type.getComponentType().getJavaKind());
if (method != null) {
final ResolvedJavaMethod snippetMethod = tool.getMetaAccess().lookupJavaMethod(method);
final Replacements replacements = tool.getReplacements();
StructuredGraph snippetGraph = null;
DebugContext debug = getDebug();
try (DebugContext.Scope s = debug.scope("ArrayCloneSnippet", snippetMethod)) {
snippetGraph = replacements.getSnippet(snippetMethod, null, graph().trackNodeSourcePosition(), this.getNodeSourcePosition());
} catch (Throwable e) {
throw debug.handle(e);
}
assert snippetGraph != null : "ObjectCloneSnippets should be installed";
assert getConcreteType(stamp(NodeView.DEFAULT)) != null;
return lowerReplacement((StructuredGraph) snippetGraph.copy(getDebug()), tool);
}
assert false : "unhandled array type " + type.getComponentType().getJavaKind();
} else {
Assumptions assumptions = graph().getAssumptions();
type = getConcreteType(getObject().stamp(NodeView.DEFAULT));
if (type != null) {
StructuredGraph newGraph = new StructuredGraph.Builder(graph().getOptions(), graph().getDebug(), AllowAssumptions.ifNonNull(assumptions)).build();
ParameterNode param = newGraph.addWithoutUnique(new ParameterNode(0, StampPair.createSingle(getObject().stamp(NodeView.DEFAULT))));
NewInstanceNode newInstance = newGraph.add(new NewInstanceNode(type, true));
newGraph.addAfterFixed(newGraph.start(), newInstance);
ReturnNode returnNode = newGraph.add(new ReturnNode(newInstance));
newGraph.addAfterFixed(newInstance, returnNode);
for (ResolvedJavaField field : type.getInstanceFields(true)) {
LoadFieldNode load = newGraph.add(LoadFieldNode.create(newGraph.getAssumptions(), param, field));
newGraph.addBeforeFixed(returnNode, load);
newGraph.addBeforeFixed(returnNode, newGraph.add(new StoreFieldNode(newInstance, field, load)));
}
assert getConcreteType(stamp(NodeView.DEFAULT)) != null;
return lowerReplacement(newGraph, tool);
}
}
}
assert getConcreteType(stamp(NodeView.DEFAULT)) == null;
return null;
}
use of jdk.vm.ci.meta.ResolvedJavaField 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.ResolvedJavaField 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);
}
}
}
Aggregations