⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hacking.texinfo

📁 linux下建立JAVA虚拟机的源码KAFFE
💻 TEXINFO
📖 第 1 页 / 共 5 页
字号:
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; ifit was not specified accurately in 1.1, then use the specfor 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; ifit was not specified accurately in 1.1, then use the specfor 1.2)@item@uref{http://developer.java.sun.com/developer/bugParade/index.html,TheBug Parade}: I have obtained a ton of useful information about howthings do work and how they *should* work from the Bug Parade just bysearching for related bugs.  The submitters are very careful about theiruse of the spec.  And if something is unspecified, usually you can finda request for specification or a response indicating how Sun thinks itshould be specified here.@end enumerateYou'll notice that in this document, white papers and specificationpapers are more canonical than the JavaDoc documentation.  This is truein general.@node Naming Conventions, Character Conversions, Specification Sources, Top@comment node-name, next, previous, up@chapter Directory and File Naming ConventionsThe Classpath directory structure is laid out in the following manner:@exampleclasspath | |---->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 exampleHere is a brief description of the toplevel directories and their contents.@table @b@item javaContains the source code to the Java packages that make up the coreclass library.  Because this is the public interface to Java, it isimportant that the public classes, interfaces, methods, and variablesare exactly the same as specified in Sun's documentation.  The directorystructure 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/javaInternal classes (roughly analogous to Sun's sun.* classes) should gounder the @file{gnu/java} directory.  Classes related to a particular publicJava package should go in a directory named like that package.  Forexample, classes related to java.util.zip should go under a directory@file{gnu/java/util/zip}.  Sub-packages under the main package name areallowed.  For classes spanning multiple public Java packages, pick anappropriate name and see what everybody else thinks.@item nativeThis directory holds native code needed by the public Java packages.Each package has its own subdirectory, which is the ``flattened'' nameof the package.  For example, native method implementations forjava.util.zip should go in @file{native/classpath/java-util}.  Classpathactually includes an all Java version of the zip classes, so no nativecode is required.@end tableEach person working on a package get's his or her own ``directoryspace'' underneath each of the toplevel directories.  In addition to thegeneral guidelines above, the following standards should be followed:@itemize @bullet@itemClasses that need to load native code should load a library with thesame name as the flattened package name, with all hyphens removed.  Forexample, the native library name specified in LoadLibrary forjava-util would be ``javautil''.@itemEach package has its own shared library for native code (if any).@itemThe main native method implementation for a given method in class shouldgo in a file with the same name as the class with a ``.c'' extension.For example, the JNI implementation of the native methods injava.net.InetAddress would go in @file{native/jni/java-net/InetAddress.c}.``Internal'' native functions called from the main native method canreside in files of any name.@end itemize@node Character Conversions, Localization, Naming Conventions, Top@comment node-name, next, previous, up@chapter Character ConversionsJava uses the Unicode character encoding system internally.  This is asixteen bit (two byte) collection of characters encompassing most of theworld's written languages.  However, Java programs must often deal withoutside interfaces that are byte (eight bit) oriented.  For example, aUnix file, a stream of data from a network socket, etc.  Beginning withJava 1.1, the @code{Reader} and @code{Writer} classes provide functionalityfor dealing with character oriented streams.  The classes @code{InputStreamReader} and @code{OutputStreamWriter} bridge the gapbetween 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 loadtranslaters that perform the actual conversion.  There are two types ofconverters, 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 usinga 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 incontexts that require character streams, but the Classpath implementationcurrently does not make use of them in this fashion.The @code{EncodingManager} class searches for requested encoders anddecoders 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 thepackage path specified by the @code{file.encoding.pkg} property.  Thename of the encoder or decoder is appended to the search path toproduce the required class name.  Note that @code{EncodingManager} knowsabout the default system encoding scheme, which it retrieves from thesystem property @code{file.encoding}, and it will return the propertranslator 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 translatorsthat it has loaded.  This eliminates the need to search for a commonlyused 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.<encoding name>}.  If such aproperty exists.  The value of that property is assumed to be thecanonical 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 requestsa decoder for the ''UTF-8'' encoding scheme by calling@code{EncodingManager.getDecoder("UTF-8")}.  First, an alias is searchedfor by looking for the system property @code{gnu.java.io.encoding_scheme_alias.UTF-8}.  In our example, thisproperty exists and has the value ''UTF8''.  That is the actualdecoder that will be searched for.  Next, @code{EncodingManager} looksin its cache for this translator.  Assuming it does not find it, itsearches the translator path, which is this example consists only ofthe 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 translatoris appended.  So @code{EncodingManager} attempts to load a translatorclass 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 abstractmethods need to be implemented.  In general, no methods need to beoverridden.  The needed methods calculate the number of bytes/charsthat 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 classesimplement all of the necessary methods.  All that is necessary tocreate a lookup table array that maps bytes to Unicode characters andset the class variable @code{lookup_table} equal to it in a staticinitializer.  Also, a single constructor that takes an appropriatestream as an argument must be supplied.  These translators areexceptionally easy to create and there are several of them suppliedin the Classpath distribution.Writing multi-byte or variable-byte encodings is more difficult, butoften not especially challenging.  The Classpath distribution ships withtranslators for the UTF8 encoding scheme which uses from one to threebytes to encode Unicode characters.  This can serve as an example ofhow to write such a translator.Many more translators are needed.  All major character encodings shouldeventually be supported.@node Localization,  , Character Conversions, Top@comment node-name, next, previous, up@chapter LocalizationThere are many parts of the Java standard runtime library that mustbe 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 agiven 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 menuIn 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 thedocumentation for the @code{java.util.ResourceBundle} class for detailson how the specific locale classes should be named.@code{ListResourceBundle}'s are used instead of @code{PropertyResourceBundle}'s because data more complex than simplestrings need to be provided to configure certain Classpath components.Because @code{ListResourceBundle} allows an arbitrary Java object tobe associated with a given configuration option, it provides theneeded flexibility to accomodate Classpath's needs.Each Java library component that can be localized requires that certainconfiguration options be specified in the resource bundle for it.  It isimportant 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 optionshould name should have the name name as the variable.  Also, the valueassociated with each option should be a Java object with the same nameas the option name (unless a simple scalar value is used).  Here is anexample:A class loads a value for the @code{format_string} variable from theresource bundle in the specified locale.  Here is the code in thelibrary class:@example  ListResourceBundle lrb =     ListResourceBundle.getBundle ("gnu/java/locale/LocaleInformation", locale);  String format_string = lrb.getString ("format_string");@end exampleIn the actual resource bundle class, here is how the configuration optiongets 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 exampleNote that each variable should be @code{private}, @code{final}, and@code{static}.  Each variable should also have a description of what itdoes as a documentation comment.  The @code{getContents()} method returnsthe @code{contents} array.There are many functional areas of the standard class library that areconfigured using this mechanism.  A given locale does not need to supporteach functional area.  But if a functional area is supported, then allof the specified entries for that area must be supplied.  In order todetermine which functional areas are supported, there is a special keythat 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 isassumed that no support exists for this functional area.  Every classusing resources for configuration must use this scheme and define a specialscheme that indicates the functional area is supported.  Simply checkingfor the resource bundle's existence is not sufficient to ensure that agiven functional area is supported.The following sections define the functional areas that use resourcesfor locale specific configuration in GNU Classpath.  Please refer to the documentation for the classes mentioned for details on how these values are 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -