Skip to content

Commit

Permalink
[GR-60367] Backport to 24.2: Bytecode DSL compiler intrinsics are not…
Browse files Browse the repository at this point in the history
… compatible with older Truffle versions.

PullRequest: graal/19568
  • Loading branch information
DSouzaM authored and ansalond committed Dec 20, 2024
2 parents 1d80be5 + 8259f78 commit 79d661f
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ public static void registerFrameWithoutBoxingPlugins(InvocationPlugins plugins,
registerFrameAccessors(r, types, JavaKind.Byte);

int accessTag = types.FrameSlotKind_javaKindToTagIndex.get(JavaKind.Object);
registerGet(r, JavaKind.Object, accessTag, "unsafeUncheckedGet", JavaKind.Object.name());
registerGet(r, JavaKind.Object, accessTag, "unsafeUncheckedGet" + JavaKind.Object.name(), true);

registerOSRFrameTransferMethods(r);

Expand Down Expand Up @@ -621,11 +621,10 @@ private static void registerFrameAccessors(Registration r, KnownTruffleTypes typ
int accessTag = types.FrameSlotKind_javaKindToTagIndex.get(accessKind);
String nameSuffix = accessKind.name();
boolean isPrimitiveAccess = accessKind.isPrimitive();
String[] indexedGetPrefixes = new String[]{"get", "unsafeGet", "expect", "unsafeExpect"};
for (String prefix : indexedGetPrefixes) {
registerGet(r, accessKind, accessTag, prefix, nameSuffix);
registerGet(r, accessKind, accessTag, "get" + nameSuffix, false);
for (String prefix : new String[]{"unsafeGet", "expect", "unsafeExpect"}) {
registerGet(r, accessKind, accessTag, prefix + nameSuffix, true);
}

r.register(new RequiredInvocationPlugin("get" + nameSuffix + "Static", Receiver.class, int.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver frameNode, ValueNode frameSlotNode) {
Expand All @@ -639,20 +638,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec
}
});

String[] indexedSetPrefixes = new String[]{"set", "unsafeSet"};
for (String prefix : indexedSetPrefixes) {
r.register(new RequiredInvocationPlugin(prefix + nameSuffix, Receiver.class, int.class, getJavaClass(accessKind)) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver frameNode, ValueNode frameSlotNode, ValueNode value) {
int frameSlotIndex = maybeGetConstantNumberedFrameSlotIndex(frameNode, frameSlotNode);
if (frameSlotIndex >= 0) {
b.add(new VirtualFrameSetNode(frameNode, frameSlotIndex, accessTag, value, VirtualFrameAccessType.Indexed, VirtualFrameAccessFlags.NON_STATIC_UPDATE));
return true;
}
return false;
}
});
}
registerSet(r, accessKind, accessTag, "set" + nameSuffix, false);
registerSet(r, accessKind, accessTag, "unsafeSet" + nameSuffix, true);
r.register(new RequiredInvocationPlugin("set" + nameSuffix + "Static", Receiver.class, int.class, getJavaClass(accessKind)) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver frameNode, ValueNode frameSlotNode, ValueNode value) {
Expand All @@ -678,8 +665,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec
});
}

private static void registerGet(Registration r, JavaKind accessKind, int accessTag, String prefix, String nameSuffix) {
r.register(new RequiredInvocationPlugin(prefix + nameSuffix, Receiver.class, int.class) {
private static void registerGet(Registration r, JavaKind accessKind, int accessTag, String name, boolean optional) {
r.register(new InvocationPlugin(name, Receiver.class, int.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver frameNode, ValueNode frameSlotNode) {
int frameSlotIndex = maybeGetConstantNumberedFrameSlotIndex(frameNode, frameSlotNode);
Expand All @@ -689,6 +676,70 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec
}
return false;
}

@Override
public boolean isOptional() {
return optional;
}
});
}

private static void registerSet(Registration r, JavaKind accessKind, int accessTag, String name, boolean optional) {
r.register(new InvocationPlugin(name, Receiver.class, int.class, getJavaClass(accessKind)) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver frameNode, ValueNode frameSlotNode, ValueNode value) {
int frameSlotIndex = maybeGetConstantNumberedFrameSlotIndex(frameNode, frameSlotNode);
if (frameSlotIndex >= 0) {
b.add(new VirtualFrameSetNode(frameNode, frameSlotIndex, accessTag, value, VirtualFrameAccessType.Indexed, VirtualFrameAccessFlags.NON_STATIC_UPDATE));
return true;
}
return false;
}

@Override
public boolean isOptional() {
return optional;
}
});
}

