コード例 #1
0
        private static jthread alloc_thread(JNIEnvHandle jniEnv)
        {
            jniNativeInterface nativeInterface = (jniNativeInterface)Marshal.PtrToStructure(Marshal.ReadIntPtr(jniEnv.Handle), typeof(jniNativeInterface));

            jclass @class = nativeInterface.FindClass(jniEnv, "java/lang/Thread");

            if (@class == jclass.Null)
            {
                throw new Exception("ERROR: JNI: Cannot find %s with FindClass.");
            }

            nativeInterface.ExceptionClear(jniEnv);

            jmethodID method = nativeInterface.GetMethodID(jniEnv, @class, "<init>", "()V");

            if (method == jmethodID.Null)
            {
                throw new Exception("Cannot find Thread constructor method.");
            }

            nativeInterface.ExceptionClear(jniEnv);
            jthread result = (jthread)nativeInterface.NewObject(jniEnv, @class, method);

            if (result == jthread.Null)
            {
                throw new Exception("Cannot create new Thread object");
            }

            nativeInterface.ExceptionClear(jniEnv);
            return(result);
        }
コード例 #2
0
 public JNIResult CallVoidMethodA(jobject* obj, jmethodID* methodID, params jvalue[] args)
 {
     if (callVoidMethodA == null)
     {
         Util.GetDelegateForFunctionPointer(functions.CallVoidMethodA, ref callVoidMethodA);
     }
     return callVoidMethodA(real, obj, methodID, args);
 }
コード例 #3
0
        private void HandleCompiledMethodUnload(jvmtiEnvHandle env, jmethodID methodId, IntPtr codeAddress)
        {
            JvmEnvironment environment = JvmEnvironment.GetEnvironment(env);
            JvmMethod      method      = new JvmMethod(environment, methodId);

            foreach (var processor in _processors)
            {
                processor.HandleCompiledMethodUnload(environment, method, codeAddress);
            }
        }
コード例 #4
0
        private void HandleCompiledMethodLoad(jvmtiEnvHandle env, jmethodID method, int codeSize, IntPtr codeAddress, int mapLength, jvmtiAddressLocationMap[] map, IntPtr compileInfo)
        {
            JvmEnvironment environment = JvmEnvironment.GetEnvironment(env);

            foreach (var processor in _processors)
            {
                throw new NotImplementedException();
                //processor.HandleCompiledMethodLoad(environment, method, codeSize, codeAddress, map2, compileInfo);
            }
        }
コード例 #5
0
        static PrintStream()
        {
            var setup = JNetHost.Run(runtime =>
            {
                var clz_PrintStream = runtime.FindClass("java/io/PrintStream");
                var mid_println_A   = runtime.GetMethodID(clz_PrintStream, "println", "(Ljava/lang/String;)V");

                clz_PrintStream = (jclass)runtime.NewGlobalRef(clz_PrintStream);

                return(clz_PrintStream, mid_println_A);
            });

            clz_PrintStream = setup.clz_PrintStream;
            mid_println_A   = setup.mid_println_A;
        }
