< prev index next >

test/jdk/java/foreign/callarranger/TestWindowsCallArranger.java

Print this page

139     public void testAbiExample() {
140         MemoryLayout structLayout = MemoryLayout.structLayout(C_INT, C_INT, C_DOUBLE);
141         MethodType mt = MethodType.methodType(void.class,
142                 int.class, int.class, MemorySegment.class, int.class, int.class,
143                 double.class, double.class, double.class, int.class, int.class, int.class);
144         FunctionDescriptor fd = FunctionDescriptor.ofVoid(
145                 C_INT, C_INT, structLayout, C_INT, C_INT,
146                 C_DOUBLE, C_DOUBLE, C_DOUBLE, C_INT, C_INT, C_INT);
147         CallArranger.Bindings bindings = CallArranger.getBindings(mt, fd, false);
148 
149         assertFalse(bindings.isInMemoryReturn);
150         CallingSequence callingSequence = bindings.callingSequence;
151         assertEquals(callingSequence.methodType(), mt);
152         assertEquals(callingSequence.functionDesc(), fd);
153 
154         checkArgumentBindings(callingSequence, new Binding[][]{
155             { vmStore(rcx, int.class) },
156             { vmStore(rdx, int.class) },
157             {
158                 copy(structLayout),
159                 baseAddress(),
160                 unboxAddress(),
161                 vmStore(r8, long.class)
162             },
163             { vmStore(r9, int.class) },
164             { vmStore(stackStorage(0), int.class) },
165             { vmStore(stackStorage(1), double.class) },
166             { vmStore(stackStorage(2), double.class) },
167             { vmStore(stackStorage(3), double.class) },
168             { vmStore(stackStorage(4), int.class) },
169             { vmStore(stackStorage(5), int.class) },
170             { vmStore(stackStorage(6), int.class) }
171         });
172 
173         checkReturnBindings(callingSequence, new Binding[]{});
174     }
175 
176     @Test
177     public void testAbiExampleVarargs() {
178         MethodType mt = MethodType.methodType(void.class,
179                 int.class, double.class, int.class, double.class, double.class);
180         FunctionDescriptor fd = FunctionDescriptor.ofVoid(
181                 C_INT, C_DOUBLE, asVarArg(C_INT), asVarArg(C_DOUBLE), asVarArg(C_DOUBLE));
182         CallArranger.Bindings bindings = CallArranger.getBindings(mt, fd, false);
183 
184         assertFalse(bindings.isInMemoryReturn);
185         CallingSequence callingSequence = bindings.callingSequence;
186         assertEquals(callingSequence.methodType(), mt);
187         assertEquals(callingSequence.functionDesc(), fd);
188 
189         checkArgumentBindings(callingSequence, new Binding[][]{
190             { vmStore(rcx, int.class) },
191             { vmStore(xmm1, double.class) },
192             { vmStore(r8, int.class) },
193             { dup(), vmStore(r9, double.class), vmStore(xmm3, double.class) },
194             { vmStore(stackStorage(0), double.class) },
195         });
196 
197         checkReturnBindings(callingSequence, new Binding[]{});
198     }
199 
200     /**
201      * struct s {

234      * void m(struct s s);
235      *
236      * m(s);
237      */
238     @Test
239     public void testStructReference() {
240         MemoryLayout struct = MemoryLayout.structLayout(C_LONG_LONG, C_LONG_LONG);
241 
242         MethodType mt = MethodType.methodType(void.class, MemorySegment.class);
243         FunctionDescriptor fd = FunctionDescriptor.ofVoid(struct);
244         CallArranger.Bindings bindings = CallArranger.getBindings(mt, fd, false);
245 
246         assertFalse(bindings.isInMemoryReturn);
247         CallingSequence callingSequence = bindings.callingSequence;
248         assertEquals(callingSequence.methodType(), mt);
249         assertEquals(callingSequence.functionDesc(), fd);
250 
251         checkArgumentBindings(callingSequence, new Binding[][]{
252             {
253                 copy(struct),
254                 baseAddress(),
255                 unboxAddress(),
256                 vmStore(rcx, long.class)
257             }
258         });
259 
260         checkReturnBindings(callingSequence, new Binding[]{});
261     }
262 
263     /**
264      * typedef void (*f)(void);
265      *
266      * void m(f f);
267      * void f_impl(void);
268      *
269      * m(f_impl);
270      */
271     @Test
272     public void testMemoryAddress() {
273         MethodType mt = MethodType.methodType(void.class, MemoryAddress.class);
274         FunctionDescriptor fd = FunctionDescriptor.ofVoid(C_POINTER);
275         CallArranger.Bindings bindings = CallArranger.getBindings(mt, fd, false);

333         MemoryLayout struct = MemoryLayout.structLayout(C_POINTER, C_DOUBLE, C_INT);
334 
335         MethodType mt = MethodType.methodType(void.class,
336             MemorySegment.class, int.class, double.class, MemoryAddress.class,
337             MemorySegment.class, int.class, double.class, MemoryAddress.class,
338             MemorySegment.class, int.class, double.class, MemoryAddress.class,
339             MemorySegment.class, int.class, double.class, MemoryAddress.class);
340         FunctionDescriptor fd = FunctionDescriptor.ofVoid(
341             struct, C_INT, C_DOUBLE, C_POINTER,
342             struct, C_INT, C_DOUBLE, C_POINTER,
343             struct, C_INT, C_DOUBLE, C_POINTER,
344             struct, C_INT, C_DOUBLE, C_POINTER);
345         CallArranger.Bindings bindings = CallArranger.getBindings(mt, fd, false);
346 
347         assertFalse(bindings.isInMemoryReturn);
348         CallingSequence callingSequence = bindings.callingSequence;
349         assertEquals(callingSequence.methodType(), mt);
350         assertEquals(callingSequence.functionDesc(), fd);
351 
352         checkArgumentBindings(callingSequence, new Binding[][]{
353             { copy(struct), baseAddress(), unboxAddress(), vmStore(rcx, long.class) },
354             { vmStore(rdx, int.class) },
355             { vmStore(xmm2, double.class) },
356             { unboxAddress(), vmStore(r9, long.class) },
357             { copy(struct), baseAddress(), unboxAddress(), vmStore(stackStorage(0), long.class) },
358             { vmStore(stackStorage(1), int.class) },
359             { vmStore(stackStorage(2), double.class) },
360             { unboxAddress(), vmStore(stackStorage(3), long.class) },
361             { copy(struct), baseAddress(), unboxAddress(), vmStore(stackStorage(4), long.class) },
362             { vmStore(stackStorage(5), int.class) },
363             { vmStore(stackStorage(6), double.class) },
364             { unboxAddress(), vmStore(stackStorage(7), long.class) },
365             { copy(struct), baseAddress(), unboxAddress(), vmStore(stackStorage(8), long.class) },
366             { vmStore(stackStorage(9), int.class) },
367             { vmStore(stackStorage(10), double.class) },
368             { unboxAddress(), vmStore(stackStorage(11), long.class) },
369         });
370 
371         checkReturnBindings(callingSequence, new Binding[]{});
372     }
373 }

