Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gluon-bot committed Oct 15, 2023
2 parents 0f72d42 + 46b81f3 commit 22597b6
Show file tree
Hide file tree
Showing 27 changed files with 531 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
import org.graalvm.compiler.api.test.ModuleSupport;
import org.graalvm.compiler.bytecode.Bytecodes;
import org.graalvm.compiler.core.phases.HighTier;
import org.graalvm.compiler.core.phases.fuzzing.FuzzedSuites;
import org.graalvm.compiler.core.test.ReflectionOptionDescriptors;
import org.graalvm.compiler.debug.GlobalMetrics;
import org.graalvm.compiler.debug.GraalError;
Expand Down Expand Up @@ -1510,7 +1511,11 @@ public static CompileTheWorld create() {
HotSpotGraalCompiler compiler = (HotSpotGraalCompiler) jvmciRuntime.getCompiler();
HotSpotGraalRuntimeProvider graalRuntime = compiler.getGraalRuntime();
OptionValues harnessOptions = loadHarnessOptions();
return new CompileTheWorld(jvmciRuntime, compiler, harnessOptions, graalRuntime.getOptions());
OptionValues compilerOptions = graalRuntime.getOptions();
if (Options.FuzzPhasePlan.getValue(harnessOptions)) {
compilerOptions = FuzzedSuites.fuzzingOptions(compilerOptions);
}
return new CompileTheWorld(jvmciRuntime, compiler, harnessOptions, compilerOptions);
}

public static void main(String[] args) throws Throwable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.graalvm.compiler.core.phases.fuzzing.AbstractCompilationPlan;
import org.graalvm.compiler.core.phases.fuzzing.FullFuzzedCompilationPlan;
import org.graalvm.compiler.core.phases.fuzzing.FullFuzzedTierPlan;
import org.graalvm.compiler.core.phases.fuzzing.FuzzedSuites;
import org.graalvm.compiler.core.phases.fuzzing.MinimalFuzzedCompilationPlan;
import org.graalvm.compiler.core.test.GraalCompilerTest;
import org.graalvm.compiler.core.test.TestPhase;
Expand Down Expand Up @@ -120,16 +121,24 @@ protected void assertDeepEquals(Object expected, Object actual) {
}
}

protected OptionValues getOptions() {
OptionValues options = getInitialOptions();
if (Boolean.getBoolean(COMPILATION_PLAN_FUZZING_SYSTEM_PROPERTY)) {
options = FuzzedSuites.fuzzingOptions(options);
}
return options;
}

protected void runTest(String name, Object... args) {
runTest(getInitialOptions(), name, args);
runTest(getOptions(), name, args);
}

protected void runTest(OptionValues options, String name, Object... args) {
runTest(options, EMPTY, name, args);
}

protected void runTest(Set<DeoptimizationReason> shouldNotDeopt, String name, Object... args) {
runTest(getInitialOptions(), shouldNotDeopt, name, args);
runTest(getOptions(), shouldNotDeopt, name, args);
}

