Tuesday, July 28, 2009

JVM Language Summit Call for Participation

I should have blogged this sooner, but things have been a little...crazy...lately.

The JVM Languages Summit is coming up for its second year. The event last year was spectacular; representatives of all the major languages and several minor ones showed up and talked about their plans, their history, and their desires from the JVM. And JVM engineers from the three major vendors (Sun, IBM, Oracle) sat there and dutifully took notes. It was a great meeting of minds, and an incredibly uplifting event for those of us invested in the JVM.

It's also not just an event for implementers; if you're keen on the nitty-gritty details of JVM languages and want to help improve them, promote them, or otherwise relate to them in some way, you should be here.

Hope to see you at the Summit!


=== CALL FOR PARTICIPATION -- JVM LANGUAGE SUMMIT, September 2009 ===

http://jvmlangsummit.com/

Dear colleague;

We are pleased to announce the the 2009 JVM Language Summit to be held at Sun's Santa Clara campus on September 16-18, 2009. Registration is now open for speaker submissions (presentations and workshops) and general attendance.

The JVM Language Summit is an open technical collaboration among language designers, compiler writers, tool builders, runtime engineers, and VM architects. We will share our experiences as creators of programming languages for the JVM and of the JVM itself. We also welcome non-JVM developers on similar technologies to attend or speak on their runtime, VM, or language of choice.

The format this year will be slightly different from last year. Attendees told us that the most successful interactions came from small discussion groups rather than prepared lectures, so we've divided the schedule equally between traditional presentations (we're limiting most presentations to 30 minutes this year) and "Workshops". Workshops are informal, facilitated discussion groups among smaller, self-selected participants, and should enable "deeper dives" into the subject matter. There will also be impromptu "lightning talks".

We encourage speakers to submit both a presentation and a workshop; we will arrange to schedule the presentation before the workshop, so that the presentation can spark people's interest and the workshop will allow those who are really interested to go deeper into the subject area. Workshop facilitators may, but are not expected to, prepare presentation materials, but they should come prepared to guide a deep technical discussion.

The Summit is being organized by the JVM Engineering team; no managers or marketers involved! So bring your slide rules and be prepared for some seriously geeky discussions.

The registration page is now open at:

http://registration.jvmlangsummit.com/

If you have any questions, send inquiries to inquire@jvmlangsummit.com.

We hope to see you in September!

Monday, July 27, 2009

JRuby's Importance to Ruby, and eRubyCon 2009

I'm going to be speaking about JRuby again this year at eRubyCon, in Columbus OH. I just got back from Rails Underground, which reminded me how much I love the smaller regional Ruby conferences. So I'm totally pumped to go to eRubyCon this year.

The idea of "Enterprise Ruby" has become less repellant since Dave Thomas's infamous keynote at RalsConf 2006. There are a lot of large, lumbering organizations out there that have yet to adopt any of the newer agile language/framework combinations, and Rails has most definitely led the way. I personally believe that in order for Ruby to become more than just a nice language with a great community, it needs to gain adoption in those organizations, and it needs to do it damn quickly. JRuby is by far the best way for that to happen.

There's another aspect to adoption I think has escaped a lot of Rubyists. In 2006 and 2007, Ruby gained a lot of Java developers who were running away from bloated, over-complicated frameworks and the verbosity and inelegance of Java. When I asked at Ruby conferences in 2005, 2006, and 2007 how many people had done Java development in a former life, almost everyone in the room raised their hands. When I've asked the same question in 2008 and 2009, it's down to less than half the room. Where did they go?

The truth is that the Java platform now has reasonably good answers to Ruby in Groovy, Scala, and Clojure, and reasonably good answers to Rails in Grails and Lift. And yet many Rubyists don't realize how important it is for JRuby to continue doing well, many still seeing it as simply "nice to have" while dismissing the entirety of the Java platform as unimportant to Ruby's future. It's an absurd position, but I blame myself for not making this case sooner.

I believe that JRuby is the most crucial technology for Ruby's future right now. Regardless of how fast or how solid the C or C++ based Ruby implementations get, the vast majority of large organizations are *never* going to run them. That's the truth. If we can leverage JRuby to grab 1-2% of the Java market, we'll *double* the size of the Ruby community. If we completely lose the Java platform to alternatives, Rubyists may not have the luxury of remaining Rubyists in the future. It's that big a deal.

So I hope you'll come by eRubyCon and hear what we've been working on in JRuby and what we have planned for the future, especially our work on making JRuby a stronger JVM citizen. I'm certain to expand on the Hibernate-based prototype code I showed at Rails Underground, and hope to have some additional, never-before-seen demonstrations that will shock and amaze you. And if there's time, I'll demonstrate my two research pets, the "Ruby Mutant" twins Duby and Juby.

See you there!

Sunday, May 31, 2009

Your JavaOne 2009 Ruby Guide

Here's a list of talks about Ruby or that mention/relate to Ruby at CommunityOne and JavaOne 2009. Some of these are about other languages, since I just did a dumb search for any mention of "ruby".

Add your suggestions in comments to help narrow down which talks people should go see.

CommunityOne:

S304128

Developing on the OpenSolaris™Operating System

David Miner, Sun Microsystems; Nicholas Solter, Sun Microsystems

Monday

June 01

10:50 AM - 11:40 AM

Esplanade 305

S307894

Sun GlassFish™ Portfolio: Where Sun's Application Platform Is Going

Eduardo Pelegri-Llopart, Sun Microsystems, Inc.

Monday

June 01

10:50 AM - 11:40 AM

Hall E 135

S304001

Pragmatic Identity 2.0: Invoking Identity Services with a Simplified REST/ROA Architecture

Pat Patterson, Sun Microsystems, Inc.; Daniel Raskin, Sun Microsystems, Inc.; Ron Ten-Hove, Sun Microsystems, Inc.

Monday

June 01

11:50 AM - 12:40 PM

Gateway 102-103

S304141

Programming Languages and the Cloud

Ted Leung, Sun Microsystems, Inc.

Monday

June 01

11:50 AM - 12:40 PM

Gateway 104

S304267

Beyond Impossible: How JRuby Has Evolved the Java™ Platform

Charles Nutter, Sun Microsystems, Inc.

Monday

June 01

1:40 PM - 2:30 PM

Hall E 134

S304040

Social-Enable Your Web Apps with OpenSocial

Dave Johnson, IBM

Monday

June 01

4:00 PM - 4:50 PM

Esplanade 300

S311290

JRuby Rails Workshop

Arun Gupta, Sun Microsystems, Inc.; Jacob Kessler, Sun Microsystems; Vivek Pandey, Sun Microsystems, Inc.; Nick Sieger, Sun Microsystems, Inc

Tuesday

June 02

9:00 AM - 5:00 PM

Breakout Room 7

S311294

Cloud Computing and Storage in Practice

Tim Bray, Sun Microsystems, Inc.; Chris Kutler, Sun Microsystems, Inc.

Wednesday

June 03

1:30 PM - 5:00 PM

Breakout Room 2


JavaOne:

