1 \input texinfo @c -*-texinfo-*-
3 @settitle Guide to GNU gcj
5 @c Merge the standard indexes into a single one.
12 @include gcc-common.texi
14 @c Note: When reading this manual you'll find lots of strange
15 @c circumlocutions like ``compiler for the Java language''.
16 @c This is necessary due to Sun's restrictions on the use of
19 @c When this manual is copyrighted.
20 @set copyrights-gcj 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
23 @c man begin COPYRIGHT
24 Copyright @copyright{} @value{copyrights-gcj} Free Software Foundation, Inc.
26 Permission is granted to copy, distribute and/or modify this document
27 under the terms of the GNU Free Documentation License, Version 1.2 or
28 any later version published by the Free Software Foundation; with no
29 Invariant Sections, the Front-Cover Texts being (a) (see below), and
30 with the Back-Cover Texts being (b) (see below).
31 A copy of the license is included in the
33 section entitled ``GNU Free Documentation License''.
35 @c man begin COPYRIGHT
40 @c man begin COPYRIGHT
42 (a) The FSF's Front-Cover Text is:
46 (b) The FSF's Back-Cover Text is:
48 You have freedom to copy and modify this GNU Manual, like GNU
49 software. Copies published by the Free Software Foundation raise
50 funds for GNU development.
56 @dircategory Software development
58 * Gcj: (gcj). Ahead-of-time compiler for the Java language
61 @dircategory Individual utilities
63 * jcf-dump: (gcj)Invoking jcf-dump.
64 Print information about Java class files
65 * gij: (gcj)Invoking gij. GNU interpreter for Java bytecode
66 * gcj-dbtool: (gcj)Invoking gcj-dbtool.
67 Tool for manipulating class file databases.
68 * jv-convert: (gcj)Invoking jv-convert.
69 Convert file from one encoding to another
70 * grmic: (gcj)Invoking grmic.
71 Generate stubs for Remote Method Invocation.
72 * gc-analyze: (gcj)Invoking gc-analyze.
73 Analyze Garbage Collector (GC) memory dumps.
74 * aot-compile: (gcj)Invoking aot-compile.
75 Compile bytecode to native and generate databases.
76 * rebuild-gcj-db: (gcj)Invoking rebuild-gcj-db.
77 Merge the per-solib databases made by aot-compile
78 into one system-wide database.
91 @vskip 0pt plus 1filll
92 Published by the Free Software Foundation @*
93 51 Franklin Street, Fifth Floor@*
94 Boston, MA 02110-1301, USA@*
105 This manual describes how to use @command{gcj}, the GNU compiler for the
106 Java programming language. @command{gcj} can generate both @file{.class}
107 files and object files, and it can read both Java source code and
111 * Copying:: The GNU General Public License
112 * GNU Free Documentation License::
113 How you can share and copy this manual
114 * Invoking gcj:: Compiler options supported by @command{gcj}
115 * Compatibility:: Compatibility between gcj and other tools for Java
116 * Invoking jcf-dump:: Print information about class files
117 * Invoking gij:: Interpreting Java bytecodes
118 * Invoking gcj-dbtool:: Tool for manipulating class file databases.
119 * Invoking jv-convert:: Converting from one encoding to another
120 * Invoking grmic:: Generate stubs for Remote Method Invocation.
121 * Invoking gc-analyze:: Analyze Garbage Collector (GC) memory dumps.
122 * Invoking aot-compile:: Compile bytecode to native and generate databases.
123 * Invoking rebuild-gcj-db:: Merge the per-solib databases made by aot-compile
124 into one system-wide database.
125 * About CNI:: Description of the Compiled Native Interface
126 * System properties:: Modifying runtime behavior of the libgcj library
127 * Resources:: Where to look for more information
138 @chapter Invoking gcj
140 @c man title gcj Ahead-of-time compiler for the Java language
143 @c man begin SYNOPSIS gcj
144 gcj [@option{-I}@var{dir}@dots{}] [@option{-d} @var{dir}@dots{}]
145 [@option{--CLASSPATH}=@var{path}] [@option{--classpath}=@var{path}]
146 [@option{-f}@var{option}@dots{}] [@option{--encoding}=@var{name}]
147 [@option{--main}=@var{classname}] [@option{-D}@var{name}[=@var{value}]@dots{}]
148 [@option{-C}] [@option{--resource} @var{resource-name}] [@option{-d} @var{directory}]
149 [@option{-W}@var{warn}@dots{}]
150 @var{sourcefile}@dots{}
152 @c man begin SEEALSO gcj
153 gcc(1), gcjh(1), gjnih(1), gij(1), jcf-dump(1), gfdl(7),
154 and the Info entries for @file{gcj} and @file{gcc}.
158 @c man begin DESCRIPTION gcj
160 As @command{gcj} is just another front end to @command{gcc}, it supports many
161 of the same options as gcc. @xref{Option Summary, , Option Summary,
162 gcc, Using the GNU Compiler Collection (GCC)}. This manual only documents the
163 options specific to @command{gcj}.
168 * Input and output files::
169 * Input Options:: How gcj finds files
170 * Encodings:: Options controlling source file encoding
171 * Warnings:: Options controlling warnings specific to gcj
172 * Linking:: Options for making an executable
173 * Code Generation:: Options controlling the output of gcj
174 * Configure-time Options:: Options you won't use
177 @c man begin OPTIONS gcj
179 @node Input and output files
180 @section Input and output files
182 A @command{gcj} command is like a @command{gcc} command, in that it
183 consists of a number of options and file names. The following kinds
184 of input file names are supported:
187 @item @var{file}.java
189 @item @var{file}.class
192 @itemx @var{file}.jar
193 An archive containing one or more @code{.class} files, all of
194 which are compiled. The archive may be compressed. Files in
195 an archive which don't end with @samp{.class} are treated as
196 resource files; they are compiled into the resulting object file
197 as @samp{core:} URLs.
199 A file containing a whitespace-separated list of input file names.
200 (Currently, these must all be @code{.java} source files, but that
202 Each named file is compiled, just as if it had been on the command line.
203 @item @var{library}.a
204 @itemx @var{library}.so
205 @itemx -l@var{libname}
206 Libraries to use when linking. See the @command{gcc} manual.
209 You can specify more than one input file on the @command{gcj} command line,
210 in which case they will all be compiled. If you specify a
211 @code{-o @var{FILENAME}}
212 option, all the input files will be compiled together, producing a
213 single output file, named @var{FILENAME}.
214 This is allowed even when using @code{-S} or @code{-c},
215 but not when using @code{-C} or @code{--resource}.
216 (This is an extension beyond the what plain @command{gcc} allows.)
217 (If more than one input file is specified, all must currently
218 be @code{.java} files, though we hope to fix this.)
221 @section Input Options
225 @command{gcj} has options to control where it looks to find files it needs.
226 For instance, @command{gcj} might need to load a class that is referenced
227 by the file it has been asked to compile. Like other compilers for the
228 Java language, @command{gcj} has a notion of a @dfn{class path}. There are
229 several options and environment variables which can be used to
230 manipulate the class path. When @command{gcj} looks for a given class, it
231 searches the class path looking for matching @file{.class} or
232 @file{.java} file. @command{gcj} comes with a built-in class path which
233 points at the installed @file{libgcj.jar}, a file which contains all the
236 In the text below, a directory or path component can refer either to an
237 actual directory on the filesystem, or to a @file{.zip} or @file{.jar}
238 file, which @command{gcj} will search as if it is a directory.
242 All directories specified by @code{-I} are kept in order and prepended
243 to the class path constructed from all the other options. Unless
244 compatibility with tools like @code{javac} is important, we recommend
245 always using @code{-I} instead of the other options for manipulating the
248 @item --classpath=@var{path}
249 This sets the class path to @var{path}, a colon-separated list of paths
250 (on Windows-based systems, a semicolon-separate list of paths).
251 This does not override the builtin (``boot'') search path.
253 @item --CLASSPATH=@var{path}
254 Deprecated synonym for @code{--classpath}.
256 @item --bootclasspath=@var{path}
257 Where to find the standard builtin classes, such as @code{java.lang.String}.
259 @item --extdirs=@var{path}
260 For each directory in the @var{path}, place the contents of that
261 directory at the end of the class path.
264 This is an environment variable which holds a list of paths.
267 The final class path is constructed like so:
271 First come all directories specified via @code{-I}.
274 If @option{--classpath} is specified, its value is appended.
275 Otherwise, if the @code{CLASSPATH} environment variable is specified,
276 then its value is appended.
277 Otherwise, the current directory (@code{"."}) is appended.
280 If @code{--bootclasspath} was specified, append its value.
281 Otherwise, append the built-in system directory, @file{libgcj.jar}.
284 Finally, if @code{--extdirs} was specified, append the contents of the
285 specified directories at the end of the class path. Otherwise, append
286 the contents of the built-in extdirs at @code{$(prefix)/share/java/ext}.
289 The classfile built by @command{gcj} for the class @code{java.lang.Object}
290 (and placed in @code{libgcj.jar}) contains a special zero length
291 attribute @code{gnu.gcj.gcj-compiled}. The compiler looks for this
292 attribute when loading @code{java.lang.Object} and will report an error
293 if it isn't found, unless it compiles to bytecode (the option
294 @code{-fforce-classes-archive-check} can be used to override this
295 behavior in this particular case.)
298 @item -fforce-classes-archive-check
299 This forces the compiler to always check for the special zero length
300 attribute @code{gnu.gcj.gcj-compiled} in @code{java.lang.Object} and
301 issue an error if it isn't found.
303 @item -fsource=@var{VERSION}
304 This option is used to choose the source version accepted by
305 @command{gcj}. The default is @samp{1.5}.
311 The Java programming language uses Unicode throughout. In an effort to
312 integrate well with other locales, @command{gcj} allows @file{.java} files
313 to be written using almost any encoding. @command{gcj} knows how to
314 convert these encodings into its internal encoding at compile time.
316 You can use the @code{--encoding=@var{NAME}} option to specify an
317 encoding (of a particular character set) to use for source files. If
318 this is not specified, the default encoding comes from your current
319 locale. If your host system has insufficient locale support, then
320 @command{gcj} assumes the default encoding to be the @samp{UTF-8} encoding
323 To implement @code{--encoding}, @command{gcj} simply uses the host
324 platform's @code{iconv} conversion routine. This means that in practice
325 @command{gcj} is limited by the capabilities of the host platform.
327 The names allowed for the argument @code{--encoding} vary from platform
328 to platform (since they are not standardized anywhere). However,
329 @command{gcj} implements the encoding named @samp{UTF-8} internally, so if
330 you choose to use this for your source files you can be assured that it
331 will work on every host.
337 @command{gcj} implements several warnings. As with other generic
338 @command{gcc} warnings, if an option of the form @code{-Wfoo} enables a
339 warning, then @code{-Wno-foo} will disable it. Here we've chosen to
340 document the form of the warning which will have an effect -- the
341 default being the opposite of what is listed.
344 @item -Wredundant-modifiers
345 With this flag, @command{gcj} will warn about redundant modifiers. For
346 instance, it will warn if an interface method is declared @code{public}.
348 @item -Wextraneous-semicolon
349 This causes @command{gcj} to warn about empty statements. Empty statements
350 have been deprecated.
352 @item -Wno-out-of-date
353 This option will cause @command{gcj} not to warn when a source file is
354 newer than its matching class file. By default @command{gcj} will warn
357 @item -Wno-deprecated
358 Warn if a deprecated class, method, or field is referred to.
361 This is the same as @command{gcc}'s @code{-Wunused}.
364 This is the same as @code{-Wredundant-modifiers -Wextraneous-semicolon
372 To turn a Java application into an executable program,
373 you need to link it with the needed libraries, just as for C or C++.
374 The linker by default looks for a global function named @code{main}.
375 Since Java does not have global functions, and a
376 collection of Java classes may have more than one class with a
377 @code{main} method, you need to let the linker know which of those
378 @code{main} methods it should invoke when starting the application.
379 You can do that in any of these ways:
383 Specify the class containing the desired @code{main} method
384 when you link the application, using the @code{--main} flag,
387 Link the Java package(s) into a shared library (dll) rather than an
388 executable. Then invoke the application using the @code{gij} program,
389 making sure that @code{gij} can find the libraries it needs.
391 Link the Java packages(s) with the flag @code{-lgij}, which links
392 in the @code{main} routine from the @code{gij} command.
393 This allows you to select the class whose @code{main} method you
394 want to run when you run the application. You can also use
395 other @code{gij} flags, such as @code{-D} flags to set properties.
396 Using the @code{-lgij} library (rather than the @code{gij} program
397 of the previous mechanism) has some advantages: it is compatible with
398 static linking, and does not require configuring or installing libraries.
401 These @code{gij} options relate to linking an executable:
404 @item --main=@var{CLASSNAME}
405 This option is used when linking to specify the name of the class whose
406 @code{main} method should be invoked when the resulting executable is
409 @item -D@var{name}[=@var{value}]
410 This option can only be used with @code{--main}. It defines a system
411 property named @var{name} with value @var{value}. If @var{value} is not
412 specified then it defaults to the empty string. These system properties
413 are initialized at the program's startup and can be retrieved at runtime
414 using the @code{java.lang.System.getProperty} method.
417 Create an application whose command-line processing is that
418 of the @code{gij} command.
420 This option is an alternative to using @code{--main}; you cannot use both.
423 This option causes linking to be done against a static version of the
424 libgcj runtime library. This option is only available if
425 corresponding linker support exists.
427 @strong{Caution:} Static linking of libgcj may cause essential parts
428 of libgcj to be omitted. Some parts of libgcj use reflection to load
429 classes at runtime. Since the linker does not see these references at
430 link time, it can omit the referred to classes. The result is usually
431 (but not always) a @code{ClassNotFoundException} being thrown at
432 runtime. Caution must be used when using this option. For more
434 @w{@uref{http://gcc.gnu.org/wiki/Statically%20linking%20libgcj}}
437 @node Code Generation
438 @section Code Generation
440 In addition to the many @command{gcc} options controlling code generation,
441 @command{gcj} has several options specific to itself.
446 This option is used to tell @command{gcj} to generate bytecode
447 (@file{.class} files) rather than object code.
449 @item --resource @var{resource-name}
450 This option is used to tell @command{gcj} to compile the contents of a
451 given file to object code so it may be accessed at runtime with the core
452 protocol handler as @samp{core:/@var{resource-name}}. Note that
453 @var{resource-name} is the name of the resource as found at runtime; for
454 instance, it could be used in a call to @code{ResourceBundle.getBundle}.
455 The actual file name to be compiled this way must be specified
458 @item -ftarget=@var{VERSION}
459 This can be used with @option{-C} to choose the version of bytecode
460 emitted by @command{gcj}. The default is @samp{1.5}. When not
461 generating bytecode, this option has no effect.
463 @item -d @var{directory}
464 When used with @code{-C}, this causes all generated @file{.class} files
465 to be put in the appropriate subdirectory of @var{directory}. By
466 default they will be put in subdirectories of the current working
469 @item -fno-bounds-check
470 By default, @command{gcj} generates code which checks the bounds of all
471 array indexing operations. With this option, these checks are omitted, which
472 can improve performance for code that uses arrays extensively. Note that this
473 can result in unpredictable behavior if the code in question actually does
474 violate array bounds constraints. It is safe to use this option if you are
475 sure that your code will never throw an @code{ArrayIndexOutOfBoundsException}.
477 @item -fno-store-check
478 Don't generate array store checks. When storing objects into arrays, a runtime
479 check is normally generated in order to ensure that the object is assignment
480 compatible with the component type of the array (which may not be known
481 at compile-time). With this option, these checks are omitted. This can
482 improve performance for code which stores objects into arrays frequently.
483 It is safe to use this option if you are sure your code will never throw an
484 @code{ArrayStoreException}.
487 With @command{gcj} there are two options for writing native methods: CNI
488 and JNI@. By default @command{gcj} assumes you are using CNI@. If you are
489 compiling a class with native methods, and these methods are implemented
490 using JNI, then you must use @code{-fjni}. This option causes
491 @command{gcj} to generate stubs which will invoke the underlying JNI
495 Don't recognize the @code{assert} keyword. This is for compatibility
496 with older versions of the language specification.
498 @item -fno-optimize-static-class-initialization
499 When the optimization level is greater or equal to @code{-O2},
500 @command{gcj} will try to optimize the way calls into the runtime are made
501 to initialize static classes upon their first use (this optimization
502 isn't carried out if @code{-C} was specified.) When compiling to native
503 code, @code{-fno-optimize-static-class-initialization} will turn this
504 optimization off, regardless of the optimization level in use.
506 @item --disable-assertions[=@var{class-or-package}]
507 Don't include code for checking assertions in the compiled code.
508 If @code{=@var{class-or-package}} is missing disables assertion code
509 generation for all classes, unless overridden by a more
510 specific @code{--enable-assertions} flag.
511 If @var{class-or-package} is a class name, only disables generating
512 assertion checks within the named class or its inner classes.
513 If @var{class-or-package} is a package name, disables generating
514 assertion checks within the named package or a subpackage.
516 By default, assertions are enabled when generating class files
517 or when not optimizing, and disabled when generating optimized binaries.
519 @item --enable-assertions[=@var{class-or-package}]
520 Generates code to check assertions. The option is perhaps misnamed,
521 as you still need to turn on assertion checking at run-time,
522 and we don't support any easy way to do that.
523 So this flag isn't very useful yet, except to partially override
524 @code{--disable-assertions}.
526 @item -findirect-dispatch
527 @command{gcj} has a special binary compatibility ABI, which is enabled
528 by the @code{-findirect-dispatch} option. In this mode, the code
529 generated by @command{gcj} honors the binary compatibility guarantees
530 in the Java Language Specification, and the resulting object files do
531 not need to be directly linked against their dependencies. Instead,
532 all dependencies are looked up at runtime. This allows free mixing of
533 interpreted and compiled code.
535 Note that, at present, @code{-findirect-dispatch} can only be used
536 when compiling @file{.class} files. It will not work when compiling
537 from source. CNI also does not yet work with the binary compatibility
538 ABI. These restrictions will be lifted in some future release.
540 However, if you compile CNI code with the standard ABI, you can call
541 it from code built with the binary compatibility ABI.
543 @item -fbootstrap-classes
544 This option can be use to tell @code{libgcj} that the compiled classes
545 should be loaded by the bootstrap loader, not the system class loader.
546 By default, if you compile a class and link it into an executable, it
547 will be treated as if it was loaded using the system class loader.
548 This is convenient, as it means that things like
549 @code{Class.forName()} will search @samp{CLASSPATH} to find the
552 @item -freduced-reflection
553 This option causes the code generated by @command{gcj} to contain a
554 reduced amount of the class meta-data used to support runtime
555 reflection. The cost of this savings is the loss of
556 the ability to use certain reflection capabilities of the standard
557 Java runtime environment. When set all meta-data except for that
558 which is needed to obtain correct runtime semantics is eliminated.
560 For code that does not use reflection (i.e. serialization, RMI, CORBA
561 or call methods in the @code{java.lang.reflect} package),
562 @code{-freduced-reflection} will result in proper operation with a
563 savings in executable code size.
565 JNI (@code{-fjni}) and the binary compatibility ABI
566 (@code{-findirect-dispatch}) do not work properly without full
567 reflection meta-data. Because of this, it is an error to use these options
568 with @code{-freduced-reflection}.
570 @strong{Caution:} If there is no reflection meta-data, code that uses
571 a @code{SecurityManager} may not work properly. Also calling
572 @code{Class.forName()} may fail if the calling method has no
573 reflection meta-data.
578 @node Configure-time Options
579 @section Configure-time Options
581 Some @command{gcj} code generations options affect the resulting ABI, and
582 so can only be meaningfully given when @code{libgcj}, the runtime
583 package, is configured. @code{libgcj} puts the appropriate options from
584 this group into a @samp{spec} file which is read by @command{gcj}. These
585 options are listed here for completeness; if you are using @code{libgcj}
586 then you won't want to touch these options.
590 This enables the use of the Boehm GC bitmap marking code. In particular
591 this causes @command{gcj} to put an object marking descriptor into each
594 @item -fhash-synchronization
595 By default, synchronization data (the data used for @code{synchronize},
596 @code{wait}, and @code{notify}) is pointed to by a word in each object.
597 With this option @command{gcj} assumes that this information is stored in a
598 hash table and not in the object itself.
600 @item -fuse-divide-subroutine
601 On some systems, a library routine is called to perform integer
602 division. This is required to get exception handling correct when
605 @item -fcheck-references
606 On some systems it's necessary to insert inline checks whenever
607 accessing an object via a reference. On other systems you won't need
608 this because null pointer accesses are caught automatically by the
615 @chapter Compatibility with the Java Platform
617 As we believe it is important that the Java platform not be fragmented,
618 @command{gcj} and @code{libgcj} try to conform to the relevant Java
619 specifications. However, limited manpower and incomplete and unclear
620 documentation work against us. So, there are caveats to using
629 @section Standard features not yet supported
631 This list of compatibility issues is by no means complete.
635 @command{gcj} implements the JDK 1.2 language. It supports inner classes
636 and the new 1.4 @code{assert} keyword. It does not yet support the Java 2
637 @code{strictfp} keyword (it recognizes the keyword but ignores it).
640 @code{libgcj} is largely compatible with the JDK 1.2 libraries.
641 However, @code{libgcj} is missing many packages, most notably
642 @code{java.awt}. There are also individual missing classes and methods.
643 We currently do not have a list showing differences between
644 @code{libgcj} and the Java 2 platform.
647 Sometimes the @code{libgcj} implementation of a method or class differs
648 from the JDK implementation. This is not always a bug. Still, if it
649 affects you, it probably makes sense to report it so that we can discuss
650 the appropriate response.
653 @command{gcj} does not currently allow for piecemeal replacement of
654 components within @code{libgcj}. Unfortunately, programmers often want
655 to use newer versions of certain packages, such as those provided by
656 the Apache Software Foundation's Jakarta project. This has forced us
657 to place the @code{org.w3c.dom} and @code{org.xml.sax} packages into
658 their own libraries, separate from @code{libgcj}. If you intend to
659 use these classes, you must link them explicitly with
660 @code{-l-org-w3c-dom} and @code{-l-org-xml-sax}. Future versions of
661 @command{gcj} may not have this restriction.
665 @section Extra features unique to gcj
667 The main feature of @command{gcj} is that it can compile programs written in
668 the Java programming language to native code. Most extensions that have been
669 added are to facilitate this functionality.
673 @command{gcj} makes it easy and efficient to mix code written in Java and C++.
674 @xref{About CNI}, for more info on how to use this in your programs.
677 When you compile your classes into a shared library using
678 @code{-findirect-dispatch} then add them to the system-wide
679 classmap.db file using @code{gcj-dbtool}, they will be automatically
680 loaded by the @code{libgcj} system classloader. This is the new,
681 preferred classname-to-library resolution mechanism. @xref{Invoking
682 gcj-dbtool}, for more information on using the classmap database.
685 The old classname-to-library lookup mechanism is still supported
686 through the @code{gnu.gcj.runtime.VMClassLoader.library_control}
687 property, but it is deprecated and will likely be removed in some
688 future release. When trying to load a class @code{gnu.pkg.SomeClass}
689 the system classloader will first try to load the shared library
690 @file{lib-gnu-pkg-SomeClass.so}, if that fails to load the class then
691 it will try to load @file{lib-gnu-pkg.so} and finally when the class
692 is still not loaded it will try to load @file{lib-gnu.so}. Note that
693 all @samp{.}s will be transformed into @samp{-}s and that searching
694 for inner classes starts with their outermost outer class. If the
695 class cannot be found this way the system classloader tries to use the
696 @code{libgcj} bytecode interpreter to load the class from the standard
697 classpath. This process can be controlled to some degree via the
698 @code{gnu.gcj.runtime.VMClassLoader.library_control} property;
699 @xref{libgcj Runtime Properties}.
702 @code{libgcj} includes a special @samp{gcjlib} URL type. A URL of
703 this form is like a @code{jar} URL, and looks like
704 @samp{gcjlib:/path/to/shared/library.so!/path/to/resource}. An access
705 to one of these URLs causes the shared library to be @code{dlopen()}d,
706 and then the resource is looked for in that library. These URLs are
707 most useful when used in conjunction with @code{java.net.URLClassLoader}.
708 Note that, due to implementation limitations, currently any such URL
709 can be accessed by only one class loader, and libraries are never
710 unloaded. This means some care must be exercised to make sure that
711 a @code{gcjlib} URL is not accessed by more than one class loader at once.
712 In a future release this limitation will be lifted, and such
713 libraries will be mapped privately.
716 A program compiled by @command{gcj} will examine the
717 @env{GCJ_PROPERTIES} environment variable and change its behavior in
718 some ways. In particular @env{GCJ_PROPERTIES} holds a list of
719 assignments to global properties, such as would be set with the
720 @option{-D} option to @command{java}. For instance,
721 @samp{java.compiler=gcj} is a valid (but currently meaningless)
723 @cindex GCJ_PROPERTIES
724 @vindex GCJ_PROPERTIES
729 @node Invoking jcf-dump
730 @chapter Invoking jcf-dump
732 @c man title jcf-dump print information about Java class files
735 @c man begin SYNOPSIS jcf-dump
736 jcf-dump [@option{-c}] [@option{--javap}]
737 [@option{--classpath}=@var{path}] [@option{--CLASSPATH}=@var{path}]
738 [@option{-I}@var{dir}@dots{}] [@option{-o} @var{file}]
739 [@option{--version}] [@option{--help}] [@option{-v}] [@option{--verbose}]
740 @var{classname}@dots{}
742 @c man begin SEEALSO jcf-dump
743 gcc(1), gcj(1), gcjh(1), gij(1), jcf-dump(1), gfdl(7),
744 and the Info entries for @file{gcj} and @file{gcc}.
748 @c man begin DESCRIPTION jcf-dump
750 This is a class file examiner, similar to @code{javap}. It will print
751 information about a number of classes, which are specified by class name
756 @c man begin OPTIONS jcf-dump
760 Disassemble method bodies. By default method bodies are not printed.
762 @item --print-constants
763 Print the constant pool. When printing a reference to a constant
764 also print its index in the constant pool.
767 Generate output in @code{javap} format. The implementation of this
768 feature is very incomplete.
770 @item --classpath=@var{path}
771 @itemx --CLASSPATH=@var{path}
772 @itemx -I@var{directory}
774 These options as the same as the corresponding @command{gcj} options.
777 Print help, then exit.
780 Print version number, then exit.
783 Print extra information while running.
784 Implies @code{--print-constants}.
790 @chapter Invoking gij
792 @c man title gij GNU interpreter for Java bytecode
795 @c man begin SYNOPSIS gij
796 gij [@option{OPTION}] @dots{} @var{JARFILE} [@var{ARGS}@dots{}]
798 gij [@option{-jar}] [@option{OPTION}] @dots{} @var{CLASS} [@var{ARGS}@dots{}]
799 [@option{-cp} @var{path}] [@option{-classpath} @var{path}]
800 [@option{-D}@var{name}[=@var{value}]@dots{}]
801 [@option{-ms=}@var{number}] [@option{-mx=}@var{number}]
802 [@option{-X@var{argument}}] [@option{-verbose}] [@option{-verbose:class}]
803 [@option{--showversion}] [@option{--version}] [@option{--help}][@option{-?}]
805 @c man begin SEEALSO gij
806 gcc(1), gcj(1), gcjh(1), jcf-dump(1), gfdl(7),
807 and the Info entries for @file{gcj} and @file{gcc}.
811 @c man begin DESCRIPTION gij
813 @code{gij} is a Java bytecode interpreter included with @code{libgcj}.
814 @code{gij} is not available on every platform; porting it requires a
815 small amount of assembly programming which has not been done for all the
816 targets supported by @command{gcj}.
818 The primary argument to @code{gij} is the name of a class or, with
819 @code{-jar}, a jar file. Options before this argument are interpreted
820 by @code{gij}; remaining options are passed to the interpreted program.
822 If a class name is specified and this class does not have a @code{main}
823 method with the appropriate signature (a @code{static void} method with
824 a @code{String[]} as its sole argument), then @code{gij} will print an
827 If a jar file is specified then @code{gij} will use information in it to
828 determine which class' @code{main} method will be invoked.
830 @code{gij} will invoke the @code{main} method with all the remaining
831 command-line options.
833 Note that @code{gij} is not limited to interpreting code. Because
834 @code{libgcj} includes a class loader which can dynamically load shared
835 objects, it is possible to give @code{gij} the name of a class which has
836 been compiled and put into a shared library on the class path.
840 @c man begin OPTIONS gij
844 @itemx -classpath @var{path}
845 Set the initial class path. The class path is used for finding
846 class and resource files. If specified, this option overrides the
847 @code{CLASSPATH} environment variable. Note that this option is
848 ignored if @code{-jar} is used.
850 @item -D@var{name}[=@var{value}]
851 This defines a system property named @var{name} with value @var{value}.
852 If @var{value} is not specified then it defaults to the empty string.
853 These system properties are initialized at the program's startup and can
854 be retrieved at runtime using the @code{java.lang.System.getProperty}
857 @item -ms=@var{number}
858 Equivalent to @code{-Xms}.
860 @item -mx=@var{number}
861 Equivalent to @code{-Xmx}.
864 Do not verify compliance of bytecode with the VM specification. In addition,
865 this option disables type verification which is otherwise performed on BC-ABI
869 @itemx -X@var{argument}
870 Supplying @code{-X} by itself will cause @code{gij} to list all the
871 supported @code{-X} options. Currently these options are supported:
875 Set the initial heap size.
878 Set the maximum heap size.
881 Set the thread stack size.
884 Unrecognized @code{-X} options are ignored, for compatibility with
888 This indicates that the name passed to @code{gij} should be interpreted
889 as the name of a jar file, not a class.
893 Print help, then exit.
896 Print version number and continue.
899 Print detailed version information, then exit.
902 Print version number, then exit.
905 @itemx -verbose:class
906 Each time a class is initialized, print a short message on standard error.
909 @code{gij} also recognizes and ignores the following options, for
910 compatibility with existing application launch scripts:
911 @code{-client}, @code{-server}, @code{-hotspot}, @code{-jrockit},
912 @code{-agentlib}, @code{-agentpath}, @code{-debug}, @code{-d32},
913 @code{-d64}, @code{-javaagent}, @code{-noclassgc}, @code{-verify},
914 and @code{-verifyremote}.
918 @node Invoking gcj-dbtool
919 @chapter Invoking gcj-dbtool.
921 @c man title gcj-dbtool Manipulate class file mapping databases for libgcj
924 @c man begin SYNOPSIS gcj-dbtool
925 gcj-dbtool @option{OPTION} @var{DBFILE} [@option{MORE}] @dots{}
927 gcj-dbtool [@option{-0}] [@option{-}] [@option{-n}] [@option{-a}] [@option{-f}]
928 [@option{-t}] [@option{-l}] [@option{-p} [@var{LIBDIR}]]
929 [@option{-v}] [@option{-m}] [@option{--version}] [@option{--help}]
932 @c man begin SEEALSO gcj-dbtool
933 gcc(1), gcj(1), gcjh(1), jcf-dump(1), gfdl(7),
934 and the Info entries for @file{gcj} and @file{gcc}.
938 @c man begin DESCRIPTION gcj-dbtool
940 @code{gcj-dbtool} is a tool for creating and manipulating class file
941 mapping databases. @code{libgcj} can use these databases to find a
942 shared library corresponding to the bytecode representation of a
943 class. This functionality is useful for ahead-of-time compilation of
944 a program that has no knowledge of @code{gcj}.
946 @code{gcj-dbtool} works best if all the jar files added to it are
947 compiled using @code{-findirect-dispatch}.
949 Note that @code{gcj-dbtool} is currently available as ``preview
950 technology''. We believe it is a reasonable way to allow
951 application-transparent ahead-of-time compilation, but this is an
952 unexplored area. We welcome your comments.
956 @c man begin OPTIONS gcj-dbtool
959 @item -n @var{DBFILE} [@var{SIZE}]
960 This creates a new database. Currently, databases cannot be resized;
961 you can choose a larger initial size if desired. The default size is
964 @item -a @var{DBFILE} @var{JARFILE} @var{LIB}
965 @itemx -f @var{DBFILE} @var{JARFILE} @var{LIB}
966 This adds a jar file to the database. For each class file in the jar,
967 a cryptographic signature of the bytecode representation of the class
968 is recorded in the database. At runtime, a class is looked up by its
969 signature and the compiled form of the class is looked for in the
970 corresponding shared library. The @option{-a} option will verify
971 that @var{LIB} exists before adding it to the database; @option{-f}
974 @item [@option{-}][@option{-0}] -m @var{DBFILE} @var{DBFILE},[@var{DBFILE}]
975 Merge a number of databases. The output database overwrites any
976 existing database. To add databases into an existing database,
977 include the destination in the list of sources.
979 If @option{-} or @option{-0} are used, the list of files to read is
980 taken from standard input instead of the command line. For
981 @option{-0}, Input filenames are terminated by a null character
982 instead of by whitespace. Useful when arguments might contain white
983 space. The GNU find -print0 option produces input suitable for this
986 @item -t @var{DBFILE}
989 @item -l @var{DBFILE}
990 List the contents of a database.
993 Print the name of the default database. If there is no default
994 database, this prints a blank line. If @var{LIBDIR} is specified, use
995 it instead of the default library directory component of the database
999 Print a help message, then exit.
1003 Print version information, then exit.
1009 @node Invoking jv-convert
1010 @chapter Invoking jv-convert
1012 @c man title jv-convert Convert file from one encoding to another
1014 @c man begin SYNOPSIS jv-convert
1015 @command{jv-convert} [@option{OPTION}] @dots{} [@var{INPUTFILE} [@var{OUTPUTFILE}]]
1018 [@option{--encoding} @var{name}]
1019 [@option{--from} @var{name}]
1020 [@option{--to} @var{name}]
1021 [@option{-i} @var{file}] [@option{-o} @var{file}]
1022 [@option{--reverse}] [@option{--help}] [@option{--version}]
1026 @c man begin DESCRIPTION jv-convert
1028 @command{jv-convert} is a utility included with @code{libgcj} which
1029 converts a file from one encoding to another. It is similar to the Unix
1030 @command{iconv} utility.
1032 The encodings supported by @command{jv-convert} are platform-dependent.
1033 Currently there is no way to get a list of all supported encodings.
1037 @c man begin OPTIONS jv-convert
1040 @item --encoding @var{name}
1041 @itemx --from @var{name}
1042 Use @var{name} as the input encoding. The default is the current
1045 @item --to @var{name}
1046 Use @var{name} as the output encoding. The default is the
1047 @code{JavaSrc} encoding; this is ASCII with @samp{\u} escapes for
1048 non-ASCII characters.
1051 Read from @var{file}. The default is to read from standard input.
1054 Write to @var{file}. The default is to write to standard output.
1057 Swap the input and output encodings.
1060 Print a help message, then exit.
1063 Print version information, then exit.
1068 @node Invoking grmic
1069 @chapter Invoking grmic
1071 @c man title grmic Generate stubs for Remote Method Invocation
1073 @c man begin SYNOPSIS grmic
1074 @command{grmic} [@option{OPTION}] @dots{} @var{class} @dots{}
1077 [@option{-keepgenerated}]
1081 [@option{-nocompile}]
1083 [@option{-d} @var{directory}]
1089 @c man begin DESCRIPTION grmic
1091 @command{grmic} is a utility included with @code{libgcj} which generates
1092 stubs for remote objects.
1094 @c FIXME: Add real information here.
1095 @c This really isn't much more than the --help output.
1097 Note that this program isn't yet fully compatible with the JDK
1098 @command{grmic}. Some options, such as @option{-classpath}, are
1099 recognized but currently ignored. We have left these options
1100 undocumented for now.
1102 Long options can also be given with a GNU-style leading @samp{--}. For
1103 instance, @option{--help} is accepted.
1107 @c man begin OPTIONS grmic
1111 @itemx -keepgenerated
1112 By default, @command{grmic} deletes intermediate files. Either of these
1113 options causes it not to delete such files.
1116 Cause @command{grmic} to create stubs and skeletons for the 1.1
1120 Cause @command{grmic} to create stubs and skeletons compatible with both
1121 the 1.1 and 1.2 protocol versions. This is the default.
1124 Cause @command{grmic} to create stubs and skeletons for the 1.2
1128 Don't compile the generated files.
1131 Print information about what @command{grmic} is doing.
1133 @item -d @var{directory}
1134 Put output files in @var{directory}. By default the files are put in
1135 the current working directory.
1138 Print a help message, then exit.
1141 Print version information, then exit.
1147 @node Invoking gc-analyze
1148 @chapter Invoking gc-analyze
1150 @c man title gc-analyze Analyze Garbage Collector (GC) memory dumps
1152 @c man begin SYNOPSIS gc-analyze
1153 @command{gc-analyze} [@option{OPTION}] @dots{} [@var{file}]
1156 [@option{--verbose}]
1157 [@option{-p} @var{tool-prefix}]
1158 [@option{-d} @var{directory}]
1159 [@option{--version}]
1164 @c man begin DESCRIPTION gc-analyze
1166 @command{gc-analyze} prints an analysis of a GC memory dump to
1169 The memory dumps may be created by calling
1170 @code{gnu.gcj.util.GCInfo.enumerate(String namePrefix)} from java
1171 code. A memory dump will be created on an out of memory condition if
1172 @code{gnu.gcj.util.GCInfo.setOOMDump(String namePrefix)} is called
1173 before the out of memory occurs.
1175 Running this program will create two files: @file{TestDump001} and
1176 @file{TestDump001.bytes}.
1179 import gnu.gcj.util.*;
1182 public class GCDumpTest
1184 static public void main(String args[])
1186 ArrayList<String> l = new ArrayList<String>(1000);
1188 for (int i = 1; i < 1500; i++) @{
1189 l.add("This is string #" + i);
1191 GCInfo.enumerate("TestDump");
1196 The memory dump may then be displayed by running:
1199 gc-analyze -v TestDump001
1202 @c FIXME: Add real information here.
1203 @c This really isn't much more than the --help output.
1207 @c man begin OPTIONS gc-analyze
1214 @item -p @var{tool-prefix}
1215 Prefix added to the names of the @command{nm} and @command{readelf} commands.
1217 @item -d @var{directory}
1218 Directory that contains the executable and shared libraries used when
1219 the dump was generated.
1222 Print a help message, then exit.
1225 Print version information, then exit.
1230 @node Invoking aot-compile
1231 @chapter Invoking aot-compile
1233 @c man title aot-compile Compile bytecode to native and generate databases
1237 @c man begin SYNOPSIS aot-compile
1238 aot-compile [@option{OPTION}] @dots{} @var{SRCDIR} @var{DSTDIR}
1240 aot-compile [@option{-M, --make}=@var{PATH}] [@option{-C, --gcj}=@var{PATH}]
1241 [@option{-D, --dbtool}=@var{PATH}] [@option{-m, --makeflags}=@var{FLAGS}]
1242 [@option{-c, --gcjflags}=@var{FLAGS}] [@option{-l, --ldflags}=@var{FLAGS}]
1243 [@option{-e, --exclude}=@var{PATH}]
1246 @c man begin SEEALSO aot-compile
1247 gcc(1), gcj(1), gcjh(1), jcf-dump(1), gfdl(7),
1248 and the Info entries for @file{gcj} and @file{gcc}.
1253 @c man begin DESCRIPTION aot-compile
1254 @code{aot-compile} is a script that searches a directory for Java bytecode
1255 (as class files, or in jars) and uses @code{gcj} to compile it to native
1256 code and generate the databases from it.
1259 @c man begin OPTIONS aot-compile
1261 @item -M, --make=@var{PATH}
1262 Specify the path to the @code{make} executable to use.
1264 @item -C, --gcj=@var{PATH}
1265 Specify the path to the @code{gcj} executable to use.
1267 @item -D, --dbtool=@var{PATH}
1268 Specify the path to the @code{gcj-dbtool} executable to use.
1270 @item -m, --makeflags=@var{FLAGS}
1271 Specify flags to pass to @code{make} during the build.
1273 @item -c, --gcjflags=@var{FLAGS}
1274 Specify flags to pass to @code{gcj} during compilation, in addition to
1275 '-fPIC -findirect-dispatch -fjni'.
1277 @item -l, --ldflags=@var{FLAGS}
1278 Specify flags to pass to @code{gcj} during linking, in addition to
1281 @item -e, --exclude=@var{PATH}
1282 Do not compile @var{PATH}.
1288 @node Invoking rebuild-gcj-db
1289 @chapter Invoking rebuild-gcj-db
1291 @c man title rebuild-gcj-db Merge the per-solib databases made by aot-compile into one system-wide database.
1294 @c man begin SYNOPSIS rebuild-gcj-db
1298 @c man begin SEEALSO rebuild-gcj-db
1299 gcc(1), gcj(1), gcjh(1), jcf-dump(1), gfdl(7),
1300 and the Info entries for @file{gcj} and @file{gcc}.
1305 @c man begin DESCRIPTION rebuild-gcj-db
1306 @code{rebuild-gcj-db} is a script that merges the per-solib databases made by
1307 @code{aot-compile} into one system-wide database so @code{gij} can find the
1314 This documents CNI, the Compiled Native Interface,
1315 which is is a convenient way to write Java native methods using C++.
1316 This is a more efficient, more convenient, but less portable
1317 alternative to the standard JNI (Java Native Interface).
1320 * Basic concepts:: Introduction to using CNI@.
1321 * Packages:: How packages are mapped to C++.
1322 * Primitive types:: Handling primitive Java types in C++.
1323 * Reference types:: Handling Java reference types in C++.
1324 * Interfaces:: How Java interfaces map to C++.
1325 * Objects and Classes:: C++ and Java classes.
1326 * Class Initialization:: How objects are initialized.
1327 * Object allocation:: How to create Java objects in C++.
1328 * Memory allocation:: How to allocate and free memory.
1329 * Arrays:: Dealing with Java arrays in C++.
1330 * Methods:: Java methods in C++.
1331 * Strings:: Information about Java Strings.
1332 * Mixing with C++:: How CNI can interoperate with C++.
1333 * Exception Handling:: How exceptions are handled.
1334 * Synchronization:: Synchronizing between Java and C++.
1335 * Invocation:: Starting the Java runtime from C++.
1336 * Reflection:: Using reflection from C++.
1340 @node Basic concepts
1341 @section Basic concepts
1343 In terms of languages features, Java is mostly a subset
1344 of C++. Java has a few important extensions, plus a powerful standard
1345 class library, but on the whole that does not change the basic similarity.
1346 Java is a hybrid object-oriented language, with a few native types,
1347 in addition to class types. It is class-based, where a class may have
1348 static as well as per-object fields, and static as well as instance methods.
1349 Non-static methods may be virtual, and may be overloaded. Overloading is
1350 resolved at compile time by matching the actual argument types against
1351 the parameter types. Virtual methods are implemented using indirect calls
1352 through a dispatch table (virtual function table). Objects are
1353 allocated on the heap, and initialized using a constructor method.
1354 Classes are organized in a package hierarchy.
1356 All of the listed attributes are also true of C++, though C++ has
1357 extra features (for example in C++ objects may be allocated not just
1358 on the heap, but also statically or in a local stack frame). Because
1359 @command{gcj} uses the same compiler technology as G++ (the GNU
1360 C++ compiler), it is possible to make the intersection of the two
1361 languages use the same ABI (object representation and calling
1362 conventions). The key idea in CNI is that Java objects are C++
1363 objects, and all Java classes are C++ classes (but not the other way
1364 around). So the most important task in integrating Java and C++ is to
1365 remove gratuitous incompatibilities.
1367 You write CNI code as a regular C++ source file. (You do have to use
1368 a Java/CNI-aware C++ compiler, specifically a recent version of G++.)
1370 @noindent A CNI C++ source file must have:
1373 #include <gcj/cni.h>
1376 @noindent and then must include one header file for each Java class it uses, e.g.:
1379 #include <java/lang/Character.h>
1380 #include <java/util/Date.h>
1381 #include <java/lang/IndexOutOfBoundsException.h>
1384 @noindent These header files are automatically generated by @code{gcjh}.
1387 CNI provides some functions and macros to make using Java objects and
1388 primitive types from C++ easier. In general, these CNI functions and
1389 macros start with the @code{Jv} prefix, for example the function
1390 @code{JvNewObjectArray}. This convention is used to avoid conflicts
1391 with other libraries. Internal functions in CNI start with the prefix
1392 @code{_Jv_}. You should not call these; if you find a need to, let us
1393 know and we will try to come up with an alternate solution.
1396 @subsection Limitations
1398 Whilst a Java class is just a C++ class that doesn't mean that you are
1399 freed from the shackles of Java, a @acronym{CNI} C++ class must adhere to the
1400 rules of the Java programming language.
1402 For example: it is not possible to declare a method in a CNI class
1403 that will take a C string (@code{char*}) as an argument, or to declare a
1404 member variable of some non-Java datatype.
1410 The only global names in Java are class names, and packages. A
1411 @dfn{package} can contain zero or more classes, and also zero or more
1412 sub-packages. Every class belongs to either an unnamed package or a
1413 package that has a hierarchical and globally unique name.
1415 A Java package is mapped to a C++ @dfn{namespace}. The Java class
1416 @code{java.lang.String} is in the package @code{java.lang}, which is a
1417 sub-package of @code{java}. The C++ equivalent is the class
1418 @code{java::lang::String}, which is in the namespace @code{java::lang}
1419 which is in the namespace @code{java}.
1421 @noindent Here is how you could express this:
1424 (// @r{Declare the class(es), possibly in a header file:}
1433 class java::lang::String : public java::lang::Object
1439 @noindent The @code{gcjh} tool automatically generates the necessary namespace
1443 @subsection Leaving out package names
1445 Always using the fully-qualified name of a java class can be
1446 tiresomely verbose. Using the full qualified name also ties the code
1447 to a single package making code changes necessary should the class
1448 move from one package to another. The Java @code{package} declaration
1449 specifies that the following class declarations are in the named
1450 package, without having to explicitly name the full package
1451 qualifiers. The @code{package} declaration can be
1452 followed by zero or more @code{import} declarations, which
1453 allows either a single class or all the classes in a package to be
1454 named by a simple identifier. C++ provides something similar with the
1455 @code{using} declaration and directive.
1460 import @var{package-name}.@var{class-name};
1463 @noindent allows the program text to refer to @var{class-name} as a shorthand for
1464 the fully qualified name: @code{@var{package-name}.@var{class-name}}.
1467 @noindent To achieve the same effect C++, you have to do this:
1470 using @var{package-name}::@var{class-name};
1474 @noindent Java can also cause imports on demand, like this:
1477 import @var{package-name}.*;
1480 @noindent Doing this allows any class from the package @var{package-name} to be
1481 referred to only by its class-name within the program text.
1484 @noindent The same effect can be achieved in C++ like this:
1487 using namespace @var{package-name};
1491 @node Primitive types
1492 @section Primitive types
1494 Java provides 8 @dfn{primitives} types which represent integers, floats,
1495 characters and booleans (and also the void type). C++ has its own
1496 very similar concrete types. Such types in C++ however are not always
1497 implemented in the same way (an int might be 16, 32 or 64 bits for example)
1498 so CNI provides a special C++ type for each primitive Java type:
1500 @multitable @columnfractions .20 .25 .60
1501 @item @strong{Java type} @tab @strong{C/C++ typename} @tab @strong{Description}
1502 @item @code{char} @tab @code{jchar} @tab 16 bit Unicode character
1503 @item @code{boolean} @tab @code{jboolean} @tab logical (true or false) values
1504 @item @code{byte} @tab @code{jbyte} @tab 8-bit signed integer
1505 @item @code{short} @tab @code{jshort} @tab 16 bit signed integer
1506 @item @code{int} @tab @code{jint} @tab 32 bit signed integer
1507 @item @code{long} @tab @code{jlong} @tab 64 bit signed integer
1508 @item @code{float} @tab @code{jfloat} @tab 32 bit IEEE floating point number
1509 @item @code{double} @tab @code{jdouble} @tab 64 bit IEEE floating point number
1510 @item @code{void} @tab @code{void} @tab no value
1513 When referring to a Java type You should always use these C++ typenames (e.g.: @code{jint})
1514 to avoid disappointment.
1517 @subsection Reference types associated with primitive types
1519 In Java each primitive type has an associated reference type,
1520 e.g.: @code{boolean} has an associated @code{java.lang.Boolean.TYPE} class.
1521 In order to make working with such classes easier GCJ provides the macro
1524 @deffn macro JvPrimClass type
1525 Return a pointer to the @code{Class} object corresponding to the type supplied.
1528 JvPrimClass(void) @result{} java.lang.Void.TYPE
1534 @node Reference types
1535 @section Reference types
1537 A Java reference type is treated as a class in C++. Classes and
1538 interfaces are handled this way. A Java reference is translated to a
1539 C++ pointer, so for instance a Java @code{java.lang.String} becomes,
1540 in C++, @code{java::lang::String *}.
1542 CNI provides a few built-in typedefs for the most common classes:
1543 @multitable @columnfractions .30 .25 .60
1544 @item @strong{Java type} @tab @strong{C++ typename} @tab @strong{Description}
1545 @item @code{java.lang.Object} @tab @code{jobject} @tab Object type
1546 @item @code{java.lang.String} @tab @code{jstring} @tab String type
1547 @item @code{java.lang.Class} @tab @code{jclass} @tab Class type
1553 Every Java class or interface has a corresponding @code{Class}
1554 instance. These can be accessed in CNI via the static @code{class$}
1555 field of a class. The @code{class$} field is of type @code{Class}
1556 (and not @code{Class *}), so you will typically take the address of
1560 Here is how you can refer to the class of @code{String}, which in
1561 Java would be written @code{String.class}:
1564 using namespace java::lang;
1565 doSomething (&String::class$);
1572 A Java class can @dfn{implement} zero or more
1573 @dfn{interfaces}, in addition to inheriting from
1574 a single base class.
1576 @acronym{CNI} allows CNI code to implement methods of interfaces.
1577 You can also call methods through interface references, with some
1580 @acronym{CNI} doesn't understand interface inheritance at all yet. So,
1581 you can only call an interface method when the declared type of the
1582 field being called matches the interface which declares that
1583 method. The workaround is to cast the interface reference to the right
1586 For example if you have:
1594 interface B extends A
1600 and declare a variable of type @code{B} in C++, you can't call
1601 @code{a()} unless you cast it to an @code{A} first.
1603 @node Objects and Classes
1604 @section Objects and Classes
1608 All Java classes are derived from @code{java.lang.Object}. C++ does
1609 not have a unique root class, but we use the C++ class
1610 @code{java::lang::Object} as the C++ version of the
1611 @code{java.lang.Object} Java class. All other Java classes are mapped
1612 into corresponding C++ classes derived from @code{java::lang::Object}.
1614 Interface inheritance (the @code{implements} keyword) is currently not
1615 reflected in the C++ mapping.
1618 @subsection Object fields
1620 Each object contains an object header, followed by the instance fields
1621 of the class, in order. The object header consists of a single
1622 pointer to a dispatch or virtual function table. (There may be extra
1623 fields @emph{in front of} the object, for example for memory
1624 management, but this is invisible to the application, and the
1625 reference to the object points to the dispatch table pointer.)
1627 The fields are laid out in the same order, alignment, and size as in
1628 C++. Specifically, 8-bit and 16-bit native types (@code{byte},
1629 @code{short}, @code{char}, and @code{boolean}) are @emph{not} widened
1630 to 32 bits. Note that the Java VM does extend 8-bit and 16-bit types
1631 to 32 bits when on the VM stack or temporary registers.
1633 If you include the @code{gcjh}-generated header for a
1634 class, you can access fields of Java classes in the @emph{natural}
1635 way. For example, given the following Java class:
1641 public Int (int i) @{ this.i = i; @}
1642 public static Int zero = new Int(0);
1649 #include <gcj/cni.h>;
1653 mult (Int *p, jint k)
1656 return Int::zero; // @r{Static member access.}
1657 return new Int(p->i * k);
1662 @subsection Access specifiers
1664 CNI does not strictly enforce the Java access
1665 specifiers, because Java permissions cannot be directly mapped
1666 into C++ permission. Private Java fields and methods are mapped
1667 to private C++ fields and methods, but other fields and methods
1668 are mapped to public fields and methods.
1672 @node Class Initialization
1673 @section Class Initialization
1675 Java requires that each class be automatically initialized at the time
1676 of the first active use. Initializing a class involves
1677 initializing the static fields, running code in class initializer
1678 methods, and initializing base classes. There may also be
1679 some implementation specific actions, such as allocating
1680 @code{String} objects corresponding to string literals in
1683 The GCJ compiler inserts calls to @code{JvInitClass} at appropriate
1684 places to ensure that a class is initialized when required. The C++
1685 compiler does not insert these calls automatically---it is the
1686 programmer's responsibility to make sure classes are initialized.
1687 However, this is fairly painless because of the conventions assumed by
1690 First, @code{libgcj} will make sure a class is initialized before an
1691 instance of that object is created. This is one of the
1692 responsibilities of the @code{new} operation. This is taken care of
1693 both in Java code, and in C++ code. When G++ sees a @code{new} of a
1694 Java class, it will call a routine in @code{libgcj} to allocate the
1695 object, and that routine will take care of initializing the class.
1696 Note however that this does not happen for Java arrays; you must
1697 allocate those using the appropriate CNI function. It follows that
1698 you can access an instance field, or call an instance (non-static)
1699 method and be safe in the knowledge that the class and all of its base
1700 classes have been initialized.
1702 Invoking a static method is also safe. This is because the
1703 Java compiler adds code to the start of a static method to make sure
1704 the class is initialized. However, the C++ compiler does not
1705 add this extra code. Hence, if you write a native static method
1706 using CNI, you are responsible for calling @code{JvInitClass}
1707 before doing anything else in the method (unless you are sure
1708 it is safe to leave it out).
1710 Accessing a static field also requires the class of the
1711 field to be initialized. The Java compiler will generate code
1712 to call @code{JvInitClass} before getting or setting the field.
1713 However, the C++ compiler will not generate this extra code,
1714 so it is your responsibility to make sure the class is
1715 initialized before you access a static field from C++.
1718 @node Object allocation
1719 @section Object allocation
1721 New Java objects are allocated using a
1722 @dfn{class instance creation expression}, e.g.:
1725 new @var{Type} ( ... )
1728 The same syntax is used in C++. The main difference is that
1729 C++ objects have to be explicitly deleted; in Java they are
1730 automatically deleted by the garbage collector.
1731 Using @acronym{CNI}, you can allocate a new Java object
1732 using standard C++ syntax and the C++ compiler will allocate
1733 memory from the garbage collector. If you have overloaded
1734 constructors, the compiler will choose the correct one
1735 using standard C++ overload resolution rules.
1737 @noindent For example:
1740 java::util::Hashtable *ht = new java::util::Hashtable(120);
1744 @node Memory allocation
1745 @section Memory allocation
1747 When allocating memory in @acronym{CNI} methods it is best to handle
1748 out-of-memory conditions by throwing a Java exception. These
1749 functions are provided for that purpose:
1751 @deftypefun void* JvMalloc (jsize @var{size})
1752 Calls malloc. Throws @code{java.lang.OutOfMemoryError} if allocation
1756 @deftypefun void* JvRealloc (void* @var{ptr}, jsize @var{size})
1757 Calls realloc. Throws @code{java.lang.OutOfMemoryError} if
1761 @deftypefun void JvFree (void* @var{ptr})
1768 While in many ways Java is similar to C and C++, it is quite different
1769 in its treatment of arrays. C arrays are based on the idea of pointer
1770 arithmetic, which would be incompatible with Java's security
1771 requirements. Java arrays are true objects (array types inherit from
1772 @code{java.lang.Object}). An array-valued variable is one that
1773 contains a reference (pointer) to an array object.
1775 Referencing a Java array in C++ code is done using the
1776 @code{JArray} template, which as defined as follows:
1779 class __JArray : public java::lang::Object
1786 class JArray : public __JArray
1790 T& operator[](jint i) @{ return data[i]; @}
1795 There are a number of @code{typedef}s which correspond to @code{typedef}s
1796 from the @acronym{JNI}. Each is the type of an array holding objects
1797 of the relevant type:
1800 typedef __JArray *jarray;
1801 typedef JArray<jobject> *jobjectArray;
1802 typedef JArray<jboolean> *jbooleanArray;
1803 typedef JArray<jbyte> *jbyteArray;
1804 typedef JArray<jchar> *jcharArray;
1805 typedef JArray<jshort> *jshortArray;
1806 typedef JArray<jint> *jintArray;
1807 typedef JArray<jlong> *jlongArray;
1808 typedef JArray<jfloat> *jfloatArray;
1809 typedef JArray<jdouble> *jdoubleArray;
1813 @deftypemethod {template<class T>} T* elements (JArray<T> @var{array})
1814 This template function can be used to get a pointer to the elements of
1815 the @code{array}. For instance, you can fetch a pointer to the
1816 integers that make up an @code{int[]} like so:
1819 extern jintArray foo;
1820 jint *intp = elements (foo);
1823 The name of this function may change in the future.
1827 @deftypefun jobjectArray JvNewObjectArray (jsize @var{length}, jclass @var{klass}, jobject @var{init})
1828 This creates a new array whose elements have reference type.
1829 @code{klass} is the type of elements of the array and
1830 @code{init} is the initial value put into every slot in the array.
1834 using namespace java::lang;
1835 JArray<String *> *array
1836 = (JArray<String *> *) JvNewObjectArray(length, &String::class$, NULL);
1840 @subsection Creating arrays
1842 For each primitive type there is a function which can be used to
1843 create a new array of that type. The name of the function is of the
1847 JvNew@var{Type}Array
1850 @noindent For example:
1856 @noindent can be used to create an array of Java primitive boolean types.
1858 @noindent The following function definition is the template for all such functions:
1860 @deftypefun jbooleanArray JvNewBooleanArray (jint @var{length})
1861 Creates an array @var{length} indices long.
1864 @deftypefun jsize JvGetArrayLength (jarray @var{array})
1865 Returns the length of the @var{array}.
1872 Java methods are mapped directly into C++ methods.
1873 The header files generated by @code{gcjh}
1874 include the appropriate method definitions.
1875 Basically, the generated methods have the same names and
1876 @emph{corresponding} types as the Java methods,
1877 and are called in the natural manner.
1879 @subsection Overloading
1881 Both Java and C++ provide method overloading, where multiple
1882 methods in a class have the same name, and the correct one is chosen
1883 (at compile time) depending on the argument types.
1884 The rules for choosing the correct method are (as expected) more complicated
1885 in C++ than in Java, but given a set of overloaded methods
1886 generated by @code{gcjh} the C++ compiler will choose
1889 Common assemblers and linkers are not aware of C++ overloading,
1890 so the standard implementation strategy is to encode the
1891 parameter types of a method into its assembly-level name.
1892 This encoding is called @dfn{mangling},
1893 and the encoded name is the @dfn{mangled name}.
1894 The same mechanism is used to implement Java overloading.
1895 For C++/Java interoperability, it is important that both the Java
1896 and C++ compilers use the @emph{same} encoding scheme.
1898 @subsection Static methods
1900 Static Java methods are invoked in @acronym{CNI} using the standard
1901 C++ syntax, using the @code{::} operator rather
1902 than the @code{.} operator.
1904 @noindent For example:
1907 jint i = java::lang::Math::round((jfloat) 2.3);
1910 @noindent C++ method definition syntax is used to define a static native method.
1914 #include <java/lang/Integer>
1915 java::lang::Integer*
1916 java::lang::Integer::getInteger(jstring str)
1923 @subsection Object Constructors
1925 Constructors are called implicitly as part of object allocation
1926 using the @code{new} operator.
1928 @noindent For example:
1931 java::lang::Integer *x = new java::lang::Integer(234);
1934 Java does not allow a constructor to be a native method.
1935 This limitation can be coded round however because a constructor
1936 can @emph{call} a native method.
1939 @subsection Instance methods
1941 Calling a Java instance method from a C++ @acronym{CNI} method is done
1942 using the standard C++ syntax, e.g.:
1945 // @r{First create the Java object.}
1946 java::lang::Integer *x = new java::lang::Integer(234);
1947 // @r{Now call a method.}
1948 jint prim_value = x->intValue();
1949 if (x->longValue == 0)
1953 @noindent Defining a Java native instance method is also done the natural way:
1956 #include <java/lang/Integer.h>
1959 java::lang:Integer::doubleValue()
1961 return (jdouble) value;
1966 @subsection Interface methods
1968 In Java you can call a method using an interface reference. This is
1969 supported, but not completely. @xref{Interfaces}.
1977 @acronym{CNI} provides a number of utility functions for
1978 working with Java Java @code{String} objects.
1979 The names and interfaces are analogous to those of @acronym{JNI}.
1982 @deftypefun jstring JvNewString (const jchar* @var{chars}, jsize @var{len})
1983 Returns a Java @code{String} object with characters from the array of
1984 Unicode characters @var{chars} up to the index @var{len} in that array.
1987 @deftypefun jstring JvNewStringLatin1 (const char* @var{bytes}, jsize @var{len})
1988 Returns a Java @code{String} made up of @var{len} bytes from @var{bytes}.
1992 @deftypefun jstring JvNewStringLatin1 (const char* @var{bytes})
1993 As above but the length of the @code{String} is @code{strlen(@var{bytes})}.
1996 @deftypefun jstring JvNewStringUTF (const char* @var{bytes})
1997 Returns a @code{String} which is made up of the UTF encoded characters
1998 present in the C string @var{bytes}.
2001 @deftypefun jchar* JvGetStringChars (jstring @var{str})
2002 Returns a pointer to an array of characters making up the @code{String} @var{str}.
2005 @deftypefun int JvGetStringUTFLength (jstring @var{str})
2006 Returns the number of bytes required to encode the contents of the
2007 @code{String} @var{str} in UTF-8.
2010 @deftypefun jsize JvGetStringUTFRegion (jstring @var{str}, jsize @var{start}, jsize @var{len}, char* @var{buf})
2011 Puts the UTF-8 encoding of a region of the @code{String} @var{str} into
2012 the buffer @code{buf}. The region to fetch is marked by @var{start} and @var{len}.
2014 Note that @var{buf} is a buffer, not a C string. It is @emph{not}
2019 @node Mixing with C++
2020 @section Interoperating with C/C++
2022 Because @acronym{CNI} is designed to represent Java classes and methods it
2023 cannot be mixed readily with C/C++ types.
2025 One important restriction is that Java classes cannot have non-Java
2026 type instance or static variables and cannot have methods which take
2027 non-Java types as arguments or return non-Java types.
2029 @noindent None of the following is possible with CNI:
2033 class ::MyClass : public java::lang::Object
2035 char* variable; // @r{char* is not a valid Java type.}
2040 ::SomeClass::someMethod (char *arg)
2045 @} // @r{@code{uint} is not a valid Java type, neither is @code{char*}}
2048 @noindent Of course, it is ok to use C/C++ types within the scope of a method:
2053 ::SomeClass::otherMethod (jstring str)
2064 The above restriction can be problematic, so @acronym{CNI} includes the
2065 @code{gnu.gcj.RawData} class. The @code{RawData} class is a
2066 @dfn{non-scanned reference} type. In other words variables declared
2067 of type @code{RawData} can contain any data and are not checked by the
2068 compiler or memory manager in any way.
2070 This means that you can put C/C++ data structures (including classes)
2071 in your @acronym{CNI} classes, as long as you use the appropriate cast.
2073 @noindent Here are some examples:
2077 class ::MyClass : public java::lang::Object
2079 gnu.gcj.RawData string;
2082 gnu.gcj.RawData getText ();
2086 ::MyClass::MyClass ()
2093 ::MyClass::getText ()
2099 ::MyClass::printText ()
2101 printf("%s\n", (char*) string);
2106 @subsection RawDataManaged
2108 @code{gnu.gcj.RawDataManaged} is another type used to indicate special data used
2109 by native code. Unlike the @code{RawData} type, fields declared as
2110 @code{RawDataManaged} will be "marked" by the memory manager and
2111 considered for garbage collection.
2113 Native data which is allocated using CNI's @code{JvAllocBytes()}
2114 function and stored in a @code{RawDataManaged} will be automatically
2115 freed when the Java object it is associated with becomes unreachable.
2117 @subsection Native memory allocation
2119 @deftypefun void* JvAllocBytes (jsize @var{size})
2120 Allocates @var{size} bytes from the heap. The memory returned is zeroed.
2121 This memory is not scanned for pointers by the garbage collector, but will
2122 be freed if no references to it are discovered.
2124 This function can be useful if you need to associate some native data with a
2125 Java object. Using a CNI's special @code{RawDataManaged} type, native data
2126 allocated with @code{JvAllocBytes} will be automatically freed when the Java
2127 object itself becomes unreachable.
2130 @subsection Posix signals
2132 On Posix based systems the @code{libgcj} library uses several signals
2133 internally. @acronym{CNI} code should not attempt to use the same
2134 signals as doing so may cause @code{libgcj} and/or the @acronym{CNI}
2137 SIGSEGV is used on many systems to generate
2138 @code{NullPointerExceptions}. SIGCHLD is used internally by
2139 @code{Runtime.exec()}. Several other signals (that vary from platform to
2140 platform) can be used by the memory manager and by
2141 @code{Thread.interrupt()}.
2143 @node Exception Handling
2144 @section Exception Handling
2146 While C++ and Java share a common exception handling framework,
2147 things are not yet perfectly integrated. The main issue is that the
2148 run-time type information facilities of the two
2149 languages are not integrated.
2151 Still, things work fairly well. You can throw a Java exception from
2152 C++ using the ordinary @code{throw} construct, and this
2153 exception can be caught by Java code. Similarly, you can catch an
2154 exception thrown from Java using the C++ @code{catch}
2157 @noindent Here is an example:
2161 throw new java::lang::IndexOutOfBoundsException();
2164 Normally, G++ will automatically detect when you are writing C++
2165 code that uses Java exceptions, and handle them appropriately.
2166 However, if C++ code only needs to execute destructors when Java
2167 exceptions are thrown through it, GCC will guess incorrectly. Sample
2171 struct S @{ ~S(); @};
2173 extern void bar(); // @r{Is implemented in Java and may throw exceptions.}
2182 The usual effect of an incorrect guess is a link failure, complaining of
2183 a missing routine called @code{__gxx_personality_v0}.
2185 You can inform the compiler that Java exceptions are to be used in a
2186 translation unit, irrespective of what it might think, by writing
2187 @code{#pragma GCC java_exceptions} at the head of the
2188 file. This @code{#pragma} must appear before any
2189 functions that throw or catch exceptions, or run destructors when
2190 exceptions are thrown through them.
2192 @node Synchronization
2193 @section Synchronization
2195 Each Java object has an implicit monitor.
2196 The Java VM uses the instruction @code{monitorenter} to acquire
2197 and lock a monitor, and @code{monitorexit} to release it.
2199 The corresponding CNI macros are @code{JvMonitorEnter} and
2200 @code{JvMonitorExit} (JNI has similar methods @code{MonitorEnter}
2201 and @code{MonitorExit}).
2204 The Java source language does not provide direct access to these primitives.
2205 Instead, there is a @code{synchronized} statement that does an
2206 implicit @code{monitorenter} before entry to the block,
2207 and does a @code{monitorexit} on exit from the block.
2208 Note that the lock has to be released even when the block is abnormally
2209 terminated by an exception, which means there is an implicit
2210 @code{try finally} surrounding synchronization locks.
2212 From C++, it makes sense to use a destructor to release a lock.
2213 @acronym{CNI} defines the following utility class:
2216 class JvSynchronize() @{
2218 JvSynchronize(jobject o) @{ obj = o; JvMonitorEnter(o); @}
2219 ~JvSynchronize() @{ JvMonitorExit(obj); @}
2232 @noindent might become this C++ code:
2236 JvSynchronize dummy (OBJ);
2241 Java also has methods with the @code{synchronized} attribute.
2242 This is equivalent to wrapping the entire method body in a
2243 @code{synchronized} statement.
2244 (Alternatively, an implementation could require the caller to do
2245 the synchronization. This is not practical for a compiler, because
2246 each virtual method call would have to test at run-time if
2247 synchronization is needed.) Since in @command{gcj}
2248 the @code{synchronized} attribute is handled by the
2249 method implementation, it is up to the programmer
2250 of a synchronized native method to handle the synchronization
2251 (in the C++ implementation of the method).
2252 In other words, you need to manually add @code{JvSynchronize}
2253 in a @code{native synchronized} method.
2258 CNI permits C++ applications to make calls into Java classes, in addition to
2259 allowing Java code to call into C++. Several functions, known as the
2260 @dfn{invocation API}, are provided to support this.
2262 @deftypefun jint JvCreateJavaVM (JvVMInitArgs* @var{vm_args})
2264 Initializes the Java runtime. This function performs essential initialization
2265 of the threads interface, garbage collector, exception handling and other key
2266 aspects of the runtime. It must be called once by an application with
2267 a non-Java @code{main()} function, before any other Java or CNI calls are made.
2268 It is safe, but not recommended, to call @code{JvCreateJavaVM()} more than
2269 once provided it is only called from a single thread.
2270 The @var{vmargs} parameter can be used to specify initialization parameters
2271 for the Java runtime. It may be @code{NULL}.
2273 JvVMInitArgs represents a list of virtual machine initialization
2274 arguments. @code{JvCreateJavaVM()} ignores the version field.
2277 typedef struct JvVMOption
2279 // a VM initialization option
2281 // extra information associated with this option
2285 typedef struct JvVMInitArgs
2287 // for compatibility with JavaVMInitArgs
2290 // number of VM initialization options
2293 // an array of VM initialization options
2294 JvVMOption* options;
2296 // true if the option parser should ignore unrecognized options
2297 jboolean ignoreUnrecognized;
2301 @code{JvCreateJavaVM()} returns @code{0} upon success, or @code{-1} if
2302 the runtime is already initialized.
2304 @emph{Note:} In GCJ 3.1, the @code{vm_args} parameter is ignored. It
2305 is recognized and used as of release 4.0.
2308 @deftypefun java::lang::Thread* JvAttachCurrentThread (jstring @var{name}, java::lang::ThreadGroup* @var{group})
2309 Registers an existing thread with the Java runtime. This must be called once
2310 from each thread, before that thread makes any other Java or CNI calls. It
2311 must be called after @code{JvCreateJavaVM}.
2312 @var{name} specifies a name for the thread. It may be @code{NULL}, in which
2313 case a name will be generated.
2314 @var{group} is the ThreadGroup in which this thread will be a member. If it
2315 is @code{NULL}, the thread will be a member of the main thread group.
2316 The return value is the Java @code{Thread} object that represents the thread.
2317 It is safe to call @code{JvAttachCurrentThread()} more than once from the same
2318 thread. If the thread is already attached, the call is ignored and the current
2319 thread object is returned.
2322 @deftypefun jint JvDetachCurrentThread ()
2323 Unregisters a thread from the Java runtime. This should be called by threads
2324 that were attached using @code{JvAttachCurrentThread()}, after they have
2325 finished making calls to Java code. This ensures that any resources associated
2326 with the thread become eligible for garbage collection.
2327 This function returns @code{0} upon success, or @code{-1} if the current thread
2331 @subsection Handling uncaught exceptions
2333 If an exception is thrown from Java code called using the invocation API, and
2334 no handler for the exception can be found, the runtime will abort the
2335 application. In order to make the application more robust, it is recommended
2336 that code which uses the invocation API be wrapped by a top-level try/catch
2337 block that catches all Java exceptions.
2341 The following code demonstrates the use of the invocation API. In this
2342 example, the C++ application initializes the Java runtime and attaches
2343 itself. The @code{java.lang.System} class is initialized in order to
2344 access its @code{out} field, and a Java string is printed. Finally, the thread
2345 is detached from the runtime once it has finished making Java calls. Everything
2346 is wrapped with a try/catch block to provide a default handler for any uncaught
2349 The example can be compiled with @command{c++ -c test.cc; gcj test.o}.
2353 #include <gcj/cni.h>
2354 #include <java/lang/System.h>
2355 #include <java/io/PrintStream.h>
2356 #include <java/lang/Throwable.h>
2358 int main(int argc, char *argv[])
2360 using namespace java::lang;
2364 JvCreateJavaVM(NULL);
2365 JvAttachCurrentThread(NULL, NULL);
2367 String *message = JvNewStringLatin1("Hello from C++");
2368 JvInitClass(&System::class$);
2369 System::out->println(message);
2371 JvDetachCurrentThread();
2373 catch (Throwable *t)
2375 System::err->println(JvNewStringLatin1("Unhandled Java exception:"));
2376 t->printStackTrace();
2384 Reflection is possible with CNI code, it functions similarly to how it
2385 functions with JNI@.
2387 @c clean this up... I mean, what are the types jfieldID and jmethodID in JNI?
2388 The types @code{jfieldID} and @code{jmethodID}
2391 @noindent The functions:
2394 @item @code{JvFromReflectedField},
2395 @item @code{JvFromReflectedMethod},
2396 @item @code{JvToReflectedField}
2397 @item @code{JvToFromReflectedMethod}
2400 @noindent will be added shortly, as will other functions corresponding to JNI@.
2403 @node System properties
2404 @chapter System properties
2406 The runtime behavior of the @code{libgcj} library can be modified by setting
2407 certain system properties. These properties can be compiled into the program
2408 using the @code{-D@var{name}[=@var{value}]} option to @command{gcj} or by
2409 setting them explicitly in the program by calling the
2410 @code{java.lang.System.setProperty()} method. Some system properties are only
2411 used for informational purposes (like giving a version number or a user name).
2412 A program can inspect the current value of a property by calling the
2413 @code{java.lang.System.getProperty()} method.
2416 * Standard Properties:: Standard properties supported by @code{libgcj}
2417 * GNU Classpath Properties:: Properties found in Classpath based libraries
2418 * libgcj Runtime Properties:: Properties specific to @code{libgcj}
2421 @node Standard Properties
2422 @section Standard Properties
2424 The following properties are normally found in all implementations of the core
2425 libraries for the Java language.
2430 The @code{libgcj} version number.
2433 Set to @samp{The Free Software Foundation, Inc.}
2435 @item java.vendor.url
2436 Set to @uref{http://gcc.gnu.org/java/}.
2439 The directory where @code{gcj} was installed. Taken from the @code{--prefix}
2440 option given to @command{configure}.
2442 @item java.class.version
2443 The class format version number supported by the libgcj byte code interpreter.
2444 (Currently @samp{46.0})
2446 @item java.vm.specification.version
2447 The Virtual Machine Specification version implemented by @code{libgcj}.
2448 (Currently @samp{1.0})
2450 @item java.vm.specification.vendor
2451 The name of the Virtual Machine specification designer.
2453 @item java.vm.specification.name
2454 The name of the Virtual Machine specification
2455 (Set to @samp{Java Virtual Machine Specification}).
2457 @item java.vm.version
2458 The @command{gcj} version number.
2460 @item java.vm.vendor
2461 Set to @samp{The Free Software Foundation, Inc.}
2464 Set to @samp{GNU libgcj}.
2466 @item java.specification.version
2467 The Runtime Environment specification version implemented by @code{libgcj}.
2468 (Currently set to @samp{1.3})
2470 @item java.specification.vendor
2471 The Runtime Environment specification designer.
2473 @item java.specification.name
2474 The name of the Runtime Environment specification
2475 (Set to @samp{Java Platform API Specification}).
2477 @item java.class.path
2478 The paths (jar files, zip files and directories) used for finding class files.
2480 @item java.library.path
2481 Directory path used for finding native libraries.
2483 @item java.io.tmpdir
2484 The directory used to put temporary files in.
2487 Name of the Just In Time compiler to use by the byte code interpreter.
2488 Currently not used in @code{libgcj}.
2491 Directories containing jar files with extra libraries. Will be used when
2494 @item java.protocol.handler.pkgs
2495 A @samp{|} separated list of package names that is used to find classes that
2496 implement handlers for @code{java.net.URL}.
2498 @item java.rmi.server.codebase
2499 A list of URLs that is used by the @code{java.rmi.server.RMIClassLoader}
2500 to load classes from.
2503 A list of class names that will be loaded by the @code{java.sql.DriverManager}
2506 @item file.separator
2507 The separator used in when directories are included in a filename
2508 (normally @samp{/} or @samp{\} ).
2511 The default character encoding used when converting platform native files to
2512 Unicode (usually set to @samp{8859_1}).
2514 @item path.separator
2515 The standard separator used when a string contains multiple paths
2516 (normally @samp{:} or @samp{;}), the string is usually not a valid character
2517 to use in normal directory names.)
2519 @item line.separator
2520 The default line separator used on the platform (normally @samp{\n}, @samp{\r}
2521 or a combination of those two characters).
2523 @item policy.provider
2524 The class name used for the default policy provider returned by
2525 @code{java.security.Policy.getPolicy}.
2528 The name of the user running the program. Can be the full name, the login name
2529 or empty if unknown.
2532 The default directory to put user specific files in.
2535 The current working directory from which the program was started.
2538 The default language as used by the @code{java.util.Locale} class.
2541 The default region as used by the @code{java.util.Local} class.
2544 The default variant of the language and region local used.
2547 The default timezone as used by the @code{java.util.TimeZone} class.
2550 The operating system/kernel name that the program runs on.
2553 The hardware that we are running on.
2556 The version number of the operating system/kernel.
2558 @item awt.appletWarning
2559 The string to display when an untrusted applet is displayed.
2560 Returned by @code{java.awt.Window.getWarningString()} when the window is
2564 The class name used for initializing the default @code{java.awt.Toolkit}.
2565 Defaults to @code{gnu.awt.gtk.GtkToolkit}.
2567 @item http.proxyHost
2568 Name of proxy host for http connections.
2570 @item http.proxyPort
2571 Port number to use when a proxy host is in use.
2575 @node GNU Classpath Properties
2576 @section GNU Classpath Properties
2578 @code{libgcj} is based on the GNU Classpath (Essential Libraries for Java) a
2579 GNU project to create free core class libraries for use with virtual machines
2580 and compilers for the Java language. The following properties are common to
2581 libraries based on GNU Classpath.
2585 @item gcj.dumpobject
2586 Enables printing serialization debugging by the @code{java.io.ObjectInput} and
2587 @code{java.io.ObjectOutput} classes when set to something else then the empty
2588 string. Only used when running a debug build of the library.
2590 @item gnu.classpath.vm.shortname
2591 This is a succinct name of the virtual machine. For @code{libgcj},
2592 this will always be @samp{libgcj}.
2594 @item gnu.classpath.home.url
2595 A base URL used for finding system property files (e.g.,
2596 @file{classpath.security}). By default this is a @samp{file:} URL
2597 pointing to the @file{lib} directory under @samp{java.home}.
2601 @node libgcj Runtime Properties
2602 @section libgcj Runtime Properties
2604 The following properties are specific to the @code{libgcj} runtime and will
2605 normally not be found in other core libraries for the java language.
2609 @item java.fullversion
2610 The combination of @code{java.vm.name} and @code{java.vm.version}.
2613 Same as @code{java.fullversion}.
2616 Used by the @code{java.net.DatagramSocket} class when set to something else
2617 then the empty string. When set all newly created @code{DatagramSocket}s will
2618 try to load a class @code{java.net.[impl.prefix]DatagramSocketImpl} instead of
2619 the normal @code{java.net.PlainDatagramSocketImpl}.
2621 @item gnu.gcj.progname
2622 The class or binary name that was used to invoke the program. This will be
2623 the name of the "main" class in the case where the @code{gij} front end is
2624 used, or the program binary name in the case where an application is compiled
2627 @item gnu.gcj.user.realname
2628 The real name of the user, as taken from the password file. This may
2629 not always hold only the user's name (as some sites put extra
2630 information in this field). Also, this property is not available on
2633 @item gnu.gcj.runtime.NameFinder.use_addr2line
2634 Whether an external process, @command{addr2line}, should be used to determine
2635 line number information when tracing the stack. Setting this to @code{false}
2636 may suppress line numbers when printing stack traces and when using
2637 the java.util.logging infrastructure. However, performance may improve
2638 significantly for applications that print stack traces or make logging calls
2641 @item gnu.gcj.runtime.NameFinder.show_raw
2642 Whether the address of a stack frame should be printed when the line
2643 number is unavailable. Setting this to @code{true} will cause the name
2644 of the object and the offset within that object to be printed when no
2645 line number is available. This allows for off-line decoding of
2646 stack traces if necessary debug information is available. The default
2647 is @code{false}, no raw addresses are printed.
2649 @item gnu.gcj.runtime.NameFinder.remove_unknown
2650 Whether stack frames for non-java code should be included in a stack
2651 trace. The default value is @code{true}, stack frames for non-java
2652 code are suppressed. Setting this to @code{false} will cause any
2653 non-java stack frames to be printed in addition to frames for the java
2656 @item gnu.gcj.runtime.VMClassLoader.library_control
2657 This controls how shared libraries are automatically loaded by the
2658 built-in class loader. If this property is set to @samp{full}, a full
2659 search is done for each requested class. If this property is set to
2660 @samp{cache}, then any failed lookups are cached and not tried again.
2661 If this property is set to @samp{never} (the default), then lookups
2662 are never done. For more information, @xref{Extensions}.
2664 @item gnu.gcj.runtime.endorsed.dirs
2665 This is like the standard @code{java.endorsed.dirs}, property, but
2666 specifies some extra directories which are searched after the standard
2667 endorsed directories. This is primarily useful for telling
2668 @code{libgcj} about additional libraries which are ordinarily
2669 incorporated into the JDK, and which should be loaded by the bootstrap
2670 class loader, but which are not yet part of @code{libgcj} itself for
2673 @item gnu.gcj.jit.compiler
2674 @c FIXME we should probably have a whole node on this...
2675 This is the full path to @command{gcj} executable which should be
2676 used to compile classes just-in-time when
2677 @code{ClassLoader.defineClass} is called. If not set, @command{gcj}
2678 will not be invoked by the runtime; this can also be controlled via
2679 @code{Compiler.disable}.
2681 @item gnu.gcj.jit.options
2682 This is a space-separated string of options which should be passed to
2683 @command{gcj} when in JIT mode. If not set, a sensible default is
2686 @item gnu.gcj.jit.cachedir
2687 This is the directory where cached shared library files are
2688 stored. If not set, JIT compilation is disabled. This should never
2689 be set to a directory that is writable by any other user.
2691 @item gnu.gcj.precompiled.db.path
2692 This is a sequence of file names, each referring to a file created by
2693 @command{gcj-dbtool}. These files will be used by @code{libgcj} to
2694 find shared libraries corresponding to classes that are loaded from
2695 bytecode. @code{libgcj} often has a built-in default database; it
2696 can be queried using @code{gcj-dbtool -p}.
2704 While writing @command{gcj} and @code{libgcj} we have, of course, relied
2705 heavily on documentation from Sun Microsystems. In particular we have
2706 used The Java Language Specification (both first and second editions),
2707 the Java Class Libraries (volumes one and two), and the Java Virtual
2708 Machine Specification. In addition we've used the online documentation
2709 at @uref{http://java.sun.com/}.
2711 The current @command{gcj} home page is
2712 @uref{http://gcc.gnu.org/java/}.
2714 For more information on gcc, see @uref{http://gcc.gnu.org/}.
2716 Some @code{libgcj} testing is done using the Mauve test suite. This is
2717 a free software Java class library test suite which is being written
2718 because the JCK is not free. See
2719 @uref{http://sources.redhat.com/mauve/} for more information.