|
Message
From: cvs at opencores.org<cvs@o...>
Date: Wed Jan 30 20:29:34 CET 2008
Subject: [cvs-checkins] MODIFIED: jop ...
Date: 00/08/01 30:20:29 Modified: jop/java/target/src/test/debug JopDebugKernel.java Log: - Created/fixed some methods for querying class structure fields - Added a GC write barrier to the "setInstanceField" method - Changed some values to use static final constants - Changed all tabs to spaces. Methods changed: 1112: private static int getInstanceSizeFromClass(int classReference) 1117: private static int getPointerToStaticPrimitiveFields(int classReference) 1123: private static int getPointerToSuperclass(int classReference) 1137: private static int getClassPointerFromObjectHandle(int objectHandle) 1160: private static int getInstanceField(int objectHandle, int fieldIndex) 1213: private static void setInstanceField(int objectHandle, int fieldIndex, 2641: private static final void printObjectHandle(int handle) ... plus a few others Methods created: 2670: private static final void debugPrintObjectHandle(int objectHandle) 2811: private static final void printClassHeader(int classPointer) 2858: private static boolean isValidClassPointer(int classPointer) Revision Changes Path 1.10 jop/java/target/src/test/debug/JopDebugKernel.java http://www.opencores.org/cvsweb.shtml/jop/java/target/src/test/debug/JopDebugKernel.java.diff?r1=1.9&r2=1.10 (In the diff below, changes in quantity of whitespace are not shown.) Index: JopDebugKernel.java =================================================================== RCS file: /cvsroot/paulo/jop/java/target/src/test/debug/JopDebugKernel.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -b -r1.9 -r1.10 --- JopDebugKernel.java 18 Jan 2008 22:47:36 -0000 1.9 +++ JopDebugKernel.java 30 Jan 2008 19:29:34 -0000 1.10 @@ -34,6 +34,7 @@ import debug.constants.CommandConstants; import debug.constants.ErrorConstants; +import debug.constants.JOPConstants; import debug.io.DebugKernelChannel; import debug.io.EmbeddedOutputStream; @@ -1111,19 +1112,17 @@ private static int getInstanceSizeFromClass(int classReference) { - return Native.rdMem(classReference); + return Native.rdMem(classReference + JOPConstants.CLASS_OFFSET_INSTANCE_SIZE); } private static int getPointerToStaticPrimitiveFields(int classReference) { - classReference++; - return Native.rdMem(classReference); + return Native.rdMem(classReference + JOPConstants.CLASS_OFFSET_STATIC_PRIMITIVE_FIELDS); } private static int getPointerToSuperclass(int classReference) { - classReference+=3; - return Native.rdMem(classReference); + return Native.rdMem(classReference + JOPConstants.CLASS_OFFSET_SUPERCLASS_POINTER); } /** @@ -1143,7 +1142,7 @@ { classPointer = getMethodTablePointerOrArrayLength(objectHandle); // fix the offset to point to the class structure (instance size) - classPointer -= 5; + classPointer -= JOPConstants.CLASS_HEADER_SIZE; } } @@ -1166,7 +1165,7 @@ synchronized(GC.getMutex()) {
// for development only
- printObjectHandle(objectHandle);
+ debugPrintObjectHandle(objectHandle);
// clear the error flag
clearFlagForInstanceFieldAccess();
@@ -1219,7 +1218,7 @@
synchronized(GC.getMutex())
{
// for development only
- printObjectHandle(objectHandle);
+ debugPrintObjectHandle(objectHandle);
// clear the error flag
clearFlagForInstanceFieldAccess();
@@ -1236,7 +1235,33 @@
// get the object pointer
objectPointer = getObjectPointer(objectHandle);
- //use it to access the object content
+// // get the correspoding class pointer.
+// int classPointer = getClassPointerFromObjectHandle(objectHandle);
+//
+// // get the object GC info from the class structure.
+// int gcInfo = Native.rdMem(classPointer
+// + JOPConstants.CLASS_OFFSET_GC_INFO);
+//
+// // check for references. If the field is a reference,
+// // execute a snapshot-at-beginning write barrier
+// if((gcInfo & (0x01 << fieldIndex)) != 0)
+// {
+// int oldVal = Native.rdMem(objectPointer + fieldIndex);
+// if(oldVal != 0 && Native.rdMem(oldVal + GC.OFF_SPACE) != GC.toSpace)
+// {
+// GC.push(oldVal);
+// }
+// }
+
+ debugPrint("Handle: ");
+ debugPrint(objectHandle);
+ debugPrint(" index: ");
+ debugPrintln(fieldIndex);
+
+ // request GC to execute the write barrier, if needed.
+ GC.writeBarrier(objectHandle, fieldIndex);
+
+ // finally, set the field content
Native.wrMem(fieldValue, objectPointer + fieldIndex);
}
else
@@ -1834,9 +1859,12 @@
// let's synchronize on the GC to avoid concurrency problems.
synchronized(GC.getMutex())
{
+ int type = Native.rdMem(objectHandle + GC.OFF_TYPE);
+
//return (Native.rdMem(objectHandle + GC.OFF_TYPE) == GC.IS_REFARR);
//return (Native.rdMem(objectHandle + GC.OFF_TYPE) == Constants.T_ARRAY);
- return (Native.rdMem(objectHandle + GC.OFF_TYPE) == 13);
+
+ return (type == 13 || type == GC.IS_REFARR);
}
}
@@ -2634,6 +2662,27 @@
}
/**
+ * Print information about the object and its class.
+ * For development only.
+ *
+ * @param handle
+ */
+ private static final void debugPrintObjectHandle(int objectHandle)
+ {
+ if(shouldPrintInternalMessages())
+ {
+ debugPrintln("Handle information:");
+ printObjectHandle(objectHandle);
+ debugPrintln();
+
+ int classPointer = getClassPointerFromObjectHandle(objectHandle);
+ debugPrintln("Class struct information:");
+ printClassHeader(classPointer);
+ debugPrintln();
+ }
+ }
+
+ /**
* Print information about one object handle.
*
* @param handle
@@ -2683,39 +2732,155 @@
if(type == GC.IS_OBJ)
{
System.out.print("Method table: ");
- System.out.println(data);
}
else
{
+ if(type == GC.IS_REFARR)
+ {
System.out.print("Array length: ");
- System.out.println(data);
}
+ else
+ {
+ System.out.print("Unknown data: ");
+ }
+ }
+ System.out.println(data);
- // this is the last access to the handle content.
- // close synchronization block and release GC lock.
data = Native.rdMem(handle + GC.OFF_SIZE);
- }
System.out.print("Instance size: ");
System.out.println(data);
- System.out.print("Type: ");
- System.out.print(type);
- System.out.print(" ");
+// System.out.print("Type: ");
+// System.out.print(type);
+// System.out.print(" ");
if(type == GC.IS_OBJ)
{
System.out.print("Type: Object (not an array) - ");
System.out.println(type);
}
+ else
+ {
if(type == GC.IS_REFARR)
{
- System.out.println("Type: Array");
+ System.out.println("Type: Array -> ");
+ }
+ else
+ {
+ System.out.println("Type: (?) ");
+ }
System.out.println(type);
}
- // for now, don't print the remaining fields. Not yet necessary.
+ //next handle
+ data = Native.rdMem(handle + 4);
+ System.out.print("Next handle: ");
+ System.out.println(data);
+
+ // gray list
+ data = Native.rdMem(handle + 5);
+ System.out.print("Gray list : ");
+ System.out.println(data);
+
+ // space marker
+ data = Native.rdMem(handle + 6);
+ System.out.print("Space marker: ");
+ System.out.println(data);
+// if(data == GC.toSpace)
+
+// System.out.println("GC class:");
+// the code below does not compile: there's one class missing.
+// System.out.println(GC.class);
+
+ // this was the last access to the handle content.
+ // close synchronization block and release GC lock.
+ }
+
// if more fields were added, remember to include on the sync block above.
- System.out.println("");
+ }
+
+ /**
+ * Print information about a class structure.
+ *
+ * Since GC does not affect (modify) classes, it's
+ * not necessary to sync on the GC lock.
+ *
+ * @param classPointer
+ */
+ private static final void printClassHeader(int classPointer)
+ {
+// * According to information on the JOP file, the class structure
+// contains the following data: (the JOP file is verbose, which helps a lot!)
+//
+// * 0 instance size
+// * 1 pointer to static primitive fields
+// * 2 instance GC info
+// * 3 pointer to super class
+// * 4 pointer to interface table
+
+ int data;
+
+ if(isValidClassPointer(classPointer) == false)
+ {
+ System.out.print("Failure: invalid class pointer! -> ");
+ System.out.println(classPointer);
+ return;
+ }
+
+ data = Native.rdMem(classPointer + JOPConstants.CLASS_OFFSET_INSTANCE_SIZE);
+ System.out.print("Instance size: ");
+ System.out.println(data);
+
+ data = Native.rdMem(classPointer + JOPConstants.CLASS_OFFSET_STATIC_PRIMITIVE_FIELDS);
+ System.out.print("Pointer to static primitive fields: ");
+ System.out.println(data);
+
+ data = Native.rdMem(classPointer + JOPConstants.CLASS_OFFSET_GC_INFO);
+ System.out.print("Instance GC info: ");
+ System.out.println(data);
+
+ data = Native.rdMem(classPointer + JOPConstants.CLASS_OFFSET_SUPERCLASS_POINTER);
+ System.out.print("Pointer to superclass: ");
+ System.out.println(data);
+
+ data = Native.rdMem(classPointer + JOPConstants.CLASS_OFFSET_INTERFACE_TABLE_POINTER);
+ System.out.print("Pointer to interface table: ");
+ System.out.println(data);
+ }
+
+ /**
+ * Check if the class pointer may be valid or not.
+ *
+ * @param classPointer
+ * @return
+ */
+ private static boolean isValidClassPointer(int classPointer)
+ {
+ int size, specialPointers;
+ int staticReferencePointer, numReferences;
+
+ // get the application size
+ size = Native.rdMem(0);
+
+ // get the special pointers
+ specialPointers = Native.rdMem(1);
+
+ // get reference info
+ staticReferencePointer = Native.rdMem(specialPointers + 4);
+ numReferences = Native.rdMem(specialPointers + 5);
+
+ // if the pointer is before the end of the static reference area
+ // or after the application size, it's surely a wrong pointer.
+ // Otherwise, it MAY be a valid class pointer, but we can't be sure...
+ if(classPointer < (staticReferencePointer + numReferences) ||
+ classPointer > size)
+ {
+ // outside the valid range. It's a wrong pointer, for sure.
+ return false;
+ }
+
+ //in the valid range. Probably a valid pointer, but may not be.
+ return true;
}
}
|
 |