If you're interested in compiled Ruby code, please read :)

One of the biggest problems in compiling Ruby code to Java classes has
been deciding on a class name.

Java is very strict about not allowing two pieces of code to load from
the same classloader with the same package and class name. So in
JRuby, we have typically used either the require path (require
'foo/bar' producing a class named foo.bar) or the full canonical path
name (like /Users/headius/projects/jruby/foo/bar) to create the class
name for the generated bytecode. In the former case, we can run into
conflicts if you have load paths that juggle around at runtime and end
up with multiple resources loading with the same require name from
different locations (which is rare, but can happen). In the latter
case, you can't precompile code and use it on a different system, nor
cache that compiled code across runs (since it's tied to a very
specific filesystem layout).

In 1.5, there's an experimental feature to produce normalized class
names for all runtime-compiled code, in order to cache that code
across runs.

-J-Djruby.jit.codeCache=<directory>

When this property is set:

* jitted methods are compiled into classes with a SHA1-calculated name
based on the actual code they contain. For example, a script
containing this code:

def foo
  1 + 1
end

1000.times { foo }

...produces a class named
ruby.jit.foo_E73CFC780569DD11D8A19F4B3FCE2D17D3C51B0B. Because this
name is based on the actual code in the method body, it can be reused
for the same method name+body in different Ruby files as well as
across runs (codeCache dumps to a directory all the .class files it
generates, which you can then jar up).

* force-compiled scripts are compiled into similar classes, where the
SHA1 hash is based on the full source of the file. In the above
example, if we specify -X+C (force all scripts to compile on load), we
get a class named
ruby.jit.FILE_940BA3B77CD258B7995561C8BD49F109CD49E5A6

In order to finally (finally!) normalize the class files globally, I
propose that we make a break in 1.5 toward generating only these
calculated class names for compiled Ruby code, both at the command
line (via jrubyc) and at runtime.

I recognize that they're far from as "nice" as we'd like, but the
generated class names from either jrubyc or the JIT have never been
nice, since the names had to be mangled for unsupported characters
(like -), canonicalized (full paths are far from "nice"), and the
resulting classes were not actually usable from normal Java code
*anyway*.

Thoughts or concerns about this approach?

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to