forked from oracle/graal
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #715 from zakkak/2024-04-17-24-0-april-cpu
[24.0] April CPU sync
- Loading branch information
Showing
546 changed files
with
1,201 additions
and
64,662 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
171 changes: 171 additions & 0 deletions
171
...dk.graal.compiler.test/src/jdk/graal/compiler/core/test/ConditionalEliminationTest17.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
/* | ||
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
package jdk.graal.compiler.core.test; | ||
|
||
import java.util.EnumSet; | ||
|
||
import org.junit.Test; | ||
|
||
import jdk.graal.compiler.api.directives.GraalDirectives; | ||
import jdk.graal.compiler.core.common.GraalOptions; | ||
import jdk.graal.compiler.options.OptionValues; | ||
import jdk.vm.ci.meta.DeoptimizationReason; | ||
|
||
public class ConditionalEliminationTest17 extends ConditionalEliminationTestBase { | ||
|
||
static final class A { | ||
} | ||
|
||
static final class B { | ||
int value = 1337; | ||
|
||
int value() { | ||
return value; | ||
} | ||
} | ||
|
||
private static boolean equals(byte[] a, byte[] b) { | ||
if (a == b) { | ||
return true; | ||
} else if (a.length != b.length) { | ||
return false; | ||
} else { | ||
for (int i = 0; i < a.length; i++) { | ||
if (a[i] != b[i]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} | ||
|
||
private static final Object X = new Object(); | ||
private static final Object Y = new Object(); | ||
|
||
public static int test1Snippet(byte[][] haystack, byte[] needle, Object[] otherValues) { | ||
Object someValue = otherValues[0]; | ||
Object anotherValue1 = otherValues[1]; | ||
Object anotherValue2 = otherValues[2]; | ||
if (haystack.length != 0) { | ||
for (int i = 0; i < haystack.length; i++) { | ||
byte[] hay = haystack[i]; | ||
if (equals(hay, needle)) { | ||
int result = 42; | ||
if (anotherValue1 == X) { | ||
if (anotherValue2 == Y) { | ||
result++; | ||
GraalDirectives.controlFlowAnchor(); | ||
} | ||
GraalDirectives.controlFlowAnchor(); | ||
} | ||
if (someValue.getClass() != A.class) { | ||
GraalDirectives.deoptimizeAndInvalidate(); | ||
} | ||
GraalDirectives.controlFlowAnchor(); | ||
return result; | ||
} | ||
} | ||
} | ||
return ((B) someValue).value(); | ||
} | ||
|
||
@Test | ||
public void test1() { | ||
Object[] args = {new byte[][]{"foo".getBytes(), "bar".getBytes()}, "neither".getBytes(), new Object[]{new B(), X, Y}}; | ||
test(getInitialOptions(), EnumSet.allOf(DeoptimizationReason.class), "test1Snippet", args); | ||
} | ||
|
||
public static int test2Snippet(byte[][] haystack, byte[] needle, Object[] otherValues) { | ||
Object someValue = otherValues[0]; | ||
Object anotherValue1 = otherValues[1]; | ||
Object anotherValue2 = otherValues[2]; | ||
if (haystack.length != 0) { | ||
for (int i = 0; i < haystack.length; i++) { | ||
byte[] hay = haystack[i]; | ||
if (equals(hay, needle)) { | ||
int result = 42; | ||
if (anotherValue1 == X) { | ||
if (anotherValue2 == Y) { | ||
result++; | ||
GraalDirectives.controlFlowAnchor(); | ||
} | ||
GraalDirectives.controlFlowAnchor(); | ||
} | ||
if (someValue == null || someValue.getClass() != A.class) { | ||
GraalDirectives.deoptimizeAndInvalidate(); | ||
} | ||
GraalDirectives.controlFlowAnchor(); | ||
return result; | ||
} | ||
} | ||
} | ||
return ((B) someValue).value(); | ||
} | ||
|
||
@Test | ||
public void test2() { | ||
Object[] args = {new byte[][]{"foo".getBytes(), "bar".getBytes()}, "bad".getBytes(), new Object[]{new B(), X, Y}}; | ||
test(getInitialOptions(), EnumSet.allOf(DeoptimizationReason.class), "test2Snippet", args); | ||
} | ||
|
||
// simplified and reduced version of equals (semantics of this method is not relevant, only IR | ||
// shape) | ||
private static boolean simpleEquals(byte[][] a) { | ||
for (int i = 0; i < a.length; i++) { | ||
if (GraalDirectives.sideEffect(i) == 123) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
|
||
} | ||
|
||
// simplified and reduced version of test1Snippet (semantics of this method is not relevant, | ||
// only IR shape) | ||
@SuppressWarnings("unused") | ||
public static int test3Snippet(byte[][] haystack, byte[] needle, Object someValue, Object anotherValue1) { | ||
for (int i = 0; i < haystack.length; i++) { | ||
if (simpleEquals(haystack)) { | ||
int result = 42; | ||
if (anotherValue1 == X) { | ||
GraalDirectives.controlFlowAnchor(); | ||
} | ||
if (someValue.getClass() != A.class) { | ||
GraalDirectives.deoptimizeAndInvalidate(); | ||
} | ||
return result; | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
@Test | ||
public void test3() { | ||
Object[] args = {new byte[][]{"foo".getBytes(), "bar".getBytes()}, "neither".getBytes(), X, Y}; | ||
OptionValues opt = new OptionValues(getInitialOptions(), GraalOptions.OptFloatingReads, false); | ||
test(opt, EnumSet.allOf(DeoptimizationReason.class), "test3Snippet", args); | ||
} | ||
|
||
} |
136 changes: 136 additions & 0 deletions
136
...dk.graal.compiler.test/src/jdk/graal/compiler/core/test/FixedGuardSimplificationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/* | ||
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
package jdk.graal.compiler.core.test; | ||
|
||
import org.junit.Test; | ||
|
||
import jdk.graal.compiler.api.directives.GraalDirectives; | ||
import jdk.graal.compiler.core.common.type.StampFactory; | ||
import jdk.graal.compiler.nodes.FixedGuardNode; | ||
import jdk.graal.compiler.nodes.GraphState; | ||
import jdk.graal.compiler.nodes.PiNode; | ||
import jdk.graal.compiler.nodes.StructuredGraph; | ||
import jdk.graal.compiler.nodes.ValueNode; | ||
import jdk.graal.compiler.nodes.java.LoadFieldNode; | ||
import jdk.graal.compiler.options.OptionValues; | ||
import jdk.graal.compiler.phases.BasePhase; | ||
import jdk.graal.compiler.phases.tiers.HighTierContext; | ||
import jdk.graal.compiler.phases.tiers.Suites; | ||
import jdk.graal.compiler.virtual.phases.ea.FinalPartialEscapePhase; | ||
import jdk.vm.ci.code.InstalledCode; | ||
import jdk.vm.ci.code.InvalidInstalledCodeException; | ||
import jdk.vm.ci.meta.DeoptimizationAction; | ||
import jdk.vm.ci.meta.DeoptimizationReason; | ||
|
||
/** | ||
* Tests that correct removal of always deoptimizing {@link FixedGuardNode}s in the presence of | ||
* floating reads. This test modifies the graph after PEA to introduce a {@link FixedGuardNode} in a | ||
* branch which is dominated by another {@link FixedGuardNode} with the inverted condition. | ||
* Replacing the always-deopt guard must ensure a proper cleanup of all attached floating reads. | ||
* This is tested by a floating read for which the removed guard ensures non-nullness of the read | ||
* object. If this read would survive the removal of the guard, a segfault would be triggered. The | ||
* guard branch is deleted in midtier after conditional elimination. | ||
*/ | ||
public class FixedGuardSimplificationTest extends GraalCompilerTest { | ||
|
||
public static class A { | ||
B b; | ||
|
||
public A(B b) { | ||
this.b = b; | ||
} | ||
} | ||
|
||
public static class B { | ||
A a; | ||
} | ||
|
||
public static void snippet(A a, A a2, int x) { | ||
guardingNull(a); | ||
if (x == 0) { | ||
// a2 is replaced by a1 after FinalPEA | ||
guardingNonNull(a2); | ||
B b = a.b; | ||
A ba = b.a; | ||
GraalDirectives.blackhole(ba); | ||
} | ||
} | ||
|
||
@Override | ||
protected Suites createSuites(OptionValues opts) { | ||
Suites s = super.createSuites(opts); | ||
s.getHighTier().findPhase(FinalPartialEscapePhase.class).add(new BasePhase<HighTierContext>() { | ||
|
||
@Override | ||
protected void run(StructuredGraph graph, HighTierContext context) { | ||
FixedGuardNode guard = graph.getNodes().filter(FixedGuardNode.class).first(); | ||
FixedGuardNode placeholderGuard = graph.getNodes().filter(FixedGuardNode.class).snapshot().get(1); | ||
|
||
/* | ||
* Makes the inner guard use the inverted condition of the dominating, outer guard | ||
* and adds the corresponding Pi. This can happen during PartialEscapeAnalysis. | ||
*/ | ||
placeholderGuard.setCondition(guard.getCondition(), true); | ||
ValueNode nullProven = (ValueNode) guard.getCondition().asNode().inputs().first(); | ||
PiNode pi = (PiNode) graph.addWithoutUnique(PiNode.create(nullProven, StampFactory.objectNonNull(), placeholderGuard)); | ||
LoadFieldNode lf = graph.getNodes().filter(LoadFieldNode.class).first(); | ||
lf.setObject(pi); | ||
} | ||
|
||
@Override | ||
public java.util.Optional<NotApplicable> notApplicableTo(GraphState graphState) { | ||
return ALWAYS_APPLICABLE; | ||
} | ||
}); | ||
return s; | ||
} | ||
|
||
private static <T> T guardingNull(T value) { | ||
if (value != null) { | ||
GraalDirectives.deoptimize(DeoptimizationAction.InvalidateRecompile, DeoptimizationReason.UnreachedCode, true); | ||
} | ||
return value; | ||
} | ||
|
||
private static <T> T guardingNonNull(T value) { | ||
if (value == null) { | ||
GraalDirectives.deoptimize(DeoptimizationAction.InvalidateRecompile, DeoptimizationReason.UnreachedCode, true); | ||
} | ||
return value; | ||
} | ||
|
||
@Test | ||
public void test() throws InvalidInstalledCodeException { | ||
InstalledCode code = getCode(getResolvedJavaMethod("snippet")); | ||
boolean exceptionSeen = false; | ||
try { | ||
code.executeVarargs(null, new A(new B()), 0); | ||
} catch (NullPointerException npe) { | ||
exceptionSeen = true; | ||
} | ||
assert exceptionSeen : "Test expects a NPE to be thrown!"; | ||
assert !code.isValid() : "Test expects the code to have deopted!"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.