From 0edabdf6d1dbda23826e2347b38d36c9f7d4155b Mon Sep 17 00:00:00 2001
From: Zbynek Slajchrt <zbynek.slajchrt@oracle.com>
Date: Fri, 16 Feb 2018 17:35:05 +0100
Subject: [PATCH] Truffle boundary added at several places in FastR NFI

---
 .../truffle/r/ffi/impl/common/JavaUpCallsRFFIImpl.java      | 6 ++++++
 .../truffle/r/ffi/impl/nodes/NewCustomConnectionNode.java   | 3 +++
 .../src/com/oracle/truffle/r/runtime/context/Engine.java    | 5 +++--
 .../com/oracle/truffle/r/runtime/data/CharSXPWrapper.java   | 4 ++++
 4 files changed, 16 insertions(+), 2 deletions(-)

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 f05db26452..ac7eec51f7 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
@@ -1714,31 +1714,37 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI {
             public abstract long execute(Object vector);
 
             @Specialization
+            @TruffleBoundary
             protected static long get(RIntVector vector) {
                 return vector.allocateNativeContents();
             }
 
             @Specialization
+            @TruffleBoundary
             protected static long get(RLogicalVector vector) {
                 return vector.allocateNativeContents();
             }
 
             @Specialization
+            @TruffleBoundary
             protected static long get(RRawVector vector) {
                 return vector.allocateNativeContents();
             }
 
             @Specialization
+            @TruffleBoundary
             protected static long get(RDoubleVector vector) {
                 return vector.allocateNativeContents();
             }
 
             @Specialization
+            @TruffleBoundary
             protected static long get(RComplexVector vector) {
                 return vector.allocateNativeContents();
             }
 
             @Specialization
+            @TruffleBoundary
             protected static long get(CharSXPWrapper vector) {
                 return vector.allocateNativeContents();
             }
diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/NewCustomConnectionNode.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/NewCustomConnectionNode.java
index c0939de055..dc8e816a7d 100644
--- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/NewCustomConnectionNode.java
+++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/NewCustomConnectionNode.java
@@ -26,6 +26,7 @@ import static com.oracle.truffle.r.runtime.data.NativeDataAccess.readNativeStrin
 
 import java.io.IOException;
 
+import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
 import com.oracle.truffle.api.dsl.Cached;
 import com.oracle.truffle.api.dsl.Specialization;
 import com.oracle.truffle.api.interop.ForeignAccess;
@@ -45,6 +46,7 @@ public abstract class NewCustomConnectionNode extends FFIUpCallNode.Arg4 {
     }
 
     @Specialization
+    @TruffleBoundary
     Object handleStrings(String description, String mode, String className, RExternalPtr connAddr) {
         try {
             return new NativeRConnection(description, mode, className, connAddr).asVector();
@@ -58,6 +60,7 @@ public abstract class NewCustomConnectionNode extends FFIUpCallNode.Arg4 {
     }
 
     @Specialization
+    @TruffleBoundary
     Object handleAddresses(TruffleObject description, TruffleObject mode, TruffleObject className, RExternalPtr connAddr,
                     @Cached("createAsPointerNode()") Node descriptionAsPtrNode, @Cached("createAsPointerNode()") Node modeAsPtrNode, @Cached("createAsPointerNode()") Node classNameAsPtrNode) {
         try {
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/Engine.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/Engine.java
index 7da6564454..a3f5d4b98c 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/Engine.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/Engine.java
@@ -172,8 +172,9 @@ public interface Engine {
     RExpression parse(Source source) throws ParseException;
 
     /**
-     * This is the external interface from {@link org.graalvm.polyglot.Context#eval(Source)}. It is
-     * required to return a {@link CallTarget} which may be cached for future use, and the
+     * This is the external interface from
+     * {@link org.graalvm.polyglot.Context#eval(org.graalvm.polyglot.Source)}. It is required to
+     * return a {@link CallTarget} which may be cached for future use, and the
      * {@link org.graalvm.polyglot.Context} is responsible for actually invoking the call target.
      */
     CallTarget parseToCallTarget(Source source, MaterializedFrame executionFrame) throws ParseException;
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/CharSXPWrapper.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/CharSXPWrapper.java
index d1d4cab104..1f7f724a11 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/CharSXPWrapper.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/CharSXPWrapper.java
@@ -24,6 +24,7 @@ package com.oracle.truffle.r.runtime.data;
 
 import java.nio.charset.StandardCharsets;
 
+import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
 import com.oracle.truffle.r.runtime.RRuntime;
 
 /**
@@ -48,6 +49,7 @@ public final class CharSXPWrapper extends RObject implements RTruffleObject {
         this.contents = contents;
     }
 
+    @TruffleBoundary
     public String getContents() {
         if (this == NA) {
             // The NA string may have been moved to the native space if someone called R_CHAR on it,
@@ -58,10 +60,12 @@ public final class CharSXPWrapper extends RObject implements RTruffleObject {
         return NativeDataAccess.getData(this, contents);
     }
 
+    @TruffleBoundary
     public byte getByteAt(int index) {
         return NativeDataAccess.getDataAt(this, getBytes(), index);
     }
 
+    @TruffleBoundary
     public int getLength() {
         return NativeDataAccess.getDataLength(this, getBytes());
     }
-- 
GitLab