public inbox for java@gcc.gnu.org
 help / color / mirror / Atom feed
* Why does a 'new' statement produce so many temporary variables
       [not found] <CA+kGxtPef8Xojf-+amOehmUsY_5MQreWUPdnODZUoX-tqX1RTg@mail.gmail.com>
@ 2011-08-09  7:18 ` Li junsong
  2011-08-09 16:22   ` Andrew Pinski
  2011-08-15  9:40   ` Andrew Haley
  0 siblings, 2 replies; 3+ messages in thread
From: Li junsong @ 2011-08-09  7:18 UTC (permalink / raw)
  To: java

Hi,

I am writing a plugin to add a pass in gcc 4.6.1. the pass will do
some optimizations before high gimple lowering,
moving some gimple nodes from one place to another. In cc1, the gimple
code is quite
understandable.  But I'm confused by the gimple that Java front end converts to.

I dump the file, here is a piece of code doing "new".

#ref#2#4 = _Jv_AllocObjectNoFinalizer (&Number.class$$);
#ref#3#6 = #ref#2#4;
#ref#2#4 = #ref#3#6;
D.459 = #slot#1#1;
#slot#4#7 = D.459;
#ref#3#6.1 = #ref#3#6;
(#ref#3#6.1, #slot#4#7);

the corresponding Java source code is

        int sum = 4;
        Number number;
        if ( sum < 100 )
            number = new Number(sum);   <=here

the Number class is a simple one:

class Number
{
    int i;
    Number(int inputi){
        i = inputi;
    }
}

Here comes my question:
 1. I am wondering why we don't use 'NEW_EXPR' to represent a "new" statement?
     The 'NEW_EXPR' has already been defined in the cp-tree.def.( As I know, the
     "new" statement in cp front end is also represented as that in
Java front end,
     which is "gimple_call" in gimple code, "ADDR_EXPR" in tree code,
is it? why?)

 2. How can I figure out which pieces of code are corresponding
     to 'NEW' statement? ( Can I always first find the
"_Jv_AllocObjectNoFinalize" or "_Jv_AllocObject"
     gimple_call and then "<init>" gimple_call to locate the code?)

 3. I find that there is no document to describe the implementation of
Java front end.
     I don't understand why we need so many temporary variables:

     #ref#2#4 = _Jv_AllocObjectNoFinalizer (&Number.class$$);
     #ref#3#6 = #ref#2#4;
     #ref#2#4 = #ref#3#6;

     Here, the #ref#3#6 and #ref#2#4 is a kind waste. But each "new" statement
     does the same thing.

Please tell me where can I find some resources to solve these
question. I have read some paper about
generic and gimple, researched the whole gcj mail list, read the gcc
internals. These questions must have
been too detailed. I did not find anything useful. Is it about alias?

I appreciate any explanations and advices.
Thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Why does a 'new' statement produce so many temporary variables
  2011-08-09  7:18 ` Why does a 'new' statement produce so many temporary variables Li junsong
@ 2011-08-09 16:22   ` Andrew Pinski
  2011-08-15  9:40   ` Andrew Haley
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Pinski @ 2011-08-09 16:22 UTC (permalink / raw)
  To: Li junsong; +Cc: java

On Tue, Aug 9, 2011 at 12:18 AM, Li junsong <ljs.darkfish@gmail.com> wrote:
>  3. I find that there is no document to describe the implementation of
> Java front end.
>      I don't understand why we need so many temporary variables:
>
>      #ref#2#4 = _Jv_AllocObjectNoFinalizer (&Number.class$$);
>      #ref#3#6 = #ref#2#4;
>      #ref#2#4 = #ref#3#6;
>
>      Here, the #ref#3#6 and #ref#2#4 is a kind waste. But each "new" statement
>      does the same thing.

The reason is because this is an exact translation of the java
byte-code.  Most source to java byte-code compilers don't do any
optimizations which is why we get a lot of temporary variables here
(this includes the one included with Eclipse which is what GCJ uses as
the source compiler).

Thanks,
Andrew Pinski

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Why does a 'new' statement produce so many temporary variables
  2011-08-09  7:18 ` Why does a 'new' statement produce so many temporary variables Li junsong
  2011-08-09 16:22   ` Andrew Pinski
@ 2011-08-15  9:40   ` Andrew Haley
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Haley @ 2011-08-15  9:40 UTC (permalink / raw)
  To: java

On 08/09/2011 08:18 AM, Li junsong wrote:
> Hi,
> 
> I am writing a plugin to add a pass in gcc 4.6.1. the pass will do
> some optimizations before high gimple lowering,
> moving some gimple nodes from one place to another. In cc1, the gimple
> code is quite
> understandable.  But I'm confused by the gimple that Java front end converts to.
> 
> I dump the file, here is a piece of code doing "new".
> 
> #ref#2#4 = _Jv_AllocObjectNoFinalizer (&Number.class$$);
> #ref#3#6 = #ref#2#4;
> #ref#2#4 = #ref#3#6;
> D.459 = #slot#1#1;
> #slot#4#7 = D.459;
> #ref#3#6.1 = #ref#3#6;
> (#ref#3#6.1, #slot#4#7);
> 
> the corresponding Java source code is
> 
>         int sum = 4;
>         Number number;
>         if ( sum < 100 )
>             number = new Number(sum);   <=here
> 
> the Number class is a simple one:
> 
> class Number
> {
>     int i;
>     Number(int inputi){
>         i = inputi;
>     }
> }
> 
> Here comes my question:
>  1. I am wondering why we don't use 'NEW_EXPR' to represent a "new" statement?
>      The 'NEW_EXPR' has already been defined in the cp-tree.def.( As I know, the
>      "new" statement in cp front end is also represented as that in
> Java front end,
>      which is "gimple_call" in gimple code, "ADDR_EXPR" in tree code,
> is it? why?)

Why would we want to use 'NEW_EXPR' ?  We simply call the allocator
which creates the object.

>  2. How can I figure out which pieces of code are corresponding
>      to 'NEW' statement? ( Can I always first find the
> "_Jv_AllocObjectNoFinalize" or "_Jv_AllocObject"
>      gimple_call and then "<init>" gimple_call to locate the code?)

I think so.

>  3. I find that there is no document to describe the implementation of
> Java front end.
>      I don't understand why we need so many temporary variables:
> 
>      #ref#2#4 = _Jv_AllocObjectNoFinalizer (&Number.class$$);
>      #ref#3#6 = #ref#2#4;
>      #ref#2#4 = #ref#3#6;
> 
>      Here, the #ref#3#6 and #ref#2#4 is a kind waste. But each "new" statement
>      does the same thing.

It's not really a waste: we assume that the optimizer will delete
useless temporaries, and as far as I know it does.

Andrew.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-08-15  9:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CA+kGxtPef8Xojf-+amOehmUsY_5MQreWUPdnODZUoX-tqX1RTg@mail.gmail.com>
2011-08-09  7:18 ` Why does a 'new' statement produce so many temporary variables Li junsong
2011-08-09 16:22   ` Andrew Pinski
2011-08-15  9:40   ` Andrew Haley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).