OSDN Git Service

2002-10-03 Michael Koch <konqueror@gmx.de>
[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 Note: When reading this manual you'll find lots of strange
6 @c circumlocutions like ``compiler for the Java language''.
7 @c This is necessary due to Sun's restrictions on the use of
8 @c the word ``Java'.
9
10 @c When this manual is copyrighted.
11 @set copyrights-gcj 2001, 2002
12
13 @c Versions
14 @set version-gcc 3.3
15 @set which-gcj GCC-@value{version-gcc}
16
17 @macro gcctabopt{body}
18 @code{\body\}
19 @end macro
20
21 @ifinfo
22 @format
23 @dircategory Programming
24 @direntry
25 * Gcj: (gcj).               Ahead-of-time compiler for the Java language
26 @end direntry
27
28 @dircategory Individual utilities
29 @direntry
30 * gcjh: (gcj)Invoking gcjh.
31                             Generate header files from Java class files
32 * jv-scan: (gcj)Invoking jv-scan.
33                             Print information about Java source files
34 * jcf-dump: (gcj)Invoking jcf-dump.
35                             Print information about Java class files
36 * gij: (gcj)Invoking gij.   GNU interpreter for Java bytecode
37 * jv-convert: (gcj)Invoking jv-convert.
38                             Convert file from one encoding to another
39 * rmic: (gcj)Invoking rmic.
40                             Generate stubs for Remote Method Invocation.
41 * rmiregistry: (gcj)Invoking rmiregistry.
42                             The remote object registry.
43 @end direntry
44 @end format
45
46 @c man begin COPYRIGHT
47 Copyright (C) @value{copyrights-gcj} Free Software Foundation, Inc.
48
49 Permission is granted to copy, distribute and/or modify this document
50 under the terms of the GNU Free Documentation License, Version 1.1 or
51 any later version published by the Free Software Foundation; with the
52 Invariant Sections being ``GNU General Public License'', the Front-Cover
53 texts being (a) (see below), and with the Back-Cover Texts being (b)
54 (see below).  A copy of the license is included in the
55 @c man end
56 section entitled
57 ``GNU Free Documentation License''.
58 @ignore
59 @c man begin COPYRIGHT
60 man page gfdl(7).
61 @c man end
62 @end ignore
63
64 (a) The FSF's Front-Cover Text is:
65
66      A GNU Manual
67
68 (b) The FSF's Back-Cover Text is:
69
70      You have freedom to copy and modify this GNU Manual, like GNU
71      software.  Copies published by the Free Software Foundation raise
72      funds for GNU development.
73 @end ifinfo
74
75 @titlepage
76 @title GNU gcj
77 @author Tom Tromey
78
79 @page
80 @vskip 0pt plus 1filll
81 Copyright @copyright{} @value{copyrights-gcj} Free Software Foundation, Inc.
82 @sp 2
83 For the @value{which-gcj} Version*
84 @sp 1
85 Published by the Free Software Foundation @*
86 59 Temple Place - Suite 330@*
87 Boston, MA 02111-1307, USA@*
88 @sp 1
89 Permission is granted to copy, distribute and/or modify this document
90 under the terms of the GNU Free Documentation License, Version 1.1 or
91 any later version published by the Free Software Foundation; with the
92 Invariant Sections being ``GNU General Public License'', the Front-Cover
93 texts being (a) (see below), and with the Back-Cover Texts being (b)
94 (see below).  A copy of the license is included in the section entitled
95 ``GNU Free Documentation License''.
96
97 (a) The FSF's Front-Cover Text is:
98
99      A GNU Manual
100
101 (b) The FSF's Back-Cover Text is:
102
103      You have freedom to copy and modify this GNU Manual, like GNU
104      software.  Copies published by the Free Software Foundation raise
105      funds for GNU development.
106 @end titlepage
107 @contents
108 @page
109
110
111 @node Top
112 @top Introduction
113
114 This manual describes how to use @command{gcj}, the GNU compiler for the
115 Java programming language.  @command{gcj} can generate both @file{.class}
116 files and object files, and it can read both Java source code and
117 @file{.class} files.
118
119 @menu
120 * Copying::              The GNU General Public License
121 * GNU Free Documentation License::
122                         How you can share and copy this manual
123 * Invoking gcj::        Compiler options supported by @command{gcj}
124 * Compatibility::       Compatibility between gcj and other tools for Java
125 * Invoking gcjh::       Generate header files from class files
126 * Invoking jv-scan::    Print information about source files
127 * Invoking jcf-dump::   Print information about class files
128 * Invoking gij::        Interpreting Java bytecodes
129 * Invoking jv-convert:: Converting from one encoding to another
130 * Invoking rmic::        Generate stubs for Remote Method Invocation.
131 * Invoking rmiregistry:: The remote object registry.
132 * About CNI::           Description of the Cygnus Native Interface
133 * System properties::   Modifying runtime behavior of the libgcj library
134 * Resources::           Where to look for more information
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), 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 * Code Generation::             Options controlling the output of gcj
179 * Configure-time Options::      Options you won't use
180 @end menu
181
182 @c man begin OPTIONS gcj
183
184 @node Input and output files
185 @section Input and output files
186
187 A @command{gcj} command is like a @command{gcc} command, in that it
188 consists of a number of options and file names.  The following kinds
189 of input file names are supported:
190
191 @table @gcctabopt
192 @item @var{file}.java
193 Java source files.
194 @item @var{file}.class
195 Java bytecode files.
196 @item @var{file}.zip
197 @itemx @var{file}.jar
198 An archive containing one or more @code{.class} files, all of
199 which are compiled.  The archive may be compressed.
200 @item @@@var{file}
201 A file containing a whitespace-separated list of input file names.
202 (Currently, these must all be @code{.java} source files, but that
203 may change.)
204 Each named file is compiled, just as if it had been on the command line.
205 @item @var{library}.a
206 @itemx @var{library}.so
207 @itemx -l@var{libname}
208 Libraries to use when linking.  See the @command{gcc} manual.
209 @end table
210
211 You can specify more than one input file on the @command{gcj} command line,
212 in which case they will all be compiled.  If you specify a
213 @code{-o @var{FILENAME}}
214 option, all the input files will be compiled together, producing a
215 single output file, named @var{FILENAME}.
216 This is allowed even when using @code{-S} or @code{-c},
217 but not when using @code{-C} or @code{--resource}.
218 (This is an extension beyond the what plain @command{gcc} allows.)
219 (If more than one input file is specified, all must currently
220 be @code{.java} files, though we hope to fix this.)
221
222 @node Input Options
223 @section Input Options
224
225 @cindex class path
226
227 @command{gcj} has options to control where it looks to find files it needs.
228 For instance, @command{gcj} might need to load a class that is referenced
229 by the file it has been asked to compile.  Like other compilers for the
230 Java language, @command{gcj} has a notion of a @dfn{class path}.  There are
231 several options and environment variables which can be used to
232 manipulate the class path.  When @command{gcj} looks for a given class, it
233 searches the class path looking for matching @file{.class} or
234 @file{.java} file.  @command{gcj} comes with a built-in class path which
235 points at the installed @file{libgcj.jar}, a file which contains all the
236 standard classes.
237
238 In the below, a directory or path component can refer either to an
239 actual directory on the filesystem, or to a @file{.zip} or @file{.jar}
240 file, which @command{gcj} will search as if it is a directory.
241
242 @table @gcctabopt
243 @item -I@var{dir}
244 All directories specified by @code{-I} are kept in order and prepended
245 to the class path constructed from all the other options.  Unless
246 compatibility with tools like @code{javac} is important, we recommend
247 always using @code{-I} instead of the other options for manipulating the
248 class path.
249
250 @item --classpath=@var{path}
251 This sets the class path to @var{path}, a colon-separated list of paths
252 (on Windows-based systems, a semicolon-separate list of paths).
253 This does not override the builtin (``boot'') search path.
254
255 @item --CLASSPATH=@var{path}
256 Deprecated synonym for @code{--classpath}.
257
258 @item --bootclasspath=@var{path}
259 Where to find the standard builtin classes, such as @code{java.lang.String}.
260
261 @item --extdirs=@var{path}
262 For each directory in the @var{path}, place the contents of that
263 directory at the end of the class path.
264
265 @item CLASSPATH
266 This is an environment variable which holds a list of paths.
267 @end table
268
269 The final class path is constructed like so:
270
271 @itemize @bullet
272 @item
273 First come all directories specified via @code{-I}.
274
275 @item
276 If @option{--classpath} is specified, its value is appended.
277 Otherwise, if the @code{CLASSPATH} environment variable is specified,
278 then its value is appended.
279 Otherwise, the current directory (@code{"."}) is appended.
280
281 @item
282 If @code{--bootclasspath} was specified, append its value.
283 Otherwise, append the built-in system directory, @file{libgcj.jar}.
284
285 @item
286 Finally, if @code{--extdirs} was specified, append the contents of the
287 specified directories at the end of the class path.  Otherwise, append
288 the contents of the built-in extdirs at @code{$(prefix)/share/java/ext}.
289 @end itemize
290
291 The classfile built by @command{gcj} for the class @code{java.lang.Object}
292 (and placed in @code{libgcj.jar}) contains a special zero length
293 attribute @code{gnu.gcj.gcj-compiled}. The compiler looks for this
294 attribute when loading @code{java.lang.Object} and will report an error
295 if it isn't found, unless it compiles to bytecode (the option
296 @code{-fforce-classes-archive-check} can be used to override this
297 behavior in this particular case.)
298
299 @table @gcctabopt
300 @item -fforce-classes-archive-check
301 This forces the compiler to always check for the special zero length
302 attribute @code{gnu.gcj.gcj-compiled} in @code{java.lang.Object} and
303 issue an error if it isn't found.
304 @end table
305
306 @node Encodings
307 @section Encodings
308
309 The Java programming language uses Unicode throughout.  In an effort to
310 integrate well with other locales, @command{gcj} allows @file{.java} files
311 to be written using almost any encoding.  @command{gcj} knows how to
312 convert these encodings into its internal encoding at compile time.
313
314 You can use the @code{--encoding=@var{NAME}} option to specify an
315 encoding (of a particular character set) to use for source files.  If
316 this is not specified, the default encoding comes from your current
317 locale.  If your host system has insufficient locale support, then
318 @command{gcj} assumes the default encoding to be the @samp{UTF-8} encoding
319 of Unicode.
320
321 To implement @code{--encoding}, @command{gcj} simply uses the host
322 platform's @code{iconv} conversion routine.  This means that in practice
323 @command{gcj} is limited by the capabilities of the host platform.
324
325 The names allowed for the argument @code{--encoding} vary from platform
326 to platform (since they are not standardized anywhere).  However,
327 @command{gcj} implements the encoding named @samp{UTF-8} internally, so if
328 you choose to use this for your source files you can be assured that it
329 will work on every host.
330
331
332 @node Warnings
333 @section Warnings
334
335 @command{gcj} implements several warnings.  As with other generic
336 @command{gcc} warnings, if an option of the form @code{-Wfoo} enables a
337 warning, then @code{-Wno-foo} will disable it.  Here we've chosen to
338 document the form of the warning which will have an effect -- the
339 default being the opposite of what is listed.
340
341 @table @gcctabopt
342 @item -Wredundant-modifiers
343 With this flag, @command{gcj} will warn about redundant modifiers.  For
344 instance, it will warn if an interface method is declared @code{public}.
345
346 @item -Wextraneous-semicolon
347 This causes @command{gcj} to warn about empty statements.  Empty statements
348 have been deprecated.
349
350 @item -Wno-out-of-date
351 This option will cause @command{gcj} not to warn when a source file is
352 newer than its matching class file.  By default @command{gcj} will warn
353 about this.
354
355 @item -Wunused
356 This is the same as @command{gcc}'s @code{-Wunused}.
357
358 @item -Wall
359 This is the same as @code{-Wredundant-modifiers -Wextraneous-semicolon
360 -Wunused}.
361 @end table
362
363
364 @node Code Generation
365 @section Code Generation
366
367 In addition to the many @command{gcc} options controlling code generation,
368 @command{gcj} has several options specific to itself.
369
370 @table @gcctabopt
371 @item --main=@var{CLASSNAME}
372 This option is used when linking to specify the name of the class whose
373 @code{main} method should be invoked when the resulting executable is
374 run.  @footnote{The linker by default looks for a global function named
375 @code{main}.  Since Java does not have global functions, and a
376 collection of Java classes may have more than one class with a
377 @code{main} method, you need to let the linker know which of those
378 @code{main} methods it should invoke when starting the application.}
379
380 @item -D@var{name}[=@var{value}]
381 This option can only be used with @code{--main}.  It defines a system
382 property named @var{name} with value @var{value}.  If @var{value} is not
383 specified then it defaults to the empty string.  These system properties
384 are initialized at the program's startup and can be retrieved at runtime
385 using the @code{java.lang.System.getProperty} method.
386
387 @item -C
388 This option is used to tell @command{gcj} to generate bytecode
389 (@file{.class} files) rather than object code.
390
391 @item --resource @var{resource-name}
392 This option is used to tell @command{gcj} to compile the contents of a
393 given file to object code so it may be accessed at runtime with the core
394 protocol handler as @samp{core:/@var{resource-name}}.  Note that
395 @var{resource-name} is the name of the resource as found at runtime; for
396 instance, it could be used in a call to @code{ResourceBundle.getBundle}.
397 The actual file name to be compiled this way must be specified
398 separately.
399
400 @item -d @var{directory}
401 When used with @code{-C}, this causes all generated @file{.class} files
402 to be put in the appropriate subdirectory of @var{directory}.  By
403 default they will be put in subdirectories of the current working
404 directory.
405
406 @item -fno-bounds-check
407 By default, @command{gcj} generates code which checks the bounds of all
408 array indexing operations.  With this option, these checks are omitted, which
409 can improve performance for code that uses arrays extensively.  Note that this 
410 can result in unpredictable behavior if the code in question actually does 
411 violate array bounds constraints.  It is safe to use this option if you are 
412 sure that your code will never throw an @code{ArrayIndexOutOfBoundsException}.
413
414 @item -fno-store-check
415 Don't generate array store checks.  When storing objects into arrays, a runtime
416 check is normally generated in order to ensure that the object is assignment
417 compatible with the component type of the array (which may not be known
418 at compile-time).  With this option, these checks are omitted.  This can 
419 improve performance for code which stores objects into arrays frequently.
420 It is safe to use this option if you are sure your code will never throw an 
421 @code{ArrayStoreException}.
422
423 @item -fjni
424 With @command{gcj} there are two options for writing native methods: CNI
425 and JNI@.  By default @command{gcj} assumes you are using CNI@.  If you are
426 compiling a class with native methods, and these methods are implemented
427 using JNI, then you must use @code{-fjni}.  This option causes
428 @command{gcj} to generate stubs which will invoke the underlying JNI
429 methods.
430
431 @item -fno-assert
432 Don't recognize the @code{assert} keyword.  This is for compatibility
433 with older versions of the language specification.
434
435 @item -fno-optimize-static-class-initialization
436 When the optimization level is greater or equal to @code{-O2},
437 @command{gcj} will try to optimize the way calls into the runtime are made
438 to initialize static classes upon their first use (this optimization
439 isn't carried out if @code{-C} was specified.) When compiling to native
440 code, @code{-fno-optimize-static-class-initialization} will turn this
441 optimization off, regardless of the optimization level in use.
442 @end table
443
444
445 @node Configure-time Options
446 @section Configure-time Options
447
448 Some @command{gcj} code generations options affect the resulting ABI, and
449 so can only be meaningfully given when @code{libgcj}, the runtime
450 package, is configured.  @code{libgcj} puts the appropriate options from
451 this group into a @samp{spec} file which is read by @command{gcj}.  These
452 options are listed here for completeness; if you are using @code{libgcj}
453 then you won't want to touch these options.
454
455 @table @gcctabopt
456 @item -fuse-boehm-gc
457 This enables the use of the Boehm GC bitmap marking code.  In particular
458 this causes @command{gcj} to put an object marking descriptor into each
459 vtable.
460
461 @item -fhash-synchronization
462 By default, synchronization data (the data used for @code{synchronize},
463 @code{wait}, and @code{notify}) is pointed to by a word in each object.
464 With this option @command{gcj} assumes that this information is stored in a
465 hash table and not in the object itself.
466
467 @item -fuse-divide-subroutine
468 On some systems, a library routine is called to perform integer
469 division.  This is required to get exception handling correct when
470 dividing by zero.
471
472 @item -fcheck-references
473 On some systems it's necessary to insert inline checks whenever
474 accessing an object via a reference.  On other systems you won't need
475 this because null pointer accesses are caught automatically by the
476 processor.
477 @end table
478
479 @c man end
480
481 @node Compatibility
482 @chapter Compatibility with the Java Platform
483
484 As we believe it is important that the Java platform not be fragmented,
485 @command{gcj} and @code{libgcj} try to conform to the relevant Java
486 specifications.  However, limited manpower and incomplete and unclear
487 documentation work against us.  So, there are caveats to using
488 @command{gcj}.
489
490 This list of compatibility issues is by no means complete.
491
492 @itemize @bullet
493 @item
494 @command{gcj} implements the JDK 1.1 language.  It supports inner classes,
495 though these are known to still be buggy.  It does not yet support the
496 Java 2 @code{strictfp} keyword (it recognizes the keyword but ignores
497 it).
498
499 @item
500 @code{libgcj} is largely compatible with the JDK 1.2 libraries.
501 However, @code{libgcj} is missing many packages, most notably
502 @code{java.awt}.  There are also individual missing classes and methods.
503 We currently do not have a list showing differences between
504 @code{libgcj} and the Java 2 platform.
505
506 @item
507 Sometimes the @code{libgcj} implementation of a method or class differs
508 from the JDK implementation.  This is not always a bug.  Still, if it
509 affects you, it probably makes sense to report it so that we can discuss
510 the appropriate response.
511 @end itemize
512
513
514 @node Invoking gcjh
515 @chapter Invoking gcjh
516
517 @c man title gcjh generate header files from Java class files
518
519 @c man begin DESCRIPTION gcjh
520
521 The @code{gcjh} program is used to generate header files from class
522 files.  It can generate both CNI and JNI header files, as well as stub
523 implementation files which can be used as a basis for implementing the
524 required native methods.
525
526 @c man end
527
528 @ignore
529 @c man begin SYNOPSIS gcjh
530 gcjh [@option{-stubs}] [@option{-jni}]
531     [@option{-add} @var{text}] [@option{-append} @var{text}] [@option{-friend} @var{text}]
532     [@option{-preprend} @var{text}]
533     [@option{--classpath}=@var{path}] [@option{--CLASSPATH}=@var{path}]
534     [@option{-I}@var{dir}@dots{}] [@option{-d} @var{dir}@dots{}]
535     [@option{-o} @var{file}] [@option{-td} @var{dir}]
536     [@option{-M}] [@option{-MM}] [@option{-MD}] [@option{-MMD}]
537     [@option{--version}] [@option{--help}] [@option{-v}] [@option{--verbose}]
538     @var{classname}@dots{}
539 @c man end
540 @c man begin SEEALSO gcjh
541 gcc(1), gcj(1), gij(1), jv-scan(1), jcf-dump(1), gfdl(7),
542 and the Info entries for @file{gcj} and @file{gcc}.
543 @c man end
544 @end ignore
545
546 @c man begin OPTIONS gcjh
547
548 @table @gcctabopt
549 @item -stubs
550 This causes @code{gcjh} to generate stub files instead of header files.
551 By default the stub file will be named after the class, with a suffix of
552 @samp{.cc}.  In JNI mode, the default output file will have the suffix
553 @samp{.c}.
554
555 @item -jni
556 This tells @code{gcjh} to generate a JNI header or stub.  By default,
557 CNI headers are generated.
558
559 @item -add @var{text}
560 Inserts @var{text} into the class body.  This is ignored in JNI mode.
561
562 @item -append @var{text}
563 Inserts @var{text} into the header file after the class declaration.
564 This is ignored in JNI mode.
565
566 @item -friend @var{text}
567 Inserts @var{text} into the class as a @code{friend} declaration.
568 This is ignored in JNI mode.
569
570 @item -prepend @var{text}
571 Inserts @var{text} into the header file before the class declaration.
572 This is ignored in JNI mode.
573
574 @item --classpath=@var{path}
575 @itemx --CLASSPATH=@var{path}
576 @itemx -I@var{directory}
577 @itemx -d @var{directory}
578 @itemx -o @var{file}
579 These options are all identical to the corresponding @command{gcj} options.
580
581 @item -o @var{file}
582 Sets the output file name.  This cannot be used if there is more than
583 one class on the command line.
584
585 @item -td @var{directory}
586 Sets the name of the directory to use for temporary files.
587
588 @item -M
589 Print all dependencies to stdout; suppress ordinary output.
590
591 @item -MM
592 Print non-system dependencies to stdout; suppress ordinary output.
593
594 @item -MD
595 Print all dependencies to stdout.
596
597 @item -MMD
598 Print non-system dependencies to stdout.
599
600 @item --help
601 Print help about @code{gcjh} and exit.  No further processing is done.
602
603 @item --version
604 Print version information for @code{gcjh} and exit.  No further
605 processing is done.
606
607 @item -v, --verbose
608 Print extra information while running.
609 @end table
610
611 All remaining options are considered to be names of classes.
612
613 @c man end
614
615 @node Invoking jv-scan
616 @chapter Invoking jv-scan
617
618 @c man title jv-scan print information about Java source file
619
620 @c man begin DESCRIPTION jv-scan
621
622 The @code{jv-scan} program can be used to print information about a Java
623 source file (@file{.java} file).
624
625 @c man end
626
627 @ignore
628 @c man begin SYNOPSIS jv-scan
629 jv-scan [@option{--no-assert}] [@option{--complexity}] 
630     [@option{--encoding}=@var{name}] [@option{--print-main}] 
631     [@option{--list-class}] [@option{--list-filename}]
632     [@option{--version}] [@option{--help}]
633     [@option{-o} @var{file}] @var{inputfile}@dots{}
634 @c man end
635 @c man begin SEEALSO jv-scan
636 gcc(1), gcj(1), gcjh(1), gij(1), jcf-dump(1), gfdl(7),
637 and the Info entries for @file{gcj} and @file{gcc}.
638 @c man end
639 @end ignore
640
641 @c man begin OPTIONS jv-scan
642
643 @table @gcctabopt
644 @item --no-assert
645 Don't recognize the @code{assert} keyword, for backwards compatibility
646 with older versions of the language specification.
647
648 @item --complexity
649 This prints a complexity measure, related to cyclomatic complexity, for
650 each input file.
651
652 @item --encoding=@var{name}
653 This works like the corresponding @command{gcj} option.
654
655 @item --print-main
656 This prints the name of the class in this file containing a @code{main}
657 method.
658
659 @item --list-class
660 This lists the names of all classes defined in the input files.
661
662 @item --list-filename
663 If @code{--list-class} is given, this option causes @code{jv-scan} to
664 also print the name of the file in which each class was found.
665
666 @item -o @var{file}
667 Print output to the named file.
668
669 @item --help
670 Print help, then exit.
671
672 @item --version
673 Print version number, then exit.
674 @end table
675
676 @c man end
677
678 @node Invoking jcf-dump
679 @chapter Invoking jcf-dump
680
681 @c man title jcf-dump print information about Java class files
682
683 @ignore
684 @c man begin SYNOPSIS jcf-dump
685 jcf-dump [@option{-c}] [@option{--javap}]
686     [@option{--classpath}=@var{path}] [@option{--CLASSPATH}=@var{path}]
687     [@option{-I}@var{dir}@dots{}] [@option{-o} @var{file}]
688     [@option{--version}] [@option{--help}] [@option{-v}] [@option{--verbose}]
689     @var{classname}@dots{}
690 @c man end
691 @c man begin SEEALSO jcf-dump
692 gcc(1), gcj(1), gcjh(1), gij(1), jcf-dump(1), gfdl(7),
693 and the Info entries for @file{gcj} and @file{gcc}.
694 @c man end
695 @end ignore
696
697 @c man begin DESCRIPTION jcf-dump
698
699 This is a class file examiner, similar to @code{javap}.  It will print
700 information about a number of classes, which are specified by class name
701 or file name.
702
703 @c man end
704
705 @c man begin OPTIONS jcf-dump
706
707 @table @gcctabopt
708 @item -c
709 Disassemble method bodies.  By default method bodies are not printed.
710
711 @item --javap
712 Generate output in @code{javap} format.  The implementation of this
713 feature is very incomplete.
714
715 @item --classpath=@var{path}
716 @itemx --CLASSPATH=@var{path}
717 @itemx -I@var{directory}
718 @itemx -o @var{file}
719 These options as the same as the corresponding @command{gcj} options.
720
721 @item --help
722 Print help, then exit.
723
724 @item --version
725 Print version number, then exit.
726
727 @item -v, --verbose
728 Print extra information while running.
729 @end table
730
731 @c man end
732
733 @node Invoking gij
734 @chapter Invoking gij
735
736 @c man title gij GNU interpreter for Java bytecode
737
738 @ignore
739 @c man begin SYNOPSIS gij
740 gij [@option{OPTION}] @dots{} @var{JARFILE} [@var{ARGS}@dots{}]
741
742 gij [@option{-jar}] [@option{OPTION}] @dots{} @var{CLASS} [@var{ARGS}@dots{}]
743   [@option{-cp} @var{path}] [@option{-classpath} @var{path}]
744   [@option{-D}@var{name}[=@var{value}]@dots{}]
745   [@option{-ms=}@var{number}] [@option{-mx=}@var{number}]
746   [@option{--version}] [@option{--help}]
747 @c man end
748 @c man begin SEEALSO gij
749 gcc(1), gcj(1), gcjh(1), jv-scan(1), jcf-dump(1), gfdl(7),
750 and the Info entries for @file{gcj} and @file{gcc}.
751 @c man end
752 @end ignore
753
754 @c man begin DESCRIPTION gij
755
756 @code{gij} is a Java bytecode interpreter included with @code{libgcj}.
757 @code{gij} is not available on every platform; porting it requires a
758 small amount of assembly programming which has not been done for all the
759 targets supported by @command{gcj}.
760
761 The primary argument to @code{gij} is the name of a class or, with
762 @code{-jar}, a jar file.  Options before this argument are interpreted
763 by @code{gij}; remaining options are passed to the interpreted program.
764
765 If a class name is specified and this class does not have a @code{main}
766 method with the appropriate signature (a @code{static void} method with
767 a @code{String[]} as its sole argument), then @code{gij} will print an
768 error and exit.
769
770 If a jar file is specified then @code{gij} will use information in it to
771 determine which class' @code{main} method will be invoked.
772
773 @code{gij} will invoke the @code{main} method with all the remaining
774 command-line options.
775
776 Note that @code{gij} is not limited to interpreting code.  Because
777 @code{libgcj} includes a class loader which can dynamically load shared
778 objects, it is possible to give @code{gij} the name of a class which has
779 been compiled and put into a shared library on the class path.
780
781 @c man end
782
783 @c man begin OPTIONS gij
784
785 @table @gcctabopt
786 @item -cp @var{path}
787 @itemx -classpath @var{path}
788 Set the initial class path.  The class path is used for finding
789 class and resource files.  If specified, this option overrides the
790 @code{CLASSPATH} environment variable.  Note that this option is
791 ignored if @code{-jar} is used.
792
793 @item -D@var{name}[=@var{value}]
794 This defines a system property named @var{name} with value @var{value}.
795 If @var{value} is not specified then it defaults to the empty string.
796 These system properties are initialized at the program's startup and can
797 be retrieved at runtime using the @code{java.lang.System.getProperty}
798 method.
799
800 @item -ms=@var{number}
801 This sets the initial heap size.
802
803 @item -mx=@var{number}
804 This sets the maximum heap size.
805
806 @item -jar
807 This indicates that the name passed to @code{gij} should be interpreted
808 as the name of a jar file, not a class.
809
810 @item --help
811 Print help, then exit.
812
813 @item --version
814 Print version number, then exit.
815 @end table
816
817 @c man end
818
819 @node Invoking jv-convert
820 @chapter Invoking jv-convert
821
822 @c man title jv-convert Convert file from one encoding to another
823
824 @c man begin SYNOPSIS jv-convert
825 @command{jv-convert} [@option{OPTION}] @dots{} [@var{INPUTFILE} [@var{OUTPUTFILE}]]
826 @ignore
827
828   [@option{--encoding} @var{name}]
829   [@option{--from} @var{name}]
830   [@option{--to} @var{name}]
831   [@option{-i} @var{file}] [@option{-o} @var{file}]
832   [@option{--reverse}] [@option{--help}] [@option{--version}]
833 @end ignore
834 @c man end
835
836 @c man begin DESCRIPTION jv-convert
837
838 @command{jv-convert} is a utility included with @code{libgcj} which
839 converts a file from one encoding to another.  It is similar to the Unix
840 @command{iconv} utility.
841
842 The encodings supported by @command{jv-convert} are platform-dependent.
843 Currently there is no way to get a list of all supported encodings.
844
845 @c man end
846
847 @c man begin OPTIONS jv-convert
848
849 @table @gcctabopt
850 @item --encoding @var{name}
851 @itemx --from @var{name}
852 Use @var{name} as the input encoding.  The default is the current
853 locale's encoding.
854
855 @item --to @var{name}
856 Use @var{name} as the output encoding.  The default is the
857 @code{JavaSrc} encoding; this is ASCII with @samp{\u} escapes for
858 non-ASCII characters.
859
860 @item -i @var{file}
861 Read from @var{file}.  The default is to read from standard input.
862
863 @item -o @var{file}
864 Write to @var{file}.  The default is to write to standard output.
865
866 @item --reverse
867 Swap the input and output encodings.
868
869 @item --help
870 Print a help message, then exit.
871
872 @item --version
873 Print version information, then exit.
874 @end table
875
876 @c man end
877
878 @node Invoking rmic
879 @chapter Invoking rmic
880
881 @c man title rmic Generate stubs for Remote Method Invocation
882
883 @c man begin SYNOPSIS rmic
884 @command{rmic} [@option{OPTION}] @dots{} @var{class} @dots{}
885 @ignore
886   [@option{-keep}]
887   [@option{-keepgenerated}]
888   [@option{-v1.1}]
889   [@option{-vcompat}]
890   [@option{-v1.2}]
891   [@option{-nocompile}]
892   [@option{-verbose}]
893   [@option{-d} @var{directory}]
894   [@option{-help}]
895   [@option{-version}]
896 @end ignore
897 @c man end
898
899 @c man begin DESCRIPTION rmic
900
901 @command{rmic} is a utility included with @code{libgcj} which generates
902 stubs for remote objects.
903
904 @c FIXME: Add real information here.
905 @c This really isn't much more than the --help output.
906
907 Note that this program isn't yet fully compatible with the JDK
908 @command{rmic}.  Some options, such as @option{-classpath}, are
909 recognized but currently ignored.  We have left these options
910 undocumented for now.
911
912 Long options can also be given with a GNU-style leading @samp{--}.  For
913 instance, @option{--help} is accepted.
914
915 @c man end
916
917 @c man begin OPTIONS rmic
918
919 @table @gcctabopt
920 @item -keep
921 @itemx -keepgenerated
922 By default, @command{rmic} deletes intermediate files.  Either of these
923 options causes it not to delete such files.
924
925 @item -v1.1
926 Cause @command{rmic} to create stubs and skeletons for the 1.1
927 protocol version.
928
929 @item -vcompat
930 Cause @command{rmic} to create stubs and skeletons compatible with both
931 the 1.1 and 1.2 protocol versions.  This is the default.
932
933 @item -v1.2
934 Cause @command{rmic} to create stubs and skeletons for the 1.2
935 protocol version.
936
937 @item -nocompile
938 Don't compile the generated files.
939
940 @item -verbose
941 Print information about what @command{rmic} is doing.
942
943 @item -d @var{directory}
944 Put output files in @var{directory}.  By default the files are put in
945 the current working directory.
946
947 @item -help
948 Print a help message, then exit.
949
950 @item -version
951 Print version information, then exit.
952 @end table
953
954 @c man end
955
956
957 @node Invoking rmiregistry
958 @chapter Invoking rmiregistry
959
960 @c man title rmiregistry Remote object registry
961
962 @c man begin SYNOPSIS rmiregistry
963 @command{rmic} [@option{OPTION}] @dots{} [@var{port}]
964 @ignore
965   [@option{--help}]
966   [@option{--version}]
967 @end ignore
968 @c man end
969
970 @c man begin DESCRIPTION rmiregistry
971
972 @command{rmiregistry} starts a remote object registry on the current
973 host.  If no port number is specified, then port 1099 is used.
974
975 @c FIXME: Add real information here.
976 @c This really isn't much more than the --help output.
977
978 @c man end
979
980 @c man begin OPTIONS rmiregistry
981
982 @table @gcctabopt
983 @item --help
984 Print a help message, then exit.
985
986 @item --version
987 Print version information, then exit.
988 @end table
989
990 @c man end
991
992
993 @node About CNI
994 @chapter About CNI
995
996 This documents CNI, the Cygnus Native Interface,
997 which is is a convenient way to write Java native methods using C++.
998 This is a more efficient, more convenient, but less portable
999 alternative to the standard JNI (Java Native Interface).
1000
1001 @menu
1002 * Basic concepts::              Introduction to using CNI@.
1003 * Packages::                    How packages are mapped to C++.
1004 * Primitive types::             Handling Java types in C++.
1005 * Interfaces::                  How Java interfaces map to C++.
1006 * Objects and Classes::         C++ and Java classes.
1007 * Class Initialization::        How objects are initialized.
1008 * Object allocation::           How to create Java objects in C++.
1009 * Arrays::                      Dealing with Java arrays in C++.
1010 * Methods::                     Java methods in C++.
1011 * Strings::                     Information about Java Strings.
1012 * Mixing with C++::             How CNI can interoperate with C++.
1013 * Exception Handling::          How exceptions are handled.
1014 * Synchronization::             Synchronizing between Java and C++.
1015 * Invocation::                  Starting the Java runtime from C++.
1016 * Reflection::                  Using reflection from C++.
1017 @end menu
1018
1019
1020 @node Basic concepts
1021 @section Basic concepts
1022
1023 In terms of languages features, Java is mostly a subset
1024 of C++.  Java has a few important extensions, plus a powerful standard
1025 class library, but on the whole that does not change the basic similarity.
1026 Java is a hybrid object-oriented language, with a few native types,
1027 in addition to class types.  It is class-based, where a class may have
1028 static as well as per-object fields, and static as well as instance methods.
1029 Non-static methods may be virtual, and may be overloaded.  Overloading is
1030 resolved at compile time by matching the actual argument types against
1031 the parameter types.  Virtual methods are implemented using indirect calls
1032 through a dispatch table (virtual function table).  Objects are
1033 allocated on the heap, and initialized using a constructor method.
1034 Classes are organized in a package hierarchy.
1035
1036 All of the listed attributes are also true of C++, though C++ has
1037 extra features (for example in C++ objects may be allocated not just
1038 on the heap, but also statically or in a local stack frame).  Because
1039 @command{gcj} uses the same compiler technology as G++ (the GNU
1040 C++ compiler), it is possible to make the intersection of the two
1041 languages use the same ABI (object representation and calling
1042 conventions).  The key idea in CNI is that Java objects are C++
1043 objects, and all Java classes are C++ classes (but not the other way
1044 around).  So the most important task in integrating Java and C++ is to
1045 remove gratuitous incompatibilities.
1046
1047 You write CNI code as a regular C++ source file.  (You do have to use
1048 a Java/CNI-aware C++ compiler, specifically a recent version of G++.)
1049
1050 @noindent A CNI C++ source file must have:
1051
1052 @example
1053 #include <gcj/cni.h>
1054 @end example
1055
1056 @noindent and then must include one header file for each Java class it uses, e.g.:
1057
1058 @example
1059 #include <java/lang/Character.h>
1060 #include <java/util/Date.h>
1061 #include <java/lang/IndexOutOfBoundsException.h>
1062 @end example
1063
1064 @noindent These header files are automatically generated by @code{gcjh}.
1065
1066
1067 CNI provides some functions and macros to make using Java objects and
1068 primitive types from C++ easier.  In general, these CNI functions and
1069 macros start with the @code{Jv} prefix, for example the function
1070 @code{JvNewObjectArray}.  This convention is used to avoid conflicts
1071 with other libraries.  Internal functions in CNI start with the prefix
1072 @code{_Jv_}.  You should not call these; if you find a need to, let us
1073 know and we will try to come up with an alternate solution.  (This
1074 manual lists @code{_Jv_AllocBytes} as an example; CNI should instead
1075 provide a @code{JvAllocBytes} function.)
1076
1077
1078 @subsection Limitations
1079
1080 Whilst a Java class is just a C++ class that doesn't mean that you are
1081 freed from the shackles of Java, a @acronym{CNI} C++ class must adhere to the
1082 rules of the Java programming language.
1083
1084 For example: it is not possible to declare a method in a CNI class
1085 that will take a C string (@code{char*}) as an argument, or to declare a
1086 member variable of some non-Java datatype.
1087
1088
1089 @node Packages
1090 @section Packages
1091
1092 The only global names in Java are class names, and packages.  A
1093 @dfn{package} can contain zero or more classes, and also zero or more
1094 sub-packages.  Every class belongs to either an unnamed package or a
1095 package that has a hierarchical and globally unique name.
1096
1097 A Java package is mapped to a C++ @dfn{namespace}.  The Java class
1098 @code{java.lang.String} is in the package @code{java.lang}, which is a
1099 sub-package of @code{java}.  The C++ equivalent is the class
1100 @code{java::lang::String}, which is in the namespace @code{java::lang}
1101 which is in the namespace @code{java}.
1102
1103 @noindent Here is how you could express this:
1104
1105 @example
1106 (// @r{Declare the class(es), possibly in a header file:}
1107 namespace java @{
1108   namespace lang @{
1109     class Object;
1110     class String;
1111     ...
1112   @}
1113 @}
1114
1115 class java::lang::String : public java::lang::Object
1116 @{
1117   ...
1118 @};
1119 @end example
1120
1121 @noindent The @code{gcjh} tool automatically generates the necessary namespace
1122 declarations.
1123
1124
1125 @subsection Leaving out package names
1126
1127 Always using the fully-qualified name of a java class can be
1128 tiresomely verbose.  Using the full qualified name also ties the code
1129 to a single package making code changes necessary should the class
1130 move from one package to another.  The Java @code{package} declaration
1131 specifies that the following class declarations are in the named
1132 package, without having to explicitly name the full package
1133 qualifiers.  The @code{package} declaration can be
1134 followed by zero or more @code{import} declarations, which
1135 allows either a single class or all the classes in a package to be
1136 named by a simple identifier.  C++ provides something similar with the
1137 @code{using} declaration and directive.
1138
1139 @noindent In Java:
1140
1141 @example
1142 import @var{package-name}.@var{class-name};
1143 @end example
1144
1145 @noindent allows the program text to refer to @var{class-name} as a shorthand for 
1146 the fully qualified name: @code{@var{package-name}.@var{class-name}}.
1147
1148
1149 @noindent To achieve the same effect C++, you have to do this:
1150
1151 @example
1152 using @var{package-name}::@var{class-name};
1153 @end example
1154
1155
1156 @noindent Java can also cause imports on demand, like this:
1157
1158 @example
1159 import @var{package-name}.*;
1160 @end example
1161
1162 @noindent Doing this allows any class from the package @var{package-name} to be
1163 referred to only by its class-name within the program text.
1164
1165
1166 @noindent The same effect can be achieved in C++ like this:
1167
1168 @example
1169 using namespace @var{package-name};
1170 @end example
1171
1172
1173 @node Primitive types
1174 @section Primitive types
1175
1176 Java provides 8 @dfn{primitives} types which represent integers, floats, 
1177 characters and booleans (and also the void type).  C++ has its own
1178 very similar concrete types.  Such types in C++ however are not always
1179 implemented in the same way (an int might be 16, 32 or 64 bits for example) 
1180 so CNI provides a special C++ type for each primitive Java type:
1181
1182 @multitable @columnfractions .20 .25 .60
1183 @item @strong{Java type}   @tab @strong{C/C++ typename} @tab @strong{Description}
1184 @item @code{char}        @tab @code{jchar}          @tab 16 bit Unicode character
1185 @item @code{boolean}     @tab @code{jboolean}       @tab logical (true or false) values
1186 @item @code{byte}        @tab @code{jbyte}          @tab 8-bit signed integer
1187 @item @code{short}       @tab @code{jshort}         @tab 16 bit signed integer
1188 @item @code{int}         @tab @code{jint}           @tab 32 bit signed integer
1189 @item @code{long}        @tab @code{jlong}          @tab 64 bit signed integer
1190 @item @code{float}       @tab @code{jfloat}         @tab 32 bit IEEE floating point number
1191 @item @code{double}      @tab @code{jdouble}        @tab 64 bit IEEE floating point number
1192 @item @code{void}        @tab @code{void}           @tab no value
1193 @end multitable
1194
1195 When referring to a Java type You should always use these C++ typenames (e.g.: @code{jint})
1196 to avoid disappointment.
1197
1198
1199 @subsection Reference types associated with primitive types
1200
1201 In Java each primitive type has an associated reference type, 
1202 e.g.: @code{boolean} has an associated @code{java.lang.Boolean} class.
1203 In order to make working with such classes easier GCJ provides the macro
1204 @code{JvPrimClass}:
1205
1206 @deffn macro JvPrimClass type
1207 Return a pointer to the @code{Class} object corresponding to the type supplied.
1208
1209 @example
1210 JvPrimClass(void) @result{} java.lang.Void.TYPE
1211 @end example
1212
1213 @end deffn
1214
1215
1216 @node Interfaces
1217 @section Interfaces
1218
1219 A Java class can @dfn{implement} zero or more
1220 @dfn{interfaces}, in addition to inheriting from
1221 a single base class. 
1222
1223 @acronym{CNI} allows CNI code to implement methods of interfaces.
1224 You can also call methods through interface references, with some
1225 limitations.
1226
1227 @acronym{CNI} doesn't understand interface inheritance at all yet.  So,
1228 you can only call an interface method when the declared type of the
1229 field being called matches the interface which declares that
1230 method.  The workaround is to cast the interface reference to the right
1231 superinterface.
1232  
1233 For example if you have: 
1234
1235 @example 
1236 interface A 
1237 @{ 
1238   void a(); 
1239 @} 
1240  
1241 interface B extends A 
1242 @{ 
1243   void b(); 
1244 @} 
1245 @end example
1246  
1247 and declare a variable of type @code{B} in C++, you can't call
1248 @code{a()} unless you cast it to an @code{A} first.
1249
1250 @node Objects and Classes
1251 @section Objects and Classes
1252
1253 @subsection Classes
1254
1255 All Java classes are derived from @code{java.lang.Object}.  C++ does
1256 not have a unique root class, but we use the C++ class
1257 @code{java::lang::Object} as the C++ version of the
1258 @code{java.lang.Object} Java class.  All other Java classes are mapped
1259 into corresponding C++ classes derived from @code{java::lang::Object}.
1260
1261 Interface inheritance (the @code{implements} keyword) is currently not
1262 reflected in the C++ mapping.
1263
1264
1265 @subsection Object fields
1266
1267 Each object contains an object header, followed by the instance fields
1268 of the class, in order.  The object header consists of a single
1269 pointer to a dispatch or virtual function table.  (There may be extra
1270 fields @emph{in front of} the object, for example for memory
1271 management, but this is invisible to the application, and the
1272 reference to the object points to the dispatch table pointer.)
1273
1274 The fields are laid out in the same order, alignment, and size as in
1275 C++.  Specifically, 8-bite and 16-bit native types (@code{byte},
1276 @code{short}, @code{char}, and @code{boolean}) are @emph{not} widened
1277 to 32 bits.  Note that the Java VM does extend 8-bit and 16-bit types
1278 to 32 bits when on the VM stack or temporary registers.
1279
1280 If you include the @code{gcjh}-generated header for a
1281 class, you can access fields of Java classes in the @emph{natural}
1282 way.  For example, given the following Java class:
1283
1284 @example
1285 public class Int
1286 @{
1287   public int i;
1288   public Integer (int i) @{ this.i = i; @}
1289   public static zero = new Integer(0);
1290 @}
1291 @end example
1292
1293 you can write:
1294
1295 @example
1296 #include <gcj/cni.h>;
1297 #include <Int>;
1298
1299 Int*
1300 mult (Int *p, jint k)
1301 @{
1302   if (k == 0)
1303     return Int::zero;  // @r{Static member access.}
1304   return new Int(p->i * k);
1305 @}
1306 @end example
1307
1308
1309 @subsection Access specifiers
1310
1311 CNI does not strictly enforce the Java access
1312 specifiers, because Java permissions cannot be directly mapped
1313 into C++ permission.  Private Java fields and methods are mapped
1314 to private C++ fields and methods, but other fields and methods
1315 are mapped to public fields and methods.
1316
1317
1318
1319 @node Class Initialization
1320 @section Class Initialization
1321
1322 Java requires that each class be automatically initialized at the time 
1323 of the first active use.  Initializing a class involves 
1324 initializing the static fields, running code in class initializer 
1325 methods, and initializing base classes.  There may also be 
1326 some implementation specific actions, such as allocating 
1327 @code{String} objects corresponding to string literals in
1328 the code.
1329
1330 The GCJ compiler inserts calls to @code{JvInitClass} at appropriate
1331 places to ensure that a class is initialized when required.  The C++
1332 compiler does not insert these calls automatically---it is the
1333 programmer's responsibility to make sure classes are initialized.
1334 However, this is fairly painless because of the conventions assumed by
1335 the Java system.
1336
1337 First, @code{libgcj} will make sure a class is initialized before an
1338 instance of that object is created.  This is one of the
1339 responsibilities of the @code{new} operation.  This is taken care of
1340 both in Java code, and in C++ code.  When G++ sees a @code{new} of a
1341 Java class, it will call a routine in @code{libgcj} to allocate the
1342 object, and that routine will take care of initializing the class.
1343 Note however that this does not happen for Java arrays; you must
1344 allocate those using the appropriate CNI function.  It follows that
1345 you can access an instance field, or call an instance (non-static)
1346 method and be safe in the knowledge that the class and all of its base
1347 classes have been initialized.
1348
1349 Invoking a static method is also safe.  This is because the
1350 Java compiler adds code to the start of a static method to make sure
1351 the class is initialized.  However, the C++ compiler does not
1352 add this extra code.  Hence, if you write a native static method
1353 using CNI, you are responsible for calling @code{JvInitClass}
1354 before doing anything else in the method (unless you are sure
1355 it is safe to leave it out).
1356
1357 Accessing a static field also requires the class of the
1358 field to be initialized.  The Java compiler will generate code
1359 to call @code{Jv_InitClass} before getting or setting the field.
1360 However, the C++ compiler will not generate this extra code,
1361 so it is your responsibility to make sure the class is
1362 initialized before you access a static field from C++.
1363
1364
1365 @node Object allocation
1366 @section Object allocation
1367
1368 New Java objects are allocated using a
1369 @dfn{class instance creation expression}, e.g.:
1370
1371 @example
1372 new @var{Type} ( ... )
1373 @end example
1374
1375 The same syntax is used in C++.  The main difference is that
1376 C++ objects have to be explicitly deleted; in Java they are
1377 automatically deleted by the garbage collector.
1378 Using @acronym{CNI}, you can allocate a new Java object
1379 using standard C++ syntax and the C++ compiler will allocate
1380 memory from the garbage collector.  If you have overloaded
1381 constructors, the compiler will choose the correct one
1382 using standard C++ overload resolution rules.  
1383
1384 @noindent For example:
1385
1386 @example
1387 java::util::Hashtable *ht = new java::util::Hashtable(120);
1388 @end example
1389
1390 @deftypefun void* _Jv_AllocBytes (jsize @var{size})
1391 Allocates @var{size} bytes from the heap.  The memory is not scanned
1392 by the garbage collector but it freed if no references to it are discovered.
1393 @end deftypefun
1394
1395
1396 @node Arrays
1397 @section Arrays
1398
1399 While in many ways Java is similar to C and C++, it is quite different
1400 in its treatment of arrays.  C arrays are based on the idea of pointer
1401 arithmetic, which would be incompatible with Java's security
1402 requirements.  Java arrays are true objects (array types inherit from
1403 @code{java.lang.Object}).  An array-valued variable is one that
1404 contains a reference (pointer) to an array object.
1405
1406 Referencing a Java array in C++ code is done using the
1407 @code{JArray} template, which as defined as follows:
1408
1409 @example
1410 class __JArray : public java::lang::Object
1411 @{
1412 public:
1413   int length;
1414 @};
1415
1416 template<class T>
1417 class JArray : public __JArray
1418 @{
1419   T data[0];
1420 public:
1421   T& operator[](jint i) @{ return data[i]; @}
1422 @};
1423 @end example
1424
1425
1426 There are a number of @code{typedef}s which correspond to @code{typedef}s 
1427 from the @acronym{JNI}.  Each is the type of an array holding objects
1428 of the relevant type:
1429
1430 @example
1431 typedef __JArray *jarray;
1432 typedef JArray<jobject> *jobjectArray;
1433 typedef JArray<jboolean> *jbooleanArray;
1434 typedef JArray<jbyte> *jbyteArray;
1435 typedef JArray<jchar> *jcharArray;
1436 typedef JArray<jshort> *jshortArray;
1437 typedef JArray<jint> *jintArray;
1438 typedef JArray<jlong> *jlongArray;
1439 typedef JArray<jfloat> *jfloatArray;
1440 typedef JArray<jdouble> *jdoubleArray;
1441 @end example
1442
1443
1444 @deftypemethod {template<class T>} T* elements (JArray<T> @var{array})
1445 This template function can be used to get a pointer to the elements of
1446 the @code{array}.  For instance, you can fetch a pointer to the
1447 integers that make up an @code{int[]} like so:
1448
1449 @example
1450 extern jintArray foo;
1451 jint *intp = elements (foo);
1452 @end example
1453
1454 The name of this function may change in the future.
1455 @end deftypemethod
1456
1457
1458 @deftypefun jobjectArray JvNewObjectArray (jsize @var{length}, jclass @var{klass}, jobject @var{init})
1459 Here @code{klass} is the type of elements of the array and
1460 @code{init} is the initial value put into every slot in the array.
1461 @end deftypefun
1462
1463
1464 @subsection Creating arrays
1465
1466 For each primitive type there is a function which can be used to
1467 create a new array of that type.  The name of the function is of the
1468 form:
1469
1470 @example
1471 JvNew@var{Type}Array
1472 @end example
1473
1474 @noindent For example:
1475
1476 @example
1477 JvNewBooleanArray
1478 @end example
1479
1480 @noindent can be used to create an array of Java primitive boolean types.
1481
1482 @noindent The following function definition is the template for all such functions:
1483
1484 @deftypefun jbooleanArray JvNewBooleanArray (jint @var{length})
1485 Create's an array @var{length} indices long.
1486 @end deftypefun
1487
1488 @deftypefun jsize JvGetArrayLength (jarray @var{array})
1489 Returns the length of the @var{array}.
1490 @end deftypefun
1491
1492
1493 @node Methods
1494 @section Methods
1495
1496 Java methods are mapped directly into C++ methods.
1497 The header files generated by @code{gcjh}
1498 include the appropriate method definitions.
1499 Basically, the generated methods have the same names and
1500 @emph{corresponding} types as the Java methods,
1501 and are called in the natural manner.
1502
1503 @subsection Overloading
1504
1505 Both Java and C++ provide method overloading, where multiple
1506 methods in a class have the same name, and the correct one is chosen
1507 (at compile time) depending on the argument types.
1508 The rules for choosing the correct method are (as expected) more complicated
1509 in C++ than in Java, but given a set of overloaded methods
1510 generated by @code{gcjh} the C++ compiler will choose
1511 the expected one.
1512
1513 Common assemblers and linkers are not aware of C++ overloading,
1514 so the standard implementation strategy is to encode the
1515 parameter types of a method into its assembly-level name.
1516 This encoding is called @dfn{mangling},
1517 and the encoded name is the @dfn{mangled name}.
1518 The same mechanism is used to implement Java overloading.
1519 For C++/Java interoperability, it is important that both the Java
1520 and C++ compilers use the @emph{same} encoding scheme.
1521
1522 @subsection Static methods
1523
1524 Static Java methods are invoked in @acronym{CNI} using the standard
1525 C++ syntax, using the @code{::} operator rather
1526 than the @code{.} operator.  
1527
1528 @noindent For example:
1529
1530 @example
1531 jint i = java::lang::Math::round((jfloat) 2.3);
1532 @end example
1533
1534 @noindent C++ method definition syntax is used to define a static native method.
1535 For example:
1536
1537 @example
1538 #include <java/lang/Integer>
1539 java::lang::Integer*
1540 java::lang::Integer::getInteger(jstring str)
1541 @{
1542   ...
1543 @}
1544 @end example
1545
1546
1547 @subsection Object Constructors
1548
1549 Constructors are called implicitly as part of object allocation
1550 using the @code{new} operator.  
1551
1552 @noindent For example:
1553
1554 @example
1555 java::lang::Integer *x = new java::lang::Integer(234);
1556 @end example
1557
1558 Java does not allow a constructor to be a native method.
1559 This limitation can be coded round however because a constructor
1560 can @emph{call} a native method.
1561
1562
1563 @subsection Instance methods
1564
1565 Calling a Java instance method from a C++ @acronym{CNI} method is done 
1566 using the standard C++ syntax, e.g.:
1567
1568 @example
1569 // @r{First create the Java object.}
1570 java::lang::Integer *x = new java::lang::Integer(234);
1571 // @r{Now call a method.}
1572 jint prim_value = x->intValue();
1573 if (x->longValue == 0) 
1574   ...
1575 @end example
1576
1577 @noindent Defining a Java native instance method is also done the natural way:
1578
1579 @example
1580 #include <java/lang/Integer.h>
1581
1582 jdouble
1583 java::lang:Integer::doubleValue()
1584 @{
1585   return (jdouble) value;
1586 @}
1587 @end example
1588
1589
1590 @subsection Interface methods
1591
1592 In Java you can call a method using an interface reference.  This is
1593 supported, but not completely.  @xref{Interfaces}.
1594
1595
1596
1597
1598 @node Strings
1599 @section Strings
1600
1601 @acronym{CNI} provides a number of utility functions for
1602 working with Java Java @code{String} objects.
1603 The names and interfaces are analogous to those of @acronym{JNI}.
1604
1605
1606 @deftypefun jstring JvNewString (const char* @var{chars}, jsize @var{len})
1607 Returns a Java @code{String} object with characters from the C string
1608 @var{chars} up to the index @var{len} in that array.
1609 @end deftypefun
1610
1611 @deftypefun jstring JvNewStringLatin1 (const char* @var{bytes}, jsize @var{len})
1612 Returns a Java @code{String} made up of @var{len} bytes from @var{bytes}.
1613 @end deftypefun
1614
1615
1616 @deftypefun jstring JvNewStringLatin1 (const char* @var{bytes})
1617 As above but the length of the @code{String} is @code{strlen(@var{bytes})}.
1618 @end deftypefun
1619
1620 @deftypefun jstring JvNewStringUTF (const char* @var{bytes})
1621 Returns a @code{String} which is made up of the UTF encoded characters
1622 present in the C string @var{bytes}.
1623 @end deftypefun
1624
1625 @deftypefun jchar* JvGetStringChars (jstring @var{str})
1626 Returns a pointer to an array of characters making up the @code{String} @var{str}.
1627 @end deftypefun
1628
1629 @deftypefun int JvGetStringUTFLength (jstring @var{str})
1630 Returns the number of bytes required to encode the contents of the
1631 @code{String} @var{str} in UTF-8.
1632 @end deftypefun
1633
1634 @deftypefun jsize JvGetStringUTFRegion (jstring @var{str}, jsize @var{start}, jsize @var{len}, char* @var{buf})
1635 Puts the UTF-8 encoding of a region of the @code{String} @var{str} into 
1636 the buffer @code{buf}.  The region to fetch is marked by @var{start} and @var{len}.
1637
1638 Note that @var{buf} is a buffer, not a C string.  It is @emph{not} 
1639 null terminated.
1640 @end deftypefun
1641
1642
1643 @node Mixing with C++
1644 @section Interoperating with C/C++
1645
1646 Because @acronym{CNI} is designed to represent Java classes and methods it
1647 cannot be mixed readily with C/C++ types.
1648
1649 One important restriction is that Java classes cannot have non-Java
1650 type instance or static variables and cannot have methods which take
1651 non-Java types as arguments or return non-Java types.
1652
1653 @noindent None of the following is possible with CNI:
1654
1655 @example
1656
1657 class ::MyClass : public java::lang::Object
1658 @{
1659    char* variable;  // @r{char* is not a valid Java type.}
1660 @}
1661
1662
1663 uint
1664 ::SomeClass::someMethod (char *arg)
1665 @{
1666   .
1667   .
1668   .
1669 @}   // @r{@code{uint} is not a valid Java type, neither is @code{char*}}
1670 @end example
1671
1672 @noindent Of course, it is ok to use C/C++ types within the scope of a method:
1673
1674
1675 @example
1676 jint
1677 ::SomeClass::otherMethod (jstring str)
1678 @{
1679    char *arg = ...
1680    .
1681    .
1682    .
1683 @}
1684 @end example
1685
1686 But this restriction can cause a problem so @acronym{CNI} includes the
1687 @code{gnu.gcj.RawData} class.  The @code{RawData} class is a
1688 @dfn{non-scanned reference} type.  In other words variables declared
1689 of type @code{RawData} can contain any data and are not checked by the
1690 compiler in any way.
1691
1692 This means that you can put C/C++ data structures (including classes)
1693 in your @acronym{CNI} classes, as long as you use the appropriate cast.
1694
1695 @noindent Here are some examples:
1696
1697 @example
1698
1699 class ::MyClass : public java::lang::Object
1700 @{
1701    gnu.gcj.RawData string;
1702
1703    MyClass ();
1704    gnu.gcj.RawData getText ();
1705    void printText ();
1706 @}
1707
1708 ::MyClass::MyClass ()
1709 @{
1710    char* text = ...
1711    string = text;
1712 @}
1713
1714 gnu.gcj.RawData
1715 ::MyClass::getText ()
1716 @{
1717    return string;
1718 @}
1719
1720 void
1721 ::MyClass::printText ()
1722 @{
1723   printf("%s\n", (char*) string);
1724 @}
1725 @end example
1726
1727
1728 @node Exception Handling
1729 @section Exception Handling
1730
1731 While C++ and Java share a common exception handling framework,
1732 things are not yet perfectly integrated.  The main issue is that the
1733 run-time type information facilities of the two
1734 languages are not integrated.
1735
1736 Still, things work fairly well.  You can throw a Java exception from
1737 C++ using the ordinary @code{throw} construct, and this
1738 exception can be caught by Java code.  Similarly, you can catch an
1739 exception thrown from Java using the C++ @code{catch}
1740 construct.
1741
1742 @noindent Here is an example:
1743
1744 @example
1745 if (i >= count)
1746    throw new java::lang::IndexOutOfBoundsException();
1747 @end example
1748
1749 Normally, G++ will automatically detect when you are writing C++
1750 code that uses Java exceptions, and handle them appropriately.
1751 However, if C++ code only needs to execute destructors when Java
1752 exceptions are thrown through it, GCC will guess incorrectly.  Sample
1753 problematic code:
1754
1755 @example
1756 struct S @{ ~S(); @};
1757
1758 extern void bar();    // @r{Is implemented in Java and may throw exceptions.}
1759
1760 void foo()
1761 @{
1762   S s;
1763   bar();
1764 @}
1765 @end example
1766
1767 The usual effect of an incorrect guess is a link failure, complaining of
1768 a missing routine called @code{__gxx_personality_v0}.
1769
1770 You can inform the compiler that Java exceptions are to be used in a
1771 translation unit, irrespective of what it might think, by writing
1772 @code{#pragma GCC java_exceptions} at the head of the
1773 file.  This @code{#pragma} must appear before any
1774 functions that throw or catch exceptions, or run destructors when
1775 exceptions are thrown through them.
1776
1777 @node Synchronization
1778 @section Synchronization
1779
1780 Each Java object has an implicit monitor.
1781 The Java VM uses the instruction @code{monitorenter} to acquire
1782 and lock a monitor, and @code{monitorexit} to release it.
1783
1784 The corresponding CNI macros are @code{JvMonitorEnter} and 
1785 @code{JvMonitorExit} (JNI has similar  methods @code{MonitorEnter}
1786 and @code{MonitorExit}).  
1787
1788
1789 The Java source language does not provide direct access to these primitives.
1790 Instead, there is a @code{synchronized} statement that does an
1791 implicit @code{monitorenter} before entry to the block,
1792 and does a @code{monitorexit} on exit from the block.
1793 Note that the lock has to be released even when the block is abnormally
1794 terminated by an exception, which means there is an implicit
1795 @code{try finally} surrounding synchronization locks.
1796
1797 From C++, it makes sense to use a destructor to release a lock.
1798 @acronym{CNI} defines the following utility class:
1799
1800 @example
1801 class JvSynchronize() @{
1802   jobject obj;
1803   JvSynchronize(jobject o) @{ obj = o; JvMonitorEnter(o); @}
1804   ~JvSynchronize() @{ JvMonitorExit(obj); @}
1805 @};
1806 @end example
1807
1808 So this Java code:
1809
1810 @example
1811 synchronized (OBJ)
1812 @{
1813    CODE
1814 @}
1815 @end example
1816
1817 @noindent might become this C++ code:
1818
1819 @example
1820 @{
1821    JvSynchronize dummy (OBJ);
1822    CODE;
1823 @}
1824 @end example
1825
1826 Java also has methods with the @code{synchronized} attribute.
1827 This is equivalent to wrapping the entire method body in a
1828 @code{synchronized} statement.
1829 (Alternatively, an implementation could require the caller to do
1830 the synchronization.  This is not practical for a compiler, because
1831 each virtual method call would have to test at run-time if
1832 synchronization is needed.)  Since in @command{gcj}
1833 the @code{synchronized} attribute is handled by the
1834 method implementation, it is up to the programmer
1835 of a synchronized native method to handle the synchronization
1836 (in the C++ implementation of the method).
1837 In other words, you need to manually add @code{JvSynchronize}
1838 in a @code{native synchronized} method.
1839
1840 @node Invocation
1841 @section Invocation
1842
1843 CNI permits C++ applications to make calls into Java classes, in addition to
1844 allowing Java code to call into C++. Several functions, known as the 
1845 @dfn{invocation API}, are provided to support this.
1846
1847 @deftypefun jint JvCreateJavaVM (void* @var{vm_args})
1848 Initializes the Java runtime. This function performs essential initialization
1849 of the threads interface, garbage collector, exception handling and other key
1850 aspects of the runtime. It must be called once by an application with
1851 a non-Java @code{main()} function, before any other Java or CNI calls are made.
1852 It is safe, but not recommended, to call @code{JvCreateJavaVM()} more than
1853 once provided it is only called from a single thread.
1854 The @var{vmargs} parameter can be used to specify initialization parameters 
1855 for the Java runtime. It may be @code{NULL}.
1856 This function returns @code{0} upon success, or @code{-1} if the runtime is
1857 already initialized.
1858
1859 @emph{Note:} In GCJ 3.1, the @code{vm_args} parameter is ignored. It may be 
1860 used in a future release.
1861 @end deftypefun
1862
1863 @deftypefun java::lang::Thread* JvAttachCurrentThread (jstring @var{name}, java::lang::ThreadGroup* @var{group})
1864 Registers an existing thread with the Java runtime.  This must be called once
1865 from each thread, before that thread makes any other Java or CNI calls. It
1866 must be called after @code{JvCreateJavaVM}.
1867 @var{name} specifies a name for the thread. It may be @code{NULL}, in which 
1868 case a name will be generated.
1869 @var{group} is the ThreadGroup in which this thread will be a member. If it
1870 is @code{NULL}, the thread will be a member of the main thread group.
1871 The return value is the Java @code{Thread} object that represents the thread.
1872 It is safe to call @code{JvAttachCurrentThread()} more than once from the same
1873 thread. If the thread is already attached, the call is ignored and the current
1874 thread object is returned.
1875 @end deftypefun
1876
1877 @deftypefun jint JvDetachCurrentThread ()
1878 Unregisters a thread from the Java runtime. This should be called by threads
1879 that were attached using @code{JvAttachCurrentThread()}, after they have 
1880 finished making calls to Java code. This ensures that any resources associated
1881 with the thread become eligible for garbage collection.
1882 This function returns @code{0} upon success, or @code{-1} if the current thread
1883 is not attached.
1884 @end deftypefun
1885
1886 @subsection Handling uncaught exceptions
1887
1888 If an exception is thrown from Java code called using the invocation API, and
1889 no handler for the exception can be found, the runtime will abort the
1890 application. In order to make the application more robust, it is recommended 
1891 that code which uses the invocation API be wrapped by a top-level try/catch 
1892 block that catches all Java exceptions.
1893
1894 @subsection Example
1895
1896 The following code demonstrates the use of the invocation API. In this
1897 example, the C++ application initializes the Java runtime and attaches
1898 itself. The @code{java.lang.System} class is initialized in order to
1899 access its @code{out} field, and a Java string is printed. Finally, the thread
1900 is detached from the runtime once it has finished making Java calls. Everything
1901 is wrapped with a try/catch block to provide a default handler for any uncaught 
1902 exceptions.
1903
1904 The example can be compiled with @command{c++ test.cc -lgcj}.
1905
1906 @example
1907 // test.cc
1908 #include <gcj/cni.h>
1909 #include <java/lang/System.h>
1910 #include <java/io/PrintStream.h>
1911 #include <java/lang/Throwable.h>
1912
1913 int main(int argc, char *argv)
1914 @{
1915   using namespace java::lang;
1916   
1917   try
1918   @{
1919     JvCreateJavaVM(NULL);
1920     JvAttachCurrentThread(NULL, NULL);
1921
1922     String *message = JvNewStringLatin1("Hello from C++");
1923     JvInitClass(&System::class$);
1924     System::out->println(message);
1925
1926     JvDetachCurrentThread();
1927   @}
1928   catch (Throwable *t)
1929   @{
1930     System::err->println(JvNewStringLatin1("Unhandled Java exception:"));
1931     t->printStackTrace();
1932   @}
1933 @}
1934 @end example
1935
1936 @node Reflection
1937 @section Reflection
1938
1939 Reflection is possible with CNI code, it functions similarly to how it
1940 functions with JNI@.
1941
1942 @c clean this up...  I mean, what are the types jfieldID and jmethodID in JNI?
1943 The types @code{jfieldID} and @code{jmethodID}
1944 are as in JNI@.
1945
1946 @noindent The functions:
1947
1948 @itemize
1949 @item @code{JvFromReflectedField},
1950 @item @code{JvFromReflectedMethod},
1951 @item @code{JvToReflectedField}
1952 @item @code{JvToFromReflectedMethod}
1953 @end itemize
1954
1955 @noindent will be added shortly, as will other functions corresponding to JNI@.
1956
1957
1958 @node System properties
1959 @chapter System properties
1960
1961 The runtime behavior of the @code{libgcj} library can be modified by setting
1962 certain system properties.  These properties can be compiled into the program
1963 using the @code{-D@var{name}[=@var{value}]} option to @command{gcj} or by
1964 setting them explicitly in the program by calling the
1965 @code{java.lang.System.setProperty()} method.  Some system properties are only
1966 used for informational purposes (like giving a version number or a user name).
1967 A program can inspect the current value of a property by calling the
1968 @code{java.lang.System.getProperty()} method.
1969
1970 @menu
1971 * Standard Properties::         Standard properties supported by @code{libgcj}
1972 * GNU Classpath Properties::    Properties found in Classpath based libraries
1973 * libgcj Runtime Properties::   Properties specific to @code{libgcj}
1974 @end menu
1975
1976 @node Standard Properties
1977 @section Standard Properties
1978
1979 The following properties are normally found in all implementations of the core
1980 libraries for the Java language.
1981
1982 @table @gcctabopt
1983
1984 @item java.version
1985 The @code{libgcj} version number.
1986
1987 @item java.vendor
1988 Set to @samp{The Free Software Foundation, Inc.}
1989
1990 @item java.vendor.url
1991 Set to @uref{http://gcc.gnu.org/java/}.
1992
1993 @item java.home
1994 The directory where @code{gcj} was installed.  Taken from the @code{--prefix}
1995 option given to @command{configure}.
1996
1997 @item java.class.version
1998 The class format version number supported by the libgcj byte code interpreter.
1999 (Currently @samp{46.0})
2000
2001 @item java.vm.specification.version
2002 The Virtual Machine Specification version implemented by @code{libgcj}.
2003 (Currently @samp{1.0})
2004
2005 @item java.vm.specification.vendor
2006 The name of the Virtual Machine specification designer.
2007
2008 @item java.vm.specification.name
2009 The name of the Virtual Machine specification
2010 (Set to @samp{Java Virtual Machine Specification}).
2011
2012 @item java.vm.version
2013 The @command{gcj} version number.
2014
2015 @item java.vm.vendor
2016 Set to @samp{The Free Software Foundation, Inc.}
2017
2018 @item java.vm.name
2019 Set to @samp{GNU libgcj}.
2020
2021 @item java.specification.version
2022 The Runtime Environment specification version implemented by @code{libgcj}.
2023 (Currently set to @samp{1.3})
2024
2025 @item java.specification.vendor
2026 The Runtime Environment specification designer.
2027
2028 @item java.specification.name
2029 The name of the Runtime Environment specification
2030 (Set to @samp{Java Platform API Specification}).
2031
2032 @item java.class.path
2033 The paths (jar files, zip files and directories) used for finding class files.
2034
2035 @item java.library.path
2036 Directory path used for finding native libraries.  Currently not set.
2037
2038 @item java.io.tmpdir
2039 The directory used to put temporary files in.
2040
2041 @item java.compiler
2042 Name of the Just In Time compiler to use by the byte code interpreter.
2043 Currently not used in @code{libgcj}.
2044
2045 @item java.ext.dirs
2046 Directories containing jar files with extra libraries.  Will be used when
2047 resolving classes.  Currently not used in @code{libgcj}.
2048
2049 @item java.protocol.handler.pkgs
2050 A @samp{|} separated list of package names that is used to find classes that
2051 implement handlers for @code{java.net.URL}.
2052
2053 @item java.rmi.server.codebase
2054 A list of URLs that is used by the @code{java.rmi.server.RMIClassLoader}
2055 to load classes from.
2056
2057 @item jdbc.drivers
2058 A list of class names that will be loaded by the @code{java.sql.DriverManager}
2059 when it starts up.
2060
2061 @item file.separator
2062 The separator used in when directories are included in a filename
2063 (normally @samp{/} or @samp{\} ).
2064
2065 @item file.encoding
2066 The default character encoding used when converting platform native files to
2067 Unicode (usually set to @samp{8859_1}).
2068
2069 @item path.separator
2070 The standard separator used when a string contains multiple paths
2071 (normally @samp{:} or @samp{;}), the string is usually not a valid character
2072 to use in normal directory names.)
2073
2074 @item line.separator
2075 The default line separator used on the platform (normally @samp{\n}, @samp{\r}
2076 or a combination of those two characters).
2077
2078 @item policy.provider
2079 The class name used for the default policy provider returned by
2080 @code{java.security.Policy.getPolicy}.
2081
2082 @item user.name
2083 The name of the user running the program.  Can be the full name, the login name
2084 or empty if unknown.
2085
2086 @item user.home
2087 The default directory to put user specific files in.
2088
2089 @item user.dir
2090 The current working directory from which the program was started.
2091
2092 @item user.language
2093 The default language as used by the @code{java.util.Locale} class.
2094
2095 @item user.region
2096 The default region as used by the @code{java.util.Local} class.
2097
2098 @item user.variant
2099 The default variant of the language and region local used.
2100
2101 @item user.timezone
2102 The default timezone as used by the @code{java.util.TimeZone} class.
2103
2104 @item os.name
2105 The operating system/kernel name that the program runs on.
2106
2107 @item os.arch
2108 The hardware that we are running on.
2109
2110 @item os.version
2111 The version number of the operating system/kernel.
2112
2113 @item awt.appletWarning
2114 The string to display when an untrusted applet is displayed.
2115 Returned by @code{java.awt.Window.getWarningString()} when the window is
2116 ``insecure''.
2117
2118 @item awt.toolkit
2119 The class name used for initializing the default @code{java.awt.Toolkit}. 
2120 Defaults to @code{gnu.awt.gtk.GtkToolkit}.
2121
2122 @end table
2123
2124 @node GNU Classpath Properties
2125 @section GNU Classpath Properties
2126
2127 @code{libgcj} is based on the GNU Classpath (Essential Libraries for Java) a
2128 GNU project to create free core class libraries for use with virtual machines
2129 and compilers for the Java language.  The following properties are common to
2130 libraries based on GNU Classpath.
2131
2132 @table @gcctabopt
2133
2134 @item gcj.dumpobject
2135 Enables printing serialization debugging by the @code{java.io.ObjectInput} and
2136 @code{java.io.ObjectOutput} classes when set to something else then the empty
2137 string.  Only used when running a debug build of the library.
2138
2139 @end table
2140
2141 @node libgcj Runtime Properties
2142 @section libgcj Runtime Properties
2143
2144 The following properties are specific to the @code{libgcj} runtime and will
2145 normally not be found in other core libraries for the java language.
2146
2147 @table @gcctabopt
2148
2149 @item java.fullversion
2150 The combination of @code{java.vm.name} and @code{java.vm.version}.
2151
2152 @item java.vm.info
2153 Same as @code{java.fullversion}.
2154
2155 @item impl.prefix
2156 Used by the @code{java.net.DatagramSocket} class when set to something else
2157 then the empty string.  When set all newly created @code{DatagramSocket}s will
2158 try to load a class @code{java.net.[impl.prefix]DatagramSocketImpl} instead of
2159 the normal @code{java.net.PlainDatagramSocketImpl}.
2160
2161 @item gnu.gcj.runtime.NameFinder.demangle
2162 Whether names in a stack trace should be demangled.  Defaults to @code{true}.
2163
2164 @item gnu.gcj.runtime.NameFinder.sanitize
2165 Whether calls to initialize exceptions and starting the runtime system
2166 should be removed from the stack trace.  Only done when names are
2167 demangled.  Defaults to @code{true}.
2168
2169 @item gnu.gcj.runtime.NameFinder.remove_unknown
2170 Whether calls to unknown functions (class and method names are unknown)
2171 should be removed from the stack trace.  Only done when the stack is
2172 sanitized.  Ignored if this means no stack trace information would be
2173 available anymore.  Defaults to @code{true}.
2174
2175 @item gnu.gcj.runtime.NameFinder.remove_interpreter
2176 Whether runtime interpreter calls (methods in the @code{_Jv_InterpMethod} class
2177 and functions starting with @samp{ffi_}) should be removed from the stack
2178 trace.  Only done when the stack is sanitized.  Defaults to @code{true}.
2179
2180
2181 @item gnu.gcj.runtime.NameFinder.use_addr2line
2182 Whether an external process (@command{addr2line} or @command{addr2name.awk})
2183 should be used as fallback to convert the addresses to function names when
2184 the runtime is unable to do it through @code{dladdr}.
2185
2186 @end table
2187
2188
2189 @node Resources
2190 @chapter Resources
2191
2192 While writing @command{gcj} and @code{libgcj} we have, of course, relied
2193 heavily on documentation from Sun Microsystems.  In particular we have
2194 used The Java Language Specification (both first and second editions),
2195 the Java Class Libraries (volumes one and two), and the Java Virtual
2196 Machine Specification.  In addition we've used the online documentation
2197 at @uref{http://java.sun.com/}.
2198
2199 The current @command{gcj} home page is
2200 @uref{http://gcc.gnu.org/java/}.
2201
2202 For more information on gcc, see @uref{http://gcc.gnu.org/}.
2203
2204 Some @code{libgcj} testing is done using the Mauve test suite.  This is
2205 a free software Java class library test suite which is being written
2206 because the JCK is not free.  See
2207 @uref{http://sources.redhat.com/mauve/} for more information.
2208
2209 @bye