Mercurial > hg > graal-jvmci-8
annotate graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/MetaUtil.java @ 15040:288c23143d47
Fix most raw type references.
author | Josef Eisl <josef.eisl@jku.at> |
---|---|
date | Wed, 09 Apr 2014 19:08:53 +0200 |
parents | db4254246f9a |
children | 820c6d353358 |
rev | line source |
---|---|
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
1 /* |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. |
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 */ |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.graal.api.meta; |
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 import static java.lang.reflect.Modifier.*; |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
26 |
13966
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
27 import java.io.*; |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
28 import java.lang.annotation.*; |
5760
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
29 import java.lang.reflect.*; |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
30 import java.util.*; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
31 |
14991
64dcb92ee75a
Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13966
diff
changeset
|
32 import com.oracle.graal.api.meta.ProfilingInfo.TriState; |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
33 |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
34 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
35 * Miscellaneous collection of utility methods used by {@code com.oracle.graal.api.meta} and its |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
36 * clients. |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
37 */ |
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
|
38 public class MetaUtil { |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
39 |
13966
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
40 private static class ClassInfo { |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
41 public long totalSize; |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
42 public long instanceCount; |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
43 |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
44 @Override |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
45 public String toString() { |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
46 return "totalSize=" + totalSize + ", instanceCount=" + instanceCount; |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
47 } |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
48 } |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
49 |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
50 /** |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
51 * Returns the number of bytes occupied by this constant value or constant object and |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
52 * recursively all values reachable from this value. |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
53 * |
13966
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
54 * @param constant the constant whose bytes should be measured |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
55 * @param printTopN print total size and instance count of the top n classes is desired |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
56 * @return the number of bytes occupied by this constant |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
57 */ |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14991
diff
changeset
|
58 public static long getMemorySizeRecursive(MetaAccessProvider access, ConstantReflectionProvider constantReflection, Constant constant, PrintStream out, int printTopN) { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14991
diff
changeset
|
59 Set<Constant> marked = new HashSet<>(); |
13966
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
60 Stack<Constant> stack = new Stack<>(); |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
61 if (constant.getKind() == Kind.Object && constant.isNonNull()) { |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14991
diff
changeset
|
62 marked.add(constant); |
13966
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
63 } |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14991
diff
changeset
|
64 final HashMap<ResolvedJavaType, ClassInfo> histogram = new HashMap<>(); |
13966
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
65 stack.push(constant); |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
66 long sum = 0; |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
67 while (!stack.isEmpty()) { |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
68 Constant c = stack.pop(); |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
69 long memorySize = access.getMemorySize(constant); |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
70 sum += memorySize; |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
71 if (c.getKind() == Kind.Object && c.isNonNull()) { |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14991
diff
changeset
|
72 ResolvedJavaType clazz = access.lookupJavaType(c); |
13966
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
73 if (!histogram.containsKey(clazz)) { |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
74 histogram.put(clazz, new ClassInfo()); |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
75 } |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
76 ClassInfo info = histogram.get(clazz); |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
77 info.instanceCount++; |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
78 info.totalSize += memorySize; |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
79 ResolvedJavaType type = access.lookupJavaType(c); |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
80 if (type.isArray()) { |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
81 if (!type.getComponentType().isPrimitive()) { |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14991
diff
changeset
|
82 int length = constantReflection.readArrayLength(c); |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14991
diff
changeset
|
83 for (int i = 0; i < length; i++) { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14991
diff
changeset
|
84 Constant value = constantReflection.readArrayElement(c, i); |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14991
diff
changeset
|
85 pushConstant(marked, stack, value); |
13966
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
86 } |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
87 } |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
88 } else { |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
89 ResolvedJavaField[] instanceFields = type.getInstanceFields(true); |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
90 for (ResolvedJavaField f : instanceFields) { |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
91 if (f.getKind() == Kind.Object) { |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
92 Constant value = f.readValue(c); |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
93 pushConstant(marked, stack, value); |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
94 } |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
95 } |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
96 } |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
97 } |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
98 } |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14991
diff
changeset
|
99 ArrayList<ResolvedJavaType> clazzes = new ArrayList<>(); |
13966
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
100 clazzes.addAll(histogram.keySet()); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14991
diff
changeset
|
101 Collections.sort(clazzes, new Comparator<ResolvedJavaType>() { |
13966
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
102 |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
103 @Override |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14991
diff
changeset
|
104 public int compare(ResolvedJavaType o1, ResolvedJavaType o2) { |
13966
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
105 long l1 = histogram.get(o1).totalSize; |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
106 long l2 = histogram.get(o2).totalSize; |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
107 if (l1 > l2) { |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
108 return -1; |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
109 } else if (l1 == l2) { |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
110 return 0; |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
111 } else { |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
112 return 1; |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
113 } |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
114 } |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
115 }); |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
116 |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
117 int z = 0; |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14991
diff
changeset
|
118 for (ResolvedJavaType c : clazzes) { |
13966
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
119 if (z > printTopN) { |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
120 break; |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
121 } |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
122 out.println("Class " + c + ", " + histogram.get(c)); |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
123 ++z; |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
124 } |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
125 |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
126 return sum; |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
127 } |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
128 |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14991
diff
changeset
|
129 private static void pushConstant(Set<Constant> marked, Stack<Constant> stack, Constant value) { |
13966
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
130 if (value.isNonNull()) { |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14991
diff
changeset
|
131 if (!marked.contains(value)) { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14991
diff
changeset
|
132 marked.add(value); |
13966
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
133 stack.push(value); |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
134 } |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
135 } |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
136 } |
be0d961e3a88
New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13270
diff
changeset
|
137 |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
138 /** |
7096
585fc9f79ebc
Remove ResolvedJavaType.isClass()
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7061
diff
changeset
|
139 * Returns true if the specified typed is exactly the type {@link java.lang.Object}. |
585fc9f79ebc
Remove ResolvedJavaType.isClass()
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7061
diff
changeset
|
140 */ |
585fc9f79ebc
Remove ResolvedJavaType.isClass()
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7061
diff
changeset
|
141 public static boolean isJavaLangObject(ResolvedJavaType type) { |
585fc9f79ebc
Remove ResolvedJavaType.isClass()
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7061
diff
changeset
|
142 boolean result = type.getSuperclass() == null && !type.isInterface() && type.getKind() == Kind.Object; |
585fc9f79ebc
Remove ResolvedJavaType.isClass()
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7061
diff
changeset
|
143 assert result == type.getName().equals("Ljava/lang/Object;") : type.getName(); |
585fc9f79ebc
Remove ResolvedJavaType.isClass()
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7061
diff
changeset
|
144 return result; |
585fc9f79ebc
Remove ResolvedJavaType.isClass()
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7061
diff
changeset
|
145 } |
585fc9f79ebc
Remove ResolvedJavaType.isClass()
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7061
diff
changeset
|
146 |
585fc9f79ebc
Remove ResolvedJavaType.isClass()
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7061
diff
changeset
|
147 /** |
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
|
148 * Calls {@link JavaType#resolve(ResolvedJavaType)} on an array of types. |
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
|
149 */ |
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
|
150 public static ResolvedJavaType[] resolveJavaTypes(JavaType[] types, ResolvedJavaType accessingClass) { |
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
|
151 ResolvedJavaType[] result = new ResolvedJavaType[types.length]; |
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
|
152 for (int i = 0; i < result.length; i++) { |
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
|
153 result[i] = types[i].resolve(accessingClass); |
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
|
154 } |
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
|
155 return result; |
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
|
156 } |
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
|
157 |
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
|
158 /** |
7300
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
159 * Calls {@link MetaAccessProvider#lookupJavaType(Class)} on an array of classes. |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
160 */ |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
161 public static ResolvedJavaType[] lookupJavaTypes(MetaAccessProvider metaAccess, Class<?>[] classes) { |
7300
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
162 ResolvedJavaType[] result = new ResolvedJavaType[classes.length]; |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
163 for (int i = 0; i < result.length; i++) { |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
164 result[i] = metaAccess.lookupJavaType(classes[i]); |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
165 } |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
166 return result; |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
167 } |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
168 |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
169 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
170 * Gets the elemental type for a given type. The elemental type of an array type is the |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
171 * corresponding zero dimensional (e.g., the elemental type of {@code int[][][]} is {@code int} |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
172 * ). A non-array type is its own elemental type. |
7059
e4d9f153934f
removed ResolvedJavaType.toJava() and introduced ResolvedJavaType.isPrimitive()
Doug Simon <doug.simon@oracle.com>
parents:
7054
diff
changeset
|
173 */ |
e4d9f153934f
removed ResolvedJavaType.toJava() and introduced ResolvedJavaType.isPrimitive()
Doug Simon <doug.simon@oracle.com>
parents:
7054
diff
changeset
|
174 public static ResolvedJavaType getElementalType(ResolvedJavaType type) { |
e4d9f153934f
removed ResolvedJavaType.toJava() and introduced ResolvedJavaType.isPrimitive()
Doug Simon <doug.simon@oracle.com>
parents:
7054
diff
changeset
|
175 ResolvedJavaType t = type; |
e4d9f153934f
removed ResolvedJavaType.toJava() and introduced ResolvedJavaType.isPrimitive()
Doug Simon <doug.simon@oracle.com>
parents:
7054
diff
changeset
|
176 while (t.getComponentType() != null) { |
e4d9f153934f
removed ResolvedJavaType.toJava() and introduced ResolvedJavaType.isPrimitive()
Doug Simon <doug.simon@oracle.com>
parents:
7054
diff
changeset
|
177 t = t.getComponentType(); |
e4d9f153934f
removed ResolvedJavaType.toJava() and introduced ResolvedJavaType.isPrimitive()
Doug Simon <doug.simon@oracle.com>
parents:
7054
diff
changeset
|
178 } |
e4d9f153934f
removed ResolvedJavaType.toJava() and introduced ResolvedJavaType.isPrimitive()
Doug Simon <doug.simon@oracle.com>
parents:
7054
diff
changeset
|
179 return t; |
7015
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
180 } |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
181 |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
182 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
183 * 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
|
184 * anonymous and local classes. |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
185 * |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
186 * @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
|
187 * @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
|
188 * 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
|
189 * 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
|
190 * @return the simple name |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
191 */ |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
192 public static String getSimpleName(Class<?> clazz, boolean withEnclosingClass) { |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
193 final String simpleName = clazz.getSimpleName(); |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
194 if (simpleName.length() != 0) { |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
195 if (withEnclosingClass) { |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
196 String prefix = ""; |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
197 Class<?> enclosingClass = clazz; |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
198 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
|
199 prefix = enclosingClass.getSimpleName() + "." + prefix; |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
200 } |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
201 return prefix + simpleName; |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
202 } |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
203 return simpleName; |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
204 } |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
205 // 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
|
206 final String name = clazz.getName(); |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
207 int index = name.indexOf('$'); |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
208 if (index == -1) { |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
209 return name; |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
210 } |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
211 index = name.lastIndexOf('.', index); |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
212 if (index == -1) { |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
213 return name; |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
214 } |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
215 return name.substring(index + 1); |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
216 } |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
217 |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
218 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
219 * Converts a given type to its Java programming language name. The following are examples of |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
220 * strings returned by this method: |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
221 * |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
222 * <pre> |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
223 * qualified == true: |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
224 * java.lang.Object |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
225 * int |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
226 * boolean[][] |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
227 * qualified == false: |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
228 * Object |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
229 * int |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
230 * boolean[][] |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
231 * </pre> |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
232 * |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
233 * @param type the type to be converted to a Java name |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
234 * @param qualified specifies if the package prefix of the type should be included in the |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
235 * returned name |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
236 * @return the Java name corresponding to {@code type} |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
237 */ |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
238 public static String toJavaName(JavaType type, boolean qualified) { |
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
|
239 Kind kind = type.getKind(); |
7098
e23980f4a890
Cleanup of Kind class: remove isXxx methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7096
diff
changeset
|
240 if (kind == Kind.Object) { |
7675
31d0b30b30a3
Add MetaUtil.classForName
Michael Haupt <michael.haupt@oracle.com>
parents:
7674
diff
changeset
|
241 return internalNameToJava(type.getName(), qualified, false); |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
242 } |
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
|
243 return type.getKind().getJavaName(); |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
244 } |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
245 |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
246 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
247 * Converts a given type to its Java programming language name. The following are examples of |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
248 * strings returned by this method: |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
249 * |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
250 * <pre> |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
251 * java.lang.Object |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
252 * int |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
253 * boolean[][] |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
254 * </pre> |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
255 * |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
256 * @param type the type to be converted to a Java name |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
257 * @return the Java name corresponding to {@code type} |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
258 */ |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
259 public static String toJavaName(JavaType type) { |
7675
31d0b30b30a3
Add MetaUtil.classForName
Michael Haupt <michael.haupt@oracle.com>
parents:
7674
diff
changeset
|
260 return (type == null) ? null : internalNameToJava(type.getName(), true, false); |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
261 } |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
262 |
9473
5c258c1feb82
Add JavaType-to-String that produces same result as Class.getName()
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9100
diff
changeset
|
263 /** |
5c258c1feb82
Add JavaType-to-String that produces same result as Class.getName()
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9100
diff
changeset
|
264 * Returns the type name in the same format as {@link Class#getName()}. |
5c258c1feb82
Add JavaType-to-String that produces same result as Class.getName()
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9100
diff
changeset
|
265 */ |
5c258c1feb82
Add JavaType-to-String that produces same result as Class.getName()
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9100
diff
changeset
|
266 public static String toClassName(JavaType type) { |
5c258c1feb82
Add JavaType-to-String that produces same result as Class.getName()
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9100
diff
changeset
|
267 return internalNameToJava(type.getName(), true, true); |
5c258c1feb82
Add JavaType-to-String that produces same result as Class.getName()
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9100
diff
changeset
|
268 } |
5c258c1feb82
Add JavaType-to-String that produces same result as Class.getName()
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9100
diff
changeset
|
269 |
7675
31d0b30b30a3
Add MetaUtil.classForName
Michael Haupt <michael.haupt@oracle.com>
parents:
7674
diff
changeset
|
270 private 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
|
271 switch (name.charAt(0)) { |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
272 case 'L': { |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
273 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
|
274 if (!qualified) { |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
275 final int lastDot = result.lastIndexOf('.'); |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
276 if (lastDot != -1) { |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
277 result = result.substring(lastDot + 1); |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
278 } |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
279 } |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
280 return result; |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
281 } |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
282 case '[': |
7676
ca9061b6694c
getMethodDescriptor does not need to be in the Signature interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7675
diff
changeset
|
283 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
|
284 default: |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
285 if (name.length() != 1) { |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
286 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
|
287 } |
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
|
288 return Kind.fromPrimitiveOrVoidTypeChar(name.charAt(0)).getJavaName(); |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
289 } |
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
290 } |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
291 |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
292 /** |
7675
31d0b30b30a3
Add MetaUtil.classForName
Michael Haupt <michael.haupt@oracle.com>
parents:
7674
diff
changeset
|
293 * Turns an class name in internal format into a resolved Java type. |
31d0b30b30a3
Add MetaUtil.classForName
Michael Haupt <michael.haupt@oracle.com>
parents:
7674
diff
changeset
|
294 */ |
31d0b30b30a3
Add MetaUtil.classForName
Michael Haupt <michael.haupt@oracle.com>
parents:
7674
diff
changeset
|
295 public static ResolvedJavaType classForName(String internal, MetaAccessProvider metaAccess, ClassLoader cl) { |
31d0b30b30a3
Add MetaUtil.classForName
Michael Haupt <michael.haupt@oracle.com>
parents:
7674
diff
changeset
|
296 Kind k = Kind.fromTypeString(internal); |
31d0b30b30a3
Add MetaUtil.classForName
Michael Haupt <michael.haupt@oracle.com>
parents:
7674
diff
changeset
|
297 try { |
31d0b30b30a3
Add MetaUtil.classForName
Michael Haupt <michael.haupt@oracle.com>
parents:
7674
diff
changeset
|
298 String n = internalNameToJava(internal, true, true); |
31d0b30b30a3
Add MetaUtil.classForName
Michael Haupt <michael.haupt@oracle.com>
parents:
7674
diff
changeset
|
299 return metaAccess.lookupJavaType(k.isPrimitive() ? k.toJavaClass() : Class.forName(n, true, cl)); |
31d0b30b30a3
Add MetaUtil.classForName
Michael Haupt <michael.haupt@oracle.com>
parents:
7674
diff
changeset
|
300 } catch (ClassNotFoundException cnfe) { |
31d0b30b30a3
Add MetaUtil.classForName
Michael Haupt <michael.haupt@oracle.com>
parents:
7674
diff
changeset
|
301 throw new IllegalArgumentException("could not instantiate class described by " + internal, cnfe); |
31d0b30b30a3
Add MetaUtil.classForName
Michael Haupt <michael.haupt@oracle.com>
parents:
7674
diff
changeset
|
302 } |
31d0b30b30a3
Add MetaUtil.classForName
Michael Haupt <michael.haupt@oracle.com>
parents:
7674
diff
changeset
|
303 } |
31d0b30b30a3
Add MetaUtil.classForName
Michael Haupt <michael.haupt@oracle.com>
parents:
7674
diff
changeset
|
304 |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
305 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
306 * Gets a string for a given method formatted according to a given format specification. A |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
307 * format specification is composed of characters that are to be copied verbatim to the result |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
308 * and specifiers that denote an attribute of the method that is to be copied to the result. A |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
309 * specifier is a single character preceded by a '%' character. The accepted specifiers and the |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
310 * method attributes they denote are described below: |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
311 * |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
312 * <pre> |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
313 * Specifier | Description | Example(s) |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
314 * ----------+------------------------------------------------------------------------------------------ |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
315 * 'R' | Qualified return type | "int" "java.lang.String" |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
316 * 'r' | Unqualified return type | "int" "String" |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
317 * 'H' | Qualified holder | "java.util.Map.Entry" |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
318 * 'h' | Unqualified holder | "Entry" |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
319 * 'n' | Method name | "add" |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
320 * 'P' | Qualified parameter types, separated by ', ' | "int, java.lang.String" |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
321 * 'p' | Unqualified parameter types, separated by ', ' | "int, String" |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
322 * 'f' | Indicator if method is unresolved, static or virtual | "unresolved" "static" "virtual" |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
323 * '%' | A '%' character | "%" |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
324 * </pre> |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
325 * |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
326 * @param format a format specification |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
327 * @param method the method to be formatted |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
328 * @return the result of formatting this method according to {@code format} |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
329 * @throws IllegalFormatException if an illegal specifier is encountered in {@code format} |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
330 */ |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
331 public static String format(String format, JavaMethod method) throws IllegalFormatException { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
332 final StringBuilder sb = new StringBuilder(); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
333 int index = 0; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
334 Signature sig = null; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
335 while (index < format.length()) { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
336 final char ch = format.charAt(index++); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
337 if (ch == '%') { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
338 if (index >= format.length()) { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
339 throw new UnknownFormatConversionException("An unquoted '%' character cannot terminate a method format specification"); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
340 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
341 final char specifier = format.charAt(index++); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
342 boolean qualified = false; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
343 switch (specifier) { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
344 case 'R': |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
345 qualified = true; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
346 // fall through |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
347 case 'r': { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
348 if (sig == 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
|
349 sig = method.getSignature(); |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
350 } |
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
|
351 sb.append(toJavaName(sig.getReturnType(null), qualified)); |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
352 break; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
353 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
354 case 'H': |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
355 qualified = true; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
356 // fall through |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
357 case 'h': { |
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
|
358 sb.append(toJavaName(method.getDeclaringClass(), qualified)); |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
359 break; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
360 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
361 case 'n': { |
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
|
362 sb.append(method.getName()); |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
363 break; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
364 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
365 case 'P': |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
366 qualified = true; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
367 // fall through |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
368 case 'p': { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
369 if (sig == 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
|
370 sig = method.getSignature(); |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
371 } |
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
|
372 for (int i = 0; i < sig.getParameterCount(false); i++) { |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
373 if (i != 0) { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
374 sb.append(", "); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
375 } |
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
|
376 sb.append(toJavaName(sig.getParameterType(i, null), qualified)); |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
377 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
378 break; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
379 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
380 case 'f': { |
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
|
381 sb.append(!(method instanceof ResolvedJavaMethod) ? "unresolved" : isStatic(((ResolvedJavaMethod) method).getModifiers()) ? "static" : "virtual"); |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
382 break; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
383 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
384 case '%': { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
385 sb.append('%'); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
386 break; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
387 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
388 default: { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
389 throw new UnknownFormatConversionException(String.valueOf(specifier)); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
390 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
391 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
392 } else { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
393 sb.append(ch); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
394 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
395 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
396 return sb.toString(); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
397 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
398 |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
399 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
400 * Gets a string for a given field formatted according to a given format specification. A format |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
401 * specification is composed of characters that are to be copied verbatim to the result and |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
402 * specifiers that denote an attribute of the field that is to be copied to the result. A |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
403 * specifier is a single character preceded by a '%' character. The accepted specifiers and the |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
404 * field attributes they denote are described below: |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
405 * |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
406 * <pre> |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
407 * Specifier | Description | Example(s) |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
408 * ----------+------------------------------------------------------------------------------------------ |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
409 * 'T' | Qualified type | "int" "java.lang.String" |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
410 * 't' | Unqualified type | "int" "String" |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
411 * 'H' | Qualified holder | "java.util.Map.Entry" |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
412 * 'h' | Unqualified holder | "Entry" |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
413 * 'n' | Field name | "age" |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
414 * 'f' | Indicator if field is unresolved, static or instance | "unresolved" "static" "instance" |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
415 * '%' | A '%' character | "%" |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
416 * </pre> |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
417 * |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
418 * @param format a format specification |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
419 * @param field the field to be formatted |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
420 * @return the result of formatting this field according to {@code format} |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
421 * @throws IllegalFormatException if an illegal specifier is encountered in {@code format} |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
422 */ |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
423 public static String format(String format, JavaField field) throws IllegalFormatException { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
424 final StringBuilder sb = new StringBuilder(); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
425 int index = 0; |
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
|
426 JavaType type = field.getType(); |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
427 while (index < format.length()) { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
428 final char ch = format.charAt(index++); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
429 if (ch == '%') { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
430 if (index >= format.length()) { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
431 throw new UnknownFormatConversionException("An unquoted '%' character cannot terminate a field format specification"); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
432 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
433 final char specifier = format.charAt(index++); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
434 boolean qualified = false; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
435 switch (specifier) { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
436 case 'T': |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
437 qualified = true; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
438 // fall through |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
439 case 't': { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
440 sb.append(toJavaName(type, qualified)); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
441 break; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
442 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
443 case 'H': |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
444 qualified = true; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
445 // fall through |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
446 case 'h': { |
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
|
447 sb.append(toJavaName(field.getDeclaringClass(), qualified)); |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
448 break; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
449 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
450 case 'n': { |
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
|
451 sb.append(field.getName()); |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
452 break; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
453 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
454 case 'f': { |
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
|
455 sb.append(!(field instanceof ResolvedJavaField) ? "unresolved" : isStatic(((ResolvedJavaField) field).getModifiers()) ? "static" : "instance"); |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
456 break; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
457 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
458 case '%': { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
459 sb.append('%'); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
460 break; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
461 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
462 default: { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
463 throw new UnknownFormatConversionException(String.valueOf(specifier)); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
464 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
465 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
466 } else { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
467 sb.append(ch); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
468 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
469 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
470 return sb.toString(); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
471 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
472 |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
473 /** |
5760
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
474 * Gets the annotations of a particular type for the formal parameters of a given method. |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
475 * |
5760
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
476 * @param annotationClass the Class object corresponding to the annotation type |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
477 * @param method the method for which a parameter annotations are being requested |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
478 * @return the annotation of type {@code annotationClass} (if any) for each formal parameter |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
479 * present |
5760
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
480 */ |
7744
437f43262915
Move @SuppressWarnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7677
diff
changeset
|
481 @SuppressWarnings("unchecked") |
5760
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
482 public static <T extends Annotation> T[] getParameterAnnotations(Class<T> annotationClass, ResolvedJavaMethod method) { |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
483 Annotation[][] parameterAnnotations = method.getParameterAnnotations(); |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
484 T[] result = (T[]) Array.newInstance(annotationClass, parameterAnnotations.length); |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
485 for (int i = 0; i < parameterAnnotations.length; i++) { |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
486 for (Annotation a : parameterAnnotations[i]) { |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
487 if (a.annotationType() == annotationClass) { |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
488 result[i] = annotationClass.cast(a); |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
489 } |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
490 } |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
491 } |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
492 return result; |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
493 } |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
494 |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
495 /** |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
496 * Gets the annotation of a particular type for a formal parameter of a given method. |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
497 * |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
498 * @param annotationClass the Class object corresponding to the annotation type |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
499 * @param parameterIndex the index of a formal parameter of {@code method} |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
500 * @param method the method for which a parameter annotation is being requested |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
501 * @return the annotation of type {@code annotationClass} for the formal parameter present, else |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
502 * null |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
503 * @throws IndexOutOfBoundsException if {@code parameterIndex} does not denote a formal |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
504 * parameter |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
505 */ |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
506 public static <T extends Annotation> T getParameterAnnotation(Class<T> annotationClass, int parameterIndex, ResolvedJavaMethod method) { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
507 if (parameterIndex >= 0) { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
508 Annotation[][] parameterAnnotations = method.getParameterAnnotations(); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
509 for (Annotation a : parameterAnnotations[parameterIndex]) { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
510 if (a.annotationType() == annotationClass) { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
511 return annotationClass.cast(a); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
512 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
513 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
514 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
515 return null; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
516 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
517 |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
518 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
519 * Convenient shortcut for calling |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
520 * {@link #appendLocation(StringBuilder, ResolvedJavaMethod, int)} without having to supply a a |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
521 * {@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
|
522 */ |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
523 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
|
524 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
|
525 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
526 |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
527 /** |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
528 * 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
|
529 * {@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
|
530 * 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
|
531 * 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
|
532 * 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
|
533 * |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
534 * <pre> |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
535 * 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
|
536 * </pre> |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
537 * |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
538 * Otherwise, the string returned is the value of applying {@link #format(String, JavaMethod)} |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
539 * 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
|
540 * |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
541 * <pre> |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
542 * 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
|
543 * </pre> |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
544 * |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
545 * @param sb |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
546 * @param method |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
547 * @param bci |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
548 */ |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
549 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
|
550 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
|
551 StackTraceElement ste = method.asStackTraceElement(bci); |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
552 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
|
553 sb.append(ste); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
554 } else { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
555 sb.append(format("%H.%n(%p)", method)); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
556 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
557 } else { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
558 sb.append("Null method"); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
559 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
560 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
|
561 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
562 |
7300
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
563 public static JavaType[] signatureToTypes(ResolvedJavaMethod method) { |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
564 JavaType receiver = isStatic(method.getModifiers()) ? null : method.getDeclaringClass(); |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
565 return signatureToTypes(method.getSignature(), receiver); |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
566 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
567 |
7300
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
568 public static JavaType[] signatureToTypes(Signature signature, JavaType receiverType) { |
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
|
569 int args = signature.getParameterCount(false); |
7300
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
570 JavaType[] result; |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
571 int i = 0; |
7300
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
572 if (receiverType != null) { |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
573 result = new JavaType[args + 1]; |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
574 result[0] = receiverType; |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
575 i = 1; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
576 } else { |
7300
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
577 result = new JavaType[args]; |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
578 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
579 for (int j = 0; j < args; j++) { |
7300
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
580 result[i + j] = signature.getParameterType(j, null); |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
581 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
582 return result; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
583 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
584 |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
585 /** |
7676
ca9061b6694c
getMethodDescriptor does not need to be in the Signature interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7675
diff
changeset
|
586 * Gets the <a |
ca9061b6694c
getMethodDescriptor does not need to be in the Signature interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7675
diff
changeset
|
587 * href="http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.3.3">method |
ca9061b6694c
getMethodDescriptor does not need to be in the Signature interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7675
diff
changeset
|
588 * descriptor</a> corresponding to this signature. For example: |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
589 * |
7676
ca9061b6694c
getMethodDescriptor does not need to be in the Signature interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7675
diff
changeset
|
590 * <pre> |
ca9061b6694c
getMethodDescriptor does not need to be in the Signature interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7675
diff
changeset
|
591 * (ILjava/lang/String;D)V |
ca9061b6694c
getMethodDescriptor does not need to be in the Signature interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7675
diff
changeset
|
592 * </pre> |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
593 * |
7676
ca9061b6694c
getMethodDescriptor does not need to be in the Signature interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7675
diff
changeset
|
594 * . |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
595 * |
7676
ca9061b6694c
getMethodDescriptor does not need to be in the Signature interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7675
diff
changeset
|
596 * @param sig the {@link Signature} to be converted. |
ca9061b6694c
getMethodDescriptor does not need to be in the Signature interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7675
diff
changeset
|
597 * @return the signature as a string |
ca9061b6694c
getMethodDescriptor does not need to be in the Signature interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7675
diff
changeset
|
598 */ |
ca9061b6694c
getMethodDescriptor does not need to be in the Signature interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7675
diff
changeset
|
599 public static String signatureToMethodDescriptor(Signature sig) { |
ca9061b6694c
getMethodDescriptor does not need to be in the Signature interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7675
diff
changeset
|
600 StringBuilder sb = new StringBuilder("("); |
ca9061b6694c
getMethodDescriptor does not need to be in the Signature interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7675
diff
changeset
|
601 for (int i = 0; i < sig.getParameterCount(false); ++i) { |
ca9061b6694c
getMethodDescriptor does not need to be in the Signature interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7675
diff
changeset
|
602 sb.append(sig.getParameterType(i, null).getName()); |
ca9061b6694c
getMethodDescriptor does not need to be in the Signature interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7675
diff
changeset
|
603 } |
ca9061b6694c
getMethodDescriptor does not need to be in the Signature interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7675
diff
changeset
|
604 sb.append(')').append(sig.getReturnType(null).getName()); |
ca9061b6694c
getMethodDescriptor does not need to be in the Signature interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7675
diff
changeset
|
605 return sb.toString(); |
ca9061b6694c
getMethodDescriptor does not need to be in the Signature interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7675
diff
changeset
|
606 } |
ca9061b6694c
getMethodDescriptor does not need to be in the Signature interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7675
diff
changeset
|
607 |
ca9061b6694c
getMethodDescriptor does not need to be in the Signature interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7675
diff
changeset
|
608 /** |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
609 * Formats some profiling information associated as a string. |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
610 * |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
611 * @param info the profiling info to format |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
612 * @param method an optional method that augments the profile string returned |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
613 * @param sep the separator to use for each separate profile record |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
614 */ |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
615 public static String profileToString(ProfilingInfo info, ResolvedJavaMethod method, String sep) { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
616 StringBuilder buf = new StringBuilder(100); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
617 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
|
618 buf.append(String.format("canBeStaticallyBound: %b%s", method.canBeStaticallyBound(), sep)); |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
619 } |
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
|
620 for (int i = 0; i < info.getCodeSize(); i++) { |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
621 if (info.getExecutionCount(i) != -1) { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
622 buf.append(String.format("executionCount@%d: %d%s", i, info.getExecutionCount(i), sep)); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
623 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
624 |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
625 if (info.getBranchTakenProbability(i) != -1) { |
7655
175fbf5a692c
improved utility for converting ProfilingInfo to a String
Doug Simon <doug.simon@oracle.com>
parents:
7530
diff
changeset
|
626 buf.append(String.format("branchProbability@%d: %.6f%s", i, info.getBranchTakenProbability(i), sep)); |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
627 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
628 |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
629 double[] switchProbabilities = info.getSwitchProbabilities(i); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
630 if (switchProbabilities != null) { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
631 buf.append(String.format("switchProbabilities@%d:", i)); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
632 for (int j = 0; j < switchProbabilities.length; j++) { |
7655
175fbf5a692c
improved utility for converting ProfilingInfo to a String
Doug Simon <doug.simon@oracle.com>
parents:
7530
diff
changeset
|
633 buf.append(String.format(" %.6f", switchProbabilities[j])); |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
634 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
635 buf.append(sep); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
636 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
637 |
13270
d86dc1b84973
modified ProfilingInfoTest to better handle variability in profiling info provided by the runtime
Doug Simon <doug.simon@oracle.com>
parents:
9764
diff
changeset
|
638 if (info.getExceptionSeen(i) != TriState.UNKNOWN) { |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
639 buf.append(String.format("exceptionSeen@%d: %s%s", i, info.getExceptionSeen(i).name(), sep)); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
640 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
641 |
13270
d86dc1b84973
modified ProfilingInfoTest to better handle variability in profiling info provided by the runtime
Doug Simon <doug.simon@oracle.com>
parents:
9764
diff
changeset
|
642 if (info.getNullSeen(i) != TriState.UNKNOWN) { |
8610
5407d1dd6450
API to access nullness profiling information for instanceof, checkcast, and aastore
Christian Haeubl <haeubl@ssw.jku.at>
parents:
7830
diff
changeset
|
643 buf.append(String.format("nullSeen@%d: %s%s", i, info.getNullSeen(i).name(), sep)); |
5407d1dd6450
API to access nullness profiling information for instanceof, checkcast, and aastore
Christian Haeubl <haeubl@ssw.jku.at>
parents:
7830
diff
changeset
|
644 } |
5407d1dd6450
API to access nullness profiling information for instanceof, checkcast, and aastore
Christian Haeubl <haeubl@ssw.jku.at>
parents:
7830
diff
changeset
|
645 |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
646 JavaTypeProfile typeProfile = info.getTypeProfile(i); |
9760
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9473
diff
changeset
|
647 appendProfile(buf, typeProfile, i, "types", sep); |
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9473
diff
changeset
|
648 |
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9473
diff
changeset
|
649 JavaMethodProfile methodProfile = info.getMethodProfile(i); |
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9473
diff
changeset
|
650 appendProfile(buf, methodProfile, i, "methods", sep); |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
651 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
652 |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
653 boolean firstDeoptReason = true; |
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
|
654 for (DeoptimizationReason reason : DeoptimizationReason.values()) { |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
655 int count = info.getDeoptimizationCount(reason); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
656 if (count > 0) { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
657 if (firstDeoptReason) { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
658 buf.append("deoptimization history").append(sep); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
659 firstDeoptReason = false; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
660 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
661 buf.append(String.format(" %s: %d%s", reason.name(), count, sep)); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
662 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
663 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
664 if (buf.length() == 0) { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
665 return ""; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
666 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
667 String s = buf.toString(); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
668 assert s.endsWith(sep); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
669 return s.substring(0, s.length() - sep.length()); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
670 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
671 |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
672 private 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
|
673 if (profile != null) { |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
674 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
|
675 if (pitems != null) { |
9764 | 676 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
|
677 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
|
678 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
|
679 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
|
680 } |
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9473
diff
changeset
|
681 if (profile.getNotRecordedProbability() != 0) { |
9764 | 682 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
|
683 } else { |
9764 | 684 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
|
685 } |
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9473
diff
changeset
|
686 } |
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9473
diff
changeset
|
687 } |
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9473
diff
changeset
|
688 } |
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9473
diff
changeset
|
689 |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
690 /** |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
691 * 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
|
692 * |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
693 * @param className the class name |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
694 * @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
|
695 */ |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
696 public static String toInternalName(String className) { |
7015
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
697 String prefix = ""; |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
698 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
|
699 while (base.endsWith("[]")) { |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
700 prefix += "["; |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
701 base = base.substring(base.length() - 2); |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
702 } |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
703 |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
704 if (className.equals("boolean")) { |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
705 return prefix + "Z"; |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
706 } |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
707 if (className.equals("byte")) { |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
708 return prefix + "B"; |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
709 } |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
710 if (className.equals("short")) { |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
711 return prefix + "S"; |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
712 } |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
713 if (className.equals("char")) { |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
714 return prefix + "C"; |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
715 } |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
716 if (className.equals("int")) { |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
717 return prefix + "I"; |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
718 } |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
719 if (className.equals("float")) { |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
720 return prefix + "F"; |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
721 } |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
722 if (className.equals("long")) { |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
723 return prefix + "J"; |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
724 } |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
725 if (className.equals("double")) { |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
726 return prefix + "D"; |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
727 } |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
728 if (className.equals("void")) { |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
729 return prefix + "V"; |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
730 } |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6699
diff
changeset
|
731 return prefix + "L" + className.replace('.', '/') + ";"; |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
732 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
733 |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
734 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
735 * Prepends the String {@code indentation} to every line in String {@code lines}, including a |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7357
diff
changeset
|
736 * possibly non-empty line following the final newline. |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
737 */ |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
738 public static String indent(String lines, String indentation) { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
739 if (lines.length() == 0) { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
740 return lines; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
741 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
742 final String newLine = "\n"; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
743 if (lines.endsWith(newLine)) { |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
744 return indentation + (lines.substring(0, lines.length() - 1)).replace(newLine, newLine + indentation) + newLine; |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
745 } |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
746 return indentation + lines.replace(newLine, newLine + indentation); |
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5547
diff
changeset
|
747 } |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
748 } |