public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM]  archer-tromey-multi-inferior: make jit global per-progspace
@ 2010-09-28 21:21 tromey
  0 siblings, 0 replies; only message in thread
From: tromey @ 2010-09-28 21:21 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-multi-inferior has been updated
       via  8ae22c773d54261ec9bb6633b25ff3e956590597 (commit)
       via  0cc442af4a45501b888cd333b3dc175bfb032dc2 (commit)
      from  ed7454cbdc9dc889029e787145e1c1eaf8f6401d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 8ae22c773d54261ec9bb6633b25ff3e956590597
Author: Tom Tromey <tromey@redhat.com>
Date:   Tue Sep 28 12:18:25 2010 -0600

    make jit global per-progspace

commit 0cc442af4a45501b888cd333b3dc175bfb032dc2
Author: Tom Tromey <tromey@redhat.com>
Date:   Tue Sep 28 10:34:01 2010 -0600

    make java objfile per-progspace

-----------------------------------------------------------------------

Summary of changes:
 gdb/jit.c     |   45 +++++++++++++++++++++---
 gdb/jv-lang.c |  103 ++++++++++++++------------------------------------------
 2 files changed, 65 insertions(+), 83 deletions(-)

First 500 lines of diff:
diff --git a/gdb/jit.c b/gdb/jit.c
index a02847f..a853d0f0 100644
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -35,9 +35,10 @@ static const char *const jit_break_name = "__jit_debug_register_code";
 
 static const char *const jit_descriptor_name = "__jit_debug_descriptor";
 
-/* This is the address of the JIT descriptor in the inferior.  */
+/* The key used to find the JIT descriptor address in the current
+   program space.  */
 
-static CORE_ADDR jit_descriptor_addr = 0;
+static const struct program_space_data *jit_program_space_key;
 
 /* This is a boolean indicating whether we're currently registering code.  This
    is used to avoid re-entering the registration code.  We want to check for
@@ -133,6 +134,24 @@ bfd_open_from_target_memory (CORE_ADDR addr, size_t size, char *target)
                           mem_bfd_iovec_stat);
 }
 
+/* Return a pointer to the address of the JIT descriptor in the
+   current program space.  */
+
+static CORE_ADDR *
+jit_get_descriptor_pointer (void)
+{
+  void *p = program_space_data (current_program_space, jit_program_space_key);
+
+  if (p == NULL)
+    {
+      p = XCNEW (CORE_ADDR);
+      set_program_space_data (current_program_space, jit_program_space_key,
+			      p);
+    }
+
+  return p;
+}
+
 /* Helper function for reading the global JIT descriptor from remote memory.  */
 
 static void
@@ -145,6 +164,7 @@ jit_read_descriptor (struct gdbarch *gdbarch,
   int desc_size;
   gdb_byte *desc_buf;
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+  CORE_ADDR inf_addr = *jit_get_descriptor_pointer ();
 
   /* Figure out how big the descriptor is on the remote and how to read it.  */
   ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
@@ -153,7 +173,7 @@ jit_read_descriptor (struct gdbarch *gdbarch,
   desc_buf = alloca (desc_size);
 
   /* Read the descriptor.  */
-  err = target_read_memory (jit_descriptor_addr, desc_buf, desc_size);
+  err = target_read_memory (inf_addr, desc_buf, desc_size);
   if (err)
     error (_("Unable to read JIT descriptor from remote memory!"));
 
@@ -314,6 +334,7 @@ jit_inferior_init (struct gdbarch *gdbarch)
   struct jit_descriptor descriptor;
   struct jit_code_entry cur_entry;
   CORE_ADDR cur_entry_addr;
+  CORE_ADDR *desc_addr_ptr;
 
   /* When we register code, GDB resets its breakpoints in case symbols have
      changed.  That in turn calls this handler, which makes us look for new
@@ -335,8 +356,9 @@ jit_inferior_init (struct gdbarch *gdbarch)
   desc_symbol = lookup_minimal_symbol (jit_descriptor_name, NULL, NULL);
   if (desc_symbol == NULL)
     return;
-  jit_descriptor_addr = SYMBOL_VALUE_ADDRESS (desc_symbol);
-  if (jit_descriptor_addr == 0)
+  desc_addr_ptr = jit_get_descriptor_pointer ();
+  *desc_addr_ptr = SYMBOL_VALUE_ADDRESS (desc_symbol);
+  if (*desc_addr_ptr == 0)
     return;
 
   /* Read the descriptor so we can check the version number and load any already
@@ -401,10 +423,11 @@ jit_inferior_exit_hook (struct inferior *inf)
 {
   struct objfile *objf;
   objfile_iterator_type iter, temp;
+  CORE_ADDR *desc_addr_ptr = jit_get_descriptor_pointer ();
 
   /* We need to reset the descriptor addr so that next time we load up the
      inferior we look for it again.  */
-  jit_descriptor_addr = 0;
+  *desc_addr_ptr = 0;
 
   ALL_OBJFILES_SAFE (iter, objf, temp)
     if (objfile_data (objf, jit_objfile_data) != NULL)
@@ -447,6 +470,14 @@ jit_event_handler (struct gdbarch *gdbarch)
     }
 }
 
