com.sun.jdi.ArrayType Java Examples

The following examples show how to use com.sun.jdi.ArrayType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OomDebugTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unused") // called via reflection
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);
    }
}
 
Example #2
Source File: OomDebugTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unused") // called via reflection
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);
    }
}
 
Example #3
Source File: SetVariableRequestHandler.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
private Value handleSetValueForObject(String name, String belongToClass, String valueString,
        ObjectReference container, Map<String, Object> options) throws InvalidTypeException, ClassNotLoadedException {
    Value newValue;
    if (container instanceof ArrayReference) {
        ArrayReference array = (ArrayReference) container;
        Type eleType = ((ArrayType) array.referenceType()).componentType();
        newValue = setArrayValue(array, eleType, Integer.parseInt(name), valueString, options);
    } else {
        if (StringUtils.isBlank(belongToClass)) {
            Field field = container.referenceType().fieldByName(name);
            if (field != null) {
                if (field.isStatic()) {
                    newValue = this.setStaticFieldValue(container.referenceType(), field, name, valueString, options);
                } else {
                    newValue = this.setObjectFieldValue(container, field, name, valueString, options);
                }
            } else {
                throw new IllegalArgumentException(
                        String.format("SetVariableRequest: Variable %s cannot be found.", name));
            }
        } else {
            newValue = setFieldValueWithConflict(container, container.referenceType().allFields(), name, belongToClass, valueString, options);
        }
    }
    return newValue;
}
 
Example #4
Source File: OomDebugTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unused") // called via reflection
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);
    }
}
 
Example #5
Source File: OomDebugTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unused") // called via reflection
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);
    }
}
 
Example #6
Source File: OomDebugTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unused") // called via reflection
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);
    }
}
 
Example #7
Source File: ObjectTranslation.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new translated node for given original one.
 *
 * @param o a node to be translated
 * @return a new translated node
 */
private Object createTranslation (Object o) {
    switch (translationID) {
        case THREAD_ID:
            if (o instanceof ThreadReference) {
                return new JPDAThreadImpl ((ThreadReference) o, debugger);
            } else if (o instanceof ThreadGroupReference) {
                return new JPDAThreadGroupImpl ((ThreadGroupReference) o, debugger);
            } else {
                return null;
            }
        case LOCALS_ID:
            if (o instanceof ArrayType) {
                return new JPDAArrayTypeImpl(debugger, (ArrayType) o);
            }
            if (o instanceof ReferenceType) {
                return new JPDAClassTypeImpl(debugger, (ReferenceType) o);
            }
        default:
            throw new IllegalStateException(""+o);
    }
}
 
Example #8
Source File: OomDebugTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unused") // called via reflection
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);
    }
}
 
Example #9
Source File: OomDebugTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unused") // called via reflection
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);
    }
}
 
Example #10
Source File: RemoteServices.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static ArrayReference createTargetBytes(VirtualMachine vm, byte[] bytes,
                                                ByteValue[] mirrorBytesCache) throws InvalidTypeException,
                                                                                     ClassNotLoadedException,
                                                                                     InternalExceptionWrapper,
                                                                                     VMDisconnectedExceptionWrapper,
                                                                                     ObjectCollectedExceptionWrapper,
                                                                                     UnsupportedOperationExceptionWrapper {
    ArrayType bytesArrayClass = getArrayClass(vm, "byte[]");
    ArrayReference array = null;
    boolean disabledCollection = false;
    while (!disabledCollection) {
        array = ArrayTypeWrapper.newInstance(bytesArrayClass, bytes.length);
        try {
            ObjectReferenceWrapper.disableCollection(array);
            disabledCollection = true;
        } catch (ObjectCollectedExceptionWrapper ocex) {
            // Collected too soon, try again...
        }
    }
    List<Value> values = new ArrayList<Value>(bytes.length);
    for (int i = 0; i < bytes.length; i++) {
        byte b = bytes[i];
        ByteValue mb = mirrorBytesCache[128 + b];
        if (mb == null) {
            mb = VirtualMachineWrapper.mirrorOf(vm, b);
            mirrorBytesCache[128 + b] = mb;
        }
        values.add(mb);
    }
    ArrayReferenceWrapper.setValues(array, values);
    return array;
}
 
