OSDN Git Service

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