This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[java]Remove TYPE_NVIRTUALS


Hi,
this patch removes TYPE_NVIRTUALS from java, relying on TYPE_VTABLE
exclusively.  I'm going to start hacking around with the BINFO_VIRTUALS
data structure in the C++ FE (to reduce memory, of course), and this
patch insulates Java from all that.

booted & checked on i686-linux-gnu, ok?

nathan
--
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

2004-09-14  Nathan Sidwell  <nathan@codesourcery.com>

	* java-tree.h (TYPE_NVIRTUALS): Remove.
	(VTABLE_INITED_P): New.
	(layout_class_method): Take and return a HOST_WIDE_INT.
	* class.c (get_dispatch_vector): Test & set VTABLE_INITED_P,
	adjust.
	(make_class_data): Use length of TYPE_VTABLE.
	(layout_class_methods): Use TYPE_VTABLE, adjust.
	(layout_class_method): Take and return a HOST_WIDE_INT for the index.
	* parse.y (generate_finit): Adjust layout_class_method call.
	(generate_instinit, maybe_generate_pre_expand_clinit,
	build_outer_field_access_method, maybe_build_thisn_access_method,
	build_dot_class_method, lookup_method_invoke): Likewise.
	(java_check_regular_methods): Check TYPE_VTABLE.

