This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: Google Summer of Code
- From: Andrea Bernardini <andrebask at gmail dot com>
- To: kawa at sourceware dot org
- Date: Fri, 18 Apr 2014 01:12:43 +0200
- Subject: Re: Google Summer of Code
- Authentication-results: sourceware.org; auth=none
- References: <20140305094242 dot 349492d0 at debian-andrebask> <5316F956 dot 8040303 at gmail dot com> <20140305132208 dot 3081f8dc at debian-andrebask> <m2lhwo48vi dot fsf at gmail dot com> <5319088C dot 5060401 at bothner dot com> <7B118191-4144-4937-B679-89392D5463EE at theptrgroup dot com> <20140316012026 dot 4e0ebfef at debian-andrebask> <53269580 dot 8040205 at bothner dot com> <20140320204856 dot 5aa0b4d3 at debian-andrebask> <532BAA5F dot 3000606 at bothner dot com> <20140328121426 dot 74f3e92d at vaio> <5337BD0C dot 8030301 at bothner dot com> <20140403021150 dot 0dc0f6f4 at vaio> <533F0CC5 dot 1060108 at bothner dot com> <20140413180307 dot 59d3fd9c at debian-andrebask> <534F2BB0 dot 1010208 at bothner dot com>
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