[PATCH] 4851444: Exposing sun.reflect.Reflection#getCallerClass as a public API in Java 8

Remi Forax forax at univ-mlv.fr
Sat Sep 21 00:25:23 UTC 2013


On 09/21/2013 01:58 AM, Mandy Chung wrote:
> On 9/20/2013 2:46 PM, Jochen Theodorou wrote:
>>> Exposing a StackStream API means that you need to eagerly walk the 
>>> stack
>>> and copy the stack frames to it before it returns.  I agree it is a 
>>> much
>>> more flexible API.  On the other hand, stack walking is sequential and
>>> ordered and a stack stream will be traversed as in an iterator.
>> to underline it: Stream does not require you to eagerly read all values 
>
>
> Yes.  What I was trying to explain is that if we want to return a 
> Stream instance to the caller and traverse later, it means that it has 
> to take a snapshot of the stack trace of the current thread. The stack 
> trace data has to be stored in whatever data structure like how 
> Throwable is currently implemented.
>
> I think referring this as a "stream" cause the confusion - will 
> revisit this.
>
> Mandy

What you can do is to call a function that will take the stream as 
argument and close the stream after its use and before returning.

<R> R processStackStream(Function<StackStream, R> fun) {
     StackStream stackStream = new 
StackStream(Thread.currentThread());   // bias the stack stream on the 
current thread
// the current thread is checked before doing something on the stream.
     try {
       return fun.apply(stackStream);  // the stack stream is visible by 
the user, but it can not use it in another thread
     } finally {
       stackStream.close();   // set a flag saying that you can't access 
to the underlying stack stream anymore
                                               // the flag doesn't need 
to be volatile if the current thread is checked first
     }
  }

cheers,
Rémi




More information about the core-libs-dev mailing list