Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/TruffleRuntimeTest.java @ 22241:14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
- Caused by lack of a "vm" known to the Accessor during most testing, making the Instrumenter unavailable, which is now required to create a CallTarget
- Modified the Instrumenter/Accessor with a static field that can be reflectively "poked" with a vm value for testing
- Create a pair of methods to globally enable/disable testing mode to modify that static field and restore it when tests complete.
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Tue, 22 Sep 2015 20:31:19 -0700 |
parents | dc83cc1f94f2 |
children | 0fb3522e5b72 |
rev | line source |
---|---|
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
1 /* |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
4 * |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
8 * |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
14 * |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
18 * |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
21 * questions. |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
22 */ |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.api.test; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
24 |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
25 import com.oracle.truffle.api.RootCallTarget; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
26 import com.oracle.truffle.api.Truffle; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
27 import com.oracle.truffle.api.TruffleRuntime; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
28 import com.oracle.truffle.api.frame.VirtualFrame; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
29 import com.oracle.truffle.api.nodes.NodeUtil; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
30 import com.oracle.truffle.api.nodes.RootNode; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
31 import com.oracle.truffle.api.source.Source; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
32 import com.oracle.truffle.api.source.SourceSection; |
22241
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
33 import com.oracle.truffle.api.test.utilities.InstrumentationTestMode; |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
34 |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
35 import java.util.ArrayList; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
36 import java.util.HashMap; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
37 import java.util.List; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
38 import java.util.Map; |
22241
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
39 |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
40 import static org.junit.Assert.assertEquals; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
41 import static org.junit.Assert.assertNotNull; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
42 import static org.junit.Assert.assertSame; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
43 import static org.junit.Assert.assertTrue; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
44 import static org.junit.Assert.fail; |
22241
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
45 |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
46 import org.junit.After; |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
47 import org.junit.Before; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
48 import org.junit.Test; |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
49 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
50 /** |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
51 * <h3>Accessing the Truffle Runtime</h3> |
16992
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
52 * |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
53 * <p> |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
54 * The Truffle runtime can be accessed at any point in time globally using the static method |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
55 * {@link Truffle#getRuntime()}. This method is guaranteed to return a non-null Truffle runtime |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
56 * object with an identifying name. A Java Virtual Machine implementation can chose to replace the |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
57 * default implementation of the {@link TruffleRuntime} interface with its own implementation for |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
58 * providing improved performance. |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
59 * </p> |
16992
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
60 * |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
61 * <p> |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
62 * The next part of the Truffle API introduction is at |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
63 * {@link com.oracle.truffle.api.test.RootNodeTest}. |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
64 * </p> |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
65 */ |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
66 public class TruffleRuntimeTest { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
67 |
16992
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
68 private TruffleRuntime runtime; |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
69 |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
70 @Before |
22241
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
71 public void before() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
72 InstrumentationTestMode.set(true); |
16992
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
73 this.runtime = Truffle.getRuntime(); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
74 } |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
75 |
22241
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
76 @After |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
77 public void after() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
78 InstrumentationTestMode.set(false); |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
79 } |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
80 |
16992
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
81 private static RootNode createTestRootNode() { |
22003
5bc7f7b867ab
Making debugger always on for each TruffleVM execution. Introducing EventConsumer to process such debugger events. Requesting each RootNode to be associated with a TruffleLanguage, so debugger can find out proper context for each Node where executions gets suspended.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
82 return new RootNode(TestingLanguage.class, null, null) { |
16992
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
83 @Override |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
84 public Object execute(VirtualFrame frame) { |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
85 return 42; |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
86 } |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
87 }; |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
88 } |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
89 |
21939
e24237684856
Few more tweaks to help us pass the gate
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21938
diff
changeset
|
90 // @Test |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
18163
diff
changeset
|
91 public void verifyTheRealRuntimeIsUsedOnRealGraal() { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
18163
diff
changeset
|
92 TruffleRuntime r = Truffle.getRuntime(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
18163
diff
changeset
|
93 final String name = r.getClass().getName(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
18163
diff
changeset
|
94 if (name.endsWith("DefaultTruffleRuntime")) { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
18163
diff
changeset
|
95 fail("Wrong name " + name + " with following System.getProperties:\n" + System.getProperties().toString()); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
18163
diff
changeset
|
96 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
18163
diff
changeset
|
97 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
18163
diff
changeset
|
98 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
18163
diff
changeset
|
99 @Test |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
100 public void test() { |
16992
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
101 assertNotNull(runtime); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
102 assertNotNull(runtime.getName()); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
103 } |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
104 |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
105 @Test |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
106 public void testCreateCallTarget() { |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
107 RootNode rootNode = createTestRootNode(); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
108 RootCallTarget target = runtime.createCallTarget(rootNode); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
109 assertNotNull(target); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
110 assertEquals(target.call(), 42); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
111 assertSame(rootNode, target.getRootNode()); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
112 } |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
113 |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
114 @Test |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
115 public void testGetCallTargets1() { |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
116 RootNode rootNode = createTestRootNode(); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
117 RootCallTarget target = runtime.createCallTarget(rootNode); |
17036
7b45e33b7986
Truffle: made TruffleRuntime#getCallTargets return a Collection and simplified its implementation.
Christian Humer <christian.humer@gmail.com>
parents:
16992
diff
changeset
|
118 assertTrue(runtime.getCallTargets().contains(target)); |
16992
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
119 } |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
120 |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
121 @Test |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
122 public void testGetCallTargets2() { |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
123 RootNode rootNode = createTestRootNode(); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
124 RootCallTarget target1 = runtime.createCallTarget(rootNode); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
125 RootCallTarget target2 = runtime.createCallTarget(rootNode); |
17036
7b45e33b7986
Truffle: made TruffleRuntime#getCallTargets return a Collection and simplified its implementation.
Christian Humer <christian.humer@gmail.com>
parents:
16992
diff
changeset
|
126 assertTrue(runtime.getCallTargets().contains(target1)); |
7b45e33b7986
Truffle: made TruffleRuntime#getCallTargets return a Collection and simplified its implementation.
Christian Humer <christian.humer@gmail.com>
parents:
16992
diff
changeset
|
127 assertTrue(runtime.getCallTargets().contains(target2)); |
16992
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
128 } |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
129 |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
130 /* |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
131 * This test case documents the use case for profilers and debuggers where they need to access |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
132 * multiple call targets for the same source section. This case may happen when the optimization |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
133 * system decides to duplicate call targets to achieve better performance. |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
134 */ |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
135 @Test |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
136 public void testGetCallTargets3() { |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
137 Source source1 = Source.fromText("a\nb\n", ""); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
138 SourceSection sourceSection1 = source1.createSection("foo", 1); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
139 SourceSection sourceSection2 = source1.createSection("bar", 2); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
140 |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
141 RootNode rootNode1 = createTestRootNode(); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
142 rootNode1.assignSourceSection(sourceSection1); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
143 RootNode rootNode2 = createTestRootNode(); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
144 rootNode2.assignSourceSection(sourceSection2); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
145 RootNode rootNode2Copy = NodeUtil.cloneNode(rootNode2); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
146 |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
147 assertSame(rootNode2.getSourceSection(), rootNode2Copy.getSourceSection()); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
148 |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
149 RootCallTarget target1 = runtime.createCallTarget(rootNode1); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
150 RootCallTarget target2 = runtime.createCallTarget(rootNode2); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
151 RootCallTarget target2Copy = runtime.createCallTarget(rootNode2Copy); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
152 |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
153 Map<SourceSection, List<RootCallTarget>> groupedTargets = groupUniqueCallTargets(); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
154 |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
155 List<RootCallTarget> targets1 = groupedTargets.get(sourceSection1); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
156 assertEquals(1, targets1.size()); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
157 assertEquals(target1, targets1.get(0)); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
158 |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
159 List<RootCallTarget> targets2 = groupedTargets.get(sourceSection2); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
160 assertEquals(2, targets2.size()); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
161 // order of targets2 is not guaranteed |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
162 assertTrue(target2 == targets2.get(0) ^ target2Copy == targets2.get(0)); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
163 assertTrue(target2 == targets2.get(1) ^ target2Copy == targets2.get(1)); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
164 } |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
165 |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
166 private static Map<SourceSection, List<RootCallTarget>> groupUniqueCallTargets() { |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
167 Map<SourceSection, List<RootCallTarget>> groupedTargets = new HashMap<>(); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
168 for (RootCallTarget target : Truffle.getRuntime().getCallTargets()) { |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
169 SourceSection section = target.getRootNode().getSourceSection(); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
170 if (section == null) { |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
171 // can not identify root node to a unique call target. Print warning? |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
172 continue; |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
173 } |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
174 List<RootCallTarget> targets = groupedTargets.get(section); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
175 if (targets == null) { |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
176 targets = new ArrayList<>(); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
177 groupedTargets.put(section, targets); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
178 } |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
179 targets.add(target); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
180 } |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
181 return groupedTargets; |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
182 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
183 } |