private static void registerCopy(Registration r, String name, boolean optional) {
r.register(new InvocationPlugin(name, Receiver.class, int.class, int.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode frameSlot1, ValueNode frameSlot2) {
int frameSlot1Index = maybeGetConstantNumberedFrameSlotIndex(receiver, frameSlot1);
int frameSlot2Index = maybeGetConstantNumberedFrameSlotIndex(receiver, frameSlot2);
if (frameSlot1Index >= 0 && frameSlot2Index >= 0) {
b.add(new VirtualFrameCopyNode(receiver, frameSlot1Index, frameSlot2Index, VirtualFrameAccessType.Indexed, VirtualFrameAccessFlags.NON_STATIC_UPDATE));
return true;
}
return false;
}

@Override
public boolean isOptional() {
return optional;
}
});
}

private static void registerClear(Registration r, String name, int illegalTag, boolean optional) {
r.register(new InvocationPlugin(name, Receiver.class, int.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode frameSlot) {
int frameSlotIndex = maybeGetConstantNumberedFrameSlotIndex(receiver, frameSlot);
if (frameSlotIndex >= 0) {
b.add(new VirtualFrameClearNode(receiver, frameSlotIndex, illegalTag, VirtualFrameAccessType.Indexed,
VirtualFrameAccessFlags.NON_STATIC_UPDATE));
return true;
}
return false;
}

@Override
public boolean isOptional() {
return optional;
}
});
}

Expand Down Expand Up @@ -814,34 +865,10 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec
}
});

for (String prefix : new String[]{"", "unsafe"}) {
r.register(new RequiredInvocationPlugin(buildCamelCaseName(prefix, "copy"), Receiver.class, int.class, int.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode frameSlot1, ValueNode frameSlot2) {
int frameSlot1Index = maybeGetConstantNumberedFrameSlotIndex(receiver, frameSlot1);
int frameSlot2Index = maybeGetConstantNumberedFrameSlotIndex(receiver, frameSlot2);
if (frameSlot1Index >= 0 && frameSlot2Index >= 0) {
b.add(new VirtualFrameCopyNode(receiver, frameSlot1Index, frameSlot2Index, VirtualFrameAccessType.Indexed, VirtualFrameAccessFlags.NON_STATIC_UPDATE));
return true;
}
return false;
}
});

r.register(new RequiredInvocationPlugin(buildCamelCaseName(prefix, "clear"), Receiver.class, int.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode frameSlot) {
int frameSlotIndex = maybeGetConstantNumberedFrameSlotIndex(receiver, frameSlot);
if (frameSlotIndex >= 0) {
b.add(new VirtualFrameClearNode(receiver, frameSlotIndex, illegalTag, VirtualFrameAccessType.Indexed,
VirtualFrameAccessFlags.NON_STATIC_UPDATE));
return true;
}
return false;
}
});

}
registerCopy(r, "copy", false);
registerCopy(r, "unsafeCopy", true);
registerClear(r, "clear", illegalTag, false);
registerClear(r, "unsafeClear", illegalTag, true);

r.register(new RequiredInvocationPlugin("clearPrimitiveStatic", Receiver.class, int.class) {
@Override
Expand Down Expand Up @@ -968,21 +995,6 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec
});
}

private static String buildCamelCaseName(String prefix, String name) {
if (prefix.isEmpty()) {
return name;
} else {
return prefix + firstLetterUpperCase(name);
}
}

private static String firstLetterUpperCase(String name) {
if (name == null || name.isEmpty()) {
return name;
}
return Character.toUpperCase(name.charAt(0)) + name.substring(1, name.length());
}

public static void registerNodePlugins(InvocationPlugins plugins, KnownTruffleTypes types, MetaAccessProvider metaAccess, boolean canDelayIntrinsification,
ConstantReflectionProvider constantReflection) {
Registration r = new Registration(plugins, new ResolvedJavaSymbol(types.Node));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ private static void registerBytecodePlugins(InvocationPlugins plugins, Replaceme
plugins.registerIntrinsificationPredicate(t -> t.getName().equals("Lcom/oracle/truffle/api/bytecode/BytecodeDSLUncheckedAccess;"));
InvocationPlugins.Registration r = new InvocationPlugins.Registration(plugins, "com.oracle.truffle.api.bytecode.BytecodeDSLUncheckedAccess", replacements);

r.register(new InlineOnlyInvocationPlugin("uncheckedCast", Receiver.class, Object.class,
Class.class) {
r.register(new InvocationPlugin("uncheckedCast", Receiver.class, Object.class, Class.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver,
ValueNode object, ValueNode clazz) {
Expand All @@ -111,6 +110,16 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec
return true;
}
}

@Override
public boolean inlineOnly() {
return true;
}

@Override
public boolean isOptional() {
return true;
}
});
}

Expand Down

0 comments on commit 79d661f

Please sign in to comment.