OSDN Git Service

2006-04-21 Andrew Haley <aph@redhat.com>
[pf3gnuchains/gcc-fork.git] / libjava / include / boehm-gc.h
1 // -*- c++ -*-
2 // boehm-gc.h - Defines for Boehm collector.
3
4 /* Copyright (C) 1998, 1999, 2002, 2004  Free Software Foundation
5
6    This file is part of libgcj.
7
8 This software is copyrighted work licensed under the terms of the
9 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
10 details.  */
11
12 #ifndef __JV_BOEHM_GC__
13 #define __JV_BOEHM_GC__
14
15 #define JV_MARKOBJ_DECL void *::_Jv_MarkObj (void *, void *, void *, void *)
16 #define JV_MARKARRAY_DECL void *::_Jv_MarkArray (void *, void *, void *, void *)
17
18 extern "C"
19 {
20   void *_Jv_MarkObj (void *, void *, void *, void *);
21   void *_Jv_MarkArray (void *, void *, void *, void *);
22   void _Jv_RegisterLibForGc (const void *);
23 }
24
25 // Enough stuff to inline _Jv_AllocObj.  Ugly.
26 #include <gcj/javaprims.h>
27 #include <java/lang/Class.h>
28 #include <string.h>
29
30 #include <gc_ext_config.h> // for THREAD_LOCAL_ALLOC
31
32 extern "C" void * GC_gcj_malloc(size_t, void *);
33 extern "C" void * GC_malloc_atomic(size_t);
34 #ifdef THREAD_LOCAL_ALLOC
35 extern "C" void * GC_local_gcj_malloc(size_t, void *);
36 extern "C" void * GC_local_malloc_atomic(size_t);
37 #endif
38
39 #ifndef LIBGCJ_GC_DEBUG
40
41 inline void *
42 _Jv_AllocObj (jsize size, jclass klass)
43 {
44   // This should call GC_GCJ_MALLOC, but that would involve
45   // including gc.h.
46 #ifdef THREAD_LOCAL_ALLOC
47   return GC_local_gcj_malloc (size, klass->vtable);
48 #else 
49   return GC_gcj_malloc (size, klass->vtable);
50 #endif
51 }
52
53 inline void *
54 _Jv_AllocPtrFreeObj (jsize size, jclass klass)
55 {
56 #ifdef JV_HASH_SYNCHRONIZATION
57 # ifdef THREAD_LOCAL_ALLOC
58     void * obj = GC_local_malloc_atomic(size);
59 # else
60     void * obj = GC_malloc_atomic(size);
61 # endif
62   *((_Jv_VTable **) obj) = klass->vtable;
63 #else
64 # ifdef THREAD_LOCAL_ALLOC
65     void * obj = GC_local_gcj_malloc(size, klass->vtable);
66 # else
67     void * obj = GC_gcj_malloc(size, klass->vtable);
68 # endif
69 #endif
70   return obj;
71 }
72
73 #else /* LIBGCJ_GC_DEBUG */
74
75 void *
76 _Jv_AllocObj (jsize size, jclass klass);
77
78 void *
79 _Jv_AllocPtrFreeObj (jsize size, jclass klass);
80
81 #endif /* LIBGCJ_GC_DEBUG */
82
83 // _Jv_AllocBytes (jsize size) should go here, too.  But clients don't
84 // usually include this header.
85
86 #endif /* __JV_BOEHM_GC__ */