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]

[gcjx] Patch: FYI: redo verifier notification


I'm checking this in on the gcjx branch.

This reworks verifier notification to avoid any reallocation; instead
memory is handed off from the verifier to its user.

Tom

Index: gcjx/ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* model/bytecode.cc (verify): Don't call allocate_flags.
	* model/bytecode.hh (model_bytecode_block::allocate_flags):
	Removed.
	(model_bytecode_block::set_flags): New method.
	* verify.h (VERIFY_INSN_START): New macro.
	(VERIFY_BRANCH_TARGET): Renamed.
	(VERIFY_SEEN): Likewise.
	(vfy_notify_verified): Removed.
	(vfy_notify_branch_target): Likewise.
	(vfy_method::flags): Removed.
	(VFY_WANT_NOTIFICATION): Removed.
	(vfy_hand_off_flags): New function.
	* bytecode/verify.cc (FLAG_SEEN): New constant.
	(branch_prepass): Don't handle notification.  Updated for change
	to 'flags'.
	(verify_instructions_0): Likewise.  Use FLAG_SEEN.
	(flags): Now 'unsigned char *'.
	(~_Jv_BytecodeVerifier): Call vfy_hand_off_flags.
Index: gcc/java/ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	* lower.cc (visit_bytecode_block): Use VERIFY_BRANCH_TARGET.



Index: gcjx/verify.h
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/Attic/verify.h,v
retrieving revision 1.1.2.5
diff -u -r1.1.2.5 verify.h
--- gcjx/verify.h 3 Apr 2005 23:54:32 -0000 1.1.2.5
+++ gcjx/verify.h 3 Apr 2005 23:58:51 -0000
@@ -41,14 +41,10 @@
 
 typedef model_bytecode_block::exception vfy_exception;
 
-// These flags aren't used by the verifier itself, but are set on the
-// model_bytecode_block during verification.
-#define VERIFY_SEEN 1
-#define VERIFY_TARGET 2
-
-// This tells the verifier that we want notification of live bytecode
-// and branch targets.
-#define VFY_WANT_NOTIFICATION
+// These must be kept in sync with verify.cc.
+#define VERIFY_INSN_START 1
+#define VERIFY_BRANCH_TARGET 2
+#define VERIFY_SEEN 4
 
 
 struct vfy_method
@@ -57,7 +53,6 @@
   model_bytecode_block *block;
   resolution_scope *scope;
   model_unit_class *unit;
-  unsigned char *flags;
 
   // These fields are referred to directly by the verifier.
   vfy_jclass defining_class;
@@ -78,7 +73,6 @@
     max_locals = block->get_max_locals ();
     code_length = block->get_code_length ();
     exc_count = block->get_exception_length ();
-    flags = block->get_flags ();
   }
 };
 
@@ -350,16 +344,6 @@
     % pc % method->method % message;
 }
 
-inline void vfy_notify_verified (vfy_method *method, int pc)
-{
-  method->flags[pc] |= VERIFY_SEEN;
-}
-
-inline void vfy_notify_branch_target (vfy_method *method, int pc)
-{
-  method->flags[pc] |= VERIFY_TARGET;
-}
-
 // Return the primitive type corresponding to the argument to
 // `newarray'.
 inline vfy_jclass vfy_get_primitive_type (int type)
@@ -392,6 +376,13 @@
   return method->unit->is_15_p ();
 }
 
+// Do something with the 'flags' array.
+// (A user could just delete[] it...)
+inline void vfy_hand_off_flags (vfy_method *method, unsigned char *flags)
+{
+  method->block->set_flags (flags);
+}
+
 #define GLOM(name, stuff) name ## stuff
 #define VFY_PRIMITIVE_CLASS(name) \
   vfy_get_primitive_type ((int) (GLOM (primitive_, GLOM (name, _type))))
Index: gcjx/bytecode/verify.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/bytecode/Attic/verify.cc,v
retrieving revision 1.1.2.5
diff -u -r1.1.2.5 verify.cc
--- gcjx/bytecode/verify.cc 3 Apr 2005 23:54:32 -0000 1.1.2.5
+++ gcjx/bytecode/verify.cc 3 Apr 2005 23:58:54 -0000
@@ -138,6 +138,7 @@
 
   static const int FLAG_INSN_START = 1;
   static const int FLAG_BRANCH_TARGET = 2;