PAN-5348
Script Bowl 2009: A Scripting Languages ShootoutPanel SessionRoberto Chinnici, Sun Microsystems, Inc.; Thomas Enebo, Sun Microsystems, Inc. ; Rich Hickey, Clojure;Guillaume Laforge, SpringSource; Raghavan Srinivas, Self; Dick Wall , Google; Frank Wierzbicki, Sun Microsystems, Inc.Tuesday
June 02
10:50 AM - 11:50 AM
Gateway 104
TS-4164
Clojure: Dynamic Functional Programming for the JVM™ MachineTechnical SessionRich Hickey, ClojureTuesday
June 02
12:10 PM - 1:10 PM
Hall E 133
TS-4487
The Feel of ScalaTechnical SessionBill Venners, Artima, Inc.Tuesday
June 02
3:20 PM - 4:20 PM
Gateway 104
TS-5015
Welcome to RubyTechnical SessionYehuda Katz, Engine YardTuesday
June 02
4:40 PM - 5:40 PM
Gateway 104
TS-5216
Toward a Renaissance VMTechnical SessionBrian Goetz, Sun Microsystems, Inc.; John Rose, Sun MicrosystemsTuesday
June 02
6:00 PM - 7:00 PM
Hall E 133
BOF-4434
Hacking JRubyBOFOla Bini, ThoughtWorksTuesday
June 02
8:30 PM - 9:20 PM
Gateway 104
BOF-5058
JRuby Experiences in the Real WorldBOFLogan Barnett, Happy Camper Studios; David Koontz, JumpBoxTuesday
June 02
9:30 PM - 10:20 PM
Gateway 104
TS-5413
JRuby on Rails in Production: Lessons Learned from Operating a Live, Real-World SiteTechnical SessionNick Sieger, Sun Microsystems, IncWednesday
June 03
11:05 AM - 12:05 PM
Gateway 104
TS-4921
Dynamic Languages Powered by GlassFish™ Application Server v3Technical SessionJacob Kessler, Sun Microsystems; Vivek Pandey, Sun Microsystems, Inc.Wednesday
June 03
11:05 AM - 12:05 PM
Hall E 133
TS-4955
Comparing Groovy and JRubyTechnical SessionNeal Ford, ThoughtWorks Inc.Wednesday
June 03
2:50 PM - 3:50 PM
Gateway 104
BOF-4682
Performance Comparisons of Dynamic Languages on the Java™ Virtual MachineBOFMichael Galpin, eBayWednesday
June 03
6:45 PM - 7:35 PM
Esplanade 300
TS-5385
Alternative Languages on the JVM™ MachineTechnical SessionCliff Click, Azul SystemsThursday
June 04
9:30 AM - 10:30 AM
Gateway 104
TS-4012
Pragmatic Identity 2.0: Simple, Open, Identity Services Using RESTTechnical SessionPat Patterson, Sun Microsystems, Inc.; Ron Ten-Hove, Sun Microsystems, Inc.Thursday
June 04
10:50 AM - 11:50 AM
Esplanade 307-310
TS-4961
"Design Patterns" for Dynamic Languages on the JVM™ MachineTechnical SessionNeal Ford, ThoughtWorks Inc.Thursday
June 04
10:50 AM - 11:50 AM
Gateway 104
TS-5354
Exploiting Concurrency with Dynamic LanguagesTechnical SessionTobias Ivarsson, Neo TechnologyThursday
June 04
1:30 PM - 2:30 PM
Gateway 104
TS-5033
Scripting Java™ Technology with JRubyTechnical SessionThomas Enebo, Sun Microsystems, Inc. ; Charles Nutter, Sun Microsystems, Inc.Thursday
June 04
2:50 PM - 3:50 PM
Gateway 104
TS-3955
Monkeybars: Tools-Enabled Swing Development with JRubyTechnical SessionLogan Barnett, Happy Camper Studios; David Koontz, JumpBoxFriday
June 05
12:10 PM - 1:10 PM
Esplanade 302

Thursday, May 14, 2009

BiteScript 0.0.2 Scripting Examples

I just released BiteScript 0.0.2, which mainly fixes some issues defining packages and non-public classes.

BiteScript is basically just a simple DSL for generating JVM bytecode. I use it in Duby and now in the "ruby2java" compiler we'll be using to turn Ruby classes into Java classes.

I've blogged about BiteScript here before, but I realized today I never posted any simple "hello world" examples. So here's a few of them, all using the command-line "scripting" mode.

First, the simplest version:
main do
ldc "Hello, world!"
aprintln
returnvoid
end

Obviously this is using a predefined "aprintln" macro, since there's no "aprintln" opcode on the JVM. Here's a longer version that shows how a macro would be defined, and accepts one argument
import java.lang.System
import java.io.PrintStream

macro :aprintln do
getstatic System, :out, PrintStream
swap
invokevirtual PrintStream, println, [Object]
end

macro :aprint do
getstatic System, :out, PrintStream
swap
invokevirtual PrintStream, print, [Object]
end

main do
ldc "Hello, "
aprint
aload 0
aaload 0
aprintln
returnvoid
end

And of course this is just Ruby code, so you can just use Ruby to alter the generation of code:
main do
5.times do
ldc "Wow!"
aprintln
end
returnvoid
end

