Stories
Slash Boxes
Comments

News for nerds, stuff that matters

Transmeta Code Morphing != Just In Time

Posted by CmdrTaco on Thu Jan 27, 2000 09:12 AM
from the stuff-to-read dept.
Andy Armstrong has written us a pretty interesting, but somewhat technical piece of Just in Time, computer generated assembly language, profiling, and more. Its a pretty interesting little bit that ought to give you a lot to talk about.

The following was written by Slashdot Reader Andy Armstrong

Transmeta Code Morphing != Code Morphing

The recent Transmeta announcment crystalised something I've been thinking about for a while. It's my belief that it should be possible to make a compiler generate much better code in the general case than someone writing hand coded assembler. Furthermore it should be possible for a JIT (Just In Time) compiler to produce better code than a conventional one time compiler.

Why should a compiler be better than an experienced assembler programmer? Well,

  1. the compiler can know the target processor intimately (cycle times, impact of instruction ordering, etc.)
  2. the compiler gets to re-write the entire program each time it sees it.

The second point is critical: any programmer writing an assy. language program of any significant size will write the code to be maintainable. Of course, it makes sense to do things like defining standard entry and exit sequences to routines, keep a few registers spare (in those architectures that have more than a few) and other practices that lead to maintainable code, but the compiler doesn't have to maintain the code it writes. It gets to write the whole thing from scratch every time. This means that functions can be inlined (and repeated code sequences turned into functions). Loops can be unrolled then rolled back up at the next compile when the programmer has decided that space is more important than speed.

If you know you're not going to have to maintain a bit of code you can do some pretty scary things to get it to perform better. A compiler can potentially do that all the time.

Why should JIT be better than one time? This should be clear to anyone who's followed the Transmeta story. A key element of their code morphing technology is that they insert instrumentation into the code they generate, effectively profiling as it runs so that the compiler can decide which bits to optimize the next time it sees the code. It's well known that the coverage graph for a typical programme looks extremely spiky - the most frequently executed code may get hit thousands or millions of times more than it's neighbours. It follows that it really isn't worth optimizing the stuff that only accounts for a millionth of the code's execution time.

This brings me to my point: is there really any reason why a Java / JIT combination shouldn't result in code that executes as quickly as the equivalents in other languages?

You might suggest that garbage collection must slow things down, but I'm convinced that, done right, garbage collection can actually improve performance. malloc()/free() require the memory manager to think about the heap for every call, but new() can be implemented as a stack (m = memlimit; memlimit += size; return m) and the garbage collector gets to do all its memory management in one chunk - it can take an overview of the memory landscape rather than trying to keep things fairly optimal each time memory is released as free() must.

You could argue that the OO nature of Java means that it must dynamically allocate objects that would be static in a program written in C or assembler. That's true, but (assuming calls to new() are cheap, which I believe they can be) this really isn't a problem. Current processors don't take a huge performance hit when working with objects who's address is not known at compile time; in fact in many architectures it makes no difference at all.

So while it might seem profoundly counter-intuitive can anyone actually give me a good reason why Java + JIT should be slower than Good Programmertm + Assembler?

