This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


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

java/1280: "Klass.class" expression should cause Klass to be initialized



>Number:         1280
>Category:       java
>Synopsis:       "Klass.class" expression should cause Klass to be initialized
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    tromey
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Dec 20 12:18:37 PST 2000
>Closed-Date:    Sun Jun 25 10:29:00 PDT 2000
>Last-Modified:  Sun Jun 25 10:30:01 PDT 2000
>Originator:     Bryce McKinlay
>Release:        gcc version 2.96 20000608 (experimental)
>Organization:
>Environment:
any
>Description:
Using .class syntax should cause the referenced class to
be initialized.

The test case below should print "A initialized". gcj 
compiled from source or bytecode fails this. Bytecode running
with gij also fails.

Bytecode produced by gcj -C works, if it is run on another VM.

Some superfluous _Jv_InitClass calls may be removed from natClass.cc 
once this PR is fixed.
 
>How-To-Repeat:
class A
{
  static
  {
    System.out.println ("A initialized");
  }
}

public class ClassInit
{
  public static void main(String args[])
  {
    Class klass = A.class;
  }
}
>Fix:

>Release-Note:

>Audit-Trail:

Formerly PR gcj/260


From: Tom Tromey <tromey@cygnus.com>
To: bryce@albatross.co.nz
Cc: java-gnats@sourceware.cygnus.com
Subject: Re: gcj/260: "Klass.class" expression should cause Klass to be initialized
Date: Thu, 15 Jun 2000 20:19:30 -0700 (PDT)

 Bryce> Using .class syntax should cause the referenced class to
 Bryce> be initialized.
 
 Is this really an active use of the class?  Do you have a reference?
 I didn't see this in the 1.2 JVM spec.
 
 Tom

From: Bryce McKinlay <bryce@albatross.co.nz>
To: Tom Tromey <tromey@cygnus.com>
Cc: java-gnats@sourceware.cygnus.com
Subject: Re: gcj/260: "Klass.class" expression should cause Klass to be 
 initialized
Date: Fri, 16 Jun 2000 15:34:41 +1200

 Tom Tromey wrote:
 
 > Bryce> Using .class syntax should cause the referenced class to
 > Bryce> be initialized.
 >
 > Is this really an active use of the class?  Do you have a reference?
 > I didn't see this in the 1.2 JVM spec.
 
 I didn't find any reference in the spec either (but I didn't look very
 hard). It does say that "certain reflective methods" will cause
 initialization, so I guess ".class" could fall into that category.
 
 I tried the test case on 3 different VMs (1.1.8, 1.2.2, and 1.3), and
 they will all initialize the class just by assigning a java.lang.Class
 variable from a ".class" expression.
 
 It should make things slightly more efficient if we have the compiler
 doing the initialization, since it can remove redundant initialization
 calls within the same method (and we can remove several initialozation
 calls from reflective methods in natClass.cc)
 
 regards
 
   [b ryce ]
 
 

From: Tom Tromey <tromey@cygnus.com>
To: Bryce McKinlay <bryce@albatross.co.nz>
Cc: Tom Tromey <tromey@cygnus.com>, java-gnats@sourceware.cygnus.com
Subject: Re: gcj/260: "Klass.class" expression should cause Klass to be 
 initialized
Date: Thu, 15 Jun 2000 21:30:10 -0700 (PDT)

 Bryce> It does say that "certain reflective methods" will cause
 Bryce> initialization, so I guess ".class" could fall into that
 Bryce> category.
 
 Oh, I didn't notice that.
 That's good enough for me.
 Probably compatibility is important even if it isn't specified this way...
 
 Tom

From: Bryce McKinlay <bryce@albatross.co.nz>
To: Jeff Sturm <jeff.sturm@appnet.com>
Cc: apbianco@cygnus.com, java-gnats@sourceware.cygnus.com
Subject: Re: gcj/260: "Klass.class" expression should cause Klass to be 
 initialized
Date: Sun, 18 Jun 2000 23:59:06 +1200

 Jeff Sturm wrote:
 
 > The Microsoft VM does not initialize such a class (or didn't, it may
 > have changed by now).  That used to break a lot of code to initialize
 > JDBC:
 >
 > Class.forName("sun.jdbc.odbc.JdbcOdbcBridge");
 >
 > which became a no-op on the MS VM (Class.forName is equivalent to the
 > .class syntax, except that latter never throws an exception).
 >
 > >  It should make things slightly more efficient if we have the compiler
 > >  doing the initialization, since it can remove redundant initialization
 > >  calls within the same method (and we can remove several initialozation
 > >  calls from reflective methods in natClass.cc)
 >
 > I agree.  It will also help to avoid certain incompatibilities.  I don't
 > remember if libgcj Class.forName also initializes a class, but it should
 > for compatibility with JDK.
 
 Oh, it does. IIRC the spec is pretty clear that Class.forName() will cause
 initialization (and JDBC wouldn't work if it didn't). If it also says
 somewhere that ".class" is equivalent to Class.forName(), then obviously
 ".class" should initialize as well.
 
 regards
 
   [ bryce ]
 
 

