locked
Must the MSIL block passed to SetILFunctionBody be the EXACT memory address used in a previous JITCompilationStarted callback? RRS feed

  • Question

  • The JITCompilationStarted documentation states:

    "If the profiler is going to replace Microsoft intermediate language (MSIL) code for method A by calling theICorProfilerInfo::SetILFunctionBody method, it must do so for both JITCompilationStarted events, but it may use the same MSIL block for both."

    Does "MSIL block" mean the same exact memory address?  Or could I pass it the same method body bytes but have it located at a different address returned from IMethodMalloc::Alloc?

    Jeffrey



    • Edited by Jeffrey__ Tuesday, October 9, 2012 9:07 PM Added quotes
    Tuesday, October 9, 2012 8:20 PM

Answers

  • Hi, all.

    Correct.  The intent is that whatever pointers you give to the CLR always point to the same IL code bytes.  The memory that the pointers point to may be at different addresses, so long as the content residing at those addresses (the IL code bytes) are the same.  So you're free to allocate as many identical blocks of code as you like, and use them all.

    Thanks,
    Dave

    • Marked as answer by Jeffrey__ Monday, October 15, 2012 1:27 PM
    Thursday, October 11, 2012 11:49 PM

All replies

  • Hi Jeffrey,

    Welcome to the MSDN Forum.

    >>Does "MSIL block" mean the same exact memory address?

    Based on my understanding, it means the MSIL code mentioned at previous sentence.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, October 10, 2012 11:42 AM
    Moderator
  • So if I use IMethodMalloc::Alloc to allocate memory for my new 'MSIL block' (i.e., method header, IL code, exception clauses) and pass that address to SetILFunctionBody... the next time JITCompilationStarted callback occurs for the same FunctionID, I won't run into any problems by calling IMethodMalloc::Alloc again as long as I give the same 'MSIL block' (even though IMethodMalloc::Alloc will surely give me a new address), correct?
    • Edited by Jeffrey__ Wednesday, October 10, 2012 3:13 PM
    Wednesday, October 10, 2012 3:12 PM
  • That is how I understand it and have implemented it with OpenCover
    Thursday, October 11, 2012 3:28 AM
  • Hi, all.

    Correct.  The intent is that whatever pointers you give to the CLR always point to the same IL code bytes.  The memory that the pointers point to may be at different addresses, so long as the content residing at those addresses (the IL code bytes) are the same.  So you're free to allocate as many identical blocks of code as you like, and use them all.

    Thanks,
    Dave

    • Marked as answer by Jeffrey__ Monday, October 15, 2012 1:27 PM
    Thursday, October 11, 2012 11:49 PM