Mercurial > hg > graal-jvmci-8
annotate jvmci/jdk.vm.ci.meta/src/jdk/vm/ci/meta/MetaUtil.java @ 24226:abc19eb35547
allow java.vm.name and java.vm.version to be initialized from a vm.properties file next to libjvm
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 24 Aug 2017 22:20:40 +0200 |
parents | a123fd9add6b |
children |
rev | line source |
---|---|
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
1 /* |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
2 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
4 * |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
8 * |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
14 * |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
18 * |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
21 * questions. |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@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.meta; |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
24 |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
25 /** |
22672
1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22569
diff
changeset
|
26 * Miscellaneous collection of utility methods used by {@code jdk.vm.ci.meta} and its clients. |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
27 */ |
5541
b4c406861c33
More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5540
diff
changeset
|
28 public class MetaUtil { |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
29 |
9100
d24955427b0b
Remove MetaUtil.getMirrorOrFail; Add necessary functionality to the Graal API so that all previous usages of java.lang.Class can now use ResolvedJavaType
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8610
diff
changeset
|
30 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
31 * Extends the functionality of {@link Class#getSimpleName()} to include a non-empty string for |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
32 * anonymous and local classes. |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
33 * |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
34 * @param clazz the class for which the simple name is being requested |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
35 * @param withEnclosingClass specifies if the returned name should be qualified with the name(s) |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
36 * of the enclosing class/classes of {@code clazz} (if any). This option is ignored |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
37 * if {@code clazz} denotes an anonymous or local class. |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
38 * @return the simple name |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
39 */ |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
40 public static String getSimpleName(Class<?> clazz, boolean withEnclosingClass) { |
23771
a123fd9add6b
Fix printing of nested method classes in MetaUtil, and ensure they do not throw.
Aleksandar Prokopec <aleksandar.prokopec@oracle.com>
parents:
23749
diff
changeset
|
41 String simpleName = null; |
a123fd9add6b
Fix printing of nested method classes in MetaUtil, and ensure they do not throw.
Aleksandar Prokopec <aleksandar.prokopec@oracle.com>
parents:
23749
diff
changeset
|
42 try { |
a123fd9add6b
Fix printing of nested method classes in MetaUtil, and ensure they do not throw.
Aleksandar Prokopec <aleksandar.prokopec@oracle.com>
parents:
23749
diff
changeset
|
43 simpleName = clazz.getSimpleName(); |
a123fd9add6b
Fix printing of nested method classes in MetaUtil, and ensure they do not throw.
Aleksandar Prokopec <aleksandar.prokopec@oracle.com>
parents:
23749
diff
changeset
|
44 } catch (InternalError e) { |
a123fd9add6b
Fix printing of nested method classes in MetaUtil, and ensure they do not throw.
Aleksandar Prokopec <aleksandar.prokopec@oracle.com>
parents:
23749
diff
changeset
|
45 } |
a123fd9add6b
Fix printing of nested method classes in MetaUtil, and ensure they do not throw.
Aleksandar Prokopec <aleksandar.prokopec@oracle.com>
parents:
23749
diff
changeset
|
46 if (simpleName != null && simpleName.length() != 0) { |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
47 if (withEnclosingClass) { |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
48 String prefix = ""; |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
49 Class<?> enclosingClass = clazz; |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
50 while ((enclosingClass = enclosingClass.getEnclosingClass()) != null) { |
7830
a452bd211e43
fix for GRAAL-121 (MetaUtil.getSimpleName() shuffles inner class names for nesting levels >2)
Michael Haupt <michael.haupt@oracle.com>
parents:
7744
diff
changeset
|
51 prefix = enclosingClass.getSimpleName() + "." + prefix; |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
52 } |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
53 return prefix + simpleName; |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
54 } |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
55 return simpleName; |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
56 } |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
57 // Must be an anonymous or local class |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
58 final String name = clazz.getName(); |
23771
a123fd9add6b
Fix printing of nested method classes in MetaUtil, and ensure they do not throw.
Aleksandar Prokopec <aleksandar.prokopec@oracle.com>
parents:
23749
diff
changeset
|
59 int index = name.lastIndexOf('.'); |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
60 return name.substring(index + 1); |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
61 } |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
62 |
23393
1d4ce2d19e52
clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
63 /** |
1d4ce2d19e52
clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
64 * Converts a type name in internal form to an external form. |
1d4ce2d19e52
clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
65 * |
1d4ce2d19e52
clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
66 * @param name the internal name to convert |
1d4ce2d19e52
clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
67 * @param qualified whether the returned name should be qualified with the package name |
1d4ce2d19e52
clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
68 * @param classForNameCompatible specifies if the returned name for array types should be in |
1d4ce2d19e52
clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
69 * {@link Class#forName(String)} format (e.g., {@code "[Ljava.lang.Object;"}, |
1d4ce2d19e52
clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
70 * {@code "[[I"}) or in Java source code format (e.g., {@code "java.lang.Object[]"}, |
1d4ce2d19e52
clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
71 * {@code "int[][]"} ). |
1d4ce2d19e52
clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
72 */ |
1d4ce2d19e52
clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
73 public static String internalNameToJava(String name, boolean qualified, boolean classForNameCompatible) { |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
74 switch (name.charAt(0)) { |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
75 case 'L': { |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
76 String result = name.substring(1, name.length() - 1).replace('/', '.'); |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
77 if (!qualified) { |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
78 final int lastDot = result.lastIndexOf('.'); |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
79 if (lastDot != -1) { |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
80 result = result.substring(lastDot + 1); |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
81 } |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
82 } |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
83 return result; |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
84 } |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
85 case '[': |
7676
ca9061b6694c
getMethodDescriptor does not need to be in the Signature interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7675
diff
changeset
|
86 return classForNameCompatible ? name.replace('/', '.') : internalNameToJava(name.substring(1), qualified, classForNameCompatible) + "[]"; |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
87 default: |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
88 if (name.length() != 1) { |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
89 throw new IllegalArgumentException("Illegal internal name: " + name); |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
90 } |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
91 return JavaKind.fromPrimitiveOrVoidTypeChar(name.charAt(0)).getJavaName(); |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
92 } |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
93 } |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
94 |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
95 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
96 * Convenient shortcut for calling |
16490
cac0a7d1c325
moved profileToString(ProfilingInfo info, ResolvedJavaMethod method, String sep) from MetaUtil to be a default method in ProfilingInfo
Doug Simon <doug.simon@oracle.com>
parents:
16488
diff
changeset
|
97 * {@link #appendLocation(StringBuilder, ResolvedJavaMethod, int)} without having to supply a |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
98 * {@link StringBuilder} instance and convert the result to a string. |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
99 */ |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
100 public static String toLocation(ResolvedJavaMethod method, int bci) { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
101 return appendLocation(new StringBuilder(), method, bci).toString(); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
102 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
103 |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
104 /** |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
105 * Appends a string representation of a location specified by a given method and bci to a given |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
106 * {@link StringBuilder}. If a stack trace element with a non-null file name and non-negative |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
107 * line number is {@linkplain ResolvedJavaMethod#asStackTraceElement(int) available} for the |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
108 * given method, then the string returned is the {@link StackTraceElement#toString()} value of |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
109 * the stack trace element, suffixed by the bci location. For example: |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
110 * |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
111 * <pre> |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
112 * java.lang.String.valueOf(String.java:2930) [bci: 12] |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
113 * </pre> |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
114 * |
16480
10c12d09a8d2
moved format(String format, JavaMethod method) from MetaUtil to be a default method in JavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
16479
diff
changeset
|
115 * Otherwise, the string returned is the value of applying {@link JavaMethod#format(String)} |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
116 * with the format string {@code "%H.%n(%p)"}, suffixed by the bci location. For example: |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
117 * |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
118 * <pre> |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
119 * java.lang.String.valueOf(int) [bci: 12] |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
120 * </pre> |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
121 * |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
122 * @param sb |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
123 * @param method |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
124 * @param bci |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
125 */ |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
126 public static StringBuilder appendLocation(StringBuilder sb, ResolvedJavaMethod method, int bci) { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
127 if (method != null) { |
6539
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6328
diff
changeset
|
128 StackTraceElement ste = method.asStackTraceElement(bci); |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
129 if (ste.getFileName() != null && ste.getLineNumber() > 0) { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
130 sb.append(ste); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
131 } else { |
16480
10c12d09a8d2
moved format(String format, JavaMethod method) from MetaUtil to be a default method in JavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
16479
diff
changeset
|
132 sb.append(method.format("%H.%n(%p)")); |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
133 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
134 } else { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
135 sb.append("Null method"); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
136 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
137 return sb.append(" [bci: ").append(bci).append(']'); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
138 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
139 |
16490
cac0a7d1c325
moved profileToString(ProfilingInfo info, ResolvedJavaMethod method, String sep) from MetaUtil to be a default method in ProfilingInfo
Doug Simon <doug.simon@oracle.com>
parents:
16488
diff
changeset
|
140 static void appendProfile(StringBuilder buf, AbstractJavaProfile<?, ?> profile, int bci, String type, String sep) { |
9760
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9473
diff
changeset
|
141 if (profile != null) { |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
142 AbstractProfiledItem<?>[] pitems = profile.getItems(); |
9760
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9473
diff
changeset
|
143 if (pitems != null) { |
9764 | 144 buf.append(String.format("%s@%d:", type, bci)); |
9760
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9473
diff
changeset
|
145 for (int j = 0; j < pitems.length; j++) { |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
146 AbstractProfiledItem<?> pitem = pitems[j]; |
9760
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9473
diff
changeset
|
147 buf.append(String.format(" %.6f (%s)%s", pitem.getProbability(), pitem.getItem(), sep)); |
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9473
diff
changeset
|
148 } |
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9473
diff
changeset
|
149 if (profile.getNotRecordedProbability() != 0) { |
9764 | 150 buf.append(String.format(" %.6f <other %s>%s", profile.getNotRecordedProbability(), type, sep)); |
9760
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9473
diff
changeset
|
151 } else { |
9764 | 152 buf.append(String.format(" <no other %s>%s", type, sep)); |
9760
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9473
diff
changeset
|
153 } |
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9473
diff
changeset
|
154 } |
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9473
diff
changeset
|
155 } |
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9473
diff
changeset
|
156 } |
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9473
diff
changeset
|
157 |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
158 /** |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
159 * Converts a Java source-language class name into the internal form. |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
160 * |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
161 * @param className the class name |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
162 * @return the internal name form of the class name |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
163 */ |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
164 public static String toInternalName(String className) { |
21963
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
165 if (className.startsWith("[")) { |
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
166 /* Already in the correct array style. */ |
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
167 return className.replace('.', '/'); |
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
168 } |
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
169 |
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
170 StringBuilder result = new StringBuilder(); |
7015
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
171 String base = className; |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
172 while (base.endsWith("[]")) { |
21963
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
173 result.append("["); |
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
174 base = base.substring(0, base.length() - 2); |
7015
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
175 } |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
176 |
21963
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
177 switch (base) { |
16726
734247341e6e
use string switch in MetaUtil
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16715
diff
changeset
|
178 case "boolean": |
21963
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
179 result.append("Z"); |
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
180 break; |
16726
734247341e6e
use string switch in MetaUtil
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16715
diff
changeset
|
181 case "byte": |
21963
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
182 result.append("B"); |
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
183 break; |
16726
734247341e6e
use string switch in MetaUtil
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16715
diff
changeset
|
184 case "short": |
21963
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
185 result.append("S"); |
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
186 break; |
16726
734247341e6e
use string switch in MetaUtil
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16715
diff
changeset
|
187 case "char": |
21963
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
188 result.append("C"); |
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
189 break; |
16726
734247341e6e
use string switch in MetaUtil
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16715
diff
changeset
|
190 case "int": |
21963
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
191 result.append("I"); |
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
192 break; |
16726
734247341e6e
use string switch in MetaUtil
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16715
diff
changeset
|
193 case "float": |
21963
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
194 result.append("F"); |
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
195 break; |
16726
734247341e6e
use string switch in MetaUtil
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16715
diff
changeset
|
196 case "long": |
21963
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
197 result.append("J"); |
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
198 break; |
16726
734247341e6e
use string switch in MetaUtil
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16715
diff
changeset
|
199 case "double": |
21963
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
200 result.append("D"); |
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
201 break; |
16726
734247341e6e
use string switch in MetaUtil
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16715
diff
changeset
|
202 case "void": |
21963
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
203 result.append("V"); |
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
204 break; |
16726
734247341e6e
use string switch in MetaUtil
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16715
diff
changeset
|
205 default: |
21963
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
206 result.append("L").append(base.replace('.', '/')).append(";"); |
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
207 break; |
7015
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
208 } |
21963
bb3f0968303c
Fix MetaUtil.toInternalName
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21798
diff
changeset
|
209 return result.toString(); |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
210 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
211 |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
212 /** |
18499
bd74da0a76f3
implemented toString() for classes that throw UnsupportedError for hashCode()
Doug Simon <doug.simon@oracle.com>
parents:
18465
diff
changeset
|
213 * Gets a string representation of an object based soley on its class and its |
bd74da0a76f3
implemented toString() for classes that throw UnsupportedError for hashCode()
Doug Simon <doug.simon@oracle.com>
parents:
18465
diff
changeset
|
214 * {@linkplain System#identityHashCode(Object) identity hash code}. This avoids and calls to |
bd74da0a76f3
implemented toString() for classes that throw UnsupportedError for hashCode()
Doug Simon <doug.simon@oracle.com>
parents:
18465
diff
changeset
|
215 * virtual methods on the object such as {@link Object#hashCode()}. |
bd74da0a76f3
implemented toString() for classes that throw UnsupportedError for hashCode()
Doug Simon <doug.simon@oracle.com>
parents:
18465
diff
changeset
|
216 */ |
bd74da0a76f3
implemented toString() for classes that throw UnsupportedError for hashCode()
Doug Simon <doug.simon@oracle.com>
parents:
18465
diff
changeset
|
217 public static String identityHashCodeString(Object obj) { |
bd74da0a76f3
implemented toString() for classes that throw UnsupportedError for hashCode()
Doug Simon <doug.simon@oracle.com>
parents:
18465
diff
changeset
|
218 if (obj == null) { |
bd74da0a76f3
implemented toString() for classes that throw UnsupportedError for hashCode()
Doug Simon <doug.simon@oracle.com>
parents:
18465
diff
changeset
|
219 return "null"; |
bd74da0a76f3
implemented toString() for classes that throw UnsupportedError for hashCode()
Doug Simon <doug.simon@oracle.com>
parents:
18465
diff
changeset
|
220 } |
bd74da0a76f3
implemented toString() for classes that throw UnsupportedError for hashCode()
Doug Simon <doug.simon@oracle.com>
parents:
18465
diff
changeset
|
221 return obj.getClass().getName() + "@" + System.identityHashCode(obj); |
bd74da0a76f3
implemented toString() for classes that throw UnsupportedError for hashCode()
Doug Simon <doug.simon@oracle.com>
parents:
18465
diff
changeset
|
222 } |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
223 } |