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 085c8e9dbd69e8c21c066e908d33780234f9f150..d8a81d9a96e028742e424ebc8da5a07bd557c070 100644
--- a/com.oracle.truffle.r.native/fficall/src/jni/Rinternals.c
+++ b/com.oracle.truffle.r.native/fficall/src/jni/Rinternals.c
@@ -234,7 +234,7 @@ static jstring stringFromCharSXP(JNIEnv *thisenv, SEXP charsxp) {
 }
 
 SEXP Rf_ScalarInteger(int value) {
-	TRACE("%s(%d)\n", value);
+	TRACE(TARGp, value);
 	JNIEnv *thisenv = getEnv();
 	SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_ScalarIntegerMethodID, value);
     return checkRef(thisenv, result);
@@ -247,14 +247,14 @@ SEXP Rf_ScalarReal(double value) {
 }
 
 SEXP Rf_ScalarString(SEXP value) {
-	TRACE(TARG1, value);
+	TRACE(TARGp, value);
 	JNIEnv *thisenv = getEnv();
 	SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_ScalarStringMethodID, value);
     return checkRef(thisenv, result);
 }
 
 SEXP Rf_ScalarLogical(int value) {
-	TRACE(TARG1, value);
+	TRACE(TARGp, value);
 	JNIEnv *thisenv = getEnv();
 	SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_ScalarLogicalMethodID, value);
     return checkRef(thisenv, result);
@@ -262,17 +262,17 @@ SEXP Rf_ScalarLogical(int value) {
 
 SEXP Rf_allocVector3(SEXPTYPE t, R_xlen_t len, R_allocator_t* allocator) {
     if (allocator != NULL) {
-	unimplemented("RF_allocVector with custom allocator");
-	return NULL;
+  	    unimplemented("RF_allocVector with custom allocator");
+	    return NULL;
     }
-    TRACE(TARG2d, t, len);
+    TRACE(TARGpd, t, len);
     JNIEnv *thisenv = getEnv();
     SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_allocateVectorMethodID, t, len);
     return checkRef(thisenv, result);
 }
 
 SEXP Rf_allocArray(SEXPTYPE t, SEXP dims) {
-	TRACE(TARG2d, t, dims);
+	TRACE(TARGppd, t, dims);
 	JNIEnv *thisenv = getEnv();
 	SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_allocateArrayMethodID, t, dims);
 	return checkRef(thisenv, result);
@@ -283,7 +283,7 @@ SEXP Rf_alloc3DArray(SEXPTYPE t, int x, int y, int z) {
 }
 
 SEXP Rf_allocMatrix(SEXPTYPE mode, int nrow, int ncol) {
-	TRACE(TARG2d, mode, nrow, ncol);
+	TRACE(TARGppd, mode, nrow, ncol);
 	JNIEnv *thisenv = getEnv();
 	SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_allocateMatrixMethodID, mode, nrow, ncol);
 	return checkRef(thisenv, result);
@@ -299,12 +299,14 @@ SEXP Rf_allocSExp(SEXPTYPE t) {
 }
 
 SEXP Rf_cons(SEXP car, SEXP cdr) {
+	TRACE(TARGpp, car, cdr);
 	JNIEnv *thisenv = getEnv();
 	SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_consMethodID, car, cdr);
     return checkRef(thisenv, result);
 }
 
 void Rf_defineVar(SEXP symbol, SEXP value, SEXP rho) {
+	TRACE(TARGppp, symbol, value, rho);
 	JNIEnv *thisenv = getEnv();
 	(*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_defineVarMethodID, symbol, value, rho);
 }
