1 /*
   2  * Copyright (c) 2011, 2015, 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 import java.net.URL;
  31 
  32 import jdk.vm.ci.common.JVMCIError;
  33 import jdk.vm.ci.meta.Assumptions.AssumptionResult;
  34 import jdk.vm.ci.meta.JavaConstant;
  35 import jdk.vm.ci.meta.JavaKind;
  36 import jdk.vm.ci.meta.JavaType;
  37 import jdk.vm.ci.meta.ResolvedJavaField;
  38 import jdk.vm.ci.meta.ResolvedJavaMethod;
  39 import jdk.vm.ci.meta.ResolvedJavaType;
  40 
  41 /**
  42  * Implementation of {@link JavaType} for primitive HotSpot types.
  43  */
  44 public final class HotSpotResolvedPrimitiveType extends HotSpotResolvedJavaType implements HotSpotProxified {
  45 
  46     private final JavaKind kind;
  47 
  48     /**
  49      * Creates the JVMCI mirror for a primitive {@link JavaKind}.
  50      *
  51      * <p>
  52      * <b>NOTE</b>: Creating an instance of this class does not install the mirror for the
  53      * {@link Class} type. Use {@link HotSpotJVMCIRuntimeProvider#fromClass(Class)} instead.
  54      * </p>
  55      *
  56      * @param kind the Kind to create the mirror for
  57      */
  58     public HotSpotResolvedPrimitiveType(JavaKind kind) {
  59         super(String.valueOf(Character.toUpperCase(kind.getTypeChar())));
  60         this.kind = kind;
  61         assert mirror().isPrimitive() : mirror() + " not a primitive type";
  62     }
  63 
  64     @Override
  65     public int getModifiers() {
  66         return Modifier.ABSTRACT | Modifier.FINAL | Modifier.PUBLIC;
  67     }
  68 
  69     @Override
  70     public HotSpotResolvedObjectTypeImpl getArrayClass() {
  71         if (kind == JavaKind.Void) {
  72             return null;
  73         }
  74         Class<?> javaArrayMirror = Array.newInstance(mirror(), 0).getClass();
  75         return HotSpotResolvedObjectTypeImpl.fromObjectClass(javaArrayMirror);
  76     }
  77 
  78     public ResolvedJavaType getElementalType() {
  79         return this;
  80     }
  81 
  82     @Override
  83     public ResolvedJavaType getComponentType() {
  84         return null;
  85     }
  86 
  87     @Override
  88     public ResolvedJavaType asExactType() {
  89         return this;
  90     }
  91 
  92     @Override
  93     public ResolvedJavaType getSuperclass() {
  94         return null;
  95     }
  96 
  97     @Override
  98     public ResolvedJavaType[] getInterfaces() {
  99         return new ResolvedJavaType[0];
 100     }
 101 
 102     @Override
 103     public ResolvedJavaType getSingleImplementor() {
 104         throw new JVMCIError("Cannot call getSingleImplementor() on a non-interface type: %s", this);
 105     }
 106 
 107     @Override
 108     public ResolvedJavaType findLeastCommonAncestor(ResolvedJavaType otherType) {
 109         return null;
 110     }
 111 
 112     @Override
 113     public JavaConstant getObjectHub() {
 114         throw JVMCIError.unimplemented();
 115     }
 116 
 117     @Override
 118     public JavaConstant getJavaClass() {
 119         throw JVMCIError.unimplemented();
 120     }
 121 
 122     @Override
 123     public AssumptionResult<Boolean> hasFinalizableSubclass() {
 124         return new AssumptionResult<>(false);
 125     }
 126 
 127     @Override
 128     public boolean hasFinalizer() {
 129         return false;
 130     }
 131 
 132     @Override
 133     public boolean isArray() {
 134         return false;
 135     }
 136 
 137     @Override
 138     public boolean isPrimitive() {
 139         return true;
 140     }
 141 
 142     @Override
 143     public boolean isInitialized() {
 144         return true;
 145     }
 146 
 147     public boolean isLinked() {
 148         return true;
 149     }
 150 
 151     @Override
 152     public boolean isInstance(JavaConstant obj) {
 153         return false;
 154     }
 155 
 156     @Override
 157     public boolean isInstanceClass() {
 158         return false;
 159     }
 160 
 161     @Override
 162     public boolean isInterface() {
 163         return false;
 164     }
 165 
 166     @Override
 167     public boolean isAssignableFrom(ResolvedJavaType other) {
 168         assert other != null;
 169         return other.equals(this);
 170     }
 171 
 172     @Override
 173     public JavaKind getJavaKind() {
 174         return kind;
 175     }
 176 
 177     @Override
 178     public boolean isJavaLangObject() {
 179         return false;
 180     }
 181 
 182     @Override
 183     public ResolvedJavaMethod resolveConcreteMethod(ResolvedJavaMethod method, ResolvedJavaType callerType) {
 184         return null;
 185     }
 186 
 187     @Override
 188     public ResolvedJavaMethod resolveMethod(ResolvedJavaMethod method, ResolvedJavaType callerType) {
 189         return null;
 190     }
 191 
 192     @Override
 193     public String toString() {
 194         return "HotSpotResolvedPrimitiveType<" + kind + ">";
 195     }
 196 
 197     @Override
 198     public AssumptionResult<ResolvedJavaType> findLeafConcreteSubtype() {
 199         return new AssumptionResult<>(this);
 200     }
 201 
 202     @Override
 203     public AssumptionResult<ResolvedJavaMethod> findUniqueConcreteMethod(ResolvedJavaMethod method) {
 204         return null;
 205     }
 206 
 207     @Override
 208     public ResolvedJavaField[] getInstanceFields(boolean includeSuperclasses) {
 209         return new ResolvedJavaField[0];
 210     }
 211 
 212     @Override
 213     public ResolvedJavaField[] getStaticFields() {
 214         return new ResolvedJavaField[0];
 215     }
 216 
 217     @Override
 218     public Annotation[] getAnnotations() {
 219         return new Annotation[0];
 220     }
 221 
 222     @Override
 223     public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
 224         return null;
 225     }
 226 
 227     @Override
 228     public ResolvedJavaType resolve(ResolvedJavaType accessingClass) {
 229         requireNonNull(accessingClass);
 230         return this;
 231     }
 232 
 233     @Override
 234     public void initialize() {
 235     }
 236 
 237     @Override
 238     public ResolvedJavaField findInstanceFieldWithOffset(long offset, JavaKind expectedType) {
 239         return null;
 240     }
 241 
 242     @Override
 243     public String getSourceFileName() {
 244         throw JVMCIError.unimplemented();
 245     }
 246 
 247     @Override
 248     public Class<?> mirror() {
 249         return kind.toJavaClass();
 250     }
 251 
 252     @Override
 253     public URL getClassFilePath() {
 254         return null;
 255     }
 256 
 257     @Override
 258     public boolean isLocal() {
 259         return false;
 260     }
 261 
 262     @Override
 263     public boolean isMember() {
 264         return false;
 265     }
 266 
 267     @Override
 268     public ResolvedJavaType getEnclosingType() {
 269         return null;
 270     }
 271 
 272     @Override
 273     public ResolvedJavaMethod[] getDeclaredConstructors() {
 274         return new ResolvedJavaMethod[0];
 275     }
 276 
 277     @Override
 278     public ResolvedJavaMethod[] getDeclaredMethods() {
 279         return new ResolvedJavaMethod[0];
 280     }
 281 
 282     @Override
 283     public ResolvedJavaMethod getClassInitializer() {
 284         return null;
 285     }
 286 
 287     @Override
 288     public boolean isTrustedInterfaceType() {
 289         return false;
 290     }
 291 }