Path: blob/master/test/hotspot/jtreg/compiler/jvmci/errors/TestInvalidCompilationResult.java
41152 views
/*1* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @requires vm.jvmci26* @modules jdk.internal.vm.ci/jdk.vm.ci.hotspot27* jdk.internal.vm.ci/jdk.vm.ci.code28* jdk.internal.vm.ci/jdk.vm.ci.code.site29* jdk.internal.vm.ci/jdk.vm.ci.meta30* jdk.internal.vm.ci/jdk.vm.ci.runtime31* jdk.internal.vm.ci/jdk.vm.ci.common32* @compile CodeInstallerTest.java33* @run junit/othervm -da:jdk.vm.ci... -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI34* -XX:-UseJVMCICompiler compiler.jvmci.errors.TestInvalidCompilationResult35*/3637package compiler.jvmci.errors;3839import jdk.vm.ci.code.StackSlot;40import jdk.vm.ci.code.site.ConstantReference;41import jdk.vm.ci.code.site.DataPatch;42import jdk.vm.ci.code.site.DataSectionReference;43import jdk.vm.ci.code.site.Infopoint;44import jdk.vm.ci.code.site.InfopointReason;45import jdk.vm.ci.code.site.Mark;46import jdk.vm.ci.code.site.Reference;47import jdk.vm.ci.code.site.Site;48import jdk.vm.ci.common.JVMCIError;49import jdk.vm.ci.hotspot.HotSpotCompiledCode.Comment;50import jdk.vm.ci.hotspot.HotSpotConstant;51import jdk.vm.ci.meta.Assumptions.Assumption;52import jdk.vm.ci.meta.VMConstant;53import org.junit.Test;5455/**56* Tests for errors in the code installer.57*/58public class TestInvalidCompilationResult extends CodeInstallerTest {5960private static class InvalidAssumption extends Assumption {61}6263private static class InvalidVMConstant implements VMConstant {6465public boolean isDefaultForKind() {66return false;67}6869public String toValueString() {70return null;71}72}7374private static class InvalidReference extends Reference {7576@Override77public int hashCode() {78return 0;79}8081@Override82public boolean equals(Object obj) {83return false;84}85}8687@Test(expected = JVMCIError.class)88public void testInvalidAssumption() {89installEmptyCode(new Site[0], new Assumption[]{new InvalidAssumption()}, new Comment[0], 16, new DataPatch[0], null);90}9192@Test(expected = JVMCIError.class)93public void testInvalidAlignment() {94installEmptyCode(new Site[0], new Assumption[0], new Comment[0], 7, new DataPatch[0], null);95}9697@Test(expected = NullPointerException.class)98public void testNullDataPatchInDataSection() {99installEmptyCode(new Site[0], new Assumption[0], new Comment[0], 16, new DataPatch[]{null}, null);100}101102@Test(expected = NullPointerException.class)103public void testNullReferenceInDataSection() {104installEmptyCode(new Site[0], new Assumption[0], new Comment[0], 16, new DataPatch[]{new DataPatch(0, null)}, null);105}106107@Test(expected = JVMCIError.class)108public void testInvalidDataSectionReference() {109DataSectionReference ref = new DataSectionReference();110ref.setOffset(0);111installEmptyCode(new Site[0], new Assumption[0], new Comment[0], 16, new DataPatch[]{new DataPatch(0, ref)}, null);112}113114@Test(expected = JVMCIError.class)115public void testInvalidNarrowMethodInDataSection() {116HotSpotConstant c = (HotSpotConstant) dummyMethod.getEncoding();117ConstantReference ref = new ConstantReference((VMConstant) c.compress());118installEmptyCode(new Site[0], new Assumption[0], new Comment[0], 16, new DataPatch[]{new DataPatch(0, ref)}, null);119}120121@Test(expected = NullPointerException.class)122public void testNullConstantInDataSection() {123ConstantReference ref = new ConstantReference(null);124installEmptyCode(new Site[0], new Assumption[0], new Comment[0], 16, new DataPatch[]{new DataPatch(0, ref)}, null);125}126127@Test(expected = JVMCIError.class)128public void testInvalidConstantInDataSection() {129ConstantReference ref = new ConstantReference(new InvalidVMConstant());130installEmptyCode(new Site[0], new Assumption[0], new Comment[0], 16, new DataPatch[]{new DataPatch(0, ref)}, null);131}132133@Test(expected = NullPointerException.class)134public void testNullReferenceInCode() {135installEmptyCode(new Site[]{new DataPatch(0, null)}, new Assumption[0], new Comment[0], 16, new DataPatch[0], null);136}137138@Test(expected = NullPointerException.class)139public void testNullConstantInCode() {140ConstantReference ref = new ConstantReference(null);141installEmptyCode(new Site[]{new DataPatch(0, ref)}, new Assumption[0], new Comment[0], 16, new DataPatch[0], null);142}143144@Test(expected = JVMCIError.class)145public void testInvalidConstantInCode() {146ConstantReference ref = new ConstantReference(new InvalidVMConstant());147installEmptyCode(new Site[]{new DataPatch(0, ref)}, new Assumption[0], new Comment[0], 16, new DataPatch[0], null);148}149150@Test(expected = JVMCIError.class)151public void testInvalidReference() {152InvalidReference ref = new InvalidReference();153installEmptyCode(new Site[]{new DataPatch(0, ref)}, new Assumption[0], new Comment[0], 16, new DataPatch[0], null);154}155156@Test(expected = JVMCIError.class)157public void testOutOfBoundsDataSectionReference() {158DataSectionReference ref = new DataSectionReference();159ref.setOffset(0x1000);160installEmptyCode(new Site[]{new DataPatch(0, ref)}, new Assumption[0], new Comment[0], 16, new DataPatch[0], null);161}162163@Test(expected = JVMCIError.class)164public void testInvalidMark() {165installEmptyCode(new Site[]{new Mark(0, new Object())}, new Assumption[0], new Comment[0], 16, new DataPatch[0], null);166}167168@Test(expected = JVMCIError.class)169public void testInvalidMarkInt() {170installEmptyCode(new Site[]{new Mark(0, -1)}, new Assumption[0], new Comment[0], 16, new DataPatch[0], null);171}172173@Test(expected = NullPointerException.class)174public void testNullSite() {175installEmptyCode(new Site[]{null}, new Assumption[0], new Comment[0], 16, new DataPatch[0], null);176}177178@Test(expected = JVMCIError.class)179public void testInfopointMissingDebugInfo() {180Infopoint info = new Infopoint(0, null, InfopointReason.METHOD_START);181installEmptyCode(new Site[]{info}, new Assumption[0], new Comment[0], 16, new DataPatch[0], null);182}183184@Test(expected = JVMCIError.class)185public void testSafepointMissingDebugInfo() {186Infopoint info = new Infopoint(0, null, InfopointReason.SAFEPOINT);187StackSlot deoptRescueSlot = StackSlot.get(null, 0, true);188installEmptyCode(new Site[]{info}, new Assumption[0], new Comment[0], 16, new DataPatch[0], deoptRescueSlot);189}190191@Test(expected = JVMCIError.class)192public void testInvalidDeoptRescueSlot() {193StackSlot deoptRescueSlot = StackSlot.get(null, -1, false);194installEmptyCode(new Site[]{}, new Assumption[0], new Comment[0], 16, new DataPatch[0], deoptRescueSlot);195}196}197198199