Steven Gong wrote:
Is the sampling process done before running or during runtime?
The sampling is done at runtime.
(There is not much advantage in using anything other than full
optimization for anything that is compiled ahead of time. However, even
ahead of time compiled methods, such as the boot image, can benefit from
profile information gathered during previous runs).
If it's done
during runtime, does it mean that some methods may be compiled several times
by different leveled JIT?
In the case of the compile only systems (Jikes RVM, J Rocket, etc), this
means that when a method is first encountered at runtime, it gets
baselined compiled (at very low cost by a very cheap compiler), and then
may subsequently be opt-compiled. Jikes RVM has three levels of
optimization O0, O1, & O2 (progressively more expensive and
progressively more heavily optimized). As Mike said, some cost-benefit
analysis is done to determine whether recompilation is likely to be a win.
A similar situation exists for systems which mix interpretation and
compilation, except the first phase is interpretation...
This gradual tuning and focussing of compilation effort is aided by
instrumentation gathered at runtime. This allows these compilers to
perform dynamic optimizations, some of which an ahead of time compiler
could only perform with the aid of profiles, and others of which are
generally not possible (microarchitecture-specific optimizations).
This is covered in much greater depth in the tutorials which are on the
wiki.
--Steve