package org.graalvm.compiler.hotspot.nodes;
import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC;
import static org.graalvm.compiler.hotspot.GraalHotSpotVMConfig.INJECTED_VMCONFIG;
import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_1;
import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_1;
import org.graalvm.compiler.api.replacements.Fold;
import org.graalvm.compiler.api.replacements.Fold.InjectedParameter;
import org.graalvm.compiler.core.common.type.StampFactory;
import org.graalvm.compiler.graph.Node;
import org.graalvm.compiler.graph.NodeClass;
import org.graalvm.compiler.graph.spi.Canonicalizable;
import org.graalvm.compiler.graph.spi.CanonicalizerTool;
import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
import org.graalvm.compiler.hotspot.HotSpotLIRGenerator;
import org.graalvm.compiler.nodeinfo.NodeInfo;
import org.graalvm.compiler.nodes.ConstantNode;
import org.graalvm.compiler.nodes.calc.FloatingNode;
import org.graalvm.compiler.nodes.spi.LIRLowerable;
import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
import jdk.vm.ci.meta.JavaKind;
import jdk.vm.ci.meta.Value;
@NodeInfo(cycles = CYCLES_1, size = SIZE_1)
public class GraalHotSpotVMConfigNode extends FloatingNode implements LIRLowerable, Canonicalizable {
public static final NodeClass<GraalHotSpotVMConfigNode> TYPE = NodeClass.create(GraalHotSpotVMConfigNode.class);
private final GraalHotSpotVMConfig config;
protected final int markId;
public GraalHotSpotVMConfigNode(@InjectedNodeParameter GraalHotSpotVMConfig config) {
super(TYPE, StampFactory.forKind(JavaKind.Boolean));
this.config = config;
this.markId = 0;
}
public GraalHotSpotVMConfigNode(@InjectedNodeParameter GraalHotSpotVMConfig config, int markId) {
super(TYPE, StampFactory.forNodeIntrinsic());
this.config = config;
this.markId = markId;
}
public GraalHotSpotVMConfigNode(@InjectedNodeParameter GraalHotSpotVMConfig config, int markId, JavaKind kind) {
super(TYPE, StampFactory.forKind(kind));
this.config = config;
this.markId = markId;
}
@Override
public void generate(NodeLIRBuilderTool generator) {
Value res = ((HotSpotLIRGenerator) generator.getLIRGeneratorTool()).emitLoadConfigValue(markId, generator.getLIRGeneratorTool().getLIRKind(stamp));
generator.setResult(this, res);
}
@NodeIntrinsic
private static native boolean areConfigValuesConstant();
@NodeIntrinsic(setStampFromReturnType = true)
private static native long loadLongConfigValue(@ConstantNodeParameter int markId);
@NodeIntrinsic(setStampFromReturnType = true)
private static native int loadIntConfigValue(@ConstantNodeParameter int markId);
@NodeIntrinsic(setStampFromReturnType = true)
private static native byte loadByteConfigValue(@ConstantNodeParameter int markId);
public static long cardTableAddress() {
return loadLongConfigValue(cardTableAddressMark(INJECTED_VMCONFIG));
}
public static boolean isCardTableAddressConstant() {
return areConfigValuesConstant();
}
public static long heapTopAddress() {
return loadLongConfigValue(heapTopAddressMark(INJECTED_VMCONFIG));
}
public static long heapEndAddress() {
return loadLongConfigValue(heapEndAddressMark(INJECTED_VMCONFIG));
}
public static long crcTableAddress() {
return loadLongConfigValue(crcTableAddressMark(INJECTED_VMCONFIG));
}
public static int logOfHeapRegionGrainBytes() {
return loadIntConfigValue(logOfHeapRegionGrainBytesMark(INJECTED_VMCONFIG));
}
public static boolean inlineContiguousAllocationSupported() {
return loadByteConfigValue(inlineContiguousAllocationSupportedMark(INJECTED_VMCONFIG)) != 0;
}
@Fold
public static int cardTableAddressMark(@InjectedParameter GraalHotSpotVMConfig config) {
return config.MARKID_CARD_TABLE_ADDRESS;
}
@Fold
public static int heapTopAddressMark(@InjectedParameter GraalHotSpotVMConfig config) {
return config.MARKID_HEAP_TOP_ADDRESS;
}
@Fold
public static int heapEndAddressMark(@InjectedParameter GraalHotSpotVMConfig config) {
return config.MARKID_HEAP_END_ADDRESS;
}
@Fold
public static int crcTableAddressMark(@InjectedParameter GraalHotSpotVMConfig config) {
return config.MARKID_CRC_TABLE_ADDRESS;
}
@Fold
public static int logOfHeapRegionGrainBytesMark(@InjectedParameter GraalHotSpotVMConfig config) {
return config.MARKID_LOG_OF_HEAP_REGION_GRAIN_BYTES;
}
@Fold
public static int inlineContiguousAllocationSupportedMark(@InjectedParameter GraalHotSpotVMConfig config) {
return config.MARKID_INLINE_CONTIGUOUS_ALLOCATION_SUPPORTED;
}
@Override
public Node canonical(CanonicalizerTool tool) {
if (markId == 0) {
return ConstantNode.forBoolean(!GeneratePIC.getValue());
}
if (!GeneratePIC.getValue()) {
if (markId == cardTableAddressMark(config)) {
return ConstantNode.forLong(config.cardtableStartAddress);
} else if (markId == heapTopAddressMark(config)) {
return ConstantNode.forLong(config.heapTopAddress);
} else if (markId == heapEndAddressMark(config)) {
return ConstantNode.forLong(config.heapEndAddress);
} else if (markId == crcTableAddressMark(config)) {
return ConstantNode.forLong(config.crcTableAddress);
} else if (markId == logOfHeapRegionGrainBytesMark(config)) {
return ConstantNode.forInt(config.logOfHRGrainBytes);
} else if (markId == inlineContiguousAllocationSupportedMark(config)) {
return ConstantNode.forBoolean(config.inlineContiguousAllocationSupported);
} else {
assert false;
}
}
return this;
}
}