Patch: class initialization optimization

Tom Tromey tromey@cygnus.com
Thu May 18 12:34:00 GMT 2000


This adds a minor optimization to class initialization.  Currently we
keep a local variable per class to see if we need to do the class
initialization.  This patch changes things so that this variable is
initialized by looking to see if the class has already been
initialized.  This means we can skip a function call in some
situations, at the cost of a load+comparison or so.

I bootstrapped libgcj with this, and "make check" seemed ok (no worse,
anyway).

Ok to commit?

2000-05-17  Tom Tromey  <tromey@cygnus.com>

	* java-tree.h: Added init state enum.
	* decl.c (emit_init_test_initialization): Initialize class
	initialization check variable by looking at class' state.

Tom

Index: java-tree.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/java-tree.h,v
retrieving revision 1.67
diff -u -r1.67 java-tree.h
--- java-tree.h	2000/05/05 04:23:23	1.67
+++ java-tree.h	2000/05/17 21:35:35
@@ -1160,5 +1162,26 @@
      if (java_error_count > save_error_count)				\
        return;								\
    }
+
+/* These are the possible values for the `state' field of the class
+   structure.  This must be kept in sync with libgcj.  */
+enum
+{
+  JV_STATE_NOTHING = 0,		/* Set by compiler.  */
+
+  JV_STATE_PRELOADING = 1,	/* Can do _Jv_FindClass.  */
+  JV_STATE_LOADING = 3,		/* Has super installed.  */
+  JV_STATE_LOADED = 5,		/* Is complete.  */
+
+  JV_STATE_COMPILED = 6,	/* This was a compiled class.  */
+
+  JV_STATE_PREPARED = 7,	/* Layout & static init done.  */
+  JV_STATE_LINKED = 9,		/* Strings interned.  */
+
+  JV_STATE_IN_PROGRESS = 10,	/* <Clinit> running.  */
+  JV_STATE_DONE = 12,
+
+  JV_STATE_ERROR = 14		/* must be last.  */
+};
 
 #undef DEBUG_JAVA_BINDING_LEVELS
Index: decl.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/decl.c,v
retrieving revision 1.65
diff -u -r1.65 decl.c
--- decl.c	2000/05/06 20:32:55	1.65
+++ decl.c	2000/05/17 21:35:40
@@ -1681,17 +1681,29 @@
 
 /* Called for every element in DECL_FUNCTION_INIT_TEST_TABLE in order
    to emit initialization code for each test flag.  */
-   
+
 static boolean
 emit_init_test_initialization (entry, key)
   struct hash_entry *entry;
   hash_table_key key ATTRIBUTE_UNUSED;
 {
   struct init_test_hash_entry *ite = (struct init_test_hash_entry *) entry;
+  tree klass = build_class_ref ((tree) entry->key);
   expand_decl (ite->init_test_decl);
 
-  expand_expr_stmt (build (MODIFY_EXPR, boolean_type_node, 
-			   ite->init_test_decl, boolean_false_node));
+  /* We initialize the class init check variable by looking at the
+     `state' field of the class to see if it is already initialized.
+     This makes things a bit faster if the class is already
+     initialized, which should be the common case.  */
+  expand_expr_stmt
+    (build (MODIFY_EXPR, boolean_type_node, 
+	    ite->init_test_decl,
+	    build (GE_EXPR, boolean_type_node,
+		   build (COMPONENT_REF, byte_type_node,
+			  build1 (INDIRECT_REF, class_type_node, klass),
+			  lookup_field (&class_type_node,
+					get_identifier ("state"))),
+		   build_int_2 (JV_STATE_DONE, 0))));
 
   return true;
 }


More information about the Gcc-patches mailing list