Skip to content

Commit

Permalink
Remove references to ICorProfilerInfo10 (open-telemetry#2492)
Browse files Browse the repository at this point in the history
* Remove reference to ICorProfilerInfo10

* Remove redundant conditional compilation
  • Loading branch information
Kielek authored Apr 26, 2023
1 parent 3eabdb4 commit c594bc9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 46 deletions.
53 changes: 17 additions & 36 deletions src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,24 @@ HRESULT STDMETHODCALLTYPE CorProfiler::Initialize(IUnknown* cor_profiler_info_un
}
}

#if defined(ARM64) || defined(ARM)
//
// In ARM64 and ARM, complete ReJIT support is only available from .NET 5.0
//
ICorProfilerInfo12* info12;
HRESULT hrInfo12 = cor_profiler_info_unknown->QueryInterface(__uuidof(ICorProfilerInfo12), (void**)&info12);
if (SUCCEEDED(hrInfo12))
// get ICorProfilerInfo12 for >= .NET 5.0
ICorProfilerInfo12* info12 = nullptr;
HRESULT hr = cor_profiler_info_unknown->QueryInterface(__uuidof(ICorProfilerInfo12), (void**)&info12);
if (SUCCEEDED(hr))
{
Logger::Info(".NET 5.0 runtime or greater was detected.");
Logger::Debug("Interface ICorProfilerInfo12 found.");
this->info_ = info12;
}
else
{
Logger::Warn("Profiler disabled: .NET 5.0 runtime or greater is required on this "
"architecture.");
return E_FAIL;
}
#endif

// get ICorProfilerInfo7 interface for .NET Framework >= 4.6.1 and any .NET (Core)
HRESULT hr = cor_profiler_info_unknown->QueryInterface(__uuidof(ICorProfilerInfo7), (void**)&this->info_);
if (FAILED(hr))
{
Logger::Warn("Failed to attach profiler: Not supported .NET Framework version (lower than 4.6.1).");
return E_FAIL;
// get ICorProfilerInfo7 interface for .NET Framework >= 4.6.1 and any .NET (Core)
hr = cor_profiler_info_unknown->QueryInterface(__uuidof(ICorProfilerInfo7), (void**)&this->info_);
if (FAILED(hr))
{
Logger::Warn("Failed to attach profiler: Not supported .NET Framework version (lower than 4.6.1).");
return E_FAIL;
}
info12 = nullptr;
}

