aboutsummaryrefslogtreecommitdiff
path: root/libjava/boehm.cc
diff options
context:
space:
mode:
authorAndrew Haley <aph@redhat.com>2006-04-24 15:33:16 +0000
committerAndrew Haley <aph@gcc.gnu.org>2006-04-24 15:33:16 +0000
commit621ae65dcd01b01cbf1b4723d55653c8c1c7855b (patch)
tree843ad6f8c55847b78d8168eb919c303e362e94d6 /libjava/boehm.cc
parent5204d06d82d16eb89d871797cf4ff082f4fa9526 (diff)
lang.c (java_init): Handle flag_indirect_classes.
2006-04-21 Andrew Haley <aph@redhat.com> * lang.c (java_init): Handle flag_indirect_classes. * jvgenmain.c: Use "class$$" instead of "class$". * mangle.c (java_mangle_decl): Accept RECORD_TYPEs sw well as DECLs. (mangle_class_field): Special case "class$$" as well as "class$". * constants.c (build_ref_from_constant_pool): If flag_indirect_classes, generate a ref into the heap. * decl.c (constants_field_decl_node, constants_data_field_decl_node): New. * class.c (build_static_class_ref): New. (build_classdollar_field): Factor out from build_class_ref(). (make_field_value): Handle static fields in heap. (make_class_data): Make sure we get a static ref to class. Make class initializer const if flag_indirect_classes. (register_class): Build a class_ref for initialization if flag_indirect_classes. (emit_indirect_register_classes): New. 2006-04-21 Andrew Haley <aph@redhat.com> * include/execution.h (struct _Jv_CompiledEngine): Define for compiled classes. * java/lang/natClassLoader.cc (_Jv_RegisterClasses): Call _Jv_RegisterLibForGc. (_Jv_RegisterClasses_Counted): Likewise. (_Jv_NewClassFromInitializer): New. (_Jv_RegisterNewClasses): New. * sources.am: Regenerate. * boehm.cc (_Jv_GC_has_static_roots): new. (_Jv_InitGC): Call GC_register_has_static_roots_callback. (filename_node, find_file, _Jv_print_gc_store, new_node, _Jv_GC_has_static_roots, _Jv_RegisterLibForGc): New. * scripts/makemake.tcl: Add -fno-indirect-classes. * Makefile.in: Regenerate. * link.cc (resolve_pool_entry): Allocate constant pool. Allocate fields. From-SVN: r113224
Diffstat (limited to 'libjava/boehm.cc')
-rw-r--r--libjava/boehm.cc115
1 files changed, 115 insertions, 0 deletions
diff --git a/libjava/boehm.cc b/libjava/boehm.cc
index 7066e286b49..9ee633b34c3 100644
--- a/libjava/boehm.cc
+++ b/libjava/boehm.cc
@@ -32,6 +32,13 @@ details. */
#undef PACKAGE_TARNAME
#undef PACKAGE_VERSION
+#ifdef HAVE_DLFCN_H
+#undef _GNU_SOURCE
+#define _GNU_SOURCE
+#include <dlfcn.h>
+#include <link.h>
+#endif
+
extern "C"
{
#include <gc_config.h>
@@ -64,6 +71,8 @@ static int array_kind_x;
// Freelist used for Java arrays.
static void **array_free_list;
+static int _Jv_GC_has_static_roots (const char *filename, void *, size_t);
+
// This is called by the GC during the mark phase. It marks a Java
@@ -468,10 +477,21 @@ void
_Jv_InitGC (void)
{
int proc;
+ static bool gc_initialized;
+
+ if (gc_initialized)
+ return;
+
+ gc_initialized = 1;
// Ignore pointers that do not point to the start of an object.
GC_all_interior_pointers = 0;
+#ifdef HAVE_DLFCN_H
+ // Tell the collector to ask us before scanning DSOs.
+ GC_register_has_static_roots_callback (_Jv_GC_has_static_roots);
+#endif
+
// Configure the collector to use the bitmap marking descriptors that we
// stash in the class vtable.
// We always use mark proc descriptor 0, since the compiler knows
@@ -559,3 +579,98 @@ _Jv_GCCanReclaimSoftReference (jobject)
// For now, always reclaim soft references. FIXME.
return true;
}
+
+
+
+#ifdef HAVE_DLFCN_H
+
+// We keep a store of the filenames of DSOs that need to be
+// conservatively scanned by the garbage collector. During collection
+// the gc calls _Jv_GC_has_static_roots() to see if the data segment
+// of a DSO should be scanned.
+typedef struct filename_node
+{
+ char *name;
+ struct filename_node *link;
+} filename_node;
+
+#define FILENAME_STORE_SIZE 17
+static filename_node *filename_store[FILENAME_STORE_SIZE];
+
+// Find a filename in filename_store.
+static filename_node **
+find_file (const char *filename)
+{
+ int index = strlen (filename) % FILENAME_STORE_SIZE;
+ filename_node **node = &filename_store[index];
+
+ while (*node)
+ {
+ if (strcmp ((*node)->name, filename) == 0)
+ return node;
+ node = &(*node)->link;
+ }
+
+ return node;
+}
+
+// Print the store of filenames of DSOs that need collection.
+void
+_Jv_print_gc_store (void)
+{
+ for (int i = 0; i < FILENAME_STORE_SIZE; i++)
+ {
+ filename_node *node = filename_store[i];
+ while (node)
+ {
+ fprintf (stderr, "%s\n", node->name);
+ node = node->link;
+ }
+ }
+}
+
+// Create a new node in the store of libraries to collect.
+static filename_node *
+new_node (const char *filename)
+{
+ filename_node *node = (filename_node*)_Jv_Malloc (sizeof (filename_node));
+ node->name = (char *)_Jv_Malloc (strlen (filename) + 1);
+ node->link = NULL;
+ strcpy (node->name, filename);
+
+ return node;
+}
+
+// Nonzero if the gc should scan this lib.
+static int
+_Jv_GC_has_static_roots (const char *filename, void *, size_t)
+{
+ if (filename == NULL || strlen (filename) == 0)
+ // No filename; better safe than sorry.
+ return 1;
+
+ filename_node **node = find_file (filename);
+ if (*node)
+ return 1;
+
+ return 0;
+}
+
+#endif
+
+// Register the DSO that contains p for collection.
+void
+_Jv_RegisterLibForGc (const void *p __attribute__ ((__unused__)))
+{
+#ifdef HAVE_DLFCN_H
+ Dl_info info;
+
+ if (dladdr (p, &info) != 0)
+ {
+ filename_node **node = find_file (info.dli_fname);
+ if (! *node)
+ *node = new_node (info.dli_fname);
+ }
+#endif
+}
+