RFR: 8288327: Executable.hasRealParameterData should not be volatile [v7]
Сергей Цыпанов
duke at openjdk.org
Mon Jul 4 10:09:25 UTC 2022
On Mon, 4 Jul 2022 06:31:15 GMT, Peter Levart <plevart at openjdk.org> wrote:
>> ...neither is obtaining a cloned array and passing its reference to JMH's black hole our usecase... Still, it seems that even part of that has some advantage. I would keep the @stable annotation then.
>
> A more realistic use case would be something in the lines of checking whether the method is an expected one:
>
>
> @Benchmark
> public boolean isFoo() {
> return matches(method, "foo", int.class, String.class);
> }
>
> private boolean matches(Method method, String name, Class<?> ...parameterTypes) {
> if (method.getName().equals(name) &&
> method.getParameterCount() == parameterTypes.length) {
> var params = method.getParameters();
> for (int i = 0; i < parameterTypes.length; i++) {
> if (params[i].getType() != parameterTypes[i]) {
> return false;
> }
> }
> return true;
> } else {
> return false;
> }
> }
Without `@Stable` your benchmark yields
Benchmark Mode Cnt Score Error Units
AccessParamsBenchmark.isFoo avgt 40 1,110 ± 0,062 ns/op
and with `@Stable` it yields
Benchmark Mode Cnt Score Error Units
AccessParamsBenchmark.isFoo avgt 40 0,836 ± 0,015 ns/op
Java 18:
Benchmark Mode Cnt Score Error Units
AccessParamsBenchmark.isFoo avgt 40 6,105 ± 0,107 ns/op
-------------
PR: https://git.openjdk.org/jdk/pull/9143
More information about the core-libs-dev
mailing list