Java Forum / General / June 2007
A fundamental question about bytecode and nativecode
cat_dog_a.s - 09 May 2007 05:50 GMT At the server end, why should Sun force us to keep our codes in bytecode (class) format? Why not allow us the translate code into native format so that it servers the clients a lot quicker? I'm sure this is technically possible. Then what the allure of bytecode. People don't change their server end operating systems often. Then the OS neutrality of bytecode should hardly be of any relevance today.
Andrew Thompson - 09 May 2007 05:59 GMT >At the server end, why should Sun force us to keep our codes in >bytecode (class) format? Why not allow us the translate code into >native format so that it servers the clients a lot quicker? Bytecodes are translated to native format on loading. Since server classes are only loaded infrequently, and thereafter kept in memory, it is not a big issue.
Servers load slow, but run quick.
 Signature Andrew Thompson http://www.athompson.info/andrew/
Matej Cepl - 09 May 2007 08:55 GMT > At the server end, why should Sun force us to keep our codes in > bytecode (class) format? Why not allow us the translate code into > native format so that it servers the clients a lot quicker? I'm sure > this is technically possible. Then what the allure of bytecode. People > don't change their server end operating systems often. Then the OS > neutrality of bytecode should hardly be of any relevance today. http://gcc.gnu.org/java/
Lew - 09 May 2007 14:29 GMT > http://gcc.gnu.org/java/ I have never found Gnu "Java" usable.
It's probably just me. But it's always a couple of versions old and misses a lot of what I use in Java. Plus it doesn't seem to integrate with anything.
Just give me Sun or IBM JVMs for server or desktop.
cat_dog_a.s wrote:
>> At the server end, why should Sun force us to keep our codes in >> bytecode (class) format? Why not allow us the translate code into >> native format so that it servers the clients a lot quicker? I'm sure >> this is technically possible. Then what the allure of bytecode. People >> don't change their server end operating systems often. Then the OS >> neutrality of bytecode should hardly be of any relevance today. As Andrew pointed out, Java does translate into machine code (which I assume you mean by "native format" - correct me if I'm mistaken). Furthermore, the beauty of running server code in a JVM is that the same product can run on different OSes. I routinely develop and test my Java projects, server, client and application, on Windows (XP these days), Linux and Solaris. Companies like IBM and Oracle, just to name two, are /awfully/ glad their server products are cross platform.
The optimizations that Java (especially in server mode) can perform on your bytecode are generally superior to those performed statically at build time on compiled executables.
Hey, isn't the object code in a compiled executable an intermediate format, too? Doesn't it get translated to "native format" also?
Sun does not "force" you to keep your "codes" in bytecode. You are perfectly welcome to use .Net and C#. Of course then you are stuck using Windows servers, which are more expensive and less reliable than, say, Linux. Oh, and you are tied to a single vendor, Microsoft. Oh, and also all your support software, like the web servers and cluster-facets, have to come from that vendor. Hmm, maybe it's economics and the desire for functioning products that forces you to use Java.
Short answer: Sun runs Java in a JVM because it works to do so, on technical grounds. Not as some sort of weird strong-arm tactic to oppress you. Maybe you should abandon the paranoid approach and just consider the technical and economic merits.
 Signature Lew
blmblm@myrealbox.com - 12 May 2007 19:02 GMT [ snip ]
> Hey, isn't the object code in a compiled executable an intermediate format, > too? Doesn't it get translated to "native format" also? How so? As I understand it, object code is "machine language" -- binary data that can be directly executed by the processor. What am I not getting here?
[ snip ]
 Signature B. L. Massingill ObDisclaimer: I don't speak for my employers; they return the favor.
Mark Thornton - 12 May 2007 19:04 GMT > [ snip ] > [quoted text clipped - 6 lines] > > [ snip ] Most modern processors perform yet another translation stage from say x86 code into some internal form which is actually executed.
blmblm@myrealbox.com - 12 May 2007 23:15 GMT > > [ snip ] > > [quoted text clipped - 9 lines] > Most modern processors perform yet another translation stage from say > x86 code into some internal form which is actually executed. Aha. How embarrassing that I was somehow blissfully unaware of this .... Well, as they say in another newsgroup I follow: You learn stuff here. Thanks.
 Signature B. L. Massingill ObDisclaimer: I don't speak for my employers; they return the favor.
Ian Wilson - 14 May 2007 09:27 GMT >> [ snip ] >> [quoted text clipped - 9 lines] > Most modern processors perform yet another translation stage from say > x86 code into some internal form which is actually executed. http://en.wikipedia.org/wiki/Microcode
blmblm@myrealbox.com - 14 May 2007 17:40 GMT > >> [ snip ] > >> [quoted text clipped - 11 lines] > > http://en.wikipedia.org/wiki/Microcode Oh, *microcode* .... Yeah, okay, I guess then one could think of object code as being an intermediate format, though the Wikipedia article referenced above seems to me to indicate that for x86 the "translation" to "native format" happens on the fly and in hardware.
Terminology quibbles, maybe.
 Signature B. L. Massingill ObDisclaimer: I don't speak for my employers; they return the favor.
Mark Thornton - 14 May 2007 19:40 GMT > Oh, *microcode* .... Yeah, okay, I guess then one could think > of object code as being an intermediate format, though the > Wikipedia article referenced above seems to me to indicate > that for x86 the "translation" to "native format" happens on > the fly and in hardware. There are number of different x86 implementations. Intel has several several, then there are AMD, TransMeta, VIA and others.
Mike Schilling - 04 Jun 2007 16:15 GMT > [ snip ] > [quoted text clipped - 4 lines] > binary data that can be directly executed by the processor. What > am I not getting here? A native executable contains machine code. It also contains directives for allocating zero'd regions, symbolic references to shared libraries, relocation information for code which may run at different addresses, and other meta-information used to modify and generate code at runtime.
blmblm@myrealbox.com - 04 Jun 2007 19:27 GMT > > [ snip ] > > [quoted text clipped - 9 lines] > relocation information for code which may run at different addresses, and > other meta-information used to modify and generate code at runtime. For what it's worth, if I remember the earlier discussion correctly, Lew's mention of "intermediate format" was intended to convey the idea that some/many/all? modern processors don't actually execute machine code, but translate it into something lower-level. Someone pointed readers to the Wikipedia article on microcode.
What you're saying is (AFAIK) true too, but a different thing, maybe?
 Signature B. L. Massingill ObDisclaimer: I don't speak for my employers; they return the favor.
Mike Schilling - 04 Jun 2007 19:35 GMT >> > [ snip ] >> > [quoted text clipped - 20 lines] > What you're saying is (AFAIK) true too, but a different thing, > maybe? Yes. I myself wouldn't call machine code an intermediate format because it's turned into microcode, any more than I'd call the microcode an intermediate format because it's turned into electrical signals.
Lew - 05 Jun 2007 03:15 GMT Mike Schilling wrote:
>>> A native executable contains machine code. It also contains directives >>> for >>> allocating zero'd regions, symbolic references to shared libraries, >>> relocation information for code which may run at different addresses, and >>> other meta-information used to modify and generate code at runtime. <blmblm@myrealbox.com> wrote in message
>> For what it's worth, if I remember the earlier discussion >> correctly, Lew's mention of "intermediate format" was intended [quoted text clipped - 5 lines] >> What you're saying is (AFAIK) true too, but a different thing, >> maybe? Actually, I meant what Mike was talking about.
Mike Schilling wrote:
> Yes. I myself wouldn't call machine code an intermediate format because > it's turned into microcode, any more than I'd call the microcode an > intermediate format because it's turned into electrical signals. I feel the same way.
 Signature Lew
Lew - 05 Jun 2007 03:20 GMT Mike Schilling wrote:
>>> A native executable contains machine code. It also contains directives for >>> allocating zero'd regions, symbolic references to shared libraries, >>> relocation information for code which may run at different addresses, and >>> other meta-information used to modify and generate code at runtime. <blmblm@myrealbox.com> wrote in message
>>> For what it's worth, if I remember the earlier discussion >>> correctly, Lew's mention of "intermediate format" was intended [quoted text clipped - 5 lines] >>> What you're saying is (AFAIK) true too, but a different thing, >>> maybe?
> Actually, I meant what Mike was talking about. Furthermore, relocation directives and the like are hardly modern in computer terms.
 Signature Lew
blmblm@myrealbox.com - 05 Jun 2007 14:23 GMT > Mike Schilling wrote: > >>> A native executable contains machine code. It also contains directives [quoted text clipped - 22 lines] > > I feel the same way. Okay .... But what you said in that earlier post was
>Hey, isn't the object code in a compiled executable an intermediate format, >too? Doesn't it get translated to "native format" also? (http://groups.google.com/group/comp.lang.java.programmer/msg/f90c5071b3d98ac4?hl=en&)
Maybe I'm just quibbling about terminology here, or taking things out of context, but -- object code in an executable is an intermediate format, but machine code isn't? I'm confused. Aren't those the same thing?
 Signature B. L. Massingill ObDisclaimer: I don't speak for my employers; they return the favor.
Lew - 05 Jun 2007 14:36 GMT > Maybe I'm just quibbling about terminology here, or taking things out > of context, but -- object code in an executable is an intermediate > format, but machine code isn't? I'm confused. Aren't those the same > thing? Yours seems like a good question, really, and made me think.
I think it's a matter of context. To a Java programmer, machine code is not "really" an intermediate step to microcode - the machine code defines the native platform from Java's point of view (and the JVM's). But in real reality, we demigods know the JVM is mistaken.
For the sake of discussion, it is useful to forget microcode exists when in Javaworld.
When I said,
>> >Hey, isn't the object code in a compiled executable an intermediate format, >> >too? Doesn't it get translated to "native format" also? I was referring to the difference in machine code, not microcode, between a pre-compiled executable, which is what the OP had discussed, and that same executable when it's actually executing, same as Mike. All those relocatable addresses get real selectors, object modules get linked, DLLs get called, and only then as the program executes do you get a reasonable facsimile of "native format". No reference to microcode is necessary to make this point, although in fact it strengthens the point I was making.
Even in machine-language terms, the CPU does a sort of JIT by re-ordering instructions, caching results, manipulating registers, prefetching operands and a host of interpretive acts. The discussion had fallen into the trap of thinking that statically pre-compiled object modules in machine language would handle all that better than a bytecode-compiled class running in the JVM.
They had missed the point that, even in machine-language terms, that "compiled" executable is far from ready to run, nor does it specify precisely or even predictably exactly how those machine instructions will execute. The JVM, by virtue of its ability to adapt to runtime considerations and to globally balance actual usage patterns, often "recompiles" or reorganizes the instructions into a more efficient pattern than the OS can when it "recompiles" the machine-code executable.
My argument is that precompiled machine-language executables are an intermediate format to a runtime machine-language executable, even without regard to microcode.
 Signature Lew
Harry - 09 May 2007 09:22 GMT Even you are right, OS seldom changes, it is designed for that purpose. If the conversion is made to native code for every developer, they will not know the advantage of JAVA, being "platform- independent".
If you really want to make it to native code after considering in your case, you will not switch to another OS, and really want it to load faster, there are many tools available which helps you to convert JAVA source to native code. (I agree to Andrew, it still run fast for bytecode)
This is one of the examples: http://gcc.gnu.org/java/
Harry
> At the server end, why should Sun force us to keep our codes in > bytecode (class) format? Why not allow us the translate code into > native format so that it servers the clients a lot quicker? I'm sure > this is technically possible. Then what the allure of bytecode. People > don't change their server end operating systems often. Then the OS > neutrality of bytecode should hardly be of any relevance today. Lew - 09 May 2007 14:32 GMT > Even you are right, OS seldom changes, it is designed for that > purpose. If the conversion is made to native code for every developer, > they will not know the advantage of JAVA, being "platform- > independent". Very good point, which would have been better made inline rather than top-posted.
> If you really want to make it to native code after considering in your > case, you will not switch to another OS, and really want it to load > faster, there are many tools available which helps you to convert JAVA > source to native code. (I agree to Andrew, it still run fast for > bytecode) The main tool that helps convert Java (not "JAVA") to native code is the JVM. It does a bang-up job and you don't have to go through a whole lot of fooferol with third-party products that will not improve the situation.
How is load time even a consideration?
> This is one of the examples: > http://gcc.gnu.org/java/ Yecch.
 Signature Lew
Andrew Thompson - 10 May 2007 04:49 GMT ..
>How is load time even a consideration? You've hit upon one of my 'pet beefs'. Java is not especially suited to little, fast 'command line' based tools. Who would want to load a JVM (even a minimal or core one) just to do a directory listing, or delete a file?
OTOH - it is best to start *learning* Java from the command line.
So when the developer sees a 'hello world' application take 0.3 seconds it seems (because it is) 'slow', and gives the vague impression (to people who do not yet understand the strengths of the way Sun does it) that 'Java is slow'.
The same applies (in some ways) to applets, with the added complication that some VM/browser combos. will cause a web page to 'freeze' while waiting for both the bytecodess (and possibly media) to download, and the JVM to load and complete 'init()'!
The places where Java is best and fastest, the server and long running desktop applications, are usually not 'seen' by end users and beginning developers.
 Signature Andrew Thompson http://www.athompson.info/andrew/
Eric Sosman - 10 May 2007 13:45 GMT > . >> How is load time even a consideration? [quoted text clipped - 3 lines] > a JVM (even a minimal or core one) just to do a directory listing, or > delete a file? Agreed! But it's my impression that Java startup has improved quite a bit with succeeding versions. Not so long ago I did a two-generation upgrade from 1.4 to 1.6, and the time-to-first-rumblings seems to have shortened a good deal. (No actual measurements, just an informal sense of immediacy.)
In the 1.2 days, of course, "Initializing Java ..." was a cue to go get coffee.
 Signature Eric Sosman esosman@acm-dot-org.invalid
Andy Dingley - 14 May 2007 16:31 GMT > You've hit upon one of my 'pet beefs'. Java is not especially suited > to little, fast 'command line' based tools. Compared to interpreted shell? Shell that uses embedded sed and scratchfiles to process strings?
My desktop box is 2GB of Windows XP, running a shedload of scripts in shell, Python and Java. Of all the things that exist solely to put a crimp in my day, JVM classload times aren't anywhere near the biggest.
XP taking 20 minutes to delete files probably _is_ the biggest. OK, so there's a lot of files in some of those directories and TortoiseSVN is probably implicated too. But if I'm going to start pointing the finger of bloatware blame at anything, it'll be the flakey stability- blancmange that is Windows Exploder, long before it's my JVM.
Adam Maass - 09 May 2007 10:55 GMT > At the server end, why should Sun force us to keep our codes in > bytecode (class) format? Why not allow us the translate code into > native format so that it servers the clients a lot quicker? I'm sure > this is technically possible. Then what the allure of bytecode. People > don't change their server end operating systems often. Then the OS > neutrality of bytecode should hardly be of any relevance today. In many cases, develop on commodity WinTel boxes, deploy on expensive Sun servers.
A java source to native compiler can make certain optimizations, but it is basicly guesswork as to which optimizations will help the most. Most compile-time optimizations are therefore a bit conservative. A JVM that runs interpreted bytecode has real runtime data to determine where aggresive to-native compiler optimzations will help the most. Only a few places in the program are turned to completely native code, but the native code can be aggressively optimized.
Patricia Shanahan - 09 May 2007 23:33 GMT >> At the server end, why should Sun force us to keep our codes in >> bytecode (class) format? Why not allow us the translate code into [quoted text clipped - 5 lines] > In many cases, develop on commodity WinTel boxes, deploy on expensive > Sun servers. Or my case, develop and do small runs on a WinTel workstation, do big runs on a Linux grid.
Patricia
Mike Schilling - 04 Jun 2007 02:15 GMT >> At the server end, why should Sun force us to keep our codes in >> bytecode (class) format? Why not allow us the translate code into [quoted text clipped - 6 lines] > In many cases, develop on commodity WinTel boxes, deploy on expensive > Sun servers. In my case, develop on a Wintel box, test on several Wintel OSes, various Linuxes, Solaris (both Intel and Sparc), and whatever else the silly customers want to run on. It's not a huge convenience that the same "executable" format works on all of them (if we had to build multiple executables as we did in C and C++ days, that could be done), but it's not wholly insignificant either.
Lew - 04 Jun 2007 02:39 GMT >>> At the server end, why should Sun force us to keep our codes in >>> bytecode (class) format? Why not allow us the translate code into [quoted text clipped - 12 lines] > executables as we did in C and C++ days, that could be done), but it's not > wholly insignificant either. I no longer see the original posts on this thread, but I believe other posters have pointed out the error in the OP's assumption that deploying in native code would result in faster execution than the JVM can achieve on bytecode.
The premise that if you "translate code into native format [outside the JVM] ... it serve[s] the clients a lot quicker" is flawed. It might actually run slower than the current generation of JVMs.
 Signature Lew
Arne Vajhøj - 04 Jun 2007 02:43 GMT > The premise that if you "translate code into native format [outside the > JVM] ... it serve[s] the clients a lot quicker" is flawed. It might > actually run slower than the current generation of JVMs. Yep.
The only areas where I see native having an advantages is startup time and memory footprint for small apps.
Arne
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|