< prev index next > test/lib/jdk/test/lib/hprof/model/JavaObject.java
Print this page
*/
public class JavaObject extends JavaLazyReadObject {
private Object clazz; // Number before resolve
// JavaClass after resolve
/**
* Construct a new JavaObject.
*
* @param classID id of the class object
* @param offset The offset of field data
*/
public JavaObject(long classID, long offset) {
! super(offset);
- this.clazz = makeId(classID);
}
public void resolve(Snapshot snapshot) {
if (clazz instanceof JavaClass) {
return;
*/
public class JavaObject extends JavaLazyReadObject {
private Object clazz; // Number before resolve
// JavaClass after resolve
+
+ public JavaObject(Object clazz, long offset) {
+ super(offset);
+ this.clazz = clazz;
+ }
+
/**
* Construct a new JavaObject.
*
* @param classID id of the class object
* @param offset The offset of field data
*/
public JavaObject(long classID, long offset) {
! this(makeId(classID), offset);
}
public void resolve(Snapshot snapshot) {
if (clazz instanceof JavaClass) {
return;
* class ID
* data length (int)
* byte[length]
*/
@Override
! protected final long readValueLength() throws IOException {
long lengthOffset = getOffset() + 2 * idSize() + 4;
return buf().getInt(lengthOffset);
}
@Override
protected final JavaThing[] readValue() throws IOException {
return parseFields(false);
}
! private long dataStartOffset() {
return getOffset() + idSize() + 4 + idSize() + 4;
}
private JavaThing[] parseFields(boolean verbose) {
JavaClass cl = getClazz();
* class ID
* data length (int)
* byte[length]
*/
@Override
! protected long readValueLength() throws IOException {
long lengthOffset = getOffset() + 2 * idSize() + 4;
return buf().getInt(lengthOffset);
}
@Override
protected final JavaThing[] readValue() throws IOException {
return parseFields(false);
}
! protected long dataStartOffset() {
return getOffset() + idSize() + 4 + idSize() + 4;
}
private JavaThing[] parseFields(boolean verbose) {
JavaClass cl = getClazz();
target -= fields.length;
}
JavaField f = fields[fieldNo];
char sig = f.getSignature().charAt(0);
try {
! switch (sig) {
! case 'L':
! case '[': {
! long id = objectIdAt(offset);
! offset += idSize();
! JavaObjectRef ref = new JavaObjectRef(id);
! fieldValues[target+fieldNo] = ref.dereference(snapshot, f, verbose);
! break;
! }
! case 'Z': {
! byte value = byteAt(offset);
! offset++;
! fieldValues[target+fieldNo] = new JavaBoolean(value != 0);
! break;
! }
! case 'B': {
! byte value = byteAt(offset);
! offset++;
! fieldValues[target+fieldNo] = new JavaByte(value);
! break;
! }
! case 'S': {
! short value = shortAt(offset);
! offset += 2;
! fieldValues[target+fieldNo] = new JavaShort(value);
! break;
! }
! case 'C': {
! char value = charAt(offset);
! offset += 2;
! fieldValues[target+fieldNo] = new JavaChar(value);
! break;
! }
! case 'I': {
! int value = intAt(offset);
! offset += 4;
! fieldValues[target+fieldNo] = new JavaInt(value);
! break;
! }
! case 'J': {
! long value = longAt(offset);
! offset += 8;
! fieldValues[target+fieldNo] = new JavaLong(value);
! break;
! }
! case 'F': {
! float value = floatAt(offset);
! offset += 4;
! fieldValues[target+fieldNo] = new JavaFloat(value);
! break;
! }
! case 'D': {
! double value = doubleAt(offset);
! offset += 8;
! fieldValues[target+fieldNo] = new JavaDouble(value);
! break;
! }
! default:
! throw new RuntimeException("invalid signature: " + sig);
}
! } catch (IOException exp) {
! System.err.println("lazy read failed at offset " + offset);
! exp.printStackTrace();
! return Snapshot.EMPTY_JAVATHING_ARRAY;
}
}
return fieldValues;
}
target -= fields.length;
}
JavaField f = fields[fieldNo];
char sig = f.getSignature().charAt(0);
try {
! if (f instanceof InlinedJavaField inlinedField) {
! JavaClass fieldClass = inlinedField.getInlinedFieldClass();
! fieldValues[target+fieldNo] = new InlinedJavaObject(fieldClass, offset);
! offset += fieldClass.getInlinedInstanceSize();
! } else {
! switch (sig) {
! case 'L':
! case '[': {
! long id = objectIdAt(offset);
! offset += idSize();
! JavaObjectRef ref = new JavaObjectRef(id);
! fieldValues[target + fieldNo] = ref.dereference(snapshot, f, verbose);
! break;
! }
! case 'Z': {
! byte value = byteAt(offset);
! offset++;
! fieldValues[target + fieldNo] = new JavaBoolean(value != 0);
! break;
! }
! case 'B': {
! byte value = byteAt(offset);
! offset++;
! fieldValues[target + fieldNo] = new JavaByte(value);
! break;
! }
! case 'S': {
! short value = shortAt(offset);
! offset += 2;
! fieldValues[target + fieldNo] = new JavaShort(value);
! break;
! }
! case 'C': {
! char value = charAt(offset);
! offset += 2;
! fieldValues[target + fieldNo] = new JavaChar(value);
! break;
! }
! case 'I': {
! int value = intAt(offset);
! offset += 4;
! fieldValues[target + fieldNo] = new JavaInt(value);
! break;
! }
! case 'J': {
! long value = longAt(offset);
! offset += 8;
! fieldValues[target + fieldNo] = new JavaLong(value);
! break;
! }
! case 'F': {
! float value = floatAt(offset);
! offset += 4;
! fieldValues[target + fieldNo] = new JavaFloat(value);
! break;
! }
! case 'D': {
! double value = doubleAt(offset);
! offset += 8;
+ fieldValues[target + fieldNo] = new JavaDouble(value);
+ break;
+ }
+ default:
+ throw new RuntimeException("invalid signature: " + sig);
+ }
}
! } catch (IOException exp) {
! System.err.println("lazy read failed at offset " + offset);
! exp.printStackTrace();
! return Snapshot.EMPTY_JAVATHING_ARRAY;
}
}
return fieldValues;
}
< prev index next >