Search in sources :

Example 1 with AbstractPointer

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

the class GCConstantPoolSlotIterator method initializeSlots_V1.

protected void initializeSlots_V1(J9ClassPointer clazz, boolean returnClassSlots, boolean returnObjectSlots) throws CorruptDataException {
    U32Pointer cpDescriptionSlots = clazz.romClass().cpShapeDescription();
    PointerPointer cpEntry = PointerPointer.cast(clazz.ramConstantPool());
    long cpDescription = 0;
    long cpEntryCount = clazz.romClass().ramConstantPoolCount().longValue();
    long cpDescriptionIndex = 0;
    ArrayList<AbstractPointer> slots = new ArrayList<AbstractPointer>();
    ArrayList<VoidPointer> addresses = new ArrayList<VoidPointer>();
    while (cpEntryCount > 0) {
        if (0 == cpDescriptionIndex) {
            // Load a new description word
            cpDescription = cpDescriptionSlots.at(0).longValue();
            cpDescriptionSlots = cpDescriptionSlots.add(1);
            cpDescriptionIndex = J9_CP_DESCRIPTIONS_PER_U32;
        }
        long slotType = cpDescription & J9_CP_DESCRIPTION_MASK;
        if ((slotType == J9CPTYPE_STRING) || (slotType == J9CPTYPE_ANNOTATION_UTF8)) {
            if (returnObjectSlots) {
                J9RAMStringRefPointer ref = J9RAMStringRefPointer.cast(cpEntry);
                J9ObjectPointer slot = ref.stringObject();
                if (slot.notNull()) {
                    slots.add(slot);
                    addresses.add(VoidPointer.cast(ref.stringObjectEA()));
                }
            }
        } else if (slotType == J9CPTYPE_METHOD_TYPE) {
            if (returnObjectSlots) {
                J9RAMMethodTypeRefPointer ref = J9RAMMethodTypeRefPointer.cast(cpEntry);
                J9ObjectPointer slot = ref.type();
                if (slot.notNull()) {
                    slots.add(slot);
                    addresses.add(VoidPointer.cast(ref.typeEA()));
                }
            }
        } else if (slotType == J9CPTYPE_METHODHANDLE) {
            if (returnObjectSlots) {
                J9RAMMethodHandleRefPointer ref = J9RAMMethodHandleRefPointer.cast(cpEntry);
                J9ObjectPointer slot = ref.methodHandle();
                if (slot.notNull()) {
                    slots.add(slot);
                    addresses.add(VoidPointer.cast(ref.methodHandleEA()));
                }
            }
        } else if (slotType == J9CPTYPE_CLASS) {
            if (returnClassSlots) {
                J9RAMClassRefPointer ref = J9RAMClassRefPointer.cast(cpEntry);
                J9ClassPointer slot = ref.value();
                if (slot.notNull()) {
                    slots.add(slot);
                    addresses.add(VoidPointer.cast(ref.valueEA()));
                }
            }
        }
        cpEntry = cpEntry.addOffset(J9RAMConstantPoolItem.SIZEOF);
        cpEntryCount -= 1;
        cpDescription >>= J9_CP_BITS_PER_DESCRIPTION;
        cpDescriptionIndex -= 1;
    }
    slotIterator = slots.iterator();
    addressIterator = addresses.iterator();
}
Also used : AbstractPointer(com.ibm.j9ddr.vm29.pointer.AbstractPointer) VoidPointer(com.ibm.j9ddr.vm29.pointer.VoidPointer) PointerPointer(com.ibm.j9ddr.vm29.pointer.PointerPointer) J9RAMClassRefPointer(com.ibm.j9ddr.vm29.pointer.generated.J9RAMClassRefPointer) J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) ArrayList(java.util.ArrayList) J9RAMMethodTypeRefPointer(com.ibm.j9ddr.vm29.pointer.generated.J9RAMMethodTypeRefPointer) J9ObjectPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer) J9RAMStringRefPointer(com.ibm.j9ddr.vm29.pointer.generated.J9RAMStringRefPointer) U32Pointer(com.ibm.j9ddr.vm29.pointer.U32Pointer) J9RAMMethodHandleRefPointer(com.ibm.j9ddr.vm29.pointer.generated.J9RAMMethodHandleRefPointer)

Example 2 with AbstractPointer

use of com.ibm.j9ddr.vm29.pointer.AbstractPointer 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 3 with AbstractPointer

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

the class LinearDumper method getAllRegions.

/**
 * Returns a tree of regions and slots. Each slot is under a region. The
 * root element is always null.
 * @param classWalker
 *
 * @return J9ClassRegionNode tree of J9ClassRegion
 * @throws CorruptDataException
 */
