changeset 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 d42425beb1d1
children 827854645d6c
files graal/com.oracle.max.cri/src/com/oracle/max/cri/ci/CiKind.java
diffstat 1 files changed, 34 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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);
     }