This discussion has been archived. No new comments can be posted.
Display Options Threshold:
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
(1) | 2 | 3 | 4 | 5
  • Re:Profoundly counterintuitive? by redhog (Score:2) Thursday January 27 2000, @07:36AM
  • Re:Compilers dont write better code than humans by interiot (Score:1) Thursday January 27 2000, @06:04AM
  • Re:Evolve code. by Geotrash (Score:2) Thursday January 27 2000, @07:42AM
  • Re:Profoundly counterintuitive? by Chuan-kai Lin (Score:1) Thursday January 27 2000, @06:05AM
  • Re:Java Byte Code by BrianJAckermann (Score:1) Thursday January 27 2000, @07:46AM
  • Re:Profoundly counterintuitive? by binkley (Score:1) Thursday January 27 2000, @06:07AM
  • Re:Profoundly counterintuitive? by Kvort (Score:1) Thursday January 27 2000, @06:07AM
  • Re:Evolve code. (Score:4)

    by DQuinn (110990) on Thursday January 27 2000, @07:50AM (#1330831)
    Sorry... this post is probably meant to be deeper inside this thread.

    Are we not all just dancing around the idea of a human compiler with a vast database of algorithms, intuition, look-ahead properties, and an abstracted idea of what it is exactly that the program is doing? IE. There is no compiler, to my knowledge, which writes highly effective parallel code. Why is that? Simply because no compiler can really understand the overall problem.

    How long do you think it will be before the all-powerful AI compiler is written, with all of these abilities, and more, on a box that runs at a few GHz?

    Or maybe i'm just being a little too science fictiony here :)

    Cheers,
    D
  • See "Engineering a Compiler" by vaxheadroom (Score:1) Thursday January 27 2000, @07:50AM
  • Re:The "C is not portable" myth by arivanov (Score:2) Thursday January 27 2000, @06:07AM
  • Re:Compiled Once vs. Compiled multiple times by mangino (Score:2) Thursday January 27 2000, @06:08AM
  • What are you saying? by Improv (Score:1) Thursday January 27 2000, @07:52AM
  • Re:Transmeta Speed by mohaine (Score:1) Thursday January 27 2000, @06:13AM
  • Re:Compiled Once vs. Compiled multiple times by JWRose (Score:1) Thursday January 27 2000, @06:13AM
  • Re:Profoundly counterintuitive? by Hard_Code (Score:2) Thursday January 27 2000, @06:15AM
  • by Junks Jerzey (54586) on Thursday January 27 2000, @06:15AM (#1330840)
    You're right, of course. No matter what some people have been trying to say for 40 years or more, you can almost always write better code than a compiler. This is especially true when you're dealing with something bigger than a a single function. The usual way of showing that a compiler is better than a human is by using one smallish C function as an example. That's a pointless example, because the benefit comes from analyzing that function in context and not on its own.

    The point of diminishing returns comes into play quickly, however. For example, take the renderer for most any fast 3D game. If you went into the routine that passes triangles to the graphics card, a frequent hot spot, and added a pointless call to a supposedly expensive function, like sqrt, you're not going to notice an effect on frame rate. Doing a higher level optimization, like removing a single polygon from a model, is going to be more of a benefit than optimizing the polygon code, but it's still not going to be noticible. Sometimes you can get big benefits by using algorithms that look more complicated, ones you wouldn't want to approach in assembly, even though they use more code.

    With complex programs, it's even conceivable for an interpreted language to out run a compiled one, because everything comes down to architecture and an understanding of the problem. This is hasn't been the case with Java, because Java is a fairly low level language (the more abstract a language is, the less win from compliation) and because Java has become entrenched in the "learn programming in 14 days" market of web designers turned programmers.

    So, yes, an assembly programmer can outrun most any compiler. But does it matter? Almost never.
  • 6502 by tilleyrw (Score:1) Thursday January 27 2000, @07:54AM
  • Why do "dynamic" single platform compiling by GrEp (Score:1) Thursday January 27 2000, @07:55AM
  • Don't rely on the Compiler to Optimize by ArcadeNut (Score:1) Thursday January 27 2000, @07:56AM
  • Why not do "dynamic" single platform compiling? by GrEp (Score:1) Thursday January 27 2000, @07:57AM
  • Re:Only when you can rewrite the whole thing by rmstar (Score:1) Thursday January 27 2000, @06:16AM
  • Re:Ooo, ooo, start on packing! by ucblockhead (Score:2) Thursday January 27 2000, @06:18AM
  • Re:Match code frag. as opt. tech. (Was:Evolve code by slashdot-terminal (Score:2) Thursday January 27 2000, @08:01AM
  • Re:Experience from Optimizing Java ... by radish (Score:1) Thursday January 27 2000, @06:18AM
  • Re:Evolve code. by mistabobdobalina (Score:1) Thursday January 27 2000, @08:07AM
  • Evolve code. (Score:3)

    by Anonymous Coward on Thursday January 27 2000, @04:28AM (#1330850)
    "In the general case", perhaps a compiler will produce better code (and certainlty not, as yet, for specialised cases - an inner loop coded direct to PPC macro assembler (PASM on Amiga PPC) is the fastest code I've ever written, but humans still write compilers. Now, if they were to force-evolve code using a genetic algorithm, you might get code better than any a human code write, but it'll probably depend on some weird side effect to some obscure instruction, or the rtesosnant frequency of your ram bus, or something...

    Cool article, all the same though. I'd love to see more of this sort of thing on Slashdot, like back in the old days.
  • JITs and one-time compilers; the good and the bad by ajdavis (Score:1) Thursday January 27 2000, @08:11AM
  • Java Byte Code by infodragon (Score:2) Thursday January 27 2000, @04:28AM
  • Yup. by TimoT (Score:1) Thursday January 27 2000, @08:12AM
  • Re:Compilers dont write better code than humans by Anonymous Coward (Score:1) Thursday January 27 2000, @06:22AM
  • JIT compiler by link-error (Score:1) Thursday January 27 2000, @04:29AM
  • Re:GC by Mr T (Score:2) Thursday January 27 2000, @08:13AM
  • Re:java JIT itself is not that slow. by radish (Score:2) Thursday January 27 2000, @06:23AM
  • by ZoeSch (70624) on Thursday January 27 2000, @06:23AM (#1330861)
    Nevertheless I'd like to point out that JIT is based a somewhat dangerous technique: a program that alters (its own) code. I believe this technique was used in the eighties to scare off hackers by making code incomprehensible and hard to disassemble until the program was actually running. Also (even on a good old 6502 processor) it's possible to make some speed improvents peeking and poking into the code you're actually executing.

    Not at all true... self modifying code is still around not only on JIT compilers but in interpreted languages and even device drivers (Or how do you think some device drivers adjust in real time to hardware changes?). And it's not a dangerous technique in itself, but (As usual) when executed improperly it can be a wild beast (As most people discovered when thy installed their first Cyrix and AMD 486 processors and discovered most x86 code wouldn't run properly because of cache integrity issues)

    When compilers for Microcomputers got faster and most processor architectures (known as Harvard architecture, I believe) explicitly require a division of RW and RO memory segments, self-modifying code was abandoned...

    First of all, Harvard machines require separate instruction and data pipelines and memory spaces, and 99% of the CPU's on the market (General, Embedded, etc.) are Von Neumann machines which use a single space to store instruction and data. The thing is, newer CPU's (Even if they're Von Neumann desings)have separate caches for data and instructions and most self modifying code violates the cache integrity (See above) because the code is modified in the cache but never stored back into memory (Unless you use a write-through cache design which is impractical from the performace point of view).

    BUT (And that's a big BUT :) if your JIT VM forces periodic cache writes to RAM (Not every time but enough times to ensure some sort of coherence if the cache and RAM are out of sync) you lose a bit of performance but gain a stabler setup.

    Disassemblers for JIT won't be as complex as a JIT assembler just because when you disassemble a piece of code you treat is under the black box principle (What goes in and what goes out) in order to derive the fundamental principles and algorithms, which can be implemented in 1E999 different ways, so if you disassembled the less optimal morph, bad luck... disassemble another test run and see if you get a better implementation of the algorithm. Or you could use the aforementioned principle and implement your own algorithm.

    JIT code/compilers, BTW are also being tested to produce self modifying chips (ASIC's and FPGA's) under VHDL/Verilog using also NNets or Gen. Algorithms to obtaing a first implementation and then using the JIT to optimize it...

    Really interesting stuff (The Transmeta Crusoe) and my bet is that soon other companies will follow altough not for the same reasons as Transmeta :)

    ZoeSch

  • The obvious answer... by nhowie (Score:1) Thursday January 27 2000, @04:32AM
  • Re:heap and stack by tagish (Score:1) Thursday January 27 2000, @06:24AM
  • within X% of the performance of native code by The Pim (Score:1) Thursday January 27 2000, @04:33AM
  • Re:Java Byte Code by Anonymous Coward (Score:1) Thursday January 27 2000, @06:25AM
  • by Chuan-kai Lin (26774) on Thursday January 27 2000, @06:26AM (#1330867) Homepage

    I do agree that machines should spit better code than humans do, but we are just not there yet. When will we get there? Maybe tomorrow, maybe next month, maybe next year, maybe next century. Nobody knows. Suppose we do get there tomorrow, I believe it will not be Java + JIT that made it, for the following reasons:

    1. Java is an imperative language, which are very hard to reason about because of the lack of referential transparency. Yes, I know that it is a known fact in computation theory that it is impossible to reason about arbitrary programs, but the fact is that we do not write arbitrary programs. Imperative programs with destructive updates are hard to reason about, and as a result we are almost always restricted to local optimizations. Local optimizations are great, but I am afraid that that alone will not be enough to break the barrier.
    2. Vast amounts of information is lost once the source program is compiled into bytecode, therefore making effective optimization much harder. You can tell the intention of the programmer from the source code, but it is hard to do so for machine instructions (or even preprocessed source code, which anyone who had read the nVidia XFree86 source code must agree). The JIT compiler must create code that acts exactly the same as the bytecode, and that restriction severely reduced its options.

    If that breakthrough were to come tomorrow, I believe it is most likely to come from the functional programming people. I believe that is the way to go for the future.

  • heap and stack by kmcardle (Score:2) Thursday January 27 2000, @04:35AM
  • provide some examples then... by SEAL (Score:2) Thursday January 27 2000, @10:46AM
  • Java Performance is due to the language itself... by Tom7 (Score:1) Thursday January 27 2000, @10:58AM
  • by TheDullBlade (28998) on Thursday January 27 2000, @08:16AM (#1330874)
    "1...not a JIT system but a dynamically optimizing compiler" a slow start is a big problem (which is why they are emphasizing long-term server programs), but that's not the main issue. There's no reason that profile-based optimization can't be applied to C programs. That there's an experimental JIT (yes, it's still a JIT) that's ahead of the C compilers in common use is no reason to claim that the JIT strategy is better.

    "2...as long as the results of the operation don't change" Which means that if the representation is different in a meaningful way they have to check whether the results of the operation change, reducing the efficiency, which was my point.

    "3...on all but the most simple applications" But I rarely do anything but the most simple applications. I allocate an array, then I free an array. I do this for hashes, trees, stacks, queues, and pretty much any data structure I use. Only when I am being extremely lazy will I allocate and free objects recursively. Modern CPUs with slow main memory and fast cache like it when you keep all the data together, so I generally do so. I also try to access it linearly, which they also like. The point holds.

    Don't try to compare the most primitive and unoptimized methods of custom memory management to the most sophisticated garbage collection algorithms. Remember, too, that a person doing custom memory management can write the same sophisticated garbage collector that Java would use.

    And don't confuse "primitive" with "fundamental". Pointers are fundamental. Having to analyse reverse polish code function to prevent dangerous operations, rather than making it impossible to construct operations you don't want, is primitive.

    "4...then tell me that dynamic dispatch is a problem." Okay, dynamic dispatch is a problem. Just because it can inline methods here and there doesn't mean you won't take an overall performance hit. Besides, that was only one example of the ways the lousy Java handholding slows things down.

    The Sun marketing papers you linked me to are just more of the same old Java hype. They'll go on to "prove" that their new super JIT is better than anything you could code by hand by comparing optimized idiomatic Java with the same code translated poorly into unidiomatic C++.

    Idiomatic C written by a competent optimizer will still blow the Java version out of the water.

    JIT by any other name smells just as bad.
  • Re:Evolve code. by Pentagram (Score:1) Thursday January 27 2000, @11:07AM
  • Very interesting, but not why I pick Java by evilpenguin (Score:2) Thursday January 27 2000, @11:10AM
  • Re:Java Byte Code by jilles (Score:2) Thursday January 27 2000, @08:18AM
  • Turf war - morphing vs. JIT by homunq (Score:2) Thursday January 27 2000, @11:17AM
  • Re:Compilers dont write better code than humans by GnrcMan (Score:1) Thursday January 27 2000, @06:26AM
  • offtopic but... by Shin Elendale (Score:1) Thursday January 27 2000, @11:18AM
  • Re:No. Hand coded assembler is faster. by nikh (Score:1) Thursday January 27 2000, @08:20AM
  • Re:that's what longs are for by AndrewHowe (Score:1) Thursday January 27 2000, @06:27AM
  • OT: computers at blitz by Daniel (Score:2) Thursday January 27 2000, @11:26AM
  • Re:This is so true, but it's getting harder by bradleyjg (Score:1) Thursday January 27 2000, @08:24AM
  • Re:Compilers dont write better code than humans by petermcanulty (Score:2) Thursday January 27 2000, @08:27AM
  • Re:Java Byte Code by deltavivis (Score:1) Thursday January 27 2000, @06:32AM
  • Re:Compilers dont write better code than humans by interiot (Score:1) Thursday January 27 2000, @06:35AM
  • Re:JIT Theory by TheFuzzy (Score:1) Thursday January 27 2000, @06:35AM
  • Re:Pretty technical? by robix (Score:1) Thursday January 27 2000, @06:37AM
  • Re:Ooo, ooo, start on packing! by ebbv (Score:1) Thursday January 27 2000, @06:39AM
  • Re:Ultimate optimisation needs better hints by zeroth (Score:1) Thursday January 27 2000, @11:27AM
  • Hey everybody...Listen Up by spacewalrus (Score:1) Thursday January 27 2000, @11:40AM
  • Re:Not so obvious by jilles (Score:2) Thursday January 27 2000, @11:43AM
  • Re:Compilers dont write better code than humans by coreman (Score:2) Thursday January 27 2000, @08:29AM
  • Re:What about the JIT? by necama (Score:1) Thursday January 27 2000, @11:50AM
  • Re:No. Hand coded assembler is faster. by GnrcMan (Score:2) Thursday January 27 2000, @11:53AM
  • Re:Evolve code. by gfxguy (Score:2) Thursday January 27 2000, @08:29AM
  • Henry Massalin's "Synthesis" Dissertation by Allen Akin (Score:1) Thursday January 27 2000, @08:30AM
  • Re:Evolve code. by mubes (Score:1) Thursday January 27 2000, @11:59AM
  • Compilers as good by Anonymous Coward (Score:1) Thursday January 27 2000, @06:39AM
  • Re:Not so obvious by jilles (Score:2) Thursday January 27 2000, @08:32AM
  • exactly by Cris E (Score:1) Thursday January 27 2000, @11:59AM
  • Re:Profoundly counterintuitive? by rmstar (Score:1) Thursday January 27 2000, @06:43AM
  • Re:Compilers dont write better code than humans by GnrcMan (Score:2) Thursday January 27 2000, @12:06PM
  • I wonder if it's really two cpus by jhonan (Score:1) Thursday January 27 2000, @12:08PM
  • Re:Compilers dont write better code than humans by technos (Score:2) Thursday January 27 2000, @08:34AM
  • Re:Java Byte Code by slashdot-terminal (Score:1) Thursday January 27 2000, @06:43AM
  • Dynamic Compilation by jmaessen (Score:1) Thursday January 27 2000, @12:13PM
  • short answer by TheDullBlade (Score:2) Thursday January 27 2000, @08:39AM
  • just plain wrong by TheDullBlade (Score:2) Thursday January 27 2000, @06:44AM
  • Java not a useable language? by Anonymous Coward (Score:1) Thursday January 27 2000, @08:40AM
  • by um... Lucas (13147) on Thursday January 27 2000, @06:45AM (#1330922) Journal
    I read that the 700 MHz Crusoe chip actually only attains the performance of a 500MHz Pentium (II or III, I forgot - oh, can Crusoe emulate SIMD? Not like it matters, but I'm wondering).

    So there you have it - code morphing, or just in time compiliing or whatever gives you about 70% of the performance precompiled code.

    That's not to downplay Transmeta's theoretical accomplishment. Those extra 200MHz go to things like monitoring it's VM, throttling the clock, etc. So in the end you lose 30% of the performance but make it up with 35X less power consumed.

    It's a great trade off for laptops, handhelds, etc. But not for workstations, servers, etc...

    I still don't like the idea that they're keeping the instruction sets closed. It would seem like if someone out there wanted to port GCC to Crusoes native instructions, that would be good... But they just don't want to be percieved as being at all incompatible with Intel, i guees.
  • Re:Java Byte Code by slashdot-terminal (Score:2) Thursday January 27 2000, @08:40AM
  • Wait a sec. by aheitner (Score:2) Thursday January 27 2000, @08:43AM
  • Re: Compilers - Deep Blue vs Kasparov by iang (Score:1) Thursday January 27 2000, @06:45AM
  • slashdot ate my < ! by TheDullBlade (Score:1) Thursday January 27 2000, @06:46AM
  • Re:No. Hand coded assembler is faster. by GnrcMan (Score:2) Thursday January 27 2000, @06:49AM
  • I'm from Kansas by donglekey (Score:1) Thursday January 27 2000, @12:13PM
  • Re:Compilers dont write better code than humans by jekk (Score:1) Thursday January 27 2000, @12:15PM
  • Re:Compilers dont write better code than humans by Brian Feldman (Score:1) Thursday January 27 2000, @12:21PM
  • Re:Don't rely on the Compiler to Optimize by PigleT (Score:2) Thursday January 27 2000, @08:48AM
  • Apples & Oranges was, Re:Not so obvious by Tassach (Score:1) Thursday January 27 2000, @12:28PM
  • Re:Compilers dont write better code than humans by GnrcMan (Score:1) Thursday January 27 2000, @12:30PM
  • Re:What about the JIT? by BinxBolling (Score:2) Thursday January 27 2000, @08:49AM
  • Re:Don't rely on the Compiler to Optimize by PigleT (Score:2) Thursday January 27 2000, @08:50AM
  • Re:Evolve code. by AxelBoldt (Score:1) Thursday January 27 2000, @12:32PM
  • Re:offtopic but... by Hallow (Score:1) Thursday January 27 2000, @12:34PM
  • Re:Compilers dont write better code than humans by AndrewHowe (Score:1) Thursday January 27 2000, @06:49AM
  • Re:Self-Modifying Code by skybrian (Score:1) Thursday January 27 2000, @12:36PM
  • Re:What about the JIT? by BinxBolling (Score:2) Thursday January 27 2000, @08:51AM
  • Re:Profoundly counterintuitive? by PeterBecker (Score:1) Thursday January 27 2000, @06:52AM
  • Re:Evolve code. by CFN (Score:1) Thursday January 27 2000, @12:38PM
  • A counterexample by David Roundy (Score:1) Thursday January 27 2000, @12:38PM
  • Re:Evolve code. by bgood (Score:1) Thursday January 27 2000, @06:53AM
  • Re:Evolve code. by Alton (Score:1) Thursday January 27 2000, @09:02AM
  • Re:Evolve code. by lollypop_man (Score:1) Thursday January 27 2000, @09:03AM
  • Re:Doesn´t work in practice by cje (Score:2) Thursday January 27 2000, @06:57AM
  • Sun's Windows Java2 JVM grows its heap slowly by billr (Score:1) Thursday January 27 2000, @06:59AM
  • Re:Sun license? by um... Lucas (Score:1) Thursday January 27 2000, @06:59AM
  • Re:Compilers dont write better code than humans by AndrewHowe (Score:1) Thursday January 27 2000, @07:00AM
  • Re:Evolve code. by Alex Belits (Score:1) Thursday January 27 2000, @06:12PM
  • just plain wrong (me this time) by TheDullBlade (Score:2) Thursday January 27 2000, @06:13PM
  • Re:Comparing JIT Misses The Main Point ! by PhiRatE (Score:2) Thursday January 27 2000, @12:39PM
  • Re:What about the JIT? by BinxBolling (Score:1) Thursday January 27 2000, @06:25PM
  • Java Numbers and the Cost of JIT Compilation by lgas (Score:1) Thursday January 27 2000, @06:56PM
  • Re:Experience from Optimizing Java ... by Brian Feldman (Score:1) Thursday January 27 2000, @12:42PM
  • Brute force and.. by xmedh02 (Score:1) Thursday January 27 2000, @12:50PM
  • Sun license? (Score:3)

    by PapaZit (33585) on Thursday January 27 2000, @04:37AM (#1330967)
    Doesn't Sun have a patent on hardware that can run java bytecode natively?

    I wonder where transmeta-ish devices fall. I'd call it software, but would sun's lawyers?
  • Re:Doesn´t work in practice by mikpos (Score:1) Thursday January 27 2000, @09:04AM
  • Re:Compilers dont write better code than humans by prizog (Score:1) Thursday January 27 2000, @12:56PM
  • by tjansen (2845) on Thursday January 27 2000, @04:38AM (#1330971) Homepage
    I have already heard that assumption that a compiler can generate better code than a programmer a thousand of times, but it does not get more true by repeating it - it is false. At least until compilers are able to understand the program. In every program there are things the compiler simply doesnt know. For example, in x86 assembler it is possible to save some cycles (and memory accesses) by using 16-bit or even 8-bit registers instead of 32 bit registers. You can double the number of registers by doing it. You need to be sure that the values in the registers are below 65536 or 256 to use these tricks, and the programmer can know this, but the compiler cant. The compiler might profile the possible value range if it is a really advanced compiler (I never heard of any compiler actually doing this), but it cannot be sure so it must at least check the values before for the case that they arent.

    As long as the programmer has more knowledge than the compiler, he will always find tricks to save an instruction here or there and outperform the compilers this way. You can find a great example of such programming tricks in the PCGPEs article about texture mapping inner loops here [gamers.org].

  • Games and Java by cstaylor (Score:1) Thursday January 27 2000, @01:02PM
  • Compiled Once vs. Compiled multiple times by JWRose (Score:2) Thursday January 27 2000, @04:38AM
  • Genuine Question: have you ever compared?? by orpheus (Score:2) Thursday January 27 2000, @07:51PM
  • Compiler will be faster than JIT by Marco Schramp (Score:1) Thursday January 27 2000, @04:40AM
  • Re:Evolve code. by lollypop_man (Score:1) Thursday January 27 2000, @09:08AM
  • Re:Why Optimize to overkill? by mikera (Score:2) Thursday January 27 2000, @09:12AM
  • possibly offtopic by speek (Score:2) Thursday January 27 2000, @07:00AM
  • within X% of the performance of native code by The Pim (Score:2) Thursday January 27 2000, @04:40AM
  • Re:Evolve code. by cranq (Score:1) Thursday January 27 2000, @01:03PM
  • The _REAL_ Reason by SamBeckett (Score:1) Thursday January 27 2000, @09:15AM
  • Re:Profoundly counterintuitive? by bhurt (Score:2) Thursday January 27 2000, @07:02AM
  • Why JIT is slow by 31eq (Score:2) Thursday January 27 2000, @04:40AM
  • Re:OT: computers at blitz by Repton (Score:1) Thursday January 27 2000, @01:03PM
  • by Hard_Code (49548) on Thursday January 27 2000, @09:15AM (#1330990)
    Right. I've always thought an ounce of design is worth a pound of optimization ;)

    Leave the design to the humans...leave the optimization to the compilers.

    Jazilla.org - the Java Mozilla [sourceforge.net]
  • Re:Evolve code. by JWRose (Score:1) Thursday January 27 2000, @01:05PM
  • Re:compiler smarter than humans? by CFN (Score:1) Thursday January 27 2000, @01:16PM
  • by TheDullBlade (28998) on Thursday January 27 2000, @04:42AM (#1330994)
    Seems profoundly intuitive to me.

    First of all, a JIT is rushed. You can design your optimizing one-time compiler to look at the code for better ways to do it all day, if you like, and while the developers will moan, they will still use it if gets them better results.

    Secondly, Java has a very specific standard (that is typically fudged... but that's beside the point). It doesn't give any leeway for a program to act a little different in boundary conditions, like C does. In C, an int is whatever size int is most easily handled by the target system; if you need a certain exact size of int, you can code that in with some extra effort. In Java, an int is a Java int and Java doesn't care in the least what the most efficient native int format is.

    Thirdly... automatic garbage collection is less efficient than hand coded allocation and deallocation, and dynamic allocation is less efficient than static allocation. There are odd cases where this is false, but they generally hold true, and where they do not, the C version can always use the more efficient method anyway. (and extremely fast calls to "new" can be easily achieved... at roughly 50% memory wastage)

    Fourthly: Java locks you into a OOP model which is inherently inefficient (at least as done in Java). All function calls must be dynamically redirected etc.

    I could go on, but it feels like trying to describe that water is wet and stones sink in it to someone who thinks it's intuitive that water should sink into stones.

    However, I will not dispute that you can definitely get better results by recompiling for each chip that something will run on. Some JITs may use this to push out ahead of one-time compilers.

    BTW, an experienced assembly coder will always beat or at least equal the optimizing compiler, because if nothing else works he can always look at what the compiler produces and see if he can improve on that. Besides, optimizing compilers are good, but not that good, someone has to write them, and when was the last time that you wrote a program that can solve complex creative problems better than you can?
  • Re:Java Byte Code by deltavivis (Score:1) Thursday January 27 2000, @07:04AM
  • JIT is not the same as Language performance by J.Random Hacker (Score:2) Thursday January 27 2000, @07:05AM
  • Re:Match code frag. as opt. tech. (Was:Evolve code by GaspodeTheWonderDog (Score:1) Thursday January 27 2000, @09:28AM
  • What C Compilers/Language needs. by Legerdemain (Score:1) Thursday January 27 2000, @07:06AM
  • Re:Sun license? by buckaroo-b (Score:1) Thursday January 27 2000, @04:44AM
  • Re:Java Byte Code by jilles (Score:2) Thursday January 27 2000, @09:32AM
  • Cache misses and other nonlinear behavior by Frank Sullivan (Score:2) Thursday January 27 2000, @09:33AM
  • counter-nit-picking by TheDullBlade (Score:1) Thursday January 27 2000, @07:06AM
  • Re:heap and stack by kmcardle (Score:1) Thursday January 27 2000, @07:06AM
  • Re:Profoundly counterintuitive? by tagish (Score:1) Thursday January 27 2000, @07:07AM
  • Re:here's how you do it (I think) by Anonymous Coward (Score:1) Thursday January 27 2000, @07:09AM
  • Re:Compilers dont write better code than humans by GnrcMan (Score:2) Thursday January 27 2000, @07:59PM
  • Re:Genuine Question: have you ever compared?? by Ninja Programmer (Score:1) Thursday January 27 2000, @08:14PM
  • Java is still slower by Xeger (Score:1) Thursday January 27 2000, @08:56PM
  • Re:Genuine Question: have you ever compared?? by Xeger (Score:1) Thursday January 27 2000, @09:01PM
  • Re:Hey everybody...Listen Up by Xeger (Score:1) Thursday January 27 2000, @09:12PM
  • A little bit o' proof by cstaylor (Score:1) Thursday January 27 2000, @01:20PM
  • Tailored Optimizations for asm conv. by LordOfYourPants (Score:1) Thursday January 27 2000, @09:24PM
  • Oops... stupid HTML by cstaylor (Score:1) Thursday January 27 2000, @01:22PM
  • Re:Evolve code. (Score:3)

    by Anonymous Coward on Thursday January 27 2000, @04:44AM (#1331016)
    For deeply pipelined, agressively superscalar architectures, I fail to believe that a human being could possibly solve the difficult scheduling and graph-theoretical problems that optimal instruction ordering requires better than a mechanistic compiler. Current architectures are simply too complex and subtle for a project of non-trivial size to be more efficiently coded by humans at such a low level.

    Nevermind of course, that for real prejects, the trade off in maintainability, portability, and extensibility is almost not worth any demonstrable performance gain anyway.

  • when ? by serialk (Score:1) Thursday January 27 2000, @09:25PM
  • Comparing JIT Misses The Main Point ! by FrankW (Score:2) Thursday January 27 2000, @09:35AM
  • Speed vs. Convenience by The Wookie (Score:1) Thursday January 27 2000, @04:45AM
  • Re:Hey everybody...Listen Up by spacewalrus (Score:1) Thursday January 27 2000, @09:26PM
  • by BinxBolling (121740) on Thursday January 27 2000, @09:36AM (#1331022)
    You need to understand the code fragment you are coding to do the must useful optimizations which are algorithmic ones. A badly coded better variant of an algorithm will beat well coded, but inherenetly slower version.

    Absolutely. But one need not be programming in assembly to do the sort of algorithmic optimizations you speak of. In fact, in higher-level languages, where source code content is determined largely by the algorithm being implemented (rather than by the low-level details of the implementation, as in assembly language), you have a better chance of 'seeing' and successfully implementing a faster algorithm. This sort of thing is one of the big reasons why assembler loses in the long run.

    It seems to me that there are two basic types of optimization task:

    • Choosing the fastest algorithm for a particular task.
    • Making a given algorithm run as fast as possible on a given piece of hardware.

    Of course, this is a bit of an oversimplification, since it assumes that the fastest algorithm for a given task is going to be the same on all platforms. Usually, this is true, but probably there are a few minor cases where it isn't. But it works most of the time.

    At any rate, humans are much better than machines at the first type of optimization. But machines are much better than humans at the second (even if only because normal humans don't have the patience required to do the enormous amount of repetitive analysis that it requires).

  • Re:heap and stack by link-error (Score:1) Thursday January 27 2000, @04:45AM
  • about Java (Score:4)

    by jilles (20976) on Thursday January 27 2000, @04:45AM (#1331027) Homepage
    Hi,

    What transmeta does is very similar to SUN's hotspot compiler for java. Like Transmeta's code morphing, hotspot compiles and optimzes bytecode on the fly using profiling data to optimize the parts that are executed most.

    Your question as to why Java is still slower than C++ is answered in a series of javaworld articles (www.javaworld.com): http://www.javaworld.com/javaworld/jw-11-1999/jw-1 1-performance.html and http://www.javaworld.com/javaworld/jw-12-1999/jw-1 2-performance.html and http://www.javaworld.com/javaworld/jw-02-2000/jw-0 2-performance.html

    Basically the problem is that stuff such as memory allocation, garbage collection, synchronization and runtime type checking have a performance price (you get a safer programming environment in return). The articles discusses these performance issues and give some usefull advice to avoid these bottlenecks.
  • Re:Java Byte Code by SamBeckett (Score:1) Thursday January 27 2000, @09:36AM
  • Not so obvious by Morgaine (Score:2) Thursday January 27 2000, @04:47AM
  • Re:Java Byte Code by wskish (Score:1) Thursday January 27 2000, @09:39AM
  • Dumb compilers, dumb languages by blanu (Score:1) Thursday January 27 2000, @09:40AM
  • by dingbat_hp (98241) on Thursday January 27 2000, @04:47AM (#1331037) Homepage

    when the programmer has decided that space is more important than speed.

    That would seem to be one of the issues where manual coding has the edge. I agree with your general point, but I think there's still work to do before auto-generation is perfect.

    Imagine a case where an algorithm could easily optimise either way speed/space - maybe there's a hash table that's going to hold some programmer-controlled depth of the initial search and allowing it to expand would make usage quicker, but eat memory. A human coder would probably know the pattern of usage this routine would get. By knowing the practical number of data items to be encountered, they could optimise the hash size. A compiler can't do this, because the necessary information comes from the overall systemm domain, not just the source code. To allow compilers to compete effectively, we'll need much more subtle optimisation hinting than we currently have; especially that of the form "ignore this block, it's only used once" and "speed like crazy here, and you'll never have more than 5 items loaded simultaneously".

    I'm not a compiler / assembler geek, so maybe someone is already doing this ?

  • Re:Compilers dont write better code than humans by interiot (Score:1) Thursday January 27 2000, @01:44PM
  • Re:Java Byte Code (Score:3)

    by jilles (20976) on Thursday January 27 2000, @04:49AM (#1331040) Homepage
    Java bytecode interpretation is not the main cause for java's weak performance. The cause lies in mechanisms like garbage collection, memory allocation, thread synchronization etc. which are expensive. If you'd implement similar mechanisms (i.e. with all the built in safety) in C++ you'd have exactly the same problems (I don't think that's actually feasible though).
  • No. Hand coded assembler is faster. by FutileRedemption (Score:1) Thursday January 27 2000, @04:49AM
  • Re:Why not? by ASM (Score:1) Thursday January 27 2000, @01:44PM
  • its free that does the work. by BeauNiddle (Score:1) Thursday January 27 2000, @04:52AM
  • Re:Isn't this REALLY the smarter compiler arguemen by stevew (Score:2) Thursday January 27 2000, @09:48AM
  • False figures by joss (Score:2) Thursday January 27 2000, @11:43PM
  • Re:provide some examples then... by Vidar Hokstad (Score:1) Friday January 28 2000, @12:10AM
  • Re:Not so obvious by nhowie (Score:1) Friday January 28 2000, @12:29AM
  • Re:Transmeta Speed by mgiammarco (Score:1) Friday January 28 2000, @02:50AM
  • within X% of the performance of native code by The Pim (Score:1) Thursday January 27 2000, @04:54AM
  • Real world?!?!? by marcus (Score:2) Thursday January 27 2000, @01:59PM
  • I'll open with a pair of twos... by Steve_Dallas (Score:1) Thursday January 27 2000, @04:55AM
  • you have no idea what you are talking about by spacewalrus (Score:1) Thursday January 27 2000, @02:03PM
  • Re:Compilers dont write better code than humans by Zagadka (Score:1) Thursday January 27 2000, @09:51AM
  • Re: Just wondering by guardian-ct (Score:1) Thursday January 27 2000, @09:52AM
  • Re:Self-Modifying Code by Tune (Score:1) Friday January 28 2000, @03:52AM
  • Re:Java Byte Code (Score:5)

    by arivanov (12034) on Thursday January 27 2000, @04:56AM (#1331064) Homepage
    No it will not.

    Think of Java licencing and control issues. Discussed widely on slashdot. Actually I shall retract this statement if one of the MAJOR league players will accept Crusoe as a primary CPU for at least one machine class.

    Otherwise it is obvious that it could be thy Java machine, but it is least likely to be.

    I think Cruose will actually make a reality something else which is much cooler than Java. It will make real thy developer's dream - the coat of many colors: The affordable machine of many architectures.

    On the basis of Crusoe even now you can build a machine that can happily emulate:

    Mac, Sun (lower end), IBM PPC (lower end), SGI (lower end), Alpha and curse it x86.

    1. All these are PCI based.

    2. The differences in chipsets can be ignored under the "one OS to rule them all, one os to find them, one os to bring them all and in (oh well cutting out darkness) bind them ". It can have drivers for the chipset and peripherals in question.

    3. You may actually do the reverse thing and develop drivers for the peripherals and the chipset for all platforms in question (not a hell of an effort, actually quite achievable). If peripherals are something like adaptec, tulip and a PCI VGA the drivers are basically there already. So you have only the chipset left. Actually you can intercept these and emulate chipset behaviour if you so desire.

    Overall - the developer's dream can become a reality for just a few bucks - about the price of a PC (excluding licencing for OSes and sowftare of course ;-)
  • Re:Compilers dont write better code than humans by dingbat_hp (Score:2) Thursday January 27 2000, @04:56AM
  • The Final Word (Score:3)

    by spacewalrus (145025) on Thursday January 27 2000, @02:15PM (#1331070)
    This whole question boils down to whether or not a human mind is deterministic. We can prove that a
    compiler is, or in fact that any program that runs on current computer hardware is.

    If a human mind is deterministic then it follows that a human could do just as good as a compiler simply by using all of the same algorithms to generate the code, although the computer would certainly finish alot sooner.

    If a human mind is NOT deterministic then it is clear that a person who had no programming skill whatsoever could beat the best compiler given enough time, a specification sheet of the language he was to generate the given algorithims in and a circit diagram of the cpu he/she was coding for.

    This is VERY simple to see. A compiler can NEVER
    under any conditions for any reason EVER EVER EVER produce better code than a human because the
    human can ALWAYS produce the same code that the compiler did. The question should be is it reasonable to wait the 150 years of time it would take me to compile mozzila by hand or should I build a compiler to do it in a few hours. The next question would be how much time(if any) should I spend hand optimizing the compiler output.

    A question I have is why cant we do the same thing that a JIT compiler does before runtime? It seems
    clear that you could easily get very close to as much optimization from a multi pass profiling compiler as you ever could with a JIT without the runtime overhead.

    Later
    Spacewalrus
  • Re:Compilers dont write better code than humans by tjansen (Score:1) Friday January 28 2000, @04:26AM
  • Re:No. Hand coded assembler is faster. by mikera (Score:2) Thursday January 27 2000, @09:59AM
  • Re:Evolve code. by Bryan Andersen (Score:2) Thursday January 27 2000, @04:57AM
  • C/C++ don't check bounds by Jecel Assumpcao Jr (Score:1) Thursday January 27 2000, @10:01AM
  • by Dominic_Mazzoni (125164) on Thursday January 27 2000, @04:57AM (#1331077) Homepage
    I completely agree that humans can always write better assembly than compilers can generate, but it's getting harder.

    Not all that long ago, compilers weren't all that smart, and processors were a lot simpler. Today processors use tricks like out-of-order execution and branch prediction, making it extremely difficult for an assembly-language programmer to determine exactly what is going on. It still remains the case, though, that the programmer may know something about the code that the processor doesn't (that a register will never contain a certain value, or that some execution paths are much more likely or more critical than others) which will give the programmer the edge.

    None of the just-in-time compilers that I am aware of recompile code as they go. If the Crusoe actually attempts to optimize sections of the code based on runtime profiling information, this could be the main reason it performs so well. There have been academic papers written on this idea before but this would be the first implementation I've heard of.
  • Re:Java Byte Code by thraxil (Score:1) Thursday January 27 2000, @02:33PM
  • extra processor? by RoLlEr_CoAsTeR (Score:1) Thursday January 27 2000, @04:58AM
  • Re:Evolve code. by norton_I (Score:1) Thursday January 27 2000, @02:44PM
  • Re:Not so obvious by stevew (Score:2) Thursday January 27 2000, @10:02AM
  • by hoss10 (108367) on Thursday January 27 2000, @04:58AM (#1331082)
    I was about to try and answer your question but it's bloody difficult to explain!
    With garbage collection implemented in the best way the JIT or whatever doesn't try to hard to keep a record of what mem has been allocated.
    But, whenever the system isn't paricularly busy or if it panics due to low memory the JIT can traverse all the objects that have been allocated (just starting with each of the Thread objects I think) just by checking the references each object has until it has a list of all the objects in the system. There are a few reasons this is more reliable (not just faster) than maintaining a reference count.
    Then I suppose it (the JIT) could ask the OS to rearrange it's memory mapping thingies (Page Translation whatchamacallems) to put any of it's user space pages after the current position of the stack or something like that (hard to describe but i know what i'm talking about (even though i can't remember the name exactly!))

    Basically it can be made to work but maybe not particular efficiently because it could result in a full page (4K) been used for just one small object but this can also be fixed
  • by stevew (4845) on Thursday January 27 2000, @04:59AM (#1331083) Journal
    Years ago I worked at a company that was going to bring VLIW to the commercial world. One of the things they had to invent was MUCH smarter compiler technology. That was in 1985, so the basic ideas involved here are at least that old.

    Anyway, when the compiler DOES know the hardware, especially VLIW machines, they can indeed do a job as GOOD as a human. (Look - they won't usually do better jobs, when the guys who designed the machine write code, they're going to do what the compiler is trying to emulate..) But from what I remember, static profiling was considered "good enough" back then if the VLIW machine is built right.

    Most codes spend most of their time in inner most loops. If those loops can be rolled up correctly for VLIW you can be executing different interations of the loop within the same instruction slot. Being able to do this is usually the largest performance payoff. If you have a GOOD compiler in the first place, that KNOWS the hardware, then JIT and morphing aren't needed, or help.

    The place that I see the morphing being a step forward is that VLIW machines were considered architectural dead-ends until just now. If I use one of these smart compilers for a machine with say 7 functional units, the code that emitted won't work on a machine with 8 functional units, or at least not be optimized any longer. These machines didn't scale well until now! Code-morphing technology completely removes this limitation!
  • Re:What about the JIT? -Server versions by borzwazie (Score:1) Thursday January 27 2000, @10:06AM
  • Re:within X% of the performance of native code by John Allsup (Score:1) Friday January 28 2000, @04:30AM
  • "Intimate knowledge of the target processor" by Tuck (Score:1) Friday January 28 2000, @04:35AM
  • Re:Ooo, ooo, start on packing! by John Allsup (Score:1) Friday January 28 2000, @04:49AM
  • Re:Evolve code. by John Allsup (Score:1) Friday January 28 2000, @05:14AM
  • Re:Java Byte Code by pnkfelix (Score:1) Thursday January 27 2000, @02:46PM
  • Re:Match code frag. as opt. tech. (Was:Evolve code by John Allsup (Score:1) Friday January 28 2000, @05:34AM
  • Re:Evolve code. by ehack (Score:1) Thursday January 27 2000, @02:54PM
  • Re:just plain wrong (me this time) by Scott Wood (Score:1) Friday January 28 2000, @06:10AM
  • ...and auto-profiling doesn't work by milliyear (Score:1) Thursday January 27 2000, @05:01AM
  • Re:Compilers dont write better code than humans by Sir Banana (Score:1) Friday January 28 2000, @06:43AM
  • Re:Self-Modifying Code by ZoeSch (Score:1) Friday January 28 2000, @08:12AM
  • Re:What about the JIT? by um... Lucas (Score:1) Thursday January 27 2000, @10:27AM
  • Re:OT: computers at blitz by Daniel (Score:2) Thursday January 27 2000, @03:10PM
  • The C failure with "int" by FutileRedemption (Score:1) Thursday January 27 2000, @05:01AM
  • a point about malloc/free vs. garbage collection by TheDullBlade (Score:2) Thursday January 27 2000, @05:02AM
  • Re:What about the JIT? by erikn (Score:1) Thursday January 27 2000, @03:38PM
  • Re:Compilers dont write better code than humans by jkain (Score:1) Thursday January 27 2000, @10:27AM
  • Considerable problems by Anonymous Coward (Score:2) Thursday January 27 2000, @05:02AM
  • Re:Evolve code. by JWRose (Score:1) Thursday January 27 2000, @10:29AM
  • Re:Evolve code. by Alex Belits (Score:2) Thursday January 27 2000, @03:38PM
  • java/jit speed vs asm by TummyX (Score:2) Thursday January 27 2000, @05:03AM
  • Re:just plain wrong (me this time) by TheDullBlade (Score:2) Friday January 28 2000, @09:55AM
  • Transmeta Speed by mohaine (Score:2) Thursday January 27 2000, @05:03AM
  • FPGAs and overall program objective by ^me^ (Score:1) Thursday January 27 2000, @03:50PM
  • Re:Q: Performance of C++ STL vs Java JGL ? by FutileRedemption (Score:1) Thursday January 27 2000, @03:50PM
  • Re:Compilers dont write better code than humans by Quaternion (Score:1) Thursday January 27 2000, @05:03AM
  • Re:Compilers DO write better code than humans by FreshView (Score:1) Thursday January 27 2000, @10:34AM
  • Clueless Ranting by signine (Score:1) Thursday January 27 2000, @05:03AM
  • Re:exactly by Kukester (Score:1) Thursday January 27 2000, @03:55PM
  • Re:Java Byte Code by moopster (Score:1) Thursday January 27 2000, @10:37AM
  • Re:NP problems by AndrewHowe (Score:1) Thursday January 27 2000, @10:42AM
  • JIT are compilers by gmarceau (Score:2) Thursday January 27 2000, @05:04AM
  • Why not? by MikeFM (Score:1) Thursday January 27 2000, @10:43AM
  • GCs can improve performance by josu (Score:1) Thursday January 27 2000, @10:46AM
  • Re:Compilers dont write better code than humans by killmeplease (Score:1) Friday January 28 2000, @11:00AM
  • Re:False figures by lgas (Score:1) Friday January 28 2000, @11:04AM
  • Re:Compilers dont write better code than humans by Junks Jerzey (Score:2) Friday January 28 2000, @11:05AM
  • Re:Profoundly counterintuitive? by Kvort (Score:1) Friday January 28 2000, @01:26PM
  • Re:Java not a useable language? by ^me^ (Score:1) Thursday January 27 2000, @03:56PM
  • Don't take it personally man (nt) by Andrew Cady (Score:1) Thursday January 27 2000, @03:56PM
  • Re:just plain wrong (me this time) by Scott Wood (Score:1) Friday January 28 2000, @02:44PM
  • Re:Self-Modifying Code by Some Strange Guy (Score:1) Friday January 28 2000, @03:34PM
  • by joe_fish (6037) on Thursday January 27 2000, @05:05AM (#1331135) Homepage Journal
    The theory looks sound, but one of the biggest things to do when optimizing any Java program is to minimize the calls to new().
    I recently sped a program up by 150% in a snap simply by killing a few new()s. Swing and LotusXSL have had similar experiences.

    I think that part of the problem is that all of this is new, so there is more to do. HotSpot the trendy JIT from Sun in places IS ALREADY FASTER THAN C, but whenever it comes to Object creation, things slow down a lot.

    So why in theory should new() be quick when in fact it is slow? IMHO the problem is not with the memory claiming, its with all the other stuff that the JVM has to do.

    When I call new Foo() the JVM:

    • Checks to see if the bytecode for Foo already exists, and if not it loads it, verifies it, and calls the class init method.
      This is very very slow, but should only be done once.
    • Allocs new memory. Probably very quick
    • Calls the hierachy of constructors of all Foos superclasses. Quite slow.
    • (For advanced garbage collectors) Place the object on the 'recent items' list. Probably quick
    So I guess the complexity of the system as a whole is the problem here.
  • Re:just plain wrong by Scott Wood (Score:1) Thursday January 27 2000, @03:59PM
  • Sounds good, but... by randolph (Score:2) Thursday January 27 2000, @04:01PM
  • JIT execution time adds up to program exec. time. by Otis_INF (Score:1) Thursday January 27 2000, @05:06AM
  • Re:just plain wrong (me this time) by TheDullBlade (Score:2) Friday January 28 2000, @04:29PM
  • Re:Compiled Once vs. Compiled multiple times by buckaroo-b (Score:1) Thursday January 27 2000, @05:07AM
  • Stupid slashdot by Scott Wood (Score:1) Thursday January 27 2000, @04:03PM
  • dammit by TheDullBlade (Score:1) Friday January 28 2000, @04:31PM
  • Java VM is a Stack Machine by happybob (Score:1) Thursday January 27 2000, @04:11PM
  • The C feature with "int" by TheDullBlade (Score:2) Thursday January 27 2000, @05:08AM
  • Re:Compiled Once vs. Compiled multiple times by John Allsup (Score:1) Thursday January 27 2000, @05:08AM
  • G.N.U. Grope.... by Jonathan Hamilton (Score:1) Thursday January 27 2000, @04:16PM
  • by Tune (17738) on Thursday January 27 2000, @05:10AM (#1331148)
    I believe Andy has a good point in arguing that there's no fundamental reason for manually written assembly being better than automatically self-optimizing stuff. I also believe that manually written assembly will ultimately become obsolete.

    Nevertheless I'd like to point out that JIT is based a somewhat dangerous technique: a program that alters (its own) code. I believe this technique was used in the eighties to scare off hackers by making code incomprehensible and hard to disassemble until the program was actually running. Also (even on a good old 6502 processor) it's possible to make some speed improvents peeking and poking into the code you're actually executing.

    When compilers for Microcomputers got faster and most processor architectures (known as Harvard architecture, I believe) explicitly require a division of RW and RO memory segments, self-modifying code was abandoned. Hacking into your own code is generally conceived as bad-programming-practice.

    I was wondering wheter JIT techniques also require very intelligent (and thus "heavy") disassemblers? One might also expect that developing a JIT compiler is a lot harder than doing a conventional one (without peep-hole optimization). Does anyone have experience in these subjects?
  • Re:Compiled Once vs. Compiled multiple times by MikeBabcock (Score:2) Friday January 28 2000, @06:18PM
  • Re:Compiler will be faster than JIT by John Allsup (Score:1) Thursday January 27 2000, @05:11AM
  • Just wondering by square (Score:1) Thursday January 27 2000, @05:14AM
  • You need to be sure that the values in the registers are below 65536 or 256 to use these tricks, and the programmer can know this, but the compiler cant.
    Isn't this why we have short int, long int, and char data types - so we can tell the compiler these things?
  • Report interviewed by Overseas Europe by bbeurope (Score:1) Saturday January 29 2000, @12:47PM
  • Re:Why not? by ASM (Score:1) Saturday January 29 2000, @07:50PM
  • Re:What about the JIT? by bab5freak (Score:1) Thursday January 27 2000, @04:35PM
  • Re:just plain wrong (me this time) by Scott Wood (Score:1) Saturday January 29 2000, @08:09PM
  • Re:Evolve code. by benedict (Score:1) Sunday January 30 2000, @10:07AM
  • Re:Compilers dont write better code than humans by kulturkritik (Score:1) Thursday January 27 2000, @04:42PM
  • NNNG! "that the allocator" . " would do" by TheDullBlade (Score:2) Thursday January 27 2000, @05:14AM
  • Languages that accept "hinting" by jekk (Score:1) Tuesday February 01 2000, @10:09AM
  • Re:This is so true, but it's getting harder by Anonynous Coward (Score:1) Thursday January 27 2000, @04:48PM
  • Cause or effect? by DragonHawk (Score:2) Thursday January 27 2000, @04:49PM
  • Re:Compiler will be faster than JIT by John Allsup (Score:1) Thursday January 27 2000, @05:14AM
  • Re:Compilers dont write better code than humans by kulturkritik (Score:1) Thursday January 27 2000, @05:00PM
  • Re:Why JIT is slow by John Allsup (Score:1) Thursday January 27 2000, @05:15AM
  • Re:provide some examples then... by BurdMan (Score:1) Wednesday February 09 2000, @10:07AM
  • Re:The C feature with "int" by AndrewHowe (Score:1) Thursday January 27 2000, @05:15AM
  • Re:Evolve code. by benedict (Score:1) Thursday January 27 2000, @05:00PM
  • Re:Evolve code. (Score:3)

    by Anonymous Coward on Thursday January 27 2000, @05:15AM (#1331175)
    Now, if they were to force-evolve code using a genetic algorithm, you might get code better than any a human code write

    Of course, you'd have to put up with the fact that this would not be executable in Kansas.
  • I think Linux does this by DragonHawk (Score:2) Thursday January 27 2000, @05:04PM
  • Re:Compilers dont write better code than humans by bogado (Score:1) Thursday January 27 2000, @05:15AM
  • It's all in the implementation by Steeltoe (Score:1) Thursday January 27 2000, @05:16AM
  • Re: Profoundly counterintuitive? by mch (Score:1) Thursday January 27 2000, @05:16AM
  • Re:Compiler will be faster than JIT by Anonymous Coward (Score:1) Thursday January 27 2000, @05:16AM
  • Re:Evolve code. by benedict (Score:1) Thursday January 27 2000, @05:20PM
  • Re:Evolve code. by benedict (Score:1) Thursday January 27 2000, @05:29PM
  • Re:heap and stack by ucblockhead (Score:1) Thursday January 27 2000, @05:35PM
  • Re:Transmeta Speed by Skratch (Score:1) Thursday January 27 2000, @05:17AM
  • A Transmeta Java Chip is pointless by FutileRedemption (Score:1) Thursday January 27 2000, @05:17AM
  • Re:Compilers dont write better code than humans by nester (Score:1) Thursday January 27 2000, @05:56PM
  • Re:Experience from Optimizing Java ... by ucblockhead (Score:2) Thursday January 27 2000, @05:57PM
  • Bless you! (Score:3)

    by aheitner (3273) on Thursday January 27 2000, @05:20AM (#1331195)
    @#$% theory.

    I can write fast C (or C++ if you stay away from the evil slow features) code.

    Everything I do in Java is bloody slow.

    I do believe fundamentally that some sort of per-machine compilation is in fact ideal -- the C compiler could do clever stuff if it new the exact cache architecture of your machine and compiled your programs from some intermediate (say parsed and desymbolized) representation when you ran them (or maybe just the 1st time you ran them).

    (all the slackware people in the crowd say "bwaahahahaha! I did compile my programs for my own machine!" :-)

    But I think the dumbness of Java -- the funky GC, the dumb dumb dumb RTTI, will always make it slow. For that matter, Java uses a dumb fake-o instruction set that's not a particularly good representation of the information needed by a compiler. Why not give your JITC something closer to the source rather than a binary for a machine that doesn't even exist ?!?

    ...

    Ditzel said something very significant when he introduced Crusoe: (i'm paraphrasing) "The reason we haven't talked openly about this before is we didn't want to boast before we could prove we've done it". Ditzel stood there and said "We've got a chip that does on-chip JIT architecture translation, and does it to run as fast as any other chip out there, and here's the proof".

    The Java people have been claiming for a long time that they could write faster code than the C compiler with JITC.

    Java has gotten better than when it started, it's true.

    But it still can't hold a candle to gcc -O2.

    My message to the Java world: I spend too much on my computers to waste time running slow code. Call me back when you can actually demonstrate your claims.
  • Limitations of compilers/translators by stevelinton (Score:1) Thursday January 27 2000, @05:20AM
  • Re:you have no idea what you are talking about by GnrcMan (Score:1) Thursday January 27 2000, @05:58PM
  • Re:JIT are compilers by scheme (Score:2) Thursday January 27 2000, @05:36AM
  • Re:heap and stack by scruffy (Score:1) Thursday January 27 2000, @05:21AM
  • MIT compilers do bitwidth analysis. by cananian (Score:1) Thursday January 27 2000, @06:02PM
  • Only when you can rewrite the whole thing by p3d0 (Score:1) Thursday January 27 2000, @05:36AM
  • Re:What about the JIT? by nester (Score:1) Thursday January 27 2000, @06:03PM
  • Re:Evolve code. by AndrewHowe (Score:1) Thursday January 27 2000, @05:21AM
  • Re:Speed vs. Convenience by arivanov (Score:2) Thursday January 27 2000, @05:21AM
  • No, that's not it... by p3d0 (Score:1) Thursday January 27 2000, @05:37AM
  • One thing is missing from the discussion. by anatoli (Score:1) Thursday January 27 2000, @05:38AM
  • re-compile the compiler by milliyear (Score:1) Thursday January 27 2000, @05:21AM
  • Does not add up by Tune (Score:1) Thursday January 27 2000, @05:39AM
  • Doesn´t work in practice by FutileRedemption (Score:1) Thursday January 27 2000, @05:39AM
  • by AndrewHowe (60826) on Thursday January 27 2000, @05:40AM (#1331212) Homepage
    In some ways I agree with you, OK, I love writing assembler stuff.
    But I'm trying to separate fantasy from the reality here.
    The fantasy is that you're some super studly asm c0der who can not only produce properly scheduled code, but also has the time to *completely re-write* it:
    a) For each new processor
    b) For each sub-type of that processor with different internal resources
    c) Every time the specification changes - Maybe you have limited the range of a variable or something.
    Any of these changes will require a huge amount of work. Even a small change, coupled with the pipelined nature of modern processors, means a large modification to re-establish optimal resource usage.
    The reality is that no-one has the time to do this, and even if they do, they should be doing something else instead. High level optimizations almost always beat low level tweaking.
    In addition, I simply don't believe it's impossible to
    a) Tell the compiler in more detail how to optimise your code
    b) Have the compiler suggest ways in which it could produce better code (for example, "Is it OK to assume there is no aliasing of this item?" or "Hey, if I make this variable 8 bits in size I can do this huge optimization")
    c) Have the compiler work this stuff out for itself
    d) As (c) but at run time, guided by profiling information.
    Some of those are hard to do right now, but I don't see anything that would make them impossible.
    Does anyone?
  • Re:heap and stack by ucblockhead (Score:2) Thursday January 27 2000, @05:41AM
  • Re:Isn't this REALLY the smarter compiler arguemen by MikeBabcock (Score:2) Thursday January 27 2000, @05:21AM
  • Sounds like Lagoona, only less sophisticated. by treyb (Score:1) Thursday January 27 2000, @05:22AM
  • compiler smarter than humans? by rmstar (Score:1) Thursday January 27 2000, @05:22AM
  • Re:within X% of the performance of native code by MikeBabcock (Score:2) Thursday January 27 2000, @05:23AM
  • Java specifics by Tal Cohen (Score:2) Thursday January 27 2000, @05:24AM
  • Re:...and auto-profiling doesn't work by AndrewHowe (Score:1) Thursday January 27 2000, @05:26AM
  • Re:Evolve code. by slashdot-terminal (Score:2) Thursday January 27 2000, @05:46AM
  • by monac (83505) on Thursday January 27 2000, @05:26AM (#1331225)
    As shown at http://www.idiom.com/~zilla/Computer/javaCbenchmar k.html, even the linux jdk, which is relatively slow than other platform's, runs as fast as natively compiled C program when runs simple operations.

    In my understanding, java's poor performance is due to following factors:

    1. too generized api design resulted in very deep call stack. for example, printing current date and time using java.text.DateFormat uses much more calls than traditional C (a system call and a printf is enough for C). It gets more terrible in swing. use of interfaces causes the same problem i think.

    2. JNI is too slow. (can't understand why but it is known to be slow and java can't help but using many JNIs)

    3. as WORA is important in java, it is hard for java to use any platform specific resources such as Graphic card's accelerations. that is one of the reasons swing's design is getting ugly as it tries to boost its performance.

    4. too many small class files result in high I/O usage when JVM loads classes.

    5. no MACRO! for example, most of java API is synchronized, which is expensive, reguardless thread is used or not. the same for security check codes and platform specific implementation codes,
    etc. these problems can be solved by MACRO but...
    someone in sun doesn't like macro and i agree with him when think of java's purity.

    some of these problems are known to be solved in next jdk version(hotspot client version). slow synchronizations and class loading speed, etc.
    but mostly, they are java's design issue and never be solved, as java is mostly running in virtual machine and originally it is designed to be used for java chips, only when JVM is implemented in processor level, the speed problem will be solved.

    I'm looking forward to seeing java running in MAJC or Transmeta's chips.

    please correct me if i'm wrong in some and forgive me for my poor english.
    Cheers.
  • Re:Profoundly counterintuitive? by rmstar (Score:1) Thursday January 27 2000, @05:47AM
  • What about chaching? by Tune (Score:1) Thursday January 27 2000, @05:29AM
  • Ooo, ooo, start on packing! by TheDullBlade (Score:2) Thursday January 27 2000, @05:47AM
  • Re:Compiled Once vs. Compiled multiple times by ucblockhead (Score:2) Thursday January 27 2000, @05:50AM
  • Theory and practise by Anonymous Coward (Score:1) Thursday January 27 2000, @05:51AM
  • The "C is not portable" myth by Björn Stenberg (Score:2) Thursday January 27 2000, @05:51AM
  • Its the libraries stupid by joss (Score:2) Thursday January 27 2000, @05:52AM
  • Re:Java Byte Code by -brazil- (Score:1) Thursday January 27 2000, @05:54AM
  • Re:Experience from Optimizing Java ... by Otis_INF (Score:1) Thursday January 27 2000, @05:29AM
  • Re:The C feature with "int" by ucblockhead (Score:2) Thursday January 27 2000, @05:29AM
  • that's what longs are for by TheDullBlade (Score:2) Thursday January 27 2000, @05:29AM
  • Crusoe == Hotspot by anonymous loser (Score:1) Thursday January 27 2000, @05:30AM
  • Re:Profoundly counterintuitive? by MikeBabcock (Score:2) Thursday January 27 2000, @05:30AM
  • by BurdMan (29934) on Thursday January 27 2000, @05:31AM (#1331240) Homepage
    Firstly, water does sink into rocks. It then freezes and the pressure it exerts reshapes the world as we know it. But that is beside the point.

    I will address your comments with respect to the Java Programming Language and its HotSpot compiler technology. If you would like to enlighten yourself on the techniques behind HotSpot take a look at http://self.sunlabs.com [sunlabs.com]. Transmeta, IMHO, was influenced by the same concepts when designing its code morphing techniques.

    1. "A JIT is rushed" - The first time bytecode is compiled to native code it must be done quickly to avoid delay. That code may be inefficient, true, but it can also be instrumented with profiler like information that can be used by later passes of the compiler. You see, what the author is describing is not a JIT system but a dynamic optimizing compiler which has the opportunity to study the program during execution and recompile parts or all of that program based on that information.
    2. "no leeway for boundary conditions" - Well here again you seem a bit confused and your example is naive. The native representation of a type is not fixed in Java, only the conceptual representation. To be a compliant Java implementation all results generated using 'int' (to use your example) must be consistent with the conceptual representation of 'int' when using the various operations. If the optimizing compiler finds a way to represent an 'int' in a more optimal way it is free to do so as long as the results of the operation don't change.
    3. "garbage collection is slower than hand coded memory management" - You really ought to read some of the latest garbage collection papers. This is no longer true even for collectors managing C or C++ allocation. When given an environment like Java which doesn't allow pointers and other antiquated memory techniques a good dynamic compiler with a modern garbage collector is both faster and more efficient than any hand coded attempt on all but the most simple of applications.
    4. "OOP and dynamic dispatch are inefficient" - Again, I urge you to read the papers at the Self site listed above. The way the Self, and now HotSpot, compilers work eliminates this bottle neck. I'll admit in early implementations of Smalltalk and Objective-C dynamic dispatch did add a small amount of overhead. Take a look at the documents on the HotSpot here [sun.com] and then tell me that dynamic dispatch is a problem.


    In summary, you are more than welcome to use assembly all you want. Code on my brother! But, please before you slam some other method try doing the smallest amount of research first. Maybe your snap intuition is wrong. You never know.

    As far as Transmeta goes, it has a lot of the HotSpot/Self style technology and I personally think that technology is the future. I can't wait to get my hands on a Crusoe powered product.

    -BurdMan
  • Re:a point about malloc/free vs. garbage collectio by ucblockhead (Score:2) Thursday January 27 2000, @05:55AM
  • It's just like Deep Blue vs. Kasparov again. Brute force compilers vs. intuitive & creative humans. In some cases, humans can write better assembly than compilers (thanks to knowing more about what the program is intended to do), and in others the compilers have the advantage (thanks to being better at scheduling instructions on today's pipelined, superscalar CPUs). JIT compilers could have even more knowledge about instruction timing, but have less time to think about it. Kinda like Deep Blue playing blitz chess. I'd say in most cases these days, a compiler could write faster code from scratch than a human could, unless the human really spends some time on it, but the optimal combination will always be a human assisted by a compiler (and profiler, etc). Best of both worlds. Namarrgon
  • Where did this article get its name? by p3d0 (Score:1) Thursday January 27 2000, @05:31AM
  • Re:Evolve code. by slashdot-terminal (Score:2) Thursday January 27 2000, @05:55AM
  • Q: Performance of C++ STL vs Java JGL ? by FutileRedemption (Score:1) Thursday January 27 2000, @05:32AM
  • Re:Not so obvious by nhowie (Score:1) Thursday January 27 2000, @05:55AM
  • Re:Compiled Once vs. Compiled multiple times by MikeBabcock (Score:2) Thursday January 27 2000, @05:32AM
  • Re:Java specifics by mch (Score:1) Thursday January 27 2000, @05:55AM
  • Re:JIT are compilers by seeken (Score:1) Thursday January 27 2000, @05:55AM
  • Re:Crusoe == Hotspot by Obsequious (Score:1) Thursday January 27 2000, @05:56AM
  • Compilers DO write better code than humans by Kvort (Score:1) Thursday January 27 2000, @05:57AM
  • by GnrcMan (53534) on Thursday January 27 2000, @05:57AM (#1331253) Homepage
    That may be true of a crappy compiler on a lame platform (x86)...but I'd like to see you try reordering and slot scheduling Alpha instructions by hand to enable optimal pipelining and branch prediction.
    As someone who worked firsthand on a compiler for the Alpha, I can tell you that for 99% of the cases, the compiler can perform better general optimizations than a human. That 1% left over is what you should be concentrating your efforts on.
    Historically, the point of a CISC processor was to reduce compiler complexity. So of course hand coding optimal X86 assembly isn't going to be difficult.

    --GnrcMan--
  • Re:Java Byte Code by flux (Score:1) Thursday January 27 2000, @07:09AM
  • Re:JIT are compilers by gmarceau (Score:1) Thursday January 27 2000, @07:12AM
  • C is not for pansies by TheDullBlade (Score:2) Thursday January 27 2000, @05:59AM
  • Re:Compilers dont write better code than humans by ddunn (Score:1) Thursday January 27 2000, @07:16AM
  • GC by joss (Score:2) Thursday January 27 2000, @07:21AM
  • by locust (6639) on Thursday January 27 2000, @06:01AM (#1331265)
    I have already heard that assumption that a compiler can generate better code than a programmer a thousand of times, but it does not get more true by repeating it - it is false.

    The metric that I given in my university computer architecture class was that a compiler can generate better code than 90% of assembly programmers. Which, when I examine higher level code written by a variety of programmers, some good, some bad, makes sense. Some people know all the details of a language and some don't. Some pay attention and some don't. I'm pretty sure it was backed up by a reference to an IEEE paper somewhere.

    If large numbers humans could reliably write large volumes of high quality, optimized code, at high speed, we'd still be using assembly everywhere. But they can't. I certainly don't have the time or the inclination to learn all the ins and outs of every instruction set architecture I operate on to squeze every last bit of juice out of the machine. And I certainly am unwilling to give up the expresiveness of a highlevel compiled language.

    But ultimately, the fraction of people that need to write things like texture mapping loops is very small, and the fact of the matter is that the loop is probably embeded in some higher level piece of code. So relax, compilers reliably produce better code than the majority of assembly programmers (maybe not on /.). Or more precisely, better machine code, than the majority of programmers, if they were asked to write assembly. --locust

  • Re:Java Byte Code by slashdot-terminal (Score:2) Thursday January 27 2000, @06:02AM
  • Re:Compilers dont write better code than humans by interiot (Score:1) Thursday January 27 2000, @07:22AM
  • Re:Evolve code. by AndrewHowe (Score:1) Thursday January 27 2000, @06:02AM
  • Re:Evolve code. by silichrome (Score:2) Thursday January 27 2000, @07:26AM
  • Re:What about the JIT? by Sketch (Score:2) Thursday January 27 2000, @07:29AM
  • Re:This is so true, but it's getting harder by tagish (Score:1) Thursday January 27 2000, @06:02AM
  • Re:Experience from Optimizing Java ... by ucblockhead (Score:2) Thursday January 27 2000, @06:02AM
  • Re:within X% of the performance of native code by spinkham (Score:2) Thursday January 27 2000, @06:04AM
  • 100 replies beneath your current threshold.
(1) | 2 | 3 | 4 | 5