From 1fb72df62fa3ade459a0c9915765a886dcb40836 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 10 Oct 2022 17:13:46 +0200 Subject: [PATCH] SPMI: Return recorded base instrumentation data address (#76765) This comment has not been accurate since the switch to the schema-based PGO format. Today this buffer records only instrumentation data and only the generated code accesses it, so we can return the recorded address and fix one cause of spurious SPMI diffs. --- .../tools/superpmi/superpmi-shared/methodcontext.cpp | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp index 50dfcb7..9bc752a 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp @@ -5612,7 +5612,6 @@ HRESULT MethodContext::repAllocPgoInstrumentationBySchema( HRESULT result = (HRESULT)value.result; Agnostic_PgoInstrumentationSchema* pAgnosticSchema = (Agnostic_PgoInstrumentationSchema*)AllocPgoInstrumentationBySchema->GetBuffer(value.schema_index); - size_t maxOffset = 0; for (UINT32 iSchema = 0; iSchema < countSchemaItems && iSchema < value.countSchemaItems; iSchema++) { // Everything but `Offset` field is an IN argument, so verify it against what we stored (since we didn't use these @@ -5640,24 +5639,11 @@ HRESULT MethodContext::repAllocPgoInstrumentationBySchema( } pSchema[iSchema].Offset = (size_t)pAgnosticSchema[iSchema].Offset; - - if (pSchema[iSchema].Offset > maxOffset) - maxOffset = pSchema[iSchema].Offset; } - // Allocate a scratch buffer, linked to method context via AllocPgoInstrumentationBySchema, so it gets - // cleaned up when the method context does. - // - // We won't bother recording this via AddBuffer because currently SPMI will never look at it. - // But we need a writeable buffer because the jit will store IL offsets inside. - // - // Todo, perhaps: record the buffer as a compile result instead, and defer copying until - // jit completion so we can snapshot the offsets the jit writes. - // - // Add 16 bytes of represent writeable space - size_t bufSize = maxOffset + 16; - *pInstrumentationData = (BYTE*)AllocJitTempBuffer(bufSize); - cr->recAddressMap((void*)value.instrumentationDataAddress, (void*)*pInstrumentationData, (unsigned)bufSize); + // We assume JIT does not write or read from this buffer, only generate + // code that uses it. + *pInstrumentationData = (BYTE*)value.instrumentationDataAddress; return result; } -- 2.7.4