1 /* 2 * Copyright (c) 2018, 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 // Android-added: package for test. 25 package test.java.lang.invoke.VarHandles; 26 27 /* 28 * @test 29 * @bug 8195650 30 * @summary Test linking of method references to VarHandle access methods. 31 * @run testng VarHandleMethodReferenceTest 32 */ 33 34 import org.testng.annotations.Test; 35 36 import java.lang.invoke.*; 37 38 public class VarHandleMethodReferenceTest { 39 40 interface R { apply()41 void apply(); 42 } 43 44 @Test testMethodReferences()45 public void testMethodReferences() { 46 VarHandle vh = MethodHandles.arrayElementVarHandle(int[].class); 47 48 // The compilation of these method references will result in the 49 // placement of MethodHandles in the constant pool that reference 50 // VarHandle signature polymorphic methods. 51 // When those constant method handles are loaded the VarHandle invoker 52 // mechanism will be used where the first argument to invocation will be 53 // the bound VarHandle instance 54 55 // VarHandle invokers are tested by other test classes so here it 56 // is just necessary to check that functional objects can be successfully 57 // obtained, it does not matter about the signature of the functional 58 // interface 59 60 R r; 61 r = vh::get; 62 r = vh::set; 63 r = vh::getVolatile; 64 r = vh::setVolatile; 65 r = vh::getOpaque; 66 r = vh::setOpaque; 67 r = vh::getAcquire; 68 r = vh::setRelease; 69 70 r = vh::compareAndSet; 71 r = vh::compareAndExchange; 72 r = vh::compareAndExchangeAcquire; 73 r = vh::compareAndExchangeRelease; 74 r = vh::weakCompareAndSetPlain; 75 r = vh::weakCompareAndSet; 76 r = vh::weakCompareAndSetAcquire; 77 r = vh::weakCompareAndSetRelease; 78 79 r = vh::getAndSet; 80 r = vh::getAndSetAcquire; 81 r = vh::getAndSetRelease; 82 r = vh::getAndAdd; 83 r = vh::getAndAddAcquire; 84 r = vh::getAndAddRelease; 85 r = vh::getAndBitwiseOr; 86 r = vh::getAndBitwiseOrAcquire; 87 r = vh::getAndBitwiseOrRelease; 88 r = vh::getAndBitwiseAnd; 89 r = vh::getAndBitwiseAndAcquire; 90 r = vh::getAndBitwiseAndRelease; 91 r = vh::getAndBitwiseXor; 92 r = vh::getAndBitwiseXorAcquire; 93 r = vh::getAndBitwiseXorRelease; 94 } 95 } 96