Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Different compilers = Different byte code?

Reply
Thread Tools

Different compilers = Different byte code?

 
 
Jaap de Bergen
Guest
Posts: n/a
 
      08-30-2004
Hello,

I'm having a very strange problem with a java applet. I couldn't get
any java applet to run in internet explorer (standard 1.1 vm <- very
old). So i went to:

http://java.sun.com/docs/books/tutor...MeApplets.html

These applets are running fine.

Now i have downloaded the source code of the example applets, compiled
them and put them on my website. And it doesn't run.

I've used exactly the same source code. The only difference is the
compiler. I guess the examples on the above link are compiled with
jdk1.1 and i compile the examples with 1.4.

Is it possible that the compiler is the source of the problem? The
compiled classes differ a couple of bytes in filesize.

I tryed compiling jdk 1.1.8, but that didn't help. Does anybody know a
place where i can download jdk1.1? (it's not on suns archive page)

Cheers!

Jaap
 
Reply With Quote
 
 
 
 
Matt Humphrey
Guest
Posts: n/a
 
      08-30-2004

"Jaap de Bergen" <DEBERGEN.COM@REMOVE_THIS_TO_EMAILdomainsbyproxy.c om> wrote
in message news:(E-Mail Removed)...
> Hello,
>
> I'm having a very strange problem with a java applet. I couldn't get
> any java applet to run in internet explorer (standard 1.1 vm <- very
> old). So i went to:
>
> http://java.sun.com/docs/books/tutor...MeApplets.html
>
> These applets are running fine.
>
> Now i have downloaded the source code of the example applets, compiled
> them and put them on my website. And it doesn't run.
>
> I've used exactly the same source code. The only difference is the
> compiler. I guess the examples on the above link are compiled with
> jdk1.1 and i compile the examples with 1.4.
>
> Is it possible that the compiler is the source of the problem? The
> compiled classes differ a couple of bytes in filesize.
>
> I tryed compiling jdk 1.1.8, but that didn't help. Does anybody know a
> place where i can download jdk1.1? (it's not on suns archive page)


What message do you get in the Java Console when they fail to run?

Cheers,
Matt Humphrey http://www.velocityreviews.com/forums/(E-Mail Removed) http://www.iviz.com/


 
Reply With Quote
 
 
 
 
Jaap de Bergen
Guest
Posts: n/a
 
      08-30-2004
On Mon, 30 Aug 2004 14:23:36 -0400, "Matt Humphrey"
<(E-Mail Removed)> wrote:

>
>"Jaap de Bergen" <DEBERGEN.COM@REMOVE_THIS_TO_EMAILdomainsbyproxy.c om> wrote
>in message news:(E-Mail Removed)...
>> Hello,
>>
>> I'm having a very strange problem with a java applet. I couldn't get
>> any java applet to run in internet explorer (standard 1.1 vm <- very
>> old). So i went to:
>>
>> http://java.sun.com/docs/books/tutor...MeApplets.html
>>
>> These applets are running fine.
>>
>> Now i have downloaded the source code of the example applets, compiled
>> them and put them on my website. And it doesn't run.
>>
>> I've used exactly the same source code. The only difference is the
>> compiler. I guess the examples on the above link are compiled with
>> jdk1.1 and i compile the examples with 1.4.
>>
>> Is it possible that the compiler is the source of the problem? The
>> compiled classes differ a couple of bytes in filesize.
>>
>> I tryed compiling jdk 1.1.8, but that didn't help. Does anybody know a
>> place where i can download jdk1.1? (it's not on suns archive page)

>
>What message do you get in the Java Console when they fail to run?
>


I'm getting the following output:
------------------------------------------------------------------------
Microsoft (R) VM for Java, 5.0 Release 5.0.0.3810
==============================================
? help
c wissen
f finalize-methode uitvoeren
g garbage verzamelen
m geheugengebruik
q afsluiten
t thread-lijst
==============================================
Error loading class: MyApplet
java.lang.NoClassDefFoundError
java.lang.ClassNotFoundException: MyApplet
at com/ms/vm/loader/URLClassLoader.loadClass
at com/ms/vm/loader/URLClassLoader.loadClass
at com/ms/applet/AppletPanel.securedClassLoad
at com/ms/applet/AppletPanel.processSentEvent
at com/ms/applet/AppletPanel.processSentEvent
at com/ms/applet/AppletPanel.run
at java/lang/Thread.run
------------------------------------------------------------------------

Cheers!

Jaap
 
Reply With Quote
 
Matt Humphrey
Guest
Posts: n/a
 
      08-30-2004

"Jaap de Bergen" <DEBERGEN.COM@REMOVE_THIS_TO_EMAILdomainsbyproxy.c om> wrote
in message news:(E-Mail Removed)...
> On Mon, 30 Aug 2004 14:23:36 -0400, "Matt Humphrey"
> <(E-Mail Removed)> wrote:


<snip>

> ==============================================
> Error loading class: MyApplet
> java.lang.NoClassDefFoundError
> java.lang.ClassNotFoundException: MyApplet
> at com/ms/vm/loader/URLClassLoader.loadClass
> at com/ms/vm/loader/URLClassLoader.loadClass
> at com/ms/applet/AppletPanel.securedClassLoad
> at com/ms/applet/AppletPanel.processSentEvent
> at com/ms/applet/AppletPanel.processSentEvent
> at com/ms/applet/AppletPanel.run
> at java/lang/Thread.run
> ------------------------------------------------------------------------


The "NoClassDefFoundError" means the JVM in the browser isn't even seeing
your applet. Are you sure you put it in the right place? Is your html
configured correctly? See Roedy's site
http://mindprod.com/jgloss/applet.html to make sure you've correctly
installed your applet.

Cheers,
Matt Humphrey (E-Mail Removed) http://www.iviz.com/


 
Reply With Quote
 
Jaap de Bergen
Guest
Posts: n/a
 
      08-30-2004
On Mon, 30 Aug 2004 14:45:03 -0400, "Matt Humphrey"
<(E-Mail Removed)> wrote:

>
>"Jaap de Bergen" <DEBERGEN.COM@REMOVE_THIS_TO_EMAILdomainsbyproxy.c om> wrote
>in message news:(E-Mail Removed)...
>> On Mon, 30 Aug 2004 14:23:36 -0400, "Matt Humphrey"
>> <(E-Mail Removed)> wrote:

>
><snip>
>
>> ==============================================
>> Error loading class: MyApplet
>> java.lang.NoClassDefFoundError
>> java.lang.ClassNotFoundException: MyApplet
>> at com/ms/vm/loader/URLClassLoader.loadClass
>> at com/ms/vm/loader/URLClassLoader.loadClass
>> at com/ms/applet/AppletPanel.securedClassLoad
>> at com/ms/applet/AppletPanel.processSentEvent
>> at com/ms/applet/AppletPanel.processSentEvent
>> at com/ms/applet/AppletPanel.run
>> at java/lang/Thread.run
>> ------------------------------------------------------------------------

>
>The "NoClassDefFoundError" means the JVM in the browser isn't even seeing
>your applet. Are you sure you put it in the right place? Is your html
>configured correctly? See Roedy's site
>http://mindprod.com/jgloss/applet.html to make sure you've correctly
>installed your applet.
>


I think i've installed/configured it correctly. After a bit of
searching through jbuilder (my IDE) i've discovered a option "Target
VM":
------------------------------------------------------------------------
Target VM
Restricts the class files to work only on a specific VM version.

All Java SDKs Generates the class files to work with versions 1.1 and
all VMs in the Java 2 SDK. When you select this as the target VM, your
class files can be loaded by any VM. If you select this target VM, you
need to enter the following VM Parameter on the Run page of the
Runtime Configurations dialog box in order for the Smart Swap debugger
feature (JBuilder Developer and Enterprise) to work properly:
-Xverify:noneFor more information see "Modifying code while
debugging."

Java 2 SDK, v 1.2 And Later Generates the class files to run only on
VMs in the Java 2 SDK, v*1.2 and later, but won't run on 1.1 VMs. This
is the default.

Java 2 SDK, v 1.3 And Later Generates the class files to run only on
VMs in the Java 2 SDK, v*1.3 and later, but won't run on 1.1 or 1.2
VMs.

Java 2 SDK, v 1.4 And Later Generates the class files to run only on
VMs in the Java 2 SDK, v*1.4 and later, but won't run on 1.1, 1.2, or
1.3 VMs.
------------------------------------------------------------------------

"Java 2 SDK, v 1.2" was selected by default, when i choose "All Java
SDKs" everything goes oke and i can run any applet without any
problems in internet explorer.

I find this really strange, but i'm happy

Cheers!

Jaap
 
Reply With Quote
 
Michael Borgwardt
Guest
Posts: n/a
 
      08-30-2004
Jaap de Bergen wrote:
> I find this really strange, but i'm happy


Nothing strange about it. The Java class file format was changed a few times,
and some of the changes lead to incompatibilities with older JVMs.

Sun's javac compiler adresses this with the -target command line option.
 
Reply With Quote
 
Chris Uppal
Guest
Posts: n/a
 
      08-31-2004
Michael Borgwardt wrote:

> Nothing strange about it. The Java class file format was changed a few
> times, and some of the changes lead to incompatibilities with older JVMs.


Not that the format actually /did/ change -- just the version numbers. E.g. a
class file produced with target = 1.4, would run perfectly well on a 1.1 JVM if
the version numbers hadn't changed. I think Sun screwed up and confused the
library with the JVM.

-- chris



 
Reply With Quote
 
Michael Borgwardt
Guest
Posts: n/a
 
      08-31-2004
Chris Uppal wrote:
>>Nothing strange about it. The Java class file format was changed a few
>>times, and some of the changes lead to incompatibilities with older JVMs.

>
>
> Not that the format actually /did/ change -- just the version numbers.


Are you sure that the introduction of assertions did not require a
true incompatibility?
 
Reply With Quote
 
Chris Uppal
Guest
Posts: n/a
 
      08-31-2004
Michael Borgwardt wrote:

> > Not that the [class file] format actually /did/ change -- just the version

numbers.
>
> Are you sure that the introduction of assertions did not require a
> true incompatibility?


Hmm, good point. I had completely forgotten about assertions -- I never use
them and have never really thought much about them.

<pause, checks... />

I think it's more what I'd call a library issue: the assertions are compiled
into normal bytecodes in normal classfile format. For instance, code like:

private static void
method1(int i)
{
assert i > 0;
}

is compiled into:

private static method1 (I)V
getstatic Test/$assertionsDisabled Z
ifne 9
iload_0
ifgt 9
new java/lang/AssertionError
dup
invokespecial java/lang/AssertionError/<init> ()V
athrow
9: return

I.e, for those who don't like reading bytecodes (and who does ?):

private static void
method1(int i)
{
if (!$assertionsDisabled && i <= 0)
throw new AssertionError();
}

And there is code in the class's <cinit> that does the equivalent of:

static
{
$assertionsDisabled = !Test.class.desiredAssertionStatus();
}

to initialise the synthetic static field:

static final boolean $assertionsDisabled;

None of the bytecodes are in any way (that I can see) abnormal, and do not
require any co-operation from the JVM to execute properly (turning assertions
/on/ would require co-operation, but that's not a issue for the format of the
class file).

Of course, it's clear that these code snippets wouldn't work against a class
library where java.lang.Class didn't have a desiredAssertionStatus() method, or
where class java.lang.AssertionError didn't exist, so you can't actually /use/
classfiles with assertions in a (vanilla) 1.2 JVM (say). And that is certainly
the practical point that will interest most people -- no question. However,
I'd still call it a library issue, not a problem caused by the classfile format
as such (or by changes to the JVM spec). Indeed, classfiles with assertions
would load perfectly well into an earlier JVM (ignoring the "version" number),
and fail in a perfectly well-defined way as part of the /normal/ correct
operation of valid classfiles that happen refer to non-existent classes, or to
non-existent members of classes.

Admittedly, that's all more interesting than actually very useful Still,
at least I now know what assertions "really mean".

-- chris


 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      08-31-2004
On Tue, 31 Aug 2004 09:19:37 +0100, Chris Uppal wrote:

>> Nothing strange about it. The Java class file format was changed a few
>> times, and some of the changes lead to incompatibilities with older JVMs.

>
> Not that the format actually /did/ change -- just the version numbers.


Nu-uh. AFAIU the spec for 1.1 was that there
might be extraneous bytes at the end of
a class (not that Sun's compiler ever did it),
but that was tightened down in 1.2+.

Thus a 1.1 class with extraneous bytes at the
end was entirely valid in that context.

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
commercial c compilers vs free c compilers geletine C Programming 33 07-07-2006 05:21 AM
Wintel compilers with: C99 tgmath.h? 16-byte "long double"? bq C Programming 22 06-28-2004 04:58 PM
typedef, member function and const meat different compilers joe C++ 2 05-13-2004 01:08 PM
Templates and Different Compilers demibee C++ 1 12-30-2003 07:36 AM
Float question - different compilers cru C++ 2 09-21-2003 01:23 AM



Advertisments