onsdag, januari 31, 2007

JFokus post-mortem

Yesterday marked the first one day conference in Sweden focused on Java. All in all, it was a resounding success. I am personally very happy about how well everything ran. The only part that wasn't really up to par was the panel discussion.

So, a quick rehash of the day. First Simon Phipps did his thing in the keynote, speaking much about where Sun's open source initiative comes from. I would have liked some more specific info on the future though, but I guess that's hard for him to say...

After that, Thorbiörn Fritzon from Sun in Sweden started of the Language track with talking about some new features in Mustang, specifically some Swing topics and the JSR 223 support (scripting). After that he showcased a really cool stack-based calculator he'd hacked during the weekend, where you could attach the functioning of the buttons to different scripts, and the scripts could be implemented in any language on the classpath that supported JSR 223. The final showdown of calculator buttons was first a script in Haskell (using Jaskell) that pushed a lambda on the stack. This lambda curried addition, with the first object on the stack. Then another script written in Python popped the lambda from the stack, popped the next value and called the lambda with the value from the stack, in effect doing an addition the longer way...

After that it was time for my presentation. It felt really good and I believe most in the audience was satisfied.

After that I sat in on Dan Bergh Johnsson from Omegapoint talking about domain driven design, and how to refactor to find your domain. I found it quite elementary, and nothing really new.

Last, Jonas Bonér talked about OpenTerracotta, which is an incredibly cool tool for clustering your JVM applications, and by doing that achieving many different cool things. Look it up! I wish there had been more time for Jonas to get in depth about the implementation of Terracotta, though. Most interesting thing he told us was about a situation where they wanted about 50-80 clients pounding in a cluster at the same time, and they used Terracotta for this too, using a CyclicBarrier that was synchronized over all the JVM's. Very nice.

The panel debate wasn't that interesting. Most of the questions asked by the moderator didn't really achieve any discussion. Open sourcing Java doesn't seem like such a controversial topic anymore.

After the debate, the conference was over, but then BEA provided a pub evening with entertainment, so we stayed and networked a little, talked with interesting people and generally had fun. After that, six of us continued to a pub in Stockholm, called Monk's Cafe, where we drank good Belgium beer and talked until our throats were sore. A very interesting day, no doubts.

måndag, januari 29, 2007

Current JRuby status - AKA The what's-cool-and-happening

This is just a small update on what's going on in JRuby development at the moment. The first and most important item is that Tom has merged his block-work to trunk. He has done a monumental achievement with a patch on over 17k lines. The most amazing thing is that my main test case for block problems (Camping) runs perfectly. Tom also reports some performance improvements, but that isn't the important thing. What this block patch is all about is to remove the block stacks from our ThreadContext, and instead just pass the current block along through the Java stack (in other words, as a parameter to the method call in question). This simplifies many things and also make it possible for our compiler to finally compile closures and blocks. Charles will soon continue the work on making this happening, but being able to do that means the JIT will work for vastly more of the code than it does at the moment.

The second work we're hard at right now is Rails compatibility. Tom is looking at ActiveRecord, Charles have improved Marshalling (with the side effect that the gem local source cache finally works) and also did some work on Multibyte::Chars. This work is going fast forward. My part in this is ActionPack, where we right now are down to 9 failures and 0 errors, from 23 failures and 8 errors. Those numbers are for 1150 tests and 5202 assertions, so there isn't much left to get this working.

My work on the YARV compiler continues, and I will soon post an update about this too.

söndag, januari 28, 2007

Focus on Java, this Tuesday

This Tuesday is JFokus in Stockholm, where I will talk about Java, JRuby and RSpec and how to combine these in exciting ways. Let me tell you, I look forward to speaking about this. I believe there is something incredibly useful in combining technologies like this.

Of course, it would also have been great fun to take about where JRuby is at right now, since there is so much cool stuff going on at the moment. When the 0.9.3 release comes along, I bet many people will be surprised and as excited as I am about this. I will get back with more information what has happened in the codebase lately quite soon.

If you're going to JFokus, please say hi if you see me!

lördag, januari 27, 2007

Advice

I usually don't like to use this blog for strictly personal reasons, but I will do an exception for once, to get advice from y'all.

