This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java 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]

Re: [RFC/RFT] Patch (java): Switch to new verifier


Andrew Haley wrote:

Bryce McKinlay writes:
> > > >Also, I suspect that the new verifier generates typemaps that require
> >special treatment by subsequent code-generation passes. There are
> >hacks in place for this, but I'm not sure they work when compiling
> >with the C++ ABI.
> >


> Andrew may correct me, but I don't recall anything we did for the new > verifier that will be incompatible with the C++ ABI. It does seem to > work ok on my (very brief) testing. It would be nice to get rid of the > old verifier - there's no point keeping it around if the new one can be > made to work.

This looks pretty good. You test it and I'll approve it.



Here's the patch. This cleans up all the #if 0 blocks, removing unused code. It also incorporates a few minor improvments that I had sitting in my tree: improves verifier error messages by reporting the PC in more cases, and fixes a probable memory leak. It also incorporates Ranjit's expr.c flag_new_verifier fix.


No regressions, and 4 XPASS's when the new verifier is enabled for the C++ ABI.

I think this patch should go into both HEAD and the branch - note that its pretty benign since it doesn't actually enable the new verifier code for the C++ ABI yet, and the changes for the BC-ABI are basically just cleanups. OK?

Bryce

2005-03-04  Bryce McKinlay  <mckinlay@redhat.com>

	* verify-glue.c (vfy_is_assignable_from): Perform static check using
	can_widen_reference_to if the C++ ABI is in use.
	(vfy_get_interface_count, vfy_get_interface): Remove unused functions.
	* verify-impl.c (debug_print, make_utf8_const, init_type, copy_type,
	type_isresolved, init_state, set_pc, state_get_pc,
	_Jv_BytecodeVerifier): Clean up unused and disabled functions.
	(verify_fail): Report the current PC from the verifier context.
	(free_state): Remove #if 0 block to enable this function.
	(free_verifier_context): Call free_state on state_list iterator
	values before freeing them.
	* expr.c (pop_type_0): Pop correct type for error message when stack
	contains a multi-word type.

2005-03-04  Ranjit Mathew  <rmathew@hotmail.com>

	* expr.c (build_java_array_length_access): Remove !flag_new_verifier
	for known NULL array length access.


Index: verify-glue.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/verify-glue.c,v
retrieving revision 1.4
diff -u -r1.4 verify-glue.c
--- verify-glue.c	19 Feb 2005 01:14:17 -0000	1.4
+++ verify-glue.c	5 Mar 2005 01:05:55 -0000
@@ -231,17 +231,18 @@
 bool
 vfy_is_assignable_from (vfy_jclass target, vfy_jclass source)
 {
-  /* At compile time, for the BC-ABI we assume that reference types are always 
-  compatible.  However, a type assertion table entry is emitted so that the
-  runtime can detect binary-incompatible changes.  */
-
-  /* FIXME: implement real test for old ABI.  */
-
   /* Any class is always assignable to itself, or java.lang.Object. */
   if (source == target || target == object_type_node)
     return true;
 
-  /* Otherwise, a type assertion is required.  */
+  /* For the C++ ABI, perform this test statically. */
+  if (! flag_indirect_dispatch)
+    return can_widen_reference_to (source, target);
+
+  /* For the BC-ABI, we assume at compile time that reference types are always 
+  compatible.  However, a type assertion table entry is emitted so that the
+  runtime can detect binary-incompatible changes.  */
+
   add_type_assertion (current_class, JV_ASSERT_TYPES_COMPATIBLE, source,
 		      target);
   return true;
@@ -257,28 +258,6 @@
   return (IDENTIFIER_POINTER (sig))[0];
 }
 
