< prev index next >

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

Print this page




  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  * @test
  26  * @run main/othervm Upcall
  27  */
  28 
  29 import java.lang.invoke.MethodHandles;
  30 import java.nicl.Libraries;
  31 import java.nicl.metadata.C;
  32 import java.nicl.metadata.CallingConvention;
  33 import java.nicl.metadata.NativeHeader;

  34 import java.nicl.metadata.NativeType;
  35 
  36 public class Upcall {
  37     private static final boolean DEBUG = false;
  38 
  39     private static final int MAGIC_INTEGER = 4711;
  40 
  41     @NativeHeader
  42     public static interface upcall {

  43         @FunctionalInterface
  44         static interface visitor {
  45             @C(file="dummy", line=47, column=11, USR="c:@F@slowsort")
  46             @NativeType(layout="(i)V", ctype="void (int)", size=4l)
  47             @CallingConvention(value=1)
  48             public void fn(int i);
  49         }
  50 
  51         @C(file="dummy", line=47, column=11, USR="c:@F@do_upcall")
  52         @NativeType(layout="(p:(i)Vi)V", ctype="void (visitor, int)", name="do_upcall", size=1)
  53         @CallingConvention(value=1)
  54         public abstract void do_upcall(visitor v, int i);
  55     }
  56 
  57     public static class visitorImpl implements upcall.visitor {
  58         boolean called = false;
  59 
  60         @Override
  61         public void fn(int i) {
  62             called = true;
  63 
  64             if (DEBUG) {
  65                 System.err.println("visit(" + i + ")");
  66             }
  67 
  68             // value passed up from native code
  69             assertEquals(i, MAGIC_INTEGER);
  70         }
  71     }
  72 
  73     public void test() {




  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  * @test
  26  * @run main/othervm Upcall
  27  */
  28 
  29 import java.lang.invoke.MethodHandles;
  30 import java.nicl.Libraries;
  31 import java.nicl.metadata.NativeCallback;

  32 import java.nicl.metadata.NativeHeader;
  33 import java.nicl.metadata.NativeLocation;
  34 import java.nicl.metadata.NativeType;
  35 
  36 public class Upcall {
  37     private static final boolean DEBUG = false;
  38 
  39     private static final int MAGIC_INTEGER = 4711;
  40 
  41     @NativeHeader
  42     public static interface upcall {
  43         @NativeCallback("(i)V")
  44         @FunctionalInterface
  45         static interface visitor {
  46             @NativeLocation(file="dummy", line=47, column=11, USR="c:@F@slowsort")


  47             public void fn(int i);
  48         }
  49 
  50         @NativeLocation(file="dummy", line=47, column=11, USR="c:@F@do_upcall")
  51         @NativeType(layout="(p:(i)Vi)V", ctype="void (visitor, int)", name="do_upcall")

  52         public abstract void do_upcall(visitor v, int i);
  53     }
  54 
  55     public static class visitorImpl implements upcall.visitor {
  56         boolean called = false;
  57 
  58         @Override
  59         public void fn(int i) {
  60             called = true;
  61 
  62             if (DEBUG) {
  63                 System.err.println("visit(" + i + ")");
  64             }
  65 
  66             // value passed up from native code
  67             assertEquals(i, MAGIC_INTEGER);
  68         }
  69     }
  70 
  71     public void test() {


< prev index next >