Java 类com.sun.jdi.ArrayReference 实例源码

项目:jdk8u-jdk    文件:OomDebugTest.java   
@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);
    }
}
项目:openjdk-jdk10    文件:OomDebugTest.java   
@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);
    }
}
项目:jdk8u_jdk    文件:OomDebugTest.java   
@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);
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:OomDebugTest.java   
@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);
    }
}
项目:jive    文件:JDIEventHandlerDelegate.java   
boolean handleNewArray(final ArrayReference array, final Location location, final StackFrame frame)
{
  if (array == null || !manager().generateArrayEvents())
  {
    return false;
  }
  // handle the instantiation of of small arrays
  if (array != null && array.length() <= EventFactoryAdapter.SMALL_ARRAY_SIZE
      && contourFactory().lookupInstanceContour(array.type().name(), array.uniqueID()) == null)
  {
    handleTypeLoad((ReferenceType) array.type(), frame.thread());
    // a specialized new event handles the immutable length of the array
    manager().jiveDispatcher().dispatchNewEvent(array, frame.thread(), array.length());
    visitArrayCells(location, frame, array);
    return true;
  }
  return false;
}
项目:incubator-netbeans    文件:ArrayFieldVariable.java   
ArrayFieldVariable (
    JPDADebuggerImpl debugger,
    PrimitiveValue value,
    String declaredType,
    ObjectVariable array,
    int index,
    int maxIndex,
    String parentID
) {
    super (
        debugger, 
        value, 
        parentID + '.' + index +
            (value instanceof ObjectReference ? "^" : "")
    );
    this.index = index;
    this.maxIndexLog = log10(maxIndex);
    this.declaredType = declaredType;
    this.parent = array;
    this.array = (ArrayReference) ((JDIVariable) array).getJDIValue();
}
项目:incubator-netbeans    文件:ObjectArrayFieldVariable.java   
ObjectArrayFieldVariable (
    JPDADebuggerImpl debugger,
    ObjectReference value,
    String declaredType,
    ObjectVariable array,
    int index,
    int maxIndex,
    String parentID
) {
    super (
        debugger, 
        value, 
        parentID + '.' + index + "^"
    );
    this.index = index;
    this.maxIndexLog = ArrayFieldVariable.log10(maxIndex);
    this.declaredType = declaredType;
    this.parent = array;
    this.array = (ArrayReference) ((JDIVariable) array).getJDIValue();
}
项目:incubator-netbeans    文件:AbstractObjectVariable.java   
/**
* Returns string representation of type of this variable.
*
* @return string representation of type of this variable.
*/
@Override
public int getFieldsCount () {
    Value v = getInnerValue ();
    if (v == null) {
        return 0;
    }
    if (v instanceof ArrayReference) {
        return ArrayReferenceWrapper.length0((ArrayReference) v);
    } else {
        synchronized (fieldsLock) {
            if (fields == null || refreshFields) {
                initFields ();
            }
            return fields.length;
        }
    }
}
项目:incubator-netbeans    文件:EvaluatorVisitor.java   
@Override
public Mirror visitArrayAccess(ArrayAccessTree arg0, EvaluationContext evaluationContext) {
    Mirror array = arg0.getExpression().accept(this, evaluationContext);
    if (array == null) {
        Assert.error(arg0, "arrayIsNull", arg0.getExpression());
    }
    Mirror index = arg0.getIndex().accept(this, evaluationContext);
    if (!(array instanceof ArrayReference)) {
        Assert.error(arg0, "notArrayType", arg0.getExpression());
    }
    if (!(index instanceof PrimitiveValue)) {
        Assert.error(arg0, "arraySizeBadType", index);
    }
    int i = ((PrimitiveValue) index).intValue();
    if (i < 0 || i >= ((ArrayReference) array).length()) {
        Assert.error(arg0, "arrayIndexOutOfBounds", array, i);
    }
    evaluationContext.putArrayAccess(arg0, (ArrayReference)array, i);
    return ((ArrayReference) array).getValue(i);
}
项目:incubator-netbeans    文件:EvaluatorTest.java   
@Override
public boolean equals(Object obj) {
    if (!(obj instanceof JDIValue)) return false;
    Value v = ((JDIValue) obj).value;
    if (value == null) return v == null;
    if (value instanceof StringReference) {
        if (!(v instanceof StringReference)) return false;
        return ((StringReference) value).value().equals(((StringReference) v).value());
    }
    if (value instanceof ArrayReference) {
        if (!(v instanceof ArrayReference)) return false;
        ArrayReference a1 = (ArrayReference) value;
        ArrayReference a2 = (ArrayReference) v;
        if (!a1.type().equals(a2.type())) return false;
        if (a1.length() != a2.length()) return false;
        int n = a1.length();
        for (int i = 0; i < n; i++) {
            if (!new JDIValue(a1.getValue(i)).equals(new JDIValue(a2.getValue(i)))) {
                return false;
            }
        }
        return true;
    }
    return value.equals(v);
}
项目:openjdk-jdk10    文件:ArrayReferenceImpl.java   
public List<Value> getValues(int index, int length) {
    if (length == -1) { // -1 means the rest of the array
       length = length() - index;
    }
    validateArrayAccess(index, length);
    if (length == 0) {
        return new ArrayList<Value>();
    }

    List<Value> vals;
    try {
        vals = cast(JDWP.ArrayReference.GetValues.process(vm, this, index, length).values);
    } catch (JDWPException exc) {
        throw exc.toJDIException();
    }

    return vals;
}
项目:java-debug    文件:SetVariableRequestHandler.java   
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;
}
项目:java-debug    文件:VariableUtils.java   
/**
 * 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) {
        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;
}
项目:acdebugger    文件:BreakpointProcessor.java   
private void checkConditions(ThreadReference threadRef, Field contextField) throws Exception {
  ArrayReference contextArray = getContextArray(contextField, threadRef);
  int size = contextArray.getValues().size();

  for (int i = 0; i < size; i++) {
    ObjectReference context = (ObjectReference) contextArray.getValues().get(i);
    if (context != null
        && (hasBundlePerms(context)
            || hasBundleProtectionDomain(context)
            || hasBlueprintProtectionDomain(context))) {
      missingPerms.put(getBundleLocation(context), getPermissionString(threadRef));
    }
  }

  if (missingPerms.isEmpty()) {
    System.out.println("this is wrong");
  }
}
项目:acdebugger    文件:BreakpointProcessor.java   
private String getBundleLocation(ObjectReference permissions) {
  List<String> walker;
  if (hasBundlePerms(permissions)) {
    walker = BUNDLE_PERM_WALKER;
  } else if (hasBlueprintProtectionDomain(permissions)) {
    walker = BLUEPRINT_PERM_WALKER;
  } else {
    walker = BUNDLE_PROTDOMAIN_WALKER;
  }

  ObjectReference revList = getReference(permissions, walker);
  ArrayReference revArray =
      (ArrayReference) revList.getValue(revList.referenceType().fieldByName("elementData"));
  ObjectReference moduleRev = (ObjectReference) revArray.getValue(0);
  return getValue(
      moduleRev,
      ImmutableList.of("symbolicName"),
      currRef -> ((StringReference) currRef).value());
}
项目:che    文件:JdbValue.java   
@Override
public List<Variable> getVariables() {
  if (variables.get() == null) {
    synchronized (variables) {
      if (variables.get() == null) {
        if (isPrimitive()) {
          variables.set(Collections.emptyList());
        } else if (isArray()) {
          variables.set(new LinkedList<>());

          ArrayReference array = (ArrayReference) jdiValue;
          for (int i = 0; i < array.length(); i++) {
            variables.get().add(new JdbArrayElement(array.getValue(i), i, variablePath));
          }
        } else {
          ObjectReference object = (ObjectReference) jdiValue;
          variables.set(
              object
                  .referenceType()
                  .allFields()
                  .stream()
                  .map(f -> new JdbField(f, object, variablePath))
                  .sorted(new JdbFieldComparator())
                  .collect(Collectors.toList()));
        }
      }
    }
  }

  return variables.get();
}
项目:form-follows-function    文件:F3Wrapper.java   
public static F3ObjectReference wrap(F3VirtualMachine f3vm, ObjectReference ref) {
    if (ref == null) {
        return null;
    } else if (ref instanceof ArrayReference) {
        return f3vm.arrayReference((ArrayReference)ref);
    } else if (ref instanceof StringReference) {
        return f3vm.stringReference((StringReference)ref);
    } else if (ref instanceof ThreadReference) {
        return f3vm.threadReference((ThreadReference)ref);
    } else if (ref instanceof ThreadGroupReference) {
        return f3vm.threadGroupReference((ThreadGroupReference)ref);
    } else if (ref instanceof ClassLoaderReference) {
        return f3vm.classLoaderReference((ClassLoaderReference)ref);
    } else if (ref instanceof ClassObjectReference) {
        return f3vm.classObjectReference((ClassObjectReference)ref);
    } else {
        return f3vm.objectReference(ref);
    }
}
项目:jive    文件:JDIEventHandlerDelegate.java   
private boolean visitArrayCells(final Location location, final StackFrame frame,
    final ArrayReference arrayRef)
{
  // only process small arrays
  if (!manager().generateArrayEvents() || arrayRef == null
      || arrayRef.length() > EventFactoryAdapter.SMALL_ARRAY_SIZE)
  {
    return false;
  }
  // retrieve the array reference type
  final ArrayType at = (ArrayType) arrayRef.type();
  // retrieve the array contour
  final IContextContour array = contourFactory().lookupInstanceContour(at.name(),
      arrayRef.uniqueID());
  // make sure the respective array contour exists
  if (array == null)
  {
    return false;
  }
  return visitArrayCells(location, frame, arrayRef, array);
}
项目:JavaTracer    文件:ClassUtils.java   
/**
 * Returns if the value is excluded in the current configuration.
 * @param value - The value object to ask if it's excluded.
 * @return True if excluded, else false.
 */

