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.arch != "aarch64"
  27  * @compile CodeInstallationTest.java TestAssembler.java amd64/AMD64TestAssembler.java sparc/SPARCTestAssembler.java
  28  * @run junit/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI compiler.jvmci.code.DataPatchTest
  29  */
  30 
  31 package compiler.jvmci.code;
  32 
  33 import jdk.vm.ci.code.Register;
  34 import jdk.vm.ci.code.site.DataSectionReference;
  35 import jdk.vm.ci.hotspot.HotSpotConstant;


  36 import jdk.vm.ci.hotspot.HotSpotVMConfig;
  37 import jdk.vm.ci.meta.ResolvedJavaType;
  38 
  39 import org.junit.Assume;
  40 import org.junit.Test;
  41 
  42 /**
  43  * Test code installation with data patches.
  44  */
  45 public class DataPatchTest extends CodeInstallationTest {
  46 
  47     public static Class<?> getConstClass() {
  48         return DataPatchTest.class;
  49     }
  50 
  51     private void test(TestCompiler compiler) {
  52         test(compiler, getMethod("getConstClass"));
  53     }
  54 
  55     @Test
  56     public void testInlineObject() {
  57         test(asm -> {
  58             ResolvedJavaType type = metaAccess.lookupJavaType(getConstClass());
  59             HotSpotConstant c = (HotSpotConstant) constantReflection.asJavaClass(type);
  60             Register ret = asm.emitLoadPointer(c);
  61             asm.emitPointerRet(ret);
  62         });
  63     }
  64 
  65     @Test
  66     public void testInlineNarrowObject() {
  67         Assume.assumeTrue(HotSpotVMConfig.config().useCompressedOops);
  68         test(asm -> {
  69             ResolvedJavaType type = metaAccess.lookupJavaType(getConstClass());
  70             HotSpotConstant c = (HotSpotConstant) constantReflection.asJavaClass(type);
  71             Register compressed = asm.emitLoadPointer((HotSpotConstant) c.compress());
  72             Register ret = asm.emitUncompressPointer(compressed, HotSpotVMConfig.config().narrowOopBase, HotSpotVMConfig.config().narrowOopShift);
  73             asm.emitPointerRet(ret);
  74         });
  75     }
  76 
  77     @Test
  78     public void testDataSectionReference() {
  79         test(asm -> {
  80             ResolvedJavaType type = metaAccess.lookupJavaType(getConstClass());
  81             HotSpotConstant c = (HotSpotConstant) constantReflection.asJavaClass(type);
  82             DataSectionReference ref = asm.emitDataItem(c);
  83             Register ret = asm.emitLoadPointer(ref);
  84             asm.emitPointerRet(ret);
  85         });
  86     }
  87 
  88     @Test
  89     public void testNarrowDataSectionReference() {
  90         Assume.assumeTrue(HotSpotVMConfig.config().useCompressedOops);
  91         test(asm -> {
  92             ResolvedJavaType type = metaAccess.lookupJavaType(getConstClass());
  93             HotSpotConstant c = (HotSpotConstant) constantReflection.asJavaClass(type);
  94             HotSpotConstant cCompressed = (HotSpotConstant) c.compress();
  95             DataSectionReference ref = asm.emitDataItem(cCompressed);
  96             Register compressed = asm.emitLoadNarrowPointer(ref);
  97             Register ret = asm.emitUncompressPointer(compressed, HotSpotVMConfig.config().narrowOopBase, HotSpotVMConfig.config().narrowOopShift);
  98             asm.emitPointerRet(ret);
  99         });
 100     }
 101 
 102     @Test
 103     public void testInlineMetadata() {
 104         test(asm -> {
 105             ResolvedJavaType type = metaAccess.lookupJavaType(getConstClass());
 106             Register klass = asm.emitLoadPointer((HotSpotConstant) constantReflection.asObjectHub(type));
 107             Register ret = asm.emitLoadPointer(klass, HotSpotVMConfig.config().classMirrorOffset);
 108             asm.emitPointerRet(ret);
 109         });
 110     }
 111 
 112     @Test
 113     public void testInlineNarrowMetadata() {
 114         Assume.assumeTrue(HotSpotVMConfig.config().useCompressedClassPointers);
 115         test(asm -> {
 116             ResolvedJavaType type = metaAccess.lookupJavaType(getConstClass());
 117             HotSpotConstant hub = (HotSpotConstant) constantReflection.asObjectHub(type);
 118             Register narrowKlass = asm.emitLoadPointer((HotSpotConstant) hub.compress());
 119             Register klass = asm.emitUncompressPointer(narrowKlass, HotSpotVMConfig.config().narrowKlassBase, HotSpotVMConfig.config().narrowKlassShift);
 120             Register ret = asm.emitLoadPointer(klass, HotSpotVMConfig.config().classMirrorOffset);
 121             asm.emitPointerRet(ret);
 122         });
 123     }
 124 
 125     @Test
 126     public void testMetadataInDataSection() {
 127         test(asm -> {
 128             ResolvedJavaType type = metaAccess.lookupJavaType(getConstClass());
 129             HotSpotConstant hub = (HotSpotConstant) constantReflection.asObjectHub(type);
 130             DataSectionReference ref = asm.emitDataItem(hub);
 131             Register klass = asm.emitLoadPointer(ref);
 132             Register ret = asm.emitLoadPointer(klass, HotSpotVMConfig.config().classMirrorOffset);
 133             asm.emitPointerRet(ret);
 134         });
 135     }
 136 
 137     @Test
 138     public void testNarrowMetadataInDataSection() {
 139         Assume.assumeTrue(HotSpotVMConfig.config().useCompressedClassPointers);
 140         test(asm -> {
 141             ResolvedJavaType type = metaAccess.lookupJavaType(getConstClass());
 142             HotSpotConstant hub = (HotSpotConstant) constantReflection.asObjectHub(type);
 143             HotSpotConstant narrowHub = (HotSpotConstant) hub.compress();
 144             DataSectionReference ref = asm.emitDataItem(narrowHub);
 145             Register narrowKlass = asm.emitLoadNarrowPointer(ref);
 146             Register klass = asm.emitUncompressPointer(narrowKlass, HotSpotVMConfig.config().narrowKlassBase, HotSpotVMConfig.config().narrowKlassShift);
 147             Register ret = asm.emitLoadPointer(klass, HotSpotVMConfig.config().classMirrorOffset);





























 148             asm.emitPointerRet(ret);
 149         });
 150     }
 151 }
--- EOF ---