Search in sources :

Example 1 with J9MemTagIterator

use of com.ibm.j9ddr.vm29.j9.walkers.J9MemTagIterator in project openj9 by eclipse.

the class J9MemTagCommands method runFindAllCallsites.

private void runFindAllCallsites(String command, String[] args, Context context) throws DDRInteractiveCommandException {
    int sortType = SORT_TYPE_ALLOCSIZE;
    J9MemTagIterator it = J9MemTagIterator.iterateAllocatedHeaders();
    if (args.length == 1) {
        sortType = parseSortType(args[0]);
    }
    printCallsitesTable(buildCallsitesTable(it, true), sortType);
}
Also used : J9MemTagIterator(com.ibm.j9ddr.vm29.j9.walkers.J9MemTagIterator)

Example 2 with J9MemTagIterator

use of com.ibm.j9ddr.vm29.j9.walkers.J9MemTagIterator in project openj9 by eclipse.

the class J9MemTagCommands method runFindAllFreedCallsites.

private void runFindAllFreedCallsites(String command, String[] args, Context context) throws DDRInteractiveCommandException {
    out.println("Searching for all freed memory block callsites...");
    int sortType = SORT_TYPE_ALLOCSIZE;
    J9MemTagIterator it = J9MemTagIterator.iterateFreedHeaders();
    if (args.length == 1) {
        sortType = parseSortType(args[0]);
    }
    printCallsitesTable(buildCallsitesTable(it, true), sortType);
}
Also used : J9MemTagIterator(com.ibm.j9ddr.vm29.j9.walkers.J9MemTagIterator)

Example 3 with J9MemTagIterator

use of com.ibm.j9ddr.vm29.j9.walkers.J9MemTagIterator in project openj9 by eclipse.

the class J9MemTagCommands method runFindHeader.

private void runFindHeader(String command, String[] args, Context context) throws DDRInteractiveCommandException {
    long address = 0;
    J9MemTagPointer header = null;
    if (args.length != 1) {
        out.println("Usage: ");
        out.println("  !findheader <address> (e.g. !findheader 0xa2b4c6d8)");
        return;
    }
    address = CommandUtils.parsePointer(args[0], J9BuildFlags.env_data64);
    out.println(String.format("Searching memory allocation header for %s", U8Pointer.cast(address).getHexAddress()));
    /*
		 * Search for an eyecatcher on or before the specified address. Start
		 * the search on the specified address since an eyecatcher may start on
		 * the address. Ensure that the eyecatcher that is found is on or before
		 * the address. If this condition is not satisfied, start searching for
		 * an eyecatcher 1K before the previous start address. Continue until an
		 * eyecatcher is found, or the start address of 0 is reached.
		 */
    long searchBase = address - SEARCH_SLAB_SIZE;
    SEARCH_LOOP: do {
        /* Add 3 (length of eyecatcher - 1) to the top address, to catch eyecatchers written between search slabs */
        J9MemTagIterator it = J9MemTagIterator.iterateAllocatedHeaders(searchBase, searchBase + SEARCH_SLAB_SIZE + 3);
        while (it.hasNext()) {
            J9MemTagPointer potential = it.next();
            if (Addresses.greaterThan(potential.getAddress(), address)) {
                /* Walked past address */
                break;
            }
            VoidPointer start = J9MemTagHelper.j9mem_get_memory_base(potential);
            VoidPointer end;
            try {
                end = start.addOffset(potential.allocSize().longValue());
            } catch (CorruptDataException e) {
                continue;
            }
            if (Addresses.greaterThanOrEqual(address, start.getAddress()) && Addresses.lessThan(address, end.getAddress())) {
                /* Match */
                header = potential;
                break SEARCH_LOOP;
            }
        }
        if (Addresses.lessThan(searchBase, SEARCH_SLAB_SIZE)) {
            searchBase = 0;
        } else {
            searchBase = searchBase - SEARCH_SLAB_SIZE;
        }
    } while (searchBase != 0);
    if (header == null) {
        out.println("No memory allocation header found");
    } else {
        String callsite;
        try {
            callsite = header.callSite().getCStringAtOffset(0);
        } catch (CorruptDataException ex) {
            callsite = "<FAULT> reading callsite string: " + ex.getMessage();
        }
        String categoryName;
        try {
            categoryName = header.category().name().getCStringAtOffset(0);
        } catch (CorruptDataException ex) {
            categoryName = "<FAULT> reading category name string: " + ex.getMessage();
        }
        try {
            out.println(String.format("Found memory allocation header, !j9x %s,0x%#x", J9MemTagHelper.j9mem_get_memory_base(header).getHexAddress(), header.allocSize().longValue()));
            out.println(String.format("J9MemTag at %s {", header.getHexAddress()));
            out.println(String.format("    U_32 eyeCatcher = 0x%x;", header.eyeCatcher().longValue()));
            out.println(String.format("    U_32 sumCheck = 0x%x;", header.sumCheck().longValue()));
            out.println(String.format("    UDATA allocSize = 0x%x;", header.allocSize().longValue()));
            out.println(String.format("    char* callSite = %s;", callsite));
            out.println(String.format("    struct OMRMemCategory* category = !omrmemcategory 0x%x (%s);", header.category().longValue(), categoryName));
            out.println("}");
        } catch (CorruptDataException ex) {
            out.println("CDE formatting J9MemTag at " + header.getHexAddress());
        }
    }
}
Also used : VoidPointer(com.ibm.j9ddr.vm29.pointer.VoidPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException) J9MemTagPointer(com.ibm.j9ddr.vm29.pointer.generated.J9MemTagPointer) J9MemTagIterator(com.ibm.j9ddr.vm29.j9.walkers.J9MemTagIterator)

