Skip to content
Snippets Groups Projects
Commit 156bb9e8 authored by stepan's avatar stepan
Browse files

Implement R_PreserveObject and R_ReleaseObject for NFI

parent 05c3b530
No related branches found
No related tags found
No related merge requests found
......@@ -32,6 +32,7 @@ import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
......@@ -1465,13 +1466,17 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI {
}
@Override
public int R_PreserveObject(Object obj) {
throw RInternalError.unimplemented();
public void R_PreserveObject(Object obj) {
guaranteeInstanceOf(obj, RObject.class);
HashSet<RObject> list = RContext.getInstance().preserveList;
list.add((RObject) obj);
}
@Override
public int R_ReleaseObject(Object obj) {
throw RInternalError.unimplemented();
public void R_ReleaseObject(Object obj) {
guaranteeInstanceOf(obj, RObject.class);
HashSet<RObject> list = RContext.getInstance().preserveList;
list.remove(obj);
}
@Override
......
......@@ -25,9 +25,9 @@ package com.oracle.truffle.r.ffi.impl.upcalls;
public interface MemoryUpCallsRFFI {
// Checkstyle: stop method name check
int R_PreserveObject(Object obj);
void R_PreserveObject(Object obj);
int R_ReleaseObject(Object obj);
void R_ReleaseObject(Object obj);
Object Rf_protect(Object x);
......
......@@ -295,7 +295,7 @@ typedef void (*call_Rf_unprotect)(int x);
typedef int (*call_R_ProtectWithIndex)(SEXP x);
typedef void (*call_R_Reprotect)(SEXP x, int y);
typedef void (*call_Rf_unprotect_ptr)(SEXP x);
typedef SEXP (*call_R_PreserveObject)(SEXP x);
typedef void (*call_R_PreserveObject)(SEXP x);
typedef void (*call_R_ReleaseObject)(SEXP x);
#endif
......
......@@ -42,6 +42,7 @@ import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
......@@ -356,8 +357,18 @@ public final class RContext implements RTruffleObject {
public final WeakHashMap<Path, REnvironment> srcfileEnvironments = new WeakHashMap<>();
public final List<String> libraryPaths = new ArrayList<>(1);
public final Map<Integer, Thread> threads = new ConcurrentHashMap<>();
/**
* Stack used by RFFI to implement the PROTECT/UNPROTECT functions.
*/
public final ArrayList<RObject> protectStack = new ArrayList<>();
/**
* FastR equivalent of GNUR's special dedicated global list that is GC root and so any vectors
* added to it will be guaranteed to be preserved.
*/
public final HashSet<RObject> preserveList = new HashSet<>();
private final AllocationReporter allocationReporter;
private ContextState[] contextStates() {
......
......@@ -54,6 +54,7 @@ com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/tools/ToolsText.ja
com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/utils/CountFields.java,gnu_r.copyright
com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/utils/Download.java,gnu_r_gentleman_ihaka2.copyright
com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/utils/Menu.java,gnu_r.copyright
com.oracle.truffle.r.native/fficall/src/truffle_common/Rembedded.c,gnu_r.copyright
com.oracle.truffle.r.native/fficall/src/common/arithmetic_fastr.c,gnu_r_gentleman_ihaka.copyright
com.oracle.truffle.r.native/fficall/src/common/coerce_fastr.c,gnu_r_gentleman_ihaka.copyright
com.oracle.truffle.r.native/fficall/src/common/errors_fastr.c,gnu_r.core.copyright
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment