public inbox for java-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Steven Bosscher <stevenb.gcc@gmail.com>
To: gcc-patches@gcc.gnu.org, java-patches@gcc.gnu.org
Cc: Richard Guenther <richard.guenther@gmail.com>,
	Eric Botcazou <ebotcazou@adacore.com>
Subject: [patch][rfa] Do not call output_constant from the front end
Date: Tue, 27 Mar 2012 22:23:00 -0000	[thread overview]
Message-ID: <CABu31nN--GqGPuaGjqq6ZQBdNYwp0wkWO06A5NJ+fk1igig06g@mail.gmail.com> (raw)
In-Reply-To: <CABu31nOk3X1LXeFdq8UEyOvjmWuc3RKRtBtqg4cm7Wq51Ej9nw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1030 bytes --]

On Tue, Mar 27, 2012 at 11:51 PM, Steven Bosscher <stevenb.gcc@gmail.com> wrote:
> On Tue, Mar 27, 2012 at 11:07 PM, Eric Botcazou <ebotcazou@adacore.com> wrote:
>>> With this patch a variable named "_Jv_CLS" is written out. The
>>> assembly before and after the patch is the same, except for the
>>> variable name. I want to write out a nameless variable but I don't
>>> know how.
>>
>> Try tree_output_constant_def.
>
> I didn't know about this function. But as far as I can tell, there is
> no way to instruct that function to put the data in a specific
> section. In the Java case, the data must be put in the .jcr section. I
> suppose that can be achieved with a bit more re-working of varasm, but
> not with the code as-is. Thanks for the pointer, though!

It also doesn't appear to be possible to adjust the alignment via
tree_output_constant_def(), so going down that path seems more trouble
than it's worth.

Therefore, an RFA for the attached patch. Bootstrapped&tested on
powerpc64-unknown-linux-gnu. OK?

Ciao!
Steven

[-- Attachment #2: java_no_output_constant.diff --]
[-- Type: text/x-patch, Size: 5043 bytes --]

java/
	PR java/52730
	* class.c (emit_register_classes_in_jcr_section): New function.
	(emit_Jv_RegisterClass_calls): New function, split out from ...
	(emit_register_classes): ... here.  Reorganize.  Do not call
	output_constant.

Index: class.c
===================================================================
--- class.c	(revision 185813)
+++ class.c	(working copy)
@@ -2786,10 +2786,78 @@ emit_indirect_register_classes (tree *list_p)
   append_to_statement_list (t, list_p);
 }
 
+/* Emit a list of pointers to all classes we have emitted to JCR_SECTION.  */
 
+static void
+emit_register_classes_in_jcr_section (void)
+{
+  tree klass, cdecl, class_array_type;
+  int i;
+  int size = VEC_length (tree, registered_class);
+  VEC(constructor_elt,gc) *init = VEC_alloc (constructor_elt, gc, size);
+
+#ifndef JCR_SECTION_NAME
+  /* A target has defined TARGET_USE_JCR_SECTION,
+     but doesn't have a JCR_SECTION_NAME.  */
+  gcc_unreachable ();
+#endif
+
+  FOR_EACH_VEC_ELT (tree, registered_class, i, klass)
+    CONSTRUCTOR_APPEND_ELT (init, NULL_TREE, build_fold_addr_expr (klass));
+
+  /* ??? I would like to use tree_output_constant_def() but there is no way
+	 to put the data in a named section name, or to set the alignment,
+	 via that function.  So do everything manually here.  */
+  class_array_type = build_prim_array_type (ptr_type_node, size);
+  cdecl = build_decl (UNKNOWN_LOCATION,
+		      VAR_DECL, get_identifier ("_Jv_JCR_SECTION_data"),
+		      class_array_type);
+  DECL_SECTION_NAME (cdecl) = build_string (strlen (JCR_SECTION_NAME),
+					    JCR_SECTION_NAME);
+  DECL_ALIGN (cdecl) = POINTER_SIZE;
+  DECL_INITIAL (cdecl) = build_constructor (class_array_type, init);
+  TREE_CONSTANT (DECL_INITIAL (cdecl)) = 1;
+  TREE_STATIC (cdecl) = 1;
+  TREE_READONLY (cdecl) = 1;
+  TREE_CONSTANT (cdecl) = 1;
+  DECL_ARTIFICIAL (cdecl) = 1;
+  DECL_IGNORED_P (cdecl) = 1;
+  pushdecl_top_level (cdecl);
+  relayout_decl (cdecl);
+  rest_of_decl_compilation (cdecl, 1, 0);
+  mark_decl_referenced (cdecl);
+}
+
+
+/* Emit a series of calls to _Jv_RegisterClass for every class we emitted.
+   A series of calls is added to LIST_P.  */
+
+static void
+emit_Jv_RegisterClass_calls (tree *list_p)
+{
+  tree klass, t, register_class_fn;
+  int i;
+
+  t = build_function_type_list (void_type_node, class_ptr_type, NULL);
+  t = build_decl (input_location,
+		  FUNCTION_DECL, get_identifier ("_Jv_RegisterClass"), t);
+  TREE_PUBLIC (t) = 1;
+  DECL_EXTERNAL (t) = 1;
+  register_class_fn = t;
+
+  FOR_EACH_VEC_ELT (tree, registered_class, i, klass)
+    {
+      t = build_fold_addr_expr (klass);
+      t = build_call_expr (register_class_fn, 1, t);
+      append_to_statement_list (t, list_p);
+    }
+}
+
 /* Emit something to register classes at start-up time.
 
-   The preferred mechanism is through the .jcr section, which contain
+   The default mechanism is to generate instances at run-time.
+
+   An alternative mechanism is through the .jcr section, which contain
    a list of pointers to classes which get registered during constructor
    invocation time.
 
@@ -2803,55 +2871,18 @@ emit_register_classes (tree *list_p)
   if (registered_class == NULL)
     return;
 
+  /* By default, generate instances of Class at runtime.  */
   if (flag_indirect_classes)