コード例 #6
0
        static System()
        {
            var setup = JNetHost.Run(runtime => {
                var clz_System      = runtime.FindClass("java/lang/System");
                var fid_out         = runtime.GetStaticFieldID(clz_System, "out", "Ljava/io/PrintStream;");
                var mid_getProperty = runtime.GetStaticMethodID(clz_System, "getProperty", "(Ljava/lang/String;)Ljava/lang/String;");

                clz_System = (jclass)runtime.NewGlobalRef(clz_System);

                return(clz_System, fid_out, mid_getProperty);
            });

            clz_System      = setup.clz_System;
            fid_out         = setup.fid_out;
            mid_getProperty = setup.mid_getProperty;
        }
            public override bool ProcessEvent(JvmtiEnvironment environment, JniEnvironment nativeEnvironment, EventProcessor processor, ThreadId thread, TaggedReferenceTypeId @class, Location?location)
            {
                if (!base.ProcessEvent(environment, nativeEnvironment, processor, thread, @class, location))
                {
                    return(false);
                }

                // Step Out is implemented with Frame Pop events set at the correct depth
                if (_depth == StepDepth.Out)
                {
                    if (location.HasValue && !location.Value.Method.Equals(_lastMethod))
                    {
                        _lastLocation = new jlocation((long)location.Value.Index);
                        _lastMethod   = location.Value.Method;
                        UpdateLastLine(environment);
                    }

                    return(true);
                }

                using (var threadHandle = environment.VirtualMachine.GetLocalReferenceForThread(nativeEnvironment, thread))
                {
                    int stackDepth;
                    JvmtiErrorHandler.ThrowOnFailure(environment.GetFrameCount(threadHandle.Value, out stackDepth));

                    if (_hasMethodInfo && stackDepth > _stackDepth)
                    {
                        bool convertToFramePop;
                        if (location.HasValue && (!_convertedToFramePop || !_framePopMethod.Equals(location.Value.Method)) && ShouldSkipCurrentMethod(processor.VirtualMachine, environment, nativeEnvironment, threadHandle.Value, stackDepth, location.Value, out convertToFramePop))
                        {
                            if (convertToFramePop)
                            {
                                // remove the single step event
                                JvmtiErrorHandler.ThrowOnFailure((jvmtiError)processor.ClearEventInternal(EventKind.FramePop, this.RequestId));
                                JvmtiErrorHandler.ThrowOnFailure((jvmtiError)processor.ClearEventInternal(EventKind.SingleStep, this.RequestId));
                                // set an actual step filter to respond when the thread arrives back in this frame
                                JvmtiErrorHandler.ThrowOnFailure((jvmtiError)processor.SetEventInternal(environment, nativeEnvironment, EventKind.FramePop, this));
                                _convertedToFramePop = true;
                                _framePopMethod      = location.Value.Method;
                            }

                            return(false);
                        }
                        else
                        {
                            _convertedToFramePop = false;
                            return(true);
                        }
                    }
                    else if (stackDepth == _stackDepth)
                    {
                        if (_size == StepSize.Statement && _disassembledMethod != null)
                        {
                            int instructionIndex = _disassembledMethod.Instructions.FindIndex(i => (uint)i.Offset == location.Value.Index);
                            if (instructionIndex >= 0 && _evaluationStackDepths != null && (_evaluationStackDepths[instructionIndex] ?? 0) != 0)
                            {
                                return(false);
                            }
                            else if (instructionIndex >= 0 && _disassembledMethod.Instructions[instructionIndex].OpCode.FlowControl == JavaFlowControl.Branch)
                            {
                                // follow branch instructions before stopping
                                return(false);
                            }
                        }
                        else if (_lastLine != null)
                        {
                            // see if we're on the same line
                            LineNumberData[] lines;
                            jvmtiError       error = environment.GetLineNumberTable(location.Value.Method, out lines);
                            if (error == jvmtiError.None)
                            {
                                LineNumberData entry = lines.LastOrDefault(i => i.LineCodeIndex <= (long)location.Value.Index);
                                if (entry.LineNumber == _lastLine)
                                {
                                    return(false);
                                }
                            }
                        }
                    }

                    if (location.HasValue)
                    {
                        _lastLocation = new jlocation((long)location.Value.Index);
                        _lastMethod   = location.Value.Method;
                        UpdateLastLine(environment);
                    }

                    _stackDepth = stackDepth;
                    return(true);
                }
            }
コード例 #8
0
 internal JvmMethodRemoteHandle(jmethodID method)
 {
     Handle = method.Handle.ToInt64();
 }
コード例 #9
0
        private void HandleFieldModification(jvmtiEnvHandle env, JNIEnvHandle jniEnv, jthread threadHandle, jmethodID method, jlocation jlocation, jclass fieldClassHandle, jobject @objectHandle, jfieldID fieldId, byte signatureType, jvalue newValue)
        {
            JvmEnvironment     environment = JvmEnvironment.GetEnvironment(env);
            JvmThreadReference thread      = JvmThreadReference.FromHandle(environment, jniEnv, threadHandle, true);
            JvmLocation        location    = new JvmLocation(environment, method, jlocation);
            JvmClassReference  fieldClass  = JvmClassReference.FromHandle(environment, jniEnv, fieldClassHandle, true);
            JvmObjectReference @object     = JvmObjectReference.FromHandle(environment, jniEnv, objectHandle, true);
            JvmField           field       = new JvmField(environment, fieldId);

            foreach (var processor in _processors)
            {
                processor.HandleFieldModification(environment, thread, location, fieldClass, @object, field, signatureType, newValue);
            }
        }
