August 4th 2010

Java’s ZipFile performance

I have an application that scales well up to around five threads a core, due to the mix of IO and CPU that it does.

That is, you give it more threads, and the throughput increases; the overall time goes down.

The following graph shows, in blue, the Sun’s java.util.zip.ZipFile time to complete a set of unzips on an increasing number of threads:

Wait, what the cocking shit.

Continue Reading »

No Comments yet »

April 23rd 2010

Java/C++ polyglot

Today I discovered Java’s “inline C++” keyword, //\u000a/*, which makes a Java/C++ polyglot pretty easy:


//\u000a/*
#include <iostream>

#define private
#define public
#define static
#define void int
struct {
  std::ostream &println(const char *c) {
    return std::cout << c < < std::endl;
  }
} out;

//*/
/*\u002a/
import static java.lang.System.out;

public class Polyglot {
//*/
  public static void main(/*\u002a/String[] args//*/
      ) {
    out.println("Hello from whatever language this is!");
  }

/*\u002a/
}
// */

Eclipse deals.. okay. The red-underlining in the commented sections is for the spelling. <3

1 Comment »

April 18th 2010

InstallShield unpacker

I couldn’t find anything that would unpack the (entirely unnecessary) Nokia map loader set-up application, which is some InstallShield 7 nastiness.

deshield can. Given the number of magic numbers in it, I fully expect it not to work with other installers.

Why do they bother? The data isn’t even compressed; it’s just bit-twiddled a little with the file-name, and this magic number: [ 0x13, 0x35, 0x86, 0x07 ].

2 Comments »

April 8th 2010

Tro^WMicrobenchmarks!

This blog is far too low in trolling. As a start, everyone knows that git is fast and svn is slow, but I wasn’t aware quite how shocking the difference was.

The test: committing a file that slowly increases in size, and a new file, 200 times.

git: 2 seconds.
darcs: 10 seconds.
bzr: 70 seconds.
svn: 200 seconds.

No comment.

Reproduction steps follow.
Continue Reading »

3 Comments »

March 14th 2010

But Java /can/ do that!

I recently attended a talk at FOSDEM by Miguel de Icaza, a fellow enemy of “Free” software.

He, like most .NET users, is desperately seeking features to differentiate his second-rate platform from the wonderfulnessness of Java.

He showed .NET expressions, a wonderful feature whereby the actual nature of a predicate can be retrieved at runtime and optimal, say, SQL can be built to match it.

He, however, claimed that Java lacks this feature. This is not the case.

ExpressionTest shows various uses of this in Java; basically:

Expression.toSQL(new Predicate() { @Override public boolean matches(FooDTO t) { t.a == 7; } });

will return:

(a = 7)

Obviously this remains slightly more verbose while the Java lambda proposals are finalised, but the feature is hardly missing!

Similarily,
return (t.a == 7 || t.a == 8 || t.a == 9) && "pony".equals(t.b);

becomes:

(a = 7 AND b = 'pony') OR
(a = 8 AND b = 'pony') OR
(a = 9 AND b = 'pony')

And, etc.

The implementation, if the devil compels you to look.

4 Comments »

February 13th 2010

Catchlogger

Post seriousness: 70%.

Catchlogger [jar] [git src] checks that exceptions are being logged properly.

It’s entirely fallible, but, if your codebase is prone to catching and ignoring exception, and you use log4j, it’s Very Helpful.

For example:

try {
  foo();
} catch (IOException e) {
  logger.error("bar: failed to foo", e);
}

This is fine; an error has occurred and it’s full stacktrace will be placed in the log4j configured log.

try {
  foo();
} catch (IOException e) {
  logger.error(e);
  logger.info("oh noes", e);
  e.printStackTrace();
}

None of these, however, will do anything useful. The first logs just the toString() to the error log, info is too low-level to log exceptions at, and printStackTrace() doesn’t necessarily go anywhere at all.

For this block, catchlogger will issue:
IOException e unused at (Test.java:15) in public main(String[] args) in path.

The JAR is huge as it pulls in the entire Eclipse compiler to parse the source. BSD/MIT licensed.

No Comments yet »

Next »