< prev index next >

test/jdk/java/foreign/TestUpcallHighArity.java

Print this page

  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 /*
 26  * @test
 27  * @enablePreview
 28  * @requires jdk.foreign.linker != "UNSUPPORTED"
 29  * @modules java.base/jdk.internal.foreign
 30  * @build NativeTestHelper CallGeneratorHelper TestUpcallHighArity
 31  *
 32  * @run testng/othervm/native
 33  *   --enable-native-access=ALL-UNNAMED
 34  *   TestUpcallHighArity
 35  */
 36 
 37 import java.lang.foreign.*;
 38 
 39 import org.testng.annotations.DataProvider;
 40 import org.testng.annotations.Test;
 41 
 42 import java.lang.invoke.MethodHandle;
 43 import java.lang.invoke.MethodType;
 44 import java.util.ArrayList;
 45 import java.util.List;
 46 import java.util.concurrent.atomic.AtomicReference;
 47 import java.util.function.Consumer;
 48 
 49 public class TestUpcallHighArity extends CallGeneratorHelper {
 50     static final MethodHandle MH_do_upcall;
 51     static final Linker LINKER = Linker.nativeLinker();
 52 
 53     // struct S_PDI { void* p0; double p1; int p2; };
 54     static final MemoryLayout S_PDI_LAYOUT = MemoryLayout.structLayout(
 55         C_POINTER.withName("p0"),
 56         C_DOUBLE.withName("p1"),
 57         C_INT.withName("p2"),
 58         MemoryLayout.paddingLayout(4)
 59     );
 60 
 61     static {
 62         System.loadLibrary("TestUpcallHighArity");
 63         MH_do_upcall = LINKER.downcallHandle(
 64                 findNativeOrThrow("do_upcall"),
 65                 FunctionDescriptor.ofVoid(C_POINTER,
 66                 S_PDI_LAYOUT, C_INT, C_DOUBLE, C_POINTER,
 67                 S_PDI_LAYOUT, C_INT, C_DOUBLE, C_POINTER,
 68                 S_PDI_LAYOUT, C_INT, C_DOUBLE, C_POINTER,
 69                 S_PDI_LAYOUT, C_INT, C_DOUBLE, C_POINTER)
 70         );
 71     }
 72 
 73     @Test(dataProvider = "args")
 74     public void testUpcall(MethodHandle downcall, MethodType upcallType,
 75                            FunctionDescriptor upcallDescriptor) throws Throwable {
 76         AtomicReference<Object[]> capturedArgs = new AtomicReference<>();
 77         try (Arena arena = Arena.ofConfined()) {
 78             Object[] args = new Object[upcallType.parameterCount() + 1];
 79             args[0] = makeArgSaverCB(upcallDescriptor, arena, capturedArgs, -1);

  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 /*
 26  * @test


 27  * @modules java.base/jdk.internal.foreign
 28  * @build NativeTestHelper CallGeneratorHelper TestUpcallHighArity
 29  *
 30  * @run testng/othervm/native
 31  *   --enable-native-access=ALL-UNNAMED
 32  *   TestUpcallHighArity
 33  */
 34 
 35 import java.lang.foreign.*;
 36 
 37 import org.testng.annotations.DataProvider;
 38 import org.testng.annotations.Test;
 39 
 40 import java.lang.invoke.MethodHandle;
 41 import java.lang.invoke.MethodType;
 42 import java.util.ArrayList;
 43 import java.util.List;
 44 import java.util.concurrent.atomic.AtomicReference;
 45 import java.util.function.Consumer;
 46 
 47 public class TestUpcallHighArity extends CallGeneratorHelper {
 48     static final MethodHandle MH_do_upcall;









 49 
 50     static {
 51         System.loadLibrary("TestUpcallHighArity");
 52         MH_do_upcall = LINKER.downcallHandle(
 53                 findNativeOrThrow("do_upcall"),
 54                 FunctionDescriptor.ofVoid(C_POINTER,
 55                 S_PDI_LAYOUT, C_INT, C_DOUBLE, C_POINTER,
 56                 S_PDI_LAYOUT, C_INT, C_DOUBLE, C_POINTER,
 57                 S_PDI_LAYOUT, C_INT, C_DOUBLE, C_POINTER,
 58                 S_PDI_LAYOUT, C_INT, C_DOUBLE, C_POINTER)
 59         );
 60     }
 61 
 62     @Test(dataProvider = "args")
 63     public void testUpcall(MethodHandle downcall, MethodType upcallType,
 64                            FunctionDescriptor upcallDescriptor) throws Throwable {
 65         AtomicReference<Object[]> capturedArgs = new AtomicReference<>();
 66         try (Arena arena = Arena.ofConfined()) {
 67             Object[] args = new Object[upcallType.parameterCount() + 1];
 68             args[0] = makeArgSaverCB(upcallDescriptor, arena, capturedArgs, -1);
< prev index next >