MemoryAccessProviderTest.java revision 12651:6ef01bd40ce2
199775Salfred/* 299775Salfred * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 399775Salfred * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 499775Salfred * 599775Salfred * This code is free software; you can redistribute it and/or modify it 699775Salfred * under the terms of the GNU General Public License version 2 only, as 799775Salfred * published by the Free Software Foundation. 899775Salfred * 999775Salfred * This code is distributed in the hope that it will be useful, but WITHOUT 1099775Salfred * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1199775Salfred * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1299775Salfred * version 2 for more details (a copy is included in the LICENSE file that 1399775Salfred * accompanied this code). 1499775Salfred * 1599775Salfred * You should have received a copy of the GNU General Public License version 1699775Salfred * 2 along with this work; if not, write to the Free Software Foundation, 1799775Salfred * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1899775Salfred * 1999775Salfred * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2099775Salfred * or visit www.oracle.com if you need additional information or have any 2199775Salfred * questions. 2299775Salfred */ 2399775Salfred 2499775Salfred/* 2599775Salfred * @test 2699775Salfred * @bug 8152341 2799775Salfred * @requires vm.jvmci 2899775Salfred * @library /test/lib /compiler/jvmci/jdk.vm.ci.hotspot.test/src 2999775Salfred * @modules jdk.internal.vm.ci/jdk.vm.ci.meta 3099775Salfred * jdk.internal.vm.ci/jdk.vm.ci.common 3199775Salfred * jdk.internal.vm.ci/jdk.vm.ci.runtime 3299775Salfred * jdk.internal.vm.ci/jdk.vm.ci.hotspot 3399775Salfred * java.base/jdk.internal.misc 3499775Salfred * @run testng/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI 3599775Salfred * jdk.vm.ci.hotspot.test.MemoryAccessProviderTest 3699775Salfred */ 3799775Salfred 3899775Salfredpackage jdk.vm.ci.hotspot.test; 3999775Salfred 4099775Salfredimport jdk.vm.ci.meta.Constant; 4199775Salfredimport jdk.vm.ci.meta.JavaKind; 4299775Salfredimport jdk.vm.ci.meta.MemoryAccessProvider; 4399775Salfredimport jdk.vm.ci.runtime.JVMCI; 4499775Salfredimport org.testng.Assert; 4599775Salfredimport org.testng.annotations.Test; 4699775Salfred 4799775Salfredpublic class MemoryAccessProviderTest { 4899775Salfred private static final MemoryAccessProvider PROVIDER = JVMCI.getRuntime().getHostJVMCIBackend().getConstantReflection().getMemoryAccessProvider(); 4999775Salfred 5099775Salfred @Test(dataProvider = "positivePrimitive", dataProviderClass = MemoryAccessProviderData.class) 5199775Salfred public void testPositiveReadPrimitiveConstant(JavaKind kind, Constant base, Long offset, Object expected, int bitsCount) { 5299775Salfred Assert.assertEquals(PROVIDER.readPrimitiveConstant(kind, base, offset, bitsCount), expected, "Failed to read constant"); 5399775Salfred } 5499775Salfred 5599775Salfred @Test(dataProvider = "positivePrimitive", dataProviderClass = MemoryAccessProviderData.class, expectedExceptions = {IllegalArgumentException.class}) 5699775Salfred public void testReadPrimitiveConstantNullBase(JavaKind kind, Constant base, Long offset, Object expected, int bitsCount) { 5799775Salfred Assert.assertNull(PROVIDER.readPrimitiveConstant(kind, null, offset, bitsCount), "Unexpected value for null base"); 5899775Salfred } 5999775Salfred 6099775Salfred @Test(dataProvider = "negative", dataProviderClass = MemoryAccessProviderData.class, expectedExceptions = {IllegalArgumentException.class}) 6199775Salfred public void testNegativeReadPrimitiveConstant(JavaKind kind, Constant base) { 6299775Salfred PROVIDER.readPrimitiveConstant(kind, base, 0L, kind == null ? 0 : kind.getBitCount()); 6399775Salfred } 6499775Salfred 6599775Salfred @Test(dataProvider = "positiveObject", dataProviderClass = MemoryAccessProviderData.class, expectedExceptions = {IllegalArgumentException.class}) 6699775Salfred public void testObjectReadPrimitiveConstant(JavaKind kind, Constant base, Long offset, Object expected, int bitsCount) { 6799775Salfred PROVIDER.readPrimitiveConstant(kind, base, 0L, bitsCount); 6899775Salfred } 6999775Salfred 7099775Salfred @Test(dataProvider = "positivePrimitive", dataProviderClass = MemoryAccessProviderData.class, expectedExceptions = {IllegalArgumentException.class}) 7199775Salfred public void testReadPrimitiveConstantLessBits(JavaKind kind, Constant base, Long offset, Object expected, int bitsCount) { 7299775Salfred PROVIDER.readPrimitiveConstant(kind, base, offset, bitsCount - 1); 7399775Salfred } 7499775Salfred 7599775Salfred @Test(dataProvider = "positiveObject", dataProviderClass = MemoryAccessProviderData.class) 7699775Salfred public void testPositiveReadObjectConstant(JavaKind kind, Constant base, Long offset, Object expected, int bitsCount) { 7799775Salfred Assert.assertEquals(PROVIDER.readObjectConstant(base, offset), expected, "Unexpected result"); 7899775Salfred } 7999775Salfred 8099775Salfred @Test(dataProvider = "positiveObject", dataProviderClass = MemoryAccessProviderData.class) 8199775Salfred public void testNegativeReadObjectConstantNullBase(JavaKind kind, Constant base, Long offset, Object expected, int bitsCount) { 8299775Salfred Assert.assertNull(PROVIDER.readObjectConstant(null, offset), "Unexpected return"); 8399775Salfred } 8499775Salfred 8599775Salfred @Test(dataProvider = "positiveObject", dataProviderClass = MemoryAccessProviderData.class) 8699775Salfred public void testNegativeReadObjectConstantWrongOffset(JavaKind kind, Constant base, Long offset, Object expected, int bitsCount) { 8799775Salfred Assert.assertNull(PROVIDER.readObjectConstant(base, offset + 1), "Expected null"); 8899775Salfred } 8999775Salfred 9099775Salfred @Test(dataProvider = "positivePrimitive", dataProviderClass = MemoryAccessProviderData.class) 9199775Salfred public void testNegativeReadObjectConstantPrimitiveBase(JavaKind kind, Constant base, Long offset, Object expected, int bitsCount) { 9299775Salfred Assert.assertNull(PROVIDER.readObjectConstant(base, offset), "Expected null"); 9399775Salfred } 9499775Salfred} 9599775Salfred