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 // FIXME: __builtin_expect doesn't work yet.
15 #define __builtin_expect(A,B) (A)
17 #include <gcj/javaprims.h>
19 #include <java-assert.h>
20 #include <java-threads.h>
21 // Must include java-gc.h before Object.h for the implementation.
24 #include <java/lang/Object.h>
26 // Include cni.h before field.h to enable all definitions. FIXME.
28 #include <gcj/field.h>
30 /* Structure of the virtual table. */
37 // Number of virtual methods on object. FIXME: it sucks that we have
38 // to keep this up to date by hand.
39 #define NUM_OBJECT_METHODS 5
41 // This structure is the type of an array's vtable.
42 struct _Jv_ArrayVTable
45 // `+1' because there is an extra slot for C++ RTTI compatibility.
46 void *method[NUM_OBJECT_METHODS + 1];
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 #define StringClass _CL_Q34java4lang6String
103 extern java::lang::Class StringClass;
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) __attribute__((__malloc__));
110 /* Allocate space for an array of Java objects. */
111 void *_Jv_AllocArray (jsize size) __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);
119 /* Allocate some unscanned, unmoveable memory. Return NULL if out of
121 void *_Jv_MallocUnchecked (jsize size) __attribute__((__malloc__));
123 /* Run finalizers for objects ready to be finalized.. */
124 void _Jv_RunFinalizers (void);
125 /* Run all finalizers. Should be called only before exit. */
126 void _Jv_RunAllFinalizers (void);
128 void _Jv_RunGC (void);
129 /* Disable and enable GC. */
130 void _Jv_DisableGC (void);
131 void _Jv_EnableGC (void);
133 /* Return approximation of total size of heap. */
134 long _Jv_GCTotalMemory (void);
135 /* Return approximation of total free memory. */
136 long _Jv_GCFreeMemory (void);
138 /* Set initial heap size. If SIZE==0, ignore. Should be run before
139 _Jv_InitGC. Not required to have any actual effect. */
140 void _Jv_GCSetInitialHeapSize (size_t size);
142 /* Set maximum heap size. If SIZE==0, unbounded. Should be run
143 before _Jv_InitGC. Not required to have any actual effect. */
144 void _Jv_GCSetMaximumHeapSize (size_t size);
146 /* External interface to setting the heap size. Parses ARG (a number
147 which can optionally have "k" or "m" appended and calls
148 _Jv_GCSetInitialHeapSize. */
149 void _Jv_SetInitialHeapSize (const char *arg);
151 /* External interface to setting the maximum heap size. Parses ARG (a
152 number which can optionally have "k" or "m" appended and calls
153 _Jv_GCSetMaximumHeapSize. */
154 void _Jv_SetMaximumHeapSize (const char *arg);
156 /* Allocate some unscanned bytes. Throw exception if out of memory. */
157 void *_Jv_AllocBytesChecked (jsize size) __attribute__((__malloc__));
159 extern "C" void JvRunMain (jclass klass, int argc, const char **argv);
160 void _Jv_RunMain (const char* name, int argc, const char **argv);
162 // This function is used to determine the hash code of an object.
164 _Jv_HashCode (jobject obj)
169 // Return a raw pointer to the elements of an array given the array
170 // and its element type. You might think we could just pick a single
171 // array type and use elements() on it, but we can't because we must
172 // account for alignment of the element type. When ARRAY is null, we
173 // obtain the number of bytes taken by the base part of the array.
175 _Jv_GetArrayElementFromElementType (jobject array,
179 if (element_type == JvPrimClass (byte))
180 elts = (char *) elements ((jbyteArray) array);
181 else if (element_type == JvPrimClass (short))
182 elts = (char *) elements ((jshortArray) array);
183 else if (element_type == JvPrimClass (int))
184 elts = (char *) elements ((jintArray) array);
185 else if (element_type == JvPrimClass (long))
186 elts = (char *) elements ((jlongArray) array);
187 else if (element_type == JvPrimClass (boolean))
188 elts = (char *) elements ((jbooleanArray) array);
189 else if (element_type == JvPrimClass (char))
190 elts = (char *) elements ((jcharArray) array);
191 else if (element_type == JvPrimClass (float))
192 elts = (char *) elements ((jfloatArray) array);
193 else if (element_type == JvPrimClass (double))
194 elts = (char *) elements ((jdoubleArray) array);
196 elts = (char *) elements ((jobjectArray) array);
200 extern "C" void _Jv_ThrowBadArrayIndex (jint bad_index);
201 extern "C" void _Jv_ThrowNullPointerException (void);
202 extern "C" jobject _Jv_NewArray (jint type, jint size)
203 __attribute__((__malloc__));
204 extern "C" jobject _Jv_NewMultiArray (jclass klass, jint dims, ...)
205 __attribute__((__malloc__));
206 extern "C" void *_Jv_CheckCast (jclass klass, jobject obj);
207 extern "C" void *_Jv_LookupInterfaceMethod (jclass klass, Utf8Const *name,
208 Utf8Const *signature);
209 extern "C" void *_Jv_LookupInterfaceMethodIdx (jclass klass, jclass iface,
211 extern "C" void _Jv_CheckArrayStore (jobject array, jobject obj);
212 extern "C" void _Jv_RegisterClass (jclass klass);
213 extern "C" void _Jv_RegisterClasses (jclass *classes);
214 extern void _Jv_UnregisterClass (_Jv_Utf8Const*, java::lang::ClassLoader*);
216 extern jclass _Jv_FindClass (_Jv_Utf8Const *name,
217 java::lang::ClassLoader *loader);
218 extern jclass _Jv_FindClassFromSignature (char *,
219 java::lang::ClassLoader *loader);
220 extern void _Jv_GetTypesFromSignature (jmethodID method,
221 jclass declaringClass,
222 JArray<jclass> **arg_types_out,
223 jclass *return_type_out);
225 extern jobject _Jv_CallAnyMethodA (jobject obj, jclass return_type,
226 jmethodID meth, jboolean is_constructor,
227 JArray<jclass> *parameter_types,
231 extern jthrowable _Jv_CallAnyMethodA (jobject obj,
234 jboolean is_constructor,
235 JArray<jclass> *parameter_types,
239 extern jobject _Jv_NewMultiArray (jclass, jint ndims, jint* dims)
240 __attribute__((__malloc__));
242 /* Checked divide subroutines. */
245 jint _Jv_divI (jint, jint);
246 jint _Jv_remI (jint, jint);
247 jlong _Jv_divJ (jlong, jlong);
248 jlong _Jv_remJ (jlong, jlong);
251 /* get/set the name of the running executable. */
252 extern char *_Jv_ThisExecutable (void);
253 extern void _Jv_ThisExecutable (const char *);
255 /* Return a pointer to a symbol in executable or loaded library. */
256 void *_Jv_FindSymbolInExecutable (const char *);
258 /* Initialize JNI. */
259 extern void _Jv_JNI_Init (void);
261 /* Get or set the per-thread JNIEnv used by the invocation API. */
262 _Jv_JNIEnv *_Jv_GetCurrentJNIEnv ();
263 void _Jv_SetCurrentJNIEnv (_Jv_JNIEnv *);
266 _Jv_JavaVM *_Jv_GetJavaVM ();
271 extern void (*_Jv_JVMPI_Notify_OBJECT_ALLOC) (JVMPI_Event *event);
272 extern void (*_Jv_JVMPI_Notify_THREAD_START) (JVMPI_Event *event);
273 extern void (*_Jv_JVMPI_Notify_THREAD_END) (JVMPI_Event *event);
276 #endif /* __JAVA_JVM_H__ */