changeset 22129:0589cc5cab30

TruffleVM can now depend on api.interop and thus there is no need for indirection between SymbolInvoker and its Impl. Enough to do direct calls.
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Thu, 03 Sep 2015 17:15:44 +0200
parents f879b1fe3773
children 226ce74876b0
files mx.truffle/suite.py truffle/com.oracle.truffle.api.interop/src/META-INF/services/com.oracle.truffle.api.impl.SymbolInvoker truffle/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/impl/SymbolInvokerImpl.java truffle/com.oracle.truffle.api.vm/src/com/oracle/truffle/api/vm/ArgumentsMishmashException.java truffle/com.oracle.truffle.api.vm/src/com/oracle/truffle/api/vm/SymbolInvokerImpl.java truffle/com.oracle.truffle.api.vm/src/com/oracle/truffle/api/vm/TruffleVM.java truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/Accessor.java truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/SymbolInvoker.java
diffstat 8 files changed, 177 insertions(+), 215 deletions(-) [+]
line wrap: on
line diff
--- a/mx.truffle/suite.py	Thu Sep 03 16:38:45 2015 +0200
+++ b/mx.truffle/suite.py	Thu Sep 03 17:15:44 2015 +0200
@@ -49,7 +49,7 @@
       "subDir" : "truffle",
       "sourceDirs" : ["src"],
       "dependencies" : [
-        "com.oracle.truffle.api",
+        "com.oracle.truffle.api.interop",
       ],
       "javaCompliance" : "1.7",
       "workingSets" : "API,Truffle",
