Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

Commit

Permalink
Merge with master.
Browse files Browse the repository at this point in the history
  • Loading branch information
christianhaeubl committed Apr 28, 2023
2 parents 92159f7 + 114067f commit 65b2eec
Show file tree
Hide file tree
Showing 132 changed files with 3,372 additions and 1,005 deletions.
30 changes: 15 additions & 15 deletions compiler/mx.compiler/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,33 +122,33 @@
"urls" : ["https://lafo.ssw.uni-linz.ac.at/pub/graal-external-deps/batik-all-1.7.jar"],
},

"ASM_9.1" : {
"digest" : "sha512:0a586544f3053ec8425d252b6f7e3e6772f010eb81d75020b4fd4759a561a4534dab4f805ffd18130594d1abbeb1ad7116b9d3a1e2e643d427e12bb866655954",
"ASM_9.5" : {
"digest" : "sha512:9e65f2983783725bae196ca939b45246958731246df1c495089c8ea5ce646de77c4e01a5a9ba10642016bb3258e1727e9ebcece6e74d9e3c32f528025d76b955",
"maven" : {
"groupId" : "org.ow2.asm",
"artifactId" : "asm",
"version" : "9.1",
"version" : "9.5",
},
},

"ASM_TREE_9.1" : {
"digest" : "sha512:2e7c7e2453b4453db83aa5f13a7a9ec9fa7896d3b13670b171f6e8f186f3ec2f382a985c69018a510ea1b14a2e986f00e1bd3dd6e77a59a28f82b7fbe738916d",
"ASM_TREE_9.5" : {
"digest" : "sha512:816de8f84c216a7bd97b2458bde64a4b99a039b7b59fbd1ef52edf8bf869edabb93967736fe0c61e8eb3e1520e0cefe69ba59cda12df30f9f85db75fb6c064f3",
"maven" : {
"groupId" : "org.ow2.asm",
"artifactId" : "asm-tree",
"version" : "9.1",
"version" : "9.5",
},
"dependencies" : ["ASM_9.1"],
"dependencies" : ["ASM_9.5"],
},

"ASM_UTIL_9.1" : {
"digest" : "sha512:2182c016c5547cd9e904a4a6d803c45a2c481533e1ffb5b0e18109b40a3d12e106654bbf0673da28ce9ac46cae3b7cfc016dfec68adf5d444917188c70f8b534",
"ASM_UTIL_9.5" : {
"digest" : "sha512:f68284d8f8fd029f3f428112225b2035ed3a4216cf3b34e0aacc83c32a6d44ab5e5d128b60a13ef768e3396041a62cf63f7fd3445dc5a05ce0ae03a2b2ed3080",
"maven" : {
"groupId" : "org.ow2.asm",
"artifactId" : "asm-util",
"version" : "9.1",
"version" : "9.5",
},
"dependencies" : ["ASM_9.1"],
"dependencies" : ["ASM_9.5"],
},

"HSDIS" : {
Expand Down Expand Up @@ -1098,8 +1098,8 @@
"dependencies" : [
"org.graalvm.compiler.core.test",
"org.graalvm.compiler.replacements.amd64",
"ASM_TREE_9.1",
"ASM_UTIL_9.1",
"ASM_TREE_9.5",
"ASM_UTIL_9.5",
],
"requires" : [
"jdk.unsupported",
Expand Down Expand Up @@ -1493,8 +1493,8 @@
"org.graalvm.compiler.graph.test",
"org.graalvm.compiler.printer",
"JAVA_ALLOCATION_INSTRUMENTER",
"ASM_TREE_9.1",
"ASM_UTIL_9.1",
"ASM_TREE_9.5",
"ASM_UTIL_9.5",
],
"requires" : [
"jdk.unsupported",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
/*
* Copyright (c) 2019, 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 org.graalvm.compiler.api.directives.test;

import org.graalvm.compiler.api.directives.GraalDirectives;
import org.graalvm.compiler.core.test.GraalCompilerTest;
import org.graalvm.compiler.debug.GraalError;
import org.graalvm.compiler.graph.iterators.NodeIterable;
import org.graalvm.compiler.nodes.StructuredGraph;
import org.graalvm.compiler.nodes.extended.IntegerSwitchNode;
import org.graalvm.compiler.nodes.extended.SwitchCaseProbabilityNode;
import org.junit.Assert;
import org.junit.Test;

import jdk.vm.ci.meta.ResolvedJavaMethod;

public class SwitchCaseProbabilityDirectiveTest extends GraalCompilerTest {
/**
* Called before a test is compiled.
*/
@Override
protected void before(ResolvedJavaMethod method) {
// don't let -Xcomp pollute profile
method.reprofile();
}

public static int switchProbabilitySnippet1(int x) {
switch (x) {
case 0:
GraalDirectives.injectSwitchCaseProbability(0.5);
return 1;
case 1:
GraalDirectives.injectSwitchCaseProbability(0.3);
return 3;
case 2:
GraalDirectives.injectSwitchCaseProbability(0.1);
return x * 3;
default:
GraalDirectives.injectSwitchCaseProbability(0.1);
return x + 5;
}
}

public static int keyHoleSwitchSnippet(int x) {
switch (x) {
case 3:
GraalDirectives.injectSwitchCaseProbability(0.2);
return 10;
case 4:
GraalDirectives.injectSwitchCaseProbability(0.2);
return 20;
case 6:
GraalDirectives.injectSwitchCaseProbability(0.2);
return 30;
case 7:
GraalDirectives.injectSwitchCaseProbability(0.2);
return 40;
default:
GraalDirectives.injectSwitchCaseProbability(0.2);
return 42;
}
}

@Test
public void testSwitch() {
test("switchProbabilitySnippet1", 1);
test("keyHoleSwitchSnippet", 4);
}

public static int missingProbability(int x) {
switch (x) {
case 1:
GraalDirectives.injectSwitchCaseProbability(0.25);
return 10;
case 2:
GraalDirectives.injectSwitchCaseProbability(0.25);
return 20;
case 3:
GraalDirectives.injectSwitchCaseProbability(0.25);
return 3;
case 4:
GraalDirectives.injectSwitchCaseProbability(0.25);
return 15;
default:
/*
* No probability usage here, which is an error, even though the other branches'
* probability adds up to 1
*/
return 42;
}
}

public static int incorrectTotalProbability(int x) {
/*
* Total probability across branches should add up to 1, and if it doesn't an error should
* be thrown.
*/
switch (x) {
case 1:
GraalDirectives.injectSwitchCaseProbability(0.20);
return 10;
case 2:
GraalDirectives.injectSwitchCaseProbability(0.20);
return 20;
case 3:
GraalDirectives.injectSwitchCaseProbability(0.20);
return 3;
default:
GraalDirectives.injectSwitchCaseProbability(0.20);
return 42;
}
}

@Test(expected = GraalError.class)
public void testMissingProbability() {
test("missingProbability", 1);
}

@Test(expected = GraalError.class)
public void testIncorrectTotalProbability() {
test("incorrectTotalProbability", 3);
}

@Override
protected void checkLowTierGraph(StructuredGraph graph) {
NodeIterable<SwitchCaseProbabilityNode> switchProbabilityInjectionNodes = graph.getNodes().filter(SwitchCaseProbabilityNode.class);
Assert.assertEquals("SwitchCaseProbabilityNode count", 0, switchProbabilityInjectionNodes.count());

NodeIterable<IntegerSwitchNode> switchNodes = graph.getNodes().filter(IntegerSwitchNode.class);
Assert.assertEquals("IntegerSwitchNode count", 1, switchNodes.count());
IntegerSwitchNode switchNode = switchNodes.first();
for (int i = 0; i < switchNode.keyCount(); ++i) {
double expectedProbability = Double.NaN;
switch (switchNode.intKeyAt(i)) {
case 0:
expectedProbability = 0.5;
break;
case 1:
expectedProbability = 0.3;
break;
case 2:
expectedProbability = 0.1;
break;
case 3:
expectedProbability = 0.2;
break;
case 4:
expectedProbability = 0.2;
break;
case 5:
// Default probability should fill the hole and be divided in two
expectedProbability = 0.1;
break;
case 6:
expectedProbability = 0.2;
break;
case 7:
expectedProbability = 0.2;
break;
default:
GraalError.shouldNotReachHereUnexpectedValue(switchNode.intKeyAt(i));
}
Assert.assertEquals(expectedProbability, switchNode.keyProbability(i), 0.001);
}
Assert.assertEquals(0.1, switchNode.defaultProbability(), 0.001);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,37 @@ public static boolean injectIterationCount(double iterations, boolean condition)
return injectBranchProbability(1. - 1. / iterations, condition);
}

/**
* Injects a probability into the profiling information of a switch branch. The probability must
* be a value between 0.0 and 1.0 (inclusive). This directive should only be used as the first
* statement of each switch branch. Either all or none of the branches should contain a call to
* injectSwitchCaseProbability, and the sum of the values across all branches must be 1.0.
*
* Example usage:
*
* <code>
* int a = ...;
* switch (a) {
* case 0:
* GraalDirectives.injectSwitchCaseProbability(0.3);
* // ...
* break;
* case 10:
* GraalDirectives.injectSwitchCaseProbability(0.2);
* // ...
* break;
* default:
* GraalDirectives.injectSwitchCaseProbability(0.5);
* // ...
* break;
* }
* </code>
*
* @param probability the probability value between 0.0 and 1.0 that should be injected
*/
public static void injectSwitchCaseProbability(double probability) {
}

/**
* Consume a value, making sure the compiler doesn't optimize away the computation of this
* value, even if it is otherwise unused.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.graalvm.compiler.phases.common.inlining.InliningPhase;
import org.graalvm.compiler.phases.common.inlining.policy.InlineEverythingPolicy;
import org.graalvm.compiler.phases.tiers.HighTierContext;
import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Test;
Expand Down Expand Up @@ -120,7 +119,6 @@ public void testStandard() throws IOException {
@Test
public void testCompiled() throws IOException {
Assume.assumeFalse("Crashes on AArch64 (GR-8351)", System.getProperty("os.arch").equalsIgnoreCase("aarch64"));
Assume.assumeTrue("JDK-8259360", JavaVersionUtil.JAVA_SPEC < 16);
ResolvedJavaMethod getMethod = asResolvedJavaMethod(getMethod(ByteBuffer.class, "get", new Class<?>[]{}));
ResolvedJavaType mbbClass = getMetaAccess().lookupJavaType(MappedByteBuffer.class);
AssumptionResult<ResolvedJavaMethod> answer = mbbClass.findUniqueConcreteMethod(getMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,14 @@

import jdk.vm.ci.common.JVMCIError;
import jdk.vm.ci.meta.ResolvedJavaMethod;
import jdk.vm.ci.meta.ResolvedJavaType;
import jdk.vm.ci.meta.Signature;

/**
* Utility class that provides an abstraction layer for emitting code.
*/
public abstract class CodeBuffer {

/**
* Prefix for indent.
*/
public static final String INDENT_PREFIX = "\t";

/**
* Current indent level.
*/
Expand Down Expand Up @@ -128,9 +124,19 @@ public void emitCode(byte[] b) {
codeBytes.write(b, 0, b.length);
}

/**
* Emit whitespace for one level of indentation.
*/
protected void emitSingleIndent() {
emitText("\t");
}

/**
* Emit whitespace for the current level of indentation.
*/
private void emitIndent() {
for (int i = 0; i < scopeIndent; i++) {
emitText(INDENT_PREFIX);
emitSingleIndent();
}
}

Expand All @@ -150,12 +156,21 @@ public void emitStringLiteral(String s) {
emitText(getStringLiteral(s));
}

public void emitBoolLiteral(boolean b) {
emitText(b ? "true" : "false");
}

public void emitKeyword(Keyword keyword) {
emitText(keyword.toString());
}

public abstract void emitDeclarationPrefix();

@SuppressWarnings("unused")
public void emitDeclarationPrefix(ResolvedJavaType type) {
emitDeclarationPrefix();
}

public abstract void emitAnonymousClassHeader(String superClass);

/**
Expand Down Expand Up @@ -283,6 +298,14 @@ public void emitDeclPrefix(String name) {
emitWhiteSpace();
}

public void emitDeclPrefix(String name, ResolvedJavaType type) {
emitDeclarationPrefix(type);
emitDeclarationName(name);
emitWhiteSpace();
emitAssignmentSymbol();
emitWhiteSpace();
}

public abstract void emitAssignmentSymbol();

public void emitNew() {
Expand All @@ -301,6 +324,8 @@ public void emitTry() {

public abstract void emitCatch(String expName);

public abstract void emitCatch(String expName, ResolvedJavaType type);

/**
* Emit a simple linebreak.
*/
Expand Down
Loading

0 comments on commit 65b2eec

Please sign in to comment.