@@ -322,54 +324,63 @@ SEXP Rf_dimnamesgets(SEXP x, SEXP y) {
 }
 
 SEXP Rf_eval(SEXP expr, SEXP env) {
+	TRACE(TARGpp, expr, env);
     JNIEnv *thisenv = getEnv();
     SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_evalMethodID, expr, env);
     return checkRef(thisenv, result);
 }
 
 SEXP Rf_findFun(SEXP symbol, SEXP rho) {
+	TRACE(TARGpp, symbol, rho);
 	JNIEnv *thisenv = getEnv();
 	SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_findfunMethodID, symbol, rho);
 	return checkRef(thisenv, result);
 }
 
 SEXP Rf_findVar(SEXP sym, SEXP rho) {
+	TRACE(TARGpp, sym, rho);
 	JNIEnv *thisenv = getEnv();
 	SEXP result =(*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_findVarMethodID, sym, rho);
     return checkRef(thisenv, result);
 }
 
 SEXP Rf_findVarInFrame(SEXP rho, SEXP sym) {
+	TRACE(TARGpp, rho, sym);
 	JNIEnv *thisenv = getEnv();
 	SEXP result =(*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_findVarInFrameMethodID, rho, sym);
     return checkRef(thisenv, result);
 }
 
 SEXP Rf_findVarInFrame3(SEXP rho, SEXP sym, Rboolean b) {
+	TRACE(TARGppd, rho, sym, b);
 	JNIEnv *thisenv = getEnv();
 	SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_findVarInFrame3MethodID, rho, sym, b);
     return checkRef(thisenv, result);
 }
 
 SEXP Rf_getAttrib(SEXP vec, SEXP name) {
+	TRACE(TARGpp, vec, name);
 	JNIEnv *thisenv = getEnv();
 	SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_getAttribMethodID, vec, name);
 	return checkRef(thisenv, result);
 }
 
 SEXP Rf_setAttrib(SEXP vec, SEXP name, SEXP val) {
+	TRACE(TARGppp, vec,name, val);
 	JNIEnv *thisenv = getEnv();
 	(*thisenv)->CallStaticVoidMethod(thisenv, CallRFFIHelperClass, Rf_setAttribMethodID, vec, name, val);
 	return val;
 }
 
 SEXP Rf_duplicate(SEXP x) {
+	TRACE(TARGp, x);
 	JNIEnv *thisenv = getEnv();
 	SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_duplicateMethodID, x);
 	return checkRef(thisenv, result);
 }
 
 R_xlen_t Rf_any_duplicated(SEXP x, Rboolean from_last) {
+	TRACE(TARGpd, x, from_last);
     if (!isVector(x)) error(_("'duplicated' applies only to vectors"));
 	JNIEnv *thisenv = getEnv();
     return (*thisenv)->CallStaticIntMethod(thisenv, CallRFFIHelperClass, Rf_anyDuplicatedMethodID, x, from_last);
@@ -397,6 +408,7 @@ int Rf_countContexts(int x, int y) {
 }
 
 Rboolean Rf_inherits(SEXP x, const char * klass) {
+	TRACE(TARGps, x, klass);
     JNIEnv *thisenv = getEnv();
     jstring klazz = (*thisenv)->NewStringUTF(thisenv, klass);
     return (*thisenv)->CallStaticIntMethod(thisenv, CallRFFIHelperClass, Rf_inheritsMethodID, x, klazz);
@@ -436,6 +448,7 @@ void Rf_PrintValue(SEXP x) {
 }
 
 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);
@@ -443,7 +456,7 @@ SEXP Rf_install(const char *name) {
 }
 
 SEXP Rf_installChar(SEXP charsxp) {
-	TRACE("%s(%p)\n", charsxp);
+	TRACE(TARGp, charsxp);
 	JNIEnv *thisenv = getEnv();
 	jstring string = stringFromCharSXP(thisenv, charsxp);
 	SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, RDataFactoryClass, createSymbolMethodID, string);
@@ -484,6 +497,7 @@ SEXP Rf_mkCharLen(const char *x, int y) {
 }
 
 SEXP Rf_mkCharLenCE(const char *x, int len, cetype_t enc) {
+	TRACE(TARGsdd, x, len, enc);
 	JNIEnv *thisenv = getEnv();
 	jbyteArray bytes = (*thisenv)->NewByteArray(thisenv, len);
 	(*thisenv)->SetByteArrayRegion(thisenv, bytes, 0, len, x);
@@ -668,7 +682,7 @@ const char *Rf_translateCharUTF8(SEXP x) {
 }
 
 SEXP Rf_lengthgets(SEXP x, R_len_t y) {
-	TRACE("%s(%p)\n", x);
+	TRACE(TARGp, x);
 	JNIEnv *thisenv = getEnv();
 	invalidateCopiedObject(thisenv, x);
 	SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_lengthgetsMethodID, x, y);
@@ -762,28 +776,28 @@ void Rf_gsetVar(SEXP symbol, SEXP value, SEXP rho)
 }
 
 SEXP TAG(SEXP e) {
-    TRACE(TARG1, e);
+    TRACE(TARGp, e);
     JNIEnv *thisenv = getEnv();
     SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, TAG_MethodID, e);
     return checkRef(thisenv, result);
 }
 
 SEXP PRINTNAME(SEXP e) {
-    TRACE(TARG1, e);
+    TRACE(TARGp, e);
     JNIEnv *thisenv = getEnv();
     SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, PRINTNAME_MethodID, e);
     return checkRef(thisenv, result);
 }
 
 SEXP CAR(SEXP e) {
-    TRACE(TARG1, e);
+    TRACE(TARGp, e);
     JNIEnv *thisenv = getEnv();
     SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, CAR_MethodID, e);
     return checkRef(thisenv, result);
 }
 
 SEXP CDR(SEXP e) {
-    TRACE(TARG1, e);
+    TRACE(TARGp, e);
     JNIEnv *thisenv = getEnv();
     SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, CDR_MethodID, e);
     return checkRef(thisenv, result);
