Path: blob/master/debugtools/DDR_VM/testsrc/DumpImageMemoryRanges.java
6000 views
import java.io.File;1import java.util.Collections;2import java.util.Comparator;3import java.util.Iterator;4import java.util.LinkedList;5import java.util.List;67import com.ibm.dtfj.image.Image;8import com.ibm.dtfj.image.ImageAddressSpace;9import com.ibm.dtfj.image.ImageFactory;10import com.ibm.dtfj.image.ImageSection;11import com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory;1213/*******************************************************************************14* Copyright (c) 2010, 2014 IBM Corp. and others15*16* This program and the accompanying materials are made available under17* the terms of the Eclipse Public License 2.0 which accompanies this18* distribution and is available at https://www.eclipse.org/legal/epl-2.0/19* or the Apache License, Version 2.0 which accompanies this distribution and20* is available at https://www.apache.org/licenses/LICENSE-2.0.21*22* This Source Code may also be made available under the following23* Secondary Licenses when the conditions for such availability set24* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU25* General Public License, version 2 with the GNU Classpath26* Exception [1] and GNU General Public License, version 2 with the27* OpenJDK Assembly Exception [2].28*29* [1] https://www.gnu.org/software/classpath/license.html30* [2] http://openjdk.java.net/legal/assembly-exception.html31*32* 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-exception33*******************************************************************************/3435/**36* @author andhall37*38*/39public class DumpImageMemoryRanges40{4142/**43* @param args44*/45public static void main(String[] args) throws Exception46{47String fileName = args[0];48boolean useJExtract = false;4950if (args.length > 1) {51if (args[1].toLowerCase().trim().equals("jextract")) {52useJExtract = true;53}54}5556ImageFactory factory = null;57if (useJExtract) {58try {59Class<?> jxfactoryclass = Class.forName("com.ibm.dtfj.image.j9.ImageFactory");60factory = (ImageFactory)jxfactoryclass.newInstance();61} catch (Exception e) {62System.out.println("Could not create a jextract based implementation of ImageFactory");63e.printStackTrace();64System.exit(1);65}66} else {67factory = new J9DDRImageFactory();68}6970Image img = factory.getImage(new File(fileName));7172Iterator<?> addressSpaceIt = img.getAddressSpaces();7374while (addressSpaceIt.hasNext()) {75Object addressSpaceObj = addressSpaceIt.next();7677if (addressSpaceObj instanceof ImageAddressSpace) {78ImageAddressSpace as = (ImageAddressSpace)addressSpaceObj;7980System.err.println("Address space " + as);8182List<ImageSection> imageSections = new LinkedList<ImageSection>();8384Iterator<?> isIt = as.getImageSections();8586while (isIt.hasNext()) {87Object isObj = isIt.next();8889if (isObj instanceof ImageSection) {90ImageSection thisIs = (ImageSection)isObj;9192imageSections.add(thisIs);93} else {94System.err.println("Weird image section object: " + isObj + ", class = " + isObj.getClass().getName());95}96}9798Collections.sort(imageSections, new Comparator<ImageSection>(){99100public int compare(ImageSection object1,101ImageSection object2)102{103int baseResult = Long.signum(object1.getBaseAddress().getAddress() - object2.getBaseAddress().getAddress());104105if (baseResult == 0) {106return Long.signum(object1.getSize() - object2.getSize());107} else {108return baseResult;109}110}});111112for (ImageSection thisIs : imageSections) {113System.err.println("0x" + Long.toHexString(thisIs.getBaseAddress().getAddress()) + " - " + "0x" + Long.toHexString(thisIs.getBaseAddress().getAddress() + thisIs.getSize() - 1));114}115} else {116System.err.println("Weird address space object: " + addressSpaceObj + " class = " + addressSpaceObj.getClass().getName());117}118}119}120121}122123124