use of jdk.incubator.foreign.VaList in project openj9 by eclipse.
the class VaListTests method test_vprintfFromDefaultLibWithVaList.
@Test
public void test_vprintfFromDefaultLibWithVaList() throws Throwable {
/* Disable the test on Windows given a misaligned access exception coming from
* java.base/java.lang.invoke.MemoryAccessVarHandleBase triggered by CLinker.toCString()
* is also captured on OpenJDK/Hotspot.
*/
if (!isWinOS) {
NativeSymbol functionSymbol = clinker.lookup("vprintf").get();
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS);
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
SegmentAllocator nativeAllocator = SegmentAllocator.nativeAllocator(scope);
MemorySegment formatSegmt = nativeAllocator.allocateUtf8String("%d * %d = %d\n");
VaList vaList = VaList.make(vaListBuilder -> vaListBuilder.addVarg(JAVA_INT, 7).addVarg(JAVA_INT, 8).addVarg(JAVA_INT, 56), scope);
MethodHandle mh = clinker.downcallHandle(functionSymbol, fd);
mh.invoke(formatSegmt, vaList);
}
}
}
use of jdk.incubator.foreign.VaList in project openj9 by eclipse.
the class VaListTests method test_addDoublesWithVaList.
@Test
public void test_addDoublesWithVaList() throws Throwable {
NativeSymbol functionSymbol = nativeLibLookup.lookup("addDoublesFromVaList").get();
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_DOUBLE, JAVA_INT, ADDRESS);
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
VaList vaList = VaList.make(vaListBuilder -> vaListBuilder.addVarg(JAVA_DOUBLE, 150.1001D).addVarg(JAVA_DOUBLE, 160.2002D).addVarg(JAVA_DOUBLE, 170.1001D).addVarg(JAVA_DOUBLE, 180.2002D), scope);
MethodHandle mh = clinker.downcallHandle(functionSymbol, fd);
double result = (double) mh.invoke(4, vaList);
Assert.assertEquals(result, 660.6006D);
}
}
use of jdk.incubator.foreign.VaList in project openj9 by eclipse.
the class VaListTests method test_addLongsWithVaList.
@Test
public void test_addLongsWithVaList() throws Throwable {
NativeSymbol functionSymbol = nativeLibLookup.lookup("addLongsFromVaList").get();
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_LONG, JAVA_INT, ADDRESS);
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
VaList vaList = VaList.make(vaListBuilder -> vaListBuilder.addVarg(JAVA_LONG, 700000L).addVarg(JAVA_LONG, 800000L).addVarg(JAVA_LONG, 900000L).addVarg(JAVA_LONG, 1000000L), scope);
MethodHandle mh = clinker.downcallHandle(functionSymbol, fd);
long result = (long) mh.invoke(4, vaList);
Assert.assertEquals(result, 3400000L);
}
}
use of jdk.incubator.foreign.VaList in project openj9 by eclipse.
the class VaListTests method test_addIntsWithVaList.
@Test
public void test_addIntsWithVaList() throws Throwable {
NativeSymbol functionSymbol = nativeLibLookup.lookup("addIntsFromVaList").get();
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_INT, JAVA_INT, ADDRESS);
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
VaList vaList = VaList.make(vaListBuilder -> vaListBuilder.addVarg(JAVA_INT, 700).addVarg(JAVA_INT, 800).addVarg(JAVA_INT, 900).addVarg(JAVA_INT, 1000), scope);
MethodHandle mh = clinker.downcallHandle(functionSymbol, fd);
int result = (int) mh.invoke(4, vaList);
Assert.assertEquals(result, 3400);
}
}
Aggregations