コード例 #1
0
        public jvmtiError GetClassMethods(JniEnvironment nativeEnvironment, ReferenceTypeId declaringType, out MethodId[] methods)
        {
            methods = null;

            using (var @class = VirtualMachine.GetLocalReferenceForClass(nativeEnvironment, declaringType))
            {
                if ([email protected])
                {
                    return(jvmtiError.InvalidClass);
                }

                int        methodsCount;
                IntPtr     methodsPtr;
                jvmtiError error = RawInterface.GetClassMethods(this, @class.Value, out methodsCount, out methodsPtr);
                if (error != jvmtiError.None)
                {
                    return(error);
                }

                try
                {
                    List <MethodId> methodList = new List <MethodId>();
                    unsafe
                    {
                        jmethodID *methodHandles = (jmethodID *)methodsPtr;
                        for (int i = 0; i < methodsCount; i++)
                        {
                            if (methodHandles[i] == jmethodID.Null)
                            {
                                continue;
                            }

                            methodList.Add(new MethodId(methodHandles[i].Handle));
                        }
                    }

                    methods = methodList.ToArray();
                    return(jvmtiError.None);
                }
                finally
                {
                    Deallocate(methodsPtr);
                }
            }
        }
コード例 #2
0
        public jvmtiError GetClassMethods(JvmVirtualMachineRemoteHandle virtualMachine, JvmClassRemoteHandle @class, out JvmMethodRemoteHandle[] methods)
        {
            JavaVM machine = JavaVM.GetInstance(virtualMachine);

            List <JvmMethodRemoteHandle> methodsList = new List <JvmMethodRemoteHandle>();
            jvmtiError result = jvmtiError.Internal;

            machine.InvokeOnJvmThread(
                (environment) =>
            {
                jvmtiInterface rawInterface = environment.RawInterface;

                IntPtr methodsPtr = IntPtr.Zero;
                try
                {
                    int methodCount;
                    result = rawInterface.GetClassMethods(environment.Handle, @class, out methodCount, out methodsPtr);

                    unsafe
                    {
                        jmethodID *rawMethods = (jmethodID *)methodsPtr;
                        for (int i = 0; i < methodCount; i++)
                        {
                            methodsList.Add(new JvmMethodRemoteHandle(rawMethods[i]));
                        }
                    }
                }
                finally
                {
                    rawInterface.Deallocate(environment.Handle, methodsPtr);
                }
            });

            methods = methodsList.ToArray();
            return(result);
        }