< prev index next >

test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessDouble.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 21,31 **** * questions. */ /* * @test ! * @run testng/othervm -Diters=20000 VarHandleTestMethodHandleAccessDouble */ import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; --- 21,31 ---- * questions. */ /* * @test ! * @run testng/othervm -Xint -Diters=2000 VarHandleTestMethodHandleAccessDouble */ import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test;
*** 55,64 **** --- 55,66 ---- VarHandle vhStaticFinalField; VarHandle vhArray; + VarHandle vhValueTypeField; + @BeforeClass public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodHandleAccessDouble.class, "final_v", double.class);
*** 70,79 **** --- 72,84 ---- vhStaticField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestMethodHandleAccessDouble.class, "static_v", double.class); vhArray = MethodHandles.arrayElementVarHandle(double[].class); + + vhValueTypeField = MethodHandles.lookup().findVarHandle( + Value.class, "double_v", double.class); } @DataProvider public Object[][] accessTestCaseProvider() throws Exception {
*** 98,107 **** --- 103,117 ---- vhArray, f, VarHandleTestMethodHandleAccessDouble::testArrayUnsupported, false)); cases.add(new MethodHandleAccessTestCase("Array index out of bounds", vhArray, f, VarHandleTestMethodHandleAccessDouble::testArrayIndexOutOfBounds, false)); + cases.add(new MethodHandleAccessTestCase("Value type field", + vhValueTypeField, f, hs -> testValueTypeField(Value.VT, hs))); + cases.add(new MethodHandleAccessTestCase("Value type field unsupported", + vhValueTypeField, f, hs -> testValueTypeFieldUnsupported(Value.VT, hs), + false)); } // Work around issue with jtreg summary reporting which truncates // the String result of Object.toString to 30 characters, hence // the first dummy argument
*** 293,302 **** --- 303,335 ---- double r = (double) hs.get(am).invokeExact(recv, 1.0d); }); } } + static void testValueTypeField(Value recv, Handles hs) throws Throwable { + // Plain + { + double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv); + assertEquals(x, 1.0d, "get double value"); + } + } + + static void testValueTypeFieldUnsupported(Value recv, Handles hs) throws Throwable { + // Plain + for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) { + checkUOE(am, () -> { + hs.get(am).invokeExact(recv, 1.0d); + }); + } + + + for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) { + checkUOE(am, () -> { + double r = (double) hs.get(am).invokeExact(recv, 1.0d); + }); + } + } static void testStaticField(Handles hs) throws Throwable { // Plain { hs.get(TestAccessMode.SET).invokeExact(1.0d);
< prev index next >