From 54a0a14af93b2e7ad37e7ad7ef0a0c86eb9eaf2c Mon Sep 17 00:00:00 2001 From: Matthias Klose Date: Tue, 20 Feb 2007 19:46:57 +0000 Subject: Makefile.am: Add rules to build and install man pages from texinfo docs. ChangeLog 2007-02-20 Matthias Klose * doc/Makefile.am: Add rules to build and install man pages from texinfo docs. * doc/hacking.texinfo doc/tools.texinfo, doc/vmintegration.texinfo: Rename, prefix files with "cp-". * doc/cp-tools.texinfo: Add markup for man page generation, add documentation for command line options for gjar, gjavah, gnative2ascii, gorbd, grmid, grmiregistry, gserialver, gtnameserv. doc/texi2pod.pl: New, taken from the GCC sources. ChangeLog.gcj 2007-02-20 Matthias Klose * Merge doc update from classpath HEAD. * doc/texi2pod.pl: Not imported. * doc/Makefile.am: Use GCC's texi2pod.pl * doc/Makefile.in: Regenerate. From-SVN: r122170 --- libjava/classpath/ChangeLog | 11 + libjava/classpath/ChangeLog.gcj | 7 + libjava/classpath/doc/Makefile.am | 85 +- libjava/classpath/doc/Makefile.in | 80 +- libjava/classpath/doc/cp-hacking.texinfo | 1733 +++++++++++++++++++++ libjava/classpath/doc/cp-tools.texinfo | 1806 +++++++++++++++++++++ libjava/classpath/doc/cp-vmintegration.texinfo | 1980 ++++++++++++++++++++++++ libjava/classpath/doc/hacking.texinfo | 1733 --------------------- libjava/classpath/doc/tools.texinfo | 1206 --------------- libjava/classpath/doc/vmintegration.texinfo | 1980 ------------------------ 10 files changed, 5696 insertions(+), 4925 deletions(-) create mode 100644 libjava/classpath/doc/cp-hacking.texinfo create mode 100644 libjava/classpath/doc/cp-tools.texinfo create mode 100644 libjava/classpath/doc/cp-vmintegration.texinfo delete mode 100644 libjava/classpath/doc/hacking.texinfo delete mode 100644 libjava/classpath/doc/tools.texinfo delete mode 100644 libjava/classpath/doc/vmintegration.texinfo (limited to 'libjava/classpath') diff --git a/libjava/classpath/ChangeLog b/libjava/classpath/ChangeLog index 2288788..c959705 100644 --- a/libjava/classpath/ChangeLog +++ b/libjava/classpath/ChangeLog @@ -1,3 +1,14 @@ +2007-02-20 Matthias Klose + + * doc/Makefile.am: Add rules to build and install man pages + from texinfo docs. + * doc/hacking.texinfo doc/tools.texinfo, doc/vmintegration.texinfo: + Rename, prefix files with "cp-". + * doc/cp-tools.texinfo: Add markup for man page generation, + add documentation for command line options for gjar, gjavah, + gnative2ascii, gorbd, grmid, grmiregistry, gserialver, gtnameserv. + doc/texi2pod.pl: New, taken from the GCC sources. + 2006-10-14 Edwin Steiner PR classpath/28652: diff --git a/libjava/classpath/ChangeLog.gcj b/libjava/classpath/ChangeLog.gcj index 9273fe2..9b1af8e 100644 --- a/libjava/classpath/ChangeLog.gcj +++ b/libjava/classpath/ChangeLog.gcj @@ -1,3 +1,10 @@ +2007-02-20 Matthias Klose + + * Merge doc update from classpath HEAD. + * doc/texi2pod.pl: Not imported. + * doc/Makefile.am: Use GCC's texi2pod.pl + * doc/Makefile.in: Regenerate. + 2007-02-20 Gary Benson * javax/management/MBeanServer.java: Updated. diff --git a/libjava/classpath/doc/Makefile.am b/libjava/classpath/doc/Makefile.am index c4a7856..b5d057a 100644 --- a/libjava/classpath/doc/Makefile.am +++ b/libjava/classpath/doc/Makefile.am @@ -1,9 +1,9 @@ SUBDIRS = api -EXTRA_DIST = README.jaxp +EXTRA_DIST = README.jaxp $(man_MANS) -## GCJ LOCAL: we don't want to install Classpath's info files. -## info_TEXINFOS = hacking.texinfo vmintegration.texinfo +## GCJ LOCAL: we don't want to install all of Classpath's info files. +## info_TEXINFOS = cp-hacking.texinfo cp-vmintegration.texinfo cp-tools.texinfo %.dvi : %.texinfo texi2dvi $< @@ -11,4 +11,81 @@ EXTRA_DIST = README.jaxp %.ps : %.dvi dvips -o $@ $< -docs: hacking.ps vmintegration.ps tools.ps +docs: cp-hacking.ps cp-vmintegration.ps cp-tools.ps + +#man_MANS = $(TOOLS_MANFILES) +TOOLS_MANFILES = \ + gappletviewer.1 \ + gjar.1 \ + gjarsigner.1 \ + gjavah.1 \ + gkeytool.1 \ + gnative2ascii.1 \ + gorbd.1 \ + grmid.1 \ + grmiregistry.1 \ + gserialver.1 \ + gtnameserv.1 + +BASEVER = $(top_srcdir)/../../gcc/BASE-VER +DEVPHASE = $(top_srcdir)/../../gcc/DEV-PHASE + +POD2MAN = pod2man --center="GNU" --release="gcc-$(shell cat $(BASEVER))" +TEXI2POD = perl $(top_srcdir)/../../contrib/texi2pod.pl +STAMP = echo timestamp > + +# gcc-vers.texi is generated from the version files. +gcc-vers.texi: $(BASEVER) $(DEVPHASE) + (echo "@set version-GCC $(shell cat $(BASEVER))"; \ + if [ "$(shell cat $(DEVPHASE))" = "experimental" ]; \ + then echo "@set DEVELOPMENT"; \ + else echo "@clear DEVELOPMENT"; \ + fi) > $@T + mv -f $@T $@ + +%.1: %.pod + $(STAMP) $@ + -($(POD2MAN) --section=1 $< > $(@).T$$$$ && \ + mv -f $(@).T$$$$ $@) || \ + (rm -f $(@).T$$$$ && exit 1) + +.INTERMEDIATE: gappletviewer.pod gjarsigner.pod gjar.pod gjavah.pod \ + gkeytool.pod gnative2ascii.pod gorbd.pod grmid.pod grmiregistry.pod \ + gserialver.pod gtnameserv.pod + +gappletviewer.pod: $(srcdir)/cp-tools.texinfo + -$(TEXI2POD) -D gappletviewer < $< > $@ + +gjarsigner.pod: $(srcdir)/cp-tools.texinfo + -$(TEXI2POD) -D gjarsigner < $< > $@ + +gjar.pod: $(srcdir)/cp-tools.texinfo + -$(TEXI2POD) -D gjar < $< > $@ + +gjavah.pod: $(srcdir)/cp-tools.texinfo + -$(TEXI2POD) -D gjavah < $< > $@ + +# hack around the cross references and the enumeration +gkeytool.pod: $(srcdir)/cp-tools.texinfo + -$(TEXI2POD) -D gkeytool < $< > $@ + sed -i -e 's/^For more details.*/See I for more details./' \ + -e 's/1\.<\([^>]*\)>/- \1/' \ + $@ + +gnative2ascii.pod: $(srcdir)/cp-tools.texinfo + -$(TEXI2POD) -D gnative2ascii < $< > $@ + +gorbd.pod: $(srcdir)/cp-tools.texinfo + -$(TEXI2POD) -D gorbd < $< > $@ + +grmid.pod: $(srcdir)/cp-tools.texinfo + -$(TEXI2POD) -D grmid < $< > $@ + +grmiregistry.pod: $(srcdir)/cp-tools.texinfo + -$(TEXI2POD) -D grmiregistry < $< > $@ + +gserialver.pod: $(srcdir)/cp-tools.texinfo + -$(TEXI2POD) -D gserialver < $< > $@ + +gtnameserv.pod: $(srcdir)/cp-tools.texinfo + -$(TEXI2POD) -D gtnameserv < $< > $@ diff --git a/libjava/classpath/doc/Makefile.in b/libjava/classpath/doc/Makefile.in index a3b2bcb..2d52813 100644 --- a/libjava/classpath/doc/Makefile.in +++ b/libjava/classpath/doc/Makefile.in @@ -296,7 +296,27 @@ target_vendor = @target_vendor@ toolexeclibdir = @toolexeclibdir@ vm_classes = @vm_classes@ SUBDIRS = api -EXTRA_DIST = README.jaxp +EXTRA_DIST = README.jaxp $(man_MANS) + +#man_MANS = $(TOOLS_MANFILES) +TOOLS_MANFILES = \ + gappletviewer.1 \ + gjar.1 \ + gjarsigner.1 \ + gjavah.1 \ + gkeytool.1 \ + gnative2ascii.1 \ + gorbd.1 \ + grmid.1 \ + grmiregistry.1 \ + gserialver.1 \ + gtnameserv.1 + +BASEVER = $(top_srcdir)/../../gcc/BASE-VER +DEVPHASE = $(top_srcdir)/../../gcc/DEV-PHASE +POD2MAN = pod2man --center="GNU" --release="gcc-$(shell cat $(BASEVER))" +TEXI2POD = perl $(top_srcdir)/../../contrib/texi2pod.pl +STAMP = echo timestamp > all: all-recursive .SUFFIXES: @@ -612,7 +632,63 @@ uninstall-info: uninstall-info-recursive %.ps : %.dvi dvips -o $@ $< -docs: hacking.ps vmintegration.ps tools.ps +docs: cp-hacking.ps cp-vmintegration.ps cp-tools.ps + +# gcc-vers.texi is generated from the version files. +gcc-vers.texi: $(BASEVER) $(DEVPHASE) + (echo "@set version-GCC $(shell cat $(BASEVER))"; \ + if [ "$(shell cat $(DEVPHASE))" = "experimental" ]; \ + then echo "@set DEVELOPMENT"; \ + else echo "@clear DEVELOPMENT"; \ + fi) > $@T + mv -f $@T $@ + +%.1: %.pod + $(STAMP) $@ + -($(POD2MAN) --section=1 $< > $(@).T$$$$ && \ + mv -f $(@).T$$$$ $@) || \ + (rm -f $(@).T$$$$ && exit 1) + +.INTERMEDIATE: gappletviewer.pod gjarsigner.pod gjar.pod gjavah.pod \ + gkeytool.pod gnative2ascii.pod gorbd.pod grmid.pod grmiregistry.pod \ + gserialver.pod gtnameserv.pod + +gappletviewer.pod: $(srcdir)/cp-tools.texinfo + -$(TEXI2POD) -D gappletviewer < $< > $@ + +gjarsigner.pod: $(srcdir)/cp-tools.texinfo + -$(TEXI2POD) -D gjarsigner < $< > $@ + +gjar.pod: $(srcdir)/cp-tools.texinfo + -$(TEXI2POD) -D gjar < $< > $@ + +gjavah.pod: $(srcdir)/cp-tools.texinfo + -$(TEXI2POD) -D gjavah < $< > $@ + +# hack around the cross references and the enumeration +gkeytool.pod: $(srcdir)/cp-tools.texinfo + -$(TEXI2POD) -D gkeytool < $< > $@ + sed -i -e 's/^For more details.*/See I for more details./' \ + -e 's/1\.<\([^>]*\)>/- \1/' \ + $@ + +gnative2ascii.pod: $(srcdir)/cp-tools.texinfo + -$(TEXI2POD) -D gnative2ascii < $< > $@ + +gorbd.pod: $(srcdir)/cp-tools.texinfo + -$(TEXI2POD) -D gorbd < $< > $@ + +grmid.pod: $(srcdir)/cp-tools.texinfo + -$(TEXI2POD) -D grmid < $< > $@ + +grmiregistry.pod: $(srcdir)/cp-tools.texinfo + -$(TEXI2POD) -D grmiregistry < $< > $@ + +gserialver.pod: $(srcdir)/cp-tools.texinfo + -$(TEXI2POD) -D gserialver < $< > $@ + +gtnameserv.pod: $(srcdir)/cp-tools.texinfo + -$(TEXI2POD) -D gtnameserv < $< > $@ # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: diff --git a/libjava/classpath/doc/cp-hacking.texinfo b/libjava/classpath/doc/cp-hacking.texinfo new file mode 100644 index 0000000..efb7aa9 --- /dev/null +++ b/libjava/classpath/doc/cp-hacking.texinfo @@ -0,0 +1,1733 @@ +\input texinfo @c -*-texinfo-*- + +@c %**start of header +@setfilename hacking.info +@settitle GNU Classpath Hacker's Guide +@c %**end of header + +@setchapternewpage off + +@ifinfo +This file contains important information you will need to know if you +are going to hack on the GNU Classpath project code. + +Copyright (C) 1998,1999,2000,2001,2002,2003,2004, 2005 Free Software Foundation, Inc. + +@ifnotplaintext +@dircategory GNU Libraries +@direntry +* Classpath Hacking: (hacking). GNU Classpath Hacker's Guide +@end direntry +@end ifnotplaintext +@end ifinfo + +@titlepage +@title GNU Classpath Hacker's Guide +@author Aaron M. Renn +@author Paul N. Fisher +@author John Keiser +@author C. Brian Jones +@author Mark J. Wielaard + +@page +@vskip 0pt plus 1filll +Copyright @copyright{} 1998,1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc. +@sp 2 +Permission is granted to make and distribute verbatim copies of +this document provided the copyright notice and this permission notice +are preserved on all copies. + +Permission is granted to copy and distribute modified versions of this +document under the conditions for verbatim copying, provided that the +entire resulting derived work is distributed under the terms of a +permission notice identical to this one. + +Permission is granted to copy and distribute translations of this manual +into another language, under the above conditions for modified versions, +except that this permission notice may be stated in a translation +approved by the Free Software Foundation. + +@end titlepage + +@ifinfo +@node Top, Introduction, (dir), (dir) +@top GNU Classpath Hacker's Guide + +This document contains important information you'll want to know if +you want to hack on GNU Classpath, Essential Libraries for Java, to +help create free core class libraries for use with virtual machines +and compilers for the java programming language. +@end ifinfo + +@menu +* Introduction:: An introduction to the GNU Classpath project +* Requirements:: Very important rules that must be followed +* Volunteering:: So you want to help out +* Project Goals:: Goals of the GNU Classpath project +* Needed Tools and Libraries:: A list of programs and libraries you will need +* Programming Standards:: Standards to use when writing code +* Hacking Code:: Working on code, Working with others +* Programming Goals:: What to consider when writing code +* API Compatibility:: How to handle serialization and deprecated methods +* Specification Sources:: Where to find class library specs +* Naming Conventions:: How files and directories are named +* Character Conversions:: Working on Character conversions +* Localization:: How to handle localization/internationalization + +@detailmenu + --- The Detailed Node Listing --- + +Programming Standards + +* Source Code Style Guide:: + +Working on the code, Working with others + +* Branches:: +* Writing ChangeLogs:: + +Working with branches + +* Writing ChangeLogs:: + +Programming Goals + +* Portability:: Writing Portable Software +* Utility Classes:: Reusing Software +* Robustness:: Writing Robust Software +* Java Efficiency:: Writing Efficient Java +* Native Efficiency:: Writing Efficient JNI +* Security:: Writing Secure Software + +API Compatibility + +* Serialization:: Serialization +* Deprecated Methods:: Deprecated methods + +Localization + +* String Collation:: Sorting strings in different locales +* Break Iteration:: Breaking up text into words, sentences, and lines +* Date Formatting and Parsing:: Locale specific date handling +* Decimal/Currency Formatting and Parsing:: Local specific number handling + +@end detailmenu +@end menu + +@node Introduction, Requirements, Top, Top +@comment node-name, next, previous, up +@chapter Introduction + +The GNU Classpath Project is a dedicated to providing a 100% free, +clean room implementation of the standard core class libraries for +compilers and runtime environments for the java programming language. +It offers free software developers an alternative core library +implementation upon which larger java-like programming environments +can be build. The GNU Classpath Project was started in the Spring of +1998 as an official Free Software Foundation project. Most of the +volunteers working on GNU Classpath do so in their spare time, but a +couple of projects based on GNU Classpath have paid programmers to +improve the core libraries. We appreciate everyone's efforts in the +past to improve and help the project and look forward to future +contributions by old and new members alike. + +@node Requirements, Volunteering, Introduction, Top +@comment node-name, next, previous, up +@chapter Requirements + +Although GNU Classpath is following an open development model where input +from developers is welcome, there are certain base requirements that +need to be met by anyone who wants to contribute code to this project. +They are mostly dictated by legal requirements and are not arbitrary +restrictions chosen by the GNU Classpath team. + +You will need to adhere to the following things if you want to donate +code to the GNU Classpath project: + +@itemize @bullet +@item +@strong{Never under any circumstances refer to proprietary code while +working on GNU Classpath.} It is best if you have never looked at +alternative proprietary core library code at all. To reduce +temptation, it would be best if you deleted the @file{src.zip} file +from your proprietary JDK distribution (note that recent versions of +GNU Classpath and the compilers and environments build on it are +mature enough to not need any proprietary implementation at all when +working on GNU Classpath, except in exceptional cases where you need +to test compatibility issues pointed out by users). If you have +signed Sun's non-disclosure statement, then you unfortunately cannot +work on Classpath code at all. If you have any reason to believe that +your code might be ``tainted'', please say something on the mailing +list before writing anything. If it turns out that your code was not +developed in a clean room environment, we could be very embarrassed +someday in court. Please don't let that happen. + +@item +@strong{Never decompile proprietary class library implementations.} While +the wording of the license in Sun's Java 2 releases has changed, it is +not acceptable, under any circumstances, for a person working on +GNU Classpath to decompile Sun's class libraries. Allowing the use of +decompilation in the GNU Classpath project would open up a giant can of +legal worms, which we wish to avoid. + +@item +Classpath is licensed under the terms of the +@uref{http://www.fsf.org/copyleft/gpl.html,GNU General Public +License}, with a special exception included to allow linking with +non-GPL licensed works as long as no other license would restrict such +linking. To preserve freedom for all users and to maintain uniform +licensing of Classpath, we will not accept code into the main +distribution that is not licensed under these terms. The exact +wording of the license of the current version of GNU Classpath can be +found online from the +@uref{http://www.gnu.org/software/classpath/license.html, GNU +Classpath license page} and is of course distributed with current +snapshot release from @uref{ftp://ftp.gnu.org/gnu/classpath/} or by +obtaining a copy of the current CVS tree. + +@item +GNU Classpath is GNU software and this project is being officially sponsored +by the @uref{http://www.fsf.org/,Free Software Foundation}. Because of +this, the FSF will hold copyright to all code developed as part of +GNU Classpath. This will allow them to pursue copyright violators in court, +something an individual developer may neither have the time nor +resources to do. Everyone contributing code to GNU Classpath will need to +sign a copyright assignment statement. Additionally, if you are +employed as a programmer, your employer may need to sign a copyright +waiver disclaiming all interest in the software. This may sound harsh, +but unfortunately, it is the only way to ensure that the code you write +is legally yours to distribute. +@end itemize + +@node Volunteering, Project Goals, Requirements, Top +@comment node-name, next, previous, up +@chapter Volunteering to Help + +The GNU Classpath project needs volunteers to help us out. People are +needed to write unimplemented core packages, to test GNU Classpath on +free software programs written in the java programming language, to +test it on various platforms, and to port it to platforms that are +currently unsupported. + +While pretty much all contributions are welcome (but see +@pxref{Requirements}) it is always preferable that volunteers do the +whole job when volunteering for a task. So when you volunteer to write +a Java package, please be willing to do the following: + +@itemize @bullet +@item +Implement a complete drop-in replacement for the particular package. +That means implementing any ``internal'' classes. For example, in the +java.net package, there are non-public classes for implementing sockets. +Without those classes, the public socket interface is useless. But do +not feel obligated to completely implement all of the functionality at +once. For example, in the java.net package, there are different types +of protocol handlers for different types of URL's. Not all of these +need to be written at once. + +@item +Please write complete and thorough API documentation comments for +every public and protected method and variable. These should be +superior to Sun's and cover everything about the item being +documented. + +@item +Please write a regression test package that can be used to run tests +of your package's functionality. GNU Classpath uses the +@uref{http://sources.redhat.com/mauve/,Mauve project} for testing the +functionality of the core class libraries. The Classpath Project is +fast approaching the point in time where all modifications to the +source code repository will require appropriate test cases in Mauve to +ensure correctness and prevent regressions. +@end itemize + +Writing good documentation, tests and fixing bugs should be every +developer's top priority in order to reach the elusive release of +version 1.0. + +@node Project Goals, Needed Tools and Libraries, Volunteering, Top +@comment node-name, next, previous, up +@chapter Project Goals + +The goal of the Classpath project is to produce a +@uref{http://www.fsf.org/philosophy/free-sw.html,free} implementation of +the standard class library for Java. However, there are other more +specific goals as to which platforms should be supported. + +Classpath is targeted to support the following operating systems: + +@enumerate +@item +Free operating systems. This includes GNU/Linux, GNU/Hurd, and the free +BSDs. + +@item +Other Unix-like operating systems. + +@item +Platforms which currently have no Java support at all. + +@item +Other platforms such as MS-Windows. +@end enumerate + +While free operating systems are the top priority, the other priorities +can shift depending on whether or not there is a volunteer to port +Classpath to those platforms and to test releases. + +Eventually we hope the Classpath will support all JVM's that provide +JNI or CNI support. However, the top priority is free JVM's. A small +list of Compiler/VM environments that are currently actively +incorporating GNU Classpath is below. A more complete overview of +projects based on GNU classpath can be found online at +@uref{http://www.gnu.org/software/classpath/stories.html,the GNU +Classpath stories page}. + +@enumerate +@item +@uref{http://gcc.gnu.org/java/,GCJ} +@item +@uref{http://jamvm.sourceforge.net/,jamvm} +@item +@uref{http://kissme.sourceforge.net/,Kissme} +@item +@uref{http://www.ibm.com/developerworks/oss/jikesrvm/,Jikes RVM} +@item +@uref{http://www.sablevm.org/,SableVM} +@item +@uref{http://www.kaffe.org/,Kaffe} +@end enumerate + +As with OS platform support, this priority list could change if a +volunteer comes forward to port, maintain, and test releases for a +particular JVM. Since gcj is part of the GNU Compiler Collective it +is one of the most important targets. But since it doesn't currently +work out of the box with GNU Classpath it is currently not the easiest +target. When hacking on GNU Classpath the easiest is to use +compilers and runtime environments that that work out of the box with +it, such as the jikes compiler and the runtime environments jamvm and +kissme. But you can also work directly with targets like gcj and +kaffe that have their own copy of GNU Classpath currently. In that +case changes have to be merged back into GNU Classpath proper though, +which is sometimes more work. SableVM is starting to migrate from an +integrated GNU Classpath version to being usable with GNU Classpath +out of the box. + + +The initial target version for Classpath is the 1.1 spec. Higher +versions can be implemented (and have been implemented, including lots +of 1.4 functionality) if desired, but please do not create classes +that depend on features in those packages unless GNU Classpath already +contains those features. GNU Classpath has been free of any +proprietary dependencies for a long time now and we like to keep it +that way. But finishing, polishing up, documenting, testing and +debugging current functionality is of higher priority then adding new +functionality. + +@node Needed Tools and Libraries, Programming Standards, Project Goals, Top +@comment node-name, next, previous, up +@chapter Needed Tools and Libraries + +If you want to hack on Classpath, you should at least download and +install the following tools. And try to familiarize yourself with +them. Although in most cases having these tools installed will be all +you really need to know about them. Also note that when working on +(snapshot) releases only GCC 3.3+ (plus a free VM from the list above +and the libraries listed below) is needed. The other tools are only +needed when working directly on the CVS version. + +@itemize @bullet +@item +GCC 3.3+ +@item +CVS 1.11+ +@item +automake 1.7+ +@item +autoconf 2.59+ +@item +libtool 1.4.2+ +@item +GNU m4 1.4 +@item +texinfo 4.2+ +@end itemize + +All of these tools are available from +@uref{ftp://gnudist.gnu.org/pub/gnu/,gnudist.gnu.org} via anonymous +ftp, except CVS which is available from +@uref{http://www.cvshome.org/,www.cvshome.org}. They are fully +documented with texinfo manuals. Texinfo can be browsed with the +Emacs editor, or with the text editor of your choice, or transformed +into nicely printable Postscript. + +Here is a brief description of the purpose of those tools. + +@table @b + +@item GCC +The GNU Compiler Collection. This contains a C compiler (gcc) for +compiling the native C code and a compiler for the java programming +language (gcj). You will need at least gcj version 3.3 or higher. If +that version is not available for your platform you can try the +@uref{http://www.jikes.org/, jikes compiler}. We try to keep all code +compilable with both gcj and jikes at all times. + +@item CVS +A version control system that maintains a centralized Internet +repository of all code in the Classpath system. + +@item automake +This tool automatically creates Makefile.in files from Makefile.am +files. The Makefile.in is turned into a Makefile by autoconf. Why +use this? Because it automatically generates every makefile target +you would ever want (clean, install, dist, etc) in full compliance +with the GNU coding standards. It also simplifies Makefile creation +in a number of ways that cannot be described here. Read the docs for +more info. + +@item autoconf +Automatically configures a package for the platform on which it is +being built and generates the Makefile for that platform. + +@item libtool +Handles all of the zillions of hairy platform specific options needed +to build shared libraries. + +@item m4 +The free GNU replacement for the standard Unix macro processor. +Proprietary m4 programs are broken and so GNU m4 is required for +autoconf to work though knowing a lot about GNU m4 is not required to +work with autoconf. + +@item perl +Larry Wall's scripting language. It is used internally by automake. + +@item texinfo +Manuals and documentation (like this guide) are written in texinfo. +Texinfo is the official documentation format of the GNU project. +Texinfo uses a single source file to produce output in a number of formats, +both online and printed (dvi, info, html, xml, etc.). This means that +instead of writing different documents for online information and another +for a printed manual, you need write only one document. And when the work +is revised, you need revise only that one document. + +@end table + + +For compiling the native AWT libraries you need to have the following +libraries installed: + +@table @b +@item GTK+ 2.2.x +@uref{http://www.gtk.org/,GTK+} is a multi-platform toolkit for +creating graphical user interfaces. It is used as the basis of the +GNU desktop project GNOME. + +@item gdk-pixbuf +@uref{http://www.gnome.org/start/,gdk-pixbuf} is a GNOME library for +representing images. +@end table + + +GNU Classpath comes with a couple of libraries included in the source +that are not part of GNU Classpath proper, but that have been included +to provide certain needed functionality. All these external libraries +should be clearly marked as such. In general we try to use as much as +possible the clean upstream versions of these sources. That way +merging in new versions will be easiest. You should always try to get +bug fixes to these files accepted upstream first. Currently we +include the following 'external' libraries. Most of these sources are +included in the @file{external} directory. That directory also +contains a @file{README} file explaining how to import newer versions. + +@table @b + +@item GNU jaxp +Can be found in @file{external/jaxp}. Provides javax.xml, org.w3c and +org.xml packages. Upstream is +@uref{http://www.gnu.org/software/classpathx/,GNU ClasspathX}. + +@item fdlibm +Can be found in @file{native/fdlibm}. Provides native implementations +of some of the Float and Double operations. Upstream is +@uref{http://gcc.gnu.org/java/,libgcj}, they sync again with the +'real' upstream @uref{http://www.netlib.org/fdlibm/readme}. See also +java.lang.StrictMath. + +@end table + + +@node Programming Standards, Hacking Code, Needed Tools and Libraries, Top +@comment node-name, next, previous, up +@chapter Programming Standards + +For C source code, follow the +@uref{http://www.gnu.org/prep/standards/,GNU Coding Standards}. +The standards also specify various things like the install directory +structure. These should be followed if possible. + +For Java source code, please follow the +@uref{http://www.gnu.org/prep/standards/,GNU Coding +Standards}, as much as possible. There are a number of exceptions to +the GNU Coding Standards that we make for GNU Classpath as documented +in this guide. We will hopefully be providing developers with a code +formatting tool that closely matches those rules soon. + +For API documentation comments, please follow +@uref{http://java.sun.com/products/jdk/javadoc/writingdoccomments.html,How +to Write Doc Comments for Javadoc}. We would like to have a set of +guidelines more tailored to GNU Classpath as part of this document. + +@menu +* Source Code Style Guide:: +@end menu + +@node Source Code Style Guide, , Programming Standards, Programming Standards +@comment node-name, next, previous, up +@section Java source coding style + +Here is a list of some specific rules used when hacking on GNU +Classpath java source code. We try to follow the standard +@uref{http://www.gnu.org/prep/standards/,GNU Coding Standards} +for that. There are lots of tools that can automatically generate it +(although most tools assume C source, not java source code) and it +seems as good a standard as any. There are a couple of exceptions and +specific rules when hacking on GNU Classpath java source code however. +The following lists how code is formatted (and some other code +conventions): + + +@itemize @bullet + +@item +Java source files in GNU Classpath are encoded using UTF-8. However, +ordinarily it is considered best practice to use the ASCII subset of +UTF-8 and write non-ASCII characters using \u escapes. + +@item +If possible, generate specific imports (expand) over java.io.* type +imports. Order by gnu, java, javax, org. There must be one blank line +between each group. The imports themselves are ordered alphabetically by +package name. Classes and interfaces occur before sub-packages. The +classes/interfaces are then also sorted alphabetical. Note that uppercase +characters occur before lowercase characters. + +@example +import gnu.java.awt.EmbeddedWindow; + +import java.io.IOException; +import java.io.InputStream; + +import javax.swing.JFrame; +@end example + +@item +Blank line after package statement, last import statement, classes, +interfaces, methods. + +@item +Opening/closing brace for class and method is at the same level of +indent as the declaration. All other braces are indented and content +between braces indented again. + +@item +Since method definitions don't start in column zero anyway (since they +are always inside a class definition), the rational for easy grepping +for ``^method_def'' is mostly gone already. Since it is customary for +almost everybody who writes java source code to put modifiers, return +value and method name on the same line, we do too. + +@c fixme Another rational for always indenting the method definition is that itmakes it a bit easier to distinguish methods in inner and anonymousclasses from code in their enclosing context. NEED EXAMPLE. + +@item +Implements and extends on separate lines, throws too. Indent extends, +implements, throws. Apply deep indentation for method arguments. + +@c fixme Needs example. + +@item +Don't add a space between a method or constructor call/definition and +the open-bracket. This is because often the return value is an object on +which you want to apply another method or from which you want to access +a field. + +Don't write: + +@example + getToolkit ().createWindow (this); +@end example + +But write: +@example + getToolkit().createWindow(this); +@end example + +@item +The GNU Coding Standard it gives examples for almost every construct +(if, switch, do, while, etc.). One missing is the try-catch construct +which should be formatted as: + +@example + try + @{ + // + @} + catch (...) + @{ + // + @} +@end example + +@item +Wrap lines at 80 characters after assignments and before operators. +Wrap always before extends, implements, throws, and labels. + +@item +Don't put multiple class definitions in the same file, except for +inner classes. File names (plus .java) and class names should be the +same. + +@item +Don't catch a @code{NullPointerException} as an alternative to simply +checking for @code{null}. It is clearer and usually more efficient +to simply write an explicit check. + +For instance, don't write: + +@example +try + @{ + return foo.doit(); + @} +catch (NullPointerException _) + @{ + return 7; + @} +@end example + +If your intent above is to check whether @samp{foo} is @code{null}, +instead write: + +@example +if (foo == null) + return 7; +else + return foo.doit(); +@end example + +@item +Don't use redundant modifiers or other redundant constructs. Here is +some sample code that shows various redundant items in comments: + +@example +/*import java.lang.Integer;*/ +/*abstract*/ interface I @{ + /*public abstract*/ void m(); + /*public static final*/ int i = 1; + /*public static*/ class Inner @{@} +@} +final class C /*extends Object*/ @{ + /*final*/ void m() @{@} +@} +@end example + +Note that Jikes will generate warnings for redundant modifiers if you +use @code{+Predundant-modifiers} on the command line. + +@item +Modifiers should be listed in the standard order recommended by the +JLS. Jikes will warn for this when given @code{+Pmodifier-order}. + +@item +Because the output of different compilers differs, we have +standardized on explicitly specifying @code{serialVersionUID} in +@code{Serializable} classes in Classpath. This field should be +declared as @code{private static final}. Note that a class may be +@code{Serializable} without being explicitly marked as such, due to +inheritance. For instance, all subclasses of @code{Throwable} need to +have @code{serialVersionUID} declared. +@c fixme index +@c fixme link to the discussion + +@item +Don't declare unchecked exceptions in the @code{throws} clause of a +method. However, if throwing an unchecked exception is part of the +method's API, you should mention it in the Javadoc. There is one +important exception to this rule, which is that a stub method should +be marked as throwing @code{gnu.classpath.NotImplementedException}. +This will let our API comparison tools note that the method is not +fully implemented. + +@item +When overriding @code{Object.equals}, remember that @code{instanceof} +filters out @code{null}, so an explicit check is not needed. + +@item +When catching an exception and rethrowing a new exception you should +``chain'' the Throwables. Don't just add the String representation of +the caught exception. + +@example + try + @{ + // Some code that can throw + @} + catch (IOException ioe) + @{ + throw (SQLException) new SQLException("Database corrupt").setCause(ioe); + @} +@end example + +@item +Avoid the use of reserved words for identifiers. This is obvious with those +such as @code{if} and @code{while} which have always been part of the Java +programming language, but you should be careful about accidentally using +words which have been added in later versions. Notable examples are +@code{assert} (added in 1.4) and @code{enum} (added in 1.5). Jikes will warn +of the use of the word @code{enum}, but, as it doesn't yet support the 1.5 +version of the language, it will still allow this usage through. A +compiler which supports 1.5 (e.g. the Eclipse compiler, ecj) will simply +fail to compile the offending source code. + +@c fixme Describe Anonymous classes (example). +@c fixme Descibe Naming conventions when different from GNU Coding Standards. +@c fixme Describee API doc javadoc tags used. + +@end itemize + +Some things are the same as in the normal GNU Coding Standards: + +@itemize @bullet + +@item +Unnecessary braces can be removed, one line after an if, for, while as +examples. + +@item +Space around operators (assignment, logical, relational, bitwise, +mathematical, shift). + +@item +Blank line before single-line comments, multi-line comments, javadoc +comments. + +@item +If more than 2 blank lines, trim to 2. + +@item +Don't keep commented out code. Just remove it or add a real comment +describing what it used to do and why it is changed to the current +implementation. +@end itemize + + +@node Hacking Code, Programming Goals, Programming Standards, Top +@comment node-name, next, previous, up +@chapter Working on the code, Working with others + +There are a lot of people helping out with GNU Classpath. Here are a +couple of practical guidelines to make working together on the code +smoother. + +The main thing is to always discuss what you are up to on the +mailinglist. Making sure that everybody knows who is working on what +is the most important thing to make sure we cooperate most +effectively. + +We maintain a +@uref{http://www.gnu.org/software/classpath/tasks.html,Task List} +which contains items that you might want to work on. + +Before starting to work on something please make sure you read this +complete guide. And discuss it on list to make sure your work does +not duplicate or interferes with work someone else is already doing. +Always make sure that you submit things that are your own work. And +that you have paperwork on file (as stated in the requirements +section) with the FSF authorizing the use of your additions. + +Technically the GNU Classpath project is hosted on +@uref{http://savannah.gnu.org/,Savannah} a central point for +development, distribution and maintenance of GNU Software. Here you +will find the +@uref{https://savannah.gnu.org/projects/classpath/,project page}, bug +reports, pending patches, links to mailing lists, news items and CVS. + +You can find instructions on getting a CVS checkout for classpath at +@uref{https://savannah.gnu.org/cvs/?group=classpath}. + +You don't have to get CVS commit write access to contribute, but it is +sometimes more convenient to be able to add your changes directly to +the project CVS. Please contact the GNU Classpath savannah admins to +arrange CVS access if you would like to have it. + +Make sure to be subscribed to the commit-classpath mailinglist while +you are actively hacking on Classpath. You have to send patches (cvs +diff -uN) to this list before committing. + +We really want to have a pretty open check-in policy. But this means +that you should be extra careful if you check something in. If at all +in doubt or if you think that something might need extra explaining +since it is not completely obvious please make a little announcement +about the change on the mailinglist. And if you do commit something +without discussing it first and another GNU Classpath hackers asks for +extra explanation or suggests to revert a certain commit then please +reply to the request by explaining why something should be so or if +you agree to revert it. (Just reverting immediately is OK without +discussion, but then please don't mix it with other changes and please +say so on list.) + +Patches that are already approved for libgcj or also OK for Classpath. +(But you still have to send a patch/diff to the list.) All other +patches require you to think whether or not they are really OK and +non-controversial, or if you would like some feedback first on them +before committing. We might get real commit rules in the future, for +now use your own judgment, but be a bit conservative. + +Always contact the GNU Classpath maintainer before adding anything +non-trivial that you didn't write yourself and that does not come from +libgcj or from another known GNU Classpath or libgcj hacker. If you +have been assigned to commit changes on behalf of another project or +a company always make sure they come from people who have signed the +papers for the FSF and/or fall under the arrangement your company made +with the FSF for contributions. Mention in the ChangeLog who actually +wrote the patch. + +Commits for completely unrelated changes they should be committed +separately (especially when doing a formatting change and a logical +change, do them in two separate commits). But do try to do a commit of +as much things/files that are done at the same time which can +logically be seen as part of the same change/cleanup etc. + +When the change fixes an important bug or adds nice new functionality +please write a short entry for inclusion in the @file{NEWS} file. If it +changes the VM interface you must mention that in both the @file{NEWS} file +and the VM Integration Guide. + +All the ``rules'' are really meant to make sure that GNU Classpath +will be maintainable in the long run and to give all the projects that +are now using GNU Classpath an accurate view of the changes we make to +the code and to see what changed when. If you think the requirements +are ``unworkable'' please try it first for a couple of weeks. If you +still feel the same after having some more experience with the project +please feel free to bring up suggestions for improvements on the list. +But don't just ignore the rules! Other hackers depend on them being +followed to be the most productive they can be (given the above +constraints). + +@menu +* Branches:: +* Writing ChangeLogs:: +@end menu + +@node Branches, Writing ChangeLogs, Hacking Code, Hacking Code +@comment node-name, next, previous, up +@section Working with branches + +Sometimes it is necessary to create branch of the source for doing new +work that is disruptive to the other hackers, or that needs new +language or libraries not yet (easily) available. + +After discussing the need for a branch on the main mailinglist with +the other hackers explaining the need of a branch and suggestion of +the particular branch rules (what will be done on the branch, who will +work on it, will there be different commit guidelines then for the +mainline trunk and when is the branch estimated to be finished and +merged back into the trunk) every GNU Classpath hacker with commit +access should feel free to create a branch. There are however a couple +of rules that every branch should follow: + +@itemize @bullet + +@item All branches ought to be documented in the developer wiki at +@uref{http://developer.classpath.org/mediation/ClasspathBranches}, so +we can know which are live, who owns them, and when they die. + +@item Some rules can be changed on a branch. In particular the branch +maintainer can change the review requirements, and the requirement of +keeping things building, testing, etc, can also be lifted. (These +should be documented along with the branch name and owner if they +differ from the trunk.) + +@item Requirements for patch email to classpath-patches and for paperwork +@strong{cannot} be lifted. See @ref{Requirements}. + +@item A branch should not be seen as ``private'' or +``may be completely broken''. It should be as much as possible +something that you work on with a team (and if there is no team - yet +- then there is nothing as bad as having a completely broken build to +get others to help out). There can of course be occasional breakage, but +it should be planned and explained. And you can certainly have a rule +like ``please ask me before committing to this branch''. + +@item Merges from the trunk to a branch are at the discretion of the +branch maintainer. + +@item A merge from a branch to the trunk is treated like any other patch. +In particular, it has to go through review, it must satisfy all the +trunk requirements (build, regression test, documentation). + +@item There may be additional timing requirements on merging a branch to +the trunk depending on the release schedule, etc. For instance we may +not want to do a branch merge just before a release. + +@end itemize + +If any of these rules are unclear please discuss on the list first. + +@menu +* Writing ChangeLogs:: +@end menu + +@node Writing ChangeLogs, , Branches, Hacking Code +@comment node-name, next, previous, up +@section Documenting what changed when with ChangeLog entries + +To keep track of who did what when we keep an explicit ChangeLog entry +together with the code. This mirrors the CVS commit messages and in +general the ChangeLog entry is the same as the CVS commit message. +This provides an easy way for people getting a (snapshot) release or +without access to the CVS server to see what happened when. We do not +generate the ChangeLog file automatically from the CVS server since +that is not reliable. + +A good ChangeLog entry guideline can be found in the Guile Manual at +@uref{http://www.gnu.org/software/guile/changelogs/guile-changelogs_3.html}. + +Here are some example to explain what should or shouldn't be in a +ChangeLog entry (and the corresponding commit message): + +@itemize @bullet + +@item +The first line of a ChangeLog entry should be: + +@example +[date] [full name] [email-contact] +@end example + +The second line should be blank. All other lines should be indented +with one tab. + +@item +Just state what was changed. Why something is done as it is done in +the current code should be either stated in the code itself or be +added to one of the documentation files (like this Hacking Guide). + +So don't write: + +@example + * java/awt/font/OpenType.java: Remove 'public static final' + from OpenType tags, reverting the change of 2003-08-11. See + Classpath discussion list of 2003-08-11. +@end example + +Just state: + +@example + * java/awt/font/OpenType.java: Remove 'public static final' from + all member fields. +@end example + +In this case the reason for the change was added to this guide. + +@item +Just as with the normal code style guide, don't make lines longer then +80 characters. + +@item +Just as with comments in the code. The ChangeLog entry should be a +full sentence, starting with a captital and ending with a period. + +@item +Be precise in what changed, not the effect of the change (which should +be clear from the code/patch). So don't write: + +@example + * java/io/ObjectOutputStream.java : Allow putFields be called more + than once. +@end example + +But explain what changed and in which methods it was changed: + +@example + * java/io/ObjectOutputStream.java (putFields): Don't call + markFieldsWritten(). Only create new PutField when + currentPutField is null. + (writeFields): Call markFieldsWritten(). +@end example + +@end itemize + +The above are all just guidelines. We all appreciate the fact that writing +ChangeLog entries, using a coding style that is not ``your own'' and the +CVS, patch and diff tools do take some time to getting used to. So don't +feel like you have to do it perfect right away or that contributions +aren't welcome if they aren't ``perfect''. We all learn by doing and +interacting with each other. + + +@node Programming Goals, API Compatibility, Hacking Code, Top +@comment node-name, next, previous, up +@chapter Programming Goals + +When you write code for Classpath, write with three things in mind, and +in the following order: portability, robustness, and efficiency. + +If efficiency breaks portability or robustness, then don't do it the +efficient way. If robustness breaks portability, then bye-bye robust +code. Of course, as a programmer you would probably like to find sneaky +ways to get around the issue so that your code can be all three ... the +following chapters will give some hints on how to do this. + +@menu +* Portability:: Writing Portable Software +* Utility Classes:: Reusing Software +* Robustness:: Writing Robust Software +* Java Efficiency:: Writing Efficient Java +* Native Efficiency:: Writing Efficient JNI +* Security:: Writing Secure Software +@end menu + +@node Portability, Utility Classes, Programming Goals, Programming Goals +@comment node-name, next, previous, up +@section Portability + +The portability goal for Classpath is the following: + +@enumerate +@item +native functions for each platform that work across all VMs on that +platform +@item +a single classfile set that work across all VMs on all platforms that +support the native functions. +@end enumerate + +For almost all of Classpath, this is a very feasible goal, using a +combination of JNI and native interfaces. This is what you should shoot +for. For those few places that require knowledge of the Virtual Machine +beyond that provided by the Java standards, the VM Interface was designed. +Read the Virtual Machine Integration Guide for more information. + +Right now the only supported platform is Linux. This will change as that +version stabilizes and we begin the effort to port to many other +platforms. Jikes RVM runs Classpath on AIX, and generally the Jikes +RVM team fixes Classpath to work on that platform. + +@node Utility Classes, Robustness, Portability, Programming Goals +@comment node-name, next, previous, up +@section Utility Classes + +At the moment, we are not very good at reuse of the JNI code. There +have been some attempts, called @dfn{libclasspath}, to +create generally useful utility classes. The utility classes are in +the directory @file{native/jni/classpath} and they are mostly declared +in @file{native/jni/classpath/jcl.h}. These utility classes are +currently only discussed in @ref{Robustness} and in @ref{Native +Efficiency}. + +There are more utility classes available that could be factored out if +a volunteer wants something nice to hack on. The error reporting and +exception throwing functions and macros in +@file{native/jni/gtk-peer/gthread-jni.c} might be good +candidates for reuse. There are also some generally useful utility +functions in @file{gnu_java_awt_peer_gtk_GtkMainThread.c} that could +be split out and put into libclasspath. + +@node Robustness, Java Efficiency, Utility Classes, Programming Goals +@comment node-name, next, previous, up +@section Robustness + +Native code is very easy to make non-robust. (That's one reason Java is +so much better!) Here are a few hints to make your native code more +robust. + +Always check return values for standard functions. It's sometimes easy +to forget to check that malloc() return for an error. Don't make that +mistake. (In fact, use JCL_malloc() in the jcl library instead--it will +check the return value and throw an exception if necessary.) + +Always check the return values of JNI functions, or call +@code{ExceptionOccurred} to check whether an error occurred. You must +do this after @emph{every} JNI call. JNI does not work well when an +exception has been raised, and can have unpredictable behavior. + +Throw exceptions using @code{JCL_ThrowException}. This guarantees that if +something is seriously wrong, the exception text will at least get out +somewhere (even if it is stderr). + +Check for null values of @code{jclass}es before you send them to JNI functions. +JNI does not behave nicely when you pass a null class to it: it +terminates Java with a "JNI Panic." + +In general, try to use functions in @file{native/jni/classpath/jcl.h}. They +check exceptions and return values and throw appropriate exceptions. + +@node Java Efficiency, Native Efficiency, Robustness, Programming Goals +@comment node-name, next, previous, up +@section Java Efficiency + +For methods which explicitly throw a @code{NullPointerException} when an +argument is passed which is null, per a Sun specification, do not write +code like: + +@example +int +strlen (String foo) throws NullPointerException +@{ + if (foo == null) + throw new NullPointerException ("foo is null"); + return foo.length (); +@} +@end example + +Instead, the code should be written as: + +@example +int +strlen (String foo) throws NullPointerException +@{ + return foo.length (); +@} +@end example + +Explicitly comparing foo to null is unnecessary, as the virtual machine +will throw a NullPointerException when length() is invoked. Classpath +is designed to be as fast as possible -- every optimization, no matter +how small, is important. + +@node Native Efficiency, Security, Java Efficiency, Programming Goals +@comment node-name, next, previous, up +@section Native Efficiency + +You might think that using native methods all over the place would give +our implementation of Java speed, speed, blinding speed. You'd be +thinking wrong. Would you believe me if I told you that an empty +@emph{interpreted} Java method is typically about three and a half times +@emph{faster} than the equivalent native method? + +Bottom line: JNI is overhead incarnate. In Sun's implementation, even +the JNI functions you use once you get into Java are slow. + +A final problem is efficiency of native code when it comes to things +like method calls, fields, finding classes, etc. Generally you should +cache things like that in static C variables if you're going to use them +over and over again. GetMethodID(), GetFieldID(), and FindClass() are +@emph{slow}. Classpath provides utility libraries for caching methodIDs +and fieldIDs in @file{native/jni/classpath/jnilink.h}. Other native data can +be cached between method calls using functions found in +@file{native/jni/classpath/native_state.h}. + +Here are a few tips on writing native code efficiently: + +Make as few native method calls as possible. Note that this is not the +same thing as doing less in native method calls; it just means that, if +given the choice between calling two native methods and writing a single +native method that does the job of both, it will usually be better to +write the single native method. You can even call the other two native +methods directly from your native code and not incur the overhead of a +method call from Java to C. + +Cache @code{jmethodID}s and @code{jfieldID}s wherever you can. String +lookups are +expensive. The best way to do this is to use the +@file{native/jni/classpath/jnilink.h} +library. It will ensure that @code{jmethodID}s are always valid, even if the +class is unloaded at some point. In 1.1, jnilink simply caches a +@code{NewGlobalRef()} to the method's underlying class; however, when 1.2 comes +along, it will use a weak reference to allow the class to be unloaded +and then re-resolve the @code{jmethodID} the next time it is used. + +Cache classes that you need to access often. jnilink will help with +this as well. The issue here is the same as the methodID and fieldID +issue--how to make certain the class reference remains valid. + +If you need to associate native C data with your class, use Paul +Fisher's native_state library (NSA). It will allow you to get and set +state fairly efficiently. Japhar now supports this library, making +native state get and set calls as fast as accessing a C variable +directly. + +If you are using native libraries defined outside of Classpath, then +these should be wrapped by a Classpath function instead and defined +within a library of their own. This makes porting Classpath's native +libraries to new platforms easier in the long run. It would be nice +to be able to use Mozilla's NSPR or Apache's APR, as these libraries +are already ported to numerous systems and provide all the necessary +system functions as well. + +@node Security, , Native Efficiency, Programming Goals +@comment node-name, next, previous, up +@section Security + +Security is such a huge topic it probably deserves its own chapter. +Most of the current code needs to be audited for security to ensure +all of the proper security checks are in place within the Java +platform, but also to verify that native code is reasonably secure and +avoids common pitfalls, buffer overflows, etc. A good source for +information on secure programming is the excellent HOWTO by David +Wheeler, +@uref{http://www.dwheeler.com/secure-programs/Secure-Programs-HOWTO/index.html,Secure +Programming for Linux and Unix HOWTO}. + +@node API Compatibility, Specification Sources, Programming Goals, Top +@comment node-name, next, previous, up +@chapter API Compatibility + +@menu +* Serialization:: Serialization +* Deprecated Methods:: Deprecated methods +@end menu + +@node Serialization, Deprecated Methods, API Compatibility, API Compatibility +@comment node-name, next, previous, up +@section Serialization + +Sun has produced documentation concerning much of the information +needed to make Classpath serializable compatible with Sun +implementations. Part of doing this is to make sure that every class +that is Serializable actually defines a field named serialVersionUID +with a value that matches the output of serialver on Sun's +implementation. The reason for doing this is below. + +If a class has a field (of any accessibility) named serialVersionUID +of type long, that is what serialver uses. Otherwise it computes a +value using some sort of hash function on the names of all method +signatures in the .class file. The fact that different compilers +create different synthetic method signatures, such as access$0() if an +inner class needs access to a private member of an enclosing class, +make it impossible for two distinct compilers to reliably generate the +same serial #, because their .class files differ. However, once you +have a .class file, its serial # is unique, and the computation will +give the same result no matter what platform you execute on. + +Serialization compatibility can be tested using tools provided with +@uref{http://www.kaffe.org/~stuart/japi/,Japitools}. These +tools can test binary serialization compatibility and also provide +information about unknown serialized formats by writing these in XML +instead. Japitools is also the primary means of checking API +compatibility for GNU Classpath with Sun's Java Platform. + +@node Deprecated Methods, , Serialization, API Compatibility +@comment node-name, next, previous, up +@section Deprecated Methods + +Sun has a practice of creating ``alias'' methods, where a public or +protected method is deprecated in favor of a new one that has the same +function but a different name. Sun's reasons for doing this vary; as +an example, the original name may contain a spelling error or it may +not follow Java naming conventions. + +Unfortunately, this practice complicates class library code that calls +these aliased methods. Library code must still call the deprecated +method so that old client code that overrides it continues to work. +But library code must also call the new version, because new code is +expected to override the new method. + +The correct way to handle this (and the way Sun does it) may seem +counterintuitive because it means that new code is less efficient than +old code: the new method must call the deprecated method, and throughout +the library code calls to the old method must be replaced with calls to +the new one. + +Take the example of a newly-written container laying out a component and +wanting to know its preferred size. The Component class has a +deprecated preferredSize method and a new method, getPreferredSize. +Assume that the container is laying out an old component that overrides +preferredSize and a new component that overrides getPreferredSize. If +the container calls getPreferredSize and the default implementation of +getPreferredSize calls preferredSize, then the old component will have +its preferredSize method called and new code will have its +getPreferredSize method called. + +Even using this calling scheme, an old component may still be laid out +improperly if it implements a method, getPreferredSize, that has the +same signature as the new Component.getPreferredSize. But that is a +general problem -- adding new public or protected methods to a +widely-used class that calls those methods internally is risky, because +existing client code may have already declared methods with the same +signature. + +The solution may still seem counterintuitive -- why not have the +deprecated method call the new method, then have the library always call +the old method? One problem with that, using the preferred size example +again, is that new containers, which will use the non-deprecated +getPreferredSize, will not get the preferred size of old components. + +@node Specification Sources, Naming Conventions, API Compatibility, Top +@comment node-name, next, previous, up +@chapter Specification Sources + +There are a number of specification sources to use when working on +Classpath. In general, the only place you'll find your classes +specified is in the JavaDoc documentation or possibly in the +corresponding white paper. In the case of java.lang, java.io and +java.util, you should look at the Java Language Specification. + +Here, however, is a list of specs, in order of canonicality: + +@enumerate +@item +@uref{http://java.sun.com/docs/books/jls/clarify.html,Clarifications and Amendments to the JLS - 1.1} +@item +@uref{http://java.sun.com/docs/books/jls/html/1.1Update.html,JLS Updates +- 1.1} +@item +@uref{http://java.sun.com/docs/books/jls/html/index.html,The 1.0 JLS} +@item +@uref{http://java.sun.com/docs/books/vmspec/index.html,JVM spec - 1.1} +@item +@uref{http://java.sun.com/products/jdk/1.1/docs/guide/jni/spec/jniTOC.doc.html,JNI spec - 1.1} +@item +@uref{http://java.sun.com/products/jdk/1.1/docs/api/packages.html,Sun's javadoc - 1.1} +(since Sun's is the reference implementation, the javadoc is +documentation for the Java platform itself.) +@item +@uref{http://java.sun.com/products/jdk/1.2/docs/guide/jvmdi/jvmdi.html,JVMDI spec - 1.2}, +@uref{http://java.sun.com/products/jdk/1.2/docs/guide/jni/jni-12.html,JNI spec - 1.2} +(sometimes gives clues about unspecified things in 1.1; if +it was not specified accurately in 1.1, then use the spec +for 1.2; also, we are using JVMDI in this project.) +@item +@uref{http://java.sun.com/products/jdk/1.2/docs/api/frame.html,Sun's javadoc - 1.2} +(sometimes gives clues about unspecified things in 1.1; if +it was not specified accurately in 1.1, then use the spec +for 1.2) +@item +@uref{http://developer.java.sun.com/developer/bugParade/index.html,The +Bug Parade}: I have obtained a ton of useful information about how +things do work and how they *should* work from the Bug Parade just by +searching for related bugs. The submitters are very careful about their +use of the spec. And if something is unspecified, usually you can find +a request for specification or a response indicating how Sun thinks it +should be specified here. +@end enumerate + +You'll notice that in this document, white papers and specification +papers are more canonical than the JavaDoc documentation. This is true +in general. + + +@node Naming Conventions, Character Conversions, Specification Sources, Top +@comment node-name, next, previous, up +@chapter Directory and File Naming Conventions + +The Classpath directory structure is laid out in the following manner: + +@example +classpath + | + |---->java + | | + | |-->awt + | |-->io + | |-->lang + | |-->util + | | | + | | |--->zip + | | |--->jar + | |-->net + | |-->etc + | + |---->gnu + | | + | |-->java + | | + | |-->awt + | |-->lang + | |-->util + | | | + | | |-->zip + | |-->etc + | + |---->native + | + |-->jni + | |-->classpath + | |-->gtk-peer + | |-->java-io + | |-->java-lang + | |-->java-net + | |-->java-util + | |-->etc + |-->cni + +@end example + +Here is a brief description of the toplevel directories and their contents. + +@table @b + +@item java +Contains the source code to the Java packages that make up the core +class library. Because this is the public interface to Java, it is +important that the public classes, interfaces, methods, and variables +are exactly the same as specified in Sun's documentation. The directory +structure is laid out just like the java package names. For example, +the class java.util.zip would be in the directory java-util. + +@item gnu/java +Internal classes (roughly analogous to Sun's sun.* classes) should go +under the @file{gnu/java} directory. Classes related to a particular public +Java package should go in a directory named like that package. For +example, classes related to java.util.zip should go under a directory +@file{gnu/java/util/zip}. Sub-packages under the main package name are +allowed. For classes spanning multiple public Java packages, pick an +appropriate name and see what everybody else thinks. + +@item native +This directory holds native code needed by the public Java packages. +Each package has its own subdirectory, which is the ``flattened'' name +of the package. For example, native method implementations for +java.util.zip should go in @file{native/classpath/java-util}. Classpath +actually includes an all Java version of the zip classes, so no native +code is required. + +@end table + +Each person working on a package get's his or her own ``directory +space'' underneath each of the toplevel directories. In addition to the +general guidelines above, the following standards should be followed: + +@itemize @bullet + +@item +Classes that need to load native code should load a library with the +same name as the flattened package name, with all hyphens removed. For +example, the native library name specified in LoadLibrary for +java-util would be ``javautil''. + +@item +Each package has its own shared library for native code (if any). + +@item +The main native method implementation for a given method in class should +go in a file with the same name as the class with a ``.c'' extension. +For example, the JNI implementation of the native methods in +java.net.InetAddress would go in @file{native/jni/java-net/InetAddress.c}. +``Internal'' native functions called from the main native method can +reside in files of any name. +@end itemize + +@node Character Conversions, Localization, Naming Conventions, Top +@comment node-name, next, previous, up +@chapter Character Conversions + +Java uses the Unicode character encoding system internally. This is a +sixteen bit (two byte) collection of characters encompassing most of the +world's written languages. However, Java programs must often deal with +outside interfaces that are byte (eight bit) oriented. For example, a +Unix file, a stream of data from a network socket, etc. Beginning with +Java 1.1, the @code{Reader} and @code{Writer} classes provide functionality +for dealing with character oriented streams. The classes +@code{InputStreamReader} and @code{OutputStreamWriter} bridge the gap +between byte streams and character streams by converting bytes to +Unicode characters and vice versa. + +In Classpath, @code{InputStreamReader} and @code{OutputStreamWriter} +rely on an internal class called @code{gnu.java.io.EncodingManager} to load +translaters that perform the actual conversion. There are two types of +converters, encoders and decoders. Encoders are subclasses of +@code{gnu.java.io.encoder.Encoder}. This type of converter takes a Java +(Unicode) character stream or buffer and converts it to bytes using +a specified encoding scheme. Decoders are a subclass of +@code{gnu.java.io.decoder.Decoder}. This type of converter takes a +byte stream or buffer and converts it to Unicode characters. The +@code{Encoder} and @code{Decoder} classes are subclasses of +@code{Writer} and @code{Reader} respectively, and so can be used in +contexts that require character streams, but the Classpath implementation +currently does not make use of them in this fashion. + +The @code{EncodingManager} class searches for requested encoders and +decoders by name. Since encoders and decoders are separate in Classpath, +it is possible to have a decoder without an encoder for a particular +encoding scheme, or vice versa. @code{EncodingManager} searches the +package path specified by the @code{file.encoding.pkg} property. The +name of the encoder or decoder is appended to the search path to +produce the required class name. Note that @code{EncodingManager} knows +about the default system encoding scheme, which it retrieves from the +system property @code{file.encoding}, and it will return the proper +translator for the default encoding if no scheme is specified. Also, the +Classpath standard translator library, which is the @code{gnu.java.io} package, +is automatically appended to the end of the path. + +For efficiency, @code{EncodingManager} maintains a cache of translators +that it has loaded. This eliminates the need to search for a commonly +used translator each time it is requested. + +Finally, @code{EncodingManager} supports aliasing of encoding scheme names. +For example, the ISO Latin-1 encoding scheme can be referred to as +''8859_1'' or ''ISO-8859-1''. @code{EncodingManager} searches for +aliases by looking for the existence of a system property called +@code{gnu.java.io.encoding_scheme_alias.}. If such a +property exists. The value of that property is assumed to be the +canonical name of the encoding scheme, and a translator with that name is +looked up instead of one with the original name. + +Here is an example of how @code{EncodingManager} works. A class requests +a decoder for the ''UTF-8'' encoding scheme by calling +@code{EncodingManager.getDecoder("UTF-8")}. First, an alias is searched +for by looking for the system property +@code{gnu.java.io.encoding_scheme_alias.UTF-8}. In our example, this +property exists and has the value ''UTF8''. That is the actual +decoder that will be searched for. Next, @code{EncodingManager} looks +in its cache for this translator. Assuming it does not find it, it +searches the translator path, which is this example consists only of +the default @code{gnu.java.io}. The ''decoder'' package name is +appended since we are looking for a decoder. (''encoder'' would be +used if we were looking for an encoder). Then name name of the translator +is appended. So @code{EncodingManager} attempts to load a translator +class called @code{gnu.java.io.decoder.UTF8}. If that class is found, +an instance of it is returned. If it is not found, a +@code{UnsupportedEncodingException}. + +To write a new translator, it is only necessary to subclass +@code{Encoder} and/or @code{Decoder}. Only a handful of abstract +methods need to be implemented. In general, no methods need to be +overridden. The needed methods calculate the number of bytes/chars +that the translation will generate, convert buffers to/from bytes, +and read/write a requested number of characters to/from a stream. + +Many common encoding schemes use only eight bits to encode characters. +Writing a translator for these encodings is very easy. There are +abstract translator classes @code{gnu.java.io.decode.DecoderEightBitLookup} +and @code{gnu.java.io.encode.EncoderEightBitLookup}. These classes +implement all of the necessary methods. All that is necessary to +create a lookup table array that maps bytes to Unicode characters and +set the class variable @code{lookup_table} equal to it in a static +initializer. Also, a single constructor that takes an appropriate +stream as an argument must be supplied. These translators are +exceptionally easy to create and there are several of them supplied +in the Classpath distribution. + +Writing multi-byte or variable-byte encodings is more difficult, but +often not especially challenging. The Classpath distribution ships with +translators for the UTF8 encoding scheme which uses from one to three +bytes to encode Unicode characters. This can serve as an example of +how to write such a translator. + +Many more translators are needed. All major character encodings should +eventually be supported. + +@node Localization, , Character Conversions, Top +@comment node-name, next, previous, up +@chapter Localization + +There are many parts of the Java standard runtime library that must +be customized to the particular locale the program is being run in. +These include the parsing and display of dates, times, and numbers; +sorting words alphabetically; breaking sentences into words, etc. +In general, Classpath uses general classes for performing these tasks, +and customizes their behavior with configuration data specific to a +given locale. + +@menu +* String Collation:: Sorting strings in different locales +* Break Iteration:: Breaking up text into words, sentences, and lines +* Date Formatting and Parsing:: Locale specific date handling +* Decimal/Currency Formatting and Parsing:: Local specific number handling +@end menu + +In Classpath, all locale specific data is stored in a +@code{ListResourceBundle} class in the package @code{gnu/java/locale}. +The basename of the bundle is @code{LocaleInformation}. See the +documentation for the @code{java.util.ResourceBundle} class for details +on how the specific locale classes should be named. + +@code{ListResourceBundle}'s are used instead of +@code{PropertyResourceBundle}'s because data more complex than simple +strings need to be provided to configure certain Classpath components. +Because @code{ListResourceBundle} allows an arbitrary Java object to +be associated with a given configuration option, it provides the +needed flexibility to accomodate Classpath's needs. + +Each Java library component that can be localized requires that certain +configuration options be specified in the resource bundle for it. It is +important that each and every option be supplied for a specific +component or a critical runtime error will most likely result. + +As a standard, each option should be assigned a name that is a string. +If the value is stored in a class or instance variable, then the option +should name should have the name name as the variable. Also, the value +associated with each option should be a Java object with the same name +as the option name (unless a simple scalar value is used). Here is an +example: + +A class loads a value for the @code{format_string} variable from the +resource bundle in the specified locale. Here is the code in the +library class: + +@example + ListResourceBundle lrb = + ListResourceBundle.getBundle ("gnu/java/locale/LocaleInformation", locale); + String format_string = lrb.getString ("format_string"); +@end example + +In the actual resource bundle class, here is how the configuration option +gets defined: + +@example +/** + * This is the format string used for displaying values + */ +private static final String format_string = "%s %d %i"; + +private static final Object[][] contents = +@{ + @{ "format_string", format_string @} +@}; +@end example + +Note that each variable should be @code{private}, @code{final}, and +@code{static}. Each variable should also have a description of what it +does as a documentation comment. The @code{getContents()} method returns +the @code{contents} array. + +There are many functional areas of the standard class library that are +configured using this mechanism. A given locale does not need to support +each functional area. But if a functional area is supported, then all +of the specified entries for that area must be supplied. In order to +determine which functional areas are supported, there is a special key +that is queried by the affected class or classes. If this key exists, +and has a value that is a @code{Boolean} object wrappering the +@code{true} value, then full support is assumed. Otherwise it is +assumed that no support exists for this functional area. Every class +using resources for configuration must use this scheme and define a special +scheme that indicates the functional area is supported. Simply checking +for the resource bundle's existence is not sufficient to ensure that a +given functional area is supported. + +The following sections define the functional areas that use resources +for locale specific configuration in GNU Classpath. Please refer to the +documentation for the classes mentioned for details on how these values +are used. You may also wish to look at the source file for +@file{gnu/java/locale/LocaleInformation_en} as an example. + +@node String Collation, Break Iteration, Localization, Localization +@comment node-name, next, previous, up +@section String Collation + +Collation involves the sorting of strings. The Java class library provides +a public class called @code{java.text.RuleBasedCollator} that performs +sorting based on a set of sorting rules. + +@itemize @bullet +@item RuleBasedCollator - A @code{Boolean} wrappering @code{true} to indicate +that this functional area is supported. +@item collation_rules - The rules the specify how string collation is to +be performed. +@end itemize + +Note that some languages might be too complex for @code{RuleBasedCollator} +to handle. In this case an entirely new class might need to be written in +lieu of defining this rule string. + +@node Break Iteration, Date Formatting and Parsing, String Collation, Localization +@comment node-name, next, previous, up +@section Break Iteration + +The class @code{java.text.BreakIterator} breaks text into words, sentences, +and lines. It is configured with the following resource bundle entries: + +@itemize @bullet +@item BreakIterator - A @code{Boolean} wrappering @code{true} to indicate +that this functional area is supported. +@item word_breaks - A @code{String} array of word break character sequences. +@item sentence_breaks - A @code{String} array of sentence break character +sequences. +@item line_breaks - A @code{String} array of line break character sequences. +@end itemize + +@node Date Formatting and Parsing, Decimal/Currency Formatting and Parsing, Break Iteration, Localization +@comment node-name, next, previous, up +@section Date Formatting and Parsing + +Date formatting and parsing is handled by the +@code{java.text.SimpleDateFormat} class in most locales. This class is +configured by attaching an instance of the @code{java.text.DateFormatSymbols} +class. That class simply reads properties from our locale specific +resource bundle. The following items are required (refer to the +documentation of the @code{java.text.DateFormatSymbols} class for details +io what the actual values should be): + +@itemize @bullet +@item DateFormatSymbols - A @code{Boolean} wrappering @code{true} to indicate +that this functional area is supported. +@item months - A @code{String} array of month names. +@item shortMonths - A @code{String} array of abbreviated month names. +@item weekdays - A @code{String} array of weekday names. +@item shortWeekdays - A @code{String} array of abbreviated weekday names. +@item ampms - A @code{String} array containing AM/PM names. +@item eras - A @code{String} array containing era (ie, BC/AD) names. +@item zoneStrings - An array of information about valid timezones for this +locale. +@item localPatternChars - A @code{String} defining date/time pattern symbols. +@item shortDateFormat - The format string for dates used by +@code{DateFormat.SHORT} +@item mediumDateFormat - The format string for dates used by +@code{DateFormat.MEDIUM} +@item longDateFormat - The format string for dates used by +@code{DateFormat.LONG} +@item fullDateFormat - The format string for dates used by +@code{DateFormat.FULL} +@item shortTimeFormat - The format string for times used by +@code{DateFormat.SHORT} +@item mediumTimeFormat - The format string for times used by +@code{DateFormat.MEDIUM} +@item longTimeFormat - The format string for times used by +@code{DateFormat.LONG} +@item fullTimeFormat - The format string for times used by +@code{DateFormat.FULL} +@end itemize + +Note that it may not be possible to use this mechanism for all locales. +In those cases a special purpose class may need to be written to handle +date/time processing. + +@node Decimal/Currency Formatting and Parsing, , Date Formatting and Parsing, Localization +@comment node-name, next, previous, up +@section Decimal/Currency Formatting and Parsing + +@code{NumberFormat} is an abstract class for formatting and parsing numbers. +The class @code{DecimalFormat} provides a concrete subclass that handles +this is in a locale independent manner. As with @code{SimpleDateFormat}, +this class gets information on how to format numbers from a class that +wrappers a collection of locale specific formatting values. In this case, +the class is @code{DecimalFormatSymbols}. That class reads its default +values for a locale from the resource bundle. The required entries are: + +@itemize @bullet +@item DecimalFormatSymbols - A @code{Boolean} wrappering @code{true} to +indicate that this functional area is supported. +@item currencySymbol - The string representing the local currency. +@item intlCurrencySymbol - The string representing the local currency in an +international context. +@item decimalSeparator - The character to use as the decimal point as a +@code{String}. +@item digit - The character used to represent digits in a format string, +as a @code{String}. +@item exponential - The char used to represent the exponent separator of a +number written in scientific notation, as a @code{String}. +@item groupingSeparator - The character used to separate groups of numbers +in a large number, such as the ``,'' separator for thousands in the US, as +a @code{String}. +@item infinity - The string representing infinity. +@item NaN - The string representing the Java not a number value. +@item minusSign - The character representing the negative sign, as a +@code{String}. +@item monetarySeparator - The decimal point used in currency values, as a +@code{String}. +@item patternSeparator - The character used to separate positive and +negative format patterns, as a @code{String}. +@item percent - The percent sign, as a @code{String}. +@item perMill - The per mille sign, as a @code{String}. +@item zeroDigit - The character representing the digit zero, as a @code{String}. +@end itemize + +Note that several of these values are an individual character. These should +be wrappered in a @code{String} at character position 0, not in a +@code{Character} object. + +@bye + diff --git a/libjava/classpath/doc/cp-tools.texinfo b/libjava/classpath/doc/cp-tools.texinfo new file mode 100644 index 0000000..c6c887e --- /dev/null +++ b/libjava/classpath/doc/cp-tools.texinfo @@ -0,0 +1,1806 @@ +\input texinfo @c -*-texinfo-*- + +@c %**start of header +@setfilename tools.info +@settitle GNU Classpath Tools Guide +@c %**end of header + +@setchapternewpage on + +@c Common macros to support generating man pages: + +@macro gcctabopt{body} +@code{\body\} +@end macro +@macro gccoptlist{body} +@smallexample +\body\ +@end smallexample +@end macro + +@ifinfo +This file documents the Tools included in a standard distribution of the GNU +Classpath project deliverables. + +Copyright (C) 2006 Free Software Foundation, Inc. + +@ifnotplaintext +@dircategory GNU Libraries +@direntry +* Classpath Tools: (tools). GNU Classpath Tools Guide +@end direntry +@end ifnotplaintext +@end ifinfo + +@titlepage +@title GNU Classpath Tools Guide +@author The GNU Classpath Team + +@page +@vskip 0pt plus 1filll +Copyright @copyright{} 2006 Free Software Foundation, Inc. +@sp 2 +Permission is granted to make and distribute verbatim copies of this document provided the copyright notice and this permission notice are preserved on all copies. + +Permission is granted to copy and distribute modified versions of this document under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. + +Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the Free Software Foundation. + +@end titlepage + +@contents + +@ifinfo +@node Top, Applet Tools, (dir), (dir) +@top GNU Classpath Tools Guide + +This document contains important information you need to know in order to use +the tools included in the GNU Classpath project deliverables. + +The Tools aim at providing a free replacement, similar in their behavior, to +their counter-parts found in the Reference Implementation (RI) of the Java +Software Development Kit (SDK). + +@end ifinfo + +@menu +* Applet Tools:: Work with applets +* Security Tools:: Work securely with Java applications +* Other Tools:: Other tools in classpath +* I18N Issues:: How to add support for non-English languages + +@detailmenu + --- The Detailed Node Listing --- + +Applet Tools + +* appletviewer Tool:: Load applets +* gcjwebplugin:: Load applets in a web browser + +Security Tools + +* jarsigner Tool:: Sign and verify .JAR files +* keytool Tool:: Manage private keys and public certificates + +jarsigner Tool + +* Common jarsigner Options:: Options used when signing or verifying a file +* Signing Options:: Options only used when signing a .JAR file +* Verification Options:: Options only used when verifying a .JAR file + +keytool Tool + +* Getting Help:: How to get help with keytool commands +* Common keytool Options:: Options used in more than one command +* Distinguished Names:: X.500 Distinguished Names used in certificates +* Add/Update Commands:: Commands for adding data to a Key Store +* Export Commands:: Commands for exporting data from a Key Store +* Display Commands:: Commands for displaying data in a Key Store +* Management Commands:: Commands for managing a Key Store + +Add/Update Commands + +* Command -genkey:: Generate private key and self-signed certificate +* Command -import:: Import certificates and certificate replies +* Command -selfcert:: Generate self-signed certificate +* Command -cacert:: Import a CA Trusted Certificate +* Command -identitydb:: Import JDK-1 style identities + +Export Commands + +* Command -certreq:: Generate Certificate Signing Requests (CSR) +* Command -export:: Export a certificate in a Key Store + +Display Commands + +* Command -list:: Display information about one or all Aliases +* Command -printcert:: Print a certificate or a certificate fingerprint + +Management Commands + +* Command -keyclone:: Clone a Key Entry in a Key Store +* Command -storepasswd:: Change the password protecting a Key Store +* Command -keypasswd:: Change the password protecting a Key Entry +* Command -delete:: Remove an entry in a Key Store + +Other Tools + +* jar Tool:: Archive tool for Java archives +* javah Tool:: A java header compiler +* native2ascii Tool:: An encoding converter +* orbd Tool:: An object request broker daemon +* serialver Tool:: A serial version command +* rmid Tool:: RMI activation daemon +* rmiregistry Tool:: Remote object registry +* tnameserv Tool:: Naming service + +I18N Issues + +* Language Resources:: Where resources are located +* Message Formats:: How messages are internationalized + +@end detailmenu +@end menu + +@comment ---------------------------------------------------------------------- + +@node Applet Tools, Security Tools, Top, Top +@comment node-name, next, previous, up +@chapter Applet Tools + +Two Applet Tools are available with GNU Classpath: @b{appletviewer} +and @b{gcjwebplugin}. + +To avoid conflicts with other implementations, the appletviewer +executable is called ``gappletviewer''. + +@menu +* appletviewer Tool:: Load applets +* gcjwebplugin:: Load applets in a web browser +@end menu + +If while using these tools you think you found a bug, then please report it at @uref{http://www.gnu.org/software/classpath/bugs.html,classpath-bugs}. + +@comment ---------------------------------------------------------------------- + +@node appletviewer Tool, gcjwebplugin, Applet Tools, Applet Tools +@comment node-name, next, previous, up +@section The @code{appletviewer} Tool +@c man title gappletviewer Load and runs an applet + +SYNOPSIS + +@c man begin SYNOPSIS gappletviewer +appletviewer [@var{OPTION}]@dots{} @var{URL}@dots{} @var{@*} + +appletviewer [@var{OPTION}]@dots{} @option{-code} @var{CODE} @var{@*} + +appletviewer [@var{OPTION}]@dots{} @option{-plugin} @var{INPUT},@var{OUTPUT} +@c man end + +DESCRIPTION +@c man begin DESCRIPTION gappletviewer +The @command{appletviewer} tool loads and runs an applet. + +Use the first form to test applets specified by tag. The URL should +resolve to an HTML document from which the @command{appletviewer} will +extract applet tags. The APPLET, EMBED and OBJECT tags are supported. +If a given document contains multiple applet tags, all the applets +will be loaded, with each applet appearing in its own window. +Likewise, when multiple URLs are specified, each applet tag instance +is given its own window. If a given document contains no recognized +tags the @command{appletviewer} does nothing. + +@smallexample +appletviewer http://www.gnu.org/software/classpath/ +@end smallexample + +Use the second form to test an applet in development. This form +allows applet tag attributes to be supplied on the command line. Only +one applet may be specified using the @option{-code} option. The +@option{-code} option overrides the URL form -- any URLs specified will +be ignored. + +@smallexample +appletviewer -code Test.class -param datafile,data.txt +@end smallexample + +@command{gcjwebplugin} uses the third form to communicate with the +@command{appletviewer} through named pipes. +@c man end + +@c man begin OPTIONS gappletviewer +URL OPTIONS +@table @gcctabopt +@item -debug +This option is not yet implemented but is provided for compatibility. + +@item -encoding @var{CHARSET} +Use this option to specify an alternate character encoding for the +specified HTML page. + +@end table + +APPLET TAG OPTIONS +@table @gcctabopt +@item -code @var{CODE} +Use the @option{-code} option to specify the value of the applet tag +@var{CODE} attribute. + +@item -codebase @var{CODEBASE} +Use the @option{-codebase} option to specify the value of the applet tag +@var{CODEBASE} attribute. + +@item -archive @var{ARCHIVE} +Use the @option{-archive} option to specify the value of the applet tag +@var{ARCHIVE} attribute. + +@item -width @var{WIDTH} +Use the @option{-width} option to specify the value of the applet tag +@var{WIDTH} attribute. + +@item -height @var{HEIGHT} +Use the @option{-height} option to specify the value of the applet tag +@var{HEIGHT} attribute. + +@item -param @var{NAME},@var{VALUE} +Use the @option{-param} option to specify values for the @var{NAME} +and @var{VALUE} attributes of an applet PARAM tag. + +@end table + +PLUGIN OPTION +@table @gcctabopt +@item -plugin @var{INPUT},@var{OUTPUT} +@command{gcjwebplugin} uses the @option{-plugin} option to specify the +named pipe the @command{appletviewer} should use for receiving commands +(@var{INPUT}) and the one it should use for sending commands to +@command{gcjwebplugin} (@var{OUTPUT}). + +@end table + +DEBUGGING OPTION +@table @gcctabopt +@item -verbose +Use the @option{-verbose} option to have the @command{appletviewer} print +debugging messages. + +@end table + +STANDARD OPTIONS + +@table @gcctabopt +@item -help +Use the @option{-help} option to have the @command{appletviewer} print a +usage message, then exit. + +@item -version +Use the @option{-version} option to have the @command{appletviewer} print +its version, then exit. + +@item -J@var{OPTION} +Use the @option{-J} option to pass @var{OPTION} to the virtual machine that +will run the @command{appletviewer}. Unlike other options, there must +not be a space between the @option{-J} and @var{OPTION}. + +@end table +@c man end + +@comment ---------------------------------------------------------------------- + +@node gcjwebplugin, , appletviewer Tool, Applet Tools +@comment node-name, next, previous, up +@section The @code{gcjwebplugin} Tool + +@code{gcjwebplugin} is a plugin that adds applet support to web +browsers. Currently @code{gcjwebplugin} only supports Mozilla-based +browsers (e.g., Firefox, Galeon, Mozilla). + +@comment ---------------------------------------------------------------------- + +@node Security Tools, Other Tools, Applet Tools, Top +@comment node-name, next, previous, up +@chapter Security Tools + +Two Security Tools are available with GNU Classpath: +@command{jarsigner} and @command{keytool}. + +To avoid conflicts with other implementations, the jarsigner +executable is called @command{gjarsigner} and the keytool executable is +called @command{gkeytool}. + +@menu +* jarsigner Tool:: Sign and verify .JAR files +* keytool Tool:: Manage private keys and public certificates +@end menu + +If while using these tools you think you found a bug, then please report it at @uref{http://www.gnu.org/software/classpath/bugs.html,classpath-bugs}. + +@comment ---------------------------------------------------------------------- + +@node jarsigner Tool, keytool Tool, Security Tools, Security Tools +@comment node-name, next, previous, up +@section The @code{jarsigner} Tool +@c man title gjarsigner Java ARchive (JAR) file signing and verification tool + +The @command{jarsigner} tool is invoked from the command line, in one +of two forms, as follows: + +@example +@c man begin SYNOPSIS gjarsigner +jarsigner [@var{OPTION}]@dots{} @var{FILE} @var{ALIAS} + +jarsigner @option{-verify} [@var{OPTION}]@dots{} @var{FILE} +@c man end +@end example + +@c man begin DESCRIPTION gjarsigner +When the first form is used, the tool signs the designated JAR file. The second form, on the other hand, is used to verify a previously signed JAR file. + +@var{FILE} is the .JAR file to process; i.e. to sign if the first syntax form is used, or to verify if the second syntax form is used instead. + +@var{ALIAS} must be a known @i{Alias} of a @i{Key Entry} in the designated @i{Key Store}. The private key material associated with this @i{Alias} is then used for signing the designated .JAR file. +@c man end + +@menu +* Common jarsigner Options:: Options used when signing or verifying a file +* Signing Options:: Options only used when signing a .JAR file +* Verification Options:: Options only used when verifying a .JAR file +@end menu + +@comment ---------------------------------------------------------------------- + +@node Common jarsigner Options, Signing Options, jarsigner Tool, jarsigner Tool +@comment node-name, next, previous, up +@c man begin OPTIONS gjarsigner +@subsection Common options + +The following options may be used when the tool is used for either signing, or verifying, a .JAR file. + +@table @gcctabopt +@item -verbose +Use this option to force the tool to generate more verbose messages, during its processing. + +@item -internalsf +When present, the tool will include --which otherwise it does not-- the @code{.SF} file in the @code{.DSA} generated file. + +@item -sectionsonly +When present, the tool will include in the @code{.SF} generated file --which otherwise it does not-- a header containing a hash of the whole manifest file. When that header is included, the tool can quickly check, during verification, if the hash (in the header) matches or not the manifest file. + +@item -provider PROVIDER_CLASS_NAME +A fully qualified class name of a @i{Security Provider} to add to the current list of @i{Security Providers} already installed in the JVM in-use. If a provider class is specified with this option, and was successfully added to the runtime --i.e. it was not already installed-- then the tool will attempt to remove this @i{Security Provider} before exiting. + +@item -help +Prints a help text similar to this one. + +@end table +@c man end + +@comment ---------------------------------------------------------------------- + +@node Signing Options, Verification Options, Common jarsigner Options, jarsigner Tool +@comment node-name, next, previous, up +@c man begin OPTIONS gjarsigner +@subsection Signing options + +The following options may be specified when using the tool for signing purposes. + +@table @gcctabopt +@item -keystore @var{URL} +Use this option to specify the location of the key store to use. The default value is a file URL referencing the file named @file{.keystore} located in the path returned by the call to @code{java.lang.System#getProperty(String)} using @code{user.home} as argument. + +If a URL was specified, but was found to be malformed --e.g. missing protocol element-- the tool will attempt to use the URL value as a file-name (with absolute or relative path-name) of a key store --as if the protocol was @code{file:}. + +@item -storetype @var{STORE_TYPE} +Use this option to specify the type of the key store to use. The default value, if this option is omitted, is that of the property @code{keystore.type} in the security properties file, which is obtained by invoking the static method call @code{getDefaultType()} in @code{java.security.KeyStore}. + +@item -storepass @var{PASSWORD} +Use this option to specify the password which will be used to unlock the key store. If this option is missing, the User will be prompted to provide a password. + +@item -keypass @var{PASSWORD} +Use this option to specify the password which the tool will use to unlock the @i{Key Entry} associated with the designated @i{Alias}. + +If this option is omitted, the tool will first attempt to unlock the @i{Key Entry} using the same password protecting the key store. If this fails, you will then be prompted to provide a password. + +@item -sigfile @var{NAME} +Use this option to designate a literal that will be used to construct file names for both the @code{.SF} and @code{.DSA} signature files. These files will be generated, by the tool, and placed in the @file{META-INF} directory of the signed JAR. Permissible characters for @var{NAME} must be in the range "a-zA-Z0-9_-". All characters will be converted to upper-case ones. + +If this option is missing, the first eight characters of the @var{ALIAS} argument will be used. When this is the case, any character in @var{ALIAS} that is outside the permissible range of characters will be replaced by an underscore. + +@item -signedjar @var{FILE} +Use this option to specify the file name of the signed JAR. If this option is omitted, then the signed JAR will be named the same as @var{FILE}; i.e. the input JAR file will be replaced with the signed copy. + +@end table +@c man end + +@comment ---------------------------------------------------------------------- + +@node Verification Options, , Signing Options, jarsigner Tool +@comment node-name, next, previous, up +@c man begin OPTIONS gjarsigner +@subsection Verification options + +The following options may be specified when using the tool for verification purposes. + +@table @gcctabopt +@item -verify +Use this option to indicate that the tool is to be used for verification purposes. + +@item -certs +This option is used in conjunction with the @option{-verbose} option. When present, along with the @option{-verbose} option, the tool will print more detailed information about the certificates of the signer(s) being processed. + +@end table +@c man end + +@comment ---------------------------------------------------------------------- + +@node keytool Tool, , jarsigner Tool, Security Tools +@comment node-name, next, previous, up +@section The @code{keytool} Tool +@c man title gkeytool Manage private keys and public certificates + +@ignore +@c man begin SYNOPSIS gkeytool +keytool [@var{COMMAND}] @dots{} +@c man end +@end ignore + +@c man begin DESCRIPTION gkeytool +Cryptographic credentials, in a Java environment, are usually stored in a @i{Key Store}. The Java SDK specifies a @i{Key Store} as a persistent container of two types of objects: @i{Key Entries} and @i{Trusted Certificates}. The security tool @command{keytool} is a Java-based application for managing those types of objects. + +A @i{Key Entry} represents the private key part of a key-pair used in Public-Key Cryptography, and a signed X.509 certificate which authenticates the public key part for a known entity; i.e. the owner of the key-pair. The X.509 certificate itself contains the public key part of the key-pair. + +A @i{Trusted Certificate} is a signed X.509 certificate issued by a trusted entity. The @i{Trust} in this context is relative to the User of the @command{keytool}. In other words, the existence of a @i{Trusted Certificate} in the @i{Key Store} processed by a @command{keytool} command implies that the User trusts the @i{Issuer} of that @i{Trusted Certificate} to also sign, and hence authenticates, other @i{Subjects} the tool may process. + +@i{Trusted Certificates} are important because they allow the tool to mechanically construct @i{Chains of Trust} starting from one of the @i{Trusted Certificates} in a @i{Key Store} and ending with a certificate whose @i{Issuer} is potentially unknown. A valid chain is an ordered list, starting with a @i{Trusted Certificate} (also called the @i{anchor}), ending with the target certificate, and satisfying the condition that the @i{Subject} of certificate @code{#i} is the @i{Issuer} of certificate @code{#i + 1}. + +The @command{keytool} is invoked from the command line as follows: + +@smallexample +keytool [COMMAND] ... +@end smallexample + +Multiple @var{COMMAND}s may be specified at once, each complete with its own options. @command{keytool} will parse all the arguments, before processing, and executing, each @code{COMMAND}. If an exception occurs while executing one @var{COMMAND} @command{keytool} will abort. Note however that because the implementation of the tool uses code to parse command line options that also supports GNU-style options, you have to separate each command group with a double-hyphen; e.g + +@smallexample +keytool -list -- -printcert -alias mykey +@end smallexample +@c man end + +Here is a summary of the commands supported by the tool: + +@c man begin OPTIONS gkeytool +@enumerate +@item Add/Update commands +@table @gcctabopt +@item -genkey [@var{OPTION}]@dots{} +Generate a new @i{Key Entry}, eventually creating a new key store. + +@item -import [@var{OPTION}]@dots{} +Add, to a key store, @i{Key Entries} (private keys and certificate chains authenticating the public keys) and @i{Trusted Certificates} (3rd party certificates which can be used as @i{Trust Anchors} when building chains-of-trust). + +@item -selfcert [@var{OPTION}]@dots{} +Generate a new self-signed @i{Trusted Certificate}. + +@item -cacert [@var{OPTION}]@dots{} +Import a CA @i{Trusted Certificate}. + +@item -identitydb [@var{OPTION}]@dots{} +@b{NOT IMPLEMENTED YET}.@* +Import a JDK 1.1 style Identity Database. +@end table + +@item Export commands +@table @gcctabopt +@item -certreq [@var{OPTION}]@dots{} +Issue a @i{Certificate Signing Request} (CSR) which can be then sent to a @i{Certification Authority} (CA) to issue a certificate signed (by the CA) and authenticating the @i{Subject} of the request. + +@item -export [@var{OPTION}]@dots{} +Export a certificate from a key store. +@end table + +@item Display commands +@table @gcctabopt +@item -list [@var{OPTION}]@dots{} +Print one or all certificates in a key store to @code{STDOUT}. + +@item -printcert [@var{OPTION}]@dots{} +Print a human-readable form of a certificate, in a designated file, to @code{STDOUT}. +@end table + +@item Management commands +@table @gcctabopt +@item -keyclone [@var{OPTION}]@dots{} +Clone a @i{Key Entry} in a key store. + +@item -storepasswd [@var{OPTION}]@dots{} +Change the password protecting a key store. + +@item -keypasswd [@var{OPTION}]@dots{} +Change the password protecting a @i{Key Entry} in a key store. + +@item -delete [@var{OPTION}]@dots{} +Delete a @i{Key Entry} or a @i{Trusted Certificate} from a key store. +@end table +@end enumerate +@c man end + +@menu +* Getting Help:: How to get help with keytool commands +* Common keytool Options:: Options used in more than one command +* Distinguished Names:: X.500 Distinguished Names used in certificates +* Add/Update Commands:: Commands for adding data to a Key Store +* Export Commands:: Commands for exporting data from a Key Store +* Display Commands:: Commands for displaying data in a Key Store +* Management Commands:: Commands for managing a Key Store +@end menu + +@comment ---------------------------------------------------------------------- + +@node Getting Help, Common keytool Options, keytool Tool, keytool Tool +@comment node-name, next, previous, up +@subsection Getting help + +To get a general help text about the tool, use the @code{-help} option; e.g. + +@example +@code{keytool -help} +@end example + +To get more specific help text about one of the tool's command use the @code{-help} option for that command; e.g. + +@example +@code{keytool -genkey -help} +@end example + +In both instances, the tool will print a help text and then will exit the running JVM. + +It is worth noting here that the help messages printed by the tool are I18N-ready. This means that if/when the contents of the tool's @i{Message Bundle} properties file are available in languages other than English, you may see those messages in that language. + +@comment ---------------------------------------------------------------------- + +@node Common keytool Options, Distinguished Names, Getting Help, keytool Tool +@comment node-name, next, previous, up +@c man begin OPTIONS gkeytool +@subsection Common options + +The following @option{OPTION}s are used in more than one @command{COMMAND}. They are described here to reduce redundancy. + +@table @gcctabopt +@anchor{alias} +@item -alias @var{Alias} +Every entry, be it a @i{Key Entry} or a @i{Trusted Certificate}, in a key store is uniquely identified by a user-defined @var{Alias} string. Use this option to specify the @var{Alias} to use when referring to an entry in the key store. Unless specified otherwise, a default value of @code{mykey} shall be used when this option is omitted from the command line. + +@anchor{keyalg} +@item -keyalg @var{ALGORITHM} +Use this option to specify the canonical name of the key-pair generation algorithm. The default value for this option is @code{DSS} (a synonym for the Digital Signature Algorithm also known as DSA). + +@anchor{keysize} +@item -keysize @var{SIZE} +Use this option to specify the number of bits of the shared modulus (for both the public and private keys) to use when generating new keys. A default value of @code{1024} will be used if this option is omitted from the command line. + +@anchor{validity} +@item -validity @var{DAY_COUNT} +Use this option to specify the number of days a newly generated certificate will be valid for. The default value is @code{90} (days) if this option is omitted from the command line. + +@anchor{storetype} +@item -storetype @var{STORE_TYPE} +Use this option to specify the type of the key store to use. The default value, if this option is omitted, is that of the property @code{keystore.type} in the security properties file, which is obtained by invoking the static method call @code{getDefaultType()} in @code{java.security.KeyStore}. + +@anchor{storepass} +@item -storepass @var{PASSWORD} +Use this option to specify the password protecting the key store. If this option is omitted from the command line, you will be prompted to provide a password. + +@anchor{keystore} +@item -keystore @var{URL} +Use this option to specify the location of the key store to use. The default value is a file URL referencing the file named @file{.keystore} located in the path returned by the call to @code{java.lang.System#getProperty(String)} using @code{user.home} as argument. + +If a URL was specified, but was found to be malformed --e.g. missing protocol element-- the tool will attempt to use the URL value as a file-name (with absolute or relative path-name) of a key store --as if the protocol was @code{file:}. + +@anchor{provider} +@item -provider @var{PROVIDER_CLASS_NAME} +A fully qualified class name of a @i{Security Provider} to add to the current list of @i{Security Providers} already installed in the JVM in-use. If a provider class is specified with this option, and was successfully added to the runtime --i.e. it was not already installed-- then the tool will attempt to removed this @i{Security Provider} before exiting. + +@anchor{file} +@item -file @var{FILE} +Use this option to designate a file to use with a command. When specified with this option, the value is expected to be the fully qualified path of a file accessible by the File System. Depending on the command, the file may be used as input or as output. When this option is omitted from the command line, @code{STDIN} will be used instead, as the source of input, and @code{STDOUT} will be used instead as the output destination. + +@anchor{verbose} +@item -v +Unless specified otherwise, use this option to enable more verbose output. + +@end table +@c man end + +@comment ---------------------------------------------------------------------- + +@node Distinguished Names, Add/Update Commands, Common keytool Options, keytool Tool +@comment node-name, next, previous, up +@subsection X.500 Distinguished Names + +@anchor{dn} +A @i{Distinguished Name} (or DN) MUST be supplied with some of the @code{COMMAND}s using a @code{-dname} option. The syntax of a valid value for this option MUST follow RFC-2253 specifications. Namely the following components (with their accepted meaning) will be recognized. Note that the component name is case-insensitive: + +@ftable @var +@item CN +The Common Name; e.g. @kbd{host.domain.com} +@item OU +The Organizational Unit; e.g. @kbd{IT Department} +@item O +The Organization Name; e.g. @kbd{The Sample Company} +@item L +The Locality Name; e.g. @kbd{Sydney} +@item ST +The State Name; e.g. @kbd{New South Wales} +@item C +The 2-letter Country identifier; e.g. @kbd{AU} +@end ftable + +When specified with a @code{-dname} option, each pair of component/value will be separated from the other with a comma. Each component and value pair MUST be separated by an equal sign. For example, the following is a valid DN value:@* + +@format +CN=host.domain.com, O=The Sample Company, L=Sydney, ST=NSW, C=AU +@end format +@* +If the @i{Distinguished Name} is required, and no valid default value can be used, the tool will prompt you to enter the information through the console. + +@comment ---------------------------------------------------------------------- + +@node Add/Update Commands, Export Commands, Distinguished Names, keytool Tool +@comment node-name, next, previous, up +@c man begin OPTIONS gkeytool +@subsection Add/Update commands +@c man end + +@menu +* Command -genkey:: Generate private key and self-signed certificate +* Command -import:: Import certificates and certificate replies +* Command -selfcert:: Generate self-signed certificate +* Command -cacert:: Import a CA Trusted Certificate +* Command -identitydb:: Import JDK-1 style identities +@end menu + +@comment ---------------------------------------------------------------------- + +@node Command -genkey, Command -import, Add/Update Commands, Add/Update Commands +@comment node-name, next, previous, up +@c man begin OPTIONS gkeytool +@subsubsection The @option{-genkey} command + +Use this command to generate a new key-pair (both private and public keys), and save these credentials in the key store as a @i{Key Entry}, associated with the designated (if was specified with the @option{-alias} option) or default (if the @option{-alias} option is omitted) @i{Alias}. + +The private key material will be protected with a user-defined password (see @option{-keypass} option). The public key on the other hand will be part of a self-signed X.509 certificate, which will form a 1-element chain and will be saved in the key store. + +@table @gcctabopt +@item -alias @var{ALIAS} +For more details @pxref{alias,, ALIAS}. + +@item -keyalg @var{ALGORITHM} +For more details @pxref{keyalg,, ALGORITHM}. + +@item -keysize @var{KEY_SIZE} +For more details @pxref{keysize,, KEY_SIZE}. + +@item -sigalg @var{ALGORITHM} +The canonical name of the digital signature algorithm to use for signing certificates. If this option is omitted, a default value will be chosen based on the type of the key-pair; i.e. the algorithm that ends up being used by the -keyalg option. If the key-pair generation algorithm is @code{DSA}, the value for the signature algorithm will be @code{SHA1withDSA}. If on the other hand the key-pair generation algorithm is @code{RSA}, then the tool will use @code{MD5withRSA} as the signature algorithm. + +@item -dname @var{NAME} +This a mandatory value for the command. If no value is specified --i.e. the @option{-dname} option is omitted-- the tool will prompt you to enter a @i{Distinguished Name} to use as both the @i{Owner} and @i{Issuer} of the generated self-signed certificate. + +For more details @pxref{dn,, X.500 DISTINGUISHED NAME}. + +@item -keypass @var{PASSWORD} +Use this option to specify the password which the tool will use to protect the newly created @i{Key Entry}. + +If this option is omitted, you will be prompted to provide a password. + +@item -validity @var{DAY_COUNT} +For more details @pxref{validity,, DAY_COUNT}. + +@item -storetype @var{STORE_TYPE} +For more details @pxref{storetype,, STORE_TYPE}. + +@item -keystore @var{URL} +For more details @pxref{keystore,, URL}. + +@item -storepass @var{PASSWORD} +For more details @pxref{storepass,, PASSWORD}. + +@item -provider @var{PROVIDER_CLASS_NAME} +For more details @pxref{provider,, PROVIDER_CLASS_NAME}. + +@item -v +For more details @pxref{verbose}. + +@end table +@c man end + +@comment ---------------------------------------------------------------------- + +@node Command -import, Command -selfcert, Command -genkey, Add/Update Commands +@comment node-name, next, previous, up +@c man begin OPTIONS gkeytool +@subsubsection The @option{-import} command + +Use this command to read an X.509 certificate, or a PKCS#7 @i{Certificate Reply} from a designated input source and incorporate the certificates into the key store. + +If the @i{Alias} does not already exist in the key store, the tool treats the certificate read from the input source as a new @i{Trusted Certificate}. It then attempts to discover a chain-of-trust, starting from that certificate and ending at another @i{Trusted Certificate}, already stored in the key store. If the @option{-trustcacerts} option is present, an additional key store, of type @code{JKS} named @file{cacerts}, and assumed to be present in @file{$@{JAVA_HOME@}/lib/security} will also be consulted if found --@code{$@{JAVA_HOME@}} refers to the location of an installed @i{Java Runtime Environment} (JRE). If no chain-of-trust can be established, and unless the @code{-noprompt} option has been specified, the certificate is printed to @code{STDOUT} and the user is prompted for a confirmation. + +If @i{Alias} exists in the key store, the tool will treat the certificate(s) read from the input source as a @i{Certificate Reply}, which can be a chain of certificates, that eventually would replace the chain of certificates associated with the @i{Key Entry} of that @i{Alias}. The substitution of the certificates only occurs if a chain-of-trust can be established between the bottom certificate of the chain read from the input file and the @i{Trusted Certificates} already present in the key store. Again, if the @option{-trustcacerts} option is specified, additional @i{Trusted Certificates} in the same @file{cacerts} key store will be considered. If no chain-of-trust can be established, the operation will abort. + +@table @gcctabopt +@item -alias @var{ALIAS} +For more details @pxref{alias,, ALIAS}. + +@item -file @var{FILE} +For more details @pxref{file,, FILE}. + +@item -keypass @var{PASSWORD} +Use this option to specify the password which the tool will use to protect the @i{Key Entry} associated with the designated @i{Alias}, when replacing this @i{Alias}' chain of certificates with that found in the certificate reply. + +If this option is omitted, and the chain-of-trust for the certificate reply has been established, the tool will first attempt to unlock the @i{Key Entry} using the same password protecting the key store. If this fails, you will then be prompted to provide a password. + +@item -noprompt +Use this option to prevent the tool from prompting the user. + +@item -trustcacerts +Use this option to indicate to the tool that a key store, of type @code{JKS}, named @file{cacerts}, and usually located in @file{lib/security} in an installed @i{Java Runtime Environment} should be considered when trying to establish chain-of-trusts. + +@item -storetype @var{STORE_TYPE} +For more details @pxref{storetype,, STORE_TYPE}. + +@item -keystore @var{URL} +For more details @pxref{keystore,, URL}. + +@item -storepass @var{PASSWORD} +For more details @pxref{storepass,, PASSWORD}. + +@item -provider @var{PROVIDER_CLASS_NAME} +For more details @pxref{provider,, PROVIDER_CLASS_NAME}. + +@item -v +For more details @pxref{verbose}. + +@end table +@c man end + +@comment ---------------------------------------------------------------------- + +@node Command -selfcert, Command -cacert, Command -import, Add/Update Commands +@comment node-name, next, previous, up +@c man begin OPTIONS gkeytool +@subsubsection The @option{-selfcert} command + +Use this command to generate a self-signed X.509 version 1 certificate. The newly generated certificate will form a chain of one element which will replace the previous chain associated with the designated @i{Alias} (if @option{-alias} option was specified), or the default @i{Alias} (if @option{-alias} option was omitted). + +@table @gcctabopt +@item -alias @var{ALIAS} +For more details @pxref{alias,, ALIAS}. + +@item -sigalg @var{ALGORITHM} +The canonical name of the digital signature algorithm to use for signing the certificate. If this option is omitted, a default value will be chosen based on the type of the private key associated with the designated @i{Alias}. If the private key is a @code{DSA} one, the value for the signature algorithm will be @code{SHA1withDSA}. If on the other hand the private key is an @code{RSA} one, then the tool will use @code{MD5withRSA} as the signature algorithm. + +@item -dname @var{NAME} +Use this option to specify the @i{Distinguished Name} of the newly generated self-signed certificate. If this option is omitted, the existing @i{Distinguished Name} of the base certificate in the chain associated with the designated @i{Alias} will be used instead. + +For more details @pxref{dn,, X.500 DISTINGUISHED NAME}. + +@item -validity @var{DAY_COUNT} +For more details @pxref{validity,, DAY_COUNT}. + +@item -keypass @var{PASSWORD} +Use this option to specify the password which the tool will use to unlock the @i{Key Entry} associated with the designated @i{Alias}. + +If this option is omitted, the tool will first attempt to unlock the @i{Key Entry} using the same password protecting the key store. If this fails, you will then be prompted to provide a password. + +@item -storetype @var{STORE_TYPE} +For more details @pxref{storetype,, STORE_TYPE}. + +@item -keystore @var{URL} +For more details @pxref{keystore,, URL}. + +@item -storepass @var{PASSWORD} +For more details @pxref{storepass,, PASSWORD}. + +@item -provider @var{PROVIDER_CLASS_NAME} +For more details @pxref{provider,, PROVIDER_CLASS_NAME}. + +@item -v +For more details @pxref{verbose}. + +@end table +@c man end + +@comment ---------------------------------------------------------------------- + +@node Command -cacert, Command -identitydb, Command -selfcert, Add/Update Commands +@comment node-name, next, previous, up +@c man begin OPTIONS gkeytool +@subsubsection The @option{-cacert} command + +Use this command to import, a CA certificate and add it to the key store as a @i{Trusted Certificate}. The @i{Alias} for this new entry will be constructed from the FILE's base-name after replacing hyphens and dots with underscores. + +This command is useful when used in a script that recursively visits a directory of CA certificates to populate a @code{cacerts.gkr} @i{Key Store} of trusted certificates which can then be used commands that specify the @option{-trustcacerts} option. + +@table @gcctabopt +@item -file @var{FILE} +For more details @pxref{file,, FILE}. + +@item -storetype @var{STORE_TYPE} +For more details @pxref{storetype,, STORE_TYPE}. + +@item -keystore @var{URL} +For more details @pxref{keystore,, URL}. + +@item -storepass @var{PASSWORD} +For more details @pxref{storepass,, PASSWORD}. + +@item -provider @var{PROVIDER_CLASS_NAME} +For more details @pxref{provider,, PROVIDER_CLASS_NAME}. + +@item -v +For more details @pxref{verbose}. + +@end table +@c man end + +@comment ---------------------------------------------------------------------- + +@node Command -identitydb, , Command -cacert, Add/Update Commands +@comment node-name, next, previous, up +@c man begin OPTIONS gkeytool +@subsubsection The @option{-identitydb} command + +@b{NOT IMPLEMENTED YET}. + +Use this command to import a JDK 1.1 style Identity Database. + +@table @gcctabopt +@item -file @var{FILE} +For more details @pxref{file,, FILE}. + +@item -storetype @var{STORE_TYPE} +For more details @pxref{storetype,, STORE_TYPE}. + +@item -keystore @var{URL} +For more details @pxref{keystore,, URL}. + +@item -storepass @var{PASSWORD} +For more details @pxref{storepass,, PASSWORD}. + +@item -provider @var{PROVIDER_CLASS_NAME} +For more details @pxref{provider,, PROVIDER_CLASS_NAME}. + +@item -v +For more details @pxref{verbose}. + +@end table +@c man end + +@comment ---------------------------------------------------------------------- + +@node Export Commands, Display Commands, Add/Update Commands, keytool Tool +@comment node-name, next, previous, up +@c man begin OPTIONS gkeytool +@subsection Export commands +@c man end + +@menu +* Command -certreq:: Generate Certificate Signing Requests (CSR) +* Command -export:: Export a certificate in a Key Store +@end menu + +@comment ---------------------------------------------------------------------- + +@node Command -certreq, Command -export, Export Commands, Export Commands +@comment node-name, next, previous, up +@c man begin OPTIONS gkeytool +@subsubsection The @option{-certreq} command + +Use this command to generate a PKCS#10 @i{Certificate Signing Request} (CSR) and write it to a designated output destination. The contents of the destination should look something like the following: + +@example +-----BEGIN NEW CERTIFICATE REQUEST----- +MI...QAwXzEUMBIGA1UEAwwLcnNuQGdudS5vcmcxGzAZBgNVBAoMElUg +Q2...A0GA1UEBwwGU3lkbmV5MQwwCgYDVQQIDANOU1cxCzAJBgNVBACC +... +FC...IVwNVOfQLRX+O5kAhQ/a4RTZme2L8PnpvgRwrf7Eg8D6w== +-----END NEW CERTIFICATE REQUEST----- +@end example + +@b{IMPORTANT}: Some documentation (e.g. RSA examples) claims that the @code{Attributes} field, in the CSR is @code{OPTIONAL} while RFC-2986 implies the opposite. This implementation considers this field, by default, as @code{OPTIONAL}, unless the option @option{-attributes} is specified on the command line. + +@table @gcctabopt +@item -alias @var{ALIAS} +For more details @pxref{alias,, ALIAS}. + +@item -sigalg @var{ALGORITHM} +The canonical name of the digital signature algorithm to use for signing the certificate. If this option is omitted, a default value will be chosen based on the type of the private key associated with the designated @i{Alias}. If the private key is a @code{DSA} one, the value for the signature algorithm will be @code{SHA1withDSA}. If on the other hand the private key is an @code{RSA} one, then the tool will use @code{MD5withRSA} as the signature algorithm. + +@item -file @var{FILE} +For more details @pxref{file,, FILE}. + +@item -keypass @var{PASSWORD} +Use this option to specify the password which the tool will use to unlock the @i{Key Entry} associated with the designated @i{Alias}. + +If this option is omitted, the tool will first attempt to unlock the @i{Key Entry} using the same password protecting the key store. If this fails, you will then be prompted to provide a password. + +@item -storetype @var{STORE_TYPE} +For more details @pxref{storetype,, STORE_TYPE}. + +@item -keystore @var{URL} +For more details @pxref{keystore,, URL}. + +@item -storepass @var{PASSWORD} +For more details @pxref{storepass,, PASSWORD}. + +@item -provider @var{PROVIDER_CLASS_NAME} +For more details @pxref{provider,, PROVIDER_CLASS_NAME}. + +@item -v +For more details @pxref{verbose}. + +@item -attributes +Use this option to force the tool to encode a @code{NULL} DER value in the CSR as the value of the @code{Attributes} field. + +@end table +@c man end + +@comment ---------------------------------------------------------------------- + +@node Command -export, , Command -certreq, Export Commands +@comment node-name, next, previous, up +@c man begin OPTIONS gkeytool +@subsubsection The @option{-export} command + +Use this command to export a certificate stored in a key store to a designated output destination, either in binary format (if the @option{-v} option is specified), or in RFC-1421 compliant encoding (if the @option{-rfc} option is specified instead). + +@table @gcctabopt +@item -alias @var{ALIAS} +For more details @pxref{alias,, ALIAS}. + +@item -file @var{FILE} +For more details @pxref{file,, FILE}. + +@item -storetype @var{STORE_TYPE} +For more details @pxref{storetype,, STORE_TYPE}. + +@item -keystore @var{URL} +For more details @pxref{keystore,, URL}. + +@item -storepass @var{PASSWORD} +For more details @pxref{storepass,, PASSWORD}. + +@item -provider @var{PROVIDER_CLASS_NAME} +For more details @pxref{provider,, PROVIDER_CLASS_NAME}. + +@item -rfc +Use RFC-1421 specifications when encoding the output. + +@item -v +Output the certificate in binary DER encoding. This is the default output format of the command if neither @option{-rfc} nor @code{-v} options were detected on the command line. If both this option and the @option{-rfc} option are detected on the command line, the tool will opt for the RFC-1421 style encoding. + +@end table +@c man end + +@comment ---------------------------------------------------------------------- + +@node Display Commands, Management Commands, Export Commands, keytool Tool +@comment node-name, next, previous, up +@c man begin OPTIONS gkeytool +@subsection Display commands +@c man end + +@menu +* Command -list:: Display information about one or all Aliases +* Command -printcert:: Print a certificate or a certificate fingerprint +@end menu + +@comment ---------------------------------------------------------------------- + +@node Command -list, Command -printcert, Display Commands, Display Commands +@comment node-name, next, previous, up +@c man begin OPTIONS gkeytool +@subsubsection The @option{-list} command + +Use this command to print one or all of a key store entries to @code{STDOUT}. Usually this command will only print a @i{fingerprint} of the certificate, unless either the @option{-rfc} or the @option{-v} option is specified. + +@table @gcctabopt +@item -alias @var{ALIAS} +If this option is omitted, the tool will print ALL the entries found in the key store. + +For more details @pxref{alias,, ALIAS}. + +@item -storetype @var{STORE_TYPE} +For more details @pxref{storetype,, STORE_TYPE}. + +@item -keystore @var{URL} +For more details @pxref{keystore,, URL}. + +@item -storepass @var{PASSWORD} +For more details @pxref{storepass,, PASSWORD}. + +@item -provider @var{PROVIDER_CLASS_NAME} +For more details @pxref{provider,, PROVIDER_CLASS_NAME}. + +@item -rfc +Use RFC-1421 specifications when encoding the output. + +@item -v +Output the certificate in human-readable format. If both this option and the @option{-rfc} option are detected on the command line, the tool will opt for the human-readable form and will not abort the command. + +@end table +@c man end + +@comment ---------------------------------------------------------------------- + +@node Command -printcert, , Command -list, Display Commands +@comment node-name, next, previous, up +@c man begin OPTIONS gkeytool +@subsubsection The @option{-printcert} command + +Use this command to read a certificate from a designated input source and print it to @code{STDOUT} in a human-readable form. + +@table @gcctabopt +@item -file @var{FILE} +For more details @pxref{file,, FILE}. + +@item -v +For more details @pxref{verbose}. + +@end table +@c man end + +@comment ---------------------------------------------------------------------- + +@node Management Commands, , Display Commands, keytool Tool +@comment node-name, next, previous, up +@c man begin OPTIONS gkeytool +@subsection Management commands +@c man end + +@menu +* Command -keyclone:: Clone a Key Entry in a Key Store +* Command -storepasswd:: Change the password protecting a Key Store +* Command -keypasswd:: Change the password protecting a Key Entry +* Command -delete:: Remove an entry in a Key Store +@end menu + +@comment ---------------------------------------------------------------------- + +@node Command -keyclone, Command -storepasswd, Management Commands, Management Commands +@comment node-name, next, previous, up +@c man begin OPTIONS gkeytool +@subsubsection The @option{-keyclone} command + +Use this command to clone an existing @i{Key Entry} and store it under a new (different) @i{Alias} protecting, its private key material with possibly a new password. + +@table @gcctabopt +@item -alias @var{ALIAS} +For more details @pxref{alias,, ALIAS}. + +@item -dest @var{ALIAS} +Use this option to specify the new @i{Alias} which will be used to identify the cloned copy of the @i{Key Entry}. + +@item -keypass @var{PASSWORD} +Use this option to specify the password which the tool will use to unlock the @i{Key Entry} associated with the designated @i{Alias}. + +If this option is omitted, the tool will first attempt to unlock the @i{Key Entry} using the same password protecting the key store. If this fails, you will then be prompted to provide a password. + +@item -new @var{PASSWORD} +Use this option to specify the password protecting the private key material of the newly cloned copy of the @i{Key Entry}. + +@item -storetype @var{STORE_TYPE} +For more details @pxref{storetype,, STORE_TYPE}. + +@item -keystore @var{URL} +For more details @pxref{keystore,, URL}. + +@item -storepass @var{PASSWORD} +For more details @pxref{storepass,, PASSWORD}. + +@item -provider @var{PROVIDER_CLASS_NAME} +For more details @pxref{provider,, PROVIDER_CLASS_NAME}. + +@item -v +For more details @pxref{verbose}. + +@end table +@c man end + +@comment ---------------------------------------------------------------------- + +@node Command -storepasswd, Command -keypasswd, Command -keyclone, Management Commands +@comment node-name, next, previous, up +@c man begin OPTIONS gkeytool +@subsubsection The @option{-storepasswd} command + +Use this command to change the password protecting a key store. + +@table @gcctabopt +@item -new @var{PASSWORD} +The new, and different, password which will be used to protect the designated key store. + +@item -storetype @var{STORE_TYPE} +For more details @pxref{storetype,, STORE_TYPE}. + +@item -keystore @var{URL} +For more details @pxref{keystore,, URL}. + +@item -storepass @var{PASSWORD} +For more details @pxref{storepass,, PASSWORD}. + +@item -provider @var{PROVIDER_CLASS_NAME} +For more details @pxref{provider,, PROVIDER_CLASS_NAME}. + +@item -v +For more details @pxref{verbose}. + +@end table +@c man end + +@comment ---------------------------------------------------------------------- + +@node Command -keypasswd, Command -delete, Command -storepasswd, Management Commands +@comment node-name, next, previous, up +@c man begin OPTIONS gkeytool +@subsubsection The @option{-keypasswd} command + +Use this command to change the password protecting the private key material of a designated @i{Key Entry}. + +@table @gcctabopt +@item -alias @var{ALIAS} +For more details @pxref{alias,, ALIAS}. + +Use this option to specify the password which the tool will use to unlock the @i{Key Entry} associated with the designated @i{Alias}. + +If this option is omitted, the tool will first attempt to unlock the @i{Key Entry} using the same password protecting the key store. If this fails, you will then be prompted to provide a password. + +@item -new @var{PASSWORD} +The new, and different, password which will be used to protect the private key material of the designated @i{Key Entry}. + +@item -storetype @var{STORE_TYPE} +For more details @pxref{storetype,, STORE_TYPE}. + +@item -keystore @var{URL} +For more details @pxref{keystore,, URL}. + +@item -storepass @var{PASSWORD} +For more details @pxref{storepass,, PASSWORD}. + +@item -provider @var{PROVIDER_CLASS_NAME} +For more details @pxref{provider,, PROVIDER_CLASS_NAME}. + +@item -v +For more details @pxref{verbose}. + +@end table +@c man end + +@comment ---------------------------------------------------------------------- + +@node Command -delete, , Command -keypasswd, Management Commands +@comment node-name, next, previous, up +@c man begin OPTIONS gkeytool +@subsubsection The @option{-delete} command + +Use this command to delete a designated key store entry. + +@table @gcctabopt +@item -alias @var{ALIAS} +For more details @pxref{alias,, ALIAS}. + +@item -storetype @var{STORE_TYPE} +For more details @pxref{storetype,, STORE_TYPE}. + +@item -keystore @var{URL} +For more details @pxref{keystore,, URL}. + +@item -storepass @var{PASSWORD} +For more details @pxref{storepass,, PASSWORD}. + +@item -provider @var{PROVIDER_CLASS_NAME} +For more details @pxref{provider,, PROVIDER_CLASS_NAME}. + +@item -v +For more details @pxref{verbose}. + +@end table +@c man end + +@comment ---------------------------------------------------------------------- + +@node Other Tools, I18N Issues, Security Tools, Top +@comment node-name, next, previous, up +@chapter Other Tools + +This is a list of currently undocumented classpath tools: @b{jar}, +@b{javah}, @b{native2ascii}, @b{orbd}, @b{serialver}, @b{rmid}, @b{rmiregistry} +and @b{tnameserv}. + +@menu +* jar Tool:: Archive tool for Java archives +* javah Tool:: A java header compiler +* native2ascii Tool:: An encoding converter +* orbd Tool:: An object request broker daemon +* serialver Tool:: A serial version command +* rmid Tool:: RMI activation daemon +* rmiregistry Tool:: Remote object registry +* tnameserv Tool:: Naming service +@end menu + +@comment ---------------------------------------------------------------------- + +@node jar Tool, javah Tool, , Other Tools +@comment node-name, next, previous, up +@section The @command{jar} Tool +@c man title gjar - Archive tool for Java archives + +@c man begin DESCRIPTION gjar + +@command{gjar} is an implementation of Sun's jar utility that comes with +the JDK. + +If any file is a directory then it is processed recursively. The +manifest file name and the archive file name needs to be specified in +the same order the @option{-m} and @option{-f} flags are specified. + +@c man end + +@ignore +@c man begin SYNOPSIS gjar +gjar @option{-ctxui} [@var{OPTIONS}] @var{jar-file} [@option{-C} @var{DIR} @var{FILE}] @var{FILE}@dots{} +@c man end +@end ignore + +@c man begin OPTIONS gjar + +Operation mode: + +@table @gcctabopt +@item -c +Create new archive. + +@item -t +List table of contents for archive. + +@item -x +Extract named (or all) files from archive. + +@item -u +Update existing archive. + +@item -i @var{FILE} +Compute archive index. +@end table + +Operation modifiers: + +@table @gcctabopt +@item -f @var{FILE} +Specify archive file name. + +@item -0 +Store only; use no ZIP compression. + +@item -v +Generate verbose output on standard output. + +@item -M +Do not create a manifest file for the entries. + +@item -m @var{manifest} +Include manifest information from specified @var{manifest} file. +@end table + +File name selection: + +@table @gcctabopt +@item -C @var{DIR} @var{FILE} +Change to the @var{DIR} and include the following @var{FILE}. + +@item -@@ +Read the names of the files to add to the archive from stdin. This +option is supported only in combination with @option{-c} or @option{-u}. +Non standard option added in the GCC version. +@end table + +Standard options: + +@table @gcctabopt +@item -help +Print help text, then exit. +@item -version +Print version number, then exit. +@item -J@var{OPTION} +Pass argument to the Java runtime. +@end table + +@c man end + +@c man begin SEEALSO gjar +java(1), @dots{} +@c man end + +@comment ---------------------------------------------------------------------- + +@node javah Tool, native2ascii Tool, jar Tool, Other Tools +@comment node-name, next, previous, up +@section The @command{javah} Tool +@c man title gjavah - generate header files from Java class files + +@c man begin DESCRIPTION gjavah + +The @command{gjavah} program is used to generate header files from class +files. It can generate both CNI and JNI header files, as well as stub +implementation files which can be used as a basis for implementing the +required native methods. + +@c man end + +@ignore +@c man begin SYNOPSIS gjavah +gjavah @dots{} +@c man end +@end ignore + +@c man begin OPTIONS gjavah + +@table @gcctabopt +@item -d @var{DIR} +Set output directory. + +@item -o @var{FILE} +Set output file (only one of @option{-d} or @option{-o} may be used). + +@item -cmdfile @var{FILE} +Read command file. + +@item -all @var{DIR} +Operate on all class files under directory @var{DIR}. + +@item -stubs +Emit stub implementation. + +@item -jni +Emit JNI stubs or header (default). + +@item -cni +Emit CNI stubs or header (default JNI). + +@item -verbose +Set verbose mode. + +@item -force +Output files should always be written. +@end table + +Class path options: +@table @gcctabopt +@item -classpath @var{PATH} +Set the class path. + +@item -I@var{DIR} +Add directory to class path. + +@item -bootclasspath @var{PATH} +Set the boot class path. + +@item -extdirs @var{PATH} +Set the extension directory path. +@end table + +Standard options: +@table @gcctabopt +@item -help +Print help text, then exit. +@item -version +Print version number, then exit. +@item -J@var{OPTION} +Pass argument to the Java runtime. +@end table +@c man end + +@c man begin SEEALSO gjavah +javac(1), @dots{} +@c man end + +@comment ---------------------------------------------------------------------- + +@node native2ascii Tool, orbd Tool, javah Tool, Other Tools +@comment node-name, next, previous, up +@section The @command{native2ascii} Tool +@c man title gnative2ascii - An encoding converter + +@c man begin DESCRIPTION gnative2ascii + +To be written @dots{} + +@c man end + +@ignore +@c man begin SYNOPSIS gnative2ascii +gnative2ascii [@var{OPTIONS}]@dots{} [@var{INPUTFILE} [@var{OUTPUTFILE}]] +@c man end +@end ignore + +@c man begin OPTIONS gnative2ascii + +@table @gcctabopt +@item -encoding @var{NAME} +Set the encoding to use. + +@item -reversed +Convert from encoding to native. +@end table + +Standard options: +@table @gcctabopt +@item -help +Print help text, then exit. +@item -version +Print version number, then exit. +@item -J@var{OPTION} +Pass argument to the Java runtime. +@end table + +@c man end + +@c man begin SEEALSO gnative2ascii +javac(1), @dots{} +@c man end + +@comment ---------------------------------------------------------------------- + +@node orbd Tool, serialver Tool, native2ascii Tool, Other Tools +@comment node-name, next, previous, up +@section The @command{orbd} object request broker daemon +@c man title gorbd - An object request broker daemon + +@c man begin DESCRIPTION gorbd + +To be written @dots{} + +@c man end + +@ignore +@c man begin SYNOPSIS gorbd +gorbd @dots{} +@c man end +@end ignore + +@c man begin OPTIONS gorbd + +@table @gcctabopt +@item -ORBInitialPort @var{PORT} +Port on which persistent naming service is to be started. + +@item -ior @var{FILE} +File in which to store persistent naming service's IOR reference + +@item -directory @var{DIR} +Directory in which to store persistent data. + +@item -restart +Restart persistent naming service, clearing persistent naming +database. +@end table + +Standard options: +@table @gcctabopt +@item -help +Print help text, then exit. +@item -version +Print version number, then exit. +@item -J@var{OPTION} +Pass argument to the Java runtime. +@end table + +@c man end + +@c man begin SEEALSO gorbd +java(1), @dots{} +@c man end + +@comment ---------------------------------------------------------------------- + +@node serialver Tool, rmid Tool, orbd Tool, Other Tools +@comment node-name, next, previous, up +@section The @command{serialver} version command +@c man title gserialver version command + +@c man begin DESCRIPTION gserialver + +Print the serialVersionUID of the specified classes. + +@c man end + +@ignore +@c man begin SYNOPSIS gserialver +gserialver [@var{OPTIONS}]@dots{} @var{CLASS}@dots{} +@c man end +@end ignore + +@c man begin OPTIONS gserialver + +@table @gcctabopt +@item -classpath @var{PATH} +Class path to use to find classes. +@end table + +Standard options: +@table @gcctabopt +@item -help +Print help text, then exit. +@item -version +Print version number, then exit. +@item -J@var{OPTION} +Pass argument to the Java runtime. +@end table + +@c man end + +@c man begin SEEALSO gserialver +javac(1), @dots{} +@c man end + +@comment ---------------------------------------------------------------------- + +@node rmid Tool, rmiregistry Tool, serialver Tool, Other Tools +@comment node-name, next, previous, up +@section The @command{rmid} RMI activation system daemon +@c man title grmid - RMI activation system daemon + +@c man begin DESCRIPTION grmid + +To be written @dots{} + +@c man end + +@ignore +@c man begin SYNOPSIS grmid +grmid [@var{OPTIONS}]@dots{} +@c man end +@end ignore + +@c man begin OPTIONS grmid + +Activation process control: +@table @gcctabopt +@item -port @var{PORT} +Port on which activation system is to be started. + +@item -restart +Restart activation system, clearing persistent naming database, if +any. + +@item -stop +Stop activation system. +@end table + +Persistence: +@table @gcctabopt +@item -persistent +Make activation system persistent. + +@item -directory @var{DIR} +Directory in which to store persistent data. +@end table + +Debugging: +@table @gcctabopt +@item -verbose +Log binding events to standard out. +@end table + +Standard options: +@table @gcctabopt +@item -help +Print help text, then exit. +@item -version +Print version number, then exit. +@item -J@var{OPTION} +Pass argument to the Java runtime. +@end table + +@c man end + +@c man begin SEEALSO grmid +java(1), @dots{} +@c man end + +@comment ---------------------------------------------------------------------- + +@node rmiregistry Tool, tnameserv Tool, rmid Tool, Other Tools +@comment node-name, next, previous, up +@section The @command{rmiregistry} Tool +@c man title grmiregistry - Remote object registry + +@c man begin DESCRIPTION grmiregistry + +@command{grmiregistry} starts a remote object registry on the current +host. If no port number is specified, then port 1099 is used. + +@c man end + +@ignore +@c man begin SYNOPSIS grmiregistry +grmiregistry [@var{OPTIONS}]@dots{} @var{PORT} +@c man end +@end ignore + +@c man begin OPTIONS grmiregistry + +Registry process control: +@table @gcctabopt +@item -restart +Restart RMI naming service, clearing persistent naming database, if +any. + +@item -stop +Stop RMI naming service. +@end table + +Persistence: +@table @gcctabopt +@item -persistent +Make RMI naming service persistent. + +@item -directory @var{DIR} +Directory in which to store persistent data. +@end table + +Debugging: +@table @gcctabopt +@item -verbose +Log binding events to standard out. +@end table + +Standard options: +@table @gcctabopt +@item -help +Print help text, then exit. +@item -version +Print version number, then exit. +@item -J@var{OPTION} +Pass argument to the Java runtime. +@end table + +@c man end + +@c man begin SEEALSO grmiregistry +java(1), @dots{} +@c man end + +@comment ---------------------------------------------------------------------- + +@node tnameserv Tool, , rmiregistry Tool, Other Tools +@comment node-name, next, previous, up +@section The @command{tnameserv} Tool +@c man title gtnameserv Naming service + +@c man begin DESCRIPTION gtnameserv + +To be written @dots{} + +@c man end + +@ignore +@c man begin SYNOPSIS gtnameserv +tnameserv [@var{OPTIONS}] +@c man end +@end ignore + +@c man begin OPTIONS gtnameserv + +@table @gcctabopt +@item -ORBInitialPort @var{PORT} +Port on which naming service is to be started. + +@item -ior @var{FILE} +File in which to store naming service's IOR reference. +@end table + +Standard options: +@table @gcctabopt +@item -help +Print help text, then exit. +@item -version +Print version number, then exit. +@item -J@var{OPTION} +Pass argument to the Java runtime. +@end table + +@c man end + +@c man begin SEEALSO gtnameserv +java(1), @dots{} +@c man end + +@comment ---------------------------------------------------------------------- + +@node I18N Issues, , Other Tools, Top +@comment node-name, next, previous, up +@chapter I18N Issues + +Some tools --@pxref{Security Tools}-- allow using other than the English language when prompting the User for input, and outputing messages. This chapter describes the elements used to offer this support and how they can be adapted for use with specific languages. + +@menu +* Language Resources:: Where resources are located +* Message Formats:: How messages are internationalized +@end menu + +@comment ---------------------------------------------------------------------- + +@node Language Resources, Message Formats, I18N Issues, I18N Issues +@comment node-name, next, previous, up +@section Language-specific resources + +The Tools use Java @code{ResourceBundle}s to store messages, and message templates they use at runtime to generate the message text itself, depending on the locale in use at the time. + +The @i{Resource Bundles} these tools use are essentially Java @i{Properties} files consisting of a set of @i{Name/Value} pairs. The @i{Name} is the @i{Propery Name} and the @i{Value} is a substitution string that is used when the code references the associated @i{Name}. For example the following is a line in a @i{Resource Bundle} used by the @code{keytool} Tool: + +@example +Command.23=A correct key password MUST be provided +@end example + +When the tool needs to signal a mandatory but missing key password, it would reference the property named @code{Command.23} and the message "@kbd{A correct key password MUST be provided}" will be used instead. This indirect referencing of "resources" permits replacing, as late as possible, the English strings with strings in other languages, provided of course @i{Resource Bundles} in those languages are provided. + +For the GNU Classpath Tools described in this Guide, the @i{Resource Bundles} are files named @file{messages[_ll[_CC[_VV]]].properties} where: + +@ftable @var +@item ll +Is the 2-letter code for the Language, +@item CC +Is the 2-letter code for the Region, and +@item VV +Is the 2-letter code for the Variant of the language. +@end ftable + +The complete list of language codes can be found at @uref{http://ftp.ics.uci.edu/pub/ietf/http/related/iso639.txt, Code for the representation of names of languages}. A similar list for the region codes can be found at @uref{http://userpage.chemie.fu-berlin.de/diverse/doc/ISO_3166.html, ISO 3166 Codes (Countries)}. + +The location of the @i{Resource Bundles} for the GNU Classpath Tools is specific to each tool. The next table shows where these files are found in a standard GNU Classpath distribution: + +@ftable @code +@item jarsigner +@file{gnu/classpath/tools/jarsigner} +@item keytool +@file{gnu/classpath/tools/keytool} +@end ftable + +The collection of @i{Resource Bundles} in a location act as an inverted tree with a parent-child relationship. For example suppose in the @file{gnu/classpath/tools/keytool} there are 3 message bundles named: + +@enumerate +@item @code{messages.properties} +@item @code{messages_fr.properties} +@item @code{messages_fr_FR.properties} +@end enumerate + +In the above example, bundle #1 will act as the parent of bundle #2, which in turn will act as the parent for bundle #3. This ordering is used by the Java runtime to choose which file to load based on the set Locale. For example if the Locale is @code{fr_CH}, @code{messages_fr.properties} will be used because (a) @code{messages_fr_CH.properties} does not exist, but (b) @code{messages_fr.properties} is the parent for the required bundle, and it exists. As another example, suppose the Locale was set to @code{en_AU}; then the tool will end up using @code{messages.properties} because (a) @code{messages_en_AU.properties} does not exist, (b) @code{messages_en.properties} which is the parent for the required bundle does not exist, but (c) @code{messages.properties} exists and is the root of the hierarchy. + +You can see from the examples above that @file{messages.properties} is the safety net that the Java runtime falls back to when failing to find a specific bunlde and its parent(s). This file is always provided with the Tool. In time, more localized versions will be included to cater for other languages. + +In the meantime, if you are willing to contribute localized versions of these resources, grab the @file{messages.properties} for a specific tool; translate it; save it with the appropriate language and region suffix and mail it to @code{classpath@@gnu.org}. + +@comment ---------------------------------------------------------------------- + +@node Message Formats, , Language Resources, I18N Issues +@comment node-name, next, previous, up +@section Message formats + +If you open any of the @file{messages.properties} described in the previous section, you may see properties that look like so: + +@example +Command.67=Issuer: @{0@} +Command.68=Serial number: @{0,number@} +Command.69=Valid from: @{0,date,full@} - @{0,time,full@} +Command.70=\ \ \ \ \ until: @{0,date,full@} - @{0,time,full@} +@end example + +These are @i{Message Formats} used by the tools to customize a text string that will then be used either as a prompt for User input or as output. + +If you are translating a @file{messages.properties} be careful not to alter text between curly braces. + +@comment ---------------------------------------------------------------------- + +@bye diff --git a/libjava/classpath/doc/cp-vmintegration.texinfo b/libjava/classpath/doc/cp-vmintegration.texinfo new file mode 100644 index 0000000..6d59b5d --- /dev/null +++ b/libjava/classpath/doc/cp-vmintegration.texinfo @@ -0,0 +1,1980 @@ +\input texinfo @c -*-texinfo-*- + +@c %**start of header +@setfilename vmintegration.info +@settitle GNU Classpath VM Integration Guide +@c %**end of header + +@setchapternewpage off + +@ifinfo +This file contains important information you will need to know if you +are going to write an interface between GNU Classpath and a Virtual +Machine. + +Copyright (C) 1998-2002, 2004, 2005, 2006 Free Software Foundation, Inc. + +@ifnotplaintext +@dircategory GNU Libraries +@direntry +* VM Integration: (vmintegration). GNU Classpath VM Integration Guide +@end direntry +@end ifnotplaintext +@end ifinfo + +@titlepage +@title GNU Classpath VM Integration Guide +@author John Keiser +@author C. Brian Jones +@author Mark Wielaard + +@page +@vskip 0pt plus 1filll +Copyright @copyright{} 1998-2002 Free Software Foundation, Inc. +@sp 2 +Permission is granted to make and distribute verbatim copies of +this document provided the copyright notice and this permission notice +are preserved on all copies. + +Permission is granted to copy and distribute modified versions of this +document under the conditions for verbatim copying, provided that the +entire resulting derived work is distributed under the terms of a +permission notice identical to this one. + +Permission is granted to copy and distribute translations of this manual +into another language, under the above conditions for modified versions, +except that this permission notice may be stated in a translation +approved by the Free Software Foundation. + +@end titlepage + +@ifinfo +@node Top, Introduction, (dir), (dir) +@top GNU Classpath Hacker's Guide + +This file contains important information you will need to know if you +are going to write an interface between GNU Classpath and a Virtual +Machine. + +This document is incomplete, as we are still in alpha with the interface. + +@end ifinfo + +@menu +* Introduction:: An introduction to the Classpath project +* Initialization:: Initializing the classes +* Classpath Hooks:: Hooks from Classpath to the VM +* VM Hooks:: Hooks from the underlying VM to Classpath +* JNI Implementation:: Hooking the VM to jni.h +* JVMTI Implementation:: Hooking the VM to jvmti.h +* Miscellaneous VM Requirements:: +@end menu + +@node Introduction, Initialization, Top, Top +@comment node-name, next, previous, up +@chapter Introduction + +The Classpath Project's ambition to be a 100% clean room implementation +of the standard Java class libraries cannot be fulfilled without some +level of integration with the Virtual Machine, the underlying machinery +that actually runs Java. + +There are several VMs out there, here is a small list. + +@itemize @bullet +@item @uref{http://www.hungry.com/old-hungry/products/japhar/,Japhar} +Japhar was the first VM to use GNU Classpath. Today you can see that +sort of relationship in the source tree which denotes several Japhar +specific files as a reference implementation of those pieces. This VM +has been primarily tested against Linux and lacks garbage collections, a +JIT, and suffers recently from slow development. + +@item @uref{http://www.intel.com/research/mrl/orp/,Intel's Open Runtime Platform} +Intel surprised us not long ago with the release of this rather advanced +VM that uses GNU Classpath for a set of class libraries and works on +Linux and Windows 2000. As of June, 2004, it does not appear that ORP +is under active development. + +@item @uref{http://www.sablevm.org/,SableVM} +SableVM is a robust, extremely portable, efficient, and +specifications-compliant Java Virtual Machine that aims to be easy to +maintain and to extend. It features a state-of-the-art, efficient +interpreter engine. Its source code is very accessible and easy to +understand, and has many robustness features that have been the object +of careful design. + +@item @uref{http://www.kaffe.org,Kaffe} +Kaffe is an advanced VM and together with its own class libraries +provides a Java 1.1 compatible environment. + +@item @uref{http://www.mozilla.org/projects/ef,Electrical Fire} +The Electrical File VM continues to be listed as a Mozilla project +though development has been somewhat quiet. A number of concepts from +EF were expected at one point to be rolled into Japhar, but that +development has not occurred as of yet. + +@item @uref{http://latte.snu.ac.kr/,LaTTe} +This VM project so far supports only Sun UltraSparc processors using the +proprietary Solaris 2.5.1 or higher operating system. LaTTe was derived +from Kaffe but claims a number of improvements. + +@item @uref{http://gcc.gnu.org/java/,GNU Compiler for Java (GCJ)} +This is a portable, optimizing, ahead-of-time compiler for the Java +Programming Language. It can compile Java source code directly to native +machine code, Java source code to Java bytecode (class files), and Java +bytecode to native machine code. Compiled applications are linked with the +GCJ runtime, libgcj which is based on the GNU Classpath code, which provides +the core class libraries, a garbage collector, and a bytecode interpreter. +libgcj can dynamically load and interpret class files, resulting in mixed +compiled/interpreted applications. +GCJ is part of the GNU Compiler Collection (@uref{http://gcc.gnu.org/,GCC}). +On March 6 2000 the libgcj and GNU Classpath projects were officially merged +and there is active work on merging all the classes between the projects. +Licensed under GPL+exception, just as GNU Classpath is. + +@item @uref{http://kissme.sourceforge.net/,Kissme} +This is a free Java Virtual Machine that is being developed on GNU/Linux +and can run console Java applications. Kissme also provides support for +orthogonally persistent Java. +@c I don't know what ``orthogonally persistent Java'' is, and I bet +@c there are other people don't know either. -- Steve Augart, 4 June 2004 + +@item @uref{http://jamvm.sourceforge.net/,JamVM} +A simple, small bytecode interpreter that works out-of-the-box with +pure GNU Classpath; it is emerging as the preferred platform for +quickly testing a new build of GNU Classpath. Licensed under the GPL. + +@item @uref{http://jikesrvm.sourceforge.net/,Jikes RVM} +A free runtime environment for Java, written in Java. Works +out-of-the-box with pure GNU Classpath. Features an optimizing JIT. +Runs on the x86 and PowerPC architectures, on the AIX, Linux, and Mac +OS/X operating systems. Licensed under the CPL (Common Public +License). Extensively documented. Actively developed as of June, +2004. + +@end itemize + +In the past integration efforts were focused mainly on Japhar with an eye +towards getting Electrical Fire to work. Most information contained in +this document is gleaned from these efforts. Recently more work has been +done on getting gcj, orp and kissme to work out of the box with GNU Classpath +but there is much to do before that becomes a reality. + + +@node Initialization, Classpath Hooks, Introduction, Top +@comment node-name, next, previous, up +@chapter Initialization + +The order of initialization, as far as I can tell, doesn't matter just +yet. However, when we move to 1.2 support, it probably will matter, so +we'll have a note in here at that time. + +The initialization order is currently documented in the +@file{Runtime.java} source file. + +@node Classpath Hooks, VM Hooks, Initialization, Top +@comment node-name, next, previous, up +@chapter Classpath Hooks + +The primary method of interaction between Classpath and the VM is via +the helper classes, which are named after the relevant core library +class, but include an additional `VM' prefix. The library classes from +Classpath call out to these to get certain VM-specific dirty work done. +A reference copy of each VM class exists. The majority consist of a +series of static methods, some of which are simply declared +@code{native}, and some which provide a default implementation. VMs may +either use these as is, or create their own local variations. When +using the default implementations, the VM is responsible for +implementing any of the code marked as @code{native} which corresponds +to functionality they wish their VM to provide. When using their own +versions of the classes, VM implementors may choose to change the mix of +native and non-native methods from that below, so as to best suit their +implementation. + +@menu +* java.lang:: +* gnu.classpath:: +* java.util:: +* java.io:: +* java.security:: +* java.net:: +* java.nio:: +* java.nio.channels:: +* gnu.java.nio:: +* java.lang.reflect:: +* gnu.java.lang:: +* gnu.java.lang.management:: +* java.lang.management:: +* Classpath Callbacks:: +@end menu + +@node java.lang, gnu.classpath, Classpath Hooks, Classpath Hooks +@comment node-name, next, previous, up + +@section @code{java.lang} + +@code{java.lang} is the core Java package, being imported automatically by all +classes. It includes basic classes as @code{Object} and @code{String}. +A VM must implement at least some parts of this package in order to +become operable. + +@menu +* java.lang.VMClass:: +* java.lang.VMObject:: +* java.lang.VMClassLoader:: +* java.lang.VMSystem:: +* java.lang.VMThrowable:: +* java.lang.VMCompiler:: +* java.lang.VMDouble:: +* java.lang.VMFloat:: +* java.lang.VMProcess:: +* java.lang.VMRuntime:: +* java.lang.VMString:: +* java.lang.VMThread:: +* java.lang.VMMath:: +@end menu + +@node java.lang.VMClass, java.lang.VMObject ,java.lang,java.lang +@subsection @code{java.lang.VMClass} + +The core class, @code{java.lang.Class}, and the corresponding VM class, +@code{java.lang.VMClass}, provide two main functions within GNU Classpath. + +@enumerate +@item For basic VM operation, @code{java.lang.Class} provides the link between +the Java-based representation of a class it embodies and the VM's own +internal structure for a class. @xref{VM Hooks}. + +@item As far as the user is concerned, the main function of +@code{java.lang.Class} is as an entry point to the reflection +facilities, and so it also provides this functionality, backed by the +VM class. +@end enumerate + +This VM class lists the following methods, organized by the version of the +Java specification in which they occur. All are @code{native}, unless +otherwise specified, and pertain to reflection. As a result, the VM only +needs to implement these methods in order to provide reflection support, +and then only to the degree required. + +@itemize @bullet +@item 1.0 +@itemize @bullet +@item @code{isInterface(Class)} -- This is simply a property test, and matches +the presence of an appropriate flag within the class file. +@item @code{getName(Class)} -- Returns the fully-qualified name of the class. +@item @code{getSuperclass(Class)} -- Returns a @code{Class} instance which +represents the superclass. Again, the class file contains an element directly +relating to this. @code{null} is returned for primitives, interfaces and +@code{Object}. +@item @code{getInterfaces(Class)} -- Same as the above, but the implemented +or extended interfaces rather than the superclass. An empty array should +be returned, rather than @code{null}. +@item @code{getDeclaredClasses(Class,boolean)} -- Returns the internal classes +this instance declares directly. The flag determines whether or not the +VM should filter out non-public classes. +@item @code{getDeclaredFields(Class,boolean)} -- The same for fields. +@item @code{getDeclaredMethods(Class,boolean)} -- And for methods. +@item @code{getDeclaredConstructors(Class,boolean)} -- And constructors. +@item @code{getClassLoader(Class)} -- Returns the @code{ClassLoader} instance +which is responsible for the specified class. +@item @code{forName(String, boolean, ClassLoader)} -- The VM should create a +@code{Class} instance corresponding to the named class. As noted in +@ref{VM Hooks}, the internal content of the instance is the +responsibility of the VM. The supplied class loader is recorded as that +which loaded the class, and the boolean specifies whether or not to +run the class initializer. +@item @code{isArray(Class)} -- Another property test, corresponding to a +class file flag. +@item @code{initialize(Class)} -- The VM should initialize the class fully, +if it has not already done so. +@item @code{loadArrayClass(String,ClassLoader)} -- This is called if +@code{forName} returns @code{null} and the string specifies an array class. +The specified array class should be loaded with the supplied class loader. +@item @code{throwException(Throwable)} -- The VM should throw the supplied +checked exception, without declaring it. +@end itemize +@item 1.1 +@itemize @bullet +@item @code{isInstance(Class,Object)} -- This is a reflection-based equivalent +of the @code{instanceof} operator. +@item @code{isAssignableFrom(Class,Class)} -- Mainly a shorthand for the above, +removing the need to create an instance to test assignability. +@item @code{isPrimitive(Class)} -- Returns true if this class is simply +a representation of one of the primitive types: @code{boolean}, @code{byte}, +@code{char}, @code{short}, @code{int}, @code{long}, @code{float}, +@code{double} and @code{void}. +@item @code{getComponentType(Class)} -- Produces a @code{Class} instance which +represents the type of the members of the array the class instance represents. +Classes which don't represent an array type return @code{null}. +@item @code{getModifiers(Class,boolean)} -- Returns an integer which encodes +the class' modifiers, such as @code{public}. Again, this relates to +information stored in the class file. +@item @code{getDeclaringClass(Class)} -- Returns the class that declared +an inner or member class, or @code{null} if the instance refers to a top-level +class. +@end itemize +@item 1.5 +@itemize @bullet +@item @code{isSynthetic(Class)} -- Returns true if the flags for this class +mark it as synthetic. +@item @code{isAnnotation(Class)} -- Returns true if the flags for this class +mark it as an annotation. +@item @code{isEnum(Class)} -- Returns true if the flags for this class +mark it as an enumeration. +@item @code{getSimpleName(Class)} -- Returns the simple name of the class. +A default implementation is provided, but a more efficient version may instead +be provided by the VM. +@item @code{getCanonicalName(Class)} -- Returns the canonical name of the +class. A default implementation is provided, but a more efficient +version may instead be provided by the VM. +@item @code{getEnclosingClass(Class)} -- Returns the immediately enclosing +class (null for a top-level class). +@item @code{getEnclosingConstructor(Class)} -- Returns the constructor +which immediately encloses the supplied class. +@item @code{getEnclosingMethod(Class)} -- Returns the method +which immediately encloses the supplied class. +@item @code{getClassSignature(Class)} -- Returns the generic signature of +the class or null if there isn't one. +@item @code{isAnonymousClass(Class)} -- Returns true if the class is an +anonymous class. +@item @code{isLocalClass(Class)} -- Returns true if the class is an +local class. +@item @code{isMemberClass(Class)} -- Returns true if the class is an +member class. +@end itemize +@end itemize + +@node java.lang.VMObject, java.lang.VMClassLoader, java.lang.VMClass, java.lang +@subsection @code{java.lang.VMObject} + +@code{VMObject} is the bridge between the low level @code{Object} +facilities such as making a clone, getting the class of the object and +the wait/notify semantics. This is accomplished using the following +@code{native} methods. + +@itemize @bullet +@item @code{getClass(Object)} -- Returns the @code{Class} instance for the +object. @code{Class} objects are produced by the VM, as described in +@ref{VM Hooks}. +@item @code{clone(Cloneable)} -- The VM should produce a low-level clone of the +specified object, creating a field-by-field shallow copy of the original. +The only difference between the two is that the new object should still be +@code{finalizable}, even if the original is not. +@item @code{notify(Object)} -- The VM should choose one of the threads waiting +for a lock on the specified object arbitrarily, and wake it. If the current +thread does not currently hold the lock on the object, then an +@code{IllegalMonitorStateException} should be thrown. +@item @code{notifyAll(Object)} -- Same as the above, but all threads are +awakened. +@item @code{wait(Object,long,int)} -- The VM should set the current thread +into a waiting state, which persists until it receives a notify signal or the +specified time (in milliseconds and nanoseconds) is exceeded. The nanoseconds +restriction may be ignored if such granularity is not available, and a +@code{IllegalMonitorStateException} should be thrown if the current thread +doesn't own the object. +@end itemize + +@node java.lang.VMClassLoader, java.lang.VMSystem, java.lang.VMObject, java.lang +@subsection @code{java.lang.VMClassLoader} +@code{VMClassLoader} provides methods for defining and resolving core and +primitive classes, as well as handling resources, packages and assertions. +The class is a mixture of @code{native} methods and Java-based +implementations, with some of the latter being @emph{stubs}. + +@itemize @bullet +@item Native Methods +@itemize @bullet +@item @code{defineClass(ClassLoader,String,byte[],int,int,ProtectionDomain)} +-- The VM should create a @code{Class} instance from the supplied byte array. +@item @code{resolveClass(Class)} -- Resolve references to other classes in the +supplied class. +@item @code{loadClass(name,boolean)} -- Load a class using the bootstrap +loader. +@item @code{getPrimitiveClass(char)} -- The VM should provide a @code{Class} +implementation for one of the primitive classes. The supplied character +matches the JNI code for the primitive class e.g. `B' for byte and +`Z' for boolean. +@end itemize +@item Java Methods +@itemize @bullet +@item @code{getResource(String)} -- The default implementation calls +@code{getResources} and returns the first element in the returned enumeration, +or @code{null} if there are no elements. +@item @code{getResources(String)} -- By default, this compiles a list of +URLs via the boot class path. Any matching files within a zip file are added, +and directories on the boot class path are automatically converted to file +URLs that refer to join the directory with the resource name (whether or not +it actually exists). +@item @code{getPackage(String)} -- Always returns null, which may be suitable +if the VM does not wish to return a @code{Package} implementation. Otherwise, +it may be necessary to make this a @code{native} method. +@item @code{getPackages()} -- As with the last, a default stub implementation +exists (returning an empty array) which may be replaced if support is +required. +@item @code{defaultAssertionStatus()} -- A stub which can be implemented +by VMs providing assertion support. At present, it always returns @code{true}. +@item @code{packageAssertionStatus()} -- Much the same status as the above. +The method should return a map converting package names to boolean status +values. The stub implementation provides an empty map. +@item @code{classAssertionStatus()} -- Same as the last, but for classes. +@item @code{getSystemClassLoader()} -- The default calls @code{ClassLoader} +to create a new auxillary class loader with a system and extension class +loader. The VM may wish to replace it if it wishes to supply its own custom +system class loader. +@end itemize +@end itemize +@node java.lang.VMSystem, java.lang.VMThrowable, java.lang.VMClassLoader, java.lang +@subsection @code{java.lang.VMSystem} +@code{VMSystem} handles the default I/O streams, provides access to the +system clock and environment variables and provides methods for +@code{System.arraycopy} and the @code{identityHashCode} of an +@code{Object}. It consists of @code{native} methods, but the default +implementation also provides some helper methods to simplify stream +creation. + +@itemize @bullet +@item Native Methods +@itemize @bullet +@item @code{arraycopy(Object,int,Object,int,int)} -- The VM should copy +a specified number of array objects from one array to another, with +appropriate checks for compatible typing, available elements and space. +The VM should be able to perform this more efficiently using native code +and direct memory manipulation than would have been achieved by using Java. +@item @code{identityHashCode(Object)} -- This is the hashcode for +@code{Object}, which relates to the actual location of the object in memory. +@item @code{setIn(InputStream)} -- Set the system input stream. +@item @code{setOut(PrintStream)} -- Set the system output stream. +@item @code{setErr(PrintStream)} -- Set the system error stream. +@item @code{currentTimeMillis()} -- Gets the system time in milliseconds. +@item @code{getenv(String)} -- Returns the value of the specified environment +variable. +@item @code{getenv()} -- Returns a list of `name=value' pairs which correspond +to the environment variables. +@end itemize +@item Java Methods +@itemize @bullet +@item @code{makeStandardInputStream()} -- Helps provide the functionality of +@code{System.in} by wrapping the appropriate file descriptor in a +buffered file input stream. VMs may choose to create the stream from +the descriptor differently rather than using this method. +@item @code{makeStandardOutputStream()} -- Helps provide the functionality of +@code{System.out} by wrapping the appropriate file descriptor in a buffered +file output stream. VMs may choose to create the stream from the descriptor +differently rather than using this method. +@item @code{makeStandardErrorStream()} -- Helps provide the functionality of +@code{System.err} by wrapping the appropriate file descriptor in a buffered +file output stream. VMs may choose to create the stream from the descriptor +differently rather than using this method. +@end itemize +@end itemize + +Classpath also provides native implementations of + +@itemize @bullet +@item @code{setIn(InputStream)} +@item @code{setOut(PrintStream)} +@item @code{setErr(PrintStream)} +@item @code{currentTimeMillis()} +@item @code{getenv(String)} +@end itemize + +making a VM implementation optional. + +@node java.lang.VMThrowable, java.lang.VMCompiler, java.lang.VMSystem, java.lang +@subsection @code{java.lang.VMThrowable} +@code{VMThrowable} is used to hold the VM state of a throwable, created either +when a @code{Throwable} is created or the @code{fillInStackTrace()} method is +called (i.e. when the actual stack trace is needed, as a lot of exceptions are +never actually used). The actual class has two @code{native} methods, +one (@code{fillInStackTrace()}) being a method of the class used to obtain +instances, and the other an instance method, @code{getStackTrace()}. +@itemize @bullet +@item @code{fillInStackTrace(Throwable)} -- The VM should return the current +execution state of the @code{Throwable} in the form of a @code{VMThrowable} +instance. The VM may also return @code{null} if it does not support this +functionality. +@item @code{getStackTrace()} -- This is used to create a real +@code{StackTraceElement} array for the exception, using the state data +stored during creation of the instance. +@end itemize + +@node java.lang.VMCompiler, java.lang.VMDouble, java.lang.VMThrowable, java.lang +@subsection @code{java.lang.VMCompiler} + +@code{VMCompiler} provides an interface for VMs which wish to provide +JIT compilation support. The default implementation is simply a series +of stubs. The property, @code{java.compiler}, should point to a library +containing the function @code{java_lang_Compiler_start()} if such support +is to be provided. + +@itemize @bullet +@item @code{compileClass(Class)} -- Invoke the compiler to compile the specific +class, returning @code{true} if successful. +@item @code{compileClasses(String)} -- The compiler should compile the classes +matching the specified string, again returning @code{true} on success. +@item @code{command(Object)} -- The object represents a command given to the +compiler, and is specific to the compiler implementation. +@item @code{enable} -- Enable the operation of the compiler. +@item @code{disable} -- Disable compiler operation. +@end itemize + +@node java.lang.VMDouble, java.lang.VMFloat, java.lang.VMCompiler, java.lang +@subsection @code{java.lang.VMDouble} + +@code{VMDouble} provides native support for the conversion and parsing +of doubles. + +@itemize @bullet +@item @code{doubleToLongBits(double)} -- Converts the double to the IEEE 754 +bit layout, collapsing NaNs to @code{0x7ff8000000000000L}. +@item @code{doubleToRawLongBits(double)} -- Same as the above, but preserves +NaNs. +@item @code{longBitsToDouble(long)} -- This is the inverse of the last method, +preserving NaNs so that the output of one can be fed into the other without +data loss. +@item @code{toString(double,boolean)} -- Converts the double to a string, +giving a shorter value if the flag @code{isFloat} is @code{true}, indicating +that the conversion was requested by @code{java.lang.Float} rather than +@code{java.lang.Double}. +@item @code{initIDs} -- Used by JNI-based solutions to initialize the cache +of the static field IDs. The default @code{VMDouble} implementation has a +static initializer which loads the JNI library and calls this method. +@item @code{parseDouble} -- Turn the string into a usable double value. +@end itemize + +Classpath provides native implementations of all these, making VM +implementation optional. + +@node java.lang.VMFloat, java.lang.VMProcess, java.lang.VMDouble, java.lang +@subsection @code{java.lang.VMFloat} + +@code{VMFloat} provides native support for the conversion of floats. + +@itemize @bullet +@item @code{floatToIntBits(float)} -- Converts the float to the IEEE 754 +bit layout, collapsing NaNs to @code{0x7fc00000}. +@item @code{floatToRawIntBits(float)} -- Same as the above, but preserves +NaNs. +@item @code{intBitsToFloat(int)} -- This is the inverse of the last method, +preserving NaNs so that the output of one can be fed into the other without +data loss. +@end itemize + +Classpath provides native implementations of all these, making VM +implementation optional. + +@node java.lang.VMProcess, java.lang.VMRuntime, java.lang.VMFloat, java.lang +@subsection @code{java.lang.VMProcess} + +@code{VMProcess} handles the execution of external processes. In the +default implementation, threads are spawned and reaped by @code{ProcessThread}. +A constructor creates a new @code{VMProcess}, which extends rather than +complements @code{Process}, using an array of arguments, an array of +environment variables and a working directory. The instance maintains +system input, output and error streams linked to the external process. +Three @code{native} methods are used, and implementations are provided +for all three by Classpath, making VM implementation optional. These use +the POSIX functions, @code{fork()}, @code{waitpid()} and @code{kill()}. + +@itemize @bullet +@item @code{nativeSpawn(String[],String[],File,boolean)} -- The VM should +create a new process which uses the specified command-line arguments, +environment variables and working directory. Unlike the other two +methods, this method is linked to an instance, and must call +@code{setProcessInfo()} with the results before returning. The +boolean argument maps to the @code{redirectErrorStream} property of +@code{java.lang.ProcessBuilder}. When true, the output and error streams +are merged. +@item @code{nativeReap()} -- This is called to perform a reap of any +zombie processes, and should not block, instead returning a boolean as to +whether reaping actually took place. +@item @code{nativeKill(long)} -- The VM should terminate the specified PID. +@end itemize + +@node java.lang.VMRuntime, java.lang.VMString, java.lang.VMProcess, java.lang +@subsection @code{java.lang.VMRuntime} + +The @code{VMRuntime} class provides a series of native methods +which divulge information about the runtime or invoke certain +operations. This includes retrieving the amount of available memory, +and scheduling the garbage collector. There are two exceptions: the +@code{enableShutdownHooks} method, which allows the VM to put in its own +shutdown hooks when @code{Runtime.addShutdownHook()} is first invoked, +and @code{exec(String[],String[],File)} which spawns an external process. +These are Java-based static methods instead. The first is simply a stub by +default, while the second simply links to the functionality of +@code{VMProcess} (and should be changed if a different @code{Process} +implementation is used). + +@itemize @bullet +@item @code{availableProcessors()} -- Returns the number of processors +available to the VM. +@item @code{freeMemory()} -- Returns the amount of memory the VM has available +on the heap for allocating. +@item @code{totalMemory()} -- Returns the size of the heap. +@item @code{maxMemory()} -- Returns the maximum memory block the VM will +attempt to allocate. May be simply @code{Long.MAX_VALUE} (8 exabytes!) +@item @code{gc()} -- Allows users to explicitly invoke the garbage collector. +This is a suggestion to the VM, rather than a command, and the garbage +collector should run anyway @emph{without} it being invoked. +@item @code{runFinalization()} -- Like the above, but related to the +finalilzation of objects rather than the garbage collector. +@item @code{runFinalizationForExit()} -- Called immediately prior to VM +shutdown in order to finalize all objects (including `live' ones) +@item @code{traceInstructions(boolean)} -- This turns on and off the optional +VM functionality of printing a trace of executed bytecode instructions. +@item @code{traceMethodCalls(boolean)} -- This turns on and off the optional +VM functionality of printing a trace of methods called. +@item @code{runFinalizersOnExit(boolean)} -- A toggleable setting for +running the finalization process at exit. +@item @code{exit(int)} -- The VM should shutdown with the specified exit code. +@item @code{nativeLoad(String,ClassLoader)} -- Attempts to load a file, +returning an integer which is non-zero for success. Nothing happens if the +file has already been loaded. +@item @code{mapLibraryName(String)} -- The VM should map the system-independent +library name supplied to the platform-dependent equivalent (e.g. a @code{.so} +or @code{.dll} file) +@end itemize + +@node java.lang.VMString, java.lang.VMThread, java.lang.VMRuntime, java.lang +@subsection @code{java.lang.VMString} +@code{VMString} is responsible for handling interned strings. If two strings +are equal (using the @code{equals()} method), then the results of calling +the @code{intern()} method on each of them makes them equal +(using @code{==}). Thus, the same string object is always returned by +@code{intern} if the two strings are equal. The default implementation +is Java-based and implements @code{intern(String)} by maintaining a +@code{WeakHashMap} which links the strings to their @code{WeakReference}. +A new mapping is created for each new string being @code{intern}ed. +A VM may implement this differently by implementing this method, +which is @code{static} and the only one in @code{VMString}. + +@node java.lang.VMThread, java.lang.VMMath, java.lang.VMString, java.lang +@subsection @code{java.lang.VMThread} + +@code{VMThread} provides the link between Java's threads and the platform +threading support. A @code{VMThread} is created via a private constructor +and linked to a @code{Thread} instance. This occurs when the @code{Thread} +instance is started by the static @code{create(Thread,long)} method (the second +argument requests a certain stack size, usually zero). The thread itself is +executed via the @code{run()} method, which handles any problems with the +running of the thread and its eventual death. + +@code{VMThread} provides the following accessors and mutators for accessing +the thread state via @code{VMThread}, + +@itemize @bullet +@item @code{getName()} +@item @code{setName(String)} +@item @code{getPriority()} +@item @code{setPriotity(int)} +@item @code{isDaemon()} +@end itemize + +all of which refer to the @code{Thread} instance. @code{setPriority(int)} also +calls the appropriate native method. @code{stop(Throwable)} similarly wraps +a native method, merely adding in a check for the state of the thread. + +The default implementation also provides Java-based implementations of +@code{join(long,int)}, @code{sleep(long,int)} and +@code{holdsLock(Object)}. @code{join} and @code{sleep} simply wait for +the appropriate amount of time, with @code{join} additionally waiting +for the thread instance to become @code{null}. @code{holdsLock} simply +checks if an object is locked by the current thread by trying to invoke +the @code{notify} method, and catching the failing exception if this is +not the case. + +The remainder of the class is a series of @code{native} methods, some of +which are mandatory for VM implementation and others which provide optional +or deprecated functionality. + +@itemize @bullet +@item Mandatory Instance Methods +@itemize @bullet +@item @code{start(long)} -- The VM should create the native thread and start +it running using the @code{run} method of the @code{VMThread} instance on +which this method is called. +@item @code{interrupt()} -- The VM should interrupt the running thread and +throw an appropriate exception. +@item @code{isInterrupted()} -- Checks the interrupted state of the thread. +@item @code{suspend()} -- The thread should be suspended until resumed. +@item @code{resume()} -- The thread should be resumed from its suspended state. +This pair of methods are deprecated, due to the possibility of a deadlock +occuring when a thread with locks is suspended. +@item @code{nativeSetPriority(int)} -- Called by @code{setPriority} +to allow the setting to flow down to the native thread. +@item @code{nativeStop(Throwable)} -- The VM should stop the thread abnormally +and throw the specified exception. This is clearly deprecated, due to the +ambiguous state an abruptly-stopped thread may leave. +@item @code{getState()} -- Returns the VM's impression of the current state +of the thread. The applicable states are supplied by the @code{State} +enumeration in @code{java.lang.Thread}. +@end itemize +@item Mandatory Class Methods +@itemize @bullet +@item @code{currentThread()} -- Return a reference to the thread currently +being executed. +@item @code{yield()} -- The VM should allow some other thread to run. +The current thread maintains its locks even though it stops executing for +the time being. +@item @code{interrupted()} -- A shortcut to obtaining the interrupted state +of the current thread. +@end itemize +@item Other Methods +@itemize @bullet +@item @code{countStackFrames()} -- Returns a count of the number of stack +frames in the thread. This depends on the deprecated method @code{suspend()} +having returned true, and is thus deprecated as a result. +@end itemize +@end itemize + +@node java.lang.VMMath,, java.lang.VMThread, java.lang +@subsection @code{java.lang.VMMath} + +The @code{VMMath} class provides a series of native methods +for some of the mathematical functions present in @code{java.lang.Math}. +Classpath provides a default implementation of these which maps the +functions to those provided by @code{fdlibm}. VM implementors are welcome +to replace this with more efficent implementations, as long as the accuracy +contract of these methods, specified in @code{java.lang.Math}, is maintained. + +@itemize @bullet +@item 1.0 +@itemize @bullet +@item @code{sin(double)} -- Returns the sine value for the given angle. +@item @code{cos(double)} -- Returns the cosine value for the given angle. +@item @code{tan(double)} -- Returns the tangent value for the given angle. +@item @code{asin(double)} -- Returns the arc sine value for the given angle. +@item @code{acos(double)} -- Returns the arc cosine value for the given angle. +@item @code{atan(double)} -- Returns the arc tangent value for the given angle. +@item @code{atan2(double,double)} -- Returns the arc tangent of the ratio of +the two arguments. +@item @code{exp(double)} -- Returns the exponent raised to the given power. +@item @code{log(double)} -- Returns the natural logarithm for the given value. +@item @code{sqrt(double)} -- Returns the square root of the value. +@item @code{pow(double,double)} -- Returns x to the power of y. +@item @code{IEEEremainder(double,double)} -- Returns the IEEE 754 remainder +for the two values. +@item @code{ceil(double)} -- Returns the nearest integer >= the value. +@item @code{floor(double)} -- Returns the nearest integer <= the value. +@item @code{rint(double)} -- Returns the nearest integer or the even one +if the distance between the two is equal. +@end itemize +@item 1.5 +@itemize @bullet +@item @code{cbrt(double)} -- Returns the cube root of the value. +@item @code{cosh(double)} -- Returns the hyperbolic cosine value for the given +angle. +@item @code{expm1(double)} -- Returns the exponent of the value minus one. +@item @code{hypot(double,double)} -- Returns the hypotenuse corresponding to +x and y. +@item @code{log10(double)} -- Returns the base 10 logarithm of the given value. +@item @code{log1p(double)} -- Returns the natural logarithm of the value plus +one. +@item @code{sinh(double)} -- Returns the hyperbolic sine value for the given +angle. +@item @code{tanh(double)} -- Returns the hyperbolic tangent value for the given angle. +@end itemize +@end itemize + +@node gnu.classpath, java.util, java.lang, Classpath Hooks +@section @code{gnu.classpath} + +The @code{gnu.classpath} package provides Classpath-specific functionality, +primarily relating to the features in @code{java.lang}. At present, this +includes the context of a class (the stack) and the system properties. + +@menu +* gnu.classpath.VMStackWalker:: +* gnu.classpath.VMSystemProperties:: +* gnu.classpath.Unsafe:: +@end menu + +@node gnu.classpath.VMStackWalker,gnu.classpath.VMSystemProperties,gnu.classpath,gnu.classpath +@subsection @code{gnu.classpath.VMStackWalker} + +@code{VMStackWalker} provides access to the class context or stack. The +default implementation consists of a @code{native} @code{static} method, +@code{getClassContext()}, which obtains the class context, and two helper +methods which obtain the calling class (the 3rd element in the context array) +and its class loader, respectively. + +@itemize @bullet +@item @code{getClassContext()} -- The VM should return an array of +@code{Class} objects, each of which relates to the method currently being +executed at that point on the stack. Thus, the first item (index 0) is the +class that contains this method. +@item @code{getCallingClass()} -- A Java-based helper method which returns +the @code{Class} object which contains the method that called the method +accessing @code{getCallingClass()}. +@item @code{getCallingClassLoader()} -- Like the last, but returning the class +loader of the class. +@end itemize + +@node gnu.classpath.VMSystemProperties,gnu.classpath.Unsafe,gnu.classpath.VMStackWalker,gnu.classpath +@subsection @code{gnu.classpath.VMSystemProperties} + +@code{VMSystemProperties} allows the VM to hook into the property creation +process, both before and after the system properties are added by GNU +Classpath. The default implementation assumes that the VM will add its +properties first, by making the pre-initialisation method @code{native}, +and that the Classpath properties may then be altered by a Java-based +post-initialisation method. + +As these methods are called as part of the bootstrap process, caution should +be used as to what classes are used, and properties should only be set +using @code{Properties.setProperty()}. Specifically, I/O classes should be +avoided at this early stage. + +@itemize @bullet +@item @code{preInit(Properties)} -- Allows the VM to add properties +@emph{before} the Classpath properties are added. The default implementation +includes a full list of properties that @emph{must} be added by the VM, but +additional VM-specific ones may also be added. +@item @code{postInit(Properties)} -- Same as the last, but called after the +Classpath properties have been added. The main purpose of this is to allow +the VM to alter the properties added by GNU Classpath to suit it. +@end itemize + +@node gnu.classpath.Unsafe,,gnu.classpath.VMSystemProperties,gnu.classpath +@subsection @code{gnu.classpath.Unsafe} + +The @code{Unsafe} class provides access to some low-level unsafe operations +as required by the addition of the java.util.concurrent classes. These +focus on direct memory access to the fields within the VM and providing +atomic update methods. + +@itemize @bullet +@item @code{objectFieldOffset(Field)} -- Provides the caller with the memory +offset of a particular field. +@item @code{compareAndSwap*(Object,long,*,*)} -- One of these methods is +provided for each of int, long and Object (hence the *s). The value of +a field pointed to by the given Object and offset is compared with the +first value and replaced with the second if they are the same. The reason +for this method is to make this change operation atomic. +@item @code{put/get*(Object,long,*)} -- These are like the last set of +methods, handling integers, longs and Objects, but the field is always +changed on a put. Different methods are provided for different semantics. +Ordered variants perform a lazy put, in that the change does not +immediately propogate to other threads, while the others provide +volatile or 'normal' semantics. +@item @code{arrayBaseOffset(Class)} and @code{arrayIndexScale(Class)} -- +These two methods allow an array class to be traversed by pointer +arithmetic, by gaining the address of the first element and then +scaling appropriately for the later ones. +@item @code{park(boolean,long)} and @code{unpark(Thread)} -- These methods +block and unblock threads respectively, with an optional timeout being +provided for the blocking. @code{unpark} is unsafe as the thread may have +been destroyed by native code. +@end itemize + +@node java.util, java.io, gnu.classpath, Classpath Hooks +@section java.util + +The @code{java.util} VM hooks provide links between the mix of functionality +present in that package, which includes collections, date and time handling +and parsing. At present, there is only one hook, which connects GNU Classpath +to the timezone information provided by the underlying platform. + +@menu +* java.util.VMTimeZone:: +@end menu + +@node java.util.VMTimeZone,,java.util,java.util +@subsection @code{java.util.VMTimeZone} + +@code{VMTimeZone} joins @code{TimeZone} to the platform timezone information +via the static method, @code{getDefaultTimeZoneId()}. The VM hook is +expected to return a @code{TimeZone} instance that represents the current +timezone in use by the platform. The default implementation provides +this functionality for POSIX or GNU-like systems, and VMs that want this +functionality can keep this implementation and implement the native +method, @code{getSystemTimeZoneId()}. This method is only called when +obtaining the timezone name from the @code{TZ} environment variable, +@code{/etc/timezone} and @code{/etc/localtime} all fail. This fallback +mechanism also means that a system which doesn't provide the above three +methods, but does provide a timezone in string form, can still use this +implementation. + +@node java.io, java.security, java.util, Classpath Hooks +@section java.io + +The @code{java.io} package is heavily reliant on access to the I/O facilities +of the underlying platform. As far as its VM hooks go, they provide two +areas of functionality to GNU Classpath, these being + +@itemize @bullet +@item File and directory queries and manipulation +@item Serialization of objects +@end itemize + +The first corresponds directly to most of the @code{File} class, while +the latter underlies the functionality provided by the +@code{ObjectInputStream} and @code{ObjectOutputStream}. More low-level I/O +is provided by @ref{java.nio}. + +@menu +* java.io.VMFile:: +* java.io.VMObjectInputStream:: +* java.io.VMObjectStreamClass:: +@end menu + +@node java.io.VMFile,java.io.VMObjectInputStream,java.io,java.io +@subsection @code{java.io.VMFile} + +@code{VMFile} allows GNU Classpath's @code{File} representations to +probe and modify the file system using the native functions of the +platform. The default implementation (which consists of both a +@code{VMFile} class and the native methods) is primarily UNIX-centric, +working with POSIX functions and assuming case-sensitive filenames, +without the restriction of the 8.3 format. It consists mainly of +@code{static} @code{native} methods, with a few Java helper methods. +The native methods represent the file as a string containing its path, +rather than using the object itself. + +@itemize @bullet +@item Native Methods +@itemize @bullet +@item @code{lastModified(String)} -- The native method should return a +@code{long} value that represents the last modified date of the file. +@item @code{setReadOnly(String)} -- Sets the file's permissions to read only, +in whichever way this is realised by the platform. +@item @code{create(String)} -- Create the named file. +@item @code{list(String)} -- The native method opens the named directory, +reads the contents and returns them as a Java @code{String} array. +@item @code{renameTo(String,String)} -- Renames the first file to the second. +@item @code{length(String)} -- Returns a @code{long} value representing +the file size. +@item @code{exists(String)} -- Tests for the existence of the named file +or directory. +@item @code{delete(String)} -- Deletes the file or directory. +@item @code{setLastModified(String,long)} -- Change the last modified time. +@item @code{mkdir(String)} -- Creates the named directory. +@item @code{isFile(String)} -- Tests that the named path references a file. +@item @code{canWrite(String)} -- Tests that the file can be written to. +This method is @code{synchronized}, so the object is locked during the check. +@item @code{canRead(String)} -- Complement of the last method. +@item @code{isDirectory(String)} -- Tests that the named path references +a directory. +@end itemize +@item Java Helper Methods +@itemize @bullet +@item @code{canWriteDirectory(File)} -- Checks that the directory can be +written to, by trying to create a temporary file in it. +@item @code{listRoots()} -- Returns the root of a GNU filesystem i.e. `/' +in an array. +@item @code{isHidden(String)} -- Checks whether the file starts with `.', +which is how files are hidden on UNIX-style systems. +@item @code{getName(String)} -- Pulls the actual filename from the end of +the path, by breaking off the characters after the last occurrence of the +platform's file separator. +@item @code{getCanonicalForm(String)} -- This converts a UNIX path to +its canonical form by removing the `.' and `..' sections that occur within. +@end itemize +@end itemize + +@node java.io.VMObjectInputStream,java.io.VMObjectStreamClass,java.io.VMFile,java.io +@subsection @code{java.io.VMObjectInputStream} + +This class consists of two methods which provide functionality used in +deserializing an object. @code{currentClassLoader()} provides the first +user-defined class loader from the class context +(@xref{gnu.classpath.VMStackWalker},) via a @code{PrivilegedAction}. +@code{allocateObject(Class,Class,Constructor)} is a @code{native} method +(a reference implementation is provided) which creates an object but +calls the constructor of another class, which is a superclass of the +object's class. + +@node java.io.VMObjectStreamClass,,java.io.VMObjectInputStream,java.io +@subsection @code{java.io.VMObjectStreamClass} + +@code{VMObjectStreamClass} is a series of @code{static} @code{native} +methods that provide some of the groundwork for @code{ObjectStreamClass} +and @code{ObjectStreamField}. @code{hasClassInitializer(Class)} works +with the former, and checks for the presence of a static initializer. +The remaining methods are of the form @code{setXXXNative(Field,Object,XXX)} +and support @code{ObjectStreamField}. One exists for each of the main types +(boolean, float, double, long, int, short, char, byte and object) and is used +to set the specified field in the supplied instance to the given value. + +A default implementation is provided for all of them, so a VM implementation +is optional. + +@node java.security, java.net, java.io, Classpath Hooks +@section java.security + +The @code{java.security} package provides support for Java's security +architecture. + +@menu +* java.security.VMAccessController:: +* java.security.VMSecureRandom:: +@end menu + +@node java.security.VMAccessController,java.security.VMSecureRandom,java.security,java.security +@subsection @code{java.security.VMAccessController} + +The @code{AccessController} is used to perform privileged actions. Its +hook class, @code{VMAccessController}, maintains the +@code{AccessControlContext} and the default implementation is purely +Java-based. The VM may choose to replace this with their own. +The methods in the reference version are as follows: + +@itemize @bullet +@item @code{pushContext(AccessControlContext)} -- Adds a new context to the +stack for the current thread. This is called before a privileged action +takes place. +@item @code{popContext()} -- Removes the top context from the stack. This +is performed after the privileged action takes place. +@item @code{getContext()} -- Either derives a context based on the +@code{ProtectionDomain}s of the call stack (see the next method) or returns +the top of the context stack. +@item @code{getStack()} -- Provides access to the call stack as a pair of +arrays of classes and method names. The actual implementation returns +an empty array, indicating that there are no permissions. +@end itemize + +@node java.security.VMSecureRandom,,java.security.VMAccessController,java.security +@subsection @code{java.security.VMSecureRandom} + +The @code{VMSecureRandom} class is used to provide access to +cryptographically secure random numbers. The default implementation +of the class runs eight threads that increment counters in a tight +loop, and XORs each counter to produce one byte of seed data. This is +not very efficient, and is not guaranteed to be random (the thread +scheduler is probably deterministic, after all). VM implementors +should provide a version of this class, which implements the method +@code{generateSeed(byte[],int,int)}, so that it fills the buffer using +a random seed from a system facility, such as a system entropy +gathering device or hardware random number generator. The parameters +are the usual set of buffer, offset and length and the method returns +the number of bytes actually generated, which may be less than that +requested. + +@node java.net, java.nio, java.security, Classpath Hooks +@section java.net + +The @code{java.net} package is heavily reliant on access to the networking +facilities of the underlying platform. The VM hooks provide information +about the available network interfaces, and access to lookup facilities +for network addresses. + +@menu +* java.net.VMInetAddress:: +* java.net.VMNetworkInterface:: +@end menu + +@node java.net.VMInetAddress,java.net.VMNetworkInterface,java.net,java.net +@subsection @code{java.net.VMInetAddress} + +@code{VMInetAddress} is a series of @code{static} @code{native} methods +which provide access to the platform's lookup facilities. All the methods +are implemented by GNU Classpath, making VM implementation optional, and +are as follows: + +@itemize @bullet +@item @code{getLocalHostname()} -- Wraps the @code{gethostname} function, and +falls back on `localhost'. +@item @code{lookupInaddrAny()} -- Returns the value of @code{INADDR_ANY}. +@item @code{getHostByAddr(byte[])} -- Looks up the hostname based on an IP +address. +@item @code{getHostByName(String)} -- The reverse of the last method, it +returns the IP addresses which the given host name resolves to. +@end itemize + +@node java.net.VMNetworkInterface,,java.net.VMInetAddress,java.net +@subsection @code{java.net.VMNetworkInterface} + +@code{VMNetworkInterface} currently consists of a single @code{static} +@code{native} method, @code{getInterfaces()}, which retrieves the +network interfaces available on the underlying platform as a @code{Vector}. +The current GNU Classpath implementation is a native stub. + +@node java.nio, java.nio.channels, java.net, Classpath Hooks +@section java.nio + +The @code{java.nio} package is part of the New I/O framework added in +Java 1.4. This splits I/O into the concepts of @emph{buffers}, +@emph{charsets}, @emph{channels} and @emph{selectors}, and +@code{java.nio} defines the buffer classes. As far as native and VM +code is concerned, the new package needs support for low-level efficient +buffer operations. + +@menu +* java.nio.VMDirectByteBuffer:: +@end menu + +@node java.nio.VMDirectByteBuffer,,java.nio,java.nio +@subsection @code{java.nio.VMDirectByteBuffer} + +A @code{ByteBuffer} maintains a buffer of bytes, and allows it to be +manipulated using primitive operations such as @code{get}, @code{put}, +@code{allocate} and @code{free}. A direct buffer avoids intermediate +copying, and uses native data which shouldn't be manipulated by a +garbage collector. The VM class consists of @code{static} @code{native} +methods, all of which are given default implementations by GNU +Classpath. + +@itemize @bullet +@item @code{init()} -- Creates an instance of an appropriate +@code{gnu.classpath.RawData} class. This class is not garbage +collected, is created natively and is used in the other methods to reference +the buffered data. +@item @code{allocate(int)} -- Allocates the memory for the buffer using +@code{malloc} and returns a reference to the @code{RawData} class. +@item @code{free(RawData)} -- Frees the memory used by the buffer. +@item @code{get(RawData,int)} -- Returns the data at the specified index. +@item @code{get(RawData,int,byte[],int,int)} -- Copies a section of the +data into a byte array using @code{memcpy}. +@item @code{put(RawData,int,byte)} -- Puts the given data in the buffer +at the specified index. +@item @code{adjustAddress(RawData,int)} -- Adjusts the pointer into the buffer. +@item @code{shiftDown(RawData,int,int,int)} -- Moves the content of the buffer +at an offset down to a new offset using @code{memmove}. +@end itemize + +@node java.nio.channels, gnu.java.nio, java.nio, Classpath Hooks +@section java.nio.channels + +Channels provide the data for the buffers with the New I/O packages. +For example, a channel may wrap a file or a socket. The VM hooks, +at the moment, simply allow the channels to be accessed by @code{java.io} +streams. + +@menu +* java.nio.channels.VMChannels:: +@end menu + +@node java.nio.channels.VMChannels,,java.nio.channels,java.nio.channels +@subsection @code{java.nio.channels.VMChannels} + +@code{VMChannels} provides the methods that create the channels or +streams. The default implementation is in pure Java and simply wraps +the channels in standard I/O classes from @code{java.io}. + +@itemize @bullet +@item @code{createStream(Class,Channel)} -- Creates a @code{FileChannel} +which wraps an instance of the specified stream class, created by reflection. +This method is private, and is used by the other two. +@item @code{newInputStream(ReadableByteChannel)} -- Wraps the channel +in a @code{FileInputStream}. +@item @code{newOutputStream(WritableByteChannel)} -- Wraps the channel +in a @code{FileOutputStream}. +@end itemize + +@node gnu.java.nio, java.lang.reflect, java.nio.channels, Classpath Hooks +@section gnu.java.nio + +The @code{gnu.java.nio} class provides Classpath implementations of the +interfaces provided by @code{java.nio}. The VM classes provide the native +support necessary to implement @emph{pipes} and @emph{selectors}. + +@menu +* gnu.java.nio.VMPipe:: +* gnu.java.nio.VMSelector:: +@end menu + +@node gnu.java.nio.VMPipe,gnu.java.nio.VMSelector,gnu.java.nio,gnu.java.nio +@subsection @code{gnu.java.nio.VMPipe} + +@code{VMPipe} provides the native functionality for a uni-directional pipe +between a source and a destination (sink) channel. It consists of one +@code{static} @code{native} method, @code{init(PipeImpl,SelectorProvider)}, +the reference implementation of which is currently a native stub. Ideally, +this should initialise the pipe at the native level. + +@node gnu.java.nio.VMSelector,,gnu.java.nio.VMPipe,gnu.java.nio +@subsection @code{gnu.java.nio.VMSelector} + +A @code{Selector} selects between multiple @code{SelectableChannel}s based +on their readiness and a key set. The VM hook for the Classpath implementation +of this is @code{VMSelector}, and this allows the actual @code{select()} +operation to be performed. This is represented by the @code{static} +@code{native} method, @code{select(int[],int[],int[],long)}, and a default +implementation of this is provided. + +@node java.lang.reflect, gnu.java.lang, gnu.java.nio, Classpath Hooks +@section @code{java.lang.reflect} +@code{java.lang.reflect} provides the interface to Java's reflection +facilities. Via reflection, programmers can obtain type information about +a particular instance at runtime or dynamically create new instances. + +@menu +* java.lang.reflect.VMArray:: +@end menu + +@node java.lang.reflect.VMArray,,,java.lang.reflect +@subsection @code{java.lang.reflect.VMArray} + +The @code{VMArray} class provides a hook, @code{createObjectArray}, +which the VM uses to generate a new non-primitive array of a +particular class and size. The default implementation simply passes +the job down to the standard JNI function, @code{NewObjectArray}. + +@node gnu.java.lang, gnu.java.lang.management, java.lang.reflect, Classpath Hooks +@section @code{gnu.java.lang} + +@code{gnu.java.lang} provides VM interfaces for the GNU +implementations of features in java.lang. Currently, this includes the +implementation of instrumentation. + +@menu +* gnu.java.lang.VMInstrumentationImpl:: +@end menu + +@node gnu.java.lang.VMInstrumentationImpl,,,gnu.java.lang +@subsection @code{gnu.java.lang.VMInstrumentationImpl} + +The @code{gnu.java.lang.VMInstrumentationImpl} and +@code{gnu.java.lang.InstrumentationImpl} classes provide an implementation of the +@code{java.lang.instrument.Instrument} interface. +A @code{InstrumentationImpl} object should be created by the VM when agents +are given in the command line (see the @code{java.lang.instrument} package +documentation). The VM has to set the static field +@code{VMClassLoader.instrumenter} to this object. The VM should implement the +static native methods of the @code{VMInstrumentationImpl} class. + +@itemize @bullet +@item @code{isRedefineClassesSupported()} -- Returns true if the JVM supports +class redefinition. +@item @code{redefineClasses()} -- Gives a set of classes with new bytecodes. +The VM must redefine the classes by reading the new bytecodes. +@item @code{getAllLoadedClass()} -- Returns an array of all loaded classes. +@item @code{getInitiatedClass()} -- Returns an array of all classes loaded +by a specific class loader. +@item @code{getObjectSize()} -- Gives the size of an object. +@end itemize + +Instrumentation allows to modify the bytecode of a class before it gets read +by the VM. In GNU Classpath, the @code{ClassLoader.defineClass} method calls +the @code{VMClassLoader.defineClassWithTransformers} method which first checks +if @code{VMClassLoader.instrumenter} is @code{null}. If it's the case, it +directly calls @code{VMClassLoader.defineClass}. If it's not the case, the +method calls at first the @code{InstrumentationImpl.callTransformers} method, +which calls each transformer registered to the @code{InstrumentationImpl} +object and returns a new bytecode array. Then, it calls the +@code{VMClassLoader.defineClass} method with this new bytecode array. + +The second use of instrumentation is to redefine a class after it has been +loaded by the VM. This is done in the Java application by calling the +@code{Instrumentation.redefineClasses} method of the standard interface on +a @code{Instrumentation} object. The @code{InstrumentationImpl.redefineClasses} +method calls the @code{VMInstrumentationImpl.redefineClasses} native method +which must be implemented by the VM. The implementation should call the +@code{InstrumentationImpl.callTransformers} method. + +@node gnu.java.lang.management, java.lang.management, gnu.java.lang, Classpath Hooks +@section @code{gnu.java.lang.management} + +@code{gnu.java.lang.management} provides the VM interfaces for the GNU +implementations of the management beans. + +@menu +* gnu.java.lang.management.VMRuntimeMXBeanImpl:: +* gnu.java.lang.management.VMClassLoadingMXBeanImpl:: +* gnu.java.lang.management.VMThreadMXBeanImpl:: +* gnu.java.lang.management.VMMemoryMXBeanImpl:: +* gnu.java.lang.management.VMCompilationMXBeanImpl:: +* gnu.java.lang.management.VMMemoryPoolMXBeanImpl:: +* gnu.java.lang.management.VMMemoryManagerMXBeanImpl:: +* gnu.java.lang.management.VMGarbageCollectorMXBeanImpl:: +@end menu + +@node gnu.java.lang.management.VMRuntimeMXBeanImpl,gnu.java.lang.management.VMClassLoadingMXBeanImpl,,gnu.java.lang.management +@subsection @code{gnu.java.lang.management.VMRuntimeMXBeanImpl} + +The @code{gnu.java.lang.management.RuntimeMXBeanImpl} provides an +implementation of the @code{java.lang.management.RuntimeMXBean} interface, +and is supported by VM functionality in the form of +@code{gnu.java.lang.management.VMRuntimeMXBeanImpl}. This provides a +series of methods, which should be implemented by the virtual machine +in order to provide the required information for the bean. The VM +methods are generally representative of information that is only +available from the virtual machine, such as the command-line arguments +it was given at startup. + +The methods are as follows: + +@itemize @bullet +@item @code{(getInputArguments())} -- The VM should supply +a @code{String} array containing each of the command-line +arguments, excluding those that are directed at the +@code{main()} method. The reference implementation expects +this to be a native method. +@item @code{(getName())} -- The VM developer should choose +an appropriate name for the virtual machine. This name can +be instance-specific e.g. it can include things like the +process identifier or host name of the machine, which only +apply to the current running instance. Thus, the intention is +that this name refers to the entity that the other information +refers to, rather than the VM in general. The reference +implementation supplies a default concatenation of the VM +name and version. +@item @code{(getStartTime())} -- This should return the number +of milliseconds at which the virtual machine was started. +The uptime property of the bean is provided relative to this +value. Again, the reference implementation also expects +this method to be native. +@end itemize + +The virtual machine also needs to provide either the +@code{sun.boot.class.path} or @code{java.boot.class.path} +property in order to support the optional boot class path +retrieval functionality. + +@node gnu.java.lang.management.VMClassLoadingMXBeanImpl,gnu.java.lang.management.VMThreadMXBeanImpl,gnu.java.lang.management.VMRuntimeMXBeanImpl,gnu.java.lang.management +@subsection @code{gnu.java.lang.management.VMClassLoadingMXBeanImpl} + +The @code{gnu.java.lang.management.ClassLoadingMXBeanImpl} provides an +implementation of the @code{java.lang.management.ClassLoadingMXBean} interface, +and is supported by VM functionality in the form of +@code{gnu.java.lang.management.VMClassLoadingMXBeanImpl}. This provides a +series of methods, which should be implemented by the virtual machine +in order to provide the required information for the bean. Implementing +this bean requires the VM to monitor when classes are loaded and unloaded, +and provide the option of verbose class loading output. + +The methods are as follows: + +@itemize @bullet +@item @code{(getLoadedClassCount())} -- This should return +the number of classes that are currently loaded by the VM. +@item @code{(getUnloadedClassCount())} -- This should return +the number of classes that have been loaded by the VM, but +have since been unloaded. +@item @code{(isVerbose())} -- This should return @code{true} +or @code{false}, depending on whether verbose class loading +output is turned or not, respectively. +@item @code{(setVerbose(boolean))} -- This should allow the +verbose class loading output to be turned on and off. +@end itemize + +@node gnu.java.lang.management.VMThreadMXBeanImpl,gnu.java.lang.management.VMMemoryMXBeanImpl,gnu.java.lang.management.VMClassLoadingMXBeanImpl,gnu.java.lang.management +@subsection @code{gnu.java.lang.management.VMThreadMXBeanImpl} + +The @code{gnu.java.lang.management.ThreadMXBeanImpl} provides an +implementation of the @code{java.lang.management.ThreadMXBean} interface, +and is supported by VM functionality in the form of +@code{gnu.java.lang.management.VMThreadMXBeanImpl}. This provides a +series of methods, which should be implemented by the virtual machine +in order to provide the required information for the bean. Implementing +this bean requires the VM to monitor thread-related statistics such as +how often the blocked and waiting states have been entered, as well as +additional optional support for time and contention monitoring. + +Optional support is determined by the following properties: + +@itemize @bullet +@item @code{gnu.java.lang.management.CurrentThreadTimeSupport} -- +This property should be present if the VM supports monitoring the +time used by the current thread. If time monitoring for all threads +is supported, this need not be provided. +@item @code{gnu.java.lang.management.ThreadTimeSupport} -- +This property should be present if the VM supports monitoring the +time used by all threads. +@item @code{gnu.java.lang.management.ThreadContentionSupport} -- +This property should be present if the VM supports thread contention +monitoring. +@end itemize + +In addition, the property +@code{gnu.java.lang.management.ThreadTimeInitallyEnabled} may be +set to the @code{String} value, @code{"true"}, if time monitoring +is enabled at startup. + +The methods are as follows: + +@itemize @bullet +@item @code{(findMonitorDeadlockedThreads())} -- This should return +an array of thread identifiers which match threads involved in +deadlock cycles (where each thread is waiting to obtain a lock +held by one of the others). This is specified as a native method +in the reference implementation. +@item @code{(getAllThreads())} -- This should return an array of +all live threads and set the @code{filled} variable to the number +found. A default implementation is provided. +@item @code{(getAllThreadIds())} -- This should return an array of +all live thread identifiers. An implementation is provided against +@code{getAllThreads()} by default. +@item @code{(getCurrentThreadCpuTime())} -- This should return the +approximate number of nanoseconds of CPU time the current thread +has used. This is an optional native method, which is used by VMs +supporting time monitoring. +@item @code{(getCurrentThreadUserTime())} -- This should return the +approximate number of nanoseconds of user time the current thread +has used. This is an optional native method, which is used by VMs +supporting time monitoring. +@item @code{(getDaemonThreadCount())} -- This should return the number +of live daemon threads. A default implementation is provided, based +on @code{getAllThreads()}. +@item @code{(getPeakThreadCount())} -- The VM should maintain a record +of the peak number of live threads, and return it when this method is +called. This is specified as a native method in the reference +implementation. +@item @code{(resetPeakThreadCount())} -- This should reset the record +of the peak number of live threads to the current number of live +threads. This is specified as a native method in the reference +implementation. +@item @code{(getThreadCount())} -- This should return the number of +live threads. A default implementation is provided, based on +@code{getAllThreads()}. +@item @code{(getThreadCpuTime(long))} -- This should return the +approximate number of nanoseconds of CPU time the specified thread +has used. This is an optional native method, which is used by VMs +supporting time monitoring. +@item @code{(getThreadUserTime(long))} -- This should return the +approximate number of nanoseconds of CPU time the specified thread +has used. This is an optional native method, which is used by VMs +supporting time monitoring. +@item @code{(getThreadInfoForId(long, int))} -- This return an instance +of @code{java.lang.management.ThreadInfo} for the specified thread. +The class includes a private constructor which VMs should use to initialise +it with the appropriate values for the thread. The second argument +given here specifies the depth of the stack trace supplied on construction +of the instance. Special values are 0 (return an empty array) and +@code{Integer.MAX_VALUE} (return the maximum depth possible). This +is specified as a native method in the reference implementation. +@item @code{(getTotalStartedThreadCount())} -- This should return the +total number of threads that have been started by the VM, including ones +that have died. This is specified as a native method in the reference +implementation. +@end itemize + +@node gnu.java.lang.management.VMMemoryMXBeanImpl,gnu.java.lang.management.VMCompilationMXBeanImpl,gnu.java.lang.management.VMThreadMXBeanImpl,gnu.java.lang.management +@subsection @code{gnu.java.lang.management.VMMemoryMXBeanImpl} + +The @code{gnu.java.lang.management.MemoryMXBeanImpl} provides an +implementation of the @code{java.lang.management.MemoryMXBean} interface, +and is supported by VM functionality in the form of +@code{gnu.java.lang.management.VMMemoryMXBeanImpl}. This provides a +series of methods, which should be implemented by the virtual machine +in order to provide the required information for the bean. Implementing +this bean requires the VM to monitor the levels of heap and non-heap +memory, and provide the number of objects which are eligible for garbage +collection. + +The methods are as follows: + +@itemize @bullet +@item @code{(getHeapMemoryUsage())} -- This should return +an instance of @code{java.lang.management.MemoryUsage} with +values pertaining to the heap. A default implementation is +provided, based on @code{java.lang.Runtime}'s methods. +@item @code{(getNonHeapMemoryUsage())} -- This should return +an instance of @code{java.lang.management.MemoryUsage} with +values pertaining to non-heap memory. +@item @code{(getObjectPendingFinalizationCount())} -- Returns +the number of objects which are no longer referenced, and which +will thus be garbage collected on the next run of the garbage +collector. +@item @code{(isVerbose())} -- This should return @code{true} +or @code{false}, depending on whether verbose memory management +output is turned or not, respectively. +@item @code{(setVerbose(boolean))} -- This should allow the +verbose memory management output to be turned on and off. +@end itemize + +@node gnu.java.lang.management.VMCompilationMXBeanImpl,gnu.java.lang.management.VMMemoryPoolMXBeanImpl,gnu.java.lang.management.VMMemoryMXBeanImpl,gnu.java.lang.management +@subsection @code{gnu.java.lang.management.VMCompilationMXBeanImpl} + +The @code{gnu.java.lang.management.CompilationMXBeanImpl} provides an +implementation of the optional @code{java.lang.management.CompilationMXBean} +interface, and is supported by VM functionality in the form of +@code{gnu.java.lang.management.VMCompilationMXBeanImpl}. This provides a +single method for returning the number of milliseconds the virtual +machine's Just-In-Time (JIT) compiler has spent compiling. Even if +a JIT compiler is available and an instance of the bean supplied, this +method is still optional. + +Optional support is determined by the following properties: + +@itemize @bullet +@item @code{gnu.java.lang.compiler.name} -- This property should +specify the name of the JIT compiler. Classpath also uses this, +within @code{java.lang.management.ManagementFactory}, to determine +whether a bean should be created. If this property is set to a +non-null value, a bean will be created and its @code{getName()} +method will return this value. +@item @code{gnu.java.lang.management.CompilationTimeSupport} -- +This property should be present if the VM supports monitoring the +time spent compiling. +@end itemize + +Time support is implemented by the following method: + +@itemize @bullet +@item @code{(getTotalCompilationTime())} -- This should return the +number of milliseconds the JIT compiler has spent compiling. +@end itemize + +@node gnu.java.lang.management.VMMemoryPoolMXBeanImpl,gnu.java.lang.management.VMMemoryManagerMXBeanImpl,gnu.java.lang.management.VMCompilationMXBeanImpl,gnu.java.lang.management +@subsection @code{gnu.java.lang.management.VMMemoryPoolMXBeanImpl} + +The @code{gnu.java.lang.management.MemoryPoolMXBeanImpl} provides an +implementation of the optional @code{java.lang.management.MemoryPoolMXBean} +interface, and is supported by VM functionality in the form of +@code{gnu.java.lang.management.VMMemoryPoolMXBeanImpl}. Providing +this interface requires implementing a number of methods for each supported +pool. These return statistics on memory usage, and, optionally, allows +monitoring of when memory usage exceedes a preset threshold. + +Optional support is determined by the following properties: + +@itemize @bullet +@item @code{gnu.java.lang.management.CollectionUsageThresholdSupport} -- +This property should be present if the VM supports setting a collection +usage threshold and monitoring when it is matched or exceeded. Collection +usage thresholds are related to the remaining memory usage following a +garbage collection cycle. +@item @code{gnu.java.lang.management.UsageThresholdSupport} -- +This property should be present if the VM supports setting a +usage threshold and monitoring when it is matched or exceeded. +@end itemize + +The methods are as follows (all take a pool name as their +first parameter): + +@itemize @bullet +@item @code{(getCollectionUsage(String))} -- Returns a +@code{java.lang.management.MemoryUsage} object, containing the +memory usage statistics following a garbage collection cycle +for the specified pool. This may also return @code{null} if +the pool isn't an appropriate pool for this particular task. +@item @code{(getCollectionUsageThreshold(String))} -- Returns +the pool's collection usage threshold, if supported. +@item @code{(getCollectionUsageThresholdCount(String))} -- Returns +the number of times the specified pool has matched or exceeded +its collection usage threshold, if supported. +@item @code{(getMemoryManagerNames(String))} -- Returns a list +of names of memory managers which manage the specified pool. +@item @code{(getPeakUsage(String))} -- Returns a +@code{java.lang.management.MemoryUsage} object for the peak +usage level of the specified pool. +@item @code{(getType(String))} -- Returns a string containing +either @code{"HEAP"} or @code{"NON_HEAP"} which indicates the type of +memory used by the specified pool. +@item @code{(getUsage(String))} -- Returns a +@code{java.lang.management.MemoryUsage} object for the current +usage level of the specified pool. +@item @code{(getUsageThreshold(String))} -- Returns +the pool's usage threshold, if supported. +@item @code{(getUsageThresholdCount(String))} -- Returns +the number of times the specified pool has matched or exceeded +its usage threshold, if supported. +@item @code{(isValid(String))} -- Returns true if the pool +is still in use by the virtual machine. +@item @code{(resetPeakUsage(String))} -- Resets the peak usage +levels to the current usage levels for the specified pool. +@item @code{(setCollectionUsageThreshold(String, long))} -- Sets +the pool's collection usage threshold, if supported. +@item @code{(setUsageThreshold(String, long))} -- Sets +the pool's usage threshold, if supported. +@end itemize + +@node gnu.java.lang.management.VMMemoryManagerMXBeanImpl,gnu.java.lang.management.VMGarbageCollectorMXBeanImpl,gnu.java.lang.management.VMMemoryPoolMXBeanImpl,gnu.java.lang.management +@subsection @code{gnu.java.lang.management.VMMemoryManagerMXBeanImpl} + +The @code{gnu.java.lang.management.MemoryManagerMXBeanImpl} provides an +implementation of the optional @code{java.lang.management.MemoryManagerMXBean} +interface, and is supported by VM functionality in the form of +@code{gnu.java.lang.management.VMMemoryManagerMXBeanImpl}. Providing +this interface requires implementing two methods (each takes the name +of the manager as the first argument): + +@itemize @bullet +@item @code{(getMemoryPoolNames(String))} -- Returns a list of the +memory pools that the manager maintains. A default implementation +which scans the results of @code{getMemoryManagerNames()} for each +pool is provided. +@item @code{(isValid(String))} -- Returns true if the specified +manager is still valid i.e. it is still in use by the virtual machine. +@end itemize + +@node gnu.java.lang.management.VMGarbageCollectorMXBeanImpl,,gnu.java.lang.management.VMMemoryManagerMXBeanImpl,gnu.java.lang.management +@subsection @code{gnu.java.lang.management.VMGarbageCollectorMXBeanImpl} + +The @code{gnu.java.lang.management.GarbageCollectorMXBeanImpl} provides an +implementation of the optional @code{java.lang.management.GarbageCollectorMXBean} +interface, and is supported by VM functionality in the form of +@code{gnu.java.lang.management.VMGarbageCollectorMXBeanImpl}. Providing +this interface requires implementing two methods (each takes the name +of the garbage collector as the first argument): + +@itemize @bullet +@item @code{(getCollectionCount(String))} -- Returns the number of +times the specified garbage collector has run. +@item @code{(getCollectionTime(String))} -- Returns the accumulated +number of milliseconds for which the garbage collector has run. +@end itemize + +Note that each garbage collector is also a memory manager, and so an +implementation of the @code{gnu.java.lang.management.VMMemoryManagerMXBeanImpl} +methods for its name should also be provided. + +@node java.lang.management, Classpath Callbacks, gnu.java.lang.management, Classpath Hooks +@section @code{java.lang.management} + +@code{gnu.java.lang.management} provides the VM interfaces for the GNU +implementations of the management beans. + +@menu +* java.lang.management.VMManagementFactory:: +@end menu + +@node java.lang.management.VMManagementFactory,,,java.lang.management +@subsection @code{java.lang.management.VMManagementFactory} + +This VM interface provides the names of the memory pools, memory managers +and garbage collectors for use by the @code{java.lang.management.ManagementFactory} +in creating lists of appropriate beans for these types of managed object. + +The methods are as follows: + +@itemize @bullet +@item @code{(getMemoryPoolNames())} -- Returns a list of the names +of the current memory pools in use by the virtual machine. +@item @code{(getMemoryManagerNames())} -- Returns a list of the names +of the current memory managers in use by the virtual machine. This +should not include those that are also garbage collectors. +@item @code{(getGarbageCollectorNames())} -- Returns a list of the names +of the current garbage collectors in use by the virtual machine. +@end itemize + +@node Classpath Callbacks, , java.lang.management, Classpath Hooks +Some of the classes you implement for the VM will need to call back to +package-private methods in Classpath: + +@itemize @bullet +@item @code{java.lang.ThreadGroup.addThread(Thread)} +Call this method from @code{Thread} when a new @code{Thread} is created, to add it to +the group. + +@item @code{java.lang.ThreadGroup.removeThread(Thread)} +Call this method from @code{Thread} when a @code{Thread} is stopped or destroyed. + +@item @code{gnu.java.lang.management.MemoryMXBeanImpl.fireThresholdExceededNotification(String, long, long, long, long)} +If the monitoring of memory usage thresholds is supported, this method +should be called when the normal usage of a memory pool crosses the +threshold, in order to emit a notification. Another notification +should not be emitted until there is an intermittent period where the +usage is again below the threshold. The parameters are the memory +pool name, the usage levels (init, used, committed and max) and the +number of times the threshold has been crossed. + +@item @code{gnu.java.lang.management.MemoryMXBeanImpl.fireCollectionThresholdExceededNotification(String, long, long, long, long)} +If the monitoring of memory usage thresholds is supported, this method +should be called when the usage of a memory pool after a garbage +collection cycle crosses the threshold, in order to emit a +notification. Another notification should not be emitted until there +is an intermittent period where the usage is again below the +threshold. The parameters are the memory pool name, the usage levels +(init, used, committed and max) and the number of times the threshold +has been crossed. + +@end itemize + +@node VM Hooks, JNI Implementation, Classpath Hooks, Top +@comment node-name, next, previous, up +@chapter VM Hooks + +VMs need to do some dirty work; there are some things in the VM that +unfortunately are dependent on the internal structure of various +classes. This is a guide to all of the things the VM itself needs to +know about classes. + +Some of the core classes, while being implemented by GNU Classpath, +provide space for state (in the form of a @code{vmdata} object) to be +stored by the VM, and can not be constructed normally. + +@itemize @bullet +@item java.lang.Class +@item java.lang.ClassLoader +@end itemize + +The default implementations of some VM classes also follow this methodology, +when it is intended that most VMs will keep the default. + +@itemize @bullet +@item java.lang.VMThread +@item java.lang.VMThrowable +@end itemize + +Several core classes must be completely implemented by the VM for Classpath to +work, although reference implementations are provided. These classes are: + +@itemize @bullet +@item java.lang.reflect.Constructor +@item java.lang.reflect.Method +@item java.lang.reflect.Field +@end itemize + +The following issues are of note; + +@itemize @bullet +@item @code{java.lang.Class} @* +The GNU Classpath implementation of @code{java.lang.Class} provides an +object for storing the internal state of the class maintained by the VM. +This is the only known place where this matters. The class is +constructed with this data by the VM. Some VMs do not create the +@code{Class} object at the point where the class is defined; instead, +they wait until a @code{Class} object is actually used. + +@item Array Classes @* +When you are creating an array class, you should set the +@code{ClassLoader} of the array class to the @code{ClassLoader} of its +component type. Whenever you add a class to a @code{ClassLoader}, you +need to notify the @code{ClassLoader} and add the new @code{Class} to +its internal cache of classes. To do this, call +@code{ClassLoader.addVMCreatedClass(Class)}. @emph{Note: this is +written in anticipation of 1.2 support and does not apply just yet.} + +@item Primordial Class Loader @* +When the primordial class loader loads a class, it needs to tell +Classpath what it has done in order for security stuff to work right. +To do this, call the static method +@code{ClassLoader.newPrimordialClass(Class)}. + +Even the first few core classes need to do this; in order to do it, +simply call this method @emph{after} the initial class loading has been +done. No harm will come, as long as you follow the guidelines in the +@pxref{Initialization} section. + +@emph{Note: this is written in anticipation of 1.2 support and does not +apply just yet.} + +@item Top-level Exception Handler @* +Exceptions take care of themselves in Classpath; all you need to do in +the top-level exception handler is call @code{Throwable.printStackTrace()}. + +@item Security and Traces @* +There will eventually be a feature in the 1.2 security that keeps the +@code{AccessController} from having to evaluate @emph{all} of the +@code{ProtectionDomain}s every time a security check is made. I think a common +case is a single method doing a lot of things that require security +checks. However, I don't want to bog down the method stack too much, so +this feature of the VM will have the @code{AccessController} for a thread +calling out to the VM to tell it how high it was on the stack when it +made the last security request. Every time the stack goes lower than +that number, the VM will decrement the number. The @code{AccessController} +will remember what the accumulated protection status was at every stack +level (an @code{AccessControlContext}) and use that aggregated information to +do the check. I am not sure, however, whether the savings are +substantial enough to outweigh the integer check and set after every +method call. I will investigate. + +@item Threading @* +I figured I'd put this here because a VM guy might be wondering about it. +We implement @code{ThreadGroup}, but that class is almost entirely +VM-independent. The root @code{ThreadGroup}, a static field called +@code{ThreadGroup.root}, should be initialized by Classpath, but if you wish to +reinitialize it yourself, there should be no harm. + +@end itemize + +@node JNI Implementation, JVMTI Implementation, VM Hooks, Top +@comment node-name, next, previous, up +@chapter JNI Implementation + +Classpath comes with its own implementation of @file{jni.h}. This +file can be customized by the VM in a few ways, by defining macros +that affect the interpretation of the file. These macros are all +intended for use by a VM which uses GNU Classpath and which wants to +use a single copy of @file{jni.h} for both internal and external use. + +@itemize @bullet +@item _CLASSPATH_VM_JNI_TYPES_DEFINED +Some VMs like to define JNI ``object'' types in a special way. If +this macro is defined, the Classpath @file{jni.h} will avoid defining +these types. By default, these types are defined in @file{jni.h}. +The full list of types and macros treated this way is: @samp{jobject}, +@samp{jclass}, @samp{jstring}, @samp{jthrowable}, @samp{jweak}, +@samp{jarray}, @samp{jobjectArray}, @samp{jbyteArray}, +@samp{jshortArray}, @samp{jintArray}, @samp{jlongArray}, +@samp{jbooleanArray}, @samp{jcharArray}, @samp{jfloatArray}, +@samp{jdoubleArray}, @samp{JNIEnv}, @samp{JavaVM}, @samp{JNI_TRUE} +(macro), @samp{JNI_FALSE} (macro). + +@item _CLASSPATH_VM_INTERNAL_TYPES_DEFINED +If the VM has its own definitions for @samp{jfieldID} and +@samp{jmethodID}, then it should define this macro. Otherwise, +@file{jni.h} will provide definitions for these types. + +@item _CLASSPATH_JNIIMPEXP +Three functions -- @samp{JNI_GetDefaultJavaVMInitArgs}, +@samp{JNI_CreateJavaVM}, and @samp{JNI_GetCreatedJavaVMs} -- must be +marked as @samp{JNIIMPORT} when seen by user code, but most likely +should be marked as @samp{JNIEXPORT} when defined in the VM +implementation. This macro can be defined to one or the other by the +VM as appropriate. If this macro is not defined, it defaults to +@samp{JNIIMPORT}. + +@item _CLASSPATH_JNIENV_CONTENTS +A VM can add fields to the @samp{JNIEnv} structure by defining this to +be a sequence of field declarations. + +@end itemize + +@node JVMTI Implementation, Miscellaneous VM Requirements, JNI Implementation, Top +@comment node-name, next, previous, up +@chapter JVMTI Implementation + +Classpath comes with its own implementation of @file{jvmti.h}. This +file can be customized by the VM in a few ways by defining macros that +affect the interpretation of the file. These macros are all intended +for use for use by a VM which uses GNU Classpath and which wants to +use a single copy of @file{jvmti.h} for both internal and external use. + +@itemize @bullet +@item _CLASSPATH_VM_JVMTI_TYPES_DEFINED +Some VMs like to define JVMTI ``object'' types in a special way. If +this macro is defined, the Classpath @file{jvmti.h} will avoid defining +these types. By default these types are defined in @file{jvmti.h}. +The full list of types and macros treated this way is: @samp{jthread}, +@samp{jthreadGroup}, @samp{jlocation}, and @samp{jrawMonitorID}. By +default @samp{jrawMonitorID} is defined as an opaque pointer which +must be defined by the VM. + +@item _CLASSPATH_JVMTIENV_CONTENTS +A VM can add fields to the @samp{jvmtiEnv} structure by defining this +to be a sequence of field declarations. + +@end itemize + +@node Miscellaneous VM Requirements, , JVMTI Implementation, Top +@comment node-name, next, previous, up +@chapter Miscellaneous VM Requirements + +Classpath places a few requirements on the VM that uses it. + +@menu +* JNI Version:: +* VM Threading Model:: +* Boot Library Path Property:: +@end menu + +@node JNI Version, VM Threading Model, Miscellaneous VM Requirements, Miscellaneous VM Requirements +@comment node-name, next, previous, up +@section JNI Version + +Classpath currently uses only JNI 1.1, except for one JNI 1.2 function +in the JNI Invocation API: GetEnv(). And GetEnv() is only used in the +now deprecated ``portable native sync'' code. + +A future direction will probably be to require that all VMs provide +JNI 1.2. If this poses problems, please raise them on the classpath +mailing list. + +@node VM Threading Model, Boot Library Path Property, JNI Version, Miscellaneous VM Requirements +@comment node-name, next, previous, up +@section VM Threading Model + +VM authors can implement a number of different threading models. When +native code is also threaded there is the potential for one threading +model to deadlock the other. The +@uref{http://java.sun.com/docs/books/jni/html/other.html#29406,Java +Native Interface Programmer's Guide and Specification} suggests +consulting VM documentation in such situations. Classpath uses +existing libraries, for example the AWT peers can use the GTK+ +graphics library. As these libraries assume a different threading +model, there is the potential for the native code to deadlock a VM. + +The different threading models available to a VM author are: +@enumerate +@item +@i{Native threads}: Map a Java thread to an underlying operating system +thread (normally a POSIX compatible pthread). This approach reduces +the potential for deadlock as there is only one thread scheduling +mechanism. +@item +@i{Green threads 1}: Green threads are threads scheduled by the VM, +typically by switching swapping registers. In early VMs green threads +were seen as advantageous as they didn't require the operating system +to resechedule, save and swap all of a threads registers. The green +thread 1 model switches thread on an externally created event, such as +a timer interrupt. An example of a VM using this approach is Kaffe +configured with its jthreads model. +@item +@i{Green threads 2}: The essential difference with this model is to +not switch threads on an event, but at fixed points in the code being +executed by the VM. Points chosen could be backward branches (loops) +or method calls. This approach can be advantageous to nonconservative +garbage collectors, as non-running threads would be at known points +and can have fixed register maps. It can also reduce the number of +registers it is necessary to swap when switching threads. +@item +@i{M:N threading}: a flaw to green threading is that it is unable to +use multiple processors. @i{M}:@i{N} threading fixes this problem by +running groups of green threads on multiple underlying native +threads. An example of a VM using this approach is the Jikes RVM, +which uses @i{M}:@i{N} threading combined with the green thread 2 +model. +@end enumerate + +An example of the problem of mixing threading models is: +@itemize @bullet +@item +A Java thread calls a native method. The native method aquires a lock. +@item +The native method calls back into the VM. +@item +An event triggers the VM to reschedule the currently running thread. +@item +A new VM thread, executing on the same underlying native thread, calls +a native method. +@item +The native method tries to aquire the lock already aquired earlier. As +the lock is busy the thread waits and allows the operating system to +reschedule native threads. +@item +The operating system reschedules the VM thread again, but the lock is +still busy and in some threading models will remain busy forever +(the VM is deadlocked). +@end itemize + +VMs that don't use the underlying operating system thread scheduling +mechanism need to avoid deadlock. One now deprecated approach was to +build Classpath and VMs on top of a wrapper thread library (aka +portable native sync). The wrapper thread library used was GLIB's +@dfn{gthreads}. This approach has been deprecated because: +@enumerate +@item +The wrapper library is only in use by some native libraries. For +example, GTK+ uses the gthread library but QT does not. +@item +The wrapper library can't be in use prior to the VM starting as the VM +must replace the wrapper libraries functions with its own. This +prevents the VM from running as a plugin in an application that +already uses the wrapper library. +@end enumerate + +An alternative approach is for the VM to detect deadlocked native code +and swap Java threads off of that native thread. The VM can't, +however, swap two blocked native threads that are potentially +deadlocking each other on a lock. The lock will be associated with the +native thread. To prevent this from happening the VM must hijack +functions that operate on locks. This is done by redifining the lock +functions inside the VM and configuring the linker so that it uses the +VMs symbol in preference to that of the external thread support +library. The VM's lock function can then reschedule Java threads if it +must wait for the lock. + +@node Boot Library Path Property, , VM Threading Model, Miscellaneous VM Requirements +@comment node-name, next, previous, up +@section Boot Library Path Property + +As of GNU Classpath 0.15 a system property named @code{gnu.classpath.boot.library.path} +can be set by the VM to specify the directories which contain GNU Classpath's native +libraries. Usually this value is given at configuration time and is then hardcoded +in the VM. However for development purposes it is handy to switch to another installation +by overriding the properties' value on the command line. + +A VM that does not support this feature can simply ignore the property. + +For compatibility reasons we suggest to set the default value of @code{java.library.path} +to the value of the @code{LD_LIBRARY_PATH} environment if it exists on your platform. + +@bye + + + diff --git a/libjava/classpath/doc/hacking.texinfo b/libjava/classpath/doc/hacking.texinfo deleted file mode 100644 index efb7aa9..0000000 --- a/libjava/classpath/doc/hacking.texinfo +++ /dev/null @@ -1,1733 +0,0 @@ -\input texinfo @c -*-texinfo-*- - -@c %**start of header -@setfilename hacking.info -@settitle GNU Classpath Hacker's Guide -@c %**end of header - -@setchapternewpage off - -@ifinfo -This file contains important information you will need to know if you -are going to hack on the GNU Classpath project code. - -Copyright (C) 1998,1999,2000,2001,2002,2003,2004, 2005 Free Software Foundation, Inc. - -@ifnotplaintext -@dircategory GNU Libraries -@direntry -* Classpath Hacking: (hacking). GNU Classpath Hacker's Guide -@end direntry -@end ifnotplaintext -@end ifinfo - -@titlepage -@title GNU Classpath Hacker's Guide -@author Aaron M. Renn -@author Paul N. Fisher -@author John Keiser -@author C. Brian Jones -@author Mark J. Wielaard - -@page -@vskip 0pt plus 1filll -Copyright @copyright{} 1998,1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc. -@sp 2 -Permission is granted to make and distribute verbatim copies of -this document provided the copyright notice and this permission notice -are preserved on all copies. - -Permission is granted to copy and distribute modified versions of this -document under the conditions for verbatim copying, provided that the -entire resulting derived work is distributed under the terms of a -permission notice identical to this one. - -Permission is granted to copy and distribute translations of this manual -into another language, under the above conditions for modified versions, -except that this permission notice may be stated in a translation -approved by the Free Software Foundation. - -@end titlepage - -@ifinfo -@node Top, Introduction, (dir), (dir) -@top GNU Classpath Hacker's Guide - -This document contains important information you'll want to know if -you want to hack on GNU Classpath, Essential Libraries for Java, to -help create free core class libraries for use with virtual machines -and compilers for the java programming language. -@end ifinfo - -@menu -* Introduction:: An introduction to the GNU Classpath project -* Requirements:: Very important rules that must be followed -* Volunteering:: So you want to help out -* Project Goals:: Goals of the GNU Classpath project -* Needed Tools and Libraries:: A list of programs and libraries you will need -* Programming Standards:: Standards to use when writing code -* Hacking Code:: Working on code, Working with others -* Programming Goals:: What to consider when writing code -* API Compatibility:: How to handle serialization and deprecated methods -* Specification Sources:: Where to find class library specs -* Naming Conventions:: How files and directories are named -* Character Conversions:: Working on Character conversions -* Localization:: How to handle localization/internationalization - -@detailmenu - --- The Detailed Node Listing --- - -Programming Standards - -* Source Code Style Guide:: - -Working on the code, Working with others - -* Branches:: -* Writing ChangeLogs:: - -Working with branches - -* Writing ChangeLogs:: - -Programming Goals - -* Portability:: Writing Portable Software -* Utility Classes:: Reusing Software -* Robustness:: Writing Robust Software -* Java Efficiency:: Writing Efficient Java -* Native Efficiency:: Writing Efficient JNI -* Security:: Writing Secure Software - -API Compatibility - -* Serialization:: Serialization -* Deprecated Methods:: Deprecated methods - -Localization - -* String Collation:: Sorting strings in different locales -* Break Iteration:: Breaking up text into words, sentences, and lines -* Date Formatting and Parsing:: Locale specific date handling -* Decimal/Currency Formatting and Parsing:: Local specific number handling - -@end detailmenu -@end menu - -@node Introduction, Requirements, Top, Top -@comment node-name, next, previous, up -@chapter Introduction - -The GNU Classpath Project is a dedicated to providing a 100% free, -clean room implementation of the standard core class libraries for -compilers and runtime environments for the java programming language. -It offers free software developers an alternative core library -implementation upon which larger java-like programming environments -can be build. The GNU Classpath Project was started in the Spring of -1998 as an official Free Software Foundation project. Most of the -volunteers working on GNU Classpath do so in their spare time, but a -couple of projects based on GNU Classpath have paid programmers to -improve the core libraries. We appreciate everyone's efforts in the -past to improve and help the project and look forward to future -contributions by old and new members alike. - -@node Requirements, Volunteering, Introduction, Top -@comment node-name, next, previous, up -@chapter Requirements - -Although GNU Classpath is following an open development model where input -from developers is welcome, there are certain base requirements that -need to be met by anyone who wants to contribute code to this project. -They are mostly dictated by legal requirements and are not arbitrary -restrictions chosen by the GNU Classpath team. - -You will need to adhere to the following things if you want to donate -code to the GNU Classpath project: - -@itemize @bullet -@item -@strong{Never under any circumstances refer to proprietary code while -working on GNU Classpath.} It is best if you have never looked at -alternative proprietary core library code at all. To reduce -temptation, it would be best if you deleted the @file{src.zip} file -from your proprietary JDK distribution (note that recent versions of -GNU Classpath and the compilers and environments build on it are -mature enough to not need any proprietary implementation at all when -working on GNU Classpath, except in exceptional cases where you need -to test compatibility issues pointed out by users). If you have -signed Sun's non-disclosure statement, then you unfortunately cannot -work on Classpath code at all. If you have any reason to believe that -your code might be ``tainted'', please say something on the mailing -list before writing anything. If it turns out that your code was not -developed in a clean room environment, we could be very embarrassed -someday in court. Please don't let that happen. - -@item -@strong{Never decompile proprietary class library implementations.} While -the wording of the license in Sun's Java 2 releases has changed, it is -not acceptable, under any circumstances, for a person working on -GNU Classpath to decompile Sun's class libraries. Allowing the use of -decompilation in the GNU Classpath project would open up a giant can of -legal worms, which we wish to avoid. - -@item -Classpath is licensed under the terms of the -@uref{http://www.fsf.org/copyleft/gpl.html,GNU General Public -License}, with a special exception included to allow linking with -non-GPL licensed works as long as no other license would restrict such -linking. To preserve freedom for all users and to maintain uniform -licensing of Classpath, we will not accept code into the main -distribution that is not licensed under these terms. The exact -wording of the license of the current version of GNU Classpath can be -found online from the -@uref{http://www.gnu.org/software/classpath/license.html, GNU -Classpath license page} and is of course distributed with current -snapshot release from @uref{ftp://ftp.gnu.org/gnu/classpath/} or by -obtaining a copy of the current CVS tree. - -@item -GNU Classpath is GNU software and this project is being officially sponsored -by the @uref{http://www.fsf.org/,Free Software Foundation}. Because of -this, the FSF will hold copyright to all code developed as part of -GNU Classpath. This will allow them to pursue copyright violators in court, -something an individual developer may neither have the time nor -resources to do. Everyone contributing code to GNU Classpath will need to -sign a copyright assignment statement. Additionally, if you are -employed as a programmer, your employer may need to sign a copyright -waiver disclaiming all interest in the software. This may sound harsh, -but unfortunately, it is the only way to ensure that the code you write -is legally yours to distribute. -@end itemize - -@node Volunteering, Project Goals, Requirements, Top -@comment node-name, next, previous, up -@chapter Volunteering to Help - -The GNU Classpath project needs volunteers to help us out. People are -needed to write unimplemented core packages, to test GNU Classpath on -free software programs written in the java programming language, to -test it on various platforms, and to port it to platforms that are -currently unsupported. - -While pretty much all contributions are welcome (but see -@pxref{Requirements}) it is always preferable that volunteers do the -whole job when volunteering for a task. So when you volunteer to write -a Java package, please be willing to do the following: - -@itemize @bullet -@item -Implement a complete drop-in replacement for the particular package. -That means implementing any ``internal'' classes. For example, in the -java.net package, there are non-public classes for implementing sockets. -Without those classes, the public socket interface is useless. But do -not feel obligated to completely implement all of the functionality at -once. For example, in the java.net package, there are different types -of protocol handlers for different types of URL's. Not all of these -need to be written at once. - -@item -Please write complete and thorough API documentation comments for -every public and protected method and variable. These should be -superior to Sun's and cover everything about the item being -documented. - -@item -Please write a regression test package that can be used to run tests -of your package's functionality. GNU Classpath uses the -@uref{http://sources.redhat.com/mauve/,Mauve project} for testing the -functionality of the core class libraries. The Classpath Project is -fast approaching the point in time where all modifications to the -source code repository will require appropriate test cases in Mauve to -ensure correctness and prevent regressions. -@end itemize - -Writing good documentation, tests and fixing bugs should be every -developer's top priority in order to reach the elusive release of -version 1.0. - -@node Project Goals, Needed Tools and Libraries, Volunteering, Top -@comment node-name, next, previous, up -@chapter Project Goals - -The goal of the Classpath project is to produce a -@uref{http://www.fsf.org/philosophy/free-sw.html,free} implementation of -the standard class library for Java. However, there are other more -specific goals as to which platforms should be supported. - -Classpath is targeted to support the following operating systems: - -@enumerate -@item -Free operating systems. This includes GNU/Linux, GNU/Hurd, and the free -BSDs. - -@item -Other Unix-like operating systems. - -@item -Platforms which currently have no Java support at all. - -@item -Other platforms such as MS-Windows. -@end enumerate - -While free operating systems are the top priority, the other priorities -can shift depending on whether or not there is a volunteer to port -Classpath to those platforms and to test releases. - -Eventually we hope the Classpath will support all JVM's that provide -JNI or CNI support. However, the top priority is free JVM's. A small -list of Compiler/VM environments that are currently actively -incorporating GNU Classpath is below. A more complete overview of -projects based on GNU classpath can be found online at -@uref{http://www.gnu.org/software/classpath/stories.html,the GNU -Classpath stories page}. - -@enumerate -@item -@uref{http://gcc.gnu.org/java/,GCJ} -@item -@uref{http://jamvm.sourceforge.net/,jamvm} -@item -@uref{http://kissme.sourceforge.net/,Kissme} -@item -@uref{http://www.ibm.com/developerworks/oss/jikesrvm/,Jikes RVM} -@item -@uref{http://www.sablevm.org/,SableVM} -@item -@uref{http://www.kaffe.org/,Kaffe} -@end enumerate - -As with OS platform support, this priority list could change if a -volunteer comes forward to port, maintain, and test releases for a -particular JVM. Since gcj is part of the GNU Compiler Collective it -is one of the most important targets. But since it doesn't currently -work out of the box with GNU Classpath it is currently not the easiest -target. When hacking on GNU Classpath the easiest is to use -compilers and runtime environments that that work out of the box with -it, such as the jikes compiler and the runtime environments jamvm and -kissme. But you can also work directly with targets like gcj and -kaffe that have their own copy of GNU Classpath currently. In that -case changes have to be merged back into GNU Classpath proper though, -which is sometimes more work. SableVM is starting to migrate from an -integrated GNU Classpath version to being usable with GNU Classpath -out of the box. - - -The initial target version for Classpath is the 1.1 spec. Higher -versions can be implemented (and have been implemented, including lots -of 1.4 functionality) if desired, but please do not create classes -that depend on features in those packages unless GNU Classpath already -contains those features. GNU Classpath has been free of any -proprietary dependencies for a long time now and we like to keep it -that way. But finishing, polishing up, documenting, testing and -debugging current functionality is of higher priority then adding new -functionality. - -@node Needed Tools and Libraries, Programming Standards, Project Goals, Top -@comment node-name, next, previous, up -@chapter Needed Tools and Libraries - -If you want to hack on Classpath, you should at least download and -install the following tools. And try to familiarize yourself with -them. Although in most cases having these tools installed will be all -you really need to know about them. Also note that when working on -(snapshot) releases only GCC 3.3+ (plus a free VM from the list above -and the libraries listed below) is needed. The other tools are only -needed when working directly on the CVS version. - -@itemize @bullet -@item -GCC 3.3+ -@item -CVS 1.11+ -@item -automake 1.7+ -@item -autoconf 2.59+ -@item -libtool 1.4.2+ -@item -GNU m4 1.4 -@item -texinfo 4.2+ -@end itemize - -All of these tools are available from -@uref{ftp://gnudist.gnu.org/pub/gnu/,gnudist.gnu.org} via anonymous -ftp, except CVS which is available from -@uref{http://www.cvshome.org/,www.cvshome.org}. They are fully -documented with texinfo manuals. Texinfo can be browsed with the -Emacs editor, or with the text editor of your choice, or transformed -into nicely printable Postscript. - -Here is a brief description of the purpose of those tools. - -@table @b - -@item GCC -The GNU Compiler Collection. This contains a C compiler (gcc) for -compiling the native C code and a compiler for the java programming -language (gcj). You will need at least gcj version 3.3 or higher. If -that version is not available for your platform you can try the -@uref{http://www.jikes.org/, jikes compiler}. We try to keep all code -compilable with both gcj and jikes at all times. - -@item CVS -A version control system that maintains a centralized Internet -repository of all code in the Classpath system. - -@item automake -This tool automatically creates Makefile.in files from Makefile.am -files. The Makefile.in is turned into a Makefile by autoconf. Why -use this? Because it automatically generates every makefile target -you would ever want (clean, install, dist, etc) in full compliance -with the GNU coding standards. It also simplifies Makefile creation -in a number of ways that cannot be described here. Read the docs for -more info. - -@item autoconf -Automatically configures a package for the platform on which it is -being built and generates the Makefile for that platform. - -@item libtool -Handles all of the zillions of hairy platform specific options needed -to build shared libraries. - -@item m4 -The free GNU replacement for the standard Unix macro processor. -Proprietary m4 programs are broken and so GNU m4 is required for -autoconf to work though knowing a lot about GNU m4 is not required to -work with autoconf. - -@item perl -Larry Wall's scripting language. It is used internally by automake. - -@item texinfo -Manuals and documentation (like this guide) are written in texinfo. -Texinfo is the official documentation format of the GNU project. -Texinfo uses a single source file to produce output in a number of formats, -both online and printed (dvi, info, html, xml, etc.). This means that -instead of writing different documents for online information and another -for a printed manual, you need write only one document. And when the work -is revised, you need revise only that one document. - -@end table - - -For compiling the native AWT libraries you need to have the following -libraries installed: - -@table @b -@item GTK+ 2.2.x -@uref{http://www.gtk.org/,GTK+} is a multi-platform toolkit for -creating graphical user interfaces. It is used as the basis of the -GNU desktop project GNOME. - -@item gdk-pixbuf -@uref{http://www.gnome.org/start/,gdk-pixbuf} is a GNOME library for -representing images. -@end table - - -GNU Classpath comes with a couple of libraries included in the source -that are not part of GNU Classpath proper, but that have been included -to provide certain needed functionality. All these external libraries -should be clearly marked as such. In general we try to use as much as -possible the clean upstream versions of these sources. That way -merging in new versions will be easiest. You should always try to get -bug fixes to these files accepted upstream first. Currently we -include the following 'external' libraries. Most of these sources are -included in the @file{external} directory. That directory also -contains a @file{README} file explaining how to import newer versions. - -@table @b - -@item GNU jaxp -Can be found in @file{external/jaxp}. Provides javax.xml, org.w3c and -org.xml packages. Upstream is -@uref{http://www.gnu.org/software/classpathx/,GNU ClasspathX}. - -@item fdlibm -Can be found in @file{native/fdlibm}. Provides native implementations -of some of the Float and Double operations. Upstream is -@uref{http://gcc.gnu.org/java/,libgcj}, they sync again with the -'real' upstream @uref{http://www.netlib.org/fdlibm/readme}. See also -java.lang.StrictMath. - -@end table - - -@node Programming Standards, Hacking Code, Needed Tools and Libraries, Top -@comment node-name, next, previous, up -@chapter Programming Standards - -For C source code, follow the -@uref{http://www.gnu.org/prep/standards/,GNU Coding Standards}. -The standards also specify various things like the install directory -structure. These should be followed if possible. - -For Java source code, please follow the -@uref{http://www.gnu.org/prep/standards/,GNU Coding -Standards}, as much as possible. There are a number of exceptions to -the GNU Coding Standards that we make for GNU Classpath as documented -in this guide. We will hopefully be providing developers with a code -formatting tool that closely matches those rules soon. - -For API documentation comments, please follow -@uref{http://java.sun.com/products/jdk/javadoc/writingdoccomments.html,How -to Write Doc Comments for Javadoc}. We would like to have a set of -guidelines more tailored to GNU Classpath as part of this document. - -@menu -* Source Code Style Guide:: -@end menu - -@node Source Code Style Guide, , Programming Standards, Programming Standards -@comment node-name, next, previous, up -@section Java source coding style - -Here is a list of some specific rules used when hacking on GNU -Classpath java source code. We try to follow the standard -@uref{http://www.gnu.org/prep/standards/,GNU Coding Standards} -for that. There are lots of tools that can automatically generate it -(although most tools assume C source, not java source code) and it -seems as good a standard as any. There are a couple of exceptions and -specific rules when hacking on GNU Classpath java source code however. -The following lists how code is formatted (and some other code -conventions): - - -@itemize @bullet - -@item -Java source files in GNU Classpath are encoded using UTF-8. However, -ordinarily it is considered best practice to use the ASCII subset of -UTF-8 and write non-ASCII characters using \u escapes. - -@item -If possible, generate specific imports (expand) over java.io.* type -imports. Order by gnu, java, javax, org. There must be one blank line -between each group. The imports themselves are ordered alphabetically by -package name. Classes and interfaces occur before sub-packages. The -classes/interfaces are then also sorted alphabetical. Note that uppercase -characters occur before lowercase characters. - -@example -import gnu.java.awt.EmbeddedWindow; - -import java.io.IOException; -import java.io.InputStream; - -import javax.swing.JFrame; -@end example - -@item -Blank line after package statement, last import statement, classes, -interfaces, methods. - -@item -Opening/closing brace for class and method is at the same level of -indent as the declaration. All other braces are indented and content -between braces indented again. - -@item -Since method definitions don't start in column zero anyway (since they -are always inside a class definition), the rational for easy grepping -for ``^method_def'' is mostly gone already. Since it is customary for -almost everybody who writes java source code to put modifiers, return -value and method name on the same line, we do too. - -@c fixme Another rational for always indenting the method definition is that itmakes it a bit easier to distinguish methods in inner and anonymousclasses from code in their enclosing context. NEED EXAMPLE. - -@item -Implements and extends on separate lines, throws too. Indent extends, -implements, throws. Apply deep indentation for method arguments. - -@c fixme Needs example. - -@item -Don't add a space between a method or constructor call/definition and -the open-bracket. This is because often the return value is an object on -which you want to apply another method or from which you want to access -a field. - -Don't write: - -@example - getToolkit ().createWindow (this); -@end example - -But write: -@example - getToolkit().createWindow(this); -@end example - -@item -The GNU Coding Standard it gives examples for almost every construct -(if, switch, do, while, etc.). One missing is the try-catch construct -which should be formatted as: - -@example - try - @{ - // - @} - catch (...) - @{ - // - @} -@end example - -@item -Wrap lines at 80 characters after assignments and before operators. -Wrap always before extends, implements, throws, and labels. - -@item -Don't put multiple class definitions in the same file, except for -inner classes. File names (plus .java) and class names should be the -same. - -@item -Don't catch a @code{NullPointerException} as an alternative to simply -checking for @code{null}. It is clearer and usually more efficient -to simply write an explicit check. - -For instance, don't write: - -@example -try - @{ - return foo.doit(); - @} -catch (NullPointerException _) - @{ - return 7; - @} -@end example - -If your intent above is to check whether @samp{foo} is @code{null}, -instead write: - -@example -if (foo == null) - return 7; -else - return foo.doit(); -@end example - -@item -Don't use redundant modifiers or other redundant constructs. Here is -some sample code that shows various redundant items in comments: - -@example -/*import java.lang.Integer;*/ -/*abstract*/ interface I @{ - /*public abstract*/ void m(); - /*public static final*/ int i = 1; - /*public static*/ class Inner @{@} -@} -final class C /*extends Object*/ @{ - /*final*/ void m() @{@} -@} -@end example - -Note that Jikes will generate warnings for redundant modifiers if you -use @code{+Predundant-modifiers} on the command line. - -@item -Modifiers should be listed in the standard order recommended by the -JLS. Jikes will warn for this when given @code{+Pmodifier-order}. - -@item -Because the output of different compilers differs, we have -standardized on explicitly specifying @code{serialVersionUID} in -@code{Serializable} classes in Classpath. This field should be -declared as @code{private static final}. Note that a class may be -@code{Serializable} without being explicitly marked as such, due to -inheritance. For instance, all subclasses of @code{Throwable} need to -have @code{serialVersionUID} declared. -@c fixme index -@c fixme link to the discussion - -@item -Don't declare unchecked exceptions in the @code{throws} clause of a -method. However, if throwing an unchecked exception is part of the -method's API, you should mention it in the Javadoc. There is one -important exception to this rule, which is that a stub method should -be marked as throwing @code{gnu.classpath.NotImplementedException}. -This will let our API comparison tools note that the method is not -fully implemented. - -@item -When overriding @code{Object.equals}, remember that @code{instanceof} -filters out @code{null}, so an explicit check is not needed. - -@item -When catching an exception and rethrowing a new exception you should -``chain'' the Throwables. Don't just add the String representation of -the caught exception. - -@example - try - @{ - // Some code that can throw - @} - catch (IOException ioe) - @{ - throw (SQLException) new SQLException("Database corrupt").setCause(ioe); - @} -@end example - -@item -Avoid the use of reserved words for identifiers. This is obvious with those -such as @code{if} and @code{while} which have always been part of the Java -programming language, but you should be careful about accidentally using -words which have been added in later versions. Notable examples are -@code{assert} (added in 1.4) and @code{enum} (added in 1.5). Jikes will warn -of the use of the word @code{enum}, but, as it doesn't yet support the 1.5 -version of the language, it will still allow this usage through. A -compiler which supports 1.5 (e.g. the Eclipse compiler, ecj) will simply -fail to compile the offending source code. - -@c fixme Describe Anonymous classes (example). -@c fixme Descibe Naming conventions when different from GNU Coding Standards. -@c fixme Describee API doc javadoc tags used. - -@end itemize - -Some things are the same as in the normal GNU Coding Standards: - -@itemize @bullet - -@item -Unnecessary braces can be removed, one line after an if, for, while as -examples. - -@item -Space around operators (assignment, logical, relational, bitwise, -mathematical, shift). - -@item -Blank line before single-line comments, multi-line comments, javadoc -comments. - -@item -If more than 2 blank lines, trim to 2. - -@item -Don't keep commented out code. Just remove it or add a real comment -describing what it used to do and why it is changed to the current -implementation. -@end itemize - - -@node Hacking Code, Programming Goals, Programming Standards, Top -@comment node-name, next, previous, up -@chapter Working on the code, Working with others - -There are a lot of people helping out with GNU Classpath. Here are a -couple of practical guidelines to make working together on the code -smoother. - -The main thing is to always discuss what you are up to on the -mailinglist. Making sure that everybody knows who is working on what -is the most important thing to make sure we cooperate most -effectively. - -We maintain a -@uref{http://www.gnu.org/software/classpath/tasks.html,Task List} -which contains items that you might want to work on. - -Before starting to work on something please make sure you read this -complete guide. And discuss it on list to make sure your work does -not duplicate or interferes with work someone else is already doing. -Always make sure that you submit things that are your own work. And -that you have paperwork on file (as stated in the requirements -section) with the FSF authorizing the use of your additions. - -Technically the GNU Classpath project is hosted on -@uref{http://savannah.gnu.org/,Savannah} a central point for -development, distribution and maintenance of GNU Software. Here you -will find the -@uref{https://savannah.gnu.org/projects/classpath/,project page}, bug -reports, pending patches, links to mailing lists, news items and CVS. - -You can find instructions on getting a CVS checkout for classpath at -@uref{https://savannah.gnu.org/cvs/?group=classpath}. - -You don't have to get CVS commit write access to contribute, but it is -sometimes more convenient to be able to add your changes directly to -the project CVS. Please contact the GNU Classpath savannah admins to -arrange CVS access if you would like to have it. - -Make sure to be subscribed to the commit-classpath mailinglist while -you are actively hacking on Classpath. You have to send patches (cvs -diff -uN) to this list before committing. - -We really want to have a pretty open check-in policy. But this means -that you should be extra careful if you check something in. If at all -in doubt or if you think that something might need extra explaining -since it is not completely obvious please make a little announcement -about the change on the mailinglist. And if you do commit something -without discussing it first and another GNU Classpath hackers asks for -extra explanation or suggests to revert a certain commit then please -reply to the request by explaining why something should be so or if -you agree to revert it. (Just reverting immediately is OK without -discussion, but then please don't mix it with other changes and please -say so on list.) - -Patches that are already approved for libgcj or also OK for Classpath. -(But you still have to send a patch/diff to the list.) All other -patches require you to think whether or not they are really OK and -non-controversial, or if you would like some feedback first on them -before committing. We might get real commit rules in the future, for -now use your own judgment, but be a bit conservative. - -Always contact the GNU Classpath maintainer before adding anything -non-trivial that you didn't write yourself and that does not come from -libgcj or from another known GNU Classpath or libgcj hacker. If you -have been assigned to commit changes on behalf of another project or -a company always make sure they come from people who have signed the -papers for the FSF and/or fall under the arrangement your company made -with the FSF for contributions. Mention in the ChangeLog who actually -wrote the patch. - -Commits for completely unrelated changes they should be committed -separately (especially when doing a formatting change and a logical -change, do them in two separate commits). But do try to do a commit of -as much things/files that are done at the same time which can -logically be seen as part of the same change/cleanup etc. - -When the change fixes an important bug or adds nice new functionality -please write a short entry for inclusion in the @file{NEWS} file. If it -changes the VM interface you must mention that in both the @file{NEWS} file -and the VM Integration Guide. - -All the ``rules'' are really meant to make sure that GNU Classpath -will be maintainable in the long run and to give all the projects that -are now using GNU Classpath an accurate view of the changes we make to -the code and to see what changed when. If you think the requirements -are ``unworkable'' please try it first for a couple of weeks. If you -still feel the same after having some more experience with the project -please feel free to bring up suggestions for improvements on the list. -But don't just ignore the rules! Other hackers depend on them being -followed to be the most productive they can be (given the above -constraints). - -@menu -* Branches:: -* Writing ChangeLogs:: -@end menu - -@node Branches, Writing ChangeLogs, Hacking Code, Hacking Code -@comment node-name, next, previous, up -@section Working with branches - -Sometimes it is necessary to create branch of the source for doing new -work that is disruptive to the other hackers, or that needs new -language or libraries not yet (easily) available. - -After discussing the need for a branch on the main mailinglist with -the other hackers explaining the need of a branch and suggestion of -the particular branch rules (what will be done on the branch, who will -work on it, will there be different commit guidelines then for the -mainline trunk and when is the branch estimated to be finished and -merged back into the trunk) every GNU Classpath hacker with commit -access should feel free to create a branch. There are however a couple -of rules that every branch should follow: - -@itemize @bullet - -@item All branches ought to be documented in the developer wiki at -@uref{http://developer.classpath.org/mediation/ClasspathBranches}, so -we can know which are live, who owns them, and when they die. - -@item Some rules can be changed on a branch. In particular the branch -maintainer can change the review requirements, and the requirement of -keeping things building, testing, etc, can also be lifted. (These -should be documented along with the branch name and owner if they -differ from the trunk.) - -@item Requirements for patch email to classpath-patches and for paperwork -@strong{cannot} be lifted. See @ref{Requirements}. - -@item A branch should not be seen as ``private'' or -``may be completely broken''. It should be as much as possible -something that you work on with a team (and if there is no team - yet -- then there is nothing as bad as having a completely broken build to -get others to help out). There can of course be occasional breakage, but -it should be planned and explained. And you can certainly have a rule -like ``please ask me before committing to this branch''. - -@item Merges from the trunk to a branch are at the discretion of the -branch maintainer. - -@item A merge from a branch to the trunk is treated like any other patch. -In particular, it has to go through review, it must satisfy all the -trunk requirements (build, regression test, documentation). - -@item There may be additional timing requirements on merging a branch to -the trunk depending on the release schedule, etc. For instance we may -not want to do a branch merge just before a release. - -@end itemize - -If any of these rules are unclear please discuss on the list first. - -@menu -* Writing ChangeLogs:: -@end menu - -@node Writing ChangeLogs, , Branches, Hacking Code -@comment node-name, next, previous, up -@section Documenting what changed when with ChangeLog entries - -To keep track of who did what when we keep an explicit ChangeLog entry -together with the code. This mirrors the CVS commit messages and in -general the ChangeLog entry is the same as the CVS commit message. -This provides an easy way for people getting a (snapshot) release or -without access to the CVS server to see what happened when. We do not -generate the ChangeLog file automatically from the CVS server since -that is not reliable. - -A good ChangeLog entry guideline can be found in the Guile Manual at -@uref{http://www.gnu.org/software/guile/changelogs/guile-changelogs_3.html}. - -Here are some example to explain what should or shouldn't be in a -ChangeLog entry (and the corresponding commit message): - -@itemize @bullet - -@item -The first line of a ChangeLog entry should be: - -@example -[date] [full name] [email-contact] -@end example - -The second line should be blank. All other lines should be indented -with one tab. - -@item -Just state what was changed. Why something is done as it is done in -the current code should be either stated in the code itself or be -added to one of the documentation files (like this Hacking Guide). - -So don't write: - -@example - * java/awt/font/OpenType.java: Remove 'public static final' - from OpenType tags, reverting the change of 2003-08-11. See - Classpath discussion list of 2003-08-11. -@end example - -Just state: - -@example - * java/awt/font/OpenType.java: Remove 'public static final' from - all member fields. -@end example - -In this case the reason for the change was added to this guide. - -@item -Just as with the normal code style guide, don't make lines longer then -80 characters. - -@item -Just as with comments in the code. The ChangeLog entry should be a -full sentence, starting with a captital and ending with a period. - -@item -Be precise in what changed, not the effect of the change (which should -be clear from the code/patch). So don't write: - -@example - * java/io/ObjectOutputStream.java : Allow putFields be called more - than once. -@end example - -But explain what changed and in which methods it was changed: - -@example - * java/io/ObjectOutputStream.java (putFields): Don't call - markFieldsWritten(). Only create new PutField when - currentPutField is null. - (writeFields): Call markFieldsWritten(). -@end example - -@end itemize - -The above are all just guidelines. We all appreciate the fact that writing -ChangeLog entries, using a coding style that is not ``your own'' and the -CVS, patch and diff tools do take some time to getting used to. So don't -feel like you have to do it perfect right away or that contributions -aren't welcome if they aren't ``perfect''. We all learn by doing and -interacting with each other. - - -@node Programming Goals, API Compatibility, Hacking Code, Top -@comment node-name, next, previous, up -@chapter Programming Goals - -When you write code for Classpath, write with three things in mind, and -in the following order: portability, robustness, and efficiency. - -If efficiency breaks portability or robustness, then don't do it the -efficient way. If robustness breaks portability, then bye-bye robust -code. Of course, as a programmer you would probably like to find sneaky -ways to get around the issue so that your code can be all three ... the -following chapters will give some hints on how to do this. - -@menu -* Portability:: Writing Portable Software -* Utility Classes:: Reusing Software -* Robustness:: Writing Robust Software -* Java Efficiency:: Writing Efficient Java -* Native Efficiency:: Writing Efficient JNI -* Security:: Writing Secure Software -@end menu - -@node Portability, Utility Classes, Programming Goals, Programming Goals -@comment node-name, next, previous, up -@section Portability - -The portability goal for Classpath is the following: - -@enumerate -@item -native functions for each platform that work across all VMs on that -platform -@item -a single classfile set that work across all VMs on all platforms that -support the native functions. -@end enumerate - -For almost all of Classpath, this is a very feasible goal, using a -combination of JNI and native interfaces. This is what you should shoot -for. For those few places that require knowledge of the Virtual Machine -beyond that provided by the Java standards, the VM Interface was designed. -Read the Virtual Machine Integration Guide for more information. - -Right now the only supported platform is Linux. This will change as that -version stabilizes and we begin the effort to port to many other -platforms. Jikes RVM runs Classpath on AIX, and generally the Jikes -RVM team fixes Classpath to work on that platform. - -@node Utility Classes, Robustness, Portability, Programming Goals -@comment node-name, next, previous, up -@section Utility Classes - -At the moment, we are not very good at reuse of the JNI code. There -have been some attempts, called @dfn{libclasspath}, to -create generally useful utility classes. The utility classes are in -the directory @file{native/jni/classpath} and they are mostly declared -in @file{native/jni/classpath/jcl.h}. These utility classes are -currently only discussed in @ref{Robustness} and in @ref{Native -Efficiency}. - -There are more utility classes available that could be factored out if -a volunteer wants something nice to hack on. The error reporting and -exception throwing functions and macros in -@file{native/jni/gtk-peer/gthread-jni.c} might be good -candidates for reuse. There are also some generally useful utility -functions in @file{gnu_java_awt_peer_gtk_GtkMainThread.c} that could -be split out and put into libclasspath. - -@node Robustness, Java Efficiency, Utility Classes, Programming Goals -@comment node-name, next, previous, up -@section Robustness - -Native code is very easy to make non-robust. (That's one reason Java is -so much better!) Here are a few hints to make your native code more -robust. - -Always check return values for standard functions. It's sometimes easy -to forget to check that malloc() return for an error. Don't make that -mistake. (In fact, use JCL_malloc() in the jcl library instead--it will -check the return value and throw an exception if necessary.) - -Always check the return values of JNI functions, or call -@code{ExceptionOccurred} to check whether an error occurred. You must -do this after @emph{every} JNI call. JNI does not work well when an -exception has been raised, and can have unpredictable behavior. - -Throw exceptions using @code{JCL_ThrowException}. This guarantees that if -something is seriously wrong, the exception text will at least get out -somewhere (even if it is stderr). - -Check for null values of @code{jclass}es before you send them to JNI functions. -JNI does not behave nicely when you pass a null class to it: it -terminates Java with a "JNI Panic." - -In general, try to use functions in @file{native/jni/classpath/jcl.h}. They -check exceptions and return values and throw appropriate exceptions. - -@node Java Efficiency, Native Efficiency, Robustness, Programming Goals -@comment node-name, next, previous, up -@section Java Efficiency - -For methods which explicitly throw a @code{NullPointerException} when an -argument is passed which is null, per a Sun specification, do not write -code like: - -@example -int -strlen (String foo) throws NullPointerException -@{ - if (foo == null) - throw new NullPointerException ("foo is null"); - return foo.length (); -@} -@end example - -Instead, the code should be written as: - -@example -int -strlen (String foo) throws NullPointerException -@{ - return foo.length (); -@} -@end example - -Explicitly comparing foo to null is unnecessary, as the virtual machine -will throw a NullPointerException when length() is invoked. Classpath -is designed to be as fast as possible -- every optimization, no matter -how small, is important. - -@node Native Efficiency, Security, Java Efficiency, Programming Goals -@comment node-name, next, previous, up -@section Native Efficiency - -You might think that using native methods all over the place would give -our implementation of Java speed, speed, blinding speed. You'd be -thinking wrong. Would you believe me if I told you that an empty -@emph{interpreted} Java method is typically about three and a half times -@emph{faster} than the equivalent native method? - -Bottom line: JNI is overhead incarnate. In Sun's implementation, even -the JNI functions you use once you get into Java are slow. - -A final problem is efficiency of native code when it comes to things -like method calls, fields, finding classes, etc. Generally you should -cache things like that in static C variables if you're going to use them -over and over again. GetMethodID(), GetFieldID(), and FindClass() are -@emph{slow}. Classpath provides utility libraries for caching methodIDs -and fieldIDs in @file{native/jni/classpath/jnilink.h}. Other native data can -be cached between method calls using functions found in -@file{native/jni/classpath/native_state.h}. - -Here are a few tips on writing native code efficiently: - -Make as few native method calls as possible. Note that this is not the -same thing as doing less in native method calls; it just means that, if -given the choice between calling two native methods and writing a single -native method that does the job of both, it will usually be better to -write the single native method. You can even call the other two native -methods directly from your native code and not incur the overhead of a -method call from Java to C. - -Cache @code{jmethodID}s and @code{jfieldID}s wherever you can. String -lookups are -expensive. The best way to do this is to use the -@file{native/jni/classpath/jnilink.h} -library. It will ensure that @code{jmethodID}s are always valid, even if the -class is unloaded at some point. In 1.1, jnilink simply caches a -@code{NewGlobalRef()} to the method's underlying class; however, when 1.2 comes -along, it will use a weak reference to allow the class to be unloaded -and then re-resolve the @code{jmethodID} the next time it is used. - -Cache classes that you need to access often. jnilink will help with -this as well. The issue here is the same as the methodID and fieldID -issue--how to make certain the class reference remains valid. - -If you need to associate native C data with your class, use Paul -Fisher's native_state library (NSA). It will allow you to get and set -state fairly efficiently. Japhar now supports this library, making -native state get and set calls as fast as accessing a C variable -directly. - -If you are using native libraries defined outside of Classpath, then -these should be wrapped by a Classpath function instead and defined -within a library of their own. This makes porting Classpath's native -libraries to new platforms easier in the long run. It would be nice -to be able to use Mozilla's NSPR or Apache's APR, as these libraries -are already ported to numerous systems and provide all the necessary -system functions as well. - -@node Security, , Native Efficiency, Programming Goals -@comment node-name, next, previous, up -@section Security - -Security is such a huge topic it probably deserves its own chapter. -Most of the current code needs to be audited for security to ensure -all of the proper security checks are in place within the Java -platform, but also to verify that native code is reasonably secure and -avoids common pitfalls, buffer overflows, etc. A good source for -information on secure programming is the excellent HOWTO by David -Wheeler, -@uref{http://www.dwheeler.com/secure-programs/Secure-Programs-HOWTO/index.html,Secure -Programming for Linux and Unix HOWTO}. - -@node API Compatibility, Specification Sources, Programming Goals, Top -@comment node-name, next, previous, up -@chapter API Compatibility - -@menu -* Serialization:: Serialization -* Deprecated Methods:: Deprecated methods -@end menu - -@node Serialization, Deprecated Methods, API Compatibility, API Compatibility -@comment node-name, next, previous, up -@section Serialization - -Sun has produced documentation concerning much of the information -needed to make Classpath serializable compatible with Sun -implementations. Part of doing this is to make sure that every class -that is Serializable actually defines a field named serialVersionUID -with a value that matches the output of serialver on Sun's -implementation. The reason for doing this is below. - -If a class has a field (of any accessibility) named serialVersionUID -of type long, that is what serialver uses. Otherwise it computes a -value using some sort of hash function on the names of all method -signatures in the .class file. The fact that different compilers -create different synthetic method signatures, such as access$0() if an -inner class needs access to a private member of an enclosing class, -make it impossible for two distinct compilers to reliably generate the -same serial #, because their .class files differ. However, once you -have a .class file, its serial # is unique, and the computation will -give the same result no matter what platform you execute on. - -Serialization compatibility can be tested using tools provided with -@uref{http://www.kaffe.org/~stuart/japi/,Japitools}. These -tools can test binary serialization compatibility and also provide -information about unknown serialized formats by writing these in XML -instead. Japitools is also the primary means of checking API -compatibility for GNU Classpath with Sun's Java Platform. - -@node Deprecated Methods, , Serialization, API Compatibility -@comment node-name, next, previous, up -@section Deprecated Methods - -Sun has a practice of creating ``alias'' methods, where a public or -protected method is deprecated in favor of a new one that has the same -function but a different name. Sun's reasons for doing this vary; as -an example, the original name may contain a spelling error or it may -not follow Java naming conventions. - -Unfortunately, this practice complicates class library code that calls -these aliased methods. Library code must still call the deprecated -method so that old client code that overrides it continues to work. -But library code must also call the new version, because new code is -expected to override the new method. - -The correct way to handle this (and the way Sun does it) may seem -counterintuitive because it means that new code is less efficient than -old code: the new method must call the deprecated method, and throughout -the library code calls to the old method must be replaced with calls to -the new one. - -Take the example of a newly-written container laying out a component and -wanting to know its preferred size. The Component class has a -deprecated preferredSize method and a new method, getPreferredSize. -Assume that the container is laying out an old component that overrides -preferredSize and a new component that overrides getPreferredSize. If -the container calls getPreferredSize and the default implementation of -getPreferredSize calls preferredSize, then the old component will have -its preferredSize method called and new code will have its -getPreferredSize method called. - -Even using this calling scheme, an old component may still be laid out -improperly if it implements a method, getPreferredSize, that has the -same signature as the new Component.getPreferredSize. But that is a -general problem -- adding new public or protected methods to a -widely-used class that calls those methods internally is risky, because -existing client code may have already declared methods with the same -signature. - -The solution may still seem counterintuitive -- why not have the -deprecated method call the new method, then have the library always call -the old method? One problem with that, using the preferred size example -again, is that new containers, which will use the non-deprecated -getPreferredSize, will not get the preferred size of old components. - -@node Specification Sources, Naming Conventions, API Compatibility, Top -@comment node-name, next, previous, up -@chapter Specification Sources - -There are a number of specification sources to use when working on -Classpath. In general, the only place you'll find your classes -specified is in the JavaDoc documentation or possibly in the -corresponding white paper. In the case of java.lang, java.io and -java.util, you should look at the Java Language Specification. - -Here, however, is a list of specs, in order of canonicality: - -@enumerate -@item -@uref{http://java.sun.com/docs/books/jls/clarify.html,Clarifications and Amendments to the JLS - 1.1} -@item -@uref{http://java.sun.com/docs/books/jls/html/1.1Update.html,JLS Updates -- 1.1} -@item -@uref{http://java.sun.com/docs/books/jls/html/index.html,The 1.0 JLS} -@item -@uref{http://java.sun.com/docs/books/vmspec/index.html,JVM spec - 1.1} -@item -@uref{http://java.sun.com/products/jdk/1.1/docs/guide/jni/spec/jniTOC.doc.html,JNI spec - 1.1} -@item -@uref{http://java.sun.com/products/jdk/1.1/docs/api/packages.html,Sun's javadoc - 1.1} -(since Sun's is the reference implementation, the javadoc is -documentation for the Java platform itself.) -@item -@uref{http://java.sun.com/products/jdk/1.2/docs/guide/jvmdi/jvmdi.html,JVMDI spec - 1.2}, -@uref{http://java.sun.com/products/jdk/1.2/docs/guide/jni/jni-12.html,JNI spec - 1.2} -(sometimes gives clues about unspecified things in 1.1; if -it was not specified accurately in 1.1, then use the spec -for 1.2; also, we are using JVMDI in this project.) -@item -@uref{http://java.sun.com/products/jdk/1.2/docs/api/frame.html,Sun's javadoc - 1.2} -(sometimes gives clues about unspecified things in 1.1; if -it was not specified accurately in 1.1, then use the spec -for 1.2) -@item -@uref{http://developer.java.sun.com/developer/bugParade/index.html,The -Bug Parade}: I have obtained a ton of useful information about how -things do work and how they *should* work from the Bug Parade just by -searching for related bugs. The submitters are very careful about their -use of the spec. And if something is unspecified, usually you can find -a request for specification or a response indicating how Sun thinks it -should be specified here. -@end enumerate - -You'll notice that in this document, white papers and specification -papers are more canonical than the JavaDoc documentation. This is true -in general. - - -@node Naming Conventions, Character Conversions, Specification Sources, Top -@comment node-name, next, previous, up -@chapter Directory and File Naming Conventions - -The Classpath directory structure is laid out in the following manner: - -@example -classpath - | - |---->java - | | - | |-->awt - | |-->io - | |-->lang - | |-->util - | | | - | | |--->zip - | | |--->jar - | |-->net - | |-->etc - | - |---->gnu - | | - | |-->java - | | - | |-->awt - | |-->lang - | |-->util - | | | - | | |-->zip - | |-->etc - | - |---->native - | - |-->jni - | |-->classpath - | |-->gtk-peer - | |-->java-io - | |-->java-lang - | |-->java-net - | |-->java-util - | |-->etc - |-->cni - -@end example - -Here is a brief description of the toplevel directories and their contents. - -@table @b - -@item java -Contains the source code to the Java packages that make up the core -class library. Because this is the public interface to Java, it is -important that the public classes, interfaces, methods, and variables -are exactly the same as specified in Sun's documentation. The directory -structure is laid out just like the java package names. For example, -the class java.util.zip would be in the directory java-util. - -@item gnu/java -Internal classes (roughly analogous to Sun's sun.* classes) should go -under the @file{gnu/java} directory. Classes related to a particular public -Java package should go in a directory named like that package. For -example, classes related to java.util.zip should go under a directory -@file{gnu/java/util/zip}. Sub-packages under the main package name are -allowed. For classes spanning multiple public Java packages, pick an -appropriate name and see what everybody else thinks. - -@item native -This directory holds native code needed by the public Java packages. -Each package has its own subdirectory, which is the ``flattened'' name -of the package. For example, native method implementations for -java.util.zip should go in @file{native/classpath/java-util}. Classpath -actually includes an all Java version of the zip classes, so no native -code is required. - -@end table - -Each person working on a package get's his or her own ``directory -space'' underneath each of the toplevel directories. In addition to the -general guidelines above, the following standards should be followed: - -@itemize @bullet - -@item -Classes that need to load native code should load a library with the -same name as the flattened package name, with all hyphens removed. For -example, the native library name specified in LoadLibrary for -java-util would be ``javautil''. - -@item -Each package has its own shared library for native code (if any). - -@item -The main native method implementation for a given method in class should -go in a file with the same name as the class with a ``.c'' extension. -For example, the JNI implementation of the native methods in -java.net.InetAddress would go in @file{native/jni/java-net/InetAddress.c}. -``Internal'' native functions called from the main native method can -reside in files of any name. -@end itemize - -@node Character Conversions, Localization, Naming Conventions, Top -@comment node-name, next, previous, up -@chapter Character Conversions - -Java uses the Unicode character encoding system internally. This is a -sixteen bit (two byte) collection of characters encompassing most of the -world's written languages. However, Java programs must often deal with -outside interfaces that are byte (eight bit) oriented. For example, a -Unix file, a stream of data from a network socket, etc. Beginning with -Java 1.1, the @code{Reader} and @code{Writer} classes provide functionality -for dealing with character oriented streams. The classes -@code{InputStreamReader} and @code{OutputStreamWriter} bridge the gap -between byte streams and character streams by converting bytes to -Unicode characters and vice versa. - -In Classpath, @code{InputStreamReader} and @code{OutputStreamWriter} -rely on an internal class called @code{gnu.java.io.EncodingManager} to load -translaters that perform the actual conversion. There are two types of -converters, encoders and decoders. Encoders are subclasses of -@code{gnu.java.io.encoder.Encoder}. This type of converter takes a Java -(Unicode) character stream or buffer and converts it to bytes using -a specified encoding scheme. Decoders are a subclass of -@code{gnu.java.io.decoder.Decoder}. This type of converter takes a -byte stream or buffer and converts it to Unicode characters. The -@code{Encoder} and @code{Decoder} classes are subclasses of -@code{Writer} and @code{Reader} respectively, and so can be used in -contexts that require character streams, but the Classpath implementation -currently does not make use of them in this fashion. - -The @code{EncodingManager} class searches for requested encoders and -decoders by name. Since encoders and decoders are separate in Classpath, -it is possible to have a decoder without an encoder for a particular -encoding scheme, or vice versa. @code{EncodingManager} searches the -package path specified by the @code{file.encoding.pkg} property. The -name of the encoder or decoder is appended to the search path to -produce the required class name. Note that @code{EncodingManager} knows -about the default system encoding scheme, which it retrieves from the -system property @code{file.encoding}, and it will return the proper -translator for the default encoding if no scheme is specified. Also, the -Classpath standard translator library, which is the @code{gnu.java.io} package, -is automatically appended to the end of the path. - -For efficiency, @code{EncodingManager} maintains a cache of translators -that it has loaded. This eliminates the need to search for a commonly -used translator each time it is requested. - -Finally, @code{EncodingManager} supports aliasing of encoding scheme names. -For example, the ISO Latin-1 encoding scheme can be referred to as -''8859_1'' or ''ISO-8859-1''. @code{EncodingManager} searches for -aliases by looking for the existence of a system property called -@code{gnu.java.io.encoding_scheme_alias.}. If such a -property exists. The value of that property is assumed to be the -canonical name of the encoding scheme, and a translator with that name is -looked up instead of one with the original name. - -Here is an example of how @code{EncodingManager} works. A class requests -a decoder for the ''UTF-8'' encoding scheme by calling -@code{EncodingManager.getDecoder("UTF-8")}. First, an alias is searched -for by looking for the system property -@code{gnu.java.io.encoding_scheme_alias.UTF-8}. In our example, this -property exists and has the value ''UTF8''. That is the actual -decoder that will be searched for. Next, @code{EncodingManager} looks -in its cache for this translator. Assuming it does not find it, it -searches the translator path, which is this example consists only of -the default @code{gnu.java.io}. The ''decoder'' package name is -appended since we are looking for a decoder. (''encoder'' would be -used if we were looking for an encoder). Then name name of the translator -is appended. So @code{EncodingManager} attempts to load a translator -class called @code{gnu.java.io.decoder.UTF8}. If that class is found, -an instance of it is returned. If it is not found, a -@code{UnsupportedEncodingException}. - -To write a new translator, it is only necessary to subclass -@code{Encoder} and/or @code{Decoder}. Only a handful of abstract -methods need to be implemented. In general, no methods need to be -overridden. The needed methods calculate the number of bytes/chars -that the translation will generate, convert buffers to/from bytes, -and read/write a requested number of characters to/from a stream. - -Many common encoding schemes use only eight bits to encode characters. -Writing a translator for these encodings is very easy. There are -abstract translator classes @code{gnu.java.io.decode.DecoderEightBitLookup} -and @code{gnu.java.io.encode.EncoderEightBitLookup}. These classes -implement all of the necessary methods. All that is necessary to -create a lookup table array that maps bytes to Unicode characters and -set the class variable @code{lookup_table} equal to it in a static -initializer. Also, a single constructor that takes an appropriate -stream as an argument must be supplied. These translators are -exceptionally easy to create and there are several of them supplied -in the Classpath distribution. - -Writing multi-byte or variable-byte encodings is more difficult, but -often not especially challenging. The Classpath distribution ships with -translators for the UTF8 encoding scheme which uses from one to three -bytes to encode Unicode characters. This can serve as an example of -how to write such a translator. - -Many more translators are needed. All major character encodings should -eventually be supported. - -@node Localization, , Character Conversions, Top -@comment node-name, next, previous, up -@chapter Localization - -There are many parts of the Java standard runtime library that must -be customized to the particular locale the program is being run in. -These include the parsing and display of dates, times, and numbers; -sorting words alphabetically; breaking sentences into words, etc. -In general, Classpath uses general classes for performing these tasks, -and customizes their behavior with configuration data specific to a -given locale. - -@menu -* String Collation:: Sorting strings in different locales -* Break Iteration:: Breaking up text into words, sentences, and lines -* Date Formatting and Parsing:: Locale specific date handling -* Decimal/Currency Formatting and Parsing:: Local specific number handling -@end menu - -In Classpath, all locale specific data is stored in a -@code{ListResourceBundle} class in the package @code{gnu/java/locale}. -The basename of the bundle is @code{LocaleInformation}. See the -documentation for the @code{java.util.ResourceBundle} class for details -on how the specific locale classes should be named. - -@code{ListResourceBundle}'s are used instead of -@code{PropertyResourceBundle}'s because data more complex than simple -strings need to be provided to configure certain Classpath components. -Because @code{ListResourceBundle} allows an arbitrary Java object to -be associated with a given configuration option, it provides the -needed flexibility to accomodate Classpath's needs. - -Each Java library component that can be localized requires that certain -configuration options be specified in the resource bundle for it. It is -important that each and every option be supplied for a specific -component or a critical runtime error will most likely result. - -As a standard, each option should be assigned a name that is a string. -If the value is stored in a class or instance variable, then the option -should name should have the name name as the variable. Also, the value -associated with each option should be a Java object with the same name -as the option name (unless a simple scalar value is used). Here is an -example: - -A class loads a value for the @code{format_string} variable from the -resource bundle in the specified locale. Here is the code in the -library class: - -@example - ListResourceBundle lrb = - ListResourceBundle.getBundle ("gnu/java/locale/LocaleInformation", locale); - String format_string = lrb.getString ("format_string"); -@end example - -In the actual resource bundle class, here is how the configuration option -gets defined: - -@example -/** - * This is the format string used for displaying values - */ -private static final String format_string = "%s %d %i"; - -private static final Object[][] contents = -@{ - @{ "format_string", format_string @} -@}; -@end example - -Note that each variable should be @code{private}, @code{final}, and -@code{static}. Each variable should also have a description of what it -does as a documentation comment. The @code{getContents()} method returns -the @code{contents} array. - -There are many functional areas of the standard class library that are -configured using this mechanism. A given locale does not need to support -each functional area. But if a functional area is supported, then all -of the specified entries for that area must be supplied. In order to -determine which functional areas are supported, there is a special key -that is queried by the affected class or classes. If this key exists, -and has a value that is a @code{Boolean} object wrappering the -@code{true} value, then full support is assumed. Otherwise it is -assumed that no support exists for this functional area. Every class -using resources for configuration must use this scheme and define a special -scheme that indicates the functional area is supported. Simply checking -for the resource bundle's existence is not sufficient to ensure that a -given functional area is supported. - -The following sections define the functional areas that use resources -for locale specific configuration in GNU Classpath. Please refer to the -documentation for the classes mentioned for details on how these values -are used. You may also wish to look at the source file for -@file{gnu/java/locale/LocaleInformation_en} as an example. - -@node String Collation, Break Iteration, Localization, Localization -@comment node-name, next, previous, up -@section String Collation - -Collation involves the sorting of strings. The Java class library provides -a public class called @code{java.text.RuleBasedCollator} that performs -sorting based on a set of sorting rules. - -@itemize @bullet -@item RuleBasedCollator - A @code{Boolean} wrappering @code{true} to indicate -that this functional area is supported. -@item collation_rules - The rules the specify how string collation is to -be performed. -@end itemize - -Note that some languages might be too complex for @code{RuleBasedCollator} -to handle. In this case an entirely new class might need to be written in -lieu of defining this rule string. - -@node Break Iteration, Date Formatting and Parsing, String Collation, Localization -@comment node-name, next, previous, up -@section Break Iteration - -The class @code{java.text.BreakIterator} breaks text into words, sentences, -and lines. It is configured with the following resource bundle entries: - -@itemize @bullet -@item BreakIterator - A @code{Boolean} wrappering @code{true} to indicate -that this functional area is supported. -@item word_breaks - A @code{String} array of word break character sequences. -@item sentence_breaks - A @code{String} array of sentence break character -sequences. -@item line_breaks - A @code{String} array of line break character sequences. -@end itemize - -@node Date Formatting and Parsing, Decimal/Currency Formatting and Parsing, Break Iteration, Localization -@comment node-name, next, previous, up -@section Date Formatting and Parsing - -Date formatting and parsing is handled by the -@code{java.text.SimpleDateFormat} class in most locales. This class is -configured by attaching an instance of the @code{java.text.DateFormatSymbols} -class. That class simply reads properties from our locale specific -resource bundle. The following items are required (refer to the -documentation of the @code{java.text.DateFormatSymbols} class for details -io what the actual values should be): - -@itemize @bullet -@item DateFormatSymbols - A @code{Boolean} wrappering @code{true} to indicate -that this functional area is supported. -@item months - A @code{String} array of month names. -@item shortMonths - A @code{String} array of abbreviated month names. -@item weekdays - A @code{String} array of weekday names. -@item shortWeekdays - A @code{String} array of abbreviated weekday names. -@item ampms - A @code{String} array containing AM/PM names. -@item eras - A @code{String} array containing era (ie, BC/AD) names. -@item zoneStrings - An array of information about valid timezones for this -locale. -@item localPatternChars - A @code{String} defining date/time pattern symbols. -@item shortDateFormat - The format string for dates used by -@code{DateFormat.SHORT} -@item mediumDateFormat - The format string for dates used by -@code{DateFormat.MEDIUM} -@item longDateFormat - The format string for dates used by -@code{DateFormat.LONG} -@item fullDateFormat - The format string for dates used by -@code{DateFormat.FULL} -@item shortTimeFormat - The format string for times used by -@code{DateFormat.SHORT} -@item mediumTimeFormat - The format string for times used by -@code{DateFormat.MEDIUM} -@item longTimeFormat - The format string for times used by -@code{DateFormat.LONG} -@item fullTimeFormat - The format string for times used by -@code{DateFormat.FULL} -@end itemize - -Note that it may not be possible to use this mechanism for all locales. -In those cases a special purpose class may need to be written to handle -date/time processing. - -@node Decimal/Currency Formatting and Parsing, , Date Formatting and Parsing, Localization -@comment node-name, next, previous, up -@section Decimal/Currency Formatting and Parsing - -@code{NumberFormat} is an abstract class for formatting and parsing numbers. -The class @code{DecimalFormat} provides a concrete subclass that handles -this is in a locale independent manner. As with @code{SimpleDateFormat}, -this class gets information on how to format numbers from a class that -wrappers a collection of locale specific formatting values. In this case, -the class is @code{DecimalFormatSymbols}. That class reads its default -values for a locale from the resource bundle. The required entries are: - -@itemize @bullet -@item DecimalFormatSymbols - A @code{Boolean} wrappering @code{true} to -indicate that this functional area is supported. -@item currencySymbol - The string representing the local currency. -@item intlCurrencySymbol - The string representing the local currency in an -international context. -@item decimalSeparator - The character to use as the decimal point as a -@code{String}. -@item digit - The character used to represent digits in a format string, -as a @code{String}. -@item exponential - The char used to represent the exponent separator of a -number written in scientific notation, as a @code{String}. -@item groupingSeparator - The character used to separate groups of numbers -in a large number, such as the ``,'' separator for thousands in the US, as -a @code{String}. -@item infinity - The string representing infinity. -@item NaN - The string representing the Java not a number value. -@item minusSign - The character representing the negative sign, as a -@code{String}. -@item monetarySeparator - The decimal point used in currency values, as a -@code{String}. -@item patternSeparator - The character used to separate positive and -negative format patterns, as a @code{String}. -@item percent - The percent sign, as a @code{String}. -@item perMill - The per mille sign, as a @code{String}. -@item zeroDigit - The character representing the digit zero, as a @code{String}. -@end itemize - -Note that several of these values are an individual character. These should -be wrappered in a @code{String} at character position 0, not in a -@code{Character} object. - -@bye - diff --git a/libjava/classpath/doc/tools.texinfo b/libjava/classpath/doc/tools.texinfo deleted file mode 100644 index 28252cd..0000000 --- a/libjava/classpath/doc/tools.texinfo +++ /dev/null @@ -1,1206 +0,0 @@ -\input texinfo @c -*-texinfo-*- - -@c %**start of header -@setfilename tools.info -@settitle GNU Classpath Tools Guide -@c %**end of header - -@setchapternewpage on - -@ifinfo -This file documents the Tools included in a standard distribution of the GNU -Classpath project deliverables. - -Copyright (C) 2006 Free Software Foundation, Inc. - -@ifnotplaintext -@dircategory GNU Libraries -@direntry -* Classpath Tools: (tools). GNU Classpath Tools Guide -@end direntry -@end ifnotplaintext -@end ifinfo - -@titlepage -@title GNU Classpath Tools Guide -@author The GNU Classpath Team - -@page -@vskip 0pt plus 1filll -Copyright @copyright{} 2006 Free Software Foundation, Inc. -@sp 2 -Permission is granted to make and distribute verbatim copies of this document provided the copyright notice and this permission notice are preserved on all copies. - -Permission is granted to copy and distribute modified versions of this document under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. - -Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the Free Software Foundation. - -@end titlepage - -@contents - -@ifinfo -@node Top, Applet Tools, (dir), (dir) -@top GNU Classpath Tools Guide - -This document contains important information you need to know in order to use -the tools included in the GNU Classpath project deliverables. - -The Tools aim at providing a free replacement, similar in their behavior, to -their counter-parts found in the Reference Implementation (RI) of the Java -Software Development Kit (SDK). - -@end ifinfo - -@menu -* Applet Tools:: Work with applets -* Security Tools:: Work securely with Java applications -* I18N Issues:: How to add support for non-English languages - -@detailmenu - --- The Detailed Node Listing --- - -Applet Tools - -* appletviewer Tool:: Load applets -* gcjwebplugin:: Load applets in a web browser - -Security Tools - -* jarsigner Tool:: Sign and verify .JAR files -* keytool Tool:: Manage private keys and public certificates - -jarsigner Tool - -* Common jarsigner Options:: Options used when signing or verifying a file -* Signing Options:: Options only used when signing a .JAR file -* Verification Options:: Options only used when verifying a .JAR file - -keytool Tool - -* Getting Help:: How to get help with keytool commands -* Common keytool Options:: Options used in more than one command -* Distinguished Names:: X.500 Distinguished Names used in certificates -* Add/Update Commands:: Commands for adding data to a Key Store -* Export Commands:: Commands for exporting data from a Key Store -* Display Commands:: Commands for displaying data in a Key Store -* Management Commands:: Commands for managing a Key Store - -Add/Update Commands - -* Command -genkey:: Generate private key and self-signed certificate -* Command -import:: Import certificates and certificate replies -* Command -selfcert:: Generate self-signed certificate -* Command -cacert:: Import a CA Trusted Certificate -* Command -identitydb:: Import JDK-1 style identities - -Export Commands - -* Command -certreq:: Generate Certificate Signing Requests (CSR) -* Command -export:: Export a certificate in a Key Store - -Display Commands - -* Command -list:: Display information about one or all Aliases -* Command -printcert:: Print a certificate or a certificate fingerprint - -Management Commands - -* Command -keyclone:: Clone a Key Entry in a Key Store -* Command -storepasswd:: Change the password protecting a Key Store -* Command -keypasswd:: Change the password protecting a Key Entry -* Command -delete:: Remove an entry in a Key Store - -I18N Issues - -* Language Resources:: Where resources are located -* Message Formats:: How messages are internationalized - -@end detailmenu -@end menu - -@comment ---------------------------------------------------------------------- - -@node Applet Tools, Security Tools, Top, Top -@comment node-name, next, previous, up -@chapter Applet Tools - -Two Applet Tools are available with GNU Classpath: @b{appletviewer} -and @b{gcjwebplugin}. - -To avoid conflicts with other implementations, the appletviewer -executable is called ``gappletviewer''. - -@menu -* appletviewer Tool:: Load applets -* gcjwebplugin:: Load applets in a web browser -@end menu - -If while using these tools you think you found a bug, then please report it at @uref{http://www.gnu.org/software/classpath/bugs.html,classpath-bugs}. - -@comment ---------------------------------------------------------------------- - -@node appletviewer Tool, gcjwebplugin, Applet Tools, Applet Tools -@comment node-name, next, previous, up -@section The @code{appletviewer} Tool - -@table @b - -@item SYNOPSIS -@code{appletviewer [OPTION]... URL...}@* -@code{appletviewer [OPTION]... -code CODE}@* -@code{appletviewer [OPTION]... -plugin INPUT,OUTPUT} - -@item DESCRIPTION -The @code{appletviewer} tool loads and runs an applet. - -Use the first form to test applets specified by tag. The URL should -resolve to an HTML document from which the @code{appletviewer} will -extract applet tags. The APPLET, EMBED and OBJECT tags are supported. -If a given document contains multiple applet tags, all the applets -will be loaded, with each applet appearing in its own window. -Likewise, when multiple URLs are specified, each applet tag instance -is given its own window. If a given document contains no recognized -tags the @code{appletviewer} does nothing. - -@example -@code{appletviewer http://www.gnu.org/software/classpath/} -@end example - -Use the second form to test an applet in development. This form -allows applet tag attributes to be supplied on the command line. Only -one applet may be specified using the @code{-code} option. The -@code{-code} option overrides the URL form -- any URLs specified will -be ignored. - -@example -@code{appletviewer -code Test.class -param datafile,data.txt} -@end example - -@code{gcjwebplugin} uses the third form to communicate with the -@code{appletviewer} through named pipes. - -@item URL OPTIONS -@table @b -@item -debug -This option is not yet implemented but is provided for compatibility. - -@item -encoding CHARSET -Use this option to specify an alternate character encoding for the -specified HTML page. - -@end table - -@item APPLET TAG OPTIONS -@table @b -@item -code CODE -Use the @code{-code} option to specify the value of the applet tag -CODE attribute. - -@item -codebase CODEBASE -Use the @code{-codebase} option to specify the value of the applet tag -CODEBASE attribute. - -@item -archive ARCHIVE -Use the @code{-archive} option to specify the value of the applet tag -ARCHIVE attribute. - -@item -width WIDTH -Use the @code{-width} option to specify the value of the applet tag -WIDTH attribute. - -@item -height HEIGHT -Use the @code{-height} option to specify the value of the applet tag -HEIGHT attribute. - -@item -param NAME,VALUE -Use the @code{-param} option to specify values for the NAME and VALUE -attributes of an applet PARAM tag. - -@end table - -@item PLUGIN OPTION -@table @b -@item -plugin INPUT,OUTPUT -@code{gcjwebplugin} uses the @code{-plugin} option to specify the -named pipe the @code{appletviewer} should use for receiving commands -(INPUT) and the one it should use for sending commands to -@code{gcjwebplugin} (OUTPUT). - -@end table - -@item DEBUGGING OPTION -@table @b -@item -verbose -Use the @code{-verbose} option to have the @code{appletviewer} print -debugging messages. - -@end table - -@item STANDARD OPTIONS -@table @b -@item -help -Use the @code{-help} option to have the @code{appletviewer} print a -usage message, then exit. - -@item -version -Use the @code{-version} option to have the @code{appletviewer} print -its version, then exit. - -@item -JOPTION -Use the @code{-J} option to pass OPTION to the virtual machine that -will run the @code{appletviewer}. Unlike other options, there must -not be a space between the -J and OPTION. - -@end table -@end table - -@comment ---------------------------------------------------------------------- - -@node gcjwebplugin, , appletviewer Tool, Applet Tools -@comment node-name, next, previous, up -@section The @code{gcjwebplugin} Tool - -@code{gcjwebplugin} is a plugin that adds applet support to web -browsers. Currently @code{gcjwebplugin} only supports Mozilla-based -browsers (e.g., Firefox, Galeon, Mozilla). - -@comment ---------------------------------------------------------------------- - -@node Security Tools, I18N Issues, Applet Tools, Top -@comment node-name, next, previous, up -@chapter Security Tools - -Two Security Tools are available with GNU Classpath: @b{jarsigner} and @b{keytool}. - -To avoid conflicts with other implementations, the jarsigner -executable is called ``gjarsigner'' and the keytool executable is -called ``gkeytool''. - -@menu -* jarsigner Tool:: Sign and verify .JAR files -* keytool Tool:: Manage private keys and public certificates -@end menu - -If while using these tools you think you found a bug, then please report it at @uref{http://www.gnu.org/software/classpath/bugs.html,classpath-bugs}. - -@comment ---------------------------------------------------------------------- - -@node jarsigner Tool, keytool Tool, Security Tools, Security Tools -@comment node-name, next, previous, up -@section The @code{jarsigner} Tool - -The @b{jarsigner} tool is invoked from the command line, in one of two forms, as follows: - -@example -@code{jarsigner [OPTION]... FILE ALIAS} -@code{jarsigner -verify [OPTION]... FILE} -@end example - -When the first form is used, the tool signs the designated JAR file. The second form, on the other hand, is used to verify a previously signed JAR file. - -@code{FILE} is the .JAR file to process; i.e. to sign if the first syntax form is used, or to verify if the second syntax form is used instead. - -@code{ALIAS} must be a known @i{Alias} of a @i{Key Entry} in the designated @i{Key Store}. The private key material associated with this @i{Alias} is then used for signing the designated .JAR file. - -@menu -* Common jarsigner Options:: Options used when signing or verifying a file -* Signing Options:: Options only used when signing a .JAR file -* Verification Options:: Options only used when verifying a .JAR file -@end menu - -@comment ---------------------------------------------------------------------- - -@node Common jarsigner Options, Signing Options, jarsigner Tool, jarsigner Tool -@comment node-name, next, previous, up -@subsection Common options - -The following options may be used when the tool is used for either signing, or verifying, a .JAR file. - -@table @b -@item -verbose -Use this option to force the tool to generate more verbose messages, during its processing. - -@item -internalsf -When present, the tool will include --which otherwise it does not-- the @code{.SF} file in the @code{.DSA} generated file. - -@item -sectionsonly -When present, the tool will include in the @code{.SF} generated file --which otherwise it does not-- a header containing a hash of the whole manifest file. When that header is included, the tool can quickly check, during verification, if the hash (in the header) matches or not the manifest file. - -@item -provider PROVIDER_CLASS_NAME -A fully qualified class name of a @i{Security Provider} to add to the current list of @i{Security Providers} already installed in the JVM in-use. If a provider class is specified with this option, and was successfully added to the runtime --i.e. it was not already installed-- then the tool will attempt to remove this @i{Security Provider} before exiting. - -@item -help -Prints a help text similar to this one. - -@end table - -@comment ---------------------------------------------------------------------- - -@node Signing Options, Verification Options, Common jarsigner Options, jarsigner Tool -@comment node-name, next, previous, up -@subsection Signing options - -The following options may be specified when using the tool for signing purposes. - -@table @b -@item -keystore URL -Use this option to specify the location of the key store to use. The default value is a file URL referencing the file named @file{.keystore} located in the path returned by the call to @code{java.lang.System#getProperty(String)} using @code{user.home} as argument. - -If a URL was specified, but was found to be malformed --e.g. missing protocol element-- the tool will attempt to use the URL value as a file-name (with absolute or relative path-name) of a key store --as if the protocol was @code{file:}. - -@item -storetype STORE_TYPE -Use this option to specify the type of the key store to use. The default value, if this option is omitted, is that of the property @code{keystore.type} in the security properties file, which is obtained by invoking the static method call @code{getDefaultType()} in @code{java.security.KeyStore}. - -@item -storepass PASSWORD -Use this option to specify the password which will be used to unlock the key store. If this option is missing, the User will be prompted to provide a password. - -@item -keypass PASSWORD -Use this option to specify the password which the tool will use to unlock the @i{Key Entry} associated with the designated @i{Alias}. - -If this option is omitted, the tool will first attempt to unlock the @i{Key Entry} using the same password protecting the key store. If this fails, you will then be prompted to provide a password. - -@item -sigfile NAME -Use this option to designate a literal that will be used to construct file names for both the @code{.SF} and @code{.DSA} signature files. These files will be generated, by the tool, and placed in the @file{META-INF} directory of the signed JAR. Permissible characters for @code{NAME} must be in the range "a-zA-Z0-9_-". All characters will be converted to upper-case ones. - -If this option is missing, the first eight characters of the @code{ALIAS} argument will be used. When this is the case, any character in @code{ALIAS} that is outside the permissible range of characters will be replaced by an underscore. - -@item -signedjar FILE -Use this option to specify the file name of the signed JAR. If this option is omitted, then the signed JAR will be named the same as @code{FILE}; i.e. the input JAR file will be replaced with the signed copy. - -@end table - -@comment ---------------------------------------------------------------------- - -@node Verification Options, , Signing Options, jarsigner Tool -@comment node-name, next, previous, up -@subsection Verification options - -The following options may be specified when using the tool for verification purposes. - -@table @b -@item -verify -Use this option to indicate that the tool is to be used for verification purposes. - -@item -certs -This option is used in conjunction with the @code{-verbose} option. When present, along with the @code{-verbose} option, the tool will print more detailed information about the certificates of the signer(s) being processed. - -@end table - -@comment ---------------------------------------------------------------------- - -@node keytool Tool, , jarsigner Tool, Security Tools -@comment node-name, next, previous, up -@section The @code{keytool} Tool - -Cryptographic credentials, in a Java environment, are usually stored in a @i{Key Store}. The Java SDK specifies a @i{Key Store} as a persistent container of two types of objects: @i{Key Entries} and @i{Trusted Certificates}. The security tool @b{keytool} is a Java-based application for managing those types of objects. - -A @i{Key Entry} represents the private key part of a key-pair used in Public-Key Cryptography, and a signed X.509 certificate which authenticates the public key part for a known entity; i.e. the owner of the key-pair. The X.509 certificate itself contains the public key part of the key-pair. - -A @i{Trusted Certificate} is a signed X.509 certificate issued by a trusted entity. The @i{Trust} in this context is relative to the User of the @b{keytool}. In other words, the existence of a @i{Trusted Certificate} in the @i{Key Store} processed by a @b{keytool} command implies that the User trusts the @i{Issuer} of that @i{Trusted Certificate} to also sign, and hence authenticates, other @i{Subjects} the tool may process. - -@i{Trusted Certificates} are important because they allow the tool to mechanically construct @i{Chains of Trust} starting from one of the @i{Trusted Certificates} in a @i{Key Store} and ending with a certificate whose @i{Issuer} is potentially unknown. A valid chain is an ordered list, starting with a @i{Trusted Certificate} (also called the @i{anchor}), ending with the target certificate, and satisfying the condition that the @i{Subject} of certificate @code{#i} is the @i{Issuer} of certificate @code{#i + 1}. - -The @b{keytool} is invoked from the command line as follows: - -@example -@code{keytool [COMMAND]...} -@end example - -Multiple @code{COMMAND}s may be specified at once, each complete with its own options. @b{keytool} will parse all the arguments, before processing, and executing, each @code{COMMAND}. If an exception occurs while executing one @code{COMMAND} @b{keytool} will abort. Note however that because the implementation of the tool uses code to parse command line options that also supports GNU-style options, you have to separate each command group with a double-hyphen; e.g - -@example -@code{keytool -list -- -printcert -alias mykey} -@end example - -Here is a summary of the commands supported by the tool: - -@enumerate -@item Add/Update commands -@itemize @bullet -@item -genkey [OPTION]@dots{} -Generate a new @i{Key Entry}, eventually creating a new key store. - -@item -import [OPTION]@dots{} -Add, to a key store, @i{Key Entries} (private keys and certificate chains authenticating the public keys) and @i{Trusted Certificates} (3rd party certificates which can be used as @i{Trust Anchors} when building chains-of-trust). - -@item -selfcert [OPTION]@dots{} -Generate a new self-signed @i{Trusted Certificate}. - -@item -cacert [OPTION]@dots{} -Import a CA @i{Trusted Certificate}. - -@item -identitydb [OPTION]@dots{} -@b{NOT IMPLEMENTED YET}.@* -Import a JDK 1.1 style Identity Database. -@end itemize - -@item Export commands -@itemize @bullet -@item -certreq [OPTION]@dots{} -Issue a @i{Certificate Signing Request} (CSR) which can be then sent to a @i{Certification Authority} (CA) to issue a certificate signed (by the CA) and authenticating the @i{Subject} of the request. - -@item -export [OPTION]@dots{} -Export a certificate from a key store. -@end itemize - -@item Display commands -@itemize @bullet -@item -list [OPTION]@dots{} -Print one or all certificates in a key store to @code{STDOUT}. - -@item -printcert [OPTION]@dots{} -Print a human-readable form of a certificate, in a designated file, to @code{STDOUT}. -@end itemize - -@item Management commands -@itemize @bullet -@item -keyclone [OPTION]@dots{} -Clone a @i{Key Entry} in a key store. - -@item -storepasswd [OPTION]@dots{} -Change the password protecting a key store. - -@item -keypasswd [OPTION]@dots{} -Change the password protecting a @i{Key Entry} in a key store. - -@item -delete [OPTION]@dots{} -Delete a @i{Key Entry} or a @i{Trusted Certificate} from a key store. -@end itemize - -@end enumerate - -@menu -* Getting Help:: How to get help with keytool commands -* Common keytool Options:: Options used in more than one command -* Distinguished Names:: X.500 Distinguished Names used in certificates -* Add/Update Commands:: Commands for adding data to a Key Store -* Export Commands:: Commands for exporting data from a Key Store -* Display Commands:: Commands for displaying data in a Key Store -* Management Commands:: Commands for managing a Key Store -@end menu - -@comment ---------------------------------------------------------------------- - -@node Getting Help, Common keytool Options, keytool Tool, keytool Tool -@comment node-name, next, previous, up -@subsection Getting help - -To get a general help text about the tool, use the @code{-help} option; e.g. - -@example -@code{keytool -help} -@end example - -To get more specific help text about one of the tool's command use the @code{-help} option for that command; e.g. - -@example -@code{keytool -genkey -help} -@end example - -In both instances, the tool will print a help text and then will exit the running JVM. - -It is worth noting here that the help messages printed by the tool are I18N-ready. This means that if/when the contents of the tool's @i{Message Bundle} properties file are available in languages other than English, you may see those messages in that language. - -@comment ---------------------------------------------------------------------- - -@node Common keytool Options, Distinguished Names, Getting Help, keytool Tool -@comment node-name, next, previous, up -@subsection Common options - -The following @code{OPTION}s are used in more than one @code{COMMAND}. They are described here to reduce redundancy. - -@table @b -@anchor{alias} -@item -alias ALIAS -Every entry, be it a @i{Key Entry} or a @i{Trusted Certificate}, in a key store is uniquely identified by a user-defined @i{Alias} string. Use this option to specify the @i{Alias} to use when referring to an entry in the key store. Unless specified otherwise, a default value of @code{mykey} shall be used when this option is omitted from the command line. - -@anchor{keyalg} -@item -keyalg ALGORITHM -Use this option to specify the canonical name of the key-pair generation algorithm. The default value for this option is @code{DSS} (a synonym for the Digital Signature Algorithm also known as DSA). - -@anchor{keysize} -@item -keysize SIZE -Use this option to specify the number of bits of the shared modulus (for both the public and private keys) to use when generating new keys. A default value of @code{1024} will be used if this option is omitted from the command line. - -@anchor{validity} -@item -validity DAY_COUNT -Use this option to specify the number of days a newly generated certificate will be valid for. The default value is @code{90} (days) if this option is omitted from the command line. - -@anchor{storetype} -@item -storetype STORE_TYPE -Use this option to specify the type of the key store to use. The default value, if this option is omitted, is that of the property @code{keystore.type} in the security properties file, which is obtained by invoking the static method call @code{getDefaultType()} in @code{java.security.KeyStore}. - -@anchor{storepass} -@item -storepass PASSWORD -Use this option to specify the password protecting the key store. If this option is omitted from the command line, you will be prompted to provide a password. - -@anchor{keystore} -@item -keystore URL -Use this option to specify the location of the key store to use. The default value is a file URL referencing the file named @file{.keystore} located in the path returned by the call to @code{java.lang.System#getProperty(String)} using @code{user.home} as argument. - -If a URL was specified, but was found to be malformed --e.g. missing protocol element-- the tool will attempt to use the URL value as a file-name (with absolute or relative path-name) of a key store --as if the protocol was @code{file:}. - -@anchor{provider} -@item -provider PROVIDER_CLASS_NAME -A fully qualified class name of a @i{Security Provider} to add to the current list of @i{Security Providers} already installed in the JVM in-use. If a provider class is specified with this option, and was successfully added to the runtime --i.e. it was not already installed-- then the tool will attempt to removed this @i{Security Provider} before exiting. - -@anchor{file} -@item -file FILE -Use this option to designate a file to use with a command. When specified with this option, the value is expected to be the fully qualified path of a file accessible by the File System. Depending on the command, the file may be used as input or as output. When this option is omitted from the command line, @code{STDIN} will be used instead, as the source of input, and @code{STDOUT} will be used instead as the output destination. - -@anchor{verbose} -@item -v -Unless specified otherwise, use this option to enable more verbose output. - -@end table - -@comment ---------------------------------------------------------------------- - -@node Distinguished Names, Add/Update Commands, Common keytool Options, keytool Tool -@comment node-name, next, previous, up -@subsection X.500 Distinguished Names - -@anchor{dn} -A @i{Distinguished Name} (or DN) MUST be supplied with some of the @code{COMMAND}s using a @code{-dname} option. The syntax of a valid value for this option MUST follow RFC-2253 specifications. Namely the following components (with their accepted meaning) will be recognized. Note that the component name is case-insensitive: - -@ftable @var -@item CN -The Common Name; e.g. @kbd{host.domain.com} -@item OU -The Organizational Unit; e.g. @kbd{IT Department} -@item O -The Organization Name; e.g. @kbd{The Sample Company} -@item L -The Locality Name; e.g. @kbd{Sydney} -@item ST -The State Name; e.g. @kbd{New South Wales} -@item C -The 2-letter Country identifier; e.g. @kbd{AU} -@end ftable - -When specified with a @code{-dname} option, each pair of component/value will be separated from the other with a comma. Each component and value pair MUST be separated by an equal sign. For example, the following is a valid DN value:@* - -@format -CN=host.domain.com, O=The Sample Company, L=Sydney, ST=NSW, C=AU -@end format -@* -If the @i{Distinguished Name} is required, and no valid default value can be used, the tool will prompt you to enter the information through the console. - -@comment ---------------------------------------------------------------------- - -@node Add/Update Commands, Export Commands, Distinguished Names, keytool Tool -@comment node-name, next, previous, up -@subsection Add/Update commands - -@menu -* Command -genkey:: Generate private key and self-signed certificate -* Command -import:: Import certificates and certificate replies -* Command -selfcert:: Generate self-signed certificate -* Command -cacert:: Import a CA Trusted Certificate -* Command -identitydb:: Import JDK-1 style identities -@end menu - -@comment ---------------------------------------------------------------------- - -@node Command -genkey, Command -import, Add/Update Commands, Add/Update Commands -@comment node-name, next, previous, up -@subsubsection @code{-genkey} command - -Use this command to generate a new key-pair (both private and public keys), and save these credentials in the key store as a @i{Key Entry}, associated with the designated (if was specified with the @code{-alias} option) or default (if the @code{-alias} option is omitted) @i{Alias}. - -The private key material will be protected with a user-defined password (see @code{-keypass} option). The public key on the other hand will be part of a self-signed X.509 certificate, which will form a 1-element chain and will be saved in the key store. - -@table @b -@item -alias ALIAS -For more details @pxref{alias,, ALIAS}. - -@item -keyalg ALGORITHM -For more details @pxref{keyalg,, ALGORITHM}. - -@item -keysize KEY_SIZE -For more details @pxref{keysize,, KEY_SIZE}. - -@item -sigalg ALGORITHM -The canonical name of the digital signature algorithm to use for signing certificates. If this option is omitted, a default value will be chosen based on the type of the key-pair; i.e. the algorithm that ends up being used by the -keyalg option. If the key-pair generation algorithm is @code{DSA}, the value for the signature algorithm will be @code{SHA1withDSA}. If on the other hand the key-pair generation algorithm is @code{RSA}, then the tool will use @code{MD5withRSA} as the signature algorithm. - -@item -dname NAME -This a mandatory value for the command. If no value is specified --i.e. the @code{-dname} option is omitted-- the tool will prompt you to enter a @i{Distinguished Name} to use as both the @i{Owner} and @i{Issuer} of the generated self-signed certificate. - -For more details @pxref{dn,, X.500 DISTINGUISHED NAME}. - -@item -keypass PASSWORD -Use this option to specify the password which the tool will use to protect the newly created @i{Key Entry}. - -If this option is omitted, you will be prompted to provide a password. - -@item -validity DAY_COUNT -For more details @pxref{validity,, DAY_COUNT}. - -@item -storetype STORE_TYPE -For more details @pxref{storetype,, STORE_TYPE}. - -@item -keystore URL -For more details @pxref{keystore,, URL}. - -@item -storepass PASSWORD -For more details @pxref{storepass,, PASSWORD}. - -@item -provider PROVIDER_CLASS_NAME -For more details @pxref{provider,, PROVIDER_CLASS_NAME}. - -@item -v -For more details @pxref{verbose}. - -@end table - -@comment ---------------------------------------------------------------------- - -@node Command -import, Command -selfcert, Command -genkey, Add/Update Commands -@comment node-name, next, previous, up -@subsubsection @code{-import} command - -Use this command to read an X.509 certificate, or a PKCS#7 @i{Certificate Reply} from a designated input source and incorporate the certificates into the key store. - -If the @i{Alias} does not already exist in the key store, the tool treats the certificate read from the input source as a new @i{Trusted Certificate}. It then attempts to discover a chain-of-trust, starting from that certificate and ending at another @i{Trusted Certificate}, already stored in the key store. If the @code{-trustcacerts} option is present, an additional key store, of type @code{JKS} named @file{cacerts}, and assumed to be present in @file{$@{JAVA_HOME@}/lib/security} will also be consulted if found --@code{$@{JAVA_HOME@}} refers to the location of an installed @i{Java Runtime Environment} (JRE). If no chain-of-trust can be established, and unless the @code{-noprompt} option has been specified, the certificate is printed to @code{STDOUT} and the user is prompted for a confirmation. - -If @i{Alias} exists in the key store, the tool will treat the certificate(s) read from the input source as a @i{Certificate Reply}, which can be a chain of certificates, that eventually would replace the chain of certificates associated with the @i{Key Entry} of that @i{Alias}. The substitution of the certificates only occurs if a chain-of-trust can be established between the bottom certificate of the chain read from the input file and the @i{Trusted Certificates} already present in the key store. Again, if the @code{-trustcacerts} option is specified, additional @i{Trusted Certificates} in the same @file{cacerts} key store will be considered. If no chain-of-trust can be established, the operation will abort. - -@table @b -@item -alias ALIAS -For more details @pxref{alias,, ALIAS}. - -@item -file FILE -For more details @pxref{file,, FILE}. - -@item -keypass PASSWORD -Use this option to specify the password which the tool will use to protect the @i{Key Entry} associated with the designated @i{Alias}, when replacing this @i{Alias}' chain of certificates with that found in the certificate reply. - -If this option is omitted, and the chain-of-trust for the certificate reply has been established, the tool will first attempt to unlock the @i{Key Entry} using the same password protecting the key store. If this fails, you will then be prompted to provide a password. - -@item -noprompt -Use this option to prevent the tool from prompting the user. - -@item -trustcacerts -Use this option to indicate to the tool that a key store, of type @code{JKS}, named @file{cacerts}, and usually located in @file{lib/security} in an installed @i{Java Runtime Environment} should be considered when trying to establish chain-of-trusts. - -@item -storetype STORE_TYPE -For more details @pxref{storetype,, STORE_TYPE}. - -@item -keystore URL -For more details @pxref{keystore,, URL}. - -@item -storepass PASSWORD -For more details @pxref{storepass,, PASSWORD}. - -@item -provider PROVIDER_CLASS_NAME -For more details @pxref{provider,, PROVIDER_CLASS_NAME}. - -@item -v -For more details @pxref{verbose}. - -@end table - -@comment ---------------------------------------------------------------------- - -@node Command -selfcert, Command -cacert, Command -import, Add/Update Commands -@comment node-name, next, previous, up -@subsubsection @code{-selfcert} command - -Use this command to generate a self-signed X.509 version 1 certificate. The newly generated certificate will form a chain of one element which will replace the previous chain associated with the designated @i{Alias} (if @code{-alias} option was specified), or the default @i{Alias} (if @code{-alias} option was omitted). - -@table @b -@item -alias ALIAS -For more details @pxref{alias,, ALIAS}. - -@item -sigalg ALGORITHM -The canonical name of the digital signature algorithm to use for signing the certificate. If this option is omitted, a default value will be chosen based on the type of the private key associated with the designated @i{Alias}. If the private key is a @code{DSA} one, the value for the signature algorithm will be @code{SHA1withDSA}. If on the other hand the private key is an @code{RSA} one, then the tool will use @code{MD5withRSA} as the signature algorithm. - -@item -dname NAME -Use this option to specify the @i{Distinguished Name} of the newly generated self-signed certificate. If this option is omitted, the existing @i{Distinguished Name} of the base certificate in the chain associated with the designated @i{Alias} will be used instead. - -For more details @pxref{dn,, X.500 DISTINGUISHED NAME}. - -@item -validity DAY_COUNT -For more details @pxref{validity,, DAY_COUNT}. - -@item -keypass PASSWORD -Use this option to specify the password which the tool will use to unlock the @i{Key Entry} associated with the designated @i{Alias}. - -If this option is omitted, the tool will first attempt to unlock the @i{Key Entry} using the same password protecting the key store. If this fails, you will then be prompted to provide a password. - -@item -storetype STORE_TYPE -For more details @pxref{storetype,, STORE_TYPE}. - -@item -keystore URL -For more details @pxref{keystore,, URL}. - -@item -storepass PASSWORD -For more details @pxref{storepass,, PASSWORD}. - -@item -provider PROVIDER_CLASS_NAME -For more details @pxref{provider,, PROVIDER_CLASS_NAME}. - -@item -v -For more details @pxref{verbose}. - -@end table - -@comment ---------------------------------------------------------------------- - -@node Command -cacert, Command -identitydb, Command -selfcert, Add/Update Commands -@comment node-name, next, previous, up -@subsubsection @code{-cacert} command - -Use this command to import, a CA certificate and add it to the key store as a @i{Trusted Certificate}. The @i{Alias} for this new entry will be constructed from the FILE's base-name after replacing hyphens and dots with underscores. - -This command is useful when used in a script that recursively visits a directory of CA certificates to populate a @code{cacerts.gkr} @i{Key Store} of trusted certificates which can then be used commands that specify the @code{-trustcacerts} option. - -@table @b -@item -file FILE -For more details @pxref{file,, FILE}. - -@item -storetype STORE_TYPE -For more details @pxref{storetype,, STORE_TYPE}. - -@item -keystore URL -For more details @pxref{keystore,, URL}. - -@item -storepass PASSWORD -For more details @pxref{storepass,, PASSWORD}. - -@item -provider PROVIDER_CLASS_NAME -For more details @pxref{provider,, PROVIDER_CLASS_NAME}. - -@item -v -For more details @pxref{verbose}. - -@end table - -@comment ---------------------------------------------------------------------- - -@node Command -identitydb, , Command -cacert, Add/Update Commands -@comment node-name, next, previous, up -@subsubsection @code{-identitydb} command - -@b{NOT IMPLEMENTED YET}. - -Use this command to import a JDK 1.1 style Identity Database. - -@table @b -@item -file FILE -For more details @pxref{file,, FILE}. - -@item -storetype STORE_TYPE -For more details @pxref{storetype,, STORE_TYPE}. - -@item -keystore URL -For more details @pxref{keystore,, URL}. - -@item -storepass PASSWORD -For more details @pxref{storepass,, PASSWORD}. - -@item -provider PROVIDER_CLASS_NAME -For more details @pxref{provider,, PROVIDER_CLASS_NAME}. - -@item -v -For more details @pxref{verbose}. - -@end table - -@comment ---------------------------------------------------------------------- - -@node Export Commands, Display Commands, Add/Update Commands, keytool Tool -@comment node-name, next, previous, up -@subsection Export commands - -@menu -* Command -certreq:: Generate Certificate Signing Requests (CSR) -* Command -export:: Export a certificate in a Key Store -@end menu - -@comment ---------------------------------------------------------------------- - -@node Command -certreq, Command -export, Export Commands, Export Commands -@comment node-name, next, previous, up -@subsubsection @code{-certreq} command - -Use this command to generate a PKCS#10 @i{Certificate Signing Request} (CSR) and write it to a designated output destination. The contents of the destination should look something like the following: - -@example ------BEGIN NEW CERTIFICATE REQUEST----- -MI...QAwXzEUMBIGA1UEAwwLcnNuQGdudS5vcmcxGzAZBgNVBAoMElUg -Q2...A0GA1UEBwwGU3lkbmV5MQwwCgYDVQQIDANOU1cxCzAJBgNVBACC -... -FC...IVwNVOfQLRX+O5kAhQ/a4RTZme2L8PnpvgRwrf7Eg8D6w== ------END NEW CERTIFICATE REQUEST----- -@end example - -@b{IMPORTANT}: Some documentation (e.g. RSA examples) claims that the @code{Attributes} field, in the CSR is @code{OPTIONAL} while RFC-2986 implies the opposite. This implementation considers this field, by default, as @code{OPTIONAL}, unless the option @code{-attributes} is specified on the command line. - -@table @b -@item -alias ALIAS -For more details @pxref{alias,, ALIAS}. - -@item -sigalg ALGORITHM -The canonical name of the digital signature algorithm to use for signing the certificate. If this option is omitted, a default value will be chosen based on the type of the private key associated with the designated @i{Alias}. If the private key is a @code{DSA} one, the value for the signature algorithm will be @code{SHA1withDSA}. If on the other hand the private key is an @code{RSA} one, then the tool will use @code{MD5withRSA} as the signature algorithm. - -@item -file FILE -For more details @pxref{file,, FILE}. - -@item -keypass PASSWORD -Use this option to specify the password which the tool will use to unlock the @i{Key Entry} associated with the designated @i{Alias}. - -If this option is omitted, the tool will first attempt to unlock the @i{Key Entry} using the same password protecting the key store. If this fails, you will then be prompted to provide a password. - -@item -storetype STORE_TYPE -For more details @pxref{storetype,, STORE_TYPE}. - -@item -keystore URL -For more details @pxref{keystore,, URL}. - -@item -storepass PASSWORD -For more details @pxref{storepass,, PASSWORD}. - -@item -provider PROVIDER_CLASS_NAME -For more details @pxref{provider,, PROVIDER_CLASS_NAME}. - -@item -v -For more details @pxref{verbose}. - -@item -attributes -Use this option to force the tool to encode a @code{NULL} DER value in the CSR as the value of the @code{Attributes} field. - -@end table - -@comment ---------------------------------------------------------------------- - -@node Command -export, , Command -certreq, Export Commands -@comment node-name, next, previous, up -@subsubsection @code{-export} command - -Use this command to export a certificate stored in a key store to a designated output destination, either in binary format (if the @code{-v} option is specified), or in RFC-1421 compliant encoding (if the @code{-rfc} option is specified instead). - -@table @b -@item -alias ALIAS -For more details @pxref{alias,, ALIAS}. - -@item -file FILE -For more details @pxref{file,, FILE}. - -@item -storetype STORE_TYPE -For more details @pxref{storetype,, STORE_TYPE}. - -@item -keystore URL -For more details @pxref{keystore,, URL}. - -@item -storepass PASSWORD -For more details @pxref{storepass,, PASSWORD}. - -@item -provider PROVIDER_CLASS_NAME -For more details @pxref{provider,, PROVIDER_CLASS_NAME}. - -@item -rfc -Use RFC-1421 specifications when encoding the output. - -@item -v -Output the certificate in binary DER encoding. This is the default output format of the command if neither @code{-rfc} nor @code{-v} options were detected on the command line. If both this option and the @code{-rfc} option are detected on the command line, the tool will opt for the RFC-1421 style encoding. - -@end table - -@comment ---------------------------------------------------------------------- - -@node Display Commands, Management Commands, Export Commands, keytool Tool -@comment node-name, next, previous, up -@subsection Display commands - -@menu -* Command -list:: Display information about one or all Aliases -* Command -printcert:: Print a certificate or a certificate fingerprint -@end menu - -@comment ---------------------------------------------------------------------- - -@node Command -list, Command -printcert, Display Commands, Display Commands -@comment node-name, next, previous, up -@subsubsection @code{-list} command - -Use this command to print one or all of a key store entries to @code{STDOUT}. Usually this command will only print a @i{fingerprint} of the certificate, unless either the @code{-rfc} or the @code{-v} option is specified. - -@table @b -@item -alias ALIAS -If this option is omitted, the tool will print ALL the entries found in the key store. - -For more details @pxref{alias,, ALIAS}. - -@item -storetype STORE_TYPE -For more details @pxref{storetype,, STORE_TYPE}. - -@item -keystore URL -For more details @pxref{keystore,, URL}. - -@item -storepass PASSWORD -For more details @pxref{storepass,, PASSWORD}. - -@item -provider PROVIDER_CLASS_NAME -For more details @pxref{provider,, PROVIDER_CLASS_NAME}. - -@item -rfc -Use RFC-1421 specifications when encoding the output. - -@item -v -Output the certificate in human-readable format. If both this option and the @code{-rfc} option are detected on the command line, the tool will opt for the human-readable form and will not abort the command. - -@end table - -@comment ---------------------------------------------------------------------- - -@node Command -printcert, , Command -list, Display Commands -@comment node-name, next, previous, up -@subsubsection @code{-printcert} command - -Use this command to read a certificate from a designated input source and print it to @code{STDOUT} in a human-readable form. - -@table @b -@item -file FILE -For more details @pxref{file,, FILE}. - -@item -v -For more details @pxref{verbose}. - -@end table - -@comment ---------------------------------------------------------------------- - -@node Management Commands, , Display Commands, keytool Tool -@comment node-name, next, previous, up -@subsection Management commands - -@menu -* Command -keyclone:: Clone a Key Entry in a Key Store -* Command -storepasswd:: Change the password protecting a Key Store -* Command -keypasswd:: Change the password protecting a Key Entry -* Command -delete:: Remove an entry in a Key Store -@end menu - -@comment ---------------------------------------------------------------------- - -@node Command -keyclone, Command -storepasswd, Management Commands, Management Commands -@comment node-name, next, previous, up -@subsubsection @code{-keyclone} command - -Use this command to clone an existing @i{Key Entry} and store it under a new (different) @i{Alias} protecting, its private key material with possibly a new password. - -@table @b -@item -alias ALIAS -For more details @pxref{alias,, ALIAS}. - -@item -dest ALIAS -Use this option to specify the new @i{Alias} which will be used to identify the cloned copy of the @i{Key Entry}. - -@item -keypass PASSWORD -Use this option to specify the password which the tool will use to unlock the @i{Key Entry} associated with the designated @i{Alias}. - -If this option is omitted, the tool will first attempt to unlock the @i{Key Entry} using the same password protecting the key store. If this fails, you will then be prompted to provide a password. - -@item -new PASSWORD -Use this option to specify the password protecting the private key material of the newly cloned copy of the @i{Key Entry}. - -@item -storetype STORE_TYPE -For more details @pxref{storetype,, STORE_TYPE}. - -@item -keystore URL -For more details @pxref{keystore,, URL}. - -@item -storepass PASSWORD -For more details @pxref{storepass,, PASSWORD}. - -@item -provider PROVIDER_CLASS_NAME -For more details @pxref{provider,, PROVIDER_CLASS_NAME}. - -@item -v -For more details @pxref{verbose}. - -@end table - -@comment ---------------------------------------------------------------------- - -@node Command -storepasswd, Command -keypasswd, Command -keyclone, Management Commands -@comment node-name, next, previous, up -@subsubsection @code{-storepasswd} command - -Use this command to change the password protecting a key store. - -@table @b -@item -new PASSWORD -The new, and different, password which will be used to protect the designated key store. - -@item -storetype STORE_TYPE -For more details @pxref{storetype,, STORE_TYPE}. - -@item -keystore URL -For more details @pxref{keystore,, URL}. - -@item -storepass PASSWORD -For more details @pxref{storepass,, PASSWORD}. - -@item -provider PROVIDER_CLASS_NAME -For more details @pxref{provider,, PROVIDER_CLASS_NAME}. - -@item -v -For more details @pxref{verbose}. - -@end table - -@comment ---------------------------------------------------------------------- - -@node Command -keypasswd, Command -delete, Command -storepasswd, Management Commands -@comment node-name, next, previous, up -@subsubsection @code{-keypasswd} command - -Use this command to change the password protecting the private key material of a designated @i{Key Entry}. - -@table @b -@item -alias ALIAS -For more details @pxref{alias,, ALIAS}. - -Use this option to specify the password which the tool will use to unlock the @i{Key Entry} associated with the designated @i{Alias}. - -If this option is omitted, the tool will first attempt to unlock the @i{Key Entry} using the same password protecting the key store. If this fails, you will then be prompted to provide a password. - -@item -new PASSWORD -The new, and different, password which will be used to protect the private key material of the designated @i{Key Entry}. - -@item -storetype STORE_TYPE -For more details @pxref{storetype,, STORE_TYPE}. - -@item -keystore URL -For more details @pxref{keystore,, URL}. - -@item -storepass PASSWORD -For more details @pxref{storepass,, PASSWORD}. - -@item -provider PROVIDER_CLASS_NAME -For more details @pxref{provider,, PROVIDER_CLASS_NAME}. - -@item -v -For more details @pxref{verbose}. - -@end table - -@comment ---------------------------------------------------------------------- - -@node Command -delete, , Command -keypasswd, Management Commands -@comment node-name, next, previous, up -@subsubsection @code{-delete} command - -Use this command to delete a designated key store entry. - -@table @b -@item -alias ALIAS -For more details @pxref{alias,, ALIAS}. - -@item -storetype STORE_TYPE -For more details @pxref{storetype,, STORE_TYPE}. - -@item -keystore URL -For more details @pxref{keystore,, URL}. - -@item -storepass PASSWORD -For more details @pxref{storepass,, PASSWORD}. - -@item -provider PROVIDER_CLASS_NAME -For more details @pxref{provider,, PROVIDER_CLASS_NAME}. - -@item -v -For more details @pxref{verbose}. - -@end table - -@comment ---------------------------------------------------------------------- - -@node I18N Issues, , Security Tools, Top -@comment node-name, next, previous, up -@chapter I18N Issues - -Some tools --@pxref{Security Tools}-- allow using other than the English language when prompting the User for input, and outputing messages. This chapter describes the elements used to offer this support and how they can be adapted for use with specific languages. - -@menu -* Language Resources:: Where resources are located -* Message Formats:: How messages are internationalized -@end menu - -@comment ---------------------------------------------------------------------- - -@node Language Resources, Message Formats, I18N Issues, I18N Issues -@comment node-name, next, previous, up -@section Language-specific resources - -The Tools use Java @code{ResourceBundle}s to store messages, and message templates they use at runtime to generate the message text itself, depending on the locale in use at the time. - -The @i{Resource Bundles} these tools use are essentially Java @i{Properties} files consisting of a set of @i{Name/Value} pairs. The @i{Name} is the @i{Propery Name} and the @i{Value} is a substitution string that is used when the code references the associated @i{Name}. For example the following is a line in a @i{Resource Bundle} used by the @code{keytool} Tool: - -@example -Command.23=A correct key password MUST be provided -@end example - -When the tool needs to signal a mandatory but missing key password, it would reference the property named @code{Command.23} and the message "@kbd{A correct key password MUST be provided}" will be used instead. This indirect referencing of "resources" permits replacing, as late as possible, the English strings with strings in other languages, provided of course @i{Resource Bundles} in those languages are provided. - -For the GNU Classpath Tools described in this Guide, the @i{Resource Bundles} are files named @file{messages[_ll[_CC[_VV]]].properties} where: - -@ftable @var -@item ll -Is the 2-letter code for the Language, -@item CC -Is the 2-letter code for the Region, and -@item VV -Is the 2-letter code for the Variant of the language. -@end ftable - -The complete list of language codes can be found at @uref{http://ftp.ics.uci.edu/pub/ietf/http/related/iso639.txt, Code for the representation of names of languages}. A similar list for the region codes can be found at @uref{http://userpage.chemie.fu-berlin.de/diverse/doc/ISO_3166.html, ISO 3166 Codes (Countries)}. - -The location of the @i{Resource Bundles} for the GNU Classpath Tools is specific to each tool. The next table shows where these files are found in a standard GNU Classpath distribution: - -@ftable @code -@item jarsigner -@file{gnu/classpath/tools/jarsigner} -@item keytool -@file{gnu/classpath/tools/keytool} -@end ftable - -The collection of @i{Resource Bundles} in a location act as an inverted tree with a parent-child relationship. For example suppose in the @file{gnu/classpath/tools/keytool} there are 3 message bundles named: - -@enumerate -@item @code{messages.properties} -@item @code{messages_fr.properties} -@item @code{messages_fr_FR.properties} -@end enumerate - -In the above example, bundle #1 will act as the parent of bundle #2, which in turn will act as the parent for bundle #3. This ordering is used by the Java runtime to choose which file to load based on the set Locale. For example if the Locale is @code{fr_CH}, @code{messages_fr.properties} will be used because (a) @code{messages_fr_CH.properties} does not exist, but (b) @code{messages_fr.properties} is the parent for the required bundle, and it exists. As another example, suppose the Locale was set to @code{en_AU}; then the tool will end up using @code{messages.properties} because (a) @code{messages_en_AU.properties} does not exist, (b) @code{messages_en.properties} which is the parent for the required bundle does not exist, but (c) @code{messages.properties} exists and is the root of the hierarchy. - -You can see from the examples above that @file{messages.properties} is the safety net that the Java runtime falls back to when failing to find a specific bunlde and its parent(s). This file is always provided with the Tool. In time, more localized versions will be included to cater for other languages. - -In the meantime, if you are willing to contribute localized versions of these resources, grab the @file{messages.properties} for a specific tool; translate it; save it with the appropriate language and region suffix and mail it to @code{classpath@@gnu.org}. - -@comment ---------------------------------------------------------------------- - -@node Message Formats, , Language Resources, I18N Issues -@comment node-name, next, previous, up -@section Message formats - -If you open any of the @file{messages.properties} described in the previous section, you may see properties that look like so: - -@example -Command.67=Issuer: @{0@} -Command.68=Serial number: @{0,number@} -Command.69=Valid from: @{0,date,full@} - @{0,time,full@} -Command.70=\ \ \ \ \ until: @{0,date,full@} - @{0,time,full@} -@end example - -These are @i{Message Formats} used by the tools to customize a text string that will then be used either as a prompt for User input or as output. - -If you are translating a @file{messages.properties} be careful not to alter text between curly braces. - -@comment ---------------------------------------------------------------------- - -@bye diff --git a/libjava/classpath/doc/vmintegration.texinfo b/libjava/classpath/doc/vmintegration.texinfo deleted file mode 100644 index 6d59b5d..0000000 --- a/libjava/classpath/doc/vmintegration.texinfo +++ /dev/null @@ -1,1980 +0,0 @@ -\input texinfo @c -*-texinfo-*- - -@c %**start of header -@setfilename vmintegration.info -@settitle GNU Classpath VM Integration Guide -@c %**end of header - -@setchapternewpage off - -@ifinfo -This file contains important information you will need to know if you -are going to write an interface between GNU Classpath and a Virtual -Machine. - -Copyright (C) 1998-2002, 2004, 2005, 2006 Free Software Foundation, Inc. - -@ifnotplaintext -@dircategory GNU Libraries -@direntry -* VM Integration: (vmintegration). GNU Classpath VM Integration Guide -@end direntry -@end ifnotplaintext -@end ifinfo - -@titlepage -@title GNU Classpath VM Integration Guide -@author John Keiser -@author C. Brian Jones -@author Mark Wielaard - -@page -@vskip 0pt plus 1filll -Copyright @copyright{} 1998-2002 Free Software Foundation, Inc. -@sp 2 -Permission is granted to make and distribute verbatim copies of -this document provided the copyright notice and this permission notice -are preserved on all copies. - -Permission is granted to copy and distribute modified versions of this -document under the conditions for verbatim copying, provided that the -entire resulting derived work is distributed under the terms of a -permission notice identical to this one. - -Permission is granted to copy and distribute translations of this manual -into another language, under the above conditions for modified versions, -except that this permission notice may be stated in a translation -approved by the Free Software Foundation. - -@end titlepage - -@ifinfo -@node Top, Introduction, (dir), (dir) -@top GNU Classpath Hacker's Guide - -This file contains important information you will need to know if you -are going to write an interface between GNU Classpath and a Virtual -Machine. - -This document is incomplete, as we are still in alpha with the interface. - -@end ifinfo - -@menu -* Introduction:: An introduction to the Classpath project -* Initialization:: Initializing the classes -* Classpath Hooks:: Hooks from Classpath to the VM -* VM Hooks:: Hooks from the underlying VM to Classpath -* JNI Implementation:: Hooking the VM to jni.h -* JVMTI Implementation:: Hooking the VM to jvmti.h -* Miscellaneous VM Requirements:: -@end menu - -@node Introduction, Initialization, Top, Top -@comment node-name, next, previous, up -@chapter Introduction - -The Classpath Project's ambition to be a 100% clean room implementation -of the standard Java class libraries cannot be fulfilled without some -level of integration with the Virtual Machine, the underlying machinery -that actually runs Java. - -There are several VMs out there, here is a small list. - -@itemize @bullet -@item @uref{http://www.hungry.com/old-hungry/products/japhar/,Japhar} -Japhar was the first VM to use GNU Classpath. Today you can see that -sort of relationship in the source tree which denotes several Japhar -specific files as a reference implementation of those pieces. This VM -has been primarily tested against Linux and lacks garbage collections, a -JIT, and suffers recently from slow development. - -@item @uref{http://www.intel.com/research/mrl/orp/,Intel's Open Runtime Platform} -Intel surprised us not long ago with the release of this rather advanced -VM that uses GNU Classpath for a set of class libraries and works on -Linux and Windows 2000. As of June, 2004, it does not appear that ORP -is under active development. - -@item @uref{http://www.sablevm.org/,SableVM} -SableVM is a robust, extremely portable, efficient, and -specifications-compliant Java Virtual Machine that aims to be easy to -maintain and to extend. It features a state-of-the-art, efficient -interpreter engine. Its source code is very accessible and easy to -understand, and has many robustness features that have been the object -of careful design. - -@item @uref{http://www.kaffe.org,Kaffe} -Kaffe is an advanced VM and together with its own class libraries -provides a Java 1.1 compatible environment. - -@item @uref{http://www.mozilla.org/projects/ef,Electrical Fire} -The Electrical File VM continues to be listed as a Mozilla project -though development has been somewhat quiet. A number of concepts from -EF were expected at one point to be rolled into Japhar, but that -development has not occurred as of yet. - -@item @uref{http://latte.snu.ac.kr/,LaTTe} -This VM project so far supports only Sun UltraSparc processors using the -proprietary Solaris 2.5.1 or higher operating system. LaTTe was derived -from Kaffe but claims a number of improvements. - -@item @uref{http://gcc.gnu.org/java/,GNU Compiler for Java (GCJ)} -This is a portable, optimizing, ahead-of-time compiler for the Java -Programming Language. It can compile Java source code directly to native -machine code, Java source code to Java bytecode (class files), and Java -bytecode to native machine code. Compiled applications are linked with the -GCJ runtime, libgcj which is based on the GNU Classpath code, which provides -the core class libraries, a garbage collector, and a bytecode interpreter. -libgcj can dynamically load and interpret class files, resulting in mixed -compiled/interpreted applications. -GCJ is part of the GNU Compiler Collection (@uref{http://gcc.gnu.org/,GCC}). -On March 6 2000 the libgcj and GNU Classpath projects were officially merged -and there is active work on merging all the classes between the projects. -Licensed under GPL+exception, just as GNU Classpath is. - -@item @uref{http://kissme.sourceforge.net/,Kissme} -This is a free Java Virtual Machine that is being developed on GNU/Linux -and can run console Java applications. Kissme also provides support for -orthogonally persistent Java. -@c I don't know what ``orthogonally persistent Java'' is, and I bet -@c there are other people don't know either. -- Steve Augart, 4 June 2004 - -@item @uref{http://jamvm.sourceforge.net/,JamVM} -A simple, small bytecode interpreter that works out-of-the-box with -pure GNU Classpath; it is emerging as the preferred platform for -quickly testing a new build of GNU Classpath. Licensed under the GPL. - -@item @uref{http://jikesrvm.sourceforge.net/,Jikes RVM} -A free runtime environment for Java, written in Java. Works -out-of-the-box with pure GNU Classpath. Features an optimizing JIT. -Runs on the x86 and PowerPC architectures, on the AIX, Linux, and Mac -OS/X operating systems. Licensed under the CPL (Common Public -License). Extensively documented. Actively developed as of June, -2004. - -@end itemize - -In the past integration efforts were focused mainly on Japhar with an eye -towards getting Electrical Fire to work. Most information contained in -this document is gleaned from these efforts. Recently more work has been -done on getting gcj, orp and kissme to work out of the box with GNU Classpath -but there is much to do before that becomes a reality. - - -@node Initialization, Classpath Hooks, Introduction, Top -@comment node-name, next, previous, up -@chapter Initialization - -The order of initialization, as far as I can tell, doesn't matter just -yet. However, when we move to 1.2 support, it probably will matter, so -we'll have a note in here at that time. - -The initialization order is currently documented in the -@file{Runtime.java} source file. - -@node Classpath Hooks, VM Hooks, Initialization, Top -@comment node-name, next, previous, up -@chapter Classpath Hooks - -The primary method of interaction between Classpath and the VM is via -the helper classes, which are named after the relevant core library -class, but include an additional `VM' prefix. The library classes from -Classpath call out to these to get certain VM-specific dirty work done. -A reference copy of each VM class exists. The majority consist of a -series of static methods, some of which are simply declared -@code{native}, and some which provide a default implementation. VMs may -either use these as is, or create their own local variations. When -using the default implementations, the VM is responsible for -implementing any of the code marked as @code{native} which corresponds -to functionality they wish their VM to provide. When using their own -versions of the classes, VM implementors may choose to change the mix of -native and non-native methods from that below, so as to best suit their -implementation. - -@menu -* java.lang:: -* gnu.classpath:: -* java.util:: -* java.io:: -* java.security:: -* java.net:: -* java.nio:: -* java.nio.channels:: -* gnu.java.nio:: -* java.lang.reflect:: -* gnu.java.lang:: -* gnu.java.lang.management:: -* java.lang.management:: -* Classpath Callbacks:: -@end menu - -@node java.lang, gnu.classpath, Classpath Hooks, Classpath Hooks -@comment node-name, next, previous, up - -@section @code{java.lang} - -@code{java.lang} is the core Java package, being imported automatically by all -classes. It includes basic classes as @code{Object} and @code{String}. -A VM must implement at least some parts of this package in order to -become operable. - -@menu -* java.lang.VMClass:: -* java.lang.VMObject:: -* java.lang.VMClassLoader:: -* java.lang.VMSystem:: -* java.lang.VMThrowable:: -* java.lang.VMCompiler:: -* java.lang.VMDouble:: -* java.lang.VMFloat:: -* java.lang.VMProcess:: -* java.lang.VMRuntime:: -* java.lang.VMString:: -* java.lang.VMThread:: -* java.lang.VMMath:: -@end menu - -@node java.lang.VMClass, java.lang.VMObject ,java.lang,java.lang -@subsection @code{java.lang.VMClass} - -The core class, @code{java.lang.Class}, and the corresponding VM class, -@code{java.lang.VMClass}, provide two main functions within GNU Classpath. - -@enumerate -@item For basic VM operation, @code{java.lang.Class} provides the link between -the Java-based representation of a class it embodies and the VM's own -internal structure for a class. @xref{VM Hooks}. - -@item As far as the user is concerned, the main function of -@code{java.lang.Class} is as an entry point to the reflection -facilities, and so it also provides this functionality, backed by the -VM class. -@end enumerate - -This VM class lists the following methods, organized by the version of the -Java specification in which they occur. All are @code{native}, unless -otherwise specified, and pertain to reflection. As a result, the VM only -needs to implement these methods in order to provide reflection support, -and then only to the degree required. - -@itemize @bullet -@item 1.0 -@itemize @bullet -@item @code{isInterface(Class)} -- This is simply a property test, and matches -the presence of an appropriate flag within the class file. -@item @code{getName(Class)} -- Returns the fully-qualified name of the class. -@item @code{getSuperclass(Class)} -- Returns a @code{Class} instance which -represents the superclass. Again, the class file contains an element directly -relating to this. @code{null} is returned for primitives, interfaces and -@code{Object}. -@item @code{getInterfaces(Class)} -- Same as the above, but the implemented -or extended interfaces rather than the superclass. An empty array should -be returned, rather than @code{null}. -@item @code{getDeclaredClasses(Class,boolean)} -- Returns the internal classes -this instance declares directly. The flag determines whether or not the -VM should filter out non-public classes. -@item @code{getDeclaredFields(Class,boolean)} -- The same for fields. -@item @code{getDeclaredMethods(Class,boolean)} -- And for methods. -@item @code{getDeclaredConstructors(Class,boolean)} -- And constructors. -@item @code{getClassLoader(Class)} -- Returns the @code{ClassLoader} instance -which is responsible for the specified class. -@item @code{forName(String, boolean, ClassLoader)} -- The VM should create a -@code{Class} instance corresponding to the named class. As noted in -@ref{VM Hooks}, the internal content of the instance is the -responsibility of the VM. The supplied class loader is recorded as that -which loaded the class, and the boolean specifies whether or not to -run the class initializer. -@item @code{isArray(Class)} -- Another property test, corresponding to a -class file flag. -@item @code{initialize(Class)} -- The VM should initialize the class fully, -if it has not already done so. -@item @code{loadArrayClass(String,ClassLoader)} -- This is called if -@code{forName} returns @code{null} and the string specifies an array class. -The specified array class should be loaded with the supplied class loader. -@item @code{throwException(Throwable)} -- The VM should throw the supplied -checked exception, without declaring it. -@end itemize -@item 1.1 -@itemize @bullet -@item @code{isInstance(Class,Object)} -- This is a reflection-based equivalent -of the @code{instanceof} operator. -@item @code{isAssignableFrom(Class,Class)} -- Mainly a shorthand for the above, -removing the need to create an instance to test assignability. -@item @code{isPrimitive(Class)} -- Returns true if this class is simply -a representation of one of the primitive types: @code{boolean}, @code{byte}, -@code{char}, @code{short}, @code{int}, @code{long}, @code{float}, -@code{double} and @code{void}. -@item @code{getComponentType(Class)} -- Produces a @code{Class} instance which -represents the type of the members of the array the class instance represents. -Classes which don't represent an array type return @code{null}. -@item @code{getModifiers(Class,boolean)} -- Returns an integer which encodes -the class' modifiers, such as @code{public}. Again, this relates to -information stored in the class file. -@item @code{getDeclaringClass(Class)} -- Returns the class that declared -an inner or member class, or @code{null} if the instance refers to a top-level -class. -@end itemize -@item 1.5 -@itemize @bullet -@item @code{isSynthetic(Class)} -- Returns true if the flags for this class -mark it as synthetic. -@item @code{isAnnotation(Class)} -- Returns true if the flags for this class -mark it as an annotation. -@item @code{isEnum(Class)} -- Returns true if the flags for this class -mark it as an enumeration. -@item @code{getSimpleName(Class)} -- Returns the simple name of the class. -A default implementation is provided, but a more efficient version may instead -be provided by the VM. -@item @code{getCanonicalName(Class)} -- Returns the canonical name of the -class. A default implementation is provided, but a more efficient -version may instead be provided by the VM. -@item @code{getEnclosingClass(Class)} -- Returns the immediately enclosing -class (null for a top-level class). -@item @code{getEnclosingConstructor(Class)} -- Returns the constructor -which immediately encloses the supplied class. -@item @code{getEnclosingMethod(Class)} -- Returns the method -which immediately encloses the supplied class. -@item @code{getClassSignature(Class)} -- Returns the generic signature of -the class or null if there isn't one. -@item @code{isAnonymousClass(Class)} -- Returns true if the class is an -anonymous class. -@item @code{isLocalClass(Class)} -- Returns true if the class is an -local class. -@item @code{isMemberClass(Class)} -- Returns true if the class is an -member class. -@end itemize -@end itemize - -@node java.lang.VMObject, java.lang.VMClassLoader, java.lang.VMClass, java.lang -@subsection @code{java.lang.VMObject} - -@code{VMObject} is the bridge between the low level @code{Object} -facilities such as making a clone, getting the class of the object and -the wait/notify semantics. This is accomplished using the following -@code{native} methods. - -@itemize @bullet -@item @code{getClass(Object)} -- Returns the @code{Class} instance for the -object. @code{Class} objects are produced by the VM, as described in -@ref{VM Hooks}. -@item @code{clone(Cloneable)} -- The VM should produce a low-level clone of the -specified object, creating a field-by-field shallow copy of the original. -The only difference between the two is that the new object should still be -@code{finalizable}, even if the original is not. -@item @code{notify(Object)} -- The VM should choose one of the threads waiting -for a lock on the specified object arbitrarily, and wake it. If the current -thread does not currently hold the lock on the object, then an -@code{IllegalMonitorStateException} should be thrown. -@item @code{notifyAll(Object)} -- Same as the above, but all threads are -awakened. -@item @code{wait(Object,long,int)} -- The VM should set the current thread -into a waiting state, which persists until it receives a notify signal or the -specified time (in milliseconds and nanoseconds) is exceeded. The nanoseconds -restriction may be ignored if such granularity is not available, and a -@code{IllegalMonitorStateException} should be thrown if the current thread -doesn't own the object. -@end itemize - -@node java.lang.VMClassLoader, java.lang.VMSystem, java.lang.VMObject, java.lang -@subsection @code{java.lang.VMClassLoader} -@code{VMClassLoader} provides methods for defining and resolving core and -primitive classes, as well as handling resources, packages and assertions. -The class is a mixture of @code{native} methods and Java-based -implementations, with some of the latter being @emph{stubs}. - -@itemize @bullet -@item Native Methods -@itemize @bullet -@item @code{defineClass(ClassLoader,String,byte[],int,int,ProtectionDomain)} --- The VM should create a @code{Class} instance from the supplied byte array. -@item @code{resolveClass(Class)} -- Resolve references to other classes in the -supplied class. -@item @code{loadClass(name,boolean)} -- Load a class using the bootstrap -loader. -@item @code{getPrimitiveClass(char)} -- The VM should provide a @code{Class} -implementation for one of the primitive classes. The supplied character -matches the JNI code for the primitive class e.g. `B' for byte and -`Z' for boolean. -@end itemize -@item Java Methods -@itemize @bullet -@item @code{getResource(String)} -- The default implementation calls -@code{getResources} and returns the first element in the returned enumeration, -or @code{null} if there are no elements. -@item @code{getResources(String)} -- By default, this compiles a list of -URLs via the boot class path. Any matching files within a zip file are added, -and directories on the boot class path are automatically converted to file -URLs that refer to join the directory with the resource name (whether or not -it actually exists). -@item @code{getPackage(String)} -- Always returns null, which may be suitable -if the VM does not wish to return a @code{Package} implementation. Otherwise, -it may be necessary to make this a @code{native} method. -@item @code{getPackages()} -- As with the last, a default stub implementation -exists (returning an empty array) which may be replaced if support is -required. -@item @code{defaultAssertionStatus()} -- A stub which can be implemented -by VMs providing assertion support. At present, it always returns @code{true}. -@item @code{packageAssertionStatus()} -- Much the same status as the above. -The method should return a map converting package names to boolean status -values. The stub implementation provides an empty map. -@item @code{classAssertionStatus()} -- Same as the last, but for classes. -@item @code{getSystemClassLoader()} -- The default calls @code{ClassLoader} -to create a new auxillary class loader with a system and extension class -loader. The VM may wish to replace it if it wishes to supply its own custom -system class loader. -@end itemize -@end itemize -@node java.lang.VMSystem, java.lang.VMThrowable, java.lang.VMClassLoader, java.lang -@subsection @code{java.lang.VMSystem} -@code{VMSystem} handles the default I/O streams, provides access to the -system clock and environment variables and provides methods for -@code{System.arraycopy} and the @code{identityHashCode} of an -@code{Object}. It consists of @code{native} methods, but the default -implementation also provides some helper methods to simplify stream -creation. - -@itemize @bullet -@item Native Methods -@itemize @bullet -@item @code{arraycopy(Object,int,Object,int,int)} -- The VM should copy -a specified number of array objects from one array to another, with -appropriate checks for compatible typing, available elements and space. -The VM should be able to perform this more efficiently using native code -and direct memory manipulation than would have been achieved by using Java. -@item @code{identityHashCode(Object)} -- This is the hashcode for -@code{Object}, which relates to the actual location of the object in memory. -@item @code{setIn(InputStream)} -- Set the system input stream. -@item @code{setOut(PrintStream)} -- Set the system output stream. -@item @code{setErr(PrintStream)} -- Set the system error stream. -@item @code{currentTimeMillis()} -- Gets the system time in milliseconds. -@item @code{getenv(String)} -- Returns the value of the specified environment -variable. -@item @code{getenv()} -- Returns a list of `name=value' pairs which correspond -to the environment variables. -@end itemize -@item Java Methods -@itemize @bullet -@item @code{makeStandardInputStream()} -- Helps provide the functionality of -@code{System.in} by wrapping the appropriate file descriptor in a -buffered file input stream. VMs may choose to create the stream from -the descriptor differently rather than using this method. -@item @code{makeStandardOutputStream()} -- Helps provide the functionality of -@code{System.out} by wrapping the appropriate file descriptor in a buffered -file output stream. VMs may choose to create the stream from the descriptor -differently rather than using this method. -@item @code{makeStandardErrorStream()} -- Helps provide the functionality of -@code{System.err} by wrapping the appropriate file descriptor in a buffered -file output stream. VMs may choose to create the stream from the descriptor -differently rather than using this method. -@end itemize -@end itemize - -Classpath also provides native implementations of - -@itemize @bullet -@item @code{setIn(InputStream)} -@item @code{setOut(PrintStream)} -@item @code{setErr(PrintStream)} -@item @code{currentTimeMillis()} -@item @code{getenv(String)} -@end itemize - -making a VM implementation optional. - -@node java.lang.VMThrowable, java.lang.VMCompiler, java.lang.VMSystem, java.lang -@subsection @code{java.lang.VMThrowable} -@code{VMThrowable} is used to hold the VM state of a throwable, created either -when a @code{Throwable} is created or the @code{fillInStackTrace()} method is -called (i.e. when the actual stack trace is needed, as a lot of exceptions are -never actually used). The actual class has two @code{native} methods, -one (@code{fillInStackTrace()}) being a method of the class used to obtain -instances, and the other an instance method, @code{getStackTrace()}. -@itemize @bullet -@item @code{fillInStackTrace(Throwable)} -- The VM should return the current -execution state of the @code{Throwable} in the form of a @code{VMThrowable} -instance. The VM may also return @code{null} if it does not support this -functionality. -@item @code{getStackTrace()} -- This is used to create a real -@code{StackTraceElement} array for the exception, using the state data -stored during creation of the instance. -@end itemize - -@node java.lang.VMCompiler, java.lang.VMDouble, java.lang.VMThrowable, java.lang -@subsection @code{java.lang.VMCompiler} - -@code{VMCompiler} provides an interface for VMs which wish to provide -JIT compilation support. The default implementation is simply a series -of stubs. The property, @code{java.compiler}, should point to a library -containing the function @code{java_lang_Compiler_start()} if such support -is to be provided. - -@itemize @bullet -@item @code{compileClass(Class)} -- Invoke the compiler to compile the specific -class, returning @code{true} if successful. -@item @code{compileClasses(String)} -- The compiler should compile the classes -matching the specified string, again returning @code{true} on success. -@item @code{command(Object)} -- The object represents a command given to the -compiler, and is specific to the compiler implementation. -@item @code{enable} -- Enable the operation of the compiler. -@item @code{disable} -- Disable compiler operation. -@end itemize - -@node java.lang.VMDouble, java.lang.VMFloat, java.lang.VMCompiler, java.lang -@subsection @code{java.lang.VMDouble} - -@code{VMDouble} provides native support for the conversion and parsing -of doubles. - -@itemize @bullet -@item @code{doubleToLongBits(double)} -- Converts the double to the IEEE 754 -bit layout, collapsing NaNs to @code{0x7ff8000000000000L}. -@item @code{doubleToRawLongBits(double)} -- Same as the above, but preserves -NaNs. -@item @code{longBitsToDouble(long)} -- This is the inverse of the last method, -preserving NaNs so that the output of one can be fed into the other without -data loss. -@item @code{toString(double,boolean)} -- Converts the double to a string, -giving a shorter value if the flag @code{isFloat} is @code{true}, indicating -that the conversion was requested by @code{java.lang.Float} rather than -@code{java.lang.Double}. -@item @code{initIDs} -- Used by JNI-based solutions to initialize the cache -of the static field IDs. The default @code{VMDouble} implementation has a -static initializer which loads the JNI library and calls this method. -@item @code{parseDouble} -- Turn the string into a usable double value. -@end itemize - -Classpath provides native implementations of all these, making VM -implementation optional. - -@node java.lang.VMFloat, java.lang.VMProcess, java.lang.VMDouble, java.lang -@subsection @code{java.lang.VMFloat} - -@code{VMFloat} provides native support for the conversion of floats. - -@itemize @bullet -@item @code{floatToIntBits(float)} -- Converts the float to the IEEE 754 -bit layout, collapsing NaNs to @code{0x7fc00000}. -@item @code{floatToRawIntBits(float)} -- Same as the above, but preserves -NaNs. -@item @code{intBitsToFloat(int)} -- This is the inverse of the last method, -preserving NaNs so that the output of one can be fed into the other without -data loss. -@end itemize - -Classpath provides native implementations of all these, making VM -implementation optional. - -@node java.lang.VMProcess, java.lang.VMRuntime, java.lang.VMFloat, java.lang -@subsection @code{java.lang.VMProcess} - -@code{VMProcess} handles the execution of external processes. In the -default implementation, threads are spawned and reaped by @code{ProcessThread}. -A constructor creates a new @code{VMProcess}, which extends rather than -complements @code{Process}, using an array of arguments, an array of -environment variables and a working directory. The instance maintains -system input, output and error streams linked to the external process. -Three @code{native} methods are used, and implementations are provided -for all three by Classpath, making VM implementation optional. These use -the POSIX functions, @code{fork()}, @code{waitpid()} and @code{kill()}. - -@itemize @bullet -@item @code{nativeSpawn(String[],String[],File,boolean)} -- The VM should -create a new process which uses the specified command-line arguments, -environment variables and working directory. Unlike the other two -methods, this method is linked to an instance, and must call -@code{setProcessInfo()} with the results before returning. The -boolean argument maps to the @code{redirectErrorStream} property of -@code{java.lang.ProcessBuilder}. When true, the output and error streams -are merged. -@item @code{nativeReap()} -- This is called to perform a reap of any -zombie processes, and should not block, instead returning a boolean as to -whether reaping actually took place. -@item @code{nativeKill(long)} -- The VM should terminate the specified PID. -@end itemize - -@node java.lang.VMRuntime, java.lang.VMString, java.lang.VMProcess, java.lang -@subsection @code{java.lang.VMRuntime} - -The @code{VMRuntime} class provides a series of native methods -which divulge information about the runtime or invoke certain -operations. This includes retrieving the amount of available memory, -and scheduling the garbage collector. There are two exceptions: the -@code{enableShutdownHooks} method, which allows the VM to put in its own -shutdown hooks when @code{Runtime.addShutdownHook()} is first invoked, -and @code{exec(String[],String[],File)} which spawns an external process. -These are Java-based static methods instead. The first is simply a stub by -default, while the second simply links to the functionality of -@code{VMProcess} (and should be changed if a different @code{Process} -implementation is used). - -@itemize @bullet -@item @code{availableProcessors()} -- Returns the number of processors -available to the VM. -@item @code{freeMemory()} -- Returns the amount of memory the VM has available -on the heap for allocating. -@item @code{totalMemory()} -- Returns the size of the heap. -@item @code{maxMemory()} -- Returns the maximum memory block the VM will -attempt to allocate. May be simply @code{Long.MAX_VALUE} (8 exabytes!) -@item @code{gc()} -- Allows users to explicitly invoke the garbage collector. -This is a suggestion to the VM, rather than a command, and the garbage -collector should run anyway @emph{without} it being invoked. -@item @code{runFinalization()} -- Like the above, but related to the -finalilzation of objects rather than the garbage collector. -@item @code{runFinalizationForExit()} -- Called immediately prior to VM -shutdown in order to finalize all objects (including `live' ones) -@item @code{traceInstructions(boolean)} -- This turns on and off the optional -VM functionality of printing a trace of executed bytecode instructions. -@item @code{traceMethodCalls(boolean)} -- This turns on and off the optional -VM functionality of printing a trace of methods called. -@item @code{runFinalizersOnExit(boolean)} -- A toggleable setting for -running the finalization process at exit. -@item @code{exit(int)} -- The VM should shutdown with the specified exit code. -@item @code{nativeLoad(String,ClassLoader)} -- Attempts to load a file, -returning an integer which is non-zero for success. Nothing happens if the -file has already been loaded. -@item @code{mapLibraryName(String)} -- The VM should map the system-independent -library name supplied to the platform-dependent equivalent (e.g. a @code{.so} -or @code{.dll} file) -@end itemize - -@node java.lang.VMString, java.lang.VMThread, java.lang.VMRuntime, java.lang -@subsection @code{java.lang.VMString} -@code{VMString} is responsible for handling interned strings. If two strings -are equal (using the @code{equals()} method), then the results of calling -the @code{intern()} method on each of them makes them equal -(using @code{==}). Thus, the same string object is always returned by -@code{intern} if the two strings are equal. The default implementation -is Java-based and implements @code{intern(String)} by maintaining a -@code{WeakHashMap} which links the strings to their @code{WeakReference}. -A new mapping is created for each new string being @code{intern}ed. -A VM may implement this differently by implementing this method, -which is @code{static} and the only one in @code{VMString}. - -@node java.lang.VMThread, java.lang.VMMath, java.lang.VMString, java.lang -@subsection @code{java.lang.VMThread} - -@code{VMThread} provides the link between Java's threads and the platform -threading support. A @code{VMThread} is created via a private constructor -and linked to a @code{Thread} instance. This occurs when the @code{Thread} -instance is started by the static @code{create(Thread,long)} method (the second -argument requests a certain stack size, usually zero). The thread itself is -executed via the @code{run()} method, which handles any problems with the -running of the thread and its eventual death. - -@code{VMThread} provides the following accessors and mutators for accessing -the thread state via @code{VMThread}, - -@itemize @bullet -@item @code{getName()} -@item @code{setName(String)} -@item @code{getPriority()} -@item @code{setPriotity(int)} -@item @code{isDaemon()} -@end itemize - -all of which refer to the @code{Thread} instance. @code{setPriority(int)} also -calls the appropriate native method. @code{stop(Throwable)} similarly wraps -a native method, merely adding in a check for the state of the thread. - -The default implementation also provides Java-based implementations of -@code{join(long,int)}, @code{sleep(long,int)} and -@code{holdsLock(Object)}. @code{join} and @code{sleep} simply wait for -the appropriate amount of time, with @code{join} additionally waiting -for the thread instance to become @code{null}. @code{holdsLock} simply -checks if an object is locked by the current thread by trying to invoke -the @code{notify} method, and catching the failing exception if this is -not the case. - -The remainder of the class is a series of @code{native} methods, some of -which are mandatory for VM implementation and others which provide optional -or deprecated functionality. - -@itemize @bullet -@item Mandatory Instance Methods -@itemize @bullet -@item @code{start(long)} -- The VM should create the native thread and start -it running using the @code{run} method of the @code{VMThread} instance on -which this method is called. -@item @code{interrupt()} -- The VM should interrupt the running thread and -throw an appropriate exception. -@item @code{isInterrupted()} -- Checks the interrupted state of the thread. -@item @code{suspend()} -- The thread should be suspended until resumed. -@item @code{resume()} -- The thread should be resumed from its suspended state. -This pair of methods are deprecated, due to the possibility of a deadlock -occuring when a thread with locks is suspended. -@item @code{nativeSetPriority(int)} -- Called by @code{setPriority} -to allow the setting to flow down to the native thread. -@item @code{nativeStop(Throwable)} -- The VM should stop the thread abnormally -and throw the specified exception. This is clearly deprecated, due to the -ambiguous state an abruptly-stopped thread may leave. -@item @code{getState()} -- Returns the VM's impression of the current state -of the thread. The applicable states are supplied by the @code{State} -enumeration in @code{java.lang.Thread}. -@end itemize -@item Mandatory Class Methods -@itemize @bullet -@item @code{currentThread()} -- Return a reference to the thread currently -being executed. -@item @code{yield()} -- The VM should allow some other thread to run. -The current thread maintains its locks even though it stops executing for -the time being. -@item @code{interrupted()} -- A shortcut to obtaining the interrupted state -of the current thread. -@end itemize -@item Other Methods -@itemize @bullet -@item @code{countStackFrames()} -- Returns a count of the number of stack -frames in the thread. This depends on the deprecated method @code{suspend()} -having returned true, and is thus deprecated as a result. -@end itemize -@end itemize - -@node java.lang.VMMath,, java.lang.VMThread, java.lang -@subsection @code{java.lang.VMMath} - -The @code{VMMath} class provides a series of native methods -for some of the mathematical functions present in @code{java.lang.Math}. -Classpath provides a default implementation of these which maps the -functions to those provided by @code{fdlibm}. VM implementors are welcome -to replace this with more efficent implementations, as long as the accuracy -contract of these methods, specified in @code{java.lang.Math}, is maintained. - -@itemize @bullet -@item 1.0 -@itemize @bullet -@item @code{sin(double)} -- Returns the sine value for the given angle. -@item @code{cos(double)} -- Returns the cosine value for the given angle. -@item @code{tan(double)} -- Returns the tangent value for the given angle. -@item @code{asin(double)} -- Returns the arc sine value for the given angle. -@item @code{acos(double)} -- Returns the arc cosine value for the given angle. -@item @code{atan(double)} -- Returns the arc tangent value for the given angle. -@item @code{atan2(double,double)} -- Returns the arc tangent of the ratio of -the two arguments. -@item @code{exp(double)} -- Returns the exponent raised to the given power. -@item @code{log(double)} -- Returns the natural logarithm for the given value. -@item @code{sqrt(double)} -- Returns the square root of the value. -@item @code{pow(double,double)} -- Returns x to the power of y. -@item @code{IEEEremainder(double,double)} -- Returns the IEEE 754 remainder -for the two values. -@item @code{ceil(double)} -- Returns the nearest integer >= the value. -@item @code{floor(double)} -- Returns the nearest integer <= the value. -@item @code{rint(double)} -- Returns the nearest integer or the even one -if the distance between the two is equal. -@end itemize -@item 1.5 -@itemize @bullet -@item @code{cbrt(double)} -- Returns the cube root of the value. -@item @code{cosh(double)} -- Returns the hyperbolic cosine value for the given -angle. -@item @code{expm1(double)} -- Returns the exponent of the value minus one. -@item @code{hypot(double,double)} -- Returns the hypotenuse corresponding to -x and y. -@item @code{log10(double)} -- Returns the base 10 logarithm of the given value. -@item @code{log1p(double)} -- Returns the natural logarithm of the value plus -one. -@item @code{sinh(double)} -- Returns the hyperbolic sine value for the given -angle. -@item @code{tanh(double)} -- Returns the hyperbolic tangent value for the given angle. -@end itemize -@end itemize - -@node gnu.classpath, java.util, java.lang, Classpath Hooks -@section @code{gnu.classpath} - -The @code{gnu.classpath} package provides Classpath-specific functionality, -primarily relating to the features in @code{java.lang}. At present, this -includes the context of a class (the stack) and the system properties. - -@menu -* gnu.classpath.VMStackWalker:: -* gnu.classpath.VMSystemProperties:: -* gnu.classpath.Unsafe:: -@end menu - -@node gnu.classpath.VMStackWalker,gnu.classpath.VMSystemProperties,gnu.classpath,gnu.classpath -@subsection @code{gnu.classpath.VMStackWalker} - -@code{VMStackWalker} provides access to the class context or stack. The -default implementation consists of a @code{native} @code{static} method, -@code{getClassContext()}, which obtains the class context, and two helper -methods which obtain the calling class (the 3rd element in the context array) -and its class loader, respectively. - -@itemize @bullet -@item @code{getClassContext()} -- The VM should return an array of -@code{Class} objects, each of which relates to the method currently being -executed at that point on the stack. Thus, the first item (index 0) is the -class that contains this method. -@item @code{getCallingClass()} -- A Java-based helper method which returns -the @code{Class} object which contains the method that called the method -accessing @code{getCallingClass()}. -@item @code{getCallingClassLoader()} -- Like the last, but returning the class -loader of the class. -@end itemize - -@node gnu.classpath.VMSystemProperties,gnu.classpath.Unsafe,gnu.classpath.VMStackWalker,gnu.classpath -@subsection @code{gnu.classpath.VMSystemProperties} - -@code{VMSystemProperties} allows the VM to hook into the property creation -process, both before and after the system properties are added by GNU -Classpath. The default implementation assumes that the VM will add its -properties first, by making the pre-initialisation method @code{native}, -and that the Classpath properties may then be altered by a Java-based -post-initialisation method. - -As these methods are called as part of the bootstrap process, caution should -be used as to what classes are used, and properties should only be set -using @code{Properties.setProperty()}. Specifically, I/O classes should be -avoided at this early stage. - -@itemize @bullet -@item @code{preInit(Properties)} -- Allows the VM to add properties -@emph{before} the Classpath properties are added. The default implementation -includes a full list of properties that @emph{must} be added by the VM, but -additional VM-specific ones may also be added. -@item @code{postInit(Properties)} -- Same as the last, but called after the -Classpath properties have been added. The main purpose of this is to allow -the VM to alter the properties added by GNU Classpath to suit it. -@end itemize - -@node gnu.classpath.Unsafe,,gnu.classpath.VMSystemProperties,gnu.classpath -@subsection @code{gnu.classpath.Unsafe} - -The @code{Unsafe} class provides access to some low-level unsafe operations -as required by the addition of the java.util.concurrent classes. These -focus on direct memory access to the fields within the VM and providing -atomic update methods. - -@itemize @bullet -@item @code{objectFieldOffset(Field)} -- Provides the caller with the memory -offset of a particular field. -@item @code{compareAndSwap*(Object,long,*,*)} -- One of these methods is -provided for each of int, long and Object (hence the *s). The value of -a field pointed to by the given Object and offset is compared with the -first value and replaced with the second if they are the same. The reason -for this method is to make this change operation atomic. -@item @code{put/get*(Object,long,*)} -- These are like the last set of -methods, handling integers, longs and Objects, but the field is always -changed on a put. Different methods are provided for different semantics. -Ordered variants perform a lazy put, in that the change does not -immediately propogate to other threads, while the others provide -volatile or 'normal' semantics. -@item @code{arrayBaseOffset(Class)} and @code{arrayIndexScale(Class)} -- -These two methods allow an array class to be traversed by pointer -arithmetic, by gaining the address of the first element and then -scaling appropriately for the later ones. -@item @code{park(boolean,long)} and @code{unpark(Thread)} -- These methods -block and unblock threads respectively, with an optional timeout being -provided for the blocking. @code{unpark} is unsafe as the thread may have -been destroyed by native code. -@end itemize - -@node java.util, java.io, gnu.classpath, Classpath Hooks -@section java.util - -The @code{java.util} VM hooks provide links between the mix of functionality -present in that package, which includes collections, date and time handling -and parsing. At present, there is only one hook, which connects GNU Classpath -to the timezone information provided by the underlying platform. - -@menu -* java.util.VMTimeZone:: -@end menu - -@node java.util.VMTimeZone,,java.util,java.util -@subsection @code{java.util.VMTimeZone} - -@code{VMTimeZone} joins @code{TimeZone} to the platform timezone information -via the static method, @code{getDefaultTimeZoneId()}. The VM hook is -expected to return a @code{TimeZone} instance that represents the current -timezone in use by the platform. The default implementation provides -this functionality for POSIX or GNU-like systems, and VMs that want this -functionality can keep this implementation and implement the native -method, @code{getSystemTimeZoneId()}. This method is only called when -obtaining the timezone name from the @code{TZ} environment variable, -@code{/etc/timezone} and @code{/etc/localtime} all fail. This fallback -mechanism also means that a system which doesn't provide the above three -methods, but does provide a timezone in string form, can still use this -implementation. - -@node java.io, java.security, java.util, Classpath Hooks -@section java.io - -The @code{java.io} package is heavily reliant on access to the I/O facilities -of the underlying platform. As far as its VM hooks go, they provide two -areas of functionality to GNU Classpath, these being - -@itemize @bullet -@item File and directory queries and manipulation -@item Serialization of objects -@end itemize - -The first corresponds directly to most of the @code{File} class, while -the latter underlies the functionality provided by the -@code{ObjectInputStream} and @code{ObjectOutputStream}. More low-level I/O -is provided by @ref{java.nio}. - -@menu -* java.io.VMFile:: -* java.io.VMObjectInputStream:: -* java.io.VMObjectStreamClass:: -@end menu - -@node java.io.VMFile,java.io.VMObjectInputStream,java.io,java.io -@subsection @code{java.io.VMFile} - -@code{VMFile} allows GNU Classpath's @code{File} representations to -probe and modify the file system using the native functions of the -platform. The default implementation (which consists of both a -@code{VMFile} class and the native methods) is primarily UNIX-centric, -working with POSIX functions and assuming case-sensitive filenames, -without the restriction of the 8.3 format. It consists mainly of -@code{static} @code{native} methods, with a few Java helper methods. -The native methods represent the file as a string containing its path, -rather than using the object itself. - -@itemize @bullet -@item Native Methods -@itemize @bullet -@item @code{lastModified(String)} -- The native method should return a -@code{long} value that represents the last modified date of the file. -@item @code{setReadOnly(String)} -- Sets the file's permissions to read only, -in whichever way this is realised by the platform. -@item @code{create(String)} -- Create the named file. -@item @code{list(String)} -- The native method opens the named directory, -reads the contents and returns them as a Java @code{String} array. -@item @code{renameTo(String,String)} -- Renames the first file to the second. -@item @code{length(String)} -- Returns a @code{long} value representing -the file size. -@item @code{exists(String)} -- Tests for the existence of the named file -or directory. -@item @code{delete(String)} -- Deletes the file or directory. -@item @code{setLastModified(String,long)} -- Change the last modified time. -@item @code{mkdir(String)} -- Creates the named directory. -@item @code{isFile(String)} -- Tests that the named path references a file. -@item @code{canWrite(String)} -- Tests that the file can be written to. -This method is @code{synchronized}, so the object is locked during the check. -@item @code{canRead(String)} -- Complement of the last method. -@item @code{isDirectory(String)} -- Tests that the named path references -a directory. -@end itemize -@item Java Helper Methods -@itemize @bullet -@item @code{canWriteDirectory(File)} -- Checks that the directory can be -written to, by trying to create a temporary file in it. -@item @code{listRoots()} -- Returns the root of a GNU filesystem i.e. `/' -in an array. -@item @code{isHidden(String)} -- Checks whether the file starts with `.', -which is how files are hidden on UNIX-style systems. -@item @code{getName(String)} -- Pulls the actual filename from the end of -the path, by breaking off the characters after the last occurrence of the -platform's file separator. -@item @code{getCanonicalForm(String)} -- This converts a UNIX path to -its canonical form by removing the `.' and `..' sections that occur within. -@end itemize -@end itemize - -@node java.io.VMObjectInputStream,java.io.VMObjectStreamClass,java.io.VMFile,java.io -@subsection @code{java.io.VMObjectInputStream} - -This class consists of two methods which provide functionality used in -deserializing an object. @code{currentClassLoader()} provides the first -user-defined class loader from the class context -(@xref{gnu.classpath.VMStackWalker},) via a @code{PrivilegedAction}. -@code{allocateObject(Class,Class,Constructor)} is a @code{native} method -(a reference implementation is provided) which creates an object but -calls the constructor of another class, which is a superclass of the -object's class. - -@node java.io.VMObjectStreamClass,,java.io.VMObjectInputStream,java.io -@subsection @code{java.io.VMObjectStreamClass} - -@code{VMObjectStreamClass} is a series of @code{static} @code{native} -methods that provide some of the groundwork for @code{ObjectStreamClass} -and @code{ObjectStreamField}. @code{hasClassInitializer(Class)} works -with the former, and checks for the presence of a static initializer. -The remaining methods are of the form @code{setXXXNative(Field,Object,XXX)} -and support @code{ObjectStreamField}. One exists for each of the main types -(boolean, float, double, long, int, short, char, byte and object) and is used -to set the specified field in the supplied instance to the given value. - -A default implementation is provided for all of them, so a VM implementation -is optional. - -@node java.security, java.net, java.io, Classpath Hooks -@section java.security - -The @code{java.security} package provides support for Java's security -architecture. - -@menu -* java.security.VMAccessController:: -* java.security.VMSecureRandom:: -@end menu - -@node java.security.VMAccessController,java.security.VMSecureRandom,java.security,java.security -@subsection @code{java.security.VMAccessController} - -The @code{AccessController} is used to perform privileged actions. Its -hook class, @code{VMAccessController}, maintains the -@code{AccessControlContext} and the default implementation is purely -Java-based. The VM may choose to replace this with their own. -The methods in the reference version are as follows: - -@itemize @bullet -@item @code{pushContext(AccessControlContext)} -- Adds a new context to the -stack for the current thread. This is called before a privileged action -takes place. -@item @code{popContext()} -- Removes the top context from the stack. This -is performed after the privileged action takes place. -@item @code{getContext()} -- Either derives a context based on the -@code{ProtectionDomain}s of the call stack (see the next method) or returns -the top of the context stack. -@item @code{getStack()} -- Provides access to the call stack as a pair of -arrays of classes and method names. The actual implementation returns -an empty array, indicating that there are no permissions. -@end itemize - -@node java.security.VMSecureRandom,,java.security.VMAccessController,java.security -@subsection @code{java.security.VMSecureRandom} - -The @code{VMSecureRandom} class is used to provide access to -cryptographically secure random numbers. The default implementation -of the class runs eight threads that increment counters in a tight -loop, and XORs each counter to produce one byte of seed data. This is -not very efficient, and is not guaranteed to be random (the thread -scheduler is probably deterministic, after all). VM implementors -should provide a version of this class, which implements the method -@code{generateSeed(byte[],int,int)}, so that it fills the buffer using -a random seed from a system facility, such as a system entropy -gathering device or hardware random number generator. The parameters -are the usual set of buffer, offset and length and the method returns -the number of bytes actually generated, which may be less than that -requested. - -@node java.net, java.nio, java.security, Classpath Hooks -@section java.net - -The @code{java.net} package is heavily reliant on access to the networking -facilities of the underlying platform. The VM hooks provide information -about the available network interfaces, and access to lookup facilities -for network addresses. - -@menu -* java.net.VMInetAddress:: -* java.net.VMNetworkInterface:: -@end menu - -@node java.net.VMInetAddress,java.net.VMNetworkInterface,java.net,java.net -@subsection @code{java.net.VMInetAddress} - -@code{VMInetAddress} is a series of @code{static} @code{native} methods -which provide access to the platform's lookup facilities. All the methods -are implemented by GNU Classpath, making VM implementation optional, and -are as follows: - -@itemize @bullet -@item @code{getLocalHostname()} -- Wraps the @code{gethostname} function, and -falls back on `localhost'. -@item @code{lookupInaddrAny()} -- Returns the value of @code{INADDR_ANY}. -@item @code{getHostByAddr(byte[])} -- Looks up the hostname based on an IP -address. -@item @code{getHostByName(String)} -- The reverse of the last method, it -returns the IP addresses which the given host name resolves to. -@end itemize - -@node java.net.VMNetworkInterface,,java.net.VMInetAddress,java.net -@subsection @code{java.net.VMNetworkInterface} - -@code{VMNetworkInterface} currently consists of a single @code{static} -@code{native} method, @code{getInterfaces()}, which retrieves the -network interfaces available on the underlying platform as a @code{Vector}. -The current GNU Classpath implementation is a native stub. - -@node java.nio, java.nio.channels, java.net, Classpath Hooks -@section java.nio - -The @code{java.nio} package is part of the New I/O framework added in -Java 1.4. This splits I/O into the concepts of @emph{buffers}, -@emph{charsets}, @emph{channels} and @emph{selectors}, and -@code{java.nio} defines the buffer classes. As far as native and VM -code is concerned, the new package needs support for low-level efficient -buffer operations. - -@menu -* java.nio.VMDirectByteBuffer:: -@end menu - -@node java.nio.VMDirectByteBuffer,,java.nio,java.nio -@subsection @code{java.nio.VMDirectByteBuffer} - -A @code{ByteBuffer} maintains a buffer of bytes, and allows it to be -manipulated using primitive operations such as @code{get}, @code{put}, -@code{allocate} and @code{free}. A direct buffer avoids intermediate -copying, and uses native data which shouldn't be manipulated by a -garbage collector. The VM class consists of @code{static} @code{native} -methods, all of which are given default implementations by GNU -Classpath. - -@itemize @bullet -@item @code{init()} -- Creates an instance of an appropriate -@code{gnu.classpath.RawData} class. This class is not garbage -collected, is created natively and is used in the other methods to reference -the buffered data. -@item @code{allocate(int)} -- Allocates the memory for the buffer using -@code{malloc} and returns a reference to the @code{RawData} class. -@item @code{free(RawData)} -- Frees the memory used by the buffer. -@item @code{get(RawData,int)} -- Returns the data at the specified index. -@item @code{get(RawData,int,byte[],int,int)} -- Copies a section of the -data into a byte array using @code{memcpy}. -@item @code{put(RawData,int,byte)} -- Puts the given data in the buffer -at the specified index. -@item @code{adjustAddress(RawData,int)} -- Adjusts the pointer into the buffer. -@item @code{shiftDown(RawData,int,int,int)} -- Moves the content of the buffer -at an offset down to a new offset using @code{memmove}. -@end itemize - -@node java.nio.channels, gnu.java.nio, java.nio, Classpath Hooks -@section java.nio.channels - -Channels provide the data for the buffers with the New I/O packages. -For example, a channel may wrap a file or a socket. The VM hooks, -at the moment, simply allow the channels to be accessed by @code{java.io} -streams. - -@menu -* java.nio.channels.VMChannels:: -@end menu - -@node java.nio.channels.VMChannels,,java.nio.channels,java.nio.channels -@subsection @code{java.nio.channels.VMChannels} - -@code{VMChannels} provides the methods that create the channels or -streams. The default implementation is in pure Java and simply wraps -the channels in standard I/O classes from @code{java.io}. - -@itemize @bullet -@item @code{createStream(Class,Channel)} -- Creates a @code{FileChannel} -which wraps an instance of the specified stream class, created by reflection. -This method is private, and is used by the other two. -@item @code{newInputStream(ReadableByteChannel)} -- Wraps the channel -in a @code{FileInputStream}. -@item @code{newOutputStream(WritableByteChannel)} -- Wraps the channel -in a @code{FileOutputStream}. -@end itemize - -@node gnu.java.nio, java.lang.reflect, java.nio.channels, Classpath Hooks -@section gnu.java.nio - -The @code{gnu.java.nio} class provides Classpath implementations of the -interfaces provided by @code{java.nio}. The VM classes provide the native -support necessary to implement @emph{pipes} and @emph{selectors}. - -@menu -* gnu.java.nio.VMPipe:: -* gnu.java.nio.VMSelector:: -@end menu - -@node gnu.java.nio.VMPipe,gnu.java.nio.VMSelector,gnu.java.nio,gnu.java.nio -@subsection @code{gnu.java.nio.VMPipe} - -@code{VMPipe} provides the native functionality for a uni-directional pipe -between a source and a destination (sink) channel. It consists of one -@code{static} @code{native} method, @code{init(PipeImpl,SelectorProvider)}, -the reference implementation of which is currently a native stub. Ideally, -this should initialise the pipe at the native level. - -@node gnu.java.nio.VMSelector,,gnu.java.nio.VMPipe,gnu.java.nio -@subsection @code{gnu.java.nio.VMSelector} - -A @code{Selector} selects between multiple @code{SelectableChannel}s based -on their readiness and a key set. The VM hook for the Classpath implementation -of this is @code{VMSelector}, and this allows the actual @code{select()} -operation to be performed. This is represented by the @code{static} -@code{native} method, @code{select(int[],int[],int[],long)}, and a default -implementation of this is provided. - -@node java.lang.reflect, gnu.java.lang, gnu.java.nio, Classpath Hooks -@section @code{java.lang.reflect} -@code{java.lang.reflect} provides the interface to Java's reflection -facilities. Via reflection, programmers can obtain type information about -a particular instance at runtime or dynamically create new instances. - -@menu -* java.lang.reflect.VMArray:: -@end menu - -@node java.lang.reflect.VMArray,,,java.lang.reflect -@subsection @code{java.lang.reflect.VMArray} - -The @code{VMArray} class provides a hook, @code{createObjectArray}, -which the VM uses to generate a new non-primitive array of a -particular class and size. The default implementation simply passes -the job down to the standard JNI function, @code{NewObjectArray}. - -@node gnu.java.lang, gnu.java.lang.management, java.lang.reflect, Classpath Hooks -@section @code{gnu.java.lang} - -@code{gnu.java.lang} provides VM interfaces for the GNU -implementations of features in java.lang. Currently, this includes the -implementation of instrumentation. - -@menu -* gnu.java.lang.VMInstrumentationImpl:: -@end menu - -@node gnu.java.lang.VMInstrumentationImpl,,,gnu.java.lang -@subsection @code{gnu.java.lang.VMInstrumentationImpl} - -The @code{gnu.java.lang.VMInstrumentationImpl} and -@code{gnu.java.lang.InstrumentationImpl} classes provide an implementation of the -@code{java.lang.instrument.Instrument} interface. -A @code{InstrumentationImpl} object should be created by the VM when agents -are given in the command line (see the @code{java.lang.instrument} package -documentation). The VM has to set the static field -@code{VMClassLoader.instrumenter} to this object. The VM should implement the -static native methods of the @code{VMInstrumentationImpl} class. - -@itemize @bullet -@item @code{isRedefineClassesSupported()} -- Returns true if the JVM supports -class redefinition. -@item @code{redefineClasses()} -- Gives a set of classes with new bytecodes. -The VM must redefine the classes by reading the new bytecodes. -@item @code{getAllLoadedClass()} -- Returns an array of all loaded classes. -@item @code{getInitiatedClass()} -- Returns an array of all classes loaded -by a specific class loader. -@item @code{getObjectSize()} -- Gives the size of an object. -@end itemize - -Instrumentation allows to modify the bytecode of a class before it gets read -by the VM. In GNU Classpath, the @code{ClassLoader.defineClass} method calls -the @code{VMClassLoader.defineClassWithTransformers} method which first checks -if @code{VMClassLoader.instrumenter} is @code{null}. If it's the case, it -directly calls @code{VMClassLoader.defineClass}. If it's not the case, the -method calls at first the @code{InstrumentationImpl.callTransformers} method, -which calls each transformer registered to the @code{InstrumentationImpl} -object and returns a new bytecode array. Then, it calls the -@code{VMClassLoader.defineClass} method with this new bytecode array. - -The second use of instrumentation is to redefine a class after it has been -loaded by the VM. This is done in the Java application by calling the -@code{Instrumentation.redefineClasses} method of the standard interface on -a @code{Instrumentation} object. The @code{InstrumentationImpl.redefineClasses} -method calls the @code{VMInstrumentationImpl.redefineClasses} native method -which must be implemented by the VM. The implementation should call the -@code{InstrumentationImpl.callTransformers} method. - -@node gnu.java.lang.management, java.lang.management, gnu.java.lang, Classpath Hooks -@section @code{gnu.java.lang.management} - -@code{gnu.java.lang.management} provides the VM interfaces for the GNU -implementations of the management beans. - -@menu -* gnu.java.lang.management.VMRuntimeMXBeanImpl:: -* gnu.java.lang.management.VMClassLoadingMXBeanImpl:: -* gnu.java.lang.management.VMThreadMXBeanImpl:: -* gnu.java.lang.management.VMMemoryMXBeanImpl:: -* gnu.java.lang.management.VMCompilationMXBeanImpl:: -* gnu.java.lang.management.VMMemoryPoolMXBeanImpl:: -* gnu.java.lang.management.VMMemoryManagerMXBeanImpl:: -* gnu.java.lang.management.VMGarbageCollectorMXBeanImpl:: -@end menu - -@node gnu.java.lang.management.VMRuntimeMXBeanImpl,gnu.java.lang.management.VMClassLoadingMXBeanImpl,,gnu.java.lang.management -@subsection @code{gnu.java.lang.management.VMRuntimeMXBeanImpl} - -The @code{gnu.java.lang.management.RuntimeMXBeanImpl} provides an -implementation of the @code{java.lang.management.RuntimeMXBean} interface, -and is supported by VM functionality in the form of -@code{gnu.java.lang.management.VMRuntimeMXBeanImpl}. This provides a -series of methods, which should be implemented by the virtual machine -in order to provide the required information for the bean. The VM -methods are generally representative of information that is only -available from the virtual machine, such as the command-line arguments -it was given at startup. - -The methods are as follows: - -@itemize @bullet -@item @code{(getInputArguments())} -- The VM should supply -a @code{String} array containing each of the command-line -arguments, excluding those that are directed at the -@code{main()} method. The reference implementation expects -this to be a native method. -@item @code{(getName())} -- The VM developer should choose -an appropriate name for the virtual machine. This name can -be instance-specific e.g. it can include things like the -process identifier or host name of the machine, which only -apply to the current running instance. Thus, the intention is -that this name refers to the entity that the other information -refers to, rather than the VM in general. The reference -implementation supplies a default concatenation of the VM -name and version. -@item @code{(getStartTime())} -- This should return the number -of milliseconds at which the virtual machine was started. -The uptime property of the bean is provided relative to this -value. Again, the reference implementation also expects -this method to be native. -@end itemize - -The virtual machine also needs to provide either the -@code{sun.boot.class.path} or @code{java.boot.class.path} -property in order to support the optional boot class path -retrieval functionality. - -@node gnu.java.lang.management.VMClassLoadingMXBeanImpl,gnu.java.lang.management.VMThreadMXBeanImpl,gnu.java.lang.management.VMRuntimeMXBeanImpl,gnu.java.lang.management -@subsection @code{gnu.java.lang.management.VMClassLoadingMXBeanImpl} - -The @code{gnu.java.lang.management.ClassLoadingMXBeanImpl} provides an -implementation of the @code{java.lang.management.ClassLoadingMXBean} interface, -and is supported by VM functionality in the form of -@code{gnu.java.lang.management.VMClassLoadingMXBeanImpl}. This provides a -series of methods, which should be implemented by the virtual machine -in order to provide the required information for the bean. Implementing -this bean requires the VM to monitor when classes are loaded and unloaded, -and provide the option of verbose class loading output. - -The methods are as follows: - -@itemize @bullet -@item @code{(getLoadedClassCount())} -- This should return -the number of classes that are currently loaded by the VM. -@item @code{(getUnloadedClassCount())} -- This should return -the number of classes that have been loaded by the VM, but -have since been unloaded. -@item @code{(isVerbose())} -- This should return @code{true} -or @code{false}, depending on whether verbose class loading -output is turned or not, respectively. -@item @code{(setVerbose(boolean))} -- This should allow the -verbose class loading output to be turned on and off. -@end itemize - -@node gnu.java.lang.management.VMThreadMXBeanImpl,gnu.java.lang.management.VMMemoryMXBeanImpl,gnu.java.lang.management.VMClassLoadingMXBeanImpl,gnu.java.lang.management -@subsection @code{gnu.java.lang.management.VMThreadMXBeanImpl} - -The @code{gnu.java.lang.management.ThreadMXBeanImpl} provides an -implementation of the @code{java.lang.management.ThreadMXBean} interface, -and is supported by VM functionality in the form of -@code{gnu.java.lang.management.VMThreadMXBeanImpl}. This provides a -series of methods, which should be implemented by the virtual machine -in order to provide the required information for the bean. Implementing -this bean requires the VM to monitor thread-related statistics such as -how often the blocked and waiting states have been entered, as well as -additional optional support for time and contention monitoring. - -Optional support is determined by the following properties: - -@itemize @bullet -@item @code{gnu.java.lang.management.CurrentThreadTimeSupport} -- -This property should be present if the VM supports monitoring the -time used by the current thread. If time monitoring for all threads -is supported, this need not be provided. -@item @code{gnu.java.lang.management.ThreadTimeSupport} -- -This property should be present if the VM supports monitoring the -time used by all threads. -@item @code{gnu.java.lang.management.ThreadContentionSupport} -- -This property should be present if the VM supports thread contention -monitoring. -@end itemize - -In addition, the property -@code{gnu.java.lang.management.ThreadTimeInitallyEnabled} may be -set to the @code{String} value, @code{"true"}, if time monitoring -is enabled at startup. - -The methods are as follows: - -@itemize @bullet -@item @code{(findMonitorDeadlockedThreads())} -- This should return -an array of thread identifiers which match threads involved in -deadlock cycles (where each thread is waiting to obtain a lock -held by one of the others). This is specified as a native method -in the reference implementation. -@item @code{(getAllThreads())} -- This should return an array of -all live threads and set the @code{filled} variable to the number -found. A default implementation is provided. -@item @code{(getAllThreadIds())} -- This should return an array of -all live thread identifiers. An implementation is provided against -@code{getAllThreads()} by default. -@item @code{(getCurrentThreadCpuTime())} -- This should return the -approximate number of nanoseconds of CPU time the current thread -has used. This is an optional native method, which is used by VMs -supporting time monitoring. -@item @code{(getCurrentThreadUserTime())} -- This should return the -approximate number of nanoseconds of user time the current thread -has used. This is an optional native method, which is used by VMs -supporting time monitoring. -@item @code{(getDaemonThreadCount())} -- This should return the number -of live daemon threads. A default implementation is provided, based -on @code{getAllThreads()}. -@item @code{(getPeakThreadCount())} -- The VM should maintain a record -of the peak number of live threads, and return it when this method is -called. This is specified as a native method in the reference -implementation. -@item @code{(resetPeakThreadCount())} -- This should reset the record -of the peak number of live threads to the current number of live -threads. This is specified as a native method in the reference -implementation. -@item @code{(getThreadCount())} -- This should return the number of -live threads. A default implementation is provided, based on -@code{getAllThreads()}. -@item @code{(getThreadCpuTime(long))} -- This should return the -approximate number of nanoseconds of CPU time the specified thread -has used. This is an optional native method, which is used by VMs -supporting time monitoring. -@item @code{(getThreadUserTime(long))} -- This should return the -approximate number of nanoseconds of CPU time the specified thread -has used. This is an optional native method, which is used by VMs -supporting time monitoring. -@item @code{(getThreadInfoForId(long, int))} -- This return an instance -of @code{java.lang.management.ThreadInfo} for the specified thread. -The class includes a private constructor which VMs should use to initialise -it with the appropriate values for the thread. The second argument -given here specifies the depth of the stack trace supplied on construction -of the instance. Special values are 0 (return an empty array) and -@code{Integer.MAX_VALUE} (return the maximum depth possible). This -is specified as a native method in the reference implementation. -@item @code{(getTotalStartedThreadCount())} -- This should return the -total number of threads that have been started by the VM, including ones -that have died. This is specified as a native method in the reference -implementation. -@end itemize - -@node gnu.java.lang.management.VMMemoryMXBeanImpl,gnu.java.lang.management.VMCompilationMXBeanImpl,gnu.java.lang.management.VMThreadMXBeanImpl,gnu.java.lang.management -@subsection @code{gnu.java.lang.management.VMMemoryMXBeanImpl} - -The @code{gnu.java.lang.management.MemoryMXBeanImpl} provides an -implementation of the @code{java.lang.management.MemoryMXBean} interface, -and is supported by VM functionality in the form of -@code{gnu.java.lang.management.VMMemoryMXBeanImpl}. This provides a -series of methods, which should be implemented by the virtual machine -in order to provide the required information for the bean. Implementing -this bean requires the VM to monitor the levels of heap and non-heap -memory, and provide the number of objects which are eligible for garbage -collection. - -The methods are as follows: - -@itemize @bullet -@item @code{(getHeapMemoryUsage())} -- This should return -an instance of @code{java.lang.management.MemoryUsage} with -values pertaining to the heap. A default implementation is -provided, based on @code{java.lang.Runtime}'s methods. -@item @code{(getNonHeapMemoryUsage())} -- This should return -an instance of @code{java.lang.management.MemoryUsage} with -values pertaining to non-heap memory. -@item @code{(getObjectPendingFinalizationCount())} -- Returns -the number of objects which are no longer referenced, and which -will thus be garbage collected on the next run of the garbage -collector. -@item @code{(isVerbose())} -- This should return @code{true} -or @code{false}, depending on whether verbose memory management -output is turned or not, respectively. -@item @code{(setVerbose(boolean))} -- This should allow the -verbose memory management output to be turned on and off. -@end itemize - -@node gnu.java.lang.management.VMCompilationMXBeanImpl,gnu.java.lang.management.VMMemoryPoolMXBeanImpl,gnu.java.lang.management.VMMemoryMXBeanImpl,gnu.java.lang.management -@subsection @code{gnu.java.lang.management.VMCompilationMXBeanImpl} - -The @code{gnu.java.lang.management.CompilationMXBeanImpl} provides an -implementation of the optional @code{java.lang.management.CompilationMXBean} -interface, and is supported by VM functionality in the form of -@code{gnu.java.lang.management.VMCompilationMXBeanImpl}. This provides a -single method for returning the number of milliseconds the virtual -machine's Just-In-Time (JIT) compiler has spent compiling. Even if -a JIT compiler is available and an instance of the bean supplied, this -method is still optional. - -Optional support is determined by the following properties: - -@itemize @bullet -@item @code{gnu.java.lang.compiler.name} -- This property should -specify the name of the JIT compiler. Classpath also uses this, -within @code{java.lang.management.ManagementFactory}, to determine -whether a bean should be created. If this property is set to a -non-null value, a bean will be created and its @code{getName()} -method will return this value. -@item @code{gnu.java.lang.management.CompilationTimeSupport} -- -This property should be present if the VM supports monitoring the -time spent compiling. -@end itemize - -Time support is implemented by the following method: - -@itemize @bullet -@item @code{(getTotalCompilationTime())} -- This should return the -number of milliseconds the JIT compiler has spent compiling. -@end itemize - -@node gnu.java.lang.management.VMMemoryPoolMXBeanImpl,gnu.java.lang.management.VMMemoryManagerMXBeanImpl,gnu.java.lang.management.VMCompilationMXBeanImpl,gnu.java.lang.management -@subsection @code{gnu.java.lang.management.VMMemoryPoolMXBeanImpl} - -The @code{gnu.java.lang.management.MemoryPoolMXBeanImpl} provides an -implementation of the optional @code{java.lang.management.MemoryPoolMXBean} -interface, and is supported by VM functionality in the form of -@code{gnu.java.lang.management.VMMemoryPoolMXBeanImpl}. Providing -this interface requires implementing a number of methods for each supported -pool. These return statistics on memory usage, and, optionally, allows -monitoring of when memory usage exceedes a preset threshold. - -Optional support is determined by the following properties: - -@itemize @bullet -@item @code{gnu.java.lang.management.CollectionUsageThresholdSupport} -- -This property should be present if the VM supports setting a collection -usage threshold and monitoring when it is matched or exceeded. Collection -usage thresholds are related to the remaining memory usage following a -garbage collection cycle. -@item @code{gnu.java.lang.management.UsageThresholdSupport} -- -This property should be present if the VM supports setting a -usage threshold and monitoring when it is matched or exceeded. -@end itemize - -The methods are as follows (all take a pool name as their -first parameter): - -@itemize @bullet -@item @code{(getCollectionUsage(String))} -- Returns a -@code{java.lang.management.MemoryUsage} object, containing the -memory usage statistics following a garbage collection cycle -for the specified pool. This may also return @code{null} if -the pool isn't an appropriate pool for this particular task. -@item @code{(getCollectionUsageThreshold(String))} -- Returns -the pool's collection usage threshold, if supported. -@item @code{(getCollectionUsageThresholdCount(String))} -- Returns -the number of times the specified pool has matched or exceeded -its collection usage threshold, if supported. -@item @code{(getMemoryManagerNames(String))} -- Returns a list -of names of memory managers which manage the specified pool. -@item @code{(getPeakUsage(String))} -- Returns a -@code{java.lang.management.MemoryUsage} object for the peak -usage level of the specified pool. -@item @code{(getType(String))} -- Returns a string containing -either @code{"HEAP"} or @code{"NON_HEAP"} which indicates the type of -memory used by the specified pool. -@item @code{(getUsage(String))} -- Returns a -@code{java.lang.management.MemoryUsage} object for the current -usage level of the specified pool. -@item @code{(getUsageThreshold(String))} -- Returns -the pool's usage threshold, if supported. -@item @code{(getUsageThresholdCount(String))} -- Returns -the number of times the specified pool has matched or exceeded -its usage threshold, if supported. -@item @code{(isValid(String))} -- Returns true if the pool -is still in use by the virtual machine. -@item @code{(resetPeakUsage(String))} -- Resets the peak usage -levels to the current usage levels for the specified pool. -@item @code{(setCollectionUsageThreshold(String, long))} -- Sets -the pool's collection usage threshold, if supported. -@item @code{(setUsageThreshold(String, long))} -- Sets -the pool's usage threshold, if supported. -@end itemize - -@node gnu.java.lang.management.VMMemoryManagerMXBeanImpl,gnu.java.lang.management.VMGarbageCollectorMXBeanImpl,gnu.java.lang.management.VMMemoryPoolMXBeanImpl,gnu.java.lang.management -@subsection @code{gnu.java.lang.management.VMMemoryManagerMXBeanImpl} - -The @code{gnu.java.lang.management.MemoryManagerMXBeanImpl} provides an -implementation of the optional @code{java.lang.management.MemoryManagerMXBean} -interface, and is supported by VM functionality in the form of -@code{gnu.java.lang.management.VMMemoryManagerMXBeanImpl}. Providing -this interface requires implementing two methods (each takes the name -of the manager as the first argument): - -@itemize @bullet -@item @code{(getMemoryPoolNames(String))} -- Returns a list of the -memory pools that the manager maintains. A default implementation -which scans the results of @code{getMemoryManagerNames()} for each -pool is provided. -@item @code{(isValid(String))} -- Returns true if the specified -manager is still valid i.e. it is still in use by the virtual machine. -@end itemize - -@node gnu.java.lang.management.VMGarbageCollectorMXBeanImpl,,gnu.java.lang.management.VMMemoryManagerMXBeanImpl,gnu.java.lang.management -@subsection @code{gnu.java.lang.management.VMGarbageCollectorMXBeanImpl} - -The @code{gnu.java.lang.management.GarbageCollectorMXBeanImpl} provides an -implementation of the optional @code{java.lang.management.GarbageCollectorMXBean} -interface, and is supported by VM functionality in the form of -@code{gnu.java.lang.management.VMGarbageCollectorMXBeanImpl}. Providing -this interface requires implementing two methods (each takes the name -of the garbage collector as the first argument): - -@itemize @bullet -@item @code{(getCollectionCount(String))} -- Returns the number of -times the specified garbage collector has run. -@item @code{(getCollectionTime(String))} -- Returns the accumulated -number of milliseconds for which the garbage collector has run. -@end itemize - -Note that each garbage collector is also a memory manager, and so an -implementation of the @code{gnu.java.lang.management.VMMemoryManagerMXBeanImpl} -methods for its name should also be provided. - -@node java.lang.management, Classpath Callbacks, gnu.java.lang.management, Classpath Hooks -@section @code{java.lang.management} - -@code{gnu.java.lang.management} provides the VM interfaces for the GNU -implementations of the management beans. - -@menu -* java.lang.management.VMManagementFactory:: -@end menu - -@node java.lang.management.VMManagementFactory,,,java.lang.management -@subsection @code{java.lang.management.VMManagementFactory} - -This VM interface provides the names of the memory pools, memory managers -and garbage collectors for use by the @code{java.lang.management.ManagementFactory} -in creating lists of appropriate beans for these types of managed object. - -The methods are as follows: - -@itemize @bullet -@item @code{(getMemoryPoolNames())} -- Returns a list of the names -of the current memory pools in use by the virtual machine. -@item @code{(getMemoryManagerNames())} -- Returns a list of the names -of the current memory managers in use by the virtual machine. This -should not include those that are also garbage collectors. -@item @code{(getGarbageCollectorNames())} -- Returns a list of the names -of the current garbage collectors in use by the virtual machine. -@end itemize - -@node Classpath Callbacks, , java.lang.management, Classpath Hooks -Some of the classes you implement for the VM will need to call back to -package-private methods in Classpath: - -@itemize @bullet -@item @code{java.lang.ThreadGroup.addThread(Thread)} -Call this method from @code{Thread} when a new @code{Thread} is created, to add it to -the group. - -@item @code{java.lang.ThreadGroup.removeThread(Thread)} -Call this method from @code{Thread} when a @code{Thread} is stopped or destroyed. - -@item @code{gnu.java.lang.management.MemoryMXBeanImpl.fireThresholdExceededNotification(String, long, long, long, long)} -If the monitoring of memory usage thresholds is supported, this method -should be called when the normal usage of a memory pool crosses the -threshold, in order to emit a notification. Another notification -should not be emitted until there is an intermittent period where the -usage is again below the threshold. The parameters are the memory -pool name, the usage levels (init, used, committed and max) and the -number of times the threshold has been crossed. - -@item @code{gnu.java.lang.management.MemoryMXBeanImpl.fireCollectionThresholdExceededNotification(String, long, long, long, long)} -If the monitoring of memory usage thresholds is supported, this method -should be called when the usage of a memory pool after a garbage -collection cycle crosses the threshold, in order to emit a -notification. Another notification should not be emitted until there -is an intermittent period where the usage is again below the -threshold. The parameters are the memory pool name, the usage levels -(init, used, committed and max) and the number of times the threshold -has been crossed. - -@end itemize - -@node VM Hooks, JNI Implementation, Classpath Hooks, Top -@comment node-name, next, previous, up -@chapter VM Hooks - -VMs need to do some dirty work; there are some things in the VM that -unfortunately are dependent on the internal structure of various -classes. This is a guide to all of the things the VM itself needs to -know about classes. - -Some of the core classes, while being implemented by GNU Classpath, -provide space for state (in the form of a @code{vmdata} object) to be -stored by the VM, and can not be constructed normally. - -@itemize @bullet -@item java.lang.Class -@item java.lang.ClassLoader -@end itemize - -The default implementations of some VM classes also follow this methodology, -when it is intended that most VMs will keep the default. - -@itemize @bullet -@item java.lang.VMThread -@item java.lang.VMThrowable -@end itemize - -Several core classes must be completely implemented by the VM for Classpath to -work, although reference implementations are provided. These classes are: - -@itemize @bullet -@item java.lang.reflect.Constructor -@item java.lang.reflect.Method -@item java.lang.reflect.Field -@end itemize - -The following issues are of note; - -@itemize @bullet -@item @code{java.lang.Class} @* -The GNU Classpath implementation of @code{java.lang.Class} provides an -object for storing the internal state of the class maintained by the VM. -This is the only known place where this matters. The class is -constructed with this data by the VM. Some VMs do not create the -@code{Class} object at the point where the class is defined; instead, -they wait until a @code{Class} object is actually used. - -@item Array Classes @* -When you are creating an array class, you should set the -@code{ClassLoader} of the array class to the @code{ClassLoader} of its -component type. Whenever you add a class to a @code{ClassLoader}, you -need to notify the @code{ClassLoader} and add the new @code{Class} to -its internal cache of classes. To do this, call -@code{ClassLoader.addVMCreatedClass(Class)}. @emph{Note: this is -written in anticipation of 1.2 support and does not apply just yet.} - -@item Primordial Class Loader @* -When the primordial class loader loads a class, it needs to tell -Classpath what it has done in order for security stuff to work right. -To do this, call the static method -@code{ClassLoader.newPrimordialClass(Class)}. - -Even the first few core classes need to do this; in order to do it, -simply call this method @emph{after} the initial class loading has been -done. No harm will come, as long as you follow the guidelines in the -@pxref{Initialization} section. - -@emph{Note: this is written in anticipation of 1.2 support and does not -apply just yet.} - -@item Top-level Exception Handler @* -Exceptions take care of themselves in Classpath; all you need to do in -the top-level exception handler is call @code{Throwable.printStackTrace()}. - -@item Security and Traces @* -There will eventually be a feature in the 1.2 security that keeps the -@code{AccessController} from having to evaluate @emph{all} of the -@code{ProtectionDomain}s every time a security check is made. I think a common -case is a single method doing a lot of things that require security -checks. However, I don't want to bog down the method stack too much, so -this feature of the VM will have the @code{AccessController} for a thread -calling out to the VM to tell it how high it was on the stack when it -made the last security request. Every time the stack goes lower than -that number, the VM will decrement the number. The @code{AccessController} -will remember what the accumulated protection status was at every stack -level (an @code{AccessControlContext}) and use that aggregated information to -do the check. I am not sure, however, whether the savings are -substantial enough to outweigh the integer check and set after every -method call. I will investigate. - -@item Threading @* -I figured I'd put this here because a VM guy might be wondering about it. -We implement @code{ThreadGroup}, but that class is almost entirely -VM-independent. The root @code{ThreadGroup}, a static field called -@code{ThreadGroup.root}, should be initialized by Classpath, but if you wish to -reinitialize it yourself, there should be no harm. - -@end itemize - -@node JNI Implementation, JVMTI Implementation, VM Hooks, Top -@comment node-name, next, previous, up -@chapter JNI Implementation - -Classpath comes with its own implementation of @file{jni.h}. This -file can be customized by the VM in a few ways, by defining macros -that affect the interpretation of the file. These macros are all -intended for use by a VM which uses GNU Classpath and which wants to -use a single copy of @file{jni.h} for both internal and external use. - -@itemize @bullet -@item _CLASSPATH_VM_JNI_TYPES_DEFINED -Some VMs like to define JNI ``object'' types in a special way. If -this macro is defined, the Classpath @file{jni.h} will avoid defining -these types. By default, these types are defined in @file{jni.h}. -The full list of types and macros treated this way is: @samp{jobject}, -@samp{jclass}, @samp{jstring}, @samp{jthrowable}, @samp{jweak}, -@samp{jarray}, @samp{jobjectArray}, @samp{jbyteArray}, -@samp{jshortArray}, @samp{jintArray}, @samp{jlongArray}, -@samp{jbooleanArray}, @samp{jcharArray}, @samp{jfloatArray}, -@samp{jdoubleArray}, @samp{JNIEnv}, @samp{JavaVM}, @samp{JNI_TRUE} -(macro), @samp{JNI_FALSE} (macro). - -@item _CLASSPATH_VM_INTERNAL_TYPES_DEFINED -If the VM has its own definitions for @samp{jfieldID} and -@samp{jmethodID}, then it should define this macro. Otherwise, -@file{jni.h} will provide definitions for these types. - -@item _CLASSPATH_JNIIMPEXP -Three functions -- @samp{JNI_GetDefaultJavaVMInitArgs}, -@samp{JNI_CreateJavaVM}, and @samp{JNI_GetCreatedJavaVMs} -- must be -marked as @samp{JNIIMPORT} when seen by user code, but most likely -should be marked as @samp{JNIEXPORT} when defined in the VM -implementation. This macro can be defined to one or the other by the -VM as appropriate. If this macro is not defined, it defaults to -@samp{JNIIMPORT}. - -@item _CLASSPATH_JNIENV_CONTENTS -A VM can add fields to the @samp{JNIEnv} structure by defining this to -be a sequence of field declarations. - -@end itemize - -@node JVMTI Implementation, Miscellaneous VM Requirements, JNI Implementation, Top -@comment node-name, next, previous, up -@chapter JVMTI Implementation - -Classpath comes with its own implementation of @file{jvmti.h}. This -file can be customized by the VM in a few ways by defining macros that -affect the interpretation of the file. These macros are all intended -for use for use by a VM which uses GNU Classpath and which wants to -use a single copy of @file{jvmti.h} for both internal and external use. - -@itemize @bullet -@item _CLASSPATH_VM_JVMTI_TYPES_DEFINED -Some VMs like to define JVMTI ``object'' types in a special way. If -this macro is defined, the Classpath @file{jvmti.h} will avoid defining -these types. By default these types are defined in @file{jvmti.h}. -The full list of types and macros treated this way is: @samp{jthread}, -@samp{jthreadGroup}, @samp{jlocation}, and @samp{jrawMonitorID}. By -default @samp{jrawMonitorID} is defined as an opaque pointer which -must be defined by the VM. - -@item _CLASSPATH_JVMTIENV_CONTENTS -A VM can add fields to the @samp{jvmtiEnv} structure by defining this -to be a sequence of field declarations. - -@end itemize - -@node Miscellaneous VM Requirements, , JVMTI Implementation, Top -@comment node-name, next, previous, up -@chapter Miscellaneous VM Requirements - -Classpath places a few requirements on the VM that uses it. - -@menu -* JNI Version:: -* VM Threading Model:: -* Boot Library Path Property:: -@end menu - -@node JNI Version, VM Threading Model, Miscellaneous VM Requirements, Miscellaneous VM Requirements -@comment node-name, next, previous, up -@section JNI Version - -Classpath currently uses only JNI 1.1, except for one JNI 1.2 function -in the JNI Invocation API: GetEnv(). And GetEnv() is only used in the -now deprecated ``portable native sync'' code. - -A future direction will probably be to require that all VMs provide -JNI 1.2. If this poses problems, please raise them on the classpath -mailing list. - -@node VM Threading Model, Boot Library Path Property, JNI Version, Miscellaneous VM Requirements -@comment node-name, next, previous, up -@section VM Threading Model - -VM authors can implement a number of different threading models. When -native code is also threaded there is the potential for one threading -model to deadlock the other. The -@uref{http://java.sun.com/docs/books/jni/html/other.html#29406,Java -Native Interface Programmer's Guide and Specification} suggests -consulting VM documentation in such situations. Classpath uses -existing libraries, for example the AWT peers can use the GTK+ -graphics library. As these libraries assume a different threading -model, there is the potential for the native code to deadlock a VM. - -The different threading models available to a VM author are: -@enumerate -@item -@i{Native threads}: Map a Java thread to an underlying operating system -thread (normally a POSIX compatible pthread). This approach reduces -the potential for deadlock as there is only one thread scheduling -mechanism. -@item -@i{Green threads 1}: Green threads are threads scheduled by the VM, -typically by switching swapping registers. In early VMs green threads -were seen as advantageous as they didn't require the operating system -to resechedule, save and swap all of a threads registers. The green -thread 1 model switches thread on an externally created event, such as -a timer interrupt. An example of a VM using this approach is Kaffe -configured with its jthreads model. -@item -@i{Green threads 2}: The essential difference with this model is to -not switch threads on an event, but at fixed points in the code being -executed by the VM. Points chosen could be backward branches (loops) -or method calls. This approach can be advantageous to nonconservative -garbage collectors, as non-running threads would be at known points -and can have fixed register maps. It can also reduce the number of -registers it is necessary to swap when switching threads. -@item -@i{M:N threading}: a flaw to green threading is that it is unable to -use multiple processors. @i{M}:@i{N} threading fixes this problem by -running groups of green threads on multiple underlying native -threads. An example of a VM using this approach is the Jikes RVM, -which uses @i{M}:@i{N} threading combined with the green thread 2 -model. -@end enumerate - -An example of the problem of mixing threading models is: -@itemize @bullet -@item -A Java thread calls a native method. The native method aquires a lock. -@item -The native method calls back into the VM. -@item -An event triggers the VM to reschedule the currently running thread. -@item -A new VM thread, executing on the same underlying native thread, calls -a native method. -@item -The native method tries to aquire the lock already aquired earlier. As -the lock is busy the thread waits and allows the operating system to -reschedule native threads. -@item -The operating system reschedules the VM thread again, but the lock is -still busy and in some threading models will remain busy forever -(the VM is deadlocked). -@end itemize - -VMs that don't use the underlying operating system thread scheduling -mechanism need to avoid deadlock. One now deprecated approach was to -build Classpath and VMs on top of a wrapper thread library (aka -portable native sync). The wrapper thread library used was GLIB's -@dfn{gthreads}. This approach has been deprecated because: -@enumerate -@item -The wrapper library is only in use by some native libraries. For -example, GTK+ uses the gthread library but QT does not. -@item -The wrapper library can't be in use prior to the VM starting as the VM -must replace the wrapper libraries functions with its own. This -prevents the VM from running as a plugin in an application that -already uses the wrapper library. -@end enumerate - -An alternative approach is for the VM to detect deadlocked native code -and swap Java threads off of that native thread. The VM can't, -however, swap two blocked native threads that are potentially -deadlocking each other on a lock. The lock will be associated with the -native thread. To prevent this from happening the VM must hijack -functions that operate on locks. This is done by redifining the lock -functions inside the VM and configuring the linker so that it uses the -VMs symbol in preference to that of the external thread support -library. The VM's lock function can then reschedule Java threads if it -must wait for the lock. - -@node Boot Library Path Property, , VM Threading Model, Miscellaneous VM Requirements -@comment node-name, next, previous, up -@section Boot Library Path Property - -As of GNU Classpath 0.15 a system property named @code{gnu.classpath.boot.library.path} -can be set by the VM to specify the directories which contain GNU Classpath's native -libraries. Usually this value is given at configuration time and is then hardcoded -in the VM. However for development purposes it is handy to switch to another installation -by overriding the properties' value on the command line. - -A VM that does not support this feature can simply ignore the property. - -For compatibility reasons we suggest to set the default value of @code{java.library.path} -to the value of the @code{LD_LIBRARY_PATH} environment if it exists on your platform. - -@bye - - - -- cgit v1.1