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