jvm.h revision 196
/*
* Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
#ifndef _JAVASOFT_JVM_H_
#define _JAVASOFT_JVM_H_
// HotSpot integration note:
//
// This file and jvm.h used with the JDK are identical,
// except for the three includes removed below and the
// SUPPORT_OLD_REFLECTION sections cut out of the JDK's jvm.h.
// #include "jni.h"
// #include "jvm_md.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* This file contains additional functions exported from the VM.
* These functions are complementary to the standard JNI support.
* There are three parts to this file:
*
* First, this file contains the VM-related functions needed by native
* libraries in the standard Java API. For example, the java.lang.Object
* class needs VM-level functions that wait for and notify monitors.
*
* Second, this file contains the functions and constant definitions
* needed by the byte code verifier and class file format checker.
* These functions allow the verifier and format checker to be written
* in a VM-independent way.
*
* Third, this file contains various I/O and nerwork operations needed
* by the standard Java I/O and network APIs.
*/
/*
* Bump the version number when either of the following happens:
*
* 1. There is a change in JVM_* functions.
*
* 2. There is a change in the contract between VM and Java classes.
* For example, if the VM relies on a new private field in Thread
* class.
*/
#define JVM_INTERFACE_VERSION 4
JVM_GetInterfaceVersion(void);
/*************************************************************************
PART 1: Functions for Native Libraries
************************************************************************/
/*
* java.lang.Object
*/
/*
* java.lang.String
*/
/*
* java.lang.System
*/
/*
* java.io.File
*/
JVM_OnExit(void (*func)(void));
/*
* java.lang.Runtime
*/
JVM_GC(void);
/* Returns the number of real-time milliseconds that have elapsed since the
* least-recently-inspected heap object was last inspected by the garbage
* collector.
*
* For simple stop-the-world collectors this value is just the time
* since the most recent collection. For generational collectors it is the
* time since the oldest generation was most recently collected. Other
* collectors are free to return a pessimistic estimate of the elapsed time, or
* simply the time since the last full collection was performed.
*
* Note that in the presence of reference objects, a given object that is no
* longer strongly reachable may have to be inspected multiple times before it
* can be reclaimed.
*/
JVM_MaxObjectInspectionAge(void);
JVM_TotalMemory(void);
JVM_FreeMemory(void);
JVM_MaxMemory(void);
JVM_ActiveProcessorCount(void);
JVM_LoadLibrary(const char *name);
JVM_UnloadLibrary(void * handle);
/*
* java.lang.Float and java.lang.Double
*/
/*
* java.lang.Throwable
*/
/*
* java.lang.Compiler
*/
/*
* java.lang.Thread
*/
/* getStackTrace() and getAllStackTraces() method */
/*
* java.lang.SecurityManager
*/
/*
* java.lang.Package
*/
/*
* java.io.ObjectInputStream
*/
/*
* This function has been deprecated and should not be considered
* part of the specified JVM interface.
*/
/*
* java.lang.reflect.Array
*/
unsigned char vCode);
/*
* java.lang.Class and java.lang.ClassLoader
*/
/*
* Returns the class in which the code invoking the native method
* belongs.
*
* Note that in JDK 1.1, native methods did not create a frame.
* In 1.2, they do. Therefore native methods like Class.forName
* can no longer look at the current frame for the caller class.
*/
/*
* Find primitive classes
* utf: class name
*/
/*
* Link the class
*/
/*
* Find a class from a given class loader. Throw ClassNotFoundException
* or NoClassDefFoundError depending on the value of the last
* argument.
*/
/*
* Find a class from a given class.
*/
/* Find a loaded class cached by the VM */
/* Define a class */
/* Define a class with a source (added in JDK1.5) */
const char *source);
/*
* Reflection support functions
*/
/* Generics support (JDK 1.5) */
/* Annotations support (JDK 1.5) */
/* Annotations support (JDK 1.6) */
// field is a handle to a java.lang.reflect.Field object
// method is a handle to a java.lang.reflect.Method object
// method is a handle to a java.lang.reflect.Method object
// method is a handle to a java.lang.reflect.Method object
/*
* New (JDK 1.4) reflection implementation
*/
/* Differs from JVM_GetClassModifiers in treatment of inner classes.
This returns the access flags for the class as specified in the
class file rather than searching the InnerClasses attribute (if
present) to find the source-level access flags. Only the values of
the low 13 bits (i.e., a mask of 0x1FFF) are guaranteed to be
valid. */
/*
* Constant pool access; currently used to implement reflective access to annotations (JDK 1.5)
*/
/*
* java.security.*
*/
/*
* Signal support, used to implement the shutdown sequence. Every VM must
* support JVM_SIGINT and JVM_SIGTERM, raising the former for user interrupts
* (^C) and the latter for external termination (kill, system shutdown, etc.).
* Other platform-dependent signal values may also be supported.
*/
JVM_FindSignal(const char *name);
/*
* Retrieve the assertion directives for the specified class.
*/
/*
* Retrieve the assertion directives from the VM.
*/
/*
* sun.misc.AtomicLong
*/
JVM_SupportsCX8(void);
/*
* com.sun.dtrace.jsdt support
*/
#define JVM_TRACING_DTRACE_VERSION 1
/*
* Structure to pass one probe description to JVM.
*
* The VM will overwrite the definition of the referenced method with
* code that will fire the probe.
*/
typedef struct {
/**
* Encapsulates the stability ratings for a DTrace provider field
*/
typedef struct {
/*
* Structure to pass one provider description to JVM
*/
typedef struct {
/*
* Get the version number the JVM was built with
*/
/*
* Register new probe with given signature, return global handle
*
* The version passed in is the version that the library code was
* built with.
*/
/*
* Check JSDT probe
*/
/*
* Destroy custom DOF
*/
/*
* Check to see if DTrace is supported by OS
*/
/*************************************************************************
PART 2: Support for the Verifier and Class File Format Checker
************************************************************************/
/*
* Return the class name in UTF format. The result is valid
* until JVM_ReleaseUTf is called.
*
* The caller must treat the string as a constant and not modify it
* in any way.
*/
/*
* Returns the constant pool types in the buffer provided by "types."
*/
/*
* Returns the number of Constant Pool entries.
*/
/*
* Returns the number of *declared* fields or methods.
*/
/*
* Returns the CP indexes of exceptions raised by a given method.
* Places the result in the given buffer.
*
* The method is identified by method_index.
*/
unsigned short *exceptions);
/*
* Returns the number of exceptions raised by a given method.
* The method is identified by method_index.
*/
/*
* Returns the byte code sequence of a given method.
* Places the result in the given buffer.
*
* The method is identified by method_index.
*/
unsigned char *code);
/*
* Returns the length of the byte code sequence of a given method.
* The method is identified by method_index.
*/
/*
* A structure used to a capture exception table entry in a Java method.
*/
typedef struct {
/*
* Returns the exception table entry at entry_index of a given method.
* Places the result in the given buffer.
*
* The method is identified by method_index.
*/
/*
* Returns the length of the exception table of a given method.
* The method is identified by method_index.
*/
/*
* Returns the modifiers of a given field.
* The field is identified by field_index.
*/
/*
* Returns the modifiers of a given method.
* The method is identified by method_index.
*/
/*
* Returns the number of local variables of a given method.
* The method is identified by method_index.
*/
/*
* Returns the number of arguments (including this pointer) of a given method.
* The method is identified by method_index.
*/
/*
* Returns the maximum amount of stack (in words) used by a given method.
* The method is identified by method_index.
*/
/*
* Is a given method a constructor.
* The method is identified by method_index.
*/
/*
* Returns the name of a given method in UTF format.
* The result remains valid until JVM_ReleaseUTF is called.
*
* The caller must treat the string as a constant and not modify it
* in any way.
*/
/*
* Returns the signature of a given method in UTF format.
* The result remains valid until JVM_ReleaseUTF is called.
*
* The caller must treat the string as a constant and not modify it
* in any way.
*/
/*
* Returns the name of the field refered to at a given constant pool
* index.
*
* The result is in UTF format and remains valid until JVM_ReleaseUTF
* is called.
*
* The caller must treat the string as a constant and not modify it
* in any way.
*/
/*
* Returns the name of the method refered to at a given constant pool
* index.
*
* The result is in UTF format and remains valid until JVM_ReleaseUTF
* is called.
*
* The caller must treat the string as a constant and not modify it
* in any way.
*/
/*
* Returns the signature of the method refered to at a given constant pool
* index.
*
* The result is in UTF format and remains valid until JVM_ReleaseUTF
* is called.
*
* The caller must treat the string as a constant and not modify it
* in any way.
*/
/*
* Returns the signature of the field refered to at a given constant pool
* index.
*
* The result is in UTF format and remains valid until JVM_ReleaseUTF
* is called.
*
* The caller must treat the string as a constant and not modify it
* in any way.
*/
/*
* Returns the class name refered to at a given constant pool index.
*
* The result is in UTF format and remains valid until JVM_ReleaseUTF
* is called.
*
* The caller must treat the string as a constant and not modify it
* in any way.
*/
/*
* Returns the class name refered to at a given constant pool index.
*
* The constant pool entry must refer to a CONSTANT_Fieldref.
*
* The result is in UTF format and remains valid until JVM_ReleaseUTF
* is called.
*
* The caller must treat the string as a constant and not modify it
* in any way.
*/
/*
* Returns the class name refered to at a given constant pool index.
*
* The constant pool entry must refer to CONSTANT_Methodref or
* CONSTANT_InterfaceMethodref.
*
* The result is in UTF format and remains valid until JVM_ReleaseUTF
* is called.
*
* The caller must treat the string as a constant and not modify it
* in any way.
*/
/*
* Returns the modifiers of a field in calledClass. The field is
* referred to in class cb at constant pool entry index.
*
* The caller must treat the string as a constant and not modify it
* in any way.
*
* Returns -1 if the field does not exist in calledClass.
*/
/*
* Returns the modifiers of a method in calledClass. The method is
* referred to in class cb at constant pool entry index.
*
* Returns -1 if the method does not exist in calledClass.
*/
/*
* Releases the UTF string obtained from the VM.
*/
JVM_ReleaseUTF(const char *utf);
/*
* Compare if two classes are in the same package.
*/
/* Constants in class files */
#define JVM_ACC_PUBLIC_BIT 0
#define JVM_ACC_PRIVATE_BIT 1
#define JVM_ACC_PROTECTED_BIT 2
#define JVM_ACC_STATIC_BIT 3
#define JVM_ACC_FINAL_BIT 4
#define JVM_ACC_SYNCHRONIZED_BIT 5
#define JVM_ACC_SUPER_BIT 5
#define JVM_ACC_VOLATILE_BIT 6
#define JVM_ACC_BRIDGE_BIT 6
#define JVM_ACC_TRANSIENT_BIT 7
#define JVM_ACC_VARARGS_BIT 7
#define JVM_ACC_NATIVE_BIT 8
#define JVM_ACC_INTERFACE_BIT 9
#define JVM_ACC_ABSTRACT_BIT 10
#define JVM_ACC_STRICT_BIT 11
#define JVM_ACC_SYNTHETIC_BIT 12
#define JVM_ACC_ANNOTATION_BIT 13
#define JVM_ACC_ENUM_BIT 14
enum {
JVM_CONSTANT_Utf8 = 1,
JVM_CONSTANT_Unicode, /* unused */
};
/* Used in the newarray instruction. */
#define JVM_T_BOOLEAN 4
#define JVM_T_CHAR 5
#define JVM_T_FLOAT 6
#define JVM_T_DOUBLE 7
#define JVM_T_BYTE 8
#define JVM_T_SHORT 9
#define JVM_T_INT 10
#define JVM_T_LONG 11
/* JVM method signatures */
#define JVM_SIGNATURE_ARRAY '['
#define JVM_SIGNATURE_BYTE 'B'
#define JVM_SIGNATURE_CHAR 'C'
#define JVM_SIGNATURE_CLASS 'L'
#define JVM_SIGNATURE_ENDCLASS ';'
#define JVM_SIGNATURE_ENUM 'E'
#define JVM_SIGNATURE_FLOAT 'F'
#define JVM_SIGNATURE_DOUBLE 'D'
#define JVM_SIGNATURE_FUNC '('
#define JVM_SIGNATURE_ENDFUNC ')'
#define JVM_SIGNATURE_INT 'I'
#define JVM_SIGNATURE_LONG 'J'
#define JVM_SIGNATURE_SHORT 'S'
#define JVM_SIGNATURE_VOID 'V'
#define JVM_SIGNATURE_BOOLEAN 'Z'
/*
* A function defined by the byte-code verifier and called by the VM.
* This is not a function implemented in the VM.
*
* Returns JNI_FALSE if verification fails. A detailed error message
* will be places in msg_buf, whose length is specified by buf_len.
*/
char * msg_buf,
/*
* Support for a VM-independent class format checker.
*/
typedef struct {
unsigned long code; /* byte code */
unsigned long excs; /* exceptions */
unsigned long etab; /* catch table */
unsigned long lnum; /* line number */
unsigned long lvar; /* local vars */
typedef struct {
unsigned int constants; /* constant pool */
unsigned int fields;
unsigned int methods;
unsigned int interfaces;
unsigned int fields2; /* number of static 2-word fields */
unsigned int innerclasses; /* # of records in InnerClasses attr */
/*
* Functions defined in libjava.so to perform string conversions.
*
*/
/* This is the function defined in libjava.so that performs class
* format checks. This functions fills in size information about
* the class file and returns:
*
* 0: good
* -1: out of memory
* -2: bad format
* -3: unsupported version
* -4: bad class name
*/
unsigned char *data,
unsigned int data_size,
char *message_buffer,
#define JVM_RECOGNIZED_CLASS_MODIFIERS (JVM_ACC_PUBLIC | \
JVM_ACC_FINAL | \
JVM_ACC_SUPER | \
JVM_ACC_ABSTRACT | \
JVM_ACC_ENUM | \
#define JVM_RECOGNIZED_FIELD_MODIFIERS (JVM_ACC_PUBLIC | \
JVM_ACC_PRIVATE | \
JVM_ACC_STATIC | \
JVM_ACC_FINAL | \
JVM_ACC_VOLATILE | \
JVM_ACC_ENUM | \
#define JVM_RECOGNIZED_METHOD_MODIFIERS (JVM_ACC_PUBLIC | \
JVM_ACC_PRIVATE | \
JVM_ACC_STATIC | \
JVM_ACC_FINAL | \
JVM_ACC_BRIDGE | \
JVM_ACC_VARARGS | \
JVM_ACC_NATIVE | \
JVM_ACC_ABSTRACT | \
JVM_ACC_STRICT | \
/*
* This is the function defined in libjava.so to perform path
* canonicalization. VM call this function before opening jar files
* to load system classes.
*
*/
/*************************************************************************
PART 3: I/O and Network Support
************************************************************************/
/* Note that the JVM IO functions are expected to return JVM_IO_ERR
* when there is any kind of error. The caller can then use the
* platform specific support (e.g., errno) to get the detailed
* error info. The JVM_GetLastErrorString procedure may also be used
* to obtain a descriptive error string.
*/
#define JVM_IO_ERR (-1)
/* For interruptible IO. Returning JVM_IO_INTR indicates that an IO
* operation has been disrupted by Thread.interrupt. There are a
* number of technical difficulties related to interruptible IO that
* need to be solved. For example, most existing programs do not handle
* InterruptedIOExceptions specially, they simply treat those as any
* IOExceptions, which typically indicate fatal errors.
*
* There are also two modes of operation for interruptible IO. In the
* resumption mode, an interrupted IO operation is guaranteed not to
* have any side-effects, and can be restarted. In the termination mode,
* an interrupted IO operation corrupts the underlying IO stream, so
* that the only reasonable operation on an interrupted stream is to
* close that stream. The resumption mode seems to be impossible to
* implement on Win32 and Solaris. Implementing the termination mode is
* easier, but it's not clear that's the right semantics.
*
* using a compile-time flag on Solaris. Third-party JVM ports do not
* need to implement interruptible IO.
*/
#define JVM_IO_INTR (-2)
/* Write a string into the given buffer, in the platform's local encoding,
* that describes the most recent system-level error to occur in this thread.
* Return the length of the string or zero if no error occurred.
*/
/*
* Convert a pathname into native format. This function does syntactic
* cleanup, such as removing redundant separator characters. It modifies
* the given pathname string in place.
*/
JVM_NativePath(char *);
/*
* JVM I/O error codes
*/
#define JVM_EEXIST -100
/*
* Open a file descriptor. This function returns a negative error code
* on error, and a non-negative integer that is the file descriptor on
* success.
*/
/*
* Close a file descriptor. This function returns -1 on error, and 0
* on success.
*
* fd the file descriptor to close.
*/
/*
* Read data from a file decriptor into a char array.
*
* fd the file descriptor to read from.
* buf the buffer where to put the read data.
* nbytes the number of bytes to read.
*
* This function returns -1 on error, and 0 on success.
*/
/*
* Write data from a char array to a file decriptor.
*
* fd the file descriptor to read from.
* buf the buffer from which to fetch the data.
* nbytes the number of bytes to write.
*
* This function returns -1 on error, and 0 on success.
*/
/*
* Returns the number of bytes available for reading from a given file
* descriptor
*/
/*
* Move the file descriptor pointer from whence by offset.
*
* fd the file descriptor to move.
* offset the number of bytes to move it by.
* whence the start from where to move it.
*
* This function returns the resulting pointer location.
*/
/*
* Set the length of the file associated with the given descriptor to the given
* length. If the new length is longer than the current length then the file
* is extended; the contents of the extended portion are not defined. The
* value of the file pointer is undefined after this procedure returns.
*/
/*
* Synchronize the file descriptor's in memory state with that of the
* physical device. Return of -1 is an error, 0 is OK.
*/
/*
* Networking library support
*/
JVM_InitializeSocketLibrary(void);
struct sockaddr;
/*
* These routines are only reentrant on Windows
*/
#ifdef _WINDOWS
JVM_GetProtoByName(char* name);
JVM_GetHostByName(char* name);
#endif /* _WINDOWS */
/*
* The standard printing functions supported by the Java VM. (Should they
* be renamed to JVM_* in the future?
*/
/*
* BE CAREFUL! The following functions do not implement the
* full feature set of standard C printf formats.
*/
int
int
int
int
JVM_RawMonitorCreate(void);
JVM_RawMonitorDestroy(void *mon);
JVM_RawMonitorEnter(void *mon);
JVM_RawMonitorExit(void *mon);
#ifdef SUPPORT_OLD_REFLECTION
/*
* Support for old native code-based (pre-JDK 1.4) reflection implementation.
* Disabled by default in the product build.
*
* See reflection.hpp for information on SUPPORT_OLD_REFLECTION
*/
/*
* reflecting fields and methods.
* which: 0 --- MEMBER_PUBLIC
* 1 --- MEMBER_DECLARED
* NOTE: absent in product build by default
*/
/*
* Implements Class.newInstance
*/
/*
* java.lang.reflect.Field
*/
unsigned char wCode);
unsigned char vCode);
/*
* java.lang.reflect.Method
*/
/*
* java.lang.reflect.Constructor
*/
#endif /* SUPPORT_OLD_REFLECTION */
/*
* java.lang.management support
*/
/*
* com.sun.tools.attach.VirtualMachine support
*
* Initialize the agent properties with the properties maintained in the VM.
*/
/* Generics reflection support.
*
* Returns information about the given class's EnclosingMethod
* attribute, if present, or null if the class had no enclosing
* method.
*
* If non-null, the returned array contains three elements. Element 0
* is the java.lang.Class of which the enclosing method is a member,
* and elements 1 and 2 are the java.lang.Strings for the enclosing
* method's name and descriptor, respectively.
*/
/*
* Java thread state support
*/
enum {
};
/*
* Returns an array of the threadStatus values representing the
* given Java thread state. Returns NULL if the VM version is
* incompatible with the JDK or doesn't support the given
* Java thread state.
*/
/*
* Returns an array of the substate names representing the
* given Java thread state. Returns NULL if the VM version is
* incompatible with the JDK or the VM doesn't support
* the given Java thread state.
* values must be the jintArray returned from JVM_GetThreadStateValues
* and javaThreadState.
*/
/* =========================================================================
* The following defines a private JVM interface that the JDK can query
* for the JVM version and capabilities. sun.misc.Version defines
* the methods for getting the VM version and its capabilities.
*
* When a new bit is added, the following should be updated to provide
* access to the new capability:
* HS: JVM_GetVersionInfo and Abstract_VM_Version class
* SDK: Version class
*
* Similary, a private JDK interface JDK_GetVersionInfo0 is defined for
* JVM to query for the JDK version and capabilities.
*
* When a new bit is added, the following should be updated to provide
* access to the new capability:
* HS: JDK_Version class
* SDK: JDK_GetVersionInfo0
*
* ==========================================================================
*/
typedef struct {
/* HotSpot Express VM version string:
* <major>.<minor>-bxx[-<identifier>][-<debug_flavor>]
*/
unsigned int jvm_version; /* Consists of major.minor.0.build */
unsigned int reserved1 : 16;
unsigned int reserved2;
/* The following bits represents JVM supports that JDK has dependency on.
* JDK can use these bits to determine which JVM version
* and support it has to maintain runtime compatibility.
*
* When a new bit is added in a minor or update release, make sure
*/
unsigned int is_attachable : 1;
unsigned int is_kernel_jvm : 1;
unsigned int : 30;
unsigned int : 32;
unsigned int : 32;
// Micro version is 0 in HotSpot Express VM (set in jvm.cpp).
/* Build number is available in all HotSpot Express VM builds.
* It is defined in make/hotspot_version file.
*/
typedef struct {
// Naming convention of RE build version string: n.n.n[_uu[c]][-<identifier>]-bxx
unsigned int jdk_version; /* Consists of major, minor, micro (n.n.n) */
/* and build number (xx) */
unsigned int reserved1 : 16;
unsigned int reserved2;
/* The following bits represents new JDK supports that VM has dependency on.
* VM implementation can use these bits to determine which JDK version
* and support it has to maintain runtime compatibility.
*
* When a new bit is added in a minor or update release, make sure
*/
unsigned int thread_park_blocker : 1;
unsigned int : 31;
unsigned int : 32;
unsigned int : 32;
/* Build number is available only for RE build (i.e. JDK_BUILD_NUMBER is set to bNN)
* It will be zero for internal builds.
*/
/*
* This is the function JDK_GetVersionInfo0 defined in libjava.so
* that is dynamically looked up by JVM.
*/
/*
* This structure is used by the launcher to get the default thread
* stack size from the VM using JNI_GetDefaultJavaVMInitArgs() with a
* version of 1.1. As it is not supported otherwise, it has been removed
* from jni.h
*/
typedef struct JDK1_1InitArgs {
char **properties;
char *classpath;
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif /* !_JAVASOFT_JVM_H_ */