# HG changeset patch # User Doug Simon # Date 1336486200 -7200 # Node ID 1d760684d9586cabcf260c15e50364a3eaa62e15 # Parent d42425beb1d13223cae50670b917961f2ec1a41e expanded formatting of array CiConstants to show contents of the array diff -r d42425beb1d1 -r 1d760684d958 graal/com.oracle.max.cri/src/com/oracle/max/cri/ci/CiKind.java --- a/graal/com.oracle.max.cri/src/com/oracle/max/cri/ci/CiKind.java Tue May 08 15:52:01 2012 +0200 +++ b/graal/com.oracle.max.cri/src/com/oracle/max/cri/ci/CiKind.java Tue May 08 16:10:00 2012 +0200 @@ -23,6 +23,9 @@ package com.oracle.max.cri.ci; import static com.oracle.max.cri.ci.CiKind.Flags.*; + +import java.lang.reflect.*; + import sun.misc.*; import com.oracle.max.cri.ri.*; @@ -297,6 +300,8 @@ return String.valueOf(value); } else if (value instanceof Class< ? >) { return ((Class< ? >) value).getName() + ".class"; + } else if (value.getClass().isArray()) { + return formatArray(value); } else { return CiUtil.getSimpleName(value.getClass(), true) + "@" + System.identityHashCode(value); } @@ -306,6 +311,35 @@ } } + private static final int MAX_FORMAT_ARRAY_LENGTH = Integer.getInteger("maxFormatArrayLength", 5); + + private static String formatArray(Object array) { + Class< ? > componentType = array.getClass().getComponentType(); + assert componentType != null; + int arrayLength = Array.getLength(array); + StringBuilder buf = new StringBuilder(CiUtil.getSimpleName(componentType, true)). + append('['). + append(arrayLength). + append("]{"); + int length = Math.min(MAX_FORMAT_ARRAY_LENGTH, arrayLength); + boolean primitive = componentType.isPrimitive(); + for (int i = 0; i < length; i++) { + if (primitive) { + buf.append(Array.get(array, i)); + } else { + Object o = ((Object[]) array)[i]; + buf.append(CiKind.Object.format(o)); + } + if (i != length - 1) { + buf.append(", "); + } + } + if (arrayLength != length) { + buf.append(", ..."); + } + return buf.append('}').toString(); + } + public final char signatureChar() { return Character.toUpperCase(typeChar); }