コード例 #1
0
        public bool IsInstanceOf(jobject @object, jclass @class)
        {
            byte result = RawInterface.IsInstanceOf(this, @object, @class);

            HandleException();
            return(result != 0);
        }
        public LocalClassReferenceHolder(JniEnvironment nativeEnvironment, jclass reference)
        {
            Contract.Requires <ArgumentNullException>(nativeEnvironment != null, "nativeEnvironment");

            _nativeEnvironment = nativeEnvironment;
            _reference         = (jclass)_nativeEnvironment.NewLocalReference(reference);
        }
コード例 #3
0
        public jclass GetObjectClass(jobject @object)
        {
            jclass result = RawInterface.GetObjectClass(this, @object);

            HandleException();
            return(result);
        }
コード例 #4
0
        public jclass GetSuperclass(jclass @class)
        {
            jclass result = RawInterface.GetSuperclass(this, @class);

            HandleException();
            return(result);
        }
コード例 #5
0
        public jvmtiError GetConstantPool(jclass classHandle, out ConstantPoolEntry[] entries)
        {
            entries = null;

            int        constantPoolCount;
            int        constantPoolByteCount;
            IntPtr     constantPoolBytesPtr;
            jvmtiError error = RawInterface.GetConstantPool(this, classHandle, out constantPoolCount, out constantPoolByteCount, out constantPoolBytesPtr);

            if (error != jvmtiError.None)
            {
                return(error);
            }

            try
            {
                List <ConstantPoolEntry> entryList = new List <ConstantPoolEntry>();
                IntPtr currentPosition             = constantPoolBytesPtr;
                for (int i = 0; i < constantPoolCount; i++)
                {
                    entryList.Add(ConstantPoolEntry.FromMemory(ref currentPosition));
                }

                entries = entryList.ToArray();
                return(jvmtiError.None);
            }
            finally
            {
                Deallocate(constantPoolBytesPtr);
            }
        }
コード例 #6
0
        public jclass FindClass(string name)
        {
            jclass result = RawInterface.FindClass(this, name);

            HandleException();
            return(result);
        }
コード例 #7
0
        internal jobject CallNonvirtualObjectMethodA(jobject instanceHandle, jclass classHandle, jmethodID methodId, params jvalue[] args)
        {
            var result = RawInterface.CallNonvirtualObjectMethodA(this, instanceHandle, classHandle, methodId, args);

            HandleException();
            return(result);
        }
コード例 #8
0
        public jclass DefineClass(string name, jobject loader, byte[] data)
        {
            jclass result = RawInterface.DefineClass(this, name, loader, data, data.Length);

            HandleException();
            return(result);
        }
コード例 #9
0
        internal bool CallStaticBooleanMethodA(jclass classHandle, jmethodID methodId, params jvalue[] args)
        {
            var result = RawInterface.CallStaticBooleanMethodA(this, classHandle, methodId, args) != 0;

            HandleException();
            return(result);
        }
コード例 #10
0
        internal jobject CallStaticObjectMethodA(jclass classHandle, jmethodID methodId, params jvalue[] args)
        {
            var result = RawInterface.CallStaticObjectMethodA(this, classHandle, methodId, args);

            HandleException();
            return(result);
        }
コード例 #11
0
        internal jobject GetStaticObjectField(jclass classHandle, jfieldID fieldId)
        {
            var result = RawInterface.GetStaticObjectField(this, classHandle, fieldId);

            HandleException();
            return(result);
        }
コード例 #12
0
        internal double GetStaticDoubleField(jclass classHandle, jfieldID fieldId)
        {
            var result = RawInterface.GetStaticDoubleField(this, classHandle, fieldId);

            HandleException();
            return(result);
        }
コード例 #13
0
        internal bool GetStaticBooleanField(jclass classHandle, jfieldID fieldId)
        {
            bool result = RawInterface.GetStaticBooleanField(this, classHandle, fieldId) != 0;

            HandleException();
            return(result);
        }
コード例 #14
0
        public jmethodID GetMethodId(jclass @class, string name, string signature)
        {
            jmethodID result = RawInterface.GetMethodID(this, @class, name, signature);

            HandleException();
            return(result);
        }
コード例 #15
0
        internal jobject NewObjectArray(int length, jclass elementType, jobject initialElement)
        {
            var result = RawInterface.NewObjectArray(this, length, elementType, initialElement);

            HandleException();
            return(result);
        }
コード例 #16
0
        public jvmtiError GetClassSignature(jclass classHandle, out string signature, out string genericSignature)
        {
            signature        = null;
            genericSignature = null;

            IntPtr signaturePtr;
            IntPtr genericPtr;

            RawInterface.GetClassSignature(this, classHandle, out signaturePtr, out genericPtr);

            try
            {
                unsafe
                {
                    if (signaturePtr != IntPtr.Zero)
                    {
                        signature = ModifiedUTF8Encoding.GetString((byte *)signaturePtr);
                    }
                    if (genericPtr != IntPtr.Zero)
                    {
                        genericSignature = ModifiedUTF8Encoding.GetString((byte *)genericPtr);
                    }
                }

                return(jvmtiError.None);
            }
            finally
            {
                Deallocate(signaturePtr);
                Deallocate(genericPtr);
            }
        }
コード例 #17
0
        public jobject NewObject(jclass @class, jmethodID ctorMethodId, params jvalue[] args)
        {
            jobject result = RawInterface.NewObjectA(this, @class, ctorMethodId, args);

            HandleException();
            return(result);
        }
コード例 #18
0
        public jvmtiError IsArrayClass(jclass classHandle, out bool result)
        {
            byte       arrayClass;
            jvmtiError error = RawInterface.IsArrayClass(this, classHandle, out arrayClass);

            result = arrayClass != 0;
            return(error);
        }
コード例 #19
0
        public jvmtiError IsInterface(jclass classHandle, out bool result)
        {
            byte       isInterface;
            jvmtiError error = RawInterface.IsInterface(this, classHandle, out isInterface);

            result = isInterface != 0;
            return(error);
        }
コード例 #20
0
ファイル: JavaVM.cs プロジェクト: weizhengwei/LangSvcV2
        internal jvmtiError GetClass(ReferenceTypeId classId, out jclass @class)
        {
            lock (_classes)
            {
                if (!_classes.TryGetValue(classId, out @class))
                {
                    return(jvmtiError.InvalidClass);
                }

                return(jvmtiError.None);
            }
        }
コード例 #21
0
ファイル: JavaVM.cs プロジェクト: weizhengwei/LangSvcV2
        internal TaggedReferenceTypeId TrackLocalClassReference(jclass classHandle, JvmtiEnvironment environment, JniEnvironment nativeEnvironment, bool freeLocalReference)
        {
            if (classHandle == jclass.Null)
            {
                return(default(TaggedReferenceTypeId));
            }

            bool isArrayClass;

            JvmtiErrorHandler.ThrowOnFailure(environment.IsArrayClass(classHandle, out isArrayClass));
            bool isInterface;

            JvmtiErrorHandler.ThrowOnFailure(environment.IsInterface(classHandle, out isInterface));

            TypeTag typeTag = isArrayClass ? TypeTag.Array : (isInterface ? TypeTag.Interface : TypeTag.Class);

            int hashCode;

            JvmtiErrorHandler.ThrowOnFailure(environment.GetObjectHashCode(classHandle, out hashCode));

            ReferenceTypeId       typeId       = new ReferenceTypeId(hashCode);
            TaggedReferenceTypeId taggedTypeId = new TaggedReferenceTypeId(typeTag, typeId);

            lock (_classes)
            {
                if (!_classes.ContainsKey(typeId))
                {
                    jweak weak  = nativeEnvironment.NewWeakGlobalReference(classHandle);
                    bool  added = false;
                    if (!_classes.ContainsKey(typeId))
                    {
                        _classes.Add(typeId, new jclass(weak.Handle));
                        added = true;
                    }

                    if (!added)
                    {
                        nativeEnvironment.DeleteWeakGlobalReference(weak);
                    }
                }
            }

            if (freeLocalReference)
            {
                nativeEnvironment.DeleteLocalReference(classHandle);
            }

            return(taggedTypeId);
        }
コード例 #22
0
        public jvmtiError GetFieldDeclaringClass(JniEnvironment nativeEnvironment, jclass classHandle, FieldId fieldId, out TaggedReferenceTypeId declaringClass)
        {
            declaringClass = default(TaggedReferenceTypeId);

            jclass     declaringClassHandle;
            jvmtiError error = RawInterface.GetFieldDeclaringClass(this, classHandle, fieldId, out declaringClassHandle);

            if (error != jvmtiError.None)
            {
                return(error);
            }

            declaringClass = VirtualMachine.TrackLocalClassReference(declaringClassHandle, this, nativeEnvironment, true);
            return(jvmtiError.None);
        }
コード例 #23
0
        public jvmtiError GetFieldName(jclass classHandle, FieldId fieldId, out string name, out string signature, out string genericSignature)
        {
            name             = null;
            signature        = null;
            genericSignature = null;

            IntPtr     namePtr;
            IntPtr     signaturePtr;
            IntPtr     genericPtr;
            jvmtiError error = RawInterface.GetFieldName(this, classHandle, fieldId, out namePtr, out signaturePtr, out genericPtr);

            if (error != jvmtiError.None)
            {
                return(error);
            }

            try
            {
                unsafe
                {
                    if (namePtr != IntPtr.Zero)
                    {
                        name = ModifiedUTF8Encoding.GetString((byte *)namePtr);
                    }
                    if (signaturePtr != IntPtr.Zero)
                    {
                        signature = ModifiedUTF8Encoding.GetString((byte *)signaturePtr);
                    }
                    if (genericPtr != IntPtr.Zero)
                    {
                        genericSignature = ModifiedUTF8Encoding.GetString((byte *)genericPtr);
                    }
                }
            }
            finally
            {
                Deallocate(namePtr);
                Deallocate(signaturePtr);
                Deallocate(genericPtr);
            }

            return(jvmtiError.None);
        }
コード例 #24
0
        public jvmtiError GetImplementedInterfaces(JniEnvironment nativeEnvironment, jclass classHandle, out TaggedReferenceTypeId[] interfaces)
        {
            interfaces = null;

            int        interfacesCount;
            IntPtr     interfacesPtr;
            jvmtiError error = RawInterface.GetImplementedInterfaces(this, classHandle, out interfacesCount, out interfacesPtr);

            if (error != jvmtiError.None)
            {
                return(error);
            }

            try
            {
                List <TaggedReferenceTypeId> interfaceList = new List <TaggedReferenceTypeId>();
                unsafe
                {
                    jclass *interfaceHandles = (jclass *)interfacesPtr;
                    for (int i = 0; i < interfacesCount; i++)
                    {
                        if (interfaceHandles[i] == jclass.Null)
                        {
                            continue;
                        }

                        interfaceList.Add(VirtualMachine.TrackLocalClassReference(interfaceHandles[i], this, nativeEnvironment, true));
                    }
                }

                interfaces = interfaceList.ToArray();
                return(jvmtiError.None);
            }
            finally
            {
                Deallocate(interfacesPtr);
            }
        }
コード例 #25
0
ファイル: JavaVM.cs プロジェクト: weizhengwei/LangSvcV2
        internal jclass FindBaseClass(JvmtiEnvironment environment, JniEnvironment nativeEnvironment, jclass classHandle, string signature)
        {
            string currentSignature;
            string genericSignature;

            JvmtiErrorHandler.ThrowOnFailure(environment.GetClassSignature(classHandle, out currentSignature, out genericSignature));
            if (currentSignature == signature)
            {
                return((jclass)nativeEnvironment.NewGlobalReference(classHandle));
            }

            jclass superClass = nativeEnvironment.GetSuperclass(classHandle);

            if (superClass == jclass.Null)
            {
                return(jclass.Null);
            }

            jclass result = FindBaseClass(environment, nativeEnvironment, superClass, signature);

            nativeEnvironment.DeleteLocalReference(superClass);
            return(result);
        }
コード例 #26
0
        public jvmtiError GetSourceDebugExtension(jclass classHandle, out string extension)
        {
            extension = null;

            IntPtr     sourceDebugExtensionPtr;
            jvmtiError error = RawInterface.GetSourceDebugExtension(this, classHandle, out sourceDebugExtensionPtr);

            if (error != jvmtiError.None)
            {
                return(error);
            }

            if (sourceDebugExtensionPtr != IntPtr.Zero)
            {
                unsafe
                {
                    extension = ModifiedUTF8Encoding.GetString((byte *)sourceDebugExtensionPtr);
                    Deallocate(sourceDebugExtensionPtr);
                }
            }

            return(jvmtiError.None);
        }
コード例 #27
0
ファイル: JavaVM.cs プロジェクト: weizhengwei/LangSvcV2
        internal void HandleVMInit(JvmtiEnvironment environment, JniEnvironment nativeEnvironment, jthread thread)
        {
            jclass threadClass = nativeEnvironment.GetObjectClass(thread);

            _threadClass = FindBaseClass(environment, nativeEnvironment, threadClass, "Ljava/lang/Thread;");

            {
                jclass classClass = nativeEnvironment.GetObjectClass(threadClass);
                _classClass = FindBaseClass(environment, nativeEnvironment, classClass, "Ljava/lang/Class;");
                nativeEnvironment.DeleteLocalReference(classClass);
            }

            {
                jvmtiThreadInfo threadInfo;
                JvmtiErrorHandler.ThrowOnFailure(environment.GetThreadInfo(thread, out threadInfo));
                jclass threadGroupClass = nativeEnvironment.GetObjectClass(threadInfo._threadGroup);
                _threadGroupClass = FindBaseClass(environment, nativeEnvironment, threadGroupClass, "Ljava/lang/ThreadGroup;");

                jclass classLoaderClass = nativeEnvironment.GetObjectClass(threadInfo._contextClassLoader);
                _classLoaderClass = FindBaseClass(environment, nativeEnvironment, classLoaderClass, "Ljava/lang/ClassLoader;");
                nativeEnvironment.DeleteLocalReference(classLoaderClass);

                nativeEnvironment.DeleteLocalReference(threadGroupClass);
                nativeEnvironment.DeleteLocalReference(threadInfo._contextClassLoader);
                nativeEnvironment.DeleteLocalReference(threadInfo._threadGroup);
                environment.Deallocate(threadInfo._name);
            }

            nativeEnvironment.DeleteLocalReference(threadClass);

            jobject stringObject = nativeEnvironment.NewString(string.Empty);
            jclass  stringClass  = nativeEnvironment.GetObjectClass(stringObject);

            _stringClass = FindBaseClass(environment, nativeEnvironment, stringClass, "Ljava/lang/String;");
            nativeEnvironment.DeleteLocalReference(stringObject);
            nativeEnvironment.DeleteLocalReference(stringClass);
        }
コード例 #28
0
        public jvmtiError GetConstantPool(jclass classHandle, out int constantPoolCount, out byte[] data)
        {
            data = null;

            int        constantPoolByteCount;
            IntPtr     constantPoolBytesPtr;
            jvmtiError error = RawInterface.GetConstantPool(this, classHandle, out constantPoolCount, out constantPoolByteCount, out constantPoolBytesPtr);

            if (error != jvmtiError.None)
            {
                return(error);
            }

            try
            {
                data = new byte[constantPoolByteCount];
                Marshal.Copy(constantPoolBytesPtr, data, 0, constantPoolByteCount);
                return(jvmtiError.None);
            }
            finally
            {
                Deallocate(constantPoolBytesPtr);
            }
        }
コード例 #29
0
 public jvmtiError GetFieldModifiers(jclass classHandle, FieldId fieldId, out JvmAccessModifiers modifiers)
 {
     return(RawInterface.GetFieldModifiers(this, classHandle, fieldId, out modifiers));
 }
コード例 #30
0
 public jvmtiError GetClassLoader(jclass @class, out jobject classLoader)
 {
     return(RawInterface.GetClassLoader(this, @class, out classLoader));
 }