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

ClassCastException with DummyDynamicScope in String#rpartition? with -X+C

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.6.7, JRuby 1.7.0.pre1
    • Fix Version/s: JRuby 1.7.0.RC1
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Trying my code with -X+C I got this weird error.
      It does not seems to be due to String#rpartition, but rather because of a bad scope.

      Steps to reproduce:
      $ git clone git://github.com/jruby/perfer.git
      $ bundle
      $ JRUBY_OPTS="-X+C -Xbacktrace.style=raw" bin/perfer run examples/file_stat.rb

      The output I got is in this gist: https://gist.github.com/f821b76e79c7d34e84bd

        Activity

        Hide
        Thomas E Enebo added a comment -

        Just to add some notes:

                    pos = regex.search19(context, this, value.getRealSize(), true);
                    if (pos < 0) return rpartitionMismatch(runtime);
                    sep = (RubyString)RubyRegexp.nth_match(0, context.getCurrentScope().getBackRef(runtime));
        

        The ClassCast is this last line, but it should not class cast since pos >= 0. Benoit is correct that this must be some bad scope setup. Plus it works in mixed + interp modes.

        Show
        Thomas E Enebo added a comment - Just to add some notes: pos = regex.search19(context, this, value.getRealSize(), true); if (pos < 0) return rpartitionMismatch(runtime); sep = (RubyString)RubyRegexp.nth_match(0, context.getCurrentScope().getBackRef(runtime)); The ClassCast is this last line, but it should not class cast since pos >= 0. Benoit is correct that this must be some bad scope setup. Plus it works in mixed + interp modes.
        Hide
        Charles Oliver Nutter added a comment -

        The issue was that rpartition and partition were not specified as needing access to the caller's backref (reads = BACKREF, writes = BACKREF in @JRubyMethod), and as a result no scope was being set up for the caller. In this particular case, a dummy scope was being set up for the caller (for one of the other calls or constructs in the method) and DummyDynamicScope always returns nil for backref.

        Trivial reproduction:

        def foo
          Object
          "/Users/headius/projects/jruby/tmp/perfer/examples/file_stat.rb:4:in `(root)'".rpartition(/:\d+(?:$|:in )/).first
        end
        
        foo
        

        (Here, the access of Object triggers a dummy scope)

        The fix is trivial. I'm trying to set up a test case, and then I'll commit.

        Show
        Charles Oliver Nutter added a comment - The issue was that rpartition and partition were not specified as needing access to the caller's backref (reads = BACKREF, writes = BACKREF in @JRubyMethod), and as a result no scope was being set up for the caller. In this particular case, a dummy scope was being set up for the caller (for one of the other calls or constructs in the method) and DummyDynamicScope always returns nil for backref. Trivial reproduction: def foo Object "/Users/headius/projects/jruby/tmp/perfer/examples/file_stat.rb:4:in `(root)'".rpartition(/:\d+(?:$|:in )/).first end foo (Here, the access of Object triggers a dummy scope) The fix is trivial. I'm trying to set up a test case, and then I'll commit.
        Hide
        Charles Oliver Nutter added a comment -
        commit ff42564963ac0d5b8b6471f23fd3441fb2db6fba
        Author: Charles Oliver Nutter <headius@headius.com>
        Date:   Wed Aug 22 18:42:34 2012 -0500
        
            Fix JRUBY-6827
            
            ClassCastException with DummyDynamicScope in String#rpartition? with -X+C
            
            String#partition and rpartition need read/write of backref.
        
        :100644 100644 278c7ff... cf60086... M	spec/compiler/general_spec.rb
        :100644 100644 48e0a15... 93d6813... M	src/org/jruby/RubyString.java
        
        Show
        Charles Oliver Nutter added a comment - commit ff42564963ac0d5b8b6471f23fd3441fb2db6fba Author: Charles Oliver Nutter <headius@headius.com> Date: Wed Aug 22 18:42:34 2012 -0500 Fix JRUBY-6827 ClassCastException with DummyDynamicScope in String#rpartition? with -X+C String#partition and rpartition need read/write of backref. :100644 100644 278c7ff... cf60086... M spec/compiler/general_spec.rb :100644 100644 48e0a15... 93d6813... M src/org/jruby/RubyString.java
        Hide
        Benoit Daloze added a comment -

        Awesome, thanks for the explanation, I'll hopefully be able to patch this myself next time I encounter something like that!

        Show
        Benoit Daloze added a comment - Awesome, thanks for the explanation, I'll hopefully be able to patch this myself next time I encounter something like that!

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Benoit Daloze
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: