use of com.ibm.dtfj.java.JavaRuntime 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.java.JavaRuntime 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.java.JavaRuntime in project openj9 by eclipse.
the class DTFJHeapSectionUnitTest method setUp.
@Before
public void setUp() throws Exception {
File core = parseCoreFilePath(getSystemProperty(PROPERTY_CORE_FILE_PATH));
File output = new File(getSystemProperty(PROPERTY_OUTPUT_PATH));
if (!output.exists()) {
output.mkdirs();
}
JavaRuntime rt = getRuntime(core);
File jxoutput = new File(output, "dtfj.xml");
filesToCompare[0] = jxoutput.getPath();
generateXML(jxoutput, rt);
testJ9DDR = true;
rt = getRuntime(core);
File ddroutput = new File(output, "ddr.xml");
filesToCompare[1] = ddroutput.getPath();
generateXML(ddroutput, rt);
}
use of com.ibm.dtfj.java.JavaRuntime 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;
}
use of com.ibm.dtfj.java.JavaRuntime in project openj9 by eclipse.
the class JExtractXMLGenerator method getRuntime.
@SuppressWarnings("unchecked")
private JavaRuntime getRuntime() throws Exception {
ImageFactory factory = new J9DDRImageFactory();
File core = new File(opts.get(OPT_CORE_FILE));
if (core.exists()) {
Image image = factory.getImage(core);
for (Iterator spaces = image.getAddressSpaces(); spaces.hasNext(); ) {
Object space = spaces.next();
if (!(space instanceof CorruptData)) {
for (Iterator processes = ((ImageAddressSpace) space).getProcesses(); processes.hasNext(); ) {
Object process = processes.next();
if (!(process instanceof CorruptData)) {
for (Iterator runtimes = ((ImageProcess) process).getRuntimes(); runtimes.hasNext(); ) {
Object runtime = runtimes.next();
if (runtime instanceof JavaRuntime) {
return (JavaRuntime) runtime;
}
}
}
}
}
}
writeComment("Could not find Java runtime in core file");
throw new IllegalArgumentException("Could not find Java runtime");
} else {
throw new IllegalArgumentException("The specified core file : " + core.getAbsolutePath() + " does not exist");
}
}
Aggregations