< prev index next >

test/jdk/java/foreign/handles/lookup_module/handle/lookup/MethodHandleLookup.java

Print this page

  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 package handle.lookup;
 25 
 26 import jdk.incubator.foreign.Addressable;
 27 import jdk.incubator.foreign.CLinker;
 28 
 29 import java.lang.invoke.MethodHandle;
 30 import java.lang.invoke.MethodHandles;
 31 import java.lang.invoke.MethodType;
 32 import java.nio.charset.Charset;
 33 import java.nio.file.Path;
 34 import java.util.Optional;
 35 
 36 import jdk.incubator.foreign.FunctionDescriptor;
 37 import jdk.incubator.foreign.SymbolLookup;
 38 import jdk.incubator.foreign.MemoryAddress;
 39 import jdk.incubator.foreign.MemoryLayout;
 40 import jdk.incubator.foreign.MemorySegment;
 41 import jdk.incubator.foreign.ResourceScope;
 42 import jdk.incubator.foreign.SegmentAllocator;
 43 


 44 import org.testng.annotations.*;
 45 
 46 public class MethodHandleLookup {
 47 
 48     @Test(dataProvider = "restrictedMethods")
 49     public void testRestrictedHandles(MethodHandle handle, String testName) throws Throwable {
 50         new handle.invoker.MethodHandleInvoker().call(handle);
 51     }
 52 
 53     @DataProvider(name = "restrictedMethods")
 54     static Object[][] restrictedMethods() {
 55         try {
 56             return new Object[][]{
 57                     { MethodHandles.lookup().findStatic(CLinker.class, "getInstance",
 58                             MethodType.methodType(CLinker.class)), "CLinker::getInstance" },
 59                     { MethodHandles.lookup().findStatic(CLinker.class, "toJavaString",
 60                             MethodType.methodType(String.class, MemoryAddress.class)),
 61                             "CLinker::toJavaString" },
 62                     { MethodHandles.lookup().findStatic(CLinker.class, "allocateMemory",
 63                             MethodType.methodType(MemoryAddress.class, long.class)),
 64                             "CLinker::allocateMemory" },
 65                     { MethodHandles.lookup().findStatic(CLinker.class, "freeMemory",
 66                             MethodType.methodType(void.class, MemoryAddress.class)),
 67                             "CLinker::freeMemory" },
 68                     { MethodHandles.lookup().findStatic(CLinker.VaList.class, "ofAddress",
 69                             MethodType.methodType(CLinker.VaList.class, MemoryAddress.class)),
 70                             "VaList::ofAddress/1" },
 71                     { MethodHandles.lookup().findStatic(CLinker.VaList.class, "ofAddress",
 72                             MethodType.methodType(CLinker.VaList.class, MemoryAddress.class, ResourceScope.class)),
 73                             "VaList::ofAddress/2" },
 74                     { MethodHandles.lookup().findStatic(CLinker.class, "systemLookup",
 75                             MethodType.methodType(SymbolLookup.class)),
 76                             "CLinker::systemLookup" },
 77                     { MethodHandles.lookup().findStatic(SymbolLookup.class, "loaderLookup",
 78                             MethodType.methodType(SymbolLookup.class)),
 79                             "SymbolLookup::loaderLookup" },
 80                     { MethodHandles.lookup().findVirtual(MemoryAddress.class, "asSegment",
 81                             MethodType.methodType(MemorySegment.class, long.class, ResourceScope.class)),
 82                             "MemoryAddress::asSegment/1" },
 83                     { MethodHandles.lookup().findVirtual(MemoryAddress.class, "asSegment",
 84                             MethodType.methodType(MemorySegment.class, long.class, Runnable.class, ResourceScope.class)),
 85                             "MemoryAddress::asSegment/2" },
 86                     { MethodHandles.lookup().findStatic(MemorySegment.class, "globalNativeSegment",
 87                             MethodType.methodType(MemorySegment.class)),
 88                             "MemoryAddress::globalNativeSegment" }






















































 89             };
 90         } catch (Throwable ex) {
 91             throw new ExceptionInInitializerError((ex));
 92         }
 93     }
 94 }

  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 package handle.lookup;
 25 

 26 import jdk.incubator.foreign.CLinker;
 27 
 28 import java.lang.invoke.MethodHandle;
 29 import java.lang.invoke.MethodHandles;
 30 import java.lang.invoke.MethodType;



 31 
 32 import jdk.incubator.foreign.Addressable;
 33 import jdk.incubator.foreign.SymbolLookup;
 34 import jdk.incubator.foreign.MemoryAddress;

 35 import jdk.incubator.foreign.MemorySegment;
 36 import jdk.incubator.foreign.ResourceScope;

 37 
 38 import jdk.incubator.foreign.VaList;
 39 import jdk.incubator.foreign.ValueLayout;
 40 import org.testng.annotations.*;
 41 
 42 public class MethodHandleLookup {
 43 
 44     @Test(dataProvider = "restrictedMethods")
 45     public void testRestrictedHandles(MethodHandle handle, String testName) throws Throwable {
 46         new handle.invoker.MethodHandleInvoker().call(handle);
 47     }
 48 
 49     @DataProvider(name = "restrictedMethods")
 50     static Object[][] restrictedMethods() {
 51         try {
 52             return new Object[][]{
 53                     { MethodHandles.lookup().findStatic(CLinker.class, "systemCLinker",
 54                             MethodType.methodType(CLinker.class)), "ForeignLinker::systemCLinker" },
 55                     { MethodHandles.lookup().findStatic(VaList.class, "ofAddress",
 56                             MethodType.methodType(VaList.class, MemoryAddress.class, ResourceScope.class)),









 57                             "VaList::ofAddress/1" },






 58                     { MethodHandles.lookup().findStatic(SymbolLookup.class, "loaderLookup",
 59                             MethodType.methodType(SymbolLookup.class)),
 60                             "SymbolLookup::loaderLookup" },
 61                     { MethodHandles.lookup().findStatic(MemorySegment.class, "ofAddressNative",
 62                             MethodType.methodType(MemorySegment.class, MemoryAddress.class, long.class, ResourceScope.class)),
 63                             "MemorySegment::ofAddressNative" },
 64                     { MethodHandles.lookup().findVirtual(MemoryAddress.class, "getUtf8String",
 65                             MethodType.methodType(String.class, long.class)),
 66                             "MemoryAddress::getUtf8String" },
 67                     { MethodHandles.lookup().findVirtual(MemoryAddress.class, "setUtf8String",
 68                             MethodType.methodType(void.class, long.class, String.class)),
 69                             "MemoryAddress::setUtf8String" },
 70                     { MethodHandles.lookup().findVirtual(MemoryAddress.class, "get",
 71                             MethodType.methodType(byte.class, ValueLayout.OfByte.class, long.class)),
 72                             "MemoryAddress::get/byte" },
 73                     { MethodHandles.lookup().findVirtual(MemoryAddress.class, "get",
 74                             MethodType.methodType(boolean.class, ValueLayout.OfBoolean.class, long.class)),
 75                             "MemoryAddress::get/boolean" },
 76                     { MethodHandles.lookup().findVirtual(MemoryAddress.class, "get",
 77                             MethodType.methodType(char.class, ValueLayout.OfChar.class, long.class)),
 78                             "MemoryAddress::get/char" },
 79                     { MethodHandles.lookup().findVirtual(MemoryAddress.class, "get",
 80                             MethodType.methodType(short.class, ValueLayout.OfShort.class, long.class)),
 81                             "MemoryAddress::get/short" },
 82                     { MethodHandles.lookup().findVirtual(MemoryAddress.class, "get",
 83                             MethodType.methodType(int.class, ValueLayout.OfInt.class, long.class)),
 84                             "MemoryAddress::get/int" },
 85                     { MethodHandles.lookup().findVirtual(MemoryAddress.class, "get",
 86                             MethodType.methodType(float.class, ValueLayout.OfFloat.class, long.class)),
 87                             "MemoryAddress::get/float" },
 88                     { MethodHandles.lookup().findVirtual(MemoryAddress.class, "get",
 89                             MethodType.methodType(long.class, ValueLayout.OfLong.class, long.class)),
 90                             "MemoryAddress::get/long" },
 91                     { MethodHandles.lookup().findVirtual(MemoryAddress.class, "get",
 92                             MethodType.methodType(double.class, ValueLayout.OfDouble.class, long.class)),
 93                             "MemoryAddress::get/double" },
 94                     { MethodHandles.lookup().findVirtual(MemoryAddress.class, "get",
 95                             MethodType.methodType(MemoryAddress.class, ValueLayout.OfAddress.class, long.class)),
 96                             "MemoryAddress::get/address" },
 97                     { MethodHandles.lookup().findVirtual(MemoryAddress.class, "set",
 98                             MethodType.methodType(void.class, ValueLayout.OfByte.class, long.class, byte.class)),
 99                             "MemoryAddress::set/byte" },
100                     { MethodHandles.lookup().findVirtual(MemoryAddress.class, "set",
101                             MethodType.methodType(void.class, ValueLayout.OfBoolean.class, long.class, boolean.class)),
102                             "MemoryAddress::set/boolean" },
103                     { MethodHandles.lookup().findVirtual(MemoryAddress.class, "set",
104                             MethodType.methodType(void.class, ValueLayout.OfChar.class, long.class, char.class)),
105                             "MemoryAddress::set/char" },
106                     { MethodHandles.lookup().findVirtual(MemoryAddress.class, "set",
107                             MethodType.methodType(void.class, ValueLayout.OfShort.class, long.class, short.class)),
108                             "MemoryAddress::set/short" },
109                     { MethodHandles.lookup().findVirtual(MemoryAddress.class, "set",
110                             MethodType.methodType(void.class, ValueLayout.OfInt.class, long.class, int.class)),
111                             "MemoryAddress::set/int" },
112                     { MethodHandles.lookup().findVirtual(MemoryAddress.class, "set",
113                             MethodType.methodType(void.class, ValueLayout.OfFloat.class, long.class, float.class)),
114                             "MemoryAddress::set/float" },
115                     { MethodHandles.lookup().findVirtual(MemoryAddress.class, "set",
116                             MethodType.methodType(void.class, ValueLayout.OfLong.class, long.class, long.class)),
117                             "MemoryAddress::set/long" },
118                     { MethodHandles.lookup().findVirtual(MemoryAddress.class, "set",
119                             MethodType.methodType(void.class, ValueLayout.OfDouble.class, long.class, double.class)),
120                             "MemoryAddress::set/double" },
121                     { MethodHandles.lookup().findVirtual(MemoryAddress.class, "set",
122                             MethodType.methodType(void.class, ValueLayout.OfAddress.class, long.class, Addressable.class)),
123                             "MemoryAddress::set/address" },
124             };
125         } catch (Throwable ex) {
126             throw new ExceptionInInitializerError((ex));
127         }
128     }
129 }
< prev index next >