OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / libjava / boehm.cc
1 // boehm.cc - interface between libjava and Boehm GC.
2
3 /* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
4    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 #include <config.h>
13
14 #include <stdio.h>
15 #include <limits.h>
16
17 #include <jvm.h>
18 #include <gcj/cni.h>
19
20 #include <java/lang/Class.h>
21 #include <java/lang/reflect/Modifier.h>
22 #include <java-interp.h>
23
24 // More nastiness: the GC wants to define TRUE and FALSE.  We don't
25 // need the Java definitions (themselves a hack), so we undefine them.
26 #undef TRUE
27 #undef FALSE
28
29 extern "C"
30 {
31 #include <gc_config.h>
32
33 // Set GC_DEBUG before including gc.h!
34 #ifdef LIBGCJ_GC_DEBUG
35 # define GC_DEBUG
36 #endif
37
38 #include <gc_mark.h>
39 #include <gc_gcj.h>
40 #include <javaxfc.h>  // GC_finalize_all declaration.  
41
42 #ifdef THREAD_LOCAL_ALLOC
43 # define GC_REDIRECT_TO_LOCAL
44 # include <gc_local_alloc.h>
45 #endif
46
47   // From boehm's misc.c 
48   void GC_enable();
49   void GC_disable();
50 };
51
52 #define MAYBE_MARK(Obj, Top, Limit, Source)  \
53         Top=GC_MARK_AND_PUSH((GC_PTR) Obj, Top, Limit, (GC_PTR *) Source)
54
55 // `kind' index used when allocating Java arrays.
56 static int array_kind_x;
57
58 // Freelist used for Java arrays.
59 static void **array_free_list;
60
61 \f
62
63 // This is called by the GC during the mark phase.  It marks a Java
64 // object.  We use `void *' arguments and return, and not what the
65 // Boehm GC wants, to avoid pollution in our headers.
66 void *
67 _Jv_MarkObj (void *addr, void *msp, void *msl, void *env)
68 {
69   struct GC_ms_entry *mark_stack_ptr = (struct GC_ms_entry *)msp;
70   struct GC_ms_entry *mark_stack_limit = (struct GC_ms_entry *)msl;
71
72   if (env == (void *)1) /* Object allocated with debug allocator.       */
73     addr = (GC_PTR)GC_USR_PTR_FROM_BASE(addr);
74   jobject obj = (jobject) addr;
75
76   _Jv_VTable *dt = *(_Jv_VTable **) addr;
77   // The object might not yet have its vtable set, or it might
78   // really be an object on the freelist.  In either case, the vtable slot
79   // will either be 0, or it will point to a cleared object.
80   // This assumes Java objects have size at least 3 words,
81   // including the header.   But this should remain true, since this
82   // should only be used with debugging allocation or with large objects.
83   if (__builtin_expect (! dt || !(dt -> get_finalizer()), false))
84     return mark_stack_ptr;
85   jclass klass = dt->clas;
86   GC_PTR p;
87
88 # ifndef JV_HASH_SYNCHRONIZATION
89     // Every object has a sync_info pointer.
90     p = (GC_PTR) obj->sync_info;
91     MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, obj);
92 # endif
93   // Mark the object's class.
94   p = (GC_PTR) klass;
95   MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, obj);
96
97   if (__builtin_expect (klass == &java::lang::Class::class$, false))
98     {
99       // Currently we allocate some of the memory referenced from class objects
100       // as pointerfree memory, and then mark it more intelligently here.
101       // We ensure that the ClassClass mark descriptor forces invocation of
102       // this procedure.
103       // Correctness of this is subtle, but it looks OK to me for now.  For the incremental
104       // collector, we need to make sure that the class object is written whenever
105       // any of the subobjects are altered and may need rescanning.  This may be tricky
106       // during construction, and this may not be the right way to do this with
107       // incremental collection.
108       // If we overflow the mark stack, we will rescan the class object, so we should
109       // be OK.  The same applies if we redo the mark phase because win32 unmapped part
110       // of our root set.               - HB
111       jclass c = (jclass) addr;
112
113       p = (GC_PTR) c->name;
114       MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c);
115       p = (GC_PTR) c->superclass;
116       MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c);
117       for (int i = 0; i < c->constants.size; ++i)
118         {
119           /* FIXME: We could make this more precise by using the tags -KKT */
120           p = (GC_PTR) c->constants.data[i].p;
121           MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c);
122         }
123
124 #ifdef INTERPRETER
125       if (_Jv_IsInterpretedClass (c))
126         {
127           p = (GC_PTR) c->constants.tags;
128           MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c);
129           p = (GC_PTR) c->constants.data;
130           MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c);
131         }
132 #endif
133
134       // The vtable might be allocated even for compiled code.
135       p = (GC_PTR) c->vtable;
136       MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c);
137
138       // If the class is an array, then the methods field holds a
139       // pointer to the element class.  If the class is primitive,
140       // then the methods field holds a pointer to the array class.
141       p = (GC_PTR) c->methods;
142       MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c);
143
144       // The vtable might have been set, but the rest of the class
145       // could still be uninitialized.  If this is the case, then
146       // c.isArray will SEGV.  We check for this, and if it is the
147       // case we just return.
148       if (__builtin_expect (c->name == NULL, false))
149         return mark_stack_ptr;
150
151       if (! c->isArray() && ! c->isPrimitive())
152         {
153           // Scan each method in the cases where `methods' really
154           // points to a methods structure.
155           for (int i = 0; i < c->method_count; ++i)
156             {
157               p = (GC_PTR) c->methods[i].name;
158               MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c);
159               p = (GC_PTR) c->methods[i].signature;
160               MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c);
161
162               // Note that we don't have to mark each individual throw
163               // separately, as these are stored in the constant pool.
164               p = (GC_PTR) c->methods[i].throws;
165               MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c);
166             }
167         }
168
169       // Mark all the fields.
170       p = (GC_PTR) c->fields;
171       MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c);
172       for (int i = 0; i < c->field_count; ++i)
173         {
174           _Jv_Field* field = &c->fields[i];
175
176           p = (GC_PTR) field->name;
177           MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c);
178           p = (GC_PTR) field->type;
179           MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c);
180
181           // For the interpreter, we also need to mark the memory
182           // containing static members
183           if ((field->flags & java::lang::reflect::Modifier::STATIC))
184             {
185               p = (GC_PTR) field->u.addr;
186               MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c);
187
188               // also, if the static member is a reference,
189               // mark also the value pointed to.  We check for isResolved
190               // since marking can happen before memory is allocated for
191               // static members.
192               // Note that field->u.addr may be null if the class c is
193               // JV_STATE_LOADED but not JV_STATE_PREPARED (initialized).
194               // Note also that field->type could be NULL in some
195               // situations, for instance if the class has state
196               // JV_STATE_ERROR.
197               if (field->type && JvFieldIsRef (field)
198                   && p && field->isResolved()) 
199                 {
200                   jobject val = *(jobject*) p;
201                   p = (GC_PTR) val;
202                   MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c);
203                 }
204             }
205         }
206
207       p = (GC_PTR) c->vtable;
208       MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c);
209       p = (GC_PTR) c->interfaces;
210       MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c);
211       for (int i = 0; i < c->interface_count; ++i)
212         {
213           p = (GC_PTR) c->interfaces[i];
214           MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c);
215         }
216       p = (GC_PTR) c->loader;
217       MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c);
218
219       // The dispatch tables can be allocated at runtime.
220       p = (GC_PTR) c->ancestors;
221       MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c);
222       if (c->idt)
223         {
224           p = (GC_PTR) c->idt;
225           MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c);
226
227           if (c->isInterface())
228             {
229               p = (GC_PTR) c->idt->iface.ioffsets;
230               MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c->idt);
231             }
232           else if (! c->isPrimitive())
233             {
234               // This field is only valid for ordinary classes.
235               p = (GC_PTR) c->idt->cls.itable;
236               MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c->idt);
237             }
238         }
239
240       p = (GC_PTR) c->arrayclass;
241       MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c);
242       p = (GC_PTR) c->protectionDomain;
243       MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c);
244       p = (GC_PTR) c->hack_signers;
245       MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c);
246       p = (GC_PTR) c->aux_info;
247       MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c);
248
249 #ifdef INTERPRETER
250       if (_Jv_IsInterpretedClass (c) && c->aux_info)
251         {
252           _Jv_InterpClass* ic = (_Jv_InterpClass*) c->aux_info;
253
254           p = (GC_PTR) ic->interpreted_methods;
255           MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, ic);
256
257           p = (GC_PTR) ic->source_file_name;
258           MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, ic);
259
260           for (int i = 0; i < c->method_count; i++)
261             {
262               // The interpreter installs a heap-allocated trampoline
263               // here, so we'll mark it.
264               p = (GC_PTR) c->methods[i].ncode;
265               MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c);
266
267               using namespace java::lang::reflect;
268
269               // Mark the direct-threaded code.  Note a subtlety here:
270               // when we add Miranda methods to a class, we don't
271               // resize its interpreted_methods array.  If we try to
272               // reference one of these methods, we may crash.
273               // However, we know these are all abstract, and we know
274               // that abstract methods have nothing useful in this
275               // array.  So, we skip all abstract methods to avoid the
276               // problem.  FIXME: this is pretty obscure, it may be
277               // better to add a methods to the execution engine and
278               // resize the array.
279               if ((c->methods[i].accflags & Modifier::ABSTRACT) != 0)
280                 continue;
281
282               p = (GC_PTR) ic->interpreted_methods[i];
283               MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, ic);
284
285               if ((c->methods[i].accflags & Modifier::NATIVE) != 0)
286                 {
287                   _Jv_JNIMethod *jm
288                     = (_Jv_JNIMethod *) ic->interpreted_methods[i];
289                   if (jm)
290                     {
291                       p = (GC_PTR) jm->jni_arg_types;
292                       MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, p);
293                     }
294                 }
295               else
296                 {
297                   _Jv_InterpMethod *im
298                     = (_Jv_InterpMethod *) ic->interpreted_methods[i];
299                   if (im)
300                     {
301                       p = (GC_PTR) im->line_table;
302                       MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, ic);
303                       p = (GC_PTR) im->prepared;
304                       MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, ic);
305                     }
306                 }
307             }
308
309           p = (GC_PTR) ic->field_initializers;
310           MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, ic);
311           
312         }
313 #endif
314
315     }
316   else
317     {
318       // NOTE: each class only holds information about the class
319       // itself.  So we must do the marking for the entire inheritance
320       // tree in order to mark all fields.  FIXME: what about
321       // interfaces?  We skip Object here, because Object only has a
322       // sync_info, and we handled that earlier.
323       // Note: occasionally `klass' can be null.  For instance, this
324       // can happen if a GC occurs between the point where an object
325       // is allocated and where the vtbl slot is set.
326       while (klass && klass != &java::lang::Object::class$)
327         {
328           jfieldID field = JvGetFirstInstanceField (klass);
329           jint max = JvNumInstanceFields (klass);
330
331           for (int i = 0; i < max; ++i)
332             {
333               if (JvFieldIsRef (field))
334                 {
335                   jobject val = JvGetObjectField (obj, field);
336                   p = (GC_PTR) val;
337                   MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, obj);
338                 }
339               field = field->getNextField ();
340             }
341           klass = klass->getSuperclass();
342         }
343     }
344
345   return mark_stack_ptr;
346 }
347
348 // This is called by the GC during the mark phase.  It marks a Java
349 // array (of objects).  We use `void *' arguments and return, and not
350 // what the Boehm GC wants, to avoid pollution in our headers.
351 void *
352 _Jv_MarkArray (void *addr, void *msp, void *msl, void *env)
353 {
354   struct GC_ms_entry *mark_stack_ptr = (struct GC_ms_entry *)msp;
355   struct GC_ms_entry *mark_stack_limit = (struct GC_ms_entry *)msl;
356
357   if (env == (void *)1) /* Object allocated with debug allocator.       */
358     addr = (void *)GC_USR_PTR_FROM_BASE(addr);
359   jobjectArray array = (jobjectArray) addr;
360
361   _Jv_VTable *dt = *(_Jv_VTable **) addr;
362   // Assumes size >= 3 words.  That's currently true since arrays have
363   // a vtable, sync pointer, and size.  If the sync pointer goes away,
364   // we may need to round up the size.
365   if (__builtin_expect (! dt || !(dt -> get_finalizer()), false))
366     return mark_stack_ptr;
367   jclass klass = dt->clas;
368   GC_PTR p;
369
370 # ifndef JV_HASH_SYNCHRONIZATION
371     // Every object has a sync_info pointer.
372     p = (GC_PTR) array->sync_info;
373     MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, array);
374 # endif
375   // Mark the object's class.
376   p = (GC_PTR) klass;
377   MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, &(dt -> clas));
378
379   for (int i = 0; i < JvGetArrayLength (array); ++i)
380     {
381       jobject obj = elements (array)[i];
382       p = (GC_PTR) obj;
383       MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, array);
384     }
385
386   return mark_stack_ptr;
387 }
388
389 // Generate a GC marking descriptor for a class.
390 //
391 // We assume that the gcj mark proc has index 0.  This is a dubious assumption,
392 // since another one could be registered first.  But the compiler also
393 // knows this, so in that case everything else will break, too.
394 #define GCJ_DEFAULT_DESCR GC_MAKE_PROC(GC_GCJ_RESERVED_MARK_PROC_INDEX,0)
395
396 void *
397 _Jv_BuildGCDescr(jclass self)
398 {
399   jlong desc = 0;
400   jint bits_per_word = CHAR_BIT * sizeof (void *);
401
402   // Note: for now we only consider a bitmap mark descriptor.  We
403   // could also handle the case where the first N fields of a type are
404   // references.  However, this is not very likely to be used by many
405   // classes, and it is easier to compute things this way.
406
407   // The vtable pointer.
408   desc |= 1ULL << (bits_per_word - 1);
409 #ifndef JV_HASH_SYNCHRONIZATION
410   // The sync_info field.
411   desc |= 1ULL << (bits_per_word - 2);
412 #endif
413
414   for (jclass klass = self; klass != NULL; klass = klass->getSuperclass())
415     {
416       jfieldID field = JvGetFirstInstanceField(klass);
417       int count = JvNumInstanceFields(klass);
418
419       for (int i = 0; i < count; ++i)
420         {
421           if (field->isRef())
422             {
423               unsigned int off = field->getOffset();
424               // If we run into a weird situation, we bail.
425               if (off % sizeof (void *) != 0)
426                 return (void *) (GCJ_DEFAULT_DESCR);
427               off /= sizeof (void *);
428               // If we find a field outside the range of our bitmap,
429               // fall back to procedure marker. The bottom 2 bits are
430               // reserved.
431               if (off >= (unsigned) bits_per_word - 2)
432                 return (void *) (GCJ_DEFAULT_DESCR);
433               desc |= 1ULL << (bits_per_word - off - 1);
434             }
435
436           field = field->getNextField();
437         }
438     }
439
440   // For bitmap mark type, bottom bits are 01.
441   desc |= 1;
442   // Bogus warning avoidance (on many platforms).
443   return (void *) (unsigned long) desc;
444 }
445
446 // Allocate some space that is known to be pointer-free.
447 void *
448 _Jv_AllocBytes (jsize size)
449 {
450   void *r = GC_MALLOC_ATOMIC (size);
451   // We have to explicitly zero memory here, as the GC doesn't
452   // guarantee that PTRFREE allocations are zeroed.  Note that we
453   // don't have to do this for other allocation types because we set
454   // the `ok_init' flag in the type descriptor.
455   memset (r, 0, size);
456   return r;
457 }
458
459 #ifdef LIBGCJ_GC_DEBUG
460
461 void *
462 _Jv_AllocObj (jsize size, jclass klass)
463 {
464   return GC_GCJ_MALLOC (size, klass->vtable);
465 }
466
467 void *
468 _Jv_AllocPtrFreeObj (jsize size, jclass klass)
469 {
470 #ifdef JV_HASH_SYNCHRONIZATION
471   void * obj = GC_MALLOC_ATOMIC(size);
472   *((_Jv_VTable **) obj) = klass->vtable;
473 #else
474   void * obj = GC_GCJ_MALLOC(size, klass->vtable);
475 #endif
476   return obj;
477 }
478
479 #endif /* LIBGCJ_GC_DEBUG */
480 // In the non-debug case, the above two functions are defined
481 // as inline functions in boehm-gc.h.  In the debug case we
482 // really want to take advantage of the definitions in gc_gcj.h.
483
484 // Allocate space for a new Java array.
485 // Used only for arrays of objects.
486 void *
487 _Jv_AllocArray (jsize size, jclass klass)
488 {
489   void *obj;
490
491 #ifdef LIBGCJ_GC_DEBUG
492   // There isn't much to lose by scanning this conservatively.
493   // If we didn't, the mark proc would have to understand that
494   // it needed to skip the header.
495   obj = GC_MALLOC(size);
496 #else
497   const jsize min_heap_addr = 16*1024;
498   // A heuristic.  If size is less than this value, the size
499   // stored in the array can't possibly be misinterpreted as
500   // a pointer.   Thus we lose nothing by scanning the object
501   // completely conservatively, since no misidentification can
502   // take place.
503   
504   if (size < min_heap_addr) 
505     obj = GC_MALLOC(size);
506   else 
507     obj = GC_generic_malloc (size, array_kind_x);
508 #endif
509   *((_Jv_VTable **) obj) = klass->vtable;
510   return obj;
511 }
512
513 /* Allocate space for a new non-Java object, which does not have the usual 
514    Java object header but may contain pointers to other GC'ed objects. */
515 void *
516 _Jv_AllocRawObj (jsize size)
517 {
518   return (void *) GC_MALLOC (size);
519 }
520
521 static void
522 call_finalizer (GC_PTR obj, GC_PTR client_data)
523 {
524   _Jv_FinalizerFunc *fn = (_Jv_FinalizerFunc *) client_data;
525   jobject jobj = (jobject) obj;
526
527   (*fn) (jobj);
528 }
529
530 void
531 _Jv_RegisterFinalizer (void *object, _Jv_FinalizerFunc *meth)
532 {
533   GC_REGISTER_FINALIZER_NO_ORDER (object, call_finalizer, (GC_PTR) meth,
534                                   NULL, NULL);
535 }
536
537 void
538 _Jv_RunFinalizers (void)
539 {
540   GC_invoke_finalizers ();
541 }
542
543 void
544 _Jv_RunAllFinalizers (void)
545 {
546   GC_finalize_all ();
547 }
548
549 void
550 _Jv_RunGC (void)
551 {
552   GC_gcollect ();
553 }
554
555 long
556 _Jv_GCTotalMemory (void)
557 {
558   return GC_get_heap_size ();
559 }
560
561 long
562 _Jv_GCFreeMemory (void)
563 {
564   return GC_get_free_bytes ();
565 }
566
567 void
568 _Jv_GCSetInitialHeapSize (size_t size)
569 {
570   size_t current = GC_get_heap_size ();
571   if (size > current)
572     GC_expand_hp (size - current);
573 }
574
575 void
576 _Jv_GCSetMaximumHeapSize (size_t size)
577 {
578   GC_set_max_heap_size ((GC_word) size);
579 }
580
581 void
582 _Jv_DisableGC (void)
583 {
584   GC_disable();
585 }
586
587 void
588 _Jv_EnableGC (void)
589 {
590   GC_enable();
591 }
592
593 static void * handle_out_of_memory(size_t)
594 {
595   _Jv_ThrowNoMemory();
596 }
597
598 static void
599 gcj_describe_type_fn(void *obj, char *out_buf)
600 {
601   _Jv_VTable *dt = *(_Jv_VTable **) obj;
602
603   if (! dt /* Shouldn't happen */)
604     {
605       strcpy(out_buf, "GCJ (bad)");
606       return;
607     }
608   jclass klass = dt->clas;
609   if (!klass /* shouldn't happen */)
610     {
611       strcpy(out_buf, "GCJ (bad)");
612       return;
613     }
614   jstring name = klass -> getName();
615   size_t len = name -> length();
616   if (len >= GC_TYPE_DESCR_LEN) len = GC_TYPE_DESCR_LEN - 1;
617   JvGetStringUTFRegion (name, 0, len, out_buf);
618   out_buf[len] = '\0';
619 }
620
621 void
622 _Jv_InitGC (void)
623 {
624   int proc;
625
626   // Ignore pointers that do not point to the start of an object.
627   GC_all_interior_pointers = 0;
628
629   // Configure the collector to use the bitmap marking descriptors that we
630   // stash in the class vtable.
631   // We always use mark proc descriptor 0, since the compiler knows
632   // about it.
633   GC_init_gcj_malloc (0, (void *) _Jv_MarkObj);  
634
635   // Cause an out of memory error to be thrown from the allocators,
636   // instead of returning 0.  This is cheaper than checking on allocation.
637   GC_oom_fn = handle_out_of_memory;
638
639   GC_java_finalization = 1;
640
641   // We use a different mark procedure for object arrays. This code 
642   // configures a different object `kind' for object array allocation and
643   // marking.
644   array_free_list = GC_new_free_list();
645   proc = GC_new_proc((GC_mark_proc)_Jv_MarkArray);
646   array_kind_x = GC_new_kind(array_free_list, GC_MAKE_PROC (proc, 0), 0, 1);
647
648   // Arrange to have the GC print Java class names in backtraces, etc.
649   GC_register_describe_type_fn(GC_gcj_kind, gcj_describe_type_fn);
650   GC_register_describe_type_fn(GC_gcj_debug_kind, gcj_describe_type_fn);
651 }
652
653 #ifdef JV_HASH_SYNCHRONIZATION
654 // Allocate an object with a fake vtable pointer, which causes only
655 // the first field (beyond the fake vtable pointer) to be traced.
656 // Eventually this should probably be generalized.
657
658 static _Jv_VTable trace_one_vtable = {
659     0,                  // class pointer
660     (void *)(2 * sizeof(void *)),
661                         // descriptor; scan 2 words incl. vtable ptr.
662                         // Least significant bits must be zero to
663                         // identify this as a length descriptor
664     {0}                 // First method
665 };
666
667 void *
668 _Jv_AllocTraceOne (jsize size /* includes vtable slot */) 
669 {
670   return GC_GCJ_MALLOC (size, &trace_one_vtable);
671 }
672
673 // Ditto for two words.
674 // the first field (beyond the fake vtable pointer) to be traced.
675 // Eventually this should probably be generalized.
676
677 static _Jv_VTable trace_two_vtable =
678 {
679   0,                    // class pointer
680   (void *)(3 * sizeof(void *)),
681                         // descriptor; scan 3 words incl. vtable ptr.
682   {0}                   // First method
683 };
684
685 void *
686 _Jv_AllocTraceTwo (jsize size /* includes vtable slot */) 
687 {
688   return GC_GCJ_MALLOC (size, &trace_two_vtable);
689 }
690
691 #endif /* JV_HASH_SYNCHRONIZATION */
692
693 void
694 _Jv_GCInitializeFinalizers (void (*notifier) (void))
695 {
696   GC_finalize_on_demand = 1;
697   GC_finalizer_notifier = notifier;
698 }
699
700 void
701 _Jv_GCRegisterDisappearingLink (jobject *objp)
702 {
703   // This test helps to ensure that we meet a precondition of
704   // GC_general_register_disappearing_link, viz. "Obj must be a
705   // pointer to the first word of an object we allocated."
706   if (GC_base(*objp))
707     GC_general_register_disappearing_link ((GC_PTR *) objp, (GC_PTR) *objp);
708 }
709
710 jboolean
711 _Jv_GCCanReclaimSoftReference (jobject)
712 {
713   // For now, always reclaim soft references.  FIXME.
714   return true;
715 }