Search in sources :

Example 1 with Scalar

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

use of com.ibm.j9ddr.vm29.types.Scalar in project openj9 by eclipse.

the class WhatIsCommand method checkScalar.

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

Example 3 with Scalar

use of com.ibm.j9ddr.vm29.types.Scalar in project openj9 by eclipse.

the class J9ObjectFieldOffsetIterator_V1 method fieldOffsetsFindNext.

// Based on fieldOffsetsFindNext from resolvefield.c
private void fieldOffsetsFindNext() throws CorruptDataException {
    while (romFieldsShapeIterator.hasNext()) {
        J9ROMFieldShapePointer localField = (J9ROMFieldShapePointer) romFieldsShapeIterator.next();
        U32 modifiers = localField.modifiers();
        /* count the index for jvmti */
        index = index.add(1);
        if (modifiers.anyBitsIn(J9AccStatic)) {
            if (walkFlags.anyBitsIn(J9VM_FIELD_OFFSET_WALK_INCLUDE_STATIC)) {
                /* found a static, the walk wants statics */
                if (modifiers.anyBitsIn(J9FieldFlagObject)) {
                    offset = new UDATA(objectStaticsSeen.mult(UDATA.SIZEOF));
                    objectStaticsSeen = objectStaticsSeen.add(1);
                    field = localField;
                    break;
                } else if (!(walkFlags.anyBitsIn(J9VM_FIELD_OFFSET_WALK_ONLY_OBJECT_SLOTS))) {
                    if (modifiers.anyBitsIn(J9FieldSizeDouble)) {
                        /* Add single scalar and object counts together, round up to 2 and divide by 2 to get number of doubles used by singles */
                        UDATA doubleSlots;
                        if (J9BuildFlags.env_data64) {
                            doubleSlots = new UDATA(romClass.objectStaticCount().add(romClass.singleScalarStaticCount()));
                        } else {
                            doubleSlots = new UDATA(romClass.objectStaticCount().add(romClass.singleScalarStaticCount()).add(1)).rightShift(1);
                        }
                        offset = doubleSlots.mult(U64.SIZEOF).add(doubleStaticsSeen.mult(U64.SIZEOF));
                        doubleStaticsSeen = doubleStaticsSeen.add(1);
                    } else {
                        offset = new UDATA(romClass.objectStaticCount().mult(UDATA.SIZEOF).add(singleStaticsSeen.mult(UDATA.SIZEOF)));
                        singleStaticsSeen = singleStaticsSeen.add(1);
                    }
                    field = localField;
                    break;
                }
            }
        } else {
            if (walkFlags.anyBitsIn(J9VM_FIELD_OFFSET_WALK_INCLUDE_INSTANCE)) {
                if (modifiers.anyBitsIn(J9FieldFlagObject)) {
                    if (walkFlags.anyBitsIn(J9VM_FIELD_OFFSET_WALK_BACKFILL_OBJECT_FIELD)) {
                        // Assert_VM_true(state->backfillOffsetToUse >= 0);
                        offset = new UDATA(backfillOffsetToUse);
                        walkFlags = walkFlags.bitAnd(new U32(new UDATA(J9VM_FIELD_OFFSET_WALK_BACKFILL_OBJECT_FIELD).bitNot()));
                    } else {
                        offset = firstObjectOffset.add(objectsSeen.mult(fj9object_t_SizeOf));
                        objectsSeen = objectsSeen.add(1);
                    }
                    field = localField;
                    break;
                } else if (!walkFlags.anyBitsIn(J9VM_FIELD_OFFSET_WALK_ONLY_OBJECT_SLOTS)) {
                    if (modifiers.anyBitsIn(J9FieldSizeDouble)) {
                        offset = firstDoubleOffset.add(doubleSeen.mult(U64.SIZEOF));
                        doubleSeen = doubleSeen.add(1);
                    } else {
                        if (walkFlags.anyBitsIn(J9VM_FIELD_OFFSET_WALK_BACKFILL_SINGLE_FIELD)) {
                            // Assert_VM_true(state->backfillOffsetToUse >= 0);
                            offset = new UDATA(backfillOffsetToUse);
                            walkFlags = walkFlags.bitAnd(new U32(new UDATA(J9VM_FIELD_OFFSET_WALK_BACKFILL_SINGLE_FIELD).bitNot()));
                        } else {
                            offset = firstSingleOffset.add(singlesSeen.mult(U32.SIZEOF));
                            singlesSeen = singlesSeen.add(1);
                        }
                    }
                    field = localField;
                    break;
                }
            }
        }
    }
    // At this point all the info we need is stashed away in private state variables
    return;
}
Also used : UDATA(com.ibm.j9ddr.vm29.types.UDATA) U32(com.ibm.j9ddr.vm29.types.U32) J9ROMFieldShapePointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMFieldShapePointer)

Example 4 with Scalar

use of com.ibm.j9ddr.vm29.types.Scalar in project openj9 by eclipse.

the class ScalarFormatter method format.

@Override
public FormatWalkResult format(String name, String type, String declaredType, int thisTypeCode, long address, PrintStream out, Context context, IStructureFormatter structureFormatter) throws CorruptDataException {
    if (thisTypeCode == this.typeCode) {
        Object o = null;
        try {
            o = castMethod.invoke(null, address);
        } catch (Exception e) {
            throw new RuntimeException("Cast failed on " + pointerClass.getName(), e);
        }
        try {
            Scalar value = (Scalar) atMethod.invoke(o, 0L);
            formatShortScalar(value, out);
        } catch (InvocationTargetException e) {
            Throwable cause = e.getCause();
            if (cause instanceof CorruptDataException) {
                throw (CorruptDataException) cause;
            } else if (cause instanceof RuntimeException) {
                throw (RuntimeException) cause;
            } else {
                throw new RuntimeException("Problem invoking at() method on " + pointerClass.getName(), e);
            }
        } catch (Exception e) {
            throw new RuntimeException("Problem invoking at() method on " + pointerClass.getName(), e);
        }
        return FormatWalkResult.STOP_WALKING;
    } else {
        return FormatWalkResult.KEEP_WALKING;
    }
}
Also used : CorruptDataException(com.ibm.j9ddr.CorruptDataException) CorruptDataException(com.ibm.j9ddr.CorruptDataException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Scalar(com.ibm.j9ddr.vm29.types.Scalar)

Aggregations

CorruptDataException (com.ibm.j9ddr.CorruptDataException)2 Scalar (com.ibm.j9ddr.vm29.types.Scalar)2 UDATA (com.ibm.j9ddr.vm29.types.UDATA)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)1 AbstractPointer (com.ibm.j9ddr.vm29.pointer.AbstractPointer)1 StructurePointer (com.ibm.j9ddr.vm29.pointer.StructurePointer)1 J9ROMFieldShapePointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMFieldShapePointer)1 U32 (com.ibm.j9ddr.vm29.types.U32)1 HashSet (java.util.HashSet)1