Who is codebix.com?

30. December, 2010

Since a few days, I got pingbacks from codebix.com. Their site contains a lot of links to a lot of blogs but no real added value as far as I can tell … who are those guys? What’s their game?

Pestered by deadlocks?

30. December, 2010

Serge Beauchamp wrote a tool to automatically locate and report places where they can occur: Freescale’s Deadlock Preventer is now released!

Details can be found in this blog post.

Another lesson in performance: NIO

29. December, 2010

Remember when I wondered how slow it is to copy data around in memory?

This time, I needed to load a 2MB file from disk and examine it for certain patterns.

The original from jazzy spell checker worked like this: It did a binary search in the file for a code. The code would be at the start of each line and be separated from the correct word by an asterisk:


The search algorithm would seek somewhere in the file, skip the current line, read the next one, compare the code against the one we look for. If our code was smaller, we would seek backward; if it was larger, we would seek forward. Standard binary search.

Only it didn’t work. The test took 4 seconds to load the file without finding anything. Debugging recursive algorithms isn’t as nice as looking at them …

So I considered a different approach: I would load the whole file, character by character, and remember the lines with the same code in an index. A good time to have a look at NIO, especially the grep example.

Question: If it takes 4 seconds to seek ten times in a RandomAccessFile and read about 2000 bytes from it, how long would it take to read it character by character, examine each line, build an index and then load whole chunks (say, 1KB each) from the file when a word needs to be looked up? Plus the additional work of removing the code pattern from the chunk to produce a list of words …

Answer: 0.3 seconds. That’s more than ten times faster. And I could probably optimize the code some more.

Conclusion: When it comes to performance, measurement beats superstition.

And the new code is easy to understand, and to test, too! ^_^

Fixing problems in models

29. December, 2010

MDD is nice as long as you don’t have exceptions. If you generate 1,000 classes and then one of them needs something special, you’re in trouble.

I think support for applying patches to the result of the code generation step would be a nice feature.

Java tip: Getting most out of exceptions

28. December, 2010

Exceptions should have two purposes: 1. Clean up after an error and 2. help you solve the issue. Sadly, many Java developers often forget about #2.

So you end up with an exception thrown in SignatureFileVerifier (no source). Or even in a native method. The error message is:

Invalid signature file digest for Manifest main attributes

Right. Which tells us exactly … nothing. The stack trace isn’t better:

java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
	at sun.security.util.SignatureFileVerifier.processImpl(SignatureFileVerifier.java:221)
	at sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:176)
	at java.util.jar.JarVerifier.processEntry(JarVerifier.java:233)
	at java.util.jar.JarVerifier.update(JarVerifier.java:188)
	at java.util.jar.JarFile.initializeVerifier(JarFile.java:325)
	at java.util.jar.JarFile.getInputStream(JarFile.java:390)
	at sun.misc.URLClassPath$JarLoader$1.getInputStream(URLClassPath.java:620)
	at sun.misc.Resource.cachedInputStream(Resource.java:59)
	at sun.misc.Resource.getByteBuffer(Resource.java:84)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:249)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
	at org.eclipse.jface.action.LegacyActionTools.initLocalizedModifiers(LegacyActionTools.java:699)
	at org.eclipse.jface.action.LegacyActionTools.findLocalizedModifier(LegacyActionTools.java:356)
	at org.eclipse.jface.action.LegacyActionTools.convertLocalizedAccelerator(LegacyActionTools.java:167)
	at org.eclipse.jface.action.Action.setText(Action.java:665)
	at de.pdark.epen.editor.actions.ForwardAction.(ForwardAction.java:29)
	at de.pdark.epen.editor.actions.ForwardActionTest.testCreate(ForwardActionTest.java:21)

So LegacyActionTools needs a class. Which one? Since I don’t have the source, how can I set a breakpoint?

Simple: Set the breakpoint in the constructor of the exception! Even native code has to pass through here, eventually.

Java performance

27. December, 2010

James Sutherland: “Java performance optimization is part analysis, and part superstition and witch craft.”