protected void runTest(OptionValues options, Set<DeoptimizationReason> shouldNotDeopt, String name, Object... args) {
Expand Down Expand Up @@ -254,10 +263,11 @@ private void testAgainstExpectedWithFuzzedCompilationPlan(OptionValues options,
*/
private void testFuzzedCompilationPlan(MinimalFuzzedCompilationPlan plan, OptionValues options, ResolvedJavaMethod method, Result expect, Set<DeoptimizationReason> shouldNotDeopt,
Object receiver, Object... args) {
OptionValues fuzzingOptions = FuzzedSuites.fuzzingOptions(options);
fuzzedSuites = plan.getSuites();
Result actual = null;
try {
actual = executeActualCheckDeopt(options, method, shouldNotDeopt, receiver, args);
actual = executeActualCheckDeopt(fuzzingOptions, method, shouldNotDeopt, receiver, args);
} catch (AssumptionViolatedException e) {
throw e;
} catch (Throwable t) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

import org.graalvm.compiler.nodes.GraphState;
import org.graalvm.compiler.nodes.GraphState.MandatoryStages;
import org.graalvm.compiler.options.OptionValues;
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
import org.graalvm.compiler.phases.tiers.Suites;

/**
Expand Down Expand Up @@ -68,6 +70,23 @@ public void saveFuzzedSuites(String dumpPath) {
fullFuzzedCompilationPlan.saveCompilationPlan(dumpPath);
}

/**
* Adjusts the {@code baseOptions} with extra compiler options to be used when running with a
* fuzzed phase plan. This can be used to relax some strict verification conditions that should
* always hold during normal compilations but are not strictly required for the correctness of
* fuzzed compilations.
*
* @return a new {@link OptionValues} instance containing extra compiler options
*/
public static OptionValues fuzzingOptions(OptionValues baseOptions) {
return new OptionValues(baseOptions,
/*
* Allow GVN even in a graph state where we would no longer allow GVN in
* normal compilations.
*/
CanonicalizerPhase.Options.CanonicalizerVerifyGVNAllowed, false);
}

@Override
public String toString() {
return fullFuzzedCompilationPlan.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ default void updateInliningLogAfterRegister(StructuredGraph newGraph) {
*/
default void updateInliningLogAfterClone(Node other) {
StructuredGraph graph = asFixedNodeOrNull().graph();
if (graph == null) {
return;
}
InliningLog log = graph.getInliningLog();
if (log != null) {
// At this point, the invokable node was already added to the inlining log
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
import org.graalvm.compiler.nodes.spi.Simplifiable;
import org.graalvm.compiler.nodes.spi.SimplifierTool;
import org.graalvm.compiler.nodes.util.GraphUtil;
import org.graalvm.compiler.options.Option;
import org.graalvm.compiler.options.OptionKey;
import org.graalvm.compiler.options.OptionType;
import org.graalvm.compiler.options.OptionValues;
import org.graalvm.compiler.phases.BasePhase;

Expand All @@ -87,6 +90,13 @@

public class CanonicalizerPhase extends BasePhase<CoreProviders> {

public static class Options {
// @formatter:off
@Option(help = "Verify if the current graph state allows GVN to be performed.", type = OptionType.Debug)
public static final OptionKey<Boolean> CanonicalizerVerifyGVNAllowed = new OptionKey<>(true);
// @formatter:on
}

/**
* Constants for types of canonicalization that can be performed.
*
Expand Down Expand Up @@ -527,9 +537,11 @@ public static boolean gvn(Node node, NodeClass<?> nodeClass) {
}

public boolean tryGlobalValueNumbering(Node node, NodeClass<?> nodeClass) {
assert ((StructuredGraph) node.graph()).getGraphState().isBeforeStage(StageFlag.PARTIAL_REDUNDANCY_SCHEDULE) : "GVN must not occur after expanding partially redundant nodes, trying to gvn " +
node +
" for graph " + node.graph();
if (Options.CanonicalizerVerifyGVNAllowed.getValue(node.getOptions())) {
assert ((StructuredGraph) node.graph()).getGraphState().isBeforeStage(
StageFlag.PARTIAL_REDUNDANCY_SCHEDULE) : "GVN must not occur after expanding partially redundant nodes, trying to gvn " + node + " for graph " +
node.graph();
}
return gvn(node, nodeClass);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.graalvm.compiler.graph.Node;
import org.graalvm.compiler.graph.NodeBitMap;
import org.graalvm.compiler.graph.Position;
import org.graalvm.compiler.nodes.AbstractBeginNode;
import org.graalvm.compiler.nodes.AbstractEndNode;
import org.graalvm.compiler.nodes.AbstractMergeNode;
import org.graalvm.compiler.nodes.ConstantNode;
Expand Down Expand Up @@ -181,6 +182,48 @@ private static boolean assertScheduleableBeforeFSA(final StructuredGraph graph)
protected NodeBitMap processBlock(final HIRBlock block, final NodeBitMap currentState) {
final List<Node> list = graph.getLastSchedule().getBlockToNodesMap().get(block);

AbstractBeginNode blockBegin = block.getBeginNode();
if (blockBegin instanceof AbstractMergeNode merge) {
/**
* Phis aren't scheduled, so they need to be added explicitly. We must do
* this first because there might be floating nodes depending on the phis
* that have floated to the beginning of the block.
* <p/>
*
* That is, we might have a graph like this:
*
* <pre>
* ... ... (inputs from predecessor blocks)
* \ /
* +----- Phi
* | |
* | Pi (or any other floating node)
* | |
* | FrameState
* | |
* +---> Merge
* </pre>
*
* In the schedule the order of these nodes can be:
*
* <pre>
* Pi
* FrameState
* Merge
* ...
* </pre>
*
* This may seem unnatural, but due to the cyclic dependency on the state,
* any other order would be unnatural as well. For the use case of checking
* the schedule, pretend that all phis in the block precede everything else.
*/
currentState.markAll(merge.phis());
if (merge instanceof LoopBeginNode loopBegin) {
// remember the state at the loop entry, it's restored at exits
loopEntryStates.put(loopBegin, currentState.copy());
}
}

/*
* A stateAfter is not valid directly after its associated state split, but
* right before the next fixed node. Therefore a pending stateAfter is kept that
Expand Down Expand Up @@ -211,12 +254,7 @@ public void apply(Node from, Position p) {
}

if (node instanceof AbstractMergeNode) {
// phis aren't scheduled, so they need to be added explicitly
currentState.markAll(((AbstractMergeNode) node).phis());
if (node instanceof LoopBeginNode) {
// remember the state at the loop entry, it's restored at exits
loopEntryStates.put((LoopBeginNode) node, currentState.copy());
}
GraalError.guarantee(node == blockBegin, "block should contain only one merge, found %s, expected %s", node, blockBegin);
} else if (node instanceof ProxyNode) {
assert false : "proxy nodes should not be in the schedule";
} else if (node instanceof LoopExitNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public void lower(Node n, LoweringTool tool) {
if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
lowerComputeObjectAddressNode((ComputeObjectAddressNode) n);
}
} else if (n instanceof FloatingIntegerDivRemNode<?> && tool.getLoweringStage() == LoweringTool.StandardLoweringStage.MID_TIER) {
} else if (n instanceof FloatingIntegerDivRemNode<?> divRem && divRem.graph().isAfterStage(GraphState.StageFlag.FSA)) {
lowerFloatingIntegerDivRem((FloatingIntegerDivRemNode<?>) n, tool);
} else if (!(n instanceof LIRLowerable)) {
// Assume that nodes that implement both Lowerable and LIRLowerable will be handled
Expand All @@ -346,6 +346,9 @@ protected void lowerFloatingIntegerDivRem(FloatingIntegerDivRemNode<?> divRem, L
divRemFixed.setCanDeopt(false);
divRem.replaceAtUsagesAndDelete(divRemFixed);
graph.addAfterFixed(insertAfter, divRemFixed);
if (tool.getLoweringStage() == LoweringTool.StandardLoweringStage.LOW_TIER) {
divRemFixed.lower(tool);
}
}

private static void lowerComputeObjectAddressNode(ComputeObjectAddressNode n) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ public HeapImpl(int pageSize) {
this.gcImpl = new GCImpl();
this.runtimeCodeInfoGcSupport = new RuntimeCodeInfoGCSupportImpl();
HeapParameters.initialize();
DiagnosticThunkRegistry.singleton().register(new DumpHeapSettingsAndStatistics());
DiagnosticThunkRegistry.singleton().register(new DumpHeapUsage());
DiagnosticThunkRegistry.singleton().register(new DumpChunkInformation());
DiagnosticThunkRegistry.singleton().add(new DumpHeapSettingsAndStatistics());
DiagnosticThunkRegistry.singleton().add(new DumpHeapUsage());
DiagnosticThunkRegistry.singleton().add(new DumpChunkInformation());
}

@Fold
Expand Down Expand Up @@ -647,7 +647,7 @@ public boolean printLocationInfo(Log log, UnsignedWord value, boolean allowJavaH
if (printLocationInfo(log, ptr, allowJavaHeapAccess, allowUnsafeOperations)) {
if (allowJavaHeapAccess && objectHeaderImpl.pointsToObjectHeader(ptr)) {
log.indent(true);
SubstrateDiagnostics.printObjectInfo(log, ptr);
SubstrateDiagnostics.printObjectInfo(log, ptr.toObject());
log.redent(false);
}
return true;
Expand Down Expand Up @@ -875,6 +875,8 @@ public void printDiagnostics(Log log, ErrorContext context, int maxDiagnosticLev
log.string("Heap base: ").zhex(KnownIntrinsics.heapBase()).newline();
}
log.string("Object reference size: ").signed(ConfigurationValues.getObjectLayout().getReferenceSize()).newline();
log.string("Reserved object header bits: 0b").number(Heap.getHeap().getObjectHeader().getReservedBitsMask(), 2, false).newline();

log.string("Aligned chunk size: ").unsigned(HeapParameters.getAlignedHeapChunkSize()).newline();
log.string("Large array threshold: ").unsigned(HeapParameters.getLargeArrayThreshold()).newline();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ public Integer getValue(OptionValues values) {
@Option(help = "Print summary GC information after application main method returns. Serial GC only.", type = OptionType.Debug)//
public static final RuntimeOptionKey<Boolean> PrintGCSummary = new RuntimeOptionKey<>(false, SerialGCOptions::serialGCOnly);

/* Will be removed as part of GR-48148. */
@Option(help = "Deprecated. Print a time stamp at each collection, if +PrintGC or +VerboseGC. Serial GC only.", type = OptionType.Debug)//
public static final RuntimeOptionKey<Boolean> PrintGCTimeStamps = new RuntimeOptionKey<>(false, SerialGCOptions::serialGCOnly);

@Option(help = "Print the time for each of the phases of each collection, if +VerboseGC. Serial GC only.", type = OptionType.Debug)//
public static final RuntimeOptionKey<Boolean> PrintGCTimes = new RuntimeOptionKey<>(false, SerialGCOptions::serialGCOnly);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,13 @@ public boolean walkObjects(ObjectVisitor visitor) {
}

public void logUsage(Log log, boolean logIfEmpty) {
UnsignedWord chunkBytes = getChunkBytes();
UnsignedWord chunkBytes;
if (isEdenSpace() && !VMOperation.isGCInProgress()) {
chunkBytes = HeapImpl.getAccounting().getEdenUsedBytes();
} else {
chunkBytes = getChunkBytes();
}

if (logIfEmpty || chunkBytes.aboveThan(0)) {
log.string(getName()).string(": ").rational(chunkBytes, GCImpl.M, 2).string("M (")
.rational(accounting.getAlignedChunkBytes(), GCImpl.M, 2).string("M in ").signed(accounting.getAlignedChunkCount()).string(" aligned chunks, ")
Expand Down
Loading

0 comments on commit 22597b6

Please sign in to comment.