Next: , Previous: Warnings, Up: Invoking gcj


1.5 Code Generation

In addition to the many gcc options controlling code generation, gcj has several options specific to itself.

--main=CLASSNAME
This option is used when linking to specify the name of the class whose main method should be invoked when the resulting executable is run. 1
-Dname[=value]
This option can only be used with --main. It defines a system property named name with value value. If value is not specified then it defaults to the empty string. These system properties are initialized at the program's startup and can be retrieved at runtime using the java.lang.System.getProperty method.
-C
This option is used to tell gcj to generate bytecode (.class files) rather than object code.
--resource resource-name
This option is used to tell gcj to compile the contents of a given file to object code so it may be accessed at runtime with the core protocol handler as `core:/resource-name'. Note that resource-name is the name of the resource as found at runtime; for instance, it could be used in a call to ResourceBundle.getBundle. The actual file name to be compiled this way must be specified separately.
-d directory
When used with -C, this causes all generated .class files to be put in the appropriate subdirectory of directory. By default they will be put in subdirectories of the current working directory.
-fno-bounds-check
By default, gcj generates code which checks the bounds of all array indexing operations. With this option, these checks are omitted, which can improve performance for code that uses arrays extensively. Note that this can result in unpredictable behavior if the code in question actually does violate array bounds constraints. It is safe to use this option if you are sure that your code will never throw an ArrayIndexOutOfBoundsException.
-fno-store-check
Don't generate array store checks. When storing objects into arrays, a runtime check is normally generated in order to ensure that the object is assignment compatible with the component type of the array (which may not be known at compile-time). With this option, these checks are omitted. This can improve performance for code which stores objects into arrays frequently. It is safe to use this option if you are sure your code will never throw an ArrayStoreException.
-fjni
With gcj there are two options for writing native methods: CNI and JNI. By default gcj assumes you are using CNI. If you are compiling a class with native methods, and these methods are implemented using JNI, then you must use -fjni. This option causes gcj to generate stubs which will invoke the underlying JNI methods.
-fno-assert
Don't recognize the assert keyword. This is for compatibility with older versions of the language specification.
-fno-optimize-static-class-initialization
When the optimization level is greater or equal to -O2, gcj will try to optimize the way calls into the runtime are made to initialize static classes upon their first use (this optimization isn't carried out if -C was specified.) When compiling to native code, -fno-optimize-static-class-initialization will turn this optimization off, regardless of the optimization level in use.

Footnotes

[1] The linker by default looks for a global function named main. Since Java does not have global functions, and a collection of Java classes may have more than one class with a main method, you need to let the linker know which of those main methods it should invoke when starting the application.