use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class PHDJavaHeap method getSections.
public Iterator<ImageSection> getSections() {
List<ImageSection> c = new ArrayList<ImageSection>();
// This is the start of the last object
long last = runtime.maxAddress;
if (runtime.minAddress <= runtime.maxAddress) {
ImagePointer objPointer = space.getPointer(last);
JavaObject lastObj = null;
try {
lastObj = getLastObject(objPointer, runtime.maxObjClass, runtime.maxObjLen);
} catch (IOException e1) {
// allow to fall through so that jo is null
}
try {
// Find the end of the last object
if (lastObj != null)
last += lastObj.getSize();
ImageSection s = new PHDImageSection(getName(), space.getPointer(runtime.minAddress), last - runtime.minAddress);
c.add(s);
} catch (CorruptDataException e) {
ImageSection s = new PHDImageSection(getName(), space.getPointer(runtime.minAddress), last - runtime.minAddress);
c.add(s);
// The object will take some space
s = new PHDCorruptImageSection("Corrupt " + getName(), objPointer, 8);
c.add(s);
}
}
if (runtime.minClassAddress <= runtime.maxClassAddress) {
// Space in heap for class objects
long last2 = runtime.maxClassAddress;
ImagePointer objPointer = space.getPointer(last2);
int insert = c.size();
ImageSection s;
try {
JavaClass jc = runtime.findClass(last2);
// Make sure the class takes up some room
long size = 8;
if (jc != null) {
JavaObject lastObj = jc.getObject();
if (lastObj != null && lastObj.getID().equals(jc.getID())) {
size = lastObj.getSize();
}
}
last2 += size;
} catch (CorruptDataException e) {
s = new PHDCorruptImageSection("Corrupt " + getName(), objPointer, 8);
c.add(s);
}
// Do the object and class object sections overlap, if so combine them
if (last2 < runtime.minAddress || last < runtime.minClassAddress) {
s = new PHDImageSection(getName(), space.getPointer(runtime.minClassAddress), last2 - runtime.minClassAddress);
c.add(insert, s);
} else {
long minAddr = Math.min(runtime.minAddress, runtime.minClassAddress);
long maxAddr = Math.max(last, last2);
s = new PHDImageSection(getName(), space.getPointer(minAddr), maxAddr - minAddr);
// Replace with a combined section
c.set(0, s);
}
}
return c.iterator();
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class PHDJavaObject method getReferences.
public Iterator<JavaReference> getReferences() {
fillInDetails(true);
final JavaObject source = this;
return new Iterator<JavaReference>() {
int count = -1;
Iterator<JavaClass> loaderCls = heap.runtime.getLoaderClasses(source);
public boolean hasNext() {
if (count < 0) {
return true;
} else if (loaderCls.hasNext()) {
return true;
} else if (refs instanceof LongEnumeration) {
LongEnumeration le = (LongEnumeration) refs;
return count < le.numberOfElements();
} else if (refs instanceof long[]) {
long[] arefs = (long[]) refs;
return count < arefs.length;
} else if (refs instanceof int[]) {
int[] arefs = (int[]) refs;
return count < arefs.length;
} else {
return false;
}
}
public JavaReference next() {
if (!hasNext())
throw new NoSuchElementException("" + count++);
long ref;
int refType = PHDJavaReference.REFERENCE_UNKNOWN;
JavaClass cls1;
if (count == -1) {
// Add the type
cls1 = cls;
// Doesn't matter
ref = 0;
++count;
refType = PHDJavaReference.REFERENCE_CLASS;
} else if (loaderCls.hasNext()) {
refType = PHDJavaReference.REFERENCE_LOADED_CLASS;
cls1 = loaderCls.next();
// Doesn't matter
ref = 0;
} else {
if (refs instanceof LongEnumeration) {
LongEnumeration le = (LongEnumeration) refs;
ref = le.nextLong();
++count;
} else if (refs instanceof int[]) {
int[] arefs = (int[]) refs;
ref = heap.getJavaRuntime().expandAddress(arefs[count++]);
} else {
long[] arefs = (long[]) refs;
ref = arefs[count++];
}
if (length >= 0) {
refType = PHDJavaReference.REFERENCE_ARRAY_ELEMENT;
} else {
refType = PHDJavaReference.REFERENCE_FIELD;
}
cls1 = heap.getJavaRuntime().findClass(ref);
}
if (cls1 != null) {
return new PHDJavaReference(cls1, source, PHDJavaReference.REACHABILITY_STRONG, refType, PHDJavaReference.HEAP_ROOT_UNKNOWN, "?");
} else {
return new PHDJavaReference(new PHDJavaObject.Builder(heap, ref, null, PHDJavaObject.NO_HASHCODE, -1).build(), source, PHDJavaReference.REACHABILITY_STRONG, refType, PHDJavaReference.HEAP_ROOT_UNKNOWN, "?");
}
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class PHDJavaObject method fillInDetails.
/**
* Sometimes a JavaObject is constructed without knowing anything about the type etc.
* If this info is needed then try to retrieve it now.
* @param withRefs Do we need to fill in the references array too?
*/
private void fillInDetails(boolean withRefs) {
if (length == UNRESOLVED_TYPE || withRefs && refs == null) {
JavaObject jo = heap.getObjectAtAddress(getID(), withRefs);
if (equals(jo)) {
PHDJavaObject po = (PHDJavaObject) jo;
if (po.cls != null) {
this.cls = po.cls;
this.hashCode = po.hashCode;
this.flags = po.flags;
} else {
// System.out.println("Oops null cls "+jo+" "+cls);
}
this.length = po.length;
this.refs = po.refs;
} else {
// System.out.println("Oops "+jo+" "+this);
length = UNKNOWN_TYPE;
}
}
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class PHDJavaObject method arraycopy.
public void arraycopy(int srcStart, Object dst, int dstStart, int length) throws CorruptDataException, MemoryAccessException {
if (dst == null)
throw new NullPointerException("destination null");
fillInDetails(true);
if (!isArray())
throw new IllegalArgumentException(this + " is not an array");
JavaClass jc = getJavaClass();
String type;
try {
type = jc.getName();
} catch (CorruptDataException e) {
// Presume all primitive arrays will have a real name
type = "[L";
}
// System.out.println("array "+srcStart+" "+dst+" "+dstStart+" "+length);
if (srcStart < 0 || length < 0 || dstStart < 0 || srcStart + length < 0 || dstStart + length < 0)
throw new IndexOutOfBoundsException(srcStart + "," + dstStart + "," + length);
if (srcStart + length > getArraySize())
throw new IndexOutOfBoundsException(srcStart + "+" + length + ">" + getArraySize() + jc);
if (dst instanceof JavaObject[]) {
if (!type.startsWith("[[") && !type.startsWith("[L"))
throw new IllegalArgumentException("Expected " + type + " not " + dst);
JavaObject[] dst1 = (JavaObject[]) dst;
// Get to the right point in the refs
int count;
if (refs instanceof LongEnumeration) {
LongEnumeration le = (LongEnumeration) refs;
count = le.numberOfElements();
// Skip over the elements before the required start
for (int idx = 0; idx < srcStart && idx < count; ++idx) {
le.nextLong();
}
} else if (refs instanceof int[]) {
int[] arefs = (int[]) refs;
count = arefs.length;
} else if (refs instanceof long[]) {
long[] arefs = (long[]) refs;
count = arefs.length;
} else {
throw new CorruptDataException(new PHDCorruptData("Unknown array contents", getID()));
}
// Copy the data to the destination
for (int idx = srcStart; idx < srcStart + length; ++idx) {
JavaObject target;
if (idx < count) {
long ref;
if (refs instanceof LongEnumeration) {
LongEnumeration le = (LongEnumeration) refs;
ref = le.nextLong();
} else if (refs instanceof int[]) {
int[] arefs = (int[]) refs;
ref = heap.getJavaRuntime().expandAddress(arefs[idx]);
} else {
long[] arefs = (long[]) refs;
ref = arefs[idx];
}
target = new PHDJavaObject.Builder(heap, ref, null, PHDJavaObject.NO_HASHCODE, -1).build();
} else {
target = null;
}
int dstIndex = dstStart + (idx - srcStart);
if (dstIndex >= dst1.length) {
throw new IndexOutOfBoundsException("Array " + jc + " 0x" + Long.toHexString(address) + "[" + getArraySize() + "]" + "," + srcStart + "," + dst1 + "[" + dst1.length + "]" + "," + dstStart + "," + length + " at " + idx);
}
dst1[dstIndex] = target;
}
} else if (dst instanceof byte[]) {
if (!type.startsWith("[B"))
throw new IllegalArgumentException("Expected " + type + " not " + dst);
byte[] dst1 = (byte[]) dst;
if (dstStart + length > dst1.length)
throw new IndexOutOfBoundsException();
} else if (dst instanceof short[]) {
if (!type.startsWith("[S"))
throw new IllegalArgumentException("Expected " + type + " not " + dst);
short[] dst1 = (short[]) dst;
if (dstStart + length > dst1.length)
throw new IndexOutOfBoundsException();
} else if (dst instanceof int[]) {
if (!type.startsWith("[I"))
throw new IllegalArgumentException("Expected " + type + " not " + dst);
int[] dst1 = (int[]) dst;
if (dstStart + length > dst1.length)
throw new IndexOutOfBoundsException();
} else if (dst instanceof long[]) {
if (!type.startsWith("[J"))
throw new IllegalArgumentException("Expected " + type + " not " + dst);
long[] dst1 = (long[]) dst;
if (dstStart + length > dst1.length)
throw new IndexOutOfBoundsException();
} else if (dst instanceof boolean[]) {
if (!type.startsWith("[Z"))
throw new IllegalArgumentException("Expected " + type + " not " + dst);
boolean[] dst1 = (boolean[]) dst;
if (dstStart + length > dst1.length)
throw new IndexOutOfBoundsException();
} else if (dst instanceof char[]) {
if (!type.startsWith("[C"))
throw new IllegalArgumentException("Expected " + type + " not " + dst);
char[] dst1 = (char[]) dst;
if (dstStart + length > dst1.length)
throw new IndexOutOfBoundsException();
} else if (dst instanceof float[]) {
if (!type.startsWith("[F"))
throw new IllegalArgumentException("Expected " + type + " not " + dst);
float[] dst1 = (float[]) dst;
if (dstStart + length > dst1.length)
throw new IndexOutOfBoundsException();
} else if (dst instanceof double[]) {
if (!type.startsWith("[D"))
throw new IllegalArgumentException("Expected " + type + " not " + dst);
double[] dst1 = (double[]) dst;
if (dstStart + length > dst1.length)
throw new IndexOutOfBoundsException();
} else {
throw new IllegalArgumentException("Expected " + type + " not " + dst);
}
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class PHDJavaRuntime method getObjectAtAddress.
public JavaObject getObjectAtAddress(ImagePointer address) throws CorruptDataException, IllegalArgumentException, MemoryAccessException, DataUnavailable {
// Is it a class object?
final long addr = address.getAddress();
JavaClass cls = findClass(addr);
JavaObject jo;
if (cls != null) {
jo = cls.getObject();
if (jo != null && address.equals(jo.getID()))
return jo;
}
if ((jo = extraObjectsCache.get(addr)) != null) {
return jo;
} else {
// See if we already have this object
for (PHDJavaHeap heap : heaps) {
try {
jo = heap.getCachedObjectAtAddress(address, false);
} catch (IOException e) {
throw new DataUnavailable("The requested object could not be read from the PHD file");
}
if (jo != null)
return jo;
}
// Return a place holder object, may return corrupt data later
jo = new PHDJavaObject.Builder(heaps.get(0), addr, null, PHDJavaObject.NO_HASHCODE, -1).build();
}
return jo;
}
Aggregations