use of com.ibm.dtfj.image.ImageSection in project openj9 by eclipse.
the class DTFJJavaRuntime method validHeapAddress.
/*
* Quickly check if an object address is within a memory range that we
* know is part of the heap.
* (Heap sections are usually contiguous so we can merge them down to
* just a few ranges. This is important in balanced mode where there
* may be thousands. See See PR 103197)
*/
private boolean validHeapAddress(ImagePointer address) {
if (mergedHeapSections == null) {
mergeSections();
}
U64 addr = new U64(address.getAddress());
for (ImageSection i : mergedHeapSections) {
U64 baseAddress = new U64(i.getBaseAddress().getAddress());
if (baseAddress.gt(addr)) {
// found the pointer in a heap.
return false;
}
U64 endAddress = new U64(i.getBaseAddress().getAddress() + i.getSize());
if (endAddress.gt(addr)) {
return true;
}
}
return false;
}
use of com.ibm.dtfj.image.ImageSection in project openj9 by eclipse.
the class DTFJJavaRuntime method mergeSections.
/*
* Merge all the sections of the heap together to simplify range checks for
* getObjectAtAddress. (This is very important with balanced heaps where there
* are thousands of heap sections but they are actually contiguous. See PR 103197)
*/
private synchronized void mergeSections() {
// Get the list of all the heap sections.
if (mergedHeapSections != null) {
return;
}
Iterator heaps = getHeaps();
List<ImageSection> heapSections = new LinkedList<ImageSection>();
// If there are no heap sections this can't be valid.
if (!heaps.hasNext()) {
return;
}
while (heaps.hasNext()) {
DTFJJavaHeap heap = (DTFJJavaHeap) heaps.next();
Iterator sections = heap.getSections();
while (sections.hasNext()) {
heapSections.add((ImageSection) sections.next());
}
}
// Sort them.
Collections.sort(heapSections, new Comparator<ImageSection>() {
public int compare(ImageSection arg0, ImageSection arg1) {
U64 ptr0 = new U64(arg0.getBaseAddress().getAddress());
U64 ptr1 = new U64(arg1.getBaseAddress().getAddress());
// not a java long comparison.
if (ptr0.lt(ptr1)) {
return -1;
} else if (ptr0.gt(ptr1)) {
return 1;
} else {
return 0;
}
}
});
mergedHeapSections = new LinkedList<ImageSection>();
Iterator<ImageSection> itr = heapSections.iterator();
// We know we have at least one section.
ImageSection currentSection = itr.next();
while (itr.hasNext()) {
ImageSection nextSection = itr.next();
// If the sections are contiguous, merge them.
if (currentSection.getBaseAddress().getAddress() + currentSection.getSize() == nextSection.getBaseAddress().getAddress()) {
currentSection = new J9DDRImageSection(DTFJContext.getProcess(), currentSection.getBaseAddress().getAddress(), currentSection.getSize() + nextSection.getSize(), null);
} else {
mergedHeapSections.add(currentSection);
currentSection = nextSection;
}
}
mergedHeapSections.add(currentSection);
}
use of com.ibm.dtfj.image.ImageSection in project openj9 by eclipse.
the class PHDImageAddressSpace method getImageSections.
public Iterator<ImageSection> getImageSections() {
List<ImageSection> list = new ArrayList<ImageSection>();
for (Iterator<ImageProcess> ip = getProcesses(); ip.hasNext(); ) {
ImageProcess p = ip.next();
if (p instanceof CorruptData)
continue;
for (Iterator<ManagedRuntime> jr = p.getRuntimes(); jr.hasNext(); ) {
ManagedRuntime mr = jr.next();
if (mr instanceof CorruptData)
continue;
if (mr instanceof JavaRuntime) {
for (Iterator<JavaHeap> jh = ((JavaRuntime) mr).getHeaps(); jh.hasNext(); ) {
JavaHeap hp = jh.next();
if (hp instanceof CorruptData)
continue;
for (Iterator<ImageSection> is = hp.getSections(); is.hasNext(); ) {
// Add the corrupt sections too
list.add(is.next());
}
}
}
}
}
if (metaImageAddressSpace != null) {
for (Iterator it = metaImageAddressSpace.getImageSections(); it.hasNext(); ) {
Object next = it.next();
if (next instanceof ImageSection) {
ImageSection section = (ImageSection) next;
ImageSection newSection = new PHDImageSection(section.getName(), getPointer(section.getBaseAddress().getAddress()), section.getSize());
list.add(newSection);
}
}
}
return list.iterator();
}
use of com.ibm.dtfj.image.ImageSection in project openj9 by eclipse.
the class PHDJavaObject method getSections.
public Iterator<ImageSection> getSections() {
List<ImageSection> c = new ArrayList<ImageSection>();
ImageSection s;
try {
s = new PHDImageSection("Object section", getID(), getSize());
} catch (CorruptDataException e) {
s = new PHDCorruptImageSection("Corrupt object section", getID());
}
c.add(s);
return c.iterator();
}
use of com.ibm.dtfj.image.ImageSection in project openj9 by eclipse.
the class InfoMmapCommand method run.
public void run(String command, String[] args, IContext context, PrintStream out) throws CommandException {
boolean verbose = false;
ImagePointer addressPointer = null;
Comparator<ImageSection> sortOrder = null;
if (initCommand(command, args, context, out)) {
// processing already handled by super class
return;
}
for (String arg : args) {
if (Utils.SORT_BY_SIZE_FLAG.equals(arg)) {
sortOrder = new SizeComparator();
} else if (Utils.SORT_BY_ADDRESS_FLAG.equals(arg)) {
sortOrder = new AddressComparator();
} else if (Utils.VERBOSE_FLAG.equals(arg)) {
verbose = true;
} else {
// longFromString will return a Long or null if we couldn't parse
// the argument as a number.
Long address = Utils.longFromString(arg);
if (address == null) {
out.println("\"info mmap\" -unknown parameter " + arg);
return;
} else {
addressPointer = ctx.getAddressSpace().getPointer(address);
}
}
}
List<ImageSection> sortedSections = new LinkedList<ImageSection>();
Iterator<ImageSection> imageSections = ctx.getAddressSpace().getImageSections();
while (imageSections.hasNext()) {
sortedSections.add(imageSections.next());
}
if (sortOrder != null) {
Collections.sort(sortedSections, sortOrder);
}
int addrSize = ctx.getProcess().getPointerSize() == 64 ? 16 : 8;
// Width for decimals can vary as we use the locales format (via %,d)
int decWidth = 0;
int hexWidth = 0;
if (addrSize == 16) {
hexWidth = String.format("%016x", Long.MAX_VALUE).length();
decWidth = String.format("(%,d)", Long.MAX_VALUE).length();
} else {
hexWidth = String.format("%08x", Integer.MAX_VALUE).length();
decWidth = String.format("(%,d)", Integer.MAX_VALUE).length();
}
out.printf("%-" + hexWidth + "s\t%-" + hexWidth + "s\t%-" + hexWidth + "s\t%-" + decWidth + "s\tRead/Write/Execute", "Start Address", "End Address", "Size", "Size");
out.println();
long totalSize = 0;
long totalSizeRwx = 0;
Iterator sortedIterator = sortedSections.iterator();
while (sortedIterator.hasNext()) {
ImageSection imageSection = (ImageSection) sortedIterator.next();
if (addressPointer != null) {
if (imageSection.getBaseAddress().getAddress() <= addressPointer.getAddress() && imageSection.getBaseAddress().add(imageSection.getSize()).getAddress() > addressPointer.getAddress()) {
// Print this address
} else {
continue;
}
}
long startAddress = imageSection.getBaseAddress().getAddress();
long size = imageSection.getSize();
long endAddress = startAddress + size - 1;
totalSize += size;
String decSize = String.format("(%,d)", size);
out.printf("0x%0" + hexWidth + "x\t0x%0" + hexWidth + "x\t0x%0" + hexWidth + "x\t%-" + decWidth + "s\t", startAddress, endAddress, size, decSize);
Properties props = imageSection.getProperties();
if (props != null) {
boolean rwx = false;
if (Boolean.TRUE.toString().equals(props.get("readable"))) {
out.print("R");
rwx = true;
}
if (Boolean.TRUE.toString().equals(props.get("writable"))) {
out.print("W");
rwx = true;
}
if (Boolean.TRUE.toString().equals(props.get("executable"))) {
out.print("X");
rwx = true;
}
if (rwx) {
totalSizeRwx += size;
}
}
if (verbose || addressPointer != null) {
out.println();
out.println("Name:\t" + imageSection.getName());
String[] keys = props.keySet().toArray(new String[0]);
ArrayList<String> table = new ArrayList<String>(keys.length);
int maxLen = 0;
Arrays.sort(keys);
// We may have a lot of properties so print them out in two columns.
for (String key : keys) {
String formatted = String.format("%s=%s", key, props.get(key));
table.add(formatted);
maxLen = Math.max(maxLen, formatted.length());
}
Iterator<String> tableIterator = table.iterator();
String tableFormatString = "\t%-" + maxLen + "s\t%-" + maxLen + "s\n";
while (tableIterator.hasNext()) {
out.printf(tableFormatString, tableIterator.next(), tableIterator.hasNext() ? tableIterator.next() : "");
}
out.println();
} else {
out.println();
}
}
if (addressPointer == null) {
if (totalSizeRwx > 0 && totalSize != totalSizeRwx) {
out.printf("Total size (Readable, Writable or Executable): 0x%1$x (%1$,d) bytes\n", totalSizeRwx);
}
out.printf("Total size: 0x%1$x (%1$,d) bytes\n", totalSize);
}
}
Aggregations