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.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  * @compile CodeInstallerTest.java
  33  * @run junit/othervm -da:jdk.vm.ci... -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI compiler.jvmci.errors.TestInvalidOopMap
  34  */
  35 
  36 package compiler.jvmci.errors;
  37 
  38 import jdk.vm.ci.code.BytecodePosition;
  39 import jdk.vm.ci.code.DebugInfo;
  40 import jdk.vm.ci.code.Location;
  41 import jdk.vm.ci.code.ReferenceMap;
  42 import jdk.vm.ci.code.Register;
  43 import jdk.vm.ci.code.StackSlot;
  44 import jdk.vm.ci.code.site.DataPatch;
  45 import jdk.vm.ci.code.site.Infopoint;
  46 import jdk.vm.ci.code.site.InfopointReason;
  47 import jdk.vm.ci.code.site.Site;
  48 import jdk.vm.ci.hotspot.HotSpotCompiledCode.Comment;
  49 import jdk.vm.ci.hotspot.HotSpotReferenceMap;
  50 import jdk.vm.ci.hotspot.HotSpotVMConfig;
  51 import jdk.vm.ci.meta.Assumptions.Assumption;
  52 import jdk.vm.ci.meta.JavaKind;
  53 import jdk.vm.ci.meta.PlatformKind;
  54 
  55 import org.junit.Test;
  56 
  57 /**
  58  * Tests for errors in oop maps.
  59  */
  60 public 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 = InternalError.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 = InternalError.class)
  98     public void testInvalidLength() {
  99         test(new HotSpotReferenceMap(new Location[1], new Location[2], new int[3], 8));
 100     }
 101 
 102     @Test(expected = InternalError.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     @Test(expected = InternalError.class)
 115     public void testInvalidNarrowDerivedOop() {
 116         if (!HotSpotVMConfig.config().useCompressedOops) {
 117             throw new InternalError("skipping test");
 118         }
 119 
 120         PlatformKind kind = arch.getPlatformKind(JavaKind.Int);
 121         Register reg = getRegister(kind, 0);
 122         Register baseReg = getRegister(arch.getPlatformKind(JavaKind.Object), 1);
 123 
 124         Location[] oops = new Location[]{Location.register(reg)};
 125         Location[] base = new Location[]{Location.register(baseReg)};
 126         int[] size = new int[]{kind.getSizeInBytes()};
 127 
 128         test(new HotSpotReferenceMap(oops, base, size, 8));
 129     }
 130 }