< prev index next >

test/jdk/java/nicl/Upcall/DoubleUpcall.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 DoubleUpcall
  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 DoubleUpcall {
  37     private static final boolean DEBUG = false;
  38 
  39     @NativeHeader
  40     public static interface upcall {

  41         @FunctionalInterface
  42         static interface cb {
  43             @C(file="dummy", line=47, column=11, USR="c:@F@slowsort")
  44             @NativeType(layout="(dd)d", ctype="double (double,double)", size=4l)
  45             @CallingConvention(value=1)
  46             public double fn(double d1, double d2);
  47         }
  48 
  49         @C(file="dummy", line=47, column=11, USR="c:@F@double_upcall")
  50         @NativeType(layout="(p:(DD)DDD)D", ctype="double (double_upcall_cb, double, double)", name="double_upcall", size=1)
  51         @CallingConvention(value=1)
  52         public abstract double double_upcall(cb cb, double d1, double d2);
  53     }
  54 
  55     public static class cbImpl implements upcall.cb {
  56         @Override
  57         public double fn(double d1, double d2) {
  58             if (DEBUG) {
  59                 System.err.println("fn(" + d1 + ", " + d2 + ")");
  60             }
  61 
  62             assertEquals(1.23, d1, 0.1);
  63             assertEquals(1.11, d2, 0.1);
  64 
  65             return d1 + d2;
  66         }
  67     }
  68 
  69     public void test() {
  70         upcall i = Libraries.bind(upcall.class, Libraries.loadLibrary(MethodHandles.lookup(), "Upcall"));
  71         upcall.cb v = new cbImpl();




  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 DoubleUpcall
  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 DoubleUpcall {
  37     private static final boolean DEBUG = false;
  38 
  39     @NativeHeader
  40     public static interface upcall {
  41         @NativeCallback("(dd)d")
  42         @FunctionalInterface
  43         static interface cb {
  44             @NativeLocation(file="dummy", line=47, column=11, USR="c:@F@slowsort")


  45             public double fn(double d1, double d2);
  46         }
  47 
  48         @NativeLocation(file="dummy", line=47, column=11, USR="c:@F@double_upcall")
  49         @NativeType(layout="(p:(DD)DDD)D", ctype="double (double_upcall_cb, double, double)", name="double_upcall")

  50         public abstract double double_upcall(cb cb, double d1, double d2);
  51     }
  52 
  53     public static class cbImpl implements upcall.cb {
  54         @Override
  55         public double fn(double d1, double d2) {
  56             if (DEBUG) {
  57                 System.err.println("fn(" + d1 + ", " + d2 + ")");
  58             }
  59 
  60             assertEquals(1.23, d1, 0.1);
  61             assertEquals(1.11, d2, 0.1);
  62 
  63             return d1 + d2;
  64         }
  65     }
  66 
  67     public void test() {
  68         upcall i = Libraries.bind(upcall.class, Libraries.loadLibrary(MethodHandles.lookup(), "Upcall"));
  69         upcall.cb v = new cbImpl();


< prev index next >