source: vendor/gcc/current/libjava/include/jvm.h

Last change on this file was 1391, checked in by bird, 21 years ago

GCC v3.3.3 sources.

  • Property cvs2svn:cvs-rev set to 1.1.1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 14.0 KB
Line 
1// jvm.h - Header file for private implementation information. -*- c++ -*-
2
3/* Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation
4
5 This file is part of libgcj.
6
7This software is copyrighted work licensed under the terms of the
8Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9details. */
10
11#ifndef __JAVA_JVM_H__
12#define __JAVA_JVM_H__
13
14// Define this before including jni.h.
15// jni.h is included by jvmpi.h, which might be included. We define
16// this unconditionally because it is convenient and it lets other
17// files include jni.h without difficulty.
18#define __GCJ_JNI_IMPL__
19
20#include <gcj/javaprims.h>
21
22#include <java-assert.h>
23#include <java-threads.h>
24// Must include java-gc.h before Object.h for the implementation.
25#include <java-gc.h>
26
27#include <java/lang/Object.h>
28
29// Include cni.h before field.h to enable all definitions. FIXME.
30#include <gcj/cni.h>
31#include <gcj/field.h>
32
33/* Structure of the virtual table. */
34struct _Jv_VTable
35{
36#ifdef __ia64__
37 typedef struct { void *pc, *gp; } vtable_elt;
38#else
39 typedef void *vtable_elt;
40#endif
41 jclass clas;
42 void *gc_descr;
43
44 // This must be last, as derived classes "extend" this by
45 // adding new data members.
46 vtable_elt method[1];
47
48#ifdef __ia64__
49 void *get_method(int i) { return &method[i]; }
50 void set_method(int i, void *fptr) { method[i] = *(vtable_elt *)fptr; }
51 void *get_finalizer()
52 {
53 // We know that get_finalizer is only used for checking whether
54 // this object needs to have a finalizer registered. So it is
55 // safe to simply return just the PC component of the vtable
56 // slot.
57 return ((vtable_elt *)(get_method(0)))->pc;
58 }
59#else
60 void *get_method(int i) { return method[i]; }
61 void set_method(int i, void *fptr) { method[i] = fptr; }
62 void *get_finalizer() { return get_method(0); }
63#endif
64
65 static size_t vtable_elt_size() { return sizeof(vtable_elt); }
66
67 // Given a method index, return byte offset from the vtable pointer.
68 static jint idx_to_offset (int index)
69 {
70 return (2 * sizeof (void *)) + (index * vtable_elt_size ());
71 }
72 static _Jv_VTable *new_vtable (int count);
73};
74
75// Number of virtual methods on object. FIXME: it sucks that we have
76// to keep this up to date by hand.
77#define NUM_OBJECT_METHODS 5
78
79// This structure is the type of an array's vtable.
80struct _Jv_ArrayVTable : public _Jv_VTable
81{
82 vtable_elt extra_method[NUM_OBJECT_METHODS - 1];
83};
84
85union _Jv_word
86{
87 jobject o;
88 jint i; // Also stores smaller integral types.
89 jfloat f;
90 jint ia[1]; // Half of _Jv_word2.
91 void* p;
92
93#if SIZEOF_VOID_P == 8
94 // We can safely put a long or a double in here without increasing
95 // the size of _Jv_Word; we take advantage of this in the interpreter.
96 jlong l;
97 jdouble d;
98#endif
99
100 jclass clazz;
101 jstring string;
102 struct _Jv_Field *field;
103 struct _Jv_Utf8Const *utf8;
104 struct _Jv_ResolvedMethod *rmethod;
105};
106
107union _Jv_word2
108{
109 jint ia[2];
110 jlong l;
111 jdouble d;
112};
113
114// An instance of this type is used to represent a single frame in a
115// backtrace. If the interpreter has been built, we also include
116// information about the interpreted method.
117struct _Jv_frame_info
118{
119 // PC value.
120 void *addr;
121#ifdef INTERPRETER
122 // Actually a _Jv_InterpMethod, but we don't want to include
123 // java-interp.h everywhere.
124 void *interp;
125#endif // INTERPRETER
126};
127
128/* Extract a character from a Java-style Utf8 string.
129 * PTR points to the current character.
130 * LIMIT points to the end of the Utf8 string.
131 * PTR is incremented to point after the character thta gets returns.
132 * On an error, -1 is returned. */
133#define UTF8_GET(PTR, LIMIT) \
134 ((PTR) >= (LIMIT) ? -1 \
135 : *(PTR) < 128 ? *(PTR)++ \
136 : (*(PTR)&0xE0) == 0xC0 && ((PTR)+=2)<=(LIMIT) && ((PTR)[-1]&0xC0) == 0x80 \
137 ? (((PTR)[-2] & 0x1F) << 6) + ((PTR)[-1] & 0x3F) \
138 : (*(PTR) & 0xF0) == 0xE0 && ((PTR) += 3) <= (LIMIT) \
139 && ((PTR)[-2] & 0xC0) == 0x80 && ((PTR)[-1] & 0xC0) == 0x80 \
140 ? (((PTR)[-3]&0x0F) << 12) + (((PTR)[-2]&0x3F) << 6) + ((PTR)[-1]&0x3F) \
141 : ((PTR)++, -1))
142
143extern int _Jv_strLengthUtf8(char* str, int len);
144
145typedef struct _Jv_Utf8Const Utf8Const;
146_Jv_Utf8Const *_Jv_makeUtf8Const (char *s, int len);
147_Jv_Utf8Const *_Jv_makeUtf8Const (jstring string);
148extern jboolean _Jv_equalUtf8Consts (_Jv_Utf8Const *, _Jv_Utf8Const *);
149extern jboolean _Jv_equal (_Jv_Utf8Const *, jstring, jint);
150extern jboolean _Jv_equaln (_Jv_Utf8Const *, jstring, jint);
151
152// FIXME: remove this define.
153#define StringClass java::lang::String::class$
154
155namespace gcj
156{
157 /* Some constants used during lookup of special class methods. */
158 extern _Jv_Utf8Const *void_signature; /* "()V" */
159 extern _Jv_Utf8Const *clinit_name; /* "<clinit>" */
160 extern _Jv_Utf8Const *init_name; /* "<init>" */
161 extern _Jv_Utf8Const *finit_name; /* "finit$", */
162
163 /* Set to true by _Jv_CreateJavaVM. */
164 extern bool runtimeInitialized;
165};
166
167/* Type of pointer used as finalizer. */
168typedef void _Jv_FinalizerFunc (jobject);
169
170/* Allocate space for a new Java object. */
171void *_Jv_AllocObj (jsize size, jclass cl) __attribute__((__malloc__));
172/* Allocate space for a potentially uninitialized pointer-free object.
173 Interesting only with JV_HASH_SYNCHRONIZATION. */
174void *_Jv_AllocPtrFreeObj (jsize size, jclass cl) __attribute__((__malloc__));
175/* Allocate space for an array of Java objects. */
176void *_Jv_AllocArray (jsize size, jclass cl) __attribute__((__malloc__));
177/* Allocate space that is known to be pointer-free. */
178void *_Jv_AllocBytes (jsize size) __attribute__((__malloc__));
179/* Allocate space for a new non-Java object, which does not have the usual
180 Java object header but may contain pointers to other GC'ed objects. */
181void *_Jv_AllocRawObj (jsize size) __attribute__((__malloc__));
182/* Explicitly throw an out-of-memory exception. */
183void _Jv_ThrowNoMemory() __attribute__((__noreturn__));
184/* Allocate an object with a single pointer. The first word is reserved
185 for the GC, and the second word is the traced pointer. */
186void *_Jv_AllocTraceOne (jsize size /* incl. reserved slot */);
187/* Ditto, but for two traced pointers. */
188void *_Jv_AllocTraceTwo (jsize size /* incl. reserved slot */);
189/* Initialize the GC. */
190void _Jv_InitGC (void);
191/* Register a finalizer. */
192void _Jv_RegisterFinalizer (void *object, _Jv_FinalizerFunc *method);
193/* Compute the GC descriptor for a class */
194void * _Jv_BuildGCDescr(jclass);
195
196/* Allocate some unscanned, unmoveable memory. Return NULL if out of
197 memory. */
198void *_Jv_MallocUnchecked (jsize size) __attribute__((__malloc__));
199
200/* Initialize finalizers. The argument is a function to be called
201 when a finalizer is ready to be run. */
202void _Jv_GCInitializeFinalizers (void (*notifier) (void));
203/* Run finalizers for objects ready to be finalized.. */
204void _Jv_RunFinalizers (void);
205/* Run all finalizers. Should be called only before exit. */
206void _Jv_RunAllFinalizers (void);
207/* Perform a GC. */
208void _Jv_RunGC (void);
209/* Disable and enable GC. */
210void _Jv_DisableGC (void);
211void _Jv_EnableGC (void);
212/* Register a disappearing link. This is a field F which should be
213 cleared when *F is found to be inaccessible. This is used in the
214 implementation of java.lang.ref.Reference. */
215void _Jv_GCRegisterDisappearingLink (jobject *objp);
216/* Return true if OBJECT should be reclaimed. This is used to
217 implement soft references. */
218jboolean _Jv_GCCanReclaimSoftReference (jobject obj);
219
220/* Return approximation of total size of heap. */
221long _Jv_GCTotalMemory (void);
222/* Return approximation of total free memory. */
223long _Jv_GCFreeMemory (void);
224
225/* Set initial heap size. If SIZE==0, ignore. Should be run before
226 _Jv_InitGC. Not required to have any actual effect. */
227void _Jv_GCSetInitialHeapSize (size_t size);
228
229/* Set maximum heap size. If SIZE==0, unbounded. Should be run
230 before _Jv_InitGC. Not required to have any actual effect. */
231void _Jv_GCSetMaximumHeapSize (size_t size);
232
233/* External interface to setting the heap size. Parses ARG (a number
234 which can optionally have "k" or "m" appended and calls
235 _Jv_GCSetInitialHeapSize. */
236void _Jv_SetInitialHeapSize (const char *arg);
237
238/* External interface to setting the maximum heap size. Parses ARG (a
239 number which can optionally have "k" or "m" appended and calls
240 _Jv_GCSetMaximumHeapSize. */
241void _Jv_SetMaximumHeapSize (const char *arg);
242
243extern "C" void JvRunMain (jclass klass, int argc, const char **argv);
244void _Jv_RunMain (jclass klass, const char *name, int argc, const char **argv,
245 bool is_jar);
246
247// Delayed until after _Jv_AllocBytes is declared.
248//
249// Note that we allocate this as unscanned memory -- the vtables
250// are handled specially by the GC.
251
252inline _Jv_VTable *
253_Jv_VTable::new_vtable (int count)
254{
255 size_t size = sizeof(_Jv_VTable) + (count - 1) * vtable_elt_size ();
256 return (_Jv_VTable *) _Jv_AllocBytes (size);
257}
258
259// This function is used to determine the hash code of an object.
260inline jint
261_Jv_HashCode (jobject obj)
262{
263 // This was chosen to yield relatively well distributed results on
264 // both 32- and 64-bit architectures. Note 0x7fffffff is prime.
265 // FIXME: we assume sizeof(long) == sizeof(void *).
266 return (jint) ((unsigned long) obj % 0x7fffffff);
267}
268
269// Return a raw pointer to the elements of an array given the array
270// and its element type. You might think we could just pick a single
271// array type and use elements() on it, but we can't because we must
272// account for alignment of the element type. When ARRAY is null, we
273// obtain the number of bytes taken by the base part of the array.
274inline char *
275_Jv_GetArrayElementFromElementType (jobject array,
276 jclass element_type)
277{
278 char *elts;
279 if (element_type == JvPrimClass (byte))
280 elts = (char *) elements ((jbyteArray) array);
281 else if (element_type == JvPrimClass (short))
282 elts = (char *) elements ((jshortArray) array);
283 else if (element_type == JvPrimClass (int))
284 elts = (char *) elements ((jintArray) array);
285 else if (element_type == JvPrimClass (long))
286 elts = (char *) elements ((jlongArray) array);
287 else if (element_type == JvPrimClass (boolean))
288 elts = (char *) elements ((jbooleanArray) array);
289 else if (element_type == JvPrimClass (char))
290 elts = (char *) elements ((jcharArray) array);
291 else if (element_type == JvPrimClass (float))
292 elts = (char *) elements ((jfloatArray) array);
293 else if (element_type == JvPrimClass (double))
294 elts = (char *) elements ((jdoubleArray) array);
295 else
296 elts = (char *) elements ((jobjectArray) array);
297 return elts;
298}
299
300extern "C" void _Jv_ThrowBadArrayIndex (jint bad_index)
301 __attribute__((noreturn));
302extern "C" void _Jv_ThrowNullPointerException (void)
303 __attribute__((noreturn));
304extern "C" jobject _Jv_NewArray (jint type, jint size)
305 __attribute__((__malloc__));
306extern "C" jobject _Jv_NewMultiArray (jclass klass, jint dims, ...)
307 __attribute__((__malloc__));
308extern "C" void *_Jv_CheckCast (jclass klass, jobject obj);
309extern "C" void *_Jv_LookupInterfaceMethod (jclass klass, Utf8Const *name,
310 Utf8Const *signature);
311extern "C" void *_Jv_LookupInterfaceMethodIdx (jclass klass, jclass iface,
312 int meth_idx);
313extern "C" void _Jv_CheckArrayStore (jobject array, jobject obj);
314extern "C" void _Jv_RegisterClass (jclass klass);
315extern "C" void _Jv_RegisterClasses (jclass *classes);
316extern "C" void _Jv_RegisterResource (void *vptr);
317extern void _Jv_UnregisterClass (_Jv_Utf8Const*, java::lang::ClassLoader*);
318extern void _Jv_ResolveField (_Jv_Field *, java::lang::ClassLoader*);
319
320extern jclass _Jv_FindClass (_Jv_Utf8Const *name,
321 java::lang::ClassLoader *loader);
322extern jclass _Jv_FindClassFromSignature (char *,
323 java::lang::ClassLoader *loader);
324extern void _Jv_GetTypesFromSignature (jmethodID method,
325 jclass declaringClass,
326 JArray<jclass> **arg_types_out,
327 jclass *return_type_out);
328
329extern jobject _Jv_CallAnyMethodA (jobject obj, jclass return_type,
330 jmethodID meth, jboolean is_constructor,
331 JArray<jclass> *parameter_types,
332 jobjectArray args);
333
334union jvalue;
335extern jthrowable _Jv_CallAnyMethodA (jobject obj,
336 jclass return_type,
337 jmethodID meth,
338 jboolean is_constructor,
339 JArray<jclass> *parameter_types,
340 jvalue *args,
341 jvalue *result);
342
343extern jobject _Jv_NewMultiArray (jclass, jint ndims, jint* dims)
344 __attribute__((__malloc__));
345
346/* Checked divide subroutines. */
347extern "C"
348{
349 jint _Jv_divI (jint, jint);
350 jint _Jv_remI (jint, jint);
351 jlong _Jv_divJ (jlong, jlong);
352 jlong _Jv_remJ (jlong, jlong);
353}
354
355/* Get the number of arguments (cf. argc) or 0 if our argument
356 list was never initialized. */
357extern int _Jv_GetNbArgs (void);
358
359/* Get the specified argument (cf. argv[index]) or "" if either
360 our argument list was never initialized or the specified index
361 is out of bounds. */
362extern const char * _Jv_GetSafeArg (int index);
363
364/* Sets our argument list. Can be used by programs with non-standard
365 entry points. */
366extern void _Jv_SetArgs (int argc, const char **argv);
367
368/* Get the name of the running executable. */
369extern const char *_Jv_ThisExecutable (void);
370
371/* Return a pointer to a symbol in executable or loaded library. */
372void *_Jv_FindSymbolInExecutable (const char *);
373
374/* Initialize JNI. */
375extern void _Jv_JNI_Init (void);
376
377/* Get or set the per-thread JNIEnv used by the invocation API. */
378_Jv_JNIEnv *_Jv_GetCurrentJNIEnv ();
379void _Jv_SetCurrentJNIEnv (_Jv_JNIEnv *);
380
381struct _Jv_JavaVM;
382_Jv_JavaVM *_Jv_GetJavaVM ();
383
384// Some verification functions from defineclass.cc.
385bool _Jv_VerifyFieldSignature (_Jv_Utf8Const*sig);
386bool _Jv_VerifyMethodSignature (_Jv_Utf8Const*sig);
387bool _Jv_VerifyClassName (unsigned char* ptr, _Jv_ushort length);
388bool _Jv_VerifyClassName (_Jv_Utf8Const *name);
389bool _Jv_VerifyIdentifier (_Jv_Utf8Const *);
390bool _Jv_ClassNameSamePackage (_Jv_Utf8Const *name1, _Jv_Utf8Const *name2);
391
392#ifdef ENABLE_JVMPI
393
394#include "jvmpi.h"
395
396extern void (*_Jv_JVMPI_Notify_OBJECT_ALLOC) (JVMPI_Event *event);
397extern void (*_Jv_JVMPI_Notify_THREAD_START) (JVMPI_Event *event);
398extern void (*_Jv_JVMPI_Notify_THREAD_END) (JVMPI_Event *event);
399#endif
400
401#endif /* __JAVA_JVM_H__ */
Note: See TracBrowser for help on using the repository browser.