public J9ClassRegionNode getAllRegions(ClassWalker classWalker) throws CorruptDataException {
    classWalker.allSlotsInObjectDo(this);
    final StructurePointer clazz = classWalker.getClazz();
    /* Add the UTF8 region */
    if (firstJ9_ROM_UTF8 != Long.MAX_VALUE) {
        addSection(clazz, PointerPointer.cast(firstJ9_ROM_UTF8), lastJ9_ROM_UTF8 - firstJ9_ROM_UTF8, "UTF8", true);
    }
    groupSectionByName(clazz, "methodDebugInfo", false);
    groupSectionByName(clazz, "variableInfo", false);
    /*
		 * the offset is a pointer which points at the end of the current
		 * region, in the case of a region which have no real size, it points at
		 * the beginning of the region
		 */
    AbstractPointer offset = PointerPointer.NULL;
    J9ClassRegionNode currentNode = new J9ClassRegionNode(null);
    Stack<J9ClassRegionNode> parentStack = new Stack<J9ClassRegionNode>();
    J9ClassRegion previousRegion = null;
    Collections.sort(classRegions);
    for (J9ClassRegion region : classRegions) {
        if (isSameRegion(previousRegion, region)) {
            previousRegion = region;
            continue;
        }
        previousRegion = region;
        if (SlotType.J9_SECTION_START == region.getType()) {
            if (region.getComputePadding() && offset.notNull() && !offset.eq(region.getSlotPtr())) {
                currentNode.addChild(new J9ClassRegionNode(new J9ClassRegion(offset, SlotType.J9_Padding, "Padding", "", region.getSlotPtr().getAddress() - offset.getAddress(), 0, true)));
            }
            if (region.getComputePadding()) {
                offset = region.getSlotPtr();
            }
            parentStack.push(currentNode);
            J9ClassRegionNode newChild = new J9ClassRegionNode(region);
            currentNode.addChild(newChild);
            currentNode = newChild;
        } else if (SlotType.J9_SECTION_END == region.getType()) {
            if (region.getComputePadding()) {
                long paddingSize = (region.getSlotPtr().getAddress() - offset.getAddress());
                if (paddingSize != 0) {
                    currentNode.addChild(new J9ClassRegionNode(new J9ClassRegion(offset, SlotType.J9_Padding, "Padding", "", paddingSize, 0, true)));
                }
                offset = region.getSlotPtr();
            }
            currentNode = parentStack.pop();
        } else {
            boolean computePadding = false;
            if (currentNode.getNodeValue() != null) {
                computePadding = currentNode.getNodeValue().getComputePadding();
            }
            if (computePadding && offset.notNull() && !offset.eq(region.getSlotPtr())) {
                currentNode.addChild(new J9ClassRegionNode(new J9ClassRegion(offset, SlotType.J9_Padding, "Padding", "", region.getSlotPtr().getAddress() - offset.getAddress(), 0, true)));
            }
            if (computePadding) {
                offset = region.getSlotPtr().addOffset(region.length);
            }
            currentNode.addChild(new J9ClassRegionNode(region));
        }
    }
    // Padding after the class and inside the romSize.
    if (clazz instanceof J9ROMClassPointer) {
        long size = J9ROMClassPointer.cast(clazz).romSize().longValue();
        long paddingSize = (clazz.longValue() + size) - offset.longValue();
        if (paddingSize != 0) {
            currentNode.addChild(new J9ClassRegionNode(new J9ClassRegion(offset, SlotType.J9_Padding, "Padding", "", paddingSize, 0, true)));
            // The class padding might be inserted out of order
            Collections.sort(currentNode.getChildren());
        }
    }
    return currentNode;
}
Also used : AbstractPointer(com.ibm.j9ddr.vm29.pointer.AbstractPointer) StructurePointer(com.ibm.j9ddr.vm29.pointer.StructurePointer) J9ROMClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassPointer) Stack(java.util.Stack)

Example 4 with AbstractPointer

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

the class WhatIsCommand method walkStructuresFrom.

