classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Informative throws


From: Eric Blake
Subject: RE: Informative throws
Date: Fri, 27 Jul 2001 10:05:07 +0100

I ran some tests on this example:
class Bar
{
  public static void main(String[] args)
  {
    // ternary version:
    throw Configuration.EXCEPTION_MESSAGES ?
        new RuntimeException("simple message") :
        new RuntimeException();
    // if/else version:
    // if (Configuration.EXCEPTION_MESSAGES)
    //   throw new RuntimeException("simple message");
    // else
    //   throw new RuntimeException();
  }
}


Here's a quick comparison in bytes generated, using compilers I have access
to:

    Compiler:  Jikes 1.14   Jikes+   Javac 1.4-beta   kjc 1.5A
ternary true:     365         350      346            346
ternary false:    368         299      295            295
if/else true:     354         354      346            346
if/else false:    303         303      295            295

Jikes+ is my personal version of jikes, with patches pending for inclusion
in 1.15 applied.  One of these patches optimizes ternary statements with a
constant condition to behave like if/else (so that dead code is not
emitted).

The 4-8 byte difference between jikes+ and kjc is due to extra line numbers
being emitted by jikes; compiling with `jikes -O' strips the line number
table which drops the minimum size to 271.  But compiling with
`javac -O -g:none' strips even more, down to 221 bytes (although I won't
decompile the file to see WHAT got stripped, in order to stay on the safe
side of copyright issues).  Something to consider - maybe ./configure should
be aware of the best set of optimizing flags to pass to a compiler when
generating a maximally stripped .jar.

(This may be off-topic for this list, but maybe someone working on binutils
could extend the functionality of strip(1) to remove debug information from
.class files, rather than requiring the java compiler to do it.  And from
there, automake could be tweaked to improve the behavior of `make
install-strip'...)

--
Eric Blake, Elixent, Castlemead, Lwr Castle St., Bristol BS1 3AG, UK
address@hidden   tel:+44(0)117 917 5611


> -----Original Message-----
> From: address@hidden
> [mailto:address@hidden Behalf Of Stuart Ballard
> Sent: 26 July 2001 19:30
> To: address@hidden
> Cc: Eric Blake; classpath
> Subject: Re: Informative throws
>
> There's always:
>
> throw Configuration.EXCEPTION_MESSAGES ?
>       new NumberFormatException("string null or empty") :
>       new NumberFormatException();
>
> This is, I think, slightly more readable - although I've always been a
> fan of the ternary operator, so I'm biased perhaps.
>
> Stuart.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]