[fix] avoid walking constructor instructions on every call#7762
[fix] avoid walking constructor instructions on every call#7762kares merged 4 commits intojruby:jruby-9.3from
Conversation
ikaronen-relex
left a comment
There was a problem hiding this comment.
LGTM, except that I do think interpreterContextForJavaConstructor should be volatile. (I also don't like the massive code duplication, but at least you haven't made it worse.)
|
@kares not related to this PR but I wonder if adding a single instr to IR which can call Java super would be a longer term solution? The tradeoff would be that all constructors would be immediately JIT compiled but we already are leaning on ASM here so I do not see much of a difference. It would remove having the split interpreter. This is a weirder suggestion than it may appear since IR JIT makes jruby methods but it probably can be repurposed to emit a valid Java constructor. The other option is to make current JIT capable of compiling the two halves but this is more difficult. temp vars in IR are java locals in JIT so it would require spilling locals into an array? to then pass back in for the second half (or guarantee no temps are accessible across the split). I did attempt to make splitable methods a few years ago so we could split on BBs on huge methods but it was invasive (it did not spill locals but changed all local access to indirect through Object[] temp array). That experiment only ran into large refactoring of JVMViisitor. Conceptually it is a path to synthetic methods which this split logic fits. |
I still do not understand all of the code but indeed approaching a way to JIT from an IR method seemed a bit impossible (without a massive refactoring of the Java super bits). Haven't thought about having an instruction for the Java super, sounds weird but at least the JITing would be much simpler (as you said byte-code is already generated in first pass anyways so shoudn't matter). Guess, we will have to attempt something on 9.4 at least. Basically anything to make the performance reasonable - comparable to 9.2. |
I have considered using Java static call instr in IR so that we can eliminate a few instrs since they end up being a single Java call (or can be). Super is a little weirder but is in the same neighborhood. Temp vars are already all Object so you can see some of the new instrs to support pattern matching already are returning Integer and not Fixnum. |
bef9cce to
2118c23
Compare
Ruby sub-classes of Java classes are reified with a generated Java class The interpreter context for the constructor was always rebuild from scratch on every IR method call -> effectively looping through method's instructions.
2118c23 to
dae4cbe
Compare
|
moving this out of draft - have some more work locally to clean things up and at least remove duplication but to keep things minimal for 9.3 this at least avoids the contention issue on Java |
headius
left a comment
There was a problem hiding this comment.
Just a couple naming things but otherwise looks good!
core/src/main/java/org/jruby/internal/runtime/methods/MixedModeIRMethod.java
Show resolved
Hide resolved
|
this is now merged and expected to be in 9.3.11.0 and 9.4.4.0 the numbers are still not the same as in 9.2 but the contention issue is handled, for the record here are the numbers for 9.4 (using the script from #7763): |
Since JRuby 9.3 Ruby sub-classes of Java classes are backed with a generated Java class,
the interpreter context for the constructor was always rebuild from scratch on every IR method call -> effectively looping through method's instructions.
NOTE: while this improves numbers by 5x it's still 4x slower than JRuby 9.2 (should probably implement a way of JIT-ing and avoid method lookup), the script from: #7763 ends up with the following numbers: