Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/debugtools/DDR_VM/src/com/ibm/j9ddr/libraries/DDRLibraryAdapter.java
6005 views
1
/*******************************************************************************
2
* Copyright (c) 1991, 2014 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* 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
21
*******************************************************************************/
22
23
package com.ibm.j9ddr.libraries;
24
25
import static java.util.logging.Level.SEVERE;
26
import static java.util.logging.Level.WARNING;
27
28
import java.io.File;
29
import java.io.IOException;
30
import java.util.ArrayList;
31
import java.util.Iterator;
32
import java.util.logging.Logger;
33
34
import com.ibm.dtfj.image.CorruptDataException;
35
import com.ibm.dtfj.image.DataUnavailable;
36
import com.ibm.dtfj.image.Image;
37
import com.ibm.dtfj.image.ImageAddressSpace;
38
import com.ibm.dtfj.image.ImageFactory;
39
import com.ibm.dtfj.image.ImageModule;
40
import com.ibm.dtfj.image.ImageProcess;
41
import com.ibm.j9ddr.corereaders.CoreReader;
42
import com.ibm.j9ddr.corereaders.ICore;
43
import com.ibm.j9ddr.corereaders.ILibraryDependentCore;
44
import com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory;
45
46
@SuppressWarnings("restriction")
47
public class DDRLibraryAdapter implements LibraryAdapter {
48
private static final Logger logger = Logger.getLogger(LibraryCollector.LOGGER_NAME);
49
private ArrayList<String> moduleNames = null;
50
private final ArrayList<String> errorMessages = new ArrayList<String>();
51
52
public ArrayList<String> getErrorMessages() {
53
return errorMessages;
54
}
55
56
public ArrayList<String> getLibraryList(final File coreFile) {
57
if(moduleNames == null) {
58
constructLibraryList(coreFile);
59
}
60
return moduleNames;
61
}
62
63
public boolean isLibraryCollectionRequired(File coreFile) {
64
ICore reader = getReader(coreFile.getPath());
65
return (reader instanceof ILibraryDependentCore);
66
}
67
68
private ICore getReader(final String path) {
69
final ICore reader;
70
try {
71
reader = CoreReader.readCoreFile(path);
72
} catch (IOException e) {
73
logger.log(SEVERE, "Could not open core file", e);
74
errorMessages.add(e.getMessage());
75
return null;
76
}
77
return reader;
78
}
79
80
/**
81
* Constructs the list of libraries required using the DDR implementation of the DTFJ Image* API.
82
* This ensures that the correct classloading is used for determining which libraries to collect.
83
* @param coreFile core file to process
84
*/
85
@SuppressWarnings({ "unchecked" })
86
private void constructLibraryList(final File coreFile) {
87
moduleNames = new ArrayList<String>();
88
ImageFactory factory = new J9DDRImageFactory();
89
final Image image;
90
final boolean isAIX;
91
try {
92
image = factory.getImage(coreFile);
93
isAIX = image.getSystemType().toLowerCase().startsWith("aix");
94
} catch (IOException e) {
95
logger.log(SEVERE, "Could not open core file", e);
96
errorMessages.add(e.getMessage());
97
return;
98
} catch (CorruptDataException e) {
99
logger.log(SEVERE, "Could not determine system type", e);
100
errorMessages.add(e.getMessage());
101
return;
102
} catch (DataUnavailable e) {
103
logger.log(SEVERE, "Could not determine system type", e);
104
errorMessages.add(e.getMessage());
105
return;
106
}
107
for(Iterator spaces = image.getAddressSpaces(); spaces.hasNext(); ) {
108
ImageAddressSpace space = (ImageAddressSpace) spaces.next();
109
for(Iterator procs = space.getProcesses(); procs.hasNext(); ) {
110
ImageProcess proc = (ImageProcess) procs.next();
111
try {
112
ImageModule exe = proc.getExecutable(); //add the executable to the list of libraries to be collected
113
moduleNames.add(exe.getName());
114
for(Iterator libraries = proc.getLibraries(); libraries.hasNext(); ) {
115
ImageModule module = (ImageModule) libraries.next();
116
String key = null;
117
try { //handle CDE thrown by getName(), as this is required further on this call needs to succeed
118
if(isAIX) {
119
key = module.getName();
120
int pos = key.indexOf(".a("); //check on AIX if module is the .a file or library
121
if((pos != -1) && (key.lastIndexOf(')') == key.length() - 1)) {
122
key = key.substring(0, pos + 2);
123
}
124
} else {
125
key = module.getName();
126
}
127
logger.fine("Module : " + key);
128
if(!moduleNames.contains(key)) { //don't store duplicate libraries
129
moduleNames.add(key);
130
}
131
} catch (Exception e) {
132
logger.log(WARNING, "Error getting module name", e);
133
}
134
}
135
} catch (DataUnavailable e) {
136
logger.log(WARNING, "Error getting library list", e);
137
errorMessages.add(e.getMessage());
138
} catch (com.ibm.dtfj.image.CorruptDataException e) {
139
logger.log(WARNING, "Error getting library list", e);
140
errorMessages.add(e.getMessage());
141
}
142
}
143
}
144
}
145
146
}
147
148