OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / libjava / include / jvm.h
1 // jvm.h - Header file for private implementation information. -*- c++ -*-
2
3 /* Copyright (C) 1998, 1999, 2000  Free Software Foundation
4
5    This file is part of libgcj.
6
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
9 details.  */
10
11 #ifndef __JAVA_JVM_H__
12 #define __JAVA_JVM_H__
13
14 // FIXME: __builtin_expect doesn't work yet.
15 #define __builtin_expect(A,B) (A)
16
17 #include <gcj/javaprims.h>
18
19 #include <java-assert.h>
20 #include <java-threads.h>
21 // Must include java-gc.h before Object.h for the implementation.
22 #include <java-gc.h>
23
24 #include <java/lang/Object.h>
25
26 // Include cni.h before field.h to enable all definitions.  FIXME.
27 #include <gcj/cni.h>
28 #include <gcj/field.h>
29
30 /* Structure of the virtual table.  */
31 struct _Jv_VTable
32 {
33   jclass clas;
34   void *method[1];
35 };
36
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
40
41 // This structure is the type of an array's vtable.
42 struct _Jv_ArrayVTable
43 {
44   jclass clas;
45   // `+1' because there is an extra slot for C++ RTTI compatibility.
46   void *method[NUM_OBJECT_METHODS + 1];
47 };
48
49 union _Jv_word
50 {
51   jobject o;
52   jint i;                       // Also stores smaller integral types.
53   jfloat f;
54   jint ia[1];                   // Half of _Jv_word2.
55   void* p;
56
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.
60   jlong l;
61   jdouble d;
62 #endif
63
64   jclass                     clazz;
65   jstring                    string;
66   struct _Jv_Field          *field;
67   struct _Jv_Utf8Const      *utf8;
68   struct _Jv_ResolvedMethod *rmethod;
69 };
70
71 union _Jv_word2
72 {
73   jint ia[2];
74   jlong l;
75   jdouble d;
76 };                              
77
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) \
91    : ((PTR)++, -1))
92
93 extern int _Jv_strLengthUtf8(char* str, int len);
94
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);
101
102 #define StringClass _CL_Q34java4lang6String
103 extern java::lang::Class StringClass;
104
105 /* Type of pointer used as finalizer.  */
106 typedef void _Jv_FinalizerFunc (jobject);
107
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);
118
119 /* Allocate some unscanned, unmoveable memory.  Return NULL if out of
120    memory.  */
121 void *_Jv_MallocUnchecked (jsize size) __attribute__((__malloc__));
122
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);
127 /* Perform a GC.  */
128 void _Jv_RunGC (void);
129 /* Disable and enable GC.  */
130 void _Jv_DisableGC (void);
131 void _Jv_EnableGC (void);
132
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);
137
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);
141
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);
145
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);
150
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);
155
156 /* Allocate some unscanned bytes.  Throw exception if out of memory.  */
157 void *_Jv_AllocBytesChecked (jsize size) __attribute__((__malloc__));
158
159 extern "C" void JvRunMain (jclass klass, int argc, const char **argv);
160 void _Jv_RunMain (const char* name, int argc, const char **argv);
161
162 // This function is used to determine the hash code of an object.
163 inline jint
164 _Jv_HashCode (jobject obj)
165 {
166   return (jint) obj;
167 }
168
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.
174 inline char *
175 _Jv_GetArrayElementFromElementType (jobject array,
176                                     jclass element_type)
177 {
178   char *elts;
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);
195   else
196     elts = (char *) elements ((jobjectArray) array);
197   return elts;
198 }
199
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, 
210                                                int meth_idx);
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*);
215
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);
224
225 extern jobject _Jv_CallAnyMethodA (jobject obj, jclass return_type,
226                                    jmethodID meth, jboolean is_constructor,
227                                    JArray<jclass> *parameter_types,
228                                    jobjectArray args);
229
230 union jvalue;
231 extern jthrowable _Jv_CallAnyMethodA (jobject obj,
232                                       jclass return_type,
233                                       jmethodID meth,
234                                       jboolean is_constructor,
235                                       JArray<jclass> *parameter_types,
236                                       jvalue *args,
237                                       jvalue *result);
238
239 extern jobject _Jv_NewMultiArray (jclass, jint ndims, jint* dims)
240   __attribute__((__malloc__));
241
242 /* Checked divide subroutines. */
243 extern "C"
244 {
245   jint _Jv_divI (jint, jint);
246   jint _Jv_remI (jint, jint);
247   jlong _Jv_divJ (jlong, jlong);
248   jlong _Jv_remJ (jlong, jlong);
249 }
250
251 /* get/set the name of the running executable. */
252 extern char *_Jv_ThisExecutable (void);
253 extern void _Jv_ThisExecutable (const char *);
254
255 /* Return a pointer to a symbol in executable or loaded library.  */
256 void *_Jv_FindSymbolInExecutable (const char *);
257
258 /* Initialize JNI.  */
259 extern void _Jv_JNI_Init (void);
260
261 /* Get or set the per-thread JNIEnv used by the invocation API.  */
262 _Jv_JNIEnv *_Jv_GetCurrentJNIEnv ();
263 void _Jv_SetCurrentJNIEnv (_Jv_JNIEnv *);
264
265 struct _Jv_JavaVM;
266 _Jv_JavaVM *_Jv_GetJavaVM ();
267
268 #ifdef ENABLE_JVMPI
269 #include "jvmpi.h"
270
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);
274 #endif
275
276 #endif /* __JAVA_JVM_H__ */