// code is ready to get runtime information
Expand All @@ -95,7 +89,7 @@ HRESULT STDMETHODCALLTYPE CorProfiler::Initialize(IUnknown* cor_profiler_info_un
{
if (runtime_information_.is_desktop())
{
// on .NET Framework it is the CLR version therfore major_version == 4 and minor_version == 0
// on .NET Framework it is the CLR version therefore major_version == 4 and minor_version == 0
Logger::Debug(".NET Runtime: .NET Framework");
}
else if (runtime_information_.major_version < 5)
Expand Down Expand Up @@ -177,22 +171,9 @@ HRESULT STDMETHODCALLTYPE CorProfiler::Initialize(IUnknown* cor_profiler_info_un
}
}

// get ICorProfilerInfo10 for >= .NET Core 3.0
ICorProfilerInfo10* info10 = nullptr;
hr = cor_profiler_info_unknown->QueryInterface(__uuidof(ICorProfilerInfo10), (void**)&info10);
if (SUCCEEDED(hr))
{
Logger::Debug("Interface ICorProfilerInfo10 found.");
}
else
{
info10 = nullptr;
}

auto pInfo = info10 != nullptr ? info10 : this->info_;
auto work_offloader = std::make_shared<RejitWorkOffloader>(pInfo);
auto work_offloader = std::make_shared<RejitWorkOffloader>(this->info_);

rejit_handler = info10 != nullptr ? std::make_shared<RejitHandler>(info10, work_offloader)
rejit_handler = info12 != nullptr ? std::make_shared<RejitHandler>(info12, work_offloader)
: std::make_shared<RejitHandler>(this->info_, work_offloader);
tracer_integration_preprocessor = std::make_unique<TracerRejitPreprocessor>(rejit_handler, work_offloader);

Expand Down
16 changes: 8 additions & 8 deletions src/OpenTelemetry.AutoInstrumentation.Native/rejit_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,23 +274,23 @@ void RejitHandler::RequestRejit(std::vector<ModuleID>& modulesVector, std::vecto
// Request ReJIT
// *************************************

if (m_profilerInfo10 != nullptr)
if (m_profilerInfo12 != nullptr)
{
// RequestReJITWithInliners is currently always failing with `Fatal error. Internal CLR error.
// (0x80131506)` more research is required, meanwhile we fallback to the normal RequestReJIT and
// manual track of inliners.

/*hr = m_profilerInfo10->RequestReJITWithInliners(COR_PRF_REJIT_BLOCK_INLINING, (ULONG)
/*hr = m_profilerInfo12->RequestReJITWithInliners(COR_PRF_REJIT_BLOCK_INLINING, (ULONG)
modulesVector.size(),
&modulesVector[0], &modulesMethodDef[0]); if (FAILED(hr))
{
Warn("Error requesting ReJITWithInliners for ", vtModules.size(),
" methods, falling back to a normal RequestReJIT");
hr = m_profilerInfo10->RequestReJIT((ULONG) modulesVector.size(), &modulesVector[0],
hr = m_profilerInfo12->RequestReJIT((ULONG) modulesVector.size(), &modulesVector[0],
&modulesMethodDef[0]);
}*/

hr = m_profilerInfo10->RequestReJIT((ULONG)modulesVector.size(), &modulesVector[0], &modulesMethodDef[0]);
hr = m_profilerInfo12->RequestReJIT((ULONG)modulesVector.size(), &modulesVector[0], &modulesMethodDef[0]);
}
else
{
Expand All @@ -313,14 +313,14 @@ void RejitHandler::RequestRejit(std::vector<ModuleID>& modulesVector, std::vecto
RejitHandler::RejitHandler(ICorProfilerInfo7* pInfo, std::shared_ptr<RejitWorkOffloader> work_offloader)
{
m_profilerInfo = pInfo;
m_profilerInfo10 = nullptr;
m_profilerInfo12 = nullptr;
m_work_offloader = work_offloader;
}

RejitHandler::RejitHandler(ICorProfilerInfo10* pInfo, std::shared_ptr<RejitWorkOffloader> work_offloader)
RejitHandler::RejitHandler(ICorProfilerInfo12* pInfo, std::shared_ptr<RejitWorkOffloader> work_offloader)
{
m_profilerInfo = pInfo;
m_profilerInfo10 = pInfo;
m_profilerInfo12 = pInfo;
m_work_offloader = work_offloader;
}

Expand Down Expand Up @@ -424,7 +424,7 @@ void RejitHandler::Shutdown()

m_modules.clear();
m_profilerInfo = nullptr;
m_profilerInfo10 = nullptr;
m_profilerInfo12 = nullptr;
}

bool RejitHandler::IsShutdownRequested()
Expand Down
4 changes: 2 additions & 2 deletions src/OpenTelemetry.AutoInstrumentation.Native/rejit_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class RejitHandler
AssemblyProperty* m_pCorAssemblyProperty = nullptr;

ICorProfilerInfo7* m_profilerInfo;
ICorProfilerInfo10* m_profilerInfo10;
ICorProfilerInfo12* m_profilerInfo12;

std::shared_ptr<RejitWorkOffloader> m_work_offloader;

Expand All @@ -139,7 +139,7 @@ class RejitHandler
void RequestRejitForInlinersInModule(ModuleID moduleId);
public:
RejitHandler(ICorProfilerInfo7* pInfo, std::shared_ptr<RejitWorkOffloader> work_offloader);
RejitHandler(ICorProfilerInfo10* pInfo, std::shared_ptr<RejitWorkOffloader> work_offloader);
RejitHandler(ICorProfilerInfo12* pInfo, std::shared_ptr<RejitWorkOffloader> work_offloader);

RejitHandlerModule* GetOrAddModule(ModuleID moduleId);
void SetEnableByRefInstrumentation(bool enableByRefInstrumentation);
Expand Down

0 comments on commit c594bc9

Please sign in to comment.