Search code examples
javajruby

Java8 string deduplication and jruby - no effect?


I'm experimenting with java8 string deduplication and sadly I'm unable to create a jruby program which can demonstrate how enabling java deduplication also helps jruby (1.7.19).

Questions:

  • Does jruby take advantage of java8 string deduplication? Is there a special option for jruby for this?

  • Is there an example program to show how jruby running with -J-XX:+UseStringDeduplication is better than jruby without this option?


Solution

  • JRuby's (Ruby) String (instances of org.jruby.RubyString) objects are different from java.lang.String ... thus the deduplication won't have effect on your Ruby Strings. The internal representation of org.jruby.util.ByteList (Ruby String internals) is byte[] while the de-duplication works on char[] arrays (internals of a Java String).

    there's no special flag for this on JRuby, it still might have some effect since String instances (although mostly interned e.g. for Ruby method names) are used internally - how much it's hard to tell without trying (but if it's actually much it might be considered a bug).