Example 4 with J9MemTagIterator

use of com.ibm.j9ddr.vm29.j9.walkers.J9MemTagIterator in project openj9 by eclipse.

the class J9MemTagCommands method runFindCallsite.

private void runFindCallsite(String command, String[] args, Context context) throws DDRInteractiveCommandException {
    final long matchFlags;
    long startAddress = 0;
    long endAddress = UDATA.MASK;
    final String needle;
    String callsiteEnd;
    int sortType = SORT_TYPE_DEFAULT;
    if (args.length == 0) {
        printUsageForFindCallsite();
        return;
    }
    String[] realArgs = args[0].split(",");
    callsiteEnd = realArgs[0];
    if (args.length == 2) {
        sortType = parseSortType(args[1]);
        if (sortType == -1) {
            printUsageForFindCallsite();
            return;
        }
    }
    if (realArgs.length == 2) {
        startAddress = Long.decode(realArgs[1]);
    } else if (realArgs.length == 3) {
        startAddress = Long.decode(realArgs[1]);
        endAddress = Long.decode(realArgs[2]);
    } else if (realArgs.length > 3 || args.length > 2) {
        out.print("Too many args : ");
        for (int i = 0; i < args.length - 1; i++) {
            out.print(args[i]);
        }
        out.println(args[args.length - 1]);
        printUsageForFindCallsite();
        return;
    }
    if (Addresses.greaterThan(startAddress, endAddress)) {
        out.println("Error: start address cannot be greater than end address");
        return;
    }
    StringBuffer needleBuffer = new StringBuffer();
    matchFlags = WildCard.parseWildcard(callsiteEnd, needleBuffer);
    if (matchFlags < 0) {
        out.println("Error: Invalid wildcard(s) in callsite");
        return;
    } else {
        needle = needleBuffer.toString();
    }
    J9MemTagIterator it = J9MemTagIterator.iterateAllocatedHeaders(startAddress, endAddress);
    ArrayList<MemTagEntry> memTagEntries = new ArrayList<MemTagEntry>();
    int callSiteCount = 0;
    while (it.hasNext()) {
        J9MemTagPointer header = it.next();
        if (!regexMatches(header, matchFlags, needle)) {
            continue;
        }
        callSiteCount++;
        try {
            long allocSize = header.allocSize().longValue();
            if (SORT_TYPE_DEFAULT != sortType) {
                memTagEntries.add(new MemTagEntry(header, allocSize));
            } else {
                printMemTagForFindCallSite(new MemTagEntry(header, allocSize));
            }
        } catch (CorruptDataException e) {
            // Unlikely - we've already checksummed the block
            e.printStackTrace(out);
        }
    }
    if (SORT_TYPE_NAME == sortType || SORT_TYPE_ALLOCSIZE == sortType) {
        if (SORT_TYPE_NAME == sortType) {
            Collections.sort(memTagEntries, new NameComparator());
        } else {
            Collections.sort(memTagEntries, new AllocSizeComparator());
        }
        for (int i = 0; i < memTagEntries.size(); i++) {
            MemTagEntry memTagEntry = memTagEntries.get(i);
            printMemTagForFindCallSite(memTagEntry);
        }
    }
    out.println("Call site count = " + callSiteCount);
}
Also used : ArrayList(java.util.ArrayList) CorruptDataException(com.ibm.j9ddr.CorruptDataException) J9MemTagPointer(com.ibm.j9ddr.vm29.pointer.generated.J9MemTagPointer) J9MemTagIterator(com.ibm.j9ddr.vm29.j9.walkers.J9MemTagIterator)

Example 5 with J9MemTagIterator

use of com.ibm.j9ddr.vm29.j9.walkers.J9MemTagIterator in project openj9 by eclipse.

the class J9MemTagCommands method runFindFreedCallsite.

