InfoQ

News

JRuby Roundup: Java Integration and Debugging (JSR-45) Improvements

Posted by Werner Schuster on Aug 18, 2008 01:30 PM

Community
Java,
Ruby
Topics
Debugging ,
Performance & Scalability ,
Runtimes ,
JRuby ,
Language
Tags
JRuby ,
Debuggers
The next maintenance release of JRuby is scheduled for release later this month. Among the changes is an overhaul of the Java Integration, which defines how Ruby code interacts with Java libraries. Java Integration concerns basics, such as type coercion or overloading, but also streamlining the interaction between Ruby and Java, eg. making it possible to pass a Ruby Block to a method when it makes sense.

Charles Nutter shows some of the recent improvements in JRuby's Java Integration:
0. Obviously, there's been a lot of performance work.

1. Closures can be passed to any method with an interface as its last argument; the closure will be converted to the target interface type. thread = java.lang.Thread.new { puts 'here' }

2. Interfaces can be implemented using Ruby-cased (underscored) names for all methods now.
class Foo
 include java.awt.event.ActionListener
 def action_performed(event)
 ...
 end
end

3. Interfaces with bean-like methods can be implemented using attr*. [..]

4. Interfaces with boolean methods can be implemented using the question-marked version of the method name.

Another improvement is the use of JSR-45 features to improve debugging (Note: link seems to be broken at the time of publication). JSR-45 allows to map source files and source lines to class files. JSR-45 defines class attributes (SourceDebugExtension) that contain metadata in the SMAP format defined in the JSR to define which input source file a class file comes from. A look at the compiler code shows that line number information is already being added to the generated class files. ASM, used for generating the class files, allows to set line numbers via the visitLineNumber method.

With the addition of SMAP files, regular Java debuggers, eg jdb, can step through Ruby code compiled to bytecode (sample pastie showing how to step through a Ruby file using jdb).

The new capabilities are another step towards a fast debugger for JRuby - however it's important to note that this method only works for code that gets compiled to bytecode. Code that is interpreted still needs to be handled by the existing trace or hook based debuggers. How much of an applications code is turned into bytecode depends on a couple of factors. For instance, there's the risk of running out of PermGen space, which usually ends in a JVM crash/termination. To solve that, the JRuby JIT limits the amount of compiled methods (the limit can be configured).

No comments

Watch Thread Reply

Educational Content

Bindings, Platforms, and Innovation

This presentation focuses on the Internet and separating myth from fact, history from the future, and the mundane from the imaginative. Bob Frankston presents a vision of what could and should be.

Orchestrating Long Running Activities with JBoss / JBPM

This article explores the use of JBoss and jBPM to implement design solutions that effectively address the issue of orchestrating long running activities.

Neo4j - The Benefits of Graph Databases

This presentation covers the use of graph databases as an optimal solution for data that is difficult to fit in static tables, rapidly evolving data or data that has a lot of optional attributes.

Realistic about Risk: Software development with Real Options

This session introduces Real Options and shows how it can help in running your project. Real Options is a decision-making process that can be used to manage risk.

Communication Flexibility Using Bindings

This article discusses the use of bindings on services and references (including the instance of non-configured bindings) as the means to implement SCA communications in a Web and SOA environment.

Writing DSLs in Groovy

After a short introduction to DSLs, Scott Davis plays with the keyboard showing how to approach the creation of a DSL by typing working snippets of Groovy code that get executed.

Scaling Agile with C/ALM (Collaborative Application Lifecycle Management)

IBM Rational and InfoQ present, Scaling Agile with C/ALM, an eBook showing organizations how to become “finely tuned software delivery machines” by enabling team integration and scaling.

Concurrent Programming with Microsoft F#

Amanda Laucher presents a real life enterprise application written in F#. She shows actual code snippets, explaining design decisions and suggesting how to use some of the F# constructs.