private boolean isExcludedClass(Value value) {
    boolean excluded = false;
    String className = "";

    if (value instanceof ObjectReference)
        className = ClassUtils.getClass(((ObjectReference)value).referenceType());
    else if (value instanceof ArrayReference)
        className = ClassUtils.getClass(((ArrayReference)value).referenceType());

    if (!basicType(className) && (value instanceof ObjectReference || value instanceof ArrayReference)){
        if (!excludedClasses.containsKey(className)){

            excluded = (isJavaDataStructure(className) && config.isExcludedDataStructure()) || (!isJavaDataStructure(className) && isExcluded(className));
            excludedClasses.put(className,excluded);

        } else 
            excluded = excludedClasses.get(className);
    }
    return excluded;
}
项目:JavaTracer    文件:ClassUtils.java   
public Data getObj(boolean force,String name,Value value,List<Long> objectProcessed){

    Data object = null;
    if (value instanceof ArrayReference){
        object = getArrayFromArrayReference(force,name,(ArrayReference)value,objectProcessed);
    } else if (value instanceof PrimitiveValue){
        object = getPrimitiveObject(name,value);
    } else if (value instanceof StringReference){
        object = getStringFromStringReference(name,(StringReference)value);
    } else if (value instanceof ObjectReference){
        object = getObjectFromObjectReference(force,name,(ObjectReference)value,objectProcessed);
    } else if (value == null){
        object = new NullData(name);
    }
    return object;
}
项目:codehint    文件:Effect.java   
public void doEffect(RVal preVal, RVal postVal) throws InvalidTypeException, ClassNotLoadedException {
    if (postVal instanceof ArrayValue) {
        ArrayValue postArrVal = ((ArrayValue)postVal);
        if (preVal.getValue() instanceof ArrayReference) {
            ArrayReference preArrVal = (ArrayReference)preVal.getValue();
            if (postArrVal.getValue() instanceof ArrayReference && ((ArrayReference)postArrVal.getValue()).uniqueID() == preArrVal.uniqueID()) {
                // If it's the same array just with different values, we can reset the values directly.
                postArrVal.resetTo(preArrVal);
                return;
            }
        }
        // We must reset the original array's values and reset to it.
        postArrVal.resetTo((ArrayReference)postArrVal.getValue());
    }
    lval.setValue(postVal.getValue());
}
项目:incubator-netbeans    文件:RemoteServices.java   
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;
}
项目:incubator-netbeans    文件:AbstractVariable.java   
static String getValue (Value v) {
    if (v == null) {
        return "null";
    }
    if (v instanceof VoidValue) {
        return "void";
    }
    if (v instanceof CharValue) {
        return "\'" + v.toString () + "\'";
    }
    if (v instanceof PrimitiveValue) {
        return v.toString ();
    }
    try {
        if (v instanceof StringReference) {
            String str = ShortenedStrings.getStringWithLengthControl((StringReference) v);
            return "\"" + str + "\"";
        }
        if (v instanceof ClassObjectReference) {
            return "class " + ReferenceTypeWrapper.name(ClassObjectReferenceWrapper.reflectedType((ClassObjectReference) v));
        }
        if (v instanceof ArrayReference) {
            return "#" + ObjectReferenceWrapper.uniqueID((ArrayReference) v) +
                "(length=" + ArrayReferenceWrapper.length((ArrayReference) v) + ")";
        }
        return "#" + ObjectReferenceWrapper.uniqueID((ObjectReference) v);
    } catch (InternalExceptionWrapper iex) {
        return "";
    } catch (ObjectCollectedExceptionWrapper oex) {
        return "";
    } catch (VMDisconnectedExceptionWrapper dex) {
        return "";
    }
}
项目:incubator-netbeans    文件:AbstractObjectVariable.java   
/**
 * Return all static fields.
 *
 * @return all static fields
 */