コード例 #10
0
            private void HandleSingleStep(jvmtiEnvHandle env, JNIEnvHandle jniEnv, jthread threadHandle, jmethodID methodId, jlocation jlocation)
            {
                JvmtiEnvironment environment = JvmtiEnvironment.GetOrCreateInstance(_service.VirtualMachine, env);
                JniEnvironment nativeEnvironment = JniEnvironment.GetOrCreateInstance(jniEnv);

                ThreadId threadId = VirtualMachine.TrackLocalThreadReference(threadHandle, environment, nativeEnvironment, false);

                TaggedReferenceTypeId declaringClass;
                MethodId method = new MethodId(methodId.Handle);
                ulong index = (ulong)jlocation.Value;
                JvmtiErrorHandler.ThrowOnFailure(environment.GetMethodDeclaringClass(nativeEnvironment, method, out declaringClass));
                Location location = new Location(declaringClass, method, index);

                EventFilter[] filters = GetEventFilters(EventKind.SingleStep);
                foreach (var filter in filters)
                {
                    if (filter.ProcessEvent(environment, nativeEnvironment, this, threadId, default(TaggedReferenceTypeId), location))
                    {
                        SendSingleStepEvent(environment, filter, threadId, location);
                    }
                }
            }
コード例 #11
0
        private void HandleExceptionCatch(jvmtiEnvHandle env, JNIEnvHandle jniEnv, jthread threadHandle, jmethodID method, jlocation jlocation, jobject exceptionHandle)
        {
            JvmEnvironment     environment = JvmEnvironment.GetEnvironment(env);
            JvmThreadReference thread      = JvmThreadReference.FromHandle(environment, jniEnv, threadHandle, true);
            JvmLocation        location    = new JvmLocation(environment, method, jlocation);
            JvmObjectReference exception   = JvmObjectReference.FromHandle(environment, jniEnv, exceptionHandle, true);

            foreach (var processor in _processors)
            {
                processor.HandleExceptionCatch(environment, thread, location, exception);
            }
        }
コード例 #12
0
ファイル: JvmMethod.cs プロジェクト: weizhengwei/LangSvcV2
 internal JvmMethod(JvmEnvironment environment, jmethodID methodId)
 {
     _environment = environment;
     _methodId    = methodId;
 }
コード例 #13
0
        private void HandleMethodExit(jvmtiEnvHandle env, JNIEnvHandle jniEnv, jthread threadHandle, jmethodID methodId, bool wasPoppedByException, jvalue returnValue)
        {
            JvmEnvironment     environment = JvmEnvironment.GetEnvironment(env);
            JvmThreadReference thread      = JvmThreadReference.FromHandle(environment, jniEnv, threadHandle, true);
            JvmMethod          method      = new JvmMethod(environment, methodId);

            foreach (var processor in _processors)
            {
                processor.HandleMethodExit(environment, thread, method, wasPoppedByException, returnValue);
            }
        }
コード例 #14
0
            private void HandleBreakpoint(jvmtiEnvHandle env, JNIEnvHandle jniEnv, jthread threadHandle, jmethodID methodId, jlocation jlocation)
            {
                if (!VirtualMachine.IsAgentThread.Value)
                {
                    // ignore events before VMInit
                    if (AgentEventDispatcher == null)
                        return;

                    // dispatch this call to an agent thread
                    Action<jvmtiEnvHandle, JNIEnvHandle, jthread, jmethodID, jlocation> invokeMethod = HandleBreakpoint;
                    AgentEventDispatcher.Invoke(invokeMethod, env, jniEnv, threadHandle, methodId, jlocation);
                    return;
                }

                JvmtiEnvironment environment = JvmtiEnvironment.GetOrCreateInstance(_service.VirtualMachine, env);
                JniEnvironment nativeEnvironment;
                JniErrorHandler.ThrowOnFailure(VirtualMachine.AttachCurrentThreadAsDaemon(environment, out nativeEnvironment, false));

                ThreadId threadId = VirtualMachine.TrackLocalThreadReference(threadHandle, environment, nativeEnvironment, false);

                TaggedReferenceTypeId declaringClass;
                MethodId method = new MethodId(methodId.Handle);
                ulong index = (ulong)jlocation.Value;
                JvmtiErrorHandler.ThrowOnFailure(environment.GetMethodDeclaringClass(nativeEnvironment, method, out declaringClass));
                Location location = new Location(declaringClass, method, index);

                EventFilter[] filters = GetEventFilters(EventKind.Breakpoint);
                foreach (var filter in filters)
                {
                    if (filter.ProcessEvent(environment, nativeEnvironment, this, threadId, default(TaggedReferenceTypeId), location))
                    {
                        ApplySuspendPolicy(environment, nativeEnvironment, filter.SuspendPolicy, threadId);
                        Callback.Breakpoint(filter.SuspendPolicy, filter.RequestId, threadId, location);
                    }
                }
            }
