Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/LazyClassLoadingTest.java @ 20934:033dd4494705
Fix compare in LoweringPhase.processBlock
author | Stefan Anzinger <stefan.anzinger@oracle.com> |
---|---|
date | Tue, 14 Apr 2015 17:23:37 +0200 |
parents | cb3bdd77c809 |
children | b1530a6cce8c |
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; |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
31 import com.oracle.truffle.api.dsl.test.TypeSystemTest.*; |
15478
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
32 |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
33 public class LazyClassLoadingTest { |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
34 @Test |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
35 public void test() { |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
36 String factoryName = TestNodeFactory.class.getName(); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
37 String nodeName = factoryName + "$" + TestNode.class.getSimpleName() + "Gen"; |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
38 Assert.assertTrue(isLoaded(factoryName)); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
39 Assert.assertFalse(isLoaded(nodeName)); |
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 NodeFactory<TestNode> factory = TestNodeFactory.getInstance(); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
42 Assert.assertTrue(isLoaded(factoryName)); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
43 Assert.assertTrue(isLoaded(nodeName)); |
15478
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
44 |
18778
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
45 Assert.assertFalse(isLoaded(nodeName + "$UninitializedNode_")); |
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
46 Assert.assertFalse(isLoaded(nodeName + "$BaseNode_")); |
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
47 Assert.assertFalse(isLoaded(nodeName + "$IntNode_")); |
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
48 Assert.assertFalse(isLoaded(nodeName + "$BooleanNode_")); |
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
49 Assert.assertFalse(isLoaded(nodeName + "$PolymorphicNode_")); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
50 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
51 TestRootNode<TestNode> root = TestHelper.createRoot(factory); |
15478
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
52 |
18778
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
53 Assert.assertTrue(isLoaded(nodeName + "$UninitializedNode_")); |
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
54 Assert.assertTrue(isLoaded(nodeName + "$BaseNode_")); |
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
55 Assert.assertFalse(isLoaded(nodeName + "$IntNode_")); |
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
56 Assert.assertFalse(isLoaded(nodeName + "$BooleanNode_")); |
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
57 Assert.assertFalse(isLoaded(nodeName + "$PolymorphicNode_")); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
58 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
59 Assert.assertEquals(42, TestHelper.executeWith(root, 42)); |
15478
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
60 |
18778
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
61 Assert.assertTrue(isLoaded(nodeName + "$IntNode_")); |
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
62 Assert.assertFalse(isLoaded(nodeName + "$BooleanNode_")); |
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
63 Assert.assertFalse(isLoaded(nodeName + "$PolymorphicNode_")); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
64 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
65 Assert.assertEquals(true, TestHelper.executeWith(root, true)); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
66 |
18778
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
67 Assert.assertTrue(isLoaded(nodeName + "$IntNode_")); |
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
68 Assert.assertTrue(isLoaded(nodeName + "$BooleanNode_")); |
cb3bdd77c809
Truffle-DSL: fixed class loading test.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
69 Assert.assertTrue(isLoaded(nodeName + "$PolymorphicNode_")); |
15478
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
70 } |
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 private boolean isLoaded(String className) { |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
73 ClassLoader classLoader = getClass().getClassLoader(); |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
74 Method m; |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
75 try { |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
76 m = ClassLoader.class.getDeclaredMethod("findLoadedClass", String.class); |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
77 m.setAccessible(true); |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
78 return m.invoke(classLoader, className) != null; |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
79 } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
80 throw new RuntimeException(e); |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
81 } |
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 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
84 @NodeChild("a") |
15478
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
85 abstract static class TestNode extends ValueNode { |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
86 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
87 @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
|
88 int doInt(int a) { |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
89 return a; |
15478
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 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
92 @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
|
93 boolean doBoolean(boolean a) { |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
15478
diff
changeset
|
94 return a; |
15478
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
95 } |
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 } |