How to use @ReservedStackAccess?
Nicolai Parlog
nipa at codefx.org
Tue Nov 1 07:48:23 UTC 2016
Hi David,
oh, now I get it! I knew that I only get 4k of reserved space but I
didn't quite get where computation would resume once stack space ran
out. I got lost in the weeds and thought the JVM would fall back to
the annotated frame and somehow continue in there... But it's much
simpler: I just get a little more rope to hang myself with. :)
Thanks!
Nicolai
On 01.11.2016 02:45, David Holmes wrote:
> Hi Nicolai,
>
> On 1/11/2016 1:39 AM, Nicolai Parlog wrote:
>> Hi!
>>
>> I've been experimenting with @ReservedStackAccess but couldn't
>> get it to work. Any help would be highly appreciated.
>>
>> ## SETUP
>>
>> I'm artificially creating a stack overflow by recursing
>> indefinitely. I then want to benefit from @ReservedStackAccess by
>> executing some code outside of an exception handler.
>>
>> Here's my code:
>>
>> public static void main(String[] args) { try {
>> recurseThenGreet(); } catch (StackOverflowError err) { // to not
>> have the console spammed with output
>> System.out.println("Error"); } }
>>
>> @ReservedStackAccess private static void recurseThenGreet() {
>> recurse(); System.out.println("Hi!"); }
>>
>> private static void recurse() { recurse(); }
>>
>> I'm using build 9-ea+141-jigsaw-nightly-h5650-20161026. I compile
>> with
>>
>> --add-exports java.base/jdk.internal.vm.annotation=ALL-UNNAMED
>>
>> to make the annotation available and launch with
>>
>> -XX:-RestrictReservedStack
>>
>> to activate the reserved stack for user land code.
>>
>> ## OBSERVED
>>
>> This is the output I get:
>>
>> Java HotSpot(TM) 64-Bit Server VM warning: Potentially dangerous
>> stack overflow in ReservedStackAccess annotated method
>> org.codefx.demo.java9.internal.stack.ReservingStackFrames_Simple.recu
rseThenGreet()V[1]
>>
>>
>>
Error
>>
>> ## EXPECTED
>>
>> I expected "Hi!" to show up somewhere there.
>
> ReservedStackAccess doesn't give you unlimited stack, it gives you
> a little extra to try and complete the method that was annotated.
> In your case you will continue to recurse and exhaust the
> additional stack area as well.
>
> David -----
>
>> My best guess is that I put the annotation in the wrong place
>> but experimenting didn't help. Any help would be greatly
>> appreciated!
>>
>> Thanks! Nicolai
>>
>>
>>
>
--
PGP Key:
http://keys.gnupg.net/pks/lookup?op=vindex&search=0xCA3BAD2E9CCCD509
Web:
http://codefx.org
a blog about software development
https://www.sitepoint.com/java
high-quality Java/JVM content
http://do-foss.de
Free and Open Source Software for the City of Dortmund
Twitter:
https://twitter.com/nipafx
More information about the hotspot-runtime-dev
mailing list