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