Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8245003: jextract does not generate accessor for MemorySegement typed values #165

Closed
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -146,7 +146,8 @@
methodType(
MemoryAddress.class,
LibraryLookup[].class,
String.class)
String.class,
MemoryLayout.class)
);
this.MH_makeCString = findRuntimeHelperBootstrap(
cString,
@@ -188,8 +189,8 @@ public DirectMethodHandleDesc addMethodHandle(String javaName, String nativeName
return emitCondyGetter(javaName + "$MH", MethodHandle.class, methodHandleDesc(nativeName, mtype, desc, varargs));
}

public DirectMethodHandleDesc addAddress(String javaName, String nativeName) {
return emitCondyGetter(javaName + "$ADDR", MemoryAddress.class, globalVarAddressDesc(nativeName));
public DirectMethodHandleDesc addAddress(String javaName, String nativeName, MemoryLayout layout) {
return emitCondyGetter(javaName + "$ADDR", MemoryAddress.class, globalVarAddressDesc(nativeName, layout));
}

public DirectMethodHandleDesc addFunctionDesc(String javaName, FunctionDescriptor fDesc) {
@@ -419,8 +420,8 @@ private static ConstantDesc varHandleDesc(String javaName, String nativeName, Me
}
}

private ConstantDesc globalVarAddressDesc(String name) {
return DynamicConstantDesc.ofNamed(BSM_INVOKE, "ADDR_" + name, CD_MemoryAddress, MH_lookupGlobalVariable, LIBRARIES, name);
private ConstantDesc globalVarAddressDesc(String name, MemoryLayout layout) {
return DynamicConstantDesc.ofNamed(BSM_INVOKE, "ADDR_" + name, CD_MemoryAddress, MH_lookupGlobalVariable, LIBRARIES, name, desc(layout));
}

private ConstantDesc addressDesc(long value) {
@@ -115,8 +115,8 @@ public void addMethodHandleGetter(String javaName, String nativeName, MethodType
emitForwardGetter(constantHelper.addMethodHandle(javaName, nativeName, mtype, desc, varargs));
}

public void addAddressGetter(String javaName, String nativeName) {
emitForwardGetter(constantHelper.addAddress(javaName, nativeName));
public void addAddressGetter(String javaName, String nativeName, MemoryLayout layout) {
emitForwardGetter(constantHelper.addAddress(javaName, nativeName, layout));
}

public void addConstantGetter(String javaName, Class<?> type, Object value) {
@@ -129,7 +129,7 @@ public void addGetter(String javaName, String nativeName, MemoryLayout layout, C
sb.append(PUB_MODS + type.getName() + " " + javaName + "$get() {\n");
incrAlign();
indent();
String vhParam = addressGetCallString(javaName, nativeName);
String vhParam = addressGetCallString(javaName, nativeName, layout);
sb.append("return (" + type.getName() + ")"
+ varHandleGetCallString(javaName, nativeName, layout, type, null) + ".get(" + vhParam + ");\n");
decrAlign();
@@ -144,7 +144,7 @@ public void addSetter(String javaName, String nativeName, MemoryLayout layout, C
sb.append(PUB_MODS + "void " + javaName + "$set(" + type.getName() + " x) {\n");
incrAlign();
indent();
String vhParam = addressGetCallString(javaName, nativeName);
String vhParam = addressGetCallString(javaName, nativeName, layout);
sb.append(varHandleGetCallString(javaName, nativeName, layout, type, null) + ".set(" + vhParam + ", x);\n");
decrAlign();
indent();
@@ -153,17 +153,13 @@ public void addSetter(String javaName, String nativeName, MemoryLayout layout, C
}

public void addAddressOf(String javaName, String nativeName, MemoryLayout layout, Class<?> type, MemoryLayout parentLayout) {
DirectMethodHandleDesc desc = constantHelper.addAddress(javaName, nativeName);
DirectMethodHandleDesc desc = constantHelper.addAddress(javaName, nativeName, layout);
incrAlign();
indent();
sb.append(PUB_MODS + "MemoryAddress " + javaName + "$addressof() {\n");
incrAlign();
indent();
sb.append("return MemorySegment.ofNativeRestricted(" + getCallString(desc));
sb.append(", ");
sb.append(layout.byteSize());
sb.append(", ");
sb.append("Thread.currentThread(), null, null).baseAddress();\n");
sb.append("return " + getCallString(desc) + ";\n");
decrAlign();
indent();
sb.append("}\n");
@@ -225,8 +221,8 @@ protected String varHandleGetCallString(String javaName, String nativeName, Memo
return getCallString(constantHelper.addVarHandle(javaName, nativeName, layout, type, parentLayout));
}

protected String addressGetCallString(String javaName, String nativeName) {
return getCallString(constantHelper.addAddress(javaName, nativeName));
protected String addressGetCallString(String javaName, String nativeName, MemoryLayout layout) {
return getCallString(constantHelper.addAddress(javaName, nativeName, layout));
}

protected void indent() {
@@ -381,7 +381,7 @@ public Void visitVariable(Declaration.Variable tree, Declaration parent) {
} else {
builder.addLayoutGetter(fieldName, layout);
builder.addVarHandleGetter(fieldName, tree.name(), treeLayout, clazz,null);
builder.addAddressGetter(fieldName, tree.name());
builder.addAddressGetter(fieldName, tree.name(), treeLayout);
builder.addGetter(fieldName, tree.name(), treeLayout, clazz, null);
builder.addSetter(fieldName, tree.name(), treeLayout, clazz, null);
}
@@ -48,8 +48,11 @@ public class RuntimeHelper {
}
}

public static final MemoryAddress lookupGlobalVariable(LibraryLookup[] LIBRARIES, String name) {
return lookup(LIBRARIES, name).orElse(null);
public static final MemoryAddress lookupGlobalVariable(LibraryLookup[] LIBRARIES, String name, MemoryLayout layout) {
return lookup(LIBRARIES, name).map(a ->
MemorySegment.ofNativeRestricted(
a, layout.byteSize(), null, null, a
).withAccessModes(MemorySegment.READ | MemorySegment.WRITE).baseAddress()).orElse(null);
}

public static final MethodHandle downcallHandle(LibraryLookup[] LIBRARIES, String name, String desc, FunctionDescriptor fdesc, boolean variadic) {
@@ -30,6 +30,8 @@
import jdk.incubator.foreign.FunctionDescriptor;
import jdk.incubator.foreign.LibraryLookup;
import jdk.incubator.foreign.MemoryAddress;
import jdk.incubator.foreign.MemoryLayout;
import jdk.incubator.foreign.MemorySegment;
import jdk.incubator.foreign.SystemABI;
import jdk.internal.foreign.abi.SharedUtils;

@@ -84,8 +86,11 @@
}
}

public static final MemoryAddress lookupGlobalVariable(LibraryLookup[] LIBRARIES, String name) {
return lookup(LIBRARIES, name).orElse(null);
public static final MemoryAddress lookupGlobalVariable(LibraryLookup[] LIBRARIES, String name, MemoryLayout layout) {
return lookup(LIBRARIES, name).map(a ->
MemorySegment.ofNativeRestricted(
a, layout.byteSize(), null, null, a
).withAccessModes(MemorySegment.READ | MemorySegment.WRITE).baseAddress()).orElse(null);
}

public static final MethodHandle downcallHandle(LibraryLookup[] LIBRARIES, String name, String desc, FunctionDescriptor fdesc) {
ProTip! Use n and p to navigate between commits in a pull request.