Example #11
Source File: RemoteServices.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static ArrayType getArrayClass(VirtualMachine vm, String name) throws InternalExceptionWrapper,
                                                                              ObjectCollectedExceptionWrapper,
                                                                              VMDisconnectedExceptionWrapper {
    List<ReferenceType> classList = VirtualMachineWrapper.classesByName(vm, name);
    ReferenceType clazz = null;
    for (ReferenceType c : classList) {
        if (ReferenceTypeWrapper.classLoader(c) == null) {
            clazz = c;
            break;
        }
    }
    return (ArrayType) clazz;
}
 
Example #12
Source File: RemoteServices.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static ArrayReference createTargetBytes(VirtualMachine vm, byte[] bytes,
                                                ByteValue[] mirrorBytesCache) throws InvalidTypeException,
                                                                                     ClassNotLoadedException,
                                                                                     InternalExceptionWrapper,
                                                                                     VMDisconnectedExceptionWrapper,
                                                                                     ObjectCollectedExceptionWrapper {
    ArrayType bytesArrayClass = getArrayClass(vm, "byte[]");
    ArrayReference array = null;
    boolean disabledCollection = false;
    while (!disabledCollection) {
        array = ArrayTypeWrapper.newInstance(bytesArrayClass, bytes.length);
        try {
            ObjectReferenceWrapper.disableCollection(array);
            disabledCollection = true;
        } catch (ObjectCollectedExceptionWrapper ocex) {
            // Collected too soon, try again...
        } catch (UnsupportedOperationExceptionWrapper uex) {
            // Hope it will not be GC'ed...
            disabledCollection = true;
        }
    }
    List<Value> values = new ArrayList<Value>(bytes.length);
    for (int i = 0; i < bytes.length; i++) {
        byte b = bytes[i];
        ByteValue mb = mirrorBytesCache[128 + b];
        if (mb == null) {
            mb = VirtualMachineWrapper.mirrorOf(vm, b);
            mirrorBytesCache[128 + b] = mb;
        }
        values.add(mb);
    }
    ArrayReferenceWrapper.setValues(array, values);
    return array;
}
 
Example #13
Source File: RemoteServices.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static ArrayType getArrayClass(VirtualMachine vm, String name) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper, ObjectCollectedExceptionWrapper {
    List<ReferenceType> classList = VirtualMachineWrapper.classesByName(vm, name);
    ReferenceType clazz = null;
    for (ReferenceType c : classList) {
        if (ReferenceTypeWrapper.classLoader(c) == null) {
            clazz = c;
            break;
        }
    }
    return (ArrayType) clazz;
}
 
Example #14
Source File: RemoteServices.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static ArrayReference createTargetBytes(VirtualMachine vm, byte[] bytes,
                                                ByteValue[] mirrorBytesCache) throws InvalidTypeException,
                                                                                     ClassNotLoadedException,
                                                                                     InternalExceptionWrapper,
                                                                                     VMDisconnectedExceptionWrapper,
                                                                                     ObjectCollectedExceptionWrapper,
                                                                                     UnsupportedOperationExceptionWrapper {
    ArrayType bytesArrayClass = getArrayClass(vm, "byte[]");
    ArrayReference array = null;
    boolean disabledCollection = false;
    while (!disabledCollection) {
        array = ArrayTypeWrapper.newInstance(bytesArrayClass, bytes.length);
        try {
            ObjectReferenceWrapper.disableCollection(array);
            disabledCollection = true;
        } catch (ObjectCollectedExceptionWrapper ocex) {
            // Collected too soon, try again...
        }
    }
    List<Value> values = new ArrayList<Value>(bytes.length);
    for (int i = 0; i < bytes.length; i++) {
        byte b = bytes[i];
        ByteValue mb = mirrorBytesCache[128 + b];
        if (mb == null) {
            mb = VirtualMachineWrapper.mirrorOf(vm, b);
            mirrorBytesCache[128 + b] = mb;
        }
        values.add(mb);
    }
    ArrayReferenceWrapper.setValues(array, values);
    return array;
}
 
Example #15
Source File: RemoteServices.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static ArrayType getArrayClass(VirtualMachine vm, String name) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper, ObjectCollectedExceptionWrapper {
    List<ReferenceType> classList = VirtualMachineWrapper.classesByName(vm, name);
    ReferenceType clazz = null;
    for (ReferenceType c : classList) {
        if (ReferenceTypeWrapper.classLoader(c) == null) {
            clazz = c;
            break;
        }
    }
    return (ArrayType) clazz;
}
 
Example #16
Source File: VariableUtils.java    From java-debug with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Test whether the value has referenced objects.
 *
 * @param value
 *            the value.
 * @param includeStatic
 *            whether or not the static fields are visible.
 * @return true if this value is reference objects.
 */
public static boolean hasChildren(Value value, boolean includeStatic) {
    if (value == null || !(value instanceof ObjectReference)) {
        return false;
    }
    Type type = value.type();
    if (type instanceof ArrayType) {
        return ((ArrayReference) value).length() > 0;
    }
    return value.type() instanceof ReferenceType && ((ReferenceType) type).allFields().stream()
            .filter(t -> includeStatic || !t.isStatic()).toArray().length > 0;
}
 
Example #17
Source File: VariableUtils.java    From java-debug with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get the variables of the object.
 *
 * @param obj
 *            the object
 * @return the variable list
 * @throws AbsentInformationException
 *             when there is any error in retrieving information
 */
public static List<Variable> listFieldVariables(ObjectReference obj, boolean includeStatic) throws AbsentInformationException {
    List<Variable> res = new ArrayList<>();
    Type type = obj.type();
    if (type instanceof ArrayType) {
        int arrayIndex = 0;
        for (Value elementValue : ((ArrayReference) obj).getValues()) {
            Variable ele = new Variable(String.valueOf(arrayIndex++), elementValue);
            res.add(ele);
        }
        return res;
    }
    List<Field> fields = obj.referenceType().allFields().stream().filter(t -> includeStatic || !t.isStatic())
            .sorted((a, b) -> {
                try {
                    boolean v1isStatic = a.isStatic();
                    boolean v2isStatic = b.isStatic();
                    if (v1isStatic && !v2isStatic) {
                        return -1;
                    }
                    if (!v1isStatic && v2isStatic) {
                        return 1;
                    }
                    return a.name().compareToIgnoreCase(b.name());
                } catch (Exception e) {
                    logger.log(Level.SEVERE, String.format("Cannot sort fields: %s", e), e);
                    return -1;
                }
            }).collect(Collectors.toList());
    fields.forEach(f -> {
        Variable var = new Variable(f.name(), obj.getValue(f));
        var.field = f;
        res.add(var);
    });
    return res;
}
 
Example #18
Source File: VariableUtils.java    From java-debug with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get the variables of the object with pagination.
 *
 * @param obj
 *            the object
 * @param start
 *            the start of the pagination
 * @param count
 *            the number of variables needed
 * @return the variable list
 * @throws AbsentInformationException
 *             when there is any error in retrieving information
 */
public static List<Variable> listFieldVariables(ObjectReference obj, int start, int count)
        throws AbsentInformationException {
    List<Variable> res = new ArrayList<>();
    Type type = obj.type();
    if (type instanceof ArrayType) {
        int arrayIndex = start;
        for (Value elementValue : ((ArrayReference) obj).getValues(start, count)) {
            res.add(new Variable(String.valueOf(arrayIndex++), elementValue));
        }
        return res;
    }
    throw new UnsupportedOperationException("Only Array type is supported.");
}
 
Example #19
Source File: JdtUtils.java    From java-debug with Eclipse Public License 1.0 5 votes vote down vote up
private static String getGenericName(ReferenceType type) throws DebugException {
    if (type instanceof ArrayType) {
        try {
            Type componentType;
            componentType = ((ArrayType) type).componentType();
            if (componentType instanceof ReferenceType) {
                return getGenericName((ReferenceType) componentType) + "[]"; //$NON-NLS-1$
            }
            return type.name();
        } catch (ClassNotLoadedException e) {
            // we cannot create the generic name using the component type,
            // just try to create one with the information
        }
    }
    String signature = type.signature();
    StringBuffer res = new StringBuffer(getTypeName(signature));
    String genericSignature = type.genericSignature();
    if (genericSignature != null) {
        String[] typeParameters = Signature.getTypeParameters(genericSignature);
        if (typeParameters.length > 0) {
            res.append('<').append(Signature.getTypeVariable(typeParameters[0]));
            for (int i = 1; i < typeParameters.length; i++) {
                res.append(',').append(Signature.getTypeVariable(typeParameters[i]));
            }
            res.append('>');
        }
    }
    return res.toString();
}
 
