comparison truffle/com.oracle.truffle.tck/src/com/oracle/truffle/tck/TruffleTCK.java @ 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.
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Thu, 30 Jul 2015 17:36:34 +0200
parents a88981c5ce8b
children f54d7e045a37
comparison
equal deleted inserted replaced
22045:ffbc7f472438 22046:e7c2d36daf72
100 * @return name of globally exported symbol 100 * @return name of globally exported symbol
101 */ 101 */
102 protected abstract String applyNumbers(); 102 protected abstract String applyNumbers();
103 103
104 /** 104 /**
105 * Name of a function that counts number of its invocations in current {@link TruffleVM}
106 * context. Your function should somehow keep a counter to remember number of its invocations
107 * and always increment it. The first invocation should return <code>1</code>, the second
108 * <code>2</code> and so on. The returned values are expected to be instances of {@link Number}.
109 * <p>
110 * The function will be used to test that two instances of your language can co-exist next to
111 * each other. Without being mutually influenced.
112 *
113 * @return name of globally expected symbol
114 */
115 protected abstract String countInvocations();
116
117 /**
105 * Return a code snippet that is invalid in your language. Its 118 * Return a code snippet that is invalid in your language. Its
106 * {@link TruffleVM#eval(java.lang.String, java.lang.String) evaluation} should fail and yield 119 * {@link TruffleVM#eval(java.lang.String, java.lang.String) evaluation} should fail and yield
107 * an exception. 120 * an exception.
108 * 121 *
109 * @return code snippet invalid in the tested language 122 * @return code snippet invalid in the tested language
195 Number n = (Number) res; 208 Number n = (Number) res;
196 209
197 assert 28 == n.intValue() : "18 < 32 and plus 10"; 210 assert 28 == n.intValue() : "18 < 32 and plus 10";
198 } 211 }
199 212
213 @Test
214 public void testCoExistanceOfMultipleLanguageInstances() throws Exception {
215 final String countMethod = countInvocations();
216 TruffleVM.Symbol count1 = findGlobalSymbol(countMethod);
217 tckVM = null; // clean-up
218 TruffleVM.Symbol count2 = findGlobalSymbol(countMethod);
219
220 int prev1 = 0;
221 int prev2 = 0;
222 Random r = new Random();
223 for (int i = 0; i < 10; i++) {
224 int quantum = r.nextInt(10);
225 for (int j = 0; j < quantum; j++) {
226 Object res = count1.invoke(null);
227 assert res instanceof Number : "expecting number: " + res;
228 assert ((Number) res).intValue() == ++prev1 : "expecting " + prev1 + " but was " + res;
229 }
230 for (int j = 0; j < quantum; j++) {
231 Object res = count2.invoke(null);
232 assert res instanceof Number : "expecting number: " + res;
233 assert ((Number) res).intValue() == ++prev2 : "expecting " + prev2 + " but was " + res;
234 }
235 assert prev1 == prev2 : "At round " + i + " the same number of invocations " + prev1 + " vs. " + prev2;
236 }
237
238 }
239
200 private TruffleVM.Symbol findGlobalSymbol(String name) throws Exception { 240 private TruffleVM.Symbol findGlobalSymbol(String name) throws Exception {
201 TruffleVM.Symbol s = vm().findGlobalSymbol(name); 241 TruffleVM.Symbol s = vm().findGlobalSymbol(name);
202 assert s != null : "Symbol " + name + " is not found!"; 242 assert s != null : "Symbol " + name + " is not found!";
203 return s; 243 return s;
204 } 244 }