Search in sources :

Example 16 with VoidPointer

use of com.ibm.j9ddr.vm29.pointer.VoidPointer in project openj9 by eclipse.

the class J9ClassHelper method superclass.

public static J9ClassPointer superclass(J9ClassPointer clazz) throws CorruptDataException {
    long index = classDepth(clazz).longValue() - 1;
    if (index < 0) {
        return J9ClassPointer.NULL;
    }
    VoidPointer j9ClassInstancePointer = clazz.superclasses().at(index);
    return J9ClassPointer.cast(j9ClassInstancePointer);
}
Also used : VoidPointer(com.ibm.j9ddr.vm29.pointer.VoidPointer)

Example 17 with VoidPointer

use of com.ibm.j9ddr.vm29.pointer.VoidPointer in project openj9 by eclipse.

the class J9MemTagHelper method j9mem_check_tags.

/**
 * Performs validation checks on the memory block starting at memoryPointer.
 *
 * The memory passed in could fall into one of three categories:
 * 1) It could be a valid J9MemTag region with valid headers and footers
 * 2) It could be not be a J9MemTag region
 * 3) It could be a J9MemTag region with some corruption in either the header, footer or padding
 *
 * @param[in] portLibrary The port library
 * @param[in] memoryPointer address returned by @ref j9mem_allocate_memory()
 *
 * @throws CorruptDataException if the tags are corrupted, or the memory is inaccessible. (Option 3)
 * @return J9PORT_MEMTAG_NOT_A_TAG if memoryPointer address is not a tag
 * 		   J9PORT_MEMTAG_HEADER_TAG_CORRUPTED if memoryPointer address is valid tag region but header tag is corrupted.
 * 		   J9PORT_MEMTAG_FOOTER_TAG_CORRUPTED if memoryPointer address is valid tag region but footer tag is corrupted.
 * 		   J9PORT_MEMTAG_FOOTER_PADDING_CORRUPTED if memoryPointer address is valid tag region but footer padding is corrupted.
 * 		   J9PORT_MEMTAG_VALID_TAG if memoryPointer address is valid tag and header/footer are not corrupted.
 * @note memoryPointer may not be NULL.
 */
public static IDATA j9mem_check_tags(VoidPointer memoryPointer, long headerEyecatcher, long footerEyecatcher) throws J9MemTagCheckError {
    J9MemTagPointer headerTagAddress, footerTagAddress = J9MemTagPointer.NULL;
    headerTagAddress = j9mem_get_header_tag(memoryPointer);
    try {
        footerTagAddress = j9mem_get_footer_tag(headerTagAddress);
        checkTagSumCheck(headerTagAddress, headerEyecatcher);
    } catch (J9MemTagCheckError e) {
        /* Corruption here either means the header tag is mangled, or the header eyecatcher isn't actually the start of a 
			 * J9MemTag block.
			 * 
			 * If we can find a valid footerTag, then we'll believe this is a mangled header.
			 */
        try {
            if (checkEyecatcher(footerTagAddress, footerEyecatcher)) {
                /* Footer eyecatcher is valid - header tag is corrupt */
                throw e;
            } else {
                /* Footer eyecatcher is invalid - this isn't a memory tag */
                return J9PORT_MEMTAG_NOT_A_TAG;
            }
        } catch (CorruptDataException e1) {
            /* Can't read the footer tag - assume memoryPointer isn't a tag */
            return J9PORT_MEMTAG_NOT_A_TAG;
        }
    } catch (CorruptDataException e) {
        /* CorruptDataException here will mean MemoryFault. Which means we can't read the 
			 * entire header tag - so we assume this isn't a valid J9MemTag
			 */
        return J9PORT_MEMTAG_NOT_A_TAG;
    }
    try {
        checkTagSumCheck(footerTagAddress, footerEyecatcher);
    } catch (J9MemTagCheckError e) {
        if (headerEyecatcher == J9MEMTAG_EYECATCHER_FREED_HEADER && footerEyecatcher == J9MEMTAG_EYECATCHER_FREED_FOOTER) {
            /* When dealing with already freed memory, it is reasonable to accept
				 * a block that is missing the footer instead of throwing an exception.
				 */
            return J9PORT_MEMTAG_FOOTER_TAG_CORRUPTED;
        } else {
            throw e;
        }
    } catch (CorruptDataException e) {
        /* If we got here, the header was valid. A memory fault here suggests
			 * we're missing the storage for the footer - which is corruption
			 */
        throw new J9MemTagCheckError(headerTagAddress, e);
    }
    try {
        checkPadding(headerTagAddress);
    } catch (J9MemTagCheckError e) {
        if (headerEyecatcher == J9MEMTAG_EYECATCHER_FREED_HEADER && footerEyecatcher == J9MEMTAG_EYECATCHER_FREED_FOOTER) {
            /* When dealing with already freed memory, it is reasonable to accept
				 * a block that is missing the footer instead of throwing an exception.
				 */
            return J9PORT_MEMTAG_FOOTER_PADDING_CORRUPTED;
        } else {
            throw e;
        }
    } catch (CorruptDataException e) {
        /* If we got here, the header was valid. A memory fault here suggests
			 * we're missing the storage for the padding - which is corruption
			 */
        throw new J9MemTagCheckError(headerTagAddress, e);
    }
    return J9PORT_MEMTAG_VALID_TAG;
}
Also used : AddressedCorruptDataException(com.ibm.j9ddr.AddressedCorruptDataException) CorruptDataException(com.ibm.j9ddr.CorruptDataException) J9MemTagPointer(com.ibm.j9ddr.vm29.pointer.generated.J9MemTagPointer)

Example 18 with VoidPointer

