This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Google Summer of Code


On Wed, 16 Apr 2014 18:17:36 -0700
Per Bothner <per@bothner.com> wrote:

> That doesn't seem right - why should switch automatically cause a
> a method return?

If I compile a case expr wit numCases == 2, this code is generated:

>...
> 31: tableswitch low: 1 high: 5 default: 114
>  1: 64
>  2: 114
>  3: 114
>  4: 114
>  5: 89
> 64: *First case code*
>...
> 83: invokevirtual <Method gnu.mapping.Procedure.apply1
> (java.lang.Object)java.lang.Object> 
> 86: goto 124
> 89: *Second case code*
>...
>108: invokevirtual <Method gnu.mapping.Procedure.apply1
>(java.lang.Object)java.lang.Object> 
>111: goto 124
>114: *Default case code*
>...
>121: invokevirtual <Method gnu.mapping.Procedure.apply2
>(java.lang.Object,java.lang.Object)java.lang.Object> 
>124: return
>Attribute "StackMapTable", length:17, number of entries: 4
>...

If I compile a case expr wit numCases == 1, this is the result:

>...
> 31: iconst_1
> 32: if_icmpne 38
> 35: goto 41
> 38: goto 66
> 41: *First case code*
>...
> 60: invokevirtual <Method gnu.mapping.Procedure.apply1
> (java.lang.Object)java.lang.Object> 
> 63: goto 76
> 66: *Default case code*
>...
> 73: invokevirtual <Method gnu.mapping.Procedure.apply2
> (java.lang.Object,java.lang.Object)java.lang.Object>
>Attribute "StackMapTable", length:13, number of entries: 3
>...

In the numCases == 2 code, all the gotos point to a return statement,
while in the numCases == 1 the return is missing. What I wanted to
obtain was the same code with a return statement at the end. But adding
a return statement at the end with emitReturn() is not enough, because
for some reason after_label is not pointing to the correct location:

>...
> 31: iconst_1
> 32: if_icmpne 38
> 35: goto 41
> 38: goto 66
> 41: *First case code*
>...
> 60: invokevirtual <Method gnu.mapping.Procedure.apply1
> (java.lang.Object)java.lang.Object> 
> 63: goto 77
> 66: *Default case code*
>...
> 73: invokevirtual <Method gnu.mapping.Procedure.apply2
> (java.lang.Object,java.lang.Object)java.lang.Object> 
> 76: return
>Attribute "StackMapTable", length:13, number of entries: 3
>...

The problem is: where is that return generated when we have numCases ==
2, and how can we obtain the same behaviour when numCases <= 1.

> And in fact it doesn't work - the test suite has numerous failures.
> 
> My recommendation: Run the test-suite early and often.
> This is easiest if you're developing on a Unix-like system (e.g.
> GNU/Linux or MacOS) and using configure+make (rather than ant builds),
> since you just do:
>    make check -k >& LOG.CHECK
> 
> I stash a copy of LOG.CHECK before I make changes, and compare (with
> diff) the result after my changes.

Thanks, I will make use of the test suite from now on. I ususally work
on Debian GNU/Linux.

Andrea


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]