private void runFindFreedCallsite(String command, String[] args, Context context) throws DDRInteractiveCommandException {
    final long matchFlags;
    long startAddress = 0;
    long endAddress = UDATA.MASK;
    final String needle;
    String callsiteEnd;
    int sortType = SORT_TYPE_DEFAULT;
    if (0 == args.length) {
        printUsageForFindFreedCallsite();
        return;
    }
    String[] realArgs = args[0].split(",");
    callsiteEnd = realArgs[0];
    if (realArgs.length == 2) {
        startAddress = Long.decode(realArgs[1]);
    } else if (realArgs.length == 3) {
        startAddress = Long.decode(realArgs[1]);
        endAddress = Long.decode(realArgs[2]);
    } else if (realArgs.length > 3 || args.length > 2) {
        out.print("Too many args : ");
        for (int i = 0; i < args.length - 1; i++) {
            out.print(args[i]);
        }
        out.println(args[args.length - 1]);
        printUsageForFindFreedCallsite();
        return;
    }
    if (args.length == 2) {
        sortType = parseSortType(args[1]);
        if (sortType == -1) {
            printUsageForFindFreedCallsite();
            return;
        }
    }
    if (Addresses.greaterThan(startAddress, endAddress)) {
        out.println("Error: start address cannot be greater than end address");
        return;
    }
    StringBuffer needleBuffer = new StringBuffer();
    matchFlags = WildCard.parseWildcard(callsiteEnd, needleBuffer);
    if (matchFlags < 0) {
        out.println("Error: Invalid wildcard(s) in callsite");
        return;
    } else {
        needle = needleBuffer.toString();
    }
    J9MemTagIterator it = J9MemTagIterator.iterateFreedHeaders(startAddress, endAddress);
    if (J9BuildFlags.env_data64) {
        out.println("+------------------------------------------+------------------+-------------------+");
        out.println("|          address      |      size        |    org size      | callsite          |");
        out.println("+------------------------------------------+------------------+-------------------+");
    /*	         " !j9x 0x000000000751F180,0x000001000 (0x000003390)   jsrinliner.c:567 */
    } else {
        out.println("+--------------------------+----------+-------------------+");
        out.println("|      address  |   size   | org size | callsite          |");
        out.println("+--------------------------+----------+-------------------+");
    /*	         " !j9x 0x0751F180,0x00001000 (0x00003390) jsrinliner.c:567 */
    }
    ArrayList<MemTagEntry> freedMemTagEntries = new ArrayList<MemTagEntry>();
    int freedCallSiteCount = 0;
    int corruptedFreedCallSiteCount = 0;
    while (it.hasNext()) {
        J9MemTagPointer header = it.next();
        if (!regexMatches(header, matchFlags, needle)) {
            continue;
        }
        freedCallSiteCount++;
        try {
            long allocSize = header.allocSize().longValue();
            if (it.isFooterCorrupted()) {
                /* 
					 * Corrupted footer is accepted only if freed call sites are being searched. 					 
					 * 
					 * If any part of current freed memory block re-allocated, 
					 * then just assume the memory between freed header and alloc header as freed memory.
					 *   
					 */
                corruptedFreedCallSiteCount++;
                J9MemTagIterator allocIte = J9MemTagIterator.iterateAllocatedHeaders(header.longValue() + J9MemTag.SIZEOF, header.add(allocSize).longValue() + +J9MemTag.SIZEOF);
                if (allocIte.hasNext()) {
                    J9MemTagPointer nextAllocHeader = allocIte.next();
                    allocSize = nextAllocHeader.longValue() - header.longValue();
                }
            }
            if (SORT_TYPE_DEFAULT != sortType) {
                freedMemTagEntries.add(new MemTagEntry(header, allocSize));
            } else {
                printMemTagForFindFreedCallSite(new MemTagEntry(header, allocSize));
            }
        } catch (CorruptDataException e) {
            // Unlikely - we've already checksummed the block
            e.printStackTrace(out);
        }
    }
    if (SORT_TYPE_NAME == sortType || SORT_TYPE_ALLOCSIZE == sortType) {
        if (SORT_TYPE_NAME == sortType) {
            Collections.sort(freedMemTagEntries, new NameComparator());
        } else {
            Collections.sort(freedMemTagEntries, new AllocSizeComparator());
        }
        for (int i = 0; i < freedMemTagEntries.size(); i++) {
            MemTagEntry freedMemTagEntry = freedMemTagEntries.get(i);
            printMemTagForFindFreedCallSite(freedMemTagEntry);
        }
    }
    out.println("Freed call site count = " + freedCallSiteCount);
    out.println("Corrupted freed call site count = " + corruptedFreedCallSiteCount);
}
Also used : ArrayList(java.util.ArrayList) CorruptDataException(com.ibm.j9ddr.CorruptDataException) J9MemTagPointer(com.ibm.j9ddr.vm29.pointer.generated.J9MemTagPointer) J9MemTagIterator(com.ibm.j9ddr.vm29.j9.walkers.J9MemTagIterator)

Aggregations

J9MemTagIterator (com.ibm.j9ddr.vm29.j9.walkers.J9MemTagIterator)6 CorruptDataException (com.ibm.j9ddr.CorruptDataException)4 J9MemTagPointer (com.ibm.j9ddr.vm29.pointer.generated.J9MemTagPointer)4 ArrayList (java.util.ArrayList)2 VoidPointer (com.ibm.j9ddr.vm29.pointer.VoidPointer)1 J9MemTagCheckError (com.ibm.j9ddr.vm29.pointer.helper.J9MemTagHelper.J9MemTagCheckError)1 TreeMap (java.util.TreeMap)1