use of com.ibm.dtfj.image.j9.CorruptData in project openj9 by eclipse.
the class JavaClass method getConstantPoolReferences.
/* (non-Javadoc)
* @see com.ibm.dtfj.java.JavaClass#getConstantPoolReferences()
*/
public Iterator getConstantPoolReferences() {
// first look up all the class IDs and translate them into classes then add the objects
Iterator ids = _constantPoolClassRefs.iterator();
Vector allRefs = new Vector();
while (ids.hasNext()) {
long oneID = ((Long) ids.next()).longValue();
Object toBeAdded = null;
com.ibm.dtfj.java.JavaClass oneClass = _javaVM.getClassForID(oneID);
if (oneClass == null) {
toBeAdded = new CorruptData("Unknown class in constant pool " + oneID, null);
} else {
try {
toBeAdded = oneClass.getObject();
} catch (CorruptDataException e) {
toBeAdded = e.getCorruptData();
} catch (Exception e) {
toBeAdded = new CorruptData(e.getMessage());
}
}
allRefs.add(toBeAdded);
}
// Loop through the list of constant pool objects, instantiating them and adding them to the list
for (int i = 0; i < _constantPoolObjects.size(); i++) {
try {
long objectId = ((Long) (_constantPoolObjects.get(i))).longValue();
if (objectId != 0) {
ImagePointer pointer = _javaVM.pointerInAddressSpace(objectId);
try {
JavaObject instance = _javaVM.getObjectAtAddress(pointer);
allRefs.add(instance);
} catch (IllegalArgumentException e) {
// getObjectAtAddress may throw an IllegalArgumentException if the address is not aligned
allRefs.add(new CorruptData(e.getMessage(), pointer));
}
}
} catch (CorruptDataException e) {
allRefs.add(e.getCorruptData());
}
}
return allRefs.iterator();
}
use of com.ibm.dtfj.image.j9.CorruptData in project openj9 by eclipse.
the class JavaObject method getSections.
/* (non-Javadoc)
* @see com.ibm.dtfj.java.JavaObject#getSections()
*/
public Iterator getSections() {
// (not initialized so that code paths will be compiler-validated)
List sections;
// arraylets have a more complicated scheme so handle them differently
if (isArraylet()) {
try {
JavaArrayClass arrayForm = (JavaArrayClass) getJavaClass();
// the first element comes immediately after the header so the offset to it is the size of the header
// NOTE: this header size does NOT count arraylet leaves
int objectHeaderSize = arrayForm.getFirstElementOffset();
// we require the pointer size in order to walk the leaf pointers in the spine
int bytesPerPointer = _javaVM.bytesPerPointer();
try {
int instanceSize = arrayForm.getInstanceSize(this);
// the instance size will include the header and the actual data inside the array so seperate them
long contentDataSize = (long) (instanceSize - objectHeaderSize);
// get the number of leaves, excluding the tail leaf (the tail leaf is the final leaf which points back into the spine). There won't be one if there is isn't a remainder in this calculation since it would be empty
int fullSizeLeaves = (int) (contentDataSize / _arrayletLeafSize);
// find out how big the tail leaf would be
long tailLeafSize = contentDataSize % _arrayletLeafSize;
// if it is non-zero, we know that there must be one (bear in mind the fact that all arraylets have at least 1 leaf pointer - consider empty arrays)
int totalLeafCount = (0 == tailLeafSize) ? fullSizeLeaves : (fullSizeLeaves + 1);
// CMVC 153943 : DTFJ fix for zero-length arraylets - remove code to add 1 to the leaf count in the event that it is 0.
// by always assuming there is a leaf means that when the image sections are determined it will cause an error as there
// is no space allocated in this instace beyond the size of the spine.
String nestedType = arrayForm.getLeafClass().getName();
// 4-byte object alignment in realtime requires the long and double arraylets have padding which may need to be placed before the array data or after, depending on if the alignment succeeded at a natural boundary or not
boolean alignmentCandidate = (4 == _objectAlignment) && ("double".equals(nestedType) || "long".equals(nestedType));
// we will need a size for the section which includes the spine (and potentially the tail leaf or even all the leaves (in immortal))
// start with the object header and the leaves
long headerAndLeafPointers = objectHeaderSize + (totalLeafCount * bytesPerPointer);
long spineSectionSize = headerAndLeafPointers;
// we will now walk the leaves to see if this is an inline arraylet
// first off, see if we would need padding to align the first inline data element
long nextExpectedInteriorLeafAddress = _basePointer.getAddress() + headerAndLeafPointers;
boolean doesHaveTailPadding = false;
if (alignmentCandidate && (totalLeafCount > 0)) {
// alignment candidates need to have at least 1 leaf otherwise there is nothing to align
if (0 == (nextExpectedInteriorLeafAddress % 8)) {
// no need to add extra space here so the extra slot will be at the tail
doesHaveTailPadding = true;
} else {
// we need to bump up our expected location for alignment
nextExpectedInteriorLeafAddress += 4;
spineSectionSize += 4;
if (0 != (nextExpectedInteriorLeafAddress % 8)) {
// this can't happen so the core is corrupt
throw new CorruptDataException(new CorruptData("Arraylet leaf pointer misaligned for object", _basePointer));
}
}
}
Vector externalSections = null;
for (int i = 0; i < totalLeafCount; i++) {
ImagePointer leafPointer = _basePointer.getPointerAt(objectHeaderSize + (i * bytesPerPointer));
if (leafPointer.getAddress() == nextExpectedInteriorLeafAddress) {
// this pointer is interior so add it to the spine section
long internalLeafSize = _arrayletLeafSize;
if (fullSizeLeaves == i) {
// this is the last leaf so get the tail leaf size
internalLeafSize = tailLeafSize;
}
spineSectionSize += internalLeafSize;
nextExpectedInteriorLeafAddress += internalLeafSize;
} else {
// this pointer is exterior so make it its own section
if (null == externalSections) {
externalSections = new Vector();
}
externalSections.add(new JavaObjectImageSection(leafPointer, _arrayletLeafSize));
}
}
if (doesHaveTailPadding) {
// now, add the extra 4 bytes to the end
spineSectionSize += 4;
}
// ensure that we are at least the minimum object size
spineSectionSize = Math.max(spineSectionSize, _arrayletSpineSize);
JavaObjectImageSection spineSection = new JavaObjectImageSection(_basePointer, spineSectionSize);
if (null == externalSections) {
// create the section list, with the spine first (other parts of our implementation use the knowledge that the spine is first to reduce logic duplication)
sections = Collections.singletonList(spineSection);
} else {
sections = new Vector();
sections.add(spineSection);
sections.addAll(externalSections);
}
} catch (MemoryAccessException e) {
// if we had a memory access exception, the spine must be corrupt, or something
sections = Collections.singletonList(new CorruptData("failed to walk arraylet spine", e.getPointer()));
}
} catch (CorruptDataException e) {
sections = Collections.singletonList(e.getCorruptData());
}
} else {
// currently J9 objects are atomic extents of memory but that changes with metronome and that will probably extend to other VM configurations, as well
long size = 0;
try {
size = ((com.ibm.dtfj.java.j9.JavaAbstractClass) getJavaClass()).getInstanceSize(this);
JavaObjectImageSection section = new JavaObjectImageSection(_basePointer, size);
sections = Collections.singletonList(section);
} catch (CorruptDataException e) {
sections = Collections.singletonList(e.getCorruptData());
}
// XXX - handle the case of this corrupt data better (may require API change)
}
return sections.iterator();
}
use of com.ibm.dtfj.image.j9.CorruptData in project openj9 by eclipse.
the class JavaReference method getTarget.
/* (non-Javadoc)
* @see com.ibm.dtfj.java.JavaReference#getTarget()
*/
public Object getTarget() throws DataUnavailable, CorruptDataException {
if (null == _target) {
if (0 == _address) {
// we have no way of determining the target so it is unresolved.
_resolution = ResolutionType_UNRESOLVED;
return null;
}
if (JavaReference.HEAP_ROOT_SYSTEM_CLASS == _roottype || JavaReference.REFERENCE_CLASS == _referencetype || JavaReference.REFERENCE_SUPERCLASS == _referencetype || JavaReference.REFERENCE_LOADED_CLASS == _referencetype || JavaReference.REFERENCE_ASSOCIATED_CLASS == _referencetype) {
// this is a class reference, so create a class to represent the target.
_target = _javaVM.getClassForID(_address);
if (null == _target) {
ImagePointer pointer = _javaVM.pointerInAddressSpace(_address);
_resolution = ResolutionType_BROKEN;
throw new CorruptDataException(new CorruptData("Unknown class ID", pointer));
}
_resolution = ResolutionType_CLASS;
} else if ((JavaReference.HEAP_ROOT_JNI_GLOBAL == _roottype) || (JavaReference.HEAP_ROOT_JNI_LOCAL == _roottype) || (JavaReference.HEAP_ROOT_MONITOR == _roottype) || (JavaReference.HEAP_ROOT_OTHER == _roottype) || (JavaReference.HEAP_ROOT_STACK_LOCAL == _roottype) || (JavaReference.HEAP_ROOT_THREAD == _roottype) || (JavaReference.HEAP_ROOT_FINALIZABLE_OBJ == _roottype) || (JavaReference.HEAP_ROOT_UNFINALIZED_OBJ == _roottype) || (JavaReference.HEAP_ROOT_CLASSLOADER == _roottype) || (JavaReference.HEAP_ROOT_STRINGTABLE == _roottype) || (JavaReference.REFERENCE_ARRAY_ELEMENT == _referencetype) || (JavaReference.REFERENCE_CLASS_LOADER == _referencetype) || (JavaReference.REFERENCE_CONSTANT_POOL == _referencetype) || (JavaReference.REFERENCE_FIELD == _referencetype) || (JavaReference.REFERENCE_INTERFACE == _referencetype) || (JavaReference.REFERENCE_PROTECTION_DOMAIN == _referencetype) || (JavaReference.REFERENCE_SIGNERS == _referencetype) || (JavaReference.REFERENCE_STATIC_FIELD == _referencetype) || (JavaReference.REFERENCE_CLASS_OBJECT == _referencetype)) {
// this is an object reference, so create a object to represent the target.
ImagePointer pointer = _javaVM.pointerInAddressSpace(_address);
try {
_target = _javaVM.getObjectAtAddress(pointer);
} catch (IllegalArgumentException e) {
// getObjectAtAddress can throw an IllegalArgumentException if the address is not aligned
_resolution = ResolutionType_BROKEN;
throw new CorruptDataException(new com.ibm.dtfj.image.j9.CorruptData(e.getMessage(), pointer));
}
if (_target == null) {
_resolution = ResolutionType_BROKEN;
throw new CorruptDataException(new CorruptData("Unknown object ID", pointer));
}
_resolution = ResolutionType_OBJECT;
} else {
// we have no way of determining the target so it is unresolved.
_resolution = ResolutionType_UNRESOLVED;
return null;
}
}
return _target;
}
use of com.ibm.dtfj.image.j9.CorruptData in project openj9 by eclipse.
the class JavaClassLoader method getDefinedClasses.
/* (non-Javadoc)
* @see com.ibm.dtfj.java.JavaClassLoader#getDefinedClasses()
*/
public Iterator getDefinedClasses() {
if (null == _defined) {
// Loop through the list of all classes building a list of this loader's defined classes.
// A defined class is a class whose class loader is this loader
Iterator cached = _javaVM.getClasses();
long thisID = _id.getAddress();
_defined = new ArrayList();
while (cached.hasNext()) {
Object next = cached.next();
// corrupt entries by looking at the cached classes via getCachedClasses()
if (next instanceof CorruptData) {
continue;
}
// Extract the current class
JavaClass currentClass = (JavaClass) next;
try {
// Extract the current class's class loader
JavaClassLoader currentClassLoader = (JavaClassLoader) currentClass.getClassLoader();
// old versions of jextract
if ((currentClassLoader != null) && (currentClassLoader._id.getAddress() == thisID)) {
_defined.add(currentClass);
}
} catch (CorruptDataException e) {
// Ignore this one
}
}
}
return _defined.iterator();
}
use of com.ibm.dtfj.image.j9.CorruptData in project openj9 by eclipse.
the class JavaClass method getReferences.
/* (non-Javadoc)
* @see com.ibm.dtfj.java.JavaClass#getReferences()
*/
public Iterator getReferences() {
// need to build a list of references from this class.
Vector references = new Vector();
JavaReference jRef = null;
// get the Constant Pool references from this class.
Iterator constantPoolIt = getConstantPoolReferences();
while (constantPoolIt.hasNext()) {
// get each reference in turn, note that the iterator can return JavaClass
// JavaObject and CorruptData. The CorruptData objects are ignored.
Object cpObject = constantPoolIt.next();
if (cpObject instanceof JavaObject) {
// add the reference to the container.
jRef = new JavaReference(_javaVM, this, cpObject, "Constant Pool Object", JavaReference.REFERENCE_CONSTANT_POOL, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG);
} else if (cpObject instanceof JavaClass) {
// got a JavaClass
JavaClass jClass = (JavaClass) cpObject;
// add the reference to the container.
jRef = new JavaReference(_javaVM, this, jClass, "Constant Pool Class", JavaReference.REFERENCE_CONSTANT_POOL, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG);
}
if (null != jRef) {
references.add(jRef);
}
}
// get the static field references from this class.
Iterator declaredFieldIt = getDeclaredFields();
while (declaredFieldIt.hasNext()) {
JavaField jField = (JavaField) declaredFieldIt.next();
// got a field, now test it to see if it is a static reference.
if (jField instanceof JavaStaticField) {
JavaStaticField sField = (JavaStaticField) jField;
try {
Object obj = sField.getReferenceType(null);
if (null != obj) {
if (obj instanceof JavaObject) {
// build a JavaReference type and add the reference to the container.
String fieldName = sField.getName();
String description = "Static field";
if (null != fieldName) {
description = description + " [field name:" + fieldName + "]";
}
JavaObject jObject = (JavaObject) obj;
jRef = new JavaReference(_javaVM, this, jObject, description, JavaReference.REFERENCE_STATIC_FIELD, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG);
references.add(jRef);
}
}
} catch (CorruptDataException e) {
// Corrupt data, so add it to the container.
references.add(e.getCorruptData());
} catch (MemoryAccessException e) {
// Memory access problems, so create a CorruptData object
// to describe the problem and add it to the container.
ImagePointer ptrInError = e.getPointer();
String message = e.getMessage();
references.add(new CorruptData(message, ptrInError));
} catch (IllegalArgumentException e) {
// No static data, so ignore.
}
}
}
addSuperclassReference(references);
addClassLoaderReference(references);
addClassObjectReference(references);
return references.iterator();
}
Aggregations