00001
00008 package edu.mit.csail.sdg.squander.serializer;
00009
00010 import java.lang.reflect.Field;
00011
00020 public class ConsoleHeap implements HeapListener {
00021
00022 @Override
00023 public void newObject(final Object obj) {
00024 System.out.println(obj.getClass().getCanonicalName() + " " + System.identityHashCode(obj));
00025 }
00026
00027 @Override
00028 public void visitPrimitive(Object obj) {
00029 newObject(obj);
00030 }
00031
00032 @Override
00033 public void visitRefField(final Field field, final Object source, final Object value) {
00034 assert !field.getType().isPrimitive();
00035 int sourceId = System.identityHashCode(source);
00036 int targetId = System.identityHashCode(value);
00037 System.out.println(field.getName() + " " + sourceId + " " + targetId);
00038 }
00039
00040 @Override
00041 public void visitIntField(final Field field, final Object source, final int value) {
00042 assert field.getType().equals(int.class);
00043 int sourceId = System.identityHashCode(source);
00044 System.out.println(field.getName() + " " + sourceId + " int" + value);
00045 }
00046
00047 @Override
00048 public void visitBooleanField(final Field field, final Object source, final boolean value) {
00049 assert field.getType().equals(boolean.class);
00050 int sourceId = System.identityHashCode(source);
00051 System.out.println(field.getName() + " " + sourceId + " " + value);
00052 }
00053
00054 @Override
00055 public void visitArrayIntField(Object sourceArray, int index, int value) {
00056 assert sourceArray.getClass().getComponentType() != null;
00057 assert sourceArray.getClass().getComponentType().equals(int.class);
00058 int sourceId = System.identityHashCode(sourceArray);
00059 System.out.println(sourceId + "[" + index + "] = (int)" + value);
00060 }
00061
00062 @Override
00063 public void visitArrayRefField(Object sourceArray, int index, Object value) {
00064 assert sourceArray.getClass().getComponentType() != null;
00065 assert !sourceArray.getClass().getComponentType().isPrimitive();
00066 int sourceId = System.identityHashCode(sourceArray);
00067 System.out.println(sourceId + "[" + index + "] = (Object)" + value);
00068 }
00069
00070 @Override
00071 public void visitArrayLength(Object sourceArray, final int length) {
00072 assert sourceArray.getClass().getComponentType() != null;
00073 int sourceId = System.identityHashCode(sourceArray);
00074 System.out.println(sourceId + ".length = " + length);
00075 }
00076
00077 }