Do not restore comp phase during comp exception - #7959
Conversation
|
I think the main change with this commit may well be around what happens in "IL gen opts". This is an opt strategy that gets run immediately after IL gen, i.e. so it could occur while some other optimization in the strategy is in progress. An example may be if one tries to generate IL during escape analysis (for peeking and/or inlining) and the OOM exception happens in some optimization that is part of IL gen opts. Which optimization number would we want to report ? The one in IL gen opts or the one in the main optimizer (escape analysis, say) ? There probably isn't a right or wrong answer here, but what do we think is more important ? I could see how gaining information about what the main optimization was when IL gen occurred as being the more interesting answer in some cases. Having said that, I don't recall much confusion in this specific area, and so I may be okay with the change in answer (and simpler code) in this case. Maybe @hzongaro or @jdmpapin have something to share, e.g. if this has been (or can be) an issue. |
|
Currently, if the exception happens during ILGen opts, the code will not report ILGen, but report the optimization that was running. |
|
By "currently" did you mean before this PR change ? This PR will change it to report the IL gen opt, right ? |
|
|
I think Vijay's original question was not about the outermost IL gen phase, but rather IL gen for inlining, which happens during another opt pass (typically the inlining pass) |
|
The old and the new implementation report "ILgen" as the current phase only if this is the ILGen of the method being compiled. |
|
The question wasn't about whether to report IL gen phase vs. the optimization from IL gen opts. It was about which optimization we should report when there are two currently running: one "outer" pass running from the main opt strategy (likely inlining, but potentially others, e.g. VP) and one "inner" pass running as part of IL gen opts because the outer pass is inlining something. Vijay seems to be under the impression that the choice of which optimization to report changes in this PR. I haven't read it myself yet, so I can't speak to that - I'm just trying to clear up a seeming miscommunication As for my two cents, it's not clear to me that one answer is necessarily better than the other in general. Not that it should block the kind of improvement made here, but I think that ideally we should be able to report some kind of nested context, so that in this kind of situation we'd be able to easily tell that e.g. a problem happened during recognized call transformer, during IL gen, during VP |
|
Devin's interpretation of what I was asking is correct. I thought the reported optimization in case of an exception would change as per the comment: In my later comments, I mentioned that this change in reported optimization in case of an exception (assuming there is a change based on Marius' prior answer) is okay with me, but I wanted to get Henry/Devin opinion too. |
|
I ran some experiments with the original code and with the code implemented by this PR. Reported vmState is 0x00055cff both with or without this change. Case 2: Exception thrown during compilation in the same spot as Case1 |
|
If I understand correctly, this will ensure that for a vmState of 0x5yyzz, the yy digits will be reported correctly in the verbose log file, but not the zz digits for the analysis phase. I think those will always be FF. To ensure those digits are reportedly correctly I think you would need to make corresponding changes to save and restore the phase before and after the various calls to |
|
The zz digits of the analysis phase move linearly through: For the phases that use a CompilationPhaseScope a compilation exception will restore the zz digits to "BEFORE_OPTIMIZATION". |
Yes, but others do occur, which is why I recently added support to the
I think it would be good to accurately capture the state in the verbose log for both the optimization and the analysis phase, as it can help to narrow down problems. I don't have a suggestion off-hand for a better way of doing it than eliminating |
I adjusted the code to eliminate the usage of |
hzongaro
left a comment
There was a problem hiding this comment.
I think the change does what was intended. If these are the only remaining uses of TR::Compilation::CompilationPhaseScope, I think the declaration and implementation of the class can be removed from OMRCompilation.hpp and OMRCompilation.cpp.
|
I didn't spot any |
|
I see that |
|
It seems like the eventual change would be pretty trivial, just That said, I'll leave it to your judgment. If you want to keep this change as it is, then I agree with Henry that |
|
I will attempt to use I wonder whether there is something wrong with |
The change that introduced |
In `OMR::Optimizer::optimize()` the JIT saves the "compilation phase" into a stack allocated object of type `TR::Compilation::CompilationPhaseScope`. This happenes in the constructor of the object. The destructor of the object restores the previously saved state. This ensures that that if we leave the scope of the `OMR::Optimizer::optimize()` routine, the compilation phase is properly restored. However, if the optimizer throws an exception, the stack is unwound, the destructor of the CompilationPhaseScope object is called and the compilation phase is restored (most likely showing as ILgen). This is not want we want. For exceptions, we want to retain the compilation phase (namely the optimization) that produced the exception, so that it can be properly reported at higher levels, when the exception is caught. This commit changes the destructor of the CompilationPhaseScope object so that the compilation phase is restored only if there isn't an exception in progress. This ensures that the compilation phase at the time when the exception was thrown is reported correctly. This commit also moves the `comp()->reportOptimizationPhase(optNum);` statement from `performOptimization()` routine to an earlier location, as soon as we determine that the current optimization is a proper optimization and not an optimization group. This ensures that the "analysisPhase" reported in case of a crash or exception is shown in the context of the current optimization and not the previous one. Signed-off-by: Marius Pirvu <mpirvu@ca.ibm.com>
|
Personal builds with code from this PR have passed (aarch64_linux, aarch64_mac, ppc64_aix, ppcle_linux, s390x_linux, x86-64_linux, x86-64_mac, x86-64_windows) |
|
Jenkins build all |
|
Jenkins build riscv |
|
The error on linux_risc64 (https://ci.eclipse.org/omr/job/PullRequest-linux_riscv64/416): The error on linux_ppc-64_le_gcc has been seen many times before, most recently here: https://ci.eclipse.org/omr/job/PullRequest-linux_ppc-64_le_gcc/4886/ |
In
OMR::Optimizer::optimize()the JIT saves the "compilation phase"into a stack allocated object of type
TR::Compilation::CompilationPhaseScope.This happens in the constructor of the object. The destructor of the
object restores the previously saved state. This ensures that that if we
leave the scope of the
OMR::Optimizer::optimize()routine, the compilationphase is properly restored.
However, if the optimizer throws an exception, the stack is unwound, the
destructor of the CompilationPhaseScope object is called and the compilation
phase is restored (most likely showing as ILgen). This is not want we want.
For exceptions, we want to retain the compilation phase (namely the optimization)
that produced the exception, so that it can be properly reported at higher
levels, when the exception is caught.
This commit changes the destructor of the CompilationPhaseScope object so that
the compilation phase is restored only if there isn't an exception in progress.
This ensures that the compilation phase at the time when the exception was
thrown is reported correctly.
This commit also moves the
comp()->reportOptimizationPhase(optNum);statement from
performOptimization()routine to an earlier location,as soon as we determine that the current optimization is a proper optimization
and not an optimization group. This ensures that the "analysisPhase" reported
in case of a crash or exception is shown in the context of the current optimization
and not the previous one.