Example #20
Source File: OomDebugTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unused") // called via reflection
private void test2() throws Exception {
    System.out.println("DEBUG: ------------> Running " + testMethodName);
    try {
        Field field = targetClass.fieldByName("byteArray");
        ArrayType arrType = (ArrayType)field.type();

        for (int i = 0; i < 15; i++) {
            ArrayReference byteArrayVal = arrType.newInstance(3000000);
            invoke("testPrimitive", "([B)V", byteArrayVal);
        }
    } catch (VMOutOfMemoryException e) {
        defaultHandleOOMFailure(e);
    }
}
 
Example #21
Source File: JPDAArrayTypeImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public JPDAArrayTypeImpl(JPDADebuggerImpl debugger, ArrayType arrayType) {
    super(debugger, arrayType);
    this.arrayType = arrayType;
}
 
Example #22
Source File: VariableUtilsTest.java    From java-debug with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testHasChildren() throws Exception {
    ObjectReference foo = this.getObjectReference("Foo");
    assertTrue("class Foo should have children", VariableUtils.hasChildren(foo, true));
    assertTrue("class Foo should have children", VariableUtils.hasChildren(foo, false));

    Value string = this.getLocalValue("str");

    assertTrue("String object should have children", VariableUtils.hasChildren(string, true));
    assertTrue("String object should have children", VariableUtils.hasChildren(string, false));

    ArrayReference arrays = (ArrayReference) this.getLocalValue("arrays");
    assertTrue("Array object with elements should have children", VariableUtils.hasChildren(
        arrays, true));
    assertTrue("Array object with elements should have children", VariableUtils.hasChildren(
        arrays, false));

    assertFalse("Array object with no elements should not have children", VariableUtils.hasChildren(
        ((ArrayType) arrays.type()).newInstance(0), true));

    assertFalse("Array object with no elements should not have children", VariableUtils.hasChildren(
        ((ArrayType) arrays.type()).newInstance(0), false));

    assertTrue("List object with elements should have children", VariableUtils.hasChildren(
        this.getLocalValue("strList"), false));

    assertFalse("Object should not have children", VariableUtils.hasChildren(this.getLocalValue("obj"), true));
    assertFalse("Object should not have children", VariableUtils.hasChildren(this.getLocalValue("obj"), false));

    assertTrue("Class object should have children", VariableUtils.hasChildren(this.getLocalValue("b"), false));
    assertTrue("Class object should have children", VariableUtils.hasChildren(this.getLocalValue("b"), false));

    assertFalse("Null object should not have children", VariableUtils.hasChildren(null, true));
    assertFalse("Null object should not have children", VariableUtils.hasChildren(null, false));

    assertTrue("Boolean object should have children", VariableUtils.hasChildren(getLocalValue("boolVar"), false));
    assertFalse("boolean object should not have children", VariableUtils.hasChildren(getVM().mirrorOf(true), false));

    assertFalse("Class with no fields should not have children", VariableUtils.hasChildren(this.getLocalValue("a"), true));
    assertFalse("Class with no fields should not have children", VariableUtils.hasChildren(this.getLocalValue("a"), false));

    assertFalse("Primitive object should not have children", VariableUtils.hasChildren(
        getVM().mirrorOf(1), true));
    assertFalse("Primitive object should not have children", VariableUtils.hasChildren(
        getVM().mirrorOf(true), true));
    assertFalse("Primitive object should not have children", VariableUtils.hasChildren(
        getVM().mirrorOf('c'), true));
    assertFalse("Primitive object should not have children", VariableUtils.hasChildren(
        getVM().mirrorOf(1000L), true));

}