I've found 2 cases where JRuby compiler produces incorrect output.
I think the bugs are related therefore I'm opening a single ticket for both of them.
JRuby version: {{jruby 1.7.2.dev (1.9.3p327) 2012-12-10 fffffff on OpenJDK 64-Bit Server VM 1.7.0-jdk7u6-b11-20120530 [darwin-x86_64]}}
The first one is reproducible with this:
git clone git://github.com/thedarkone/thread_safe.git jruby-compiler-bug
cd jruby-compiler-bug
git checkout jruby-bug
gem install atomic
ruby -Ilib -e"require 'thread_safe';c=ThreadSafe::Cache.new;100.times{|i| puts(c.put_if_absent(i,i).inspect)}"
The snippet inserts 100 numbers into a Cache via put_if_absent method which returns either an existing mapping or nil if none exists yet. The expected output from running this is 100 nil lines, however as soon as the compiler kicks in (usually around 55-65 insertions) it incorrectly starts printing the numbers being inserted.
The method that gets messed up can be found here:
https://github.com/thedarkone/thread_safe/blob/jruby-bug/lib/thread_safe/cache.rb#L56-L63
the parent compute_if_absent method is here:
https://github.com/thedarkone/thread_safe/blob/jruby-bug/lib/thread_safe/atomic_reference_cache_backend.rb#L408-L429
the second is reproducible with this:
git clone git://github.com/thedarkone/thread_safe.git jruby-compiler-bug-2
cd jruby-compiler-bug-2
git checkout jruby-bug-2
gem install atomic
ruby -Ilib -e"require 'thread_safe';c=ThreadSafe::Cache.new;100.times{|i| c[i] = i};100.times{|i| puts(c.delete_pair(i,i).inspect)}"
The snippet inserts 100 numbers into a Cache via [] method, it then deletes them via delete_pair method which returns returns true or false (if no matching mapping exists). The expected output from running this is 100 true lines, however as soon as the compiler kicks in (usually around 55-65 deletions) it incorrectly starts printing the numbers being deleted.
The method that gets messed up can be found here:
https://github.com/thedarkone/thread_safe/blob/jruby-bug-2/lib/thread_safe/atomic_reference_cache_backend.rb#L477-L484
|