internal jvmtiError AddGlobalReference(JvmtiEnvironment environment, JniEnvironment nativeEnvironment, jobject obj) { long tag; jvmtiError error = environment.GetTag(obj, out tag); if (error != jvmtiError.None) { return(error); } if (tag == 0) { return(jvmtiError.IllegalArgument); } _globalReferences.AddOrUpdate(tag, t => { return(Tuple.Create(nativeEnvironment.NewGlobalReference(obj), 1)); }, (t, v) => { if (v.Item2 == 0) { return(Tuple.Create(nativeEnvironment.NewGlobalReference(obj), 1)); } else { return(Tuple.Create(v.Item1, v.Item2 + 1)); } }); return(jvmtiError.None); }
public static void ThrowOnFailure(jvmtiError error) { if (error == jvmtiError.None) return; throw new Exception(string.Format("{0} ({1})", error, (int)error)); }
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); } }
public jvmtiError GetSystemProperty(string name, out string value) { value = null; using (ModifiedUTF8StringData property = new ModifiedUTF8StringData(name)) { IntPtr valuePtr; jvmtiError error = RawInterface.GetSystemProperty(this, property, out valuePtr); if (error != jvmtiError.None) { return(error); } unsafe { if (valuePtr != IntPtr.Zero) { value = ModifiedUTF8Encoding.GetString((byte *)valuePtr); Deallocate(valuePtr); } } return(jvmtiError.None); } }
public jvmtiError GetSourceFileName(JvmVirtualMachineRemoteHandle virtualMachine, JvmClassRemoteHandle @class, out string sourceName) { JavaVM machine = JavaVM.GetInstance(virtualMachine); string sourceNameResult = null; jvmtiError result = jvmtiError.Internal; machine.InvokeOnJvmThread( (environment) => { jvmtiInterface rawInterface = environment.RawInterface; IntPtr sourceNamePtr = IntPtr.Zero; try { result = rawInterface.GetSourceFileName(environment.Handle, @class, out sourceNamePtr); unsafe { if (sourceNamePtr != IntPtr.Zero) { sourceNameResult = ModifiedUTF8Encoding.GetString((byte *)sourceNamePtr); } } } finally { rawInterface.Deallocate(environment.Handle, sourceNamePtr); } }); sourceName = sourceNameResult; return(result); }
public jvmtiError GetBytecodes(MethodId methodId, out byte[] bytecode) { bytecode = null; int bytecodeCount; IntPtr bytecodePtr; jvmtiError error = RawInterface.GetBytecodes(this, methodId, out bytecodeCount, out bytecodePtr); if (error != jvmtiError.None) { return(error); } try { if (bytecodeCount > 0) { bytecode = new byte[bytecodeCount]; Marshal.Copy(bytecodePtr, bytecode, 0, bytecodeCount); } } finally { Deallocate(bytecodePtr); } return(jvmtiError.None); }
public jvmtiError GetLineNumberTable(MethodId methodId, out LineNumberData[] lines) { lines = null; int entryCount; IntPtr table; jvmtiError error = RawInterface.GetLineNumberTable(this, (jmethodID)methodId, out entryCount, out table); if (error != jvmtiError.None) { return(error); } try { List <LineNumberData> lineData = new List <LineNumberData>(); unsafe { jvmtiLineNumberEntry *entryTable = (jvmtiLineNumberEntry *)table; for (int i = 0; i < entryCount; i++) { long lineCodeIndex = entryTable[i].StartLocation.Value; LineNumberData line = new LineNumberData(lineCodeIndex, entryTable[i].LineNumber); lineData.Add(line); } } lines = lineData.ToArray(); return(jvmtiError.None); } finally { Deallocate(table); } }
public jvmtiError GetThreadInfo(JvmVirtualMachineRemoteHandle virtualMachine, JvmThreadRemoteHandle thread, out JvmThreadRemoteInfo info) { JavaVM machine = JavaVM.GetInstance(virtualMachine); jvmtiThreadInfo threadInfo = default(jvmtiThreadInfo); jvmtiError result = jvmtiError.Internal; machine.InvokeOnJvmThread( (environment) => { jvmtiInterface rawInterface = environment.RawInterface; result = rawInterface.GetThreadInfo(environment.Handle, thread, out threadInfo); }); info = new JvmThreadRemoteInfo() { Name = threadInfo.Name, Priority = threadInfo._priority, IsDaemon = threadInfo._isDaemon != 0, ContextClassLoader = new JvmObjectRemoteHandle(threadInfo._contextClassLoader), ThreadGroup = new JvmThreadGroupRemoteHandle(threadInfo._threadGroup) }; return(result); }
public jvmtiError IsArrayClass(jclass classHandle, out bool result) { byte arrayClass; jvmtiError error = RawInterface.IsArrayClass(this, classHandle, out arrayClass); result = arrayClass != 0; return(error); }
public jvmtiError IsInterface(jclass classHandle, out bool result) { byte isInterface; jvmtiError error = RawInterface.IsInterface(this, classHandle, out isInterface); result = isInterface != 0; return(error); }
private static void GetEnvironmentVersion(JavaVM vm) { JvmtiEnvironment env; int error = vm.GetEnvironment(out env); int version; jvmtiError error2 = env.GetVersionNumber(out version); }
public static void ThrowOnFailure(jvmtiError error) { if (error == jvmtiError.None) { return; } throw new Exception(string.Format("{0} ({1})", error, (int)error)); }
private void HandleVMInit(jvmtiEnvHandle env, JNIEnvHandle jniEnv, jthread threadHandle) { JvmEnvironment environment = JvmEnvironment.GetEnvironment(env); JvmThreadReference thread = JvmThreadReference.FromHandle(environment, jniEnv, threadHandle, true); jvmtiError result = environment.RawInterface.RunAgentThread(env, alloc_thread(jniEnv), DispatchJvmEvents, IntPtr.Zero, JvmThreadPriority.Maximum); foreach (var processor in _processors) { processor.HandleVMInitialization(environment, thread); } }
internal LocalObjectReferenceHolder GetLocalReferenceForObject(JniEnvironment nativeEnvironment, ObjectId objectId) { LocalObjectReferenceHolder thread; jvmtiError error = GetLocalReferenceForObject(nativeEnvironment, objectId, out thread); if (error != jvmtiError.None) { return(new LocalObjectReferenceHolder()); } return(thread); }
public jvmtiError IsMethodNative(MethodId methodId, out bool result) { result = false; byte native; jvmtiError error = RawInterface.IsMethodNative(this, methodId, out native); if (error != jvmtiError.None) { return(error); } result = native != 0; return(jvmtiError.None); }
internal jvmtiError GetLocalReferenceForObject(JniEnvironment nativeEnvironment, ObjectId objectId, out LocalObjectReferenceHolder thread) { thread = default(LocalObjectReferenceHolder); jobject threadHandle; jvmtiError error = GetObject(objectId, out threadHandle); if (error != jvmtiError.None) { return(error); } thread = new LocalObjectReferenceHolder(nativeEnvironment, threadHandle); return(jvmtiError.None); }
public jvmtiError Deallocate(JvmVirtualMachineRemoteHandle virtualMachine, long address) { JavaVM machine = JavaVM.GetInstance(virtualMachine); jvmtiError result = jvmtiError.Internal; machine.InvokeOnJvmThread( (environment) => { jvmtiInterface rawInterface = environment.RawInterface; result = rawInterface.Deallocate(environment.Handle, (IntPtr)address); }); return(result); }
public jvmtiError GetCurrentThread(JniEnvironment nativeEnvironment, out ThreadId thread) { thread = default(ThreadId); jthread threadPtr; jvmtiError error = RawInterface.GetCurrentThread(this, out threadPtr); if (error != jvmtiError.None) { return(error); } thread = VirtualMachine.TrackLocalThreadReference(threadPtr, this, nativeEnvironment, true); return(jvmtiError.None); }
public jvmtiError GetLocalObject(JniEnvironment nativeEnvironment, jthread thread, int depth, int slot, out TaggedObjectId value) { value = default(TaggedObjectId); jobject obj; jvmtiError error = RawInterface.GetLocalObject(this, thread, depth, slot, out obj); if (error != jvmtiError.None) { return(error); } value = VirtualMachine.TrackLocalObjectReference(obj, this, nativeEnvironment, true); return(jvmtiError.None); }
public jvmtiError GetMethodDeclaringClass(JniEnvironment nativeEnvironment, MethodId methodId, out TaggedReferenceTypeId declaringClass) { declaringClass = default(TaggedReferenceTypeId); jclass classHandle; jvmtiError error = RawInterface.GetMethodDeclaringClass(this, (jmethodID)methodId, out classHandle); if (error != jvmtiError.None) { return(error); } declaringClass = VirtualMachine.TrackLocalClassReference(classHandle, this, nativeEnvironment, true); return(jvmtiError.None); }
internal jvmtiError GetLocalReferenceForThread(JniEnvironment nativeEnvironment, ThreadId threadId, out LocalThreadReferenceHolder thread) { thread = default(LocalThreadReferenceHolder); jthread threadHandle; jvmtiError error = GetThread(threadId, out threadHandle); if (error != jvmtiError.None) { return(error); } thread = new LocalThreadReferenceHolder(nativeEnvironment, threadHandle); return(jvmtiError.None); }
public jvmtiError SetTag(JvmVirtualMachineRemoteHandle virtualMachine, JvmObjectRemoteHandle @object, long tag) { JavaVM machine = JavaVM.GetInstance(virtualMachine); jvmtiError result = jvmtiError.Internal; machine.InvokeOnJvmThread( (environment) => { jvmtiInterface rawInterface = environment.RawInterface; result = rawInterface.SetTag(environment.Handle, @object, tag); }); return(result); }
internal jvmtiError GetLocalReferenceForClass(JniEnvironment nativeEnvironment, ReferenceTypeId typeId, out LocalClassReferenceHolder thread) { thread = default(LocalClassReferenceHolder); jclass threadHandle; jvmtiError error = GetClass(typeId, out threadHandle); if (error != jvmtiError.None) { return(error); } thread = new LocalClassReferenceHolder(nativeEnvironment, threadHandle); return(jvmtiError.None); }
public jvmtiError GetObjectHashCode(JvmVirtualMachineRemoteHandle virtualMachine, JvmObjectRemoteHandle @object, out int hashCode) { JavaVM machine = JavaVM.GetInstance(virtualMachine); int hashCodeResult = 0; jvmtiError result = jvmtiError.Internal; machine.InvokeOnJvmThread( (environment) => { jvmtiInterface rawInterface = environment.RawInterface; result = rawInterface.GetObjectHashCode(environment.Handle, @object, out hashCodeResult); }); hashCode = hashCodeResult; return(result); }
public jvmtiError GetCurrentThread(JvmVirtualMachineRemoteHandle virtualMachine, out JvmThreadRemoteHandle threadHandle) { JavaVM machine = JavaVM.GetInstance(virtualMachine); jthread thread = jthread.Null; jvmtiError result = jvmtiError.Internal; machine.InvokeOnJvmThread( (environment) => { jvmtiInterface rawInterface = environment.RawInterface; result = rawInterface.GetCurrentThread(environment.Handle, out thread); }); threadHandle = new JvmThreadRemoteHandle(thread); return(result); }
public jvmtiError GetThreadState(JvmVirtualMachineRemoteHandle virtualMachine, JvmThreadRemoteHandle thread, out jvmtiThreadState threadState) { JavaVM machine = JavaVM.GetInstance(virtualMachine); jvmtiThreadState threadStateResult = jvmtiThreadState.None; jvmtiError result = jvmtiError.Internal; machine.InvokeOnJvmThread( (environment) => { jvmtiInterface rawInterface = environment.RawInterface; result = rawInterface.GetThreadState(environment.Handle, thread, out threadStateResult); }); threadState = threadStateResult; return(result); }
public jvmtiError Allocate(JvmVirtualMachineRemoteHandle virtualMachine, long size, out long address) { JavaVM machine = JavaVM.GetInstance(virtualMachine); jvmtiError result = jvmtiError.Internal; IntPtr memory = IntPtr.Zero; machine.InvokeOnJvmThread( (environment) => { jvmtiInterface rawInterface = environment.RawInterface; result = rawInterface.Allocate(environment.Handle, size, out memory); }); address = memory.ToInt64(); return(result); }
public jvmtiError GetClassFields(JniEnvironment nativeEnvironment, ReferenceTypeId declaringType, out FieldId[] fields) { fields = null; using (var @class = VirtualMachine.GetLocalReferenceForClass(nativeEnvironment, declaringType)) { if ([email protected]) { return(jvmtiError.InvalidClass); } int fieldsCount; IntPtr fieldsPtr; jvmtiError error = RawInterface.GetClassFields(this, @class.Value, out fieldsCount, out fieldsPtr); if (error != jvmtiError.None) { return(error); } try { List <FieldId> fieldList = new List <FieldId>(); unsafe { jfieldID *fieldHandles = (jfieldID *)fieldsPtr; for (int i = 0; i < fieldsCount; i++) { if (fieldHandles[i] == jfieldID.Null) { continue; } fieldList.Add(fieldHandles[i]); } } fields = fieldList.ToArray(); return(jvmtiError.None); } finally { Deallocate(fieldsPtr); } } }
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); } } }
public jvmtiError ResumeThreads(JniEnvironment nativeEnvironment, ThreadId[] threads, out jvmtiError[] errors) { List <Tuple <int, LocalThreadReferenceHolder> > threadsToResume = new List <Tuple <int, LocalThreadReferenceHolder> >(); errors = new jvmtiError[threads.Length]; for (int i = 0; i < threads.Length; i++) { LocalThreadReferenceHolder thread; errors[i] = VirtualMachine.GetLocalReferenceForThread(nativeEnvironment, threads[i], out thread); if (errors[i] == jvmtiError.None && thread.IsAlive) { int suspendCount = VirtualMachine.SuspendCounts.AddOrUpdate(threads[i], 0, (existingId, existingValue) => existingValue - 1); if (suspendCount == 0) { threadsToResume.Add(Tuple.Create(i, thread)); } } } if (threadsToResume.Count == 0) { return(jvmtiError.None); } jthread[] requestList = threadsToResume.Select(i => i.Item2.Value).ToArray(); jvmtiError[] intermediateErrors = new jvmtiError[requestList.Length]; jvmtiError error = RawInterface.ResumeThreadList(this, requestList.Length, requestList, intermediateErrors); for (int i = 0; i < intermediateErrors.Length; i++) { errors[threadsToResume[i].Item1] = intermediateErrors[i]; if (error != jvmtiError.None || intermediateErrors[i] != jvmtiError.None) { VirtualMachine.SuspendCounts.AddOrUpdate(threads[threadsToResume[i].Item1], 0, (existingId, existingValue) => existingValue + 1); } } foreach (var referencePair in threadsToResume) { referencePair.Item2.Dispose(); } return(error); }
public jvmtiError GetMethodName(MethodId methodId, out string name, out string signature, out string genericSignature) { name = null; signature = null; genericSignature = null; IntPtr namePtr; IntPtr signaturePtr; IntPtr genericPtr; jvmtiError error = RawInterface.GetMethodName(this, new jmethodID((IntPtr)methodId.Handle), 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); }
public jvmtiError ResumeThreads(JniEnvironment nativeEnvironment, ThreadId[] threads, out jvmtiError[] errors) { List<Tuple<int, LocalThreadReferenceHolder>> threadsToResume = new List<Tuple<int, LocalThreadReferenceHolder>>(); errors = new jvmtiError[threads.Length]; for (int i = 0; i < threads.Length; i++) { LocalThreadReferenceHolder thread; errors[i] = VirtualMachine.GetLocalReferenceForThread(nativeEnvironment, threads[i], out thread); if (errors[i] == jvmtiError.None && thread.IsAlive) { int suspendCount = VirtualMachine.SuspendCounts.AddOrUpdate(threads[i], 0, (existingId, existingValue) => existingValue - 1); if (suspendCount == 0) threadsToResume.Add(Tuple.Create(i, thread)); } } if (threadsToResume.Count == 0) return jvmtiError.None; jthread[] requestList = threadsToResume.Select(i => i.Item2.Value).ToArray(); jvmtiError[] intermediateErrors = new jvmtiError[requestList.Length]; jvmtiError error = RawInterface.ResumeThreadList(this, requestList.Length, requestList, intermediateErrors); for (int i = 0; i < intermediateErrors.Length; i++) { errors[threadsToResume[i].Item1] = intermediateErrors[i]; if (error != jvmtiError.None || intermediateErrors[i] != jvmtiError.None) VirtualMachine.SuspendCounts.AddOrUpdate(threads[threadsToResume[i].Item1], 0, (existingId, existingValue) => existingValue + 1); } foreach (var referencePair in threadsToResume) referencePair.Item2.Dispose(); return error; }
internal static Error GetStandardError(jvmtiError internalError) { switch (internalError) { case jvmtiError.None: return Error.None; case jvmtiError.NullPointer: return Error.NullPointer; case jvmtiError.OutOfMemory: return Error.OutOfMemory; case jvmtiError.AccessDenied: return Error.AccessDenied; case jvmtiError.UnattachedThread: return Error.UnattachedThread; case jvmtiError.InvalidPriority: return Error.InvalidPriority; case jvmtiError.ThreadNotSuspended: return Error.ThreadNotSuspended; case jvmtiError.ThreadSuspended: return Error.ThreadSuspended; case jvmtiError.ClassNotPrepared: return Error.ClassNotPrepared; case jvmtiError.NoMoreFrames: return Error.NoMoreFrames; case jvmtiError.OpaqueFrame: return Error.OpaqueFrame; case jvmtiError.Duplicate: return Error.Duplicate; case jvmtiError.NotFound: return Error.NotFound; case jvmtiError.NotMonitorOwner: return Error.NotMonitorOwner; case jvmtiError.Interrupt: return Error.Interrupt; case jvmtiError.AbsentInformation: return Error.AbsentInformation; case jvmtiError.InvalidEventType: return Error.InvalidEventType; case jvmtiError.NativeMethod: return Error.NativeMethod; case jvmtiError.ClassLoaderUnsupported: return Error.InvalidClassLoader; case jvmtiError.InvalidThread: return Error.InvalidThread; case jvmtiError.InvalidFieldid: return Error.InvalidFieldid; case jvmtiError.InvalidMethodid: return Error.InvalidMethodid; case jvmtiError.InvalidLocation: return Error.InvalidLocation; case jvmtiError.InvalidObject: return Error.InvalidObject; case jvmtiError.InvalidClass: return Error.InvalidClass; case jvmtiError.TypeMismatch: return Error.TypeMismatch; case jvmtiError.InvalidSlot: return Error.InvalidSlot; case jvmtiError.InvalidThreadGroup: return Error.InvalidThreadGroup; case jvmtiError.InvalidMonitor: return Error.InvalidMonitor; case jvmtiError.IllegalArgument: return Error.IllegalArgument; case jvmtiError.InvalidTypestate: return Error.InvalidTypestate; case jvmtiError.UnsupportedVersion: return Error.UnsupportedVersion; case jvmtiError.InvalidClassFormat: return Error.InvalidClassFormat; case jvmtiError.CircularClassDefinition: return Error.CircularClassDefinition; case jvmtiError.FailsVerification: return Error.FailsVerification; case jvmtiError.NamesDontMatch: return Error.NamesDontMatch; case jvmtiError.UnsupportedRedefinitionMethodAdded: return Error.AddMethodNotImplemented; case jvmtiError.UnsupportedRedefinitionSchemaChanged: return Error.SchemaChangeNotImplemented; case jvmtiError.UnsupportedRedefinitionHierarchyChanged: return Error.HierarchyChangeNotImplemented; case jvmtiError.UnsupportedRedefinitionMethodDeleted: return Error.DeleteMethodNotImplemented; case jvmtiError.UnsupportedRedefinitionClassModifiersChanged: return Error.ClassModifiersChangeNotImplemented; case jvmtiError.UnsupportedRedefinitionMethodModifiersChanged: return Error.MethodModifiersChangeNotImplemented; case jvmtiError.Internal: return Error.Internal; case jvmtiError.MustPossessCapability: return Error.NotImplemented; case jvmtiError.ThreadNotAlive: case jvmtiError.InvalidEnvironment: case jvmtiError.UnmodifiableClass: case jvmtiError.WrongPhase: case jvmtiError.NotAvailable: default: return Error.Internal; } }