Repository navigation
Implement loop versioner privatization/HCR/OSR fixed-point analysis - #6869
Conversation
This fixed-point analysis determines the maximal set of deferred versioning operations that are possible to carry out. It does this by initially tentatively allowing all versioning operations, and then until a fixed-point is reached, analyzing what would remain of the loop after versioning with the current tentative assumptions. If no remaining operations would interfere with the versioning, then a fixed-point has been reached, and the tentative assumptions can be locked in. Previously, versioner would separately consider each of privatization with HCR guard versioning, privatization without HCR guard versioning, and OSR guard versioning, in that order. While that strategy was fine for correctness, it was possible to miss opportunities in cases where the loop contains an OSR guard that targets a cold call, which can occur starting with 3d1fec9. For example, consider the following loop: while (...) { if (OSR assumptions hold) { // OSR guard // inline code } else { coldCall1(); } if (profiled guard receiver is good) { // inline code } else { coldCall2(); } } Suppose that versioner would like to version the profiled guard, and that its receiver comes from a load that requires privatization in order to version. And suppose further that nothing in either block of inlined code interferes with privatization or OSR guard versioning. Then it's possible to version both guards in this loop. But if we consider OSR guard versioning separately from privatization, there is no order in which we can consider the two of them that will allow for the versioning to happen. Suppose we consider privatization first, as versioner used to do. In that case, coldCall1() will prevent privatization, and then since privatization is not allowed, coldCall2() will prevent OSR guard versioning. Considering them in the opposite order would find the same result: first coldCall2() will prevent OSR guard versioning, and then since OSR guard versioning is not allowed, coldCall1() will prevent privatization. Now with the fixed-point analysis, versioner will start by considering privatization and OSR guard versioning simultaneously, and it will find that after such versioning, neither coldCall1() nor coldCall2() would be reachable, and so it will go on to version both guards. This fixed-point analysis will search through the loop at most 3 times, which is no worse than the old worst case. Furthermore, it simplifies the previous analysis by consolidating all of the searches. Note also that even prior to 3d1fec9 it was already possible for the loop to contain a virtual+OSR guard targeting a cold call, but as it stands, versioner treats such guards as virtual guards only, ignoring the merged OSR guard. This problem is not directly addressed by this commit, but the fixed-point analysis will make it straightforward for a later commit to restrict versioning of such guards to cases where OSR guard versioning is possible.
215ff7b to
ce45970
Compare
|
Updated the copyright dates |
|
Jenkins build all |
|
|
||
| // If the VM is configured to allow for OSR-HCR, then HCR invalidation | ||
| // can only happen at a subset of GC points even in compilations using | ||
| // traditional HCR. We could try to take advantage of that here, but |
There was a problem hiding this comment.
Some clarification (perhaps via more comments in this part of the code) would help me on these points. I didn't completely understand the connection between OSR-HCR and traditional HCR (I thought traditional HCR meant no OSR usage for HCR). This might also help me understand why we only need to do newHCRGuardVersioningOK = false; if the HCR mode is traditional.
There was a problem hiding this comment.
When OSR-HCR is generally in use, that doesn't necessarily mean that it's in use for all compilations. We can opt to ignore our capability to do OSR-HCR in a particular compilation and use traditional HCR instead. And indeed we currently do that for some subset of compilations (to reduce the overhead of OSR liveness analysis IIRC) - something like all those at cold or below, plus warm compilations during startup. Regardless, if the VM is set up for OSR-HCR, and some compilations use it (or even just some compilations could use it), then the VM can't redefine classes at any time that would have been allowed by traditional HCR, i.e. at any GC point whatsoever. Since there may be methods on the stack that use OSR-HCR, it will have to respect the related restrictions and allow all threads to run until they can stop at an OSR yield point. (I guess we could try to be clever and opportunistically allow threads to stop at any old GC point if the innermost frame does not use OSR-HCR. Any outer frames are necessarily at calls anyway. But I don't think that we do this or even remember which JIT bodies use OSR-HCR and which don't, and I don't think there would really be any benefit to doing so.)
However, the point of this comment is that I am not currently taking that into account when handling traditional HCR here.
newHCRGuardVersioningOK = false; happens in two places, only one of which will be relevant in a particular compilation. The choice of which condition matters is based on the HCR mode. If we're using OSR-HCR, then HCR can only occur at OSR yield points, i.e. at the same places where OSR invalidation can happen. If we're using traditional HCR, then HCR can occur at any GC point, and it matters to versioning when we can stay in the loop after GC. As it stands, the code will use this condition for compilations using traditional HCR even if the VM is set up for OSR-HCR.
There was a problem hiding this comment.
I think if I were to add code comments, they'd end up something like "In OSR-HCR, HCR can occur at OSR yield points" and "In traditional HCR, HCR can occur at any GC point," which is basically just restating what the code already says in this case.
There was a problem hiding this comment.
Okay I wasn't thinking of the case when traditional HCR can be used in certain compilations with OSR-HCR in effect in general but now that I'm thinking about that, the existing comment makes more sense to me and the following code is also just setting whether its okay to do certain versioning transformations, regardless of the HCR mode in use for the compilation.
|
Jenkins build osx |
|
Checks have passed, I am merging. |
This fixed-point analysis determines the maximal set of deferred versioning operations that are possible to carry out. It does this by initially tentatively allowing all versioning operations, and then until a fixed-point is reached, analyzing what would remain of the loop after versioning with the current tentative assumptions. If no remaining operations would interfere with the versioning, then a fixed-point has been reached, and the tentative assumptions can be locked in.
Previously, versioner would separately consider each of privatization with HCR guard versioning, privatization without HCR guard versioning, and OSR guard versioning, in that order. While that strategy was fine for correctness, it was possible to miss opportunities in cases where the loop contains an OSR guard that targets a cold call, which can occur starting with 3d1fec9. For example, consider the following loop:
Suppose that versioner would like to version the profiled guard, and that its receiver comes from a load that requires privatization in order to version. And suppose further that nothing in either block of inlined code interferes with privatization or OSR guard versioning. Then it's possible to version both guards in this loop.
But if we consider OSR guard versioning separately from privatization, there is no order in which we can consider the two of them that will allow for the versioning to happen. Suppose we consider privatization first, as versioner used to do. In that case, coldCall1() will prevent privatization, and then since privatization is not allowed, coldCall2() will prevent OSR guard versioning. Considering them in the opposite order would find the same result: first coldCall2() will prevent OSR guard versioning, and then since OSR guard versioning is not allowed, coldCall1() will prevent privatization.
Now with the fixed-point analysis, versioner will start by considering privatization and OSR guard versioning simultaneously, and it will find that after such versioning, neither coldCall1() nor coldCall2() would be reachable, and so it will go on to version both guards.
This fixed-point analysis will search through the loop at most 3 times, which is no worse than the old worst case. Furthermore, it simplifies the previous analysis by consolidating all of the searches.
Note also that even prior to 3d1fec9 it was already possible for the loop to contain a virtual+OSR guard targeting a cold call, but as it stands, versioner treats such guards as virtual guards only, ignoring the merged OSR guard. This problem is not directly addressed by this commit, but the fixed-point analysis will make it straightforward for a later commit to restrict versioning of such guards to cases where OSR guard versioning is possible.