1 /* 2 * Copyright (c) 2011, 2019, 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 import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime; 27 28 import java.lang.annotation.Annotation; 29 import java.lang.reflect.Modifier; 30 31 import jdk.vm.ci.common.JVMCIError; 32 import jdk.vm.ci.common.NativeImageReinitialize; 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 { 45 46 @NativeImageReinitialize static HotSpotResolvedPrimitiveType[] primitives; 47 48 private JavaKind kind; 49 HotSpotObjectConstantImpl mirror; 50 51 /** 52 * Creates the JVMCI mirror for a primitive {@link JavaKind}. 53 * 54 * @param kind the Kind to create the mirror for 55 */ HotSpotResolvedPrimitiveType(JavaKind kind, HotSpotObjectConstantImpl mirror)56 private HotSpotResolvedPrimitiveType(JavaKind kind, HotSpotObjectConstantImpl mirror) { 57 super(String.valueOf(kind.getTypeChar())); 58 this.mirror = mirror; 59 this.kind = kind; 60 } 61 forKind(JavaKind kind)62 static HotSpotResolvedPrimitiveType forKind(JavaKind kind) { 63 HotSpotResolvedPrimitiveType primitive = primitives[kind.getBasicType()]; 64 assert primitive != null : kind; 65 return primitive; 66 } 67 68 @VMEntryPoint fromMetaspace(HotSpotObjectConstantImpl mirror, char typeChar)69 static HotSpotResolvedPrimitiveType fromMetaspace(HotSpotObjectConstantImpl mirror, char typeChar) { 70 JavaKind kind = JavaKind.fromPrimitiveOrVoidTypeChar(typeChar); 71 if (primitives == null) { 72 primitives = new HotSpotResolvedPrimitiveType[JavaKind.Void.getBasicType() + 1]; 73 } 74 HotSpotResolvedPrimitiveType result = new HotSpotResolvedPrimitiveType(kind, mirror); 75 primitives[kind.getBasicType()] = result; 76 return result; 77 } 78 79 @Override getModifiers()80 public int getModifiers() { 81 return Modifier.ABSTRACT | Modifier.FINAL | Modifier.PUBLIC; 82 } 83 84 @Override getArrayClass()85 public HotSpotResolvedObjectType getArrayClass() { 86 if (kind == JavaKind.Void) { 87 return null; 88 } 89 return super.getArrayClass(); 90 } 91 92 @Override getElementalType()93 public ResolvedJavaType getElementalType() { 94 return this; 95 } 96 97 @Override getComponentType()98 public ResolvedJavaType getComponentType() { 99 return null; 100 } 101 102 @Override getSuperclass()103 public ResolvedJavaType getSuperclass() { 104 return null; 105 } 106 107 @Override getInterfaces()108 public ResolvedJavaType[] getInterfaces() { 109 return new ResolvedJavaType[0]; 110 } 111 112 @Override getSingleImplementor()113 public ResolvedJavaType getSingleImplementor() { 114 throw new JVMCIError("Cannot call getSingleImplementor() on a non-interface type: %s", this); 115 } 116 117 @Override findLeastCommonAncestor(ResolvedJavaType otherType)118 public ResolvedJavaType findLeastCommonAncestor(ResolvedJavaType otherType) { 119 return null; 120 } 121 122 @Override hasFinalizableSubclass()123 public AssumptionResult<Boolean> hasFinalizableSubclass() { 124 return new AssumptionResult<>(false); 125 } 126 127 @Override hasFinalizer()128 public boolean hasFinalizer() { 129 return false; 130 } 131 132 @Override isArray()133 public boolean isArray() { 134 return false; 135 } 136 137 @Override isEnum()138 public boolean isEnum() { 139 return false; 140 } 141 142 @Override isPrimitive()143 public boolean isPrimitive() { 144 return true; 145 } 146 147 @Override isInitialized()148 public boolean isInitialized() { 149 return true; 150 } 151 152 @Override isBeingInitialized()153 public boolean isBeingInitialized() { 154 return false; 155 } 156 157 @Override isLinked()158 public boolean isLinked() { 159 return true; 160 } 161 162 @Override isInstance(JavaConstant obj)163 public boolean isInstance(JavaConstant obj) { 164 return false; 165 } 166 167 @Override isInstanceClass()168 public boolean isInstanceClass() { 169 return false; 170 } 171 172 @Override isInterface()173 public boolean isInterface() { 174 return false; 175 } 176 177 @Override isAssignableFrom(ResolvedJavaType other)178 public boolean isAssignableFrom(ResolvedJavaType other) { 179 assert other != null; 180 return other.equals(this); 181 } 182 183 @Override getHostClass()184 public ResolvedJavaType getHostClass() { 185 return null; 186 } 187 188 @Override getJavaKind()189 public JavaKind getJavaKind() { 190 return kind; 191 } 192 193 @Override isJavaLangObject()194 public boolean isJavaLangObject() { 195 return false; 196 } 197 198 @Override resolveMethod(ResolvedJavaMethod method, ResolvedJavaType callerType)199 public ResolvedJavaMethod resolveMethod(ResolvedJavaMethod method, ResolvedJavaType callerType) { 200 return null; 201 } 202 203 @Override toString()204 public String toString() { 205 return "HotSpotResolvedPrimitiveType<" + kind + ">"; 206 } 207 208 @Override findLeafConcreteSubtype()209 public AssumptionResult<ResolvedJavaType> findLeafConcreteSubtype() { 210 return new AssumptionResult<>(this); 211 } 212 213 @Override findUniqueConcreteMethod(ResolvedJavaMethod method)214 public AssumptionResult<ResolvedJavaMethod> findUniqueConcreteMethod(ResolvedJavaMethod method) { 215 return null; 216 } 217 218 @Override getInstanceFields(boolean includeSuperclasses)219 public ResolvedJavaField[] getInstanceFields(boolean includeSuperclasses) { 220 return new ResolvedJavaField[0]; 221 } 222 223 @Override getStaticFields()224 public ResolvedJavaField[] getStaticFields() { 225 return new ResolvedJavaField[0]; 226 } 227 228 @Override getAnnotations()229 public Annotation[] getAnnotations() { 230 return new Annotation[0]; 231 } 232 233 @Override getDeclaredAnnotations()234 public Annotation[] getDeclaredAnnotations() { 235 return new Annotation[0]; 236 } 237 238 @Override getAnnotation(Class<T> annotationClass)239 public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { 240 return null; 241 } 242 243 @Override resolve(ResolvedJavaType accessingClass)244 public ResolvedJavaType resolve(ResolvedJavaType accessingClass) { 245 requireNonNull(accessingClass); 246 return this; 247 } 248 249 @Override initialize()250 public void initialize() { 251 } 252 253 @Override link()254 public void link() { 255 } 256 257 @Override hasDefaultMethods()258 public boolean hasDefaultMethods() { 259 return false; 260 } 261 262 @Override declaresDefaultMethods()263 public boolean declaresDefaultMethods() { 264 return false; 265 } 266 267 @Override findInstanceFieldWithOffset(long offset, JavaKind expectedType)268 public ResolvedJavaField findInstanceFieldWithOffset(long offset, JavaKind expectedType) { 269 return null; 270 } 271 272 @Override getSourceFileName()273 public String getSourceFileName() { 274 throw JVMCIError.unimplemented(); 275 } 276 277 @Override isLocal()278 public boolean isLocal() { 279 return false; 280 } 281 282 @Override isMember()283 public boolean isMember() { 284 return false; 285 } 286 287 @Override getEnclosingType()288 public ResolvedJavaType getEnclosingType() { 289 return null; 290 } 291 292 @Override getDeclaredConstructors()293 public ResolvedJavaMethod[] getDeclaredConstructors() { 294 return new ResolvedJavaMethod[0]; 295 } 296 297 @Override getDeclaredMethods()298 public ResolvedJavaMethod[] getDeclaredMethods() { 299 return new ResolvedJavaMethod[0]; 300 } 301 302 @Override getClassInitializer()303 public ResolvedJavaMethod getClassInitializer() { 304 return null; 305 } 306 307 @Override isCloneableWithAllocation()308 public boolean isCloneableWithAllocation() { 309 return false; 310 } 311 312 @Override equals(Object obj)313 public boolean equals(Object obj) { 314 if (!(obj instanceof HotSpotResolvedPrimitiveType)) { 315 return false; 316 } 317 HotSpotResolvedPrimitiveType that = (HotSpotResolvedPrimitiveType) obj; 318 return that.kind == kind; 319 } 320 321 @Override getJavaMirror()322 JavaConstant getJavaMirror() { 323 return runtime().reflection.getJavaMirror(this); 324 } 325 } 326