139     public void testAbiExample() {
140         MemoryLayout structLayout = MemoryLayout.structLayout(C_INT, C_INT, C_DOUBLE);
141         MethodType mt = MethodType.methodType(void.class,
142                 int.class, int.class, MemorySegment.class, int.class, int.class,
143                 double.class, double.class, double.class, int.class, int.class, int.class);
144         FunctionDescriptor fd = FunctionDescriptor.ofVoid(
145                 C_INT, C_INT, structLayout, C_INT, C_INT,
146                 C_DOUBLE, C_DOUBLE, C_DOUBLE, C_INT, C_INT, C_INT);
147         CallArranger.Bindings bindings = CallArranger.getBindings(mt, fd, false);
148 
149         assertFalse(bindings.isInMemoryReturn);
150         CallingSequence callingSequence = bindings.callingSequence;
151         assertEquals(callingSequence.methodType(), mt);
152         assertEquals(callingSequence.functionDesc(), fd);
153 
154         checkArgumentBindings(callingSequence, new Binding[][]{
155             { vmStore(rcx, int.class) },
156             { vmStore(rdx, int.class) },
157             {
158                 copy(structLayout),
159                 unboxAddress(MemorySegment.class),

160                 vmStore(r8, long.class)
161             },
162             { vmStore(r9, int.class) },
163             { vmStore(stackStorage(0), int.class) },
164             { vmStore(stackStorage(1), double.class) },
165             { vmStore(stackStorage(2), double.class) },
166             { vmStore(stackStorage(3), double.class) },
167             { vmStore(stackStorage(4), int.class) },
168             { vmStore(stackStorage(5), int.class) },
169             { vmStore(stackStorage(6), int.class) }
170         });
171 
172         checkReturnBindings(callingSequence, new Binding[]{});
173     }
174 
175     @Test
176     public void testAbiExampleVarargs() {
177         MethodType mt = MethodType.methodType(void.class,
178                 int.class, double.class, int.class, double.class, double.class);
179         FunctionDescriptor fd = FunctionDescriptor.ofVoid(
180                 C_INT, C_DOUBLE).asVariadic(C_INT, C_DOUBLE, C_DOUBLE);
181         CallArranger.Bindings bindings = CallArranger.getBindings(mt, fd, false);
182 
183         assertFalse(bindings.isInMemoryReturn);
184         CallingSequence callingSequence = bindings.callingSequence;
185         assertEquals(callingSequence.methodType(), mt);
186         assertEquals(callingSequence.functionDesc(), fd);
187 
188         checkArgumentBindings(callingSequence, new Binding[][]{
189             { vmStore(rcx, int.class) },
190             { vmStore(xmm1, double.class) },
191             { vmStore(r8, int.class) },
192             { dup(), vmStore(r9, double.class), vmStore(xmm3, double.class) },
193             { vmStore(stackStorage(0), double.class) },
194         });
195 
196         checkReturnBindings(callingSequence, new Binding[]{});
197     }
198 
199     /**
200      * struct s {

233      * void m(struct s s);
234      *
235      * m(s);
236      */
237     @Test
238     public void testStructReference() {
239         MemoryLayout struct = MemoryLayout.structLayout(C_LONG_LONG, C_LONG_LONG);
240 
241         MethodType mt = MethodType.methodType(void.class, MemorySegment.class);
242         FunctionDescriptor fd = FunctionDescriptor.ofVoid(struct);
243         CallArranger.Bindings bindings = CallArranger.getBindings(mt, fd, false);
244 
245         assertFalse(bindings.isInMemoryReturn);
246         CallingSequence callingSequence = bindings.callingSequence;
247         assertEquals(callingSequence.methodType(), mt);
248         assertEquals(callingSequence.functionDesc(), fd);
249 
250         checkArgumentBindings(callingSequence, new Binding[][]{
251             {
252                 copy(struct),
253                 unboxAddress(MemorySegment.class),

254                 vmStore(rcx, long.class)
255             }
256         });
257 
258         checkReturnBindings(callingSequence, new Binding[]{});
259     }
260 
261     /**
262      * typedef void (*f)(void);
263      *
264      * void m(f f);
265      * void f_impl(void);
266      *
267      * m(f_impl);
268      */
269     @Test
270     public void testMemoryAddress() {
271         MethodType mt = MethodType.methodType(void.class, MemoryAddress.class);
272         FunctionDescriptor fd = FunctionDescriptor.ofVoid(C_POINTER);
273         CallArranger.Bindings bindings = CallArranger.getBindings(mt, fd, false);

331         MemoryLayout struct = MemoryLayout.structLayout(C_POINTER, C_DOUBLE, C_INT);
332 
333         MethodType mt = MethodType.methodType(void.class,
334             MemorySegment.class, int.class, double.class, MemoryAddress.class,
335             MemorySegment.class, int.class, double.class, MemoryAddress.class,
336             MemorySegment.class, int.class, double.class, MemoryAddress.class,
337             MemorySegment.class, int.class, double.class, MemoryAddress.class);
338         FunctionDescriptor fd = FunctionDescriptor.ofVoid(
339             struct, C_INT, C_DOUBLE, C_POINTER,
340             struct, C_INT, C_DOUBLE, C_POINTER,
341             struct, C_INT, C_DOUBLE, C_POINTER,
342             struct, C_INT, C_DOUBLE, C_POINTER);
343         CallArranger.Bindings bindings = CallArranger.getBindings(mt, fd, false);
344 
345         assertFalse(bindings.isInMemoryReturn);
346         CallingSequence callingSequence = bindings.callingSequence;
347         assertEquals(callingSequence.methodType(), mt);
348         assertEquals(callingSequence.functionDesc(), fd);
349 
350         checkArgumentBindings(callingSequence, new Binding[][]{
351             { copy(struct), unboxAddress(MemorySegment.class), vmStore(rcx, long.class) },
352             { vmStore(rdx, int.class) },
353             { vmStore(xmm2, double.class) },
354             { unboxAddress(), vmStore(r9, long.class) },
355             { copy(struct), unboxAddress(MemorySegment.class), vmStore(stackStorage(0), long.class) },
356             { vmStore(stackStorage(1), int.class) },
357             { vmStore(stackStorage(2), double.class) },
358             { unboxAddress(), vmStore(stackStorage(3), long.class) },
359             { copy(struct), unboxAddress(MemorySegment.class), vmStore(stackStorage(4), long.class) },
360             { vmStore(stackStorage(5), int.class) },
361             { vmStore(stackStorage(6), double.class) },
362             { unboxAddress(), vmStore(stackStorage(7), long.class) },
363             { copy(struct), unboxAddress(MemorySegment.class), vmStore(stackStorage(8), long.class) },
364             { vmStore(stackStorage(9), int.class) },
365             { vmStore(stackStorage(10), double.class) },
366             { unboxAddress(), vmStore(stackStorage(11), long.class) },
367         });
368 
369         checkReturnBindings(callingSequence, new Binding[]{});
370     }
371 }
< prev index next >