diff --git a/src/Agent/NewRelic/Agent/Core/ProfilerAgentMethodCallCache.cs b/src/Agent/NewRelic/Agent/Core/ProfilerAgentMethodInvoker.cs similarity index 96% rename from src/Agent/NewRelic/Agent/Core/ProfilerAgentMethodCallCache.cs rename to src/Agent/NewRelic/Agent/Core/ProfilerAgentMethodInvoker.cs index 5dcbcb25f3..f5684b70b6 100644 --- a/src/Agent/NewRelic/Agent/Core/ProfilerAgentMethodCallCache.cs +++ b/src/Agent/NewRelic/Agent/Core/ProfilerAgentMethodInvoker.cs @@ -9,9 +9,9 @@ namespace NewRelic.Agent.Core { /// - /// Cache of the Agent methods that can be invoked by the byte-code injected by the profiler. + /// The class used by the byte-code injected by the profiler to invoke arbitrary methods defined in the managed agent. /// - public class ProfilerAgentMethodCallCache + public class ProfilerAgentMethodInvoker { private static readonly ConcurrentDictionary> _invokerCache = new ConcurrentDictionary>(); @@ -24,7 +24,7 @@ public class ProfilerAgentMethodCallCache /// A reference to the method that is used to invoked the requrested agent method. The result is treated as an object /// to simplify the type definition injected by the profiler to store this reference. /// - public static object GetInvokerFromCache() + public static object GetInvoker() { return (Func)GetAndInvokeMethodFromCache; } diff --git a/src/Agent/NewRelic/Profiler/MethodRewriter/ApiFunctionManipulator.h b/src/Agent/NewRelic/Profiler/MethodRewriter/ApiFunctionManipulator.h index 0b11c9a87a..f70d0f5ec9 100644 --- a/src/Agent/NewRelic/Profiler/MethodRewriter/ApiFunctionManipulator.h +++ b/src/Agent/NewRelic/Profiler/MethodRewriter/ApiFunctionManipulator.h @@ -47,19 +47,14 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter { if (_agentCallStrategy == AgentCallStyle::Strategy::InAgentCache) { - // Ensure that the managed agent is loaded - _instructions->AppendString(_instrumentationSettings->GetCorePath()); - _instructions->Append(_X("call void [") + _instructions->GetCoreLibAssemblyName() + _X("]System.CannotUnloadAppDomainException::EnsureInitialized(string)")); - - // Get the Func holding a reference to the ProfilerAgentMethodCallCache.GetAndInvokeMethodFromCache method - _instructions->Append(_X("call object [") + _instructions->GetCoreLibAssemblyName() + _X("]System.CannotUnloadAppDomainException::GetMethodCacheLookupMethod()")); - _instructions->Append(CEE_CASTCLASS, _X("class [") + _instructions->GetCoreLibAssemblyName() + _X("]System.Func`7GetCoreLibAssemblyName() + _X("]System.Type[], class [") + _instructions->GetCoreLibAssemblyName() + _X("]System.Type, object[], object>")); + // result = System.CannotUnloadAppDomainException.InvokeAgentMethodInvokerFunc("C:\path\to\NewRelic.Agent.Core", "NewRelic_Delegate_API_", "NewRelic.Core.AgentApi", "", new System.Type[] { }, , new object[] { }) xstring_t className = _X("NewRelic.Agent.Core.AgentApi"); xstring_t methodName = _function->GetFunctionName(); xstring_t keyName = className + _X(".") + methodName + _X("_") + to_xstring((unsigned long)_function->GetFunctionId()); auto argumentTypesLambda = GetArrayOfTypeParametersLamdba(); + _instructions->AppendString(_instrumentationSettings->GetCorePath()); _instructions->AppendString(keyName); _instructions->AppendString(className); _instructions->AppendString(methodName); @@ -77,7 +72,7 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter BuildObjectArrayOfParameters(); - _instructions->Append(CEE_CALLVIRT, _X("instance !6 class [") + _instructions->GetCoreLibAssemblyName() + _X("]System.Func`7GetCoreLibAssemblyName() + _X("]System.Type[], class [") + _instructions->GetCoreLibAssemblyName() + _X("]System.Type, object[], object>::Invoke(!0, !1, !2, !3, !4, !5)")); + _instructions->Append(_X("call object [") + _instructions->GetCoreLibAssemblyName() + _X("]System.CannotUnloadAppDomainException::InvokeAgentMethodInvokerFunc(string, string, string, string, class [") + _instructions->GetCoreLibAssemblyName() + _X("]System.Type[], class [") + _instructions->GetCoreLibAssemblyName() + _X("]System.Type, object[])")); if (_methodSignature->_returnType->_kind == SignatureParser::ReturnType::Kind::VOID_RETURN_TYPE) { diff --git a/src/Agent/NewRelic/Profiler/MethodRewriter/HelperFunctionManipulator.h b/src/Agent/NewRelic/Profiler/MethodRewriter/HelperFunctionManipulator.h index d200b97573..3885492b97 100644 --- a/src/Agent/NewRelic/Profiler/MethodRewriter/HelperFunctionManipulator.h +++ b/src/Agent/NewRelic/Profiler/MethodRewriter/HelperFunctionManipulator.h @@ -50,25 +50,25 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter { BuildEnsureInitializedMethod(); } - else if (_function->GetFunctionName() == _X("GetMethodCacheLookupMethod")) + else if (_function->GetFunctionName() == _X("GetAgentMethodInvokerObject")) { - BuildGetMethodCacheLookupMethodMethod(); + BuildGetAgentMethodInvokerObject(); } - else if (_function->GetFunctionName() == _X("GetAgentShimFinishTracerDelegateMethod")) + else if (_function->GetFunctionName() == _X("GetAgentShimFinishTracerDelegateFunc")) { - BuildGetAgentShimFinishTracerDelegateMethod(); + BuildGetAgentShimFinishTracerDelegateFunc(); } - else if (_function->GetFunctionName() == _X("GetMethodInfoFromAgentCache")) + else if (_function->GetFunctionName() == _X("InvokeAgentMethodInvokerFunc")) { - BuildGetMethodInfoFromAgentCache(); + BuildInvokeAgentMethodInvokerFunc(); } - else if (_function->GetFunctionName() == _X("StoreMethodCacheLookupMethod")) + else if (_function->GetFunctionName() == _X("StoreAgentMethodInvokerFunc")) { - BuildStoreMethodCacheLookupMethod(); + BuildStoreAgentMethodInvokerFunc(); } - else if (_function->GetFunctionName() == _X("StoreAgentShimFinishTracerDelegateMethod")) + else if (_function->GetFunctionName() == _X("StoreAgentShimFinishTracerDelegateFunc")) { - BuildStoreAgentShimFinishTracerDelegateMethod(); + BuildStoreAgentShimFinishTracerDelegateFunc(); } else { @@ -176,42 +176,45 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter _instructions->Append(CEE_RET); } - void BuildGetMethodInfoFromAgentCache() + // resultObject InvokeAgentMethodInvokerFunc(string assemblyPath, string storageKey, string typeName, string methodName, Type[] parameterTypes, Type returnType, object[] methodParameters) + void BuildInvokeAgentMethodInvokerFunc() { - _instructions->Append(CEE_LDARG_1); + _instructions->Append(CEE_LDARG_0); _instructions->Append(_X("call void System.CannotUnloadAppDomainException::EnsureInitialized(string)")); - _instructions->Append(_X("call object System.CannotUnloadAppDomainException::GetMethodCacheLookupMethod()")); + _instructions->Append(_X("call object System.CannotUnloadAppDomainException::GetAgentMethodInvokerObject()")); - _instructions->Append(CEE_CASTCLASS, _X("class System.Func`5")); - _instructions->Append(CEE_LDARG_0); + _instructions->Append(CEE_CASTCLASS, _X("class System.Func`7")); + _instructions->Append(CEE_LDARG_1); _instructions->Append(CEE_LDARG_2); _instructions->Append(CEE_LDARG_3); _instructions->Append(CEE_LDARG_S, (uint8_t)4); - _instructions->Append(CEE_CALLVIRT, _X("instance !4 class System.Func`5::Invoke(!0, !1, !2, !3)")); + _instructions->Append(CEE_LDARG_S, (uint8_t)5); + _instructions->Append(CEE_LDARG_S, (uint8_t)6); + _instructions->Append(CEE_CALLVIRT, _X("instance !6 class System.Func`7::Invoke(!0, !1, !2, !3, !4, !5)")); _instructions->Append(CEE_RET); } - void BuildGetMethodCacheLookupMethodMethod() + void BuildGetAgentMethodInvokerObject() { _instructions->Append(CEE_VOLATILE); _instructions->Append(CEE_LDSFLD, _X("object __NRInitializer__::_methodCache")); _instructions->Append(CEE_RET); } - void BuildGetAgentShimFinishTracerDelegateMethod() + void BuildGetAgentShimFinishTracerDelegateFunc() { _instructions->Append(CEE_VOLATILE); _instructions->Append(CEE_LDSFLD, _X("object __NRInitializer__::_tracerFunc")); _instructions->Append(CEE_RET); } - void BuildStoreMethodCacheLookupMethod() + void BuildStoreAgentMethodInvokerFunc() { _instructions->Append(CEE_LDARG_0); - _instructions->AppendString(_X("NewRelic.Agent.Core.ProfilerAgentMethodCallCache")); - _instructions->AppendString(_X("GetInvokerFromCache")); + _instructions->AppendString(_X("NewRelic.Agent.Core.ProfilerAgentMethodInvoker")); + _instructions->AppendString(_X("GetInvoker")); _instructions->Append(CEE_LDNULL); _instructions->Append(CEE_CALL, _X("class System.Reflection.MethodInfo System.CannotUnloadAppDomainException::GetMethodViaReflectionOrThrow(string,string,string,class System.Type[])")); @@ -224,7 +227,7 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter _instructions->Append(CEE_RET); } - void BuildStoreAgentShimFinishTracerDelegateMethod() + void BuildStoreAgentShimFinishTracerDelegateFunc() { _instructions->Append(CEE_LDARG_0); _instructions->AppendString(_X("NewRelic.Agent.Core.AgentShim")); @@ -248,10 +251,10 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter auto afterInit = _instructions->AppendJump(CEE_BRTRUE); _instructions->Append(CEE_LDARG_0); - _instructions->Append(_X("call void System.CannotUnloadAppDomainException::StoreAgentShimFinishTracerDelegateMethod(string)")); + _instructions->Append(_X("call void System.CannotUnloadAppDomainException::StoreAgentShimFinishTracerDelegateFunc(string)")); _instructions->Append(CEE_LDARG_0); - _instructions->Append(_X("call void System.CannotUnloadAppDomainException::StoreMethodCacheLookupMethod(string)")); + _instructions->Append(_X("call void System.CannotUnloadAppDomainException::StoreAgentMethodInvokerFunc(string)")); _instructions->AppendLabel(afterInit); diff --git a/src/Agent/NewRelic/Profiler/MethodRewriter/InstrumentFunctionManipulator.h b/src/Agent/NewRelic/Profiler/MethodRewriter/InstrumentFunctionManipulator.h index 00992edbb6..39d54a081e 100644 --- a/src/Agent/NewRelic/Profiler/MethodRewriter/InstrumentFunctionManipulator.h +++ b/src/Agent/NewRelic/Profiler/MethodRewriter/InstrumentFunctionManipulator.h @@ -168,7 +168,7 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter _instructions->Append(_X("call void [") + _instructions->GetCoreLibAssemblyName() + _X("]System.CannotUnloadAppDomainException::EnsureInitialized(string)")); // Get the Func holding a reference to NewRelic.Agent.Core.AgentShim.GetFinishTracerDelegateParameterWrapper - _instructions->Append(_X("call object [") + _instructions->GetCoreLibAssemblyName() + _X("]System.CannotUnloadAppDomainException::GetAgentShimFinishTracerDelegateMethod()")); + _instructions->Append(_X("call object [") + _instructions->GetCoreLibAssemblyName() + _X("]System.CannotUnloadAppDomainException::GetAgentShimFinishTracerDelegateFunc()")); _instructions->Append(CEE_CASTCLASS, _X("class [") + _instructions->GetCoreLibAssemblyName() + _X("]System.Func`2GetCoreLibAssemblyName() + _X("]System.Action`2GetCoreLibAssemblyName() + _X("]System.Exception>>")); } else diff --git a/src/Agent/NewRelic/Profiler/MethodRewriter/Instrumentors.h b/src/Agent/NewRelic/Profiler/MethodRewriter/Instrumentors.h index 97d0dbafbf..2fa7e21bb9 100644 --- a/src/Agent/NewRelic/Profiler/MethodRewriter/Instrumentors.h +++ b/src/Agent/NewRelic/Profiler/MethodRewriter/Instrumentors.h @@ -136,11 +136,11 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter function->GetFunctionName() != _X("GetMethodFromAppDomainStorage") && function->GetFunctionName() != _X("GetMethodFromAppDomainStorageOrReflectionOrThrow") && function->GetFunctionName() != _X("StoreMethodInAppDomainStorageOrThrow") && - function->GetFunctionName() != _X("GetMethodCacheLookupMethod") && - function->GetFunctionName() != _X("GetAgentShimFinishTracerDelegateMethod") && - function->GetFunctionName() != _X("GetMethodInfoFromAgentCache") && - function->GetFunctionName() != _X("StoreMethodCacheLookupMethod") && - function->GetFunctionName() != _X("StoreAgentShimFinishTracerDelegateMethod") && + function->GetFunctionName() != _X("InvokeAgentMethodInvokerFunc") && + function->GetFunctionName() != _X("GetAgentShimFinishTracerDelegateFunc") && + function->GetFunctionName() != _X("GetAgentMethodInvokerObject") && + function->GetFunctionName() != _X("StoreAgentMethodInvokerFunc") && + function->GetFunctionName() != _X("StoreAgentShimFinishTracerDelegateFunc") && function->GetFunctionName() != _X("EnsureInitialized")) return false; diff --git a/src/Agent/NewRelic/Profiler/MethodRewriter/MethodRewriter.h b/src/Agent/NewRelic/Profiler/MethodRewriter/MethodRewriter.h index 22fe06201c..44b7eb81c0 100644 --- a/src/Agent/NewRelic/Profiler/MethodRewriter/MethodRewriter.h +++ b/src/Agent/NewRelic/Profiler/MethodRewriter/MethodRewriter.h @@ -53,12 +53,12 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter { _instrumentedFunctionNames->emplace(_X("GetTypeViaReflectionOrThrow")); _instrumentedFunctionNames->emplace(_X("LoadAssemblyOrThrow")); _instrumentedFunctionNames->emplace(_X("StoreMethodInAppDomainStorageOrThrow")); - _instrumentedFunctionNames->emplace(_X("GetMethodCacheLookupMethod")); - _instrumentedFunctionNames->emplace(_X("GetAgentShimFinishTracerDelegateMethod")); - _instrumentedFunctionNames->emplace(_X("StoreAgentShimFinishTracerDelegateMethod")); - _instrumentedFunctionNames->emplace(_X("StoreMethodCacheLookupMethod")); + _instrumentedFunctionNames->emplace(_X("GetAgentMethodInvokerObject")); + _instrumentedFunctionNames->emplace(_X("GetAgentShimFinishTracerDelegateFunc")); + _instrumentedFunctionNames->emplace(_X("StoreAgentShimFinishTracerDelegateFunc")); + _instrumentedFunctionNames->emplace(_X("StoreAgentMethodInvokerObject")); _instrumentedFunctionNames->emplace(_X("EnsureInitialized")); - _instrumentedFunctionNames->emplace(_X("GetMethodInfoFromAgentCache")); + _instrumentedFunctionNames->emplace(_X("InvokeAgentMethodInvokerFunc")); auto instrumentationPoints = _instrumentationConfiguration->GetInstrumentationPoints(); diff --git a/src/Agent/NewRelic/Profiler/MethodRewriterTest/FunctionManipulatorTest.cpp b/src/Agent/NewRelic/Profiler/MethodRewriterTest/FunctionManipulatorTest.cpp index 75c3a6a57d..59317e30d1 100644 --- a/src/Agent/NewRelic/Profiler/MethodRewriterTest/FunctionManipulatorTest.cpp +++ b/src/Agent/NewRelic/Profiler/MethodRewriterTest/FunctionManipulatorTest.cpp @@ -204,19 +204,19 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter { namespace T manipulator.InstrumentHelper(); } - TEST_METHOD(helper_method_GetMethodCacheLookupMethod) + TEST_METHOD(helper_method_InvokeAgentMethodInvokerFunc) { auto function = std::make_shared(); - function->_functionName = _X("GetMethodCacheLookupMethod"); + function->_functionName = _X("InvokeAgentMethodInvokerFunc"); HelperFunctionManipulator manipulator(function, true, AgentCallStyle::Strategy::InAgentCache); manipulator.InstrumentHelper(); } - TEST_METHOD(helper_method_GetMethodInfoFromAgentCache) + TEST_METHOD(helper_method_GetAgentMethodInvokerObject) { auto function = std::make_shared(); - function->_functionName = _X("GetMethodInfoFromAgentCache"); + function->_functionName = _X("GetAgentMethodInvokerObject"); HelperFunctionManipulator manipulator(function, true, AgentCallStyle::Strategy::InAgentCache); manipulator.InstrumentHelper(); diff --git a/src/Agent/NewRelic/Profiler/MethodRewriterTest/InstrumentorsTest.cpp b/src/Agent/NewRelic/Profiler/MethodRewriterTest/InstrumentorsTest.cpp index c07dc9c42a..18ab663bc3 100644 --- a/src/Agent/NewRelic/Profiler/MethodRewriterTest/InstrumentorsTest.cpp +++ b/src/Agent/NewRelic/Profiler/MethodRewriterTest/InstrumentorsTest.cpp @@ -316,14 +316,14 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter { namespace T AssertHelperMethodIsInstrumented(true, _X("StoreMethodInAppDomainStorageOrThrow")); } - TEST_METHOD(HelperInstrumentor_CoreClr_ShouldInstrument_GetMethodCacheLookupMethod) + TEST_METHOD(HelperInstrumentor_CoreClr_ShouldInstrument_InvokeAgentMethodInvokerFunc) { - AssertHelperMethodIsInstrumented(true, _X("GetMethodCacheLookupMethod")); + AssertHelperMethodIsInstrumented(true, _X("InvokeAgentMethodInvokerFunc")); } - TEST_METHOD(HelperInstrumentor_CoreClr_ShouldInstrument_GetMethodInfoFromAgentCache) + TEST_METHOD(HelperInstrumentor_CoreClr_ShouldInstrument_GetAgentMethodInvokerObject) { - AssertHelperMethodIsInstrumented(true, _X("GetMethodInfoFromAgentCache")); + AssertHelperMethodIsInstrumented(true, _X("GetAgentMethodInvokerObject")); } TEST_METHOD(HelperInstrumentor_CoreClr_ShouldInstrument_EnsureInitialized) @@ -381,14 +381,14 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter { namespace T AssertHelperMethodIsInstrumented(false, _X("StoreMethodInAppDomainStorageOrThrow")); } - TEST_METHOD(HelperInstrumentor_NetFramework_ShouldInstrument_GetMethodCacheLookupMethod) + TEST_METHOD(HelperInstrumentor_NetFramework_ShouldInstrument_InvokeAgentMethodInvokerFunc) { - AssertHelperMethodIsInstrumented(false, _X("GetMethodCacheLookupMethod")); + AssertHelperMethodIsInstrumented(false, _X("InvokeAgentMethodInvokerFunc")); } - TEST_METHOD(HelperInstrumentor_NetFramework_ShouldInstrument_GetMethodInfoFromAgentCache) + TEST_METHOD(HelperInstrumentor_NetFramework_ShouldInstrument_GetAgentMethodInvokerObject) { - AssertHelperMethodIsInstrumented(false, _X("GetMethodInfoFromAgentCache")); + AssertHelperMethodIsInstrumented(false, _X("GetAgentMethodInvokerObject")); } TEST_METHOD(HelperInstrumentor_NetFramework_ShouldInstrument_EnsureInitialized) diff --git a/src/Agent/NewRelic/Profiler/MethodRewriterTest/MethodRewriterTest.cpp b/src/Agent/NewRelic/Profiler/MethodRewriterTest/MethodRewriterTest.cpp index ad0c99b85d..959c41555d 100644 --- a/src/Agent/NewRelic/Profiler/MethodRewriterTest/MethodRewriterTest.cpp +++ b/src/Agent/NewRelic/Profiler/MethodRewriterTest/MethodRewriterTest.cpp @@ -282,13 +282,13 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter { namespace T Assert::IsTrue(methodRewriter->ShouldInstrumentFunction(_X("StoreMethodInAppDomainStorageOrThrow"))); } - TEST_METHOD(ShouldInstrumentFunction_GetMethodCacheLookupMethod) + TEST_METHOD(ShouldInstrumentFunction_InvokeAgentMethodInvokerFunc) { auto function = std::make_shared(); auto methodRewriter = GetMethodRewriterWithConfigurationForFunction(function); - Assert::IsTrue(methodRewriter->ShouldInstrumentFunction(_X("GetMethodCacheLookupMethod"))); + Assert::IsTrue(methodRewriter->ShouldInstrumentFunction(_X("InvokeAgentMethodInvokerFunc"))); } TEST_METHOD(ShouldInstrumentFunction_EnsureInitialized) @@ -300,13 +300,13 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter { namespace T Assert::IsTrue(methodRewriter->ShouldInstrumentFunction(_X("EnsureInitialized"))); } - TEST_METHOD(ShouldInstrumentFunction_GetMethodInfoFromAgentCache) + TEST_METHOD(ShouldInstrumentFunction_GetAgentMethodInvokerObject) { auto function = std::make_shared(); auto methodRewriter = GetMethodRewriterWithConfigurationForFunction(function); - Assert::IsTrue(methodRewriter->ShouldInstrumentFunction(_X("GetMethodInfoFromAgentCache"))); + Assert::IsTrue(methodRewriter->ShouldInstrumentFunction(_X("GetAgentMethodInvokerObject"))); } private: diff --git a/src/Agent/NewRelic/Profiler/ModuleInjector/ModuleInjector.h b/src/Agent/NewRelic/Profiler/ModuleInjector/ModuleInjector.h index 4acb433b2a..0f95dee941 100644 --- a/src/Agent/NewRelic/Profiler/ModuleInjector/ModuleInjector.h +++ b/src/Agent/NewRelic/Profiler/ModuleInjector/ModuleInjector.h @@ -42,12 +42,12 @@ namespace NewRelic { namespace Profiler { namespace ModuleInjector ManagedMethodToInject(_X("[System.Private.CoreLib]System.CannotUnloadAppDomainException"), _X("GetMethodFromAppDomainStorage"), _X("class [System.Private.CoreLib]System.Reflection.MethodInfo"), _X("string")), ManagedMethodToInject(_X("[System.Private.CoreLib]System.CannotUnloadAppDomainException"), _X("GetMethodFromAppDomainStorageOrReflectionOrThrow"), _X("class [System.Private.CoreLib]System.Reflection.MethodInfo"), _X("string,string,string,string,class [System.Private.CoreLib]System.Type[]")), ManagedMethodToInject(_X("[System.Private.CoreLib]System.CannotUnloadAppDomainException"), _X("StoreMethodInAppDomainStorageOrThrow"), _X("void"), _X("class [System.Private.CoreLib]System.Reflection.MethodInfo,string")), - ManagedMethodToInject(_X("[System.Private.CoreLib]System.CannotUnloadAppDomainException"), _X("StoreMethodCacheLookupMethod"), _X("void"), _X("string")), - ManagedMethodToInject(_X("[System.Private.CoreLib]System.CannotUnloadAppDomainException"), _X("StoreAgentShimFinishTracerDelegateMethod"), _X("void"), _X("string")), + ManagedMethodToInject(_X("[System.Private.CoreLib]System.CannotUnloadAppDomainException"), _X("StoreAgentMethodInvokerFunc"), _X("void"), _X("string")), + ManagedMethodToInject(_X("[System.Private.CoreLib]System.CannotUnloadAppDomainException"), _X("StoreAgentShimFinishTracerDelegateFunc"), _X("void"), _X("string")), ManagedMethodToInject(_X("[System.Private.CoreLib]System.CannotUnloadAppDomainException"),_X("EnsureInitialized"), _X("void"), _X("string")), - ManagedMethodToInject(_X("[System.Private.CoreLib]System.CannotUnloadAppDomainException"), _X("GetMethodInfoFromAgentCache"), _X("class [System.Private.CoreLib]System.Reflection.MethodInfo"), _X("string,string,string,string,class [System.Private.CoreLib]System.Type[]")), - ManagedMethodToInject(_X("[System.Private.CoreLib]System.CannotUnloadAppDomainException"), _X("GetMethodCacheLookupMethod"), _X("object"), _X("")), - ManagedMethodToInject(_X("[System.Private.CoreLib]System.CannotUnloadAppDomainException"), _X("GetAgentShimFinishTracerDelegateMethod"), _X("object"), _X("")) + ManagedMethodToInject(_X("[System.Private.CoreLib]System.CannotUnloadAppDomainException"), _X("InvokeAgentMethodInvokerFunc"), _X("object"), _X("string,string,string,string,class [System.Private.CoreLib]System.Type[],class [System.Private.CoreLib]System.Type,object[]")), + ManagedMethodToInject(_X("[System.Private.CoreLib]System.CannotUnloadAppDomainException"), _X("GetAgentMethodInvokerObject"), _X("object"), _X("")), + ManagedMethodToInject(_X("[System.Private.CoreLib]System.CannotUnloadAppDomainException"), _X("GetAgentShimFinishTracerDelegateFunc"), _X("object"), _X("")) }; // When injecting method REFERENCES into an assembly, theses references should have @@ -59,12 +59,12 @@ namespace NewRelic { namespace Profiler { namespace ModuleInjector ManagedMethodToInject(_X("[mscorlib]System.CannotUnloadAppDomainException"), _X("GetMethodFromAppDomainStorage"), _X("class [mscorlib]System.Reflection.MethodInfo"), _X("string")), ManagedMethodToInject(_X("[mscorlib]System.CannotUnloadAppDomainException"), _X("GetMethodFromAppDomainStorageOrReflectionOrThrow"), _X("class [mscorlib]System.Reflection.MethodInfo"), _X("string,string,string,string,class [mscorlib]System.Type[]")), ManagedMethodToInject(_X("[mscorlib]System.CannotUnloadAppDomainException"), _X("StoreMethodInAppDomainStorageOrThrow"), _X("void"), _X("class [mscorlib]System.Reflection.MethodInfo,string")), - ManagedMethodToInject(_X("[mscorlib]System.CannotUnloadAppDomainException"), _X("StoreMethodCacheLookupMethod"), _X("void"), _X("string")), - ManagedMethodToInject(_X("[mscorlib]System.CannotUnloadAppDomainException"), _X("StoreAgentShimFinishTracerDelegateMethod"), _X("void"), _X("string")), + ManagedMethodToInject(_X("[mscorlib]System.CannotUnloadAppDomainException"), _X("StoreAgentMethodInvokerFunc"), _X("void"), _X("string")), + ManagedMethodToInject(_X("[mscorlib]System.CannotUnloadAppDomainException"), _X("StoreAgentShimFinishTracerDelegateFunc"), _X("void"), _X("string")), ManagedMethodToInject(_X("[mscorlib]System.CannotUnloadAppDomainException"), _X("EnsureInitialized"), _X("void"), _X("string")), - ManagedMethodToInject(_X("[mscorlib]System.CannotUnloadAppDomainException"), _X("GetMethodInfoFromAgentCache"), _X("class [mscorlib]System.Reflection.MethodInfo"), _X("string,string,string,string,class [mscorlib]System.Type[]")), - ManagedMethodToInject(_X("[mscorlib]System.CannotUnloadAppDomainException"), _X("GetMethodCacheLookupMethod"), _X("object"), _X("")), - ManagedMethodToInject(_X("[mscorlib]System.CannotUnloadAppDomainException"), _X("GetAgentShimFinishTracerDelegateMethod"), _X("object"), _X("")) + ManagedMethodToInject(_X("[mscorlib]System.CannotUnloadAppDomainException"), _X("InvokeAgentMethodInvokerFunc"), _X("object"), _X("string,string,string,string,class [mscorlib]System.Type[],class [mscorlib]System.Type,object[]")), + ManagedMethodToInject(_X("[mscorlib]System.CannotUnloadAppDomainException"), _X("GetAgentMethodInvokerObject"), _X("object"), _X("")), + ManagedMethodToInject(_X("[mscorlib]System.CannotUnloadAppDomainException"), _X("GetAgentShimFinishTracerDelegateFunc"), _X("object"), _X("")) }; // When injecting HELPER METHODS into the Core Lib assembly, theses references should be local. @@ -76,12 +76,12 @@ namespace NewRelic { namespace Profiler { namespace ModuleInjector ManagedMethodToInject(_X("System.CannotUnloadAppDomainException"), _X("GetMethodFromAppDomainStorage"), _X("class System.Reflection.MethodInfo"), _X("string")), ManagedMethodToInject(_X("System.CannotUnloadAppDomainException"), _X("GetMethodFromAppDomainStorageOrReflectionOrThrow"), _X("class System.Reflection.MethodInfo"), _X("string,string,string,string,class System.Type[]")), ManagedMethodToInject(_X("System.CannotUnloadAppDomainException"), _X("StoreMethodInAppDomainStorageOrThrow"), _X("void"), _X("class System.Reflection.MethodInfo,string")), - ManagedMethodToInject(_X("System.CannotUnloadAppDomainException"), _X("StoreMethodCacheLookupMethod"), _X("void"), _X("string")), - ManagedMethodToInject(_X("System.CannotUnloadAppDomainException"), _X("StoreAgentShimFinishTracerDelegateMethod"), _X("void"), _X("string")), + ManagedMethodToInject(_X("System.CannotUnloadAppDomainException"), _X("StoreAgentMethodInvokerFunc"), _X("void"), _X("string")), + ManagedMethodToInject(_X("System.CannotUnloadAppDomainException"), _X("StoreAgentShimFinishTracerDelegateFunc"), _X("void"), _X("string")), ManagedMethodToInject(_X("System.CannotUnloadAppDomainException"), _X("EnsureInitialized"), _X("void"), _X("string")), - ManagedMethodToInject(_X("System.CannotUnloadAppDomainException"), _X("GetMethodInfoFromAgentCache"), _X("class System.Reflection.MethodInfo"), _X("string,string,string,string,class System.Type[]")), - ManagedMethodToInject(_X("System.CannotUnloadAppDomainException"), _X("GetMethodCacheLookupMethod"), _X("object"), _X("")), - ManagedMethodToInject(_X("System.CannotUnloadAppDomainException"), _X("GetAgentShimFinishTracerDelegateMethod"), _X("object"), _X("")) + ManagedMethodToInject(_X("System.CannotUnloadAppDomainException"), _X("InvokeAgentMethodInvokerFunc"), _X("object"), _X("string,string,string,string,class System.Type[],class System.Type,object[]")), + ManagedMethodToInject(_X("System.CannotUnloadAppDomainException"), _X("GetAgentMethodInvokerObject"), _X("object"), _X("")), + ManagedMethodToInject(_X("System.CannotUnloadAppDomainException"), _X("GetAgentShimFinishTracerDelegateFunc"), _X("object"), _X("")) }; const auto is_coreLib = module.GetIsThisTheCoreLibAssembly(); diff --git a/src/Agent/NewRelic/Profiler/ModuleInjectorTest/ModuleInjectorTest.cpp b/src/Agent/NewRelic/Profiler/ModuleInjectorTest/ModuleInjectorTest.cpp index b4fe3c360f..0e741a6162 100644 --- a/src/Agent/NewRelic/Profiler/ModuleInjectorTest/ModuleInjectorTest.cpp +++ b/src/Agent/NewRelic/Profiler/ModuleInjectorTest/ModuleInjectorTest.cpp @@ -138,11 +138,11 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter { namespace T _X("System.CannotUnloadAppDomainException.GetMethodFromAppDomainStorageOrReflectionOrThrow"), _X("System.CannotUnloadAppDomainException.StoreMethodInAppDomainStorageOrThrow"), _X("System.CannotUnloadAppDomainException.EnsureInitialized"), - _X("System.CannotUnloadAppDomainException.GetMethodInfoFromAgentCache"), - _X("System.CannotUnloadAppDomainException.GetMethodCacheLookupMethod"), - _X("System.CannotUnloadAppDomainException.GetAgentShimFinishTracerDelegateMethod"), - _X("System.CannotUnloadAppDomainException.StoreAgentShimFinishTracerDelegateMethod"), - _X("System.CannotUnloadAppDomainException.StoreMethodCacheLookupMethod") + _X("System.CannotUnloadAppDomainException.InvokeAgentMethodInvokerFunc"), + _X("System.CannotUnloadAppDomainException.GetAgentMethodInvokerObject"), + _X("System.CannotUnloadAppDomainException.GetAgentShimFinishTracerDelegateFunc"), + _X("System.CannotUnloadAppDomainException.StoreAgentShimFinishTracerDelegateFunc"), + _X("System.CannotUnloadAppDomainException.StoreAgentMethodInvokerFunc") }; auto modulePtr = std::make_shared(); @@ -184,11 +184,11 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter { namespace T expectedAssembly + _X("System.CannotUnloadAppDomainException.GetMethodFromAppDomainStorageOrReflectionOrThrow"), expectedAssembly + _X("System.CannotUnloadAppDomainException.StoreMethodInAppDomainStorageOrThrow"), expectedAssembly + _X("System.CannotUnloadAppDomainException.EnsureInitialized"), - expectedAssembly + _X("System.CannotUnloadAppDomainException.GetMethodInfoFromAgentCache"), - expectedAssembly + _X("System.CannotUnloadAppDomainException.GetMethodCacheLookupMethod"), - expectedAssembly + _X("System.CannotUnloadAppDomainException.GetAgentShimFinishTracerDelegateMethod"), - expectedAssembly + _X("System.CannotUnloadAppDomainException.StoreAgentShimFinishTracerDelegateMethod"), - expectedAssembly + _X("System.CannotUnloadAppDomainException.StoreMethodCacheLookupMethod") + expectedAssembly + _X("System.CannotUnloadAppDomainException.GetAgentMethodInvokerObject"), + expectedAssembly + _X("System.CannotUnloadAppDomainException.InvokeAgentMethodInvokerFunc"), + expectedAssembly + _X("System.CannotUnloadAppDomainException.GetAgentShimFinishTracerDelegateFunc"), + expectedAssembly + _X("System.CannotUnloadAppDomainException.StoreAgentShimFinishTracerDelegateFunc"), + expectedAssembly + _X("System.CannotUnloadAppDomainException.StoreAgentMethodInvokerFunc") }; auto modulePtr = std::make_shared(); diff --git a/tests/Agent/UnitTests/Core.UnitTest/ProfilerAgentMethodCallCacheTests.cs b/tests/Agent/UnitTests/Core.UnitTest/ProfilerAgentMethodInvokerTests.cs similarity index 91% rename from tests/Agent/UnitTests/Core.UnitTest/ProfilerAgentMethodCallCacheTests.cs rename to tests/Agent/UnitTests/Core.UnitTest/ProfilerAgentMethodInvokerTests.cs index 423afde1a3..587af727b5 100644 --- a/tests/Agent/UnitTests/Core.UnitTest/ProfilerAgentMethodCallCacheTests.cs +++ b/tests/Agent/UnitTests/Core.UnitTest/ProfilerAgentMethodInvokerTests.cs @@ -8,19 +8,19 @@ namespace NewRelic.Agent.Core { [TestFixture] - public class ProfilerAgentMethodCallCacheTests + public class ProfilerAgentMethodInvokerTests { [Test] public void GetMethodCacheFuncShouldReturnAFuncAsAnObject() { - var methodReference = ProfilerAgentMethodCallCache.GetInvokerFromCache(); + var methodReference = ProfilerAgentMethodInvoker.GetInvoker(); Assert.IsAssignableFrom(typeof(Func), methodReference); } [Test] public void ShouldInvokeMethodWithNoParameters() { - var invoker = (Func)ProfilerAgentMethodCallCache.GetInvokerFromCache(); + var invoker = (Func)ProfilerAgentMethodInvoker.GetInvoker(); var typeName = typeof(TestingClass).AssemblyQualifiedName; var methodName = nameof(TestingClass.MethodWithNoParams); @@ -39,7 +39,7 @@ public void ShouldInvokeMethodWithNoParameters() [Test] public void ShouldInvokeMethodWithParameters() { - var invoker = (Func)ProfilerAgentMethodCallCache.GetInvokerFromCache(); + var invoker = (Func)ProfilerAgentMethodInvoker.GetInvoker(); var typeName = typeof(TestingClass).AssemblyQualifiedName; var methodName = nameof(TestingClass.MethodWithParams); @@ -59,7 +59,7 @@ public void ShouldInvokeMethodWithParameters() [Test] public void ShouldInvokeWrongMethodIfCacheKeyNotUniqueEnough() { - var invoker = (Func)ProfilerAgentMethodCallCache.GetInvokerFromCache(); + var invoker = (Func)ProfilerAgentMethodInvoker.GetInvoker(); var typeName = typeof(TestingClass).AssemblyQualifiedName; var methodName = nameof(TestingClass.MethodWithOverload); @@ -77,7 +77,7 @@ public void ShouldInvokeWrongMethodIfCacheKeyNotUniqueEnough() [Test] public void ShouldHandleMethodsWithVoidReturnType() { - var invoker = (Func)ProfilerAgentMethodCallCache.GetInvokerFromCache(); + var invoker = (Func)ProfilerAgentMethodInvoker.GetInvoker(); var typeName = typeof(TestingClass).AssemblyQualifiedName;