Skip to content

Commit 73130fc

Browse files
committedApr 5, 2024
7903704: Expose addresses of native functions
Reviewed-by: mcimadamore
1 parent c24224e commit 73130fc

File tree

47 files changed

+175
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+175
-7
lines changed
 

‎src/main/java/org/openjdk/jextract/impl/HeaderFileBuilder.java

+18-3
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ private void emitFunctionWrapper(String javaName, String nativeName, boolean nee
156156
private static class \{holderClass} {
157157
public static final FunctionDescriptor DESC = \{functionDescriptorString(1, decl.type())};
158158
159-
public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(
160-
\{runtimeHelperName()}.findOrThrow("\{nativeName}"),
161-
DESC);
159+
public static final MemorySegment ADDR = \{runtimeHelperName()}.findOrThrow("\{nativeName}");
160+
161+
public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC);
162162
}
163163
""");
164164
appendBlankLine();
@@ -175,6 +175,14 @@ private static class \{holderClass} {
175175
return \{holderClass}.HANDLE;
176176
}
177177
""");
178+
appendBlankLine();
179+
emitDocComment(decl, "Address for:");
180+
appendLines(STR."""
181+
public static MemorySegment \{javaName}$address() {
182+
return \{holderClass}.ADDR;
183+
}
184+
""");
185+
appendBlankLine();
178186
emitDocComment(decl);
179187
appendLines(STR."""
180188
public static \{retType} \{javaName}(\{paramExprs(declType, finalParamNames, isVarArg)}) {
@@ -224,6 +232,13 @@ public static class \{invokerClassName} {
224232
decrAlign();
225233
appendLines(STR."""
226234
235+
/**
236+
* {@return the address}
237+
*/
238+
public static MemorySegment address() {
239+
return ADDR;
240+
}
241+
227242
/**
228243
* {@return the specialized method handle}
229244
*/

‎test/jtreg/TestSplit.java

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
/*
3232
* @test
3333
* @library /lib
34+
* @build testlib.JextractToolRunner testlib.TestUtils
3435
* @run testng/othervm -Djextract.decls.per.header=1 TestSplit
3536
*/
3637
public class TestSplit extends JextractToolRunner {

0 commit comments

Comments
 (0)
Please sign in to comment.