I'm not sure which messages you're talking about - is it the one where Combuster failed to unroll a small loop and remove all branches?embryo wrote:We already have examples of the compiler win in the runtime optimization quest. There are a few messages above right about such win.Brendan wrote:For other things (e.g. branch prediction) it's impossible for the compiler to beat the processor because the optimisation can't be done statically and if it is done in software at run-time (e.g. JIT or self modifying code) the overhead of doing the optimisation is greater than the overhead it saves.
Note: Would you mind specifying which compiler you're referring to? When you say "compiler" I assume you mean the compiler that converts Java source code into Java byte-code; but usually you seem to be referring to the JVM instead.
I'll assume you're talking about the "pointer aliasing" problem that was partially fixed in C++ (strict aliasing rules), and then properly fixed in C99 (the "restrict" keyword) and then adopted by most C++ compilers to completely fix their previous partial fix.embryo wrote:It is not exactly such simple. For C/C++ to match Java in case of pointers problem it is required to reject to use pointers. But it means C/C++ will just emulate Java, then why not to use Java directly?Brendan wrote:Of course for almost all cases where Java is faster you can find out why and improve the C/C++ code until the C/C++ version is at least as fast or faster than the Java version
From my point of view, even though the problem is "fixed" in C/C++, it's a symptom of a larger problem with compiler implementations (object files and linking causing difficulty with whole program optimisation); and not necessarily a problem that's part of the languages themselves. Also note that it's definitely not related to "ahead of time" vs. "just in time" - e.g. Fortan never had the problem to begin with even though it also uses an "ahead of time" compiler and doesn't use JIT at all.
Um, we were talking about speed, not safety. For C/C++ the normal malloc/new is stupid and slow (causes cache locality problems that can be avoided with smarter memory allocation). Modern Java does implement the smarter memory allocation, which gives it an advantage over the typical "written by a noob" C/C++ code you'll find in most benchmarks (and find in most C/C++ projects). This isn't a problem caused by C/C++ though (it's relatively easy to write your own special purpose allocators that don't suffer from cache locality problems), it's caused by lazy programmers. Again; it's definitely not related to "ahead of time" vs. "just in time".embryo wrote:With memory allocation it's again the same - to have less bugs C/C++ need to reject manual memory allocation. And there are more items in this list.
For safety, C/C++ were never intended to be safe to begin with; and Java was never intended to be useful for low-level code. Complaining that C/C++ aren't safe is as stupid as complaining that Java won't let you have direct access to any address you like.
I'm not sure what you're trying to say here. You can use (e.g.) GCJ to "ahead of time" compile Java directly to native code and not bother having any JIT; but the performance will probably be even worse than running Java byte-code on a JVM because the language was never designed to do this efficiently (although I'd expect the memory footprint will be better - no big bloated virtual machine involved).embryo wrote:Why I can't use compiler like GCC and get the exact result the C/C++ have? And I can use such compiler at runtime, like JIT. And there will be no significant performance overhead because compiler runs once and the server code then runs for very long time.Brendan wrote:and for most of the cases where C/C++ is faster than Java you can't do anything about it.
Heh. For detecting bugs, it's like trying to determine the winner of a horse race when both horses have broken legs - you end up trying to determine "least worst" when you know both options are bad.embryo wrote:Number of bugs is a very volatile issue, but we can remember causes of most common bugs - manual memory allocation ,pointers, unsafe operations, etc.Brendan wrote:For my goals, Java has ... However, far too many bugs aren't discovered until run-time, it's harder to learn, and none of the overhead is obvious.
If you were a novice bull fighter, you'd probably want to start learning with a "safe" fat cow too.embryo wrote:About learning problem - it just seems non existent - why young people prefer not to learn C but learn Java and other safe languages?
You have no problems with Java because you're not using Java. If you want to disagree, then show me where in the Java documentation I can find the "using assembly language in Java" section.embryo wrote:In jEmbryoS the assembler parts are as easy to implement as the inline assembly in C. Again we have no problems with Java.Brendan wrote:consider writing code to switch the CPU from protected mode to long mode, or code to do a task switch to a thread in a different virtual address space, or code to support hardware virtualisation, or even just code for a boring interrupt handler. Without being able to use assembly you're screwed.
Again; once you stop using Java and start using assembly (to implement your own garbage collectors, etc), the restrictions of Java no longer apply.embryo wrote:With Java OS all 4 things are under control. And the GC is not an issue, because it can be as controllable as you wish. It can run at some predefined points in the program thread or it can run in a separate thread on a dedicated core with it's independent cache. It's just a matter of design, but not a stopper any more.Brendan wrote:When do you start looking at performance there's 4 main things to worry about - memory hierarchy efficiency (e.g. things like knowing which cache lines you touch when), doing stuff in parallel efficiently (both multiple CPUs and SIMD), controlling when things happen (e.g. important work done before unimportant work) and latency. Something like garbage collection is enough to completely destroy all of this.
Cheers,
Brendan