Skip to content

Commit 144f652

Browse files
committed
refactorings for more context data in bgv dumps
1 parent 0fbbfe1 commit 144f652

File tree

6 files changed

+67
-25
lines changed

6 files changed

+67
-25
lines changed

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/ObjectHashCodeInliningTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
*/
2525
package jdk.graal.compiler.hotspot.test;
2626

27+
import org.junit.Test;
28+
2729
import jdk.graal.compiler.core.test.GraalCompilerTest;
2830
import jdk.graal.compiler.nodes.StructuredGraph;
2931
import jdk.graal.compiler.nodes.extended.ForeignCallNode;
3032
import jdk.graal.compiler.nodes.java.MethodCallTargetNode;
3133
import jdk.graal.compiler.nodes.memory.ReadNode;
32-
import org.junit.Test;
33-
3434
import jdk.vm.ci.meta.JavaTypeProfile;
3535
import jdk.vm.ci.meta.JavaTypeProfile.ProfiledType;
3636
import jdk.vm.ci.meta.MetaAccessProvider;
@@ -72,7 +72,7 @@ private static boolean containsForeignCallToIdentityHashCode(StructuredGraph gra
7272

7373
private static boolean containsReadStringHash(StructuredGraph graph) {
7474
for (ReadNode readNode : graph.getNodes().filter(ReadNode.class)) {
75-
if ("String.hash".equals(readNode.getLocationIdentity().toString())) {
75+
if ("java.lang.String.hash".equals(readNode.getLocationIdentity().toString())) {
7676
return true;
7777
}
7878
}

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/ResourceLimitsCompilationTest.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@
2727
import java.util.concurrent.Semaphore;
2828
import java.util.function.Predicate;
2929

30+
import org.graalvm.polyglot.Context;
31+
import org.graalvm.polyglot.Engine;
32+
import org.graalvm.polyglot.ResourceLimits;
33+
import org.junit.Assert;
34+
import org.junit.Test;
35+
36+
import com.oracle.truffle.api.TruffleOptions;
37+
import com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage;
38+
import com.oracle.truffle.runtime.OptimizedCallTarget;
39+
3040
import jdk.graal.compiler.graph.Node;
3141
import jdk.graal.compiler.graph.NodeClass;
3242
import jdk.graal.compiler.nodes.InvokeWithExceptionNode;
@@ -37,15 +47,6 @@
3747
import jdk.graal.compiler.nodes.java.MethodCallTargetNode;
3848
import jdk.graal.compiler.nodes.memory.ReadNode;
3949
import jdk.graal.compiler.nodes.memory.WriteNode;
40-
import org.graalvm.polyglot.Context;
41-
import org.graalvm.polyglot.Engine;
42-
import org.graalvm.polyglot.ResourceLimits;
43-
import org.junit.Assert;
44-
import org.junit.Test;
45-
46-
import com.oracle.truffle.api.TruffleOptions;
47-
import com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage;
48-
import com.oracle.truffle.runtime.OptimizedCallTarget;
4950

5051
public class ResourceLimitsCompilationTest extends PartialEvaluationTest {
5152

@@ -64,8 +65,8 @@ public void testStatementLimitSingleContext() {
6465
/*
6566
* Verify that the statements fold to a single read/write.
6667
*/
67-
Assert.assertEquals(1, countNodes(graph, ReadNode.TYPE, (n) -> n.getLocationIdentity().toString().equals("PolyglotContextImpl.statementCounter")));
68-
Assert.assertEquals(1, countNodes(graph, WriteNode.TYPE, (n) -> n.getLocationIdentity().toString().equals("PolyglotContextImpl.statementCounter")));
68+
Assert.assertEquals(1, countNodes(graph, ReadNode.TYPE, (n) -> n.getLocationIdentity().toString().equals("com.oracle.truffle.polyglot.PolyglotContextImpl.statementCounter")));
69+
Assert.assertEquals(1, countNodes(graph, WriteNode.TYPE, (n) -> n.getLocationIdentity().toString().equals("com.oracle.truffle.polyglot.PolyglotContextImpl.statementCounter")));
6970
}
7071
}
7172

@@ -125,9 +126,9 @@ public void testStatementLimitMultiContextTwoDifferentConfigs() {
125126
if (!TruffleOptions.AOT) {
126127
Assert.assertEquals(1, countNodes(graph, ReadNode.TYPE, (n) -> n.getLocationIdentity().toString().equals("JavaThread::<JVMCIReservedOop0>")));
127128
}
128-
Assert.assertEquals(1, countNodes(graph, ReadNode.TYPE, (n) -> n.getLocationIdentity().toString().equals("PolyglotContextImpl.statementCounter")));
129-
Assert.assertEquals(0, countNodes(graph, ReadNode.TYPE, (n) -> n.getLocationIdentity().toString().equals("PolyglotContextImpl.statementLimit")));
130-
Assert.assertEquals(1, countNodes(graph, WriteNode.TYPE, (n) -> n.getLocationIdentity().toString().equals("PolyglotContextImpl.statementCounter")));
129+
Assert.assertEquals(1, countNodes(graph, ReadNode.TYPE, (n) -> n.getLocationIdentity().toString().equals("com.oracle.truffle.polyglot.PolyglotContextImpl.statementCounter")));
130+
Assert.assertEquals(0, countNodes(graph, ReadNode.TYPE, (n) -> n.getLocationIdentity().toString().equals("com.oracle.truffle.polyglot.PolyglotContextImpl.statementLimit")));
131+
Assert.assertEquals(1, countNodes(graph, WriteNode.TYPE, (n) -> n.getLocationIdentity().toString().equals("com.oracle.truffle.polyglot.PolyglotContextImpl.statementCounter")));
131132
}
132133
}
133134
}
@@ -145,9 +146,9 @@ private void assertLimitCheckFastPath(Context context) {
145146
if (!TruffleOptions.AOT) {
146147
Assert.assertEquals(1, countNodes(graph, ReadNode.TYPE, (n) -> n.getLocationIdentity().toString().equals("JavaThread::<JVMCIReservedOop0>")));
147148
}
148-
Assert.assertEquals(1, countNodes(graph, ReadNode.TYPE, (n) -> n.getLocationIdentity().toString().equals("PolyglotContextImpl.statementCounter")));
149-
Assert.assertEquals(1, countNodes(graph, WriteNode.TYPE, (n) -> n.getLocationIdentity().toString().equals("PolyglotContextImpl.statementCounter")));
150-
Assert.assertEquals(0, countNodes(graph, ReadNode.TYPE, (n) -> n.getLocationIdentity().toString().equals("PolyglotContextImpl.statementLimit")));
149+
Assert.assertEquals(1, countNodes(graph, ReadNode.TYPE, (n) -> n.getLocationIdentity().toString().equals("com.oracle.truffle.polyglot.PolyglotContextImpl.statementCounter")));
150+
Assert.assertEquals(1, countNodes(graph, WriteNode.TYPE, (n) -> n.getLocationIdentity().toString().equals("com.oracle.truffle.polyglot.PolyglotContextImpl.statementCounter")));
151+
Assert.assertEquals(0, countNodes(graph, ReadNode.TYPE, (n) -> n.getLocationIdentity().toString().equals("com.oracle.truffle.polyglot.PolyglotContextImpl.statementLimit")));
151152
}
152153

153154
@Test
@@ -170,8 +171,8 @@ public void testStatementLimitEngineMultiThread() throws InterruptedException {
170171
* Verify that the statements fold to a single read for the context and a single
171172
* read/write for the statement counts.
172173
*/
173-
Assert.assertEquals(1, countNodes(graph, ReadNode.TYPE, (n) -> n.getLocationIdentity().toString().equals("PolyglotContextImpl.statementCounter")));
174-
Assert.assertEquals(1, countNodes(graph, WriteNode.TYPE, (n) -> n.getLocationIdentity().toString().equals("PolyglotContextImpl.statementCounter")));
174+
Assert.assertEquals(1, countNodes(graph, ReadNode.TYPE, (n) -> n.getLocationIdentity().toString().equals("com.oracle.truffle.polyglot.PolyglotContextImpl.statementCounter")));
175+
Assert.assertEquals(1, countNodes(graph, WriteNode.TYPE, (n) -> n.getLocationIdentity().toString().equals("com.oracle.truffle.polyglot.PolyglotContextImpl.statementCounter")));
175176
Assert.assertEquals(0, countNodes(graph, InvokeWithExceptionNode.TYPE));
176177
}
177178
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/graph/Node.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.lang.annotation.ElementType;
3030
import java.lang.annotation.RetentionPolicy;
3131
import java.util.Arrays;
32+
import java.util.Base64;
3233
import java.util.Collections;
3334
import java.util.EnumSet;
3435
import java.util.Formattable;
@@ -1715,6 +1716,14 @@ public Map<Object, Object> getDebugProperties(Map<Object, Object> map) {
17151716
// Convert a char to an int as chars are not guaranteed to printable/viewable
17161717
char ch = (char) value;
17171718
value = Integer.valueOf(ch);
1719+
} else if (properties.getType(i) == byte[].class) {
1720+
String encoded = Base64.getEncoder().encodeToString((byte[]) value);
1721+
/*
1722+
* BGV Replay for truffle: in order to be able to reconstruct most of the truffle
1723+
* graphs after partial evaluation we have to dump some properties in a parseable
1724+
* form. Byte arrays are used throughout truffle, thus make them re-parseable.
1725+
*/
1726+
value = "base64:" + encoded;
17181727
}
17191728
map.put(properties.getName(i), value);
17201729
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/FieldLocationIdentity.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@
2424
*/
2525
package jdk.graal.compiler.nodes;
2626

27-
import jdk.vm.ci.meta.JavaKind.FormatWithToString;
28-
2927
import java.util.Objects;
3028

3129
import org.graalvm.word.LocationIdentity;
3230

31+
import jdk.vm.ci.meta.JavaKind.FormatWithToString;
3332
import jdk.vm.ci.meta.ResolvedJavaField;
3433

3534
public class FieldLocationIdentity extends LocationIdentity implements FormatWithToString {
@@ -74,6 +73,6 @@ public int hashCode() {
7473

7574
@Override
7675
public String toString() {
77-
return inner.format("%h.%n") + (isImmutable() ? ":immutable" : "");
76+
return inner.format("%H.%n") + (isImmutable() ? ":immutable" : "");
7877
}
7978
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/GraphState.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ public void setAfterFSA() {
618618
* order used to defined theses stages corresponds to their order in a standard compilation.
619619
*/
620620
public enum StageFlag {
621+
PARTIAL_EVALUATION,
621622
CANONICALIZATION,
622623
/* Stages applied by high tier. */
623624
LOOP_OVERFLOWS_CHECKED,

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/PostPartialEvaluationSuite.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@
2424
*/
2525
package jdk.graal.compiler.truffle;
2626

27+
import java.util.Optional;
28+
2729
import jdk.graal.compiler.loop.phases.ConvertDeoptimizeToGuardPhase;
30+
import jdk.graal.compiler.nodes.GraphState;
2831
import jdk.graal.compiler.nodes.StructuredGraph;
2932
import jdk.graal.compiler.nodes.java.MethodCallTargetNode;
3033
import jdk.graal.compiler.options.OptionValues;
3134
import jdk.graal.compiler.phases.BasePhase;
35+
import jdk.graal.compiler.phases.Phase;
3236
import jdk.graal.compiler.phases.PhaseSuite;
3337
import jdk.graal.compiler.phases.common.CanonicalizerPhase;
3438
import jdk.graal.compiler.phases.common.ConditionalEliminationPhase;
@@ -40,8 +44,36 @@
4044

4145
public class PostPartialEvaluationSuite extends PhaseSuite<TruffleTierContext> {
4246

47+
static class PEMarkingPhase extends Phase {
48+
49+
@Override
50+
public Optional<NotApplicable> notApplicableTo(GraphState graphState) {
51+
return ALWAYS_APPLICABLE;
52+
}
53+
54+
@Override
55+
protected void run(StructuredGraph graph) {
56+
// nothing to do
57+
}
58+
59+
@Override
60+
public void updateGraphState(GraphState graphState) {
61+
if (graphState.isBeforeStage(GraphState.StageFlag.PARTIAL_EVALUATION)) {
62+
graphState.setAfterStage(GraphState.StageFlag.PARTIAL_EVALUATION);
63+
}
64+
}
65+
66+
@Override
67+
public CharSequence getName() {
68+
return "PEMarkingPhase";
69+
}
70+
}
71+
72+
private static final PEMarkingPhase MARKING_PHASE = new PEMarkingPhase();
73+
4374
@SuppressWarnings("this-escape")
4475
public PostPartialEvaluationSuite(OptionValues optionValues, boolean iterativePartialEscape) {
76+
appendPhase(MARKING_PHASE);
4577
CanonicalizerPhase canonicalizerPhase = CanonicalizerPhase.create();
4678
appendPhase(new InsertProxyPhase());
4779
appendPhase(new ConvertDeoptimizeToGuardPhase(canonicalizerPhase));

0 commit comments

Comments
 (0)