📄 vmintegration.texinfo
字号:
@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 suppliedchecked exception, without declaring it.@end itemize@item 1.1@itemize @bullet@item @code{isInstance(Class,Object)} -- This is a reflection-based equivalentof 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 simplya 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 whichrepresents 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 encodesthe class' modifiers, such as @code{public}. Again, this relates toinformation stored in the class file.@item @code{getDeclaringClass(Class)} -- Returns the class that declaredan inner or member class, or @code{null} if the instance refers to a top-levelclass.@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} facilitiessuch as making a clone, getting the class of the object and the wait/notifysemantics. This is accomplished using the following @code{native}methods.@itemize @bullet@item @code{getClass(Object)} -- Returns the @code{Class} instance for theobject. @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 thespecified 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 waitingfor a lock on the specified object arbitrarily, and wake it. If the currentthread 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 areawakened.@item @code{wait(Object,long,int)} -- The VM should set the current threadinto a waiting state, which persists until it receives a notify signal or thespecified time (in milliseconds and nanoseconds) is exceeded. The nanosecondsrestriction may be ignored if such granularity is not available, and a@code{IllegalMonitorStateException} should be thrown if the current threaddoesn'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 andprimitive classes, as well as handling resources, packages and assertions.The class is a mixture of @code{native} methods and Java-basedimplementations, 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 thesupplied class.@item @code{loadClass(name,boolean)} -- Load a class using the bootstraploader.@item @code{getPrimitiveClass(char)} -- The VM should provide a @code{Class}implementation for one of the primitive classes. The supplied charactermatches 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 ofURLs 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 fileURLs that refer to join the directory with the resource name (whether or notit actually exists).@item @code{getPackage(String)} -- Always returns null, which may be suitableif 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 implementationexists (returning an empty array) which may be replaced if support isrequired. @item @code{defaultAssertionStatus()} -- A stub which can be implementedby 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 statusvalues. 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 classloader. The VM may wish to replace it if it wishes to supply its own customsystem 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 thesystem 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 defaultimplementation also provides some helper methods to simplify streamcreation. @itemize @bullet@item Native Methods@itemize @bullet@item @code{arraycopy(Object,int,Object,int,int)} -- The VM should copya 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 codeand 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 environmentvariable.@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 bufferedfile input stream. VMs may choose to create the stream from the descriptordifferently rather than using this method.@item @code{makeStandardOutputStream()} -- Helps provide the functionality of@code{System.out} by wrapping the appropriate file descriptor in a bufferedfile output stream. VMs may choose to create the stream from the descriptordifferently rather than using this method.@item @code{makeStandardErrorStream()} -- Helps provide the functionality of@code{System.err} by wrapping the appropriate file descriptor in a bufferedfile output stream. VMs may choose to create the stream from the descriptordifferently rather than using this method.@end itemize@end itemizeClasspath 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 itemizemaking 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 eitherwhen a @code{Throwable} is created or the @code{fillInStackTrace()} method iscalled (i.e. when the actual stack trace is needed, as a lot of exceptions arenever actually used). The actual class has two @code{native} methods,one (@code{fillInStackTrace()}) being a method of the class used to obtaininstances, and the other an instance method, @code{getStackTrace()}.@itemize @bullet@item @code{fillInStackTrace(Throwable)} -- The VM should return the currentexecution 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 thisfunctionality.@item @code{getStackTrace()} -- This is used to create a real@code{StackTraceElement} array for the exception, using the state datastored 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 provideJIT compilation support. The default implementation is simply a seriesof stubs. The property, @code{java.compiler}, should point to a librarycontaining the function @code{java_lang_Compiler_start()} if such supportis to be provided.@itemize @bullet@item @code{compileClass(Class)} -- Invoke the compiler to compile the specificclass, returning @code{true} if successful.@item @code{compileClasses(String)} -- The compiler should compile the classesmatching the specified string, again returning @code{true} on success.@item @code{command(Object)} -- The object represents a command given to thecompiler, 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 parsingof doubles.@itemize @bullet@item @code{doubleToLongBits(double)} -- Converts the double to the IEEE 754bit layout, collapsing NaNs to @code{0x7ff8000000000000L}.@item @code{doubleToRawLongBits(double)} -- Same as the above, but preservesNaNs.@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 withoutdata loss.@item @code{toString(double,boolean)} -- Converts the double to a string,giving a shorter value if the flag @code{isFloat} is @code{true}, indicatingthat 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 cacheof the static field IDs. The default @code{VMDouble} implementation has astatic initializer which loads the JNI library and calls this method.@item @code{parseDouble} -- Turn the string into a usable double value.@end itemizeClasspath provides native implementations of all these, making VMimplementation 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 754bit layout, collapsing NaNs to @code{0x7fc00000}.@item @code{floatToRawIntBits(float)} -- Same as the above, but preservesNaNs.@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 withoutdata loss.@end itemizeClasspath provides native implementations of all these, making VMimplementation 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 thedefault implementation, threads are spawned and reaped by @code{ProcessThread}.A constructor creates a new @code{VMProcess}, which extends rather thancomplements @code{Process}, using an array of arguments, an array ofenvironment variables and a working directory. The instance maintainssystem input, output and error streams linked to the external process.Three @code{native} methods are used, and implementations are providedfor all three by Classpath, making VM implementation optional. These usethe POSIX functions, @code{fork()}, @code{waitpid()} and @code{kill()}.@itemize @bullet@item @code{nativeSpawn(String[],String[],File)} -- The VM should create anew process which uses the specified command-line arguments, environmentvariables and working directory. Unlike the other two methods, thismethod is linked to an instance, and must call @code{setProcessInfo()} withthe results before returning.@item @code{nativeReap()} -- This is called to perform a reap of anyzombie processes, and should not block, instead returning a boolean as towhether 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 methodswhich divulge information about the runtime or invoke certainoperations. 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 ownshutdown 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 bydefault, 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -