How to use @ReservedStackAccess?
Nicolai Parlog
nipa at codefx.org
Mon Oct 31 15:39:51 UTC 2016
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.
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