コード例 #15
0
            private void HandleMethodExit(jvmtiEnvHandle env, JNIEnvHandle jniEnv, jthread threadHandle, jmethodID methodId, bool wasPoppedByException, jvalue returnValue)
            {
                if (!VirtualMachine.IsAgentThread.Value)
                {
                    // ignore events before VMInit
                    if (AgentEventDispatcher == null)
                        return;

                    // dispatch this call to an agent thread
                    Action<jvmtiEnvHandle, JNIEnvHandle, jthread, jmethodID, bool, jvalue> method = HandleMethodExit;
                    AgentEventDispatcher.Invoke(method, env, jniEnv, threadHandle, methodId, wasPoppedByException, returnValue);
                    return;
                }

                //JvmEnvironment environment = JvmEnvironment.GetEnvironment(env);
                //JvmThreadReference thread = JvmThreadReference.FromHandle(environment, jniEnv, threadHandle, true);
                //JvmMethod method = new JvmMethod(environment, methodId);

                //foreach (var processor in _processors)
                //{
                //    processor.HandleMethodExit(environment, thread, method, wasPoppedByException, returnValue);
                //}
            }
コード例 #16
0
            public override bool ProcessEvent(JvmtiEnvironment environment, JniEnvironment nativeEnvironment, EventProcessor processor, ThreadId thread, TaggedReferenceTypeId @class, Location? location)
            {
                if (!base.ProcessEvent(environment, nativeEnvironment, processor, thread, @class, location))
                    return false;

                // Step Out is implemented with Frame Pop events set at the correct depth
                if (_depth == StepDepth.Out)
                {
                    if (location.HasValue && !location.Value.Method.Equals(_lastMethod))
                    {
                        _lastLocation = new jlocation((long)location.Value.Index);
                        _lastMethod = location.Value.Method;
                        UpdateLastLine(environment);
                    }

                    return true;
                }

                using (var threadHandle = environment.VirtualMachine.GetLocalReferenceForThread(nativeEnvironment, thread))
                {
                    int stackDepth;
                    JvmtiErrorHandler.ThrowOnFailure(environment.GetFrameCount(threadHandle.Value, out stackDepth));

                    if (_hasMethodInfo && stackDepth > _stackDepth)
                    {
                        bool convertToFramePop;
                        if (location.HasValue && (!_convertedToFramePop || !_framePopMethod.Equals(location.Value.Method)) && ShouldSkipCurrentMethod(processor.VirtualMachine, environment, nativeEnvironment, threadHandle.Value, stackDepth, location.Value, out convertToFramePop))
                        {
                            if (convertToFramePop)
                            {
                                // remove the single step event
                                JvmtiErrorHandler.ThrowOnFailure((jvmtiError)processor.ClearEventInternal(EventKind.FramePop, this.RequestId));
                                JvmtiErrorHandler.ThrowOnFailure((jvmtiError)processor.ClearEventInternal(EventKind.SingleStep, this.RequestId));
                                // set an actual step filter to respond when the thread arrives back in this frame
                                JvmtiErrorHandler.ThrowOnFailure((jvmtiError)processor.SetEventInternal(environment, nativeEnvironment, EventKind.FramePop, this));
                                _convertedToFramePop = true;
                                _framePopMethod = location.Value.Method;
                            }

                            return false;
                        }
                        else
                        {
                            _convertedToFramePop = false;
                            return true;
                        }
                    }
                    else if (stackDepth == _stackDepth)
                    {
                        if (_size == StepSize.Statement && _disassembledMethod != null)
                        {
                            int instructionIndex = _disassembledMethod.Instructions.FindIndex(i => (uint)i.Offset == location.Value.Index);
                            if (instructionIndex >= 0 && _evaluationStackDepths != null && (_evaluationStackDepths[instructionIndex] ?? 0) != 0)
                            {
                                return false;
                            }
                            else if (instructionIndex >= 0 && _disassembledMethod.Instructions[instructionIndex].OpCode.FlowControl == JavaFlowControl.Branch)
                            {
                                // follow branch instructions before stopping
                                return false;
                            }
                        }
                        else if (_lastLine != null)
                        {
                            // see if we're on the same line
                            LineNumberData[] lines;
                            jvmtiError error = environment.GetLineNumberTable(location.Value.Method, out lines);
                            if (error == jvmtiError.None)
                            {
                                LineNumberData entry = lines.LastOrDefault(i => i.LineCodeIndex <= (long)location.Value.Index);
                                if (entry.LineNumber == _lastLine)
                                    return false;
                            }
                        }
                    }

                    if (location.HasValue)
                    {
                        _lastLocation = new jlocation((long)location.Value.Index);
                        _lastMethod = location.Value.Method;
                        UpdateLastLine(environment);
                    }

                    _stackDepth = stackDepth;
                    return true;
                }
            }
