Skip to content

Commit

Permalink
[GR-60011] Delete CompositeValueClass.
Browse files Browse the repository at this point in the history
PullRequest: graal/19392
  • Loading branch information
dougxc committed Nov 23, 2024
2 parents bcd53e5 + eaf37ca commit 3b5860a
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public CompositeValue forEachComponent(LIRInstruction inst, OperandMode mode, In
protected void visitEachComponent(LIRInstruction inst, OperandMode mode, InstructionValueConsumer proc) {
proc.visitValue(inst, value, mode, flags);
}

@Override
public String toString() {
return String.valueOf(value);
}
}

private static class DummyValue extends Value {
Expand Down
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 @@ -48,7 +48,6 @@ public abstract class CompositeValue extends Value {

public CompositeValue(ValueKind<?> kind) {
super(kind);
assert CompositeValueClass.get(getClass()) != null;
}

/**
Expand All @@ -64,10 +63,11 @@ public CompositeValue(ValueKind<?> kind) {

protected abstract void visitEachComponent(LIRInstruction inst, LIRInstruction.OperandMode mode, InstructionValueConsumer proc);

/**
* Must be implemented by subclasses.
*/
@Override
public String toString() {
return CompositeValueClass.format(this);
}
public abstract String toString();

@Override
public int hashCode() {
Expand Down

This file was deleted.

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
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,10 @@ protected void visitEachComponent(LIRInstruction inst, LIRInstruction.OperandMod
proc.visitValue(inst, base, mode, flags);
proc.visitValue(inst, offset, mode, flags);
}

@Override
public String toString() {
return String.format("{base: %s, offset: %s} bitMemoryTransferSize: %s displacement: %s scaleFactor: %s addressingMode: %s",
base, offset, bitMemoryTransferSize, displacement, scaleFactor, addressingMode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class LibGraalCompilerSupport {

public final EconomicMap<Class<?>, Object> nodeClasses = ImageHeapMap.create();
public final EconomicMap<Class<?>, Object> instructionClasses = ImageHeapMap.create();
public final EconomicMap<Class<?>, Object> compositeValueClasses = ImageHeapMap.create();

protected EconomicMap<Class<?>, Object> basePhaseStatistics = ImageHeapMap.create();
protected EconomicMap<Class<?>, Object> lirPhaseStatistics = ImageHeapMap.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ public final class LibGraalFieldsOffsetsFeature implements InternalFeature {
private Class<?> lirInstructionClass;
private Class<?> lirInstructionClassClass;
private MethodHandle lirInstructionClassClassGetMethod;
private Class<?> compositeValueClass;
private Class<?> compositeValueClassClass;
private MethodHandle compositeValueClassClassGetMethod;

private static class FieldsOffsetsReplacement {
protected final Object fields;
Expand Down Expand Up @@ -128,8 +125,6 @@ public void duringSetup(DuringSetupAccess a) {
nodeClassClass = libGraalFeature.loadClassOrFail("jdk.graal.compiler.graph.NodeClass");
lirInstructionClass = libGraalFeature.loadClassOrFail("jdk.graal.compiler.lir.LIRInstruction");
lirInstructionClassClass = libGraalFeature.loadClassOrFail("jdk.graal.compiler.lir.LIRInstructionClass");
compositeValueClass = libGraalFeature.loadClassOrFail("jdk.graal.compiler.lir.CompositeValue");
compositeValueClassClass = libGraalFeature.loadClassOrFail("jdk.graal.compiler.lir.CompositeValueClass");
fieldIntrospectionClass = libGraalFeature.loadClassOrFail("jdk.graal.compiler.core.common.FieldIntrospection");
inputEdgesClass = libGraalFeature.loadClassOrFail("jdk.graal.compiler.graph.InputEdges");
successorEdgesClass = libGraalFeature.loadClassOrFail("jdk.graal.compiler.graph.SuccessorEdges");
Expand All @@ -151,7 +146,6 @@ public void duringSetup(DuringSetupAccess a) {
nodeClassClassComputeIterationMaskMethod = mhl.findStatic(nodeClassClass, "computeIterationMask", MethodType.methodType(long.class, edgesTypeClass, int.class, long[].class));

lirInstructionClassClassGetMethod = mhl.findStatic(lirInstructionClassClass, "get", MethodType.methodType(lirInstructionClassClass, Class.class));
compositeValueClassClassGetMethod = mhl.findStatic(compositeValueClassClass, "get", MethodType.methodType(compositeValueClassClass, Class.class));

fieldIntrospectionClassGetDataMethod = mhl.findVirtual(fieldIntrospectionClass, "getData", MethodType.methodType(fieldsClass));
fieldIntrospectionClassGetAllFieldsMethod = mhl.findVirtual(fieldIntrospectionClass, "getAllFields", MethodType.methodType(fieldsClass.arrayType()));
Expand Down Expand Up @@ -251,8 +245,6 @@ private void classReachabilityListener(DuringAnalysisAccess a, Class<?> newlyRea
registerClass(newlyReachableClass, LibGraalCompilerSupport.get().nodeClasses, this::getNodeClassFromNode, false, access);
} else if (!newlyReachableClass.equals(lirInstructionClass) && lirInstructionClass.isAssignableFrom(newlyReachableClass)) {
registerClass(newlyReachableClass, LibGraalCompilerSupport.get().instructionClasses, this::getLIRInstructionClassFromLIRInstruction, true, access);
} else if (!newlyReachableClass.equals(compositeValueClass) && compositeValueClass.isAssignableFrom(newlyReachableClass)) {
registerClass(newlyReachableClass, LibGraalCompilerSupport.get().compositeValueClasses, this::getCompositeValueClassFromCompositeValue, true, access);
}
}

Expand Down Expand Up @@ -486,15 +478,4 @@ private Object getLIRInstructionClassFromLIRInstruction(Class<?> clazz) {
throw VMError.shouldNotReachHere(e);
}
}

private Object getCompositeValueClassFromCompositeValue(Class<?> clazz) {
try {
assert compositeValueClass.isAssignableFrom(clazz);
Object nodeClassInstance = compositeValueClassClassGetMethod.invoke(clazz);
assert compositeValueClassClass.isInstance(nodeClassInstance);
return nodeClassInstance;
} catch (Throwable e) {
throw VMError.shouldNotReachHere(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -360,19 +360,6 @@ static final class Target_jdk_graal_compiler_lir_phases_LIRPhase_LIRPhaseStatist
@TargetClass(className = "jdk.graal.compiler.graph.NodeClass", classLoader = LibGraalClassLoaderSupplier.class, onlyWith = LibGraalFeature.IsEnabled.class)
static final class Target_jdk_graal_compiler_graph_NodeClass {

/*
* Redirect method to image build-time pre-computed nodeClasses map in
* LibGraalCompilerSupport.
*/
@Substitute
public static Target_jdk_graal_compiler_graph_NodeClass get(Class<?> clazz) {
Object nodeClass = LibGraalCompilerSupport.get().nodeClasses.get(clazz);
if (nodeClass == null) {
throw VMError.shouldNotReachHere(String.format("Unknown node class: %s%n", clazz.getName()));
}
return SubstrateUtil.cast(nodeClass, Target_jdk_graal_compiler_graph_NodeClass.class);
}

@Alias //
private String shortName;

Expand All @@ -387,40 +374,6 @@ public String shortName() {
}
}

@TargetClass(className = "jdk.graal.compiler.lir.LIRInstructionClass", classLoader = LibGraalClassLoaderSupplier.class, onlyWith = LibGraalFeature.IsEnabled.class)
static final class Target_jdk_graal_compiler_lir_LIRInstructionClass {

/*
* Redirect method to image build-time pre-computed instructionClasses map in
* LibGraalCompilerSupport.
*/
@Substitute
public static Target_jdk_graal_compiler_lir_LIRInstructionClass get(Class<?> clazz) {
Object instructionClass = LibGraalCompilerSupport.get().instructionClasses.get(clazz);
if (instructionClass == null) {
throw VMError.shouldNotReachHere(String.format("Unknown instruction class: %s%n", clazz.getName()));
}
return SubstrateUtil.cast(instructionClass, Target_jdk_graal_compiler_lir_LIRInstructionClass.class);
}
}

@TargetClass(className = "jdk.graal.compiler.lir.CompositeValueClass", classLoader = LibGraalClassLoaderSupplier.class, onlyWith = LibGraalFeature.IsEnabled.class)
static final class Target_jdk_graal_compiler_lir_CompositeValueClass {

/*
* Redirect method to image build-time pre-computed compositeValueClasses map in
* LibGraalCompilerSupport.
*/
@Substitute
public static Target_jdk_graal_compiler_lir_CompositeValueClass get(Class<?> clazz) {
Object compositeValueClass = LibGraalCompilerSupport.get().compositeValueClasses.get(clazz);
if (compositeValueClass == null) {
throw VMError.shouldNotReachHere(String.format("Unknown composite value class: %s%n", clazz.getName()));
}
return SubstrateUtil.cast(compositeValueClass, Target_jdk_graal_compiler_lir_CompositeValueClass.class);
}
}

@TargetClass(className = "jdk.graal.compiler.hotspot.HotSpotGraalOptionValues", classLoader = LibGraalClassLoaderSupplier.class, onlyWith = LibGraalFeature.IsEnabled.class)
static final class Target_jdk_graal_compiler_hotspot_HotSpotGraalOptionValues {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import jdk.graal.compiler.debug.DebugHandlersFactory;
import jdk.graal.compiler.graph.Node;
import jdk.graal.compiler.graph.NodeClass;
import jdk.graal.compiler.lir.CompositeValueClass;
import jdk.graal.compiler.lir.LIRInstructionClass;
import jdk.graal.compiler.lir.phases.LIRPhase;
import jdk.graal.compiler.phases.BasePhase;
Expand All @@ -56,7 +55,6 @@ public class GraalCompilerSupport {

public final EconomicMap<Class<?>, NodeClass<?>> nodeClasses = ImageHeapMap.create();
public final EconomicMap<Class<?>, LIRInstructionClass<?>> instructionClasses = ImageHeapMap.create();
public final EconomicMap<Class<?>, CompositeValueClass<?>> compositeValueClasses = ImageHeapMap.create();
public HashMap<Class<? extends NodeMatchRules>, EconomicMap<Class<? extends Node>, List<MatchStatement>>> matchRuleRegistry;

protected EconomicMap<Class<?>, BasePhase.BasePhaseStatistics> basePhaseStatistics;
Expand Down
Loading

0 comments on commit 3b5860a

Please sign in to comment.