-int
-vfy_get_interface_count (vfy_jclass klass ATTRIBUTE_UNUSED)
-{
-  /* FIXME: Need to merge from mainline to get this. */
-  #if 0
-  return BINFO_N_BASE_BINFOS (klass);
-  #endif
-  return -1;
-}
-
-vfy_jclass
-vfy_get_interface (vfy_jclass klass ATTRIBUTE_UNUSED, int index ATTRIBUTE_UNUSED)
-{
-  /* FIXME: Need to merge from mainline to get this. */
-  #if 0
-  vfy_jclass k;
-  k = BINFO_BASE_BINFO (klass, index);
-  return k;
-  #endif
-  return NULL;
-}
-
 bool
 vfy_is_array (vfy_jclass klass)
 {
Index: verify-impl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/verify-impl.c,v
retrieving revision 1.7
diff -u -r1.7 verify-impl.c
--- verify-impl.c	22 Feb 2005 18:14:37 -0000	1.7
+++ verify-impl.c	5 Mar 2005 01:05:56 -0000
@@ -42,22 +42,6 @@
 }    
 #endif /* VERIFY_DEBUG */
 
-#if 0
-static void debug_print (const char *fmt, ...)
-  __attribute__ ((format (printf, 1, 2)));
-
-static void
-debug_print (const char *fmt, ...)
-{
-#ifdef VERIFY_DEBUG
-  va_list ap;
-  va_start (ap, fmt);
-  vfprintf (stderr, fmt, ap);
-  va_end (ap);
-#endif /* VERIFY_DEBUG */
-}
-#endif
-
 /* This started as a fairly ordinary verifier, and for the most part
    it remains so.  It works in the obvious way, by modeling the effect
    of each opcode as it is encountered.  For most opcodes, this is a
@@ -224,22 +208,6 @@
 bool type_initialized (type *t);
 int ref_count_dimensions (ref_intersection *ref);
 
-#if 0
-  /* Create a new Utf-8 constant and return it.  We do this to avoid
-     having our Utf-8 constants prematurely collected.  */
-  static vfy_string
-  make_utf8_const (const char *s, int len)
-  {
-    vfy_string val = vfy_make_string (s, len);
-    vfy_string_list *lu = vfy_alloc (sizeof (vfy_string_list));
-    lu->val = val;
-    lu->next = vfr->utf8_list;
-    vfr->utf8_list = lu;
-
-    return val;
-  }
-#endif
-
 static void
 verify_fail_pc (const char *s, int pc)
 {
@@ -249,7 +217,7 @@
 static void
 verify_fail (const char *s)
 {
-  verify_fail_pc (s, -1);
+  verify_fail_pc (s, vfr->PC);
 }
 
 /* This enum holds a list of tags for all the different types we
@@ -554,17 +522,6 @@
 #define EITHER -3
 };
 
-#if 0
-/* Basic constructor.  */
-static void
-init_type (type *t)
-{
-  t->key = unsuitable_type;
-  t->klass = NULL;
-  t->pc = UNINIT;
-}
-#endif
-
 /* Make a new instance given the type tag.  We assume a generic
    `reference_type' means Object.  */
 static void
@@ -626,26 +583,6 @@
   return t;
 }
 
-#if 0
-    /* Make a new instance given the name of a class.  */
-    type (vfy_string n)
-    {
-      key = reference_type;
-      klass = new ref_intersection (n, verifier);
-      pc = UNINIT;
-    }
-
-    /* Copy constructor.  */
-    static type copy_type (type *t)
-    {
-      type copy;
-      copy.key = t->key;
-      copy.klass = t->klass;
-      copy.pc = t->pc;
-      return copy;
-    }
-#endif
-
 /* Promote a numeric type.  */
 static void
 vfy_promote_type (type *t)
@@ -874,16 +811,6 @@
   return t->key == reference_type || t->key == null_type;
 }
 
-#if 0
-static bool
-type_isresolved (type *t)
-{
-  return (t->key == reference_type
-	  || t->key == null_type
-	  || t->key == uninitialized_reference_type);
-}
-#endif
-
 static void
 type_verify_dimensions (type *t, int ndims)
 {
@@ -1018,16 +945,6 @@
    acquired from the verification list.  */
 #define NO_NEXT -1
 
-#if 0
-static void
-init_state (state *s)
-{
-  s->stack = NULL;
-  s->locals = NULL;
-  s->next = INVALID_STATE;  
-}
-#endif
-
 static void
 init_state_with_stack (state *s, int max_stack, int max_locals)
 {
@@ -1084,7 +1001,6 @@
   return s;
 }
 
-#if 0
 static void
 free_state (state *s)
 {
@@ -1093,29 +1009,6 @@
   if (s->locals != NULL)
     vfy_free (s->locals);
 }
-#endif
-
-#if 0
-    void *operator new[] (size_t bytes)
-    {
-      return vfy_alloc (bytes);
-    }
-
-    void operator delete[] (void *mem)
-    {
-      vfy_free (mem);
-    }
-
-    void *operator new (size_t bytes)
-    {
-      return vfy_alloc (bytes);
-    }
-
-    void operator delete (void *mem)
-    {
-      vfy_free (mem);
-    }
-#endif
 
 /* Modify this state to reflect entry to an exception handler.  */
 static void
@@ -1129,20 +1022,6 @@
     init_type_from_tag (&s->stack[i], unsuitable_type);
 }
 
