> From: Berin Loritsch [mailto:[EMAIL PROTECTED] 
>
> J�rg Schaible wrote:
> 
> > 
> > Sure? I would suppose, that an object is created and 
> directly handed 
> > over to the GC. Otherwise the Compiler must have knowledge of the 
> > (possibly empty) implementation of any inherited c'tors.
> > 
> 
> All I am saying is that optimizing compilers look at things 
> like initializing variables that will never be used, and then 
> remove them from use.  Very few people have constructors that 
> have side-effects outside of the actual object that they are 
> using.  I would call it a bug if they did.
> 
> All that aside, it would be a legal optimization for the 
> compiler to make to strip out the contents of the loop and 
> merely compile an empty loop.  If the compiler doesn't do it, 
> then the HotSpot VM sure will.

Classic example is a loop that strobes a memory-mapped port
(C++ code below):

    char* port = (char*) 0x1000;
    *port = 0;
    for (int i = 0; i < 10; i++)
    {
        *port = 1;
        *port = 0;
    }

Since the value of *port is unchanged by the whole loop, the
loop can be reduced to:


    char* port = (char*) 0x1000;
    *port = 0;
    for (int i = 0; i < 10; i++)
    {
    }

And then the compiler can remove the loop altogether and
feel really good about how clever it was:

    char* port = (char*) 0x1000;
    *port = 0;

But that wasn't really what the programmer intended.

/LS


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to