Ejemplo n.º 1
0
        public jvmtiCapabilities GetPotentialCapabilities()
        {
            jvmtiCapabilities capabilities;

            ThrowOnFailure(_rawInterface.GetPotentialCapabilities(_env, out capabilities));
            return(capabilities);
        }
Ejemplo n.º 2
0
        private JvmEnvironment(jvmtiEnvHandle env)
        {
            Contract.Requires <ArgumentException>(env != jvmtiEnvHandle.Null);

            jvmtiInterface rawInterface = (jvmtiInterface)Marshal.PtrToStructure(Marshal.ReadIntPtr(env.Handle), typeof(jvmtiInterface));

            Contract.Assert(rawInterface.GetCapabilities != null);
            Contract.Assert(rawInterface.Allocate != null);
            Contract.Assert(rawInterface.Deallocate != null);
            Contract.Assert(rawInterface.GetThreadState != null);
            Contract.Assert(rawInterface.GetCurrentThread != null);
            Contract.Assert(rawInterface.GetAllThreads != null);
            Contract.Assert(rawInterface.GetThreadInfo != null);
            Contract.Assert(rawInterface.RunAgentThread != null);
            Contract.Assert(rawInterface.SetThreadLocalStorage != null);
            Contract.Assert(rawInterface.GetThreadLocalStorage != null);
            Contract.Assert(rawInterface.GetTopThreadGroups != null);
            Contract.Assert(rawInterface.GetThreadGroupInfo != null);
            Contract.Assert(rawInterface.GetThreadGroupChildren != null);
            Contract.Assert(rawInterface.GetStackTrace != null);
            Contract.Assert(rawInterface.GetAllStackTraces != null);
            Contract.Assert(rawInterface.GetThreadListStackTraces != null);
            Contract.Assert(rawInterface.GetFrameCount != null);
            Contract.Assert(rawInterface.GetFrameLocation != null);
            Contract.Assert(rawInterface.ForceGarbageCollection != null);
            Contract.Assert(rawInterface.GetLoadedClasses != null);
            Contract.Assert(rawInterface.GetClassLoaderClasses != null);
            Contract.Assert(rawInterface.GetClassSignature != null);
            Contract.Assert(rawInterface.GetClassStatus != null);
            Contract.Assert(rawInterface.GetClassModifiers != null);
            Contract.Assert(rawInterface.GetClassMethods != null);
            Contract.Assert(rawInterface.GetClassFields != null);
            Contract.Assert(rawInterface.GetImplementedInterfaces != null);
            Contract.Assert(rawInterface.GetClassVersionNumbers != null);
            Contract.Assert(rawInterface.IsInterface != null);
            Contract.Assert(rawInterface.IsArrayClass != null);
            Contract.Assert(rawInterface.IsModifiableClass != null);
            Contract.Assert(rawInterface.GetClassLoader != null);
            Contract.Assert(rawInterface.GetObjectSize != null);
            Contract.Assert(rawInterface.GetObjectHashCode != null);
            Contract.Assert(rawInterface.GetFieldName != null);
            Contract.Assert(rawInterface.GetFieldDeclaringClass != null);
            Contract.Assert(rawInterface.GetFieldModifiers != null);
            Contract.Assert(rawInterface.GetMethodName != null);
            Contract.Assert(rawInterface.GetMethodDeclaringClass != null);
            Contract.Assert(rawInterface.GetMethodModifiers != null);
            Contract.Assert(rawInterface.GetMaxLocals != null);
            Contract.Assert(rawInterface.GetArgumentsSize != null);
            Contract.Assert(rawInterface.GetMethodLocation != null);
            Contract.Assert(rawInterface.IsMethodNative != null);
            Contract.Assert(rawInterface.IsMethodObsolete != null);
            Contract.Assert(rawInterface.CreateRawMonitor != null);
            Contract.Assert(rawInterface.DestroyRawMonitor != null);
            Contract.Assert(rawInterface.RawMonitorEnter != null);
            Contract.Assert(rawInterface.RawMonitorExit != null);
            Contract.Assert(rawInterface.RawMonitorWait != null);
            Contract.Assert(rawInterface.RawMonitorNotify != null);
            Contract.Assert(rawInterface.RawMonitorNotifyAll != null);
            Contract.Assert(rawInterface.SetJNIFunctionTable != null);
            Contract.Assert(rawInterface.GetJNIFunctionTable != null);
            Contract.Assert(rawInterface.SetEventCallbacks != null);
            Contract.Assert(rawInterface.SetEventNotificationMode != null);
            Contract.Assert(rawInterface.GenerateEvents != null);
            Contract.Assert(rawInterface.GetExtensionFunctions != null);
            Contract.Assert(rawInterface.GetExtensionEvents != null);
            Contract.Assert(rawInterface.SetExtensionEventCallback != null);
            Contract.Assert(rawInterface.GetPotentialCapabilities != null);
            Contract.Assert(rawInterface.AddCapabilities != null);
            Contract.Assert(rawInterface.RelinquishCapabilities != null);
            Contract.Assert(rawInterface.GetCapabilities != null);
            Contract.Assert(rawInterface.GetTimerInfo != null);
            Contract.Assert(rawInterface.GetTime != null);
            Contract.Assert(rawInterface.GetAvailableProcessors != null);
            Contract.Assert(rawInterface.AddToBootstrapClassLoaderSearch != null);
            Contract.Assert(rawInterface.AddToSystemClassLoaderSearch != null);
            Contract.Assert(rawInterface.GetSystemProperties != null);
            Contract.Assert(rawInterface.GetSystemProperty != null);
            Contract.Assert(rawInterface.SetSystemProperty != null);
            Contract.Assert(rawInterface.GetPhase != null);
            Contract.Assert(rawInterface.DisposeEnvironment != null);
            Contract.Assert(rawInterface.SetEnvironmentLocalStorage != null);
            Contract.Assert(rawInterface.GetEnvironmentLocalStorage != null);
            Contract.Assert(rawInterface.GetVersionNumber != null);
            Contract.Assert(rawInterface.GetErrorName != null);
            Contract.Assert(rawInterface.SetVerboseFlag != null);
            Contract.Assert(rawInterface.GetJLocationFormat != null);

            jvmtiCapabilities capabilities;

            if (rawInterface.GetPotentialCapabilities(env, out capabilities) != jvmtiError.None)
            {
                throw new InvalidOperationException();
            }

            Contract.Assert(!capabilities.CanSuspend || rawInterface.SuspendThread != null);
            Contract.Assert(!capabilities.CanSuspend || rawInterface.SuspendThreadList != null);
            Contract.Assert(!capabilities.CanSuspend || rawInterface.ResumeThread != null);
            Contract.Assert(!capabilities.CanSuspend || rawInterface.ResumeThreadList != null);

            Contract.Assert(!capabilities.CanSignalThread || rawInterface.StopThread != null);
            Contract.Assert(!capabilities.CanSignalThread || rawInterface.InterruptThread != null);

            Contract.Assert(!capabilities.CanGetOwnedMonitorInfo || rawInterface.GetOwnedMonitorInfo != null);

            Contract.Assert(!capabilities.CanGetOwnedMonitorStackDepthInfo || rawInterface.GetOwnedMonitorStackDepthInfo != null);
            Contract.Assert(!capabilities.CanGetCurrentContendedMonitor || rawInterface.GetCurrentContendedMonitor != null);
            Contract.Assert(!capabilities.CanPopFrame || rawInterface.PopFrame != null);
            Contract.Assert(!capabilities.CanGenerateFramePopEvents || rawInterface.NotifyFramePop != null);
            Contract.Assert(!capabilities.CanForceEarlyReturn || rawInterface.ForceEarlyReturnObject != null);
            Contract.Assert(!capabilities.CanForceEarlyReturn || rawInterface.ForceEarlyReturnInt != null);
            Contract.Assert(!capabilities.CanForceEarlyReturn || rawInterface.ForceEarlyReturnLong != null);
            Contract.Assert(!capabilities.CanForceEarlyReturn || rawInterface.ForceEarlyReturnFloat != null);
            Contract.Assert(!capabilities.CanForceEarlyReturn || rawInterface.ForceEarlyReturnDouble != null);
            Contract.Assert(!capabilities.CanForceEarlyReturn || rawInterface.ForceEarlyReturnVoid != null);
            Contract.Assert(!capabilities.CanTagObjects || rawInterface.FollowReferences != null);
            Contract.Assert(!capabilities.CanTagObjects || rawInterface.IterateThroughHeap != null);
            Contract.Assert(!capabilities.CanTagObjects || rawInterface.GetTag != null);
            Contract.Assert(!capabilities.CanTagObjects || rawInterface.SetTag != null);
            Contract.Assert(!capabilities.CanTagObjects || rawInterface.GetObjectsWithTags != null);
            Contract.Assert(!capabilities.CanAccessLocalVariables || rawInterface.GetLocalObject != null);
            Contract.Assert(!capabilities.CanAccessLocalVariables || rawInterface.GetLocalInstance != null);
            Contract.Assert(!capabilities.CanAccessLocalVariables || rawInterface.GetLocalInt != null);
            Contract.Assert(!capabilities.CanAccessLocalVariables || rawInterface.GetLocalLong != null);
            Contract.Assert(!capabilities.CanAccessLocalVariables || rawInterface.GetLocalFloat != null);
            Contract.Assert(!capabilities.CanAccessLocalVariables || rawInterface.GetLocalDouble != null);
            Contract.Assert(!capabilities.CanAccessLocalVariables || rawInterface.SetLocalObject != null);
            Contract.Assert(!capabilities.CanAccessLocalVariables || rawInterface.SetLocalInt != null);
            Contract.Assert(!capabilities.CanAccessLocalVariables || rawInterface.SetLocalLong != null);
            Contract.Assert(!capabilities.CanAccessLocalVariables || rawInterface.SetLocalFloat != null);
            Contract.Assert(!capabilities.CanAccessLocalVariables || rawInterface.SetLocalDouble != null);
            Contract.Assert(!capabilities.CanGenerateBreakpointEvents || rawInterface.SetBreakpoint != null);
            Contract.Assert(!capabilities.CanGenerateBreakpointEvents || rawInterface.ClearBreakpoint != null);
            Contract.Assert(!capabilities.CanGenerateFieldAccessEvents || rawInterface.SetFieldAccessWatch != null);
            Contract.Assert(!capabilities.CanGenerateFieldAccessEvents || rawInterface.ClearFieldAccessWatch != null);
            Contract.Assert(!capabilities.CanGenerateFieldModificationEvents || rawInterface.SetFieldModificationWatch != null);
            Contract.Assert(!capabilities.CanGenerateFieldModificationEvents || rawInterface.ClearFieldModificationWatch != null);

            Contract.Assert(!capabilities.CanGetSourceFileName || rawInterface.GetSourceFileName != null);

            Contract.Assert(!capabilities.CanGetConstantPool || rawInterface.GetConstantPool != null);

            Contract.Assert(!capabilities.CanGetSourceDebugExtension || rawInterface.GetSourceDebugExtension != null);
            Contract.Assert(!capabilities.CanRetransformClasses || rawInterface.RetransformClasses != null);
            Contract.Assert(!capabilities.CanRedefineClasses || rawInterface.RedefineClasses != null);

            Contract.Assert(!capabilities.CanGetMonitorInfo || rawInterface.GetObjectMonitorUsage != null);

            Contract.Assert(!capabilities.CanGetSyntheticAttribute || rawInterface.IsFieldSynthetic != null);
            Contract.Assert(!capabilities.CanGetLineNumbers || rawInterface.GetLineNumberTable != null);
            Contract.Assert(!capabilities.CanAccessLocalVariables || rawInterface.GetLocalVariableTable != null);
            Contract.Assert(!capabilities.CanGetBytecodes || rawInterface.GetBytecodes != null);
            Contract.Assert(!capabilities.CanGetSyntheticAttribute || rawInterface.IsMethodSynthetic != null);
            Contract.Assert(!capabilities.CanSetNativeMethodPrefix || rawInterface.SetNativeMethodPrefix != null);
            Contract.Assert(!capabilities.CanSetNativeMethodPrefix || rawInterface.SetNativeMethodPrefixes != null);

            Contract.Assert(!capabilities.CanGetCurrentThreadCpuTime || rawInterface.GetCurrentThreadCpuTimerInfo != null);
            Contract.Assert(!capabilities.CanGetCurrentThreadCpuTime || rawInterface.GetCurrentThreadCpuTime != null);
            Contract.Assert(!capabilities.CanGetThreadCpuTime || rawInterface.GetCurrentThreadCpuTimerInfo != null);
            Contract.Assert(!capabilities.CanGetThreadCpuTime || rawInterface.GetCurrentThreadCpuTime != null);

            capabilities = new jvmtiCapabilities(
                jvmtiCapabilities.CapabilityFlags1.CanTagObjects
                | jvmtiCapabilities.CapabilityFlags1.CanGetSourceFileName
                | jvmtiCapabilities.CapabilityFlags1.CanGetLineNumbers
                );
            rawInterface.AddCapabilities(env, ref capabilities);

            _env          = env;
            _rawInterface = rawInterface;

            _eventManager = new JvmEventManager(this);
            _eventManager.Attach();
        }