Mercurial > hg > graal-jvmci-8
annotate jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/NameAndSignature.java @ 24148:4f3ad306ac6e jvmci-0.28
Process _jvmci_loader_parent oop along _jvmci_loader
author | Gilles Duboscq <gilles.m.duboscq@oracle.com> |
---|---|
date | Fri, 16 Jun 2017 19:28:31 +0200 |
parents | 4b58c92e939b |
children |
rev | line source |
---|---|
7044
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1 /* |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
4 * |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
8 * |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
14 * |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
18 * |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
21 * questions. |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
22 */ |
22672
1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22569
diff
changeset
|
23 package jdk.vm.ci.runtime.test; |
7044
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
24 |
22569
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
25 import java.lang.reflect.Method; |
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
26 import java.util.Arrays; |
7044
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
27 |
22672
1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22569
diff
changeset
|
28 import jdk.vm.ci.meta.MetaAccessProvider; |
1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22569
diff
changeset
|
29 import jdk.vm.ci.meta.ResolvedJavaMethod; |
1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22569
diff
changeset
|
30 import jdk.vm.ci.meta.ResolvedJavaType; |
1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22569
diff
changeset
|
31 import jdk.vm.ci.meta.Signature; |
1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22569
diff
changeset
|
32 import jdk.vm.ci.runtime.JVMCI; |
7044
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
33 |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
34 class NameAndSignature { |
7096
585fc9f79ebc
Remove ResolvedJavaType.isClass()
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7044
diff
changeset
|
35 |
21663
381ab4105afe
moved com.oracle.graal.java.test to com.oracle.jvmci.runtime.test
Doug Simon <doug.simon@oracle.com>
parents:
21556
diff
changeset
|
36 public static final MetaAccessProvider metaAccess = JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess(); |
7096
585fc9f79ebc
Remove ResolvedJavaType.isClass()
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7044
diff
changeset
|
37 |
7044
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
38 final String name; |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
12488
diff
changeset
|
39 final Class<?> returnType; |
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
12488
diff
changeset
|
40 final Class<?>[] parameterTypes; |
7044
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
41 |
23297
4b58c92e939b
remove redundant modifiers
Manuel Rigger <rigger.manuel@gmail.com>
parents:
22672
diff
changeset
|
42 NameAndSignature(Method m) { |
7044
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
43 this.name = m.getName(); |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
44 this.returnType = m.getReturnType(); |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
45 this.parameterTypes = m.getParameterTypes(); |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
46 } |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
47 |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
48 @Override |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
49 public boolean equals(Object obj) { |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
50 if (obj instanceof NameAndSignature) { |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
51 NameAndSignature s = (NameAndSignature) obj; |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
52 return s.returnType == returnType && name.equals(s.name) && Arrays.equals(s.parameterTypes, parameterTypes); |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
53 } |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
54 return false; |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
55 } |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
56 |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
57 @Override |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
58 public int hashCode() { |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
59 return name.hashCode(); |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
60 } |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
61 |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
62 @Override |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
63 public String toString() { |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
64 StringBuilder sb = new StringBuilder(name + "("); |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
65 String sep = ""; |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
12488
diff
changeset
|
66 for (Class<?> p : parameterTypes) { |
7044
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
67 sb.append(sep); |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
68 sep = ", "; |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
69 sb.append(p.getName()); |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
70 } |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
71 return sb.append(')').append(returnType.getName()).toString(); |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
72 } |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
73 |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
74 public boolean signatureEquals(ResolvedJavaMethod m) { |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
75 Signature s = m.getSignature(); |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
76 ResolvedJavaType declaringClass = m.getDeclaringClass(); |
12488
1a4dc163cd0a
abstracted HotSpotGraalRuntime as a RuntimeProvider which removes the recent selector addition to the Graal capabilities API and also makes Truffle independent of the graal.hotspot project (GRAAL-363)
Doug Simon <doug.simon@oracle.com>
parents:
7096
diff
changeset
|
77 if (!s.getReturnType(declaringClass).resolve(declaringClass).equals(metaAccess.lookupJavaType(returnType))) { |
7044
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
78 return false; |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
79 } |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
80 if (s.getParameterCount(false) != parameterTypes.length) { |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
81 return false; |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
82 } |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
83 for (int i = 0; i < parameterTypes.length; i++) { |
12488
1a4dc163cd0a
abstracted HotSpotGraalRuntime as a RuntimeProvider which removes the recent selector addition to the Graal capabilities API and also makes Truffle independent of the graal.hotspot project (GRAAL-363)
Doug Simon <doug.simon@oracle.com>
parents:
7096
diff
changeset
|
84 if (!s.getParameterType(i, declaringClass).resolve(declaringClass).equals(metaAccess.lookupJavaType(parameterTypes[i]))) { |
7044
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
85 return false; |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
86 } |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
87 } |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
88 return true; |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
89 } |
34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
90 } |