The speed of exception handling !?!

Christoph Kulla Christoph.Kulla at tu-clausthal.de
Thu Apr 2 00:56:26 PST 1998


Hi,

The exception handling code in kaffe is very slow. Running the
following program, shows that SUNs VM executes more than twenty times faster!
I´m using Kaffe without debug code and with JIT enabled (default under
Linux).

class kaffeExceptions {

  public static final void generateException () throws Exception {
    throw new Exception ();
  }
  
  public static final void main (String[] args)  {
    for (int i=0; i<20000; i++)
      try {
        generateException ();
      } catch (Exception exp) {
      }
  }
}

time java kaffeExceptions

real    0m2.069s
user    0m1.770s
sys     0m0.220s

time kaffe kaffeExceptions

real    0m44.913s
user    0m43.060s
sys     0m0.410s


Creating exception objects without throwing them, results in:

public static final void generateException () throws Exception {
  new Exception ();
}

time java kaffeExceptions

real    0m1.904s
user    0m1.620s
sys     0m0.250s

time kaffe kaffeExceptions

real    0m36.853s
user    0m34.570s
sys     0m0.380s

Creating an empty method, results in:

public static final void generateException () throws Exception {
}

time java kaffeExceptions

real    0m1.613s
user    0m1.420s
sys     0m0.170s

time kaffe kaffeExceptions

real    0m2.026s
user    0m1.900s
sys     0m0.070s

Obviously the problem is not the exception throwing or handling, the problem
is the exception class object instantiation. But Object instantiation in
general is not the problem

class A {
}

class kaffeExceptions {

  public static final void generateException () throws Exception {
    new A ();
  }
  
  public static final void main (String[] args)  {
    for (int i=0; i<20000; i++)
      try {
        generateException ();
      } catch (Exception exp) {
      }
  }
}

time java kaffeExceptions

real    0m1.936s
user    0m1.470s
sys     0m0.190s

time kaffe kaffeExceptions

real    0m2.167s
user    0m1.990s
sys     0m0.120s

Bye,

        Christoph


More information about the kaffe mailing list