コード例 #17
0
ファイル: JniEnvironment.cs プロジェクト: Kav2018/JavaForVS
 public jobject NewObject(jclass @class, jmethodID ctorMethodId, params jvalue[] args)
 {
     jobject result = RawInterface.NewObjectA(this, @class, ctorMethodId, args);
     HandleException();
     return result;
 }
コード例 #18
0
ファイル: JvmtiEnvironment.cs プロジェクト: Kav2018/JavaForVS
 internal jvmtiError ClearBreakpoint(jmethodID methodId, jlocation location)
 {
     return RawInterface.ClearBreakpoint(this, methodId, location);
 }
コード例 #19
0
ファイル: JvmtiEnvironment.cs プロジェクト: Kav2018/JavaForVS
 public jvmtiError GetFrameLocation(jthread thread, int depth, out jmethodID method, out jlocation location)
 {
     return RawInterface.GetFrameLocation(this, thread, depth, out method, out location);
 }
コード例 #20
0
        private void HandleMethodEntry(jvmtiEnvHandle env, JNIEnvHandle jniEnv, jthread threadHandle, jmethodID methodId)
        {
            JvmEnvironment     environment = JvmEnvironment.GetEnvironment(env);
            JvmThreadReference thread      = JvmThreadReference.FromHandle(environment, jniEnv, threadHandle, true);
            JvmMethod          method      = new JvmMethod(environment, methodId);

            foreach (var processor in _processors)
            {
                processor.HandleMethodEntry(environment, thread, method);
            }
        }
コード例 #21
0
        private void HandleBreakpoint(jvmtiEnvHandle env, JNIEnvHandle jniEnv, jthread threadHandle, jmethodID method, jlocation jlocation)
        {
            JvmEnvironment     environment = JvmEnvironment.GetEnvironment(env);
            JvmThreadReference thread      = JvmThreadReference.FromHandle(environment, jniEnv, threadHandle, true);
            JvmLocation        location    = new JvmLocation(environment, method, jlocation);

            foreach (var processor in _processors)
            {
                processor.HandleBreakpoint(environment, thread, location);
            }
        }
コード例 #22
0
            private void HandleCompiledMethodLoad(jvmtiEnvHandle env, jmethodID methodId, int codeSize, IntPtr codeAddress, int mapLength, jvmtiAddressLocationMap[] map, IntPtr compileInfo)
            {
                if (!VirtualMachine.IsAgentThread.Value)
                {
                    // ignore events before VMInit
                    if (AgentEventDispatcher == null)
                        return;

                    // dispatch this call to an agent thread
                    Action<jvmtiEnvHandle, jmethodID, int, IntPtr, int, jvmtiAddressLocationMap[], IntPtr> method = HandleCompiledMethodLoad;
                    AgentEventDispatcher.Invoke(method, env, methodId, codeSize, codeAddress, mapLength, map, compileInfo);
                    return;
                }

                //JvmEnvironment environment = JvmEnvironment.GetEnvironment(env);

                //foreach (var processor in _processors)
                //{
                //    throw new NotImplementedException();
                //    //processor.HandleCompiledMethodLoad(environment, method, codeSize, codeAddress, map2, compileInfo);
                //}
            }
コード例 #23
0
ファイル: JvmLocation.cs プロジェクト: weizhengwei/LangSvcV2
 internal JvmLocation(JvmEnvironment environment, jmethodID method, jlocation location)
 {
     throw new NotImplementedException();
 }
コード例 #24
0
            private void HandleException(jvmtiEnvHandle env, JNIEnvHandle jniEnv, jthread threadHandle, jmethodID methodId, jlocation jlocation, jobject exceptionHandle, jmethodID catchMethodId, jlocation catchjLocation)
            {
                // don't send exception events from an agent thread
                if (VirtualMachine.IsAgentThread.Value)
                    return;

                JvmtiEnvironment environment = JvmtiEnvironment.GetOrCreateInstance(_service.VirtualMachine, env);
                JniEnvironment nativeEnvironment = JniEnvironment.GetOrCreateInstance(jniEnv);

                TaggedReferenceTypeId declaringClass;
                MethodId method = new MethodId(methodId.Handle);
                ulong index = (ulong)jlocation.Value;
                JvmtiErrorHandler.ThrowOnFailure(environment.GetMethodDeclaringClass(nativeEnvironment, method, out declaringClass));
                Location location = new Location(declaringClass, method, index);

                Location catchLocation;
                method = new MethodId(catchMethodId.Handle);
                index = (ulong)catchjLocation.Value;
                if (catchMethodId.Handle != IntPtr.Zero)
                {
                    JvmtiErrorHandler.ThrowOnFailure(environment.GetMethodDeclaringClass(nativeEnvironment, method, out declaringClass));
                    catchLocation = new Location(declaringClass, method, index);
                }
                else
                {
                    catchLocation = default(Location);
                }

                TaggedObjectId exceptionId = VirtualMachine.TrackLocalObjectReference(exceptionHandle, environment, nativeEnvironment, false);

                ThreadId threadId = VirtualMachine.TrackLocalThreadReference(threadHandle, environment, nativeEnvironment, false);
                EventFilter[] filters = GetEventFilters(EventKind.Exception);
                foreach (var filter in filters)
                {
                    if (filter.ProcessEvent(environment, nativeEnvironment, this, threadId, default(TaggedReferenceTypeId), location))
                    {
                        SendExceptionEvent(environment, filter, threadId, location, exceptionId, catchLocation);
                    }
                }

                ////Location location = new Location();
                ////Location catchLocation = new Location();
                //throw new NotImplementedException();

#if false
                ThreadId threadId = GetObjectId(ref threadHandle);
                TaggedObjectId exception = GetObjectId(ref exceptionHandle);
                EventFilter[] filters = GetEventFilters(EventKind.Exception);
                foreach (var filter in filters)
                {
                    if (filter.ProcessEvent(threadId, default(TaggedReferenceTypeId)))
                    {
                        ApplySuspendPolicy(environment, filter.SuspendPolicy, threadId);
                        Callback.HandleException(filter.SuspendPolicy, filter.RequestId, threadId, location, exception, catchLocation);
                    }
                }
#endif

                //JvmEnvironment environment = JvmEnvironment.GetEnvironment(env);
                //JvmThreadReference thread = JvmThreadReference.FromHandle(environment, jniEnv, threadHandle, true);
                //JvmLocation location = new JvmLocation(environment, method, jlocation);
                //JvmObjectReference exception = JvmObjectReference.FromHandle(environment, jniEnv, exceptionHandle, true);
                //JvmLocation catchLocation = new JvmLocation(environment, catchMethod, catchjLocation);

                //foreach (var processor in _processors)
                //{
                //    processor.HandleException(environment, thread, location, exception, catchLocation);
                //}
            }
コード例 #25
0
ファイル: JniEnvironment.cs プロジェクト: Kav2018/JavaForVS
 internal bool CallStaticBooleanMethodA(jclass classHandle, jmethodID methodId, params jvalue[] args)
 {
     var result = RawInterface.CallStaticBooleanMethodA(this, classHandle, methodId, args) != 0;
     HandleException();
     return result;
 }
コード例 #26
0
        private void HandleNativeMethodBind(jvmtiEnvHandle env, JNIEnvHandle jniEnv, jthread threadHandle, jmethodID methodId, IntPtr address, ref IntPtr newAddressPtr)
        {
            JvmEnvironment     environment = JvmEnvironment.GetEnvironment(env);
            JvmThreadReference thread      = JvmThreadReference.FromHandle(environment, jniEnv, threadHandle, true);
            JvmMethod          method      = new JvmMethod(environment, methodId);

            foreach (var processor in _processors)
            {
                IntPtr?newAddress = null;
                processor.HandleNativeMethodBind(environment, thread, method, address, ref newAddress);
            }
        }
コード例 #27
0
            private void HandleFieldModification(jvmtiEnvHandle env, JNIEnvHandle jniEnv, jthread threadHandle, jmethodID methodId, jlocation jlocation, jclass fieldClassHandle, jobject objectHandle, jfieldID fieldId, byte signatureType, jvalue newValue)
            {
                if (!VirtualMachine.IsAgentThread.Value)
                {
                    // ignore events before VMInit
                    if (AgentEventDispatcher == null)
                        return;

                    // dispatch this call to an agent thread
                    Action<jvmtiEnvHandle, JNIEnvHandle, jthread, jmethodID, jlocation, jclass, jobject, jfieldID, byte, jvalue> method = HandleFieldModification;
                    AgentEventDispatcher.Invoke(method, env, jniEnv, threadHandle, methodId, jlocation, fieldClassHandle, objectHandle, fieldId, signatureType, newValue);
                    return;
                }

                //JvmEnvironment environment = JvmEnvironment.GetEnvironment(env);
                //JvmThreadReference thread = JvmThreadReference.FromHandle(environment, jniEnv, threadHandle, true);
                //JvmLocation location = new JvmLocation(environment, method, jlocation);
                //JvmClassReference fieldClass = JvmClassReference.FromHandle(environment, jniEnv, fieldClassHandle, true);
                //JvmObjectReference @object = JvmObjectReference.FromHandle(environment, jniEnv, objectHandle, true);
                //JvmField field = new JvmField(environment, fieldId);

                //foreach (var processor in _processors)
                //{
                //    processor.HandleFieldModification(environment, thread, location, fieldClass, @object, field, signatureType, newValue);
                //}
            }
コード例 #28
0
ファイル: JniEnvironment.cs プロジェクト: Kav2018/JavaForVS
 internal jobject CallStaticObjectMethodA(jclass classHandle, jmethodID methodId, params jvalue[] args)
 {
     var result = RawInterface.CallStaticObjectMethodA(this, classHandle, methodId, args);
     HandleException();
     return result;
 }
コード例 #29
0
            private void HandleNativeMethodBind(jvmtiEnvHandle env, JNIEnvHandle jniEnv, jthread threadHandle, jmethodID methodId, IntPtr address, ref IntPtr newAddressPtr)
            {
                if (!VirtualMachine.IsAgentThread.Value)
                {
                    // ignore events before VMInit
                    if (AgentEventDispatcher == null)
                        return;

                    // dispatch this call to an agent thread
                    //Action<jvmtiEnvHandle, JNIEnvHandle, jthread, jmethodID, IntPtr, ReferenceTypeData intptr> method = HandleNativeMethodBind;
                    //AgentEventDispatcher.Invoke(method, env, jniEnv);
                    //return;
                    throw new NotImplementedException();
                }

                //JvmEnvironment environment = JvmEnvironment.GetEnvironment(env);
                //JvmThreadReference thread = JvmThreadReference.FromHandle(environment, jniEnv, threadHandle, true);
                //JvmMethod method = new JvmMethod(environment, methodId);

                //foreach (var processor in _processors)
                //{
                //    IntPtr? newAddress = null;
                //    processor.HandleNativeMethodBind(environment, thread, method, address, ref newAddress);
                //}
            }
コード例 #30
0
ファイル: JniEnvironment.cs プロジェクト: Kav2018/JavaForVS
 internal bool CallBooleanMethodA(jobject instanceHandle, jmethodID methodId, params jvalue[] args)
 {
     var result = RawInterface.CallBooleanMethodA(this, instanceHandle, methodId, args) != 0;
     HandleException();
     return result;
 }
コード例 #31
0
            private void HandleCompiledMethodUnload(jvmtiEnvHandle env, jmethodID methodId, IntPtr codeAddress)
            {
                if (!VirtualMachine.IsAgentThread.Value)
                {
                    // ignore events before VMInit
                    if (AgentEventDispatcher == null)
                        return;

                    // dispatch this call to an agent thread
                    Action<jvmtiEnvHandle, jmethodID, IntPtr> method = HandleCompiledMethodUnload;
                    AgentEventDispatcher.Invoke(method, env, methodId, codeAddress);
                    return;
                }

                //JvmEnvironment environment = JvmEnvironment.GetEnvironment(env);
                //JvmMethod method = new JvmMethod(environment, methodId);

                //foreach (var processor in _processors)
                //{
                //    processor.HandleCompiledMethodUnload(environment, method, codeAddress);
                //}
            }
コード例 #32
0
ファイル: JniEnvironment.cs プロジェクト: Kav2018/JavaForVS
 internal short CallShortMethodA(jobject instanceHandle, jmethodID methodId, params jvalue[] args)
 {
     var result = RawInterface.CallShortMethodA(this, instanceHandle, methodId, args);
     HandleException();
     return result;
 }
