diff --git a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/ffi/nfi/TruffleNFI_Base.java b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/ffi/nfi/TruffleNFI_Base.java
index 7e9c053144dc427043a3127e060ff3151515de07..3ad8a7f1da8940084e236abec1033023f40d4d32 100644
--- a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/ffi/nfi/TruffleNFI_Base.java
+++ b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/ffi/nfi/TruffleNFI_Base.java
@@ -25,6 +25,7 @@ package com.oracle.truffle.r.engine.interop.ffi.nfi;
 import java.io.IOException;
 import java.util.ArrayList;
 
+import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
 import com.oracle.truffle.api.interop.ForeignAccess;
 import com.oracle.truffle.api.interop.InteropException;
 import com.oracle.truffle.api.interop.Message;
@@ -90,6 +91,7 @@ public class TruffleNFI_Base implements BaseRFFI {
     }
 
     public static class TruffleNFI_GetwdNode extends GetwdNode {
+        @TruffleBoundary
         @Override
         public String execute() {
             byte[] buf = new byte[4096];
@@ -180,6 +182,7 @@ public class TruffleNFI_Base implements BaseRFFI {
     }
 
     public static class TruffleNFI_MkdtempNode extends MkdtempNode {
+        @TruffleBoundary
         @Override
         public String execute(String template) {
             /*
diff --git a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/ffi/nfi/TruffleNFI_DLL.java b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/ffi/nfi/TruffleNFI_DLL.java
index 36cfaaa2d30743e96f318b91c81d3f5d1203fc87..fe390032a4aa5e8877963447e0e3e8a63e3425b8 100644
--- a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/ffi/nfi/TruffleNFI_DLL.java
+++ b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/ffi/nfi/TruffleNFI_DLL.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -51,6 +51,7 @@ public class TruffleNFI_DLL implements DLLRFFI {
 
     private static class TruffleNFI_DLOpenNode extends DLLRFFI.DLOpenNode {
 
+        @TruffleBoundary
         @Override
         public Object execute(String path, boolean local, boolean now) {
             String libName = DLL.libName(path);
diff --git a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/ffi/nfi/TruffleNFI_Utils.java b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/ffi/nfi/TruffleNFI_Utils.java
index 92a0e6dcb43f4931571047721eaa3d5e74c3c4f2..55b6efe6d4374eb9d1da7b142ea7ee09bb5d6601 100644
--- a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/ffi/nfi/TruffleNFI_Utils.java
+++ b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/ffi/nfi/TruffleNFI_Utils.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,6 +24,7 @@ package com.oracle.truffle.r.engine.interop.ffi.nfi;
 
 import java.nio.charset.StandardCharsets;
 
+import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
 import com.oracle.truffle.api.TruffleLanguage.Env;
 import com.oracle.truffle.api.interop.ForeignAccess;
 import com.oracle.truffle.api.interop.InteropException;
@@ -57,6 +58,7 @@ public class TruffleNFI_Utils {
 
     private static TruffleObject defaultLibrary;
 
+    @TruffleBoundary
     private static void initDefaultLibrary() {
         if (defaultLibrary == null) {
             Env env = RContext.getInstance().getEnv();
diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LNewPage.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LNewPage.java
index 95c5e9bcfd0767a0731a6920f4a06256552c4f16..1b234eda3a3fc0e7ff305cf18785e6ec77813c36 100644
--- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LNewPage.java
+++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LNewPage.java
@@ -12,6 +12,7 @@
 package com.oracle.truffle.r.library.fastrGrid;
 
 import com.oracle.truffle.api.CompilerDirectives;
+import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
 import com.oracle.truffle.api.frame.VirtualFrame;
 import com.oracle.truffle.r.library.fastrGrid.device.GridDevice;
 import com.oracle.truffle.r.nodes.builtin.RExternalBuiltinNode;
@@ -29,7 +30,7 @@ final class LNewPage extends RExternalBuiltinNode {
     public Object call(VirtualFrame frame, RArgsValuesAndNames args) {
         GridDevice device = GridContext.getContext().getCurrentDevice();
         if (GridContext.getContext().getGridState().isDeviceInitialized()) {
-            device.openNewPage();
+            openNewPage(device);
             return RNull.instance;
         }
         // There are some exceptions to the rule that any external call from grid R code is
@@ -38,6 +39,11 @@ final class LNewPage extends RExternalBuiltinNode {
         return gridDirty.call(frame, RArgsValuesAndNames.EMPTY);
     }
 
+    @TruffleBoundary
+    private static void openNewPage(GridDevice device) {
+        device.openNewPage();
+    }
+
     @Override
     protected Object call(RArgsValuesAndNames args) {
         assert false : "should be shadowed by the overload with frame";
diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LPretty.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LPretty.java
index 1ff6bb3f1130162602ad376ecb38736e367fddae..2d447deb2c14deb1ba1fcc1194328383ee72480f 100644
--- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LPretty.java
+++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LPretty.java
@@ -14,6 +14,7 @@ package com.oracle.truffle.r.library.fastrGrid;
 import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.numericValue;
 import static com.oracle.truffle.r.runtime.nmath.TOMS708.fabs;
 
+import com.oracle.truffle.api.CompilerDirectives;
 import com.oracle.truffle.api.dsl.Specialization;
 import com.oracle.truffle.r.nodes.builtin.RExternalBuiltinNode;
 import com.oracle.truffle.r.runtime.PrettyIntevals;
@@ -42,6 +43,7 @@ public abstract class LPretty extends RExternalBuiltinNode.Arg1 {
         }
 
         if (Double.isInfinite(min) || Double.isInfinite(max)) {
+            CompilerDirectives.transferToInterpreter();
             throw error(Message.GENERIC, String.format("infinite axis extents [GEPretty(%g,%g,5)]", min, max));
         }
 
diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/SVGDevice.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/SVGDevice.java
index 702a586e3c65000cf14534ba168f8908c0064c73..063847725fa7afdcc56e983d7b54e324eb4da6a1 100644
--- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/SVGDevice.java
+++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/SVGDevice.java
@@ -36,6 +36,7 @@ import com.oracle.truffle.r.library.fastrGrid.device.DrawingContext.GridFontStyl
 import com.oracle.truffle.r.library.fastrGrid.device.DrawingContext.GridLineEnd;
 import com.oracle.truffle.r.library.fastrGrid.device.DrawingContext.GridLineJoin;
 import com.oracle.truffle.r.runtime.RInternalError;
+import com.oracle.truffle.r.runtime.Utils;
 
 public class SVGDevice implements GridDevice {
     private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("0.000");
@@ -250,11 +251,11 @@ public class SVGDevice implements GridDevice {
     }
 
     private static String getStyleColor(String prefix, GridColor color) {
-        return String.format("%s:rgb(%d,%d,%d);%s-opacity:%.3f", prefix, color.getRed(), color.getGreen(), color.getBlue(), prefix, (double) color.getAlpha() / 255d);
+        return Utils.stringFormat("%s:rgb(%d,%d,%d);%s-opacity:%.3f", prefix, color.getRed(), color.getGreen(), color.getBlue(), prefix, color.getAlpha() / 255d);
     }
 
     private void append(String fmt, Object... args) {
-        data.append(String.format(fmt + "\n", args));
+        data.append(Utils.stringFormat(fmt + "\n", args));
     }
 
     private double transY(double y) {
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 d822fac092537378d31171e30e6e21497990cf7d..d3dad0bc79bf3e3e0c56e7c91ab3d3e68a98f5f7 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
@@ -27,8 +27,8 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.stream.Collectors;
 
+import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
 import com.oracle.truffle.api.RootCallTarget;
 import com.oracle.truffle.api.dsl.Cached;
 import com.oracle.truffle.api.dsl.Specialization;
@@ -149,6 +149,43 @@ public abstract class Deriv extends RExternalBuiltinNode {
     }
 
     private Object derive(VirtualFrame frame, RBaseNode elem, RAbstractStringVector names, Object functionArg, String tag, boolean hessian) {
+        return findDerive(elem, names, functionArg, tag, hessian).getResult(frame);
+    }
+
+    private static final class DerivResult {
+        private final RExpression result;
+        private final RSyntaxNode blockCall;
+        private final List<Argument<RSyntaxNode>> targetArgs;
+
+        private DerivResult(RExpression result) {
+            this.result = result;
+            blockCall = null;
+            targetArgs = null;
+        }
+
+        private DerivResult(RSyntaxNode blockCall, List<Argument<RSyntaxNode>> targetArgs) {
+            this.blockCall = blockCall;
+            this.targetArgs = targetArgs;
+            result = null;
+        }
+
+        private Object getResult(VirtualFrame frame) {
+            if (result != null) {
+                return result;
+            }
+            RootCallTarget callTarget = getRootCallTarget();
+            FrameSlotChangeMonitor.initializeEnclosingFrame(callTarget.getRootNode().getFrameDescriptor(), frame);
+            return RDataFactory.createFunction(RFunction.NO_NAME, RFunction.NO_NAME, callTarget, null, frame.materialize());
+        }
+
+        @TruffleBoundary
+        private RootCallTarget getRootCallTarget() {
+            return RContext.getASTBuilder().rootFunction(RSyntaxNode.LAZY_DEPARSE, targetArgs, blockCall, null);
+        }
+    }
+
+    @TruffleBoundary
+    private DerivResult findDerive(RBaseNode elem, RAbstractStringVector names, Object functionArg, String tag, boolean hessian) {
         LinkedList<RSyntaxNode> exprlist = new LinkedList<>();
         int fIndex = findSubexpression(elem, exprlist, tag);
 
@@ -275,7 +312,10 @@ public abstract class Deriv extends RExternalBuiltinNode {
         // prune exprlist
         exprlist.removeAll(Collections.singleton(null));
 
-        List<Argument<RSyntaxNode>> blockStatements = exprlist.stream().map(e -> RCodeBuilder.argument(e)).collect(Collectors.toList());
+        List<Argument<RSyntaxNode>> blockStatements = new ArrayList<>(exprlist.size());
+        for (RSyntaxNode e : exprlist) {
+            blockStatements.add(RCodeBuilder.argument(e));
+        }
         RSyntaxNode blockCall = RContext.getASTBuilder().call(RSyntaxNode.LAZY_DEPARSE, ReadVariableNode.create("{"), blockStatements);
 
         if (functionArg instanceof RAbstractStringVector) {
@@ -285,14 +325,14 @@ public abstract class Deriv extends RExternalBuiltinNode {
                 targetArgs.add(RCodeBuilder.argument(RSyntaxNode.LAZY_DEPARSE, funArgNames.getDataAt(i), ConstantNode.create(RMissing.instance)));
             }
 
-            return createFunction(frame, blockCall, targetArgs);
+            return new DerivResult(blockCall, targetArgs);
         } else if (functionArg == Boolean.TRUE) {
             List<Argument<RSyntaxNode>> targetArgs = new ArrayList<>();
             for (int i = 0; i < names.getLength(); i++) {
                 targetArgs.add(RCodeBuilder.argument(RSyntaxNode.LAZY_DEPARSE, names.getDataAt(i), ConstantNode.create(RMissing.instance)));
             }
 
-            return createFunction(frame, blockCall, targetArgs);
+            return new DerivResult(blockCall, targetArgs);
         } else if (functionArg instanceof RFunction) {
             RFunction funTemplate = (RFunction) functionArg;
             FormalArguments formals = ((RRootNode) funTemplate.getRootNode()).getFormalArguments();
@@ -302,21 +342,15 @@ public abstract class Deriv extends RExternalBuiltinNode {
                 targetArgs.add(RCodeBuilder.argument(RSyntaxNode.LAZY_DEPARSE, formals.getSignature().getName(i), cloneElement((RSyntaxNode) defArgs[i])));
             }
 
-            return createFunction(frame, blockCall, targetArgs);
+            return new DerivResult(blockCall, targetArgs);
         } else {
             RLanguage lan = RDataFactory.createLanguage(blockCall.asRNode());
             RExpression res = RDataFactory.createExpression(new Object[]{lan});
-            return res;
+            return new DerivResult(res);
         }
 
     }
 
-    private static RFunction createFunction(VirtualFrame frame, RSyntaxNode blockCall, List<Argument<RSyntaxNode>> targetArgs) {
-        RootCallTarget callTarget = RContext.getASTBuilder().rootFunction(RSyntaxNode.LAZY_DEPARSE, targetArgs, blockCall, null);
-        FrameSlotChangeMonitor.initializeEnclosingFrame(callTarget.getRootNode().getFrameDescriptor(), frame);
-        return RDataFactory.createFunction(RFunction.NO_NAME, RFunction.NO_NAME, callTarget, null, frame.materialize());
-    }
-
     private int findSubexpression(RBaseNode expr, List<RSyntaxNode> exprlist, String tag) {
         if (!(expr instanceof RSyntaxElement)) {
             throw RError.error(RError.SHOW_CALLER, RError.Message.INVALID_EXPRESSION, "FindSubexprs");
diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/ProfiledSpecialsUtils.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/ProfiledSpecialsUtils.java
index fe6a876c607855fca7f4aa53eba48c88d0171e32..4d9d655c0723c28762833aa930d565f84a2d24f9 100644
--- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/ProfiledSpecialsUtils.java
+++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/ProfiledSpecialsUtils.java
@@ -62,6 +62,7 @@ public class ProfiledSpecialsUtils {
         @Specialization(replaces = "access")
         public Object accessGeneric(VirtualFrame frame, Object vector, Object index) {
             if (defaultAccessNode == null) {
+                CompilerDirectives.transferToInterpreterAndInvalidate();
                 defaultAccessNode = insert(createAccessNode());
             }
             return defaultAccessNode.execute(frame, vector, index);
@@ -120,6 +121,7 @@ public class ProfiledSpecialsUtils {
         @Specialization(replaces = "access")
         public Object accessGeneric(VirtualFrame frame, Object vector, Object index1, Object index2) {
             if (defaultAccessNode == null) {
+                CompilerDirectives.transferToInterpreterAndInvalidate();
                 defaultAccessNode = insert(createAccessNode());
             }
             return defaultAccessNode.execute(frame, vector, index1, index2);
@@ -220,6 +222,7 @@ public class ProfiledSpecialsUtils {
         @Specialization(replaces = "access")
         public Object accessGeneric(VirtualFrame frame, Object vector, Object index1, Object index2, Object value) {
             if (defaultAccessNode == null) {
+                CompilerDirectives.transferToInterpreterAndInvalidate();
                 defaultAccessNode = insert(createAccessNode());
             }
             return defaultAccessNode.execute(frame, vector, index1, index2, value);
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/variables/LocalReadVariableNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/variables/LocalReadVariableNode.java
index 5e1b476097b7ad544331269c48dfe303268c9b88..4ce17a2cce609f80633704791c90461355b68150 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/variables/LocalReadVariableNode.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/variables/LocalReadVariableNode.java
@@ -101,6 +101,7 @@ public final class LocalReadVariableNode extends Node {
         }
         Object result = null;
         if (isMissingProfile == null) {
+            CompilerDirectives.transferToInterpreterAndInvalidate();
             seenValueKinds = new boolean[FrameSlotKind.values().length];
             valueProfile = ValueProfile.createClassProfile();
             isNullProfile = ConditionProfile.createBinaryProfile();
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/ToStringNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/ToStringNode.java
index e4e82a96e64db090f0a6915488049b162630ff25..ba6bf5714fabbcb7f76cb23751ebbd3ccd328cf7 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/ToStringNode.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/ToStringNode.java
@@ -31,6 +31,7 @@ import com.oracle.truffle.api.profiles.ConditionProfile;
 import com.oracle.truffle.r.nodes.function.ClassHierarchyNode;
 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.data.RComplex;
 import com.oracle.truffle.r.runtime.data.RFunction;
 import com.oracle.truffle.r.runtime.data.RList;
@@ -148,7 +149,7 @@ public abstract class ToStringNode extends RBaseNode {
         } else {
             throw RInternalError.shouldNotReachHere("S4 object has no class");
         }
-        return String.format("<S4 object of class %s>", clazz);
+        return Utils.stringFormat("<S4 object of class %s>", clazz);
     }
 
     @FunctionalInterface
diff --git a/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/LibPaths.java b/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/LibPaths.java
index 2292780c3fcd9ecd6392f10f1e06920e26b49723..86b8d0a62c33348b68b95270c11e0f69816917dd 100644
--- a/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/LibPaths.java
+++ b/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/LibPaths.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,7 @@ package com.oracle.truffle.r.runtime.ffi;
 import java.nio.file.FileSystems;
 import java.nio.file.Path;
 
+import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
 import com.oracle.truffle.r.runtime.REnvVars;
 import com.oracle.truffle.r.runtime.RPlatform;
 import com.oracle.truffle.r.runtime.RPlatform.OSInfo;
@@ -34,6 +35,7 @@ public class LibPaths {
     /**
      * Returns the absolute path to the directory containing the builtin libraries.
      */
+    @TruffleBoundary
     public static String getBuiltinLibPath() {
         return FileSystems.getDefault().getPath(REnvVars.rHome(), "lib").toString();
     }
@@ -42,6 +44,7 @@ public class LibPaths {
      * Returns the absolute path to the builtin library {@code libName} for use with
      * {@link System#load}.
      */
+    @TruffleBoundary
     public static String getBuiltinLibPath(String libName) {
         String rHome = REnvVars.rHome();
         OSInfo osInfo = RPlatform.getOSInfo();
@@ -53,6 +56,7 @@ public class LibPaths {
      * Returns the absolute path to the shared library associated with package {@code name}. (Does
      * not check for existence).
      */
+    @TruffleBoundary
     public static String getPackageLibPath(String name) {
         String rHome = REnvVars.rHome();
         String packageDir = "library";
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RDeparse.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RDeparse.java
index 9cd3ced303bce6c8a067230865ee612f636e7883..03cdad3ac2418da7b92327c41e95a7bf8cb393f8 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RDeparse.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RDeparse.java
@@ -871,7 +871,7 @@ public class RDeparse {
                     break;
                 case RAWSXP:
                     RRaw r = (RRaw) element;
-                    append(String.format("0x%02x", r.getValue()));
+                    append(Utils.stringFormat("0x%02x", r.getValue()));
                     break;
                 default:
                     throw RInternalError.shouldNotReachHere("unexpected SEXPTYPE: " + type);
@@ -987,6 +987,7 @@ public class RDeparse {
     /**
      * Ensure that {@code node} has a {@link SourceSection} by deparsing if necessary.
      */
+    @TruffleBoundary
     public static void ensureSourceSection(RSyntaxNode node) {
         SourceSection ss = node.getLazySourceSection();
         if (ss == RSyntaxNode.LAZY_DEPARSE) {
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/REnvVars.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/REnvVars.java
index e0a2d61e8320f0e2edd8676e9a34562c13e26c4c..87fcb60bbdc6016d67d2e0aaef48f0264062cfe9 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/REnvVars.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/REnvVars.java
@@ -217,6 +217,7 @@ public final class REnvVars implements RContext.ContextState {
     /**
      * Sanity check on the expected structure of an {@code R_HOME}.
      */
+    @TruffleBoundary
     private static boolean validateRHome(Path path, String markerFile) {
         if (path == null) {
             return false;
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java
index 0824d30cddff34978f08716f598c5d124f0f61df..e31111eb6fe6c5813d651697f70f4dd6578140e7 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java
@@ -188,7 +188,7 @@ public final class RError extends RuntimeException {
             }
             current = current.getParent();
         }
-        throw new AssertionError("Could not find RBaseNode for given Node. Is it not adopted in the AST?");
+        throw RInternalError.shouldNotReachHere("Could not find RBaseNode for given Node. Is it not adopted in the AST?");
     }
 
     /**
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RProfile.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RProfile.java
index 50d4e6c01a35aaf5dd2f24ba593c314e70a87fe0..80a9f3cad82eed5af15ce628fe23d50d00074f97 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RProfile.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RProfile.java
@@ -28,6 +28,7 @@ import java.nio.file.FileSystem;
 import java.nio.file.FileSystems;
 import java.nio.file.Path;
 
+import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
 import com.oracle.truffle.api.source.Source;
 import com.oracle.truffle.r.runtime.context.RContext;
 import com.oracle.truffle.r.runtime.ffi.BaseRFFI;
@@ -45,6 +46,7 @@ public final class RProfile implements RContext.ContextState {
     }
 
     @Override
+    @TruffleBoundary
     public RContext.ContextState initialize(RContext context) {
         String rHome = REnvVars.rHome();
         FileSystem fileSystem = FileSystems.getDefault();
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/DelegateRConnection.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/DelegateRConnection.java
index 74bc8391a0ace37af462c5777fdb26bc7c0b163b..437743ed51822b3e3d5b54dbec81824a52195864 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/DelegateRConnection.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/DelegateRConnection.java
@@ -230,6 +230,7 @@ abstract class DelegateRConnection implements RConnection, ByteChannel {
      * @return {@code true} if an incomplete line was written; {@code false} otherwise
      * @throws IOException
      */
+    @TruffleBoundary
     public static boolean writeStringHelper(WritableByteChannel out, String s, boolean nl, Charset encoding) throws IOException {
         boolean incomplete;
         final byte[] bytes = s.getBytes(encoding);
@@ -258,6 +259,7 @@ abstract class DelegateRConnection implements RConnection, ByteChannel {
      * @param eos The end-of-string terminator (may be {@code null}).
      * @throws IOException
      */
+    @TruffleBoundary
     public static void writeCharHelper(@NotNull WritableByteChannel channel, @NotNull String s, int pad, String eos) throws IOException {
 
         final byte[] bytes = s.getBytes();
@@ -394,6 +396,7 @@ abstract class DelegateRConnection implements RConnection, ByteChannel {
         }
     }
 
+    @TruffleBoundary
     public static boolean writeLinesHelper(WritableByteChannel out, RAbstractStringVector lines, String sep, Charset encoding) throws IOException {
         if (sep != null && sep.contains("\n")) {
             // fast path: we know that the line is complete
@@ -461,6 +464,7 @@ abstract class DelegateRConnection implements RConnection, ByteChannel {
     }
 
     @Override
+    @TruffleBoundary
     public int read(ByteBuffer dst) throws IOException {
         if (cache != null) {
             final int bytesRequested = dst.remaining();
@@ -481,6 +485,7 @@ abstract class DelegateRConnection implements RConnection, ByteChannel {
     }
 
     @Override
+    @TruffleBoundary
     public int write(ByteBuffer src) throws IOException {
         return getChannel().write(src);
     }
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/FileConnections.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/FileConnections.java
index 51e1782e0d2ec485d2cef0bfbb4bf36f89d93963..b14529c998dfd7df4fa202a0df4e432724a99b7c 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/FileConnections.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/FileConnections.java
@@ -624,6 +624,7 @@ public class FileConnections {
             return super.readBinChars();
         }
 
+        @TruffleBoundary
         private void setReadPosition() throws IOException {
             if (lastMode != SeekRWMode.READ) {
                 raf.seek(readOffset);
@@ -631,6 +632,7 @@ public class FileConnections {
             }
         }
 
+        @TruffleBoundary
         private void setWritePosition() throws IOException {
             if (lastMode != SeekRWMode.WRITE) {
                 raf.seek(writeOffset);
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/GammaFunctions.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/GammaFunctions.java
index 6145b2d5b45ff27a5d6a9ac691e78a0b7a706611..8979aeef7d4f1bc349c82ddfd74733af7223f8c3 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/GammaFunctions.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/GammaFunctions.java
@@ -1052,7 +1052,7 @@ public abstract class GammaFunctions {
         }
         f = res12 / elfb;
 
-        np = new Pnorm().evaluate(s2pt, 0.0, 1.0, !lowerTail, logp);
+        np = Pnorm.createTemp().evaluate(s2pt, 0.0, 1.0, !lowerTail, logp);
 
         if (logp) {
             double ndOverP = dpnorm(s2pt, !lowerTail, np);
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Pnorm.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Pnorm.java
index bf069e9a0186908a05efc768ac27b87da679fbb7..4bb9d06fc8ba6608cccc0629ecfae3fc23894608 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Pnorm.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Pnorm.java
@@ -22,7 +22,22 @@ import com.oracle.truffle.r.runtime.nmath.MathFunctions.Function3_2;
 
 public final class Pnorm implements Function3_2 {
 
-    private final BranchProfile nanProfile = BranchProfile.create();
+    private final BranchProfile nanProfile;
+
+    public Pnorm() {
+        this(BranchProfile.create());
+    }
+
+    private Pnorm(BranchProfile nanProfile) {
+        this.nanProfile = nanProfile;
+    }
+
+    /**
+     * For use in a temporary (non-Truffle Node) context.
+     */
+    public static Pnorm createTemp() {
+        return new Pnorm(null);
+    }
 
     @Override
     public double evaluate(double x, double mu, double sigma, boolean lowerTail, boolean logP) {
@@ -31,7 +46,9 @@ public final class Pnorm implements Function3_2 {
          * == mu and sigma == 0, we get the correct answer 1.
          */
         if (Double.isNaN(x) || Double.isNaN(mu) || Double.isNaN(sigma)) {
-            nanProfile.enter();
+            if (nanProfile != null) {
+                nanProfile.enter();
+            }
             return x + mu + sigma;
         }
         if (!Double.isFinite(x) && mu == x) {
@@ -40,7 +57,9 @@ public final class Pnorm implements Function3_2 {
         }
         if (sigma <= 0) {
             if (sigma < 0) {
-                nanProfile.enter();
+                if (nanProfile != null) {
+                    nanProfile.enter();
+                }
                 return Double.NaN;
             }
             /* sigma = 0 : */
@@ -170,24 +189,24 @@ public final class Pnorm implements Function3_2 {
                 /*
                  * else |x| > sqrt(32) = 5.657 : the next two case differentiations were really for
                  * lower=T, log=F Particularly *not* for log_p !
-                 * 
+                 *
                  * Cody had (-37.5193 < x && x < 8.2924) ; R originally had y < 50
-                 * 
+                 *
                  * Note that we do want symmetry(0), lower/upper -> hence use y
                  */
             } else if ((logP && y < 1e170) /* avoid underflow below */
             /*
              * ^^^^^ MM FIXME: can speedup for log_p and much larger |x| ! Then, make use of
              * Abramowitz & Stegun, 26.2.13, something like
-             * 
+             *
              * xsq = x*x;
-             * 
+             *
              * if(xsq * DBL_EPSILON < 1.) del = (1. - (1. - 5./(xsq+6.)) / (xsq+4.)) / (xsq+2.);
              * else del = 0.;cum = -.5*xsq - M_LN_SQRT_2PI - log(x) + log1p(-del);ccum =
              * log1p(-exp(*cum)); /.* ~ log(1) = 0 *./
-             * 
+             *
              * swap_tail;
-             * 
+             *
              * [Yes, but xsq might be infinite.]
              */
                             || (lower && -37.5193 < x && x < 8.2924) || (upper && -8.2924 < x && x < 37.5193)) {
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/SNorm.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/SNorm.java
index 07ff51a3390803a91bad6afe41108422f8553f51..7549bbc4924ea6a7b4401d9d53bca33fb6c39555 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/SNorm.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/SNorm.java
@@ -351,7 +351,8 @@ public final class SNorm {
                 return 0d; // can NEVER reach here (infinite loop ahead)
 
             default:
-                throw new AssertionError();
+                assert false;
+                return 0d;
         }
     }
 }