001/*
002 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package jdk.internal.jvmci.hotspot;
024
025import static java.util.Objects.*;
026
027import java.lang.annotation.*;
028import java.lang.reflect.*;
029import java.net.*;
030
031import jdk.internal.jvmci.common.*;
032import jdk.internal.jvmci.meta.*;
033import jdk.internal.jvmci.meta.Assumptions.*;
034
035/**
036 * Implementation of {@link JavaType} for primitive HotSpot types.
037 */
038public final class HotSpotResolvedPrimitiveType extends HotSpotResolvedJavaType implements HotSpotProxified {
039
040    private final Kind kind;
041
042    /**
043     * Creates the JVMCI mirror for a primitive {@link Kind}.
044     *
045     * <p>
046     * <b>NOTE</b>: Creating an instance of this class does not install the mirror for the
047     * {@link Class} type. Use {@link #fromClass(Class)} instead.
048     * </p>
049     *
050     * @param kind the Kind to create the mirror for
051     */
052    public HotSpotResolvedPrimitiveType(Kind kind) {
053        super(String.valueOf(Character.toUpperCase(kind.getTypeChar())));
054        this.kind = kind;
055        assert mirror().isPrimitive() : mirror() + " not a primitive type";
056    }
057
058    @Override
059    public int getModifiers() {
060        return Modifier.ABSTRACT | Modifier.FINAL | Modifier.PUBLIC;
061    }
062
063    @Override
064    public HotSpotResolvedObjectTypeImpl getArrayClass() {
065        if (kind == Kind.Void) {
066            return null;
067        }
068        Class<?> javaArrayMirror = Array.newInstance(mirror(), 0).getClass();
069        return HotSpotResolvedObjectTypeImpl.fromObjectClass(javaArrayMirror);
070    }
071
072    public ResolvedJavaType getElementalType() {
073        return this;
074    }
075
076    @Override
077    public ResolvedJavaType getComponentType() {
078        return null;
079    }
080
081    @Override
082    public ResolvedJavaType asExactType() {
083        return this;
084    }
085
086    @Override
087    public ResolvedJavaType getSuperclass() {
088        return null;
089    }
090
091    @Override
092    public ResolvedJavaType[] getInterfaces() {
093        return new ResolvedJavaType[0];
094    }
095
096    @Override
097    public ResolvedJavaType getSingleImplementor() {
098        throw new JVMCIError("Cannot call getSingleImplementor() on a non-interface type: %s", this);
099    }
100
101    @Override
102    public ResolvedJavaType findLeastCommonAncestor(ResolvedJavaType otherType) {
103        return null;
104    }
105
106    @Override
107    public JavaConstant getObjectHub() {
108        throw JVMCIError.unimplemented();
109    }
110
111    @Override
112    public JavaConstant getJavaClass() {
113        throw JVMCIError.unimplemented();
114    }
115
116    @Override
117    public AssumptionResult<Boolean> hasFinalizableSubclass() {
118        return new AssumptionResult<>(false);
119    }
120
121    @Override
122    public boolean hasFinalizer() {
123        return false;
124    }
125
126    @Override
127    public boolean isArray() {
128        return false;
129    }
130
131    @Override
132    public boolean isPrimitive() {
133        return true;
134    }
135
136    @Override
137    public boolean isInitialized() {
138        return true;
139    }
140
141    public boolean isLinked() {
142        return true;
143    }
144
145    @Override
146    public boolean isInstance(JavaConstant obj) {
147        return false;
148    }
149
150    @Override
151    public boolean isInstanceClass() {
152        return false;
153    }
154
155    @Override
156    public boolean isInterface() {
157        return false;
158    }
159
160    @Override
161    public boolean isAssignableFrom(ResolvedJavaType other) {
162        assert other != null;
163        return other.equals(this);
164    }
165
166    @Override
167    public Kind getKind() {
168        return kind;
169    }
170
171    @Override
172    public boolean isJavaLangObject() {
173        return false;
174    }
175
176    @Override
177    public ResolvedJavaMethod resolveConcreteMethod(ResolvedJavaMethod method, ResolvedJavaType callerType) {
178        return null;
179    }
180
181    @Override
182    public ResolvedJavaMethod resolveMethod(ResolvedJavaMethod method, ResolvedJavaType callerType) {
183        return null;
184    }
185
186    @Override
187    public String toString() {
188        return "HotSpotResolvedPrimitiveType<" + kind + ">";
189    }
190
191    @Override
192    public AssumptionResult<ResolvedJavaType> findLeafConcreteSubtype() {
193        return new AssumptionResult<>(this);
194    }
195
196    @Override
197    public AssumptionResult<ResolvedJavaMethod> findUniqueConcreteMethod(ResolvedJavaMethod method) {
198        return null;
199    }
200
201    @Override
202    public ResolvedJavaField[] getInstanceFields(boolean includeSuperclasses) {
203        return new ResolvedJavaField[0];
204    }
205
206    @Override
207    public ResolvedJavaField[] getStaticFields() {
208        return new ResolvedJavaField[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, Kind 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 URL getClassFilePath() {
243        return null;
244    }
245
246    @Override
247    public boolean isLocal() {
248        return false;
249    }
250
251    @Override
252    public boolean isMember() {
253        return false;
254    }
255
256    @Override
257    public ResolvedJavaType getEnclosingType() {
258        return null;
259    }
260
261    @Override
262    public ResolvedJavaMethod[] getDeclaredConstructors() {
263        return new ResolvedJavaMethod[0];
264    }
265
266    @Override
267    public ResolvedJavaMethod[] getDeclaredMethods() {
268        return new ResolvedJavaMethod[0];
269    }
270
271    @Override
272    public ResolvedJavaMethod getClassInitializer() {
273        return null;
274    }
275
276    @Override
277    public boolean isTrustedInterfaceType() {
278        return false;
279    }
280}