Missed IR test review, rearrange benches

This commit is contained in:
Chen Liang 2025-12-15 11:37:42 -06:00
parent f9d808c185
commit 1d5461db02
4 changed files with 98 additions and 20 deletions

View File

@ -66,8 +66,7 @@ public class VarHandleMismatchedTypeFold {
}
@Check(test = "testSum")
public void runTestSum() {
long sum = testSum();
public void checkTestSum(long sum) {
if (sum != 2L + 5L) {
throw new IllegalStateException("Failed, unexpected sum " + sum);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -74,21 +74,16 @@ public class VarHandleExact {
@Benchmark
public void exact_exactInvocation() {
var _ = (int) exact.getAndAdd(data, (long) 0, 42);
exact.set(data, (long) 0, 42);
}
@Benchmark
public void generic_genericInvocation() {
generic.getAndAdd(data, 0, 42);
}
@Benchmark
public void generic_returnDroppingInvocation() {
generic.getAndAdd(data, (long) 0, 42);
generic.set(data, 0, 42);
}
@Benchmark
public void generic_exactInvocation() {
var _ = (int) generic.getAndAdd(data, (long) 0, 42);
generic.set(data, (long) 0, 42);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -69,21 +69,16 @@ public class VarHandleExact {
@Benchmark
public void exact_exactInvocation() {
var _ = (long) exact.getAndAdd(data, (long) 42);
exact.set(data, (long) 42);
}
@Benchmark
public void generic_genericInvocation() {
generic.getAndAdd(data, 42);
}
@Benchmark
public void generic_returnDroppingInvocation() {
generic.getAndAdd(data, (long) 42);
generic.set(data, 42);
}
@Benchmark
public void generic_exactInvocation() {
var _ = (long) generic.getAndAdd(data, (long) 42);
generic.set(data, (long) 42);
}
}

View File

@ -0,0 +1,89 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package org.openjdk.bench.java.lang.invoke;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;
@BenchmarkMode(Mode.AverageTime)
@Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
@State(org.openjdk.jmh.annotations.Scope.Thread)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Fork(3)
public class VarHandleTypeMismatch {
static final VarHandle handle, noiseHandle;
static {
try {
handle = MethodHandles.lookup().findVarHandle(Data.class, "longField", long.class);
noiseHandle = MethodHandles.lookup().findVarHandle(Data.class, "longField", long.class);
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}
Data data;
static class Data {
long longField;
}
@Setup
public void setup() {
data = new Data();
if (handle == noiseHandle) {
throw new IllegalStateException("Must use different handles to pollute signature");
}
// Pollute the set(VH, byte)void signature
noiseHandle.set(data, (byte) 42);
handle.set(data, (byte) 42);
}
@Benchmark
public void pollutedInvocation() {
handle.set(data, (byte) 42);
}
@Benchmark
public void genericInvocation() {
handle.set(data, 42);
}
@Benchmark
public void exactInvocation() {
handle.set(data, (long) 42);
}
}