How to use @ReservedStackAccess?

David Holmes david.holmes at oracle.com
Tue Nov 1 01:45:21 UTC 2016


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.recurseThenGreet()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
>
>
>


More information about the hotspot-runtime-dev mailing list