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: fix PR java/24321


I'm checking this in on the trunk.

This fixes a bug with over-eager class initialization, aka PR 24321.

It also fixes a related bug with Class.isAssignableFrom.  The test
case for this bug is a bit roundabout, because in 1.4 and earlier, the
".class" syntax caused class initialization (with most compilers,
maybe jikes got this right).  In any case, with gcj we still see a
class initialization with the simpler "Z.class.isAssignableFrom(...)".

Tom

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

	PR java/24321:
	* testsuite/libjava.lang/pr24321.java: New file.
	* testsuite/libjava.lang/pr24321.out: New file.
	* java/lang/natClass.cc (isInstance): Don't initialize class.
	(isAssignableFrom): Likewise.

Index: testsuite/libjava.lang/pr24321.out
===================================================================
--- testsuite/libjava.lang/pr24321.out	(revision 0)
+++ testsuite/libjava.lang/pr24321.out	(revision 0)
@@ -0,0 +1,2 @@
+false
+true
Index: testsuite/libjava.lang/pr24321.java
===================================================================
--- testsuite/libjava.lang/pr24321.java	(revision 0)
+++ testsuite/libjava.lang/pr24321.java	(revision 0)
@@ -0,0 +1,21 @@
+public class pr24321 {
+  static class Z {
+    static {
+      System.out.println("init");
+    }
+  }
+
+  static class Y extends Z { }
+
+  public static Object x () { return new Object(); }
+
+  public static void main(String[] args) throws Throwable
+  {
+    System.out.println(x() instanceof Z);
+
+    ClassLoader cl = pr24321.class.getClassLoader();
+    Class zk = Class.forName("pr24321$Z", false, cl);
+    Class yk = Class.forName("pr24321$Y", false, cl);
+    System.out.println(zk.isAssignableFrom(yk));
+  }
+}
Index: java/lang/natClass.cc
===================================================================
--- java/lang/natClass.cc	(revision 111573)
+++ java/lang/natClass.cc	(working copy)
@@ -621,8 +621,9 @@
 java::lang::Class::isAssignableFrom (jclass klass)
 {
   // Arguments may not have been initialized, given ".class" syntax.
-  _Jv_InitClass (this);
-  _Jv_InitClass (klass);
+  // This ensures we can at least look at their superclasses.
+  _Jv_Linker::wait_for_state (this, JV_STATE_LOADING);
+  _Jv_Linker::wait_for_state (klass, JV_STATE_LOADING);
   return _Jv_IsAssignableFrom (klass, this);
 }
 
@@ -631,7 +632,6 @@
 {
   if (! obj)
     return false;
-  _Jv_InitClass (this);
   return _Jv_IsAssignableFrom (JV_CLASS (obj), this);
 }
 


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