68 throw new Error("Invalid size: " + Constants.INTEGER_REGISTER_SIZE);
69 }
70 if ((Constants.VECTOR_REGISTER_SIZE % size) != 0) {
71 throw new Error("Invalid size: " + Constants.VECTOR_REGISTER_SIZE);
72 }
73 }
74
75 public static UpcallHandler make(Class<?> c, Object o) throws Throwable {
76 if (!Util.isFunctionalInterface(c)) {
77 throw new IllegalArgumentException("Class is not a @FunctionalInterface: " + c.getName());
78 }
79 if (o == null) {
80 throw new NullPointerException();
81 }
82
83 if (!c.isInstance(o)) {
84 throw new IllegalArgumentException("Object must implement FunctionalInterface class: " + c.getName());
85 }
86
87 Method ficMethod = Util.findFunctionalInterfaceMethod(c);
88 Function ftype = Util.functionof(ficMethod);
89
90 MethodType mt = MethodHandles.publicLookup().unreflect(ficMethod).type().dropParameterTypes(0, 1);
91
92 MethodHandle mh = MethodHandles.publicLookup().findVirtual(c, "fn", mt);
93
94 return UpcallHandler.make(mh.bindTo(o), ftype);
95 }
96
97 private static UpcallHandler make(MethodHandle mh, Function ftype) throws Throwable {
98 synchronized (HANDLERS_LOCK) {
99 int id = ID2HANDLER.size();
100 UpcallHandler handler = new UpcallHandler(mh, ftype, id);
101 ID2HANDLER.add(handler);
102
103 if (DEBUG) {
104 System.err.println("Allocated upcall handler with id " + id);
105 }
106
107 return handler;
108 }
|
68 throw new Error("Invalid size: " + Constants.INTEGER_REGISTER_SIZE);
69 }
70 if ((Constants.VECTOR_REGISTER_SIZE % size) != 0) {
71 throw new Error("Invalid size: " + Constants.VECTOR_REGISTER_SIZE);
72 }
73 }
74
75 public static UpcallHandler make(Class<?> c, Object o) throws Throwable {
76 if (!Util.isFunctionalInterface(c)) {
77 throw new IllegalArgumentException("Class is not a @FunctionalInterface: " + c.getName());
78 }
79 if (o == null) {
80 throw new NullPointerException();
81 }
82
83 if (!c.isInstance(o)) {
84 throw new IllegalArgumentException("Object must implement FunctionalInterface class: " + c.getName());
85 }
86
87 Method ficMethod = Util.findFunctionalInterfaceMethod(c);
88 Function ftype = Util.functionof(c);
89
90 MethodType mt = MethodHandles.publicLookup().unreflect(ficMethod).type().dropParameterTypes(0, 1);
91
92 MethodHandle mh = MethodHandles.publicLookup().findVirtual(c, "fn", mt);
93
94 return UpcallHandler.make(mh.bindTo(o), ftype);
95 }
96
97 private static UpcallHandler make(MethodHandle mh, Function ftype) throws Throwable {
98 synchronized (HANDLERS_LOCK) {
99 int id = ID2HANDLER.size();
100 UpcallHandler handler = new UpcallHandler(mh, ftype, id);
101 ID2HANDLER.add(handler);
102
103 if (DEBUG) {
104 System.err.println("Allocated upcall handler with id " + id);
105 }
106
107 return handler;
108 }
|