Support inner @State classes
Roman Leventov
leventov.ru at gmail.com
Sun Dec 11 22:01:13 UTC 2016
I suppose that a large fraction of State DAG uses look like this:
@State
public class TopLevelBenchmarkClass {
.. some state
@State
static class StateForSomeSpecificBenchmark {
.. specific state
public void setup(TopLevelBenchmarkClass rootState) {
.. use rootState to initialize the specific state
}
}
@Benchmark
public int specificBenchmark(StateForSomeSpecificBenchmark state) {
..
}
}
A real example:
https://github.com/druid-io/druid/blob/d9807835f9b75e36ba7d352d1e5f2d22b1bdd050/benchmarks/src/main/java/io/druid/benchmark/BitmapIterationBenchmark.java
If State DAG supports inner classes, StateForSomeSpecificBenchmark could be
simplified, it could be an inner class, then doesn't need
`TopLevelBenchmarkClass rootState` parameter in it's setup() method and
access TopLevelBenchmarkClass's methods and state without qualifier.
On 8 December 2016 at 08:00, Aleksey Shipilev <shade at redhat.com> wrote:
> Hi,
>
> On 12/07/2016 04:12 AM, Roman Leventov wrote:
> > If a @State class is an inner class of another @State class, it could
> mean
> > the same dependency as if the first @State class is static and has the
> > second class as a parameter of it's @Setup method.
> >
> > It would be nice to have this feature because it would allow to reduce
> > verbosity of dependent @State classes.
>
> Can you give a motivating example?
>
> I thought we only support nested classes, not inners. Mostly because there
> are
> non-trivial lifecycle dependencies between them, e.g.:
>
> @State
> static class BS {
>
> @State
> class TS1 {
> // Thread initializes this, but needs BS instance to call new...
> }
> }
>
> ...which, I think are resolvable, but need to see the motivating example.
>
> Thanks,
> -Aleksey
>
>
More information about the jmh-dev
mailing list