private boolean walkStructuresFrom(StructurePointer startPoint) throws DDRInteractiveCommandException {
    Set<AbstractPointer> walked = new HashSet<AbstractPointer>();
    SearchStack searchStack = new SearchStack(maxDepth);
    if (UDATA.cast(startPoint).eq(searchValue)) {
        out.println("Found " + searchValue.getHexValue() + " as " + startPoint.formatShortInteractive());
        return true;
    }
    /* Seed with startPoint */
    searchStack.push(new SearchFrame(startPoint));
    walked.add(startPoint);
    boolean found = false;
    while (!searchStack.isEmpty() && !found) {
        SearchFrame current = searchStack.peek();
        int fieldIndex = current.fieldIndex++;
        if (current.fieldAccessors.length <= fieldIndex) {
            // We've walked all the fields on this object
            searchStack.pop();
            continue;
        }
        try {
            current.fieldName = current.fieldAccessors[fieldIndex].getName();
            Object result = current.fieldAccessors[fieldIndex].invoke(current.ptr);
            if (result == null) {
                continue;
            }
            fieldCount++;
            if (result instanceof StructurePointer) {
                StructurePointer ptr = (StructurePointer) result;
                found = checkPointer(searchStack, ptr);
                if (!searchStack.isFull() && !walked.contains(ptr)) {
                    walked.add(ptr);
                    searchStack.push(new SearchFrame(ptr));
                }
            } else if (result instanceof AbstractPointer) {
                AbstractPointer ptr = (AbstractPointer) result;
                found = checkPointer(searchStack, ptr);
            } else if (result instanceof Scalar) {
                Scalar s = (Scalar) result;
                found = checkScalar(searchStack, s);
            } else {
                out.println("Unexpected type walked: " + result.getClass().getName());
                continue;
            }
        } catch (InvocationTargetException e) {
            Throwable cause = e.getCause();
            if (cause instanceof CorruptDataException || cause instanceof NoSuchFieldError || cause instanceof NoClassDefFoundError) {
                // Skip this field
                continue;
            } else {
                throw new DDRInteractiveCommandException("Unexpected exception during walk", cause);
            }
        } catch (Exception e) {
            throw new DDRInteractiveCommandException("Unexpected exception during !whatis walk", e);
        }
    }
    return found;
}
Also used : AbstractPointer(com.ibm.j9ddr.vm29.pointer.AbstractPointer) StructurePointer(com.ibm.j9ddr.vm29.pointer.StructurePointer) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) CorruptDataException(com.ibm.j9ddr.CorruptDataException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) CorruptDataException(com.ibm.j9ddr.CorruptDataException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Scalar(com.ibm.j9ddr.vm29.types.Scalar) HashSet(java.util.HashSet)

Example 5 with AbstractPointer

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

the class WhatIsCommand method checkPointer.

private boolean checkPointer(SearchStack searchStack, AbstractPointer ptr) {
    UDATA cmpValue = UDATA.cast(ptr);
    if (searchValue.eq(cmpValue)) {
        if (++foundCount > skipCount) {
            out.print("Found " + searchValue.getHexValue() + " as " + ptr.formatShortInteractive() + ": ");
            searchStack.dump(out);
            out.println();
            return true;
        }
    } else {
        updateClosest(searchStack, cmpValue);
    }
    return false;
}
Also used : UDATA(com.ibm.j9ddr.vm29.types.UDATA)

Aggregations

AbstractPointer (com.ibm.j9ddr.vm29.pointer.AbstractPointer)8 CorruptDataException (com.ibm.j9ddr.CorruptDataException)7 VoidPointer (com.ibm.j9ddr.vm29.pointer.VoidPointer)4 UDATA (com.ibm.j9ddr.vm29.types.UDATA)3 DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)2 PointerPointer (com.ibm.j9ddr.vm29.pointer.PointerPointer)2 StructurePointer (com.ibm.j9ddr.vm29.pointer.StructurePointer)2 U32Pointer (com.ibm.j9ddr.vm29.pointer.U32Pointer)2 J9ROMClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassPointer)2 FieldDescriptor (com.ibm.j9ddr.StructureReader.FieldDescriptor)1 StructureDescriptor (com.ibm.j9ddr.StructureReader.StructureDescriptor)1 GCHeapRegionDescriptor (com.ibm.j9ddr.vm29.j9.gc.GCHeapRegionDescriptor)1 GCHeapRegionIterator (com.ibm.j9ddr.vm29.j9.gc.GCHeapRegionIterator)1 U64Pointer (com.ibm.j9ddr.vm29.pointer.U64Pointer)1 U8Pointer (com.ibm.j9ddr.vm29.pointer.U8Pointer)1 UDATAPointer (com.ibm.j9ddr.vm29.pointer.UDATAPointer)1 J9ClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer)1 J9ConstantPoolPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ConstantPoolPointer)1 J9JavaVMPointer (com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer)1 J9MemorySegmentPointer (com.ibm.j9ddr.vm29.pointer.generated.J9MemorySegmentPointer)1