Search in sources :

Example 1 with ArrayType

use of com.sun.jdi.ArrayType in project jdk8u_jdk by JetBrains.

the class OomDebugTest method test2.

/*
     * Test case: Array reference as method parameter.
     */
// called via reflection
@SuppressWarnings("unused")
private void test2() throws Exception {
    System.out.println("DEBUG: ------------> Running test2");
    try {
        Field field = targetClass.fieldByName("byteArray");
        ArrayType arrType = (ArrayType) field.type();
        for (int i = 0; i < 15; i++) {
            ArrayReference byteArrayVal = arrType.newInstance(3000000);
            if (byteArrayVal.isCollected()) {
                System.out.println("DEBUG: Object got GC'ed before we can use it. NO-OP.");
                continue;
            }
            invoke("testPrimitive", "([B)V", byteArrayVal);
        }
    } catch (VMOutOfMemoryException e) {
        defaultHandleOOMFailure(e);
    }
}
Also used : ArrayType(com.sun.jdi.ArrayType) Field(com.sun.jdi.Field) ArrayReference(com.sun.jdi.ArrayReference) VMOutOfMemoryException(com.sun.jdi.VMOutOfMemoryException)

Example 2 with ArrayType

use of com.sun.jdi.ArrayType in project che by eclipse.

the class Evaluator method isAssignable.

private boolean isAssignable(Type from, Type to) {
    if (from.equals(to)) {
        return true;
    }
    if (from instanceof BooleanType) {
        return to instanceof BooleanType;
    }
    if (to instanceof BooleanType) {
        return false;
    }
    if (from instanceof PrimitiveType) {
        return to instanceof PrimitiveType;
    }
    if (to instanceof PrimitiveType) {
        return false;
    }
    if (from instanceof ArrayType) {
        if (to instanceof ArrayType) {
            Type fromArrayComponent;
            Type toArrayComponent;
            try {
                fromArrayComponent = ((ArrayType) from).componentType();
                toArrayComponent = ((ArrayType) to).componentType();
            } catch (ClassNotLoadedException e) {
                return false;
            }
            if (fromArrayComponent instanceof PrimitiveType) {
                return fromArrayComponent.equals(toArrayComponent);
            }
            return !(toArrayComponent instanceof PrimitiveType) && isAssignable(fromArrayComponent, toArrayComponent);
        }
        return to.name().equals("java.lang.Object");
    }
    if (from instanceof ClassType) {
        ClassType superClass = ((ClassType) from).superclass();
        if (superClass != null && isAssignable(superClass, to)) {
            return true;
        }
        for (InterfaceType interfaceType : ((ClassType) from).interfaces()) {
            if (isAssignable(interfaceType, to)) {
                return true;
            }
        }
    }
    for (InterfaceType interfaceType : ((InterfaceType) from).subinterfaces()) {
        if (isAssignable(interfaceType, to)) {
            return true;
        }
    }
    return false;
}
Also used : ArrayType(com.sun.jdi.ArrayType) ClassNotLoadedException(com.sun.jdi.ClassNotLoadedException) InterfaceType(com.sun.jdi.InterfaceType) Type(com.sun.jdi.Type) ClassType(com.sun.jdi.ClassType) ArrayType(com.sun.jdi.ArrayType) PrimitiveType(com.sun.jdi.PrimitiveType) BooleanType(com.sun.jdi.BooleanType) ReferenceType(com.sun.jdi.ReferenceType) InterfaceType(com.sun.jdi.InterfaceType) BooleanType(com.sun.jdi.BooleanType) PrimitiveType(com.sun.jdi.PrimitiveType) ClassType(com.sun.jdi.ClassType)

Example 3 with ArrayType

use of com.sun.jdi.ArrayType in project intellij-community by JetBrains.

the class JumpToTypeSourceAction method getObjectType.

@Nullable
private static ReferenceType getObjectType(@NotNull ReferenceType ref) {
    if (!(ref instanceof ArrayType)) {
        return ref;
    }
    final String elementTypeName = ref.name().replace("[]", "");
    final VirtualMachine vm = ref.virtualMachine();
    final List<ReferenceType> referenceTypes = vm.classesByName(elementTypeName);
    if (referenceTypes.size() == 1) {
        return referenceTypes.get(0);
    }
    return null;
}
Also used : ArrayType(com.sun.jdi.ArrayType) ReferenceType(com.sun.jdi.ReferenceType) VirtualMachine(com.sun.jdi.VirtualMachine) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ArrayType (com.sun.jdi.ArrayType)3 ReferenceType (com.sun.jdi.ReferenceType)2 ArrayReference (com.sun.jdi.ArrayReference)1 BooleanType (com.sun.jdi.BooleanType)1 ClassNotLoadedException (com.sun.jdi.ClassNotLoadedException)1 ClassType (com.sun.jdi.ClassType)1 Field (com.sun.jdi.Field)1 InterfaceType (com.sun.jdi.InterfaceType)1 PrimitiveType (com.sun.jdi.PrimitiveType)1 Type (com.sun.jdi.Type)1 VMOutOfMemoryException (com.sun.jdi.VMOutOfMemoryException)1 VirtualMachine (com.sun.jdi.VirtualMachine)1 Nullable (org.jetbrains.annotations.Nullable)1