Ejemplo n.º 1
0
        internal ClassObjectReference GetMirrorOf(ClassObjectId classObject)
        {
            if (classObject == default(ClassObjectId))
            {
                return(null);
            }

            return(new ClassObjectReference(this, classObject));
        }
Ejemplo n.º 2
0
        public Error GetClassObject(out ClassObjectId classObject, ReferenceTypeId referenceType)
        {
            byte[] packet = new byte[HeaderSize + ReferenceTypeIdSize];
            int id = GetMessageId();
            SerializeHeader(packet, id, ReferenceTypeCommand.ClassObject);
            WriteReferenceTypeId(packet, HeaderSize, referenceType);

            byte[] response = SendPacket(id, packet);
            Error errorCode = ReadErrorCode(response);
            if (errorCode != Error.None)
            {
                classObject = default(ClassObjectId);
                return errorCode;
            }

            int offset = HeaderSize;
            classObject = (ClassObjectId)ReadObjectId(response, ref offset);
            return Error.None;
        }
Ejemplo n.º 3
0
 internal ClassObjectReference(VirtualMachine virtualMachine, ClassObjectId objectId)
     : base(virtualMachine, objectId, null)
 {
     Contract.Requires(virtualMachine != null);
 }
Ejemplo n.º 4
0
        public Error GetReflectedType(out TypeTag typeTag, out ReferenceTypeId typeId, ClassObjectId classObject)
        {
            byte[] packet = new byte[HeaderSize + ObjectIdSize];
            int id = GetMessageId();
            SerializeHeader(packet, id, ClassObjectReferenceCommand.ReflectedType);
            WriteObjectId(packet, HeaderSize, classObject);

            byte[] response = SendPacket(id, packet);
            Error errorCode = ReadErrorCode(response);
            if (errorCode != Error.None)
            {
                typeTag = default(TypeTag);
                typeId = default(ReferenceTypeId);
                return errorCode;
            }

            int offset = HeaderSize;
            typeTag = (TypeTag)ReadByte(response, ref offset);
            typeId = ReadReferenceTypeId(response, ref offset);
            return Error.None;
        }
Ejemplo n.º 5
0
 public Error GetClassObject(ReferenceTypeId referenceType, out ClassObjectId classObject)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 6
0
        public Error GetReflectedType(ClassObjectId classObjectId, out TypeTag typeTag, out ReferenceTypeId typeId)
        {
            typeTag = default(TypeTag);
            typeId = default(ReferenceTypeId);

            JniEnvironment nativeEnvironment;
            JvmtiEnvironment environment;
            jvmtiError error = GetEnvironment(out environment, out nativeEnvironment);
            if (error != jvmtiError.None)
                return GetStandardError(error);

            TaggedReferenceTypeId[] classes;
            error = environment.GetLoadedClasses(nativeEnvironment, out classes);
            if (error != jvmtiError.None)
                return GetStandardError(error);

            jmethodID getNameMethod = nativeEnvironment.GetMethodId(VirtualMachine.ClassClass, "getName", "()Ljava/lang/String;");

            using (var classObject = VirtualMachine.GetLocalReferenceForObject(nativeEnvironment, classObjectId))
            {
                if (!classObject.IsAlive)
                    return Error.InvalidObject;

                jobject nameObject = nativeEnvironment.CallObjectMethodA(classObject.Value, getNameMethod);
                int length = nativeEnvironment.GetStringUTFLength(nameObject);
                byte[] buffer = new byte[length + 1];
                nativeEnvironment.GetStringUTFRegion(nameObject, 0, length, buffer);
                string name = ModifiedUTF8Encoding.GetString(buffer, 0, length);
                nativeEnvironment.DeleteLocalReference(nameObject);

                string signature;

                switch (name)
                {
                case "boolean":
                case "byte":
                case "char":
                case "double":
                case "float":
                case "int":
                case "long":
                case "short":
                case "void":
                    return Error.IllegalArgument;

                default:
                    signature = name.Replace('.', '/');
                    if (name[0] != '[')
                        signature = 'L' + signature + ';';

                    break;
                }

                foreach (var loadedTypeId in classes)
                {
                    using (var loadedType = VirtualMachine.GetLocalReferenceForClass(nativeEnvironment, loadedTypeId.TypeId))
                    {
                        if (!loadedType.IsAlive)
                            continue;

                        string loadedTypeSignature;
                        string loadedTypeGenericSignature;
                        error = environment.GetClassSignature(loadedType.Value, out loadedTypeSignature, out loadedTypeGenericSignature);
                        if (error == jvmtiError.None && loadedTypeSignature == signature)
                        {
                            typeTag = loadedTypeId.TypeTag;
                            typeId = loadedTypeId.TypeId;
                            return Error.None;
                        }
                    }
                }
            }

            return Error.InvalidClass;
        }
Ejemplo n.º 7
0
        internal ClassObjectReference GetMirrorOf(ClassObjectId classObject)
        {
            if (classObject == default(ClassObjectId))
                return null;

            return new ClassObjectReference(this, classObject);
        }
Ejemplo n.º 8
0
 internal ClassObjectReference(VirtualMachine virtualMachine, ClassObjectId objectId)
     : base(virtualMachine, objectId, null)
 {
     Contract.Requires(virtualMachine != null);
 }