use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.
the class PHDJavaClassLoader method processData.
private void processData(HeapdumpReader reader, final PHDImage parentImage, final ImageAddressSpace space, final PHDJavaRuntime runtime) throws IOException {
final JavaClassLoader loader = this;
final int adjustLen = reader.version() == 4 && reader.isJ9() ? 1 : 0;
final int[] realClasses = new int[1];
try {
reader.parse(new PortableHeapDumpListener() {
long prevAddress;
PHDJavaClass prevObjClass;
private void updateSizes(long address) {
if (prevObjClass != null)
prevObjClass.updateSize(prevAddress, address);
prevObjClass = null;
prevAddress = address;
}
public void classDump(long address, long superAddress, String name, int size, int flags, int hashCode, LongEnumeration refs) throws Exception {
updateSizes(address);
classes.put(address, new PHDJavaClass.Builder(space, runtime, loader, address, superAddress, name).size(size).flags(flags).hashCode(hashCode).refs(refs).build());
updateAddresses(address, size, name);
++realClasses[0];
}
public void objectArrayDump(long address, long classAddress, int flags, int hashCode, LongEnumeration refs, int length, long instanceSize) throws Exception {
int refsLen = refs.numberOfElements();
int adjustLen2 = Math.min(adjustLen, refsLen);
updateSizes(address);
updateAddresses(address, classAddress, length - adjustLen2);
long classAddress2 = adjustLen2 == 1 ? refs.nextLong() : 0;
genArrayClasses(space, runtime, loader, adjustLen2, classAddress, classAddress2);
}
public void objectDump(long address, long classAddress, int flags, int hashCode, LongEnumeration refs, long instanceSize) throws Exception {
updateSizes(address);
updateAddresses(address, classAddress, -1);
genObjectClass(space, runtime, loader, classAddress, hashCode);
}
public void primitiveArrayDump(long address, int type, int length, int flags, int hashCode, long instanceSize) throws Exception {
updateSizes(address);
updateAddresses(address, type, length);
}
private void genObjectClass(final ImageAddressSpace space, final PHDJavaRuntime runtime, final JavaClassLoader loader, long classAddress, int hashCode) {
if (!classes.containsKey(classAddress)) {
PHDJavaClass objClass = new PHDJavaClass.Builder(space, runtime, loader, classAddress, PHDJavaClass.UNKNOWN_SUPERCLASS, PHDJavaClass.UNKNOWN_NONARRAY).build();
classes.put(classAddress, objClass);
updateAddresses(classAddress, 100, null);
}
prevObjClass = (PHDJavaClass) findClass(classAddress);
}
private PHDJavaClass genArrayClass(final ImageAddressSpace space, final PHDJavaRuntime runtime, final JavaClassLoader loader, long classAddress, long sup, String name) {
PHDJavaClass elemCls;
int size = 100;
elemCls = new PHDJavaClass.Builder(space, runtime, loader, classAddress, sup, name).build();
classes.put(classAddress, elemCls);
updateAddresses(classAddress, size, name);
return elemCls;
}
private void genArrayClasses(final ImageAddressSpace space, final PHDJavaRuntime runtime, final JavaClassLoader loader, final int adjustLen, long classAddress, long classAddress2) {
if (adjustLen == 1) {
// Java 5.0 arrays with type = base component type e.g. String
// First reference = actual array type e.g. [[Ljava.lang.String;
JavaClass arrayCls;
if (!classes.containsKey(classAddress2)) {
String name = PHDJavaClass.UNKNOWN_ARRAY;
arrayCls = genArrayClass(space, runtime, loader, classAddress2, jlo, name);
} else {
arrayCls = findClass(classAddress2);
}
arrayClasses.put(classAddress, arrayCls);
if (!classes.containsKey(classAddress)) {
String name = PHDJavaClass.UNKNOWN_NONARRAY;
genArrayClass(space, runtime, loader, classAddress, PHDJavaClass.UNKNOWN_SUPERCLASS, name);
}
} else {
arrayClasses.put(classAddress, null);
}
return;
}
});
} catch (EOFException e) {
classes.put(runtime.nextDummyClassAddr(), new PHDCorruptJavaClass("Truncated dump found building class " + realClasses[0], null, e));
} catch (IOException e) {
classes.put(runtime.nextDummyClassAddr(), new PHDCorruptJavaClass("Corrupted dump found building class " + realClasses[0], null, e));
} catch (Exception e) {
classes.put(runtime.nextDummyClassAddr(), new PHDCorruptJavaClass("Building class " + realClasses[0], null, e));
} finally {
reader.close();
reader = null;
}
jlo = 0;
// Use an uncached search as the index hasn't been built.
JavaClass jco = findClassUncached("java/lang/Object");
if (jco != null) {
ImagePointer ip = jco.getID();
if (ip != null)
jlo = ip.getAddress();
} else {
// If the dump is very corrupt it won't have java.lang.Object - so create one
jco = new PHDJavaClass.Builder(space, runtime, loader, 0, 0, "java/lang/Object").build();
jlo = runtime.nextDummyClassAddr();
classes.put(jlo, jco);
}
// If the dump is very corrupt it won't have java.lang.Class - so create one
JavaClass jcl = findClassUncached("java/lang/Class");
if (jcl == null) {
jcl = new PHDJavaClass.Builder(space, runtime, loader, 0, jlo, "java/lang/Class").build();
classes.put(runtime.nextDummyClassAddr(), jcl);
}
// nor will it have primitive array classes
for (int i = 0; i < PHDJavaRuntime.arrayTypeName.length; ++i) {
JavaClass jc = findClassUncached(PHDJavaRuntime.arrayTypeName[i]);
if (jc == null) {
jc = new PHDJavaClass.Builder(space, runtime, loader, 0, jlo, PHDJavaRuntime.arrayTypeName[i]).build();
classes.put(runtime.nextDummyClassAddr(), jc);
}
}
// Bug in PHD dumps - some Java 6 types have the type of an array being the whole array, not the elements
// Is the type of the array the whole array or the type of an element?
boolean arrayTypeIsArray = true;
for (Long id : arrayClasses.keySet()) {
JavaClass cl1 = findClass(id);
// Corrupt dump might not have the class!
if (cl1 == null)
continue;
try {
if (!cl1.isArray()) {
arrayTypeIsArray = false;
}
} catch (CorruptDataException e) {
// If we don't know the type then presume they are not arrays
arrayTypeIsArray = false;
}
}
// Create a mapping from the phd id of an array object to the type of the whole array
for (Long id : arrayClasses.keySet()) {
JavaClass cl1 = findClass(id);
if (cl1 == null) {
String name = arrayTypeIsArray ? PHDJavaClass.UNKNOWN_ARRAY : null;
long sup = arrayTypeIsArray ? jlo : PHDJavaClass.UNKNOWN_SUPERCLASS;
cl1 = new PHDJavaClass.Builder(space, runtime, loader, id, sup, name).build();
classes.put(id, cl1);
}
JavaClass ar = arrayClasses.get(id);
if (ar != null) {
ImagePointer ip = ar.getID();
if (ip != null) {
JavaClass ar2 = findClass(ip.getAddress());
if (ar2 != null) {
ar = ar2;
}
}
// cl1 is not a component type for multidimensional arrays, but is the scalar type
// ((PHDJavaClass)ar).setComponentType(cl1);
}
JavaClass cl2;
if (arrayTypeIsArray) {
cl2 = cl1;
} else if (ar != null) {
cl2 = ar;
} else {
try {
String name = cl1.getName();
String arrayName = arrayName(name);
Set<JavaClass> s = findClasses(arrayName);
if (s.size() == 0) {
// Array class doesn't exist, so create a dummy one
cl2 = new PHDJavaClass.Builder(space, runtime, loader, 0, jlo, arrayName).componentType(cl1).build();
} else if (s.size() == 1) {
// Only one, so use it
cl2 = s.iterator().next();
} else {
// Multiple classes, so if possible choose one
cl2 = null;
for (JavaClass cl3 : s) {
// If so then it is the one.
if (PHDJavaClass.referencesClass(cl3, cl1)) {
cl2 = cl3;
break;
}
}
}
} catch (CorruptDataException e) {
// Array class doesn't exist, so create a dummy one
cl2 = new PHDJavaClass.Builder(space, runtime, loader, 0, jlo, PHDJavaClass.UNKNOWN_ARRAY).componentType(cl1).build();
}
if (cl2 instanceof PHDJavaClass) {
// We know the component type, so remember it for later
((PHDJavaClass) cl2).setComponentType(cl1);
}
}
// Even if the array class is null (we couldn't decide), mark it so we know for later
arrayClasses.put(id, cl2);
}
initCache();
}
use of com.ibm.dtfj.java.JavaClass 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.JavaClass 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.JavaClass 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.JavaClass in project openj9 by eclipse.
the class PHDJavaClassLoader method initCache.
void initCache() {
allClasses.clear();
classNameCache.clear();
for (JavaClass cls : classes.values()) {
cacheClass(cls);
}
for (JavaClass cls : arrayClasses.values()) {
// been found.
if (cls != null)
cacheClass(cls);
}
return;
}
Aggregations