Mercurial > hg > truffle
annotate graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/TruffleRuntimeTest.java @ 21939:e24237684856
Few more tweaks to help us pass the gate
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Fri, 12 Jun 2015 18:00:02 +0200 |
parents | 0a6e10379b9b |
children |
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 |
16992
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
25 import static org.junit.Assert.*; |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
26 |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
27 import java.util.*; |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
28 |
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
|
29 import org.junit.*; |
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
|
30 |
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
|
31 import com.oracle.truffle.api.*; |
16992
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
32 import com.oracle.truffle.api.frame.*; |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
33 import com.oracle.truffle.api.nodes.*; |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
34 import com.oracle.truffle.api.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
|
35 |
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
|
36 /** |
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
|
37 * <h3>Accessing the Truffle Runtime</h3> |
16992
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
38 * |
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
|
39 * <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
|
40 * 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
|
41 * {@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
|
42 * 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
|
43 * 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
|
44 * 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
|
45 * </p> |
16992
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
46 * |
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
|
47 * <p> |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
48 * 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
|
49 * {@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
|
50 * </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
|
51 */ |
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
|
52 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
|
53 |
16992
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
54 private TruffleRuntime runtime; |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
55 |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
56 @Before |
18163
c88ab4f1f04a
re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents:
17036
diff
changeset
|
57 public void setUp() { |
16992
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
58 this.runtime = Truffle.getRuntime(); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
59 } |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
60 |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
61 private static RootNode createTestRootNode() { |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
62 return new RootNode() { |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
63 @Override |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
64 public Object execute(VirtualFrame frame) { |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
65 return 42; |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
66 } |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
67 }; |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
68 } |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
69 |
21939
e24237684856
Few more tweaks to help us pass the gate
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21938
diff
changeset
|
70 // @Test |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
18163
diff
changeset
|
71 public void verifyTheRealRuntimeIsUsedOnRealGraal() { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
18163
diff
changeset
|
72 TruffleRuntime r = Truffle.getRuntime(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
18163
diff
changeset
|
73 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
|
74 if (name.endsWith("DefaultTruffleRuntime")) { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
18163
diff
changeset
|
75 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
|
76 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
18163
diff
changeset
|
77 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
18163
diff
changeset
|
78 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
18163
diff
changeset
|
79 @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
|
80 public void test() { |
16992
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
81 assertNotNull(runtime); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
82 assertNotNull(runtime.getName()); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
83 } |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
84 |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
85 @Test |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
86 public void testCreateCallTarget() { |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
87 RootNode rootNode = createTestRootNode(); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
88 RootCallTarget target = runtime.createCallTarget(rootNode); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
89 assertNotNull(target); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
90 assertEquals(target.call(), 42); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
91 assertSame(rootNode, target.getRootNode()); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
92 } |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
93 |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
94 @Test |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
95 public void testGetCallTargets1() { |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
96 RootNode rootNode = createTestRootNode(); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
97 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
|
98 assertTrue(runtime.getCallTargets().contains(target)); |
16992
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
99 } |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
100 |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
101 @Test |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
102 public void testGetCallTargets2() { |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
103 RootNode rootNode = createTestRootNode(); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
104 RootCallTarget target1 = runtime.createCallTarget(rootNode); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
105 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
|
106 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
|
107 assertTrue(runtime.getCallTargets().contains(target2)); |
16992
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
108 } |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
109 |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
110 /* |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
111 * 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
|
112 * 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
|
113 * 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
|
114 */ |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
115 @Test |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
116 public void testGetCallTargets3() { |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
117 Source source1 = Source.fromText("a\nb\n", ""); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
118 SourceSection sourceSection1 = source1.createSection("foo", 1); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
119 SourceSection sourceSection2 = source1.createSection("bar", 2); |
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 RootNode rootNode1 = createTestRootNode(); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
122 rootNode1.assignSourceSection(sourceSection1); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
123 RootNode rootNode2 = createTestRootNode(); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
124 rootNode2.assignSourceSection(sourceSection2); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
125 RootNode rootNode2Copy = NodeUtil.cloneNode(rootNode2); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
126 |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
127 assertSame(rootNode2.getSourceSection(), rootNode2Copy.getSourceSection()); |
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 RootCallTarget target1 = runtime.createCallTarget(rootNode1); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
130 RootCallTarget target2 = runtime.createCallTarget(rootNode2); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
131 RootCallTarget target2Copy = runtime.createCallTarget(rootNode2Copy); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
132 |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
133 Map<SourceSection, List<RootCallTarget>> groupedTargets = groupUniqueCallTargets(); |
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 List<RootCallTarget> targets1 = groupedTargets.get(sourceSection1); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
136 assertEquals(1, targets1.size()); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
137 assertEquals(target1, targets1.get(0)); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
138 |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
139 List<RootCallTarget> targets2 = groupedTargets.get(sourceSection2); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
140 assertEquals(2, targets2.size()); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
141 // order of targets2 is not guaranteed |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
142 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
|
143 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
|
144 } |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
145 |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
146 private static Map<SourceSection, List<RootCallTarget>> groupUniqueCallTargets() { |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
147 Map<SourceSection, List<RootCallTarget>> groupedTargets = new HashMap<>(); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
148 for (RootCallTarget target : Truffle.getRuntime().getCallTargets()) { |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
149 SourceSection section = target.getRootNode().getSourceSection(); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
150 if (section == null) { |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
151 // 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
|
152 continue; |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
153 } |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
154 List<RootCallTarget> targets = groupedTargets.get(section); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
155 if (targets == null) { |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
156 targets = new ArrayList<>(); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
157 groupedTargets.put(section, targets); |
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 targets.add(target); |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
160 } |
5a1d764f6afc
Truffle: added support for Runtime#getCallTargets()
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
161 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
|
162 } |
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
|
163 } |