--- a/truffle/com.oracle.truffle.api.interop/src/META-INF/services/com.oracle.truffle.api.impl.SymbolInvoker	Thu Sep 03 16:38:45 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-com.oracle.truffle.api.interop.impl.SymbolInvokerImpl
--- a/truffle/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/impl/SymbolInvokerImpl.java	Thu Sep 03 16:38:45 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,138 +0,0 @@
-/*
- * Copyright (c) 2014, 2015, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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.api.interop.impl;
-
-import java.io.*;
-
-import com.oracle.truffle.api.*;
-import com.oracle.truffle.api.frame.*;
-import com.oracle.truffle.api.impl.*;
-import com.oracle.truffle.api.interop.ForeignAccess;
-import com.oracle.truffle.api.interop.Message;
-import com.oracle.truffle.api.interop.TruffleObject;
-import com.oracle.truffle.api.nodes.*;
-
-public final class SymbolInvokerImpl extends SymbolInvoker {
-    @SuppressWarnings({"unchecked", "rawtypes"})
-    @Override
-    protected CallTarget createCallTarget(TruffleLanguage<?> lang, Object symbol, Object... arr) throws IOException {
-        Class<? extends TruffleLanguage<?>> type;
-        if (lang != null) {
-            type = (Class) lang.getClass();
-        } else {
-            type = (Class) TruffleLanguage.class;
-        }
-        RootNode symbolNode;
-        if ((symbol instanceof String) || (symbol instanceof Number) || (symbol instanceof Boolean) || (symbol instanceof Character)) {
-            symbolNode = new ConstantRootNode(type, symbol);
-        } else {
-            Node executeMain = Message.createExecute(arr.length).createNode();
-            symbolNode = new TemporaryRoot(type, executeMain, (TruffleObject) symbol, arr.length);
-        }
-        return Truffle.getRuntime().createCallTarget(symbolNode);
-    }
-
-    private final class ConstantRootNode extends RootNode {
-
-        private final Object value;
-
-        public ConstantRootNode(Class<? extends TruffleLanguage<?>> lang, Object value) {
-            super(lang, null, null);
-            this.value = value;
-        }
-
-        @Override
-        public Object execute(VirtualFrame vf) {
-            return value;
-        }
-    }
-
-    private static class TemporaryRoot extends RootNode {
-        @Child private Node foreignAccess;
-        @Child private ConvertNode convert;
-        private final int argumentLength;
-        private final TruffleObject function;
-
-        public TemporaryRoot(Class<? extends TruffleLanguage<?>> lang, Node foreignAccess, TruffleObject function, int argumentLength) {
-            super(lang, null, null);
-            this.foreignAccess = foreignAccess;
-            this.convert = new ConvertNode();
-            this.function = function;
-            this.argumentLength = argumentLength;
-        }
-
-        @Override
-        public Object execute(VirtualFrame frame) {
-            final Object[] args = frame.getArguments();
-            if (args.length != argumentLength) {
-                throw new ArgumentsMishmashException();
-            }
-            Object tmp = ForeignAccess.execute(foreignAccess, frame, function, args);
-            return convert.convert(frame, tmp);
-        }
-    }
-
-    private static final class ConvertNode extends Node {
-        @Child private Node isNull;
-        @Child private Node isBoxed;
-        @Child private Node unbox;
-
-        public ConvertNode() {
-            this.isNull = Message.IS_NULL.createNode();
-            this.isBoxed = Message.IS_BOXED.createNode();
-            this.unbox = Message.UNBOX.createNode();
-        }
-
-        Object convert(VirtualFrame frame, Object obj) {
-            if (obj instanceof TruffleObject) {
-                return convert(frame, (TruffleObject) obj);
-            } else {
-                return obj;
-            }
-        }
-
-        private Object convert(VirtualFrame frame, TruffleObject obj) {
-            Object isBoxedResult;
-            try {
-                isBoxedResult = ForeignAccess.execute(isBoxed, frame, obj);
-            } catch (IllegalArgumentException ex) {
-                isBoxedResult = false;
-            }
-            if (Boolean.TRUE.equals(isBoxedResult)) {
-                return ForeignAccess.execute(unbox, frame, obj);
-            } else {
-                try {
-                    Object isNullResult = ForeignAccess.execute(isNull, frame, obj);
-                    if (Boolean.TRUE.equals(isNullResult)) {
-                        return null;
-                    }
-                } catch (IllegalArgumentException ex) {
-                    // fallthrough
-                }
-            }
-            return obj;
-        }
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/truffle/com.oracle.truffle.api.vm/src/com/oracle/truffle/api/vm/ArgumentsMishmashException.java	Thu Sep 03 17:15:44 2015 +0200
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2014, 2015, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.api.vm;
+
+final class ArgumentsMishmashException extends IllegalArgumentException {
+    static final long serialVersionUID = 1L;
+
+    public ArgumentsMishmashException() {
+    }
+
+    @Override
+    public synchronized Throwable fillInStackTrace() {
+        return this;
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/truffle/com.oracle.truffle.api.vm/src/com/oracle/truffle/api/vm/SymbolInvokerImpl.java	Thu Sep 03 17:15:44 2015 +0200
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2014, 2015, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.api.vm;
+
+import com.oracle.truffle.api.*;
+import com.oracle.truffle.api.frame.*;
+import com.oracle.truffle.api.interop.ForeignAccess;
+import com.oracle.truffle.api.interop.Message;
+import com.oracle.truffle.api.interop.TruffleObject;
+import com.oracle.truffle.api.nodes.*;
+import java.io.*;
+
+final class SymbolInvokerImpl {
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    static CallTarget createCallTarget(TruffleLanguage<?> lang, Object symbol, Object... arr) throws IOException {
+        Class<? extends TruffleLanguage<?>> type;
+        if (lang != null) {
+            type = (Class) lang.getClass();
+        } else {
+            type = (Class) TruffleLanguage.class;
+        }
+        RootNode symbolNode;
+        if ((symbol instanceof String) || (symbol instanceof Number) || (symbol instanceof Boolean) || (symbol instanceof Character)) {
+            symbolNode = new ConstantRootNode(type, symbol);
+        } else {
+            Node executeMain = Message.createExecute(arr.length).createNode();
+            symbolNode = new TemporaryRoot(type, executeMain, (TruffleObject) symbol, arr.length);
+        }
+        return Truffle.getRuntime().createCallTarget(symbolNode);
+    }
+
+    private static final class ConstantRootNode extends RootNode {
+
+        private final Object value;
+
+        public ConstantRootNode(Class<? extends TruffleLanguage<?>> lang, Object value) {
+            super(lang, null, null);
+            this.value = value;
+        }
+
+        @Override
+        public Object execute(VirtualFrame vf) {
+            return value;
+        }
+    }
+
+    private static class TemporaryRoot extends RootNode {
+        @Child private Node foreignAccess;
+        @Child private ConvertNode convert;
+        private final int argumentLength;
+        private final TruffleObject function;
+
+        public TemporaryRoot(Class<? extends TruffleLanguage<?>> lang, Node foreignAccess, TruffleObject function, int argumentLength) {
+            super(lang, null, null);
+            this.foreignAccess = foreignAccess;
+            this.convert = new ConvertNode();
+            this.function = function;
+            this.argumentLength = argumentLength;
+        }
+
+        @Override
+        public Object execute(VirtualFrame frame) {
+            final Object[] args = frame.getArguments();
+            if (args.length != argumentLength) {
+                throw new ArgumentsMishmashException();
+            }
+            Object tmp = ForeignAccess.execute(foreignAccess, frame, function, args);
+            return convert.convert(frame, tmp);
+        }
+    }
+
+    private static final class ConvertNode extends Node {
+        @Child private Node isNull;
+        @Child private Node isBoxed;
+        @Child private Node unbox;
+
+        public ConvertNode() {
+            this.isNull = Message.IS_NULL.createNode();
+            this.isBoxed = Message.IS_BOXED.createNode();
+            this.unbox = Message.UNBOX.createNode();
+        }
+
+        Object convert(VirtualFrame frame, Object obj) {
+            if (obj instanceof TruffleObject) {
+                return convert(frame, (TruffleObject) obj);
+            } else {
+                return obj;
+            }
+        }
+
+        private Object convert(VirtualFrame frame, TruffleObject obj) {
+            Object isBoxedResult;
+            try {
+                isBoxedResult = ForeignAccess.execute(isBoxed, frame, obj);
+            } catch (IllegalArgumentException ex) {
+                isBoxedResult = false;
+            }
+            if (Boolean.TRUE.equals(isBoxedResult)) {
+                return ForeignAccess.execute(unbox, frame, obj);
+            } else {
+                try {
+                    Object isNullResult = ForeignAccess.execute(isNull, frame, obj);
+                    if (Boolean.TRUE.equals(isNullResult)) {
+                        return null;
+                    }
+                } catch (IllegalArgumentException ex) {
+                    // fallthrough
+                }
+            }
+            return obj;
+        }
+    }
+}
--- a/truffle/com.oracle.truffle.api.vm/src/com/oracle/truffle/api/vm/TruffleVM.java	Thu Sep 03 16:38:45 2015 +0200
+++ b/truffle/com.oracle.truffle.api.vm/src/com/oracle/truffle/api/vm/TruffleVM.java	Thu Sep 03 17:15:44 2015 +0200
@@ -639,11 +639,11 @@
                 for (;;) {
                     try {
                         if (target == null) {
-                            target = SPI.createCallTarget(language, result[0], arr.toArray());
+                            target = SymbolInvokerImpl.createCallTarget(language, result[0], arr.toArray());
                         }
                         res[0] = target.call(arr.toArray());
                         break;
-                    } catch (SymbolInvoker.ArgumentsMishmashException ex) {
+                    } catch (ArgumentsMishmashException ex) {
                         target = null;
                     }
                 }
@@ -843,11 +843,6 @@
         }
 
         @Override
-        protected CallTarget createCallTarget(TruffleLanguage<?> lang, Object obj, Object[] args) throws IOException {
-            return super.createCallTarget(lang, obj, args);
-        }
-
-        @Override
         public ToolSupportProvider getToolSupport(TruffleLanguage<?> l) {
             return super.getToolSupport(l);
         }
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/Accessor.java	Thu Sep 03 16:38:45 2015 +0200
+++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/Accessor.java	Thu Sep 03 17:15:44 2015 +0200
@@ -24,9 +24,6 @@
  */
 package com.oracle.truffle.api.impl;
 
