Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.tck/src/com/oracle/truffle/tck/TruffleTCK.java @ 22076:f54d7e045a37
Verify the two TruffleVM instances are different - otherwise the isolation cannot work
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Thu, 13 Aug 2015 09:42:06 +0200 |
parents | e7c2d36daf72 |
children | cf19259edf87 |
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 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
27 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
|
28 import java.io.IOException; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
29 import java.util.Random; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
30 import static org.junit.Assert.*; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
31 import org.junit.Test; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
32 |
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 * 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
|
35 * 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
|
36 * include in your test suite. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
37 */ |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
38 public abstract class TruffleTCK { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
39 private TruffleVM tckVM; |
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 protected TruffleTCK() { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
42 } |
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 * 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
|
46 * your language up, so it is ready for testing. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
47 * {@link TruffleVM#eval(java.lang.String, java.lang.String) Execute} any scripts you need, and |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
48 * prepare global symbols with proper names. The symbols will then be looked up by the |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
49 * 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
|
50 * used for internal testing. |
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 * @return initialized Truffle virtual machine |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
53 * @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
|
54 */ |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
55 protected abstract TruffleVM prepareVM() throws Exception; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
56 |
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 * Mimetype associated with your language. The mimetype will be passed to |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
59 * {@link TruffleVM#eval(java.lang.String, java.lang.String)} method of the {@link #prepareVM() |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
60 * created TruffleVM}. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
61 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
62 * @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
|
63 */ |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
64 protected abstract String mimeType(); |
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 /** |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
67 * 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
|
68 * 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
|
69 * <code>42</code>. |
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 name of globally exported symbol |
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 fourtyTwo(); |
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 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
|
77 * 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
|
78 * {@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
|
79 * 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
|
80 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
81 * @return name of globally exported symbol |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
82 */ |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
83 protected abstract String returnsNull(); |
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 /** |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
86 * 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
|
87 * 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
|
88 * {@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
|
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 plusInt(); |
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 /** |
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
|
95 * 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
|
96 * 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
|
97 * 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
|
98 * 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
|
99 * |
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 * @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
|
101 */ |
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 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
|
103 |
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 /** |
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
|
105 * 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
|
106 * 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
|
107 * 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
|
108 * <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
|
109 * <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
|
110 * 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
|
111 * 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
|
112 * |
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 * @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
|
114 */ |
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 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
|
116 |
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 /** |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
118 * Return a code snippet that is invalid in your language. Its |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
119 * {@link TruffleVM#eval(java.lang.String, java.lang.String) evaluation} should fail and yield |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
120 * an exception. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
121 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
122 * @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
|
123 */ |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
124 protected abstract String invalidCode(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
125 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
126 private TruffleVM vm() throws Exception { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
127 if (tckVM == null) { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
128 tckVM = prepareVM(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
129 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
130 return tckVM; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
131 } |
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 // The tests |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
135 // |
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 @Test |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
138 public void testFortyTwo() throws Exception { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
139 TruffleVM.Symbol fourtyTwo = findGlobalSymbol(fourtyTwo()); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
140 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
141 Object res = fourtyTwo.invoke(null); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
142 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
143 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
|
144 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
145 Number n = (Number) res; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
146 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
147 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
|
148 } |
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 @Test |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
151 public void testNull() throws Exception { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
152 if (getClass() == TruffleTCK.class) { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
153 return; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
154 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
155 TruffleVM.Symbol retNull = findGlobalSymbol(returnsNull()); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
156 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
157 Object res = retNull.invoke(null); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
158 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
159 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
|
160 } |
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 @Test |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
163 public void testPlusWithInts() throws Exception { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
164 Random r = new Random(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
165 int a = r.nextInt(100); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
166 int b = r.nextInt(100); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
167 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
168 TruffleVM.Symbol plus = findGlobalSymbol(plusInt()); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
169 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
170 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
|
171 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
172 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
|
173 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
174 Number n = (Number) res; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
175 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
176 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
|
177 } |
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 @Test(expected = IOException.class) |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
180 public void testInvalidTestMethod() throws Exception { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
181 String mime = mimeType(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
182 String code = invalidCode(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
183 Object ret = vm().eval(mime, code); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
184 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
|
185 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
186 |
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
|
187 @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
|
188 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
|
189 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
|
190 |
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 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
|
192 |
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 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
|
194 |
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 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
|
196 |
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 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
|
198 } |
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 @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
|
201 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
|
202 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
|
203 |
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 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
|
205 |
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 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
|
207 |
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 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
|
209 |
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 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
|
211 } |
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 |
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
|
213 @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
|
214 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
|
215 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
|
216 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
|
217 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
|
218 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
|
219 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
|
220 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
|
221 |
f54d7e045a37
Verify the two TruffleVM instances are different - otherwise the isolation cannot work
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22046
diff
changeset
|
222 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
|
223 |
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 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
|
225 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
|
226 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
|
227 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
|
228 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
|
229 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
|
230 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
|
231 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
|
232 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
|
233 } |
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 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
|
235 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
|
236 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
|
237 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
|
238 } |
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 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
|
240 } |
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 |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
244 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
|
245 TruffleVM.Symbol s = vm().findGlobalSymbol(name); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
246 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
|
247 return s; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
248 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
249 } |