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