Message5767

Author alexey
Recipients alexey
Date 2010-05-15.15:58:16
SpamBayes Score 1.5017296e-06
Marked as misclassified No
Message-id <1273939099.73.0.820010682586.issue1611@psf.upfronthosting.co.za>
In-reply-to
Content
Consider the simplest example aaa.py with one line of code: 
print "Simple test"
Here is a fragment of bytecode, generated by Jython for this program (bytecode can be seen with javap, which is part of Sun’s JDK. It is might be helpful to create another single line file bbb.py, which contains “import aaa” and launch “jython.bat bbb.py” in order to see aaa$py.class in your local directory. Then run “javap -c aaa$py”):

public class aaa$py extends org.python.core.PyFunctionTable implements org.python.core.PyRunnable{
static final aaa$py self; //Field declared both static and final
...
public aaa$py(java.lang.String);  //Instance constructor
  Code:
   0:	aload_0
   1:	invokespecial	#35;
   4:	aload_0
   5:	putstatic	#39; //Write to field self:Laaa$py;
}

Line 5 (putstatic #39) in the instance constructor breaks JVM specifications, because fields declared both static and final must be initialized with compile-time values prior any instance of the class are created (see chapter 2.17.4 in the JVMS specification http://java.sun.com/docs/books/jvms/second_edition/html/VMSpecTOC.doc.html).
Seems that problem arises when Sun JVM performs some optimizations during bytecode compilation, which are correct in terms of JVMS, but don’t compatible with Jython. 
To observe the issue just force code compilation by passing –Xcomp option to JRE. 
I used:
set _JAVA_OPTS=-Xcomp
Because this problem exists in every file that Jython executes, it is not necessary to pass other arguments, just run jython.bat without parameters:
C:\jython2.5.1\test>..\jython.bat

Jython 2.5.1 (Release_2_5_1:6813, Sep 26 2009, 13:47:54)
[Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.6.0_18
error importing site
Traceback (most recent call last):
  File "C:\jython2.5.1\Lib\site.py", line 0, in <module>
java.lang.NullPointerException
        at org.python.core.PyTableCode.call(PyTableCode.java:165)
        at org.python.core.PyCode.call(PyCode.java:18)
        at org.python.core.imp.createFromCode(imp.java:326)
        at org.python.core.imp.createFromPyClass(imp.java:145)
        at org.python.core.imp.loadFromSource(imp.java:505)
        at org.python.core.imp.find_module(imp.java:411)
        at org.python.core.imp.import_next(imp.java:635)
        at org.python.core.imp.import_first(imp.java:656)
        at org.python.core.imp.load(imp.java:564)
        at org.python.util.jython.run(jython.java:177)
        at org.python.util.jython.main(jython.java:129)
java.lang.NullPointerException: java.lang.NullPointerException

I believe that field “self” shouldn’t be declared as final in order to avoid this issue.

Java version is
C:\Program Files\Java\jdk1.6.0_18\bin>java.exe -version
java version "1.6.0_18"
Java(TM) SE Runtime Environment (build 1.6.0_18-b07)
Java HotSpot(TM) Client VM (build 16.0-b13, mixed mode, sharing)
History
Date User Action Args
2010-05-15 15:58:20alexeysetrecipients: + alexey
2010-05-15 15:58:19alexeysetmessageid: <1273939099.73.0.820010682586.issue1611@psf.upfronthosting.co.za>
2010-05-15 15:58:19alexeylinkissue1611 messages
2010-05-15 15:58:16alexeycreate