Hypothetically, I would like to know what kind of work opportunities I should look for, if I was in a situation where my current work situation was alright, but not satisfactory (since I've been at the same place for 6 years.) Further, I'm interested in getting away from Sweden. The places I would most likely want to be situated in would be SF or London.

The picture is complicated by my lack of academic degrees. The kind of experience I have is strictly professional and recreational. (In which category should I put my work on JRuby?). Apart from that, my interests are in the region of work where I can use different languages, and will not be constrained by Java. I haven't done consulting, and maybe I should do that. On the other hand, I'm not sure that is the right thing for me either.

So, please. I need advice. What should I do with my professional life at this moment?

fredag, januari 19, 2007

YARV tail call optimization in JRuby

After some further developments on the YARVMachine, I can report that JRuby trunk supports most of the optimized instructions that YARV makes use of. The big thing missing is the local cache optimization. But that is just an aside from the main course.

Because right now there is support in JRuby's YARVMachine to handle a limited form of tail call optimization. Specifically, if the last call in a method is to the method we're in and the receiver of that call is the same as the current self, tail call optimization will happen. That allows JRuby to run this script:
def fact(n, acc)
if n == 0
acc
else
fact n-1, n*acc
end
end

p fact(25000, 1)
That will explode in both YARV and MRI, long before getting anywhere, since the stack goes out. But this will work correctly in JRuby with -y, provided that the tail call optimization is actually turned on. To turn it on, use $JAVA_OPTS and set the variable jruby.tailcall.enabled to true, like this:
JAVA_OPTS="-Djruby.tailcall.enabled=true"
jruby -y testRecFact.rbc
Of course, you need latest trunk for this to work, and you need to compile the YARV file as described in my previous post. But provided you have done that, the above will actually work perfectly, without deepening the stack at all. The reason this is not turned on by default in the YARVMachine is that it isn't completely safe yet. There is one small kink, which is that if you redefine the current method within the current method, and then call self, this will not work as expected. It should be easy to add checks for this behavior, though, so that will come soon.

Of course, the big problem with something like this is the stack trace. How to handle it? The implementation behavior would make it look like those 25000 calls to fact was just a single one. In the same manner, trace methods won't get called.

But trunk will actually report when these tail calls have been done. Say you have a script like this:
def a(n)
if n > 20000
raise "hell"
end
a(n+1)
end

a(0)
(it is designed to explode at a certain depth, of course.) In current JRuby trunk, executed with -y, this will generate an output that looks like this:
testRaise.rb:-1:in `a' TAIL CALL(20001): hell (RuntimeError)
from testRaise.rb:-1
So it is quite obvious that the exception was raised in the 20001:th invocation of 'a'.

This work goes forward very fast, and it's funny to see progress happen this quickly. Yesterday SASADA Koichi visited the #jruby and #rubinius IRC channels, and we had some very interesting discussions on further collaboration. The future looks bright indeed, and this weekend I'll probably have time enough to take a first crack at a YARV compiler for JRuby.

torsdag, januari 18, 2007

Executing YARV (in JRuby)

I guess the title says it all. Oh, it doesn't? You want what? A tutorial on how to play with this? Well, alright then.

What you will need to get started is first and foremost JRuby trunk. Download and build that. You will also need either a very recent version of YARV or Ruby trunk. Download either and build that too. I have the source in $YARV_SRC and $RUBY_TRUNK_SRC. I've also installed them with suffixes, so I have ruby-yarv and ruby-trunk globally available. That's a quite good setup.

Before compiling some Ruby, we need to change the change the compile-script slightly. So open up the file in $YARV_SRC/tool/compile.rb and disable the peephole_optimization and inline_const_cache, since JRuby doesn't really support these features yet. If you use Ruby trunk, you also need to do a global search-and-replace in this file, from YARVCore to VM.

Now you're finished to compile something. The goal for this execution have been to get an iterative fibonacci sequence running, so save this code in a file called fib.rb:
def fib_iter_ruby(n)
i = 0
j = 1
cur = 1
while cur <= n
k = i
i = j
j = k + j
cur = cur + 1
end
i
end

puts fib_iter_ruby(5000)
Next, compile this file:
ruby-yarv $YARV_SRC/tool/compile.rb -o fib.rbc fib.rb
Modify as needed if you use Ruby trunk instead. Now, how to run this? With the y-flag to JRuby:
jruby -y fib.rbc
As you can see, simple files like this just work. Of course, there are much missing yet, but basic interpretation works really nice. Some more additions to the YARV machine will come quite soon, probably. But the next step will be to implement a compiler for YARV too. From that point it should be possible to execute Ruby-files in JRuby in several different ways; by regular interpretation, YARV compilation, YARV interpretation, Java bytecode AOT compiling, Java bytecode JIT compiling and also possibly Rubinius interpretation. The future is, as always, interesting.

fredag, januari 12, 2007

Rubinius and Lisp

Yesterday on the #rubinius-channel, me, Evan and MenTaLguY had the beginnings of a discussion about a Lisp dialect for the Rubinius VM. Since this sound exactly like the kind of thing I've been thinking about for some time, I got excited. But anyway, Pat Eyler covered the issue much better and did a small interview with us that can be read here. Ruby is wonderful. Rubinius is sweet. With Lisp added to the mix, it will be better.

I'll probably follow this up with some more information and ideas, as soon it's fleshed out.

torsdag, januari 11, 2007

That Rails Thing

I need to join the fray. Pat Eyler has announced a competition together with APress. The first installment is about how Rails has made me a better programmer. Details to be found here.

So, let's get at it. Rails has inspired and affected me in numerous ways. You got to realize that I have been programming web applications in Java for way too many years. Before that I've done both ASP and PHP. Nothing ever felt natural. I've tried many of the LISP frameworks (and Uncommon Web is really cool). I've embraced continuation-based frameworks. But none felt so powerful, yet nonintrusive. Rails embodies the best parts of Ruby.

For me, Rails is very interesting for several reasons. First and foremost is the fact that it is an incredibly good framework. It's really amazing how good it is. And that in itself acts as an inspiration. To know that software can be this good makes me want to strive to perfect my API's, make my libraries more usable, and finding new and novel ways to improve my DSL's.

But that's only part of it. The flip side of this is that Rails is not perfect. In fact, there are myriad ways it can be improved. And that gives me hope, because it also means that no matter how good my code gets, it can always get better. And that means I'll never be totally bored!

In a very literal sense, Rails has made me a better programmer in another way. Since Ruby on Rails was the first Ruby-application to make it into Karolinska Institutet, it means I can thank Rails for being able to write more Ruby at work. And writing Ruby instead of Java must make you a better programmer, neh?

Of course, Rails is an excellent testing tool for seeing how far we have left with JRuby. It goes without saying that you become a better programmer by implementing a language...

I have several applications and libraries that I keep in mind when writing my code. Those libraries act as a gauge against which I measure my code. Code quality, testing ability, interface, sheer trickyness; in all these areas, Rails is one of the top frameworks I know.

söndag, januari 07, 2007

Five Things.

Oh well. It has finally hit me, as I knew it would sooner or later. Charles O Nutter managed to nail me.

If you don't know what this is, it's called the "5 Things Meme" and it means I'll tell you 5 things about me that you probably don't know, and then pass the baton on to 5 other people. We'll see about that.
  • I am an "academic failure" in that I haven't even finished the Swedish equivalent to High School (in Swedish it's Gymnasium). There is no thing about computers I have learned in school. And even though I have no education, I actually work centrally at Karolinska Institutet, which is one of the more esteemed universities in Sweden.
  • I am an amateur musician. I play guitar, some piano, sing quite a lot and play a few other instruments (but not very good). I create some music, but nothing that has been finished enough to make public. Until recently I was a singer in a Swedish barbershop chorus called the Entertainmen. We came 14:th on the World Barbershop Competition in Salt Lake City 2 years ago. I used to sing Lead, but switched to Bari.
  • I train martial arts. I have been doing so for most of my life, but not with enough regularity to attain a black belt yet. What I've been training for the last few years is called Bujinkan Budo Taijutsu, and it seems I will stay with it.
  • I am a vegetarian, and has been for the past 10 years. I don't eat meat, fowl or fish, but I do eat egg and dairy products.
  • I live in a former mental hospital, in a beautiful park 20 minutes from central Stockholm. The hospital was built 1908 and looks very much like a castle.
So. Now I've done my share. What's left is to give this burden to someone else. Since I don't like the concept of chain *anything* I will introduce a small twist by tagging 5 people who probably won't do it, for several reasons. But if they do it, it will be all the more interesting. So, without further ado: