Skip to content

Commit

Permalink
mark NodeClass and LIRInstructionClass constructors as hosted-only
Browse files Browse the repository at this point in the history
  • Loading branch information
dougxc committed Nov 23, 2024
1 parent f11bd20 commit eaf37ca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
import jdk.graal.compiler.nodeinfo.NodeSize;
import jdk.graal.compiler.nodeinfo.Verbosity;
import jdk.internal.misc.Unsafe;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;

/**
* Metadata for every {@link Node} type. The metadata includes:
Expand Down Expand Up @@ -109,6 +111,7 @@ private static <T extends Annotation> T getAnnotationTimed(AnnotatedElement e, C
/**
* Gets the {@link NodeClass} associated with a given {@link Class}.
*/
@Platforms(Platform.HOSTED_ONLY.class)
public static <T> NodeClass<T> create(Class<T> c) {
assert getUnchecked(c) == null;
Class<? super T> superclass = c.getSuperclass();
Expand All @@ -120,6 +123,7 @@ public static <T> NodeClass<T> create(Class<T> c) {
}

@SuppressWarnings("unchecked")
@Platforms(Platform.HOSTED_ONLY.class)
private static <T> NodeClass<T> getUnchecked(Class<T> clazz) {
try {
Field field = clazz.getDeclaredField("TYPE");
Expand All @@ -130,6 +134,7 @@ private static <T> NodeClass<T> getUnchecked(Class<T> clazz) {
}
}

@Platforms(Platform.HOSTED_ONLY.class)
public static <T> NodeClass<T> get(Class<T> clazz) {
NodeClass<T> result = getUnchecked(clazz);
if (result == null && clazz != NODE_CLASS) {
Expand Down Expand Up @@ -169,12 +174,14 @@ public static <T> NodeClass<T> get(Class<T> clazz) {

private final int leafId;

@Platforms(Platform.HOSTED_ONLY.class)
public NodeClass(Class<T> clazz, NodeClass<? super T> superNodeClass) {
this(clazz, superNodeClass, new FieldsScanner.DefaultCalcOffset(), null, 0);
}

@SuppressWarnings("try")
public NodeClass(Class<T> clazz, NodeClass<? super T> superNodeClass, FieldsScanner.CalcOffset calcOffset, int[] presetIterableIds, int presetIterableId) {
@Platforms(Platform.HOSTED_ONLY.class)
private NodeClass(Class<T> clazz, NodeClass<? super T> superNodeClass, FieldsScanner.CalcOffset calcOffset, int[] presetIterableIds, int presetIterableId) {
super(clazz);
DebugContext debug = DebugContext.forCurrentThread();
this.superNodeClass = superNodeClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@
import jdk.graal.compiler.lir.StandardOp.ValueMoveOp;
import jdk.vm.ci.code.BytecodeFrame;
import jdk.vm.ci.meta.Value;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;

public class LIRInstructionClass<T> extends LIRIntrospection<T> {

@Platforms(Platform.HOSTED_ONLY.class)
public static <T extends LIRInstruction> LIRInstructionClass<T> create(Class<T> c) {
return new LIRInstructionClass<>(c);
}
Expand All @@ -63,10 +66,12 @@ public static <T extends LIRInstruction> LIRInstructionClass<T> create(Class<T>
private String opcodeConstant;
private int opcodeIndex;

@Platforms(Platform.HOSTED_ONLY.class)
private LIRInstructionClass(Class<T> clazz) {
this(clazz, new FieldsScanner.DefaultCalcOffset());
}

@Platforms(Platform.HOSTED_ONLY.class)
public LIRInstructionClass(Class<T> clazz, FieldsScanner.CalcOffset calcOffset) {
super(clazz);
assert INSTRUCTION_CLASS.isAssignableFrom(clazz);
Expand Down Expand Up @@ -95,6 +100,7 @@ public LIRInstructionClass(Class<T> clazz, FieldsScanner.CalcOffset calcOffset)
}

@SuppressWarnings("unchecked")
@Platforms(Platform.HOSTED_ONLY.class)
public static <T> LIRInstructionClass<T> get(Class<T> clazz) {
try {
Field field = clazz.getDeclaredField("TYPE");
Expand Down

0 comments on commit eaf37ca

Please sign in to comment.