Yes, the simple hash function in footer.S is loose by design and will
definitely trigger false positive "hot" traces. Note, though, that
as far as triggering an actual trace compilation request, the hash
function here is only half of the test. This is the "first level" hot
trace filter. Look at the beginning of dvmCheckJitTraceRequest in
Jit.c and you will find the second level filter.
It goes something like this:
o When interpreting and we reach a potential trace head, hash rPC
and decrement counter. If zero, then we may have an interesting rPC.
[Note: this operation is frequently performed during interpretation
and must not only be fast, but should avoid excessive D-cache
pollution].
o On trigger, ask the question "Do we already have a translation for
this rPC?"
o If so, jump to the translation.
o If not, tentatively switch the interpreter into trace selection
mode.
o In dvmCheckJitTraceRequest(), check the 2nd-level filter to see if
we have seen a trace request for this exact rPC recently. If so,
proceed with trace selection and generate a trace. If not, record
this rPC in the 2nd-level filter, discard the trace selection request
and revert to normal interpretation.
In this style of trace JIT there is an inherent tension between
wanting to avoid uselessly compiling cold traces vs. the desire to
transition into natively-compiled code as soon as possible. The first
level hash & test serves two purposes: identifying hot trace heads
*and* identifying points at which we can re-enter the translated code
cache. We expect a lot of false positives here, but the cost of a
false positive at this level is low - whereas the opportunity cost of
missing a point at which we could transition from interpretation back
to previously translated code is high.
The second level filter requires that a specific rPC goes hot twice in
a relatively short period of time before we commit the resources to
generating a trace.
...Bill