use of com.ibm.j9ddr.vm29.pointer.generated.J9MemTagPointer in project openj9 by eclipse.
the class J9MemTagHelper method checkTagSumCheck.
/**
* Checks that the memory tag is not corrupt.
*
* @param[in] tagAddress the in-process or out-of-process address of the
* header/footer memory tag
* @param[in] eyeCatcher the eyecatcher corresponding to the memory tag
*
* @return 0 if the sum check is successful, non-zero otherwise
* @throws CorruptDataException
*/
public static void checkTagSumCheck(J9MemTagPointer tag, long eyeCatcher) throws CorruptDataException {
int sum = 0;
U32Pointer slots;
if (!checkEyecatcher(tag, eyeCatcher)) {
throw new J9MemTagCheckError(tag, "Wrong eyecatcher. Expected 0x" + Long.toHexString(eyeCatcher) + " but was " + UDATA.cast(tag).getHexValue());
}
slots = U32Pointer.cast(tag);
/*
* Could be unrolled into chained xors with a J9VM_ENV_DATA64
* conditional on the extra 2 U_32s
*/
for (int i = 0; i < (J9MemTag.SIZEOF / U32.SIZEOF); i++) {
sum ^= slots.at(i).longValue();
}
if (J9BuildFlags.env_data64) {
U32 a = new U32(UDATA.cast(tag).rightShift(32));
U32 b = new U32(UDATA.cast(tag).bitAnd(U32.MAX));
sum ^= a.longValue() ^ b.longValue();
} else {
sum ^= tag.longValue();
}
if (sum != 0) {
throw new J9MemTagCheckError(tag, "J9MemTag sumcheck failed: " + sum);
}
}
use of com.ibm.j9ddr.vm29.pointer.generated.J9MemTagPointer 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);
}
use of com.ibm.j9ddr.vm29.pointer.generated.J9MemTagPointer in project openj9 by eclipse.
the class J9MemTagCommands method printMemTagForFindFreedCallSite.
private void printMemTagForFindFreedCallSite(MemTagEntry freedMemTagEntry) {
J9MemTagPointer freedHeader = freedMemTagEntry.getHeader();
long allocSize = freedMemTagEntry.getAllocSize();
try {
String callsite = freedHeader.callSite().getCStringAtOffset(0);
if (J9BuildFlags.env_data64) {
out.append(String.format(" !j9x 0x%s ", padWith('0', J9MemTagHelper.j9mem_get_memory_base(freedHeader).getHexAddress().substring(2), 16)));
out.append(String.format("0x%s ", padWith('0', Long.toHexString(allocSize), 16)));
if (allocSize == freedHeader.allocSize().longValue()) {
out.append(String.format("%19s", ""));
} else {
out.append(String.format("%s ", freedHeader.allocSize().getHexValue()));
}
out.append(String.format("%s", callsite));
} else {
out.append(String.format(" !j9x 0x%s ", padWith('0', J9MemTagHelper.j9mem_get_memory_base(freedHeader).getHexAddress().substring(2), 8)));
out.append(String.format("0x%s ", padWith('0', Long.toHexString(allocSize), 8)));
if (allocSize != freedHeader.allocSize().longValue()) {
out.append(String.format("%13s", ""));
} else {
out.append(String.format("%s ", freedHeader.allocSize().getHexValue()));
}
out.append(String.format("%s", callsite));
}
out.append('\n');
} catch (CorruptDataException e) {
// Unlikely - we've already checksummed the block
e.printStackTrace(out);
}
}
use of com.ibm.j9ddr.vm29.pointer.generated.J9MemTagPointer 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);
}
use of com.ibm.j9ddr.vm29.pointer.generated.J9MemTagPointer in project openj9 by eclipse.
the class J9MemTagCommands method buildCallsitesTable.
private Map<String, J9DbgExtMemStats> buildCallsitesTable(J9MemTagIterator it, boolean lookingForFreedCallSites) {
Map<String, J9DbgExtMemStats> callSites = new TreeMap<String, J9DbgExtMemStats>();
while (it.hasNext()) {
J9MemTagPointer header = it.next();
long allocSize;
String callsite;
try {
allocSize = header.allocSize().longValue();
if (lookingForFreedCallSites && 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.
*
*/
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();
}
}
callsite = header.callSite().getCStringAtOffset(0);
/*
* Since the type of next alloc size memory is known, iterator can safely jump to the end of it.
*/
it.moveCurrentSearchAddress(allocSize);
if (!callSites.containsKey(callsite)) {
callSites.put(callsite, new J9DbgExtMemStats(header.allocSize().longValue()));
} else {
J9DbgExtMemStats memStats = callSites.get(callsite);
memStats.incrementTotalBlocksAllocated();
memStats.addTotalBytesAllocated(header.allocSize().longValue());
}
} catch (CorruptDataException e) {
// Unlikely - J9MemTagIterator already checksummed the header
out.println("Unexpected CDE reading contents of " + Long.toHexString(header.getAddress()));
e.printStackTrace(out);
continue;
}
}
return callSites;
}
Aggregations