Mercurial > hg > graal-jvmci-8
annotate graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/SymbolInvokerImpl.java @ 21689:ed234a3178af
Behavior of null-like values is now part of the TCK
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Wed, 03 Jun 2015 10:17:19 +0200 |
parents | 5fa7935c5de3 |
children | 2f9e4d984d16 |
rev | line source |
---|---|
21468
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
1 /* |
21686
5fa7935c5de3
Truffle/Instrumentation: fix the small tool demonstration in SL
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21578
diff
changeset
|
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
21468
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
4 * |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. Oracle designates this |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
8 * particular file as subject to the "Classpath" exception as provided |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
9 * by Oracle in the LICENSE file that accompanied this code. |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
10 * |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
15 * accompanied this code). |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
16 * |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU General Public License version |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
20 * |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
22 * or visit www.oracle.com if you need additional information or have any |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
23 * questions. |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
24 */ |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
25 package com.oracle.truffle.interop; |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
26 |
21554
b1530a6cce8c
renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21468
diff
changeset
|
27 import java.io.*; |
b1530a6cce8c
renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21468
diff
changeset
|
28 |
b1530a6cce8c
renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21468
diff
changeset
|
29 import com.oracle.truffle.api.*; |
b1530a6cce8c
renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21468
diff
changeset
|
30 import com.oracle.truffle.api.frame.*; |
b1530a6cce8c
renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21468
diff
changeset
|
31 import com.oracle.truffle.api.impl.*; |
b1530a6cce8c
renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21468
diff
changeset
|
32 import com.oracle.truffle.api.interop.*; |
21689
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
33 import com.oracle.truffle.api.interop.exception.UnsupportedMessageException; |
21554
b1530a6cce8c
renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21468
diff
changeset
|
34 import com.oracle.truffle.api.nodes.*; |
b1530a6cce8c
renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21468
diff
changeset
|
35 import com.oracle.truffle.interop.messages.*; |
b1530a6cce8c
renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21468
diff
changeset
|
36 import com.oracle.truffle.interop.node.*; |
21468
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
37 |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
38 public final class SymbolInvokerImpl extends SymbolInvoker { |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
39 static final FrameDescriptor UNUSED_FRAMEDESCRIPTOR = new FrameDescriptor(); |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
40 |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
41 @Override |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
42 protected Object invoke(Object symbol, Object... arr) throws IOException { |
21689
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
43 ForeignObjectAccessNode callMain = ForeignObjectAccessNode.getAccess(Execute.create(Receiver.create(), arr.length)); |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
44 CallTarget callMainTarget = Truffle.getRuntime().createCallTarget(new TemporaryRoot(callMain, (TruffleObject) symbol, arr)); |
21468
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
45 VirtualFrame frame = Truffle.getRuntime().createVirtualFrame(arr, UNUSED_FRAMEDESCRIPTOR); |
21689
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
46 Object ret = callMainTarget.call(frame); |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
47 if (ret instanceof TruffleObject) { |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
48 TruffleObject tret = (TruffleObject) ret; |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
49 Object isBoxedResult; |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
50 try { |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
51 ForeignObjectAccessNode isBoxed = ForeignObjectAccessNode.getAccess(IsBoxed.create(Receiver.create())); |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
52 CallTarget isBoxedTarget = Truffle.getRuntime().createCallTarget(new TemporaryRoot(isBoxed, tret)); |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
53 isBoxedResult = isBoxedTarget.call(frame); |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
54 } catch (UnsupportedMessageException ex) { |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
55 isBoxedResult = false; |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
56 } |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
57 if (Boolean.TRUE.equals(isBoxedResult)) { |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
58 ForeignObjectAccessNode unbox = ForeignObjectAccessNode.getAccess(Unbox.create(Receiver.create())); |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
59 CallTarget unboxTarget = Truffle.getRuntime().createCallTarget(new TemporaryRoot(unbox, tret)); |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
60 Object unboxResult = unboxTarget.call(frame); |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
61 return unboxResult; |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
62 } else { |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
63 try { |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
64 ForeignObjectAccessNode isNull = ForeignObjectAccessNode.getAccess(IsNull.create(Receiver.create())); |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
65 CallTarget isNullTarget = Truffle.getRuntime().createCallTarget(new TemporaryRoot(isNull, tret)); |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
66 Object isNullResult = isNullTarget.call(frame); |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
67 if (Boolean.TRUE.equals(isNullResult)) { |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
68 return null; |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
69 } |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
70 } catch (UnsupportedMessageException ex) { |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
71 // fallthrough |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
72 } |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
73 } |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
74 } |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21686
diff
changeset
|
75 return ret; |
21468
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
76 } |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
77 |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
78 private static class TemporaryRoot extends RootNode { |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
79 @Child private ForeignObjectAccessNode foreignAccess; |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
80 private final TruffleObject function; |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
81 private final Object[] args; |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
82 |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
83 public TemporaryRoot(ForeignObjectAccessNode foreignAccess, TruffleObject function, Object... args) { |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
84 this.foreignAccess = foreignAccess; |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
85 this.function = function; |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
86 this.args = args; |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
87 } |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
88 |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
89 @Override |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
90 public Object execute(VirtualFrame frame) { |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
91 return foreignAccess.executeForeign(frame, function, args); |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
92 } |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
93 } |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
94 |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
95 } |