Mercurial > hg > graal-compiler
comparison c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotTypeResolved.java @ 2285:762de4b26788
turn Compiler and HotSpotTypeResolved into interfaces
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Fri, 08 Apr 2011 13:43:05 +0200 |
parents | 569d3fe7d65c |
children | 8c426c2891c8 |
comparison
equal
deleted
inserted
replaced
2284:569d3fe7d65c | 2285:762de4b26788 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2010 Sun Microsystems, Inc. All rights reserved. | 2 * Copyright (c) 2011 Sun Microsystems, Inc. All rights reserved. |
3 * | 3 * |
4 * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product | 4 * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product |
5 * that is described in this document. In particular, and without limitation, these intellectual property | 5 * that is described in this document. In particular, and without limitation, these intellectual property |
6 * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or | 6 * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or |
7 * more additional patents or pending patent applications in the U.S. and in other countries. | 7 * more additional patents or pending patent applications in the U.S. and in other countries. |
18 * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open | 18 * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open |
19 * Company, Ltd. | 19 * Company, Ltd. |
20 */ | 20 */ |
21 package com.sun.hotspot.c1x; | 21 package com.sun.hotspot.c1x; |
22 | 22 |
23 import java.lang.reflect.*; | |
24 import java.util.*; | |
25 | |
26 import com.sun.cri.ci.*; | 23 import com.sun.cri.ci.*; |
27 import com.sun.cri.ri.*; | 24 import com.sun.cri.ri.*; |
28 | 25 |
29 /** | 26 public interface HotSpotTypeResolved extends RiType { |
30 * Implementation of RiType for resolved non-primitive HotSpot classes. | |
31 * | |
32 * @author Thomas Wuerthinger, Lukas Stadler | |
33 */ | |
34 public class HotSpotTypeResolved extends HotSpotType { | |
35 | 27 |
36 private Class javaMirror; | 28 public int accessFlags(); |
37 private String simpleName; | |
38 private int accessFlags; | |
39 private boolean hasFinalizer; | |
40 private boolean hasSubclass; | |
41 private boolean hasFinalizableSubclass; | |
42 private boolean isInitialized; | |
43 private boolean isArrayClass; | |
44 private boolean isInstanceClass; | |
45 private boolean isInterface; | |
46 private int instanceSize; | |
47 private RiType componentType; | |
48 private HashMap<Integer, RiField> fieldCache; | |
49 private RiConstantPool pool; | |
50 | 29 |
51 private HotSpotTypeResolved() { | 30 public RiType arrayOf(); |
52 super(null); | |
53 } | |
54 | 31 |
55 @Override | 32 public RiType componentType(); |
56 public int accessFlags() { | |
57 return accessFlags; | |
58 } | |
59 | 33 |
60 @Override | 34 public RiType uniqueConcreteSubtype(); |
61 public RiType arrayOf() { | |
62 return compiler.getVMEntries().RiType_arrayOf(this); | |
63 } | |
64 | 35 |
65 @Override | 36 public RiType exactType(); |
66 public RiType componentType() { | |
67 return compiler.getVMEntries().RiType_componentType(this); | |
68 } | |
69 | 37 |
70 @Override | 38 public CiConstant getEncoding(Representation r); |
71 public RiType uniqueConcreteSubtype() { | |
72 return compiler.getVMEntries().RiType_uniqueConcreteSubtype(this); | |
73 } | |
74 | 39 |
75 @Override | 40 public CiKind getRepresentationKind(Representation r); |
76 public RiType exactType() { | |
77 if (Modifier.isFinal(accessFlags)) { | |
78 return this; | |
79 } | |
80 return null; | |
81 } | |
82 | 41 |
83 @Override | 42 public boolean hasFinalizableSubclass(); |
84 public CiConstant getEncoding(Representation r) { | |
85 switch (r) { | |
86 case JavaClass: | |
87 return CiConstant.forObject(javaClass()); | |
88 case ObjectHub: | |
89 return CiConstant.forObject(this); | |
90 case StaticFields: | |
91 return CiConstant.forObject(this); | |
92 case TypeInfo: | |
93 return CiConstant.forObject(this); | |
94 default: | |
95 return null; | |
96 } | |
97 } | |
98 | 43 |
99 @Override | 44 public boolean hasFinalizer(); |
100 public CiKind getRepresentationKind(Representation r) { | |
101 return CiKind.Object; | |
102 } | |
103 | 45 |
104 @Override | 46 public boolean hasSubclass(); |
105 public boolean hasFinalizableSubclass() { | |
106 return hasFinalizableSubclass; | |
107 } | |
108 | 47 |
109 @Override | 48 public boolean isArrayClass(); |
110 public boolean hasFinalizer() { | |
111 return hasFinalizer; | |
112 } | |
113 | 49 |
114 @Override | 50 public boolean isInitialized(); |
115 public boolean hasSubclass() { | |
116 return hasSubclass; | |
117 } | |
118 | 51 |
119 @Override | 52 public boolean isInstance(Object obj); |
120 public boolean isArrayClass() { | |
121 return isArrayClass; | |
122 } | |
123 | 53 |
124 @Override | 54 public boolean isInstanceClass(); |
125 public boolean isInitialized() { | |
126 return isInitialized; | |
127 } | |
128 | 55 |
129 @Override | 56 public boolean isInterface(); |
130 public boolean isInstance(Object obj) { | |
131 return javaMirror.isInstance(obj); | |
132 } | |
133 | 57 |
134 @Override | 58 public boolean isResolved(); |
135 public boolean isInstanceClass() { | |
136 return isInstanceClass; | |
137 } | |
138 | 59 |
139 @Override | 60 public boolean isSubtypeOf(RiType other); |
140 public boolean isInterface() { | |
141 return isInterface; | |
142 } | |
143 | 61 |
144 @Override | 62 public Class<?> javaClass(); |
145 public boolean isResolved() { | |
146 return true; | |
147 } | |
148 | 63 |
149 @Override | 64 public CiKind kind(); |
150 public boolean isSubtypeOf(RiType other) { | |
151 if (other instanceof HotSpotTypeResolved) { | |
152 return compiler.getVMEntries().RiType_isSubtypeOf(this, other); | |
153 } | |
154 // No resolved type is a subtype of an unresolved type. | |
155 return false; | |
156 } | |
157 | 65 |
158 @Override | 66 public RiMethod resolveMethodImpl(RiMethod method); |
159 public Class<?> javaClass() { | |
160 return javaMirror; | |
161 } | |
162 | 67 |
163 @Override | 68 public String toString(); |
164 public CiKind kind() { | |
165 return CiKind.Object; | |
166 } | |
167 | 69 |
168 @Override | 70 public RiConstantPool constantPool(); |
169 public RiMethod resolveMethodImpl(RiMethod method) { | |
170 assert method instanceof HotSpotMethod; | |
171 return compiler.getVMEntries().RiType_resolveMethodImpl(this, method.name(), method.signature().asString()); | |
172 } | |
173 | 71 |
174 @Override | 72 public int instanceSize(); |
175 public String toString() { | |
176 return "HotSpotType<" + simpleName + ", resolved>"; | |
177 } | |
178 | 73 |
179 public RiConstantPool constantPool() { | 74 public RiField createRiField(String name, RiType type, int offset); |
180 // TODO: Implement constant pool without the need for VmId and cache the constant pool. | |
181 return compiler.getVMEntries().RiType_constantPool(this); | |
182 } | |
183 | |
184 public int instanceSize() { | |
185 return instanceSize; | |
186 } | |
187 | |
188 public RiField createRiField(String name, RiType type, int offset) { | |
189 RiField result = null; | |
190 | |
191 // (tw) Must cache the fields, because the local load elimination only works if the objects from two field lookups are equal. | |
192 if (fieldCache == null) { | |
193 fieldCache = new HashMap<Integer, RiField>(8); | |
194 } else { | |
195 result = fieldCache.get(offset); | |
196 } | |
197 | |
198 if (result == null) { | |
199 result = new HotSpotField(compiler, this, name, type, offset); | |
200 fieldCache.put(offset, result); | |
201 } | |
202 | |
203 return result; | |
204 } | |
205 | 75 |
206 } | 76 } |