@Override
public Field[] getAllStaticFields (int from, int to) {
    Value v = getInnerValue ();
    if (v == null || v instanceof ArrayReference) {
        return new Field[] {};
    }
    synchronized (fieldsLock) {
        if (fields == null || refreshFields) {
            initFields ();
        }
        return getSubFields(staticFields, from, to);
    }
}
项目:incubator-netbeans    文件:AbstractObjectVariable.java   
/**
 * Return all inherited fields.
 * 
 * @return all inherited fields
 */
@Override
public Field[] getInheritedFields (int from, int to) {
    Value v = getInnerValue ();
    if (v == null || v instanceof ArrayReference) {
        return new Field[] {};
    }
    synchronized (fieldsLock) {
        if (fields == null || refreshFields) {
            initFields ();
        }
        return getSubFields(inheritedFields, from, to);
    }
}
项目:incubator-netbeans    文件:RemoteServices.java   
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;
}
项目:incubator-netbeans    文件:EvaluatorVisitor.java   
private String toString(Tree arg0, Mirror v, EvaluationContext evaluationContext) {
    if (v instanceof PrimitiveValue) {
        PrimitiveValue pv = (PrimitiveValue) v;
        PrimitiveType t = (PrimitiveType) pv.type();
        if (t instanceof ByteType) {
            return Byte.toString(pv.byteValue());
        }
        if (t instanceof BooleanType) {
            return Boolean.toString(pv.booleanValue());
        }
        if (t instanceof CharType) {
            return Character.toString(pv.charValue());
        }
        if (t instanceof ShortType) {
            return Short.toString(pv.shortValue());
        }
        if (t instanceof IntegerType) {
            return Integer.toString(pv.intValue());
        }
        if (t instanceof LongType) {
            return Long.toString(pv.longValue());
        }
        if (t instanceof FloatType) {
            return Float.toString(pv.floatValue());
        }
        if (t instanceof DoubleType) {
            return Double.toString(pv.doubleValue());
        }
        throw new IllegalStateException("Unknown primitive type: "+t);
    }
    if (v == null) {
        return "" + null;
    }
    ObjectReference ov = (ObjectReference) v;
    if (ov instanceof ArrayReference) {
        return "#" + ov.uniqueID() +
            " " + ov.type().name() +
            "(length=" + ((ArrayReference) ov).length() + ")";
    }
    if (ov instanceof StringReference) {
        return ((StringReference) ov).value();
    }
    // Call toString() method:
    List<? extends TypeMirror> typeArguments = Collections.emptyList();
    Method method;
    try {
        method = getConcreteMethod((ReferenceType) ov.type(), "toString", typeArguments);
    } catch (UnsuitableArgumentsException uaex) {
        throw new IllegalStateException(uaex);
    }
    ((ClassType) ov.type()).methodsByName("toString");
    List<Value> argVals = Collections.emptyList();
    Value sv = invokeMethod(arg0, method, false, null, ov, argVals, evaluationContext, false);
    if (sv instanceof StringReference) {
        return ((StringReference) sv).value();
    } else if (sv == null) {
        return null;
    } else {
        return "Result of toString() call on "+ov+" is not a String, but: "+sv; // NOI18N - should not ever happen.
    }
}
项目:incubator-netbeans    文件:EvaluatorVisitor.java   
private static ArrayReference createArrayMirrorWithDisabledCollection(ArrayType arrayType, int dimension, EvaluationContext evaluationContext) {
    ArrayReference array;
    do {
        array = arrayType.newInstance(dimension);
        try {
            evaluationContext.disableCollectionOf(array);
        } catch (ObjectCollectedException oce) {
            array = null; // Already collected! Create a new value and try again...
        }
    } while (array == null);
    return array;
}
项目:openjdk-jdk10    文件:ArrayReferenceImpl.java   
/**
 * Return array length.
 * Need not be synchronized since it cannot be provably stale.
 */
