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