Mercurial > hg > truffle
comparison c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotTypeResolvedImpl.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 | |
children | 6190d20bd6d6 |
comparison
equal
deleted
inserted
replaced
2284:569d3fe7d65c | 2285:762de4b26788 |
---|---|
1 /* | |
2 * Copyright (c) 2010 Sun Microsystems, Inc. All rights reserved. | |
3 * | |
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 | |
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. | |
8 * | |
9 * U.S. Government Rights - Commercial software. Government users are subject to the Sun | |
10 * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its | |
11 * supplements. | |
12 * | |
13 * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or | |
14 * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks | |
15 * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the | |
16 * U.S. and other countries. | |
17 * | |
18 * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open | |
19 * Company, Ltd. | |
20 */ | |
21 package com.sun.hotspot.c1x; | |
22 | |
23 import java.lang.reflect.*; | |
24 import java.util.*; | |
25 | |
26 import com.sun.cri.ci.*; | |
27 import com.sun.cri.ri.*; | |
28 | |
29 /** | |
30 * Implementation of RiType for resolved non-primitive HotSpot classes. | |
31 * | |
32 * @author Thomas Wuerthinger, Lukas Stadler | |
33 */ | |
34 public class HotSpotTypeResolvedImpl extends HotSpotType implements HotSpotTypeResolved { | |
35 | |
36 private Class javaMirror; | |
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 | |
51 private HotSpotTypeResolvedImpl() { | |
52 super(null); | |
53 } | |
54 | |
55 @Override | |
56 public int accessFlags() { | |
57 return accessFlags; | |
58 } | |
59 | |
60 @Override | |
61 public RiType arrayOf() { | |
62 return compiler.getVMEntries().RiType_arrayOf(this); | |
63 } | |
64 | |
65 @Override | |
66 public RiType componentType() { | |
67 return compiler.getVMEntries().RiType_componentType(this); | |
68 } | |
69 | |
70 @Override | |
71 public RiType uniqueConcreteSubtype() { | |
72 return compiler.getVMEntries().RiType_uniqueConcreteSubtype(this); | |
73 } | |
74 | |
75 @Override | |
76 public RiType exactType() { | |
77 if (Modifier.isFinal(accessFlags)) { | |
78 return this; | |
79 } | |
80 return null; | |
81 } | |
82 | |
83 @Override | |
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 | |
99 @Override | |
100 public CiKind getRepresentationKind(Representation r) { | |
101 return CiKind.Object; | |
102 } | |
103 | |
104 @Override | |
105 public boolean hasFinalizableSubclass() { | |
106 return hasFinalizableSubclass; | |
107 } | |
108 | |
109 @Override | |
110 public boolean hasFinalizer() { | |
111 return hasFinalizer; | |
112 } | |
113 | |
114 @Override | |
115 public boolean hasSubclass() { | |
116 return hasSubclass; | |
117 } | |
118 | |
119 @Override | |
120 public boolean isArrayClass() { | |
121 return isArrayClass; | |
122 } | |
123 | |
124 @Override | |
125 public boolean isInitialized() { | |
126 return isInitialized; | |
127 } | |
128 | |
129 @Override | |
130 public boolean isInstance(Object obj) { | |
131 return javaMirror.isInstance(obj); | |
132 } | |
133 | |
134 @Override | |
135 public boolean isInstanceClass() { | |
136 return isInstanceClass; | |
137 } | |
138 | |
139 @Override | |
140 public boolean isInterface() { | |
141 return isInterface; | |
142 } | |
143 | |
144 @Override | |
145 public boolean isResolved() { | |
146 return true; | |
147 } | |
148 | |
149 @Override | |
150 public boolean isSubtypeOf(RiType other) { | |
151 if (other.isResolved()) { | |
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 | |
158 @Override | |
159 public Class<?> javaClass() { | |
160 return javaMirror; | |
161 } | |
162 | |
163 @Override | |
164 public CiKind kind() { | |
165 return CiKind.Object; | |
166 } | |
167 | |
168 @Override | |
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 | |
174 @Override | |
175 public String toString() { | |
176 return "HotSpotType<" + simpleName + ", resolved>"; | |
177 } | |
178 | |
179 @Override | |
180 public RiConstantPool constantPool() { | |
181 // TODO: Implement constant pool without the need for VmId and cache the constant pool. | |
182 return compiler.getVMEntries().RiType_constantPool(this); | |
183 } | |
184 | |
185 @Override | |
186 public int instanceSize() { | |
187 return instanceSize; | |
188 } | |
189 | |
190 @Override | |
191 public RiField createRiField(String name, RiType type, int offset) { | |
192 RiField result = null; | |
193 | |
194 // (tw) Must cache the fields, because the local load elimination only works if the objects from two field lookups are equal. | |
195 if (fieldCache == null) { | |
196 fieldCache = new HashMap<Integer, RiField>(8); | |
197 } else { | |
198 result = fieldCache.get(offset); | |
199 } | |
200 | |
201 if (result == null) { | |
202 result = new HotSpotField(compiler, this, name, type, offset); | |
203 fieldCache.put(offset, result); | |
204 } | |
205 | |
206 return result; | |
207 } | |
208 | |
209 } |