These "BiteScripts" can all be either run with the "bite" command or compiled with the "bitec" command:
$ bite examples/using_ruby.bs 
Wow!
Wow!
Wow!
Wow!
Wow!

$ bitec examples/using_ruby.bs

$ javap -c examples/using_ruby
Compiled from "examples.using_ruby.bs"
public class examples.using_ruby extends java.lang.Object{
public static void main(java.lang.String[]);
Code:
0: ldc #9; //String Wow!
2: getstatic #15; //Field java/lang/System.out:Ljava/io/PrintStream;
5: swap
6: invokevirtual #21; //Method java/io/PrintStream.println:(Ljava/lang/Object;)V
9: ldc #9; //String Wow!
11: getstatic #15; //Field java/lang/System.out:Ljava/io/PrintStream;
14: swap
15: invokevirtual #21; //Method java/io/PrintStream.println:(Ljava/lang/Object;)V
18: ldc #9; //String Wow!
20: getstatic #15; //Field java/lang/System.out:Ljava/io/PrintStream;
23: swap
24: invokevirtual #21; //Method java/io/PrintStream.println:(Ljava/lang/Object;)V
27: ldc #9; //String Wow!
29: getstatic #15; //Field java/lang/System.out:Ljava/io/PrintStream;
32: swap
33: invokevirtual #21; //Method java/io/PrintStream.println:(Ljava/lang/Object;)V
36: ldc #9; //String Wow!
38: getstatic #15; //Field java/lang/System.out:Ljava/io/PrintStream;
41: swap
42: invokevirtual #21; //Method java/io/PrintStream.println:(Ljava/lang/Object;)V
45: return

}

This last example shows the resulting JVM bytecode as well.

Future plans for BiteScript include making it have better error detection (right now it just falls back on the JVM bytecode verifier, which is not the most descriptive thing in the world) and improving the API to more easily handle all the various combinations of class, field, and method modifiers. I'd also like to make it detect if you're doing bad things to the stack to save you the hassle of interpreting verification errors that may not happen until runtime.

Anyway, give it a try and feel free to contribute; the code is all Ruby, wrapping the ASM bytecode library, so anyone that knows Ruby can tweak it. The project page and wiki are hosted at Kenai.com: http://kenai.com/projects/jvmscript

And if you're not up on the JVM or JVM bytecodes, the JVM Specification is an easy-to-read complete reference for code targeting the JVM, and here is my favorite JVM opcode quickref.

Help JRuby by Fixing RubySpecs

A number of you have asked how you can help JRuby development. Well there's actually an easy way: fix RubySpec failures.

You may have noticed we periodically update our RubySpec "stable" revision number, and usually have to file a few bugs. This isn't because we don't want to fix those issues...on the contrary, we would love to fix them. We just don't have enough manpower, and there's usually harder issues we need to tackle first.

But most of the failures are easy to fix, and a lot of JRuby newcomers have gotten their feet wet fixing them. So here's a short guide on how to run the specs and fix them quickly.

1. Get a JRuby working copy and build it

This is as simple as 'git clone git://github.com/jruby/jruby.git', then 'cd jruby' and 'ant'. You'll need Apache Ant 1.7 and Java 5/1.5 or higher (grab "Java SE Development Kit" from the Java SE downloads page.

2. Run the CI spec run

We have a clean spec run that should be clean for you before you start. Just run "ant spec-short" and it will pull the mspec and rubyspec repositories, roll them to the stable versions, and run all known good specs. Now you're ready to investigate specific failures.

3. Run specific spec files with bugs reported

You can look in Jira under the "RubySpec" category, or look under spec/tags/ruby for "tag" files listing failing specs and Jira bug numbers. Once you find something you'd like to investigate, run that spec file using "bin/jruby spec/mspec/bin/mspec <path/to/spec/file>". For example to set the Range#initialize failures I just reported, run "bin/jruby spec/mspec/bin/mspec spec/ruby/core/range/initialize_spec.rb".

Now you can proceed to fixing it.

4. Identify where the problem is.

