enabling/disabling assertions

Per Bothner per@bothner.com
Mon Mar 1 23:16:00 GMT 2004

Sun's "java" command has -enableassertions and -disableassertions
options to control whether assertions are tested.  When a JIT is
used, assertions have no run-time cost.  However, since we have
an ahead-of-time compiler, we want to disable generation of
assertion code at compile-time.

For my client, and probably most people, a global option to disable
assertions is sufficient, so I probably won't implement more than
that.  However, we should have a more general design, in case
someone wants to implement JDK-style file-grained control.

I propose two new gcj options:
The syntax for NAME matches that for JDK's java command:
If there is no "=NAME" the default applies to all classes.

In JDK, javac always generates assertions, but assertions are
disabled by default at run-time.  I suggest our default should
be that gcj generates assertions by default when generating
class files or compiling without optimization, and by default
disables assertions when compiling to native code with optimization.
The --enable-assertions and --disable-assertions flags override
the defaults.

We should also also add support for enabling/disabling assertions
in gij, though that is less urgent.  (I don't plan on doing it.)
Here we should follow Sun's syntax, though we should allow
--[enable|disable]-assertions[=NAME] as a GNU-style synonym for

	--Per Bothner
per@bothner.com   http://per.bothner.com/

More information about the Java mailing list