changeset 21013:556b6a4b36b2

Interop: add truffle.interop
author Matthias Grimmer <grimmer@ssw.jku.at>
date Mon, 20 Apr 2015 10:58:35 +0200
parents 44ee46c753b1
children c11ea4cb5765
files graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/ForeignAccessArguments.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/TruffleLanguage.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/Argument.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/Execute.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/GetSize.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/HasSize.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/IsBoxed.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/IsExecutable.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/IsNull.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/MessageUtil.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/Read.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/Receiver.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/UnaryMessage.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/Unbox.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/Write.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/node/ForeignObjectAccessHeadNode.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/node/ForeignObjectAccessNode.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/node/ObjectAccessNode.java mx/suite.py
diffstat 19 files changed, 1006 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/ForeignAccessArguments.java	Mon Apr 20 10:58:35 2015 +0200
@@ -0,0 +1,78 @@
+/*
+ * 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.interop;
+
+import com.oracle.truffle.api.*;
+
+public final class ForeignAccessArguments {
+    public static final Object[] EMPTY_ARGUMENTS_ARRAY = new Object[0];
+    public static final int RECEIVER_INDEX = 0;
+    public static final int RUNTIME_ARGUMENT_COUNT = 1;
+
+    public static Object[] create(Object receiver) {
+        return new Object[]{receiver};
+    }
+
+    public static Object[] create(Object receiver, Object[] arguments) {
+        Object[] objectArguments = new Object[RUNTIME_ARGUMENT_COUNT + arguments.length];
+        objectArguments[RECEIVER_INDEX] = receiver;
+        arraycopy(arguments, 0, objectArguments, RUNTIME_ARGUMENT_COUNT, arguments.length);
+        return objectArguments;
+    }
+
+    public static Object getArgument(Object[] arguments, int index) {
+        return arguments[RUNTIME_ARGUMENT_COUNT + index];
+    }
+
+    public static Object getReceiver(Object[] arguments) {
+        return arguments[RECEIVER_INDEX];
+    }
+
+    public static Object[] extractUserArguments(Object[] arguments) {
+        return copyOfRange(arguments, RUNTIME_ARGUMENT_COUNT, arguments.length);
+    }
+
+    public static int getUserArgumentCount(Object[] arguments) {
+        return arguments.length - RUNTIME_ARGUMENT_COUNT;
+    }
+
+    private static Object[] copyOfRange(Object[] original, int from, int to) {
+        int newLength = to - from;
+        if (newLength < 0) {
+            CompilerDirectives.transferToInterpreter();
+            throw new IllegalArgumentException(from + " > " + to);
+        }
+        Object[] copy = new Object[newLength];
+        arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength));
+        return copy;
+    }
+
+    private static void arraycopy(Object[] src, int srcPos, Object[] dest, int destPos, int length) {
+        for (int i = 0; i < length; i++) {
+            dest[destPos + i] = src[srcPos + i];
+        }
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/TruffleLanguage.java	Mon Apr 20 10:58:35 2015 +0200
@@ -0,0 +1,40 @@
+/*
+ * 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.interop;
+
+import com.oracle.truffle.api.interop.*;
+
+public interface TruffleLanguage {
+    String getLanguageName();
+
+    TruffleObject getLanguageContext();
+
+    void setGlobalContext(TruffleObject context);
+
+    boolean hasGlobalProperty(String name);
+
+    Object run(String[] arguments);
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/Argument.java	Mon Apr 20 10:58:35 2015 +0200
@@ -0,0 +1,39 @@
+/*
+ * 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.interop.messages;
+
+public final class Argument {
+    private Argument() {
+    }
+
+    public static Argument create() {
+        return new Argument();
+    }
+
+    @Override
+    public String toString() {
+        return String.format("Argument");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/Execute.java	Mon Apr 20 10:58:35 2015 +0200
@@ -0,0 +1,68 @@
+/*
+ * 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.interop.messages;
+
+import com.oracle.truffle.api.interop.messages.*;
+
+public final class Execute implements Message {
+    private final Object receiver;
+    private final int arity;
+
+    public static Execute create(Receiver receiver, int arity) {
+        return new Execute(receiver, arity);
+    }
+
+    public static Execute create(Message receiver, int arity) {
+        return new Execute(receiver, arity);
+    }
+
+    private Execute(Object receiver, int arity) {
+        this.receiver = receiver;
+        this.arity = arity;
+    }
+
+    public Object getReceiver() {
+        return receiver;
+    }
+
+    public int getArity() {
+        return arity;
+    }
+
+    public boolean matchStructure(Object message) {
+        if (!(message instanceof Execute)) {
+            return false;
+        }
+        Execute m1 = this;
+        Execute m2 = (Execute) message;
+        return MessageUtil.compareMessage(m1.getReceiver(), m2.getReceiver());
+    }
+
+    @Override
+    public String toString() {
+        return String.format("Execute(%s)", receiver.toString());
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/GetSize.java	Mon Apr 20 10:58:35 2015 +0200
@@ -0,0 +1,47 @@
+/*
+ * 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.interop.messages;
+
+import com.oracle.truffle.api.interop.messages.*;
+
+public final class GetSize extends UnaryMessage {
+
+    public static GetSize create(Receiver receiver) {
+        return new GetSize(receiver);
+    }
+
+    public static GetSize create(Message receiver) {
+        return new GetSize(receiver);
+    }
+
+    private GetSize(Object receiver) {
+        super(receiver);
+    }
+
+    @Override
+    public String toString() {
+        return String.format("GetSize(%s)", receiver.toString());
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/HasSize.java	Mon Apr 20 10:58:35 2015 +0200
@@ -0,0 +1,46 @@
+/*
+ * 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.interop.messages;
+
+import com.oracle.truffle.api.interop.messages.*;
+
+public final class HasSize extends UnaryMessage {
+    public static HasSize create(Receiver receiver) {
+        return new HasSize(receiver);
+    }
+
+    public static HasSize create(Message receiver) {
+        return new HasSize(receiver);
+    }
+
+    private HasSize(Object receiver) {
+        super(receiver);
+    }
+
+    @Override
+    public String toString() {
+        return String.format("HasSize(%s)", receiver.toString());
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/IsBoxed.java	Mon Apr 20 10:58:35 2015 +0200
@@ -0,0 +1,46 @@
+/*
+ * 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.interop.messages;
+
+import com.oracle.truffle.api.interop.messages.*;
+
+public final class IsBoxed extends UnaryMessage {
+    public static IsBoxed create(Receiver receiver) {
+        return new IsBoxed(receiver);
+    }
+
+    public static IsBoxed create(Message receiver) {
+        return new IsBoxed(receiver);
+    }
+
+    private IsBoxed(Object receiver) {
+        super(receiver);
+    }
+
+    @Override
+    public String toString() {
+        return String.format("IsBoxed(%s)", receiver.toString());
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/IsExecutable.java	Mon Apr 20 10:58:35 2015 +0200
@@ -0,0 +1,46 @@
+/*
+ * 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.interop.messages;
+
+import com.oracle.truffle.api.interop.messages.*;
+
+public final class IsExecutable extends UnaryMessage {
+    public static IsExecutable create(Receiver receiver) {
+        return new IsExecutable(receiver);
+    }
+
+    public static IsExecutable create(Message receiver) {
+        return new IsExecutable(receiver);
+    }
+
+    private IsExecutable(Object receiver) {
+        super(receiver);
+    }
+
+    @Override
+    public String toString() {
+        return String.format("IsExecutable(%s)", receiver.toString());
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/IsNull.java	Mon Apr 20 10:58:35 2015 +0200
@@ -0,0 +1,46 @@
+/*
+ * 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.interop.messages;
+
+import com.oracle.truffle.api.interop.messages.*;
+
+public final class IsNull extends UnaryMessage {
+    public static IsNull create(Receiver receiver) {
+        return new IsNull(receiver);
+    }
+
+    public static IsNull create(Message receiver) {
+        return new IsNull(receiver);
+    }
+
+    private IsNull(Object receiver) {
+        super(receiver);
+    }
+
+    @Override
+    public String toString() {
+        return String.format("IsNull(%s)", receiver.toString());
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/MessageUtil.java	Mon Apr 20 10:58:35 2015 +0200
@@ -0,0 +1,39 @@
+/*
+ * 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.interop.messages;
+
+import com.oracle.truffle.api.interop.messages.*;
+
+final class MessageUtil {
+
+    static boolean compareMessage(Object o1, Object o2) {
+        if (o1 instanceof Message && o2 instanceof Message) {
+            return ((Message) o1).matchStructure(o2);
+        } else if (o1 instanceof Receiver && o2 instanceof Receiver) {
+            return true;
+        }
+        throw new IllegalStateException();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/Read.java	Mon Apr 20 10:58:35 2015 +0200
@@ -0,0 +1,67 @@
+/*
+ * 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.interop.messages;
+
+import com.oracle.truffle.api.interop.messages.*;
+
+public final class Read implements Message {
+    private final Object receiver;
+    private final Argument id;
+
+    private Read(Object receiver, Argument id) {
+        this.receiver = receiver;
+        this.id = id;
+    }
+
+    public static Read create(Receiver receiver, Argument id) {
+        return new Read(receiver, id);
+    }
+
+    public static Read create(Message receiver, Argument id) {
+        return new Read(receiver, id);
+    }
+
+    public Argument getId() {
+        return id;
+    }
+
+    public Object getReceiver() {
+        return receiver;
+    }
+
+    public boolean matchStructure(Object message) {
+        if (!(message instanceof Read)) {
+            return false;
+        }
+        Read m1 = this;
+        Read m2 = (Read) message;
+        return MessageUtil.compareMessage(m1.getReceiver(), m2.getReceiver()) && MessageUtil.compareMessage(m1.getId(), m2.getId());
+    }
+
+    @Override
+    public String toString() {
+        return String.format("Read(%s, %s)", receiver.toString(), id.toString());
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/Receiver.java	Mon Apr 20 10:58:35 2015 +0200
@@ -0,0 +1,41 @@
+/*
+ * 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.interop.messages;
+
+public final class Receiver {
+
+    private Receiver() {
+
+    }
+
+    public static Receiver create() {
+        return new Receiver();
+    }
+
+    @Override
+    public String toString() {
+        return String.format("Receiver");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/UnaryMessage.java	Mon Apr 20 10:58:35 2015 +0200
@@ -0,0 +1,54 @@
+/*
+ * 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.interop.messages;
+
+import com.oracle.truffle.api.interop.messages.*;
+
+abstract class UnaryMessage implements Message {
+    protected final Object receiver;
+
+    protected UnaryMessage(Object receiver) {
+        this.receiver = receiver;
+    }
+
+    public Object getReceiver() {
+        return receiver;
+    }
+
+    public boolean matchStructure(Object message) {
+        if (message == null) {
+            return false;
+        }
+        if (this.getClass() != message.getClass()) {
+            return false;
+        }
+        UnaryMessage m1 = this;
+        UnaryMessage m2 = (UnaryMessage) message;
+        return MessageUtil.compareMessage(m1.getReceiver(), m2.getReceiver());
+    }
+
+    @Override
+    public abstract String toString();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/Unbox.java	Mon Apr 20 10:58:35 2015 +0200
@@ -0,0 +1,46 @@
+/*
+ * 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.interop.messages;
+
+import com.oracle.truffle.api.interop.messages.*;
+
+public final class Unbox extends UnaryMessage {
+    public static Unbox create(Receiver receiver) {
+        return new Unbox(receiver);
+    }
+
+    public static Unbox create(Message receiver) {
+        return new Unbox(receiver);
+    }
+
+    private Unbox(Object receiver) {
+        super(receiver);
+    }
+
+    @Override
+    public String toString() {
+        return String.format("Unbox(%s)", receiver.toString());
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/Write.java	Mon Apr 20 10:58:35 2015 +0200
@@ -0,0 +1,74 @@
+/*
+ * 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.interop.messages;
+
+import com.oracle.truffle.api.interop.messages.*;
+
+public final class Write implements Message {
+    private final Object receiver;
+    private final Argument id;
+    private final Argument value;
+
+    private Write(Object receiver, Argument id, Argument value) {
+        this.receiver = receiver;
+        this.id = id;
+        this.value = value;
+    }
+
+    public static Write create(Receiver receiver, Argument id, Argument value) {
+        return new Write(receiver, id, value);
+    }
+
+    public static Write create(Message receiver, Argument id, Argument value) {
+        return new Write(receiver, id, value);
+    }
+
+    public Argument getId() {
+        return id;
+    }
+
+    public Object getReceiver() {
+        return receiver;
+    }
+
+    public Argument getValue() {
+        return value;
+    }
+
+    public boolean matchStructure(Object message) {
+        if (!(message instanceof Write)) {
+            return false;
+        }
+        Write m1 = this;
+        Write m2 = (Write) message;
+        return MessageUtil.compareMessage(m1.getReceiver(), m2.getReceiver());
+    }
+
+    @Override
+    public String toString() {
+        return String.format("Write(%s, %s, %s)", receiver.toString(), id.toString(), value.toString());
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/node/ForeignObjectAccessHeadNode.java	Mon Apr 20 10:58:35 2015 +0200
@@ -0,0 +1,56 @@
+/*
+ * 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.interop.node;
+
+import com.oracle.truffle.api.frame.*;
+import com.oracle.truffle.api.interop.*;
+import com.oracle.truffle.api.interop.messages.*;
+
+final class ForeignObjectAccessHeadNode extends ForeignObjectAccessNode {
+
+    @Child private ObjectAccessNode first;
+    private final Message accessTree;
+
+    protected ForeignObjectAccessHeadNode(Message tree) {
+        this.accessTree = tree;
+        this.first = new UnresolvedObjectAccessNode();
+        adoptChildren();
+    }
+
+    protected Message getAccessTree() {
+        return accessTree;
+    }
+
+    protected ObjectAccessNode getFirst() {
+        return first;
+    }
+
+    @Override
+    public Object executeForeign(VirtualFrame frame, TruffleObject receiver, Object... arguments) {
+        return first.executeWith(frame, receiver, arguments);
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/node/ForeignObjectAccessNode.java	Mon Apr 20 10:58:35 2015 +0200
@@ -0,0 +1,41 @@
+/*
+ * 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.interop.node;
+
+import com.oracle.truffle.api.frame.*;
+import com.oracle.truffle.api.interop.*;
+import com.oracle.truffle.api.interop.messages.*;
+import com.oracle.truffle.api.nodes.*;
+
+public abstract class ForeignObjectAccessNode extends Node {
+
+    public static ForeignObjectAccessNode getAccess(Message tree) {
+        return new ForeignObjectAccessHeadNode(tree);
+    }
+
+    public abstract Object executeForeign(VirtualFrame frame, TruffleObject receiver, Object... arguments);
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/node/ObjectAccessNode.java	Mon Apr 20 10:58:35 2015 +0200
@@ -0,0 +1,123 @@
+/*
+ * 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.interop.node;
+
+import com.oracle.truffle.api.*;
+import com.oracle.truffle.api.frame.*;
+import com.oracle.truffle.api.interop.*;
+import com.oracle.truffle.api.interop.InteropPredicate;
+import com.oracle.truffle.api.interop.messages.*;
+import com.oracle.truffle.api.nodes.*;
+import com.oracle.truffle.interop.*;
+
+abstract class ObjectAccessNode extends Node {
+
+    public abstract Object executeWith(VirtualFrame frame, TruffleObject receiver, Object[] arguments);
+
+}
+
+class UnresolvedObjectAccessNode extends ObjectAccessNode {
+
+    private static final int CACHE_SIZE = 8;
+    private int cacheLength = 1;
+
+    @Override
+    public Object executeWith(VirtualFrame frame, TruffleObject receiver, Object[] arguments) {
+        CompilerDirectives.transferToInterpreterAndInvalidate();
+        ForeignObjectAccessHeadNode nthParent = (ForeignObjectAccessHeadNode) NodeUtil.getNthParent(this, cacheLength);
+        ObjectAccessNode first = nthParent.getFirst();
+        if (cacheLength < CACHE_SIZE) {
+            cacheLength++;
+            CachedObjectAccessNode createCachedAccess = createCachedAccess(receiver, nthParent.getAccessTree(), first);
+            return first.replace(createCachedAccess).executeWith(frame, receiver, arguments);
+        } else {
+            return first.replace(createGenericAccess(nthParent.getAccessTree())).executeWith(frame, receiver, arguments);
+        }
+    }
+
+    private static CachedObjectAccessNode createCachedAccess(TruffleObject receiver, Message accessTree, ObjectAccessNode next) {
+        ForeignAccessFactory accessFactory = receiver.getForeignAccessFactory();
+        return new CachedObjectAccessNode(Truffle.getRuntime().createDirectCallNode(accessFactory.getAccess(accessTree)), next, accessFactory.getLanguageCheck());
+    }
+
+    private static GenericObjectAccessNode createGenericAccess(Message access) {
+        return new GenericObjectAccessNode(access);
+    }
+}
+
+class GenericObjectAccessNode extends ObjectAccessNode {
+
+    private final Message access;
+    @Child private IndirectCallNode indirectCallNode;
+
+    public GenericObjectAccessNode(Message access) {
+        this.access = access;
+        indirectCallNode = Truffle.getRuntime().createIndirectCallNode();
+    }
+
+    public GenericObjectAccessNode(GenericObjectAccessNode prev) {
+        this(prev.access);
+    }
+
+    @Override
+    public Object executeWith(VirtualFrame frame, TruffleObject truffleObject, Object[] arguments) {
+        return indirectCallNode.call(frame, truffleObject.getForeignAccessFactory().getAccess(access), ForeignAccessArguments.create(truffleObject, arguments));
+    }
+}
+
+class CachedObjectAccessNode extends ObjectAccessNode {
+    @Child private DirectCallNode callTarget;
+    @Child private ObjectAccessNode next;
+
+    private final InteropPredicate languageCheck;
+
+    protected CachedObjectAccessNode(DirectCallNode callTarget, ObjectAccessNode next, InteropPredicate languageCheck) {
+        this.callTarget = callTarget;
+        this.next = next;
+        this.languageCheck = languageCheck;
+        this.callTarget.forceInlining();
+    }
+
+    protected CachedObjectAccessNode(CachedObjectAccessNode prev) {
+        this(prev.callTarget, prev.next, prev.languageCheck);
+    }
+
+    @Override
+    public Object executeWith(VirtualFrame frame, TruffleObject receiver, Object[] arguments) {
+        return doAccess(frame, receiver, arguments);
+    }
+
+    private Object doAccess(VirtualFrame frame, TruffleObject receiver, Object[] arguments) {
+        if (languageCheck.test(receiver)) {
+            return callTarget.call(frame, ForeignAccessArguments.create(receiver, arguments));
+        } else {
+            return doNext(frame, receiver, arguments);
+        }
+    }
+
+    private Object doNext(VirtualFrame frame, TruffleObject receiver, Object[] arguments) {
+        return next.executeWith(frame, receiver, arguments);
+    }
+}
--- a/mx/suite.py	Fri Apr 17 15:40:26 2015 +0200
+++ b/mx/suite.py	Mon Apr 20 10:58:35 2015 +0200
@@ -1003,6 +1003,15 @@
       "workingSets" : "API,Truffle",
     },
 
+    "com.oracle.truffle.interop" : {
+      "subDir" : "graal",
+      "sourceDirs" : ["src"],
+      "dependencies" : ["com.oracle.truffle.api.interop"],
+      "javaCompliance" : "1.7",
+      "workingSets" : "Truffle",
+      "checkstyle" : "com.oracle.truffle.api",
+    },
+
     "com.oracle.truffle.api.object" : {
       "subDir" : "graal",
       "sourceDirs" : ["src"],