+/* Clean up the JIT-specific program space data.  */
+
+static void
+jit_program_space_cleanup (struct program_space *ignore, void *data)
+{
+  xfree (data);
+}
+
 /* Provide a prototype to silence -Wmissing-prototypes.  */
 
 extern void _initialize_jit (void);
@@ -457,4 +488,6 @@ _initialize_jit (void)
   observer_attach_inferior_created (jit_inferior_created_observer);
   observer_attach_inferior_exit (jit_inferior_exit_hook);
   jit_objfile_data = register_objfile_data ();
+  jit_program_space_key
+    = register_program_space_data_with_cleanup (jit_program_space_cleanup);
 }
diff --git a/gdb/jv-lang.c b/gdb/jv-lang.c
index 5751200..fe99928 100644
--- a/gdb/jv-lang.c
+++ b/gdb/jv-lang.c
@@ -56,35 +56,13 @@ static void java_emit_char (int c, struct type *type,
 
 static char *java_class_name_from_physname (const char *physname);
 
-static const struct objfile_data *jv_dynamics_objfile_data_key;
-static const struct objfile_data *jv_type_objfile_data_key;
-
-/* This objfile contains symtabs that have been dynamically created
-   to record dynamically loaded Java classes and dynamically
-   compiled java methods. */
-
-static struct objfile *dynamics_objfile = NULL;
-
-/* symtab contains classes read from the inferior. */
-
-static struct symtab *class_symtab = NULL;
+/* The dynamic objfile is kept per-program-space.  This key lets us
+   associate the objfile with the program space.  */
+static const struct program_space_data *jv_dynamics_progspace_key;
 
 static struct type *java_link_class_type (struct gdbarch *,
 					  struct type *, struct value *);
 
-/* A function called when the dynamics_objfile is freed.  We use this
-   to clean up some internal state.  */
-static void
-jv_per_objfile_free (struct objfile *objfile, void *ignore)
-{
-  gdb_assert (objfile == dynamics_objfile);
-  /* Clean up all our cached state.  These objects are all allocated
-     in the dynamics_objfile, so we don't need to actually free
-     anything.  */
-  dynamics_objfile = NULL;
-  class_symtab = NULL;
-}
-
 /* FIXME: carlton/2003-02-04: This is the main or only caller of
    allocate_objfile with first argument NULL; as a result, this code
    breaks every so often.  Somebody should write a test case that
@@ -94,18 +72,21 @@ jv_per_objfile_free (struct objfile *objfile, void *ignore)
 static struct objfile *
 get_dynamics_objfile (struct gdbarch *gdbarch)
 {
+  struct objfile *dynamics_objfile;
+
+  dynamics_objfile = program_space_data (current_program_space,
+					 jv_dynamics_progspace_key);
+
   if (dynamics_objfile == NULL)
     {
       /* Mark it as shared so that it is cleared when the inferior is
 	 re-run.  */
       dynamics_objfile = allocate_objfile (NULL, OBJF_SHARED);
       OBJFILE_GDBARCH (dynamics_objfile) = gdbarch;
-      /* We don't have any data to store, but this lets us get a
-	 notification when the objfile is destroyed.  Since we have to
-	 store a non-NULL value, we just pick something arbitrary and
-	 safe.  */
-      set_objfile_data (dynamics_objfile, jv_dynamics_objfile_data_key,
-			&dynamics_objfile);
+
+      set_program_space_data (current_program_space,
+			      jv_dynamics_progspace_key,
+			      dynamics_objfile);
     }
   return dynamics_objfile;
 }