-static int
-state_get_pc (state *s)
-{
-  return s->pc;
-}
-
-#if 0
-static void
-set_pc (state *s, int npc)
-{
-  s->pc = npc;
-}
-#endif
-
 /* Merge STATE_OLD into this state.  Destructively modifies this
    state.  Returns true if the new state was in fact changed.
    Will throw an exception if the states are not mergeable.  */
@@ -2368,7 +2247,7 @@
 	  if (new_state == NULL)
 	    break;
 
-	  vfr->PC = state_get_pc (new_state);
+	  vfr->PC = new_state->pc;
 	  debug_print ("== State pop from pending list\n");
 	  /* Set up the current state.  */
 	  copy_state (vfr->current_state, new_state, 
@@ -3259,32 +3138,6 @@
 	  handle_jsr_insn (get_int ());
 	  break;
 
-#if 0
-	/* These are unused here, but we call them out explicitly
-	   so that -Wswitch-enum doesn't complain.  */
-	case op_putfield_1:
-	case op_putfield_2:
-	case op_putfield_4:
-	case op_putfield_8:
-	case op_putfield_a:
-	case op_putstatic_1:
-	case op_putstatic_2:
-	case op_putstatic_4:
-	case op_putstatic_8:
-	case op_putstatic_a:
-	case op_getfield_1:
-	case op_getfield_2s:
-	case op_getfield_2u:
-	case op_getfield_4:
-	case op_getfield_8:
-	case op_getfield_a:
-	case op_getstatic_1:
-	case op_getstatic_2s:
-	case op_getstatic_2u:
-	case op_getstatic_4:
-	case op_getstatic_8:
-	case op_getstatic_a:
-#endif
 	default:
 	  /* Unrecognized opcode.  */
 	  verify_fail_pc ("unrecognized instruction in verify_instructions_0",
@@ -3375,17 +3228,6 @@
     }
 }
 
-#if 0
-_Jv_BytecodeVerifier (_Jv_InterpMethod *m)
-{
-  /* We just print the text as utf-8.  This is just for debugging
-     anyway.  */
-  debug_print ("--------------------------------\n");
-  debug_print ("-- Verifying method `%s'\n", m->self->name->chars());
-
-}
-#endif
-
 static void
 make_verifier_context (vfy_method *m)
 {
@@ -3436,6 +3278,7 @@
 	  while (iter != NULL)
 	    {
 	      state_list *next = iter->next;
+	      free_state (iter->val);
 	      vfy_free (iter->val);
 	      vfy_free (iter);
 	      iter = next;
Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/expr.c,v
retrieving revision 1.218
diff -u -r1.218 expr.c
--- expr.c	14 Feb 2005 14:58:22 -0000	1.218
+++ expr.c	5 Mar 2005 01:05:56 -0000
@@ -383,6 +383,10 @@
  fail:
   {
     char *temp = xstrdup (lang_printable_name (type, 0));
+    /* If the stack contains a multi-word type, keep popping the stack until 
+       the real type is found.  */
+    while (t == void_type_node)
+      t = stack_type_map[--stack_pointer];
     *messagep = concat ("expected type '", temp,
 			"' but stack contains '", lang_printable_name (t, 0),
 			"'", NULL);
@@ -818,7 +822,7 @@
      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 (!flag_new_verifier && type == ptr_type_node)
+  if (type == ptr_type_node)
     return build3 (CALL_EXPR, int_type_node, 
 		   build_address_of (soft_nullpointer_node),
 		   NULL_TREE, NULL_TREE);

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