Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.tck/src/com/oracle/truffle/tck/TruffleTCK.java @ 22104:cf19259edf87
TruffleVM.eval and Source.withMimeType
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Mon, 24 Aug 2015 08:46:21 +0200 |
parents | f54d7e045a37 |
children | d045a505c2b3 |
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 |
22104
cf19259edf87
TruffleVM.eval and Source.withMimeType
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22076
diff
changeset
|
27 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
|
28 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
|
29 import java.io.IOException; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
30 import java.util.Random; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
31 import static org.junit.Assert.*; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
32 import org.junit.Test; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
33 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
34 /** |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
35 * 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
|
36 * 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
|
37 * include in your test suite. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
38 */ |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
39 public abstract class TruffleTCK { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
40 private TruffleVM tckVM; |
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 protected TruffleTCK() { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
43 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
44 |
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 * 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
|
47 * 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
|
48 * {@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
|
49 * 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
|
50 * 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
|
51 * used for internal testing. |
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 * @return initialized Truffle virtual machine |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
54 * @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
|
55 */ |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
56 protected abstract TruffleVM prepareVM() throws Exception; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
57 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
58 /** |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
59 * Mimetype associated with your language. The mimetype will be passed to |
22104
cf19259edf87
TruffleVM.eval and Source.withMimeType
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22076
diff
changeset
|
60 * {@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
|
61 * {@link #prepareVM() created TruffleVM}. |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
62 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
63 * @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
|
64 */ |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
65 protected abstract String mimeType(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
66 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
67 /** |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
68 * 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
|
69 * 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
|
70 * <code>42</code>. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
71 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
72 * @return name of globally exported symbol |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
73 */ |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
74 protected abstract String fourtyTwo(); |
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 /** |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
77 * 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
|
78 * 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
|
79 * {@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
|
80 * 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
|
81 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
82 * @return name of globally exported symbol |
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 protected abstract String returnsNull(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
85 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
86 /** |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
87 * 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
|
88 * 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
|
89 * {@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
|
90 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
91 * @return name of globally exported symbol |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
92 */ |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
93 protected abstract String plusInt(); |
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 /** |
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
|
96 * 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
|
97 * 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
|
98 * 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
|
99 * 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
|
100 * |
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
|
101 * @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
|
102 */ |
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
|
103 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
|
104 |
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
|
105 /** |
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
|
106 * 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
|
107 * 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
|
108 * 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
|
109 * <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
|
110 * <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
|
111 * 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
|
112 * 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
|
113 * |
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
|
114 * @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
|
115 */ |
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
|
116 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
|
117 |
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
|
118 /** |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
119 * 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
|
120 * {@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
|
121 * an exception. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
122 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
123 * @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
|
124 */ |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
125 protected abstract String invalidCode(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
126 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
127 private TruffleVM vm() throws Exception { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
128 if (tckVM == null) { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
129 tckVM = prepareVM(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
130 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
131 return tckVM; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
132 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
133 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
134 // |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
135 // The tests |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
136 // |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
137 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
138 @Test |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
139 public void testFortyTwo() throws Exception { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
140 TruffleVM.Symbol fourtyTwo = findGlobalSymbol(fourtyTwo()); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
141 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
142 Object res = fourtyTwo.invoke(null); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
143 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
144 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
|
145 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
146 Number n = (Number) res; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
147 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
148 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
|
149 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
150 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
151 @Test |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
152 public void testNull() throws Exception { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
153 if (getClass() == TruffleTCK.class) { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
154 return; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
155 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
156 TruffleVM.Symbol retNull = findGlobalSymbol(returnsNull()); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
157 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
158 Object res = retNull.invoke(null); |
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 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
|
161 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
162 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
163 @Test |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
164 public void testPlusWithInts() throws Exception { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
165 Random r = new Random(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
166 int a = r.nextInt(100); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
167 int b = r.nextInt(100); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
168 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
169 TruffleVM.Symbol plus = findGlobalSymbol(plusInt()); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
170 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
171 Object res = plus.invoke(null, a, b); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
172 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
173 assert res instanceof Number : "+ on two ints 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
|
174 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
175 Number n = (Number) res; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
176 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
177 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
|
178 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
179 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
180 @Test(expected = IOException.class) |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
181 public void testInvalidTestMethod() throws Exception { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
182 String mime = mimeType(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
183 String code = invalidCode(); |
22104
cf19259edf87
TruffleVM.eval and Source.withMimeType
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22076
diff
changeset
|
184 Object ret = vm().eval(Source.fromText(code, "Invalid code").withMimeType(mime)); |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
185 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
|
186 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
187 |
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
|
188 @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
|
189 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
|
190 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
|
191 |
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
|
192 Object res = apply.invoke(null, new MaxMinObject(true)); |
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
|
193 |
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
|
194 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
|
195 |
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
|
196 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
|
197 |
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
|
198 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
|
199 } |
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
|
200 |
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
|
201 @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
|
202 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
|
203 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
|
204 |
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
|
205 Object res = apply.invoke(null, new MaxMinObject(false)); |
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
|
206 |
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
|
207 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
|
208 |
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
|
209 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
|
210 |
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
|
211 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
|
212 } |
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
|
213 |
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
|
214 @Test |
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
|
215 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
|
216 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
|
217 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
|
218 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
|
219 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
|
220 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
|
221 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
|
222 |
f54d7e045a37
Verify the two TruffleVM instances are different - otherwise the isolation cannot work
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22046
diff
changeset
|
223 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
|
224 |
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
|
225 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
|
226 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
|
227 Random r = new Random(); |
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
|
228 for (int i = 0; i < 10; i++) { |
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
|
229 int quantum = r.nextInt(10); |
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
|
230 for (int j = 0; j < quantum; j++) { |
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
|
231 Object res = count1.invoke(null); |
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
|
232 assert res instanceof Number : "expecting number: " + res; |
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
|
233 assert ((Number) res).intValue() == ++prev1 : "expecting " + prev1 + " but was " + res; |
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
|
234 } |
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
|
235 for (int j = 0; j < quantum; j++) { |
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
|
236 Object res = count2.invoke(null); |
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
|
237 assert res instanceof Number : "expecting number: " + res; |
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
|
238 assert ((Number) res).intValue() == ++prev2 : "expecting " + prev2 + " but was " + res; |
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
|
239 } |
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
|
240 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
|
241 } |
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
|
242 |
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
|
243 } |
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
|
244 |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
245 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
|
246 TruffleVM.Symbol s = vm().findGlobalSymbol(name); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
247 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
|
248 return s; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
249 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
250 } |