< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/JVMCIInfopointErrorTest.java

Print this page




   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.test;
  26 

  27 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.REG;
  28 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.STACK;
  29 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_IGNORED;
  30 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_IGNORED;
  31 
  32 import java.util.function.Consumer;
  33 
  34 import org.graalvm.compiler.code.CompilationResult;
  35 import org.graalvm.compiler.core.common.LIRKind;
  36 import org.graalvm.compiler.core.common.type.StampFactory;
  37 import org.graalvm.compiler.core.test.GraalCompilerTest;
  38 import org.graalvm.compiler.debug.DebugContext;
  39 import org.graalvm.compiler.debug.DebugContext.Scope;
  40 import org.graalvm.compiler.debug.DebugHandlersFactory;
  41 import org.graalvm.compiler.graph.NodeClass;
  42 import org.graalvm.compiler.hotspot.HotSpotCompiledCodeBuilder;
  43 import org.graalvm.compiler.lir.FullInfopointOp;
  44 import org.graalvm.compiler.lir.LIRFrameState;
  45 import org.graalvm.compiler.lir.LIRInstruction;
  46 import org.graalvm.compiler.lir.LIRInstructionClass;
  47 import org.graalvm.compiler.lir.Variable;
  48 import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
  49 import org.graalvm.compiler.lir.gen.LIRGeneratorTool;
  50 import org.graalvm.compiler.nodeinfo.NodeInfo;
  51 import org.graalvm.compiler.nodes.DeoptimizingFixedWithNextNode;
  52 import org.graalvm.compiler.nodes.StructuredGraph;
  53 import org.graalvm.compiler.nodes.spi.LIRLowerable;
  54 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;

  55 import org.junit.Test;
  56 
  57 import jdk.vm.ci.code.BytecodeFrame;
  58 import jdk.vm.ci.code.CodeCacheProvider;
  59 import jdk.vm.ci.code.VirtualObject;
  60 import jdk.vm.ci.code.site.InfopointReason;
  61 import jdk.vm.ci.common.JVMCIError;
  62 import jdk.vm.ci.hotspot.HotSpotCompiledCode;
  63 import jdk.vm.ci.meta.AllocatableValue;
  64 import jdk.vm.ci.meta.JavaConstant;
  65 import jdk.vm.ci.meta.JavaKind;
  66 import jdk.vm.ci.meta.JavaValue;
  67 import jdk.vm.ci.meta.PlatformKind;
  68 import jdk.vm.ci.meta.ResolvedJavaMethod;
  69 import jdk.vm.ci.meta.ResolvedJavaType;
  70 import jdk.vm.ci.meta.Value;
  71 
  72 public class JVMCIInfopointErrorTest extends GraalCompilerTest {
  73 
  74     private static class ValueDef extends LIRInstruction {


 122             LIRGeneratorTool tool = gen.getLIRGeneratorTool();
 123             LIRFrameState state = gen.state(this);
 124             spec.spec(tool, state, st -> {
 125                 tool.append(new FullInfopointOp(st, InfopointReason.SAFEPOINT));
 126             });
 127         }
 128     }
 129 
 130     @FunctionalInterface
 131     private interface TestSpec {
 132         void spec(LIRGeneratorTool tool, LIRFrameState state, Consumer<LIRFrameState> safepoint);
 133     }
 134 
 135     public static void testMethod() {
 136     }
 137 
 138     private void test(TestSpec spec) {
 139         test(getDebugContext(), spec);
 140     }
 141 








 142     private void test(DebugContext debug, TestSpec spec) {
 143         ResolvedJavaMethod method = getResolvedJavaMethod("testMethod");
 144 
 145         StructuredGraph graph = parseForCompile(method, debug);
 146         TestNode test = graph.add(new TestNode(spec));
 147         graph.addAfterFixed(graph.start(), test);
 148 
 149         CompilationResult compResult = compile(method, graph);
 150         CodeCacheProvider codeCache = getCodeCache();
 151         HotSpotCompiledCode compiledCode = HotSpotCompiledCodeBuilder.createCompiledCode(codeCache, method, null, compResult, getInitialOptions());
 152         codeCache.addCode(method, compiledCode, null, null);
 153     }
 154 
 155     @Test(expected = Error.class)
 156     public void testInvalidShortOop() {
 157         test((tool, state, safepoint) -> {
 158             PlatformKind kind = tool.target().arch.getPlatformKind(JavaKind.Short);
 159             LIRKind lirKind = LIRKind.reference(kind);
 160 
 161             Variable var = tool.newVariable(lirKind);
 162             tool.append(new ValueDef(var));
 163             safepoint.accept(state);
 164             tool.append(new ValueUse(var));
 165         });
 166     }
 167 
 168     @Test(expected = Error.class)
 169     public void testInvalidShortDerivedOop() {
 170         test((tool, state, safepoint) -> {
 171             Variable baseOop = tool.newVariable(LIRKind.fromJavaKind(tool.target().arch, JavaKind.Object));
 172             tool.append(new ValueDef(baseOop));
 173 
 174             PlatformKind kind = tool.target().arch.getPlatformKind(JavaKind.Short);
 175             LIRKind lirKind = LIRKind.derivedReference(kind, baseOop, false);
 176 
 177             Variable var = tool.newVariable(lirKind);
 178             tool.append(new ValueDef(var));
 179             safepoint.accept(state);
 180             tool.append(new ValueUse(var));
 181         });
 182     }
 183 
 184     private static LIRFrameState modifyTopFrame(LIRFrameState state, JavaValue[] values, JavaKind[] slotKinds, int locals, int stack, int locks) {
 185         return modifyTopFrame(state, null, values, slotKinds, locals, stack, locks);
 186     }
 187 
 188     private static LIRFrameState modifyTopFrame(LIRFrameState state, VirtualObject[] vobj, JavaValue[] values, JavaKind[] slotKinds, int locals, int stack, int locks) {
 189         BytecodeFrame top = state.topFrame;
 190         top = new BytecodeFrame(top.caller(), top.getMethod(), top.getBCI(), top.rethrowException, top.duringCall, values, slotKinds, locals, stack, locks);




   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.test;
  26 
  27 import static org.graalvm.compiler.debug.DebugOptions.DumpOnError;
  28 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.REG;
  29 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.STACK;
  30 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_IGNORED;
  31 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_IGNORED;
  32 
  33 import java.util.function.Consumer;
  34 
  35 import org.graalvm.compiler.code.CompilationResult;
  36 import org.graalvm.compiler.core.common.LIRKind;
  37 import org.graalvm.compiler.core.common.type.StampFactory;
  38 import org.graalvm.compiler.core.test.GraalCompilerTest;
  39 import org.graalvm.compiler.debug.DebugContext;
  40 import org.graalvm.compiler.debug.DebugContext.Scope;
  41 import org.graalvm.compiler.debug.DebugHandlersFactory;
  42 import org.graalvm.compiler.graph.NodeClass;
  43 import org.graalvm.compiler.hotspot.HotSpotCompiledCodeBuilder;
  44 import org.graalvm.compiler.lir.FullInfopointOp;
  45 import org.graalvm.compiler.lir.LIRFrameState;
  46 import org.graalvm.compiler.lir.LIRInstruction;
  47 import org.graalvm.compiler.lir.LIRInstructionClass;
  48 import org.graalvm.compiler.lir.Variable;
  49 import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
  50 import org.graalvm.compiler.lir.gen.LIRGeneratorTool;
  51 import org.graalvm.compiler.nodeinfo.NodeInfo;
  52 import org.graalvm.compiler.nodes.DeoptimizingFixedWithNextNode;
  53 import org.graalvm.compiler.nodes.StructuredGraph;
  54 import org.graalvm.compiler.nodes.spi.LIRLowerable;
  55 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
  56 import org.graalvm.compiler.options.OptionValues;
  57 import org.junit.Test;
  58 
  59 import jdk.vm.ci.code.BytecodeFrame;
  60 import jdk.vm.ci.code.CodeCacheProvider;
  61 import jdk.vm.ci.code.VirtualObject;
  62 import jdk.vm.ci.code.site.InfopointReason;
  63 import jdk.vm.ci.common.JVMCIError;
  64 import jdk.vm.ci.hotspot.HotSpotCompiledCode;
  65 import jdk.vm.ci.meta.AllocatableValue;
  66 import jdk.vm.ci.meta.JavaConstant;
  67 import jdk.vm.ci.meta.JavaKind;
  68 import jdk.vm.ci.meta.JavaValue;
  69 import jdk.vm.ci.meta.PlatformKind;
  70 import jdk.vm.ci.meta.ResolvedJavaMethod;
  71 import jdk.vm.ci.meta.ResolvedJavaType;
  72 import jdk.vm.ci.meta.Value;
  73 
  74 public class JVMCIInfopointErrorTest extends GraalCompilerTest {
  75 
  76     private static class ValueDef extends LIRInstruction {


 124             LIRGeneratorTool tool = gen.getLIRGeneratorTool();
 125             LIRFrameState state = gen.state(this);
 126             spec.spec(tool, state, st -> {
 127                 tool.append(new FullInfopointOp(st, InfopointReason.SAFEPOINT));
 128             });
 129         }
 130     }
 131 
 132     @FunctionalInterface
 133     private interface TestSpec {
 134         void spec(LIRGeneratorTool tool, LIRFrameState state, Consumer<LIRFrameState> safepoint);
 135     }
 136 
 137     public static void testMethod() {
 138     }
 139 
 140     private void test(TestSpec spec) {
 141         test(getDebugContext(), spec);
 142     }
 143 
 144     /**
 145      * Avoids dumping during tests which are expected to fail.
 146      */
 147     private void testNoDump(TestSpec spec) {
 148         OptionValues options = new OptionValues(getInitialOptions(), DumpOnError, false);
 149         test(getDebugContext(options, null, null), spec);
 150     }
 151 
 152     private void test(DebugContext debug, TestSpec spec) {
 153         ResolvedJavaMethod method = getResolvedJavaMethod("testMethod");
 154 
 155         StructuredGraph graph = parseForCompile(method, debug);
 156         TestNode test = graph.add(new TestNode(spec));
 157         graph.addAfterFixed(graph.start(), test);
 158 
 159         CompilationResult compResult = compile(method, graph);
 160         CodeCacheProvider codeCache = getCodeCache();
 161         HotSpotCompiledCode compiledCode = HotSpotCompiledCodeBuilder.createCompiledCode(codeCache, method, null, compResult, getInitialOptions());
 162         codeCache.addCode(method, compiledCode, null, null);
 163     }
 164 
 165     @Test(expected = Error.class)
 166     public void testInvalidShortOop() {
 167         testNoDump((tool, state, safepoint) -> {
 168             PlatformKind kind = tool.target().arch.getPlatformKind(JavaKind.Short);
 169             LIRKind lirKind = LIRKind.reference(kind);
 170 
 171             Variable var = tool.newVariable(lirKind);
 172             tool.append(new ValueDef(var));
 173             safepoint.accept(state);
 174             tool.append(new ValueUse(var));
 175         });
 176     }
 177 
 178     @Test(expected = Error.class)
 179     public void testInvalidShortDerivedOop() {
 180         testNoDump((tool, state, safepoint) -> {
 181             Variable baseOop = tool.newVariable(LIRKind.fromJavaKind(tool.target().arch, JavaKind.Object));
 182             tool.append(new ValueDef(baseOop));
 183 
 184             PlatformKind kind = tool.target().arch.getPlatformKind(JavaKind.Short);
 185             LIRKind lirKind = LIRKind.derivedReference(kind, baseOop, false);
 186 
 187             Variable var = tool.newVariable(lirKind);
 188             tool.append(new ValueDef(var));
 189             safepoint.accept(state);
 190             tool.append(new ValueUse(var));
 191         });
 192     }
 193 
 194     private static LIRFrameState modifyTopFrame(LIRFrameState state, JavaValue[] values, JavaKind[] slotKinds, int locals, int stack, int locks) {
 195         return modifyTopFrame(state, null, values, slotKinds, locals, stack, locks);
 196     }
 197 
 198     private static LIRFrameState modifyTopFrame(LIRFrameState state, VirtualObject[] vobj, JavaValue[] values, JavaKind[] slotKinds, int locals, int stack, int locks) {
 199         BytecodeFrame top = state.topFrame;
 200         top = new BytecodeFrame(top.caller(), top.getMethod(), top.getBCI(), top.rethrowException, top.duringCall, values, slotKinds, locals, stack, locks);


< prev index next >