use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class JavaAbstractClass method addClassLoaderReference.
protected void addClassLoaderReference(Collection coll) {
JavaReference jRef = null;
try {
JavaClassLoader classLoader = this.getClassLoader();
if (null != classLoader) {
JavaObject classLoaderObject = classLoader.getObject();
if (null != classLoaderObject) {
jRef = new JavaReference(_javaVM, this, classLoaderObject, "Classloader", JavaReference.REFERENCE_CLASS_LOADER, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG);
coll.add(jRef);
}
}
} catch (CorruptDataException e) {
coll.add(e.getCorruptData());
}
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class JavaThread method getName.
/* (non-Javadoc)
* @see com.ibm.dtfj.java.JavaThread#getName()
*/
public String getName() throws CorruptDataException {
JavaObject theObject = getObject();
if (null != theObject) {
JavaClass threadClass = _javaLangThreadSuperclass();
Iterator fields = threadClass.getDeclaredFields();
while (fields.hasNext()) {
JavaField oneField = (JavaField) fields.next();
if (oneField.getName().equals("name")) {
try {
return oneField.getString(theObject);
} catch (MemoryAccessException e) {
throw new CorruptDataException(new CorruptData("unable to read memory for 'name' field", null));
}
}
}
throw new CorruptDataException(new CorruptData("unable to find 'name' field", null));
} else {
return "vmthread @" + _jniEnv.getAddress();
}
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class JavaHeapRegion method getObjectAtAddress.
public JavaObject getObjectAtAddress(ImagePointer address) throws CorruptDataException, IllegalArgumentException {
JavaObject object = null;
if ((null != address) && (0 != address.getAddress())) {
// try the special objects cache first...
JavaObject specialObject = _javaVM.getSpecialObject(address);
if (null != specialObject) {
return specialObject;
}
// CMVC 173262 - check alignment
if ((address.getAddress() & (_objectAlignment - 1)) != 0) {
throw new IllegalArgumentException("Invalid alignment for JavaObject should be " + _objectAlignment + " aligned. Address = " + address.toString());
}
long arrayletIdentificationBitmask = 0;
long arrayletIdentificationResult = 0;
int arrayletIdentificationWidth = 0;
int arrayletIdentificationOffset = 0;
int arrayletSpineSize = 0;
long arrayletLeafSize = 0;
arrayletIdentificationBitmask = _parentHeap.getArrayletIdentificationBitmask();
arrayletIdentificationResult = _parentHeap.getArrayletIdentificationResult();
arrayletIdentificationWidth = _parentHeap.getArrayletIdentificationWidth();
arrayletIdentificationOffset = _parentHeap.getArrayletIdentificationOffset();
arrayletSpineSize = getArrayletSpineSize();
arrayletLeafSize = getArrayletLeafSize();
boolean isArraylet = false;
if (0 != arrayletIdentificationResult) {
// note that this may be an arraylet so we need to do some extra work here
long maskedFlags = 0;
if (4 == arrayletIdentificationWidth) {
try {
maskedFlags = 0xFFFFFFFFL & (long) (address.getIntAt(arrayletIdentificationOffset));
} catch (MemoryAccessException e) {
throw new CorruptDataException(new CorruptData("unable to access object flags", address));
}
} else if (8 == arrayletIdentificationWidth) {
try {
maskedFlags = address.getLongAt(arrayletIdentificationOffset);
} catch (MemoryAccessException e) {
throw new CorruptDataException(new CorruptData("unable to access object flags", address));
}
} else {
// this size cannot be read without exposing endian of the underlying core
System.err.println("Arraylet identification width is invalid: " + arrayletIdentificationWidth + " (should be 4 or 8)");
}
isArraylet = arrayletIdentificationResult == (arrayletIdentificationBitmask & maskedFlags);
}
object = new com.ibm.dtfj.java.j9.JavaObject(_javaVM, address, _parentHeap, arrayletSpineSize, arrayletLeafSize, isArraylet, _objectAlignment);
}
return object;
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class PHDJavaClass method getReferences.
public Iterator<JavaReference> getReferences() {
final JavaClass source = this;
return new Iterator<JavaReference>() {
int count;
JavaClass sup;
JavaObject load;
{
try {
sup = getSuperclass();
if (sup != null)
count = -1;
} catch (CorruptDataException e) {
}
try {
load = loader.getObject();
if (load != null)
count = -2;
} catch (CorruptDataException e) {
}
}
public boolean hasNext() {
if (count < 0) {
return true;
} else if (refs instanceof LongEnumeration) {
LongEnumeration le = (LongEnumeration) refs;
return le.hasMoreElements();
} 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;
Object cls = null;
if (count == -2) {
cls = load;
++count;
// Skip over the superclass if not present
if (sup == null)
++count;
ref = 0;
refType = PHDJavaReference.REFERENCE_CLASS_LOADER;
} else if (count == -1) {
cls = sup;
++count;
ref = 0;
refType = PHDJavaReference.REFERENCE_SUPERCLASS;
} else {
if (refs instanceof LongEnumeration) {
LongEnumeration le = (LongEnumeration) refs;
ref = le.nextLong();
++count;
} else if (refs instanceof int[]) {
int[] arefs = (int[]) refs;
ref = runtime.expandAddress(arefs[count++]);
} else {
long[] arefs = (long[]) refs;
ref = arefs[count++];
}
cls = runtime.findClass(ref);
}
if (cls != null) {
return new PHDJavaReference(cls, source, PHDJavaReference.REACHABILITY_STRONG, refType, PHDJavaReference.HEAP_ROOT_UNKNOWN, "?");
} else {
return new PHDJavaReference(new PHDJavaObject.Builder((PHDJavaHeap) (runtime.getHeaps().next()), 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 PHDJavaHeap method getCachedObjectAtAddress.
JavaObject getCachedObjectAtAddress(ImagePointer address, boolean withRefs) throws IOException {
for (CacheHeapSegment seg : cache.values()) {
SoftReference<Map<AddressKey, JavaObject>> sr = seg.objects;
Map<AddressKey, JavaObject> map = sr.get();
if (map == null || withRefs && !seg.withRefs && map.get(AddressKey.getAddress(PHDJavaHeap.this, address.getAddress())) != null) {
long addr = address.getAddress();
if (seg.minAddress <= addr && addr <= seg.maxAddress) {
// Possibly here, so refresh the data
int[] next = new int[] { seg.index };
map = getObjects(seg.maxSize, next, withRefs);
seg.withRefs = withRefs;
seg.objects = sr = new SoftReference<Map<AddressKey, JavaObject>>(map);
}
}
if (map != null) {
JavaObject jo = map.get(AddressKey.getAddress(PHDJavaHeap.this, address.getAddress()));
if (jo != null) {
// Found object
return jo;
}
}
}
return null;
}
Aggregations