52578
|
1 |
/*
|
54084
|
2 |
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
|
52578
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
|
|
25 |
package org.graalvm.compiler.hotspot.lir.test;
|
|
26 |
|
|
27 |
import static org.graalvm.compiler.test.SubprocessUtil.getVMCommandLine;
|
|
28 |
import static org.graalvm.compiler.test.SubprocessUtil.withoutDebuggerArguments;
|
|
29 |
|
54084
|
30 |
import java.io.File;
|
57537
|
31 |
import java.io.IOException;
|
52578
|
32 |
import java.util.ArrayList;
|
|
33 |
import java.util.Iterator;
|
|
34 |
import java.util.List;
|
54084
|
35 |
import java.util.regex.Matcher;
|
|
36 |
import java.util.regex.Pattern;
|
52578
|
37 |
|
|
38 |
import org.graalvm.compiler.api.directives.GraalDirectives;
|
|
39 |
import org.graalvm.compiler.core.common.LIRKind;
|
|
40 |
import org.graalvm.compiler.hotspot.HotSpotBackend;
|
|
41 |
import org.graalvm.compiler.hotspot.debug.BenchmarkCounters;
|
|
42 |
import org.graalvm.compiler.lir.ConstantValue;
|
|
43 |
import org.graalvm.compiler.lir.gen.LIRGeneratorTool;
|
|
44 |
import org.graalvm.compiler.lir.jtt.LIRTest;
|
|
45 |
import org.graalvm.compiler.lir.jtt.LIRTestSpecification;
|
|
46 |
import org.graalvm.compiler.test.SubprocessUtil;
|
|
47 |
import org.junit.Assert;
|
|
48 |
import org.junit.Assume;
|
|
49 |
import org.junit.Before;
|
|
50 |
import org.junit.Test;
|
|
51 |
|
|
52 |
import jdk.vm.ci.amd64.AMD64;
|
|
53 |
import jdk.vm.ci.meta.JavaConstant;
|
|
54 |
import jdk.vm.ci.meta.JavaKind;
|
|
55 |
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
|
56 |
|
|
57 |
public class BenchmarkCounterOverflowTest extends LIRTest {
|
|
58 |
private static final String SUBPROCESS_PROPERTY = BenchmarkCounterOverflowTest.class.getSimpleName() + ".subprocess.call";
|
|
59 |
private static final boolean VERBOSE = Boolean.getBoolean(BenchmarkCounterOverflowTest.class.getSimpleName() + ".verbose");
|
|
60 |
|
|
61 |
private static LIRKind intKind;
|
|
62 |
|
|
63 |
@Before
|
|
64 |
public void checkAMD64() {
|
|
65 |
Assume.assumeTrue("skipping AMD64 specific test", getTarget().arch instanceof AMD64);
|
|
66 |
Assume.assumeTrue("skipping HotSpot specific test", getBackend() instanceof HotSpotBackend);
|
|
67 |
}
|
|
68 |
|
|
69 |
@Before
|
|
70 |
public void setUp() {
|
|
71 |
intKind = LIRKind.fromJavaKind(getBackend().getTarget().arch, JavaKind.Long);
|
|
72 |
}
|
|
73 |
|
|
74 |
private static final LIRTestSpecification constCounterIncrement = new LIRTestSpecification() {
|
|
75 |
@Override
|
|
76 |
public void generate(LIRGeneratorTool gen) {
|
|
77 |
gen.append(gen.createBenchmarkCounter("counter", "test", new ConstantValue(intKind, JavaConstant.forLong(Integer.MAX_VALUE))));
|
|
78 |
}
|
|
79 |
};
|
|
80 |
|
|
81 |
@SuppressWarnings("unused")
|
|
82 |
@LIRIntrinsic
|
|
83 |
public static void counterInc(LIRTestSpecification spec) {
|
|
84 |
}
|
|
85 |
|
|
86 |
public static void test(long count) {
|
|
87 |
for (long i = 0; i < count; i++) {
|
|
88 |
counterInc(constCounterIncrement);
|
|
89 |
GraalDirectives.blackhole(i);
|
|
90 |
}
|
|
91 |
}
|
|
92 |
|
|
93 |
@Test
|
|
94 |
public void incrementCounter() {
|
|
95 |
Assume.assumeTrue("not a subprocess -> skip", Boolean.getBoolean(SUBPROCESS_PROPERTY));
|
|
96 |
BenchmarkCounters.enabled = true;
|
|
97 |
|
|
98 |
Object[] args = new Object[]{Integer.MAX_VALUE * 4L};
|
|
99 |
ResolvedJavaMethod method = getResolvedJavaMethod("test");
|
|
100 |
executeActualCheckDeopt(getInitialOptions(), method, EMPTY, null, args);
|
|
101 |
}
|
|
102 |
|
|
103 |
@Test
|
57537
|
104 |
public void spawnSubprocess() throws IOException, InterruptedException {
|
52578
|
105 |
Assume.assumeFalse("subprocess already spawned -> skip", Boolean.getBoolean(SUBPROCESS_PROPERTY));
|
|
106 |
List<String> vmArgs = withoutDebuggerArguments(getVMCommandLine());
|
|
107 |
vmArgs.add("-XX:JVMCICounterSize=1");
|
|
108 |
vmArgs.add("-Dgraal." + BenchmarkCounters.Options.AbortOnBenchmarkCounterOverflow.getName() + "=true");
|
58299
|
109 |
vmArgs.addAll(SubprocessUtil.getPackageOpeningOptions());
|
52578
|
110 |
vmArgs.add("-D" + SUBPROCESS_PROPERTY + "=true");
|
|
111 |
|
|
112 |
// Disable increment range checks (e.g. HotSpotCounterOp.checkIncrements())
|
|
113 |
vmArgs.add("-dsa");
|
|
114 |
vmArgs.add("-da");
|
|
115 |
|
|
116 |
List<String> mainClassAndArgs = new ArrayList<>();
|
|
117 |
mainClassAndArgs.add("com.oracle.mxtool.junit.MxJUnitWrapper");
|
|
118 |
mainClassAndArgs.add(BenchmarkCounterOverflowTest.class.getName());
|
|
119 |
|
|
120 |
SubprocessUtil.Subprocess proc = SubprocessUtil.java(vmArgs, mainClassAndArgs);
|
|
121 |
|
|
122 |
if (VERBOSE) {
|
|
123 |
System.out.println(proc);
|
|
124 |
}
|
|
125 |
|
|
126 |
Assert.assertNotEquals("Expected non-zero exit status", 0, proc.exitCode);
|
|
127 |
|
|
128 |
Iterator<String> it = proc.output.iterator();
|
54084
|
129 |
boolean foundProblematicFrame = false;
|
52578
|
130 |
while (it.hasNext()) {
|
|
131 |
String line = it.next();
|
|
132 |
if (line.contains("Problematic frame:")) {
|
|
133 |
if (!it.hasNext()) {
|
|
134 |
// no more line
|
|
135 |
break;
|
|
136 |
}
|
|
137 |
line = it.next();
|
|
138 |
if (line.contains(BenchmarkCounterOverflowTest.class.getName() + ".test")) {
|
54084
|
139 |
foundProblematicFrame = true;
|
|
140 |
break;
|
52578
|
141 |
}
|
|
142 |
Assert.fail("Unexpected stack trace: " + line);
|
|
143 |
}
|
|
144 |
}
|
54084
|
145 |
// find and delete hserr file
|
|
146 |
while (it.hasNext()) {
|
|
147 |
String line = it.next();
|
|
148 |
if (line.contains("An error report file with more information is saved as:")) {
|
|
149 |
if (!it.hasNext()) {
|
|
150 |
// no more line
|
|
151 |
break;
|
|
152 |
}
|
|
153 |
line = it.next();
|
|
154 |
Pattern pattern = Pattern.compile("^# (.*hs_err_pid.*log)$");
|
|
155 |
Matcher matcher = pattern.matcher(line);
|
|
156 |
if (matcher.matches()) {
|
|
157 |
File hserrFile = new File(matcher.group(1));
|
|
158 |
if (hserrFile.exists()) {
|
|
159 |
if (VERBOSE) {
|
|
160 |
System.out.println("Deleting error report file:" + hserrFile.getAbsolutePath());
|
|
161 |
}
|
|
162 |
hserrFile.delete();
|
|
163 |
}
|
|
164 |
}
|
|
165 |
}
|
|
166 |
}
|
|
167 |
Assert.assertTrue(String.format("Could not find method in output:%n%s", proc), foundProblematicFrame);
|
52578
|
168 |
}
|
|
169 |
}
|