From 2bb6e0cefeba590b744da9fe75a299f2deacff87 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 1 Mar 2006 16:01:34 +0000 Subject: [PATCH] re PR libgcj/24321 (instanceof erroneously causes class initialization) 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. From-SVN: r111603 --- libjava/ChangeLog | 10 +++++++++- libjava/java/lang/natClass.cc | 6 +++--- libjava/testsuite/libjava.lang/pr24321.java | 21 +++++++++++++++++++++ libjava/testsuite/libjava.lang/pr24321.out | 2 ++ 4 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 libjava/testsuite/libjava.lang/pr24321.java create mode 100644 libjava/testsuite/libjava.lang/pr24321.out diff --git a/libjava/ChangeLog b/libjava/ChangeLog index ba8b42b50c74..f3bdb61e87e8 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,11 @@ +2006-03-01 Tom Tromey + + 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. + 2006-02-27 Jakub Jelinek PR other/26208 @@ -109,7 +117,7 @@ is_attribute_name): Likewise. * prims.cc (_Jv_strLengthUtf8, _Jv_hashUtf8String, _Jv_Utf8Const::init, _Jv_makeUtf8Const, _Jv_InitPrimClass): Likewise. - + 2006-02-08 Tom Tromey PR libgcj/26063, PR libgcj/17978, PR libgcj/10598: diff --git a/libjava/java/lang/natClass.cc b/libjava/java/lang/natClass.cc index 8972cb2c4997..38a9aff4a0bc 100644 --- a/libjava/java/lang/natClass.cc +++ b/libjava/java/lang/natClass.cc @@ -621,8 +621,9 @@ jboolean 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 @@ java::lang::Class::isInstance (jobject obj) { if (! obj) return false; - _Jv_InitClass (this); return _Jv_IsAssignableFrom (JV_CLASS (obj), this); } diff --git a/libjava/testsuite/libjava.lang/pr24321.java b/libjava/testsuite/libjava.lang/pr24321.java new file mode 100644 index 000000000000..513304b50146 --- /dev/null +++ b/libjava/testsuite/libjava.lang/pr24321.java @@ -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)); + } +} diff --git a/libjava/testsuite/libjava.lang/pr24321.out b/libjava/testsuite/libjava.lang/pr24321.out new file mode 100644 index 000000000000..1d474d525571 --- /dev/null +++ b/libjava/testsuite/libjava.lang/pr24321.out @@ -0,0 +1,2 @@ +false +true