diff --git a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/RAbstractVectorAccessFactory.java b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/RAbstractVectorAccessFactory.java index 5cd19ab664801dd4672e28b25376aa76adc3f57d..6e7fdef1027291b64163674d37218aa2640c9fc9 100644 --- a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/RAbstractVectorAccessFactory.java +++ b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/RAbstractVectorAccessFactory.java @@ -94,6 +94,7 @@ public final class RAbstractVectorAccessFactory implements Factory26 { @Cached("createKeyInfoNode()") VectorKeyInfoImplNode keyInfo) { int info = keyInfo.execute(frame, receiver, idx); if (unknownIdentifier.profile(!KeyInfo.isExisting(info))) { + CompilerDirectives.transferToInterpreter(); throw UnknownIdentifierException.raise("" + idx); } return read(receiver, new Object[]{idx + 1}); @@ -104,6 +105,7 @@ public final class RAbstractVectorAccessFactory implements Factory26 { @Cached("createKeyInfoNode()") VectorKeyInfoImplNode keyInfo) { int info = keyInfo.execute(frame, receiver, idx); if (unknownIdentifier.profile(!KeyInfo.isExisting(info))) { + CompilerDirectives.transferToInterpreter(); throw UnknownIdentifierException.raise("" + idx); } return read(receiver, new Object[]{idx + 1}); @@ -124,6 +126,7 @@ public final class RAbstractVectorAccessFactory implements Factory26 { @Fallback protected Object read(@SuppressWarnings("unused") Object receiver, Object indentifier) { + CompilerDirectives.transferToInterpreter(); throw UnknownIdentifierException.raise("" + indentifier); } @@ -172,6 +175,7 @@ public final class RAbstractVectorAccessFactory implements Factory26 { @Fallback protected Object write(@SuppressWarnings("unused") Object receiver, Object field, @SuppressWarnings("unused") Object object) { + CompilerDirectives.transferToInterpreter(); throw UnknownIdentifierException.raise("" + field); } } diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/common/JavaUpCallsRFFIImpl.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/common/JavaUpCallsRFFIImpl.java index 81e8940e45ef8ac53c0f6a3857aaea1db95e4d55..a34050460abaabc7cd1cc2a5211859fb1cb193a7 100644 --- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/common/JavaUpCallsRFFIImpl.java +++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/common/JavaUpCallsRFFIImpl.java @@ -211,6 +211,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public int Rf_defineVar(Object symbolArg, Object value, Object envArg) { REnvironment env = (REnvironment) envArg; RSymbol name = (RSymbol) symbolArg; @@ -223,6 +224,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object R_getClassDef(String clazz) { String name = "getClassDef"; RFunction getClass = (RFunction) RContext.getRRuntimeASTAccess().forcePromise(name, REnvironment.getRegisteredNamespace("methods").get(name)); @@ -230,6 +232,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object R_do_MAKE_CLASS(String clazz) { String name = "getClass"; RFunction getClass = (RFunction) RContext.getRRuntimeASTAccess().forcePromise(name, REnvironment.getRegisteredNamespace("methods").get(name)); @@ -242,6 +245,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object Rf_findVar(Object symbolArg, Object envArg) { return findVarInFrameHelper(envArg, symbolArg, true); } @@ -287,13 +291,14 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object Rf_getAttrib(Object obj, Object name) { Object result = RNull.instance; if (obj instanceof RAttributable) { RAttributable attrObj = (RAttributable) obj; DynamicObject attrs = attrObj.getAttributes(); if (attrs != null) { - String nameAsString = ((RSymbol) name).getName().intern(); + String nameAsString = Utils.intern(((RSymbol) name).getName()); Object attr = attrs.get(nameAsString); if (attr != null) { result = attr; @@ -315,7 +320,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { nameAsString = RRuntime.asString(name); assert nameAsString != null; } - nameAsString = nameAsString.intern(); + nameAsString = Utils.intern(nameAsString); if (val == RNull.instance) { removeAttr(attrObj, nameAsString); } else if ("class" == nameAsString) { @@ -339,6 +344,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public int Rf_inherits(Object x, String clazz) { int result = 0; RStringVector hierarchy = getClassHr(x); @@ -351,6 +357,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object Rf_install(String name) { Object ret = nameSymbolCache.get(name); if (ret == null) { @@ -361,18 +368,21 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object Rf_installChar(Object name) { CharSXPWrapper charSXP = guaranteeInstanceOf(name, CharSXPWrapper.class); return RDataFactory.createSymbolInterned(charSXP.getContents()); } @Override + @TruffleBoundary public Object Rf_lengthgets(Object x, int newSize) { RAbstractVector vec = (RAbstractVector) RRuntime.asAbstractVector(x); return vec.resize(newSize); } @Override + @TruffleBoundary public int Rf_isString(Object x) { return RRuntime.checkType(x, RType.Character) ? 1 : 0; } @@ -383,6 +393,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object Rf_PairToVectorList(Object x) { if (x == RNull.instance) { return RDataFactory.createList(); @@ -392,30 +403,35 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public int Rf_error(String msg) { RError.error(RError.SHOW_CALLER2, RError.Message.GENERIC, msg); return 0; } @Override + @TruffleBoundary public int Rf_warning(String msg) { RError.warning(RError.SHOW_CALLER2, RError.Message.GENERIC, msg); return 0; } @Override + @TruffleBoundary public int Rf_warningcall(Object call, String msg) { RErrorHandling.warningcallRFFI(call, msg); return 0; } @Override + @TruffleBoundary public int Rf_errorcall(Object call, String msg) { RErrorHandling.errorcallRFFI(call, msg); return 0; } @Override + @TruffleBoundary public Object Rf_allocVector(int mode, long n) { SEXPTYPE type = SEXPTYPE.mapInt(mode); if (n > Integer.MAX_VALUE) { @@ -449,6 +465,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object Rf_allocArray(int mode, Object dimsObj) { RIntVector dims = (RIntVector) dimsObj; int n = 1; @@ -470,6 +487,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object Rf_allocMatrix(int mode, int nrow, int ncol) { SEXPTYPE type = SEXPTYPE.mapInt(mode); if (nrow < 0 || ncol < 0) { @@ -496,11 +514,13 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public int Rf_nrows(Object x) { return RRuntime.nrows(x); } @Override + @TruffleBoundary public int Rf_ncols(Object x) { return RRuntime.ncols(x); } @@ -586,6 +606,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object SET_TYPEOF_FASTR(Object x, int v) { int code = SEXPTYPE.gnuRCodeForObject(x); if (code == SEXPTYPE.LISTSXP.code && v == SEXPTYPE.LANGSXP.code) { @@ -615,6 +636,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object Rf_duplicate(Object x, int deep) { guarantee(x != null, "unexpected type: null instead of " + x.getClass().getSimpleName()); guarantee(x instanceof RShareable || x instanceof RSequence || x instanceof RExternalPtr, @@ -629,6 +651,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public long Rf_any_duplicated(Object x, int fromLast) { RAbstractVector vec = (RAbstractVector) x; if (vec.getLength() == 0) { @@ -704,6 +727,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object SYMVALUE(Object x) { if (!(x instanceof RSymbol)) { throw RInternalError.shouldNotReachHere(); @@ -717,6 +741,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public int SET_SYMVALUE(Object x, Object v) { if (!(x instanceof RSymbol)) { throw RInternalError.shouldNotReachHere(); @@ -726,6 +751,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public int R_BindingIsLocked(Object sym, Object env) { guaranteeInstanceOf(sym, RSymbol.class); guaranteeInstanceOf(env, REnvironment.class); @@ -733,6 +759,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object R_FindNamespace(Object name) { Object result = RContext.getInstance().stateREnvironment.getNamespaceRegistry().get(RRuntime.asString(name)); return result; @@ -757,6 +784,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object Rf_eval(Object expr, Object env) { guarantee(env instanceof REnvironment); Object result; @@ -789,6 +817,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object Rf_findFun(Object symbolObj, Object envObj) { guarantee(envObj instanceof REnvironment); REnvironment env = (REnvironment) envObj; @@ -805,6 +834,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object Rf_GetOption1(Object tag) { guarantee(tag instanceof RSymbol); Object result = RContext.getInstance().stateROptions.getValue(((RSymbol) tag).getName()); @@ -812,6 +842,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public int Rf_gsetVar(Object symbol, Object value, Object rho) { guarantee(symbol instanceof RSymbol); REnvironment baseEnv = RContext.getInstance().stateREnvironment.getBaseEnv(); @@ -825,6 +856,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public int DUPLICATE_ATTRIB(Object to, Object from) { if (from instanceof RAttributable) { guaranteeInstanceOf(to, RAttributable.class); @@ -850,6 +882,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public int Rf_copyMatrix(Object t, Object s, int byRow) { int tRows = RRuntime.nrows(t); int tCols = RRuntime.ncols(t); @@ -982,6 +1015,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object R_tryEval(Object expr, Object env, int silent) { Object handlerStack = RErrorHandling.getHandlerStack(); Object restartStack = RErrorHandling.getRestartStack(); @@ -1003,11 +1037,13 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { * ONLY called from R_TopLevelExec prior to calling C function. */ @Override + @TruffleBoundary public Object R_ToplevelExec() { return RErrorHandling.resetAndGetHandlerStacks(); } @Override + @TruffleBoundary public int RDEBUG(Object x) { REnvironment env = guaranteeInstanceOf(x, REnvironment.class); if (env instanceof REnvironment.Function) { @@ -1020,6 +1056,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public int SET_RDEBUG(Object x, int v) { REnvironment env = guaranteeInstanceOf(x, REnvironment.class); if (env instanceof REnvironment.Function) { @@ -1035,6 +1072,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public int RSTEP(Object x) { @SuppressWarnings("unused") REnvironment env = guaranteeInstanceOf(x, REnvironment.class); @@ -1042,6 +1080,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public int SET_RSTEP(Object x, int v) { @SuppressWarnings("unused") REnvironment env = guaranteeInstanceOf(x, REnvironment.class); @@ -1073,6 +1112,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object R_ParseVector(Object text, int n, Object srcFile) { // TODO general case + all statuses assert n == 1 : "unsupported: R_ParseVector with n != 0."; @@ -1097,6 +1137,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object R_lsInternal3(Object envArg, int allArg, int sortedArg) { boolean sorted = sortedArg != 0; boolean all = allArg != 0; @@ -1105,17 +1146,20 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public String R_HomeDir() { return REnvVars.rHome(); } @Override + @TruffleBoundary public int R_CleanUp(int sa, int status, int runlast) { RCleanUp.stdCleanUp(SA_TYPE.values()[sa], status, runlast != 0); return 0; } @Override + @TruffleBoundary public Object R_GlobalContext() { Utils.warn("Potential memory leak (global context object)"); Frame frame = Utils.getActualCurrentFrame(); @@ -1172,24 +1216,28 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public int Rprintf(String message) { RContext.getInstance().getConsole().print(message); return 0; } @Override + @TruffleBoundary public int GetRNGstate() { RRNG.getRNGState(); return 0; } @Override + @TruffleBoundary public int PutRNGstate() { RRNG.putRNGState(); return 0; } @Override + @TruffleBoundary public double unif_rand() { return RRNG.unifRand(); } @@ -1197,6 +1245,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { // Checkstyle: stop method name check @Override + @TruffleBoundary public Object R_getGlobalFunctionContext() { Utils.warn("Potential memory leak (global function context object)"); Frame frame = Utils.getActualCurrentFrame(); @@ -1214,6 +1263,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object R_getParentFunctionContext(Object c) { Utils.warn("Potential memory leak (parent function context object)"); RCaller currentCaller = guaranteeInstanceOf(c, RCaller.class); @@ -1228,6 +1278,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object R_getContextEnv(Object c) { RCaller rCaller = guaranteeInstanceOf(c, RCaller.class); if (rCaller == RCaller.topLevel) { @@ -1254,6 +1305,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object R_getContextFun(Object c) { RCaller rCaller = guaranteeInstanceOf(c, RCaller.class); if (rCaller == RCaller.topLevel) { @@ -1280,6 +1332,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object R_getContextCall(Object c) { RCaller rCaller = guaranteeInstanceOf(c, RCaller.class); if (rCaller == RCaller.topLevel) { @@ -1289,6 +1342,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object R_getContextSrcRef(Object c) { Object o = R_getContextFun(c); if (!(o instanceof RFunction)) { @@ -1303,6 +1357,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public int R_insideBrowser() { return RContext.getInstance().stateInstrumentation.getBrowserState().inBrowser() ? 1 : 0; } @@ -1404,6 +1459,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object PRCODE(Object x) { RPromise promise = RFFIUtils.guaranteeInstanceOf(x, RPromise.class); RSyntaxNode expr = RASTUtils.unwrap(promise.getRep()).asRSyntaxNode(); @@ -1411,6 +1467,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object R_new_custom_connection(String description, String mode, String className, Object connAddrObj) { // TODO handle encoding properly ! RExternalPtr connAddr = guaranteeInstanceOf(connAddrObj, RExternalPtr.class); @@ -1422,6 +1479,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public int R_ReadConnection(int fd, long bufAddress, int size) { // Workaround using Unsafe until GR-5927 is fixed byte[] buf = new byte[size]; @@ -1437,6 +1495,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public int R_WriteConnection(int fd, long bufAddress, int size) { // Workaround using Unsafe until GR-5927 is fixed byte[] buf = new byte[size]; @@ -1451,29 +1510,34 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object R_GetConnection(int fd) { return RConnection.fromIndex(fd); } @Override + @TruffleBoundary public String getSummaryDescription(Object x) { BaseRConnection conn = guaranteeInstanceOf(x, BaseRConnection.class); return conn.getSummaryDescription(); } @Override + @TruffleBoundary public String getConnectionClassString(Object x) { BaseRConnection conn = guaranteeInstanceOf(x, BaseRConnection.class); return conn.getConnectionClass(); } @Override + @TruffleBoundary public String getOpenModeString(Object x) { BaseRConnection conn = guaranteeInstanceOf(x, BaseRConnection.class); return conn.getOpenMode().toString(); } @Override + @TruffleBoundary public boolean isSeekable(Object x) { BaseRConnection conn = guaranteeInstanceOf(x, BaseRConnection.class); return conn.isSeekable(); @@ -1490,11 +1554,13 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object R_MethodsNamespace() { return REnvironment.getRegisteredNamespace("methods"); } @Override + @TruffleBoundary public void R_PreserveObject(Object obj) { guaranteeInstanceOf(obj, RObject.class); HashSet<RObject> list = getContext().preserveList; @@ -1502,6 +1568,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public void R_ReleaseObject(Object obj) { guaranteeInstanceOf(obj, RObject.class); HashSet<RObject> list = getContext().preserveList; @@ -1509,12 +1576,14 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public Object Rf_protect(Object x) { getContext().protectStack.add(guaranteeInstanceOf(x, RObject.class)); return x; } @Override + @TruffleBoundary public void Rf_unprotect(int x) { RFFIContext context = getContext(); ArrayList<RObject> stack = context.protectStack; @@ -1524,6 +1593,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public int R_ProtectWithIndex(Object x) { ArrayList<RObject> stack = getContext().protectStack; stack.add(guaranteeInstanceOf(x, RObject.class)); @@ -1531,12 +1601,14 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public void R_Reprotect(Object x, int y) { ArrayList<RObject> stack = getContext().protectStack; stack.set(y, guaranteeInstanceOf(x, RObject.class)); } @Override + @TruffleBoundary public void Rf_unprotect_ptr(Object x) { RFFIContext context = getContext(); ArrayList<RObject> stack = context.protectStack; @@ -1549,6 +1621,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public int FASTR_getConnectionChar(Object obj) { try { return guaranteeInstanceOf(obj, RConnection.class).getc(); @@ -1599,6 +1672,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public int registerRoutines(Object dllInfoObj, int nstOrd, int num, Object routines) { DLLInfo dllInfo = guaranteeInstanceOf(dllInfoObj, DLLInfo.class); DotSymbol[] array = new DotSymbol[num]; @@ -1611,6 +1685,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public int registerCCallable(String pkgName, String functionName, Object address) { DLLInfo lib = DLL.safeFindLibrary(pkgName); lib.registerCEntry(new CEntry(functionName, new SymbolHandle(address))); @@ -1618,18 +1693,21 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { } @Override + @TruffleBoundary public int useDynamicSymbols(Object dllInfoObj, int value) { DLLInfo dllInfo = guaranteeInstanceOf(dllInfoObj, DLLInfo.class); return DLL.useDynamicSymbols(dllInfo, value); } @Override + @TruffleBoundary public int forceSymbols(Object dllInfoObj, int value) { DLLInfo dllInfo = guaranteeInstanceOf(dllInfoObj, DLLInfo.class); return DLL.forceSymbols(dllInfo, value); } @Override + @TruffleBoundary public DotSymbol setDotSymbolValues(Object dllInfoObj, String name, Object fun, int numArgs) { @SuppressWarnings("unused") DLLInfo dllInfo = guaranteeInstanceOf(dllInfoObj, DLLInfo.class); diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_CAccess.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_CAccess.java index acbc32f9818e8d1bc0100a9bb9b4d24aa994bd45..78acc95f1ad38dacacd8b39b008666492fde1f4d 100644 --- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_CAccess.java +++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_CAccess.java @@ -22,6 +22,8 @@ */ package com.oracle.truffle.r.ffi.impl.nfi; +import com.oracle.truffle.api.CompilerDirectives; +import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; import com.oracle.truffle.api.interop.ForeignAccess; import com.oracle.truffle.api.interop.InteropException; import com.oracle.truffle.api.interop.Message; @@ -38,7 +40,7 @@ public class TruffleNFI_CAccess { READ_POINTER_DOUBLE("(pointer): double"), READ_ARRAY_DOUBLE("(pointer, sint32): double"); - private TruffleObject symbolFunction; + @CompilationFinal private TruffleObject symbolFunction; private final String signature; Function(String signature) { @@ -47,6 +49,7 @@ public class TruffleNFI_CAccess { public TruffleObject getSymbolFunction() { if (symbolFunction == null) { + CompilerDirectives.transferToInterpreterAndInvalidate(); SymbolHandle symbolHandle = DLL.findSymbol(cName(), null); assert symbolHandle != null; Node bind = Message.createInvoke(1).createNode(); diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/upcalls/FFIWrapNode.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/upcalls/FFIWrapNode.java index bbf83e4735d3e74c0e36b146ab8d833ba98cd611..c97e1286f4201428fe3c768bd1f7c0e12e16b823 100644 --- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/upcalls/FFIWrapNode.java +++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/upcalls/FFIWrapNode.java @@ -22,10 +22,12 @@ */ package com.oracle.truffle.r.ffi.impl.upcalls; +import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.dsl.Fallback; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.r.ffi.impl.nfi.TruffleNFI_UpCallsRFFIImpl.VectorWrapper; +import com.oracle.truffle.r.runtime.RInternalError; import com.oracle.truffle.r.runtime.data.RComplex; import com.oracle.truffle.r.runtime.data.RDataFactory; import com.oracle.truffle.r.runtime.data.RDouble; @@ -101,8 +103,8 @@ public abstract class FFIWrapNode extends Node { @Fallback protected static Object wrap(Object value) { - System.out.println("invalid wrapping: " + value.getClass().getSimpleName()); - return value; + CompilerDirectives.transferToInterpreter(); + throw RInternalError.shouldNotReachHere("invalid wrapping: " + value.getClass().getSimpleName()); } public static FFIWrapNode create() { diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/deriv/Deriv.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/deriv/Deriv.java index 2db1002741a2ad78d23122863da374121ab3f4fc..b39ebad1daef8b87199c9de858d0b83837700633 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/deriv/Deriv.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/deriv/Deriv.java @@ -43,6 +43,7 @@ import com.oracle.truffle.r.runtime.ArgumentsSignature; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RInternalError; import com.oracle.truffle.r.runtime.RRuntime; +import com.oracle.truffle.r.runtime.Utils; import com.oracle.truffle.r.runtime.context.RContext; import com.oracle.truffle.r.runtime.context.TruffleRLanguage; import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames; @@ -618,20 +619,20 @@ public abstract class Deriv extends RExternalBuiltinNode { } private static RSyntaxNode createAssignNode(String varName, RSyntaxNode rhs) { - return RContext.getASTBuilder().call(RSyntaxNode.SOURCE_UNAVAILABLE, createLookup("<-"), createLookup(varName.intern()), addParens(rhs)); + return RContext.getASTBuilder().call(RSyntaxNode.SOURCE_UNAVAILABLE, createLookup("<-"), createLookup(Utils.intern(varName)), addParens(rhs)); } private static RSyntaxNode hessAssign1(String varName, RSyntaxNode rhs) { RSyntaxNode tmp = RContext.getASTBuilder().call(RSyntaxNode.SOURCE_UNAVAILABLE, createLookup("["), createLookup(".hessian"), ConstantNode.create(REmpty.instance), - ConstantNode.create(varName.intern()), ConstantNode.create(varName.intern())); + ConstantNode.create(Utils.intern(varName)), ConstantNode.create(Utils.intern(varName))); return RContext.getASTBuilder().call(RSyntaxNode.SOURCE_UNAVAILABLE, createLookup("<-"), tmp, rhs); } private static RSyntaxNode hessAssign2(String varName1, String varName2, RSyntaxNode rhs) { RSyntaxNode tmp1 = RContext.getASTBuilder().call(RSyntaxNode.SOURCE_UNAVAILABLE, createLookup("["), createLookup(".hessian"), ConstantNode.create(REmpty.instance), - ConstantNode.create(varName1.intern()), ConstantNode.create(varName2.intern())); + ConstantNode.create(Utils.intern(varName1)), ConstantNode.create(Utils.intern(varName2))); RSyntaxNode tmp2 = RContext.getASTBuilder().call(RSyntaxNode.SOURCE_UNAVAILABLE, createLookup("["), createLookup(".hessian"), ConstantNode.create(REmpty.instance), - ConstantNode.create(varName2.intern()), ConstantNode.create(varName1.intern())); + ConstantNode.create(Utils.intern(varName2)), ConstantNode.create(Utils.intern(varName1))); RSyntaxNode tmp3 = RContext.getASTBuilder().call(RSyntaxNode.SOURCE_UNAVAILABLE, createLookup("<-"), tmp2, rhs); return RContext.getASTBuilder().call(RSyntaxNode.SOURCE_UNAVAILABLE, createLookup("<-"), tmp1, tmp3); @@ -641,7 +642,7 @@ public abstract class Deriv extends RExternalBuiltinNode { int n = names.getLength(); List<Argument<RSyntaxNode>> cArgs = new ArrayList<>(); for (int i = 0; i < n; i++) { - cArgs.add(RCodeBuilder.argument(ConstantNode.create(names.getDataAt(i).intern()))); + cArgs.add(RCodeBuilder.argument(ConstantNode.create(Utils.intern(names.getDataAt(i))))); } RSyntaxNode tmp1 = RContext.getASTBuilder().call(RSyntaxNode.SOURCE_UNAVAILABLE, createLookup("c"), cArgs); RSyntaxNode dimnames = RContext.getASTBuilder().call(RSyntaxNode.SOURCE_UNAVAILABLE, createLookup("list"), ConstantNode.create(RNull.instance), tmp1); @@ -658,7 +659,7 @@ public abstract class Deriv extends RExternalBuiltinNode { int n = names.getLength(); List<Argument<RSyntaxNode>> cArgs = new ArrayList<>(); for (int i = 0; i < n; i++) { - cArgs.add(RCodeBuilder.argument(ConstantNode.create(names.getDataAt(i).intern()))); + cArgs.add(RCodeBuilder.argument(ConstantNode.create(Utils.intern(names.getDataAt(i))))); } RSyntaxNode tmp1 = RContext.getASTBuilder().call(RSyntaxNode.SOURCE_UNAVAILABLE, createLookup("c"), cArgs); RSyntaxNode tmp1Clone = cloneElement(tmp1); @@ -674,7 +675,7 @@ public abstract class Deriv extends RExternalBuiltinNode { private static RSyntaxNode derivAssign(String name, RSyntaxNode expr) { RSyntaxNode tmp = RContext.getASTBuilder().call(RSyntaxNode.SOURCE_UNAVAILABLE, createLookup("["), createLookup(".grad"), ConstantNode.create(REmpty.instance), - ConstantNode.create(name.intern())); + ConstantNode.create(Utils.intern(name))); return RContext.getASTBuilder().call(RSyntaxNode.SOURCE_UNAVAILABLE, createLookup("<-"), tmp, expr); } diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/utils/Crc64.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/utils/Crc64.java index 301ce24664ed88bad44dbc578435ac599edf9b9a..41b55e0ca9a926262d43476cdc95b4b1d751f50f 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/utils/Crc64.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/utils/Crc64.java @@ -42,6 +42,7 @@ public abstract class Crc64 extends RExternalBuiltinNode.Arg1 { return crc(x); } + @TruffleBoundary public static String crc(RAbstractStringVector x) { final String string = x.getDataAt(0); byte[] bytes = string.getBytes(); diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/utils/Rprof.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/utils/Rprof.java index 49efa1fd131ed509dc5d88b3a5ffebe7056d6fdb..6d8e31c50fb23dd84f95cae48c33c7c854043701 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/utils/Rprof.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/utils/Rprof.java @@ -218,20 +218,24 @@ public abstract class Rprof extends RExternalBuiltinNode.Arg8 implements MemoryC @Override public void onEnter(EventContext context, VirtualFrame frame) { if (newInterval) { - /* context tells here we are now, frame provides callers. */ - final ArrayList<RSyntaxElement> stack = new ArrayList<>(); - stack.add((RSyntaxElement) context.getInstrumentedNode()); - collectStack(stack); - intervalStacks.add(stack); - RprofState profState = RprofState.get(); - if (profState.memoryProfiling) { - intervalMemory.add(profState.memoryQuad.copyAndClear()); - } - + onEnter(context); newInterval = false; } } + @TruffleBoundary + private void onEnter(EventContext context) { + /* context tells here we are now, frame provides callers. */ + ArrayList<RSyntaxElement> stack = new ArrayList<>(); + stack.add((RSyntaxElement) context.getInstrumentedNode()); + collectStack(stack); + intervalStacks.add(stack); + RprofState profState = RprofState.get(); + if (profState.memoryProfiling) { + intervalMemory.add(profState.memoryQuad.copyAndClear()); + } + } + @TruffleBoundary private void collectStack(final ArrayList<RSyntaxElement> stack) { Utils.iterateRFrames(FrameAccess.READ_ONLY, new Function<Frame, Object>() { diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Identical.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Identical.java index 8fbce0e16b3edc0a9c0908402421edf9abbb3a8e..ace865e7680268a921567c7275bb8c4c226783d0 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Identical.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Identical.java @@ -314,7 +314,7 @@ public abstract class Identical extends RBuiltinNode.Arg7 { if (xSubList.getTag() instanceof RSymbol && ySubList.getTag() instanceof RSymbol) { String xTagName = ((RSymbol) xSubList.getTag()).getName(); String yTagName = ((RSymbol) ySubList.getTag()).getName(); - assert xTagName == xTagName.intern() && yTagName == yTagName.intern(); + assert Utils.isInterned(xTagName) && Utils.isInterned(yTagName); if (xTagName != yTagName) { return RRuntime.LOGICAL_FALSE; } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/RNGFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/RNGFunctions.java index 0d8a7a3ed9f02a2c78dd0abb9b43c22a6bd485c0..0f6057c3312527dd5518d15503ee077165ec376d 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/RNGFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/RNGFunctions.java @@ -63,6 +63,7 @@ public class RNGFunctions { @SuppressWarnings("unused") @Specialization + @TruffleBoundary protected RNull setSeed(int seed, int kind, RNull normKind) { doSetSeed(seed, kind, RRNG.NO_KIND_CHANGE); return RNull.instance; @@ -70,6 +71,7 @@ public class RNGFunctions { @SuppressWarnings("unused") @Specialization + @TruffleBoundary protected RNull setSeed(RNull seed, int kind, RNull normKind) { doSetSeed(RRNG.timeToSeed(), kind, RRNG.NO_KIND_CHANGE); return RNull.instance; @@ -90,6 +92,7 @@ public class RNGFunctions { } @Specialization + @TruffleBoundary protected RIntVector doRNGkind(int kind, int normKind) { RRNG.getRNGState(); RIntVector result = getCurrent(); diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/TraceFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/TraceFunctions.java index 69d421843f509817fb28b6c594a7625e9d6adf23..de4f53cdcde1fc9f06dc8d0a968bdacc097d8ebd 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/TraceFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/TraceFunctions.java @@ -263,11 +263,13 @@ public class TraceFunctions { @Specialization protected Object execute(VirtualFrame frame, Object x, @SuppressWarnings("unused") RNull previous) { + CompilerDirectives.transferToInterpreter(); return getResult(frame, x); } @Specialization protected Object execute(VirtualFrame frame, Object x, @SuppressWarnings("unused") RMissing previous) { + CompilerDirectives.transferToInterpreter(); return getResult(frame, x); } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/UpdateAttributes.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/UpdateAttributes.java index fc662f9acea716e14fc6c82927acfe1f593a609d..5efb1486a32c28a3cedb2e7530ad7eefd352298b 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/UpdateAttributes.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/UpdateAttributes.java @@ -47,6 +47,7 @@ import com.oracle.truffle.r.nodes.unary.CastToVectorNodeGen; import com.oracle.truffle.r.nodes.unary.GetNonSharedNode; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RRuntime; +import com.oracle.truffle.r.runtime.Utils; import com.oracle.truffle.r.runtime.builtins.RBuiltin; import com.oracle.truffle.r.runtime.data.RAttributable; import com.oracle.truffle.r.runtime.data.RComplex; @@ -237,7 +238,7 @@ public abstract class UpdateAttributes extends RBuiltinNode.Arg2 { CompilerDirectives.transferToInterpreterAndInvalidate(); setAttrNode = insert(SetAttributeNode.create()); } - setAttrNode.execute(res, attrName.intern(), value); + setAttrNode.execute(res, Utils.intern(attrName), value); } } } @@ -274,7 +275,7 @@ public abstract class UpdateAttributes extends RBuiltinNode.Arg2 { } obj.setClassAttr(UpdateAttr.convertClassAttrFromObject(attrValue)); } else { - obj.setAttr(attrName.intern(), list.getDataAt(i)); + obj.setAttr(Utils.intern(attrName), list.getDataAt(i)); } } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/SpecialsUtils.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/SpecialsUtils.java index 425bb7220c544608be9f77badb5a340fadadb823..2d25546585e829459ca483a694e24bd4745cd46c 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/SpecialsUtils.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/SpecialsUtils.java @@ -37,6 +37,7 @@ import com.oracle.truffle.r.nodes.builtin.base.infix.SpecialsUtilsFactory.Conver import com.oracle.truffle.r.nodes.builtin.base.infix.SpecialsUtilsFactory.ConvertValueNodeGen; import com.oracle.truffle.r.nodes.function.ClassHierarchyNode; import com.oracle.truffle.r.runtime.ArgumentsSignature; +import com.oracle.truffle.r.runtime.Utils; import com.oracle.truffle.r.runtime.data.RDoubleVector; import com.oracle.truffle.r.runtime.data.RIntVector; import com.oracle.truffle.r.runtime.data.RStringVector; @@ -51,7 +52,7 @@ import com.oracle.truffle.r.runtime.nodes.RSyntaxNode; */ class SpecialsUtils { - private static final String valueArgName = "value".intern(); + private static final String valueArgName = Utils.intern("value"); public static boolean isCorrectUpdateSignature(ArgumentsSignature signature) { if (signature.getLength() == 3) { diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/printer/ValuePrinterNode.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/printer/ValuePrinterNode.java index 333012b0465d59c88387d85c3d73870e222fea8b..bb1f76a06ef65996bb18ddcbb1e9a73c8989b679 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/printer/ValuePrinterNode.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/printer/ValuePrinterNode.java @@ -22,9 +22,9 @@ */ package com.oracle.truffle.r.nodes.builtin.base.printer; -import com.oracle.truffle.api.CompilerDirectives; import java.io.IOException; +import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.interop.ForeignAccess; import com.oracle.truffle.api.interop.InteropException; @@ -69,10 +69,6 @@ import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; import com.oracle.truffle.r.runtime.data.model.RAbstractVector; import com.oracle.truffle.r.runtime.interop.Foreign2R; import com.oracle.truffle.r.runtime.interop.ForeignArray2R.InteropTypeCheck; -import static com.oracle.truffle.r.runtime.interop.ForeignArray2R.InteropTypeCheck.RType.BOOLEAN; -import static com.oracle.truffle.r.runtime.interop.ForeignArray2R.InteropTypeCheck.RType.DOUBLE; -import static com.oracle.truffle.r.runtime.interop.ForeignArray2R.InteropTypeCheck.RType.INTEGER; -import static com.oracle.truffle.r.runtime.interop.ForeignArray2R.InteropTypeCheck.RType.STRING; import com.oracle.truffle.r.runtime.nodes.RBaseNode; public final class ValuePrinterNode extends RBaseNode { @@ -113,11 +109,13 @@ public final class ValuePrinterNode extends RBaseNode { } @Override + @TruffleBoundary public Object getDataAtAsObject(int index) { return getDataAt(index); } @Override + @TruffleBoundary public String getDataAt(int index) { Object value; try { @@ -129,6 +127,7 @@ public final class ValuePrinterNode extends RBaseNode { } @Override + @TruffleBoundary public RStringVector materialize() { throw RInternalError.shouldNotReachHere(); } @@ -147,11 +146,13 @@ public final class ValuePrinterNode extends RBaseNode { } @Override + @TruffleBoundary public Object getDataAtAsObject(int index) { return getDataAt(index); } @Override + @TruffleBoundary public Object getDataAt(int index) { try { Object value = ForeignAccess.sendRead(readNode, obj, names != null ? names.getDataAt(index) : index); @@ -162,11 +163,13 @@ public final class ValuePrinterNode extends RBaseNode { } @Override + @TruffleBoundary public RStringVector getNames() { return names; } @Override + @TruffleBoundary public RList materialize() { throw RInternalError.shouldNotReachHere(); } @@ -193,11 +196,13 @@ public final class ValuePrinterNode extends RBaseNode { } @Override + @TruffleBoundary public Object getDataAtAsObject(int index) { return getDataAt(index); } @Override + @TruffleBoundary public byte getDataAt(int index) { try { Object value = ForeignAccess.sendRead(readNode, obj, index); @@ -208,6 +213,7 @@ public final class ValuePrinterNode extends RBaseNode { } @Override + @TruffleBoundary public RLogicalVector materialize() { throw RInternalError.shouldNotReachHere(); } @@ -221,11 +227,13 @@ public final class ValuePrinterNode extends RBaseNode { } @Override + @TruffleBoundary public Object getDataAtAsObject(int index) { return getDataAt(index); } @Override + @TruffleBoundary public int getDataAt(int index) { try { Object value = ForeignAccess.sendRead(readNode, obj, index); @@ -236,6 +244,7 @@ public final class ValuePrinterNode extends RBaseNode { } @Override + @TruffleBoundary public RIntVector materialize() { throw RInternalError.shouldNotReachHere(); } @@ -249,11 +258,13 @@ public final class ValuePrinterNode extends RBaseNode { } @Override + @TruffleBoundary public Object getDataAtAsObject(int index) { return getDataAt(index); } @Override + @TruffleBoundary public double getDataAt(int index) { try { Object value = ForeignAccess.sendRead(readNode, obj, index); @@ -264,6 +275,7 @@ public final class ValuePrinterNode extends RBaseNode { } @Override + @TruffleBoundary public RDoubleVector materialize() { throw RInternalError.shouldNotReachHere(); } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RASTBuilder.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RASTBuilder.java index 4f3115f233669eec29fe85ccfce468ae46e79744..9219aa235cebf5677f8c90f7f91da4e2342da33c 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RASTBuilder.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RASTBuilder.java @@ -53,6 +53,7 @@ import com.oracle.truffle.r.nodes.function.signature.MissingNode; import com.oracle.truffle.r.runtime.ArgumentsSignature; import com.oracle.truffle.r.runtime.FastROptions; import com.oracle.truffle.r.runtime.RRuntime; +import com.oracle.truffle.r.runtime.Utils; import com.oracle.truffle.r.runtime.builtins.FastPathFactory; import com.oracle.truffle.r.runtime.context.TruffleRLanguage; import com.oracle.truffle.r.runtime.data.REmpty; @@ -256,7 +257,7 @@ public final class RASTBuilder implements RCodeBuilder<RSyntaxNode> { @Override public RSyntaxNode constant(SourceSection source, Object value) { if (value instanceof String && !RRuntime.isNA((String) value)) { - return ConstantNode.create(source, ((String) value).intern()); + return ConstantNode.create(source, Utils.intern((String) value)); } else { if (value instanceof RShareable) { RShareable shareable = (RShareable) value; diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/variables/ReadVariableNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/variables/ReadVariableNode.java index 338251a3ff4be1790e17ee1d2f8f6361ee9a7ca0..7ba6b410c2b3af05e23eac3ea4a29cc96968e07a 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/variables/ReadVariableNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/variables/ReadVariableNode.java @@ -57,6 +57,7 @@ import com.oracle.truffle.r.runtime.RInternalError; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.RType; import com.oracle.truffle.r.runtime.StableValue; +import com.oracle.truffle.r.runtime.Utils; import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames; import com.oracle.truffle.r.runtime.data.RFunction; import com.oracle.truffle.r.runtime.data.RMissing; @@ -199,7 +200,7 @@ public final class ReadVariableNode extends RBaseNode { private ReadVariableNode(Object identifier, RType mode, ReadKind kind) { this.identifier = identifier; - this.identifierAsString = identifier.toString().intern(); + this.identifierAsString = Utils.intern(identifier.toString()); this.mode = mode; this.kind = kind; diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/FixedAttributeAccessNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/FixedAttributeAccessNode.java index 9a4a27636eeb72b5c75a2b94d04b9f07fa02ccde..439c0a224927d217f9216f4436717e9c33a236ae 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/FixedAttributeAccessNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/FixedAttributeAccessNode.java @@ -22,6 +22,8 @@ */ package com.oracle.truffle.r.nodes.attributes; +import com.oracle.truffle.r.runtime.Utils; + /** * The base class for the nodes that get/set/remove a fixed attribute. */ @@ -32,7 +34,7 @@ public abstract class FixedAttributeAccessNode extends AttributeAccessNode { protected final String name; protected FixedAttributeAccessNode(String name) { - assert name.intern() == name; + assert Utils.isInterned(name); this.name = name; } } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/SpecialAttributesFunctions.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/SpecialAttributesFunctions.java index 523657c9364ad595ffec583557e2deecb119016f..814b3c6f6e324ee9af106229a09be0c709778256 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/SpecialAttributesFunctions.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/SpecialAttributesFunctions.java @@ -37,6 +37,7 @@ import com.oracle.truffle.r.nodes.function.opt.ShareObjectNode; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RInternalError; import com.oracle.truffle.r.runtime.RRuntime; +import com.oracle.truffle.r.runtime.Utils; import com.oracle.truffle.r.runtime.context.RContext; import com.oracle.truffle.r.runtime.data.RAttributable; import com.oracle.truffle.r.runtime.data.RAttributesLayout; @@ -80,7 +81,7 @@ public final class SpecialAttributesFunctions { * The fast-path method. */ public boolean execute(String name) { - assert name.intern() == name; + assert Utils.isInterned(name); if (name == RRuntime.NAMES_ATTR_KEY) { namesProfile.enter(); return true; @@ -104,7 +105,7 @@ public final class SpecialAttributesFunctions { * The slow-path method. */ public static boolean isSpecialAttribute(String name) { - assert name.intern() == name; + assert Utils.isInterned(name); return name == RRuntime.NAMES_ATTR_KEY || name == RRuntime.DIM_ATTR_KEY || name == RRuntime.DIMNAMES_ATTR_KEY || @@ -134,7 +135,7 @@ public final class SpecialAttributesFunctions { } public void execute(RAttributable x, String name, Object value) { - assert name.intern() == name; + assert Utils.isInterned(name); if (name == RRuntime.NAMES_ATTR_KEY) { namesProfile.enter(); if (namesAttrNode == null) { @@ -180,7 +181,7 @@ public final class SpecialAttributesFunctions { * @return the node */ public static SetSpecialAttributeNode createSetSpecialAttributeNode(String name) { - assert name.intern() == name; + assert Utils.isInterned(name); if (name == RRuntime.NAMES_ATTR_KEY) { return SetNamesAttributeNode.create(); } else if (name == RRuntime.DIM_ATTR_KEY) { @@ -203,7 +204,7 @@ public final class SpecialAttributesFunctions { * @return the node */ public static RemoveSpecialAttributeNode createRemoveSpecialAttributeNode(String name) { - assert name.intern() == name; + assert Utils.isInterned(name); if (name == RRuntime.NAMES_ATTR_KEY) { return RemoveNamesAttributeNode.create(); } else if (name == RRuntime.DIM_ATTR_KEY) { @@ -226,7 +227,7 @@ public final class SpecialAttributesFunctions { * @return the node */ public static GetFixedAttributeNode createGetSpecialAttributeNode(String name) { - assert name.intern() == name; + assert Utils.isInterned(name); if (name == RRuntime.NAMES_ATTR_KEY) { return GetNamesAttributeNode.create(); } else if (name == RRuntime.DIM_ATTR_KEY) { diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/FunctionDefinitionNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/FunctionDefinitionNode.java index 2b427df2deb4d73160eed621fee45ebb0ccf1377..ae33c008f3d0a8f163fd369a29c80529afc8e10d 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/FunctionDefinitionNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/FunctionDefinitionNode.java @@ -362,6 +362,7 @@ public final class FunctionDefinitionNode extends RRootNode implements RSyntaxNo for (RPairList expr : current) { if (expr.car() != RNull.instance) { if (!(expr.car() instanceof RNode)) { + CompilerDirectives.transferToInterpreter(); RInternalError.shouldNotReachHere("unexpected type for on.exit entry: " + expr.car()); } onExitExpressionCache.execute(frame, expr.car()); diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/S3FunctionLookupNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/S3FunctionLookupNode.java index 4a3d4606b1ef7486d3927e80e7847a1b1d3013f0..19d0954b1caeea4434360020d2ca8893a0f83190 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/S3FunctionLookupNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/S3FunctionLookupNode.java @@ -37,6 +37,7 @@ import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RInternalError; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.RType; +import com.oracle.truffle.r.runtime.Utils; import com.oracle.truffle.r.runtime.context.RContext; import com.oracle.truffle.r.runtime.data.RDataFactory; import com.oracle.truffle.r.runtime.data.RFunction; @@ -68,7 +69,7 @@ public abstract class S3FunctionLookupNode extends RBaseNode { public final boolean groupMatch; private Result(String generic, RFunction function, Object clazz, String targetFunctionName, boolean groupMatch) { - this.generic = generic.intern(); + this.generic = Utils.intern(generic); this.function = function; this.signature = function == null ? null : ArgumentMatcher.getFunctionSignature(function); this.clazz = clazz; diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ArgumentsSignature.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ArgumentsSignature.java index d8a18bfca7d19bc019bea4df248d9ef5acf477ef..c6af06d8a2d5b71bd0f464aa2c32ea947ef30bab 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ArgumentsSignature.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ArgumentsSignature.java @@ -107,7 +107,7 @@ public final class ArgumentsSignature implements Iterable<String> { localNames = new String[names.length]; } nonNull++; - localNames[i] = s == UNMATCHED ? s : s.intern(); + localNames[i] = s == UNMATCHED ? s : Utils.intern(s); } this.names = localNames; this.nonNullCount = nonNull; diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RSerialize.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RSerialize.java index 93c1cab891f025f44824415e9707b8aca331a55f..291db3b4e6155332e1de91ccaa50720086b6b278 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RSerialize.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RSerialize.java @@ -889,7 +889,7 @@ public class RSerialize { Object result = object; while (true) { RSymbol tagSym = (RSymbol) pl.getTag(); - String tag = tagSym.getName().intern(); + String tag = Utils.intern(tagSym.getName()); // this may convert a plain vector to a data.frame or factor Object attrValue = pl.car(); if (attrValue instanceof RShareable && ((RShareable) attrValue).isTemporary()) { diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/builtins/RBuiltinDescriptor.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/builtins/RBuiltinDescriptor.java index 07ede76bbdf97724f7aa50ca9aa2e717b3d552c4..af16e05665e80b6ccbafb0944b42a6f097aaffc4 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/builtins/RBuiltinDescriptor.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/builtins/RBuiltinDescriptor.java @@ -29,6 +29,7 @@ import com.oracle.truffle.r.runtime.ArgumentsSignature; import com.oracle.truffle.r.runtime.PrimitiveMethodsInfo; import com.oracle.truffle.r.runtime.RDispatch; import com.oracle.truffle.r.runtime.RVisibility; +import com.oracle.truffle.r.runtime.Utils; public abstract class RBuiltinDescriptor { @@ -56,7 +57,7 @@ public abstract class RBuiltinDescriptor { int[] nonEvalArgs, boolean splitCaller, boolean alwaysSplit, RDispatch dispatch, String genericName, RBehavior behavior, RSpecialFactory specialCall) { this.specialCall = specialCall; - this.name = name.intern(); + this.name = Utils.intern(name); this.builtinMetaClass = builtinMetaClass; this.builtinNodeClass = builtinNodeClass; this.visibility = visibility; @@ -67,7 +68,7 @@ public abstract class RBuiltinDescriptor { this.splitCaller = splitCaller; this.alwaysSplit = alwaysSplit; this.dispatch = dispatch; - this.genericName = genericName.intern(); + this.genericName = Utils.intern(genericName); this.behavior = behavior; evaluatesArgument = new boolean[signature.getLength()]; diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/NativeDataAccess.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/NativeDataAccess.java index de9ff2b821a97f48a5dc9189edde8caa77b27dd2..d6ddd16f25845c82fb8772eb3ca45bd1202f488e 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/NativeDataAccess.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/NativeDataAccess.java @@ -129,6 +129,7 @@ public final class NativeDataAccess { this.dataAddress = address; } + @TruffleBoundary void allocateNative(Object source, int len, int elementBase, int elementSize) { assert dataAddress == 0; dataAddress = UnsafeAdapter.UNSAFE.allocateMemory(len * elementSize); @@ -136,6 +137,7 @@ public final class NativeDataAccess { this.length = len; } + @TruffleBoundary void allocateNative(String source) { assert dataAddress == 0; byte[] bytes = source.getBytes(StandardCharsets.US_ASCII); @@ -224,8 +226,10 @@ public final class NativeDataAccess { } /** - * For given native mirror ID returns the Java side object (vector). + * For given native mirror ID returns the Java side object (vector). TruffleBoundary because it + * calls into HashMap. */ + @TruffleBoundary public static Object lookup(long address) { WeakReference<RObject> reference = nativeMirrors.get(address); if (reference == null) { diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RDataFactory.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RDataFactory.java index 47e1c9d20c8c08cbce0b211a20673d7701fbd8a3..434f23bb056da3702e818a2be7cee7e38aff6281 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RDataFactory.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RDataFactory.java @@ -480,7 +480,7 @@ public final class RDataFactory { * serialization/deparsing. */ public static RSymbol createSymbolInterned(String name) { - return createSymbol(name.intern()); + return createSymbol(Utils.intern(name)); } public static RLanguage createLanguage(RBaseNode rep) { diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RPromise.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RPromise.java index 40d136a0a76ec2af58870ffec1a884d1d71a0265..8b7ff52fec004d9869457e7e8d49c5780ae5ebc5 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RPromise.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RPromise.java @@ -443,7 +443,7 @@ public class RPromise extends RObject implements RTypedValue { private Closure(RBaseNode expr) { this.expr = expr; if (expr.asRSyntaxNode() instanceof RSyntaxLookup) { - this.symbol = ((RSyntaxLookup) expr.asRSyntaxNode()).getIdentifier().intern(); + this.symbol = Utils.intern(((RSyntaxLookup) expr.asRSyntaxNode()).getIdentifier()); } else { this.symbol = null; } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RStringSequence.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RStringSequence.java index 03c11fa316b416042f33958257930f2e024c2fee..845abb5784b684ee3794327e53a79440b3e7111f 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RStringSequence.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RStringSequence.java @@ -23,6 +23,7 @@ package com.oracle.truffle.r.runtime.data; import com.oracle.truffle.api.CompilerAsserts; +import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.profiles.ConditionProfile; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.RType; @@ -83,11 +84,13 @@ public class RStringSequence extends RSequence implements RAbstractStringVector } @Override + @TruffleBoundary public String getDataAt(int index) { assert index >= 0 && index < getLength(); return prefix + (start + stride * index) + suffix; } + @TruffleBoundary private void populateVectorData(String[] result) { int current = start; for (int i = 0; i < result.length && i < getLength(); i++) { @@ -114,11 +117,13 @@ public class RStringSequence extends RSequence implements RAbstractStringVector } @Override + @TruffleBoundary public Object getStartObject() { return prefix + start + suffix; } @Override + @TruffleBoundary public Object getStrideObject() { return Integer.toString(stride); } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/DLL.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/DLL.java index 82c66ae4693bd9d53df5c2752607eae8e037acc7..9c4a6f1dcf0039271d3e4c9bdb40ee17d66d663d 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/DLL.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/DLL.java @@ -389,6 +389,7 @@ public class DLL { if (value instanceof TruffleObject) { return (TruffleObject) value; } else { + CompilerDirectives.transferToInterpreter(); throw RInternalError.shouldNotReachHere("value: " + value); } }