+  static const int FLAG_SEEN = 4;
 
   struct state;
   struct type;
@@ -172,7 +173,7 @@
 
   // We keep some flags for each instruction.  The values are the
   // FLAG_* constants defined above.  This is an array indexed by PC.
-  char *flags;
+  unsigned char *flags;
 
   // The bytecode itself.
   const unsigned char *bytecode;
@@ -1594,7 +1595,7 @@
   // instruction starts.
   void branch_prepass ()
   {
-    flags = (char *) vfy_alloc (current_method->code_length);
+    flags = (unsigned char *) vfy_alloc (current_method->code_length);
 
     for (int i = 0; i < current_method->code_length; ++i)
       flags[i] = 0;
@@ -1930,9 +1931,6 @@
 		       end);
 
 	flags[handler] |= FLAG_BRANCH_TARGET;
-#ifdef VFY_WANT_NOTIFICATION
-	vfy_notify_branch_target (current_method, handler);
-#endif
       }
   }
 
@@ -2238,10 +2236,7 @@
 	// Set this before handling exceptions so that debug output is
 	// sane.
 	start_PC = PC;
-
-#ifdef VFY_WANT_NOTIFICATION
-	vfy_notify_verified (current_method, PC);
-#endif
+	flags[PC] |= FLAG_SEEN;
 
 	// Update states for all active exception handlers.  Ordinarily
 	// there are not many exception handlers.  So we simply run
@@ -3149,8 +3144,7 @@
 
   ~_Jv_BytecodeVerifier ()
   {
-    if (flags)
-      vfy_free (flags);
+    vfy_hand_off_flags (current_method, flags);
 
     while (utf8_list != NULL)
       {
Index: gcjx/model/bytecode.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/model/Attic/bytecode.cc,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 bytecode.cc
--- gcjx/model/bytecode.cc 3 Apr 2005 23:39:55 -0000 1.1.2.3
+++ gcjx/model/bytecode.cc 3 Apr 2005 23:58:54 -0000
@@ -49,8 +49,6 @@
 	    = assert_cast<model_unit_class *> (klass->get_compilation_unit ());
 	}
 
-      allocate_flags (length);
-
       if (global->get_compiler ()->verbose ())
 	std::cout << "[verifying method "
 		  << decl->get_fully_qualified_name ()
Index: gcjx/model/bytecode.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/model/Attic/bytecode.hh,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 bytecode.hh
--- gcjx/model/bytecode.hh 3 Apr 2005 23:39:55 -0000 1.1.2.3
+++ gcjx/model/bytecode.hh 3 Apr 2005 23:58:54 -0000
@@ -72,15 +72,6 @@
   // with new[] and owned by this object.
   unsigned char *flags;
 
-
-  /// Allocate space for the flags.
-  void allocate_flags (int size)
-  {
-    assert (! flags);
-    flags = new unsigned char[size];
-    memset (flags, 0, size);
-  }
-
 public:
 
   model_bytecode_block (const location &w)
@@ -199,6 +190,12 @@
     assert (flags);
     return flags;
   }
+
+  void set_flags (unsigned char *f)
+  {
+    assert (! flags);
+    flags = f;
+  }
 };
 
 /// This is a phony block which is used when reading a .class file
Index: gcc/java/lower.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/lower.cc,v
retrieving revision 1.1.2.13
diff -u -r1.1.2.13 lower.cc
--- gcc/java/lower.cc 3 Apr 2005 23:57:55 -0000 1.1.2.13
+++ gcc/java/lower.cc 3 Apr 2005 23:59:02 -0000
@@ -140,7 +140,7 @@
 
       // If this location is a branch target, link its corresponding
       // label into the instruction stream.
-      if ((flags[pc] & VERIFY_TARGET) != 0)
+      if ((flags[pc] & VERIFY_BRANCH_TARGET) != 0)
 	{
 	  tree label_decl = find_label (pc);
 	  tsi_link_after (&statements, build1 (LABEL_EXPR, void_type_node,


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