1 // jvm.h - Header file for private implementation information. -*- c++ -*-
3 /* Copyright (C) 1998, 1999, 2000 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
11 #ifndef __JAVA_JVM_H__
12 #define __JAVA_JVM_H__
14 #include <gcj/javaprims.h>
16 #include <java-assert.h>
17 #include <java-threads.h>
18 // Must include java-gc.h before Object.h for the implementation.
21 #include <java/lang/Object.h>
23 // Include cni.h before field.h to enable all definitions. FIXME.
25 #include <gcj/field.h>
27 /* Structure of the virtual table. */
33 void *get_finalizer() { return method
[0]; }
36 // Number of virtual methods on object. FIXME: it sucks that we have
37 // to keep this up to date by hand.
38 #define NUM_OBJECT_METHODS 5
40 // This structure is the type of an array's vtable.
41 struct _Jv_ArrayVTable
45 void *method
[NUM_OBJECT_METHODS
];
46 void *get_finalizer() { return method
[0]; }
52 jint i
; // Also stores smaller integral types.
54 jint ia
[1]; // Half of _Jv_word2.
57 #if SIZEOF_VOID_P == 8
58 // We can safely put a long or a double in here without increasing
59 // the size of _Jv_Word; we take advantage of this in the interpreter.
66 struct _Jv_Field
*field
;
67 struct _Jv_Utf8Const
*utf8
;
68 struct _Jv_ResolvedMethod
*rmethod
;
78 /* Extract a character from a Java-style Utf8 string.
79 * PTR points to the current character.
80 * LIMIT points to the end of the Utf8 string.
81 * PTR is incremented to point after the character thta gets returns.
82 * On an error, -1 is returned. */
83 #define UTF8_GET(PTR, LIMIT) \
84 ((PTR) >= (LIMIT) ? -1 \
85 : *(PTR) < 128 ? *(PTR)++ \
86 : (*(PTR)&0xE0) == 0xC0 && ((PTR)+=2)<=(LIMIT) && ((PTR)[-1]&0xC0) == 0x80 \
87 ? (((PTR)[-2] & 0x1F) << 6) + ((PTR)[-1] & 0x3F) \
88 : (*(PTR) & 0xF0) == 0xE0 && ((PTR) += 3) <= (LIMIT) \
89 && ((PTR)[-2] & 0xC0) == 0x80 && ((PTR)[-1] & 0xC0) == 0x80 \
90 ? (((PTR)[-3]&0x0F) << 12) + (((PTR)[-2]&0x3F) << 6) + ((PTR)[-1]&0x3F) \
93 extern int _Jv_strLengthUtf8(char* str
, int len
);
95 typedef struct _Jv_Utf8Const Utf8Const
;
96 _Jv_Utf8Const
*_Jv_makeUtf8Const (char *s
, int len
);
97 _Jv_Utf8Const
*_Jv_makeUtf8Const (jstring string
);
98 extern jboolean
_Jv_equalUtf8Consts (_Jv_Utf8Const
*, _Jv_Utf8Const
*);
99 extern jboolean
_Jv_equal (_Jv_Utf8Const
*, jstring
, jint
);
100 extern jboolean
_Jv_equaln (_Jv_Utf8Const
*, jstring
, jint
);
102 // FIXME: remove this define.
103 #define StringClass java::lang::String::class$
105 /* Type of pointer used as finalizer. */
106 typedef void _Jv_FinalizerFunc (jobject
);
108 /* Allocate space for a new Java object. */
109 void *_Jv_AllocObj (jsize size
, jclass cl
) __attribute__((__malloc__
));
110 /* Allocate space for an array of Java objects. */
111 void *_Jv_AllocArray (jsize size
, jclass cl
) __attribute__((__malloc__
));
112 /* Allocate space that is known to be pointer-free. */
113 void *_Jv_AllocBytes (jsize size
) __attribute__((__malloc__
));
114 /* Initialize the GC. */
115 void _Jv_InitGC (void);
116 /* Register a finalizer. */
117 void _Jv_RegisterFinalizer (void *object
, _Jv_FinalizerFunc
*method
);
118 /* Compute the GC descriptor for a class */
120 void * _Jv_BuildGCDescr(jclass
);
123 /* Allocate some unscanned, unmoveable memory. Return NULL if out of
125 void *_Jv_MallocUnchecked (jsize size
) __attribute__((__malloc__
));
127 /* Run finalizers for objects ready to be finalized.. */
128 void _Jv_RunFinalizers (void);
129 /* Run all finalizers. Should be called only before exit. */
130 void _Jv_RunAllFinalizers (void);
132 void _Jv_RunGC (void);
133 /* Disable and enable GC. */
134 void _Jv_DisableGC (void);
135 void _Jv_EnableGC (void);
137 /* Return approximation of total size of heap. */
138 long _Jv_GCTotalMemory (void);
139 /* Return approximation of total free memory. */
140 long _Jv_GCFreeMemory (void);
142 /* Set initial heap size. If SIZE==0, ignore. Should be run before
143 _Jv_InitGC. Not required to have any actual effect. */
144 void _Jv_GCSetInitialHeapSize (size_t size
);
146 /* Set maximum heap size. If SIZE==0, unbounded. Should be run
147 before _Jv_InitGC. Not required to have any actual effect. */
148 void _Jv_GCSetMaximumHeapSize (size_t size
);
150 /* External interface to setting the heap size. Parses ARG (a number
151 which can optionally have "k" or "m" appended and calls
152 _Jv_GCSetInitialHeapSize. */
153 void _Jv_SetInitialHeapSize (const char *arg
);
155 /* External interface to setting the maximum heap size. Parses ARG (a
156 number which can optionally have "k" or "m" appended and calls
157 _Jv_GCSetMaximumHeapSize. */
158 void _Jv_SetMaximumHeapSize (const char *arg
);
160 /* Allocate some unscanned bytes. Throw exception if out of memory. */
161 void *_Jv_AllocBytesChecked (jsize size
) __attribute__((__malloc__
));
163 extern "C" void JvRunMain (jclass klass
, int argc
, const char **argv
);
164 void _Jv_RunMain (const char* name
, int argc
, const char **argv
, bool is_jar
);
166 // This function is used to determine the hash code of an object.
168 _Jv_HashCode (jobject obj
)
170 // This was chosen to yield relatively well distributed results on
171 // both 32- and 64-bit architectures. Note 0x7fffffff is prime.
172 // FIXME: we assume sizeof(long) == sizeof(void *).
173 return (jint
) ((unsigned long) obj
% 0x7fffffff);
176 // Return a raw pointer to the elements of an array given the array
177 // and its element type. You might think we could just pick a single
178 // array type and use elements() on it, but we can't because we must
179 // account for alignment of the element type. When ARRAY is null, we
180 // obtain the number of bytes taken by the base part of the array.
182 _Jv_GetArrayElementFromElementType (jobject array
,
186 if (element_type
== JvPrimClass (byte
))
187 elts
= (char *) elements ((jbyteArray
) array
);
188 else if (element_type
== JvPrimClass (short))
189 elts
= (char *) elements ((jshortArray
) array
);
190 else if (element_type
== JvPrimClass (int))
191 elts
= (char *) elements ((jintArray
) array
);
192 else if (element_type
== JvPrimClass (long))
193 elts
= (char *) elements ((jlongArray
) array
);
194 else if (element_type
== JvPrimClass (boolean
))
195 elts
= (char *) elements ((jbooleanArray
) array
);
196 else if (element_type
== JvPrimClass (char))
197 elts
= (char *) elements ((jcharArray
) array
);
198 else if (element_type
== JvPrimClass (float))
199 elts
= (char *) elements ((jfloatArray
) array
);
200 else if (element_type
== JvPrimClass (double))
201 elts
= (char *) elements ((jdoubleArray
) array
);
203 elts
= (char *) elements ((jobjectArray
) array
);
207 extern "C" void _Jv_ThrowBadArrayIndex (jint bad_index
);
208 extern "C" void _Jv_ThrowNullPointerException (void);
209 extern "C" jobject
_Jv_NewArray (jint type
, jint size
)
210 __attribute__((__malloc__
));
211 extern "C" jobject
_Jv_NewMultiArray (jclass klass
, jint dims
, ...)
212 __attribute__((__malloc__
));
213 extern "C" void *_Jv_CheckCast (jclass klass
, jobject obj
);
214 extern "C" void *_Jv_LookupInterfaceMethod (jclass klass
, Utf8Const
*name
,
215 Utf8Const
*signature
);
216 extern "C" void *_Jv_LookupInterfaceMethodIdx (jclass klass
, jclass iface
,
218 extern "C" void _Jv_CheckArrayStore (jobject array
, jobject obj
);
219 extern "C" void _Jv_RegisterClass (jclass klass
);
220 extern "C" void _Jv_RegisterClasses (jclass
*classes
);
221 extern void _Jv_UnregisterClass (_Jv_Utf8Const
*, java::lang::ClassLoader
*);
223 extern jclass
_Jv_FindClass (_Jv_Utf8Const
*name
,
224 java::lang::ClassLoader
*loader
);
225 extern jclass
_Jv_FindClassFromSignature (char *,
226 java::lang::ClassLoader
*loader
);
227 extern void _Jv_GetTypesFromSignature (jmethodID method
,
228 jclass declaringClass
,
229 JArray
<jclass
> **arg_types_out
,
230 jclass
*return_type_out
);
232 extern jobject
_Jv_CallAnyMethodA (jobject obj
, jclass return_type
,
233 jmethodID meth
, jboolean is_constructor
,
234 JArray
<jclass
> *parameter_types
,
238 extern jthrowable
_Jv_CallAnyMethodA (jobject obj
,
241 jboolean is_constructor
,
242 JArray
<jclass
> *parameter_types
,
246 extern jobject
_Jv_NewMultiArray (jclass
, jint ndims
, jint
* dims
)
247 __attribute__((__malloc__
));
249 /* Checked divide subroutines. */
252 jint
_Jv_divI (jint
, jint
);
253 jint
_Jv_remI (jint
, jint
);
254 jlong
_Jv_divJ (jlong
, jlong
);
255 jlong
_Jv_remJ (jlong
, jlong
);
258 /* get/set the name of the running executable. */
259 extern char *_Jv_ThisExecutable (void);
260 extern void _Jv_ThisExecutable (const char *);
262 /* Return a pointer to a symbol in executable or loaded library. */
263 void *_Jv_FindSymbolInExecutable (const char *);
265 /* Initialize JNI. */
266 extern void _Jv_JNI_Init (void);
268 /* Get or set the per-thread JNIEnv used by the invocation API. */
269 _Jv_JNIEnv
*_Jv_GetCurrentJNIEnv ();
270 void _Jv_SetCurrentJNIEnv (_Jv_JNIEnv
*);
273 _Jv_JavaVM
*_Jv_GetJavaVM ();
278 extern void (*_Jv_JVMPI_Notify_OBJECT_ALLOC
) (JVMPI_Event
*event
);
279 extern void (*_Jv_JVMPI_Notify_THREAD_START
) (JVMPI_Event
*event
);
280 extern void (*_Jv_JVMPI_Notify_THREAD_END
) (JVMPI_Event
*event
);
283 #endif /* __JAVA_JVM_H__ */