public Error GetFields(ReferenceTypeId referenceType, out DeclaredFieldData[] fields)
        {
            fields = null;

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

            FieldId[] fieldIds;
            error = environment.GetClassFields(nativeEnvironment, referenceType, out fieldIds);
            if (error != jvmtiError.None)
                return GetStandardError(error);

            using (var classHandle = VirtualMachine.GetLocalReferenceForClass(nativeEnvironment, referenceType))
            {
                if (!classHandle.IsAlive)
                    return Error.InvalidClass;

                List<DeclaredFieldData> fieldsList = new List<DeclaredFieldData>();
                foreach (var fieldId in fieldIds)
                {
                    string name;
                    string signature;
                    string genericSignature;
                    error = environment.GetFieldName(classHandle.Value, fieldId, out name, out signature, out genericSignature);
                    if (error != jvmtiError.None)
                        return GetStandardError(error);

                    JvmAccessModifiers modifiers;
                    error = environment.GetFieldModifiers(classHandle.Value, fieldId, out modifiers);

                    fieldsList.Add(new DeclaredFieldData(fieldId, name, signature, genericSignature, (AccessModifiers)modifiers));
                }

                fields = fieldsList.ToArray();
                return Error.None;
            }
        }
        public Error GetFields(out DeclaredFieldData[] fields, ReferenceTypeId referenceType)
        {
            byte[] packet = new byte[HeaderSize + ReferenceTypeIdSize];
            int id = GetMessageId();
            SerializeHeader(packet, id, ReferenceTypeCommand.FieldsWithGeneric);
            WriteReferenceTypeId(packet, HeaderSize, referenceType);

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

            int offset = HeaderSize;
            int fieldCount = ReadInt32(response, ref offset);
            fields = new DeclaredFieldData[fieldCount];
            for (int i = 0; i < fieldCount; i++)
            {
                FieldId fieldId = ReadFieldId(response, ref offset);
                string name = ReadString(response, ref offset);
                string signature = ReadString(response, ref offset);
                string genericSignature = ReadString(response, ref offset);
                AccessModifiers modifiers = (AccessModifiers)ReadInt32(response, ref offset);
                fields[i] = new DeclaredFieldData(fieldId, name, signature, genericSignature, modifiers);
            }

            return Error.None;
        }
Exemple #3
0
        internal Field GetMirrorOf(ReferenceType declaringType, DeclaredFieldData fieldData)
        {
            lock (_fields)
            {
                List<Field> fields;
                if (!_fields.TryGetValue(declaringType.ReferenceTypeId, out fields))
                {
                    fields = new List<Field>();
                    _fields[declaringType.ReferenceTypeId] = fields;
                }

                Field field = fields.SingleOrDefault(i => i.FieldId == fieldData.FieldId);
                if (field == null)
                {
                    field = new Field(this, declaringType, fieldData.Name, fieldData.Signature, fieldData.GenericSignature, (AccessModifiers)fieldData.Modifiers, fieldData.FieldId);
                    fields.Add(field);
                }

                return field;
            }
        }