ICorProfilerCallback::JITCompilationStarted Method

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

Syntax

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

Parameters

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

fIsSafeToBlock [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.

Remarks

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 common intermediate language (CIL) code for method A by calling the ICorProfilerInfo::SetILFunctionBody method, it must do so for both JITCompilationStarted events, but it may use the same CIL 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.

Requirements

Platforms: See System Requirements.

Header: CorProf.idl, CorProf.h

Library: CorGuids.lib

.NET Framework Versions: Available since 2.0

See also