@@ -115,9 +96,11 @@ static void free_class_block (struct symtab *symtab);
 static struct symtab *
 get_java_class_symtab (struct gdbarch *gdbarch)
 {
+  struct objfile *objfile = get_dynamics_objfile (gdbarch);
+  struct symtab *class_symtab = OBJFILE_SYMTABS (objfile);
+
   if (class_symtab == NULL)
     {
-      struct objfile *objfile = get_dynamics_objfile (gdbarch);
       struct blockvector *bv;
       struct block *bl;
 
@@ -158,9 +141,10 @@ static struct symbol *
 add_class_symbol (struct type *type, CORE_ADDR addr)
 {
   struct symbol *sym;
+  struct objfile *objfile = get_dynamics_objfile (get_type_arch (type));
 
   sym = (struct symbol *)
-    obstack_alloc (&OBJFILE_OBSTACK (dynamics_objfile), sizeof (struct symbol));
+    obstack_alloc (&OBJFILE_OBSTACK (objfile), sizeof (struct symbol));
   memset (sym, 0, sizeof (struct symbol));
   SYMBOL_LANGUAGE (sym) = language_java;
   SYMBOL_SET_LINKAGE_NAME (sym, TYPE_TAG_NAME (type));
@@ -483,7 +467,7 @@ java_link_class_type (struct gdbarch *gdbarch,
   TYPE_NFN_FIELDS_TOTAL (type) = nmethods;
   j = nmethods * sizeof (struct fn_field);
   fn_fields = (struct fn_field *)
-    obstack_alloc (&OBJFILE_OBSTACK (dynamics_objfile), j);
+    obstack_alloc (&OBJFILE_OBSTACK (objfile), j);
   memset (fn_fields, 0, j);
   fn_fieldlists = (struct fn_fieldlist *)
     alloca (nmethods * sizeof (struct fn_fieldlist));
@@ -561,49 +545,21 @@ java_link_class_type (struct gdbarch *gdbarch,
 
   j = TYPE_NFN_FIELDS (type) * sizeof (struct fn_fieldlist);
   TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
-    obstack_alloc (&OBJFILE_OBSTACK (dynamics_objfile), j);
+    obstack_alloc (&OBJFILE_OBSTACK (objfile), j);
   memcpy (TYPE_FN_FIELDLISTS (type), fn_fieldlists, j);
 
   return type;
 }
 
-static struct type *java_object_type;
-
-/* A free function that is attached to the objfile defining
-   java_object_type.  This is used to clear the cached type whenever
-   its owning objfile is destroyed.  */
-static void
-jv_clear_object_type (struct objfile *objfile, void *ignore)
-{
-  java_object_type = NULL;
-}
-
-static void
-set_java_object_type (struct type *type)
-{
-  struct objfile *owner;
-
-  gdb_assert (java_object_type == NULL);
-
-  owner = TYPE_OBJFILE (type);
-  if (owner)
-    set_objfile_data (owner, jv_type_objfile_data_key, &java_object_type);
-  java_object_type = type;
-}
-
 struct type *
 get_java_object_type (void)
 {
-  if (java_object_type == NULL)
-    {
-      struct symbol *sym;
+  struct symbol *sym;
 
-      sym = lookup_symbol ("java.lang.Object", NULL, STRUCT_DOMAIN, NULL);
-      if (sym == NULL)
-	error (_("cannot find java.lang.Object"));
-      set_java_object_type (SYMBOL_TYPE (sym));
-    }
-  return java_object_type;
+  sym = lookup_symbol ("java.lang.Object", NULL, STRUCT_DOMAIN, NULL);
+  if (sym == NULL)
+    error (_("cannot find java.lang.Object"));
+  return SYMBOL_TYPE (sym);
 }
 
 int
@@ -634,11 +590,7 @@ is_object_type (struct type *type)
 	return 1;
       name = TYPE_NFIELDS (ttype) > 0 ? TYPE_FIELD_NAME (ttype, 0) : (char *) 0;
       if (name != NULL && strcmp (name, "vtable") == 0)
-	{
-	  if (java_object_type == NULL)
-	    set_java_object_type (type);
-	  return 1;
-	}
+	return 1;
     }
   return 0;
 }
@@ -1224,10 +1176,7 @@ builtin_java_type (struct gdbarch *gdbarch)
 void
 _initialize_java_language (void)
 {
-  jv_dynamics_objfile_data_key
-    = register_objfile_data_with_cleanup (NULL, jv_per_objfile_free);
-  jv_type_objfile_data_key
-    = register_objfile_data_with_cleanup (NULL, jv_clear_object_type);
+  jv_dynamics_progspace_key = register_program_space_data ();
 
   java_type_data = gdbarch_data_register_post_init (build_java_types);
 


hooks/post-receive
--
Repository for Project Archer.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-09-28 21:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-28 21:21 [SCM] archer-tromey-multi-inferior: make jit global per-progspace tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).