From 73fb1d9d78bcd966fe8db0007ad77984fd7989d6 Mon Sep 17 00:00:00 2001 From: Mick Jordan <mick.jordan@oracle.com> Date: Wed, 30 Nov 2016 10:56:51 -0800 Subject: [PATCH] rffi: further cleanp --- .../fficall/src/jni/Rdynload_fastr.c | 1 + .../fficall/src/jni/Rinternals.c | 16 ++++++------ .../fficall/src/jni/rffiutils.c | 10 ------- .../fficall/src/jni/rffiutils.h | 3 --- .../r/runtime/ffi/jni/CallRFFIHelper.java | 26 ++++++++++++------- 5 files changed, 26 insertions(+), 30 deletions(-) diff --git a/com.oracle.truffle.r.native/fficall/src/jni/Rdynload_fastr.c b/com.oracle.truffle.r.native/fficall/src/jni/Rdynload_fastr.c index b86229a115..d6e16e35f3 100644 --- a/com.oracle.truffle.r.native/fficall/src/jni/Rdynload_fastr.c +++ b/com.oracle.truffle.r.native/fficall/src/jni/Rdynload_fastr.c @@ -13,6 +13,7 @@ #include <Rdynload.h> // Registering routines from loaded shared libraries +// Currently an exception to the rule that all upcalls go via CallRFFIHelper static jclass DLLClass; static jclass JNI_PkgInitClass; diff --git a/com.oracle.truffle.r.native/fficall/src/jni/Rinternals.c b/com.oracle.truffle.r.native/fficall/src/jni/Rinternals.c index f2cf530d47..3972ae97f4 100644 --- a/com.oracle.truffle.r.native/fficall/src/jni/Rinternals.c +++ b/com.oracle.truffle.r.native/fficall/src/jni/Rinternals.c @@ -52,10 +52,11 @@ static jmethodID Rf_getAttribMethodID; static jmethodID Rf_setAttribMethodID; static jmethodID Rf_isStringMethodID; static jmethodID Rf_isNullMethodID; +static jmethodID Rf_installMethodID; static jmethodID Rf_warningcallMethodID; static jmethodID Rf_warningMethodID; static jmethodID Rf_errorMethodID; -static jmethodID Rf_NewHashedEnvMethodID; +static jmethodID R_NewHashedEnvMethodID; static jmethodID Rf_classgetsMethodID; static jmethodID Rf_rPsortMethodID; static jmethodID Rf_iPsortMethodID; @@ -150,6 +151,7 @@ void init_internals(JNIEnv *env) { Rf_setAttribMethodID = checkGetMethodID(env, CallRFFIHelperClass, "Rf_setAttrib", "(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V", 1); Rf_isStringMethodID = checkGetMethodID(env, CallRFFIHelperClass, "Rf_isString", "(Ljava/lang/Object;)I", 1); Rf_isNullMethodID = checkGetMethodID(env, CallRFFIHelperClass, "Rf_isNull", "(Ljava/lang/Object;)I", 1); + Rf_installMethodID = checkGetMethodID(env, CallRFFIHelperClass, "Rf_install", "(Ljava/lang/String;)Ljava/lang/Object;", 1); Rf_warningMethodID = checkGetMethodID(env, CallRFFIHelperClass, "Rf_warning", "(Ljava/lang/String;)V", 1); Rf_warningcallMethodID = checkGetMethodID(env, CallRFFIHelperClass, "Rf_warningcall", "(Ljava/lang/Object;Ljava/lang/String;)V", 1); Rf_errorMethodID = checkGetMethodID(env, CallRFFIHelperClass, "Rf_error", "(Ljava/lang/String;)V", 1); @@ -158,7 +160,7 @@ void init_internals(JNIEnv *env) { Rf_allocateArrayMethodID = checkGetMethodID(env, CallRFFIHelperClass, "Rf_allocateArray", "(ILjava/lang/Object;)Ljava/lang/Object;", 1); Rf_duplicateMethodID = checkGetMethodID(env, CallRFFIHelperClass, "Rf_duplicate", "(Ljava/lang/Object;I)Ljava/lang/Object;", 1); Rf_anyDuplicatedMethodID = checkGetMethodID(env, CallRFFIHelperClass, "Rf_anyDuplicated", "(Ljava/lang/Object;I)I", 1); - Rf_NewHashedEnvMethodID = checkGetMethodID(env, CallRFFIHelperClass, "Rf_createNewEnv", "(Lcom/oracle/truffle/r/runtime/env/REnvironment;Ljava/lang/String;ZI)Lcom/oracle/truffle/r/runtime/env/REnvironment;", 1); + R_NewHashedEnvMethodID = checkGetMethodID(env, CallRFFIHelperClass, "R_NewHashedEnv", "(Lcom/oracle/truffle/r/runtime/env/REnvironment;Ljava/lang/String;ZI)Lcom/oracle/truffle/r/runtime/env/REnvironment;", 1); Rf_classgetsMethodID = checkGetMethodID(env, CallRFFIHelperClass, "Rf_classgets", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", 1); RprintfMethodID = checkGetMethodID(env, CallRFFIHelperClass, "printf", "(Ljava/lang/String;)V", 1); R_do_MAKE_CLASS_MethodID = checkGetMethodID(env, CallRFFIHelperClass, "R_do_MAKE_CLASS", "(Ljava/lang/String;)Ljava/lang/Object;", 1); @@ -475,7 +477,7 @@ SEXP Rf_install(const char *name) { TRACE(TARGs, name); JNIEnv *thisenv = getEnv(); jstring string = (*thisenv)->NewStringUTF(thisenv, name); - SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, RDataFactoryClass, createSymbolMethodID, string); + SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_installMethodID, string); return checkRef(thisenv, result); } @@ -483,7 +485,7 @@ SEXP Rf_installChar(SEXP charsxp) { TRACE(TARGp, charsxp); JNIEnv *thisenv = getEnv(); jstring string = stringFromCharSXP(thisenv, charsxp); - SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, RDataFactoryClass, createSymbolMethodID, string); + SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_installMethodID, string); return checkRef(thisenv, result); } @@ -677,17 +679,15 @@ void R_ProcessEvents(void) { } // Tools package support, not in public API - SEXP R_NewHashedEnv(SEXP parent, SEXP size) { JNIEnv *thisenv = getEnv(); - int sizeAsInt = Rf_asInteger(size); - SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, RDataFactoryClass, Rf_NewHashedEnvMethodID, parent, NULL, JNI_TRUE, sizeAsInt); + SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, R_NewHashedEnvMethodID, parent, size); return checkRef(thisenv, result); } SEXP Rf_classgets(SEXP vec, SEXP klass) { JNIEnv *thisenv = getEnv(); - SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, RDataFactoryClass, Rf_classgetsMethodID, vec, klass); + SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_classgetsMethodID, vec, klass); return checkRef(thisenv, result); } diff --git a/com.oracle.truffle.r.native/fficall/src/jni/rffiutils.c b/com.oracle.truffle.r.native/fficall/src/jni/rffiutils.c index aa7a7506b4..0010587bcc 100644 --- a/com.oracle.truffle.r.native/fficall/src/jni/rffiutils.c +++ b/com.oracle.truffle.r.native/fficall/src/jni/rffiutils.c @@ -33,13 +33,8 @@ * (portably) for MT use. JNI provides no help. */ jclass CallRFFIHelperClass; -jclass RDataFactoryClass; -jclass RRuntimeClass; jclass CharSXPWrapperClass; -static jclass RInternalErrorClass; -static jmethodID unimplementedMethodID; -jmethodID createSymbolMethodID; static jmethodID validateMethodID; static JNIEnv *curenv = NULL; @@ -114,12 +109,7 @@ void init_utils(JNIEnv *env) { setvbuf(traceFile, (char*) NULL, _IONBF, 0); } } - RDataFactoryClass = checkFindClass(env, "com/oracle/truffle/r/runtime/data/RDataFactory"); CallRFFIHelperClass = checkFindClass(env, "com/oracle/truffle/r/runtime/ffi/jni/CallRFFIHelper"); - RRuntimeClass = checkFindClass(env, "com/oracle/truffle/r/runtime/RRuntime"); - RInternalErrorClass = checkFindClass(env, "com/oracle/truffle/r/runtime/RInternalError"); - unimplementedMethodID = checkGetMethodID(env, RInternalErrorClass, "unimplemented", "(Ljava/lang/String;)Ljava/lang/RuntimeException;", 1); - createSymbolMethodID = checkGetMethodID(env, RDataFactoryClass, "createSymbolInterned", "(Ljava/lang/String;)Lcom/oracle/truffle/r/runtime/data/RSymbol;", 1); validateMethodID = checkGetMethodID(env, CallRFFIHelperClass, "validate", "(Ljava/lang/Object;)Ljava/lang/Object;", 1); cachedGlobalRefs = calloc(CACHED_GLOBALREFS_INITIAL_SIZE, sizeof(GlobalRefElem)); cachedGlobalRefsLength = CACHED_GLOBALREFS_INITIAL_SIZE; diff --git a/com.oracle.truffle.r.native/fficall/src/jni/rffiutils.h b/com.oracle.truffle.r.native/fficall/src/jni/rffiutils.h index 9ace813ba4..3a3539579e 100644 --- a/com.oracle.truffle.r.native/fficall/src/jni/rffiutils.h +++ b/com.oracle.truffle.r.native/fficall/src/jni/rffiutils.h @@ -38,7 +38,6 @@ void setEnv(JNIEnv *env); jclass checkFindClass(JNIEnv *env, const char *name); jmethodID checkGetMethodID(JNIEnv *env, jclass klass, const char *name, const char *sig, int isStatic); jfieldID checkGetFieldID(JNIEnv *env, jclass klass, const char *name, const char *sig, int isStatic); -extern jmethodID createSymbolMethodID; // use for an unimplemented API function void *unimplemented(char *msg); @@ -91,9 +90,7 @@ void setEmbedded(void); void setTempDir(JNIEnv *, jstring tempDir); -extern jclass RDataFactoryClass; extern jclass CallRFFIHelperClass; -extern jclass RRuntimeClass; extern FILE *traceFile; // tracing/debugging support, set to 1 and recompile to enable diff --git a/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jni/CallRFFIHelper.java b/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jni/CallRFFIHelper.java index 1666ec2d2a..fa73127bce 100644 --- a/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jni/CallRFFIHelper.java +++ b/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jni/CallRFFIHelper.java @@ -429,6 +429,13 @@ public class CallRFFIHelper { return result; } + public static Object Rf_install(String name) { + if (RFFIUtils.traceEnabled()) { + RFFIUtils.traceUpCall("Rf_install", name); + } + return RDataFactory.createSymbolInterned(name); + } + public static Object Rf_lengthgets(Object x, int newSize) { if (RFFIUtils.traceEnabled()) { RFFIUtils.traceUpCall("Rf_lengthgets", x, newSize); @@ -1027,15 +1034,6 @@ public class CallRFFIHelper { // TODO: copy OBJECT? and S4 attributes } - public static REnvironment Rf_createNewEnv(REnvironment parent, String name, boolean hashed, int initialSize) { - if (RFFIUtils.traceEnabled()) { - RFFIUtils.traceUpCall("Rf_createNewEnv", parent, name, hashed, initialSize); - } - REnvironment env = RDataFactory.createNewEnv(name, hashed, initialSize); - RArguments.initializeEnclosingFrame(env.getFrame(), parent.getFrame()); - return env; - } - public static int R_computeIdentical(Object x, Object y, int flags) { if (RFFIUtils.traceEnabled()) { RFFIUtils.traceUpCall("R_computeIdentical", x, y, flags); @@ -1520,4 +1518,14 @@ public class CallRFFIHelper { RExternalPtr p = guaranteeInstanceOf(x, RExternalPtr.class); p.setProt(prot); } + + public static REnvironment R_NewHashedEnv(REnvironment parent, String name, boolean hashed, int initialSize) { + if (RFFIUtils.traceEnabled()) { + RFFIUtils.traceUpCall("R_NewHashedEnv", parent, name, hashed, initialSize); + } + REnvironment env = RDataFactory.createNewEnv(name, hashed, initialSize); + RArguments.initializeEnclosingFrame(env.getFrame(), parent.getFrame()); + return env; + } + } -- GitLab