@@ -800,7 +814,7 @@ SEXP CDAR(SEXP e) {
 }
 
 SEXP CADR(SEXP e) {
-    TRACE(TARG1, e);
+    TRACE(TARGp, e);
     JNIEnv *thisenv = getEnv();
     SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, CADR_MethodID, e);
     return checkRef(thisenv, result);
@@ -841,20 +855,20 @@ void SET_MISSING(SEXP x, int v) {
 }
 
 void SET_TAG(SEXP x, SEXP y) {
-    TRACE(TARG2, x, y);
+    TRACE(TARGpp, x, y);
     JNIEnv *thisenv = getEnv();
     (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, SET_TAG_MethodID, x, y);
 }
 
 SEXP SETCAR(SEXP x, SEXP y) {
-    TRACE(TARG2, x, y);
+    TRACE(TARGpp, x, y);
     JNIEnv *thisenv = getEnv();
     SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, SETCAR_MethodID, x, y);
     return checkRef(thisenv, result);
 }
 
 SEXP SETCDR(SEXP x, SEXP y) {
-    TRACE(TARG2, x, y);
+    TRACE(TARGpp, x, y);
     JNIEnv *thisenv = getEnv();
     SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, SETCDR_MethodID, x, y);
     return checkRef(thisenv, result);
@@ -1031,7 +1045,7 @@ void SET_PRCODE(SEXP x, SEXP v) {
 }
 
 int LENGTH(SEXP x) {
-    TRACE(TARG1, x);
+    TRACE(TARGp, x);
     JNIEnv *thisenv = getEnv();
     return (*thisenv)->CallStaticIntMethod(thisenv, CallRFFIHelperClass, LENGTH_MethodID, x);
 }
