use of jdk.vm.ci.meta.JavaKind in project graal by oracle.
the class DefaultHotSpotLoweringProvider method lowerInvoke.
private void lowerInvoke(Invoke invoke, LoweringTool tool, StructuredGraph graph) {
if (invoke.callTarget() instanceof MethodCallTargetNode) {
MethodCallTargetNode callTarget = (MethodCallTargetNode) invoke.callTarget();
NodeInputList<ValueNode> parameters = callTarget.arguments();
ValueNode receiver = parameters.size() <= 0 ? null : parameters.get(0);
if (!callTarget.isStatic() && receiver.stamp(NodeView.DEFAULT) instanceof ObjectStamp && !StampTool.isPointerNonNull(receiver)) {
ValueNode nonNullReceiver = createNullCheckedValue(receiver, invoke.asNode(), tool);
parameters.set(0, nonNullReceiver);
receiver = nonNullReceiver;
}
JavaType[] signature = callTarget.targetMethod().getSignature().toParameterTypes(callTarget.isStatic() ? null : callTarget.targetMethod().getDeclaringClass());
LoweredCallTargetNode loweredCallTarget = null;
OptionValues options = graph.getOptions();
if (InlineVTableStubs.getValue(options) && callTarget.invokeKind().isIndirect() && (AlwaysInlineVTableStubs.getValue(options) || invoke.isPolymorphic())) {
HotSpotResolvedJavaMethod hsMethod = (HotSpotResolvedJavaMethod) callTarget.targetMethod();
ResolvedJavaType receiverType = invoke.getReceiverType();
if (hsMethod.isInVirtualMethodTable(receiverType)) {
JavaKind wordKind = runtime.getTarget().wordJavaKind;
ValueNode hub = createReadHub(graph, receiver, tool);
ReadNode metaspaceMethod = createReadVirtualMethod(graph, hub, hsMethod, receiverType);
// We use LocationNode.ANY_LOCATION for the reads that access the
// compiled code entry as HotSpot does not guarantee they are final
// values.
int methodCompiledEntryOffset = runtime.getVMConfig().methodCompiledEntryOffset;
AddressNode address = createOffsetAddress(graph, metaspaceMethod, methodCompiledEntryOffset);
ReadNode compiledEntry = graph.add(new ReadNode(address, any(), StampFactory.forKind(wordKind), BarrierType.NONE));
loweredCallTarget = graph.add(new HotSpotIndirectCallTargetNode(metaspaceMethod, compiledEntry, parameters.toArray(new ValueNode[parameters.size()]), callTarget.returnStamp(), signature, callTarget.targetMethod(), HotSpotCallingConventionType.JavaCall, callTarget.invokeKind()));
graph.addBeforeFixed(invoke.asNode(), metaspaceMethod);
graph.addAfterFixed(metaspaceMethod, compiledEntry);
}
}
if (loweredCallTarget == null) {
loweredCallTarget = graph.add(new HotSpotDirectCallTargetNode(parameters.toArray(new ValueNode[parameters.size()]), callTarget.returnStamp(), signature, callTarget.targetMethod(), HotSpotCallingConventionType.JavaCall, callTarget.invokeKind()));
}
callTarget.replaceAndDelete(loweredCallTarget);
}
}
use of jdk.vm.ci.meta.JavaKind in project graal by oracle.
the class WordOperationPlugin method processWordOperation.
protected void processWordOperation(GraphBuilderContext b, ValueNode[] args, ResolvedJavaMethod wordMethod) throws GraalError {
JavaKind returnKind = wordMethod.getSignature().getReturnKind();
WordFactory.FactoryOperation factoryOperation = BridgeMethodUtils.getAnnotation(WordFactory.FactoryOperation.class, wordMethod);
if (factoryOperation != null) {
switch(factoryOperation.opcode()) {
case ZERO:
assert args.length == 0;
b.addPush(returnKind, forIntegerKind(wordKind, 0L));
return;
case FROM_UNSIGNED:
assert args.length == 1;
b.push(returnKind, fromUnsigned(b, args[0]));
return;
case FROM_SIGNED:
assert args.length == 1;
b.push(returnKind, fromSigned(b, args[0]));
return;
}
}
Word.Operation operation = BridgeMethodUtils.getAnnotation(Word.Operation.class, wordMethod);
if (operation == null) {
throw bailout(b, "Cannot call method on a word value: " + wordMethod.format("%H.%n(%p)"));
}
switch(operation.opcode()) {
case NODE_CLASS:
assert args.length == 2;
ValueNode left = args[0];
ValueNode right = operation.rightOperandIsInt() ? toUnsigned(b, args[1], JavaKind.Int) : fromSigned(b, args[1]);
b.addPush(returnKind, createBinaryNodeInstance(operation.node(), left, right));
break;
case COMPARISON:
assert args.length == 2;
b.push(returnKind, comparisonOp(b, operation.condition(), args[0], fromSigned(b, args[1])));
break;
case IS_NULL:
assert args.length == 1;
b.push(returnKind, comparisonOp(b, Condition.EQ, args[0], ConstantNode.forIntegerKind(wordKind, 0L)));
break;
case IS_NON_NULL:
assert args.length == 1;
b.push(returnKind, comparisonOp(b, Condition.NE, args[0], ConstantNode.forIntegerKind(wordKind, 0L)));
break;
case NOT:
assert args.length == 1;
b.addPush(returnKind, new XorNode(args[0], b.add(forIntegerKind(wordKind, -1))));
break;
case READ_POINTER:
case READ_OBJECT:
case READ_BARRIERED:
{
assert args.length == 2 || args.length == 3;
JavaKind readKind = wordTypes.asKind(wordMethod.getSignature().getReturnType(wordMethod.getDeclaringClass()));
AddressNode address = makeAddress(b, args[0], args[1]);
LocationIdentity location;
if (args.length == 2) {
location = any();
} else {
assert args[2].isConstant();
location = snippetReflection.asObject(LocationIdentity.class, args[2].asJavaConstant());
}
b.push(returnKind, readOp(b, readKind, address, location, operation.opcode()));
break;
}
case READ_HEAP:
{
assert args.length == 3;
JavaKind readKind = wordTypes.asKind(wordMethod.getSignature().getReturnType(wordMethod.getDeclaringClass()));
AddressNode address = makeAddress(b, args[0], args[1]);
BarrierType barrierType = snippetReflection.asObject(BarrierType.class, args[2].asJavaConstant());
b.push(returnKind, readOp(b, readKind, address, any(), barrierType, true));
break;
}
case WRITE_POINTER:
case WRITE_OBJECT:
case WRITE_BARRIERED:
case INITIALIZE:
{
assert args.length == 3 || args.length == 4;
JavaKind writeKind = wordTypes.asKind(wordMethod.getSignature().getParameterType(wordMethod.isStatic() ? 2 : 1, wordMethod.getDeclaringClass()));
AddressNode address = makeAddress(b, args[0], args[1]);
LocationIdentity location;
if (args.length == 3) {
location = any();
} else {
assert args[3].isConstant();
location = snippetReflection.asObject(LocationIdentity.class, args[3].asJavaConstant());
}
writeOp(b, writeKind, address, location, args[2], operation.opcode());
break;
}
case TO_RAW_VALUE:
assert args.length == 1;
b.push(returnKind, toUnsigned(b, args[0], JavaKind.Long));
break;
case OBJECT_TO_TRACKED:
assert args.length == 1;
WordCastNode objectToTracked = b.add(WordCastNode.objectToTrackedPointer(args[0], wordKind));
b.push(returnKind, objectToTracked);
break;
case OBJECT_TO_UNTRACKED:
assert args.length == 1;
WordCastNode objectToUntracked = b.add(WordCastNode.objectToUntrackedPointer(args[0], wordKind));
b.push(returnKind, objectToUntracked);
break;
case FROM_ADDRESS:
assert args.length == 1;
WordCastNode addressToWord = b.add(WordCastNode.addressToWord(args[0], wordKind));
b.push(returnKind, addressToWord);
break;
case TO_OBJECT:
assert args.length == 1;
WordCastNode wordToObject = b.add(WordCastNode.wordToObject(args[0], wordKind));
b.push(returnKind, wordToObject);
break;
case TO_OBJECT_NON_NULL:
assert args.length == 1;
WordCastNode wordToObjectNonNull = b.add(WordCastNode.wordToObjectNonNull(args[0], wordKind));
b.push(returnKind, wordToObjectNonNull);
break;
case CAS_POINTER:
assert args.length == 5;
AddressNode address = makeAddress(b, args[0], args[1]);
JavaKind valueKind = wordTypes.asKind(wordMethod.getSignature().getParameterType(1, wordMethod.getDeclaringClass()));
assert valueKind.equals(wordTypes.asKind(wordMethod.getSignature().getParameterType(2, wordMethod.getDeclaringClass()))) : wordMethod.getSignature();
assert args[4].isConstant() : Arrays.toString(args);
LocationIdentity location = snippetReflection.asObject(LocationIdentity.class, args[4].asJavaConstant());
JavaType returnType = wordMethod.getSignature().getReturnType(wordMethod.getDeclaringClass());
b.addPush(returnKind, casOp(valueKind, wordTypes.asKind(returnType), address, location, args[2], args[3]));
break;
default:
throw new GraalError("Unknown opcode: %s", operation.opcode());
}
}
use of jdk.vm.ci.meta.JavaKind in project graal by oracle.
the class HotSpotWordOperationPlugin method processHotSpotWordOperation.
protected void processHotSpotWordOperation(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args, HotSpotOperation operation) {
JavaKind returnKind = method.getSignature().getReturnKind();
switch(operation.opcode()) {
case POINTER_EQ:
case POINTER_NE:
assert args.length == 2;
HotspotOpcode opcode = operation.opcode();
ValueNode left = args[0];
ValueNode right = args[1];
assert left.stamp(NodeView.DEFAULT) instanceof MetaspacePointerStamp : left + " " + left.stamp(NodeView.DEFAULT);
assert right.stamp(NodeView.DEFAULT) instanceof MetaspacePointerStamp : right + " " + right.stamp(NodeView.DEFAULT);
assert opcode == POINTER_EQ || opcode == POINTER_NE;
PointerEqualsNode comparison = b.add(new PointerEqualsNode(left, right));
ValueNode eqValue = b.add(forBoolean(opcode == POINTER_EQ));
ValueNode neValue = b.add(forBoolean(opcode == POINTER_NE));
b.addPush(returnKind, ConditionalNode.create(comparison, eqValue, neValue, NodeView.DEFAULT));
break;
case IS_NULL:
assert args.length == 1;
ValueNode pointer = args[0];
assert pointer.stamp(NodeView.DEFAULT) instanceof MetaspacePointerStamp;
LogicNode isNull = b.addWithInputs(IsNullNode.create(pointer));
b.addPush(returnKind, ConditionalNode.create(isNull, b.add(forBoolean(true)), b.add(forBoolean(false)), NodeView.DEFAULT));
break;
case FROM_POINTER:
assert args.length == 1;
b.addPush(returnKind, new PointerCastNode(StampFactory.forKind(wordKind), args[0]));
break;
case TO_KLASS_POINTER:
assert args.length == 1;
b.addPush(returnKind, new PointerCastNode(KlassPointerStamp.klass(), args[0]));
break;
case TO_METHOD_POINTER:
assert args.length == 1;
b.addPush(returnKind, new PointerCastNode(MethodPointerStamp.method(), args[0]));
break;
case READ_KLASS_POINTER:
assert args.length == 2 || args.length == 3;
Stamp readStamp = KlassPointerStamp.klass();
AddressNode address = makeAddress(b, args[0], args[1]);
LocationIdentity location;
if (args.length == 2) {
location = any();
} else {
assert args[2].isConstant();
location = snippetReflection.asObject(LocationIdentity.class, args[2].asJavaConstant());
}
ReadNode read = b.add(new ReadNode(address, location, readStamp, BarrierType.NONE));
b.push(returnKind, read);
break;
default:
throw GraalError.shouldNotReachHere("unknown operation: " + operation.opcode());
}
}
use of jdk.vm.ci.meta.JavaKind in project graal by oracle.
the class AMD64GraphBuilderPlugins method registerUnsafePlugins.
private static void registerUnsafePlugins(InvocationPlugins plugins, BytecodeProvider replacementsBytecodeProvider) {
Registration r;
if (Java8OrEarlier) {
r = new Registration(plugins, Unsafe.class);
} else {
r = new Registration(plugins, "jdk.internal.misc.Unsafe", replacementsBytecodeProvider);
}
for (JavaKind kind : new JavaKind[] { JavaKind.Int, JavaKind.Long, JavaKind.Object }) {
Class<?> javaClass = kind == JavaKind.Object ? Object.class : kind.toJavaClass();
r.register4("getAndSet" + kind.name(), Receiver.class, Object.class, long.class, javaClass, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unsafe, ValueNode object, ValueNode offset, ValueNode value) {
// Emits a null-check for the otherwise unused receiver
unsafe.get();
b.addPush(kind, new AtomicReadAndWriteNode(object, offset, value, kind, LocationIdentity.any()));
b.getGraph().markUnsafeAccess();
return true;
}
});
if (kind != JavaKind.Object) {
r.register4("getAndAdd" + kind.name(), Receiver.class, Object.class, long.class, javaClass, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unsafe, ValueNode object, ValueNode offset, ValueNode delta) {
// Emits a null-check for the otherwise unused receiver
unsafe.get();
AddressNode address = b.add(new OffsetAddressNode(object, offset));
b.addPush(kind, new AtomicReadAndAddNode(address, delta, LocationIdentity.any()));
b.getGraph().markUnsafeAccess();
return true;
}
});
}
}
for (JavaKind kind : new JavaKind[] { JavaKind.Char, JavaKind.Short, JavaKind.Int, JavaKind.Long }) {
Class<?> javaClass = kind.toJavaClass();
r.registerOptional3("get" + kind.name() + "Unaligned", Receiver.class, Object.class, long.class, new UnsafeGetPlugin(kind, false));
r.registerOptional4("put" + kind.name() + "Unaligned", Receiver.class, Object.class, long.class, javaClass, new UnsafePutPlugin(kind, false));
}
}
use of jdk.vm.ci.meta.JavaKind in project graal by oracle.
the class CollectingObjectReferenceVisitor method verifyFrame.
private void verifyFrame(CompilationResult compilation, BytecodeFrame expectedFrame, FrameInfoQueryResult actualFrame, BitSet visitedVirtualObjects) {
assert (expectedFrame == null) == (actualFrame == null);
if (expectedFrame == null || !actualFrame.needLocalValues) {
return;
}
verifyFrame(compilation, expectedFrame.caller(), actualFrame.getCaller(), visitedVirtualObjects);
for (int i = 0; i < expectedFrame.values.length; i++) {
JavaValue expectedValue = expectedFrame.values[i];
if (i >= actualFrame.getValueInfos().length) {
assert ValueUtil.isIllegalJavaValue(expectedValue);
continue;
}
ValueInfo actualValue = actualFrame.getValueInfos()[i];
JavaKind expectedKind = FrameInfoEncoder.getFrameValueKind(expectedFrame, i);
assert expectedKind == actualValue.getKind();
verifyValue(compilation, expectedValue, actualValue, actualFrame, visitedVirtualObjects);
}
}
Aggregations