Proposed API for JEP 259: Stack-Walking API

David M. Lloyd david.lloyd at
Fri Oct 30 22:38:03 UTC 2015

On 10/30/2015 03:39 PM, Mandy Chung wrote:
>> On Oct 30, 2015, at 12:59 PM, David M. Lloyd <david.lloyd at> wrote:
>> Since this is very likely to be a one-implementation API, is there a reason to have a separate WalkerOption interface and Option enum?  Seems like you could just skip the interface.
> Locals and operands is one experimental feature in mind that is not target for JDK 9.   But it would be an interesting feature for e.g. Fibers to experiment.  This will also allow JDK-specific capability to be implemented in the future.

Ah, that makes sense, I forgot about cases where the JDK itself might 
have non-spec extensions.  It should probably be specified in the docs 
that unrecognized options are either ignored or rejected though.

>> All that boxing seems unnecessary... the next best candidate I can see though is IntToLongFunction.  I wonder why we didn't do an IntToIntFunction in JSR 335.  Or maybe the stream itself should be somehow made aware of the optimum batch size.  What's the use case for changing the batch size as you iterate?
>> Is the traversal *that* expensive?
> Altering the first batch size would be useful for Log4J and Groovy use cases that filter implementation classes and finds the caller.   Altering subsequent batch size is more as a flexible option.  One can simple have the function to return the same batch size.

Maybe an overload of walk() which accepts an int (initial batch size) in 
addition to the function for the simple case?

> I do think IntSupplier is probably a better choice that won’t restrict to supply only the initial batch size.   The last batch size parameter is solely for information.

UnaryOperator is a good option too (that's what I was looking for 
before), or maybe even ToIntFunction<X> where X is something that might 
inform the next batch size based on the work that has already been done 
- maybe even a Stream<StackFrame> that consists only of the current batch?

Or another idea:
   <T> T walk(BiFunction<Stream<StackWalker.StackFrame>, IntConsumer, T> 

where the IntConsumer can be called at any time to update a minimum 
number of remaining frames needed, which in turn can (with the knowledge 
of how many elements have been consumed by the stream) inform the next 
batch size.


More information about the core-libs-dev mailing list