Skip to content

regressed indy fixnum op with custom equality (==) #5938

@kares

Description

@kares

tracking a regression from elastic/logstash#11196 (comment)

... which boiled down to be a separate JRuby 9.2.8.0 issue (with -Xcompile.invokedynamic)

the regression was introduced with #4736 and relates to == comparison, sample reproducer:

class Primitive

  def _value
    @__value ||= 0
  end

  def ==(other)
    other == _value
  end

  # def <=>(other)
  #   _value <=> other
  # end

  # def eql?(other)
  #   # double dispatch
  #   other.eql?(snapshot)
  # end

end

class Klass; end

threads = []

3.times do |i|
  threads << Thread.start do

    begin

      header = Klass.new

      def header.version
        Primitive.new
      end

      header.version == 5
    rescue java.lang.Exception => ex
      puts("FAILED " + java.lang.Thread.currentThread.name + " - " + ex.toString)
      raise ex
    end

  end
end

threads.each &:join

p :done
Unhandled Java exception: java.lang.ClassCastException: org.jruby.gen.RubyObject1 cannot be cast to org.jruby.RubyFixnum
java.lang.ClassCastException: org.jruby.gen.RubyObject1 cannot be cast to org.jruby.RubyFixnum
            fixnum_op_equal at org/jruby/runtime/invokedynamic/MathLinker.java:234
        invokeWithArguments at java/lang/invoke/MethodHandle.java:627
             fixnumOperator at org/jruby/runtime/invokedynamic/MathLinker.java:168
  bug_bindata_reproducer.rb at bug_bindata_reproducer.rb:41
                 callDirect at org/jruby/runtime/CompiledIRBlockBody.java:136
                       call at org/jruby/runtime/IRBlockBody.java:77
                       call at org/jruby/runtime/Block.java:129
                       call at org/jruby/RubyProc.java:295
                       call at org/jruby/RubyProc.java:274
                       call at org/jruby/RubyProc.java:270
                        run at org/jruby/internal/runtime/RubyRunnable.java:105
                        run at java/lang/Thread.java:748

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions