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

项目:incubator-netbeans    文件:RemoteServices.java   
private synchronized boolean remove(ObjectReference component, ClassObjectReference listenerClass, LoggingListenerCallBack listener) {
    Map<ClassObjectReference, Set<LoggingListenerCallBack>> listeners = componentListeners.get(component);
    if (listeners == null) {
        return false;
    }
    Set<LoggingListenerCallBack> lcb = listeners.get(listenerClass);
    if (lcb == null) {
        return false;
    }
    boolean removed = lcb.remove(listener);
    if (removed) {
        if (lcb.isEmpty()) {
            listeners.remove(listenerClass);
            if (listeners.isEmpty()) {
                componentListeners.remove(component);
            }
        }
    }
    return removed;
}
项目:incubator-netbeans    文件:VisualDebuggerListener.java   
private void stopDebuggerRemoteService(JPDADebugger d) {
    ClassObjectReference serviceClass = RemoteServices.getServiceClass(d, RemoteServices.ServiceType.AWT);
    if (serviceClass == null) {
        return ;
    }
    try {
        ReferenceType serviceType = serviceClass.reflectedType();
        Field awtAccessLoop = serviceType.fieldByName("awtAccessLoop"); // NOI18N
        if (awtAccessLoop != null) {
            ((ClassType) serviceType).setValue(awtAccessLoop, serviceClass.virtualMachine().mirrorOf(false));
        }
        serviceClass.enableCollection();
    } catch (VMDisconnectedException vdex) {
        // Ignore
    } catch (Exception ex) {
        Exceptions.printStackTrace(ex);
    }
}
项目:openjdk-jdk10    文件:ReferenceTypeImpl.java   
public ClassObjectReference classObject() {
    if (classObject == null) {
        // Are classObjects unique for an Object, or
        // created each time? Is this spec'ed?
        synchronized(this) {
            if (classObject == null) {
                try {
                    classObject = JDWP.ReferenceType.ClassObject.
                        process(vm, this).classObject;
                } catch (JDWPException exc) {
                    throw exc.toJDIException();
                }
            }
        }
    }
    return classObject;
}
项目: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);
    }
}
项目:incubator-netbeans    文件:RemoteServices.java   
private synchronized boolean add(ObjectReference component, ClassObjectReference listenerClass, LoggingListenerCallBack listener) {
    Map<ClassObjectReference, Set<LoggingListenerCallBack>> listeners = componentListeners.get(component);
    if (listeners == null) {
        listeners = new HashMap<ClassObjectReference, Set<LoggingListenerCallBack>>();
        componentListeners.put(component, listeners);
    }
    Set<LoggingListenerCallBack> lcb = listeners.get(listenerClass);
    if (lcb == null) {
        lcb = new HashSet<LoggingListenerCallBack>();
        listeners.put(listenerClass, lcb);
    }
    return lcb.add(listener);
}
项目:incubator-netbeans    文件:RemoteServices.java   
synchronized Set<LoggingListenerCallBack> getListeners(ObjectReference component, ClassObjectReference listenerClass) {
    Map<ClassObjectReference, Set<LoggingListenerCallBack>> listeners = componentListeners.get(component);
    if (listeners == null) {
        return null;
    }
    return new HashSet<>(listeners.get(listenerClass));
}
项目:incubator-netbeans    文件:RemoteServices.java   
public static boolean hasServiceAccess(JPDADebugger debugger) {
    Map<ServiceType, ClassObjectReference> cs;
    synchronized (remoteServiceClasses) {
        cs = remoteServiceClasses.get(debugger);
    }
    if (cs != null) {
        Boolean has;
        synchronized (remoteServiceAccess) {
            has = remoteServiceAccess.get(debugger);
        }
        return has != null && has.booleanValue();
    } else {
        return false;
    }
}
项目:incubator-netbeans    文件:RemoteServices.java   
public static ClassObjectReference getServiceClass(JPDADebugger debugger, ServiceType sType) {
    synchronized (remoteServiceClasses) {
        Map<ServiceType, ClassObjectReference> cs = remoteServiceClasses.get(debugger);
        if (cs == null) {
            return null;
        } else {
            return cs.get(sType);
        }
    }

}
项目:incubator-netbeans    文件:ClassVariableImpl.java   
/** Creates a new instance of ClassVariableImpl */
public ClassVariableImpl(
    JPDADebuggerImpl debugger,
    ClassObjectReference clazz,
    String parentID
) {
    super (
        debugger,
        clazz,
        parentID + ".class"
    );
    this.clazz = clazz;
}
项目: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    文件:JPDAClassTypeImpl.java   
@Override
public ClassVariable classObject() {
    ClassObjectReference co;
    try {
        co = ReferenceTypeWrapper.classObject(classType);
    } catch (InternalExceptionWrapper | ObjectCollectedExceptionWrapper |
             VMDisconnectedExceptionWrapper | UnsupportedOperationExceptionWrapper ex) {
        co = null;
    }
    return new ClassVariableImpl(debugger, co, "");
}
项目:incubator-netbeans    文件:ClassFieldVariable.java   
private ClassFieldVariable (
    JPDADebuggerImpl debugger, 
    ClassObjectReference value, 
    //String className,
    Field field,
    String parentID,
    String genericSignature,
    ObjectReference objectReference
) {
    super(debugger, value, field, parentID, genericSignature, objectReference);
}
项目:openjdk-jdk10    文件:ClassObjectReferenceImpl.java   
public ReferenceType reflectedType() {
    if (reflectedType == null) {
        try {
            JDWP.ClassObjectReference.ReflectedType reply =
                JDWP.ClassObjectReference.ReflectedType.process(vm, this);
            reflectedType = vm.referenceType(reply.typeID,
                                             reply.refTypeTag);

        } catch (JDWPException exc) {
            throw exc.toJDIException();
        }
    }
    return reflectedType;
}
项目:codehint    文件:SideEffectHandler.java   
@Override
public boolean handleEvent(Event event, JDIDebugTarget target, boolean suspendVote, EventSet eventSet) {
    try {
        //System.out.println("Reflection: " + event);
        ThreadReference thread = ((LocatableEvent)event).thread();
        StackFrame stack = thread.frame(0);
        ObjectReference fieldValue = stack.thisObject();
        ReferenceType fieldType = fieldValue.referenceType();
        //String className = ((ObjectReference)fieldValue.getValue(fieldType.fieldByName("clazz"))).invokeMethod(thread, event.virtualMachine().classesByName("java.lang.Class").get(0).methodsByName("getName").get(0), new ArrayList<Value>(0), 0).toString();  // Calling methods in the child JVM seems to crash here.
        //String className = ((StringReference)((ObjectReference)fieldValue.getValue(fieldType.fieldByName("clazz"))).getValue(event.virtualMachine().classesByName("java.lang.Class").get(0).fieldByName("name"))).value();  // This works in JDK 7 but breaks in JDK 8 (because getting fields no longer calls SecurityManager.checkMemberAccess).
        String className = ((ClassObjectReference)fieldValue.getValue(fieldType.fieldByName("clazz"))).reflectedType().name();
        String fieldName = ((StringReference)fieldValue.getValue(fieldType.fieldByName("name"))).value();
        Field field = event.virtualMachine().classesByName(className).get(0).fieldByName(fieldName);
        List<Value> argValues = stack.getArgumentValues();
        ObjectReference obj = (ObjectReference)argValues.get(0);
        if (!field.isStatic() && obj == null)
            return true;  // The execution will crash.
        Value oldValue = field.isStatic() ? field.declaringType().getValue(field) : obj.getValue(field);
        if (argValues.size() == 2) {  // We're setting the value of a field.
            Value newValue = argValues.get(1);
            if (newValue instanceof ObjectReference && EclipseUtils.isPrimitive(field.signature()))  // Unbox primitive values.
                newValue = ((ObjectReference)newValue).getValue(((ReferenceType)newValue.type()).fieldByName("value"));
            recordEffect(FieldLVal.makeFieldLVal(obj, field), oldValue, newValue);
        } else if (oldValue instanceof ArrayReference)  // We're reading the value of an array.
            backupArray(FieldLVal.makeFieldLVal(obj, field), oldValue);
    } catch (IncompatibleThreadStateException e) {
        throw new RuntimeException(e);
    }
    return true;
}
项目:incubator-netbeans    文件:EventsModel.java   
private void setListenerObject(ObjectReference listener, ClassObjectReference listenerClass) {
    this.listener = listener;
    this.listenerClass = listenerClass;
}
项目:incubator-netbeans    文件:EventsModel.java   
public ClassObjectReference getListenerClass() {
    return listenerClass;
}
项目:incubator-netbeans    文件:JPDADebuggerImpl.java   
public Variable getVariable (Value value) {
    if (value instanceof ClassObjectReference) {
        return new ClassVariableImpl(this, (ClassObjectReference) value, null);
    }
    return createVariable(value);
}
项目:incubator-netbeans    文件:VariableMirrorTranslator.java   
private static ObjectReference createObjectOfType(ClassType type, VirtualMachine vm, ThreadReference thread)
                                                  throws InvalidObjectException, InternalExceptionWrapper,
                                                         VMDisconnectedExceptionWrapper, ClassNotPreparedExceptionWrapper,
                                                         ObjectCollectedExceptionWrapper, InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException, InvocationException, UnsupportedOperationExceptionWrapper {
    com.sun.jdi.Method c = ClassTypeWrapper.concreteMethodByName(type, "<init>", "()V");
    if (c == null || !c.declaringType().equals(type)) { // No no-arg constructor
        //ReflectionFactory rf = ReflectionFactory.getReflectionFactory();
        //constructor = rf.newConstructorForSerialization(clazz, Object.class.getDeclaredConstructor());
        ClassType reflectionFactoryType = (ClassType) getOrLoadClass(vm, "sun.reflect.ReflectionFactory");
        if (reflectionFactoryType == null) {
            throw new InvalidObjectException("No constructor for "+TypeWrapper.name(type));
        }
        com.sun.jdi.Method getReflectionFactoryMethod = ClassTypeWrapper.concreteMethodByName(
                reflectionFactoryType, "getReflectionFactory", "()Lsun/reflect/ReflectionFactory;");
        if (getReflectionFactoryMethod == null) {
            throw new InvalidObjectException("Reflection Factory getter not found.");
        }
        ClassType objectClassType = (ClassType) getOrLoadClass(vm, "java.lang.Object");
        if (objectClassType == null) {
            throw new InvalidObjectException("No Object class found in the target VM.");
        }
        ClassObjectReference objectClass = ReferenceTypeWrapper.classObject(objectClassType);
        com.sun.jdi.Method getDeclaredConstructorMethod = ClassTypeWrapper.concreteMethodByName(
                ((ClassType) ObjectReferenceWrapper.referenceType(objectClass)),
                "getDeclaredConstructor", "([Ljava/lang/Class;)Ljava/lang/reflect/Constructor;");
        if (getDeclaredConstructorMethod == null) {
            throw new InvalidObjectException("getDeclaredConstructor() method not found on Object class. Can not create a new instance.");
        }
        com.sun.jdi.Method newConstructorForSerializationMethod = ClassTypeWrapper.concreteMethodByName(
                reflectionFactoryType,
                "newConstructorForSerialization",
                "(Ljava/lang/Class;Ljava/lang/reflect/Constructor;)Ljava/lang/reflect/Constructor;");
        if (newConstructorForSerializationMethod == null) {
            throw new InvalidObjectException("newConstructorForSerialization() method not found on Object class. Can not create a new instance.");
        }

        ObjectReference objectConstructor = (ObjectReference)
                ObjectReferenceWrapper.invokeMethod(objectClass, thread,
                                              getDeclaredConstructorMethod,
                                              Collections.EMPTY_LIST,
                                              ClassType.INVOKE_SINGLE_THREADED);
        ObjectReference rf = (ObjectReference)
                ClassTypeWrapper.invokeMethod(reflectionFactoryType, thread,
                                              getReflectionFactoryMethod,
                                              Collections.EMPTY_LIST,
                                              ClassType.INVOKE_SINGLE_THREADED);
        ObjectReference constructor = (ObjectReference)
                ObjectReferenceWrapper.invokeMethod(rf, thread,
                                                    newConstructorForSerializationMethod,
                                                    Arrays.asList(new Value[] {
                                                        ReferenceTypeWrapper.classObject(type),
                                                        objectConstructor }),
                                                    ClassType.INVOKE_SINGLE_THREADED);
        // Object newInstance = constructor.newInstance();
        com.sun.jdi.Method newInstanceMethod = ClassTypeWrapper.concreteMethodByName(
                ((ClassType) ObjectReferenceWrapper.referenceType(constructor)),
                "newInstance", "([Ljava/lang/Object;)Ljava/lang/Object;");
        if (newInstanceMethod == null) {
            throw new InvalidObjectException("newInstance() method not found on Constructor class. Can not create a new instance.");
        }
        ObjectReference newInstance = (ObjectReference)
                ObjectReferenceWrapper.invokeMethod(constructor, thread,
                                                    newInstanceMethod,
                                                    Collections.EMPTY_LIST,
                                                    ClassType.INVOKE_SINGLE_THREADED);
        return newInstance;
    } else {
        return ClassTypeWrapper.newInstance(type, thread, c, Collections.EMPTY_LIST, ClassType.INVOKE_SINGLE_THREADED);
    }
}
项目:incubator-netbeans    文件:EvaluatorVisitor.java   
@Override
public ClassObjectReference classObject() {
    return types[0].classObject();
}
项目:java-debug    文件:ClassObjectFormatter.java   
@Override
protected String getPrefix(ObjectReference value, Map<String, Object> options) {
    Type classType = ((ClassObjectReference) value).reflectedType();
    return String.format("%s (%s)", super.getPrefix(value, options),
            typeToStringFunction.apply(classType, options));
}
项目:openjdk9    文件:ReferenceTypeImpl.java   
public ClassObjectReference classObject() {
    return vm.classObjectMirror(ref().getJavaMirror());
}
项目:form-follows-function    文件:F3Wrapper.java   
public static F3ClassObjectReference wrap(F3VirtualMachine f3vm, ClassObjectReference ref) {
    return (ref == null)? null : f3vm.classObjectReference(ref);
}
项目:form-follows-function    文件:F3ClassObjectReference.java   
public F3ClassObjectReference(F3VirtualMachine f3vm, ClassObjectReference underlying) {
    super(f3vm, underlying);
}
项目:form-follows-function    文件:F3ClassObjectReference.java   
@Override
protected ClassObjectReference underlying() {
    return (ClassObjectReference) super.underlying();
}
项目:form-follows-function    文件:F3ReferenceType.java   
public ClassObjectReference classObject() {
    return F3Wrapper.wrap(virtualMachine(), underlying().classObject());
}
项目:form-follows-function    文件:F3VirtualMachine.java   
protected F3ClassObjectReference classObjectReference(ClassObjectReference coref) {
    return new F3ClassObjectReference(this, coref);
}