comparison graal/com.oracle.max.cri/src/com/oracle/max/cri/ci/CiKind.java @ 5363:1d760684d958

expanded formatting of array CiConstants to show contents of the array
author Doug Simon <doug.simon@oracle.com>
date Tue, 08 May 2012 16:10:00 +0200
parents 077ec9468516
children ab31310d4af9
comparison
equal deleted inserted replaced
5362:d42425beb1d1 5363:1d760684d958
21 * questions. 21 * questions.
22 */ 22 */
23 package com.oracle.max.cri.ci; 23 package com.oracle.max.cri.ci;
24 24
25 import static com.oracle.max.cri.ci.CiKind.Flags.*; 25 import static com.oracle.max.cri.ci.CiKind.Flags.*;
26
27 import java.lang.reflect.*;
28
26 import sun.misc.*; 29 import sun.misc.*;
27 30
28 import com.oracle.max.cri.ri.*; 31 import com.oracle.max.cri.ri.*;
29 32
30 /** 33 /**
295 return "class " + CiUtil.toJavaName((RiType) value); 298 return "class " + CiUtil.toJavaName((RiType) value);
296 } else if (value instanceof Enum || value instanceof FormatWithToString) { 299 } else if (value instanceof Enum || value instanceof FormatWithToString) {
297 return String.valueOf(value); 300 return String.valueOf(value);
298 } else if (value instanceof Class< ? >) { 301 } else if (value instanceof Class< ? >) {
299 return ((Class< ? >) value).getName() + ".class"; 302 return ((Class< ? >) value).getName() + ".class";
303 } else if (value.getClass().isArray()) {
304 return formatArray(value);
300 } else { 305 } else {
301 return CiUtil.getSimpleName(value.getClass(), true) + "@" + System.identityHashCode(value); 306 return CiUtil.getSimpleName(value.getClass(), true) + "@" + System.identityHashCode(value);
302 } 307 }
303 } 308 }
304 } else { 309 } else {
305 return value.toString(); 310 return value.toString();
306 } 311 }
312 }
313
314 private static final int MAX_FORMAT_ARRAY_LENGTH = Integer.getInteger("maxFormatArrayLength", 5);
315
316 private static String formatArray(Object array) {
317 Class< ? > componentType = array.getClass().getComponentType();
318 assert componentType != null;
319 int arrayLength = Array.getLength(array);
320 StringBuilder buf = new StringBuilder(CiUtil.getSimpleName(componentType, true)).
321 append('[').
322 append(arrayLength).
323 append("]{");
324 int length = Math.min(MAX_FORMAT_ARRAY_LENGTH, arrayLength);
325 boolean primitive = componentType.isPrimitive();
326 for (int i = 0; i < length; i++) {
327 if (primitive) {
328 buf.append(Array.get(array, i));
329 } else {
330 Object o = ((Object[]) array)[i];
331 buf.append(CiKind.Object.format(o));
332 }
333 if (i != length - 1) {
334 buf.append(", ");
335 }
336 }
337 if (arrayLength != length) {
338 buf.append(", ...");
339 }
340 return buf.append('}').toString();
307 } 341 }
308 342
309 public final char signatureChar() { 343 public final char signatureChar() {
310 return Character.toUpperCase(typeChar); 344 return Character.toUpperCase(typeChar);
311 } 345 }