Merged with mainline at revision 128810.
[official-gcc.git] / libjava / include / execution.h
blobc48b2fc32736b801985e0a03ad11f1b998eef1ca
1 // execution.h - Execution engines. -*- c++ -*-
3 /* Copyright (C) 2004, 2006, 2007 Free Software Foundation
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
9 details. */
11 #ifndef __JAVA_EXECUTION_H__
12 #define __JAVA_EXECUTION_H__
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
19 public:
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 _Jv_ClosureList **(*get_closure_list) (jclass);
35 // This handles gcj-compiled code except that compiled with
36 // -findirect-classes.
37 struct _Jv_CompiledEngine : public _Jv_ExecutionEngine
39 public:
41 static void do_unregister (jclass)
45 static bool do_need_resolve_string_fields ()
47 return true;
50 static void do_verify (jclass klass)
52 _Jv_Linker::verify_type_assertions (klass);
55 static _Jv_ResolvedMethod *do_resolve_method (_Jv_Method *, jclass,
56 jboolean)
58 return NULL;
61 static void do_allocate_static_fields (jclass,
62 int,
63 int)
67 static void do_allocate_field_initializers (jclass)
71 static void do_create_ncode (jclass)
73 // Not needed.
76 static void do_post_miranda_hook (jclass)
78 // Not needed.
81 static _Jv_ClosureList **do_get_closure_list (jclass)
83 return NULL;
86 _Jv_CompiledEngine ()
88 unregister = do_unregister;
89 need_resolve_string_fields = do_need_resolve_string_fields;
90 verify = do_verify;
91 allocate_static_fields = do_allocate_static_fields;
92 allocate_field_initializers = do_allocate_field_initializers;
93 create_ncode = do_create_ncode;
94 resolve_method = do_resolve_method;
95 post_miranda_hook = do_post_miranda_hook;
96 get_closure_list = do_get_closure_list;
99 // These operators make it so we don't have to link in libstdc++.
100 void *operator new (size_t bytes)
102 return _Jv_Malloc(bytes);
105 void operator delete (void *mem)
107 _Jv_Free(mem);
111 class _Jv_IndirectCompiledClass
113 public:
114 void **field_initializers;
115 _Jv_ClosureList **closures;
118 // This handles gcj-compiled code compiled with -findirect-classes.
119 struct _Jv_IndirectCompiledEngine : public _Jv_CompiledEngine
121 _Jv_IndirectCompiledEngine () : _Jv_CompiledEngine ()
123 allocate_static_fields = do_allocate_static_fields;
124 allocate_field_initializers = do_allocate_field_initializers;
125 get_closure_list = do_get_closure_list;
128 static _Jv_IndirectCompiledClass *get_aux_info (jclass klass)
130 _Jv_IndirectCompiledClass *aux =
131 (_Jv_IndirectCompiledClass*)klass->aux_info;
132 if (!aux)
134 aux = (_Jv_IndirectCompiledClass*)
135 _Jv_AllocRawObj (sizeof (_Jv_IndirectCompiledClass));
136 klass->aux_info = aux;
139 return aux;
142 static void do_allocate_field_initializers (jclass klass)
144 _Jv_IndirectCompiledClass *aux = get_aux_info (klass);
145 if (!aux)
147 aux = (_Jv_IndirectCompiledClass*)
148 _Jv_AllocRawObj (sizeof (_Jv_IndirectCompiledClass));
149 klass->aux_info = aux;
152 aux->field_initializers = (void **)_Jv_Malloc (klass->field_count
153 * sizeof (void*));
155 for (int i = 0; i < klass->field_count; i++)
157 _Jv_Field *field = &klass->fields[i];
158 if (field->flags & java::lang::reflect::Modifier::STATIC)
160 aux->field_initializers[i] = field->u.addr;
161 field->u.addr = NULL;
166 static void do_allocate_static_fields (jclass klass,
167 int pointer_size,
168 int other_size)
170 // Splitting the allocations here lets us scan reference fields
171 // and avoid scanning non-reference fields.
172 char *reference_fields = (char *) _Jv_AllocRawObj (pointer_size);
173 char *non_reference_fields = (char *) _Jv_AllocBytes (other_size);
175 _Jv_IndirectCompiledClass *aux
176 = (_Jv_IndirectCompiledClass*)klass->aux_info;
178 for (int i = 0; i < klass->field_count; i++)
180 _Jv_Field *field = &klass->fields[i];
182 if ((field->flags & java::lang::reflect::Modifier::STATIC) == 0)
183 continue;
185 char *base = field->isRef() ? reference_fields : non_reference_fields;
186 field->u.addr = base + field->u.boffset;
188 if (aux->field_initializers[i])
190 int field_size;
191 if (! field->isRef ())
192 field_size = field->type->size ();
193 else
194 field_size = sizeof (jobject);
196 memcpy (field->u.addr, aux->field_initializers[i], field_size);
199 _Jv_Free (aux->field_initializers);
202 #ifdef INTERPRETER
203 static _Jv_ClosureList **do_get_closure_list (jclass klass)
205 _Jv_IndirectCompiledClass *aux = get_aux_info (klass);
207 if (!aux->closures)
208 aux->closures = _Jv_ClosureListFinalizer ();
210 return aux->closures;
212 #endif
215 #ifdef INTERPRETER
217 // This handles interpreted code.
218 class _Jv_InterpreterEngine : public _Jv_ExecutionEngine
220 public:
222 static void do_verify (jclass);
223 static void do_allocate_static_fields (jclass, int, int);
224 static void do_create_ncode (jclass);
225 static _Jv_ResolvedMethod *do_resolve_method (_Jv_Method *, jclass,
226 jboolean);
228 static bool do_need_resolve_string_fields ()
230 return false;
233 static void do_unregister(jclass klass)
235 _Jv_UnregisterClass(klass);
238 static void do_allocate_field_initializers (jclass)
242 static void do_post_miranda_hook (jclass);
244 static _Jv_ClosureList **do_get_closure_list (jclass klass);
246 _Jv_InterpreterEngine ()
248 unregister = do_unregister;
249 need_resolve_string_fields = do_need_resolve_string_fields;
250 verify = do_verify;
251 allocate_static_fields = do_allocate_static_fields;
252 allocate_field_initializers = do_allocate_field_initializers;
253 create_ncode = do_create_ncode;
254 resolve_method = do_resolve_method;
255 post_miranda_hook = do_post_miranda_hook;
256 get_closure_list = do_get_closure_list;
259 // These operators make it so we don't have to link in libstdc++.
260 void *operator new (size_t bytes)
262 return _Jv_Malloc(bytes);
265 void operator delete (void *mem)
267 _Jv_Free(mem);
271 extern _Jv_InterpreterEngine _Jv_soleInterpreterEngine;
272 #endif // INTERPRETER
274 extern _Jv_CompiledEngine _Jv_soleCompiledEngine;
275 extern _Jv_IndirectCompiledEngine _Jv_soleIndirectCompiledEngine;
276 #endif // __JAVA_EXECUTION_H__