From: Jeff Sturm <jsturm@sigma6.com>
To: Bryce McKinlay <bryce@albatross.co.nz>
Cc: tromey@cygnus.com, apbianco@cygnus.com, java-gnats@sourceware.cygnus.com
Subject: Re: gcj/260: "Klass.class" expression should cause Klass to be 
 initialized
Date: Sun, 18 Jun 2000 10:58:38 -0400

 Bryce McKinlay wrote:
 > Oh, it does. IIRC the spec is pretty clear that Class.forName() will cause
 > initialization (and JDBC wouldn't work if it didn't).
 
 I've never found that anywhere in the JLS... is there a newer copy I
 don't have?  All I see is that vague explanation about "certain methods
 in java.lang.Class..."
 
 No matter, we clearly want to match Sun's behavior anyway.
 
 > If it also says somewhere that ".class" is equivalent to Class.forName(), 
 > then obviously ".class" should initialize as well.
 
 I don't know if they are intentionally equivalent, but javac supports
 the ".class" syntax by generating (indirectly) a call to
 Class.forName().
 
 Now, the PR also says "gij ClassInit" fails the test.  It turns out that
 libgcj's Class.forName() fails to perform initialization as well.  So
 the runtime must be patched along with gcj.
 
 --
 Jeff Sturm
 jeff.sturm@appnet.com

From: tromey@sourceware.cygnus.com
To: java-gnats@sourceware.cygnus.com
Cc:  
Subject: gcj/260
Date: 18 Jun 2000 22:14:07 -0000

 CVSROOT:	/cvs/java
 Module name:	libgcj
 Changes by:	tromey@sourceware.cygnus.com	00/06/18 15:14:07
 
 Modified files:
 	libjava        : ChangeLog Makefile.in 
 	libjava/java/lang: natClass.cc 
 
 Log message:
 	* java/lang/natClass.cc (forName): Removed dead code.  Initialize
 	returned class.  For PR gcj/260.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/gcc/libjava/ChangeLog.diff?cvsroot=java&r1=1.393&r2=1.394
 http://gcc.gnu.org/cgi-bin/gcc/libjava/Makefile.in.diff?cvsroot=java&r1=1.72&r2=1.73
 http://gcc.gnu.org/cgi-bin/gcc/libjava/java/lang/natClass.cc.diff?cvsroot=java&r1=1.26&r2=1.27
 

From: Bryce McKinlay <bryce@albatross.co.nz>
To: Jeff Sturm <jsturm@sigma6.com>
Cc: tromey@cygnus.com, apbianco@cygnus.com, java-gnats@sourceware.cygnus.com
Subject: Re: gcj/260: "Klass.class" expression should cause Klass to be 
 initialized
Date: Mon, 19 Jun 2000 11:10:23 +1200

 Jeff Sturm wrote:
 
 > Bryce McKinlay wrote:
 > > Oh, it does. IIRC the spec is pretty clear that Class.forName() will cause
 > > initialization (and JDBC wouldn't work if it didn't).
 >
 > I've never found that anywhere in the JLS... is there a newer copy I
 > don't have?  All I see is that vague explanation about "certain methods
 > in java.lang.Class..."
 
 I was actually thinking of the JDK 1.2/1.3 html docs, where it says:
 
 "A call to forName("X") causes the class named X to be initialized."
 
 In JDK 1.2 there is also an extended version of forName which allows you to
 specifiy whether you want the class to be inititalized or not.
 
 > > If it also says somewhere that ".class" is equivalent to Class.forName(),
 > > then obviously ".class" should initialize as well.
 >
 > I don't know if they are intentionally equivalent, but javac supports
 > the ".class" syntax by generating (indirectly) a call to
 > Class.forName().
 >
 > Now, the PR also says "gij ClassInit" fails the test.  It turns out that
 > libgcj's Class.forName() fails to perform initialization as well.  So
 > the runtime must be patched along with gcj.
 
 Oops, your right. I don't know how I didnt notice this before! But I see Tom
 has checked in a fix for that already. gcj still needs to be fixed as well of
 course, as ".class" is implemented differently.
 
 regards
 
   [ bryce ]
 
 

From: Jeff Sturm <jsturm@sigma6.com>
To: Bryce McKinlay <bryce@albatross.co.nz>
Cc: tromey@cygnus.com, apbianco@cygnus.com, java-gnats@sourceware.cygnus.com
Subject: Re: gcj/260: "Klass.class" expression should cause Klass to be 
 initialized
Date: Sun, 18 Jun 2000 19:48:22 -0400

 Bryce McKinlay wrote:
 > I was actually thinking of the JDK 1.2/1.3 html docs, where it says:
 > 
 > "A call to forName("X") causes the class named X to be initialized."
 
 Thanks.  Tom pointed out the same.  I'd bet Sun added that line after
 all the confusion with JDBC driver initialization prior to 1.2.
 
 > > Now, the PR also says "gij ClassInit" fails the test.  It turns out that
 > > libgcj's Class.forName() fails to perform initialization as well.  So
 > > the runtime must be patched along with gcj.
 > 
 > Oops, your right. I don't know how I didnt notice this before! But I see Tom
 > has checked in a fix for that already. gcj still needs to be fixed as well of
 > course, as ".class" is implemented differently.
 
 Right.  A more direct mechanism is used, but only when compiling source
 to native code.
 
 --
 Jeff Sturm
 jeff.sturm@appnet.com

