use of com.ibm.dtfj.image.CorruptDataException in project openj9 by eclipse.
the class J9DDRImageProcess method getEnvironment.
/**
* This method gets the environment variables.
* First it tries to extract it from RAS structure.
* If not, it tries to get it from loaded modules.
* @return Properties instance of environment variables.
* @throws DataUnavailable
* @throws CorruptDataException
*/
public Properties getEnvironment() throws DataUnavailable, CorruptDataException {
try {
checkFailureInfo();
if (j9rasProcessData != null) {
try {
Properties properties;
long environ = j9rasProcessData.getEnvironment();
if (process.getPlatform() == Platform.WINDOWS && j9rasProcessData.version() > 4) {
// Get the env vars from an environment strings block instead of the environ global
properties = EnvironmentUtils.readEnvironmentStrings(process, environ);
} else {
long stringPointer = process.getPointerAt(environ);
properties = EnvironmentUtils.readEnvironment(process, stringPointer);
}
if ((null == properties) || (0 == properties.size())) {
/* In the case of env vars is null or empty,
* throw exception so that it tries to get env vars from modules
*/
throw new com.ibm.j9ddr.CorruptDataException("");
}
return properties;
} catch (com.ibm.j9ddr.CorruptDataException e1) {
/* Seems like RAS structure is corrupted. Try to get it from modules. */
return process.getEnvironmentVariables();
}
} else {
/* We don't have a J9RAS structure to work with. Try to get it from modules. */
return process.getEnvironmentVariables();
}
} catch (com.ibm.j9ddr.CorruptDataException e) {
throw new DTFJCorruptDataException(process, e);
} catch (DataUnavailableException e) {
throw new DataUnavailable(e.getMessage());
}
}
use of com.ibm.dtfj.image.CorruptDataException in project openj9 by eclipse.
the class DTFJJavaRuntimeHelper method getTotalHeapSize.
@SuppressWarnings("rawtypes")
public static long getTotalHeapSize(JavaRuntime runtime, IProcess process) throws CorruptDataException {
if (totalSizeOfAllHeaps > 0) {
// already calculated, never changes
return totalSizeOfAllHeaps;
}
if (runtime == null) {
throw new com.ibm.dtfj.image.CorruptDataException(J9DDRDTFJUtils.newCorruptData(process, "No Java Runtime present"));
}
Iterator heaps = runtime.getHeaps();
while (heaps.hasNext()) {
Object nextHeap = heaps.next();
Iterator sections;
if (nextHeap instanceof JavaHeap) {
sections = ((JavaHeap) nextHeap).getSections();
} else {
// CorruptData?
throw new com.ibm.dtfj.image.CorruptDataException(J9DDRDTFJUtils.newCorruptData(process, "Corrupt heap encountered whilst calculating total heap size"));
}
while (sections.hasNext()) {
Object nextSection = sections.next();
if (nextSection instanceof ImageSection) {
long sectionSize = ((ImageSection) nextSection).getSize();
if (Long.MAX_VALUE - sectionSize > totalSizeOfAllHeaps) {
totalSizeOfAllHeaps += sectionSize;
} else {
// no point adding further, the cap is on Long.MAX_VALUE
return Long.MAX_VALUE;
}
} else {
// CorruptData?
throw new com.ibm.dtfj.image.CorruptDataException(J9DDRDTFJUtils.newCorruptData(process, "Corrupt section encountered whilst calculating total heap size"));
}
}
}
return totalSizeOfAllHeaps;
}
use of com.ibm.dtfj.image.CorruptDataException in project openj9 by eclipse.
the class DTFJJavaObject method getHeap.
public JavaHeap getHeap() throws CorruptDataException, DataUnavailable {
try {
if (heap == null) {
DTFJJavaRuntime runtime = DTFJContext.getRuntime();
heap = runtime.getHeapFromAddress(DTFJContext.getImagePointer(object.getAddress()));
if (heap == null) {
throw new CorruptDataException(new CorruptJavaObject(null, object));
}
}
return heap;
} catch (Throwable t) {
throw J9DDRDTFJUtils.handleAsCorruptDataException(DTFJContext.getProcess(), t);
}
}
use of com.ibm.dtfj.image.CorruptDataException in project openj9 by eclipse.
the class DTFJJavaObject method getAssociatedClass.
private JavaClass getAssociatedClass(JavaObject targetClassLoaderObject) {
Iterator<?> classloaderIt = DTFJContext.getRuntime().getJavaClassLoaders();
while (classloaderIt.hasNext()) {
Object clObj = classloaderIt.next();
if (clObj instanceof JavaClassLoader) {
JavaClassLoader loader = (JavaClassLoader) clObj;
try {
if (targetClassLoaderObject != null && !loader.getObject().equals(targetClassLoaderObject)) {
continue;
}
} catch (CorruptDataException e1) {
// This is an optimisation so if it fails, continue.
}
Iterator<?> classesIt = loader.getDefinedClasses();
while (classesIt.hasNext()) {
Object classObj = classesIt.next();
if (classObj instanceof JavaClass) {
JavaClass clazz = (JavaClass) classObj;
try {
if (clazz.getObject().equals(this)) {
return clazz;
}
} catch (CorruptDataException e) {
// Deliberately do nothing. If this is the class we're interesting in, we'll
// insert a CorruptData object later when it isn't found. If it's not the class
// we want, we don't need to worry
}
}
}
}
}
return null;
}
use of com.ibm.dtfj.image.CorruptDataException in project openj9 by eclipse.
the class DTFJJavaObject method getSections.
public Iterator getSections() {
try {
fetchDeferredData();
LinkedList<ImageSection> sections = new LinkedList<ImageSection>();
long mainSectionSize = ObjectModel.getConsumedSizeInBytesWithHeader(object).longValue();
String name = getSectionName(mainSectionSize);
J9DDRImageSection section = DTFJContext.getImageSection(object.getAddress(), name);
section.setSize(mainSectionSize);
sections.add(section);
return sections.iterator();
} catch (CorruptDataException e) {
return corruptIterator(e.getCorruptData());
} catch (Throwable t) {
CorruptData cd = J9DDRDTFJUtils.handleAsCorruptData(DTFJContext.getProcess(), t);
return corruptIterator(cd);
}
}
Aggregations