1 // jvm.h - Header file for private implementation information. -*- c++ -*-
3 /* Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
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. */
34 /* Extract a character from a Java-style Utf8 string.
35 * PTR points to the current character.
36 * LIMIT points to the end of the Utf8 string.
37 * PTR is incremented to point after the character thta gets returns.
38 * On an error, -1 is returned. */
39 #define UTF8_GET(PTR, LIMIT) \
40 ((PTR) >= (LIMIT) ? -1 \
41 : *(PTR) < 128 ? *(PTR)++ \
42 : (*(PTR)&0xE0) == 0xC0 && ((PTR)+=2)<=(LIMIT) && ((PTR)[-1]&0xC0) == 0x80 \
43 ? (((PTR)[-2] & 0x1F) << 6) + ((PTR)[-1] & 0x3F) \
44 : (*(PTR) & 0xF0) == 0xE0 && ((PTR) += 3) <= (LIMIT) \
45 && ((PTR)[-2] & 0xC0) == 0x80 && ((PTR)[-1] & 0xC0) == 0x80 \
46 ? (((PTR)[-3]&0x0F) << 12) + (((PTR)[-2]&0x3F) << 6) + ((PTR)[-1]&0x3F) \
49 extern int _Jv_strLengthUtf8(char* str, int len);
51 typedef struct _Jv_Utf8Const Utf8Const;
52 _Jv_Utf8Const *_Jv_makeUtf8Const (char *s, int len);
53 _Jv_Utf8Const *_Jv_makeUtf8Const (jstring string);
54 extern jboolean _Jv_equalUtf8Consts (_Jv_Utf8Const *, _Jv_Utf8Const *);
55 extern jboolean _Jv_equal (_Jv_Utf8Const *, jstring, jint);
56 extern jboolean _Jv_equaln (_Jv_Utf8Const *, jstring, jint);
58 #define StringClass _CL_Q34java4lang6String
59 extern java::lang::Class StringClass;
61 /* Type of pointer used as finalizer. */
62 typedef void _Jv_FinalizerFunc (jobject);
64 /* Allocate space for a new Java object. */
65 void *_Jv_AllocObj (jsize size) __attribute__((__malloc__));
66 /* Allocate space for an array of Java objects. */
67 void *_Jv_AllocArray (jsize size) __attribute__((__malloc__));
68 /* Allocate space that is known to be pointer-free. */
69 void *_Jv_AllocBytes (jsize size) __attribute__((__malloc__));
70 /* Initialize the GC. */
71 void _Jv_InitGC (void);
72 /* Register a finalizer. */
73 void _Jv_RegisterFinalizer (void *object, _Jv_FinalizerFunc *method);
75 /* Allocate some unscanned, unmoveable memory. Return NULL if out of
77 void *_Jv_MallocUnchecked (jsize size) __attribute__((__malloc__));
79 /* Run finalizers for objects ready to be finalized.. */
80 void _Jv_RunFinalizers (void);
81 /* Run all finalizers. Should be called only before exit. */
82 void _Jv_RunAllFinalizers (void);
84 void _Jv_RunGC (void);
86 /* Return approximation of total size of heap. */
87 long _Jv_GCTotalMemory (void);
88 /* Return approximation of total free memory. */
89 long _Jv_GCFreeMemory (void);
91 /* Set initial heap size. If SIZE==0, ignore. Should be run before
92 _Jv_InitGC. Not required to have any actual effect. */
93 void _Jv_GCSetInitialHeapSize (size_t size);
95 /* Set maximum heap size. If SIZE==0, unbounded. Should be run
96 before _Jv_InitGC. Not required to have any actual effect. */
97 void _Jv_GCSetMaximumHeapSize (size_t size);
99 /* External interface to setting the heap size. Parses ARG (a number
100 which can optionally have "k" or "m" appended and calls
101 _Jv_GCSetInitialHeapSize. */
102 void _Jv_SetInitialHeapSize (const char *arg);
104 /* External interface to setting the maximum heap size. Parses ARG (a
105 number which can optionally have "k" or "m" appended and calls
106 _Jv_GCSetMaximumHeapSize. */
107 void _Jv_SetMaximumHeapSize (const char *arg);
109 /* Allocate some unscanned bytes. Throw exception if out of memory. */
110 void *_Jv_AllocBytesChecked (jsize size) __attribute__((__malloc__));
112 extern "C" void JvRunMain (jclass klass, int argc, const char **argv);
113 void _Jv_RunMain (const char* name, int argc, const char **argv);
115 // This function is used to determine the hash code of an object.
117 _Jv_HashCode (jobject obj)
122 // Return a raw pointer to the elements of an array given the array
123 // and its element type. You might think we could just pick a single
124 // array type and use elements() on it, but we can't because we must
125 // account for alignment of the element type.
127 _Jv_GetArrayElementFromElementType (jobject array,
131 if (element_type == JvPrimClass (byte))
132 elts = (char *) elements ((jbyteArray) array);
133 else if (element_type == JvPrimClass (short))
134 elts = (char *) elements ((jshortArray) array);
135 else if (element_type == JvPrimClass (int))
136 elts = (char *) elements ((jintArray) array);
137 else if (element_type == JvPrimClass (long))
138 elts = (char *) elements ((jlongArray) array);
139 else if (element_type == JvPrimClass (boolean))
140 elts = (char *) elements ((jbooleanArray) array);
141 else if (element_type == JvPrimClass (char))
142 elts = (char *) elements ((jcharArray) array);
143 else if (element_type == JvPrimClass (float))
144 elts = (char *) elements ((jfloatArray) array);
145 else if (element_type == JvPrimClass (double))
146 elts = (char *) elements ((jdoubleArray) array);
148 elts = (char *) elements ((jobjectArray) array);
152 extern "C" void _Jv_ThrowBadArrayIndex (jint bad_index);
153 extern "C" jobject _Jv_NewArray (jint type, jint size)
154 __attribute__((__malloc__));
155 extern "C" jobject _Jv_NewMultiArray (jclass klass, jint dims, ...)
156 __attribute__((__malloc__));
157 extern "C" void *_Jv_CheckCast (jclass klass, jobject obj);
158 extern "C" void *_Jv_LookupInterfaceMethod (jclass klass, Utf8Const *name,
159 Utf8Const *signature);
160 extern "C" void _Jv_CheckArrayStore (jobject array, jobject obj);
161 extern "C" void _Jv_RegisterClass (jclass klass);
162 extern "C" void _Jv_RegisterClasses (jclass *classes);
163 extern void _Jv_UnregisterClass (_Jv_Utf8Const*, java::lang::ClassLoader*);
165 extern jclass _Jv_FindClass (_Jv_Utf8Const *name,
166 java::lang::ClassLoader *loader);
167 extern jclass _Jv_FindClassFromSignature (char *,
168 java::lang::ClassLoader *loader);
169 extern void _Jv_GetTypesFromSignature (jmethodID method,
170 jclass declaringClass,
171 JArray<jclass> **arg_types_out,
172 jclass *return_type_out);
174 extern jobject _Jv_CallAnyMethodA (jobject obj, jclass return_type,
175 jmethodID meth, jboolean is_constructor,
176 JArray<jclass> *parameter_types,
180 extern jthrowable _Jv_CallAnyMethodA (jobject obj,
183 jboolean is_constructor,
184 JArray<jclass> *parameter_types,
188 extern jobject _Jv_NewMultiArray (jclass, jint ndims, jint* dims)
189 __attribute__((__malloc__));
191 /* Checked divide subroutines. */
194 jint _Jv_divI (jint, jint);
195 jint _Jv_remI (jint, jint);
196 jlong _Jv_divJ (jlong, jlong);
197 jlong _Jv_remJ (jlong, jlong);
200 /* get/set the name of the running executable. */
201 extern char *_Jv_ThisExecutable (void);
202 extern void _Jv_ThisExecutable (const char *);
204 /* Initialize JNI. */
205 extern void _Jv_JNI_Init (void);
208 #endif /* __JAVA_JVM_H__ */