Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/LazyClassLoadingTest.java @ 18564:966081b8e830
guard against null element in HotSpotConstantReflectionProvider.readStableFieldValue
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 27 Nov 2014 11:45:13 +0100 |
parents | dd95dff835f9 |
children | a665483c3881 |
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; |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
31 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; |
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() { |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
36 String testClassName = getClass().getName(); |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
37 String factoryClassName = testClassName + "Factory"; |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
38 String nodeFactoryClassName = factoryClassName + "$TestNodeFactory"; |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
39 |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
40 Assert.assertFalse(isLoaded(factoryClassName + "$TestNode")); |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
41 Assert.assertFalse(isLoaded(nodeFactoryClassName)); |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
42 |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
43 NodeFactory<TestNode> factory = TestNodeFactory.getInstance(); |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
44 |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
45 Assert.assertTrue(isLoaded(nodeFactoryClassName)); |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
46 Assert.assertFalse(isLoaded(nodeFactoryClassName + "$TestBaseNode")); |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
47 |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
48 TestHelper.createRoot(factory); |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
49 |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
50 Assert.assertTrue(isLoaded(nodeFactoryClassName + "$TestBaseNode")); |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
51 Assert.assertTrue(isLoaded(nodeFactoryClassName + "$TestUninitializedNode")); |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
52 Assert.assertFalse(isLoaded(nodeFactoryClassName + "$TestGenericNode")); |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
53 } |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
54 |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
55 private boolean isLoaded(String className) { |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
56 ClassLoader classLoader = getClass().getClassLoader(); |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
57 Method m; |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
58 try { |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
59 m = ClassLoader.class.getDeclaredMethod("findLoadedClass", String.class); |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
60 m.setAccessible(true); |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
61 return m.invoke(classLoader, className) != null; |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
62 } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
63 throw new RuntimeException(e); |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
64 } |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
65 } |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
66 |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
67 @SuppressWarnings("unused") |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
68 @NodeChildren({@NodeChild("left"), @NodeChild("right")}) |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
69 abstract static class TestNode extends ValueNode { |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
70 @Specialization(order = 1) |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
71 int add(int left, int right) { |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
72 return 42; |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
73 } |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
74 |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
75 @Specialization(order = 2) |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
76 int add(boolean left, boolean right) { |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
77 return 21; |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
78 } |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
79 |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
80 @Specialization(order = 4) |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
81 String add(boolean left, int right) { |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
82 return "(boolean,int)"; |
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 } |
dd95dff835f9
TruffleDSL: add class loading test
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
85 } |