Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/TestResolvedJavaType.java @ 13982:b167b1838029
mx eclipseinit: take care of working sets that were edited by hand
author | Michael Haupt <michael.haupt@oracle.com> |
---|---|
date | Thu, 20 Feb 2014 11:14:46 +0100 |
parents | d2f520f46180 |
children | 64dcb92ee75a |
rev | line source |
---|---|
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1 /* |
7044
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
7043
diff
changeset
|
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
4 * |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
8 * |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
14 * |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
18 * |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
21 * questions. |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
22 */ |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.graal.api.meta.test; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
24 |
7282
390448a6b535
converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
7098
diff
changeset
|
25 import static java.lang.Integer.*; |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
26 import static java.lang.reflect.Modifier.*; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
27 import static org.junit.Assert.*; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
28 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
29 import java.lang.annotation.*; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
30 import java.lang.reflect.*; |
7831
fb0ef768d877
simplified class file path retrieval, added test
Michael Haupt <michael.haupt@oracle.com>
parents:
7829
diff
changeset
|
31 import java.net.*; |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
32 import java.util.*; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
33 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
34 import org.junit.*; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
35 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
36 import sun.reflect.ConstantPool; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
37 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
38 import com.oracle.graal.api.meta.*; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
39 |
7043
947de43c68d6
improved documentation for ResolvedJavaType.findUniqueConcreteSubtype()
Doug Simon <doug.simon@oracle.com>
parents:
7037
diff
changeset
|
40 /** |
947de43c68d6
improved documentation for ResolvedJavaType.findUniqueConcreteSubtype()
Doug Simon <doug.simon@oracle.com>
parents:
7037
diff
changeset
|
41 * Tests for {@link ResolvedJavaType}. |
947de43c68d6
improved documentation for ResolvedJavaType.findUniqueConcreteSubtype()
Doug Simon <doug.simon@oracle.com>
parents:
7037
diff
changeset
|
42 */ |
13818
d2f520f46180
added more unit tests for meta.api, discovering and fixing an issue with HotSpotResolvedJavaField.getModifiers() in the process
Doug Simon <doug.simon@oracle.com>
parents:
13183
diff
changeset
|
43 @SuppressWarnings("unused") |
9806
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
44 public class TestResolvedJavaType extends TypeUniverse { |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
45 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
46 public TestResolvedJavaType() { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
47 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
48 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
49 @Test |
7056
2841e28b5f41
added test for ResolvedJavaType.findFieldWithOffset
Doug Simon <doug.simon@oracle.com>
parents:
7045
diff
changeset
|
50 public void findInstanceFieldWithOffsetTest() { |
2841e28b5f41
added test for ResolvedJavaType.findFieldWithOffset
Doug Simon <doug.simon@oracle.com>
parents:
7045
diff
changeset
|
51 for (Class c : classes) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
52 ResolvedJavaType type = metaAccess.lookupJavaType(c); |
7056
2841e28b5f41
added test for ResolvedJavaType.findFieldWithOffset
Doug Simon <doug.simon@oracle.com>
parents:
7045
diff
changeset
|
53 Set<Field> reflectionFields = getInstanceFields(c, true); |
2841e28b5f41
added test for ResolvedJavaType.findFieldWithOffset
Doug Simon <doug.simon@oracle.com>
parents:
7045
diff
changeset
|
54 for (Field f : reflectionFields) { |
2841e28b5f41
added test for ResolvedJavaType.findFieldWithOffset
Doug Simon <doug.simon@oracle.com>
parents:
7045
diff
changeset
|
55 ResolvedJavaField rf = lookupField(type.getInstanceFields(true), f); |
2841e28b5f41
added test for ResolvedJavaType.findFieldWithOffset
Doug Simon <doug.simon@oracle.com>
parents:
7045
diff
changeset
|
56 assertNotNull(rf); |
2841e28b5f41
added test for ResolvedJavaType.findFieldWithOffset
Doug Simon <doug.simon@oracle.com>
parents:
7045
diff
changeset
|
57 long offset = isStatic(f.getModifiers()) ? unsafe.staticFieldOffset(f) : unsafe.objectFieldOffset(f); |
7057
c37022832f1a
rename: findFieldWithOffset -> findInstanceFieldWithOffset
Doug Simon <doug.simon@oracle.com>
parents:
7056
diff
changeset
|
58 ResolvedJavaField result = type.findInstanceFieldWithOffset(offset); |
7056
2841e28b5f41
added test for ResolvedJavaType.findFieldWithOffset
Doug Simon <doug.simon@oracle.com>
parents:
7045
diff
changeset
|
59 assertNotNull(result); |
2841e28b5f41
added test for ResolvedJavaType.findFieldWithOffset
Doug Simon <doug.simon@oracle.com>
parents:
7045
diff
changeset
|
60 assertTrue(fieldsEqual(f, result)); |
2841e28b5f41
added test for ResolvedJavaType.findFieldWithOffset
Doug Simon <doug.simon@oracle.com>
parents:
7045
diff
changeset
|
61 } |
2841e28b5f41
added test for ResolvedJavaType.findFieldWithOffset
Doug Simon <doug.simon@oracle.com>
parents:
7045
diff
changeset
|
62 } |
2841e28b5f41
added test for ResolvedJavaType.findFieldWithOffset
Doug Simon <doug.simon@oracle.com>
parents:
7045
diff
changeset
|
63 } |
2841e28b5f41
added test for ResolvedJavaType.findFieldWithOffset
Doug Simon <doug.simon@oracle.com>
parents:
7045
diff
changeset
|
64 |
2841e28b5f41
added test for ResolvedJavaType.findFieldWithOffset
Doug Simon <doug.simon@oracle.com>
parents:
7045
diff
changeset
|
65 @Test |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
66 public void isInterfaceTest() { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
67 for (Class c : classes) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
68 ResolvedJavaType type = metaAccess.lookupJavaType(c); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
69 boolean expected = c.isInterface(); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
70 boolean actual = type.isInterface(); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
71 assertEquals(expected, actual); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
72 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
73 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
74 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
75 @Test |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
76 public void isInstanceClassTest() { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
77 for (Class c : classes) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
78 ResolvedJavaType type = metaAccess.lookupJavaType(c); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
79 boolean expected = !c.isArray() && !c.isPrimitive() && !c.isInterface(); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
80 boolean actual = type.isInstanceClass(); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
81 assertEquals(expected, actual); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
82 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
83 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
84 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
85 @Test |
9806
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
86 public void isArrayTest() { |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
87 for (Class c : classes) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
88 ResolvedJavaType type = metaAccess.lookupJavaType(c); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
89 boolean expected = c.isArray(); |
7060
06d5f450f32b
rename: ResolvedJavaType.isArrayClass() -> ResolvedJavaType.isArray()
Doug Simon <doug.simon@oracle.com>
parents:
7057
diff
changeset
|
90 boolean actual = type.isArray(); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
91 assertEquals(expected, actual); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
92 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
93 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
94 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
95 @Test |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
96 public void getModifiersTest() { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
97 for (Class c : classes) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
98 ResolvedJavaType type = metaAccess.lookupJavaType(c); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
99 int expected = c.getModifiers(); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
100 int actual = type.getModifiers(); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
101 assertEquals(expected, actual); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
102 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
103 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
104 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
105 @Test |
9806
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
106 public void isAssignableFromTest() { |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
107 Class[] all = classes.toArray(new Class[classes.size()]); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
108 for (int i = 0; i < all.length; i++) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
109 Class<?> c1 = all[i]; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
110 for (int j = i; j < all.length; j++) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
111 Class<?> c2 = all[j]; |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
112 ResolvedJavaType t1 = metaAccess.lookupJavaType(c1); |
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
113 ResolvedJavaType t2 = metaAccess.lookupJavaType(c2); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
114 boolean expected = c1.isAssignableFrom(c2); |
7097
6644cecbd3a7
Replace ResolvedJavaType.isAssignableTo with isAssignableFrom to be consistent with java.lang.Class
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7096
diff
changeset
|
115 boolean actual = t1.isAssignableFrom(t2); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
116 assertEquals(expected, actual); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
117 if (expected && t1 != t2) { |
7097
6644cecbd3a7
Replace ResolvedJavaType.isAssignableTo with isAssignableFrom to be consistent with java.lang.Class
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7096
diff
changeset
|
118 assertFalse(t2.isAssignableFrom(t1)); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
119 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
120 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
121 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
122 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
123 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
124 @Test |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
125 public void isInstanceTest() { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
126 for (Constant c : constants) { |
7098
e23980f4a890
Cleanup of Kind class: remove isXxx methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7097
diff
changeset
|
127 if (c.getKind() == Kind.Object && !c.isNull()) { |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
128 Object o = c.asObject(); |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
129 Class<? extends Object> cls = o.getClass(); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
130 while (cls != null) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
131 ResolvedJavaType type = metaAccess.lookupJavaType(cls); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
132 boolean expected = cls.isInstance(o); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
133 boolean actual = type.isInstance(c); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
134 assertEquals(expected, actual); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
135 cls = cls.getSuperclass(); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
136 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
137 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
138 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
139 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
140 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
141 private static Class asExactClass(Class c) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
142 if (c.isArray()) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
143 if (asExactClass(c.getComponentType()) != null) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
144 return c; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
145 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
146 } else { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
147 if (c.isPrimitive() || Modifier.isFinal(c.getModifiers())) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
148 return c; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
149 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
150 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
151 return null; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
152 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
153 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
154 @Test |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
155 public void asExactTypeTest() { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
156 for (Class c : classes) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
157 ResolvedJavaType type = metaAccess.lookupJavaType(c); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
158 ResolvedJavaType exactType = type.asExactType(); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
159 Class expected = asExactClass(c); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
160 if (expected == null) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
161 assertTrue("exact(" + c.getName() + ") != null", exactType == null); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
162 } else { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
163 assertNotNull(exactType); |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
164 assertTrue(exactType.equals(metaAccess.lookupJavaType(expected))); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
165 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
166 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
167 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
168 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
169 @Test |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
170 public void getSuperclassTest() { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
171 for (Class c : classes) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
172 ResolvedJavaType type = metaAccess.lookupJavaType(c); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
173 Class expected = c.getSuperclass(); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
174 ResolvedJavaType actual = type.getSuperclass(); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
175 if (expected == null) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
176 assertTrue(actual == null); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
177 } else { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
178 assertNotNull(actual); |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
179 assertTrue(actual.equals(metaAccess.lookupJavaType(expected))); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
180 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
181 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
182 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
183 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
184 @Test |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
185 public void getInterfacesTest() { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
186 for (Class c : classes) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
187 ResolvedJavaType type = metaAccess.lookupJavaType(c); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
188 Class[] expected = c.getInterfaces(); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
189 ResolvedJavaType[] actual = type.getInterfaces(); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
190 assertEquals(expected.length, actual.length); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
191 for (int i = 0; i < expected.length; i++) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
192 assertTrue(actual[i].equals(metaAccess.lookupJavaType(expected[i]))); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
193 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
194 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
195 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
196 |
9806
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
197 public Class getSupertype(Class c) { |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
198 assert !c.isPrimitive(); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
199 if (c.isArray()) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
200 Class componentType = c.getComponentType(); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
201 if (componentType.isPrimitive() || componentType == Object.class) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
202 return Object.class; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
203 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
204 return getArrayClass(getSupertype(componentType)); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
205 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
206 if (c.isInterface()) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
207 return Object.class; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
208 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
209 return c.getSuperclass(); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
210 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
211 |
9806
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
212 public Class findLeastCommonAncestor(Class<?> c1Initial, Class<?> c2Initial) { |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
213 if (c1Initial.isPrimitive() || c2Initial.isPrimitive()) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
214 return null; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
215 } else { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
216 Class<?> c1 = c1Initial; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
217 Class<?> c2 = c2Initial; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
218 while (true) { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
219 if (c1.isAssignableFrom(c2)) { |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
220 return c1; |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
221 } |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
222 if (c2.isAssignableFrom(c1)) { |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
223 return c2; |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
224 } |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
225 c1 = getSupertype(c1); |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
226 c2 = getSupertype(c2); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
227 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
228 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
229 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
230 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
231 @Test |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
232 public void findLeastCommonAncestorTest() { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
233 Class[] all = classes.toArray(new Class[classes.size()]); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
234 for (int i = 0; i < all.length; i++) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
235 Class<?> c1 = all[i]; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
236 for (int j = i; j < all.length; j++) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
237 Class<?> c2 = all[j]; |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
238 ResolvedJavaType t1 = metaAccess.lookupJavaType(c1); |
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
239 ResolvedJavaType t2 = metaAccess.lookupJavaType(c2); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
240 Class expected = findLeastCommonAncestor(c1, c2); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
241 ResolvedJavaType actual = t1.findLeastCommonAncestor(t2); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
242 if (expected == null) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
243 assertTrue(actual == null); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
244 } else { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
245 assertNotNull(actual); |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
246 assertTrue(actual.equals(metaAccess.lookupJavaType(expected))); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
247 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
248 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
249 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
250 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
251 |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
252 private static class Base { |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
253 } |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
254 |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
255 abstract static class Abstract1 extends Base { |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
256 } |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
257 |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
258 interface Interface1 { |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
259 } |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
260 |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
261 static class Concrete1 extends Abstract1 { |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
262 } |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
263 |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
264 static class Concrete2 extends Abstract1 implements Interface1 { |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
265 } |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
266 |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
267 static class Concrete3 extends Concrete2 { |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
268 } |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
269 |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
270 abstract static class Abstract4 extends Concrete3 { |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
271 } |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
272 |
9806
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
273 void checkConcreteSubtype(ResolvedJavaType type, Class expected) { |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
274 ResolvedJavaType subtype = type.findUniqueConcreteSubtype(); |
7043
947de43c68d6
improved documentation for ResolvedJavaType.findUniqueConcreteSubtype()
Doug Simon <doug.simon@oracle.com>
parents:
7037
diff
changeset
|
275 if (subtype == null) { |
7045
7ac6e4c10e37
bug fix for HotSpotReslvedJavaType.findUniqueConcreteSubtype() on arrays of interfaces
Doug Simon <doug.simon@oracle.com>
parents:
7044
diff
changeset
|
276 // findUniqueConcreteSubtype() is conservative |
7ac6e4c10e37
bug fix for HotSpotReslvedJavaType.findUniqueConcreteSubtype() on arrays of interfaces
Doug Simon <doug.simon@oracle.com>
parents:
7044
diff
changeset
|
277 } else { |
7ac6e4c10e37
bug fix for HotSpotReslvedJavaType.findUniqueConcreteSubtype() on arrays of interfaces
Doug Simon <doug.simon@oracle.com>
parents:
7044
diff
changeset
|
278 if (expected == null) { |
7ac6e4c10e37
bug fix for HotSpotReslvedJavaType.findUniqueConcreteSubtype() on arrays of interfaces
Doug Simon <doug.simon@oracle.com>
parents:
7044
diff
changeset
|
279 assertNull(subtype); |
7ac6e4c10e37
bug fix for HotSpotReslvedJavaType.findUniqueConcreteSubtype() on arrays of interfaces
Doug Simon <doug.simon@oracle.com>
parents:
7044
diff
changeset
|
280 } else { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
281 assertTrue(subtype.equals(metaAccess.lookupJavaType(expected))); |
7045
7ac6e4c10e37
bug fix for HotSpotReslvedJavaType.findUniqueConcreteSubtype() on arrays of interfaces
Doug Simon <doug.simon@oracle.com>
parents:
7044
diff
changeset
|
282 } |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
283 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
284 |
7060
06d5f450f32b
rename: ResolvedJavaType.isArrayClass() -> ResolvedJavaType.isArray()
Doug Simon <doug.simon@oracle.com>
parents:
7057
diff
changeset
|
285 if (!type.isArray()) { |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
286 ResolvedJavaType arrayType = type.getArrayClass(); |
7043
947de43c68d6
improved documentation for ResolvedJavaType.findUniqueConcreteSubtype()
Doug Simon <doug.simon@oracle.com>
parents:
7037
diff
changeset
|
287 ResolvedJavaType arraySubtype = arrayType.findUniqueConcreteSubtype(); |
947de43c68d6
improved documentation for ResolvedJavaType.findUniqueConcreteSubtype()
Doug Simon <doug.simon@oracle.com>
parents:
7037
diff
changeset
|
288 if (arraySubtype != null) { |
947de43c68d6
improved documentation for ResolvedJavaType.findUniqueConcreteSubtype()
Doug Simon <doug.simon@oracle.com>
parents:
7037
diff
changeset
|
289 assertEquals(arraySubtype, arrayType); |
7045
7ac6e4c10e37
bug fix for HotSpotReslvedJavaType.findUniqueConcreteSubtype() on arrays of interfaces
Doug Simon <doug.simon@oracle.com>
parents:
7044
diff
changeset
|
290 } else { |
7ac6e4c10e37
bug fix for HotSpotReslvedJavaType.findUniqueConcreteSubtype() on arrays of interfaces
Doug Simon <doug.simon@oracle.com>
parents:
7044
diff
changeset
|
291 // findUniqueConcreteSubtype() method is conservative |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
292 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
293 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
294 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
295 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
296 @Test |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
297 public void findUniqueConcreteSubtypeTest() { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
298 ResolvedJavaType base = metaAccess.lookupJavaType(Base.class); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
299 checkConcreteSubtype(base, Base.class); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
300 |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
301 ResolvedJavaType a1 = metaAccess.lookupJavaType(Abstract1.class); |
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
302 ResolvedJavaType c1 = metaAccess.lookupJavaType(Concrete1.class); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
303 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
304 checkConcreteSubtype(base, null); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
305 checkConcreteSubtype(a1, Concrete1.class); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
306 checkConcreteSubtype(c1, Concrete1.class); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
307 |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
308 ResolvedJavaType i1 = metaAccess.lookupJavaType(Interface1.class); |
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
309 ResolvedJavaType c2 = metaAccess.lookupJavaType(Concrete2.class); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
310 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
311 checkConcreteSubtype(base, null); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
312 checkConcreteSubtype(a1, null); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
313 checkConcreteSubtype(c1, Concrete1.class); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
314 checkConcreteSubtype(i1, Concrete2.class); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
315 checkConcreteSubtype(c2, Concrete2.class); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
316 |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
317 ResolvedJavaType c3 = metaAccess.lookupJavaType(Concrete3.class); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
318 checkConcreteSubtype(c2, null); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
319 checkConcreteSubtype(c3, Concrete3.class); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
320 |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
321 ResolvedJavaType a4 = metaAccess.lookupJavaType(Abstract4.class); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
322 checkConcreteSubtype(c3, null); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
323 checkConcreteSubtype(a4, null); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
324 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
325 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
326 @Test |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
327 public void getComponentTypeTest() { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
328 for (Class c : classes) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
329 ResolvedJavaType type = metaAccess.lookupJavaType(c); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
330 Class expected = c.getComponentType(); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
331 ResolvedJavaType actual = type.getComponentType(); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
332 if (expected == null) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
333 assertNull(actual); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
334 } else { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
335 assertTrue(actual.equals(metaAccess.lookupJavaType(expected))); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
336 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
337 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
338 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
339 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
340 @Test |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
341 public void getArrayClassTest() { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
342 for (Class c : classes) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
343 if (c != void.class) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
344 ResolvedJavaType type = metaAccess.lookupJavaType(c); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
345 Class expected = getArrayClass(c); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
346 ResolvedJavaType actual = type.getArrayClass(); |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
347 assertTrue(actual.equals(metaAccess.lookupJavaType(expected))); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
348 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
349 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
350 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
351 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
352 static class Declarations { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
353 |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
354 final Method implementation; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
355 final Set<Method> declarations; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
356 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
357 public Declarations(Method impl) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
358 this.implementation = impl; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
359 declarations = new HashSet<>(); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
360 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
361 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
362 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
363 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
364 * See <a href="http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-5.html#jvms-5.4.5">Method |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
365 * overriding</a>. |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
366 */ |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
367 static boolean isOverriderOf(Method impl, Method m) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
368 if (!isPrivate(m.getModifiers()) && !isFinal(m.getModifiers())) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
369 if (m.getName().equals(impl.getName())) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
370 if (m.getReturnType() == impl.getReturnType()) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
371 if (Arrays.equals(m.getParameterTypes(), impl.getParameterTypes())) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
372 if (isPublic(m.getModifiers()) || isProtected(m.getModifiers())) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
373 // m is public or protected |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
374 return isPublic(impl.getModifiers()) || isProtected(impl.getModifiers()); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
375 } else { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
376 // m is package-private |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
377 return impl.getDeclaringClass().getPackage() == m.getDeclaringClass().getPackage(); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
378 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
379 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
380 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
381 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
382 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
383 return false; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
384 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
385 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
386 static final Map<Class, VTable> vtables = new HashMap<>(); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
387 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
388 static class VTable { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
389 |
7044
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
7043
diff
changeset
|
390 final Map<NameAndSignature, Method> methods = new HashMap<>(); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
391 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
392 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
393 static synchronized VTable getVTable(Class c) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
394 VTable vtable = vtables.get(c); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
395 if (vtable == null) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
396 vtable = new VTable(); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
397 if (c != Object.class) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
398 VTable superVtable = getVTable(c.getSuperclass()); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
399 vtable.methods.putAll(superVtable.methods); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
400 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
401 for (Method m : c.getDeclaredMethods()) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
402 if (!isStatic(m.getModifiers()) && !isPrivate(m.getModifiers())) { |
11823
6440f50c1ea8
improved documentation and testing for ResolvedJavaType.resolveMethod() (GRAAL-489)
Doug Simon <doug.simon@oracle.com>
parents:
11520
diff
changeset
|
403 if (isAbstract(m.getModifiers())) { |
6440f50c1ea8
improved documentation and testing for ResolvedJavaType.resolveMethod() (GRAAL-489)
Doug Simon <doug.simon@oracle.com>
parents:
11520
diff
changeset
|
404 // A subclass makes a concrete method in a superclass abstract |
6440f50c1ea8
improved documentation and testing for ResolvedJavaType.resolveMethod() (GRAAL-489)
Doug Simon <doug.simon@oracle.com>
parents:
11520
diff
changeset
|
405 vtable.methods.remove(new NameAndSignature(m)); |
6440f50c1ea8
improved documentation and testing for ResolvedJavaType.resolveMethod() (GRAAL-489)
Doug Simon <doug.simon@oracle.com>
parents:
11520
diff
changeset
|
406 } else { |
6440f50c1ea8
improved documentation and testing for ResolvedJavaType.resolveMethod() (GRAAL-489)
Doug Simon <doug.simon@oracle.com>
parents:
11520
diff
changeset
|
407 vtable.methods.put(new NameAndSignature(m), m); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
408 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
409 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
410 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
411 vtables.put(c, vtable); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
412 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
413 return vtable; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
414 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
415 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
416 static Set<Method> findDeclarations(Method impl, Class c) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
417 Set<Method> declarations = new HashSet<>(); |
7044
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
7043
diff
changeset
|
418 NameAndSignature implSig = new NameAndSignature(impl); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
419 if (c != null) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
420 for (Method m : c.getDeclaredMethods()) { |
7044
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
7043
diff
changeset
|
421 if (new NameAndSignature(m).equals(implSig)) { |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
422 declarations.add(m); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
423 break; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
424 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
425 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
426 if (!c.isInterface()) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
427 declarations.addAll(findDeclarations(impl, c.getSuperclass())); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
428 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
429 for (Class i : c.getInterfaces()) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
430 declarations.addAll(findDeclarations(impl, i)); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
431 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
432 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
433 return declarations; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
434 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
435 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
436 private static void checkResolveMethod(ResolvedJavaType type, ResolvedJavaMethod decl, ResolvedJavaMethod expected) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
437 ResolvedJavaMethod impl = type.resolveMethod(decl); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
438 assertEquals(expected, impl); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
439 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
440 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
441 @Test |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
442 public void resolveMethodTest() { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
443 for (Class c : classes) { |
11823
6440f50c1ea8
improved documentation and testing for ResolvedJavaType.resolveMethod() (GRAAL-489)
Doug Simon <doug.simon@oracle.com>
parents:
11520
diff
changeset
|
444 if (c.isInterface() || c.isPrimitive()) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
445 ResolvedJavaType type = metaAccess.lookupJavaType(c); |
11823
6440f50c1ea8
improved documentation and testing for ResolvedJavaType.resolveMethod() (GRAAL-489)
Doug Simon <doug.simon@oracle.com>
parents:
11520
diff
changeset
|
446 for (Method m : c.getDeclaredMethods()) { |
13183
0266ac3b26c0
JDK8: added support for default methods as well as interfaces containing static and private methods
Doug Simon <doug.simon@oracle.com>
parents:
11959
diff
changeset
|
447 if (JAVA_VERSION <= 1.7D || (!isStatic(m.getModifiers()) && !isPrivate(m.getModifiers()))) { |
0266ac3b26c0
JDK8: added support for default methods as well as interfaces containing static and private methods
Doug Simon <doug.simon@oracle.com>
parents:
11959
diff
changeset
|
448 ResolvedJavaMethod resolved = metaAccess.lookupJavaMethod(m); |
0266ac3b26c0
JDK8: added support for default methods as well as interfaces containing static and private methods
Doug Simon <doug.simon@oracle.com>
parents:
11959
diff
changeset
|
449 ResolvedJavaMethod impl = type.resolveMethod(resolved); |
0266ac3b26c0
JDK8: added support for default methods as well as interfaces containing static and private methods
Doug Simon <doug.simon@oracle.com>
parents:
11959
diff
changeset
|
450 ResolvedJavaMethod expected = resolved.isDefault() ? resolved : null; |
0266ac3b26c0
JDK8: added support for default methods as well as interfaces containing static and private methods
Doug Simon <doug.simon@oracle.com>
parents:
11959
diff
changeset
|
451 assertEquals(m.toString(), expected, impl); |
0266ac3b26c0
JDK8: added support for default methods as well as interfaces containing static and private methods
Doug Simon <doug.simon@oracle.com>
parents:
11959
diff
changeset
|
452 } else { |
0266ac3b26c0
JDK8: added support for default methods as well as interfaces containing static and private methods
Doug Simon <doug.simon@oracle.com>
parents:
11959
diff
changeset
|
453 // As of JDK 8, interfaces can have static and private methods |
0266ac3b26c0
JDK8: added support for default methods as well as interfaces containing static and private methods
Doug Simon <doug.simon@oracle.com>
parents:
11959
diff
changeset
|
454 } |
11823
6440f50c1ea8
improved documentation and testing for ResolvedJavaType.resolveMethod() (GRAAL-489)
Doug Simon <doug.simon@oracle.com>
parents:
11520
diff
changeset
|
455 } |
6440f50c1ea8
improved documentation and testing for ResolvedJavaType.resolveMethod() (GRAAL-489)
Doug Simon <doug.simon@oracle.com>
parents:
11520
diff
changeset
|
456 } else { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
457 ResolvedJavaType type = metaAccess.lookupJavaType(c); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
458 VTable vtable = getVTable(c); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
459 for (Method impl : vtable.methods.values()) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
460 Set<Method> decls = findDeclarations(impl, c); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
461 for (Method decl : decls) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
462 ResolvedJavaMethod m = metaAccess.lookupJavaMethod(decl); |
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
463 ResolvedJavaMethod i = metaAccess.lookupJavaMethod(impl); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
464 checkResolveMethod(type, m, i); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
465 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
466 } |
11823
6440f50c1ea8
improved documentation and testing for ResolvedJavaType.resolveMethod() (GRAAL-489)
Doug Simon <doug.simon@oracle.com>
parents:
11520
diff
changeset
|
467 for (Method m : c.getDeclaredMethods()) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
468 ResolvedJavaMethod impl = type.resolveMethod(metaAccess.lookupJavaMethod(m)); |
11823
6440f50c1ea8
improved documentation and testing for ResolvedJavaType.resolveMethod() (GRAAL-489)
Doug Simon <doug.simon@oracle.com>
parents:
11520
diff
changeset
|
469 ResolvedJavaMethod expected = isAbstract(m.getModifiers()) ? null : impl; |
6440f50c1ea8
improved documentation and testing for ResolvedJavaType.resolveMethod() (GRAAL-489)
Doug Simon <doug.simon@oracle.com>
parents:
11520
diff
changeset
|
470 assertEquals(type + " " + m.toString(), expected, impl); |
6440f50c1ea8
improved documentation and testing for ResolvedJavaType.resolveMethod() (GRAAL-489)
Doug Simon <doug.simon@oracle.com>
parents:
11520
diff
changeset
|
471 } |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
472 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
473 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
474 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
475 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
476 @Test |
9806
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
477 public void findUniqueConcreteMethodTest() throws NoSuchMethodException { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
478 ResolvedJavaMethod thisMethod = metaAccess.lookupJavaMethod(getClass().getDeclaredMethod("findUniqueConcreteMethodTest")); |
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
479 ResolvedJavaMethod ucm = metaAccess.lookupJavaType(getClass()).findUniqueConcreteMethod(thisMethod); |
9806
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
480 assertEquals(thisMethod, ucm); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
481 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
482 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
483 public static Set<Field> getInstanceFields(Class c, boolean includeSuperclasses) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
484 if (c.isArray() || c.isPrimitive() || c.isInterface()) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
485 return Collections.emptySet(); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
486 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
487 Set<Field> result = new HashSet<>(); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
488 for (Field f : c.getDeclaredFields()) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
489 if (!Modifier.isStatic(f.getModifiers())) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
490 result.add(f); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
491 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
492 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
493 if (includeSuperclasses && c != Object.class) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
494 result.addAll(getInstanceFields(c.getSuperclass(), true)); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
495 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
496 return result; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
497 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
498 |
9806
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
499 public boolean fieldsEqual(Field f, ResolvedJavaField rjf) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
500 return rjf.getDeclaringClass().equals(metaAccess.lookupJavaType(f.getDeclaringClass())) && rjf.getName().equals(f.getName()) && |
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
501 rjf.getType().resolve(rjf.getDeclaringClass()).equals(metaAccess.lookupJavaType(f.getType())); |
7056
2841e28b5f41
added test for ResolvedJavaType.findFieldWithOffset
Doug Simon <doug.simon@oracle.com>
parents:
7045
diff
changeset
|
502 } |
2841e28b5f41
added test for ResolvedJavaType.findFieldWithOffset
Doug Simon <doug.simon@oracle.com>
parents:
7045
diff
changeset
|
503 |
9806
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
504 public ResolvedJavaField lookupField(ResolvedJavaField[] fields, Field key) { |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
505 for (ResolvedJavaField rf : fields) { |
7056
2841e28b5f41
added test for ResolvedJavaType.findFieldWithOffset
Doug Simon <doug.simon@oracle.com>
parents:
7045
diff
changeset
|
506 if (fieldsEqual(key, rf)) { |
2841e28b5f41
added test for ResolvedJavaType.findFieldWithOffset
Doug Simon <doug.simon@oracle.com>
parents:
7045
diff
changeset
|
507 return rf; |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
508 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
509 } |
7056
2841e28b5f41
added test for ResolvedJavaType.findFieldWithOffset
Doug Simon <doug.simon@oracle.com>
parents:
7045
diff
changeset
|
510 return null; |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
511 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
512 |
9806
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
513 public Field lookupField(Set<Field> fields, ResolvedJavaField key) { |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
514 for (Field f : fields) { |
7056
2841e28b5f41
added test for ResolvedJavaType.findFieldWithOffset
Doug Simon <doug.simon@oracle.com>
parents:
7045
diff
changeset
|
515 if (fieldsEqual(f, key)) { |
2841e28b5f41
added test for ResolvedJavaType.findFieldWithOffset
Doug Simon <doug.simon@oracle.com>
parents:
7045
diff
changeset
|
516 return f; |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
517 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
518 } |
7056
2841e28b5f41
added test for ResolvedJavaType.findFieldWithOffset
Doug Simon <doug.simon@oracle.com>
parents:
7045
diff
changeset
|
519 return null; |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
520 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
521 |
9806
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
522 private boolean isHiddenFromReflection(ResolvedJavaField f) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
523 if (f.getDeclaringClass().equals(metaAccess.lookupJavaType(Throwable.class)) && f.getName().equals("backtrace")) { |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
524 return true; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
525 } |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
526 if (f.getDeclaringClass().equals(metaAccess.lookupJavaType(ConstantPool.class)) && f.getName().equals("constantPoolOop")) { |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
527 return true; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
528 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
529 return false; |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
530 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
531 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
532 @Test |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
533 public void getInstanceFieldsTest() { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
534 for (Class c : classes) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
535 ResolvedJavaType type = metaAccess.lookupJavaType(c); |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7282
diff
changeset
|
536 for (boolean includeSuperclasses : new boolean[]{true, false}) { |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
537 Set<Field> expected = getInstanceFields(c, includeSuperclasses); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
538 ResolvedJavaField[] actual = type.getInstanceFields(includeSuperclasses); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
539 for (Field f : expected) { |
7056
2841e28b5f41
added test for ResolvedJavaType.findFieldWithOffset
Doug Simon <doug.simon@oracle.com>
parents:
7045
diff
changeset
|
540 assertNotNull(lookupField(actual, f)); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
541 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
542 for (ResolvedJavaField rf : actual) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
543 if (!isHiddenFromReflection(rf)) { |
7056
2841e28b5f41
added test for ResolvedJavaType.findFieldWithOffset
Doug Simon <doug.simon@oracle.com>
parents:
7045
diff
changeset
|
544 assertEquals(lookupField(expected, rf) != null, !rf.isInternal()); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
545 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
546 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
547 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
548 // Test stability of getInstanceFields |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
549 ResolvedJavaField[] actual2 = type.getInstanceFields(includeSuperclasses); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
550 assertArrayEquals(actual, actual2); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
551 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
552 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
553 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
554 |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
555 @Test |
11953
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
556 public void getDeclaredMethodsTest() { |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
557 for (Class c : classes) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
558 ResolvedJavaType type = metaAccess.lookupJavaType(c); |
11953
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
559 Method[] raw = c.getDeclaredMethods(); |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
560 Set<ResolvedJavaMethod> expected = new HashSet<>(); |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
561 for (Method m : raw) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
562 ResolvedJavaMethod resolvedMethod = metaAccess.lookupJavaMethod(m); |
11953
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
563 assertNotNull(resolvedMethod); |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
564 expected.add(resolvedMethod); |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
565 } |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
566 Set<ResolvedJavaMethod> actual = new HashSet<>(Arrays.asList(type.getDeclaredMethods())); |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
567 assertEquals(expected, actual); |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
568 } |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
569 } |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
570 |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
571 static class A { |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
572 static String name = "foo"; |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
573 } |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
574 |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
575 static class B extends A { |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
576 } |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
577 |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
578 static class C { |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
579 } |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
580 |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
581 static class D { |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
582 void foo() { |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
583 // use of assertions causes the class to have a <clinit> |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
584 assert getClass() != null; |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
585 } |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
586 } |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
587 |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
588 @Test |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
589 public void getClassInitializerTest() { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
590 assertNotNull(metaAccess.lookupJavaType(A.class).getClassInitializer()); |
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
591 assertNotNull(metaAccess.lookupJavaType(D.class).getClassInitializer()); |
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
592 assertNull(metaAccess.lookupJavaType(B.class).getClassInitializer()); |
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
593 assertNull(metaAccess.lookupJavaType(C.class).getClassInitializer()); |
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
594 assertNull(metaAccess.lookupJavaType(int.class).getClassInitializer()); |
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
595 assertNull(metaAccess.lookupJavaType(void.class).getClassInitializer()); |
11953
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
596 } |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
597 |
f9f18098479e
added tests for ResolvedJavaType.getClassInitializer() and ResolvedJavaType.getDeclaredMethods()
Doug Simon <doug.simon@oracle.com>
parents:
11823
diff
changeset
|
598 @Test |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
599 public void getAnnotationTest() { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
600 for (Class c : classes) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
601 ResolvedJavaType type = metaAccess.lookupJavaType(c); |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
602 for (Annotation a : c.getAnnotations()) { |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
603 assertEquals(a, type.getAnnotation(a.annotationType())); |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
604 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
605 } |
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
606 } |
7829
a44887443b0c
support for inner classes (local/member) in meta API
Michael Haupt <michael.haupt@oracle.com>
parents:
7530
diff
changeset
|
607 |
a44887443b0c
support for inner classes (local/member) in meta API
Michael Haupt <michael.haupt@oracle.com>
parents:
7530
diff
changeset
|
608 @Test |
a44887443b0c
support for inner classes (local/member) in meta API
Michael Haupt <michael.haupt@oracle.com>
parents:
7530
diff
changeset
|
609 public void memberClassesTest() { |
a44887443b0c
support for inner classes (local/member) in meta API
Michael Haupt <michael.haupt@oracle.com>
parents:
7530
diff
changeset
|
610 for (Class c : classes) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
611 ResolvedJavaType type = metaAccess.lookupJavaType(c); |
7829
a44887443b0c
support for inner classes (local/member) in meta API
Michael Haupt <michael.haupt@oracle.com>
parents:
7530
diff
changeset
|
612 assertEquals(c.isLocalClass(), type.isLocal()); |
a44887443b0c
support for inner classes (local/member) in meta API
Michael Haupt <michael.haupt@oracle.com>
parents:
7530
diff
changeset
|
613 assertEquals(c.isMemberClass(), type.isMember()); |
a44887443b0c
support for inner classes (local/member) in meta API
Michael Haupt <michael.haupt@oracle.com>
parents:
7530
diff
changeset
|
614 Class enclc = c.getEnclosingClass(); |
a44887443b0c
support for inner classes (local/member) in meta API
Michael Haupt <michael.haupt@oracle.com>
parents:
7530
diff
changeset
|
615 ResolvedJavaType enclt = type.getEnclosingType(); |
a44887443b0c
support for inner classes (local/member) in meta API
Michael Haupt <michael.haupt@oracle.com>
parents:
7530
diff
changeset
|
616 assertFalse(enclc == null ^ enclt == null); |
a44887443b0c
support for inner classes (local/member) in meta API
Michael Haupt <michael.haupt@oracle.com>
parents:
7530
diff
changeset
|
617 if (enclc != null) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
618 assertEquals(enclt, metaAccess.lookupJavaType(enclc)); |
7829
a44887443b0c
support for inner classes (local/member) in meta API
Michael Haupt <michael.haupt@oracle.com>
parents:
7530
diff
changeset
|
619 } |
a44887443b0c
support for inner classes (local/member) in meta API
Michael Haupt <michael.haupt@oracle.com>
parents:
7530
diff
changeset
|
620 } |
a44887443b0c
support for inner classes (local/member) in meta API
Michael Haupt <michael.haupt@oracle.com>
parents:
7530
diff
changeset
|
621 } |
7831
fb0ef768d877
simplified class file path retrieval, added test
Michael Haupt <michael.haupt@oracle.com>
parents:
7829
diff
changeset
|
622 |
fb0ef768d877
simplified class file path retrieval, added test
Michael Haupt <michael.haupt@oracle.com>
parents:
7829
diff
changeset
|
623 @Test |
fb0ef768d877
simplified class file path retrieval, added test
Michael Haupt <michael.haupt@oracle.com>
parents:
7829
diff
changeset
|
624 public void classFilePathTest() { |
fb0ef768d877
simplified class file path retrieval, added test
Michael Haupt <michael.haupt@oracle.com>
parents:
7829
diff
changeset
|
625 for (Class c : classes) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11953
diff
changeset
|
626 ResolvedJavaType type = metaAccess.lookupJavaType(c); |
7831
fb0ef768d877
simplified class file path retrieval, added test
Michael Haupt <michael.haupt@oracle.com>
parents:
7829
diff
changeset
|
627 URL path = type.getClassFilePath(); |
fb0ef768d877
simplified class file path retrieval, added test
Michael Haupt <michael.haupt@oracle.com>
parents:
7829
diff
changeset
|
628 if (type.isPrimitive() || type.isArray()) { |
fb0ef768d877
simplified class file path retrieval, added test
Michael Haupt <michael.haupt@oracle.com>
parents:
7829
diff
changeset
|
629 assertEquals(null, path); |
fb0ef768d877
simplified class file path retrieval, added test
Michael Haupt <michael.haupt@oracle.com>
parents:
7829
diff
changeset
|
630 } else { |
fb0ef768d877
simplified class file path retrieval, added test
Michael Haupt <michael.haupt@oracle.com>
parents:
7829
diff
changeset
|
631 assertNotNull(path); |
fb0ef768d877
simplified class file path retrieval, added test
Michael Haupt <michael.haupt@oracle.com>
parents:
7829
diff
changeset
|
632 String pathString = path.getPath(); |
fb0ef768d877
simplified class file path retrieval, added test
Michael Haupt <michael.haupt@oracle.com>
parents:
7829
diff
changeset
|
633 if (type.isLocal() || type.isMember()) { |
fb0ef768d877
simplified class file path retrieval, added test
Michael Haupt <michael.haupt@oracle.com>
parents:
7829
diff
changeset
|
634 assertTrue(pathString.indexOf('$') > 0); |
fb0ef768d877
simplified class file path retrieval, added test
Michael Haupt <michael.haupt@oracle.com>
parents:
7829
diff
changeset
|
635 } |
fb0ef768d877
simplified class file path retrieval, added test
Michael Haupt <michael.haupt@oracle.com>
parents:
7829
diff
changeset
|
636 } |
fb0ef768d877
simplified class file path retrieval, added test
Michael Haupt <michael.haupt@oracle.com>
parents:
7829
diff
changeset
|
637 } |
fb0ef768d877
simplified class file path retrieval, added test
Michael Haupt <michael.haupt@oracle.com>
parents:
7829
diff
changeset
|
638 } |
9806
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
639 |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
640 private Method findTestMethod(Method apiMethod) { |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
641 String testName = apiMethod.getName() + "Test"; |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
642 for (Method m : getClass().getDeclaredMethods()) { |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
643 if (m.getName().equals(testName) && m.getAnnotation(Test.class) != null) { |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
644 return m; |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
645 } |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
646 } |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
647 return null; |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
648 } |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
649 |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
650 // @formatter:off |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
651 private static final String[] untestedApiMethods = { |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
652 "initialize", |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
653 "isPrimitive", |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
654 "newArray", |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
655 "getDeclaredConstructors", |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
656 "isInitialized", |
11520
7cca436d600b
Add isLinked method to ResolvedJavaType
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9806
diff
changeset
|
657 "isLinked", |
9806
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
658 "getEncoding", |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
659 "hasFinalizableSubclass", |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
660 "hasFinalizer", |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
661 "getSourceFileName", |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
662 "getClassFilePath", |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
663 "isLocal", |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
664 "isMember", |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
665 "getEnclosingType" |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
666 }; |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
667 // @formatter:on |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
668 |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
669 /** |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
670 * Ensures that any new methods added to {@link ResolvedJavaMethod} either have a test written |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
671 * for them or are added to {@link #untestedApiMethods}. |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
672 */ |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
673 @Test |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
674 public void testCoverage() { |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
675 Set<String> known = new HashSet<>(Arrays.asList(untestedApiMethods)); |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
676 for (Method m : ResolvedJavaType.class.getDeclaredMethods()) { |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
677 if (findTestMethod(m) == null) { |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
678 assertTrue("test missing for " + m, known.contains(m.getName())); |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
679 } else { |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
680 assertFalse("test should be removed from untestedApiMethods" + m, known.contains(m.getName())); |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
681 } |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
682 } |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
683 } |
21b8cd853b2b
cleaned up api.meta tests (GRAAL-59)
Doug Simon <doug.simon@oracle.com>
parents:
8959
diff
changeset
|
684 |
7037
dd81042f4eb1
added unit tests for ResolvedJavaType
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
685 } |