use of com.ibm.j9ddr.vm29.pointer.VoidPointer in project openj9 by eclipse.

the class MM_HeapRegionDescriptorHelper method getHighAddress.

public static VoidPointer getHighAddress(MM_HeapRegionDescriptorPointer region) throws CorruptDataException {
    VoidPointer result = VoidPointer.NULL;
    long regionsInSpan = region._regionsInSpan().longValue();
    if (regionsInSpan == 0) {
        result = region._highAddress();
    } else {
        UDATA low = UDATA.cast(region._lowAddress());
        UDATA high = UDATA.cast(region._highAddress());
        UDATA delta = high.sub(low);
        UDATA spanningSize = delta.mult((int) regionsInSpan);
        result = VoidPointer.cast(low.add(spanningSize));
    }
    return result;
}
Also used : UDATA(com.ibm.j9ddr.vm29.types.UDATA) VoidPointer(com.ibm.j9ddr.vm29.pointer.VoidPointer)

Example 19 with VoidPointer

use of com.ibm.j9ddr.vm29.pointer.VoidPointer in project openj9 by eclipse.

the class LinearDumper method addSlot.

public void addSlot(StructurePointer clazz, SlotType type, AbstractPointer slotPtr, String slotName, String additionalInfo) throws CorruptDataException {
    try {
        J9ROMNameAndSignaturePointer nas;
        long offset;
        /* The slots of the type J9_ROM_UTF8 are changed to have 2 slots:
			 * -J9_SRP_TO_STRING
			 * -J9_ROM_UTF8
			 * This is done because we want to print the SRP field and also print
			 * the UTF8 it is pointing to */
        switch(type) {
            case J9_ROM_UTF8:
                offset = slotPtr.getAddress() - clazz.getAddress();
                classRegions.add(new J9ClassRegion(slotPtr, SlotType.J9_SRP_TO_STRING, slotName, additionalInfo, type.getSize(), offset, true));
                VoidPointer srp = SelfRelativePointer.cast(slotPtr).get();
                addUTF8Region(clazz, slotName, additionalInfo, srp);
                break;
            case J9_UTF8:
                addUTF8Region(clazz, slotName, additionalInfo, slotPtr);
                break;
            /* The fields of the type J9_SRPNAS or J9_SRP are changed to have 2 J9_ROM_UTF8
				 * fields for their name and signature separated. */
            case J9_SRPNAS:
                nas = J9ROMNameAndSignaturePointer.cast(SelfRelativePointer.cast(slotPtr).get());
                if (nas.notNull()) {
                    addSlot(clazz, SlotType.J9_ROM_UTF8, nas.nameEA(), "name");
                    addSlot(clazz, SlotType.J9_ROM_UTF8, nas.signatureEA(), "signature");
                }
                /* Since it is a SRP to a NAS, also print the SRP field. */
                addSlot(clazz, SlotType.J9_SRP, slotPtr, "cpFieldNAS");
                break;
            case J9_NAS:
                nas = J9ROMNameAndSignaturePointer.cast(slotPtr);
                addSlot(clazz, SlotType.J9_ROM_UTF8, nas.nameEA(), "name");
                addSlot(clazz, SlotType.J9_ROM_UTF8, nas.signatureEA(), "signature");
                break;
            case J9_IntermediateClassData:
                offset = slotPtr.getAddress() - clazz.getAddress();
                classRegions.add(new J9ClassRegion(slotPtr, type, slotName, additionalInfo, ((J9ROMClassPointer) clazz).intermediateClassDataLength().longValue(), offset, true));
                break;
            default:
                offset = slotPtr.getAddress() - clazz.getAddress();
                classRegions.add(new J9ClassRegion(slotPtr, type, slotName, additionalInfo, type.getSize(), offset, true));
                break;
        }
    } catch (Exception e) {
    }
}
Also used : J9ROMNameAndSignaturePointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMNameAndSignaturePointer) VoidPointer(com.ibm.j9ddr.vm29.pointer.VoidPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Example 20 with VoidPointer

use of com.ibm.j9ddr.vm29.pointer.VoidPointer 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)

Aggregations

VoidPointer (com.ibm.j9ddr.vm29.pointer.VoidPointer)48 CorruptDataException (com.ibm.j9ddr.CorruptDataException)37 J9ObjectPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)15 NoSuchElementException (java.util.NoSuchElementException)13 PointerPointer (com.ibm.j9ddr.vm29.pointer.PointerPointer)9 UDATA (com.ibm.j9ddr.vm29.types.UDATA)9 DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)5 GCVMThreadListIterator (com.ibm.j9ddr.vm29.j9.gc.GCVMThreadListIterator)5 J9VMThreadPointer (com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer)5 U8Pointer (com.ibm.j9ddr.vm29.pointer.U8Pointer)4 UDATAPointer (com.ibm.j9ddr.vm29.pointer.UDATAPointer)3 J9ClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer)3 CorruptData (com.ibm.dtfj.image.CorruptData)2 JavaObject (com.ibm.dtfj.java.JavaObject)2 J9DDRCorruptData (com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)2 MonitorTable (com.ibm.j9ddr.vm29.j9.MonitorTable)2 GCJNIGlobalReferenceIterator (com.ibm.j9ddr.vm29.j9.gc.GCJNIGlobalReferenceIterator)2 GCJNIWeakGlobalReferenceIterator (com.ibm.j9ddr.vm29.j9.gc.GCJNIWeakGlobalReferenceIterator)2 GCObjectIterator (com.ibm.j9ddr.vm29.j9.gc.GCObjectIterator)2 BaseStackWalkerCallbacks (com.ibm.j9ddr.vm29.j9.stackwalker.BaseStackWalkerCallbacks)2