Path: blob/master/debugtools/DDR_VM/testsrc/DTFJKickTyres.java
6000 views
import java.io.File;1import java.util.Iterator;2import java.util.Properties;34import com.ibm.dtfj.image.Image;5import com.ibm.dtfj.image.ImageAddressSpace;6import com.ibm.dtfj.image.ImageFactory;7import com.ibm.dtfj.image.ImageModule;8import com.ibm.dtfj.image.ImageProcess;9import com.ibm.dtfj.image.ImageSymbol;10import com.ibm.dtfj.java.JavaRuntime;11import com.ibm.dtfj.java.JavaVMInitArgs;12import com.ibm.dtfj.java.JavaVMOption;13import com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory;1415/*******************************************************************************16* Copyright (c) 2009, 2014 IBM Corp. and others17*18* This program and the accompanying materials are made available under19* the terms of the Eclipse Public License 2.0 which accompanies this20* distribution and is available at https://www.eclipse.org/legal/epl-2.0/21* or the Apache License, Version 2.0 which accompanies this distribution and22* is available at https://www.apache.org/licenses/LICENSE-2.0.23*24* This Source Code may also be made available under the following25* Secondary Licenses when the conditions for such availability set26* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU27* General Public License, version 2 with the GNU Classpath28* Exception [1] and GNU General Public License, version 2 with the29* OpenJDK Assembly Exception [2].30*31* [1] https://www.gnu.org/software/classpath/license.html32* [2] http://openjdk.java.net/legal/assembly-exception.html33*34* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception35*******************************************************************************/3637/**38* @author andhall39*40*/41public class DTFJKickTyres42{4344/**45* @param args46*/47public static void main(String[] args) throws Exception48{49boolean useJExtract = false;5051if (args.length > 1) {52if (args[1].toLowerCase().trim().equals("jextract")) {53useJExtract = true;54}55}5657ImageFactory factory = null;58if (useJExtract) {59try {60Class<?> jxfactoryclass = Class.forName("com.ibm.dtfj.image.j9.ImageFactory");61factory = (ImageFactory)jxfactoryclass.newInstance();62} catch (Exception e) {63System.out.println("Could not create a jextract based implementation of ImageFactory");64e.printStackTrace();65System.exit(1);66}67} else {68factory = new J9DDRImageFactory();69}7071Image img = factory.getImage(new File(args[0]));7273Iterator<?> addressSpaceIt = img.getAddressSpaces();7475while (addressSpaceIt.hasNext()) {7677ImageAddressSpace as = (ImageAddressSpace)addressSpaceIt.next();7879Iterator<?> processIt = as.getProcesses();8081while (processIt.hasNext()) {82ImageProcess process = (ImageProcess)processIt.next();8384System.err.println("Got process " + process);85try {86System.err.println("Command line was " + process.getCommandLine());87} catch (Throwable t) {88t.printStackTrace();89}9091try {92System.err.println("Executable was: " + process.getExecutable());93} catch (Throwable t) {94t.printStackTrace();95}969798try {99System.err.println("Modules were:");100101Iterator<?> it = process.getLibraries();102103if (!it.hasNext()) {104System.err.println("No modules!");105}106107while (it.hasNext()) {108ImageModule module = (ImageModule) it.next();109110System.err.println("* " + module.getName());111112Iterator<?> symIt = module.getSymbols();113114while (symIt.hasNext()) {115Object symObj = symIt.next();116if (symObj instanceof ImageSymbol) {117ImageSymbol sym = (ImageSymbol) symObj;118119if (sym.getName().toLowerCase().contains("environ")) {120System.err.println("X sym " + sym.getName() + " = " + sym.getAddress());121}122}123}124}125} catch (Throwable t) {126t.printStackTrace();127}128129try {130Properties env = process.getEnvironment();131132System.err.println("Environment");133for (Object key : env.keySet()) {134System.err.println(key + " = " + env.getProperty((String)key));135}136} catch (Throwable t) {137t.printStackTrace();138}139140Iterator<?> runtimeIt = process.getRuntimes();141142while (runtimeIt.hasNext()) {143JavaRuntime runtime = (JavaRuntime) runtimeIt.next();144145System.err.println("Got runtime: " + runtime);146147JavaVMInitArgs initArgs = runtime.getJavaVMInitArgs();148149Iterator<?> optionsIt = initArgs.getOptions();150151System.err.println("Options:");152while (optionsIt.hasNext()) {153Object optionObj = optionsIt.next();154155if (optionObj instanceof JavaVMOption) {156JavaVMOption option = (JavaVMOption) optionObj;157158System.err.println("* " + option.getOptionString());159}160}161}162}163164}165}166167}168169170