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