From: tromey@sourceware.cygnus.com
To: java-gnats@sourceware.cygnus.com
Cc:  
Subject: gcj/260
Date: 23 Jun 2000 21:53:52 -0000

 CVSROOT:	/cvs/java
 Module name:	libgcj
 Changes by:	tromey@sourceware.cygnus.com	00/06/23 14:53:52
 
 Modified files:
 	libjava/testsuite: ChangeLog 
 Added files:
 	libjava/testsuite/libjava.lang: PR260.java PR260.out 
 
 Log message:
 	For PR gcj/260:
 	* libjava.lang/PR260.out: New file.
 	* libjava.lang/PR260.java: New file.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/gcc/libjava/testsuite/ChangeLog.diff?cvsroot=java&r1=1.101&r2=1.102
 http://gcc.gnu.org/cgi-bin/gcc/libjava/testsuite/libjava.lang/PR260.java.diff?cvsroot=java&r1=NONE&r2=1.1
 http://gcc.gnu.org/cgi-bin/gcc/libjava/testsuite/libjava.lang/PR260.out.diff?cvsroot=java&r1=NONE&r2=1.1
 
Responsible-Changed-From-To: apbianco->tromey
Responsible-Changed-By: tromey
Responsible-Changed-When: Fri Jun 23 15:09:53 2000
Responsible-Changed-Why:
    I fixed it.
State-Changed-From-To: open->analyzed
State-Changed-By: tromey
State-Changed-When: Fri Jun 23 15:09:53 2000
State-Changed-Why:
    I have a patch to fix this.
    It is waiting approval from Alex.

From: tromey@cygnus.com
To: apbianco@cygnus.com, bryce@albatross.co.nz,
  java-gnats@sourceware.cygnus.com, tromey@cygnus.com
Cc:  
Subject: Re: gcj/260
Date: 23 Jun 2000 22:09:53 -0000

 Synopsis: "Klass.class" expression should cause Klass to be initialized
 
 Responsible-Changed-From-To: apbianco->tromey
 Responsible-Changed-By: tromey
 Responsible-Changed-When: Fri Jun 23 15:09:53 2000
 Responsible-Changed-Why:
     I fixed it.
 State-Changed-From-To: open->analyzed
 State-Changed-By: tromey
 State-Changed-When: Fri Jun 23 15:09:53 2000
 State-Changed-Why:
     I have a patch to fix this.
     It is waiting approval from Alex.
 
 http://sourceware.cygnus.com/cgi-bin/gnatsweb.pl?cmd=view&pr=260&database=java

From: Alexandre Petit-Bianco <apbianco@cygnus.com>
To: tromey@cygnus.com
Cc: bryce@albatross.co.nz, java-gnats@sourceware.cygnus.com
Subject: Re: gcj/260
Date: Fri, 23 Jun 2000 18:40:19 -0700 (PDT)

 tromey@cygnus.com writes:
 
 >     I have a patch to fix this.  It is waiting approval from Alex.
 
 I'm guessing you're talking about a compiler patch. I can't find in
 with the GNATS database.
 
 ./A

From: Tom Tromey <tromey@cygnus.com>
To: Alexandre Petit-Bianco <apbianco@cygnus.com>
Cc: tromey@cygnus.com, java-gnats@sourceware.cygnus.com
Subject: Re: gcj/260
Date: Fri, 23 Jun 2000 23:01:51 -0700 (PDT)

 Alex>  I'm guessing you're talking about a compiler patch. I can't
 Alex>  find in with the GNATS database.
 
 I resent it to gcc-patches.
 It didn't seem to go through the first time.
 I CCd you this time.
 
 Tom
State-Changed-From-To: analyzed->closed
State-Changed-By: tromey
State-Changed-When: Sun Jun 25 10:29:00 2000
State-Changed-Why:
    I checked in a fix for this.
    Please give it a try.  If it doesn't work, reopen the PR.
    (It does work for me on your test case.)

From: tromey@cygnus.com
To: bryce@albatross.co.nz, java-gnats@sourceware.cygnus.com, tromey@cygnus.com
Cc:  
Subject: Re: gcj/260
Date: 25 Jun 2000 17:29:00 -0000

 Synopsis: "Klass.class" expression should cause Klass to be initialized
 
 State-Changed-From-To: analyzed->closed
 State-Changed-By: tromey
 State-Changed-When: Sun Jun 25 10:29:00 2000
 State-Changed-Why:
     I checked in a fix for this.
     Please give it a try.  If it doesn't work, reopen the PR.
     (It does work for me on your test case.)
 
 http://sourceware.cygnus.com/cgi-bin/gnatsweb.pl?cmd=view&pr=260&database=java
>Unformatted:



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