43972
|
1 |
/*
|
57537
|
2 |
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
|
43972
|
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 |
*/
|
50858
|
23 |
|
|
24 |
|
43972
|
25 |
package org.graalvm.compiler.hotspot.lir.test;
|
|
26 |
|
|
27 |
import org.junit.Test;
|
|
28 |
|
|
29 |
import org.graalvm.compiler.core.common.LIRKind;
|
|
30 |
import org.graalvm.compiler.hotspot.HotSpotBackend;
|
|
31 |
import org.graalvm.compiler.lir.framemap.FrameMapBuilder;
|
|
32 |
import org.graalvm.compiler.lir.gen.LIRGeneratorTool;
|
|
33 |
import org.graalvm.compiler.lir.jtt.LIRTest;
|
|
34 |
import org.graalvm.compiler.lir.jtt.LIRTestSpecification;
|
|
35 |
import org.graalvm.compiler.nodes.SafepointNode;
|
|
36 |
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
|
|
37 |
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
|
|
38 |
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
|
|
39 |
|
|
40 |
import jdk.vm.ci.code.BailoutException;
|
|
41 |
import jdk.vm.ci.meta.AllocatableValue;
|
|
42 |
import jdk.vm.ci.meta.JavaConstant;
|
|
43 |
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
|
44 |
|
|
45 |
public class ExceedMaxOopMapStackOffset extends LIRTest {
|
|
46 |
|
|
47 |
/**
|
|
48 |
* Allocate lots of stacks slots and initialize them with a constant.
|
|
49 |
*/
|
|
50 |
private static class WriteStackSlotsSpec extends LIRTestSpecification {
|
|
51 |
private final JavaConstant constant;
|
|
52 |
|
|
53 |
WriteStackSlotsSpec(JavaConstant constant) {
|
|
54 |
this.constant = constant;
|
|
55 |
}
|
|
56 |
|
|
57 |
@Override
|
|
58 |
public void generate(LIRGeneratorTool gen) {
|
|
59 |
FrameMapBuilder frameMapBuilder = gen.getResult().getFrameMapBuilder();
|
|
60 |
LIRKind lirKind = LIRKind.reference(gen.target().arch.getPlatformKind(constant.getJavaKind()));
|
|
61 |
// create slots
|
|
62 |
for (int i = 0; i < slots.length; i++) {
|
|
63 |
AllocatableValue src = gen.emitLoadConstant(lirKind, constant);
|
|
64 |
slots[i] = frameMapBuilder.allocateSpillSlot(lirKind);
|
|
65 |
gen.emitMove(slots[i], src);
|
|
66 |
}
|
|
67 |
}
|
|
68 |
}
|
|
69 |
|
|
70 |
/**
|
|
71 |
* Read stacks slots and move their content into a blackhole.
|
|
72 |
*/
|
|
73 |
private static class ReadStackSlotsSpec extends LIRTestSpecification {
|
|
74 |
|
|
75 |
ReadStackSlotsSpec() {
|
|
76 |
}
|
|
77 |
|
|
78 |
@Override
|
|
79 |
public void generate(LIRGeneratorTool gen) {
|
|
80 |
for (int i = 0; i < slots.length; i++) {
|
|
81 |
gen.emitBlackhole(gen.emitMove(slots[i]));
|
|
82 |
}
|
|
83 |
}
|
|
84 |
}
|
|
85 |
|
|
86 |
@Override
|
|
87 |
protected GraphBuilderConfiguration editGraphBuilderConfiguration(GraphBuilderConfiguration conf) {
|
|
88 |
InvocationPlugin safepointPlugin = new InvocationPlugin() {
|
|
89 |
@Override
|
|
90 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
|
|
91 |
b.add(new SafepointNode());
|
|
92 |
return true;
|
|
93 |
}
|
|
94 |
};
|
|
95 |
conf.getPlugins().getInvocationPlugins().register(safepointPlugin, getClass(), "safepoint");
|
|
96 |
return super.editGraphBuilderConfiguration(conf);
|
|
97 |
}
|
|
98 |
|
|
99 |
/*
|
|
100 |
* Safepoint Snippet
|
|
101 |
*/
|
|
102 |
private static void safepoint() {
|
|
103 |
}
|
|
104 |
|
|
105 |
private static AllocatableValue[] slots;
|
|
106 |
|
|
107 |
private static final LIRTestSpecification readStackObjects = new ReadStackSlotsSpec();
|
|
108 |
|
|
109 |
@SuppressWarnings("unused")
|
|
110 |
@LIRIntrinsic
|
|
111 |
public static void instrinsic(LIRTestSpecification spec) {
|
|
112 |
}
|
|
113 |
|
|
114 |
private static final LIRTestSpecification writeStackObjects = new WriteStackSlotsSpec(JavaConstant.NULL_POINTER);
|
|
115 |
|
|
116 |
public void testStackObjects() {
|
|
117 |
instrinsic(writeStackObjects);
|
|
118 |
safepoint();
|
|
119 |
instrinsic(readStackObjects);
|
|
120 |
}
|
|
121 |
|
|
122 |
@Test
|
57537
|
123 |
public void runStackObjects() {
|
43972
|
124 |
int max = ((HotSpotBackend) getBackend()).getRuntime().getVMConfig().maxOopMapStackOffset;
|
|
125 |
if (max == Integer.MAX_VALUE) {
|
|
126 |
max = 16 * 1024 - 64;
|
|
127 |
}
|
|
128 |
try {
|
|
129 |
int numSlots = (max / 8) + 1;
|
|
130 |
slots = new AllocatableValue[numSlots];
|
|
131 |
runTest("testStackObjects");
|
|
132 |
} catch (BailoutException e) {
|
|
133 |
return;
|
|
134 |
}
|
|
135 |
fail("Expected exception BailoutException wasn't thrown");
|
|
136 |
}
|
|
137 |
}
|