Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.api.vm/src/com/oracle/truffle/api/vm/SymbolInvokerImpl.java @ 22131:626862cfa58d
removed unnecessary exception clause
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 03 Sep 2015 17:56:41 +0200 |
parents | 0589cc5cab30 |
children | e70b20f4bb00 |
rev | line source |
---|---|
21770
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
1 /* |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
4 * |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. Oracle designates this |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
8 * particular file as subject to the "Classpath" exception as provided |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
9 * by Oracle in the LICENSE file that accompanied this code. |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
10 * |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
15 * accompanied this code). |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
16 * |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU General Public License version |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
20 * |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
22 * or visit www.oracle.com if you need additional information or have any |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
23 * questions. |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
24 */ |
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.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22107
diff
changeset
|
25 package com.oracle.truffle.api.vm; |
21770
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
26 |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
27 import com.oracle.truffle.api.*; |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
28 import com.oracle.truffle.api.frame.*; |
22131
626862cfa58d
removed unnecessary exception clause
Doug Simon <doug.simon@oracle.com>
parents:
22129
diff
changeset
|
29 import com.oracle.truffle.api.interop.*; |
21770
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
30 import com.oracle.truffle.api.nodes.*; |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
31 |
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.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22107
diff
changeset
|
32 final class SymbolInvokerImpl { |
22096
1e78795e7e6a
Allow to specify globalSymbols when defining TruffleVM
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22086
diff
changeset
|
33 @SuppressWarnings({"unchecked", "rawtypes"}) |
22131
626862cfa58d
removed unnecessary exception clause
Doug Simon <doug.simon@oracle.com>
parents:
22129
diff
changeset
|
34 static CallTarget createCallTarget(TruffleLanguage<?> lang, Object symbol, Object... arr) { |
22096
1e78795e7e6a
Allow to specify globalSymbols when defining TruffleVM
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22086
diff
changeset
|
35 Class<? extends TruffleLanguage<?>> type; |
1e78795e7e6a
Allow to specify globalSymbols when defining TruffleVM
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22086
diff
changeset
|
36 if (lang != null) { |
1e78795e7e6a
Allow to specify globalSymbols when defining TruffleVM
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22086
diff
changeset
|
37 type = (Class) lang.getClass(); |
1e78795e7e6a
Allow to specify globalSymbols when defining TruffleVM
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22086
diff
changeset
|
38 } else { |
1e78795e7e6a
Allow to specify globalSymbols when defining TruffleVM
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22086
diff
changeset
|
39 type = (Class) TruffleLanguage.class; |
1e78795e7e6a
Allow to specify globalSymbols when defining TruffleVM
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22086
diff
changeset
|
40 } |
22084
77562c7bc5a6
Caching the CallTarget in Symbol, so it may get hot one day
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22083
diff
changeset
|
41 RootNode symbolNode; |
77562c7bc5a6
Caching the CallTarget in Symbol, so it may get hot one day
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22083
diff
changeset
|
42 if ((symbol instanceof String) || (symbol instanceof Number) || (symbol instanceof Boolean) || (symbol instanceof Character)) { |
77562c7bc5a6
Caching the CallTarget in Symbol, so it may get hot one day
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22083
diff
changeset
|
43 symbolNode = new ConstantRootNode(type, symbol); |
77562c7bc5a6
Caching the CallTarget in Symbol, so it may get hot one day
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22083
diff
changeset
|
44 } else { |
77562c7bc5a6
Caching the CallTarget in Symbol, so it may get hot one day
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22083
diff
changeset
|
45 Node executeMain = Message.createExecute(arr.length).createNode(); |
22086
93bfc9602271
Recreate the CallTarget when number of arguments to the createExecute message changes
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22084
diff
changeset
|
46 symbolNode = new TemporaryRoot(type, executeMain, (TruffleObject) symbol, arr.length); |
21770
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
47 } |
22084
77562c7bc5a6
Caching the CallTarget in Symbol, so it may get hot one day
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22083
diff
changeset
|
48 return Truffle.getRuntime().createCallTarget(symbolNode); |
77562c7bc5a6
Caching the CallTarget in Symbol, so it may get hot one day
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22083
diff
changeset
|
49 } |
77562c7bc5a6
Caching the CallTarget in Symbol, so it may get hot one day
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22083
diff
changeset
|
50 |
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.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22107
diff
changeset
|
51 private static final class ConstantRootNode extends RootNode { |
22084
77562c7bc5a6
Caching the CallTarget in Symbol, so it may get hot one day
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22083
diff
changeset
|
52 |
77562c7bc5a6
Caching the CallTarget in Symbol, so it may get hot one day
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22083
diff
changeset
|
53 private final Object value; |
77562c7bc5a6
Caching the CallTarget in Symbol, so it may get hot one day
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22083
diff
changeset
|
54 |
77562c7bc5a6
Caching the CallTarget in Symbol, so it may get hot one day
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22083
diff
changeset
|
55 public ConstantRootNode(Class<? extends TruffleLanguage<?>> lang, Object value) { |
77562c7bc5a6
Caching the CallTarget in Symbol, so it may get hot one day
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22083
diff
changeset
|
56 super(lang, null, null); |
77562c7bc5a6
Caching the CallTarget in Symbol, so it may get hot one day
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22083
diff
changeset
|
57 this.value = value; |
21770
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
58 } |
22084
77562c7bc5a6
Caching the CallTarget in Symbol, so it may get hot one day
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22083
diff
changeset
|
59 |
77562c7bc5a6
Caching the CallTarget in Symbol, so it may get hot one day
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22083
diff
changeset
|
60 @Override |
77562c7bc5a6
Caching the CallTarget in Symbol, so it may get hot one day
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22083
diff
changeset
|
61 public Object execute(VirtualFrame vf) { |
77562c7bc5a6
Caching the CallTarget in Symbol, so it may get hot one day
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22083
diff
changeset
|
62 return value; |
77562c7bc5a6
Caching the CallTarget in Symbol, so it may get hot one day
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22083
diff
changeset
|
63 } |
22083
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
64 } |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
65 |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
66 private static class TemporaryRoot extends RootNode { |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
67 @Child private Node foreignAccess; |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
68 @Child private ConvertNode convert; |
22086
93bfc9602271
Recreate the CallTarget when number of arguments to the createExecute message changes
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22084
diff
changeset
|
69 private final int argumentLength; |
22083
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
70 private final TruffleObject function; |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
71 |
22086
93bfc9602271
Recreate the CallTarget when number of arguments to the createExecute message changes
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22084
diff
changeset
|
72 public TemporaryRoot(Class<? extends TruffleLanguage<?>> lang, Node foreignAccess, TruffleObject function, int argumentLength) { |
22083
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
73 super(lang, null, null); |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
74 this.foreignAccess = foreignAccess; |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
75 this.convert = new ConvertNode(); |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
76 this.function = function; |
22086
93bfc9602271
Recreate the CallTarget when number of arguments to the createExecute message changes
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22084
diff
changeset
|
77 this.argumentLength = argumentLength; |
22083
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
78 } |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
79 |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
80 @Override |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
81 public Object execute(VirtualFrame frame) { |
22086
93bfc9602271
Recreate the CallTarget when number of arguments to the createExecute message changes
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22084
diff
changeset
|
82 final Object[] args = frame.getArguments(); |
93bfc9602271
Recreate the CallTarget when number of arguments to the createExecute message changes
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22084
diff
changeset
|
83 if (args.length != argumentLength) { |
93bfc9602271
Recreate the CallTarget when number of arguments to the createExecute message changes
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22084
diff
changeset
|
84 throw new ArgumentsMishmashException(); |
93bfc9602271
Recreate the CallTarget when number of arguments to the createExecute message changes
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22084
diff
changeset
|
85 } |
93bfc9602271
Recreate the CallTarget when number of arguments to the createExecute message changes
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22084
diff
changeset
|
86 Object tmp = ForeignAccess.execute(foreignAccess, frame, function, args); |
22083
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
87 return convert.convert(frame, tmp); |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
88 } |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
89 } |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
90 |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
91 private static final class ConvertNode extends Node { |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
92 @Child private Node isNull; |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
93 @Child private Node isBoxed; |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
94 @Child private Node unbox; |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
95 |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
96 public ConvertNode() { |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
97 this.isNull = Message.IS_NULL.createNode(); |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
98 this.isBoxed = Message.IS_BOXED.createNode(); |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
99 this.unbox = Message.UNBOX.createNode(); |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
100 } |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
101 |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
102 Object convert(VirtualFrame frame, Object obj) { |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
103 if (obj instanceof TruffleObject) { |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
104 return convert(frame, (TruffleObject) obj); |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
105 } else { |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
106 return obj; |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
107 } |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
108 } |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
109 |
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
110 private Object convert(VirtualFrame frame, TruffleObject obj) { |
21770
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
111 Object isBoxedResult; |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
112 try { |
22083
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
113 isBoxedResult = ForeignAccess.execute(isBoxed, frame, obj); |
21770
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
114 } catch (IllegalArgumentException ex) { |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
115 isBoxedResult = false; |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
116 } |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
117 if (Boolean.TRUE.equals(isBoxedResult)) { |
22083
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
118 return ForeignAccess.execute(unbox, frame, obj); |
21770
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
119 } else { |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
120 try { |
22083
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
121 Object isNullResult = ForeignAccess.execute(isNull, frame, obj); |
21770
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
122 if (Boolean.TRUE.equals(isNullResult)) { |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
123 return null; |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
124 } |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
125 } catch (IllegalArgumentException ex) { |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
126 // fallthrough |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
127 } |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
128 } |
22083
245dc37053f3
Using just a one RootNode per call and otherwise doing all the conversions in its children. Is it faster?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22066
diff
changeset
|
129 return obj; |
21770
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
130 } |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
131 } |
c76742cc2c6f
Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
132 } |