Mercurial > hg > graal-compiler
comparison graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/MetaUtil.java @ 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.
author | Christian Wimmer <christian.wimmer@oracle.com> |
---|---|
date | Tue, 09 Oct 2012 15:23:38 -0700 |
parents | 6e66d97a16ae |
children | d79098b9db3b |
comparison
equal
deleted
inserted
replaced
6538:d1ba5ba4f484 | 6539:2463eb24b644 |
---|---|
27 import java.lang.annotation.*; | 27 import java.lang.annotation.*; |
28 import java.lang.reflect.*; | 28 import java.lang.reflect.*; |
29 import java.util.*; | 29 import java.util.*; |
30 | 30 |
31 import com.oracle.graal.api.meta.JavaTypeProfile.ProfiledType; | 31 import com.oracle.graal.api.meta.JavaTypeProfile.ProfiledType; |
32 import com.oracle.graal.api.meta.ProfilingInfo.ExceptionSeen; | |
32 | 33 |
33 /** | 34 /** |
34 * Miscellaneous collection of utility methods used by {@code com.oracle.graal.api.meta} and its clients. | 35 * Miscellaneous collection of utility methods used by {@code com.oracle.graal.api.meta} and its clients. |
35 */ | 36 */ |
36 public class MetaUtil { | 37 public class MetaUtil { |
37 | 38 |
38 /** | 39 /** |
39 * Extends the functionality of {@link Class#getSimpleName()} to include a non-empty string for anonymous and local | 40 * Extends the functionality of {@link Class#getSimpleName()} to include a non-empty string for anonymous and local |
40 * classes. | 41 * classes. |
41 * | 42 * |
42 * @param clazz the class for which the simple name is being requested | 43 * @param clazz the class for which the simple name is being requested |
43 * @param withEnclosingClass specifies if the returned name should be qualified with the name(s) of the enclosing | 44 * @param withEnclosingClass specifies if the returned name should be qualified with the name(s) of the enclosing |
44 * class/classes of {@code clazz} (if any). This option is ignored if {@code clazz} denotes an anonymous | 45 * class/classes of {@code clazz} (if any). This option is ignored if {@code clazz} denotes an anonymous |
45 * or local class. | 46 * or local class. |
46 * @return the simple name | 47 * @return the simple name |
69 return name; | 70 return name; |
70 } | 71 } |
71 return name.substring(index + 1); | 72 return name.substring(index + 1); |
72 } | 73 } |
73 | 74 |
74 | |
75 /** | 75 /** |
76 * Converts a given type to its Java programming language name. The following are examples of strings returned by | 76 * Converts a given type to its Java programming language name. The following are examples of strings returned by |
77 * this method: | 77 * this method: |
78 * | 78 * |
79 * <pre> | 79 * <pre> |
80 * qualified == true: | 80 * qualified == true: |
81 * java.lang.Object | 81 * java.lang.Object |
82 * int | 82 * int |
83 * boolean[][] | 83 * boolean[][] |
84 * qualified == false: | 84 * qualified == false: |
85 * Object | 85 * Object |
86 * int | 86 * int |
87 * boolean[][] | 87 * boolean[][] |
88 * </pre> | 88 * </pre> |
89 * | 89 * |
90 * @param type the type to be converted to a Java name | 90 * @param type the type to be converted to a Java name |
91 * @param qualified specifies if the package prefix of the type should be included in the returned name | 91 * @param qualified specifies if the package prefix of the type should be included in the returned name |
92 * @return the Java name corresponding to {@code type} | 92 * @return the Java name corresponding to {@code type} |
93 */ | 93 */ |
94 public static String toJavaName(JavaType type, boolean qualified) { | 94 public static String toJavaName(JavaType type, boolean qualified) { |
95 Kind kind = type.kind(); | 95 Kind kind = type.getKind(); |
96 if (kind.isObject()) { | 96 if (kind.isObject()) { |
97 return internalNameToJava(type.name(), qualified); | 97 return internalNameToJava(type.getName(), qualified); |
98 } | 98 } |
99 return type.kind().javaName; | 99 return type.getKind().getJavaName(); |
100 } | 100 } |
101 | 101 |
102 /** | 102 /** |
103 * Converts a given type to its Java programming language name. The following are examples of strings returned by | 103 * Converts a given type to its Java programming language name. The following are examples of strings returned by |
104 * this method: | 104 * this method: |
105 * | 105 * |
106 * <pre> | 106 * <pre> |
107 * java.lang.Object | 107 * java.lang.Object |
108 * int | 108 * int |
109 * boolean[][] | 109 * boolean[][] |
110 * </pre> | 110 * </pre> |
111 * | 111 * |
112 * @param type the type to be converted to a Java name | 112 * @param type the type to be converted to a Java name |
113 * @return the Java name corresponding to {@code type} | 113 * @return the Java name corresponding to {@code type} |
114 */ | 114 */ |
115 public static String toJavaName(JavaType type) { | 115 public static String toJavaName(JavaType type) { |
116 return (type == null) ? null : internalNameToJava(type.name(), true); | 116 return (type == null) ? null : internalNameToJava(type.getName(), true); |
117 } | 117 } |
118 | 118 |
119 private static String internalNameToJava(String name, boolean qualified) { | 119 private static String internalNameToJava(String name, boolean qualified) { |
120 switch (name.charAt(0)) { | 120 switch (name.charAt(0)) { |
121 case 'L': { | 121 case 'L': { |
133 return internalNameToJava(name.substring(1), qualified) + "[]"; | 133 return internalNameToJava(name.substring(1), qualified) + "[]"; |
134 default: | 134 default: |
135 if (name.length() != 1) { | 135 if (name.length() != 1) { |
136 throw new IllegalArgumentException("Illegal internal name: " + name); | 136 throw new IllegalArgumentException("Illegal internal name: " + name); |
137 } | 137 } |
138 return Kind.fromPrimitiveOrVoidTypeChar(name.charAt(0)).javaName; | 138 return Kind.fromPrimitiveOrVoidTypeChar(name.charAt(0)).getJavaName(); |
139 } | 139 } |
140 } | 140 } |
141 | |
142 | 141 |
143 /** | 142 /** |
144 * Gets a string for a given method formatted according to a given format specification. A format specification is | 143 * Gets a string for a given method formatted according to a given format specification. A format specification is |
145 * composed of characters that are to be copied verbatim to the result and specifiers that denote an attribute of | 144 * composed of characters that are to be copied verbatim to the result and specifiers that denote an attribute of |
146 * the method that is to be copied to the result. A specifier is a single character preceded by a '%' character. The | 145 * the method that is to be copied to the result. A specifier is a single character preceded by a '%' character. The |
147 * accepted specifiers and the method attributes they denote are described below: | 146 * accepted specifiers and the method attributes they denote are described below: |
148 * | 147 * |
149 * <pre> | 148 * <pre> |
150 * Specifier | Description | Example(s) | 149 * Specifier | Description | Example(s) |
151 * ----------+------------------------------------------------------------------------------------------ | 150 * ----------+------------------------------------------------------------------------------------------ |
152 * 'R' | Qualified return type | "int" "java.lang.String" | 151 * 'R' | Qualified return type | "int" "java.lang.String" |
153 * 'r' | Unqualified return type | "int" "String" | 152 * 'r' | Unqualified return type | "int" "String" |
157 * 'P' | Qualified parameter types, separated by ', ' | "int, java.lang.String" | 156 * 'P' | Qualified parameter types, separated by ', ' | "int, java.lang.String" |
158 * 'p' | Unqualified parameter types, separated by ', ' | "int, String" | 157 * 'p' | Unqualified parameter types, separated by ', ' | "int, String" |
159 * 'f' | Indicator if method is unresolved, static or virtual | "unresolved" "static" "virtual" | 158 * 'f' | Indicator if method is unresolved, static or virtual | "unresolved" "static" "virtual" |
160 * '%' | A '%' character | "%" | 159 * '%' | A '%' character | "%" |
161 * </pre> | 160 * </pre> |
162 * | 161 * |
163 * @param format a format specification | 162 * @param format a format specification |
164 * @param method the method to be formatted | 163 * @param method the method to be formatted |
165 * @return the result of formatting this method according to {@code format} | 164 * @return the result of formatting this method according to {@code format} |
166 * @throws IllegalFormatException if an illegal specifier is encountered in {@code format} | 165 * @throws IllegalFormatException if an illegal specifier is encountered in {@code format} |
167 */ | 166 */ |
181 case 'R': | 180 case 'R': |
182 qualified = true; | 181 qualified = true; |
183 // fall through | 182 // fall through |
184 case 'r': { | 183 case 'r': { |
185 if (sig == null) { | 184 if (sig == null) { |
186 sig = method.signature(); | 185 sig = method.getSignature(); |
187 } | 186 } |
188 sb.append(toJavaName(sig.returnType(null), qualified)); | 187 sb.append(toJavaName(sig.getReturnType(null), qualified)); |
189 break; | 188 break; |
190 } | 189 } |
191 case 'H': | 190 case 'H': |
192 qualified = true; | 191 qualified = true; |
193 // fall through | 192 // fall through |
194 case 'h': { | 193 case 'h': { |
195 sb.append(toJavaName(method.holder(), qualified)); | 194 sb.append(toJavaName(method.getDeclaringClass(), qualified)); |
196 break; | 195 break; |
197 } | 196 } |
198 case 'n': { | 197 case 'n': { |
199 sb.append(method.name()); | 198 sb.append(method.getName()); |
200 break; | 199 break; |
201 } | 200 } |
202 case 'P': | 201 case 'P': |
203 qualified = true; | 202 qualified = true; |
204 // fall through | 203 // fall through |
205 case 'p': { | 204 case 'p': { |
206 if (sig == null) { | 205 if (sig == null) { |
207 sig = method.signature(); | 206 sig = method.getSignature(); |
208 } | 207 } |
209 for (int i = 0; i < sig.argumentCount(false); i++) { | 208 for (int i = 0; i < sig.getParameterCount(false); i++) { |
210 if (i != 0) { | 209 if (i != 0) { |
211 sb.append(", "); | 210 sb.append(", "); |
212 } | 211 } |
213 sb.append(toJavaName(sig.argumentTypeAt(i, null), qualified)); | 212 sb.append(toJavaName(sig.getParameterType(i, null), qualified)); |
214 } | 213 } |
215 break; | 214 break; |
216 } | 215 } |
217 case 'f': { | 216 case 'f': { |
218 sb.append(!(method instanceof ResolvedJavaMethod) ? "unresolved" : isStatic(((ResolvedJavaMethod) method).accessFlags()) ? "static" : "virtual"); | 217 sb.append(!(method instanceof ResolvedJavaMethod) ? "unresolved" : isStatic(((ResolvedJavaMethod) method).getModifiers()) ? "static" : "virtual"); |
219 break; | 218 break; |
220 } | 219 } |
221 case '%': { | 220 case '%': { |
222 sb.append('%'); | 221 sb.append('%'); |
223 break; | 222 break; |
230 sb.append(ch); | 229 sb.append(ch); |
231 } | 230 } |
232 } | 231 } |
233 return sb.toString(); | 232 return sb.toString(); |
234 } | 233 } |
235 | |
236 | 234 |
237 /** | 235 /** |
238 * Gets a string for a given field formatted according to a given format specification. A format specification is | 236 * Gets a string for a given field formatted according to a given format specification. A format specification is |
239 * composed of characters that are to be copied verbatim to the result and specifiers that denote an attribute of | 237 * composed of characters that are to be copied verbatim to the result and specifiers that denote an attribute of |
240 * the field that is to be copied to the result. A specifier is a single character preceded by a '%' character. The | 238 * the field that is to be copied to the result. A specifier is a single character preceded by a '%' character. The |
241 * accepted specifiers and the field attributes they denote are described below: | 239 * accepted specifiers and the field attributes they denote are described below: |
242 * | 240 * |
243 * <pre> | 241 * <pre> |
244 * Specifier | Description | Example(s) | 242 * Specifier | Description | Example(s) |
245 * ----------+------------------------------------------------------------------------------------------ | 243 * ----------+------------------------------------------------------------------------------------------ |
246 * 'T' | Qualified type | "int" "java.lang.String" | 244 * 'T' | Qualified type | "int" "java.lang.String" |
247 * 't' | Unqualified type | "int" "String" | 245 * 't' | Unqualified type | "int" "String" |
249 * 'h' | Unqualified holder | "Entry" | 247 * 'h' | Unqualified holder | "Entry" |
250 * 'n' | Field name | "age" | 248 * 'n' | Field name | "age" |
251 * 'f' | Indicator if field is unresolved, static or instance | "unresolved" "static" "instance" | 249 * 'f' | Indicator if field is unresolved, static or instance | "unresolved" "static" "instance" |
252 * '%' | A '%' character | "%" | 250 * '%' | A '%' character | "%" |
253 * </pre> | 251 * </pre> |
254 * | 252 * |
255 * @param format a format specification | 253 * @param format a format specification |
256 * @param field the field to be formatted | 254 * @param field the field to be formatted |
257 * @return the result of formatting this field according to {@code format} | 255 * @return the result of formatting this field according to {@code format} |
258 * @throws IllegalFormatException if an illegal specifier is encountered in {@code format} | 256 * @throws IllegalFormatException if an illegal specifier is encountered in {@code format} |
259 */ | 257 */ |
260 public static String format(String format, JavaField field) throws IllegalFormatException { | 258 public static String format(String format, JavaField field) throws IllegalFormatException { |
261 final StringBuilder sb = new StringBuilder(); | 259 final StringBuilder sb = new StringBuilder(); |
262 int index = 0; | 260 int index = 0; |
263 JavaType type = field.type(); | 261 JavaType type = field.getType(); |
264 while (index < format.length()) { | 262 while (index < format.length()) { |
265 final char ch = format.charAt(index++); | 263 final char ch = format.charAt(index++); |
266 if (ch == '%') { | 264 if (ch == '%') { |
267 if (index >= format.length()) { | 265 if (index >= format.length()) { |
268 throw new UnknownFormatConversionException("An unquoted '%' character cannot terminate a field format specification"); | 266 throw new UnknownFormatConversionException("An unquoted '%' character cannot terminate a field format specification"); |
279 } | 277 } |
280 case 'H': | 278 case 'H': |
281 qualified = true; | 279 qualified = true; |
282 // fall through | 280 // fall through |
283 case 'h': { | 281 case 'h': { |
284 sb.append(toJavaName(field.holder(), qualified)); | 282 sb.append(toJavaName(field.getDeclaringClass(), qualified)); |
285 break; | 283 break; |
286 } | 284 } |
287 case 'n': { | 285 case 'n': { |
288 sb.append(field.name()); | 286 sb.append(field.getName()); |
289 break; | 287 break; |
290 } | 288 } |
291 case 'f': { | 289 case 'f': { |
292 sb.append(!(field instanceof ResolvedJavaField) ? "unresolved" : isStatic(((ResolvedJavaField) field).accessFlags()) ? "static" : "instance"); | 290 sb.append(!(field instanceof ResolvedJavaField) ? "unresolved" : isStatic(((ResolvedJavaField) field).getModifiers()) ? "static" : "instance"); |
293 break; | 291 break; |
294 } | 292 } |
295 case '%': { | 293 case '%': { |
296 sb.append('%'); | 294 sb.append('%'); |
297 break; | 295 break; |
305 } | 303 } |
306 } | 304 } |
307 return sb.toString(); | 305 return sb.toString(); |
308 } | 306 } |
309 | 307 |
310 | |
311 /** | 308 /** |
312 * Gets the annotations of a particular type for the formal parameters of a given method. | 309 * Gets the annotations of a particular type for the formal parameters of a given method. |
313 * | 310 * |
314 * @param annotationClass the Class object corresponding to the annotation type | 311 * @param annotationClass the Class object corresponding to the annotation type |
315 * @param method the method for which a parameter annotations are being requested | 312 * @param method the method for which a parameter annotations are being requested |
316 * @return the annotation of type {@code annotationClass} (if any) for each formal parameter present | 313 * @return the annotation of type {@code annotationClass} (if any) for each formal parameter present |
317 */ | 314 */ |
318 public static <T extends Annotation> T[] getParameterAnnotations(Class<T> annotationClass, ResolvedJavaMethod method) { | 315 public static <T extends Annotation> T[] getParameterAnnotations(Class<T> annotationClass, ResolvedJavaMethod method) { |
329 return result; | 326 return result; |
330 } | 327 } |
331 | 328 |
332 /** | 329 /** |
333 * Gets the annotation of a particular type for a formal parameter of a given method. | 330 * Gets the annotation of a particular type for a formal parameter of a given method. |
334 * | 331 * |
335 * @param annotationClass the Class object corresponding to the annotation type | 332 * @param annotationClass the Class object corresponding to the annotation type |
336 * @param parameterIndex the index of a formal parameter of {@code method} | 333 * @param parameterIndex the index of a formal parameter of {@code method} |
337 * @param method the method for which a parameter annotation is being requested | 334 * @param method the method for which a parameter annotation is being requested |
338 * @return the annotation of type {@code annotationClass} for the formal parameter present, else null | 335 * @return the annotation of type {@code annotationClass} for the formal parameter present, else null |
339 * @throws IndexOutOfBoundsException if {@code parameterIndex} does not denote a formal parameter | 336 * @throws IndexOutOfBoundsException if {@code parameterIndex} does not denote a formal parameter |
349 } | 346 } |
350 return null; | 347 return null; |
351 } | 348 } |
352 | 349 |
353 /** | 350 /** |
354 * Convenient shortcut for calling {@link #appendLocation(StringBuilder, ResolvedJavaMethod, int)} without having to supply a | 351 * Convenient shortcut for calling {@link #appendLocation(StringBuilder, ResolvedJavaMethod, int)} without having to |
355 * a {@link StringBuilder} instance and convert the result to a string. | 352 * supply a a {@link StringBuilder} instance and convert the result to a string. |
356 */ | 353 */ |
357 public static String toLocation(ResolvedJavaMethod method, int bci) { | 354 public static String toLocation(ResolvedJavaMethod method, int bci) { |
358 return appendLocation(new StringBuilder(), method, bci).toString(); | 355 return appendLocation(new StringBuilder(), method, bci).toString(); |
359 } | 356 } |
360 | 357 |
361 | |
362 /** | 358 /** |
363 * Appends a string representation of a location specified by a given method and bci to a given | 359 * Appends a string representation of a location specified by a given method and bci to a given |
364 * {@link StringBuilder}. If a stack trace element with a non-null file name and non-negative line number is | 360 * {@link StringBuilder}. If a stack trace element with a non-null file name and non-negative line number is |
365 * {@linkplain ResolvedJavaMethod#toStackTraceElement(int) available} for the given method, then the string returned is the | 361 * {@linkplain ResolvedJavaMethod#asStackTraceElement(int) available} for the given method, then the string returned |
366 * {@link StackTraceElement#toString()} value of the stack trace element, suffixed by the bci location. For example: | 362 * is the {@link StackTraceElement#toString()} value of the stack trace element, suffixed by the bci location. For |
367 * | 363 * example: |
364 * | |
368 * <pre> | 365 * <pre> |
369 * java.lang.String.valueOf(String.java:2930) [bci: 12] | 366 * java.lang.String.valueOf(String.java:2930) [bci: 12] |
370 * </pre> | 367 * </pre> |
371 * | 368 * |
372 * Otherwise, the string returned is the value of applying {@link #format(String, JavaMethod)} | 369 * Otherwise, the string returned is the value of applying {@link #format(String, JavaMethod)} with the format |
373 * with the format string {@code "%H.%n(%p)"}, suffixed by the bci location. | 370 * string {@code "%H.%n(%p)"}, suffixed by the bci location. For example: |
374 * For example: | 371 * |
375 * | |
376 * <pre> | 372 * <pre> |
377 * java.lang.String.valueOf(int) [bci: 12] | 373 * java.lang.String.valueOf(int) [bci: 12] |
378 * </pre> | 374 * </pre> |
379 * | 375 * |
380 * @param sb | 376 * @param sb |
381 * @param method | 377 * @param method |
382 * @param bci | 378 * @param bci |
383 */ | 379 */ |
384 public static StringBuilder appendLocation(StringBuilder sb, ResolvedJavaMethod method, int bci) { | 380 public static StringBuilder appendLocation(StringBuilder sb, ResolvedJavaMethod method, int bci) { |
385 if (method != null) { | 381 if (method != null) { |
386 StackTraceElement ste = method.toStackTraceElement(bci); | 382 StackTraceElement ste = method.asStackTraceElement(bci); |
387 if (ste.getFileName() != null && ste.getLineNumber() > 0) { | 383 if (ste.getFileName() != null && ste.getLineNumber() > 0) { |
388 sb.append(ste); | 384 sb.append(ste); |
389 } else { | 385 } else { |
390 sb.append(format("%H.%n(%p)", method)); | 386 sb.append(format("%H.%n(%p)", method)); |
391 } | 387 } |
393 sb.append("Null method"); | 389 sb.append("Null method"); |
394 } | 390 } |
395 return sb.append(" [bci: ").append(bci).append(']'); | 391 return sb.append(" [bci: ").append(bci).append(']'); |
396 } | 392 } |
397 | 393 |
398 | |
399 public static Kind[] signatureToKinds(ResolvedJavaMethod method) { | 394 public static Kind[] signatureToKinds(ResolvedJavaMethod method) { |
400 Kind receiver = isStatic(method.accessFlags()) ? null : method.holder().kind(); | 395 Kind receiver = isStatic(method.getModifiers()) ? null : method.getDeclaringClass().getKind(); |
401 return signatureToKinds(method.signature(), receiver); | 396 return signatureToKinds(method.getSignature(), receiver); |
402 } | 397 } |
403 | |
404 | 398 |
405 public static Kind[] signatureToKinds(Signature signature, Kind receiverKind) { | 399 public static Kind[] signatureToKinds(Signature signature, Kind receiverKind) { |
406 int args = signature.argumentCount(false); | 400 int args = signature.getParameterCount(false); |
407 Kind[] result; | 401 Kind[] result; |
408 int i = 0; | 402 int i = 0; |
409 if (receiverKind != null) { | 403 if (receiverKind != null) { |
410 result = new Kind[args + 1]; | 404 result = new Kind[args + 1]; |
411 result[0] = receiverKind; | 405 result[0] = receiverKind; |
412 i = 1; | 406 i = 1; |
413 } else { | 407 } else { |
414 result = new Kind[args]; | 408 result = new Kind[args]; |
415 } | 409 } |
416 for (int j = 0; j < args; j++) { | 410 for (int j = 0; j < args; j++) { |
417 result[i + j] = signature.argumentKindAt(j); | 411 result[i + j] = signature.getParameterKind(j); |
418 } | 412 } |
419 return result; | 413 return result; |
420 } | 414 } |
421 | 415 |
422 | |
423 public static Class< ? >[] signatureToTypes(Signature signature, ResolvedJavaType accessingClass) { | 416 public static Class< ? >[] signatureToTypes(Signature signature, ResolvedJavaType accessingClass) { |
424 int count = signature.argumentCount(false); | 417 int count = signature.getParameterCount(false); |
425 Class< ? >[] result = new Class< ? >[count]; | 418 Class< ? >[] result = new Class< ? >[count]; |
426 for (int i = 0; i < result.length; ++i) { | 419 for (int i = 0; i < result.length; ++i) { |
427 result[i] = signature.argumentTypeAt(i, accessingClass).resolve(accessingClass).toJava(); | 420 result[i] = signature.getParameterType(i, accessingClass).resolve(accessingClass).toJava(); |
428 } | 421 } |
429 return result; | 422 return result; |
430 } | 423 } |
431 | 424 |
432 | |
433 /** | 425 /** |
434 * Formats some profiling information associated as a string. | 426 * Formats some profiling information associated as a string. |
435 * | 427 * |
436 * @param info the profiling info to format | 428 * @param info the profiling info to format |
437 * @param method an optional method that augments the profile string returned | 429 * @param method an optional method that augments the profile string returned |
438 * @param sep the separator to use for each separate profile record | 430 * @param sep the separator to use for each separate profile record |
439 */ | 431 */ |
440 public static String profileToString(ProfilingInfo info, ResolvedJavaMethod method, String sep) { | 432 public static String profileToString(ProfilingInfo info, ResolvedJavaMethod method, String sep) { |
441 StringBuilder buf = new StringBuilder(100); | 433 StringBuilder buf = new StringBuilder(100); |
442 if (method != null) { | 434 if (method != null) { |
443 buf.append(String.format("canBeStaticallyBound: %b%s", method.canBeStaticallyBound(), sep)). | 435 buf.append(String.format("canBeStaticallyBound: %b%s", method.canBeStaticallyBound(), sep)); |
444 append(String.format("invocationCount: %d%s", method.invocationCount(), sep)); | 436 } |
445 } | 437 for (int i = 0; i < info.getCodeSize(); i++) { |
446 for (int i = 0; i < info.codeSize(); i++) { | |
447 if (info.getExecutionCount(i) != -1) { | 438 if (info.getExecutionCount(i) != -1) { |
448 buf.append(String.format("executionCount@%d: %d%s", i, info.getExecutionCount(i), sep)); | 439 buf.append(String.format("executionCount@%d: %d%s", i, info.getExecutionCount(i), sep)); |
449 } | 440 } |
450 | 441 |
451 if (info.getBranchTakenProbability(i) != -1) { | 442 if (info.getBranchTakenProbability(i) != -1) { |
470 ProfiledType[] ptypes = typeProfile.getTypes(); | 461 ProfiledType[] ptypes = typeProfile.getTypes(); |
471 if (ptypes != null) { | 462 if (ptypes != null) { |
472 buf.append(String.format("types@%d:", i)); | 463 buf.append(String.format("types@%d:", i)); |
473 for (int j = 0; j < ptypes.length; j++) { | 464 for (int j = 0; j < ptypes.length; j++) { |
474 ProfiledType ptype = ptypes[j]; | 465 ProfiledType ptype = ptypes[j]; |
475 buf.append(String.format(" %.3f (%s)%s", ptype.probability, ptype.type, sep)); | 466 buf.append(String.format(" %.3f (%s)%s", ptype.getProbability(), ptype.getType(), sep)); |
476 } | 467 } |
477 buf.append(String.format(" %.3f <not recorded>%s", typeProfile.getNotRecordedProbability(), sep)); | 468 buf.append(String.format(" %.3f <not recorded>%s", typeProfile.getNotRecordedProbability(), sep)); |
478 } | 469 } |
479 } | 470 } |
480 } | 471 } |
481 | 472 |
482 boolean firstDeoptReason = true; | 473 boolean firstDeoptReason = true; |
483 for (DeoptimizationReason reason: DeoptimizationReason.values()) { | 474 for (DeoptimizationReason reason : DeoptimizationReason.values()) { |
484 int count = info.getDeoptimizationCount(reason); | 475 int count = info.getDeoptimizationCount(reason); |
485 if (count > 0) { | 476 if (count > 0) { |
486 if (firstDeoptReason) { | 477 if (firstDeoptReason) { |
487 buf.append("deoptimization history").append(sep); | 478 buf.append("deoptimization history").append(sep); |
488 firstDeoptReason = false; | 479 firstDeoptReason = false; |
496 String s = buf.toString(); | 487 String s = buf.toString(); |
497 assert s.endsWith(sep); | 488 assert s.endsWith(sep); |
498 return s.substring(0, s.length() - sep.length()); | 489 return s.substring(0, s.length() - sep.length()); |
499 } | 490 } |
500 | 491 |
501 | |
502 /** | 492 /** |
503 * Converts a Java source-language class name into the internal form. | 493 * Converts a Java source-language class name into the internal form. |
504 * | 494 * |
505 * @param className the class name | 495 * @param className the class name |
506 * @return the internal name form of the class name | 496 * @return the internal name form of the class name |
507 */ | 497 */ |
508 public static String toInternalName(String className) { | 498 public static String toInternalName(String className) { |
509 return "L" + className.replace('.', '/') + ";"; | 499 return "L" + className.replace('.', '/') + ";"; |
510 } | 500 } |
511 | |
512 | 501 |
513 /** | 502 /** |
514 * Prepends the String {@code indentation} to every line in String {@code lines}, including a possibly non-empty | 503 * Prepends the String {@code indentation} to every line in String {@code lines}, including a possibly non-empty |
515 * line following the final newline. | 504 * line following the final newline. |
516 */ | 505 */ |