1 /*
2  * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 package jdk.vm.ci.hotspot;
24 
25 import static java.util.Objects.requireNonNull;
26 
27 import java.lang.annotation.Annotation;
28 import java.lang.reflect.Array;
29 import java.lang.reflect.Modifier;
30 
31 import jdk.vm.ci.common.JVMCIError;
32 import jdk.vm.ci.meta.Assumptions.AssumptionResult;
33 import jdk.vm.ci.meta.JavaConstant;
34 import jdk.vm.ci.meta.JavaKind;
35 import jdk.vm.ci.meta.JavaType;
36 import jdk.vm.ci.meta.ResolvedJavaField;
37 import jdk.vm.ci.meta.ResolvedJavaMethod;
38 import jdk.vm.ci.meta.ResolvedJavaType;
39 
40 /**
41  * Implementation of {@link JavaType} for primitive HotSpot types.
42  */
43 public final class HotSpotResolvedPrimitiveType extends HotSpotResolvedJavaType {
44 
45     private final JavaKind kind;
46 
47     /**
48      * Creates the JVMCI mirror for a primitive {@link JavaKind}.
49      *
50      * <p>
51      * <b>NOTE</b>: Creating an instance of this class does not install the mirror for the
52      * {@link Class} type. Use {@link HotSpotJVMCIRuntime#fromClass(Class)} instead.
53      * </p>
54      *
55      * @param kind the Kind to create the mirror for
56      */
HotSpotResolvedPrimitiveType(JavaKind kind)57     HotSpotResolvedPrimitiveType(JavaKind kind) {
58         super(String.valueOf(kind.getTypeChar()));
59         this.kind = kind;
60         assert mirror().isPrimitive() : mirror() + " not a primitive type";
61     }
62 
63     @Override
getModifiers()64     public int getModifiers() {
65         return Modifier.ABSTRACT | Modifier.FINAL | Modifier.PUBLIC;
66     }
67 
68     @Override
getArrayClass()69     public HotSpotResolvedObjectTypeImpl getArrayClass() {
70         if (kind == JavaKind.Void) {
71             return null;
72         }
73         Class<?> javaArrayMirror = Array.newInstance(mirror(), 0).getClass();
74         return HotSpotResolvedObjectTypeImpl.fromObjectClass(javaArrayMirror);
75     }
76 
77     @Override
getElementalType()78     public ResolvedJavaType getElementalType() {
79         return this;
80     }
81 
82     @Override
getComponentType()83     public ResolvedJavaType getComponentType() {
84         return null;
85     }
86 
87     @Override
getSuperclass()88     public ResolvedJavaType getSuperclass() {
89         return null;
90     }
91 
92     @Override
getInterfaces()93     public ResolvedJavaType[] getInterfaces() {
94         return new ResolvedJavaType[0];
95     }
96 
97     @Override
getSingleImplementor()98     public ResolvedJavaType getSingleImplementor() {
99         throw new JVMCIError("Cannot call getSingleImplementor() on a non-interface type: %s", this);
100     }
101 
102     @Override
findLeastCommonAncestor(ResolvedJavaType otherType)103     public ResolvedJavaType findLeastCommonAncestor(ResolvedJavaType otherType) {
104         return null;
105     }
106 
107     @Override
hasFinalizableSubclass()108     public AssumptionResult<Boolean> hasFinalizableSubclass() {
109         return new AssumptionResult<>(false);
110     }
111 
112     @Override
hasFinalizer()113     public boolean hasFinalizer() {
114         return false;
115     }
116 
117     @Override
isArray()118     public boolean isArray() {
119         return false;
120     }
121 
122     @Override
isEnum()123     public boolean isEnum() {
124         return false;
125     }
126 
127     @Override
isPrimitive()128     public boolean isPrimitive() {
129         return true;
130     }
131 
132     @Override
isInitialized()133     public boolean isInitialized() {
134         return true;
135     }
136 
137     @Override
isLinked()138     public boolean isLinked() {
139         return true;
140     }
141 
142     @Override
isInstance(JavaConstant obj)143     public boolean isInstance(JavaConstant obj) {
144         return false;
145     }
146 
147     @Override
isInstanceClass()148     public boolean isInstanceClass() {
149         return false;
150     }
151 
152     @Override
isInterface()153     public boolean isInterface() {
154         return false;
155     }
156 
157     @Override
isAssignableFrom(ResolvedJavaType other)158     public boolean isAssignableFrom(ResolvedJavaType other) {
159         assert other != null;
160         return other.equals(this);
161     }
162 
163     @Override
getHostClass()164     public ResolvedJavaType getHostClass() {
165         return null;
166     }
167 
168     @Override
getJavaKind()169     public JavaKind getJavaKind() {
170         return kind;
171     }
172 
173     @Override
isJavaLangObject()174     public boolean isJavaLangObject() {
175         return false;
176     }
177 
178     @Override
resolveMethod(ResolvedJavaMethod method, ResolvedJavaType callerType)179     public ResolvedJavaMethod resolveMethod(ResolvedJavaMethod method, ResolvedJavaType callerType) {
180         return null;
181     }
182 
183     @Override
toString()184     public String toString() {
185         return "HotSpotResolvedPrimitiveType<" + kind + ">";
186     }
187 
188     @Override
findLeafConcreteSubtype()189     public AssumptionResult<ResolvedJavaType> findLeafConcreteSubtype() {
190         return new AssumptionResult<>(this);
191     }
192 
193     @Override
findUniqueConcreteMethod(ResolvedJavaMethod method)194     public AssumptionResult<ResolvedJavaMethod> findUniqueConcreteMethod(ResolvedJavaMethod method) {
195         return null;
196     }
197 
198     @Override
getInstanceFields(boolean includeSuperclasses)199     public ResolvedJavaField[] getInstanceFields(boolean includeSuperclasses) {
200         return new ResolvedJavaField[0];
201     }
202 
203     @Override
getStaticFields()204     public ResolvedJavaField[] getStaticFields() {
205         return new ResolvedJavaField[0];
206     }
207 
208     @Override
getAnnotations()209     public Annotation[] getAnnotations() {
210         return new Annotation[0];
211     }
212 
213     @Override
getDeclaredAnnotations()214     public Annotation[] getDeclaredAnnotations() {
215         return new Annotation[0];
216     }
217 
218     @Override
getAnnotation(Class<T> annotationClass)219     public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
220         return null;
221     }
222 
223     @Override
resolve(ResolvedJavaType accessingClass)224     public ResolvedJavaType resolve(ResolvedJavaType accessingClass) {
225         requireNonNull(accessingClass);
226         return this;
227     }
228 
229     @Override
initialize()230     public void initialize() {
231     }
232 
233     @Override
link()234     public void link() {
235     }
236 
237     @Override
hasDefaultMethods()238     public boolean hasDefaultMethods() {
239         return false;
240     }
241 
242     @Override
declaresDefaultMethods()243     public boolean declaresDefaultMethods() {
244         return false;
245     }
246 
247     @Override
findInstanceFieldWithOffset(long offset, JavaKind expectedType)248     public ResolvedJavaField findInstanceFieldWithOffset(long offset, JavaKind expectedType) {
249         return null;
250     }
251 
252     @Override
getSourceFileName()253     public String getSourceFileName() {
254         throw JVMCIError.unimplemented();
255     }
256 
257     @Override
mirror()258     Class<?> mirror() {
259         return kind.toJavaClass();
260     }
261 
262     @Override
isLocal()263     public boolean isLocal() {
264         return false;
265     }
266 
267     @Override
isMember()268     public boolean isMember() {
269         return false;
270     }
271 
272     @Override
getEnclosingType()273     public ResolvedJavaType getEnclosingType() {
274         return null;
275     }
276 
277     @Override
getDeclaredConstructors()278     public ResolvedJavaMethod[] getDeclaredConstructors() {
279         return new ResolvedJavaMethod[0];
280     }
281 
282     @Override
getDeclaredMethods()283     public ResolvedJavaMethod[] getDeclaredMethods() {
284         return new ResolvedJavaMethod[0];
285     }
286 
287     @Override
getClassInitializer()288     public ResolvedJavaMethod getClassInitializer() {
289         return null;
290     }
291 
292     @Override
isCloneableWithAllocation()293     public boolean isCloneableWithAllocation() {
294         return false;
295     }
296 }
297