Skip to content
Snippets Groups Projects
Commit 5709e037 authored by Zbynek Slajchrt's avatar Zbynek Slajchrt
Browse files

Obsolete native pointer table removed

parent 24ca968c
Branches
No related tags found
No related merge requests found
...@@ -53,23 +53,23 @@ final class TruffleLLVM_DownCallNodeFactory extends DownCallNodeFactory { ...@@ -53,23 +53,23 @@ final class TruffleLLVM_DownCallNodeFactory extends DownCallNodeFactory {
public DownCallNode createDownCallNode(NativeFunction f) { public DownCallNode createDownCallNode(NativeFunction f) {
return new DownCallNode(f) { return new DownCallNode(f) {
@Override @Override
protected TruffleObject getTarget(NativeFunction function) { protected TruffleObject getTarget(NativeFunction fn) {
CompilerAsserts.neverPartOfCompilation(); CompilerAsserts.neverPartOfCompilation();
String library = function.getLibrary(); String library = fn.getLibrary();
DLLInfo dllInfo = null; DLLInfo dllInfo = null;
if (library != anyLibrary()) { if (library != anyLibrary()) {
dllInfo = DLL.findLibrary(library); dllInfo = DLL.findLibrary(library);
} }
SymbolHandle result = DLL.findSymbol(function.getCallName(), dllInfo); SymbolHandle result = DLL.findSymbol(fn.getCallName(), dllInfo);
if (result == DLL.SYMBOL_NOT_FOUND) { if (result == DLL.SYMBOL_NOT_FOUND) {
throw RInternalError.shouldNotReachHere("Could not find function " + function.getCallName() + " in library " + library); throw RInternalError.shouldNotReachHere("Could not find function " + fn.getCallName() + " in library " + library);
} }
return result.asTruffleObject(); return result.asTruffleObject();
} }
@Override @Override
@ExplodeLoop @ExplodeLoop
protected long beforeCall(NativeFunction nativeFunction, TruffleObject function, Object[] args) { protected long beforeCall(NativeFunction nativeFunction, TruffleObject fn, Object[] args) {
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
Object obj = args[i]; Object obj = args[i];
if (obj instanceof double[]) { if (obj instanceof double[]) {
...@@ -92,7 +92,7 @@ final class TruffleLLVM_DownCallNodeFactory extends DownCallNodeFactory { ...@@ -92,7 +92,7 @@ final class TruffleLLVM_DownCallNodeFactory extends DownCallNodeFactory {
@Override @Override
@ExplodeLoop @ExplodeLoop
protected void afterCall(long before, NativeFunction function, TruffleObject target, Object[] args) { protected void afterCall(long before, NativeFunction fn, TruffleObject target, Object[] args) {
for (Object obj : args) { for (Object obj : args) {
if (obj instanceof NativeNACheck<?>) { if (obj instanceof NativeNACheck<?>) {
((NativeNACheck<?>) obj).close(); ((NativeNACheck<?>) obj).close();
......
...@@ -42,14 +42,14 @@ public final class TruffleNFI_DownCallNodeFactory extends DownCallNodeFactory { ...@@ -42,14 +42,14 @@ public final class TruffleNFI_DownCallNodeFactory extends DownCallNodeFactory {
public DownCallNode createDownCallNode(NativeFunction f) { public DownCallNode createDownCallNode(NativeFunction f) {
return new DownCallNode(f) { return new DownCallNode(f) {
@Override @Override
protected TruffleObject getTarget(NativeFunction function) { protected TruffleObject getTarget(NativeFunction fn) {
// TODO: this lookupNativeFunction function can exist in all FFI Contexts // TODO: this lookupNativeFunction function can exist in all FFI Contexts
return TruffleNFI_Context.getInstance().lookupNativeFunction(function); return TruffleNFI_Context.getInstance().lookupNativeFunction(fn);
} }
@Override @Override
@ExplodeLoop @ExplodeLoop
protected long beforeCall(NativeFunction function, TruffleObject target, Object[] args) { protected long beforeCall(NativeFunction fn, TruffleObject target, Object[] args) {
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
Object obj = args[i]; Object obj = args[i];
if (obj instanceof double[]) { if (obj instanceof double[]) {
...@@ -72,7 +72,7 @@ public final class TruffleNFI_DownCallNodeFactory extends DownCallNodeFactory { ...@@ -72,7 +72,7 @@ public final class TruffleNFI_DownCallNodeFactory extends DownCallNodeFactory {
} }
} }
if (function.hasComplexInteraction()) { if (fn.hasComplexInteraction()) {
return ((TruffleNFI_Context) RContext.getInstance().getRFFI()).beforeDowncall(); return ((TruffleNFI_Context) RContext.getInstance().getRFFI()).beforeDowncall();
} }
return 0; return 0;
...@@ -88,8 +88,8 @@ public final class TruffleNFI_DownCallNodeFactory extends DownCallNodeFactory { ...@@ -88,8 +88,8 @@ public final class TruffleNFI_DownCallNodeFactory extends DownCallNodeFactory {
@Override @Override
@ExplodeLoop @ExplodeLoop
protected void afterCall(long before, NativeFunction function, TruffleObject target, Object[] args) { protected void afterCall(long before, NativeFunction fn, TruffleObject target, Object[] args) {
if (function.hasComplexInteraction()) { if (fn.hasComplexInteraction()) {
((TruffleNFI_Context) RContext.getInstance().getRFFI()).afterDowncall(before); ((TruffleNFI_Context) RContext.getInstance().getRFFI()).afterDowncall(before);
} }
......
...@@ -32,7 +32,7 @@ import com.oracle.truffle.r.runtime.data.RTruffleObject; ...@@ -32,7 +32,7 @@ import com.oracle.truffle.r.runtime.data.RTruffleObject;
* Created when a {@link RTruffleObject} subclass has no meaningful native representation, * Created when a {@link RTruffleObject} subclass has no meaningful native representation,
* nevertheless a {@link Message#TO_NATIVE} message is sent to it. * nevertheless a {@link Message#TO_NATIVE} message is sent to it.
*/ */
public class NativePointer implements TruffleObject { public abstract class NativePointer implements TruffleObject {
/** /**
* This is used when an {@link RNull} is stored in memory (LLVM). * This is used when an {@link RNull} is stored in memory (LLVM).
...@@ -50,23 +50,9 @@ public class NativePointer implements TruffleObject { ...@@ -50,23 +50,9 @@ public class NativePointer implements TruffleObject {
public static final NullNativePointer NULL_NATIVEPOINTER = new NullNativePointer(); public static final NullNativePointer NULL_NATIVEPOINTER = new NullNativePointer();
private static Table[] table = new Table[16];
private static int tableHwm;
private static class Table {
// TODO: is this reference to object needed?
@SuppressWarnings("unused") private final RTruffleObject object;
private final long nativePointer;
Table(RTruffleObject object, long nativePointer) {
this.object = object;
this.nativePointer = nativePointer;
}
}
final RTruffleObject object; final RTruffleObject object;
public NativePointer(RTruffleObject object) { protected NativePointer(RTruffleObject object) {
this.object = object; this.object = object;
} }
...@@ -80,27 +66,8 @@ public class NativePointer implements TruffleObject { ...@@ -80,27 +66,8 @@ public class NativePointer implements TruffleObject {
} }
final long asPointer() { final long asPointer() {
long result = asPointerImpl(); return asPointerImpl();
boolean newPointer = true;
for (int i = 0; i < tableHwm; i++) {
if (table[i].nativePointer == result) {
newPointer = false;
break;
}
}
if (newPointer) {
// System.out.printf("as_pointer: %x from %s\n", result, object.getClass().getName());
if (tableHwm >= table.length) {
Table[] newTable = new Table[table.length * 2];
System.arraycopy(table, 0, newTable, 0, table.length);
table = newTable;
}
table[tableHwm++] = new Table(object, result);
}
return result;
} }
protected long asPointerImpl() { protected abstract long asPointerImpl();
return System.identityHashCode(object);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment