OSDN Git Service

* include/no-gc.h (_Jv_SuspendThread): Declare.
[pf3gnuchains/gcc-fork.git] / libjava / include / execution.h
1 // execution.h - Execution engines. -*- c++ -*-
2
3 /* Copyright (C) 2004, 2006  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_EXECUTION_H__
12 #define __JAVA_EXECUTION_H__
13
14 // This represents one execution engine.  Note that we use function
15 // pointers and not virtual methods to avoid calls to
16 // __cxa_call_unexpected and the like.
17 struct _Jv_ExecutionEngine
18 {
19  public:
20
21   void (*unregister) (jclass);
22   // FIXME: probably should handle this elsewhere, see how
23   // interpreter does it.
24   bool (*need_resolve_string_fields) ();
25   void (*verify) (jclass);
26   void (*allocate_static_fields) (jclass, int, int);
27   void (*allocate_field_initializers) (jclass);
28   void (*create_ncode) (jclass);
29   _Jv_ResolvedMethod *(*resolve_method) (_Jv_Method *, jclass,
30                                          jboolean);
31   void (*post_miranda_hook) (jclass);
32 };
33
34 // This handles gcj-compiled code except that compiled with
35 // -findirect-classes.
36 struct _Jv_CompiledEngine : public _Jv_ExecutionEngine
37 {
38  public:
39
40   static void do_unregister (jclass)
41   {
42   }
43
44   static bool do_need_resolve_string_fields ()
45   {
46     return true;
47   }
48
49   static void do_verify (jclass klass)
50   {
51     _Jv_Linker::verify_type_assertions (klass);
52   }
53
54   static _Jv_ResolvedMethod *do_resolve_method (_Jv_Method *, jclass,
55                                                 jboolean)
56   {
57     return NULL;
58   }
59
60   static void do_allocate_static_fields (jclass,
61                                          int,
62                                          int)
63   {
64   }
65
66   static void do_allocate_field_initializers (jclass)
67   {
68   }
69
70   static void do_create_ncode (jclass)
71   {
72     // Not needed.
73   }
74
75   static void do_post_miranda_hook (jclass)
76   {
77     // Not needed.
78   }
79
80   _Jv_CompiledEngine ()
81   {
82     unregister = do_unregister;
83     need_resolve_string_fields = do_need_resolve_string_fields;
84     verify = do_verify;
85     allocate_static_fields = do_allocate_static_fields;
86     allocate_field_initializers = do_allocate_field_initializers;
87     create_ncode = do_create_ncode;
88     resolve_method = do_resolve_method;
89     post_miranda_hook = do_post_miranda_hook;
90   }
91
92   // These operators make it so we don't have to link in libstdc++.
93   void *operator new (size_t bytes)
94   {
95     return _Jv_Malloc(bytes);
96   }
97
98   void operator delete (void *mem)
99   {
100     _Jv_Free(mem);
101   }
102 };
103
104 class _Jv_IndirectCompiledClass
105 {
106 public:
107   void **field_initializers;
108 };
109
110 // This handles gcj-compiled code compiled with -findirect-classes.
111 struct _Jv_IndirectCompiledEngine : public _Jv_CompiledEngine
112 {
113   _Jv_IndirectCompiledEngine () : _Jv_CompiledEngine ()
114   {
115     allocate_static_fields = do_allocate_static_fields;
116     allocate_field_initializers = do_allocate_field_initializers;
117   }
118   
119   static void do_allocate_field_initializers (jclass klass)
120   {
121     _Jv_IndirectCompiledClass *aux 
122       =  (_Jv_IndirectCompiledClass*)
123         _Jv_AllocRawObj (sizeof (_Jv_IndirectCompiledClass));
124     klass->aux_info = aux;
125
126     aux->field_initializers = (void **)_Jv_Malloc (klass->field_count 
127                                                    * sizeof (void*));    
128
129     for (int i = 0; i < klass->field_count; i++)
130       {
131         _Jv_Field *field = &klass->fields[i];
132         if (field->flags & java::lang::reflect::Modifier::STATIC)
133           {
134             aux->field_initializers[i] = field->u.addr;
135             field->u.addr = NULL; 
136           }
137       }
138   }
139
140   static void do_allocate_static_fields (jclass klass,
141                                          int pointer_size,
142                                          int other_size)
143   {
144     // Splitting the allocations here lets us scan reference fields
145     // and avoid scanning non-reference fields.
146     char *reference_fields = (char *) _Jv_AllocRawObj (pointer_size);
147     char *non_reference_fields = (char *) _Jv_AllocBytes (other_size);
148
149     _Jv_IndirectCompiledClass *aux 
150       =  (_Jv_IndirectCompiledClass*)klass->aux_info;
151
152     for (int i = 0; i < klass->field_count; i++)
153       {
154         _Jv_Field *field = &klass->fields[i];
155
156         if ((field->flags & java::lang::reflect::Modifier::STATIC) == 0)
157           continue;
158
159         char *base = field->isRef() ? reference_fields : non_reference_fields;
160         field->u.addr  = base + field->u.boffset;
161
162         if (aux->field_initializers[i])
163           {
164             int field_size;
165             if (! field->isRef ())
166               field_size = field->type->size ();
167             else 
168               field_size = sizeof (jobject);
169
170             memcpy (field->u.addr, aux->field_initializers[i], field_size);
171           }
172       } 
173     _Jv_Free (aux->field_initializers);
174   }
175 };
176
177
178
179 // This handles interpreted code.
180 class _Jv_InterpreterEngine : public _Jv_ExecutionEngine
181 {
182  public:
183
184   static void do_verify (jclass);
185   static void do_allocate_static_fields (jclass, int, int);
186   static void do_create_ncode (jclass);
187   static _Jv_ResolvedMethod *do_resolve_method (_Jv_Method *, jclass,
188                                                 jboolean);
189
190   static bool do_need_resolve_string_fields ()
191   {
192     return false;
193   }
194
195   static void do_unregister(jclass klass)
196   {
197     _Jv_UnregisterClass(klass);
198   }
199
200   static void do_allocate_field_initializers (jclass)
201   {
202   }
203
204   static void do_post_miranda_hook (jclass);
205
206   _Jv_InterpreterEngine ()
207   {
208     unregister = do_unregister;
209     need_resolve_string_fields = do_need_resolve_string_fields;
210     verify = do_verify;
211     allocate_static_fields = do_allocate_static_fields;
212     allocate_field_initializers = do_allocate_field_initializers;
213     create_ncode = do_create_ncode;
214     resolve_method = do_resolve_method;
215     post_miranda_hook = do_post_miranda_hook;
216   }
217
218   // These operators make it so we don't have to link in libstdc++.
219   void *operator new (size_t bytes)
220   {
221     return _Jv_Malloc(bytes);
222   }
223
224   void operator delete (void *mem)
225   {
226     _Jv_Free(mem);
227   }
228 };
229
230
231 extern _Jv_InterpreterEngine _Jv_soleInterpreterEngine;
232 extern _Jv_CompiledEngine _Jv_soleCompiledEngine;
233 extern _Jv_IndirectCompiledEngine _Jv_soleIndirectCompiledEngine;
234 #endif // __JAVA_EXECUTION_H__