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.*;
  26 
  27 import java.lang.annotation.*;
  28 import java.lang.reflect.*;
  29 import java.net.*;
  30 
  31 import jdk.vm.ci.common.*;
  32 import jdk.vm.ci.meta.*;
  33 import jdk.vm.ci.meta.Assumptions.AssumptionResult;
  34 
  35 /**
  36  * Implementation of {@link JavaType} for primitive HotSpot types.
  37  */
  38 public final class HotSpotResolvedPrimitiveType extends HotSpotResolvedJavaType implements HotSpotProxified {
  39 
  40     private final JavaKind kind;
  41 
  42     /**
  43      * Creates the JVMCI mirror for a primitive {@link JavaKind}.
  44      *
  45      * <p>
  46      * <b>NOTE</b>: Creating an instance of this class does not install the mirror for the
  47      * {@link Class} type. Use {@link HotSpotJVMCIRuntimeProvider#fromClass(Class)} instead.
  48      * </p>
  49      *
  50      * @param kind the Kind to create the mirror for
  51      */
  52     public HotSpotResolvedPrimitiveType(JavaKind kind) {
  53         super(String.valueOf(Character.toUpperCase(kind.getTypeChar())));
  54         this.kind = kind;
  55         assert mirror().isPrimitive() : mirror() + " not a primitive type";
  56     }
  57 
  58     @Override
  59     public int getModifiers() {
  60         return Modifier.ABSTRACT | Modifier.FINAL | Modifier.PUBLIC;
  61     }
  62 
  63     @Override
  64     public HotSpotResolvedObjectTypeImpl getArrayClass() {
  65         if (kind == JavaKind.Void) {
  66             return null;
  67         }
  68         Class<?> javaArrayMirror = Array.newInstance(mirror(), 0).getClass();
  69         return HotSpotResolvedObjectTypeImpl.fromObjectClass(javaArrayMirror);
  70     }
  71 
  72     public ResolvedJavaType getElementalType() {
  73         return this;
  74     }
  75 
  76     @Override
  77     public ResolvedJavaType getComponentType() {
  78         return null;
  79     }
  80 
  81     @Override
  82     public ResolvedJavaType asExactType() {
  83         return this;
  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 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 JavaKind getJavaKind() {
 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 Annotation[] getAnnotations() {
 213         return new Annotation[0];
 214     }
 215 
 216     @Override
 217     public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
 218         return null;
 219     }
 220 
 221     @Override
 222     public ResolvedJavaType resolve(ResolvedJavaType accessingClass) {
 223         requireNonNull(accessingClass);
 224         return this;
 225     }
 226 
 227     @Override
 228     public void initialize() {
 229     }
 230 
 231     @Override
 232     public ResolvedJavaField findInstanceFieldWithOffset(long offset, JavaKind expectedType) {
 233         return null;
 234     }
 235 
 236     @Override
 237     public String getSourceFileName() {
 238         throw JVMCIError.unimplemented();
 239     }
 240 
 241     @Override
 242     public Class<?> mirror() {
 243         return kind.toJavaClass();
 244     }
 245 
 246     @Override
 247     public URL getClassFilePath() {
 248         return null;
 249     }
 250 
 251     @Override
 252     public boolean isLocal() {
 253         return false;
 254     }
 255 
 256     @Override
 257     public boolean isMember() {
 258         return false;
 259     }
 260 
 261     @Override
 262     public ResolvedJavaType getEnclosingType() {
 263         return null;
 264     }
 265 
 266     @Override
 267     public ResolvedJavaMethod[] getDeclaredConstructors() {
 268         return new ResolvedJavaMethod[0];
 269     }
 270 
 271     @Override
 272     public ResolvedJavaMethod[] getDeclaredMethods() {
 273         return new ResolvedJavaMethod[0];
 274     }
 275 
 276     @Override
 277     public ResolvedJavaMethod getClassInitializer() {
 278         return null;
 279     }
 280 
 281     @Override
 282     public boolean isTrustedInterfaceType() {
 283         return false;
 284     }
 285 }