Search in sources :

Example 1 with StructurePointer

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

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

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

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

the class ACCommand method dumpACForObject.

public void dumpACForObject(J9JavaVMPointer vm, StructurePointer objectPointer, PrintStream out) throws CorruptDataException {
    if (GCExtensions.isVLHGC()) {
        if ((null != objectPointer) && !objectPointer.isNull()) {
            /* get the object's region */
            GCHeapRegionDescriptor region = heapRegionManager.regionDescriptorForAddress(objectPointer);
            if (null != region) {
                MM_HeapRegionDescriptorVLHGCPointer vlhgcRegionPointer = MM_HeapRegionDescriptorVLHGCPointer.cast(region.getHeapRegionDescriptorPointer());
                /* get the region's owning allocation context */
                StructurePointer act = vlhgcRegionPointer._allocateData()._owningContext().getAsRuntimeType();
                out.println("Object's owning context: " + act.formatShortInteractive());
            }
        }
    }
}
Also used : GCHeapRegionDescriptor(com.ibm.j9ddr.vm29.j9.gc.GCHeapRegionDescriptor) StructurePointer(com.ibm.j9ddr.vm29.pointer.StructurePointer) MM_HeapRegionDescriptorVLHGCPointer(com.ibm.j9ddr.vm29.pointer.generated.MM_HeapRegionDescriptorVLHGCPointer)

Example 5 with StructurePointer

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

the class ClassWalker method addObjectsAsSlot.

/**
 * It walks through each field in this structure that is represented by methodClass and
 * registers each field as a slot into ClassWalkerCallBack
 *
 * It uses the StructureDescriptor of J9DDR to get the FieldDescriptor of a structure.
 * The name, type and address are found in the FieldDescriptor. The name, type and address
 * are guaranteed to match the current core file, since they are taken from it.
 *
 * @param methodClass pointer class that is generated for the VM structure
 * @param renameFields	list of names to rename the original field names in the structure
 * @throws CorruptDataException
 */
protected void addObjectsAsSlot(StructurePointer methodClass, HashMap<String, String> renameFields) throws CorruptDataException {
    /* Get the structure name by removing "Pointer" suffix from the DDR generated class name*/
    String structureName = methodClass.getClass().getSimpleName().substring(0, methodClass.getClass().getSimpleName().indexOf("Pointer"));
    /* Get structure descriptor by using structure name */
    StructureDescriptor sd = StructureCommandUtil.getStructureDescriptor(structureName, getContext());
    /* Structure descriptor can not be null in normal circumstances, 
		 * because StructurePointer "methodClass" is generated for an existing structure in the VM, 
		 * so it should exist. If not, throw an exception. 
		 */
    if (sd == null) {
        throw new CorruptDataException("Structure \"" + structureName + "\" can not be found.");
    }
    for (FieldDescriptor fd : sd.getFields()) {
        /* Get the name of the field from field descriptor */
        String outName = fd.getName();
        /* Get SlotType by using field type name */
        SlotType type = getTypeByFieldTypeName(fd.getType());
        /* Get the address of the field by adding the offset to the methodClass'address */
        AbstractPointer address = U8Pointer.cast(methodClass).addOffset(fd.getOffset());
        /* Rename fields if any defined. */
        if (null != renameFields) {
            if (renameFields.containsKey(outName)) {
                outName = renameFields.get(outName);
            }
        }
        /*add the field into classWalkerCallback by its name, type, address and debug extension method name */
        classWalkerCallback.addSlot(clazz, type, address, outName, getDebugExtForMethodName(outName));
    }
}
Also used : AbstractPointer(com.ibm.j9ddr.vm29.pointer.AbstractPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException) StructureDescriptor(com.ibm.j9ddr.StructureReader.StructureDescriptor) FieldDescriptor(com.ibm.j9ddr.StructureReader.FieldDescriptor) SlotType(com.ibm.j9ddr.vm29.tools.ddrinteractive.IClassWalkCallbacks.SlotType)

Aggregations

CorruptDataException (com.ibm.j9ddr.CorruptDataException)5 StructurePointer (com.ibm.j9ddr.vm29.pointer.StructurePointer)5 AbstractPointer (com.ibm.j9ddr.vm29.pointer.AbstractPointer)4 MM_HeapRegionDescriptorSegregatedPointer (com.ibm.j9ddr.vm29.pointer.generated.MM_HeapRegionDescriptorSegregatedPointer)2 MM_LockingFreeHeapRegionListPointer (com.ibm.j9ddr.vm29.pointer.generated.MM_LockingFreeHeapRegionListPointer)2 MM_LockingHeapRegionQueuePointer (com.ibm.j9ddr.vm29.pointer.generated.MM_LockingHeapRegionQueuePointer)2 FieldDescriptor (com.ibm.j9ddr.StructureReader.FieldDescriptor)1 StructureDescriptor (com.ibm.j9ddr.StructureReader.StructureDescriptor)1 DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)1 GCHeapRegionDescriptor (com.ibm.j9ddr.vm29.j9.gc.GCHeapRegionDescriptor)1 VoidPointer (com.ibm.j9ddr.vm29.pointer.VoidPointer)1 J9ROMClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassPointer)1 J9ROMNameAndSignaturePointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMNameAndSignaturePointer)1 MM_HeapRegionDescriptorVLHGCPointer (com.ibm.j9ddr.vm29.pointer.generated.MM_HeapRegionDescriptorVLHGCPointer)1 SlotType (com.ibm.j9ddr.vm29.tools.ddrinteractive.IClassWalkCallbacks.SlotType)1 Scalar (com.ibm.j9ddr.vm29.types.Scalar)1 UDATA (com.ibm.j9ddr.vm29.types.UDATA)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashSet (java.util.HashSet)1 Stack (java.util.Stack)1