Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/debugtools/DDR_VM/testsrc/DumpImageMemoryRanges.java
6000 views
1
import java.io.File;
2
import java.util.Collections;
3
import java.util.Comparator;
4
import java.util.Iterator;
5
import java.util.LinkedList;
6
import java.util.List;
7
8
import com.ibm.dtfj.image.Image;
9
import com.ibm.dtfj.image.ImageAddressSpace;
10
import com.ibm.dtfj.image.ImageFactory;
11
import com.ibm.dtfj.image.ImageSection;
12
import com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory;
13
14
/*******************************************************************************
15
* Copyright (c) 2010, 2014 IBM Corp. and others
16
*
17
* This program and the accompanying materials are made available under
18
* the terms of the Eclipse Public License 2.0 which accompanies this
19
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
20
* or the Apache License, Version 2.0 which accompanies this distribution and
21
* is available at https://www.apache.org/licenses/LICENSE-2.0.
22
*
23
* This Source Code may also be made available under the following
24
* Secondary Licenses when the conditions for such availability set
25
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
26
* General Public License, version 2 with the GNU Classpath
27
* Exception [1] and GNU General Public License, version 2 with the
28
* OpenJDK Assembly Exception [2].
29
*
30
* [1] https://www.gnu.org/software/classpath/license.html
31
* [2] http://openjdk.java.net/legal/assembly-exception.html
32
*
33
* 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-exception
34
*******************************************************************************/
35
36
/**
37
* @author andhall
38
*
39
*/
40
public class DumpImageMemoryRanges
41
{
42
43
/**
44
* @param args
45
*/
46
public static void main(String[] args) throws Exception
47
{
48
String fileName = args[0];
49
boolean useJExtract = false;
50
51
if (args.length > 1) {
52
if (args[1].toLowerCase().trim().equals("jextract")) {
53
useJExtract = true;
54
}
55
}
56
57
ImageFactory factory = null;
58
if (useJExtract) {
59
try {
60
Class<?> jxfactoryclass = Class.forName("com.ibm.dtfj.image.j9.ImageFactory");
61
factory = (ImageFactory)jxfactoryclass.newInstance();
62
} catch (Exception e) {
63
System.out.println("Could not create a jextract based implementation of ImageFactory");
64
e.printStackTrace();
65
System.exit(1);
66
}
67
} else {
68
factory = new J9DDRImageFactory();
69
}
70
71
Image img = factory.getImage(new File(fileName));
72
73
Iterator<?> addressSpaceIt = img.getAddressSpaces();
74
75
while (addressSpaceIt.hasNext()) {
76
Object addressSpaceObj = addressSpaceIt.next();
77
78
if (addressSpaceObj instanceof ImageAddressSpace) {
79
ImageAddressSpace as = (ImageAddressSpace)addressSpaceObj;
80
81
System.err.println("Address space " + as);
82
83
List<ImageSection> imageSections = new LinkedList<ImageSection>();
84
85
Iterator<?> isIt = as.getImageSections();
86
87
while (isIt.hasNext()) {
88
Object isObj = isIt.next();
89
90
if (isObj instanceof ImageSection) {
91
ImageSection thisIs = (ImageSection)isObj;
92
93
imageSections.add(thisIs);
94
} else {
95
System.err.println("Weird image section object: " + isObj + ", class = " + isObj.getClass().getName());
96
}
97
}
98
99
Collections.sort(imageSections, new Comparator<ImageSection>(){
100
101
public int compare(ImageSection object1,
102
ImageSection object2)
103
{
104
int baseResult = Long.signum(object1.getBaseAddress().getAddress() - object2.getBaseAddress().getAddress());
105
106
if (baseResult == 0) {
107
return Long.signum(object1.getSize() - object2.getSize());
108
} else {
109
return baseResult;
110
}
111
}});
112
113
for (ImageSection thisIs : imageSections) {
114
System.err.println("0x" + Long.toHexString(thisIs.getBaseAddress().getAddress()) + " - " + "0x" + Long.toHexString(thisIs.getBaseAddress().getAddress() + thisIs.getSize() - 1));
115
}
116
} else {
117
System.err.println("Weird address space object: " + addressSpaceObj + " class = " + addressSpaceObj.getClass().getName());
118
}
119
}
120
}
121
122
}
123
124