Implements #614

This pull request implements jruby/jruby#614

I've performed the changes outlined in the issue description. Benchmarks show that the performance degradation is ~0.7%