📄 vmintegration.texinfo
字号:
or deprecated functionality.@itemize @bullet@item Mandatory Instance Methods@itemize @bullet@item @code{start(long)} -- The VM should create the native thread and startit running using the @code{run} method of the @code{VMThread} instance onwhich this method is called.@item @code{interrupt()} -- The VM should interrupt the running thread andthrow 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 deadlockoccuring 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 abnormallyand throw the specified exception. This is clearly deprecated, due to theambiguous state an abruptly-stopped thread may leave.@end itemize@item Mandatory Class Methods@itemize @bullet@item @code{currentThread()} -- Return a reference to the thread currentlybeing executed.@item @code{yield()} -- The VM should allow some other thread to run.The current thread maintains its locks even though it stops executing forthe time being.@item @code{interrupted()} -- A shortcut to obtaining the interrupted stateof the current thread.@end itemize@item Other Methods@itemize @bullet@item @code{countStackFrames()} -- Returns a count of the number of stackframes 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 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, thisincludes the context of a class (the stack) and the system properties.@menu* gnu.classpath.VMStackWalker::* gnu.classpath.VMSystemProperties::@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. Thedefault implementation consists of a @code{native} @code{static} method,@code{getClassContext()}, which obtains the class context, and two helpermethods 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 beingexecuted at that point on the stack. Thus, the first item (index 0) is theclass that contains this method.@item @code{getCallingClass()} -- A Java-based helper method which returnsthe @code{Class} object which contains the method that called the methodaccessing @code{getCallingClass()}. @item @code{getCallingClassLoader()} -- Like the last, but returning the classloader of the class.@end itemize@node gnu.classpath.VMSystemProperties,,gnu.classpath.VMStackWalker,gnu.classpath@subsection @code{gnu.classpath.VMSystemProperties}@code{VMSystemProperties} allows the VM to hook into the property creationprocess, both before and after the system properties are added by GNUClasspath. The default implementation assumes that the VM will add itsproperties first, by making the pre-initialisation method @code{native},and that the Classpath properties may then be altered by a Java-basedpost-initialisation method.As these methods are called as part of the bootstrap process, caution shouldbe used as to what classes are used, and properties should only be setusing @code{Properties.setProperty()}. Specifically, I/O classes should beavoided 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 implementationincludes a full list of properties that @emph{must} be added by the VM, butadditional VM-specific ones may also be added. @item @code{postInit(Properties)} -- Same as the last, but called after theClasspath properties have been added. The main purpose of this is to allowthe VM to alter the properties added by GNU Classpath to suit it.@end itemize@node java.util, java.io, gnu.classpath, Classpath Hooks@section java.utilThe @code{java.util} VM hooks provide links between the mix of functionalitypresent in that package, which includes collections, date and time handlingand parsing. At present, there is only one hook, which connects GNU Classpathto 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 informationvia the static method, @code{getDefaultTimeZoneId()}. The VM hook isexpected to return a @code{TimeZone} instance that represents the currenttimezone in use by the platform. The default implementation providesthis functionality for POSIX or GNU-like systems, and VMs that want thisfunctionality can keep this implementation and implement the nativemethod, @code{getSystemTimeZoneId()}. This method is only called whenobtaining the timezone name from the @code{TZ} environment variable,@code{/etc/timezone} and @code{/etc/localtime} all fail. This fallbackmechanism also means that a system which doesn't provide the above threemethods, but does provide a timezone in string form, can still use thisimplementation.@node java.io, java.security, java.util, Classpath Hooks@section java.ioThe @code{java.io} package is heavily reliant on access to the I/O facilitiesof the underlying platform. As far as its VM hooks go, they provide twoareas of functionality to GNU Classpath, these being@itemize @bullet@item File and directory queries and manipulation@item Serialization of objects@end itemizeThe first corresponds directly to most of the @code{File} class, whilethe latter underlies the functionality provided by the@code{ObjectInputStream} and @code{ObjectOutputStream}. More low-level I/Ois 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 toprobe and modify the file system using the native functions of theplatform. 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 representingthe file size.@item @code{exists(String)} -- Tests for the existence of the named fileor 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 referencesa directory.@end itemize@item Java Helper Methods@itemize @bullet@item @code{canWriteDirectory(File)} -- Checks that the directory can bewritten 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 ofthe path, by breaking off the characters after the last occurrence of theplatform's file separator.@item @code{getCanonicalForm(String)} -- This converts a UNIX path toits 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 indeserializing an object. @code{currentClassLoader()} provides the firstuser-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 butcalls the constructor of another class, which is a superclass of theobject'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)} workswith 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 usedto set the specified field in the supplied instance to the given value.A default implementation is provided for all of them, so a VM implementationis optional.@node java.security, java.net, java.io, Classpath Hooks@section java.securityThe @code{java.security} package provides support for Java's securityarchitecture. At present, @code{VMAccessController} represents the soleVM hook for this.@menu* java.security.VMAccessController::@end menu@node java.security.VMAccessController,,java.security,java.security@subsection @code{java.security.VMAccessController}The @code{AccessController} is used to perform privileged actions. Itshook class, @code{VMAccessController}, maintains the@code{AccessControlContext} and the default implementation is purelyJava-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 thestack for the current thread. This is called before a privileged actiontakes place.@item @code{popContext()} -- Removes the top context from the stack. Thisis 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 returnsthe top of the context stack.@item @code{getStack()} -- Provides access to the call stack as a pair ofarrays of classes and method names. The actual implementation returnsan empty array, indicating that there are no permissions.@end itemize@node java.net, java.nio, java.security, Classpath Hooks@section java.netThe @code{java.net} package is heavily reliant on access to the networkingfacilities of the underlying platform. The VM hooks provide informationabout the available network interfaces, and access to lookup facilitiesfor 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} methodswhich provide access to the platform's lookup facilities. All the methodsare implemented by GNU Classpath, making VM implementation optional, andare as follows:@itemize @bullet@item @code{getLocalHostname()} -- Wraps the @code{gethostname} function, andfalls back on `localhost'.@item @code{lookupInaddrAny()} -- Returns the value of @code{INADDR_ANY}.@item @code{getHostByAddr(byte[])} -- Looks up the hostname based on an IPaddress.@item @code{getHostByName(String)} -- The reverse of the last method, itreturns 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 thenetwork 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.nioThe @code{java.nio} package is part of the New I/O framework added inJava 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 VMcode is concerned, the new package needs support for low-level efficientbuffer 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 bemanipulated using primitive operations such as @code{get}, @code{put},@code{allocate} and @code{free}. A direct buffer avoids intermediatecopying, and uses native data which shouldn't be manipulated by a
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -