OSDN Git Service

2006-06-05 David Daney <ddaney@avtrex.com>
[pf3gnuchains/gcc-fork.git] / gcc / java / gcj.texi
1 \input texinfo @c -*-texinfo-*-
2 @setfilename gcj.info
3 @settitle Guide to GNU gcj
4
5 @c Merge the standard indexes into a single one.
6 @syncodeindex fn cp
7 @syncodeindex vr cp
8 @syncodeindex ky cp
9 @syncodeindex pg cp
10 @syncodeindex tp cp
11
12 @include gcc-common.texi
13
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
17 @c the word ``Java'.
18
19 @c When this manual is copyrighted.
20 @set copyrights-gcj 2001, 2002, 2003, 2004, 2005
21
22 @c Versions
23 @set which-gcj GCC-@value{version-GCC}
24
25 @copying
26 @c man begin COPYRIGHT
27 Copyright @copyright{} @value{copyrights-gcj} Free Software Foundation, Inc.
28
29 Permission is granted to copy, distribute and/or modify this document
30 under the terms of the GNU Free Documentation License, Version 1.2 or
31 any later version published by the Free Software Foundation; with the
32 Invariant Sections being ``GNU General Public License'', the Front-Cover
33 texts being (a) (see below), and with the Back-Cover Texts being (b)
34 (see below).  A copy of the license is included in the
35 @c man end
36 section entitled
37 ``GNU Free Documentation License''.
38 @ignore
39 @c man begin COPYRIGHT
40 man page gfdl(7).
41 @c man end
42 @end ignore
43
44 @c man begin COPYRIGHT
45
46 (a) The FSF's Front-Cover Text is:
47
48      A GNU Manual
49
50 (b) The FSF's Back-Cover Text is:
51
52      You have freedom to copy and modify this GNU Manual, like GNU
53      software.  Copies published by the Free Software Foundation raise
54      funds for GNU development.
55 @c man end
56 @end copying
57
58 @ifinfo
59 @format
60 @dircategory Programming
61 @direntry
62 * Gcj: (gcj).               Ahead-of-time compiler for the Java language
63 @end direntry
64
65 @dircategory Individual utilities
66 @direntry
67 * gcjh: (gcj)Invoking gcjh.
68                             Generate header files from Java class files
69 * gjnih: (gcj)Invoking gjnih.
70                             Generate JNI header files from Java class files
71 * jv-scan: (gcj)Invoking jv-scan.
72                             Print information about Java source files
73 * jcf-dump: (gcj)Invoking jcf-dump.
74                             Print information about Java class files
75 * gij: (gcj)Invoking gij.   GNU interpreter for Java bytecode
76 * gcj-dbtool: (gcj)Invoking gcj-dbtool.
77                             Tool for manipulating class file databases.
78 * jv-convert: (gcj)Invoking jv-convert.
79                             Convert file from one encoding to another
80 * grmic: (gcj)Invoking grmic.
81                             Generate stubs for Remote Method Invocation.
82 * grmiregistry: (gcj)Invoking grmiregistry.
83                             The remote object registry.
84 @end direntry
85 @end format
86
87 @insertcopying
88 @end ifinfo
89
90 @titlepage
91 @title GNU gcj
92 @author Tom Tromey
93
94 @page
95 @vskip 0pt plus 1filll
96 For the @value{which-gcj} Version*
97 @sp 1
98 Published by the Free Software Foundation @*
99 51 Franklin Street, Fifth Floor@*
100 Boston, MA 02110-1301, USA@*
101 @sp 1
102 @insertcopying
103 @end titlepage
104 @contents
105 @page
106
107
108 @node Top
109 @top Introduction
110
111 This manual describes how to use @command{gcj}, the GNU compiler for the
112 Java programming language.  @command{gcj} can generate both @file{.class}
113 files and object files, and it can read both Java source code and
114 @file{.class} files.
115
116 @menu
117 * Copying::              The GNU General Public License
118 * GNU Free Documentation License::
119                         How you can share and copy this manual
120 * Invoking gcj::        Compiler options supported by @command{gcj}
121 * Compatibility::       Compatibility between gcj and other tools for Java
122 * Invoking gcjh::       Generate header files from class files
123 * Invoking gjnih::      Generate JNI header files from class files
124 * Invoking jv-scan::    Print information about source files
125 * Invoking jcf-dump::   Print information about class files
126 * Invoking gij::        Interpreting Java bytecodes
127 * Invoking gcj-dbtool:: Tool for manipulating class file databases.
128 * Invoking jv-convert:: Converting from one encoding to another
129 * Invoking grmic::      Generate stubs for Remote Method Invocation.
130 * Invoking grmiregistry:: The remote object registry.
131 * About CNI::           Description of the Compiled Native Interface
132 * System properties::   Modifying runtime behavior of the libgcj library
133 * Resources::           Where to look for more information
134 * Index::               Index.
135 @end menu
136
137
138 @include gpl.texi
139
140 @include fdl.texi
141
142
143 @node Invoking gcj
144 @chapter Invoking gcj
145
146 @c man title gcj Ahead-of-time compiler for the Java language
147
148 @ignore
149 @c man begin SYNOPSIS gcj
150 gcj [@option{-I}@var{dir}@dots{}] [@option{-d} @var{dir}@dots{}]
151     [@option{--CLASSPATH}=@var{path}] [@option{--classpath}=@var{path}]
152     [@option{-f}@var{option}@dots{}] [@option{--encoding}=@var{name}]
153     [@option{--main}=@var{classname}] [@option{-D}@var{name}[=@var{value}]@dots{}]
154     [@option{-C}] [@option{--resource} @var{resource-name}] [@option{-d} @var{directory}]
155     [@option{-W}@var{warn}@dots{}]
156     @var{sourcefile}@dots{}
157 @c man end
158 @c man begin SEEALSO gcj
159 gcc(1), gcjh(1), gjnih(1), gij(1), jv-scan(1), jcf-dump(1), gfdl(7),
160 and the Info entries for @file{gcj} and @file{gcc}.
161 @c man end
162 @end ignore
163
164 @c man begin DESCRIPTION gcj
165
166 As @command{gcj} is just another front end to @command{gcc}, it supports many
167 of the same options as gcc.  @xref{Option Summary, , Option Summary,
168 gcc, Using the GNU Compiler Collection (GCC)}.  This manual only documents the
169 options specific to @command{gcj}.
170
171 @c man end
172
173 @menu
174 * Input and output files::
175 * Input Options::               How gcj finds files
176 * Encodings::                   Options controlling source file encoding
177 * Warnings::                    Options controlling warnings specific to gcj
178 * Linking::                     Options for making an executable
179 * Code Generation::             Options controlling the output of gcj
180 * Configure-time Options::      Options you won't use
181 @end menu
182
183 @c man begin OPTIONS gcj
184
185 @node Input and output files
186 @section Input and output files
187
188 A @command{gcj} command is like a @command{gcc} command, in that it
189 consists of a number of options and file names.  The following kinds
190 of input file names are supported:
191
192 @table @gcctabopt
193 @item @var{file}.java
194 Java source files.
195 @item @var{file}.class
196 Java bytecode files.
197 @item @var{file}.zip
198 @itemx @var{file}.jar
199 An archive containing one or more @code{.class} files, all of
200 which are compiled.  The archive may be compressed.  Files in
201 an archive which don't end with @samp{.class} are treated as
202 resource files; they are compiled into the resulting object file
203 as @samp{core:} URLs.
204 @item @@@var{file}
205 A file containing a whitespace-separated list of input file names.
206 (Currently, these must all be @code{.java} source files, but that
207 may change.)
208 Each named file is compiled, just as if it had been on the command line.
209 @item @var{library}.a
210 @itemx @var{library}.so
211 @itemx -l@var{libname}
212 Libraries to use when linking.  See the @command{gcc} manual.
213 @end table
214
215 You can specify more than one input file on the @command{gcj} command line,
216 in which case they will all be compiled.  If you specify a
217 @code{-o @var{FILENAME}}
218 option, all the input files will be compiled together, producing a
219 single output file, named @var{FILENAME}.
220 This is allowed even when using @code{-S} or @code{-c},
221 but not when using @code{-C} or @code{--resource}.
222 (This is an extension beyond the what plain @command{gcc} allows.)
223 (If more than one input file is specified, all must currently
224 be @code{.java} files, though we hope to fix this.)
225
226 @node Input Options
227 @section Input Options
228
229 @cindex class path
230
231 @command{gcj} has options to control where it looks to find files it needs.
232 For instance, @command{gcj} might need to load a class that is referenced
233 by the file it has been asked to compile.  Like other compilers for the
234 Java language, @command{gcj} has a notion of a @dfn{class path}.  There are
235 several options and environment variables which can be used to
236 manipulate the class path.  When @command{gcj} looks for a given class, it
237 searches the class path looking for matching @file{.class} or
238 @file{.java} file.  @command{gcj} comes with a built-in class path which
239 points at the installed @file{libgcj.jar}, a file which contains all the
240 standard classes.
241
242 In the below, a directory or path component can refer either to an
243 actual directory on the filesystem, or to a @file{.zip} or @file{.jar}
244 file, which @command{gcj} will search as if it is a directory.
245
246 @table @gcctabopt
247 @item -I@var{dir}
248 All directories specified by @code{-I} are kept in order and prepended
249 to the class path constructed from all the other options.  Unless
250 compatibility with tools like @code{javac} is important, we recommend
251 always using @code{-I} instead of the other options for manipulating the
252 class path.
253
254 @item --classpath=@var{path}
255 This sets the class path to @var{path}, a colon-separated list of paths
256 (on Windows-based systems, a semicolon-separate list of paths).
257 This does not override the builtin (``boot'') search path.
258
259 @item --CLASSPATH=@var{path}
260 Deprecated synonym for @code{--classpath}.
261
262 @item --bootclasspath=@var{path}
263 Where to find the standard builtin classes, such as @code{java.lang.String}.
264
265 @item --extdirs=@var{path}
266 For each directory in the @var{path}, place the contents of that
267 directory at the end of the class path.
268
269 @item CLASSPATH
270 This is an environment variable which holds a list of paths.
271 @end table
272
273 The final class path is constructed like so:
274
275 @itemize @bullet
276 @item
277 First come all directories specified via @code{-I}.
278
279 @item
280 If @option{--classpath} is specified, its value is appended.
281 Otherwise, if the @code{CLASSPATH} environment variable is specified,
282 then its value is appended.
283 Otherwise, the current directory (@code{"."}) is appended.
284
285 @item
286 If @code{--bootclasspath} was specified, append its value.
287 Otherwise, append the built-in system directory, @file{libgcj.jar}.
288
289 @item
290 Finally, if @code{--extdirs} was specified, append the contents of the
291 specified directories at the end of the class path.  Otherwise, append
292 the contents of the built-in extdirs at @code{$(prefix)/share/java/ext}.
293 @end itemize
294
295 The classfile built by @command{gcj} for the class @code{java.lang.Object}
296 (and placed in @code{libgcj.jar}) contains a special zero length
297 attribute @code{gnu.gcj.gcj-compiled}. The compiler looks for this
298 attribute when loading @code{java.lang.Object} and will report an error
299 if it isn't found, unless it compiles to bytecode (the option
300 @code{-fforce-classes-archive-check} can be used to override this
301 behavior in this particular case.)
302
303 @table @gcctabopt
304 @item -fforce-classes-archive-check
305 This forces the compiler to always check for the special zero length
306 attribute @code{gnu.gcj.gcj-compiled} in @code{java.lang.Object} and
307 issue an error if it isn't found.
308 @end table
309
310 @node Encodings
311 @section Encodings
312
313 The Java programming language uses Unicode throughout.  In an effort to
314 integrate well with other locales, @command{gcj} allows @file{.java} files
315 to be written using almost any encoding.  @command{gcj} knows how to
316 convert these encodings into its internal encoding at compile time.
317
318 You can use the @code{--encoding=@var{NAME}} option to specify an
319 encoding (of a particular character set) to use for source files.  If
320 this is not specified, the default encoding comes from your current
321 locale.  If your host system has insufficient locale support, then
322 @command{gcj} assumes the default encoding to be the @samp{UTF-8} encoding
323 of Unicode.
324
325 To implement @code{--encoding}, @command{gcj} simply uses the host
326 platform's @code{iconv} conversion routine.  This means that in practice
327 @command{gcj} is limited by the capabilities of the host platform.
328
329 The names allowed for the argument @code{--encoding} vary from platform
330 to platform (since they are not standardized anywhere).  However,
331 @command{gcj} implements the encoding named @samp{UTF-8} internally, so if
332 you choose to use this for your source files you can be assured that it
333 will work on every host.
334
335
336 @node Warnings
337 @section Warnings
338
339 @command{gcj} implements several warnings.  As with other generic
340 @command{gcc} warnings, if an option of the form @code{-Wfoo} enables a
341 warning, then @code{-Wno-foo} will disable it.  Here we've chosen to
342 document the form of the warning which will have an effect -- the
343 default being the opposite of what is listed.
344
345 @table @gcctabopt
346 @item -Wredundant-modifiers
347 With this flag, @command{gcj} will warn about redundant modifiers.  For
348 instance, it will warn if an interface method is declared @code{public}.
349
350 @item -Wextraneous-semicolon
351 This causes @command{gcj} to warn about empty statements.  Empty statements
352 have been deprecated.
353
354 @item -Wno-out-of-date
355 This option will cause @command{gcj} not to warn when a source file is
356 newer than its matching class file.  By default @command{gcj} will warn
357 about this.
358
359 @item -Wno-deprecated
360 Warn if a deprecated class, method, or field is referred to.
361
362 @item -Wunused
363 This is the same as @command{gcc}'s @code{-Wunused}.
364
365 @item -Wall
366 This is the same as @code{-Wredundant-modifiers -Wextraneous-semicolon
367 -Wunused}.
368 @end table
369
370
371 @node Linking
372 @section Linking
373
374 To turn a Java application into an executable program,
375 you need to link it with the needed libraries, just as for C or C++.
376 The linker by default looks for a global function named @code{main}.
377 Since Java does not have global functions, and a
378 collection of Java classes may have more than one class with a
379 @code{main} method, you need to let the linker know which of those
380 @code{main} methods it should invoke when starting the application.
381 You can do that in any of these ways:
382
383 @itemize @bullet
384 @item
385 Specify the class containing the desired @code{main} method
386 when you link the application, using the @code{--main} flag,
387 described below.
388 @item
389 Link the Java package(s) into a shared library (dll) rather than an
390 executable.  Then invoke the application using the @code{gij} program,
391 making sure that @code{gij} can find the libraries it needs.
392 @item
393 Link the Java packages(s) with the flag @code{-lgij}, which links
394 in the @code{main} routine from the @code{gij} command.
395 This allows you to select the class whose @code{main} method you
396 want to run when you run the application.  You can also use
397 other @code{gij} flags, such as @code{-D} flags to set properties.
398 Using the @code{-lgij} library (rather than the @code{gij} program
399 of the previous mechanism) has some advantages: it is compatible with
400 static linking, and does not require configuring or installing libraries.
401 @end itemize
402
403 These @code{gij} options relate to linking an executable:
404
405 @table @gcctabopt
406 @item --main=@var{CLASSNAME}
407 This option is used when linking to specify the name of the class whose
408 @code{main} method should be invoked when the resulting executable is
409 run.
410
411 @item -D@var{name}[=@var{value}]
412 This option can only be used with @code{--main}.  It defines a system
413 property named @var{name} with value @var{value}.  If @var{value} is not
414 specified then it defaults to the empty string.  These system properties
415 are initialized at the program's startup and can be retrieved at runtime
416 using the @code{java.lang.System.getProperty} method.
417
418 @item -lgij
419 Create an application whose command-line processing is that
420 of the @code{gij} command.
421
422 This option is an alternative to using @code{--main}; you cannot use both.
423
424 @item -static-libgcj
425 This option causes linking to be done against a static version of the
426 libgcj runtime library.  This option is only available if
427 corresponding linker support exists.
428
429 @strong{Caution:} Static linking of libgcj may cause essential parts
430 of libgcj to be omitted.  Some parts of libgcj use reflection to load
431 classes at runtime.  Since the linker does not see these references at
432 link time, it can omit the referred to classes.  The result is usually
433 (but not always) a @code{ClassNotFoundException} being thrown at
434 runtime. Caution must be used when using this option.  For more
435 details see:
436 @w{@uref{http://gcc.gnu.org/wiki/Statically%20linking%20libgcj}}
437 @end table
438
439 @node Code Generation
440 @section Code Generation
441
442 In addition to the many @command{gcc} options controlling code generation,
443 @command{gcj} has several options specific to itself.
444
445 @table @gcctabopt
446
447 @item -C
448 This option is used to tell @command{gcj} to generate bytecode
449 (@file{.class} files) rather than object code.
450
451 @item --resource @var{resource-name}
452 This option is used to tell @command{gcj} to compile the contents of a
453 given file to object code so it may be accessed at runtime with the core
454 protocol handler as @samp{core:/@var{resource-name}}.  Note that
455 @var{resource-name} is the name of the resource as found at runtime; for
456 instance, it could be used in a call to @code{ResourceBundle.getBundle}.
457 The actual file name to be compiled this way must be specified
458 separately.
459
460 @item -d @var{directory}
461 When used with @code{-C}, this causes all generated @file{.class} files
462 to be put in the appropriate subdirectory of @var{directory}.  By
463 default they will be put in subdirectories of the current working
464 directory.
465
466 @item -fno-bounds-check
467 By default, @command{gcj} generates code which checks the bounds of all
468 array indexing operations.  With this option, these checks are omitted, which
469 can improve performance for code that uses arrays extensively.  Note that this 
470 can result in unpredictable behavior if the code in question actually does 
471 violate array bounds constraints.  It is safe to use this option if you are 
472 sure that your code will never throw an @code{ArrayIndexOutOfBoundsException}.
473
474 @item -fno-store-check
475 Don't generate array store checks.  When storing objects into arrays, a runtime
476 check is normally generated in order to ensure that the object is assignment
477 compatible with the component type of the array (which may not be known
478 at compile-time).  With this option, these checks are omitted.  This can 
479 improve performance for code which stores objects into arrays frequently.
480 It is safe to use this option if you are sure your code will never throw an 
481 @code{ArrayStoreException}.
482
483 @item -fjni
484 With @command{gcj} there are two options for writing native methods: CNI
485 and JNI@.  By default @command{gcj} assumes you are using CNI@.  If you are
486 compiling a class with native methods, and these methods are implemented
487 using JNI, then you must use @code{-fjni}.  This option causes
488 @command{gcj} to generate stubs which will invoke the underlying JNI
489 methods.
490
491 @item -fno-assert
492 Don't recognize the @code{assert} keyword.  This is for compatibility
493 with older versions of the language specification.
494
495 @item -fno-optimize-static-class-initialization
496 When the optimization level is greater or equal to @code{-O2},
497 @command{gcj} will try to optimize the way calls into the runtime are made
498 to initialize static classes upon their first use (this optimization
499 isn't carried out if @code{-C} was specified.) When compiling to native
500 code, @code{-fno-optimize-static-class-initialization} will turn this
501 optimization off, regardless of the optimization level in use.
502
503 @item --disable-assertions[=@var{class-or-package}]
504 Don't include code for checking assertions in the compiled code.
505 If @code{=@var{class-or-package}} is missing disables assertion code
506 generation for all classes, unless overridden by a more
507 specific @code{--enable-assertions} flag.
508 If @var{class-or-package} is a class name, only disables generating
509 assertion checks within the named class or its inner classes.
510 If @var{class-or-package} is a package name, disables generating
511 assertion checks within the named package or a subpackage.
512
513 By default, assertions are enabled when generating class files
514 or when not optimizing, and disabled when generating optimized binaries.
515
516 @item --enable-assertions[=@var{class-or-package}]
517 Generates code to check assertions.  The option is perhaps misnamed,
518 as you still need to turn on assertion checking at run-time,
519 and we don't support any easy way to do that.
520 So this flag isn't very useful yet, except to partially override
521 @code{--disable-assertions}.
522
523 @item -findirect-dispatch
524 @command{gcj} has a special binary compatibility ABI, which is enabled
525 by the @code{-findirect-dispatch} option.  In this mode, the code
526 generated by @command{gcj} honors the binary compatibility guarantees
527 in the Java Language Specification, and the resulting object files do
528 not need to be directly linked against their dependencies.  Instead,
529 all dependencies are looked up at runtime.  This allows free mixing of
530 interpreted and compiled code.
531
532 Note that, at present, @code{-findirect-dispatch} can only be used
533 when compiling @file{.class} files.  It will not work when compiling
534 from source.  CNI also does not yet work with the binary compatibility
535 ABI.  These restrictions will be lifted in some future release.
536
537 However, if you compile CNI code with the standard ABI, you can call
538 it from code built with the binary compatibility ABI.
539
540 @item -fbootstrap-classes
541 This option can be use to tell @code{libgcj} that the compiled classes
542 should be loaded by the bootstrap loader, not the system class loader.
543 By default, if you compile a class and link it into an executable, it
544 will be treated as if it was loaded using the system class loader.
545 This is convenient, as it means that things like
546 @code{Class.forName()} will search @samp{CLASSPATH} to find the
547 desired class.
548
549 @item -freduced-reflection
550 This option causes the code generated by @command{gcj} to contain a
551 reduced amount of the class meta-data used to support runtime
552 reflection. The cost of this savings is the loss of
553 the ability to use certain reflection capabilities of the standard
554 Java runtime environment. When set all meta-data except for that
555 which is needed to obtain correct runtime semantics is eliminated.
556
557 For code that does not use reflection (i.e. the methods in the
558 @code{java.lang.reflect} package), @code{-freduced-reflection}
559 will result in proper operation with a savings in executable code size.
560
561 JNI (@code{-fjni}) and the binary compatibility ABI
562 (@code{-findirect-dispatch}) do not work properly without full
563 reflection meta-data.  Because of this, it is an error to use these options
564 with @code{-freduced-reflection}.
565
566 @strong{Caution:} If there is no reflection meta-data, code that uses
567 a @code{SecurityManager} may not work properly.  Also calling
568 @code{Class.forName()} may fail if the calling method has no
569 reflection meta-data.
570
571 @end table
572
573
574 @node Configure-time Options
575 @section Configure-time Options
576
577 Some @command{gcj} code generations options affect the resulting ABI, and
578 so can only be meaningfully given when @code{libgcj}, the runtime
579 package, is configured.  @code{libgcj} puts the appropriate options from
580 this group into a @samp{spec} file which is read by @command{gcj}.  These
581 options are listed here for completeness; if you are using @code{libgcj}
582 then you won't want to touch these options.
583
584 @table @gcctabopt
585 @item -fuse-boehm-gc
586 This enables the use of the Boehm GC bitmap marking code.  In particular
587 this causes @command{gcj} to put an object marking descriptor into each
588 vtable.
589
590 @item -fhash-synchronization
591 By default, synchronization data (the data used for @code{synchronize},
592 @code{wait}, and @code{notify}) is pointed to by a word in each object.
593 With this option @command{gcj} assumes that this information is stored in a
594 hash table and not in the object itself.
595
596 @item -fuse-divide-subroutine
597 On some systems, a library routine is called to perform integer
598 division.  This is required to get exception handling correct when
599 dividing by zero.
600
601 @item -fcheck-references
602 On some systems it's necessary to insert inline checks whenever
603 accessing an object via a reference.  On other systems you won't need
604 this because null pointer accesses are caught automatically by the
605 processor.
606 @end table
607
608 @c man end
609
610 @node Compatibility
611 @chapter Compatibility with the Java Platform
612
613 As we believe it is important that the Java platform not be fragmented,
614 @command{gcj} and @code{libgcj} try to conform to the relevant Java
615 specifications.  However, limited manpower and incomplete and unclear
616 documentation work against us.  So, there are caveats to using
617 @command{gcj}.
618
619 @menu
620 * Limitations::                 
621 * Extensions::                  
622 @end menu
623
624 @node Limitations
625 @section Standard features not yet supported
626
627 This list of compatibility issues is by no means complete.
628
629 @itemize @bullet
630 @item
631 @command{gcj} implements the JDK 1.2 language.  It supports inner classes
632 and the new 1.4 @code{assert} keyword.  It does not yet support the Java 2
633 @code{strictfp} keyword (it recognizes the keyword but ignores it).  
634
635 @item
636 @code{libgcj} is largely compatible with the JDK 1.2 libraries.
637 However, @code{libgcj} is missing many packages, most notably
638 @code{java.awt}.  There are also individual missing classes and methods.
639 We currently do not have a list showing differences between
640 @code{libgcj} and the Java 2 platform.
641
642 @item
643 Sometimes the @code{libgcj} implementation of a method or class differs
644 from the JDK implementation.  This is not always a bug.  Still, if it
645 affects you, it probably makes sense to report it so that we can discuss
646 the appropriate response.
647
648 @item
649 @command{gcj} does not currently allow for piecemeal replacement of
650 components within @code{libgcj}. Unfortunately, programmers often want
651 to use newer versions of certain packages, such as those provided by
652 the Apache Software Foundation's Jakarta project.  This has forced us
653 to place the @code{org.w3c.dom} and @code{org.xml.sax} packages into
654 their own libraries, separate from @code{libgcj}.  If you intend to
655 use these classes, you must link them explicitly with
656 @code{-l-org-w3c-dom} and @code{-l-org-xml-sax}.  Future versions of
657 @command{gcj} may not have this restriction.
658 @end itemize
659
660 @node Extensions
661 @section Extra features unique to gcj
662
663 The main feature of @command{gcj} is that it can compile programs written in
664 the Java programming language to native code.  Most extensions that have been
665 added are to facilitate this functionality.
666
667 @itemize @bullet
668 @item
669 @command{gcj} makes it easy and efficient to mix code written in Java and C++.
670 @xref{About CNI}, for more info on how to use this in your programs.
671
672 @item
673 When you compile your classes into a shared library using
674 @code{-findirect-dispatch} then add them to the system-wide
675 classmap.db file using @code{gcj-dbtool}, they will be automatically
676 loaded by the @code{libgcj} system classloader.  This is the new,
677 preferred classname-to-library resolution mechanism.  @xref{Invoking
678 gcj-dbtool}, for more information on using the classmap database.
679
680 @item
681 The old classname-to-library lookup mechanism is still supported
682 through the @code{gnu.gcj.runtime.VMClassLoader.library_control}
683 property, but it is deprecated and will likely be removed in some
684 future release.  When trying to load a class @code{gnu.pkg.SomeClass}
685 the system classloader will first try to load the shared library
686 @file{lib-gnu-pkg-SomeClass.so}, if that fails to load the class then
687 it will try to load @file{lib-gnu-pkg.so} and finally when the class
688 is still not loaded it will try to load @file{lib-gnu.so}.  Note that
689 all @samp{.}s will be transformed into @samp{-}s and that searching
690 for inner classes starts with their outermost outer class.  If the
691 class cannot be found this way the system classloader tries to use the
692 @code{libgcj} bytecode interpreter to load the class from the standard
693 classpath.  This process can be controlled to some degree via the
694 @code{gnu.gcj.runtime.VMClassLoader.library_control} property;
695 @xref{libgcj Runtime Properties}.
696
697 @item
698 @code{libgcj} includes a special @samp{gcjlib} URL type.  A URL of
699 this form is like a @code{jar} URL, and looks like
700 @samp{gcjlib:/path/to/shared/library.so!/path/to/resource}.  An access
701 to one of these URLs causes the shared library to be @code{dlopen()}d,
702 and then the resource is looked for in that library.  These URLs are
703 most useful when used in conjunction with @code{java.net.URLClassLoader}.
704 Note that, due to implementation limitations, currently any such URL
705 can be accessed by only one class loader, and libraries are never
706 unloaded.  This means some care must be exercised to make sure that
707 a @code{gcjlib} URL is not accessed by more than one class loader at once.
708 In a future release this limitation will be lifted, and such
709 libraries will be mapped privately.
710
711 @item
712 A program compiled by @command{gcj} will examine the
713 @env{GCJ_PROPERTIES} environment variable and change its behavior in
714 some ways.  In particular @env{GCJ_PROPERTIES} holds a list of
715 assignments to global properties, such as would be set with the
716 @option{-D} option to @command{java}.  For instance,
717 @samp{java.compiler=gcj} is a valid (but currently meaningless)
718 setting.
719 @cindex GCJ_PROPERTIES
720 @vindex GCJ_PROPERTIES
721
722 @end itemize
723
724
725 @node Invoking gcjh
726 @chapter Invoking gcjh
727
728 @c man title gcjh generate header files from Java class files
729
730 @c man begin DESCRIPTION gcjh
731
732 The @code{gcjh} program is used to generate header files from class
733 files.  It can generate both CNI and JNI header files, as well as stub
734 implementation files which can be used as a basis for implementing the
735 required native methods.
736
737 @c man end
738
739 @ignore
740 @c man begin SYNOPSIS gcjh
741 gcjh [@option{-stubs}] [@option{-jni}]
742     [@option{-force}] [@option{-old}] [@option{-trace}] [@option{-J} @var{option}]
743     [@option{-add} @var{text}] [@option{-append} @var{text}] [@option{-friend} @var{text}]
744     [@option{-preprend} @var{text}]
745     [@option{--classpath}=@var{path}] [@option{--CLASSPATH}=@var{path}]
746     [@option{--bootclasspath}=@var{path}]
747     [@option{-I}@var{dir}@dots{}] [@option{-d} @var{dir}@dots{}]
748     [@option{-o} @var{file}] [@option{-td} @var{dir}]
749     [@option{-M}] [@option{-MM}] [@option{-MD}] [@option{-MMD}]
750     [@option{--version}] [@option{--help}] [@option{-v}] [@option{--verbose}]
751     @var{classname}@dots{}
752 @c man end
753 @c man begin SEEALSO gcjh
754 gcc(1), gcj(1), gij(1), jv-scan(1), jcf-dump(1), gfdl(7),
755 and the Info entries for @file{gcj} and @file{gcc}.
756 @c man end
757 @end ignore
758
759 @c man begin OPTIONS gcjh
760
761 @table @gcctabopt
762 @item -stubs
763 This causes @code{gcjh} to generate stub files instead of header files.
764 By default the stub file will be named after the class, with a suffix of
765 @samp{.cc}.  In JNI mode, the default output file will have the suffix
766 @samp{.c}.
767
768 @item -jni
769 This tells @code{gcjh} to generate a JNI header or stub.  By default,
770 CNI headers are generated.
771
772 @item -force
773 This option forces @code{gcjh} to write the output file.
774
775 @item -old
776 This option is accepted but ignored for compatibility.
777
778 @item -trace
779 This option is accepted but ignored for compatibility.
780
781 @item -J @var{option}
782 This option is accepted but ignored for compatibility.
783
784 @item -add @var{text}
785 Inserts @var{text} into the class body.  This is ignored in JNI mode.
786
787 @item -append @var{text}
788 Inserts @var{text} into the header file after the class declaration.
789 This is ignored in JNI mode.
790
791 @item -friend @var{text}
792 Inserts @var{text} into the class as a @code{friend} declaration.
793 This is ignored in JNI mode.
794
795 @item -prepend @var{text}
796 Inserts @var{text} into the header file before the class declaration.
797 This is ignored in JNI mode.
798
799 @item --classpath=@var{path}
800 @itemx --CLASSPATH=@var{path}
801 @itemx --bootclasspath=@var{path}
802 @itemx -I@var{directory}
803 @itemx -d @var{directory}
804 @itemx -o @var{file}
805 These options are all identical to the corresponding @command{gcj} options.
806
807 @item -o @var{file}
808 Sets the output file name.  This cannot be used if there is more than
809 one class on the command line.
810
811 @item -td @var{directory}
812 Sets the name of the directory to use for temporary files.
813
814 @item -M
815 Print all dependencies to stdout; suppress ordinary output.
816
817 @item -MM
818 Print non-system dependencies to stdout; suppress ordinary output.
819
820 @item -MD
821 Print all dependencies to stdout.
822
823 @item -MMD
824 Print non-system dependencies to stdout.
825
826 @item --help
827 Print help about @code{gcjh} and exit.  No further processing is done.
828
829 @item --version
830 Print version information for @code{gcjh} and exit.  No further
831 processing is done.
832
833 @item -v, --verbose
834 Print extra information while running.
835 @end table
836
837 All remaining options are considered to be names of classes.
838
839 @c man end
840
841 @node Invoking gjnih
842 @chapter Invoking gjnih
843
844 @c man title gjnih generate JNI header files from Java class files
845
846 @c man begin DESCRIPTION gjnih
847
848 The @code{gjnih} program is used to generate JNI header files from class
849 files.  Running it is equivalent to running @code{gcjh -jni}.
850
851 @c man end
852
853 @ignore
854 @c man begin SYNOPSIS gjnih
855 gjnih [@option{-stubs}] [@option{-jni}]
856     [@option{-force}] [@option{-old}] [@option{-trace}] [@option{-J} @var{option}]
857     [@option{-add} @var{text}] [@option{-append} @var{text}] [@option{-friend} @var{text}]
858     [@option{-preprend} @var{text}]
859     [@option{--classpath}=@var{path}] [@option{--CLASSPATH}=@var{path}]
860     [@option{--bootclasspath}=@var{path}]
861     [@option{-I}@var{dir}@dots{}] [@option{-d} @var{dir}@dots{}]
862     [@option{-o} @var{file}] [@option{-td} @var{dir}]
863     [@option{-M}] [@option{-MM}] [@option{-MD}] [@option{-MMD}]
864     [@option{--version}] [@option{--help}] [@option{-v}] [@option{--verbose}]
865     @var{classname}@dots{}
866 @c man end
867 @c man begin SEEALSO gjnih
868 gcc(1), gcj(1), gcjh(1), gij(1), jv-scan(1), jcf-dump(1), gfdl(7),
869 and the Info entries for @file{gcj} and @file{gcc}.
870 @c man end
871 @end ignore
872
873 @c man begin OPTIONS gjnih
874
875 @table @gcctabopt
876 @item -stubs
877 This causes @code{gjnih} to generate stub files instead of header files.
878 By default the stub file will be named after the class, with a suffix of
879 @samp{.c}.
880
881 @item -jni
882 This option specifies the default behavior which is to generate a JNI
883 header or stub.
884
885 @item -force
886 This option forces @code{gjnih} to write the output file.
887
888 @item -old
889 This option is accepted but ignored for compatibility.
890
891 @item -trace
892 This option is accepted but ignored for compatibility.
893
894 @item -J @var{option}
895 This option is accepted but ignored for compatibility.
896
897 @item -add @var{text}
898 Inserts @var{text} into the class body.  This is ignored in by
899 @code{gjnih}.
900
901 @item -append @var{text}
902 Inserts @var{text} into the header file after the class declaration.
903 This is ignored in by @code{gjnih}.
904
905 @item -friend @var{text}
906 Inserts @var{text} into the class as a @code{friend} declaration.
907 This is ignored by @code{gjnih}.
908
909 @item -prepend @var{text}
910 Inserts @var{text} into the header file before the class declaration.
911 This is ignored in by @code{gjnih}.
912
913 @item --classpath=@var{path}
914 @itemx --CLASSPATH=@var{path}
915 @itemx --bootclasspath=@var{path}
916 @itemx -I@var{directory}
917 @itemx -d @var{directory}
918 @itemx -o @var{file}
919 These options are all identical to the corresponding @command{gcj} options.
920
921 @item -o @var{file}
922 Sets the output file name.  This cannot be used if there is more than
923 one class on the command line.
924
925 @item -td @var{directory}
926 Sets the name of the directory to use for temporary files.
927
928 @item -M
929 Print all dependencies to stdout; suppress ordinary output.
930
931 @item -MM
932 Print non-system dependencies to stdout; suppress ordinary output.
933
934 @item -MD
935 Print all dependencies to stdout.
936
937 @item -MMD
938 Print non-system dependencies to stdout.
939
940 @item --help
941 Print help about @code{gjnih} and exit.  No further processing is done.
942
943 @item --version
944 Print version information for @code{gjnih} and exit.  No further
945 processing is done.
946
947 @item -v, --verbose
948 Print extra information while running.
949 @end table
950
951 All remaining options are considered to be names of classes.
952
953 @c man end
954
955 @node Invoking jv-scan
956 @chapter Invoking jv-scan
957
958 @c man title jv-scan print information about Java source file
959
960 @c man begin DESCRIPTION jv-scan
961
962 The @code{jv-scan} program can be used to print information about a Java
963 source file (@file{.java} file).
964
965 @c man end
966
967 @ignore
968 @c man begin SYNOPSIS jv-scan
969 jv-scan [@option{--no-assert}] [@option{--complexity}] 
970     [@option{--encoding}=@var{name}] [@option{--print-main}] 
971     [@option{--list-class}] [@option{--list-filename}]
972     [@option{--version}] [@option{--help}]
973     [@option{-o} @var{file}] @var{inputfile}@dots{}
974 @c man end
975 @c man begin SEEALSO jv-scan
976 gcc(1), gcj(1), gcjh(1), gij(1), jcf-dump(1), gfdl(7),
977 and the Info entries for @file{gcj} and @file{gcc}.
978 @c man end
979 @end ignore
980
981 @c man begin OPTIONS jv-scan
982
983 @table @gcctabopt
984 @item --no-assert
985 Don't recognize the @code{assert} keyword, for backwards compatibility
986 with older versions of the language specification.
987
988 @item --complexity
989 This prints a complexity measure, related to cyclomatic complexity, for
990 each input file.
991
992 @item --encoding=@var{name}
993 This works like the corresponding @command{gcj} option.
994
995 @item --print-main
996 This prints the name of the class in this file containing a @code{main}
997 method.
998
999 @item --list-class
1000 This lists the names of all classes defined in the input files.
1001
1002 @item --list-filename
1003 If @code{--list-class} is given, this option causes @code{jv-scan} to
1004 also print the name of the file in which each class was found.
1005
1006 @item -o @var{file}
1007 Print output to the named file.
1008
1009 @item --help
1010 Print help, then exit.
1011
1012 @item --version
1013 Print version number, then exit.
1014 @end table
1015
1016 @c man end
1017
1018 @node Invoking jcf-dump
1019 @chapter Invoking jcf-dump
1020
1021 @c man title jcf-dump print information about Java class files
1022
1023 @ignore
1024 @c man begin SYNOPSIS jcf-dump
1025 jcf-dump [@option{-c}] [@option{--javap}]
1026     [@option{--classpath}=@var{path}] [@option{--CLASSPATH}=@var{path}]
1027     [@option{-I}@var{dir}@dots{}] [@option{-o} @var{file}]
1028     [@option{--version}] [@option{--help}] [@option{-v}] [@option{--verbose}]
1029     @var{classname}@dots{}
1030 @c man end
1031 @c man begin SEEALSO jcf-dump
1032 gcc(1), gcj(1), gcjh(1), gij(1), jcf-dump(1), gfdl(7),
1033 and the Info entries for @file{gcj} and @file{gcc}.
1034 @c man end
1035 @end ignore
1036
1037 @c man begin DESCRIPTION jcf-dump
1038
1039 This is a class file examiner, similar to @code{javap}.  It will print
1040 information about a number of classes, which are specified by class name
1041 or file name.
1042
1043 @c man end
1044
1045 @c man begin OPTIONS jcf-dump
1046
1047 @table @gcctabopt
1048 @item -c
1049 Disassemble method bodies.  By default method bodies are not printed.
1050
1051 @item --print-constants
1052 Print the constant pool.  When printing a reference to a constant
1053 also print its index in the constant pool.
1054
1055 @item --javap
1056 Generate output in @code{javap} format.  The implementation of this
1057 feature is very incomplete.
1058
1059 @item --classpath=@var{path}
1060 @itemx --CLASSPATH=@var{path}
1061 @itemx -I@var{directory}
1062 @itemx -o @var{file}
1063 These options as the same as the corresponding @command{gcj} options.
1064
1065 @item --help
1066 Print help, then exit.
1067
1068 @item --version
1069 Print version number, then exit.
1070
1071 @item -v, --verbose
1072 Print extra information while running.
1073 Implies @code{--print-constants}.
1074 @end table
1075
1076 @c man end
1077
1078 @node Invoking gij
1079 @chapter Invoking gij
1080
1081 @c man title gij GNU interpreter for Java bytecode
1082
1083 @ignore
1084 @c man begin SYNOPSIS gij
1085 gij [@option{OPTION}] @dots{} @var{JARFILE} [@var{ARGS}@dots{}]
1086
1087 gij [@option{-jar}] [@option{OPTION}] @dots{} @var{CLASS} [@var{ARGS}@dots{}]
1088   [@option{-cp} @var{path}] [@option{-classpath} @var{path}]
1089   [@option{-D}@var{name}[=@var{value}]@dots{}]
1090   [@option{-ms=}@var{number}] [@option{-mx=}@var{number}]
1091   [@option{-X@var{argument}}] [@option{-verbose}] [@option{-verbose:class}]
1092   [@option{--showversion}] [@option{--version}] [@option{--help}][@option{-?}]
1093 @c man end
1094 @c man begin SEEALSO gij
1095 gcc(1), gcj(1), gcjh(1), jv-scan(1), jcf-dump(1), gfdl(7),
1096 and the Info entries for @file{gcj} and @file{gcc}.
1097 @c man end
1098 @end ignore
1099
1100 @c man begin DESCRIPTION gij
1101
1102 @code{gij} is a Java bytecode interpreter included with @code{libgcj}.
1103 @code{gij} is not available on every platform; porting it requires a
1104 small amount of assembly programming which has not been done for all the
1105 targets supported by @command{gcj}.
1106
1107 The primary argument to @code{gij} is the name of a class or, with
1108 @code{-jar}, a jar file.  Options before this argument are interpreted
1109 by @code{gij}; remaining options are passed to the interpreted program.
1110
1111 If a class name is specified and this class does not have a @code{main}
1112 method with the appropriate signature (a @code{static void} method with
1113 a @code{String[]} as its sole argument), then @code{gij} will print an
1114 error and exit.
1115
1116 If a jar file is specified then @code{gij} will use information in it to
1117 determine which class' @code{main} method will be invoked.
1118
1119 @code{gij} will invoke the @code{main} method with all the remaining
1120 command-line options.
1121
1122 Note that @code{gij} is not limited to interpreting code.  Because
1123 @code{libgcj} includes a class loader which can dynamically load shared
1124 objects, it is possible to give @code{gij} the name of a class which has
1125 been compiled and put into a shared library on the class path.
1126
1127 @c man end
1128
1129 @c man begin OPTIONS gij
1130
1131 @table @gcctabopt
1132 @item -cp @var{path}
1133 @itemx -classpath @var{path}
1134 Set the initial class path.  The class path is used for finding
1135 class and resource files.  If specified, this option overrides the
1136 @code{CLASSPATH} environment variable.  Note that this option is
1137 ignored if @code{-jar} is used.
1138
1139 @item -D@var{name}[=@var{value}]
1140 This defines a system property named @var{name} with value @var{value}.
1141 If @var{value} is not specified then it defaults to the empty string.
1142 These system properties are initialized at the program's startup and can
1143 be retrieved at runtime using the @code{java.lang.System.getProperty}
1144 method.
1145
1146 @item -ms=@var{number}
1147 Equivalent to @code{-Xms}.
1148
1149 @item -mx=@var{number}
1150 Equivalent to @code{-Xmx}.
1151
1152 @item -noverify
1153 Do not verify compliance of bytecode with the VM specification. In addition,
1154 this option disables type verification which is otherwise performed on BC-ABI
1155 compiled code.
1156
1157 @item -X
1158 @itemx -X@var{argument}
1159 Supplying @code{-X} by itself will cause @code{gij} to list all the
1160 supported @code{-X} options.  Currently these options are supported:
1161
1162 @table @gcctabopt
1163 @item -Xms@var{size}
1164 Set the initial heap size.
1165
1166 @item -Xmx@var{size}
1167 Set the maximum heap size.
1168
1169 @item -Xss@var{size}
1170 Set the thread stack size.
1171 @end table
1172
1173 Unrecognized @code{-X} options are ignored, for compatibility with
1174 other runtimes.
1175
1176 @item -jar
1177 This indicates that the name passed to @code{gij} should be interpreted
1178 as the name of a jar file, not a class.
1179
1180 @item --help
1181 @itemx -?
1182 Print help, then exit.
1183
1184 @item --showversion
1185 Print version number and continue.
1186
1187 @item --fullversion
1188 Print detailed version information, then exit.
1189
1190 @item --version
1191 Print version number, then exit.
1192
1193 @item -verbose
1194 @itemx -verbose:class
1195 Each time a class is initialized, print a short message on standard error.
1196 @end table
1197
1198 @code{gij} also recognizes and ignores the following options, for
1199 compatibility with existing application launch scripts:
1200 @code{-client}, @code{-server}, @code{-hotspot}, @code{-jrockit},
1201 @code{-agentlib}, @code{-agentpath}, @code{-debug}, @code{-d32},
1202 @code{-d64}, @code{-javaagent}, @code{-noclassgc}, @code{-verify},
1203 and @code{-verifyremote}.
1204
1205 @c man end
1206
1207 @node Invoking gcj-dbtool
1208 @chapter Invoking gcj-dbtool.
1209
1210 @c man title gcj-dbtool Manipulate class file mapping databases for libgcj
1211
1212 @ignore
1213 @c man begin SYNOPSIS gcj-dbtool
1214 gcj-dbtool @option{OPTION} @var{DBFILE} [@option{MORE}] @dots{}
1215
1216 gcj-dbtool [@option{-0}] [@option{-}] [@option{-n}] [@option{-a}] [@option{-f}]
1217   [@option{-t}] [@option{-l}] [@option{-p} [@var{LIBDIR}]]
1218   [@option{-v}] [@option{-m}] [@option{--version}] [@option{--help}]
1219
1220 @c man end
1221 @c man begin SEEALSO gij
1222 gcc(1), gcj(1), gcjh(1), jv-scan(1), jcf-dump(1), gfdl(7),
1223 and the Info entries for @file{gcj} and @file{gcc}.
1224 @c man end
1225 @end ignore
1226
1227 @c man begin DESCRIPTION gcj-dbtool
1228
1229 @code{gcj-dbtool} is a tool for creating and manipulating class file
1230 mapping databases.  @code{libgcj} can use these databases to find a
1231 shared library corresponding to the bytecode representation of a
1232 class.  This functionality is useful for ahead-of-time compilation of
1233 a program that has no knowledge of @code{gcj}.
1234
1235 @code{gcj-dbtool} works best if all the jar files added to it are
1236 compiled using @code{-findirect-dispatch}.
1237
1238 Note that @code{gcj-dbtool} is currently available as ``preview
1239 technology''.  We believe it is a reasonable way to allow
1240 application-transparent ahead-of-time compilation, but this is an
1241 unexplored area.  We welcome your comments.
1242
1243 @c man end
1244
1245 @c man begin OPTIONS gcj-dbtool
1246
1247 @table @gcctabopt
1248 @item -n @var{DBFILE} [@var{SIZE}]
1249 This creates a new database.  Currently, databases cannot be resized;
1250 you can choose a larger initial size if desired.  The default size is
1251 32,749.
1252
1253 @item -a @var{DBFILE} @var{JARFILE} @var{LIB}
1254 @itemx -f @var{DBFILE} @var{JARFILE} @var{LIB}
1255 This adds a jar file to the database.  For each class file in the jar,
1256 a cryptographic signature of the bytecode representation of the class
1257 is recorded in the database.  At runtime, a class is looked up by its
1258 signature and the compiled form of the class is looked for in the
1259 corresponding shared library.  The @option{-a} option will verify
1260 that @var{LIB} exists before adding it to the database; @option{-f}
1261 skips this check.
1262
1263 @item [@option{-}][@option{-0}] -m @var{DBFILE} @var{DBFILE},[@var{DBFILE}]
1264 Merge a number of databases.  The output database overwrites any
1265 existing database.  To add databases into an existing database,
1266 include the destination in the list of sources.
1267
1268 If @option{-} or @option{-0} are used, the list of files to read is
1269 taken from standard input instead of the command line.  For
1270 @option{-0}, Input filenames are terminated by a null character
1271 instead of by whitespace.  Useful when arguments might contain white
1272 space.  The GNU find -print0 option produces input suitable for this
1273 mode.
1274
1275 @item -t @var{DBFILE}
1276 Test a database.
1277
1278 @item -l @var{DBFILE}
1279 List the contents of a database.
1280
1281 @item -p
1282 Print the name of the default database.  If there is no default
1283 database, this prints a blank line.  If @var{LIBDIR} is specified, use
1284 it instead of the default library directory component of the database
1285 name.
1286
1287 @item --help
1288 Print a help message, then exit.
1289
1290 @item --version
1291 @itemx -v
1292 Print version information, then exit.
1293
1294 @end table
1295
1296 @c man end
1297
1298 @node Invoking jv-convert
1299 @chapter Invoking jv-convert
1300
1301 @c man title jv-convert Convert file from one encoding to another
1302
1303 @c man begin SYNOPSIS jv-convert
1304 @command{jv-convert} [@option{OPTION}] @dots{} [@var{INPUTFILE} [@var{OUTPUTFILE}]]
1305 @ignore
1306
1307   [@option{--encoding} @var{name}]
1308   [@option{--from} @var{name}]
1309   [@option{--to} @var{name}]
1310   [@option{-i} @var{file}] [@option{-o} @var{file}]
1311   [@option{--reverse}] [@option{--help}] [@option{--version}]
1312 @end ignore
1313 @c man end
1314
1315 @c man begin DESCRIPTION jv-convert
1316
1317 @command{jv-convert} is a utility included with @code{libgcj} which
1318 converts a file from one encoding to another.  It is similar to the Unix
1319 @command{iconv} utility.
1320
1321 The encodings supported by @command{jv-convert} are platform-dependent.
1322 Currently there is no way to get a list of all supported encodings.
1323
1324 @c man end
1325
1326 @c man begin OPTIONS jv-convert
1327
1328 @table @gcctabopt
1329 @item --encoding @var{name}
1330 @itemx --from @var{name}
1331 Use @var{name} as the input encoding.  The default is the current
1332 locale's encoding.
1333
1334 @item --to @var{name}
1335 Use @var{name} as the output encoding.  The default is the
1336 @code{JavaSrc} encoding; this is ASCII with @samp{\u} escapes for
1337 non-ASCII characters.
1338
1339 @item -i @var{file}
1340 Read from @var{file}.  The default is to read from standard input.
1341
1342 @item -o @var{file}
1343 Write to @var{file}.  The default is to write to standard output.
1344
1345 @item --reverse
1346 Swap the input and output encodings.
1347
1348 @item --help
1349 Print a help message, then exit.
1350
1351 @item --version
1352 Print version information, then exit.
1353 @end table
1354
1355 @c man end
1356
1357 @node Invoking grmic
1358 @chapter Invoking grmic
1359
1360 @c man title grmic Generate stubs for Remote Method Invocation
1361
1362 @c man begin SYNOPSIS grmic
1363 @command{grmic} [@option{OPTION}] @dots{} @var{class} @dots{}
1364 @ignore
1365   [@option{-keep}]
1366   [@option{-keepgenerated}]
1367   [@option{-v1.1}]
1368   [@option{-vcompat}]
1369   [@option{-v1.2}]
1370   [@option{-nocompile}]
1371   [@option{-verbose}]
1372   [@option{-d} @var{directory}]
1373   [@option{-help}]
1374   [@option{-version}]
1375 @end ignore
1376 @c man end
1377
1378 @c man begin DESCRIPTION grmic
1379
1380 @command{grmic} is a utility included with @code{libgcj} which generates
1381 stubs for remote objects.
1382
1383 @c FIXME: Add real information here.
1384 @c This really isn't much more than the --help output.
1385
1386 Note that this program isn't yet fully compatible with the JDK
1387 @command{grmic}.  Some options, such as @option{-classpath}, are
1388 recognized but currently ignored.  We have left these options
1389 undocumented for now.
1390
1391 Long options can also be given with a GNU-style leading @samp{--}.  For
1392 instance, @option{--help} is accepted.
1393
1394 @c man end
1395
1396 @c man begin OPTIONS grmic
1397
1398 @table @gcctabopt
1399 @item -keep
1400 @itemx -keepgenerated
1401 By default, @command{grmic} deletes intermediate files.  Either of these
1402 options causes it not to delete such files.
1403
1404 @item -v1.1
1405 Cause @command{grmic} to create stubs and skeletons for the 1.1
1406 protocol version.
1407
1408 @item -vcompat
1409 Cause @command{grmic} to create stubs and skeletons compatible with both
1410 the 1.1 and 1.2 protocol versions.  This is the default.
1411
1412 @item -v1.2
1413 Cause @command{grmic} to create stubs and skeletons for the 1.2
1414 protocol version.
1415
1416 @item -nocompile
1417 Don't compile the generated files.
1418
1419 @item -verbose
1420 Print information about what @command{grmic} is doing.
1421
1422 @item -d @var{directory}
1423 Put output files in @var{directory}.  By default the files are put in
1424 the current working directory.
1425
1426 @item -help
1427 Print a help message, then exit.
1428
1429 @item -version
1430 Print version information, then exit.
1431 @end table
1432
1433 @c man end
1434
1435
1436 @node Invoking grmiregistry
1437 @chapter Invoking grmiregistry
1438
1439 @c man title grmiregistry Remote object registry
1440
1441 @c man begin SYNOPSIS grmiregistry
1442 @command{grmic} [@option{OPTION}] @dots{} [@var{port}]
1443 @ignore
1444   [@option{--help}]
1445   [@option{--version}]
1446 @end ignore
1447 @c man end
1448
1449 @c man begin DESCRIPTION grmiregistry
1450
1451 @command{grmiregistry} starts a remote object registry on the current
1452 host.  If no port number is specified, then port 1099 is used.
1453
1454 @c FIXME: Add real information here.
1455 @c This really isn't much more than the --help output.
1456
1457 @c man end
1458
1459 @c man begin OPTIONS grmiregistry
1460
1461 @table @gcctabopt
1462 @item --help
1463 Print a help message, then exit.
1464
1465 @item --version
1466 Print version information, then exit.
1467 @end table
1468
1469 @c man end
1470
1471
1472 @node About CNI
1473 @chapter About CNI
1474
1475 This documents CNI, the Compiled Native Interface,
1476 which is is a convenient way to write Java native methods using C++.
1477 This is a more efficient, more convenient, but less portable
1478 alternative to the standard JNI (Java Native Interface).
1479
1480 @menu
1481 * Basic concepts::              Introduction to using CNI@.
1482 * Packages::                    How packages are mapped to C++.
1483 * Primitive types::             Handling primitive Java types in C++.
1484 * Reference types::             Handling Java reference types in C++.
1485 * Interfaces::                  How Java interfaces map to C++.
1486 * Objects and Classes::         C++ and Java classes.
1487 * Class Initialization::        How objects are initialized.
1488 * Object allocation::           How to create Java objects in C++.
1489 * Memory allocation::           How to allocate and free memory.
1490 * Arrays::                      Dealing with Java arrays in C++.
1491 * Methods::                     Java methods in C++.
1492 * Strings::                     Information about Java Strings.
1493 * Mixing with C++::             How CNI can interoperate with C++.
1494 * Exception Handling::          How exceptions are handled.
1495 * Synchronization::             Synchronizing between Java and C++.
1496 * Invocation::                  Starting the Java runtime from C++.
1497 * Reflection::                  Using reflection from C++.
1498 @end menu
1499
1500
1501 @node Basic concepts
1502 @section Basic concepts
1503
1504 In terms of languages features, Java is mostly a subset
1505 of C++.  Java has a few important extensions, plus a powerful standard
1506 class library, but on the whole that does not change the basic similarity.
1507 Java is a hybrid object-oriented language, with a few native types,
1508 in addition to class types.  It is class-based, where a class may have
1509 static as well as per-object fields, and static as well as instance methods.
1510 Non-static methods may be virtual, and may be overloaded.  Overloading is
1511 resolved at compile time by matching the actual argument types against
1512 the parameter types.  Virtual methods are implemented using indirect calls
1513 through a dispatch table (virtual function table).  Objects are
1514 allocated on the heap, and initialized using a constructor method.
1515 Classes are organized in a package hierarchy.
1516
1517 All of the listed attributes are also true of C++, though C++ has
1518 extra features (for example in C++ objects may be allocated not just
1519 on the heap, but also statically or in a local stack frame).  Because
1520 @command{gcj} uses the same compiler technology as G++ (the GNU
1521 C++ compiler), it is possible to make the intersection of the two
1522 languages use the same ABI (object representation and calling
1523 conventions).  The key idea in CNI is that Java objects are C++
1524 objects, and all Java classes are C++ classes (but not the other way
1525 around).  So the most important task in integrating Java and C++ is to
1526 remove gratuitous incompatibilities.
1527
1528 You write CNI code as a regular C++ source file.  (You do have to use
1529 a Java/CNI-aware C++ compiler, specifically a recent version of G++.)
1530
1531 @noindent A CNI C++ source file must have:
1532
1533 @example
1534 #include <gcj/cni.h>
1535 @end example
1536
1537 @noindent and then must include one header file for each Java class it uses, e.g.:
1538
1539 @example
1540 #include <java/lang/Character.h>
1541 #include <java/util/Date.h>
1542 #include <java/lang/IndexOutOfBoundsException.h>
1543 @end example
1544
1545 @noindent These header files are automatically generated by @code{gcjh}.
1546
1547
1548 CNI provides some functions and macros to make using Java objects and
1549 primitive types from C++ easier.  In general, these CNI functions and
1550 macros start with the @code{Jv} prefix, for example the function
1551 @code{JvNewObjectArray}.  This convention is used to avoid conflicts
1552 with other libraries.  Internal functions in CNI start with the prefix
1553 @code{_Jv_}.  You should not call these; if you find a need to, let us
1554 know and we will try to come up with an alternate solution.
1555
1556
1557 @subsection Limitations
1558
1559 Whilst a Java class is just a C++ class that doesn't mean that you are
1560 freed from the shackles of Java, a @acronym{CNI} C++ class must adhere to the
1561 rules of the Java programming language.
1562
1563 For example: it is not possible to declare a method in a CNI class
1564 that will take a C string (@code{char*}) as an argument, or to declare a
1565 member variable of some non-Java datatype.
1566
1567
1568 @node Packages
1569 @section Packages
1570
1571 The only global names in Java are class names, and packages.  A
1572 @dfn{package} can contain zero or more classes, and also zero or more
1573 sub-packages.  Every class belongs to either an unnamed package or a
1574 package that has a hierarchical and globally unique name.
1575
1576 A Java package is mapped to a C++ @dfn{namespace}.  The Java class
1577 @code{java.lang.String} is in the package @code{java.lang}, which is a
1578 sub-package of @code{java}.  The C++ equivalent is the class
1579 @code{java::lang::String}, which is in the namespace @code{java::lang}
1580 which is in the namespace @code{java}.
1581
1582 @noindent Here is how you could express this:
1583
1584 @example
1585 (// @r{Declare the class(es), possibly in a header file:}
1586 namespace java @{
1587   namespace lang @{
1588     class Object;
1589     class String;
1590     ...
1591   @}
1592 @}
1593
1594 class java::lang::String : public java::lang::Object
1595 @{
1596   ...
1597 @};
1598 @end example
1599
1600 @noindent The @code{gcjh} tool automatically generates the necessary namespace
1601 declarations.
1602
1603
1604 @subsection Leaving out package names
1605
1606 Always using the fully-qualified name of a java class can be
1607 tiresomely verbose.  Using the full qualified name also ties the code
1608 to a single package making code changes necessary should the class
1609 move from one package to another.  The Java @code{package} declaration
1610 specifies that the following class declarations are in the named
1611 package, without having to explicitly name the full package
1612 qualifiers.  The @code{package} declaration can be
1613 followed by zero or more @code{import} declarations, which
1614 allows either a single class or all the classes in a package to be
1615 named by a simple identifier.  C++ provides something similar with the
1616 @code{using} declaration and directive.
1617
1618 @noindent In Java:
1619
1620 @example
1621 import @var{package-name}.@var{class-name};
1622 @end example
1623
1624 @noindent allows the program text to refer to @var{class-name} as a shorthand for 
1625 the fully qualified name: @code{@var{package-name}.@var{class-name}}.
1626
1627
1628 @noindent To achieve the same effect C++, you have to do this:
1629
1630 @example
1631 using @var{package-name}::@var{class-name};
1632 @end example
1633
1634
1635 @noindent Java can also cause imports on demand, like this:
1636
1637 @example
1638 import @var{package-name}.*;
1639 @end example
1640
1641 @noindent Doing this allows any class from the package @var{package-name} to be
1642 referred to only by its class-name within the program text.
1643
1644
1645 @noindent The same effect can be achieved in C++ like this:
1646
1647 @example
1648 using namespace @var{package-name};
1649 @end example
1650
1651
1652 @node Primitive types
1653 @section Primitive types
1654
1655 Java provides 8 @dfn{primitives} types which represent integers, floats, 
1656 characters and booleans (and also the void type).  C++ has its own
1657 very similar concrete types.  Such types in C++ however are not always
1658 implemented in the same way (an int might be 16, 32 or 64 bits for example) 
1659 so CNI provides a special C++ type for each primitive Java type:
1660
1661 @multitable @columnfractions .20 .25 .60
1662 @item @strong{Java type}   @tab @strong{C/C++ typename} @tab @strong{Description}
1663 @item @code{char}        @tab @code{jchar}          @tab 16 bit Unicode character
1664 @item @code{boolean}     @tab @code{jboolean}       @tab logical (true or false) values
1665 @item @code{byte}        @tab @code{jbyte}          @tab 8-bit signed integer
1666 @item @code{short}       @tab @code{jshort}         @tab 16 bit signed integer
1667 @item @code{int}         @tab @code{jint}           @tab 32 bit signed integer
1668 @item @code{long}        @tab @code{jlong}          @tab 64 bit signed integer
1669 @item @code{float}       @tab @code{jfloat}         @tab 32 bit IEEE floating point number
1670 @item @code{double}      @tab @code{jdouble}        @tab 64 bit IEEE floating point number
1671 @item @code{void}        @tab @code{void}           @tab no value
1672 @end multitable
1673
1674 When referring to a Java type You should always use these C++ typenames (e.g.: @code{jint})
1675 to avoid disappointment.
1676
1677
1678 @subsection Reference types associated with primitive types
1679
1680 In Java each primitive type has an associated reference type, 
1681 e.g.: @code{boolean} has an associated @code{java.lang.Boolean.TYPE} class.
1682 In order to make working with such classes easier GCJ provides the macro
1683 @code{JvPrimClass}:
1684
1685 @deffn macro JvPrimClass type
1686 Return a pointer to the @code{Class} object corresponding to the type supplied.
1687
1688 @example
1689 JvPrimClass(void) @result{} java.lang.Void.TYPE
1690 @end example
1691
1692 @end deffn
1693
1694
1695 @node Reference types
1696 @section Reference types
1697
1698 A Java reference type is treated as a class in C++.  Classes and
1699 interfaces are handled this way.  A Java reference is translated to a
1700 C++ pointer, so for instance a Java @code{java.lang.String} becomes,
1701 in C++, @code{java::lang::String *}.
1702
1703 CNI provides a few built-in typedefs for the most common classes:
1704 @multitable @columnfractions .30 .25 .60
1705 @item @strong{Java type} @tab @strong{C++ typename} @tab @strong{Description}
1706 @item @code{java.lang.Object} @tab @code{jobject} @tab Object type
1707 @item @code{java.lang.String} @tab @code{jstring} @tab String type
1708 @item @code{java.lang.Class} @tab @code{jclass} @tab Class type
1709 @end multitable
1710 @cindex jobject
1711 @cindex jstring
1712 @cindex jclass
1713
1714 Every Java class or interface has a corresponding @code{Class}
1715 instance.  These can be accessed in CNI via the static @code{class$}
1716 field of a class.  The @code{class$} field is of type @code{Class}
1717 (and not @code{Class *}), so you will typically take the address of
1718 it.
1719 @cindex class$
1720
1721 Here is how you can refer to the class of @code{String}, which in
1722 Java would be written @code{String.class}:
1723
1724 @example
1725 using namespace java::lang;
1726 doSomething (&String::class$);
1727 @end example
1728
1729
1730 @node Interfaces
1731 @section Interfaces
1732
1733 A Java class can @dfn{implement} zero or more
1734 @dfn{interfaces}, in addition to inheriting from
1735 a single base class. 
1736
1737 @acronym{CNI} allows CNI code to implement methods of interfaces.
1738 You can also call methods through interface references, with some
1739 limitations.
1740
1741 @acronym{CNI} doesn't understand interface inheritance at all yet.  So,
1742 you can only call an interface method when the declared type of the
1743 field being called matches the interface which declares that
1744 method.  The workaround is to cast the interface reference to the right
1745 superinterface.
1746  
1747 For example if you have: 
1748
1749 @example 
1750 interface A 
1751 @{ 
1752   void a(); 
1753 @} 
1754  
1755 interface B extends A 
1756 @{ 
1757   void b(); 
1758 @} 
1759 @end example
1760  
1761 and declare a variable of type @code{B} in C++, you can't call
1762 @code{a()} unless you cast it to an @code{A} first.
1763
1764 @node Objects and Classes
1765 @section Objects and Classes
1766
1767 @subsection Classes
1768
1769 All Java classes are derived from @code{java.lang.Object}.  C++ does
1770 not have a unique root class, but we use the C++ class
1771 @code{java::lang::Object} as the C++ version of the
1772 @code{java.lang.Object} Java class.  All other Java classes are mapped
1773 into corresponding C++ classes derived from @code{java::lang::Object}.
1774
1775 Interface inheritance (the @code{implements} keyword) is currently not
1776 reflected in the C++ mapping.
1777
1778
1779 @subsection Object fields
1780
1781 Each object contains an object header, followed by the instance fields
1782 of the class, in order.  The object header consists of a single
1783 pointer to a dispatch or virtual function table.  (There may be extra
1784 fields @emph{in front of} the object, for example for memory
1785 management, but this is invisible to the application, and the
1786 reference to the object points to the dispatch table pointer.)
1787
1788 The fields are laid out in the same order, alignment, and size as in
1789 C++.  Specifically, 8-bit and 16-bit native types (@code{byte},
1790 @code{short}, @code{char}, and @code{boolean}) are @emph{not} widened
1791 to 32 bits.  Note that the Java VM does extend 8-bit and 16-bit types
1792 to 32 bits when on the VM stack or temporary registers.
1793
1794 If you include the @code{gcjh}-generated header for a
1795 class, you can access fields of Java classes in the @emph{natural}
1796 way.  For example, given the following Java class:
1797
1798 @example
1799 public class Int
1800 @{
1801   public int i;
1802   public Int (int i) @{ this.i = i; @}
1803   public static Int zero = new Int(0);
1804 @}
1805 @end example
1806
1807 you can write:
1808
1809 @example
1810 #include <gcj/cni.h>;
1811 #include <Int>;
1812
1813 Int*
1814 mult (Int *p, jint k)
1815 @{
1816   if (k == 0)
1817     return Int::zero;  // @r{Static member access.}
1818   return new Int(p->i * k);
1819 @}
1820 @end example
1821
1822
1823 @subsection Access specifiers
1824
1825 CNI does not strictly enforce the Java access
1826 specifiers, because Java permissions cannot be directly mapped
1827 into C++ permission.  Private Java fields and methods are mapped
1828 to private C++ fields and methods, but other fields and methods
1829 are mapped to public fields and methods.
1830
1831
1832
1833 @node Class Initialization
1834 @section Class Initialization
1835
1836 Java requires that each class be automatically initialized at the time 
1837 of the first active use.  Initializing a class involves 
1838 initializing the static fields, running code in class initializer 
1839 methods, and initializing base classes.  There may also be 
1840 some implementation specific actions, such as allocating 
1841 @code{String} objects corresponding to string literals in
1842 the code.
1843
1844 The GCJ compiler inserts calls to @code{JvInitClass} at appropriate
1845 places to ensure that a class is initialized when required.  The C++
1846 compiler does not insert these calls automatically---it is the
1847 programmer's responsibility to make sure classes are initialized.
1848 However, this is fairly painless because of the conventions assumed by
1849 the Java system.
1850
1851 First, @code{libgcj} will make sure a class is initialized before an
1852 instance of that object is created.  This is one of the
1853 responsibilities of the @code{new} operation.  This is taken care of
1854 both in Java code, and in C++ code.  When G++ sees a @code{new} of a
1855 Java class, it will call a routine in @code{libgcj} to allocate the
1856 object, and that routine will take care of initializing the class.
1857 Note however that this does not happen for Java arrays; you must
1858 allocate those using the appropriate CNI function.  It follows that
1859 you can access an instance field, or call an instance (non-static)
1860 method and be safe in the knowledge that the class and all of its base
1861 classes have been initialized.
1862
1863 Invoking a static method is also safe.  This is because the
1864 Java compiler adds code to the start of a static method to make sure
1865 the class is initialized.  However, the C++ compiler does not
1866 add this extra code.  Hence, if you write a native static method
1867 using CNI, you are responsible for calling @code{JvInitClass}
1868 before doing anything else in the method (unless you are sure
1869 it is safe to leave it out).
1870
1871 Accessing a static field also requires the class of the
1872 field to be initialized.  The Java compiler will generate code
1873 to call @code{JvInitClass} before getting or setting the field.
1874 However, the C++ compiler will not generate this extra code,
1875 so it is your responsibility to make sure the class is
1876 initialized before you access a static field from C++.
1877
1878
1879 @node Object allocation
1880 @section Object allocation
1881
1882 New Java objects are allocated using a
1883 @dfn{class instance creation expression}, e.g.:
1884
1885 @example
1886 new @var{Type} ( ... )
1887 @end example
1888
1889 The same syntax is used in C++.  The main difference is that
1890 C++ objects have to be explicitly deleted; in Java they are
1891 automatically deleted by the garbage collector.
1892 Using @acronym{CNI}, you can allocate a new Java object
1893 using standard C++ syntax and the C++ compiler will allocate
1894 memory from the garbage collector.  If you have overloaded
1895 constructors, the compiler will choose the correct one
1896 using standard C++ overload resolution rules.  
1897
1898 @noindent For example:
1899
1900 @example
1901 java::util::Hashtable *ht = new java::util::Hashtable(120);
1902 @end example
1903
1904
1905 @node Memory allocation
1906 @section Memory allocation
1907
1908 When allocating memory in @acronym{CNI} methods it is best to handle
1909 out-of-memory conditions by throwing a Java exception.  These
1910 functions are provided for that purpose:
1911
1912 @deftypefun void* JvMalloc (jsize @var{size})
1913 Calls malloc.  Throws @code{java.lang.OutOfMemoryError} if allocation
1914 fails.
1915 @end deftypefun
1916
1917 @deftypefun void* JvRealloc (void* @var{ptr}, jsize @var{size})
1918 Calls realloc.  Throws @code{java.lang.OutOfMemoryError} if
1919 reallocation fails.
1920 @end deftypefun
1921
1922 @deftypefun void JvFree (void* @var{ptr})
1923 Calls free.
1924 @end deftypefun
1925
1926 @node Arrays
1927 @section Arrays
1928
1929 While in many ways Java is similar to C and C++, it is quite different
1930 in its treatment of arrays.  C arrays are based on the idea of pointer
1931 arithmetic, which would be incompatible with Java's security
1932 requirements.  Java arrays are true objects (array types inherit from
1933 @code{java.lang.Object}).  An array-valued variable is one that
1934 contains a reference (pointer) to an array object.
1935
1936 Referencing a Java array in C++ code is done using the
1937 @code{JArray} template, which as defined as follows:
1938
1939 @example
1940 class __JArray : public java::lang::Object
1941 @{
1942 public:
1943   int length;
1944 @};
1945
1946 template<class T>
1947 class JArray : public __JArray
1948 @{
1949   T data[0];
1950 public:
1951   T& operator[](jint i) @{ return data[i]; @}
1952 @};
1953 @end example
1954
1955
1956 There are a number of @code{typedef}s which correspond to @code{typedef}s 
1957 from the @acronym{JNI}.  Each is the type of an array holding objects
1958 of the relevant type:
1959
1960 @example
1961 typedef __JArray *jarray;
1962 typedef JArray<jobject> *jobjectArray;
1963 typedef JArray<jboolean> *jbooleanArray;
1964 typedef JArray<jbyte> *jbyteArray;
1965 typedef JArray<jchar> *jcharArray;
1966 typedef JArray<jshort> *jshortArray;
1967 typedef JArray<jint> *jintArray;
1968 typedef JArray<jlong> *jlongArray;
1969 typedef JArray<jfloat> *jfloatArray;
1970 typedef JArray<jdouble> *jdoubleArray;
1971 @end example
1972
1973
1974 @deftypemethod {template<class T>} T* elements (JArray<T> @var{array})
1975 This template function can be used to get a pointer to the elements of
1976 the @code{array}.  For instance, you can fetch a pointer to the
1977 integers that make up an @code{int[]} like so:
1978
1979 @example
1980 extern jintArray foo;
1981 jint *intp = elements (foo);
1982 @end example
1983
1984 The name of this function may change in the future.
1985 @end deftypemethod
1986
1987
1988 @deftypefun jobjectArray JvNewObjectArray (jsize @var{length}, jclass @var{klass}, jobject @var{init})
1989 This creates a new array whose elements have reference type.
1990 @code{klass} is the type of elements of the array and
1991 @code{init} is the initial value put into every slot in the array.
1992 @end deftypefun
1993
1994 @example
1995 using namespace java::lang;
1996 JArray<String *> *array
1997   = (JArray<String *> *) JvNewObjectArray(length, &String::class$, NULL);
1998 @end example
1999
2000
2001 @subsection Creating arrays
2002
2003 For each primitive type there is a function which can be used to
2004 create a new array of that type.  The name of the function is of the
2005 form:
2006
2007 @example
2008 JvNew@var{Type}Array
2009 @end example
2010
2011 @noindent For example:
2012
2013 @example
2014 JvNewBooleanArray
2015 @end example
2016
2017 @noindent can be used to create an array of Java primitive boolean types.
2018
2019 @noindent The following function definition is the template for all such functions:
2020
2021 @deftypefun jbooleanArray JvNewBooleanArray (jint @var{length})
2022 Create's an array @var{length} indices long.
2023 @end deftypefun
2024
2025 @deftypefun jsize JvGetArrayLength (jarray @var{array})
2026 Returns the length of the @var{array}.
2027 @end deftypefun
2028
2029
2030 @node Methods
2031 @section Methods
2032
2033 Java methods are mapped directly into C++ methods.
2034 The header files generated by @code{gcjh}
2035 include the appropriate method definitions.
2036 Basically, the generated methods have the same names and
2037 @emph{corresponding} types as the Java methods,
2038 and are called in the natural manner.
2039
2040 @subsection Overloading
2041
2042 Both Java and C++ provide method overloading, where multiple
2043 methods in a class have the same name, and the correct one is chosen
2044 (at compile time) depending on the argument types.
2045 The rules for choosing the correct method are (as expected) more complicated
2046 in C++ than in Java, but given a set of overloaded methods
2047 generated by @code{gcjh} the C++ compiler will choose
2048 the expected one.
2049
2050 Common assemblers and linkers are not aware of C++ overloading,
2051 so the standard implementation strategy is to encode the
2052 parameter types of a method into its assembly-level name.
2053 This encoding is called @dfn{mangling},
2054 and the encoded name is the @dfn{mangled name}.
2055 The same mechanism is used to implement Java overloading.
2056 For C++/Java interoperability, it is important that both the Java
2057 and C++ compilers use the @emph{same} encoding scheme.
2058
2059 @subsection Static methods
2060
2061 Static Java methods are invoked in @acronym{CNI} using the standard
2062 C++ syntax, using the @code{::} operator rather
2063 than the @code{.} operator.  
2064
2065 @noindent For example:
2066
2067 @example
2068 jint i = java::lang::Math::round((jfloat) 2.3);
2069 @end example
2070
2071 @noindent C++ method definition syntax is used to define a static native method.
2072 For example:
2073
2074 @example
2075 #include <java/lang/Integer>
2076 java::lang::Integer*
2077 java::lang::Integer::getInteger(jstring str)
2078 @{
2079   ...
2080 @}
2081 @end example
2082
2083
2084 @subsection Object Constructors
2085
2086 Constructors are called implicitly as part of object allocation
2087 using the @code{new} operator.  
2088
2089 @noindent For example:
2090
2091 @example
2092 java::lang::Integer *x = new java::lang::Integer(234);
2093 @end example
2094
2095 Java does not allow a constructor to be a native method.
2096 This limitation can be coded round however because a constructor
2097 can @emph{call} a native method.
2098
2099
2100 @subsection Instance methods
2101
2102 Calling a Java instance method from a C++ @acronym{CNI} method is done 
2103 using the standard C++ syntax, e.g.:
2104
2105 @example
2106 // @r{First create the Java object.}
2107 java::lang::Integer *x = new java::lang::Integer(234);
2108 // @r{Now call a method.}
2109 jint prim_value = x->intValue();
2110 if (x->longValue == 0) 
2111   ...
2112 @end example
2113
2114 @noindent Defining a Java native instance method is also done the natural way:
2115
2116 @example
2117 #include <java/lang/Integer.h>
2118
2119 jdouble
2120 java::lang:Integer::doubleValue()
2121 @{
2122   return (jdouble) value;
2123 @}
2124 @end example
2125
2126
2127 @subsection Interface methods
2128
2129 In Java you can call a method using an interface reference.  This is
2130 supported, but not completely.  @xref{Interfaces}.
2131
2132
2133
2134
2135 @node Strings
2136 @section Strings
2137
2138 @acronym{CNI} provides a number of utility functions for
2139 working with Java Java @code{String} objects.
2140 The names and interfaces are analogous to those of @acronym{JNI}.
2141
2142
2143 @deftypefun jstring JvNewString (const char* @var{chars}, jsize @var{len})
2144 Returns a Java @code{String} object with characters from the C string
2145 @var{chars} up to the index @var{len} in that array.
2146 @end deftypefun
2147
2148 @deftypefun jstring JvNewStringLatin1 (const char* @var{bytes}, jsize @var{len})
2149 Returns a Java @code{String} made up of @var{len} bytes from @var{bytes}.
2150 @end deftypefun
2151
2152
2153 @deftypefun jstring JvNewStringLatin1 (const char* @var{bytes})
2154 As above but the length of the @code{String} is @code{strlen(@var{bytes})}.
2155 @end deftypefun
2156
2157 @deftypefun jstring JvNewStringUTF (const char* @var{bytes})
2158 Returns a @code{String} which is made up of the UTF encoded characters
2159 present in the C string @var{bytes}.
2160 @end deftypefun
2161
2162 @deftypefun jchar* JvGetStringChars (jstring @var{str})
2163 Returns a pointer to an array of characters making up the @code{String} @var{str}.
2164 @end deftypefun
2165
2166 @deftypefun int JvGetStringUTFLength (jstring @var{str})
2167 Returns the number of bytes required to encode the contents of the
2168 @code{String} @var{str} in UTF-8.
2169 @end deftypefun
2170
2171 @deftypefun jsize JvGetStringUTFRegion (jstring @var{str}, jsize @var{start}, jsize @var{len}, char* @var{buf})
2172 Puts the UTF-8 encoding of a region of the @code{String} @var{str} into 
2173 the buffer @code{buf}.  The region to fetch is marked by @var{start} and @var{len}.
2174
2175 Note that @var{buf} is a buffer, not a C string.  It is @emph{not} 
2176 null terminated.
2177 @end deftypefun
2178
2179
2180 @node Mixing with C++
2181 @section Interoperating with C/C++
2182
2183 Because @acronym{CNI} is designed to represent Java classes and methods it
2184 cannot be mixed readily with C/C++ types.
2185
2186 One important restriction is that Java classes cannot have non-Java
2187 type instance or static variables and cannot have methods which take
2188 non-Java types as arguments or return non-Java types.
2189
2190 @noindent None of the following is possible with CNI:
2191
2192 @example
2193
2194 class ::MyClass : public java::lang::Object
2195 @{
2196    char* variable;  // @r{char* is not a valid Java type.}
2197 @}
2198
2199
2200 uint
2201 ::SomeClass::someMethod (char *arg)
2202 @{
2203   .
2204   .
2205   .
2206 @}   // @r{@code{uint} is not a valid Java type, neither is @code{char*}}
2207 @end example
2208
2209 @noindent Of course, it is ok to use C/C++ types within the scope of a method:
2210
2211
2212 @example
2213 jint
2214 ::SomeClass::otherMethod (jstring str)
2215 @{
2216    char *arg = ...
2217    .
2218    .
2219    .
2220 @}
2221 @end example
2222
2223 @subsection RawData
2224
2225 The above restriction can be problematic, so @acronym{CNI} includes the
2226 @code{gnu.gcj.RawData} class.  The @code{RawData} class is a
2227 @dfn{non-scanned reference} type.  In other words variables declared
2228 of type @code{RawData} can contain any data and are not checked by the
2229 compiler or memory manager in any way.
2230
2231 This means that you can put C/C++ data structures (including classes)
2232 in your @acronym{CNI} classes, as long as you use the appropriate cast.
2233
2234 @noindent Here are some examples:
2235
2236 @example
2237
2238 class ::MyClass : public java::lang::Object
2239 @{
2240    gnu.gcj.RawData string;
2241
2242    MyClass ();
2243    gnu.gcj.RawData getText ();
2244    void printText ();
2245 @}
2246
2247 ::MyClass::MyClass ()
2248 @{
2249    char* text = ...
2250    string = text;
2251 @}
2252
2253 gnu.gcj.RawData
2254 ::MyClass::getText ()
2255 @{
2256    return string;
2257 @}
2258
2259 void
2260 ::MyClass::printText ()
2261 @{
2262   printf("%s\n", (char*) string);
2263 @}
2264 @end example
2265
2266
2267 @subsection RawDataManaged
2268
2269 @code{gnu.gcj.RawDataManaged} is another type used to indicate special data used 
2270 by native code. Unlike the @code{RawData} type, fields declared as 
2271 @code{RawDataManaged} will be "marked" by the memory manager and 
2272 considered for garbage collection.  
2273
2274 Native data which is allocated using CNI's @code{JvAllocBytes()}
2275 function and stored in a @code{RawDataManaged} will be automatically 
2276 freed when the Java object it is associated with becomes unreachable.
2277
2278 @subsection Native memory allocation
2279
2280 @deftypefun void* JvAllocBytes (jsize @var{size})
2281 Allocates @var{size} bytes from the heap.  The memory returned is zeroed.
2282 This memory is not scanned for pointers by the garbage collector, but will 
2283 be freed if no references to it are discovered.
2284
2285 This function can be useful if you need to associate some native data with a
2286 Java object. Using a CNI's special @code{RawDataManaged} type, native data 
2287 allocated with @code{JvAllocBytes} will be automatically freed when the Java 
2288 object itself becomes unreachable.
2289 @end deftypefun
2290
2291 @subsection Posix signals
2292
2293 On Posix based systems the @code{libgcj} library uses several signals
2294 internally.  @acronym{CNI} code should not attempt to use the same
2295 signals as doing so may cause @code{libgcj} and/or the @acronym{CNI}
2296 code to fail.
2297
2298 SIGSEGV is used on many systems to generate
2299 @code{NullPointerExceptions}.  SIGCHLD is used internally by
2300 @code{Runtime.exec()}.  Several other signals (that vary from platform to
2301 platform) can be used by the memory manager and by
2302 @code{Thread.interrupt()}.
2303
2304 @node Exception Handling
2305 @section Exception Handling
2306
2307 While C++ and Java share a common exception handling framework,
2308 things are not yet perfectly integrated.  The main issue is that the
2309 run-time type information facilities of the two
2310 languages are not integrated.
2311
2312 Still, things work fairly well.  You can throw a Java exception from
2313 C++ using the ordinary @code{throw} construct, and this
2314 exception can be caught by Java code.  Similarly, you can catch an
2315 exception thrown from Java using the C++ @code{catch}
2316 construct.
2317
2318 @noindent Here is an example:
2319
2320 @example
2321 if (i >= count)
2322    throw new java::lang::IndexOutOfBoundsException();
2323 @end example
2324
2325 Normally, G++ will automatically detect when you are writing C++
2326 code that uses Java exceptions, and handle them appropriately.
2327 However, if C++ code only needs to execute destructors when Java
2328 exceptions are thrown through it, GCC will guess incorrectly.  Sample
2329 problematic code:
2330
2331 @example
2332 struct S @{ ~S(); @};
2333
2334 extern void bar();    // @r{Is implemented in Java and may throw exceptions.}
2335
2336 void foo()
2337 @{
2338   S s;
2339   bar();
2340 @}
2341 @end example
2342
2343 The usual effect of an incorrect guess is a link failure, complaining of
2344 a missing routine called @code{__gxx_personality_v0}.
2345
2346 You can inform the compiler that Java exceptions are to be used in a
2347 translation unit, irrespective of what it might think, by writing
2348 @code{#pragma GCC java_exceptions} at the head of the
2349 file.  This @code{#pragma} must appear before any
2350 functions that throw or catch exceptions, or run destructors when
2351 exceptions are thrown through them.
2352
2353 @node Synchronization
2354 @section Synchronization
2355
2356 Each Java object has an implicit monitor.
2357 The Java VM uses the instruction @code{monitorenter} to acquire
2358 and lock a monitor, and @code{monitorexit} to release it.
2359
2360 The corresponding CNI macros are @code{JvMonitorEnter} and 
2361 @code{JvMonitorExit} (JNI has similar  methods @code{MonitorEnter}
2362 and @code{MonitorExit}).  
2363
2364
2365 The Java source language does not provide direct access to these primitives.
2366 Instead, there is a @code{synchronized} statement that does an
2367 implicit @code{monitorenter} before entry to the block,
2368 and does a @code{monitorexit} on exit from the block.
2369 Note that the lock has to be released even when the block is abnormally
2370 terminated by an exception, which means there is an implicit
2371 @code{try finally} surrounding synchronization locks.
2372
2373 From C++, it makes sense to use a destructor to release a lock.
2374 @acronym{CNI} defines the following utility class:
2375
2376 @example
2377 class JvSynchronize() @{
2378   jobject obj;
2379   JvSynchronize(jobject o) @{ obj = o; JvMonitorEnter(o); @}
2380   ~JvSynchronize() @{ JvMonitorExit(obj); @}
2381 @};
2382 @end example
2383
2384 So this Java code:
2385
2386 @example
2387 synchronized (OBJ)
2388 @{
2389    CODE
2390 @}
2391 @end example
2392
2393 @noindent might become this C++ code:
2394
2395 @example
2396 @{
2397    JvSynchronize dummy (OBJ);
2398    CODE;
2399 @}
2400 @end example
2401
2402 Java also has methods with the @code{synchronized} attribute.
2403 This is equivalent to wrapping the entire method body in a
2404 @code{synchronized} statement.
2405 (Alternatively, an implementation could require the caller to do
2406 the synchronization.  This is not practical for a compiler, because
2407 each virtual method call would have to test at run-time if
2408 synchronization is needed.)  Since in @command{gcj}
2409 the @code{synchronized} attribute is handled by the
2410 method implementation, it is up to the programmer
2411 of a synchronized native method to handle the synchronization
2412 (in the C++ implementation of the method).
2413 In other words, you need to manually add @code{JvSynchronize}
2414 in a @code{native synchronized} method.
2415
2416 @node Invocation
2417 @section Invocation
2418
2419 CNI permits C++ applications to make calls into Java classes, in addition to
2420 allowing Java code to call into C++. Several functions, known as the 
2421 @dfn{invocation API}, are provided to support this.
2422
2423 @deftypefun jint JvCreateJavaVM (JvVMInitArgs* @var{vm_args})
2424
2425 Initializes the Java runtime. This function performs essential initialization
2426 of the threads interface, garbage collector, exception handling and other key
2427 aspects of the runtime. It must be called once by an application with
2428 a non-Java @code{main()} function, before any other Java or CNI calls are made.
2429 It is safe, but not recommended, to call @code{JvCreateJavaVM()} more than
2430 once provided it is only called from a single thread.
2431 The @var{vmargs} parameter can be used to specify initialization parameters 
2432 for the Java runtime. It may be @code{NULL}.
2433
2434 JvVMInitArgs represents a list of virtual machine initialization
2435 arguments. @code{JvCreateJavaVM()} ignores the version field.
2436
2437 @example
2438 typedef struct JvVMOption
2439 @{
2440   // a VM initialization option
2441   char* optionString;
2442   // extra information associated with this option
2443   void* extraInfo;
2444 @} JvVMOption;
2445
2446 typedef struct JvVMInitArgs
2447 @{
2448   // for compatibility with JavaVMInitArgs
2449   jint version;
2450
2451   // number of VM initialization options
2452   jint nOptions;
2453
2454   // an array of VM initialization options
2455   JvVMOption* options;
2456
2457   // true if the option parser should ignore unrecognized options
2458   jboolean ignoreUnrecognized;
2459 @} JvVMInitArgs;
2460 @end example
2461
2462 @code{JvCreateJavaVM()} returns @code{0} upon success, or @code{-1} if
2463 the runtime is already initialized.
2464
2465 @emph{Note:} In GCJ 3.1, the @code{vm_args} parameter is ignored. It
2466 is recognized and used as of release 4.0.
2467 @end deftypefun
2468
2469 @deftypefun java::lang::Thread* JvAttachCurrentThread (jstring @var{name}, java::lang::ThreadGroup* @var{group})
2470 Registers an existing thread with the Java runtime.  This must be called once
2471 from each thread, before that thread makes any other Java or CNI calls. It
2472 must be called after @code{JvCreateJavaVM}.
2473 @var{name} specifies a name for the thread. It may be @code{NULL}, in which 
2474 case a name will be generated.
2475 @var{group} is the ThreadGroup in which this thread will be a member. If it
2476 is @code{NULL}, the thread will be a member of the main thread group.
2477 The return value is the Java @code{Thread} object that represents the thread.
2478 It is safe to call @code{JvAttachCurrentThread()} more than once from the same
2479 thread. If the thread is already attached, the call is ignored and the current
2480 thread object is returned.
2481 @end deftypefun
2482
2483 @deftypefun jint JvDetachCurrentThread ()
2484 Unregisters a thread from the Java runtime. This should be called by threads
2485 that were attached using @code{JvAttachCurrentThread()}, after they have 
2486 finished making calls to Java code. This ensures that any resources associated
2487 with the thread become eligible for garbage collection.
2488 This function returns @code{0} upon success, or @code{-1} if the current thread
2489 is not attached.
2490 @end deftypefun
2491
2492 @subsection Handling uncaught exceptions
2493
2494 If an exception is thrown from Java code called using the invocation API, and
2495 no handler for the exception can be found, the runtime will abort the
2496 application. In order to make the application more robust, it is recommended 
2497 that code which uses the invocation API be wrapped by a top-level try/catch 
2498 block that catches all Java exceptions.
2499
2500 @subsection Example
2501
2502 The following code demonstrates the use of the invocation API. In this
2503 example, the C++ application initializes the Java runtime and attaches
2504 itself. The @code{java.lang.System} class is initialized in order to
2505 access its @code{out} field, and a Java string is printed. Finally, the thread
2506 is detached from the runtime once it has finished making Java calls. Everything
2507 is wrapped with a try/catch block to provide a default handler for any uncaught 
2508 exceptions.
2509
2510 The example can be compiled with @command{c++ test.cc -lgcj}.
2511
2512 @example
2513 // test.cc
2514 #include <gcj/cni.h>
2515 #include <java/lang/System.h>
2516 #include <java/io/PrintStream.h>
2517 #include <java/lang/Throwable.h>
2518
2519 int main(int argc, char *argv)
2520 @{
2521   using namespace java::lang;
2522   
2523   try
2524   @{
2525     JvCreateJavaVM(NULL);
2526     JvAttachCurrentThread(NULL, NULL);
2527
2528     String *message = JvNewStringLatin1("Hello from C++");
2529     JvInitClass(&System::class$);
2530     System::out->println(message);
2531
2532     JvDetachCurrentThread();
2533   @}
2534   catch (Throwable *t)
2535   @{
2536     System::err->println(JvNewStringLatin1("Unhandled Java exception:"));
2537     t->printStackTrace();
2538   @}
2539 @}
2540 @end example
2541
2542 @node Reflection
2543 @section Reflection
2544
2545 Reflection is possible with CNI code, it functions similarly to how it
2546 functions with JNI@.
2547
2548 @c clean this up...  I mean, what are the types jfieldID and jmethodID in JNI?
2549 The types @code{jfieldID} and @code{jmethodID}
2550 are as in JNI@.
2551
2552 @noindent The functions:
2553
2554 @itemize
2555 @item @code{JvFromReflectedField},
2556 @item @code{JvFromReflectedMethod},
2557 @item @code{JvToReflectedField}
2558 @item @code{JvToFromReflectedMethod}
2559 @end itemize
2560
2561 @noindent will be added shortly, as will other functions corresponding to JNI@.
2562
2563
2564 @node System properties
2565 @chapter System properties
2566
2567 The runtime behavior of the @code{libgcj} library can be modified by setting
2568 certain system properties.  These properties can be compiled into the program
2569 using the @code{-D@var{name}[=@var{value}]} option to @command{gcj} or by
2570 setting them explicitly in the program by calling the
2571 @code{java.lang.System.setProperty()} method.  Some system properties are only
2572 used for informational purposes (like giving a version number or a user name).
2573 A program can inspect the current value of a property by calling the
2574 @code{java.lang.System.getProperty()} method.
2575
2576 @menu
2577 * Standard Properties::         Standard properties supported by @code{libgcj}
2578 * GNU Classpath Properties::    Properties found in Classpath based libraries
2579 * libgcj Runtime Properties::   Properties specific to @code{libgcj}
2580 @end menu
2581
2582 @node Standard Properties
2583 @section Standard Properties
2584
2585 The following properties are normally found in all implementations of the core
2586 libraries for the Java language.
2587
2588 @table @gcctabopt
2589
2590 @item java.version
2591 The @code{libgcj} version number.
2592
2593 @item java.vendor
2594 Set to @samp{The Free Software Foundation, Inc.}
2595
2596 @item java.vendor.url
2597 Set to @uref{http://gcc.gnu.org/java/}.
2598
2599 @item java.home
2600 The directory where @code{gcj} was installed.  Taken from the @code{--prefix}
2601 option given to @command{configure}.
2602
2603 @item java.class.version
2604 The class format version number supported by the libgcj byte code interpreter.
2605 (Currently @samp{46.0})
2606
2607 @item java.vm.specification.version
2608 The Virtual Machine Specification version implemented by @code{libgcj}.
2609 (Currently @samp{1.0})
2610
2611 @item java.vm.specification.vendor
2612 The name of the Virtual Machine specification designer.
2613
2614 @item java.vm.specification.name
2615 The name of the Virtual Machine specification
2616 (Set to @samp{Java Virtual Machine Specification}).
2617
2618 @item java.vm.version
2619 The @command{gcj} version number.
2620
2621 @item java.vm.vendor
2622 Set to @samp{The Free Software Foundation, Inc.}
2623
2624 @item java.vm.name
2625 Set to @samp{GNU libgcj}.
2626
2627 @item java.specification.version
2628 The Runtime Environment specification version implemented by @code{libgcj}.
2629 (Currently set to @samp{1.3})
2630
2631 @item java.specification.vendor
2632 The Runtime Environment specification designer.
2633
2634 @item java.specification.name
2635 The name of the Runtime Environment specification
2636 (Set to @samp{Java Platform API Specification}).
2637
2638 @item java.class.path
2639 The paths (jar files, zip files and directories) used for finding class files.
2640
2641 @item java.library.path
2642 Directory path used for finding native libraries.
2643
2644 @item java.io.tmpdir
2645 The directory used to put temporary files in.
2646
2647 @item java.compiler
2648 Name of the Just In Time compiler to use by the byte code interpreter.
2649 Currently not used in @code{libgcj}.
2650
2651 @item java.ext.dirs
2652 Directories containing jar files with extra libraries.  Will be used when
2653 resolving classes.
2654
2655 @item java.protocol.handler.pkgs
2656 A @samp{|} separated list of package names that is used to find classes that
2657 implement handlers for @code{java.net.URL}.
2658
2659 @item java.rmi.server.codebase
2660 A list of URLs that is used by the @code{java.rmi.server.RMIClassLoader}
2661 to load classes from.
2662
2663 @item jdbc.drivers
2664 A list of class names that will be loaded by the @code{java.sql.DriverManager}
2665 when it starts up.
2666
2667 @item file.separator
2668 The separator used in when directories are included in a filename
2669 (normally @samp{/} or @samp{\} ).
2670
2671 @item file.encoding
2672 The default character encoding used when converting platform native files to
2673 Unicode (usually set to @samp{8859_1}).
2674
2675 @item path.separator
2676 The standard separator used when a string contains multiple paths
2677 (normally @samp{:} or @samp{;}), the string is usually not a valid character
2678 to use in normal directory names.)
2679
2680 @item line.separator
2681 The default line separator used on the platform (normally @samp{\n}, @samp{\r}
2682 or a combination of those two characters).
2683
2684 @item policy.provider
2685 The class name used for the default policy provider returned by
2686 @code{java.security.Policy.getPolicy}.
2687
2688 @item user.name
2689 The name of the user running the program.  Can be the full name, the login name
2690 or empty if unknown.
2691
2692 @item user.home
2693 The default directory to put user specific files in.
2694
2695 @item user.dir
2696 The current working directory from which the program was started.
2697
2698 @item user.language
2699 The default language as used by the @code{java.util.Locale} class.
2700
2701 @item user.region
2702 The default region as used by the @code{java.util.Local} class.
2703
2704 @item user.variant
2705 The default variant of the language and region local used.
2706
2707 @item user.timezone
2708 The default timezone as used by the @code{java.util.TimeZone} class.
2709
2710 @item os.name
2711 The operating system/kernel name that the program runs on.
2712
2713 @item os.arch
2714 The hardware that we are running on.
2715
2716 @item os.version
2717 The version number of the operating system/kernel.
2718
2719 @item awt.appletWarning
2720 The string to display when an untrusted applet is displayed.
2721 Returned by @code{java.awt.Window.getWarningString()} when the window is
2722 ``insecure''.
2723
2724 @item awt.toolkit
2725 The class name used for initializing the default @code{java.awt.Toolkit}. 
2726 Defaults to @code{gnu.awt.gtk.GtkToolkit}.
2727
2728 @item http.proxyHost
2729 Name of proxy host for http connections.
2730
2731 @item http.proxyPort
2732 Port number to use when a proxy host is in use.
2733
2734 @end table
2735
2736 @node GNU Classpath Properties
2737 @section GNU Classpath Properties
2738
2739 @code{libgcj} is based on the GNU Classpath (Essential Libraries for Java) a
2740 GNU project to create free core class libraries for use with virtual machines
2741 and compilers for the Java language.  The following properties are common to
2742 libraries based on GNU Classpath.
2743
2744 @table @gcctabopt
2745
2746 @item gcj.dumpobject
2747 Enables printing serialization debugging by the @code{java.io.ObjectInput} and
2748 @code{java.io.ObjectOutput} classes when set to something else then the empty
2749 string.  Only used when running a debug build of the library.
2750
2751 @item gnu.classpath.vm.shortname
2752 This is a succinct name of the virtual machine.  For @code{libgcj},
2753 this will always be @samp{libgcj}.
2754
2755 @item gnu.classpath.home.url
2756 A base URL used for finding system property files (e.g.,
2757 @file{classpath.security}).  By default this is a @samp{file:} URL
2758 pointing to the @file{lib} directory under @samp{java.home}.
2759
2760 @end table
2761
2762 @node libgcj Runtime Properties
2763 @section libgcj Runtime Properties
2764
2765 The following properties are specific to the @code{libgcj} runtime and will
2766 normally not be found in other core libraries for the java language.
2767
2768 @table @gcctabopt
2769
2770 @item java.fullversion
2771 The combination of @code{java.vm.name} and @code{java.vm.version}.
2772
2773 @item java.vm.info
2774 Same as @code{java.fullversion}.
2775
2776 @item impl.prefix
2777 Used by the @code{java.net.DatagramSocket} class when set to something else
2778 then the empty string.  When set all newly created @code{DatagramSocket}s will
2779 try to load a class @code{java.net.[impl.prefix]DatagramSocketImpl} instead of
2780 the normal @code{java.net.PlainDatagramSocketImpl}.
2781
2782 @item gnu.gcj.progname
2783 The class or binary name that was used to invoke the program. This will be
2784 the name of the "main" class in the case where the @code{gij} front end is
2785 used, or the program binary name in the case where an application is compiled 
2786 to a native binary.
2787
2788 @item gnu.gcj.runtime.NameFinder.use_addr2line
2789 Whether an external process, @command{addr2line}, should be used to determine
2790 line number information when tracing the stack. Setting this to @code{false} 
2791 may suppress line numbers when printing stack traces and when using
2792 the java.util.logging infrastructure. However, performance may improve
2793 significantly for applications that print stack traces or make logging calls
2794 frequently.
2795
2796 @item gnu.gcj.runtime.NameFinder.show_raw
2797 Whether the address of a stack frame should be printed when the line
2798 number is unavailable. Setting this to @code{true} will cause the name
2799 of the object and the offset within that object to be printed when no
2800 line number is available.  This allows for off-line decoding of
2801 stack traces if necessary debug information is available.  The default
2802 is @code{false}, no raw addresses are printed.
2803
2804 @item gnu.gcj.runtime.NameFinder.remove_unknown
2805 Whether stack frames for non-java code should be included in a stack
2806 trace.  The default value is @code{true}, stack frames for non-java
2807 code are suppressed.  Setting this to @code{false} will cause any
2808 non-java stack frames to be printed in addition to frames for the java
2809 code.
2810
2811 @item gnu.gcj.runtime.VMClassLoader.library_control
2812 This controls how shared libraries are automatically loaded by the
2813 built-in class loader.  If this property is set to @samp{full}, a full
2814 search is done for each requested class.  If this property is set to
2815 @samp{cache}, then any failed lookups are cached and not tried again.
2816 If this property is set to @samp{never} (the default), then lookups
2817 are never done.  For more information, @xref{Extensions}.
2818
2819 @item gnu.gcj.runtime.endorsed.dirs
2820 This is like the standard @code{java.endorsed.dirs}, property, but
2821 specifies some extra directories which are searched after the standard
2822 endorsed directories.  This is primarily useful for telling
2823 @code{libgcj} about additional libraries which are ordinarily
2824 incorporated into the JDK, and which should be loaded by the bootstrap
2825 class loader, but which are not yet part of @code{libgcj} itself for
2826 some reason.
2827
2828 @item gnu.gcj.jit.compiler
2829 @c FIXME we should probably have a whole node on this...
2830 This is the full path to @command{gcj} executable which should be
2831 used to compile classes just-in-time when
2832 @code{ClassLoader.defineClass} is called.  If not set, @command{gcj}
2833 will not be invoked by the runtime; this can also be controlled via
2834 @code{Compiler.disable}.
2835
2836 @item gnu.gcj.jit.options
2837 This is a space-separated string of options which should be passed to
2838 @command{gcj} when in JIT mode.  If not set, a sensible default is
2839 chosen.
2840
2841 @item gnu.gcj.jit.cachedir
2842 This is the directory where cached shared library files are
2843 stored.  If not set, JIT compilation is disabled.  This should never
2844 be set to a directory that is writable by any other user.
2845
2846 @item gnu.gcj.precompiled.db.path
2847 This is a sequence of file names, each referring to a file created by
2848 @command{gcj-dbtool}.  These files will be used by @code{libgcj} to
2849 find shared libraries corresponding to classes that are loaded from
2850 bytecode.  @code{libgcj} often has a built-in default database; it
2851 can be queried using @code{gcj-dbtool -p}.
2852
2853 @end table
2854
2855
2856 @node Resources
2857 @chapter Resources
2858
2859 While writing @command{gcj} and @code{libgcj} we have, of course, relied
2860 heavily on documentation from Sun Microsystems.  In particular we have
2861 used The Java Language Specification (both first and second editions),
2862 the Java Class Libraries (volumes one and two), and the Java Virtual
2863 Machine Specification.  In addition we've used the online documentation
2864 at @uref{http://java.sun.com/}.
2865
2866 The current @command{gcj} home page is
2867 @uref{http://gcc.gnu.org/java/}.
2868
2869 For more information on gcc, see @uref{http://gcc.gnu.org/}.
2870
2871 Some @code{libgcj} testing is done using the Mauve test suite.  This is
2872 a free software Java class library test suite which is being written
2873 because the JCK is not free.  See
2874 @uref{http://sources.redhat.com/mauve/} for more information.
2875
2876
2877 @node Index
2878 @unnumbered Index
2879
2880 @printindex cp
2881
2882 @bye