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]

Patch: FYI: verifier and interpreter fix


I'm checking this in.

This fixes a buglet in the interpreter: invokespecial wasn't properly
checking its argument against `null'.

It also fixes a bug in the verifier: `null' is not an uninitialized
object.

There's a new Mauve verifier test for the second problem.

Tom

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

	* verify.cc (type::compatible): Check initialization status
	first.
	* interpret.cc (run) [insn_invokespecial, invokespecial_resolved]:
	Don't use NULLCHECK.

Index: libjava/interpret.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/interpret.cc,v
retrieving revision 1.35
diff -u -r1.35 interpret.cc
--- libjava/interpret.cc 8 Oct 2002 18:12:42 -0000 1.35
+++ libjava/interpret.cc 26 Nov 2002 06:46:52 -0000
@@ -2795,7 +2795,10 @@
 
 	sp -= rmeth->stack_item_count;
 
-	NULLCHECK (sp[0].o);
+	// We don't use NULLCHECK here because we can't rely on that
+	// working for <init>.  So instead we do an explicit test.
+	if (! sp[0].o)
+	  throw new java::lang::NullPointerException;
 
 	fun = (void (*)()) rmeth->method->ncode;
 
@@ -2813,7 +2816,10 @@
       {
 	rmeth = (_Jv_ResolvedMethod *) AVAL ();
 	sp -= rmeth->stack_item_count;
-	NULLCHECK (sp[0].o);
+	// We don't use NULLCHECK here because we can't rely on that
+	// working for <init>.  So instead we do an explicit test.
+	if (! sp[0].o)
+	  throw new java::lang::NullPointerException;
 	fun = (void (*)()) rmeth->method->ncode;
       }
       goto perform_invoke;
Index: libjava/verify.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/verify.cc,v
retrieving revision 1.42
diff -u -r1.42 verify.cc
--- libjava/verify.cc 24 Jun 2002 20:38:45 -0000 1.42
+++ libjava/verify.cc 26 Nov 2002 06:46:55 -0000
@@ -458,8 +458,12 @@
       if (key < reference_type || k.key < reference_type)
 	return key == k.key;
 
+      // An initialized type and an uninitialized type are not
+      // compatible.
+      if (isinitialized () != k.isinitialized ())
+	return false;
+
       // The `null' type is convertible to any reference type.
-      // FIXME: is this correct for THIS?
       if (key == null_type || k.key == null_type)
 	return true;
 
@@ -468,11 +472,6 @@
       if (key == reference_type
 	  && data.klass == &java::lang::Object::class$)
 	return true;
-
-      // An initialized type and an uninitialized type are not
-      // compatible.
-      if (isinitialized () != k.isinitialized ())
-	return false;
 
       // Two uninitialized objects are compatible if either:
       // * The PCs are identical, or


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