1 /* |
1 /* |
2 * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. |
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. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 package jdk.vm.ci.hotspot; |
23 package jdk.vm.ci.hotspot; |
24 |
24 |
25 import static java.util.Objects.requireNonNull; |
25 import static java.util.Objects.requireNonNull; |
|
26 import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime; |
26 |
27 |
27 import java.lang.annotation.Annotation; |
28 import java.lang.annotation.Annotation; |
28 import java.lang.reflect.Array; |
|
29 import java.lang.reflect.Modifier; |
29 import java.lang.reflect.Modifier; |
30 |
30 |
31 import jdk.vm.ci.common.JVMCIError; |
31 import jdk.vm.ci.common.JVMCIError; |
|
32 import jdk.vm.ci.common.NativeImageReinitialize; |
32 import jdk.vm.ci.meta.Assumptions.AssumptionResult; |
33 import jdk.vm.ci.meta.Assumptions.AssumptionResult; |
33 import jdk.vm.ci.meta.JavaConstant; |
34 import jdk.vm.ci.meta.JavaConstant; |
34 import jdk.vm.ci.meta.JavaKind; |
35 import jdk.vm.ci.meta.JavaKind; |
35 import jdk.vm.ci.meta.JavaType; |
36 import jdk.vm.ci.meta.JavaType; |
36 import jdk.vm.ci.meta.ResolvedJavaField; |
37 import jdk.vm.ci.meta.ResolvedJavaField; |
40 /** |
41 /** |
41 * Implementation of {@link JavaType} for primitive HotSpot types. |
42 * Implementation of {@link JavaType} for primitive HotSpot types. |
42 */ |
43 */ |
43 public final class HotSpotResolvedPrimitiveType extends HotSpotResolvedJavaType { |
44 public final class HotSpotResolvedPrimitiveType extends HotSpotResolvedJavaType { |
44 |
45 |
45 private final JavaKind kind; |
46 @NativeImageReinitialize static HotSpotResolvedPrimitiveType[] primitives; |
|
47 |
|
48 private JavaKind kind; |
|
49 private HotSpotResolvedObjectType arrayClass; |
|
50 HotSpotObjectConstantImpl mirror; |
46 |
51 |
47 /** |
52 /** |
48 * Creates the JVMCI mirror for a primitive {@link JavaKind}. |
53 * Creates the JVMCI mirror for a primitive {@link JavaKind}. |
49 * |
54 * |
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 |
55 * @param kind the Kind to create the mirror for |
56 */ |
56 */ |
57 HotSpotResolvedPrimitiveType(JavaKind kind) { |
57 private HotSpotResolvedPrimitiveType(JavaKind kind, HotSpotObjectConstantImpl mirror) { |
58 super(String.valueOf(kind.getTypeChar())); |
58 super(String.valueOf(kind.getTypeChar())); |
|
59 this.mirror = mirror; |
59 this.kind = kind; |
60 this.kind = kind; |
60 assert mirror().isPrimitive() : mirror() + " not a primitive type"; |
61 } |
|
62 |
|
63 static HotSpotResolvedPrimitiveType forKind(JavaKind kind) { |
|
64 HotSpotResolvedPrimitiveType primitive = primitives[kind.getBasicType()]; |
|
65 assert primitive != null : kind; |
|
66 return primitive; |
|
67 } |
|
68 |
|
69 @VMEntryPoint |
|
70 static HotSpotResolvedPrimitiveType fromMetaspace(HotSpotObjectConstantImpl mirror, char typeChar) { |
|
71 JavaKind kind = JavaKind.fromPrimitiveOrVoidTypeChar(typeChar); |
|
72 if (primitives == null) { |
|
73 primitives = new HotSpotResolvedPrimitiveType[JavaKind.Void.getBasicType() + 1]; |
|
74 } |
|
75 HotSpotResolvedPrimitiveType result = new HotSpotResolvedPrimitiveType(kind, mirror); |
|
76 primitives[kind.getBasicType()] = result; |
|
77 return result; |
61 } |
78 } |
62 |
79 |
63 @Override |
80 @Override |
64 public int getModifiers() { |
81 public int getModifiers() { |
65 return Modifier.ABSTRACT | Modifier.FINAL | Modifier.PUBLIC; |
82 return Modifier.ABSTRACT | Modifier.FINAL | Modifier.PUBLIC; |
68 @Override |
85 @Override |
69 public HotSpotResolvedObjectType getArrayClass() { |
86 public HotSpotResolvedObjectType getArrayClass() { |
70 if (kind == JavaKind.Void) { |
87 if (kind == JavaKind.Void) { |
71 return null; |
88 return null; |
72 } |
89 } |
73 Class<?> javaArrayMirror = Array.newInstance(mirror(), 0).getClass(); |
90 if (arrayClass == null) { |
74 return HotSpotResolvedObjectTypeImpl.fromObjectClass(javaArrayMirror); |
91 try { |
|
92 arrayClass = (HotSpotResolvedObjectType) runtime().compilerToVm.lookupType("[" + kind.getTypeChar(), null, true); |
|
93 } catch (ClassNotFoundException e) { |
|
94 throw new JVMCIError(e); |
|
95 } |
|
96 } |
|
97 return arrayClass; |
75 } |
98 } |
76 |
99 |
77 @Override |
100 @Override |
78 public ResolvedJavaType getElementalType() { |
101 public ResolvedJavaType getElementalType() { |
79 return this; |
102 return this; |