-    {
-      emit_indirect_register_classes (list_p);
-      return;
-    }
-
+    emit_indirect_register_classes (list_p);
   /* TARGET_USE_JCR_SECTION defaults to 1 if SUPPORTS_WEAK and
      TARGET_ASM_NAMED_SECTION, else 0.  Some targets meet those conditions
      but lack suitable crtbegin/end objects or linker support.  These
      targets can override the default in tm.h to use the fallback mechanism.  */
-  if (TARGET_USE_JCR_SECTION)
-    {
-      tree klass, t;
-      int i;
-
-#ifdef JCR_SECTION_NAME
-      switch_to_section (get_section (JCR_SECTION_NAME, SECTION_WRITE, NULL));
-#else
-      /* A target has defined TARGET_USE_JCR_SECTION,
-	 but doesn't have a JCR_SECTION_NAME.  */
-      gcc_unreachable ();
-#endif
-      assemble_align (POINTER_SIZE);
-
-      FOR_EACH_VEC_ELT (tree, registered_class, i, klass)
-	{
-	  t = build_fold_addr_expr (klass);
-	  output_constant (t, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE);
-	}
-    }
+  else if (TARGET_USE_JCR_SECTION)
+    emit_register_classes_in_jcr_section ();
+  /* Use the fallback mechanism.  */
   else
-    {
-      tree klass, t, register_class_fn;
-      int i;
-
-      t = build_function_type_list (void_type_node, class_ptr_type, NULL);
-      t = build_decl (input_location,
-		      FUNCTION_DECL, get_identifier ("_Jv_RegisterClass"), t);
-      TREE_PUBLIC (t) = 1;
-      DECL_EXTERNAL (t) = 1;
-      register_class_fn = t;
-
-      FOR_EACH_VEC_ELT (tree, registered_class, i, klass)
-	{
-	  t = build_fold_addr_expr (klass);
-	  t = build_call_expr (register_class_fn, 1, t);
-	  append_to_statement_list (t, list_p);
-	}
-    }
+    emit_Jv_RegisterClass_calls (list_p);
 }
 
 /* Build a constructor for an entry in the symbol table.  */

  reply	other threads:[~2012-03-27 22:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-27 20:36 [patch] " Steven Bosscher
2012-03-27 21:07 ` Eric Botcazou
2012-03-27 21:52   ` Steven Bosscher
2012-03-27 22:23     ` Steven Bosscher [this message]
2012-03-28  7:46       ` [patch][rfa] " Andrew Haley
2012-03-28 10:02       ` Richard Guenther
2012-03-29 21:04         ` Steven Bosscher
2012-04-02 12:24       ` Rainer Orth
2012-04-02 12:29         ` Richard Guenther

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CABu31nN--GqGPuaGjqq6ZQBdNYwp0wkWO06A5NJ+fk1igig06g@mail.gmail.com \
    --to=stevenb.gcc@gmail.com \
    --cc=ebotcazou@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=java-patches@gcc.gnu.org \
    --cc=richard.guenther@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).