annotate truffle/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/LazyClassLoadingTest.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 0d36601f233e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15478
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
1 /*
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
4 *
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
7 * published by the Free Software Foundation.
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
8 *
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
13 * accompanied this code).
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
14 *
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
18 *
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
21 * questions.
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
22 */
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
23 package com.oracle.truffle.api.dsl.test;
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
24
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
25 import java.lang.reflect.InvocationTargetException;
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
26 import java.lang.reflect.Method;
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
27
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
28 import org.junit.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
29 import org.junit.Assert;
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
30 import org.junit.Before;
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
31 import org.junit.Test;
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
32
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
33 import com.oracle.truffle.api.dsl.NodeChild;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
34 import com.oracle.truffle.api.dsl.NodeFactory;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
35 import com.oracle.truffle.api.dsl.Specialization;
15478
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
36 import com.oracle.truffle.api.dsl.test.LazyClassLoadingTestFactory.TestNodeFactory;
21554
b1530a6cce8c renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 18778
diff changeset
37 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode;
b1530a6cce8c renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 18778
diff changeset
38 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode;
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 import com.oracle.truffle.api.dsl.test.utilities.InstrumentationTestMode;
15478
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
40
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
41 public class LazyClassLoadingTest {
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
42
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
43 @Before
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
44 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
45 InstrumentationTestMode.set(true);
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 }
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
47
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
48 @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
49 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
50 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
51 }
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
52
15478
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
53 @Test
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
54 public void test() {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 15478
diff changeset
55 String factoryName = TestNodeFactory.class.getName();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 15478
diff changeset
56 String nodeName = factoryName + "$" + TestNode.class.getSimpleName() + "Gen";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 15478
diff changeset
57 Assert.assertTrue(isLoaded(factoryName));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 15478
diff changeset
58 Assert.assertFalse(isLoaded(nodeName));
15478
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
59
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
60 NodeFactory<TestNode> factory = TestNodeFactory.getInstance();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 15478
diff changeset
61 Assert.assertTrue(isLoaded(factoryName));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 15478
diff changeset
62 Assert.assertTrue(isLoaded(nodeName));
15478
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
63
18778
cb3bdd77c809 Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents: 18771
diff changeset
64 Assert.assertFalse(isLoaded(nodeName + "$UninitializedNode_"));
cb3bdd77c809 Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents: 18771
diff changeset
65 Assert.assertFalse(isLoaded(nodeName + "$BaseNode_"));
cb3bdd77c809 Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents: 18771
diff changeset
66 Assert.assertFalse(isLoaded(nodeName + "$IntNode_"));
cb3bdd77c809 Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents: 18771
diff changeset
67 Assert.assertFalse(isLoaded(nodeName + "$BooleanNode_"));
cb3bdd77c809 Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents: 18771
diff changeset
68 Assert.assertFalse(isLoaded(nodeName + "$PolymorphicNode_"));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 15478
diff changeset
69
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 15478
diff changeset
70 TestRootNode<TestNode> root = TestHelper.createRoot(factory);
15478
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
71
18778
cb3bdd77c809 Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents: 18771
diff changeset
72 Assert.assertTrue(isLoaded(nodeName + "$UninitializedNode_"));
cb3bdd77c809 Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents: 18771
diff changeset
73 Assert.assertTrue(isLoaded(nodeName + "$BaseNode_"));
cb3bdd77c809 Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents: 18771
diff changeset
74 Assert.assertFalse(isLoaded(nodeName + "$IntNode_"));
cb3bdd77c809 Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents: 18771
diff changeset
75 Assert.assertFalse(isLoaded(nodeName + "$BooleanNode_"));
cb3bdd77c809 Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents: 18771
diff changeset
76 Assert.assertFalse(isLoaded(nodeName + "$PolymorphicNode_"));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 15478
diff changeset
77
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 15478
diff changeset
78 Assert.assertEquals(42, TestHelper.executeWith(root, 42));
15478
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
79
18778
cb3bdd77c809 Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents: 18771
diff changeset
80 Assert.assertTrue(isLoaded(nodeName + "$IntNode_"));
cb3bdd77c809 Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents: 18771
diff changeset
81 Assert.assertFalse(isLoaded(nodeName + "$BooleanNode_"));
cb3bdd77c809 Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents: 18771
diff changeset
82 Assert.assertFalse(isLoaded(nodeName + "$PolymorphicNode_"));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 15478
diff changeset
83
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 15478
diff changeset
84 Assert.assertEquals(true, TestHelper.executeWith(root, true));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 15478
diff changeset
85
18778
cb3bdd77c809 Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents: 18771
diff changeset
86 Assert.assertTrue(isLoaded(nodeName + "$IntNode_"));
cb3bdd77c809 Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents: 18771
diff changeset
87 Assert.assertTrue(isLoaded(nodeName + "$BooleanNode_"));
cb3bdd77c809 Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents: 18771
diff changeset
88 Assert.assertTrue(isLoaded(nodeName + "$PolymorphicNode_"));
15478
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
89 }
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
90
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
91 private boolean isLoaded(String className) {
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
92 ClassLoader classLoader = getClass().getClassLoader();
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
93 Method m;
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
94 try {
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
95 m = ClassLoader.class.getDeclaredMethod("findLoadedClass", String.class);
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
96 m.setAccessible(true);
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
97 return m.invoke(classLoader, className) != null;
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
98 } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
99 throw new RuntimeException(e);
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
100 }
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
101 }
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
102
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 15478
diff changeset
103 @NodeChild("a")
15478
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
104 abstract static class TestNode extends ValueNode {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 15478
diff changeset
105
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 15478
diff changeset
106 @Specialization
18771
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
107 int doInt(int a) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 15478
diff changeset
108 return a;
15478
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
109 }
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
110
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 15478
diff changeset
111 @Specialization
18771
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
112 boolean doBoolean(boolean a) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 15478
diff changeset
113 return a;
15478
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
114 }
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
115
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
116 }
dd95dff835f9 TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
117 }