use of com.ibm.j9ddr.corereaders.memory.IProcess in project openj9 by eclipse.
the class SnapBaseCommand method createAndWriteTraceFileHeader.
private void createAndWriteTraceFileHeader(Context context, long utglobaldataAddress, int bufferSize, PrintStream out) throws CorruptDataException, DDRInteractiveCommandException {
IProcess process = context.process;
boolean isBigEndian = process.getByteOrder().equals(ByteOrder.BIG_ENDIAN);
long j9rasAddress = CommandUtils.followPointerFromStructure(context, "J9JavaVM", context.vmAddress, "j9ras");
long cpuOffset = CommandUtils.getOffsetForField(StructureCommandUtil.getStructureDescriptor("J9RAS", context), "cpus");
int cpuCount = context.process.getIntAt(j9rasAddress + cpuOffset);
long archOffset = CommandUtils.getOffsetForField(StructureCommandUtil.getStructureDescriptor("J9RAS", context), "osarch");
String arch = getCStringAtAddress(process, j9rasAddress + archOffset, 16);
// We can't actually work this out.
String processorSubType = "";
long serviceInfoOffset = CommandUtils.getOffsetForField(StructureCommandUtil.getStructureDescriptor("UtGlobalData", context), "serviceInfo");
long serviceInfoAddress = process.getPointerAt(utglobaldataAddress + serviceInfoOffset);
String serviceLevel = getCStringAtAddress(process, serviceInfoAddress);
long propertiesOffset = CommandUtils.getOffsetForField(StructureCommandUtil.getStructureDescriptor("UtGlobalData", context), "properties");
long propertiesAddress = process.getPointerAt(utglobaldataAddress + propertiesOffset);
String startupOptions = getCStringAtAddress(process, propertiesAddress);
int wordSize = process.bytesPerPointer() * 8;
// The trace configuration options are in a list.
String traceConfig = "";
long commandOffset = CommandUtils.getOffsetForField(StructureCommandUtil.getStructureDescriptor("UtTraceCfg", context), "command");
long nextConfigAddress = CommandUtils.followPointerFromStructure(context, "UtGlobalData", utglobaldataAddress, "config");
while (nextConfigAddress != 0) {
traceConfig += getCStringAtAddress(process, nextConfigAddress + commandOffset);
nextConfigAddress = CommandUtils.followPointerFromStructure(context, "UtTraceCfg", nextConfigAddress, "next");
if (nextConfigAddress != 0) {
traceConfig += "\n";
}
}
long startPlatformOffset = CommandUtils.getOffsetForField(StructureCommandUtil.getStructureDescriptor("UtGlobalData", context), "startPlatform");
long startPlatform = context.process.getLongAt(utglobaldataAddress + startPlatformOffset);
long startSystemOffset = CommandUtils.getOffsetForField(StructureCommandUtil.getStructureDescriptor("UtGlobalData", context), "startSystem");
long startSystem = context.process.getLongAt(utglobaldataAddress + startSystemOffset);
long externalTraceOffset = CommandUtils.getOffsetForField(StructureCommandUtil.getStructureDescriptor("UtGlobalData", context), "externalTrace");
int type = context.process.getIntAt(utglobaldataAddress + externalTraceOffset);
long traceGenerationsOffset = CommandUtils.getOffsetForField(StructureCommandUtil.getStructureDescriptor("UtGlobalData", context), "traceGenerations");
int generations = context.process.getIntAt(utglobaldataAddress + traceGenerationsOffset);
TraceFileHeaderWriter headerWriter;
try {
headerWriter = new TraceFileHeaderWriter(fileName, isBigEndian, cpuCount, wordSize, bufferSize, arch, processorSubType, serviceLevel, startupOptions, traceConfig, startPlatform, startSystem, type, generations);
byte[] headerBytes = headerWriter.createAndWriteTraceFileHeader();
writeHeaderBytesToTrace(context, headerBytes, out);
} catch (IOException e) {
e.printStackTrace();
}
}
use of com.ibm.j9ddr.corereaders.memory.IProcess in project openj9 by eclipse.
the class DDRInteractive method locateRuntimes.
private void locateRuntimes(ICore reader) {
currentCore = reader;
Collection<? extends IAddressSpace> spaces = reader.getAddressSpaces();
for (IAddressSpace thisSpace : spaces) {
// indicates if a context has been allocated for the address space
boolean hasCtxBeenAddedForAS = false;
Collection<? extends IProcess> processes = thisSpace.getProcesses();
for (IProcess thisProcess : processes) {
hasCtxBeenAddedForAS = true;
try {
IVMData vmData = VMDataFactory.getVMData(thisProcess);
if (vmData != null) {
contexts.add(new Context(thisProcess, vmData, nonVMCommands));
} else {
addMissingJVMToContexts(thisProcess);
}
} catch (JVMNotDDREnabledException e) {
addMissingJVMToContexts(thisProcess);
} catch (JVMNotFoundException e) {
addMissingJVMToContexts(thisProcess);
} catch (MissingDDRStructuresException e) {
addMissingJVMToContexts(thisProcess);
} catch (IOException e) {
System.err.println("Problem searching for VMData in process " + thisProcess);
e.printStackTrace();
// put the stack trace to the log
Logger logger = Logger.getLogger(LoggerNames.LOGGER_INTERACTIVE_CONTEXT);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
logger.logp(FINE, null, null, sw.toString());
}
}
if (!hasCtxBeenAddedForAS) {
ASNoProcess as = new ASNoProcess(thisSpace);
addMissingJVMToContexts(as);
}
}
if (contexts.size() == 0) {
throw new RuntimeException("Couldn't find any address spaces in this dump");
} else {
// default to the first address space
currentContext = contexts.get(0);
for (Context ctx : contexts) {
// but if there is one with a JVM in it, set it to that
if (!(ctx.vmData instanceof MissingVMData)) {
currentContext = ctx;
break;
}
}
}
}
use of com.ibm.j9ddr.corereaders.memory.IProcess in project openj9 by eclipse.
the class DDRInteractive method addDDRContextFromDTFJ.
private void addDDRContextFromDTFJ(Object dtfjctx) throws Exception {
Method getAddressSpace = findMethod(dtfjctx.getClass(), "getAddressSpace", (Class<?>[]) null);
Method getProcess = findMethod(dtfjctx.getClass(), "getProcess", (Class<?>[]) null);
Method getRuntime = findMethod(dtfjctx.getClass(), "getRuntime", (Class<?>[]) null);
Object addressSpace = getAddressSpace.invoke(dtfjctx, (Object[]) null);
Object process = getProcess.invoke(dtfjctx, (Object[]) null);
Object runtime = getRuntime.invoke(dtfjctx, (Object[]) null);
if (addressSpace == null) {
throw new IOException("Cannot create a context without an associated address space");
}
if (!(addressSpace instanceof J9DDRImageAddressSpace)) {
throw new UnsupportedOperationException("The supplied DTFJ context is not backed by a DDR implementation");
}
IAddressSpace space = ((J9DDRImageAddressSpace) addressSpace).getIAddressSpace();
IProcess proc = null;
if (process != null) {
proc = ((J9DDRImageProcess) process).getIProcess();
}
if (proc == null) {
ASNoProcess as = new ASNoProcess(space);
addMissingJVMToContexts(as);
return;
}
if (runtime == null) {
addMissingJVMToContexts(proc);
return;
}
// DDR will cache the VM data, so if the DTFJ context has already found it then this should be in the cache
IVMData vmData = VMDataFactory.getVMData(proc);
if (vmData != null) {
contexts.add(new Context(proc, vmData, nonVMCommands));
} else {
addMissingJVMToContexts(proc);
}
}
use of com.ibm.j9ddr.corereaders.memory.IProcess in project openj9 by eclipse.
the class FindInMemoryCommand method run.
public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
IProcess process = context.process;
boolean isLittleEndian = process.getByteOrder().equals(ByteOrder.LITTLE_ENDIAN);
int udataSize = process.bytesPerPointer();
int udataSearch = udataSize == 4 ? TYPE_U32 : TYPE_U64;
int searchType = TYPE_NONE;
String searchTypeName;
boolean findAll = false;
byte[] searchPattern;
int alignment;
long startAddress;
int argIndex = 0;
String arg;
// check for the findnext and findall variants of the command
if (command.endsWith("findnext")) {
findNext(out, process);
return;
} else if (command.endsWith("findall")) {
findAll = true;
}
// except for findnext (handled above), there should be parameters following the command
if (args.length == 0) {
printHelp(out);
return;
}
// get the first parameter (the search type), and post-increment the parameter index
arg = args[argIndex++];
searchTypeName = arg;
if (arg.equalsIgnoreCase("u8")) {
searchType = TYPE_U8;
alignment = 1;
} else if (arg.equalsIgnoreCase("u16")) {
searchType = TYPE_U16;
alignment = 2;
} else if (arg.equalsIgnoreCase("u32")) {
searchType = TYPE_U32;
alignment = 4;
} else if (arg.equalsIgnoreCase("u64")) {
searchType = TYPE_U64;
alignment = 8;
} else if (arg.equalsIgnoreCase("udata")) {
searchType = udataSearch;
alignment = udataSize;
} else if (arg.equalsIgnoreCase("pointer")) {
searchType = udataSearch;
alignment = udataSize;
} else if (arg.equalsIgnoreCase("ascii")) {
searchType = TYPE_ASCII;
alignment = 1;
} else {
printHelp(out);
out.println("Unknown search type '" + searchTypeName + "'\n");
return;
}
/* Now parse the search criteria */
if (args.length <= argIndex) {
printHelp(out);
out.println("Expected pattern as argument " + (argIndex + 1) + "\n");
return;
}
arg = args[argIndex++];
if (searchType == TYPE_ASCII) {
if (arg.startsWith("\"")) {
arg = arg.substring(1, arg.lastIndexOf('"'));
}
try {
searchPattern = arg.getBytes("ASCII");
} catch (UnsupportedEncodingException e) {
// fall back to default platform
searchPattern = arg.getBytes();
// encoding
}
} else {
searchPattern = new byte[alignment];
if (arg.startsWith("0x")) {
arg = arg.substring(2);
}
int hexBytes = (arg.length() + 1) / 2;
if (hexBytes > alignment) {
out.println("Search pattern too long for type '" + searchTypeName + "'");
return;
}
// Pad for simplicity
arg = "0000000000000000".concat(arg);
arg = arg.substring(arg.length() - alignment * 2);
for (int i = 0; i < alignment; i++) {
int b = Integer.parseInt(arg.substring(i * 2, i * 2 + 2), 16);
if (isLittleEndian) {
searchPattern[alignment - i - 1] = (byte) (b & 0xFF);
} else {
searchPattern[i] = (byte) (b & 0xFF);
}
}
}
/* Now parse the start address (optional) */
if (args.length <= argIndex) {
startAddress = 0L;
} else {
arg = args[argIndex++];
if (arg.startsWith("0x")) {
startAddress = Long.decode(arg);
} else {
startAddress = Long.parseLong(arg, 16);
}
}
currentAddress = startAddress;
currentAlignment = alignment;
currentPattern = searchPattern;
boolean result = findFirst(out, process);
if (findAll) {
while (result) {
result = findNext(out, process);
}
}
}
use of com.ibm.j9ddr.corereaders.memory.IProcess in project openj9 by eclipse.
the class J9DDRImageAddressSpace method getImageSections.
public Iterator<?> getImageSections() {
Collection<? extends IMemoryRange> ranges = as.getMemoryRanges();
List<ImageSection> sections = new ArrayList<ImageSection>(ranges.size());
IProcess proc = getPointerProcess();
// it may be the case that we can't determine the pointer size if there are no processes found in the address space
if (null == proc) {
return J9DDRDTFJUtils.emptyIterator();
}
for (IMemoryRange thisRange : ranges) {
J9DDRImageSection section = new J9DDRImageSection(proc, thisRange.getBaseAddress(), thisRange.getSize(), thisRange.getName());
sections.add(section);
}
return sections.iterator();
}
Aggregations