This documentation is archived and is not being maintained.

ICorProfilerCallback::JITCompilationStarted Method

Notifies the profiler that the just-in-time (JIT) compiler has started to compile a function.

HRESULT JITCompilationStarted(
    [in] FunctionID functionId,
    [in] BOOL       fIsSafeToBlock);


[in] The ID of the function for which the compilation is starting.


[in] A value indicating to the profiler whether blocking will affect the operation of the runtime. The value is true if blocking may cause the runtime to wait for the calling thread to return from this callback; otherwise, false.

Although a value of true will not harm the runtime, it can skew the profiling results.

It is possible to receive more than one pair of JITCompilationStarted and ICorProfilerCallback::JITCompilationFinished calls for each function because of the way the runtime handles class constructors. For example, the runtime starts to JIT-compile method A, but the class constructor for class B needs to be run. Therefore, the runtime JIT-compiles the constructor for class B and runs it. While the constructor is running, it makes a call to method A, which causes method A to be JIT-compiled again. In this scenario, the first JIT compilation of method A is halted. However, both attempts to JIT-compile method A are reported with JIT-compilation events. If the profiler is going to replace Microsoft intermediate language (MSIL) code for method A by calling the ICorProfilerInfo::SetILFunctionBody method, it must do so for both JITCompilationStarted events, but it may use the same MSIL block for both.

Profilers must support the sequence of JIT callbacks in cases where two threads are simultaneously making callbacks. For example, thread A calls JITCompilationStarted. However, before thread A calls JITCompilationFinished, thread B calls ICorProfilerCallback::ExceptionSearchFunctionEnter with the function ID from thread A's JITCompilationStarted callback. It might appear that the function ID should not yet be valid because a call to JITCompilationFinished had not yet been received by the profiler. However, in a case like this one, the function ID is valid.

Platforms: See .NET Framework System Requirements.

Header: CorProf.idl, CorProf.h

Library: CorGuids.lib

.NET Framework Versions: 4, 3.5 SP1, 3.5, 3.0 SP1, 3.0, 2.0 SP1, 2.0