public int length() {
    if(length == -1) {
        try {
            length = JDWP.ArrayReference.Length.
                process(vm, this).arrayLength;
        } catch (JDWPException exc) {
            throw exc.toJDIException();
        }
    }
    return length;
}
项目:openjdk-jdk10    文件:ArrayTypeImpl.java   
public ArrayReference newInstance(int length) {
    try {
        return (ArrayReference)JDWP.ArrayType.NewInstance.
                                   process(vm, this, length).newArray;
    } catch (JDWPException exc) {
        throw exc.toJDIException();
    }
}
项目:java-debug    文件:VariableUtils.java   
/**
 * 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;
}
项目:java-debug    文件:VariableUtils.java   
/**
 * 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.");
}
项目:intellij-ce-playground    文件:ForeachStatementEvaluator.java   
@Override
protected Object evaluateInitialization(EvaluationContextImpl context, Object value) throws EvaluateException {
  final Object iterable = myIterableEvaluator.evaluate(context);
  if (!(iterable instanceof ObjectReference)) {
    throw new EvaluateException("Unable to do foreach for" + iterable);
  }
  IdentityEvaluator iterableEvaluator = new IdentityEvaluator((Value)iterable);
  if (iterable instanceof ArrayReference) {
    myCurrentIndex = 0;
    myArrayLength = ((ArrayReference)iterable).length();
    myNextEvaluator = new AssignmentEvaluator(myIterationParameterEvaluator,
                                              new Evaluator() {
                                                @Override
                                                public Object evaluate(EvaluationContextImpl context) throws EvaluateException {
                                                  return ((ArrayReference)iterable).getValue(myCurrentIndex++);
                                                }

                                                @Override
                                                public Modifier getModifier() {
                                                  return null;
                                                }
                                              });
  }
  else {
    Object iterator = new MethodEvaluator(iterableEvaluator, null, "iterator", null, new Evaluator[0]).evaluate(context);
    IdentityEvaluator iteratorEvaluator = new IdentityEvaluator((Value)iterator);
    myConditionEvaluator = new MethodEvaluator(iteratorEvaluator, null, "hasNext", null, new Evaluator[0]);
    myNextEvaluator = new AssignmentEvaluator(myIterationParameterEvaluator,
                                              new MethodEvaluator(iteratorEvaluator, null, "next", null, new Evaluator[0]));
  }
  return value;
}
项目:intellij-ce-playground    文件:ArrayRenderer.java   
private static boolean elementIsNull(ArrayReference arrayReference, int index) {
  try {
    return ArrayElementDescriptorImpl.getArrayElement(arrayReference, index) == null;
  }
  catch (EvaluateException e) {
    return false;
  }
}
项目:intellij-ce-playground    文件:ArrayElementDescriptorImpl.java   
public static Value getArrayElement(ArrayReference reference, int idx) throws EvaluateException {
  try {
    return reference.getValue(idx);
  }
  catch (ObjectCollectedException e) {
    throw EvaluateExceptionUtil.ARRAY_WAS_COLLECTED;
  }
}
项目:intellij-ce-playground    文件:ArrayItemData.java   
public ArrayItemData(@NotNull ArrayReference arrRef, int idx) {
  LOG.assertTrue(0 <= idx);
  if(LOG.isDebugEnabled()) {
    LOG.assertTrue(idx <= arrRef.length());
  }
  myArray = arrRef;
  myIndex = idx;
}
项目:nopol    文件:ValueFactory.java   
public static Value create(Object value) {
    if (value == null) {
        return new ComplexValueImpl(null);
    }
    if (value instanceof Value) {
        return (Value) value;
    }
    if (value instanceof ArrayReference) {
        ArrayReference array = (ArrayReference) value;
        List<Value> arrayValues = create(array.getValues());
        return new ArrayValueImpl(array.type().name(), array, arrayValues, value);
    }
    if (value instanceof ObjectReference) {
        return new ComplexValueImpl((ObjectReference) value);
    }
    if (value instanceof ClassType) {
        return new TypeValueImpl((ClassType) value);
    }
    if (value instanceof PrimitiveValue) {
        try {
            java.lang.reflect.Method valueMethod = value.getClass().getMethod("value");
            Object result = valueMethod.invoke(value);
            PrimitiveValueImpl primitiveValue = new PrimitiveValueImpl(result);
            primitiveValue.setJDIValue((PrimitiveValue) value);
            return primitiveValue;
        } catch (Exception e) {
            return null;
        }
    }
    if (value.getClass().isArray()) {
        List<Object> values = new ArrayList<>();
        int length = Array.getLength(value);
        for (int i = 0; i< length; i++) {
            values.add(Array.get(value, i));
        }
        return new ArrayValueImpl(value.getClass().getComponentType().getCanonicalName(), null, create(values), value);
    }
    return new PrimitiveValueImpl(value);
}
项目:tools-idea    文件:ArrayItemData.java   
public ArrayItemData(@NotNull ArrayReference arrRef, int idx) {
  LOG.assertTrue(0 <= idx);
  if(LOG.isDebugEnabled()) {
    LOG.assertTrue(idx <= arrRef.length());
  }
  myArray = arrRef;
  myIndex = idx;
}
项目:jive    文件:JDIEventHandlerDelegate.java   
private boolean visitArrayCells(final Location location, final StackFrame frame,
    final ArrayReference arrayRef, final IContextContour array)
{
  boolean modified = false;
  // retrieve the array values
  final List<Value> values = arrayRef.length() > 0 ? arrayRef.getValues() : null;
  // check for modifications on each of the array cells
  for (int i = 0; values != null && i < values.size(); i++)
  {
    final IContourMember cell = array.lookupMember(i);
    final Value cellValue = values.get(i);
    // recursively process the array reference value
    if (cellValue instanceof ArrayReference)
    {
      if (!handleNewArray((ArrayReference) cellValue, location, frame)
          && EventFactoryAdapter.PROCESS_MULTI_ARRAY)
      {
        final ArrayReference innerArray = (ArrayReference) cellValue;
        // retrieve the array reference type
        final ArrayType at = (ArrayType) cellValue.type();
        // retrieve the array contour
        final IContextContour innerContour = contourFactory().lookupInstanceContour(at.name(),
            innerArray.uniqueID());
        visitArrayCells(location, frame, innerArray, innerContour);
      }
    }
    // true if the variable was newly observed or its value changed
    if (executionState().observedVariable(cell, cellValue, frame.thread(), location.lineNumber()))
    {
      // dispatch the assignment to the modified cell
      dispatcher().dispatchArrayCellWriteEvent(location, frame.thread(), array, cell, cellValue,
          ((ArrayType) arrayRef.type()).componentTypeName());
      modified = true;
    }
  }
  return modified;
}
项目:jive    文件:JDIEventHandlerDelegate.java   
/**
 * Field reads/writes are registered only for non-filtered classes.
 */
void handleFieldWrite(final ModificationWatchpointEvent event)
    throws IncompatibleThreadStateException, AbsentInformationException
{
  final StackFrame frame = determineStackFrame(event);
  handleNewObject(frame, event.thread());
  // dispatch a new object for the array value, if appropriate
  if (manager().generateArrayEvents() && event.valueToBe() instanceof ArrayReference)
  {
    // dispatch a new array event and the respective cell assignments
    handleNewArray((ArrayReference) event.valueToBe(), event.location(), frame);
  }
  dispatcher().dispatchFieldWriteEvent(event);
}