< prev index next >

test/jdk/java/nicl/Upcall/StructUpcall.java

Print this page




  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  * @test
  26  * @modules java.base/jdk.internal.misc
  27  * @run main/othervm StructUpcall
  28  */
  29 
  30 import java.lang.invoke.MethodHandles;
  31 import java.nicl.Libraries;
  32 import java.nicl.NativeTypes;
  33 import java.nicl.Scope;
  34 import java.nicl.metadata.C;
  35 import java.nicl.metadata.CallingConvention;
  36 import java.nicl.metadata.NativeHeader;


  37 import java.nicl.metadata.NativeType;
  38 import java.nicl.metadata.Offset;
  39 import java.nicl.types.LayoutType;
  40 import java.nicl.types.Pointer;
  41 import java.nicl.types.Struct;
  42 
  43 public class StructUpcall {
  44     private static final boolean DEBUG = false;
  45 
  46     @NativeHeader
  47     public static interface Index {
  48         @NativeType(layout="[iiippp]", ctype="dummy", size=40, isRecordType=true)
  49         @C(file="dummy", line=47, column=11, USR="C:@S@MyStruct")
  50         static interface MyStruct extends Struct<MyStruct> {
  51             @Offset(offset=0l)
  52             @C(file="dummy", line=47, column=11, USR="c:@SA@MyStruct@FI@field1")
  53             @NativeType(layout="i", ctype="enum MyStructField1", size=4l)
  54             int field1$get();
  55             void field1$set(int i);
  56 
  57             @Offset(offset=32l)
  58             @C(file="dummy", line=47, column=11, USR="c:@SA@MyStruct@FI@field2")
  59             @NativeType(layout="i", ctype="int", size=4l)
  60             int field2$get();
  61             void field2$set(int i);
  62 
  63             @Offset(offset=64l)
  64             @C(file="dummy", line=47, column=11, USR="c:@SA@MyStruct@FI@field3")
  65             @NativeType(layout="i", ctype="int", size=4l)
  66             int field3$get();
  67             void field3$set(int i);
  68 
  69             @Offset(offset=128l)
  70             @C(file="dummy", line=47, column=11, USR="c:@SA@MyStruct@FI@field4")
  71             @NativeType(layout="p", ctype="const void *", size=8l)
  72             Pointer<Void> field4$get();
  73             void field4$set(Pointer<?> p);
  74 
  75             @Offset(offset=192l)
  76             @C(file="dummy", line=47, column=11, USR="c:@SA@MyStruct@FI@field5")
  77             @NativeType(layout="p", ctype="const void *", size=8l)
  78             Pointer<Void> field5$get();
  79             void field5$set(Pointer<?> p);
  80 
  81             @Offset(offset=256l)
  82             @C(file="dummy", line=47, column=11, USR="c:@SA@MyStruct@FI@field6")
  83             @NativeType(layout="p", ctype="const void *", size=8l)
  84             Pointer<Void> field6$get();
  85             void field6$set(Pointer<?> p);
  86         }
  87 

  88         @FunctionalInterface
  89         static interface MyStructVisitor {
  90             @C(file="dummy", line=47, column=11, USR="c:@F@slowsort")
  91             @NativeType(layout="([iiippp])V", ctype="void (dummy)", size=4l)
  92             @CallingConvention(value=1)
  93             public void fn(MyStruct s);
  94         }
  95 
  96         @C(file="dummy", line=47, column=11, USR="c:@F@struct_upcall")
  97         @NativeType(layout="(p:([iiip:Vp:Vp:V])V[iiip:Vp:Vp:V])V", ctype="void (struct_upcall_cb, struct MyStruct)", name="struct_upcall", size=1)
  98         @CallingConvention(value=1)
  99         public abstract void struct_upcall(MyStructVisitor v, MyStruct s);
 100     }
 101 
 102 
 103     public static class MyStructVisitorImpl implements Index.MyStructVisitor {
 104         MyStructVisitorImpl() {
 105         }
 106 
 107         @Override
 108         public void fn(Index.MyStruct s) {
 109             if (DEBUG) {
 110                 System.err.println("visit(" + s + ")");
 111                 System.err.println("\ts.field1  = " + s.field1$get());
 112                 System.err.println("\ts.field2 = " + s.field2$get());
 113                 System.err.println("\ts.field3 = " + s.field3$get());
 114                 System.err.println("\ts.field4 = " + s.field4$get().cast(NativeTypes.INT8).get());
 115                 System.err.println("\ts.field5 = " + s.field5$get().cast(NativeTypes.INT8).get());
 116                 System.err.println("\ts.field6 = " + s.field6$get().cast(NativeTypes.INT8).get());
 117             }
 118 




  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  * @test
  26  * @modules java.base/jdk.internal.misc
  27  * @run main/othervm StructUpcall
  28  */
  29 
  30 import java.lang.invoke.MethodHandles;
  31 import java.nicl.Libraries;
  32 import java.nicl.NativeTypes;
  33 import java.nicl.Scope;
  34 import java.nicl.metadata.NativeCallback;

  35 import java.nicl.metadata.NativeHeader;
  36 import java.nicl.metadata.NativeLocation;
  37 import java.nicl.metadata.NativeStruct;
  38 import java.nicl.metadata.NativeType;
  39 import java.nicl.metadata.Offset;
  40 import java.nicl.types.LayoutType;
  41 import java.nicl.types.Pointer;
  42 import java.nicl.types.Struct;
  43 
  44 public class StructUpcall {
  45     private static final boolean DEBUG = false;
  46 
  47     @NativeHeader
  48     public static interface Index {
  49         @NativeLocation(file="dummy", line=47, column=11, USR="C:@S@MyStruct")
  50         @NativeStruct("[iiippp]")
  51         static interface MyStruct extends Struct<MyStruct> {
  52             @Offset(offset=0l)
  53             @NativeLocation(file="dummy", line=47, column=11, USR="c:@SA@MyStruct@FI@field1")
  54             @NativeType(layout="i", ctype="enum MyStructField1")
  55             int field1$get();
  56             void field1$set(int i);
  57 
  58             @Offset(offset=32l)
  59             @NativeLocation(file="dummy", line=47, column=11, USR="c:@SA@MyStruct@FI@field2")
  60             @NativeType(layout="i", ctype="int")
  61             int field2$get();
  62             void field2$set(int i);
  63 
  64             @Offset(offset=64l)
  65             @NativeLocation(file="dummy", line=47, column=11, USR="c:@SA@MyStruct@FI@field3")
  66             @NativeType(layout="i", ctype="int")
  67             int field3$get();
  68             void field3$set(int i);
  69 
  70             @Offset(offset=128l)
  71             @NativeLocation(file="dummy", line=47, column=11, USR="c:@SA@MyStruct@FI@field4")
  72             @NativeType(layout="p", ctype="const void *")
  73             Pointer<Void> field4$get();
  74             void field4$set(Pointer<?> p);
  75 
  76             @Offset(offset=192l)
  77             @NativeLocation(file="dummy", line=47, column=11, USR="c:@SA@MyStruct@FI@field5")
  78             @NativeType(layout="p", ctype="const void *")
  79             Pointer<Void> field5$get();
  80             void field5$set(Pointer<?> p);
  81 
  82             @Offset(offset=256l)
  83             @NativeLocation(file="dummy", line=47, column=11, USR="c:@SA@MyStruct@FI@field6")
  84             @NativeType(layout="p", ctype="const void *")
  85             Pointer<Void> field6$get();
  86             void field6$set(Pointer<?> p);
  87         }
  88 
  89         @NativeCallback("([iiippp])V")
  90         @FunctionalInterface
  91         static interface MyStructVisitor {
  92             @NativeLocation(file="dummy", line=47, column=11, USR="c:@F@slowsort")


  93             public void fn(MyStruct s);
  94         }
  95 
  96         @NativeLocation(file="dummy", line=47, column=11, USR="c:@F@struct_upcall")
  97         @NativeType(layout="(p:([iiip:Vp:Vp:V])V[iiip:Vp:Vp:V])V", ctype="void (struct_upcall_cb, struct MyStruct)", name="struct_upcall")

  98         public abstract void struct_upcall(MyStructVisitor v, MyStruct s);
  99     }
 100 
 101 
 102     public static class MyStructVisitorImpl implements Index.MyStructVisitor {
 103         MyStructVisitorImpl() {
 104         }
 105 
 106         @Override
 107         public void fn(Index.MyStruct s) {
 108             if (DEBUG) {
 109                 System.err.println("visit(" + s + ")");
 110                 System.err.println("\ts.field1  = " + s.field1$get());
 111                 System.err.println("\ts.field2 = " + s.field2$get());
 112                 System.err.println("\ts.field3 = " + s.field3$get());
 113                 System.err.println("\ts.field4 = " + s.field4$get().cast(NativeTypes.INT8).get());
 114                 System.err.println("\ts.field5 = " + s.field5$get().cast(NativeTypes.INT8).get());
 115                 System.err.println("\ts.field6 = " + s.field6$get().cast(NativeTypes.INT8).get());
 116             }
 117 


< prev index next >