annotate truffle/com.oracle.truffle.tck/src/com/oracle/truffle/tck/TruffleTCK.java @ 22157:dc83cc1f94f2

Using fully qualified imports
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 16 Sep 2015 11:33:22 +0200
parents 50056a161d7f
children dcb70d90c11d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21938
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
1 /*
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
4 *
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation. Oracle designates this
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
8 * particular file as subject to the "Classpath" exception as provided
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
9 * by Oracle in the LICENSE file that accompanied this code.
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
10 *
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
11 * This code is distributed in the hope that it will be useful, but WITHOUT
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
14 * version 2 for more details (a copy is included in the LICENSE file that
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
15 * accompanied this code).
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
16 *
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License version
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
18 * 2 along with this work; if not, write to the Free Software Foundation,
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
20 *
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
22 * or visit www.oracle.com if you need additional information or have any
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
23 * questions.
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
24 */
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
25 package com.oracle.truffle.tck;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
26
22135
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
27 import com.oracle.truffle.api.interop.TruffleObject;
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
28 import com.oracle.truffle.api.interop.java.JavaInterop;
22104
cf19259edf87 TruffleVM.eval and Source.withMimeType
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22076
diff changeset
29 import com.oracle.truffle.api.source.Source;
21938
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
30 import com.oracle.truffle.api.vm.TruffleVM;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
31 import java.io.IOException;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
32 import java.util.Random;
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22156
diff changeset
33 import static org.junit.Assert.assertEquals;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22156
diff changeset
34 import static org.junit.Assert.assertNotNull;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22156
diff changeset
35 import static org.junit.Assert.assertNotSame;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22156
diff changeset
36 import static org.junit.Assert.assertNull;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22156
diff changeset
37 import static org.junit.Assert.assertSame;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22156
diff changeset
38 import static org.junit.Assert.fail;
21938
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
39 import org.junit.Test;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
40
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
41 /**
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
42 * A collection of tests that can certify language implementation to be compliant with most recent
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
43 * requirements of the Truffle infrastructure and tooling. Subclass, implement abstract methods and
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
44 * include in your test suite.
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
45 */
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
46 public abstract class TruffleTCK {
22135
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
47 private static final Random RANDOM = new Random();
21938
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
48 private TruffleVM tckVM;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
49
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
50 protected TruffleTCK() {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
51 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
52
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
53 /**
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
54 * This methods is called before first test is executed. It's purpose is to set a TruffleVM with
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
55 * your language up, so it is ready for testing.
22104
cf19259edf87 TruffleVM.eval and Source.withMimeType
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22076
diff changeset
56 * {@link TruffleVM#eval(com.oracle.truffle.api.source.Source) Execute} any scripts you need,
cf19259edf87 TruffleVM.eval and Source.withMimeType
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22076
diff changeset
57 * and prepare global symbols with proper names. The symbols will then be looked up by the
21938
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
58 * infrastructure (using the names provided by you from methods like {@link #plusInt()}) and
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
59 * used for internal testing.
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
60 *
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
61 * @return initialized Truffle virtual machine
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
62 * @throws java.lang.Exception thrown when the VM preparation fails
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
63 */
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
64 protected abstract TruffleVM prepareVM() throws Exception;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
65
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
66 /**
22135
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
67 * MIME type associated with your language. The MIME type will be passed to
22104
cf19259edf87 TruffleVM.eval and Source.withMimeType
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22076
diff changeset
68 * {@link TruffleVM#eval(com.oracle.truffle.api.source.Source)} method of the
cf19259edf87 TruffleVM.eval and Source.withMimeType
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22076
diff changeset
69 * {@link #prepareVM() created TruffleVM}.
21938
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
70 *
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
71 * @return mime type of the tested language
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
72 */
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
73 protected abstract String mimeType();
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
74
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
75 /**
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
76 * Name of function which will return value 42 as a number. The return value of the method
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
77 * should be instance of {@link Number} and its {@link Number#intValue()} should return
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
78 * <code>42</code>.
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
79 *
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
80 * @return name of globally exported symbol
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
81 */
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
82 protected abstract String fourtyTwo();
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
83
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
84 /**
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
85 * Name of a function that returns <code>null</code>. Truffle languages are encouraged to have
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
86 * their own type representing <code>null</code>, but when such value is returned from
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
87 * {@link TruffleVM#eval}, it needs to be converted to real Java <code>null</code> by sending a
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
88 * foreign access <em>isNull</em> message. There is a test to verify it is really true.
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
89 *
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
90 * @return name of globally exported symbol
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
91 */
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
92 protected abstract String returnsNull();
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
93
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
94 /**
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
95 * Name of function to add two integer values together. The symbol will be invoked with two
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
96 * parameters of type {@link Integer} and expects result of type {@link Number} which's
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
97 * {@link Number#intValue()} is equivalent of <code>param1 + param2</code>.
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
98 *
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
99 * @return name of globally exported symbol
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
100 */
22138
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
101 protected String plusInt() {
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
102 throw new UnsupportedOperationException("Override plus(Class,Class) method!");
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
103 }
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
104
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
105 /**
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
106 * Name of function to add two numbers together. The symbol will be invoked with two parameters
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
107 * of <code>type1</code> and <code>type2</code> and expects result of type {@link Number}
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
108 * which's {@link Number#intValue()} is equivalent of <code>param1 + param2</code>. As some
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
109 * languages may have different operations for different types of numbers, the actual types are
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
110 * passed to the method and the implementation can decide to return different symbol based on
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
111 * the parameters.
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
112 *
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
113 * @param type1 one of byte, short, int, long, float, double class
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
114 * @param type2 one of byte, short, int, long, float, double class
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
115 * @return name of globally exported symbol
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
116 */
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
117 protected String plus(Class<?> type1, Class<?> type2) {
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
118 return plusInt();
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
119 }
21938
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
120
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
121 /**
21960
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
122 * Name of a function in your language to perform a callback to foreign function. Your function
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
123 * should prepare two numbers (18 and 32) and apply them to the function passed in as an
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
124 * argument of your function. It should then add 10 to the returned value and return the result
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
125 * back to its caller.
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
126 *
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
127 * @return name of globally exported symbol
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
128 */
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
129 protected abstract String applyNumbers();
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
130
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
131 /**
22140
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
132 * Name of identity function. The identity function accepts one argument and returns it. The
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
133 * argument should go through without any modification, e.g. the input should result in
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
134 * identical output.
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
135 *
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
136 * @return name of globally exported symbol
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
137 */
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
138 protected String identity() {
22156
50056a161d7f Replacing time out associated warnings by UnsupportedOperationException. Meaning of exception is probably more straightforward than a soft hint attempted before. Shouldn't influence the way things are build, if tests are skipped.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22142
diff changeset
139 throw new UnsupportedOperationException("identity() method not implemented");
22140
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
140 }
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
141
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
142 /**
22046
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
143 * Name of a function that counts number of its invocations in current {@link TruffleVM}
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
144 * context. Your function should somehow keep a counter to remember number of its invocations
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
145 * and always increment it. The first invocation should return <code>1</code>, the second
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
146 * <code>2</code> and so on. The returned values are expected to be instances of {@link Number}.
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
147 * <p>
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
148 * The function will be used to test that two instances of your language can co-exist next to
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
149 * each other. Without being mutually influenced.
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
150 *
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
151 * @return name of globally expected symbol
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
152 */
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
153 protected abstract String countInvocations();
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
154
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
155 /**
21938
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
156 * Return a code snippet that is invalid in your language. Its
22104
cf19259edf87 TruffleVM.eval and Source.withMimeType
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22076
diff changeset
157 * {@link TruffleVM#eval(com.oracle.truffle.api.source.Source) evaluation} should fail and yield
21938
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
158 * an exception.
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
159 *
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
160 * @return code snippet invalid in the tested language
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
161 */
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
162 protected abstract String invalidCode();
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
163
22135
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
164 /**
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
165 * Name of a function that returns a compound object with members representing certain
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
166 * operations. In the JavaScript the object should look like:
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
167 *
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
168 * <pre>
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
169 * <b>var</b> obj = {
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
170 * 'fourtyTwo': function {@link #fourtyTwo()},
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
171 * 'plus': function {@link #plusInt()},
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
172 * 'returnsNull': function {@link #returnsNull()},
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
173 * 'returnsThis': function() { return obj; }
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
174 * };
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
175 * <b>return</b> obj;
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
176 * </pre>
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
177 *
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
178 * The returned object shall have three functions that will be obtained and used exactly as
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
179 * described in their Javadoc - e.g. {@link #fourtyTwo()}, {@link #plusInt()} and
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
180 * {@link #returnsNull()}. In addition to that there should be one more function
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
181 * <b>returnsThis</b> that will return the object itself again.
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
182 *
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
183 * @return name of a function that returns such compound object
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
184 */
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
185 protected String compoundObject() {
22156
50056a161d7f Replacing time out associated warnings by UnsupportedOperationException. Meaning of exception is probably more straightforward than a soft hint attempted before. Shouldn't influence the way things are build, if tests are skipped.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22142
diff changeset
186 throw new UnsupportedOperationException("compoundObject() method not implemented");
22135
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
187 }
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
188
21938
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
189 private TruffleVM vm() throws Exception {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
190 if (tckVM == null) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
191 tckVM = prepareVM();
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
192 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
193 return tckVM;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
194 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
195
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
196 //
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
197 // The tests
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
198 //
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
199
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
200 @Test
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
201 public void testFortyTwo() throws Exception {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
202 TruffleVM.Symbol fourtyTwo = findGlobalSymbol(fourtyTwo());
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
203
22121
d045a505c2b3 Asynchronous TruffleVM can be created by providing own Executor when configuring the TruffleVM.Builder
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
204 Object res = fourtyTwo.invoke(null).get();
21938
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
205
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
206 assert res instanceof Number : "should yield a number, but was: " + res;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
207
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
208 Number n = (Number) res;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
209
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
210 assert 42 == n.intValue() : "The value is 42 = " + n.intValue();
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
211 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
212
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
213 @Test
22135
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
214 public void testFortyTwoWithCompoundObject() throws Exception {
22156
50056a161d7f Replacing time out associated warnings by UnsupportedOperationException. Meaning of exception is probably more straightforward than a soft hint attempted before. Shouldn't influence the way things are build, if tests are skipped.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22142
diff changeset
215 CompoundObject obj = findCompoundSymbol();
22135
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
216 if (obj == null) {
21938
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
217 return;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
218 }
22135
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
219 Number res = obj.fourtyTwo();
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
220 assertEquals("Should be 42", 42, res.intValue());
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
221 }
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
222
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
223 @Test
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
224 public void testNull() throws Exception {
21938
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
225 TruffleVM.Symbol retNull = findGlobalSymbol(returnsNull());
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
226
22121
d045a505c2b3 Asynchronous TruffleVM can be created by providing own Executor when configuring the TruffleVM.Builder
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
227 Object res = retNull.invoke(null).get();
21938
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
228
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
229 assertNull("Should yield real Java null", res);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
230 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
231
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
232 @Test
22135
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
233 public void testNullInCompoundObject() throws Exception {
22156
50056a161d7f Replacing time out associated warnings by UnsupportedOperationException. Meaning of exception is probably more straightforward than a soft hint attempted before. Shouldn't influence the way things are build, if tests are skipped.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22142
diff changeset
234 CompoundObject obj = findCompoundSymbol();
22135
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
235 if (obj == null) {
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
236 return;
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
237 }
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
238 Object res = obj.returnsNull();
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
239 assertNull("Should yield real Java null", res);
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
240 }
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
241
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
242 @Test
21938
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
243 public void testPlusWithInts() throws Exception {
22135
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
244 int a = RANDOM.nextInt(100);
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
245 int b = RANDOM.nextInt(100);
21938
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
246
22138
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
247 TruffleVM.Symbol plus = findGlobalSymbol(plus(int.class, int.class));
21938
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
248
22135
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
249 Number n = plus.invoke(null, a, b).as(Number.class);
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
250 assert a + b == n.intValue() : "The value is correct: (" + a + " + " + b + ") = " + n.intValue();
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
251 }
21938
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
252
22135
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
253 @Test
22138
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
254 public void testPlusWithBytes() throws Exception {
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
255 int a = RANDOM.nextInt(100);
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
256 int b = RANDOM.nextInt(100);
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
257
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
258 TruffleVM.Symbol plus = findGlobalSymbol(plus(byte.class, byte.class));
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
259
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
260 Number n = plus.invoke(null, (byte) a, (byte) b).as(Number.class);
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
261 assert a + b == n.intValue() : "The value is correct: (" + a + " + " + b + ") = " + n.intValue();
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
262 }
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
263
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
264 @Test
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
265 public void testPlusWithShort() throws Exception {
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
266 int a = RANDOM.nextInt(100);
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
267 int b = RANDOM.nextInt(100);
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
268
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
269 TruffleVM.Symbol plus = findGlobalSymbol(plus(short.class, short.class));
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
270
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
271 Number n = plus.invoke(null, (short) a, (short) b).as(Number.class);
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
272 assert a + b == n.intValue() : "The value is correct: (" + a + " + " + b + ") = " + n.intValue();
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
273 }
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
274
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
275 @Test
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
276 public void testPlusWithLong() throws Exception {
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
277 long a = RANDOM.nextInt(100);
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
278 long b = RANDOM.nextInt(100);
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
279
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
280 TruffleVM.Symbol plus = findGlobalSymbol(plus(long.class, long.class));
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
281
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
282 Number n = plus.invoke(null, a, b).as(Number.class);
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
283 assert a + b == n.longValue() : "The value is correct: (" + a + " + " + b + ") = " + n.longValue();
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
284 }
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
285
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
286 @Test
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
287 public void testPlusWithFloat() throws Exception {
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
288 float a = RANDOM.nextFloat();
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
289 float b = RANDOM.nextFloat();
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
290
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
291 TruffleVM.Symbol plus = findGlobalSymbol(plus(float.class, float.class));
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
292
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
293 Number n = plus.invoke(null, a, b).as(Number.class);
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
294 assertEquals("Correct value computed", a + b, n.floatValue(), 0.01f);
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
295 }
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
296
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
297 @Test
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
298 public void testPlusWithDouble() throws Exception {
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
299 double a = RANDOM.nextDouble();
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
300 double b = RANDOM.nextDouble();
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
301
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
302 TruffleVM.Symbol plus = findGlobalSymbol(plus(float.class, float.class));
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
303
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
304 Number n = plus.invoke(null, a, b).as(Number.class);
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
305 assertEquals("Correct value computed", a + b, n.doubleValue(), 0.01);
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
306 }
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
307
a583d7ffd285 Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22135
diff changeset
308 @Test
22135
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
309 public void testPlusWithIntsOnCompoundObject() throws Exception {
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
310 int a = RANDOM.nextInt(100);
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
311 int b = RANDOM.nextInt(100);
21938
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
312
22156
50056a161d7f Replacing time out associated warnings by UnsupportedOperationException. Meaning of exception is probably more straightforward than a soft hint attempted before. Shouldn't influence the way things are build, if tests are skipped.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22142
diff changeset
313 CompoundObject obj = findCompoundSymbol();
22135
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
314 if (obj == null) {
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
315 return;
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
316 }
21938
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
317
22135
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
318 Number n = obj.plus(a, b);
21938
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
319 assert a + b == n.intValue() : "The value is correct: (" + a + " + " + b + ") = " + n.intValue();
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
320 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
321
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
322 @Test(expected = IOException.class)
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
323 public void testInvalidTestMethod() throws Exception {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
324 String mime = mimeType();
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
325 String code = invalidCode();
22121
d045a505c2b3 Asynchronous TruffleVM can be created by providing own Executor when configuring the TruffleVM.Builder
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
326 Object ret = vm().eval(Source.fromText(code, "Invalid code").withMimeType(mime)).get();
21938
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
327 fail("Should yield IOException, but returned " + ret);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
328 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
329
21960
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
330 @Test
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
331 public void testMaxOrMinValue() throws Exception {
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
332 TruffleVM.Symbol apply = findGlobalSymbol(applyNumbers());
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
333
22135
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
334 TruffleObject fn = JavaInterop.asTruffleFunction(LongBinaryOperation.class, new MaxMinObject(true));
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
335 Object res = apply.invoke(null, fn).get();
21960
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
336
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
337 assert res instanceof Number : "result should be a number: " + res;
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
338
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
339 Number n = (Number) res;
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
340
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
341 assert 42 == n.intValue() : "32 > 18 and plus 10";
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
342 }
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
343
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
344 @Test
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
345 public void testMaxOrMinValue2() throws Exception {
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
346 TruffleVM.Symbol apply = findGlobalSymbol(applyNumbers());
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
347
22135
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
348 TruffleObject fn = JavaInterop.asTruffleFunction(LongBinaryOperation.class, new MaxMinObject(false));
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
349 final TruffleVM.Symbol result = apply.invoke(null, fn);
21960
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
350
22135
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
351 try {
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
352 String res = result.as(String.class);
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
353 fail("Cannot be converted to String: " + res);
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
354 } catch (ClassCastException ex) {
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
355 // correct
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
356 }
21960
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
357
22135
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
358 Number n = result.as(Number.class);
21960
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
359 assert 28 == n.intValue() : "18 < 32 and plus 10";
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
360 }
a88981c5ce8b Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
361
22046
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
362 @Test
22139
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
363 public void testPrimitiveReturnTypeByte() throws Exception {
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
364 TruffleVM.Symbol apply = findGlobalSymbol(applyNumbers());
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
365
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
366 byte value = (byte) RANDOM.nextInt(100);
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
367
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
368 TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value));
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
369 Number n = apply.invoke(null, fn).as(Number.class);
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
370 assertEquals("The same value returned", value + 10, n.byteValue());
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
371 }
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
372
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
373 @Test
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
374 public void testPrimitiveReturnTypeShort() throws Exception {
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
375 TruffleVM.Symbol apply = findGlobalSymbol(applyNumbers());
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
376
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
377 short value = (short) RANDOM.nextInt(100);
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
378
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
379 TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value));
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
380 Number n = apply.invoke(null, fn).as(Number.class);
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
381 assertEquals("The same value returned", value + 10, n.shortValue());
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
382 }
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
383
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
384 @Test
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
385 public void testPrimitiveReturnTypeInt() throws Exception {
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
386 TruffleVM.Symbol apply = findGlobalSymbol(applyNumbers());
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
387
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
388 int value = RANDOM.nextInt(100);
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
389
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
390 TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value));
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
391 Number n = apply.invoke(null, fn).as(Number.class);
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
392 assertEquals("The same value returned", value + 10, n.intValue());
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
393 }
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
394
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
395 @Test
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
396 public void testPrimitiveReturnTypeLong() throws Exception {
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
397 TruffleVM.Symbol apply = findGlobalSymbol(applyNumbers());
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
398
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
399 long value = RANDOM.nextInt(1000);
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
400
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
401 TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value));
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
402 Number n = apply.invoke(null, fn).as(Number.class);
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
403 assertEquals("The same value returned", value + 10, n.longValue());
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
404 }
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
405
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
406 @Test
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
407 public void testPrimitiveReturnTypeFloat() throws Exception {
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
408 TruffleVM.Symbol apply = findGlobalSymbol(applyNumbers());
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
409
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
410 float value = RANDOM.nextInt(1000) + RANDOM.nextFloat();
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
411
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
412 TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value));
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
413 Number n = apply.invoke(null, fn).as(Number.class);
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
414 assertEquals("The same value returned", value + 10, n.floatValue(), 0.01);
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
415 }
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
416
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
417 @Test
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
418 public void testPrimitiveReturnTypeDouble() throws Exception {
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
419 TruffleVM.Symbol apply = findGlobalSymbol(applyNumbers());
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
420
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
421 double value = RANDOM.nextInt(1000) + RANDOM.nextDouble();
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
422
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
423 TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value));
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
424 Number n = apply.invoke(null, fn).as(Number.class);
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
425 assertEquals("The same value returned", value + 10, n.doubleValue(), 0.01);
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
426 }
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
427
597953a8e6f0 Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22138
diff changeset
428 @Test
22140
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
429 public void testPrimitiveidentityByte() throws Exception {
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
430 String id = identity();
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
431 if (id == null) {
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
432 return;
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
433 }
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
434 TruffleVM.Symbol apply = findGlobalSymbol(id);
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
435
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
436 byte value = (byte) RANDOM.nextInt(100);
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
437
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
438 Number n = (Number) apply.invoke(null, value).get();
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
439 assertEquals("The same value returned", value, n.byteValue());
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
440 }
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
441
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
442 @Test
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
443 public void testPrimitiveidentityShort() throws Exception {
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
444 String id = identity();
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
445 if (id == null) {
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
446 return;
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
447 }
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
448 TruffleVM.Symbol apply = findGlobalSymbol(id);
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
449
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
450 short value = (short) RANDOM.nextInt(100);
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
451 Number n = (Number) apply.invoke(null, value).get();
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
452 assertEquals("The same value returned", value, n.shortValue());
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
453 }
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
454
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
455 @Test
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
456 public void testPrimitiveidentityInt() throws Exception {
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
457 String id = identity();
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
458 if (id == null) {
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
459 return;
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
460 }
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
461 TruffleVM.Symbol apply = findGlobalSymbol(id);
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
462
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
463 int value = RANDOM.nextInt(100);
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
464
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
465 Number n = (Number) apply.invoke(null, value).get();
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
466 assertEquals("The same value returned", value, n.intValue());
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
467 }
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
468
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
469 @Test
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
470 public void testPrimitiveidentityLong() throws Exception {
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
471 String id = identity();
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
472 if (id == null) {
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
473 return;
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
474 }
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
475 TruffleVM.Symbol apply = findGlobalSymbol(id);
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
476
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
477 long value = RANDOM.nextInt(1000);
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
478
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
479 Number n = (Number) apply.invoke(null, value).get();
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
480 assertEquals("The same value returned", value, n.longValue());
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
481 }
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
482
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
483 @Test
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
484 public void testPrimitiveidentityFloat() throws Exception {
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
485 String id = identity();
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
486 if (id == null) {
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
487 return;
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
488 }
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
489 TruffleVM.Symbol apply = findGlobalSymbol(id);
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
490
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
491 float value = RANDOM.nextInt(1000) + RANDOM.nextFloat();
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
492
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
493 Number n = (Number) apply.invoke(null, value).get();
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
494 assertEquals("The same value returned", value, n.floatValue(), 0.01);
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
495 }
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
496
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
497 @Test
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
498 public void testPrimitiveidentityDouble() throws Exception {
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
499 String id = identity();
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
500 if (id == null) {
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
501 return;
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
502 }
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
503 TruffleVM.Symbol apply = findGlobalSymbol(id);
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
504
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
505 double value = RANDOM.nextInt(1000) + RANDOM.nextDouble();
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
506
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
507 Number n = (Number) apply.invoke(null, value).get();
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
508 assertEquals("The same value returned", value, n.doubleValue(), 0.01);
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
509 }
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
510
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
511 @Test
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
512 public void testPrimitiveIdentityForeignObject() throws Exception {
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
513 String id = identity();
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
514 if (id == null) {
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
515 return;
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
516 }
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
517 TruffleVM.Symbol apply = findGlobalSymbol(id);
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
518
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
519 TruffleObject fn = JavaInterop.asTruffleFunction(LongBinaryOperation.class, new MaxMinObject(true));
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
520
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
521 Object ret = apply.invoke(null, fn).get();
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
522 assertSame("The same value returned", fn, ret);
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
523 }
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
524
92906003d607 Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22139
diff changeset
525 @Test
22046
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
526 public void testCoExistanceOfMultipleLanguageInstances() throws Exception {
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
527 final String countMethod = countInvocations();
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
528 TruffleVM.Symbol count1 = findGlobalSymbol(countMethod);
22076
f54d7e045a37 Verify the two TruffleVM instances are different - otherwise the isolation cannot work
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22046
diff changeset
529 TruffleVM vm1 = tckVM;
22046
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
530 tckVM = null; // clean-up
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
531 TruffleVM.Symbol count2 = findGlobalSymbol(countMethod);
22076
f54d7e045a37 Verify the two TruffleVM instances are different - otherwise the isolation cannot work
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22046
diff changeset
532 TruffleVM vm2 = tckVM;
f54d7e045a37 Verify the two TruffleVM instances are different - otherwise the isolation cannot work
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22046
diff changeset
533
f54d7e045a37 Verify the two TruffleVM instances are different - otherwise the isolation cannot work
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22046
diff changeset
534 assertNotSame("Two virtual machines allocated", vm1, vm2);
22046
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
535
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
536 int prev1 = 0;
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
537 int prev2 = 0;
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
538 for (int i = 0; i < 10; i++) {
22135
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
539 int quantum = RANDOM.nextInt(10);
22046
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
540 for (int j = 0; j < quantum; j++) {
22121
d045a505c2b3 Asynchronous TruffleVM can be created by providing own Executor when configuring the TruffleVM.Builder
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
541 Object res = count1.invoke(null).get();
22046
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
542 assert res instanceof Number : "expecting number: " + res;
22135
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
543 ++prev1;
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
544 assert ((Number) res).intValue() == prev1 : "expecting " + prev1 + " but was " + res;
22046
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
545 }
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
546 for (int j = 0; j < quantum; j++) {
22121
d045a505c2b3 Asynchronous TruffleVM can be created by providing own Executor when configuring the TruffleVM.Builder
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
547 Object res = count2.invoke(null).get();
22046
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
548 assert res instanceof Number : "expecting number: " + res;
22135
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
549 ++prev2;
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
550 assert ((Number) res).intValue() == prev2 : "expecting " + prev2 + " but was " + res;
22046
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
551 }
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
552 assert prev1 == prev2 : "At round " + i + " the same number of invocations " + prev1 + " vs. " + prev2;
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
553 }
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
554
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
555 }
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21960
diff changeset
556
21938
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
557 private TruffleVM.Symbol findGlobalSymbol(String name) throws Exception {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
558 TruffleVM.Symbol s = vm().findGlobalSymbol(name);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
559 assert s != null : "Symbol " + name + " is not found!";
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
560 return s;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
561 }
22135
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
562
22156
50056a161d7f Replacing time out associated warnings by UnsupportedOperationException. Meaning of exception is probably more straightforward than a soft hint attempted before. Shouldn't influence the way things are build, if tests are skipped.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22142
diff changeset
563 private CompoundObject findCompoundSymbol() throws Exception {
22135
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
564 final String compoundObjectName = compoundObject();
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
565 TruffleVM.Symbol s = vm().findGlobalSymbol(compoundObjectName);
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
566 assert s != null : "Symbol " + compoundObjectName + " is not found!";
22141
46384e637592 Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22140
diff changeset
567 final TruffleVM.Symbol value = s.invoke(null);
46384e637592 Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22140
diff changeset
568 CompoundObject obj = value.as(CompoundObject.class);
46384e637592 Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22140
diff changeset
569 assertNotNull("Compound object for " + value + " found", obj);
22135
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
570 int traverse = RANDOM.nextInt(10);
22141
46384e637592 Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22140
diff changeset
571 for (int i = 1; i <= traverse; i++) {
22135
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
572 obj = obj.returnsThis();
22141
46384e637592 Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22140
diff changeset
573 assertNotNull("Remains non-null even after " + i + " iteration", obj);
22135
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
574 }
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
575 return obj;
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
576 }
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
577
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
578 interface CompoundObject {
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
579 Number fourtyTwo();
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
580
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
581 Number plus(int x, int y);
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
582
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
583 Object returnsNull();
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
584
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
585 CompoundObject returnsThis();
e70b20f4bb00 Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
586 }
21938
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
587 }