-import java.io.*;
-import java.util.*;
-
 import com.oracle.truffle.api.*;
 import com.oracle.truffle.api.TruffleLanguage.Env;
 import com.oracle.truffle.api.debug.*;
@@ -34,6 +31,7 @@
 import com.oracle.truffle.api.nodes.Node;
 import com.oracle.truffle.api.nodes.RootNode;
 import com.oracle.truffle.api.source.*;
+import java.io.*;
 import java.lang.ref.Reference;
 import java.lang.ref.WeakReference;
 
@@ -154,22 +152,6 @@
         return API.getDebugSupport(l);
     }
 
-    private static final SymbolInvoker INVOKER;
-
-    static {
-        SymbolInvoker singleton = null;
-        for (SymbolInvoker si : ServiceLoader.load(SymbolInvoker.class)) {
-            assert singleton == null : "More than one SymbolInvoker found: " + singleton + ", " + si;
-            singleton = si;
-        }
-        assert singleton != null : "No SymbolInvoker found";
-        INVOKER = singleton;
-    }
-
-    protected CallTarget createCallTarget(TruffleLanguage<?> lang, Object obj, Object[] args) throws IOException {
-        return INVOKER.createCallTarget(lang, obj, args);
-    }
-
     protected Class<? extends TruffleLanguage> findLanguage(RootNode n) {
         return NODES.findLanguage(n);
     }
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/SymbolInvoker.java	Thu Sep 03 16:38:45 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2014, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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.api.impl;
-
-import com.oracle.truffle.api.CallTarget;
-import com.oracle.truffle.api.TruffleLanguage;
-import java.io.*;
-
-/**
- * XXX: Temporary class to make unit tests pass without messing with Message implementations and
- * associated nodes too much.
- */
-public abstract class SymbolInvoker {
-    protected abstract CallTarget createCallTarget(TruffleLanguage<?> lang, Object symbol, Object... args) throws IOException;
-
-    public static final class ArgumentsMishmashException extends IllegalArgumentException {
-        static final long serialVersionUID = 1L;
-
-        public ArgumentsMishmashException() {
-        }
-
-        @Override
-        public synchronized Throwable fillInStackTrace() {
-            return this;
-        }
-    }
-}