InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

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

Posted by Werner Schuster on Aug 18, 2008

Sections
Development,
Architecture & Design
Topics
Java ,
Debugging ,
JRuby ,
Runtimes ,
Ruby ,
Performance & Scalability ,
Language
Tags
Debuggers ,
JRuby
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

Jesper Boeg on Priming Kanban

In this interview, Jesper Boeg, author of the new InfoQ book – Priming Kanban, discusses the keys to using Kanban effectively, and how to get started if you are currently using other approaches.

New-age Transactional Systems - Not Your Grandpa's OLTP

John Hugg discusses high volume transaction processing applications with high and low frequency profiles, and how VoltDB can be used for that purpose.

Cool Code

Kevlin Henney examines code samples to see what can be learned from them starting from the premise that one won’t write great code unless he knows how to read it.

Collaboration: At the Extremities of Extreme

Jason Ayers share the observations he made watching a team of developers collaborating in real time on the same code base, pushing XP, pair programming and continuous integration to their extremes.

Yesod Web Framework

Michael Snoyman presents Yesod, a web framework written in Haskell and containing a web server, templating, ORM, libraries (templating, gravatar, etc.).

Transactions without Transactions

Richard Kreuter and Kyle Banker on how to avoid classical RDBMS transactional systems by using compensation mechanisms, transactional messaging or transactional procedures.

Attila Szegedi on JVM and GC Performance Tuning at Twitter

Attila Szegedi talks about performance tuning Java and Scala programs at Twitter: how to approach GC problems, the importance of asynchronous I/O, when to use MySQL/Cassandra/Redis, and much more.

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.