コード例 #33
0
            private void HandleExceptionCatch(jvmtiEnvHandle env, JNIEnvHandle jniEnv, jthread threadHandle, jmethodID methodId, jlocation jlocation, jobject exceptionHandle)
            {
                if (!VirtualMachine.IsAgentThread.Value)
                {
                    // ignore events before VMInit
                    if (AgentEventDispatcher == null)
                        return;

                    // dispatch this call to an agent thread
                    Action<jvmtiEnvHandle, JNIEnvHandle, jthread, jmethodID, jlocation, jobject> method = HandleExceptionCatch;
                    AgentEventDispatcher.Invoke(method, env, jniEnv, threadHandle, methodId, jlocation, exceptionHandle);
                    return;
                }

                //JvmEnvironment environment = JvmEnvironment.GetEnvironment(env);
                //JvmThreadReference thread = JvmThreadReference.FromHandle(environment, jniEnv, threadHandle, true);
                //JvmLocation location = new JvmLocation(environment, method, jlocation);
                //JvmObjectReference exception = JvmObjectReference.FromHandle(environment, jniEnv, exceptionHandle, true);

                //foreach (var processor in _processors)
                //{
                //    processor.HandleExceptionCatch(environment, thread, location, exception);
                //}
            }
コード例 #34
0
ファイル: JniEnvironment.cs プロジェクト: Kav2018/JavaForVS
 internal void CallNonvirtualVoidMethodA(jobject instanceHandle, jclass classHandle, jmethodID methodId, params jvalue[] args)
 {
     RawInterface.CallNonvirtualVoidMethodA(this, instanceHandle, classHandle, methodId, args);
     HandleException();
 }
コード例 #35
0
            private void HandleFramePop(jvmtiEnvHandle env, JNIEnvHandle jniEnv, jthread threadHandle, jmethodID methodId, bool wasPoppedByException)
            {
                try
                {
                    JvmtiEnvironment environment = JvmtiEnvironment.GetOrCreateInstance(_service.VirtualMachine, env);
                    JniEnvironment nativeEnvironment = JniEnvironment.GetOrCreateInstance(jniEnv);

                    TaggedReferenceTypeId declaringClass;
                    MethodId method = new MethodId(methodId.Handle);
                    jlocation jlocation;
                    JvmtiErrorHandler.ThrowOnFailure(environment.GetFrameLocation(threadHandle, 1, out methodId, out jlocation));
                    ulong index = (ulong)jlocation.Value;
                    JvmtiErrorHandler.ThrowOnFailure(environment.GetMethodDeclaringClass(nativeEnvironment, method, out declaringClass));
                    Location location = new Location(declaringClass, method, index);

                    ThreadId threadId = VirtualMachine.TrackLocalThreadReference(threadHandle, environment, nativeEnvironment, false);

                    EventFilter[] filters = GetEventFilters(EventKind.FramePop);
                    foreach (var filter in filters)
                    {
                        if (filter.ProcessEvent(environment, nativeEnvironment, this, threadId, default(TaggedReferenceTypeId), location))
                        {
                            if (filter.InternalEventKind == EventKind.SingleStep)
                            {
                                // remove the frame pop event
                                JvmtiErrorHandler.ThrowOnFailure((jvmtiError)ClearEventInternal(EventKind.FramePop, filter.RequestId));
                                // set an actual step filter to respond when the thread arrives in the parent frame
                                JvmtiErrorHandler.ThrowOnFailure((jvmtiError)SetEventInternal(environment, nativeEnvironment, EventKind.SingleStep, filter));
                            }
                            else
                            {
                                SendFramePopEvent(environment, filter, threadId, location, wasPoppedByException);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    string caption = "Exception while handling a frame pop event";
                    System.Windows.Forms.MessageBox.Show(e.Message + System.Environment.NewLine + System.Environment.NewLine + e.StackTrace, caption, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    throw;
                }
            }
コード例 #36
0
ファイル: JniEnvironment.cs プロジェクト: Kav2018/JavaForVS
 internal jobject CallNonvirtualObjectMethodA(jobject instanceHandle, jclass classHandle, jmethodID methodId, params jvalue[] args)
 {
     var result = RawInterface.CallNonvirtualObjectMethodA(this, instanceHandle, classHandle, methodId, args);
     HandleException();
     return result;
 }