use of com.ibm.dtfj.image.Image in project openj9 by eclipse.
the class DTFJKickTyres method main.
/**
* @param args
*/
public static void main(String[] args) throws Exception {
boolean useJExtract = false;
if (args.length > 1) {
if (args[1].toLowerCase().trim().equals("jextract")) {
useJExtract = true;
}
}
ImageFactory factory = null;
if (useJExtract) {
try {
Class<?> jxfactoryclass = Class.forName("com.ibm.dtfj.image.j9.ImageFactory");
factory = (ImageFactory) jxfactoryclass.newInstance();
} catch (Exception e) {
System.out.println("Could not create a jextract based implementation of ImageFactory");
e.printStackTrace();
System.exit(1);
}
} else {
factory = new J9DDRImageFactory();
}
Image img = factory.getImage(new File(args[0]));
Iterator<?> addressSpaceIt = img.getAddressSpaces();
while (addressSpaceIt.hasNext()) {
ImageAddressSpace as = (ImageAddressSpace) addressSpaceIt.next();
Iterator<?> processIt = as.getProcesses();
while (processIt.hasNext()) {
ImageProcess process = (ImageProcess) processIt.next();
System.err.println("Got process " + process);
try {
System.err.println("Command line was " + process.getCommandLine());
} catch (Throwable t) {
t.printStackTrace();
}
try {
System.err.println("Executable was: " + process.getExecutable());
} catch (Throwable t) {
t.printStackTrace();
}
try {
System.err.println("Modules were:");
Iterator<?> it = process.getLibraries();
if (!it.hasNext()) {
System.err.println("No modules!");
}
while (it.hasNext()) {
ImageModule module = (ImageModule) it.next();
System.err.println("* " + module.getName());
Iterator<?> symIt = module.getSymbols();
while (symIt.hasNext()) {
Object symObj = symIt.next();
if (symObj instanceof ImageSymbol) {
ImageSymbol sym = (ImageSymbol) symObj;
if (sym.getName().toLowerCase().contains("environ")) {
System.err.println("X sym " + sym.getName() + " = " + sym.getAddress());
}
}
}
}
} catch (Throwable t) {
t.printStackTrace();
}
try {
Properties env = process.getEnvironment();
System.err.println("Environment");
for (Object key : env.keySet()) {
System.err.println(key + " = " + env.getProperty((String) key));
}
} catch (Throwable t) {
t.printStackTrace();
}
Iterator<?> runtimeIt = process.getRuntimes();
while (runtimeIt.hasNext()) {
JavaRuntime runtime = (JavaRuntime) runtimeIt.next();
System.err.println("Got runtime: " + runtime);
JavaVMInitArgs initArgs = runtime.getJavaVMInitArgs();
Iterator<?> optionsIt = initArgs.getOptions();
System.err.println("Options:");
while (optionsIt.hasNext()) {
Object optionObj = optionsIt.next();
if (optionObj instanceof JavaVMOption) {
JavaVMOption option = (JavaVMOption) optionObj;
System.err.println("* " + option.getOptionString());
}
}
}
}
}
}
use of com.ibm.dtfj.image.Image in project openj9 by eclipse.
the class DumpImageMemoryRanges method main.
/**
* @param args
*/
public static void main(String[] args) throws Exception {
String fileName = args[0];
boolean useJExtract = false;
if (args.length > 1) {
if (args[1].toLowerCase().trim().equals("jextract")) {
useJExtract = true;
}
}
ImageFactory factory = null;
if (useJExtract) {
try {
Class<?> jxfactoryclass = Class.forName("com.ibm.dtfj.image.j9.ImageFactory");
factory = (ImageFactory) jxfactoryclass.newInstance();
} catch (Exception e) {
System.out.println("Could not create a jextract based implementation of ImageFactory");
e.printStackTrace();
System.exit(1);
}
} else {
factory = new J9DDRImageFactory();
}
Image img = factory.getImage(new File(fileName));
Iterator<?> addressSpaceIt = img.getAddressSpaces();
while (addressSpaceIt.hasNext()) {
Object addressSpaceObj = addressSpaceIt.next();
if (addressSpaceObj instanceof ImageAddressSpace) {
ImageAddressSpace as = (ImageAddressSpace) addressSpaceObj;
System.err.println("Address space " + as);
List<ImageSection> imageSections = new LinkedList<ImageSection>();
Iterator<?> isIt = as.getImageSections();
while (isIt.hasNext()) {
Object isObj = isIt.next();
if (isObj instanceof ImageSection) {
ImageSection thisIs = (ImageSection) isObj;
imageSections.add(thisIs);
} else {
System.err.println("Weird image section object: " + isObj + ", class = " + isObj.getClass().getName());
}
}
Collections.sort(imageSections, new Comparator<ImageSection>() {
public int compare(ImageSection object1, ImageSection object2) {
int baseResult = Long.signum(object1.getBaseAddress().getAddress() - object2.getBaseAddress().getAddress());
if (baseResult == 0) {
return Long.signum(object1.getSize() - object2.getSize());
} else {
return baseResult;
}
}
});
for (ImageSection thisIs : imageSections) {
System.err.println("0x" + Long.toHexString(thisIs.getBaseAddress().getAddress()) + " - " + "0x" + Long.toHexString(thisIs.getBaseAddress().getAddress() + thisIs.getSize() - 1));
}
} else {
System.err.println("Weird address space object: " + addressSpaceObj + " class = " + addressSpaceObj.getClass().getName());
}
}
}
use of com.ibm.dtfj.image.Image in project openj9 by eclipse.
the class ImageComparator method testEquals.
/* (non-Javadoc)
* @see com.ibm.j9ddr.view.dtfj.test.DTFJComparator#testEquals(java.lang.Object, java.lang.Object, int)
*/
@Override
public void testEquals(Object ddrObject, Object jextractObject, int members) {
Image ddrImg = (Image) ddrObject;
Image jextractImg = (Image) jextractObject;
if ((members & ADDRESS_SPACES) != 0) {
new ImageAddressSpaceComparator().testComparatorIteratorEquals(ddrImg.getAddressSpaces(), jextractImg.getAddressSpaces(), "getAddressSpaces", ImageAddressSpace.class);
}
if ((members & CREATION_TIME) != 0) {
long ddrCreationTime = -1;
long jextractCreationTime = -1;
Exception ddrException = null;
Exception jextractException = null;
try {
ddrCreationTime = ddrImg.getCreationTime();
} catch (DataUnavailable e) {
e.printStackTrace();
ddrException = e;
}
try {
jextractCreationTime = jextractImg.getCreationTime();
} catch (DataUnavailable e) {
e.printStackTrace();
jextractException = e;
}
if (ddrException == null && jextractException == null) {
assertEquals(jextractCreationTime, ddrCreationTime);
} else if (ddrException != null && jextractException != null) {
assertEquals(jextractException.getClass(), ddrException.getClass());
} else {
if (ddrException != null) {
fail("DDR threw an exception, and jextract didn't");
} else {
fail("jextract threw an exception, and ddr didn't");
}
}
}
if ((members & HOST_NAME) != 0) {
String ddrHostname = null;
String jextractHostname = null;
Exception ddrException = null;
Exception jextractException = null;
try {
ddrHostname = ddrImg.getHostName();
} catch (Exception e) {
e.printStackTrace();
ddrException = e;
}
try {
jextractHostname = jextractImg.getHostName();
} catch (Exception e) {
e.printStackTrace();
jextractException = e;
}
if (ddrException == null && jextractException == null) {
assertEquals(jextractHostname, ddrHostname);
} else if (ddrException != null && jextractException != null) {
assertEquals(jextractException.getClass(), ddrException.getClass());
} else {
if (ddrException != null) {
fail("DDR threw an exception, and jextract didn't");
} else {
fail("jextract threw an exception, and ddr didn't");
}
}
}
if ((members & INSTALLED_MEMORY) != 0) {
long ddrInstalledMemory = -1;
long jextractInstalledMemory = -1;
Exception ddrException = null;
Exception jextractException = null;
try {
ddrInstalledMemory = ddrImg.getInstalledMemory();
} catch (DataUnavailable e) {
e.printStackTrace();
ddrException = e;
}
try {
jextractInstalledMemory = jextractImg.getInstalledMemory();
} catch (DataUnavailable e) {
e.printStackTrace();
jextractException = e;
}
if (ddrException == null && jextractException == null) {
assertEquals(jextractInstalledMemory, ddrInstalledMemory);
} else if (ddrException != null && jextractException != null) {
assertEquals(jextractException.getClass(), ddrException.getClass());
} else {
if (ddrException != null) {
fail("DDR threw an exception, and jextract didn't");
} else {
fail("jextract threw an exception, and ddr didn't");
}
}
}
if ((members & IP_ADDRESSES) != 0) {
Iterator<?> ddrIt = null;
Iterator<?> jextractIt = null;
Exception ddrException = null;
Exception jextractException = null;
try {
ddrIt = ddrImg.getIPAddresses();
} catch (Exception e) {
e.printStackTrace();
ddrException = e;
}
try {
jextractIt = jextractImg.getIPAddresses();
} catch (Exception e) {
e.printStackTrace();
jextractException = e;
}
if (ddrException == null && jextractException == null) {
// Slurp iterators into lists, sort lists, compare contents
List<?> ddrList = slurpIterator(ddrIt);
List<?> jextractList = slurpIterator(jextractIt);
assertEquals("IP address lists different lengths", jextractList.size(), ddrList.size());
Comparator<Object> inetAddressComp = new Comparator<Object>() {
public int compare(Object o1, Object o2) {
InetAddress i1 = (InetAddress) o1;
InetAddress i2 = (InetAddress) o2;
return i1.getHostAddress().compareTo(i2.getHostAddress());
}
};
Collections.sort(ddrList, inetAddressComp);
Collections.sort(jextractList, inetAddressComp);
assertEquals(jextractList, ddrList);
} else if (ddrException != null && jextractException != null) {
assertEquals(jextractException.getClass(), ddrException.getClass());
} else {
if (ddrException != null) {
fail("DDR threw an exception, and jextract didn't");
} else {
fail("jextract threw an exception, and ddr didn't");
}
}
}
if ((members & PROCESSOR_COUNT) != 0) {
int ddrProcessorCount = -1;
int jextractProcessorCount = -1;
Exception ddrException = null;
Exception jextractException = null;
try {
ddrProcessorCount = ddrImg.getProcessorCount();
} catch (DataUnavailable e) {
e.printStackTrace();
ddrException = e;
}
try {
jextractProcessorCount = jextractImg.getProcessorCount();
} catch (DataUnavailable e) {
e.printStackTrace();
jextractException = e;
}
if (ddrException == null && jextractException == null) {
assertEquals(jextractProcessorCount, ddrProcessorCount);
} else if (ddrException != null && jextractException != null) {
assertEquals(jextractException.getClass(), ddrException.getClass());
} else {
if (ddrException != null) {
fail("DDR threw an exception, and jextract didn't");
} else {
fail("jextract threw an exception, and ddr didn't");
}
}
}
if ((members & PROCESSOR_SUB_TYPE) != 0) {
String ddrSubType = null;
String jextractSubType = null;
Exception ddrException = null;
Exception jextractException = null;
try {
ddrSubType = ddrImg.getProcessorSubType();
} catch (Exception e) {
e.printStackTrace();
ddrException = e;
}
try {
jextractSubType = jextractImg.getProcessorSubType();
} catch (Exception e) {
e.printStackTrace();
jextractException = e;
}
if (ddrException == null && jextractException == null) {
assertEquals(jextractSubType, ddrSubType);
} else if (ddrException != null && jextractException != null) {
assertEquals(jextractException.getClass(), ddrException.getClass());
} else {
if (ddrException != null) {
fail("DDR threw an exception, and jextract didn't");
} else {
fail("jextract threw an exception, and ddr didn't");
}
}
}
if ((members & PROCESSOR_TYPE) != 0) {
String ddrType = null;
String jextractType = null;
Exception ddrException = null;
Exception jextractException = null;
try {
ddrType = ddrImg.getProcessorType();
} catch (Exception e) {
e.printStackTrace();
ddrException = e;
}
try {
jextractType = jextractImg.getProcessorType();
} catch (Exception e) {
e.printStackTrace();
jextractException = e;
}
if (ddrException == null && jextractException == null) {
assertEquals(jextractType, ddrType);
} else if (ddrException != null && jextractException != null) {
assertEquals(jextractException.getClass(), ddrException.getClass());
} else {
if (ddrException != null) {
fail("DDR threw an exception, and jextract didn't");
} else {
fail("jextract threw an exception, and ddr didn't");
}
}
}
if ((members & SYSTEM_TYPE) != 0) {
String ddrType = null;
String jextractType = null;
Exception ddrException = null;
Exception jextractException = null;
try {
ddrType = ddrImg.getSystemType();
} catch (Exception e) {
e.printStackTrace();
ddrException = e;
}
try {
jextractType = jextractImg.getSystemType();
} catch (Exception e) {
e.printStackTrace();
jextractException = e;
}
if (ddrException == null && jextractException == null) {
assertEquals(jextractType, ddrType);
} else if (ddrException != null && jextractException != null) {
assertEquals(jextractException.getClass(), ddrException.getClass());
} else {
if (ddrException != null) {
fail("DDR threw an exception, and jextract didn't");
} else {
fail("jextract threw an exception, and ddr didn't");
}
}
}
if ((members & SYSTEM_SUB_TYPE) != 0) {
String ddrType = null;
String jextractType = null;
Exception ddrException = null;
Exception jextractException = null;
try {
ddrType = ddrImg.getSystemSubType();
} catch (Exception e) {
e.printStackTrace();
ddrException = e;
}
try {
jextractType = jextractImg.getSystemSubType();
} catch (Exception e) {
e.printStackTrace();
jextractException = e;
}
if (ddrException == null && jextractException == null) {
assertEquals(jextractType, ddrType);
} else if (ddrException != null && jextractException != null) {
assertEquals(jextractException.getClass(), ddrException.getClass());
} else {
if (ddrException != null) {
fail("DDR threw an exception, and jextract didn't");
} else {
fail("jextract threw an exception, and ddr didn't");
}
}
}
}
use of com.ibm.dtfj.image.Image in project openj9 by eclipse.
the class DTFJTest method getRuntime.
public JavaRuntime getRuntime(File core) throws Exception {
ImageFactory factory = getImageFactory();
Image image = factory.getImage(core);
log.finest("Image returned: " + image);
@SuppressWarnings("unchecked") Iterator addressSpaceIt = image.getAddressSpaces();
while (addressSpaceIt.hasNext()) {
Object asObj = addressSpaceIt.next();
if (asObj instanceof CorruptData) {
log.warning("Corrupt AddressSpace returned: " + asObj);
} else if (asObj instanceof ImageAddressSpace) {
ImageAddressSpace as = (ImageAddressSpace) asObj;
log.finest("Address Space: " + as + " found");
@SuppressWarnings("unchecked") Iterator processIterator = as.getProcesses();
while (processIterator.hasNext()) {
Object processObj = processIterator.next();
if (processObj instanceof CorruptData) {
log.warning("Corrupt ImageProcess returned: " + asObj);
} else if (processObj instanceof ImageProcess) {
ImageProcess process = (ImageProcess) processObj;
log.finest("ImageProcess: " + process + " found");
@SuppressWarnings("unchecked") Iterator runtimeIterator = process.getRuntimes();
while (runtimeIterator.hasNext()) {
Object runtimeObj = runtimeIterator.next();
if (runtimeObj instanceof CorruptData) {
log.warning("Corrupt ImageProcess returned: " + asObj);
} else if (runtimeObj instanceof JavaRuntime) {
JavaRuntime runtime = (JavaRuntime) runtimeObj;
log.finer("JavaRuntime found: " + runtime + ", was loaded by " + runtime.getClass().getClassLoader());
return runtime;
} else {
throw new ClassCastException("Unexpected type from Runtime iterator: " + runtimeObj.getClass() + ": " + runtimeObj);
}
}
} else {
throw new ClassCastException("Unexpected type from Process iterator: " + processObj.getClass() + ": " + processObj);
}
}
} else {
throw new ClassCastException("Unexpected type from AddressSpace iterator: " + asObj.getClass() + ": " + asObj);
}
}
throw new RuntimeException("Could not find a Java Runtime");
}
use of com.ibm.dtfj.image.Image in project openj9 by eclipse.
the class ImageCreator method createJavaRuntime.
public JavaRuntime createJavaRuntime(TCKConfiguration conf) throws IOException {
Image image = createProcessImage(conf);
Iterator<?> it = image.getAddressSpaces();
while (it.hasNext()) {
Object addressSpaceObj = it.next();
if (addressSpaceObj instanceof ImageAddressSpace) {
ImageAddressSpace as = (ImageAddressSpace) addressSpaceObj;
Iterator<?> processesIt = as.getProcesses();
while (processesIt.hasNext()) {
Object processObj = processesIt.next();
if (processObj instanceof ImageProcess) {
ImageProcess process = (ImageProcess) processObj;
Iterator<?> runtimeIterator = process.getRuntimes();
while (runtimeIterator.hasNext()) {
Object runtimeObj = runtimeIterator.next();
if (runtimeObj instanceof JavaRuntime) {
return (JavaRuntime) runtimeObj;
} else {
throw new IOException("Unexpected runtime object: " + runtimeObj + ", class = " + runtimeObj.getClass());
}
}
} else {
throw new IOException("Unexpected process object: " + processObj + ", class = " + processObj.getClass());
}
}
} else {
throw new IOException("Unexpected address space object: " + addressSpaceObj + ", class = " + addressSpaceObj.getClass());
}
}
return null;
}
Aggregations