Most of the core classes are pretty easy to locate. Any classes in the "core" specs will have a Java class named Ruby, like RubyArray, RubyRange, and so on. They're generally located in src/org/jruby. If you know any Java, these files are pretty easy to follow, and we're standing by on IRC or on the mailing list to hold your hand at the start.

5. Create a patch and submit it to the bug

Once you have a working fix, you can go ahead create a patch, either with "git diff > somefile.patch" or by committing it to your local repository and using "git format-patch -1" to create a formatted patch for the topmost commit. Some git-fu may be necessary, so I usually just use "git diff".

That's all there is to it! You'll be a JRuby contributor in no time!

Wednesday, May 13, 2009

fork and exec on the JVM? JRuby to the Rescue!

Today David R. MacIver pinged me in #scala and asked "headius: Presumably you guys have spent quite a lot of time trying to make things like system("vim") work correctly in JRuby and failing? i.e. I'm probably wasting my time to attempt similar?"

My first answer was "yes", since there's no direct way to exec a program like vim (which wants a real terminal) and have it work on the JVM. The JVM's process launching gives the newly-spawned processes the child side of piped streams, which you then have to manually pump (which is what we do in JRuby's system, backtick, and exec methods). Under these circumstances, vim may start up, but it's certainly not functional.

But then I got to thinking...if you were doing this in C, you'd fork+exec and all would be happy. But we can't fork+exec on the JVM..OR CAN WE?

As you should know by now, JRuby ships with FFI, a library that allows you to bind any arbitrary C function in Ruby code. So getting fork+exec to work was a simple matter of writing a little Ruby code:
require 'ffi'

module Exec
extend FFI::Library

attach_function :my_exec, :execl, [:string, :string, :varargs], :int
attach_function :fork, [], :int
end

vim1 = '/usr/bin/vim'
vim2 = 'vim'
if Exec.fork == 0
Exec.my_exec vim1, vim2, :pointer, nil
end

Process.waitall

Running that with JRuby (I tried master, David tried 1.3.0RC1, and 1.2.0 works too) brings up a full-screen vim session, just like you'd expect, and it all just works. No other JVM language can do this so quickly and easily.

We'll probably try to generalize this into an optional library JRubyists can load (require 'jruby/real_exec' or similar) and perhaps add fork and exec to jna-posix so that the other JVM languages can have sweet, sweet process launching too.

JRuby rocks.

JRuby Nailgun Support in 1.3.0

I've merged changes into master (to be 1.3 soon) that should make Nailgun easier to use. And 1.3 will be the first release to include all NG stuff in the binary dist.
  • jruby --ng-server starts up a server. You can manage it however you like
  • jruby --ng uses the Nailgun client instead of launching a new JVM for the command you run. You'll just need to run make in tool/nailgun to build the ng executable (already built for you on Windows).
Future improvements will include having --ng start up the server for you if you haven't started it, passing signals through (don't expect signals to work at all right now), better management of threads and commands, and so on. But it's a good start, and people can try to play with it and report issues more easily now.

Heres a sample session:
~/projects/jruby ➔ cd tool/nailgun/ ; make ; cd -
Building ng client. To build a Windows binary, type 'make ng.exe'
gcc -Wall -pedantic -s -O3 -o ng src/c/ng.c
ld warning: option -s is obsolete and being ignored
/Users/headius/projects/jruby

~/projects/jruby ➔ jruby --ng-server
NGServer started on all interfaces, port 2113.
^Z
[1]+ Stopped jruby --ng-server

~/projects/jruby ➔ bg
[1]+ jruby --ng-server &

~/projects/jruby ➔ jruby --ng -e "puts 1"
1

~/projects/jruby ➔ time jruby -e "puts 1"
1

real 0m0.609s
user 0m0.482s
sys 0m0.119s

~/projects/jruby ➔ time jruby --ng -e "puts 1"
1

real 0m0.073s
user 0m0.010s
sys 0m0.018s

Update: For those not familiar, "NailGun is a client, protocol, and server for running Java programs from the command line without incurring the JVM startup overhead. Programs run in the server (implemented in java), triggered by the client (written in C), which handles all I/O."