1 /* 2 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. 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 * @test 26 * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9" | os.simpleArch == "aarch64") 27 * @modules jdk.vm.ci/jdk.vm.ci.code 28 * jdk.vm.ci/jdk.vm.ci.code.site 29 * jdk.vm.ci/jdk.vm.ci.meta 30 * jdk.vm.ci/jdk.vm.ci.runtime 31 * jdk.vm.ci/jdk.vm.ci.common 32 * jdk.vm.ci.hotspot/jdk.vm.ci.hotspot 33 * @compile CodeInstallerTest.java 34 * @run junit/othervm -da:jdk.vm.ci... -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI compiler.jvmci.errors.TestInvalidOopMap 35 */ 36 37 package compiler.jvmci.errors; 38 39 import jdk.vm.ci.code.BytecodePosition; 40 import jdk.vm.ci.code.DebugInfo; 41 import jdk.vm.ci.code.Location; 42 import jdk.vm.ci.code.ReferenceMap; 43 import jdk.vm.ci.code.Register; 44 import jdk.vm.ci.code.StackSlot; 45 import jdk.vm.ci.code.site.DataPatch; 46 import jdk.vm.ci.code.site.Infopoint; 47 import jdk.vm.ci.code.site.InfopointReason; 48 import jdk.vm.ci.code.site.Site; 49 import jdk.vm.ci.common.JVMCIError; 50 import jdk.vm.ci.hotspot.HotSpotCompiledCode.Comment; 51 import jdk.vm.ci.hotspot.HotSpotReferenceMap; 52 import jdk.vm.ci.hotspot.HotSpotVMConfig; 53 import jdk.vm.ci.meta.Assumptions.Assumption; 54 import jdk.vm.ci.meta.JavaKind; 55 import jdk.vm.ci.meta.PlatformKind; 56 57 import org.junit.Test; 58 59 /** 60 * Tests for errors in oop maps. 61 */ 62 public class TestInvalidOopMap extends CodeInstallerTest { 63 64 private static class InvalidReferenceMap extends ReferenceMap { 65 } 66 67 private void test(ReferenceMap refMap) { 68 BytecodePosition pos = new BytecodePosition(null, dummyMethod, 0); 69 DebugInfo info = new DebugInfo(pos); 70 info.setReferenceMap(refMap); 71 installEmptyCode(new Site[]{new Infopoint(0, info, InfopointReason.SAFEPOINT)}, new Assumption[0], new Comment[0], 16, new DataPatch[0], StackSlot.get(null, 0, true)); 72 } 73 74 @Test(expected = NullPointerException.class) 75 public void testMissingReferenceMap() { 76 test(null); 77 } 78 79 @Test(expected = JVMCIError.class) 80 public void testInvalidReferenceMap() { 81 test(new InvalidReferenceMap()); 82 } 83 84 @Test(expected = NullPointerException.class) 85 public void testNullOops() { 86 test(new HotSpotReferenceMap(null, new Location[0], new int[0], 8)); 87 } 88 89 @Test(expected = NullPointerException.class) 90 public void testNullBase() { 91 test(new HotSpotReferenceMap(new Location[0], null, new int[0], 8)); 92 } 93 94 @Test(expected = NullPointerException.class) 95 public void testNullSize() { 96 test(new HotSpotReferenceMap(new Location[0], new Location[0], null, 8)); 97 } 98 99 @Test(expected = JVMCIError.class) 100 public void testInvalidLength() { 101 test(new HotSpotReferenceMap(new Location[1], new Location[2], new int[3], 8)); 102 } 103 104 @Test(expected = JVMCIError.class) 105 public void testInvalidShortOop() { 106 PlatformKind kind = arch.getPlatformKind(JavaKind.Short); 107 Register reg = getRegister(kind, 0); 108 109 Location[] oops = new Location[]{Location.register(reg)}; 110 Location[] base = new Location[]{null}; 111 int[] size = new int[]{kind.getSizeInBytes()}; 112 113 test(new HotSpotReferenceMap(oops, base, size, 8)); 114 } 115 116 @Test(expected = JVMCIError.class) 117 public void testInvalidNarrowDerivedOop() { 118 if (!HotSpotVMConfig.config().useCompressedOops) { 119 throw new JVMCIError("skipping test"); 120 } 121 122 PlatformKind kind = arch.getPlatformKind(JavaKind.Int); 123 Register reg = getRegister(kind, 0); 124 Register baseReg = getRegister(arch.getPlatformKind(JavaKind.Object), 1); 125 126 Location[] oops = new Location[]{Location.register(reg)}; 127 Location[] base = new Location[]{Location.register(baseReg)}; 128 int[] size = new int[]{kind.getSizeInBytes()}; 129 130 test(new HotSpotReferenceMap(oops, base, size, 8)); 131 } 132 }