Index: java/class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/class.c,v
retrieving revision 1.207
diff -c -3 -p -r1.207 class.c
*** java/class.c	14 Sep 2004 01:50:12 -0000	1.207
--- java/class.c	14 Sep 2004 16:04:09 -0000
*************** get_dispatch_vector (tree type)
*** 1376,1394 ****
  {
    tree vtable = TYPE_VTABLE (type);
  
!   if (vtable == NULL_TREE)
      {
        HOST_WIDE_INT i;
        tree method;
        tree super = CLASSTYPE_SUPER (type);
!       HOST_WIDE_INT nvirtuals = tree_low_cst (TYPE_NVIRTUALS (type), 0);
!       vtable = make_tree_vec (nvirtuals);
!       TYPE_VTABLE (type) = vtable;
        if (super != NULL_TREE)
  	{
  	  tree super_vtable = get_dispatch_vector (super);
  
! 	  for (i = tree_low_cst (TYPE_NVIRTUALS (super), 0); --i >= 0; )
  	    TREE_VEC_ELT (vtable, i) = TREE_VEC_ELT (super_vtable, i);
  	}
  
--- 1376,1392 ----
  {
    tree vtable = TYPE_VTABLE (type);
  
!   if (!VTABLE_INITED_P (vtable))
      {
        HOST_WIDE_INT i;
        tree method;
        tree super = CLASSTYPE_SUPER (type);
!       
        if (super != NULL_TREE)
  	{
  	  tree super_vtable = get_dispatch_vector (super);
  
! 	  for (i = TREE_VEC_LENGTH (super_vtable); --i >= 0; )
  	    TREE_VEC_ELT (vtable, i) = TREE_VEC_ELT (super_vtable, i);
  	}
  
*************** get_dispatch_vector (tree type)
*** 1400,1405 ****
--- 1398,1404 ----
  	      && host_integerp (method_index, 0))
  	    TREE_VEC_ELT (vtable, tree_low_cst (method_index, 0)) = method;
  	}
+       VTABLE_INITED_P (vtable) = 1;
      }
  
    return vtable;
*************** make_class_data (tree type)
*** 1755,1761 ****
    if (flag_indirect_dispatch)
      PUSH_FIELD_VALUE (cons, "vtable_method_count", integer_minus_one_node);
    else
!     PUSH_FIELD_VALUE (cons, "vtable_method_count", TYPE_NVIRTUALS (type));
      
    PUSH_FIELD_VALUE (cons, "fields",
  		    fields_decl == NULL_TREE ? null_pointer_node
--- 1754,1762 ----
    if (flag_indirect_dispatch)
      PUSH_FIELD_VALUE (cons, "vtable_method_count", integer_minus_one_node);
    else
!     PUSH_FIELD_VALUE (cons, "vtable_method_count",
! 		      build_int_cst (NULL_TREE,
! 				     TREE_VEC_LENGTH (TYPE_VTABLE (type))));
      
    PUSH_FIELD_VALUE (cons, "fields",
  		    fields_decl == NULL_TREE ? null_pointer_node
*************** add_miranda_methods (tree base_class, tr
*** 2162,2171 ****
  void
  layout_class_methods (tree this_class)
  {
!   tree method_decl, dtable_count;
    tree super_class, type_name;
  
!   if (TYPE_NVIRTUALS (this_class))
      return;
  
    super_class = CLASSTYPE_SUPER (this_class);
--- 2163,2173 ----
  void
  layout_class_methods (tree this_class)
  {
!   tree method_decl;
!   HOST_WIDE_INT dtable_count;
    tree super_class, type_name;
  
!   if (TYPE_VTABLE (this_class))
      return;
  
    super_class = CLASSTYPE_SUPER (this_class);
*************** layout_class_methods (tree this_class)
*** 2173,2184 ****
    if (super_class)
      {
        super_class = maybe_layout_super_class (super_class, this_class);
!       if (!TYPE_NVIRTUALS (super_class))
  	layout_class_methods (super_class);
!       dtable_count = TYPE_NVIRTUALS (super_class);
      }
    else
!     dtable_count = integer_zero_node;
  
    type_name = TYPE_NAME (this_class);
    if (CLASS_ABSTRACT (type_name) || CLASS_INTERFACE (type_name))
--- 2175,2186 ----
    if (super_class)
      {
        super_class = maybe_layout_super_class (super_class, this_class);
!       if (!TYPE_VTABLE (super_class))
  	layout_class_methods (super_class);
!       dtable_count = TREE_VEC_LENGTH (TYPE_VTABLE (super_class));
      }
    else
!     dtable_count = 0;
  
    type_name = TYPE_NAME (this_class);
    if (CLASS_ABSTRACT (type_name) || CLASS_INTERFACE (type_name))
*************** layout_class_methods (tree this_class)
*** 2197,2203 ****
      dtable_count = layout_class_method (this_class, super_class,
  					method_decl, dtable_count);
  
!   TYPE_NVIRTUALS (this_class) = dtable_count;
  }
  
  /* Return the index of METHOD in INTERFACE.  This index begins at 1 and is used as an
--- 2199,2205 ----
      dtable_count = layout_class_method (this_class, super_class,
  					method_decl, dtable_count);
  
!   TYPE_VTABLE (this_class) = make_tree_vec (dtable_count);
  }
  
  /* Return the index of METHOD in INTERFACE.  This index begins at 1 and is used as an
*************** get_interface_method_index (tree method,
*** 2220,2228 ****
  /* Lay METHOD_DECL out, returning a possibly new value of
     DTABLE_COUNT. Also mangle the method's name. */
  
! tree
  layout_class_method (tree this_class, tree super_class,
! 		     tree method_decl, tree dtable_count)
  {
    tree method_name = DECL_NAME (method_decl);
  
--- 2222,2230 ----
  /* Lay METHOD_DECL out, returning a possibly new value of
     DTABLE_COUNT. Also mangle the method's name. */
  
! HOST_WIDE_INT
  layout_class_method (tree this_class, tree super_class,
! 		     tree method_decl, HOST_WIDE_INT dtable_count)
  {
    tree method_name = DECL_NAME (method_decl);
  
*************** layout_class_method (tree this_class, tr
*** 2284,2297 ****
  	    error ("%Jnon-static method '%D' overrides static method",
                     method_decl, method_decl);
  	}
!       else if (! METHOD_FINAL (method_decl)
  	       && ! METHOD_PRIVATE (method_decl)
! 	       && ! CLASS_FINAL (TYPE_NAME (this_class))
! 	       && dtable_count)
  	{
! 	  set_method_index (method_decl, dtable_count);
! 	  dtable_count = fold (build2 (PLUS_EXPR, integer_type_node,
! 				       dtable_count, integer_one_node));
  	}
      }
  
--- 2286,2299 ----
  	    error ("%Jnon-static method '%D' overrides static method",
                     method_decl, method_decl);
  	}
!       else if (dtable_count >= 0
! 	       && ! METHOD_FINAL (method_decl)
  	       && ! METHOD_PRIVATE (method_decl)
! 	       && ! CLASS_FINAL (TYPE_NAME (this_class)))
  	{
! 	  set_method_index (method_decl,
! 			    build_int_cst (NULL_TREE, dtable_count));
! 	  dtable_count += 1;
  	}
      }
  
Index: java/java-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/java-tree.h,v
retrieving revision 1.216
diff -c -3 -p -r1.216 java-tree.h
*** java/java-tree.h	10 Aug 2004 04:29:16 -0000	1.216
--- java/java-tree.h	14 Sep 2004 16:04:14 -0000
*************** struct JCF;
*** 48,53 ****
--- 48,54 ----
        SUPPRESS_UNREACHABLE_ERROR (for other _EXPR nodes)
        ANONYMOUS_CLASS_P (in RECORD_TYPE)
        ARG_FINAL_P (in TREE_LIST)
+       VTABLE_INITED_P (in TREE_VEC of a TYPE_VTABLE)
     1: IS_A_CLASSFILE_NAME (in IDENTIFIER_NODE)
        COMPOUND_ASSIGN_P (in EXPR (binop_*))
        LOCAL_CLASS_P (in RECORD_TYPE)
*************** extern tree parse_signature_string (cons
*** 1149,1155 ****
  extern tree get_type_from_signature (tree);
  extern void layout_class (tree);
  extern int get_interface_method_index (tree, tree);
! extern tree layout_class_method (tree, tree, tree, tree);
  extern void layout_class_methods (tree);
  extern tree build_class_ref (tree);
  extern tree build_dtable_decl (tree);
--- 1150,1156 ----
  extern tree get_type_from_signature (tree);
  extern void layout_class (tree);
  extern int get_interface_method_index (tree, tree);
! extern HOST_WIDE_INT layout_class_method (tree, tree, tree, HOST_WIDE_INT);
  extern void layout_class_methods (tree);
  extern tree build_class_ref (tree);
  extern tree build_dtable_decl (tree);
*************** extern tree builtin_function (const char
*** 1429,1443 ****
  #define CLASS_DEPRECATED(DECL) DECL_LANG_FLAG_0 (DECL)
  #define DECL_DEPRECATED(DECL) DECL_LANG_FLAG_0 (DECL)
  
- /* The number of virtual methods in this class's dispatch table.
-    Does not include initial two dummy entries (one points to the
-    Class object, and the other is for G++ -fvtable-thunks compatibility). */
- #define TYPE_NVIRTUALS(TYPE) BINFO_VIRTUALS (TYPE_BINFO (TYPE))
- 
  /* A TREE_VEC (indexed by DECL_VINDEX) containing this class's
     virtual methods. */
  #define TYPE_VTABLE(TYPE) BINFO_VTABLE(TYPE_BINFO (TYPE))
  
  /* Use CLASS_LOADED_P? FIXME */
  #define CLASS_COMPLETE_P(DECL) DECL_LANG_FLAG_2 (DECL) 
  
--- 1430,1442 ----
  #define CLASS_DEPRECATED(DECL) DECL_LANG_FLAG_0 (DECL)
  #define DECL_DEPRECATED(DECL) DECL_LANG_FLAG_0 (DECL)
  
  /* A TREE_VEC (indexed by DECL_VINDEX) containing this class's
     virtual methods. */
  #define TYPE_VTABLE(TYPE) BINFO_VTABLE(TYPE_BINFO (TYPE))
  
+ /* Indicates that VEC, a TYPE_VTABLE, has been initialized.  */
+ #define VTABLE_INITED_P(VEC) TREE_LANG_FLAG_0(VEC)
+ 
  /* Use CLASS_LOADED_P? FIXME */
  #define CLASS_COMPLETE_P(DECL) DECL_LANG_FLAG_2 (DECL) 
  
Index: java/parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.504
diff -c -3 -p -r1.504 parse.y
*** java/parse.y	25 Aug 2004 09:52:52 -0000	1.504
--- java/parse.y	14 Sep 2004 16:04:48 -0000
*************** generate_finit (tree class_type)
*** 4448,4454 ****
  				    finit_identifier_node, parms);
    fix_method_argument_names (parms, mdecl);
    layout_class_method (class_type, CLASSTYPE_SUPER (class_type),
! 		       mdecl, NULL_TREE);
    DECL_FUNCTION_NAP (mdecl) = count;
    start_artificial_method_body (mdecl);
  
--- 4448,4454 ----
  				    finit_identifier_node, parms);
    fix_method_argument_names (parms, mdecl);
    layout_class_method (class_type, CLASSTYPE_SUPER (class_type),
! 		       mdecl, -1);
    DECL_FUNCTION_NAP (mdecl) = count;
    start_artificial_method_body (mdecl);
  
*************** generate_instinit (tree class_type)
*** 4479,4485 ****
  					 instinit_identifier_node, parms);
  
    layout_class_method (class_type, CLASSTYPE_SUPER (class_type),
! 		       mdecl, NULL_TREE);
  
    /* Gather all the statements in a compound */
    for (current = TYPE_II_STMT_LIST (class_type);
--- 4479,4485 ----
  					 instinit_identifier_node, parms);
  
    layout_class_method (class_type, CLASSTYPE_SUPER (class_type),
! 		       mdecl, -1);
  
    /* Gather all the statements in a compound */
    for (current = TYPE_II_STMT_LIST (class_type);
*************** java_check_regular_methods (tree class_d
*** 6334,6340 ****
    if (class == object_type_node)
      return;
  
!   if (!TYPE_NVIRTUALS (class))
      TYPE_METHODS (class) = nreverse (TYPE_METHODS (class));
  
    /* Should take interfaces into account. FIXME */
--- 6334,6340 ----
    if (class == object_type_node)
      return;
  
!   if (!TYPE_VTABLE (class))
      TYPE_METHODS (class) = nreverse (TYPE_METHODS (class));
  
    /* Should take interfaces into account. FIXME */
*************** java_check_regular_methods (tree class_d
*** 6489,6495 ****
       ways to organize this checking; we should implement one.  */
    check_interface_throws_clauses (class, class);
  
!   if (!TYPE_NVIRTUALS (class))
      TYPE_METHODS (class) = nreverse (TYPE_METHODS (class));
  
    /* Search for inherited abstract method not yet implemented in this
--- 6489,6495 ----
       ways to organize this checking; we should implement one.  */
    check_interface_throws_clauses (class, class);
  
!   if (!TYPE_VTABLE (class))
      TYPE_METHODS (class) = nreverse (TYPE_METHODS (class));
  
    /* Search for inherited abstract method not yet implemented in this
*************** maybe_generate_pre_expand_clinit (tree c
*** 7819,7825 ****
    mdecl = create_artificial_method (class_type, ACC_STATIC, void_type_node,
  				    clinit_identifier_node, end_params_node);
    layout_class_method (class_type, CLASSTYPE_SUPER (class_type),
! 		       mdecl, NULL_TREE);
    start_artificial_method_body (mdecl);
  
    /* We process the list of assignment we produced as the result of
--- 7819,7825 ----
    mdecl = create_artificial_method (class_type, ACC_STATIC, void_type_node,
  				    clinit_identifier_node, end_params_node);
    layout_class_method (class_type, CLASSTYPE_SUPER (class_type),
! 		       mdecl, -1);
    start_artificial_method_body (mdecl);
  
    /* We process the list of assignment we produced as the result of
*************** build_outer_field_access_method (tree cl
*** 8439,8445 ****
    /* Create the method */
    mdecl = create_artificial_method (class, ACC_STATIC, type, name, args);
    fix_method_argument_names (args, mdecl);
!   layout_class_method (class, NULL_TREE, mdecl, NULL_TREE);
  
    /* Attach the method body. */
    saved_current_function_decl = current_function_decl;
--- 8439,8445 ----
    /* Create the method */
    mdecl = create_artificial_method (class, ACC_STATIC, type, name, args);
    fix_method_argument_names (args, mdecl);
!   layout_class_method (class, NULL_TREE, mdecl, -1);
  
    /* Attach the method body. */
    saved_current_function_decl = current_function_decl;
*************** build_outer_method_access_method (tree d
*** 8492,8498 ****
    /* Create the method */
    mdecl = create_artificial_method (class, ACC_STATIC,
  				    TREE_TYPE (TREE_TYPE (decl)), id, args);
!   layout_class_method (class, NULL_TREE, mdecl, NULL_TREE);
    /* There is a potential bug here. We should be able to use
       fix_method_argument_names, but then arg names get mixed up and
       eventually a constructor will have its this$0 altered and the
--- 8492,8498 ----
    /* Create the method */
    mdecl = create_artificial_method (class, ACC_STATIC,
  				    TREE_TYPE (TREE_TYPE (decl)), id, args);
!   layout_class_method (class, NULL_TREE, mdecl, -1);
    /* There is a potential bug here. We should be able to use
       fix_method_argument_names, but then arg names get mixed up and
       eventually a constructor will have its this$0 altered and the
*************** maybe_build_thisn_access_method (tree ty
*** 8606,8612 ****
    mdecl = create_artificial_method (type, ACC_STATIC, rtype,
  				    access0_identifier_node, args);
    fix_method_argument_names (args, mdecl);
!   layout_class_method (type, NULL_TREE, mdecl, NULL_TREE);
    stmt = build_current_thisn (type);
    stmt = make_qualified_primary (build_wfl_node (inst_id),
  				 build_wfl_node (stmt), 0);
--- 8606,8612 ----
    mdecl = create_artificial_method (type, ACC_STATIC, rtype,
  				    access0_identifier_node, args);
    fix_method_argument_names (args, mdecl);
!   layout_class_method (type, NULL_TREE, mdecl, -1);
    stmt = build_current_thisn (type);
    stmt = make_qualified_primary (build_wfl_node (inst_id),
  				 build_wfl_node (stmt), 0);
*************** build_dot_class_method (tree class)
*** 8759,8765 ****
    stmt = encapsulate_with_try_catch (0, qual_name, stmt, throw_stmt);
  
    fix_method_argument_names (args, mdecl);
!   layout_class_method (class, NULL_TREE, mdecl, NULL_TREE);
    saved_current_function_decl = current_function_decl;
    start_artificial_method_body (mdecl);
    java_method_add_stmt (mdecl, stmt);
--- 8759,8765 ----
    stmt = encapsulate_with_try_catch (0, qual_name, stmt, throw_stmt);
  
    fix_method_argument_names (args, mdecl);
!   layout_class_method (class, NULL_TREE, mdecl, -1);
    saved_current_function_decl = current_function_decl;
    start_artificial_method_body (mdecl);
    java_method_add_stmt (mdecl, stmt);
*************** lookup_method_invoke (int lc, tree cl, t
*** 10927,10933 ****
        tree mdecl = craft_constructor (TYPE_NAME (class), atl);
        /* The anonymous class may have already been laid out, so make sure
           the new constructor is laid out here.  */
!       layout_class_method (class, CLASSTYPE_SUPER (class), mdecl, NULL_TREE);
      }
  
    /* Find all candidates and then refine the list, searching for the
--- 10927,10933 ----
        tree mdecl = craft_constructor (TYPE_NAME (class), atl);
        /* The anonymous class may have already been laid out, so make sure
           the new constructor is laid out here.  */
!       layout_class_method (class, CLASSTYPE_SUPER (class), mdecl, -1);
      }
  
    /* Find all candidates and then refine the list, searching for the

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]