Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/LazyClassLoadingTest.java @ 21554:b1530a6cce8c
renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 26 May 2015 23:21:15 +0200 |
parents | cb3bdd77c809 |
children |
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 |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
25 import java.lang.reflect.*; |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
26 |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
27 import org.junit.*; |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
28 |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
29 import com.oracle.truffle.api.dsl.*; |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
30 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
|
31 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
|
32 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; |
15478
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
33 |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
34 public class LazyClassLoadingTest { |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
35 @Test |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
36 public void test() { |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
37 String factoryName = TestNodeFactory.class.getName(); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
38 String nodeName = factoryName + "$" + TestNode.class.getSimpleName() + "Gen"; |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
39 Assert.assertTrue(isLoaded(factoryName)); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
40 Assert.assertFalse(isLoaded(nodeName)); |
15478
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
41 |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
42 NodeFactory<TestNode> factory = TestNodeFactory.getInstance(); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
43 Assert.assertTrue(isLoaded(factoryName)); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
44 Assert.assertTrue(isLoaded(nodeName)); |
15478
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
45 |
18778
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
46 Assert.assertFalse(isLoaded(nodeName + "$UninitializedNode_")); |
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
47 Assert.assertFalse(isLoaded(nodeName + "$BaseNode_")); |
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
48 Assert.assertFalse(isLoaded(nodeName + "$IntNode_")); |
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
49 Assert.assertFalse(isLoaded(nodeName + "$BooleanNode_")); |
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
50 Assert.assertFalse(isLoaded(nodeName + "$PolymorphicNode_")); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
51 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
52 TestRootNode<TestNode> root = TestHelper.createRoot(factory); |
15478
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
53 |
18778
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
54 Assert.assertTrue(isLoaded(nodeName + "$UninitializedNode_")); |
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
55 Assert.assertTrue(isLoaded(nodeName + "$BaseNode_")); |
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
56 Assert.assertFalse(isLoaded(nodeName + "$IntNode_")); |
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
57 Assert.assertFalse(isLoaded(nodeName + "$BooleanNode_")); |
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
58 Assert.assertFalse(isLoaded(nodeName + "$PolymorphicNode_")); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
59 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
60 Assert.assertEquals(42, TestHelper.executeWith(root, 42)); |
15478
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
61 |
18778
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
62 Assert.assertTrue(isLoaded(nodeName + "$IntNode_")); |
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
63 Assert.assertFalse(isLoaded(nodeName + "$BooleanNode_")); |
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
64 Assert.assertFalse(isLoaded(nodeName + "$PolymorphicNode_")); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
65 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
66 Assert.assertEquals(true, TestHelper.executeWith(root, true)); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
67 |
18778
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
68 Assert.assertTrue(isLoaded(nodeName + "$IntNode_")); |
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
69 Assert.assertTrue(isLoaded(nodeName + "$BooleanNode_")); |
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
70 Assert.assertTrue(isLoaded(nodeName + "$PolymorphicNode_")); |
15478
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
71 } |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
72 |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
73 private boolean isLoaded(String className) { |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
74 ClassLoader classLoader = getClass().getClassLoader(); |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
75 Method m; |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
76 try { |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
77 m = ClassLoader.class.getDeclaredMethod("findLoadedClass", String.class); |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
78 m.setAccessible(true); |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
79 return m.invoke(classLoader, className) != null; |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
80 } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
81 throw new RuntimeException(e); |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
82 } |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
83 } |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
84 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
85 @NodeChild("a") |
15478
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
86 abstract static class TestNode extends ValueNode { |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
87 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
88 @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
|
89 int doInt(int a) { |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
90 return a; |
15478
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
91 } |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
92 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
93 @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
|
94 boolean doBoolean(boolean a) { |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
95 return a; |
15478
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
96 } |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
97 |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
98 } |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
99 } |