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 java.util.*;
26
27 import jdk.vm.ci.common.*;
28 import jdk.vm.ci.meta.*;
29
30 /**
31 * Represents a method signature.
32 */
33 public class HotSpotSignature implements Signature {
34
35 private final List<String> parameters = new ArrayList<>();
36 private final String returnType;
37 private final String originalString;
38 private ResolvedJavaType[] parameterTypes;
39 private ResolvedJavaType returnTypeCache;
40 private final HotSpotJVMCIRuntimeProvider runtime;
41
42 public HotSpotSignature(HotSpotJVMCIRuntimeProvider runtime, String signature) {
43 this.runtime = runtime;
44 assert signature.length() > 0;
45 this.originalString = signature;
46
47 if (signature.charAt(0) == '(') {
48 int cur = 1;
114 @Override
115 public JavaKind getParameterKind(int index) {
116 return JavaKind.fromTypeString(parameters.get(index));
117 }
118
119 private static boolean checkValidCache(ResolvedJavaType type, ResolvedJavaType accessingClass) {
120 assert accessingClass != null;
121 if (type == null) {
122 return false;
123 } else if (type instanceof HotSpotResolvedObjectTypeImpl) {
124 return ((HotSpotResolvedObjectTypeImpl) type).isDefinitelyResolvedWithRespectTo(accessingClass);
125 }
126 return true;
127 }
128
129 private static JavaType getUnresolvedOrPrimitiveType(HotSpotJVMCIRuntimeProvider runtime, String name) {
130 if (name.length() == 1) {
131 JavaKind kind = JavaKind.fromPrimitiveOrVoidTypeChar(name.charAt(0));
132 return runtime.getHostJVMCIBackend().getMetaAccess().lookupJavaType(kind.toJavaClass());
133 }
134 return new HotSpotUnresolvedJavaType(name, runtime);
135 }
136
137 @Override
138 public JavaType getParameterType(int index, ResolvedJavaType accessingClass) {
139 if (accessingClass == null) {
140 // Caller doesn't care about resolution context so return an unresolved
141 // or primitive type (primitive type resolution is context free)
142 return getUnresolvedOrPrimitiveType(runtime, parameters.get(index));
143 }
144 if (parameterTypes == null) {
145 parameterTypes = new ResolvedJavaType[parameters.size()];
146 }
147
148 ResolvedJavaType type = parameterTypes[index];
149 if (!checkValidCache(type, accessingClass)) {
150 JavaType result = runtime.lookupType(parameters.get(index), (HotSpotResolvedObjectType) accessingClass, false);
151 if (result instanceof ResolvedJavaType) {
152 type = (ResolvedJavaType) result;
153 parameterTypes[index] = type;
154 } else {
|
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 java.util.ArrayList;
26 import java.util.List;
27
28 import jdk.vm.ci.common.JVMCIError;
29 import jdk.vm.ci.meta.JavaKind;
30 import jdk.vm.ci.meta.JavaType;
31 import jdk.vm.ci.meta.ResolvedJavaType;
32 import jdk.vm.ci.meta.Signature;
33
34 /**
35 * Represents a method signature.
36 */
37 public class HotSpotSignature implements Signature {
38
39 private final List<String> parameters = new ArrayList<>();
40 private final String returnType;
41 private final String originalString;
42 private ResolvedJavaType[] parameterTypes;
43 private ResolvedJavaType returnTypeCache;
44 private final HotSpotJVMCIRuntimeProvider runtime;
45
46 public HotSpotSignature(HotSpotJVMCIRuntimeProvider runtime, String signature) {
47 this.runtime = runtime;
48 assert signature.length() > 0;
49 this.originalString = signature;
50
51 if (signature.charAt(0) == '(') {
52 int cur = 1;
118 @Override
119 public JavaKind getParameterKind(int index) {
120 return JavaKind.fromTypeString(parameters.get(index));
121 }
122
123 private static boolean checkValidCache(ResolvedJavaType type, ResolvedJavaType accessingClass) {
124 assert accessingClass != null;
125 if (type == null) {
126 return false;
127 } else if (type instanceof HotSpotResolvedObjectTypeImpl) {
128 return ((HotSpotResolvedObjectTypeImpl) type).isDefinitelyResolvedWithRespectTo(accessingClass);
129 }
130 return true;
131 }
132
133 private static JavaType getUnresolvedOrPrimitiveType(HotSpotJVMCIRuntimeProvider runtime, String name) {
134 if (name.length() == 1) {
135 JavaKind kind = JavaKind.fromPrimitiveOrVoidTypeChar(name.charAt(0));
136 return runtime.getHostJVMCIBackend().getMetaAccess().lookupJavaType(kind.toJavaClass());
137 }
138 return HotSpotUnresolvedJavaType.create(runtime, name);
139 }
140
141 @Override
142 public JavaType getParameterType(int index, ResolvedJavaType accessingClass) {
143 if (accessingClass == null) {
144 // Caller doesn't care about resolution context so return an unresolved
145 // or primitive type (primitive type resolution is context free)
146 return getUnresolvedOrPrimitiveType(runtime, parameters.get(index));
147 }
148 if (parameterTypes == null) {
149 parameterTypes = new ResolvedJavaType[parameters.size()];
150 }
151
152 ResolvedJavaType type = parameterTypes[index];
153 if (!checkValidCache(type, accessingClass)) {
154 JavaType result = runtime.lookupType(parameters.get(index), (HotSpotResolvedObjectType) accessingClass, false);
155 if (result instanceof ResolvedJavaType) {
156 type = (ResolvedJavaType) result;
157 parameterTypes[index] = type;
158 } else {
|