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]

Don't generate NullPointerExceptions for arraylength and arrayload


This removes the special case code that throws a NullPointerException
bease on the type of an arrayref.  This trick no longer works because
in the bytecode front end we now use the same variable decl for every
object.  In ancy case, this optimization just provided a fast path to
throw a NullPointerException.

This is a regression from 3.x.

Andrew.


2005-03-16  Andrew Haley  <aph@redhat.com>

        * expr.c (expand_java_arrayload): Don't generate a
        NullPointerException based on the type of the node.
        (build_java_array_length_access): Likewise.

Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/expr.c,v
retrieving revision 1.220
diff -u -w -p -r1.220 expr.c
--- expr.c      7 Mar 2005 21:10:49 -0000       1.220
+++ expr.c      16 Mar 2005 18:43:05 -0000
@@ -818,15 +818,6 @@ build_java_array_length_access (tree nod
   tree array_type = TREE_TYPE (type);
   HOST_WIDE_INT length;
 
-  /* JVM spec: If the arrayref is null, the arraylength instruction
-     throws a NullPointerException.  The only way we could get a node
-     of type ptr_type_node at this point is `aconst_null; arraylength'
-     or something equivalent.  */
-  if (type == ptr_type_node)
-    return build3 (CALL_EXPR, int_type_node, 
-                  build_address_of (soft_nullpointer_node),
-                  NULL_TREE, NULL_TREE);
-
   if (!is_array_type_p (type))
     {
       /* With the new verifier, we will see an ordinary pointer type
@@ -1229,21 +1220,11 @@ expand_java_arrayload (tree lhs_type_nod
   index_node = save_expr (index_node);
   array_node = save_expr (array_node);
 
-  if (TREE_TYPE (array_node) == ptr_type_node)
-    /* The only way we could get a node of type ptr_type_node at this
-       point is `aconst_null; arraylength' or something equivalent, so
-       unconditionally throw NullPointerException.  */
-    load_node = build3 (CALL_EXPR, lhs_type_node, 
-                       build_address_of (soft_nullpointer_node),
-                       NULL_TREE, NULL_TREE);
-  else
-    {
       lhs_type_node = build_java_check_indexed_type (array_node,
                                                     lhs_type_node);
       load_node = build_java_arrayaccess (array_node,
                                          lhs_type_node,
                                          index_node);
-    }
   if (INTEGRAL_TYPE_P (lhs_type_node) && TYPE_PRECISION (lhs_type_node) <= 32)
     load_node = fold (build1 (NOP_EXPR, int_type_node, load_node));
   push_value (load_node);


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