@@ -1082,7 +1096,7 @@ int SETLEVELS(SEXP x, int v){
 }
 
 int *LOGICAL(SEXP x){
-	TRACE(TARG1, x);
+	TRACE(TARGp, x);
 	JNIEnv *thisenv = getEnv();
 	jint *data = (jint *) findCopiedObject(thisenv, x);
 	if (data == NULL) {
@@ -1101,7 +1115,7 @@ int *LOGICAL(SEXP x){
 }
 
 int *INTEGER(SEXP x){
-	TRACE(TARG1, x);
+	TRACE(TARGp, x);
 	JNIEnv *thisenv = getEnv();
 	jint *data = (jint *) findCopiedObject(thisenv, x);
 	if (data == NULL) {
@@ -1147,7 +1161,7 @@ Rcomplex *COMPLEX(SEXP x){
 
 
 SEXP STRING_ELT(SEXP x, R_xlen_t i){
-	TRACE(TARG2d, x, i);
+	TRACE(TARGpd, x, i);
 	JNIEnv *thisenv = getEnv();
     SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, STRING_ELT_MethodID, x, i);
     return checkRef(thisenv, result);
@@ -1155,7 +1169,7 @@ SEXP STRING_ELT(SEXP x, R_xlen_t i){
 
 
 SEXP VECTOR_ELT(SEXP x, R_xlen_t i){
-	TRACE(TARG2d, x, i);
+	TRACE(TARGpd, x, i);
 	JNIEnv *thisenv = getEnv();
     SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, VECTOR_ELT_MethodID, x, i);
     return checkRef(thisenv, result);
@@ -1188,14 +1202,14 @@ SEXP *VECTOR_PTR(SEXP x){
 }
 
 SEXP Rf_asChar(SEXP x){
-	TRACE(TARG1, x);
+	TRACE(TARGp, x);
 	JNIEnv *thisenv = getEnv();
 	SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_asCharMethodID, x);
 	return checkRef(thisenv, result);
 }
 
 SEXP Rf_PairToVectorList(SEXP x){
-	TRACE(TARG1, x);
+	TRACE(TARGp, x);
 	JNIEnv *thisenv = getEnv();
 	SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_PairToVectorListMethodID, x);
 	return checkRef(thisenv, result);
@@ -1212,19 +1226,19 @@ SEXP Rf_asCharacterFactor(SEXP x){
 }
 
 int Rf_asLogical(SEXP x){
-	TRACE(TARG1, x);
+	TRACE(TARGp, x);
 	JNIEnv *thisenv = getEnv();
 	return (*thisenv)->CallStaticIntMethod(thisenv, CallRFFIHelperClass, Rf_asLogicalMethodID, x);
 }
 
 int Rf_asInteger(SEXP x) {
-	TRACE(TARG1, x);
+	TRACE(TARGp, x);
 	JNIEnv *thisenv = getEnv();
 	return (*thisenv)->CallStaticIntMethod(thisenv, CallRFFIHelperClass, Rf_asIntegerMethodID, x);
 }
 
 //double Rf_asReal(SEXP x) {
-//	TRACE(TARG1, x);
+//	TRACE(TARGp, x);
 //	JNIEnv *thisenv = getEnv();
 //	return (*thisenv)->CallStaticDoubleMethod(thisenv, CallRFFIHelperClass, Rf_asRealMethodID, x);
 //}
@@ -1235,7 +1249,7 @@ Rcomplex Rf_asComplex(SEXP x){
 }
 
 int TYPEOF(SEXP x) {
-	TRACE(TARG1, x);
+	TRACE(TARGp, x);
 	JNIEnv *thisenv = getEnv();
 	return (*thisenv)->CallStaticIntMethod(thisenv, CallRFFIHelperClass, TYPEOF_MethodID, x);
 }
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 2018a4e1dc1feef251b7eb31ca217117b3357183..549455e5c8aecbb100f6099e8a04f4586c41389e 100644
--- a/com.oracle.truffle.r.native/fficall/src/jni/rffiutils.c
+++ b/com.oracle.truffle.r.native/fficall/src/jni/rffiutils.c
@@ -47,9 +47,11 @@ jmp_buf *callErrorJmpBuf;
 
 #define DEBUG_CACHE 0
 #define TRACE_COPIES 0
-#define CACHED_GLOBALREFS_TABLE_SIZE 100
-static SEXP cachedGlobalRefs[CACHED_GLOBALREFS_TABLE_SIZE];
-static SEXP checkCachedGlobalRef(JNIEnv *env, SEXP obj);
+
+static int alwaysUseGlobal = 0;
+#define CACHED_GLOBALREFS_INITIAL_SIZE 64
+static SEXP *cachedGlobalRefs;
+static int cachedGlobalRefsLength;
 
 typedef struct CopiedVectors_struct {
 	SEXPTYPE type;
@@ -58,7 +60,7 @@ typedef struct CopiedVectors_struct {
 	void *data;
 } CopiedVector;
 
-#define COPIED_VECTORS_INITIAL_SIZE 100
+#define COPIED_VECTORS_INITIAL_SIZE 64
 // A table of vectors that have been accessed and whose contents, e.g. the actual data
 // as a primitive array have been copied and handed out to the native code.
 static CopiedVector *copiedVectors;
@@ -76,10 +78,9 @@ void init_utils(JNIEnv *env) {
 	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);
-    for (int i = 0; i < CACHED_GLOBALREFS_TABLE_SIZE; i++) {
-    	cachedGlobalRefs[i] = NULL;
-    }
-	copiedVectors = malloc(sizeof(CopiedVector) * COPIED_VECTORS_INITIAL_SIZE);
+    cachedGlobalRefs = calloc(CACHED_GLOBALREFS_INITIAL_SIZE, sizeof(SEXP));
+    cachedGlobalRefsLength = CACHED_GLOBALREFS_INITIAL_SIZE;
+	copiedVectors = calloc(COPIED_VECTORS_INITIAL_SIZE, sizeof(CopiedVector));
 	copiedVectorsLength = COPIED_VECTORS_INITIAL_SIZE;
 	copiedVectorsIndex = 0;
 }
@@ -197,9 +198,9 @@ void addCopiedObject(JNIEnv *env, SEXP x, SEXPTYPE type, void *jArray, void *dat
 #endif
 	if (copiedVectorsIndex >= copiedVectorsLength) {
 		int newLength = 2 * copiedVectorsLength;
-		CopiedVector *newCopiedVectors = malloc(sizeof(CopiedVector) * newLength);
+		CopiedVector *newCopiedVectors = calloc(newLength, sizeof(CopiedVector));
 		if (newCopiedVectors == NULL) {
-			fatalError("malloc failure");
+			fatalError("FFI copied vectors table expansion failure");
 		}
 		memcpy(newCopiedVectors, copiedVectors, copiedVectorsLength * sizeof(CopiedVector));
 		free(copiedVectors);
@@ -216,41 +217,52 @@ void addCopiedObject(JNIEnv *env, SEXP x, SEXPTYPE type, void *jArray, void *dat
 #endif
 }
 
-SEXP checkRef(JNIEnv *env, SEXP obj) {
-	SEXP result = checkCachedGlobalRef(env, obj);
-	return result;
-}
-
-SEXP mkNamedGlobalRef(JNIEnv *env, int index, SEXP obj) {
-	SEXP result = (*env)->NewGlobalRef(env, obj);
-	if (cachedGlobalRefs[index] != NULL) {
-		fatalError("duplicate named global ref index\n");
+static SEXP checkCachedGlobalRef(JNIEnv *env, SEXP obj, int useGlobal) {
+	int i;
+	for (i = 0; i < cachedGlobalRefsLength; i++) {
+		SEXP ref = cachedGlobalRefs[i];
+		if (ref == NULL) {
+			break;
+		}
+		if ((*env)->IsSameObject(env, ref, obj)) {
+#if DEBUG_CACHE
+			printf("gref: cache hit: %d\n", i);
+#endif
+			return ref;
+		}
 	}
-	cachedGlobalRefs[index] = result;
+	SEXP result;
+	if (useGlobal) {
+		if (i >= cachedGlobalRefsLength) {
+			int newLength = cachedGlobalRefsLength * 2;
 #if DEBUG_CACHE
-	printf("gref: %d=%p\n", index, result);
+			printf("gref: extending table to %d\n", newLength);
 #endif
+			SEXP newCachedGlobalRefs = calloc(newLength, sizeof(SEXP));
+			if (newCachedGlobalRefs == NULL) {
+				fatalError("FFI global refs table expansion failure");
+			}
+			memcpy(newCachedGlobalRefs, cachedGlobalRefs, cachedGlobalRefsLength * sizeof(SEXP));
+			free(cachedGlobalRefs);
+			cachedGlobalRefs = newCachedGlobalRefs;
+			cachedGlobalRefsLength = newLength;
+		}
+		result = (*env)->NewGlobalRef(env, obj);
+		cachedGlobalRefs[i] = result;
+	} else {
+		result = obj;
+	}
 	return result;
 }
 
-static SEXP checkCachedGlobalRef(JNIEnv *env, SEXP obj) {
-    for (int i = 0; i < CACHED_GLOBALREFS_TABLE_SIZE; i++) {
-    	SEXP ref = cachedGlobalRefs[i];
-    	if (ref == NULL) {
-    		break;
-    	}
-    	if ((*env)->IsSameObject(env, ref, obj)) {
-#if DEBUG_CACHE
-    		printf("gref: cache hit: %d\n", i);
-#endif
-    		return ref;
-    	}
-    }
-#if USE_GLOBAL
-    SEXP result = (*env)->NewGlobalRef(env, obj);
-#else
-    SEXP result = obj;
-#endif
+SEXP checkRef(JNIEnv *env, SEXP obj) {
+	SEXP result = checkCachedGlobalRef(env, obj, alwaysUseGlobal);
+	TRACE(TARGp, result);
+	return result;
+}
+
+SEXP mkNamedGlobalRef(JNIEnv *env, SEXP obj) {
+	SEXP result = checkCachedGlobalRef(env, obj, 1);
 	return result;
 }
 
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 ee157855cde1a4692e6383e7cca5b585db966eae..784236055a1f1cc83ecc52ada79dce1266b84eaa 100644
--- a/com.oracle.truffle.r.native/fficall/src/jni/rffiutils.h
+++ b/com.oracle.truffle.r.native/fficall/src/jni/rffiutils.h
@@ -48,8 +48,8 @@ void fatalError(char *msg);
 void validate(SEXP x);
 // checks x against the list of canonical (named) refs, returning the canonical version if a match
 SEXP checkRef(JNIEnv *env, SEXP x);
-// creates a JNI global ref from x for slot index of the named refs table
-SEXP mkNamedGlobalRef(JNIEnv *env, int index, SEXP x);
+// creates a canonical (named) JNI global ref from x
+SEXP mkNamedGlobalRef(JNIEnv *env, SEXP x);
 // validate a JNI reference
 void validateRef(JNIEnv *env, SEXP x, const char *msg);
 
@@ -84,9 +84,14 @@ extern jclass RRuntimeClass;
 
 #define TRACE_UPCALLS 0
 
-#define TARG1 "%s(%p)\n"
-#define TARG2 "%s(%p, %p)\n"
-#define TARG2d "%s(%p, %d)\n"
+#define TARGp "%s(%p)\n"
+#define TARGpp "%s(%p, %p)\n"
+#define TARGppp "%s(%p, %p, %p)\n"
+#define TARGpd "%s(%p, %d)\n"
+#define TARGppd "%s(%p, %p, %d)\n"
+#define TARGs "%s(\"%s\")\n"
+#define TARGps "%s(%p, \"%s\")\n"
+#define TARGsdd "%s(\"%s\", %d, %d)\n"
 
 #if TRACE_UPCALLS
 #define TRACE(format, ...) printf(format, __FUNCTION__, __VA_ARGS__)
diff --git a/com.oracle.truffle.r.native/fficall/src/jni/variables.c b/com.oracle.truffle.r.native/fficall/src/jni/variables.c
index 858e7507beb193bfe812fc13c1e10da85e251016..623b68725bfbaddd1b544e9b25bc3eba1cea9a3b 100644
--- a/com.oracle.truffle.r.native/fficall/src/jni/variables.c
+++ b/com.oracle.truffle.r.native/fficall/src/jni/variables.c
@@ -78,7 +78,6 @@ void init_variables(JNIEnv *env, jobjectArray initialValues) {
 
 	int length = (*env)->GetArrayLength(env, initialValues);
 	int index;
-	int globalRefIndex = 0;
 	for (index = 0; index < length; index++) {
 		jobject variable = (*env)->GetObjectArrayElement(env, initialValues, index);
 		jstring nameString = (*env)->CallObjectMethod(env, variable, nameMethodID);
@@ -98,7 +97,7 @@ void init_variables(JNIEnv *env, jobjectArray initialValues) {
 			} else if (strcmp(nameChars, "R_NaInt") == 0) {
 				R_NaInt = (*env)->CallIntMethod(env, value, intValueMethodID);
 			} else {
-				SEXP ref = mkNamedGlobalRef(env, globalRefIndex++, value);
+				SEXP ref = mkNamedGlobalRef(env, value);
 				if (strcmp(nameChars, "R_EmptyEnv") == 0) {
 					R_EmptyEnv = ref;
 				} else if (strcmp(nameChars, "R_NilValue") == 0) {