diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/common/Generic_Tools.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/common/Generic_Tools.java deleted file mode 100644 index 6ba135893500d83227032afcf8fd1dd69512e369..0000000000000000000000000000000000000000 --- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/common/Generic_Tools.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.r.ffi.impl.common; - -import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; -import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.r.runtime.RInternalError; -import com.oracle.truffle.r.runtime.conn.RConnection; -import com.oracle.truffle.r.runtime.data.RLogicalVector; -import com.oracle.truffle.r.runtime.data.RStringVector; -import com.oracle.truffle.r.runtime.env.REnvironment; -import com.oracle.truffle.r.runtime.ffi.CallRFFI; -import com.oracle.truffle.r.runtime.ffi.DLL; -import com.oracle.truffle.r.runtime.ffi.DLL.DLLInfo; -import com.oracle.truffle.r.runtime.ffi.DLL.SymbolHandle; -import com.oracle.truffle.r.runtime.ffi.NativeCallInfo; -import com.oracle.truffle.r.runtime.ffi.RFFIFactory; -import com.oracle.truffle.r.runtime.ffi.ToolsRFFI; - -public class Generic_Tools implements ToolsRFFI { - public static class Generic_ToolsRFFINode extends Node implements ParseRdNode { - private static final String C_PARSE_RD = "C_parseRd"; - protected static final String TOOLS = "tools"; - - @Child private CallRFFI.InvokeCallNode callRFFINode = RFFIFactory.getCallRFFI().createInvokeCallNode(); - @Child private DLL.RFindSymbolNode findSymbolNode = DLL.RFindSymbolNode.create(); - - @CompilationFinal private NativeCallInfo nativeCallInfo; - - /** - * Invoke C implementation, N.B., code is not thread safe. - */ - @Override - public Object execute(RConnection con, REnvironment srcfile, RLogicalVector verbose, RLogicalVector fragment, RStringVector basename, RLogicalVector warningCalls, Object macros, - RLogicalVector warndups) { - synchronized (Generic_Tools.class) { - try { - if (nativeCallInfo == null) { - // lookup entry point (assert library is loaded) - DLLInfo toolsDLLInfo = DLL.findLibrary(TOOLS); - assert toolsDLLInfo != null; - SymbolHandle symbolHandle = findSymbolNode.execute(C_PARSE_RD, TOOLS, DLL.RegisteredNativeSymbol.any()); - assert symbolHandle != DLL.SYMBOL_NOT_FOUND; - nativeCallInfo = new NativeCallInfo(C_PARSE_RD, symbolHandle, toolsDLLInfo); - } - return callRFFINode.dispatch(nativeCallInfo, - new Object[]{con, srcfile, verbose, fragment, basename, warningCalls, macros, warndups}); - } catch (Throwable ex) { - throw RInternalError.shouldNotReachHere(ex, "error during Rd parsing" + ex.getMessage()); - } - } - } - } - - @Override - public ParseRdNode createParseRdNode() { - return new Generic_ToolsRFFINode(); - } -} diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_Context.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_Context.java index 7efafe94f6edbad71a0028d13c593c62725c3175..e898711c4ee5131cd4a2798af98f8d0618cfee44 100644 --- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_Context.java +++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_Context.java @@ -34,6 +34,7 @@ import com.oracle.truffle.r.runtime.ffi.NativeFunction; import com.oracle.truffle.r.runtime.ffi.PCRERFFI; import com.oracle.truffle.r.runtime.ffi.RFFIContext; import com.oracle.truffle.r.runtime.ffi.StatsRFFI; +import com.oracle.truffle.r.runtime.ffi.ToolsRFFI; import com.oracle.truffle.r.runtime.ffi.ZipRFFI; /** @@ -49,7 +50,7 @@ final class TruffleLLVM_Context extends RFFIContext { super(new TruffleLLVM_C(), new BaseRFFI(TruffleLLVM_DownCallNodeFactory.INSTANCE), new TruffleLLVM_Call(), new TruffleLLVM_DLL(), new TruffleLLVM_UserRng(), new ZipRFFI(TruffleLLVM_DownCallNodeFactory.INSTANCE), new PCRERFFI(TruffleLLVM_DownCallNodeFactory.INSTANCE), new LapackRFFI(TruffleLLVM_DownCallNodeFactory.INSTANCE), new StatsRFFI(TruffleLLVM_DownCallNodeFactory.INSTANCE), - new TruffleLLVM_Tools(), new TruffleLLVM_REmbed(), new MiscRFFI(TruffleLLVM_DownCallNodeFactory.INSTANCE)); + new ToolsRFFI(), new TruffleLLVM_REmbed(), new MiscRFFI(TruffleLLVM_DownCallNodeFactory.INSTANCE)); } static TruffleLLVM_Context getContextState() { diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_Tools.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_Tools.java deleted file mode 100644 index 5e0d1feead4941ca78725f517ffbda4a51616428..0000000000000000000000000000000000000000 --- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_Tools.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.r.ffi.impl.llvm; - -import com.oracle.truffle.r.ffi.impl.common.Generic_Tools; -import com.oracle.truffle.r.runtime.conn.RConnection; -import com.oracle.truffle.r.runtime.data.RLogicalVector; -import com.oracle.truffle.r.runtime.data.RStringVector; -import com.oracle.truffle.r.runtime.env.REnvironment; -import com.oracle.truffle.r.runtime.ffi.ToolsRFFI; - -public class TruffleLLVM_Tools implements ToolsRFFI { - - private static class TruffleLLVM_ToolsRFFINode extends Generic_Tools.Generic_ToolsRFFINode { - /** - * Invoke C implementation, N.B., code is not thread safe. - */ - @Override - public Object execute(RConnection con, REnvironment srcfile, RLogicalVector verbose, RLogicalVector fragment, RStringVector basename, RLogicalVector warningCalls, Object macros, - RLogicalVector warndups) { - return super.execute(con, srcfile, verbose, fragment, basename, warningCalls, macros, warndups); - } - } - - @Override - public ParseRdNode createParseRdNode() { - return new TruffleLLVM_ToolsRFFINode(); - } -} diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/managed/Managed_RFFIFactory.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/managed/Managed_RFFIFactory.java index 5807ab6fe962171ba6b848834df603aa6fea3406..728b244fa3b67f40b4a1b7cccbf702a0bc0dea6e 100644 --- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/managed/Managed_RFFIFactory.java +++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/managed/Managed_RFFIFactory.java @@ -108,12 +108,7 @@ public final class Managed_RFFIFactory extends RFFIFactory { throw unsupported("user defined RNG"); } }, new ZipRFFI(Managed_DownCallNodeFactory.INSTANCE), new PCRERFFI(Managed_DownCallNodeFactory.INSTANCE), new LapackRFFI(Managed_DownCallNodeFactory.INSTANCE), - new StatsRFFI(Managed_DownCallNodeFactory.INSTANCE), new ToolsRFFI() { - @Override - public ParseRdNode createParseRdNode() { - throw unsupported("parseRD"); - } - }, new Managed_REmbedRFFI(), new MiscRFFI(Managed_DownCallNodeFactory.INSTANCE)); + new StatsRFFI(Managed_DownCallNodeFactory.INSTANCE), new ToolsRFFI(), new Managed_REmbedRFFI(), new MiscRFFI(Managed_DownCallNodeFactory.INSTANCE)); } private static class IgnoreUpCallExceptionNode extends Node implements HandleUpCallExceptionNode { diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_Context.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_Context.java index c620ea79966a7ea26ce7ebcf4960e1962dcc5277..31635cc690c340ab23191edd67aee486b20b13c7 100644 --- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_Context.java +++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_Context.java @@ -62,6 +62,7 @@ import com.oracle.truffle.r.runtime.ffi.PCRERFFI; import com.oracle.truffle.r.runtime.ffi.RFFIContext; import com.oracle.truffle.r.runtime.ffi.RFFIVariables; import com.oracle.truffle.r.runtime.ffi.StatsRFFI; +import com.oracle.truffle.r.runtime.ffi.ToolsRFFI; import com.oracle.truffle.r.runtime.ffi.ZipRFFI; import sun.misc.Unsafe; @@ -92,7 +93,7 @@ final class TruffleNFI_Context extends RFFIContext { TruffleNFI_Context() { super(new TruffleNFI_C(), new BaseRFFI(TruffleNFI_DownCallNodeFactory.INSTANCE), new TruffleNFI_Call(), new TruffleNFI_DLL(), new TruffleNFI_UserRng(), new ZipRFFI(TruffleNFI_DownCallNodeFactory.INSTANCE), new PCRERFFI(TruffleNFI_DownCallNodeFactory.INSTANCE), new LapackRFFI(TruffleNFI_DownCallNodeFactory.INSTANCE), - new StatsRFFI(TruffleNFI_DownCallNodeFactory.INSTANCE), new TruffleNFI_Tools(), new TruffleNFI_REmbed(), new MiscRFFI(TruffleNFI_DownCallNodeFactory.INSTANCE)); + new StatsRFFI(TruffleNFI_DownCallNodeFactory.INSTANCE), new ToolsRFFI(), new TruffleNFI_REmbed(), new MiscRFFI(TruffleNFI_DownCallNodeFactory.INSTANCE)); // forward constructor } diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_Tools.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_Tools.java deleted file mode 100644 index ca3cebfcfc3afcecddff9b59c82236f861f7267b..0000000000000000000000000000000000000000 --- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_Tools.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.r.ffi.impl.nfi; - -import com.oracle.truffle.r.ffi.impl.common.Generic_Tools; -import com.oracle.truffle.r.runtime.conn.RConnection; -import com.oracle.truffle.r.runtime.data.RLogicalVector; -import com.oracle.truffle.r.runtime.data.RStringVector; -import com.oracle.truffle.r.runtime.env.REnvironment; -import com.oracle.truffle.r.runtime.ffi.ToolsRFFI; - -public class TruffleNFI_Tools implements ToolsRFFI { - - private static class TruffleNFI_ToolsRFFINode extends Generic_Tools.Generic_ToolsRFFINode { - - @Override - public Object execute(RConnection con, REnvironment srcfile, RLogicalVector verbose, RLogicalVector fragment, RStringVector basename, RLogicalVector warningCalls, Object macros, - RLogicalVector warndups) { - return super.execute(con, srcfile, verbose, fragment, basename, warningCalls, macros, warndups); - } - } - - @Override - public ParseRdNode createParseRdNode() { - return new TruffleNFI_ToolsRFFINode(); - } -} diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/ToolsRFFI.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/ToolsRFFI.java index 629bc1a5889deaf3bfc9beaa9784423f32ae5e16..34ef4a966a9d902205ce7a03b932b5fe1b5d8b69 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/ToolsRFFI.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/ToolsRFFI.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2018, 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 @@ -22,17 +22,30 @@ */ package com.oracle.truffle.r.runtime.ffi; +import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; +import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.NodeInterface; +import com.oracle.truffle.r.runtime.RInternalError; import com.oracle.truffle.r.runtime.conn.RConnection; import com.oracle.truffle.r.runtime.data.RLogicalVector; import com.oracle.truffle.r.runtime.data.RStringVector; import com.oracle.truffle.r.runtime.env.REnvironment; +import com.oracle.truffle.r.runtime.ffi.DLL.DLLInfo; +import com.oracle.truffle.r.runtime.ffi.DLL.SymbolHandle; /** * Interface to native (C) methods provided by the {@code tools} package. */ -public interface ToolsRFFI { - interface ParseRdNode extends NodeInterface { +public final class ToolsRFFI { + public static class ParseRdNode extends Node { + private static final String C_PARSE_RD = "C_parseRd"; + protected static final String TOOLS = "tools"; + + @Child private CallRFFI.InvokeCallNode callRFFINode = RFFIFactory.getCallRFFI().createInvokeCallNode(); + @Child private DLL.RFindSymbolNode findSymbolNode = DLL.RFindSymbolNode.create(); + + @CompilationFinal private NativeCallInfo nativeCallInfo; + /** * This invokes the Rd parser, written in C, and part of GnuR, that does its work using the * R FFI interface. The R code initially invokes this via {@code .External2(C_parseRd, ...)} @@ -41,9 +54,28 @@ public interface ToolsRFFI { * code. We can't go straight to the GnuR C entry point as that makes GnuR-specific * assumptions about, for example, how connections are implemented. */ - Object execute(RConnection con, REnvironment srcfile, RLogicalVector verbose, RLogicalVector fragment, RStringVector basename, RLogicalVector warningCalls, Object macros, - RLogicalVector warndups); + public Object execute(RConnection con, REnvironment srcfile, RLogicalVector verbose, RLogicalVector fragment, RStringVector basename, RLogicalVector warningCalls, Object macros, + RLogicalVector warndups) { + synchronized (ToolsRFFI.class) { + try { + if (nativeCallInfo == null) { + // lookup entry point (assert library is loaded) + DLLInfo toolsDLLInfo = DLL.findLibrary(TOOLS); + assert toolsDLLInfo != null; + SymbolHandle symbolHandle = findSymbolNode.execute(C_PARSE_RD, TOOLS, DLL.RegisteredNativeSymbol.any()); + assert symbolHandle != DLL.SYMBOL_NOT_FOUND; + nativeCallInfo = new NativeCallInfo(C_PARSE_RD, symbolHandle, toolsDLLInfo); + } + return callRFFINode.dispatch(nativeCallInfo, + new Object[]{con, srcfile, verbose, fragment, basename, warningCalls, macros, warndups}); + } catch (Throwable ex) { + throw RInternalError.shouldNotReachHere(ex, "error during Rd parsing" + ex.getMessage()); + } + } + } } - ParseRdNode createParseRdNode(); + public ParseRdNode createParseRdNode() { + return new ParseRdNode(); + } }