Debugging native code with Hotspot and GDB

The last couple of hours I struggled to debug a segfault some JNI code of OpenJDK. I could not get GDB doing anything useful with Hotspot. Until I discovered the following very useful command line option:

java -XX:OnError="gdb - %p" MyApplication

This fires up gdb whenever an error occurs, and sets up all the libraries etc for debugging. Very nice. Ideally you do this using a debug build of OpenJDK, so get get as much useful information as possible.

Escher on OpenJDK graphics

After a couple of hours hacking I’ve got a small Swing demo running pretty cool on my ‘next generation’ Escher peer implementation:

This uses the JDK Java2D rendering pipeline architecture. The cool thing is, that there are generic implementations for (almost?) everything Java2D. I started out with a bare minimum implementation which only could set and get single pixel. This was awefully slow. I optimized a couple things: accelerated (X Pixmap) volatile images instead of buffered images, blitting between those and the window surface, drawing lines, filling and drawing rectangles and a very simple font renderer. This is already enough to allow large pieces of Swing to render pretty fast. And it covers all of Java2D with no extra effort (but slowly).

Regarding the font rendering, I am not sure why it looks so crappy. I have the feeling that the glyphs are not hinted, but this is the FreeType font engine and it should do hinting (or not?). At the graphics level I only set the pixels that I am told to set. Besides that I have nothing to do with the glyphs at all. The EscherTextRenderer is a simple subclass of GlyphListPipe, which implements only drawGlyphList(). If anybody has a good guess how I can improve the glyph rendering, please comment.

Kudos to whoever designed the Java2D pipeline architecture (I think it was Jim Graham). It is really well thought out in most places. I think I will write up some documentation on how to get started, so that implementing new graphics backends becomes a little easier.

FOSDEM

This year’s FOSDEM has been a great event, as every year. I’ll try to wrap up my personal highlights.

Friday

I arrived in the evening and immediately headed for the Brandweg hacking session and general gathering to the BXL. The waitresses wouldn’t let us go upstairs into our usual location, but when more and more people joined us, they had no choice but open up. I guess they were not really prepared for such an event. In the end they became really nervous that things get out of hand, so we collected money to pay the bill and leave. I went to the hotel then because I was very tired.

Saturday

The keynote talks have been kindof disappointing for me. I couldn’t really relate to the Hollywood and FreeBSD stuff. The patent talk was an interesting update though.

Regarding the various talks I will only mention my personal highlights. All talks have been very cool, but I can’t cover every bit here.

Mark and Mark wrapped up what happened during the last year to GNU Classpath and OpenJDK, and where things are going. GNU Classpath ain’t dead at all,though things slowed down, and OpenJDK is moving towards 100% free software steadily.

Christian Thalinger gave an interesting overview and comparison about the different VM interfaces of GNU Classpath, phoneme and OpenJDK. Especially since I’m porting OpenJDK to Jamaica now.

I was really excited about what Guillaume showed with MIDPath. He did some really amazing work on those little devices, showing off a number of great demos.

My own talk didn’t go that well. I was suffering from a major headache at this time because I didn’t drink anything for the whole day (that always kills me). I think I spoiled the party a little by bashing OpenJDK handling of the community, which probably came around too negative. (Yes, some developers do very good work with handling the community). And to make things worse, my nice demos of OpenJDK-Swing-on-Escher and OpenJDK-Swing-on-GTK crashed because I was trying to run them on a clean OpenJDK, but they require some patches in Swing and AWT. Too bad.

Andrew picked up my own mashup things and introduced Brandweg, a project similar to IcedTea, but in the other direction. (GNU Classpath, patched with OpenJDK stuff where appropriate).

The VM rumble was great, just as last year. Robert gave a good update on JamVM (which goes into a JIT-like direction now), Kaffe collapses to a big shell script that pulls in all the pieces, Hotspot is getting better all the time, and conquering new platforms with Gary’s zero assembler hacks.

In the evening (almost) everybody gathered at the FOSDEM dinner. The food was very good, very expensive and too little for my hunger. Afterwards, a couple of people moved over into a greek(?) bar, where a small but loud YMCA party was going on. Fun, but not good for chatting. I had some nice conversations anyway, geeks are so boring ;-).

Sunday

The first talk I attended on Sunday was Lillian’s and Thomas’ talk about IcedTea. They did some truly amazing stuff, turning OpenJDK into a free software JDK, and plugging the holes with GNU Classpath pieces for the API, NetX as a WebStart replacement and gcjwebplugin/IcedTeaPlugin as browser plugin. Very nice. Thomas also showed some of his work to implement LiveConnect in the IcedTeaPlugin.

The cool stuff section had some amazing projects showing off really cool stuff. Steph showed FBToolkit, a very cool project which aims to provide an alternative AWT toolkit/graphics implementation for framebuffers and other backends. Mario did a very nice presentation about his work on the GConf preferences, Classpath’s Desktop API implementation and about his GStreamer backend for javax.sound, showing off a nice rocking demonstration.  The JNode impressed me very much, despite the technical problems. A whole operating system mostly written in Java (plus some assembler for the very low level device stuff), this is really cool.

Unfortunately I missed the Jalimo talk and everything afterwards, because I had to leave to catch my train. In the train I turned all the fresh inspiration into code and completed a first prototype of the new Escher peers (aka Caciocavallo), which are based on OpenJDK’s architecture for Java2D (SunGraphics2D, SunGraphicsEnvironment, et al). I had a very very first prototype already running before FOSDEM, but this was awefully slow. Now I can already do some Swing stuff at reasonable speed. That’s really amazing (to me).

Escher 0.3 released

Today I released the Escher library, version 0.3. This has long been overdue. Here’s a quick list of changes:

  • Performance has been greatly enhanced. This required an almost complete rewrite of the innards, but is really blazingly fast now ;-).
  • Image, pixmap, window property and fonts support have been significantly improved.
  • The render extension has been extended for glyph support.
  • API has been cleaned up, making many public methods private that shouldn’t be public, hiding fields behind accessors, removing cruft and making use of Java5 language features.

You can find all the code at the project download page. Have fun.

How to use a Linux box as CD player

This might sound like a stupid title. But there are some real gotchas that many might know.

I used to listen CDs using the usual preinstalled setup, namely Rhythmbox and the usual Gnome tools. This has a couple of disadvantages:

  •  The output volume never seems to be correct. Either it is too low, making the music sound thin, or it is too high, driving the amp and/or soundcard into clipping and distortion.
  • The CD drive spins up like mad, using the maximum drive speed. This is annoying because of the noise, and not necessary at all, 1x speed is enough for CD audio playback.
  • There is a small pause between every song, this is disturbing in live recordings, or when songs of a CD are mastered together like on The Beatles’ Abbey Road album.
  • This might not be as important, but is a side effect of how all this is implemented. Instead of playing the digital data directly from the CD into the soundcard, it gets pulled over the bus via libcdparanoia and pumped into the PCM (!) input of the soundcard. This is certainly overkill, because all modern soundcards have a direct connection with the CD drive, and can play directly from CD.

The solution to the first problem is to use alsamixer, a command line tool to adjust the mixer settings. Here you can see for each channel the effective dB gain. Set this to 0.0 for all channels.

The solution to the other problems is to avoid Rhythmbox (or, for that matter, all of the other CD playing tools in Gnome, like gnome-cd, soundjuicer, and whatnot) and use another set of command line tools, cdplay, cdstop, etc. These are found in the Ubuntu/Debian package cdtool. These tools do not use gstreamer, but instead play directly from CD to soundcard.

If anybody knows of programs that accomplish this in a GUIish fashion and integrate nicely with Gnome, please comment. Yes, I know, Amarok is a little better here, but frankly, I don’t like the thing either.