In his blog post “What is faster? JVM Performance,” he compares various ways to solve problems in Java and how they perform. For example, how the various map types perform.

What surprised me as well was to poor performance of HashMap. 23% slower than Hashtable…

Another surprise that block synchronized code is twice as expensive as synchronized methods. Tools like FindBugs discourage using synchronized methods.

Or the impact of volatile on field access.

Merry Christmas

24. December, 2010
Christmas in the post-War United States

Image via Wikipedia

Merry Christmas to you all 🙂

Identifying you

22. December, 2010

You have a firewall, NoScript, disabled cookies and everything. Do you think you’re surfing anonymously?

Think again: http://panopticlick.eff.org/index.php

Humble Indie Bundle

19. December, 2010

Good games are rare today. Most games feel like DOOM clones with better graphics. Fun if you have the reflexes of a 10-year old … and the intellectual horizon. Makes me wonder why a lot of them have an “adults only” sticker or must not be sold to minors … Most of them don’t run on Linux (or need a remove-the-f***ing DRM patch – so playing the game I just bought is illegal).

But there are exceptions and The Humble Indie Bundle #2 is one of them. Five of them. Even though I don’t like all of them. So four of them. Three … I didn’t play Revenge of the Titans, yet.

Braid. An insane jump’n’run with time travel and non-repeating puzzles. I think more than enough has been said about this game.

Cortex Command is a 3D shoot-em-up, the graphics are coarse, I fought more with the controls than with the game plus it’s a game for 10-year olds. ‘Nuff said.

Machinarium. Wow. Beautiful graphics, sad story, clever and demanding puzzles. The only flaw: It uses flash. It’s not really a flaw of the game – there simply isn’t a better cross-platform framework than Flash. Sad, isn’t it?

Osmos brings slow motion back. No need to rush things. Some levels take a long time to complete. A little push here, wait, a tiny push there, … atmo sound. Great to relax.

And best of all, you set the price and the split. With freedom comes responsibility 🙂

Security is nothing without trust and respect

17. December, 2010

Little Brother” got me thinking. When the DHS tries to make the city more safe and secure, they just make it worse. Why?

Because they ignore one of the most fundamental principles without which society cannot work: Trust and respect.

That doesn’t mean you need to trust someone completely or respect them in every way. It means: Know how much you can and should trust someone. Then treat them politely, without second thoughts. Surprise: Our brains have been trained for the millions of years before we had speech to read body language. And we’re really good at it.

You don’t have to be nice to a terrorist, bow your head to them or grovel. Not at all. But just imaging how kicking you around, killing your family, relatives, friends, would make you feel.

Now, I imagine that terrorists aren’t exactly lenient or forgiving. So if you would become mad at such a treatment, what will they do? Go on a killing spree? Gee, I think that’s exactly what they do. How surprising.

Which puts us into a delicate position. We can only be safe when we start treating everyone else on the planet with respect. Respect can mean to drive your car for another year, even if it sucks. Or to sell it to someone poor way under price because they deserve it — just as a human. It doesn’t mean we should all convert to the Islam or anything.

It just means that: Show some basic respect (as in polite).

It probably doesn’t mean to go to a poor country, “help” them fight against terrorism and then “suddenly” discover that there are billions of dollars buried in the ground. These people might not have spent a lot of time in school, but they spend an awful lot of time haggling at the bazaar. They see you lie.

Imagine if all the terrorists in the world believed that there were better ways to make them as happy as us. Wouldn’t that be better than strip searches at airports, constant fear of an attack, ever more complicated and even debasing security laws? What’s security without respect?

If we were 100% secure, no one could go anywhere (they might be infected), talk to anyone (they might spill secrets), do anything (they might make mistakes). In computer sciences, you learn early that a secure computer is one which is switched off, without any data or use. Secure but useless.

That’s why security measurements in companies work out so badly: If they were really enforced, the company couldn’t do business anymore. So you have to trust your workers. You have to treat them with respect or else you get the very problems that your dream of “security” pretended to solve.

%d bloggers like this: