JRuby (please use github issues at http://bugs.jruby.org)
  1. JRuby (please use github issues at http://bugs.jruby.org)
  2. JRUBY-6849

pp Object.new shows 0x0000000 instead of a unique number for each object.

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: JRuby 1.7.0.RC1
    • Component/s: Standard Library
    • Labels:
      None
    • Environment:
      1.9 mode
    • Patch Submitted:
      Yes
    • Number of attachments :
      1

      Description

      The pp library in ruby-1.9 tries to do clever tricks to determine the length of pointers on the current system. This fails on jruby, so it ends up printing out #<Object:0x00000000> all the time.

      Reported to Pry on IRC: https://gist.github.com/3380575

        Activity

        Hide
        Douglas Campos added a comment -

        looks good to me

        Show
        Douglas Campos added a comment - looks good to me
        Hide
        Charles Oliver Nutter added a comment -

        A clever but weird patch. One problem with it is that it uses to_java, which for many core types (fixnums, strings, etc) will not produce normal Ruby objects. The subsequent inspectHashCode won't work, as a result.

        inspectHashCode is also based on java.lang.System.identityHashCode, which is not guaranteed to be unique (it's just the hashcode the object would have if it weren't overridden).

        object_id is probably the right way to do this, even though it has quite a bit more overhead for JRuby. I suspect the real problem here is that we don't (and won't) support the "p" format for Array#pack, and so the mask doesn't work right.

        I'll try to patch it in another way. Thanks for the interesting shot at it!

        Show
        Charles Oliver Nutter added a comment - A clever but weird patch. One problem with it is that it uses to_java, which for many core types (fixnums, strings, etc) will not produce normal Ruby objects. The subsequent inspectHashCode won't work, as a result. inspectHashCode is also based on java.lang.System.identityHashCode, which is not guaranteed to be unique (it's just the hashcode the object would have if it weren't overridden). object_id is probably the right way to do this, even though it has quite a bit more overhead for JRuby. I suspect the real problem here is that we don't (and won't) support the "p" format for Array#pack, and so the mask doesn't work right. I'll try to patch it in another way. Thanks for the interesting shot at it!
        Hide
        Charles Oliver Nutter added a comment -

        Minimal reproductions, showing only 1.9 mode failing:

        system ~/projects/jruby $ jruby -rpp -e "pp Object.new"
        #<Object:0x00000000>
        
        system ~/projects/jruby $ jruby -rpp -e "p Object.new"
        #<Object:0x5ea1068>
        
        system ~/projects/jruby $ jruby --1.8 -rpp -e "pp Object.new"
        #<Object:0xfa0>
        
        Show
        Charles Oliver Nutter added a comment - Minimal reproductions, showing only 1.9 mode failing: system ~/projects/jruby $ jruby -rpp -e "pp Object.new" #<Object:0x00000000> system ~/projects/jruby $ jruby -rpp -e "p Object.new" #<Object:0x5ea1068> system ~/projects/jruby $ jruby --1.8 -rpp -e "pp Object.new" #<Object:0xfa0>
        Hide
        Conrad Irwin added a comment -

        Cool. Thanks for the feedback I was unaware of to_java's behaviour on core types (though luckily this code wouldn't have been called for too many of them!).

        It would be nice (if it's possible) to have the same hex string here as is used by the default inspect (though maybe changing the default inspect to use .object_id would be an interesting way to unify them).

        Show
        Conrad Irwin added a comment - Cool. Thanks for the feedback I was unaware of to_java's behaviour on core types (though luckily this code wouldn't have been called for too many of them!). It would be nice (if it's possible) to have the same hex string here as is used by the default inspect (though maybe changing the default inspect to use .object_id would be an interesting way to unify them).
        Hide
        Charles Oliver Nutter added a comment -

        MRI's output seems to be largely hacked to produce the "hashy" result in PP that inspect would produce if it weren't already overloaded...so they're trying to basically reimplement inspect's hashy logic from Ruby using these tricks.

        Your version may be good enough, if we don't use to_java (since that causes other things to happen). Perhaps it would be ok for us to use JRuby.reference internally, or to add a JRuby.identity_hash that just uses System.identityHashCode?

        I'll try the latter.

        Show
        Charles Oliver Nutter added a comment - MRI's output seems to be largely hacked to produce the "hashy" result in PP that inspect would produce if it weren't already overloaded...so they're trying to basically reimplement inspect's hashy logic from Ruby using these tricks. Your version may be good enough, if we don't use to_java (since that causes other things to happen). Perhaps it would be ok for us to use JRuby.reference internally, or to add a JRuby.identity_hash that just uses System.identityHashCode? I'll try the latter.
        Hide
        Charles Oliver Nutter added a comment - - edited
        commit be2e49d66d074fbae59e335d3854cf047adcd18e
        Author: Charles Oliver Nutter <headius@headius.com>
        Date:   Tue Aug 21 15:37:59 2012 -0500
        
            Fix JRUBY-6849
            
            pp Object.new shows 0x0000000 instead of a unique number for each object.
            
            MRI logic appears to want to simply reproduce their "hashy"
            inspect value, but this doesn't work in JRuby due to the lack of
            the "p" format for Array#unpack. Modified to use a JRuby ext to
            get the identityHashCode of the object. It is not unique, but
            neither is our inspect output.
        
        :100644 100644 56d726d... 38c0186... M	lib/ruby/1.9/pp.rb
        :100644 100644 9374be4... 17bfc35... M	src/org/jruby/ext/jruby/JRubyLibrary.java
        
        Show
        Charles Oliver Nutter added a comment - - edited commit be2e49d66d074fbae59e335d3854cf047adcd18e Author: Charles Oliver Nutter <headius@headius.com> Date: Tue Aug 21 15:37:59 2012 -0500 Fix JRUBY-6849 pp Object.new shows 0x0000000 instead of a unique number for each object. MRI logic appears to want to simply reproduce their "hashy" inspect value, but this doesn't work in JRuby due to the lack of the "p" format for Array#unpack. Modified to use a JRuby ext to get the identityHashCode of the object. It is not unique, but neither is our inspect output. :100644 100644 56d726d... 38c0186... M lib/ruby/1.9/pp.rb :100644 100644 9374be4... 17bfc35... M src/org/jruby/ext/jruby/JRubyLibrary.java
        Hide
        Conrad Irwin added a comment -

        Thanks .

        Show
        Conrad Irwin added a comment - Thanks .

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Conrad Irwin
          • Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: