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 */
23package jdk.vm.ci.hotspot;
24
25import static java.util.Objects.requireNonNull;
26
27import java.lang.annotation.Annotation;
28import java.lang.reflect.Array;
29import java.lang.reflect.Modifier;
30
31import jdk.vm.ci.common.JVMCIError;
32import jdk.vm.ci.meta.Assumptions.AssumptionResult;
33import jdk.vm.ci.meta.JavaConstant;
34import jdk.vm.ci.meta.JavaKind;
35import jdk.vm.ci.meta.JavaType;
36import jdk.vm.ci.meta.ResolvedJavaField;
37import jdk.vm.ci.meta.ResolvedJavaMethod;
38import jdk.vm.ci.meta.ResolvedJavaType;
39
40/**
41 * Implementation of {@link JavaType} for primitive HotSpot types.
42 */
43public 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 HotSpotJVMCIRuntimeProvider#fromClass(Class)} instead.
53     * </p>
54     *
55     * @param kind the Kind to create the mirror for
56     */
57    public 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
64    public int getModifiers() {
65        return Modifier.ABSTRACT | Modifier.FINAL | Modifier.PUBLIC;
66    }
67
68    @Override
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    public ResolvedJavaType getElementalType() {
78        return this;
79    }
80
81    @Override
82    public ResolvedJavaType getComponentType() {
83        return null;
84    }
85
86    @Override
87    public ResolvedJavaType getSuperclass() {
88        return null;
89    }
90
91    @Override
92    public ResolvedJavaType[] getInterfaces() {
93        return new ResolvedJavaType[0];
94    }
95
96    @Override
97    public ResolvedJavaType getSingleImplementor() {
98        throw new JVMCIError("Cannot call getSingleImplementor() on a non-interface type: %s", this);
99    }
100
101    @Override
102    public ResolvedJavaType findLeastCommonAncestor(ResolvedJavaType otherType) {
103        return null;
104    }
105
106    @Override
107    public AssumptionResult<Boolean> hasFinalizableSubclass() {
108        return new AssumptionResult<>(false);
109    }
110
111    @Override
112    public boolean hasFinalizer() {
113        return false;
114    }
115
116    @Override
117    public boolean isArray() {
118        return false;
119    }
120
121    @Override
122    public boolean isPrimitive() {
123        return true;
124    }
125
126    @Override
127    public boolean isInitialized() {
128        return true;
129    }
130
131    public boolean isLinked() {
132        return true;
133    }
134
135    @Override
136    public boolean isInstance(JavaConstant obj) {
137        return false;
138    }
139
140    @Override
141    public boolean isInstanceClass() {
142        return false;
143    }
144
145    @Override
146    public boolean isInterface() {
147        return false;
148    }
149
150    @Override
151    public boolean isAssignableFrom(ResolvedJavaType other) {
152        assert other != null;
153        return other.equals(this);
154    }
155
156    @Override
157    public ResolvedJavaType getHostClass() {
158        return null;
159    }
160
161    @Override
162    public JavaKind getJavaKind() {
163        return kind;
164    }
165
166    @Override
167    public boolean isJavaLangObject() {
168        return false;
169    }
170
171    @Override
172    public ResolvedJavaMethod resolveMethod(ResolvedJavaMethod method, ResolvedJavaType callerType) {
173        return null;
174    }
175
176    @Override
177    public String toString() {
178        return "HotSpotResolvedPrimitiveType<" + kind + ">";
179    }
180
181    @Override
182    public AssumptionResult<ResolvedJavaType> findLeafConcreteSubtype() {
183        return new AssumptionResult<>(this);
184    }
185
186    @Override
187    public AssumptionResult<ResolvedJavaMethod> findUniqueConcreteMethod(ResolvedJavaMethod method) {
188        return null;
189    }
190
191    @Override
192    public ResolvedJavaField[] getInstanceFields(boolean includeSuperclasses) {
193        return new ResolvedJavaField[0];
194    }
195
196    @Override
197    public ResolvedJavaField[] getStaticFields() {
198        return new ResolvedJavaField[0];
199    }
200
201    @Override
202    public Annotation[] getAnnotations() {
203        return new Annotation[0];
204    }
205
206    @Override
207    public Annotation[] getDeclaredAnnotations() {
208        return new Annotation[0];
209    }
210
211    @Override
212    public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
213        return null;
214    }
215
216    @Override
217    public ResolvedJavaType resolve(ResolvedJavaType accessingClass) {
218        requireNonNull(accessingClass);
219        return this;
220    }
221
222    @Override
223    public void initialize() {
224    }
225
226    @Override
227    public ResolvedJavaField findInstanceFieldWithOffset(long offset, JavaKind expectedType) {
228        return null;
229    }
230
231    @Override
232    public String getSourceFileName() {
233        throw JVMCIError.unimplemented();
234    }
235
236    @Override
237    public Class<?> mirror() {
238        return kind.toJavaClass();
239    }
240
241    @Override
242    public boolean isLocal() {
243        return false;
244    }
245
246    @Override
247    public boolean isMember() {
248        return false;
249    }
250
251    @Override
252    public ResolvedJavaType getEnclosingType() {
253        return null;
254    }
255
256    @Override
257    public ResolvedJavaMethod[] getDeclaredConstructors() {
258        return new ResolvedJavaMethod[0];
259    }
260
261    @Override
262    public ResolvedJavaMethod[] getDeclaredMethods() {
263        return new ResolvedJavaMethod[0];
264    }
265
266    @Override
267    public ResolvedJavaMethod getClassInitializer() {
268        return null;
269    }
270
271    @Override
272    public boolean isCloneableWithAllocation() {
273        return false;
274    }
275}
276