Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/debugtools/DDR_VM/testsrc/DTFJKickTyres.java
6000 views
1
import java.io.File;
2
import java.util.Iterator;
3
import java.util.Properties;
4
5
import com.ibm.dtfj.image.Image;
6
import com.ibm.dtfj.image.ImageAddressSpace;
7
import com.ibm.dtfj.image.ImageFactory;
8
import com.ibm.dtfj.image.ImageModule;
9
import com.ibm.dtfj.image.ImageProcess;
10
import com.ibm.dtfj.image.ImageSymbol;
11
import com.ibm.dtfj.java.JavaRuntime;
12
import com.ibm.dtfj.java.JavaVMInitArgs;
13
import com.ibm.dtfj.java.JavaVMOption;
14
import com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory;
15
16
/*******************************************************************************
17
* Copyright (c) 2009, 2014 IBM Corp. and others
18
*
19
* This program and the accompanying materials are made available under
20
* the terms of the Eclipse Public License 2.0 which accompanies this
21
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
22
* or the Apache License, Version 2.0 which accompanies this distribution and
23
* is available at https://www.apache.org/licenses/LICENSE-2.0.
24
*
25
* This Source Code may also be made available under the following
26
* Secondary Licenses when the conditions for such availability set
27
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
28
* General Public License, version 2 with the GNU Classpath
29
* Exception [1] and GNU General Public License, version 2 with the
30
* OpenJDK Assembly Exception [2].
31
*
32
* [1] https://www.gnu.org/software/classpath/license.html
33
* [2] http://openjdk.java.net/legal/assembly-exception.html
34
*
35
* 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
36
*******************************************************************************/
37
38
/**
39
* @author andhall
40
*
41
*/
42
public class DTFJKickTyres
43
{
44
45
/**
46
* @param args
47
*/
48
public static void main(String[] args) throws Exception
49
{
50
boolean useJExtract = false;
51
52
if (args.length > 1) {
53
if (args[1].toLowerCase().trim().equals("jextract")) {
54
useJExtract = true;
55
}
56
}
57
58
ImageFactory factory = null;
59
if (useJExtract) {
60
try {
61
Class<?> jxfactoryclass = Class.forName("com.ibm.dtfj.image.j9.ImageFactory");
62
factory = (ImageFactory)jxfactoryclass.newInstance();
63
} catch (Exception e) {
64
System.out.println("Could not create a jextract based implementation of ImageFactory");
65
e.printStackTrace();
66
System.exit(1);
67
}
68
} else {
69
factory = new J9DDRImageFactory();
70
}
71
72
Image img = factory.getImage(new File(args[0]));
73
74
Iterator<?> addressSpaceIt = img.getAddressSpaces();
75
76
while (addressSpaceIt.hasNext()) {
77
78
ImageAddressSpace as = (ImageAddressSpace)addressSpaceIt.next();
79
80
Iterator<?> processIt = as.getProcesses();
81
82
while (processIt.hasNext()) {
83
ImageProcess process = (ImageProcess)processIt.next();
84
85
System.err.println("Got process " + process);
86
try {
87
System.err.println("Command line was " + process.getCommandLine());
88
} catch (Throwable t) {
89
t.printStackTrace();
90
}
91
92
try {
93
System.err.println("Executable was: " + process.getExecutable());
94
} catch (Throwable t) {
95
t.printStackTrace();
96
}
97
98
99
try {
100
System.err.println("Modules were:");
101
102
Iterator<?> it = process.getLibraries();
103
104
if (!it.hasNext()) {
105
System.err.println("No modules!");
106
}
107
108
while (it.hasNext()) {
109
ImageModule module = (ImageModule) it.next();
110
111
System.err.println("* " + module.getName());
112
113
Iterator<?> symIt = module.getSymbols();
114
115
while (symIt.hasNext()) {
116
Object symObj = symIt.next();
117
if (symObj instanceof ImageSymbol) {
118
ImageSymbol sym = (ImageSymbol) symObj;
119
120
if (sym.getName().toLowerCase().contains("environ")) {
121
System.err.println("X sym " + sym.getName() + " = " + sym.getAddress());
122
}
123
}
124
}
125
}
126
} catch (Throwable t) {
127
t.printStackTrace();
128
}
129
130
try {
131
Properties env = process.getEnvironment();
132
133
System.err.println("Environment");
134
for (Object key : env.keySet()) {
135
System.err.println(key + " = " + env.getProperty((String)key));
136
}
137
} catch (Throwable t) {
138
t.printStackTrace();
139
}
140
141
Iterator<?> runtimeIt = process.getRuntimes();
142
143
while (runtimeIt.hasNext()) {
144
JavaRuntime runtime = (JavaRuntime) runtimeIt.next();
145
146
System.err.println("Got runtime: " + runtime);
147
148
JavaVMInitArgs initArgs = runtime.getJavaVMInitArgs();
149
150
Iterator<?> optionsIt = initArgs.getOptions();
151
152
System.err.println("Options:");
153
while (optionsIt.hasNext()) {
154
Object optionObj = optionsIt.next();
155
156
if (optionObj instanceof JavaVMOption) {
157
JavaVMOption option = (JavaVMOption) optionObj;
158
159
System.err.println("* " + option.getOptionString());
160
}
161
}
162
}
163
}
164
165
}
166
}
167
168
}
169
170