From 29321447b16d318e580f99edb748165eed1a4e00 Mon Sep 17 00:00:00 2001 From: Claes Redestad Date: Thu, 31 Oct 2024 22:28:53 +0000 Subject: [PATCH] 8343305: Remove Indify-dependent microbenchmarks Reviewed-by: liach, ihse, erikj --- make/test/BuildMicrobenchmark.gmk | 23 +- .../java/lang/invoke/CallSiteSetTarget.java | 214 ------------------ .../lang/invoke/CallSiteSetTargetSelf.java | 155 ------------- .../java/lang/invoke/CallSiteStable.java | 171 -------------- 4 files changed, 1 insertion(+), 562 deletions(-) delete mode 100644 test/micro/org/openjdk/bench/java/lang/invoke/CallSiteSetTarget.java delete mode 100644 test/micro/org/openjdk/bench/java/lang/invoke/CallSiteSetTargetSelf.java delete mode 100644 test/micro/org/openjdk/bench/java/lang/invoke/CallSiteStable.java diff --git a/make/test/BuildMicrobenchmark.gmk b/make/test/BuildMicrobenchmark.gmk index 700aac3c9c6..1b2eb40b252 100644 --- a/make/test/BuildMicrobenchmark.gmk +++ b/make/test/BuildMicrobenchmark.gmk @@ -49,7 +49,6 @@ MICROBENCHMARK_CLASSES := $(MICROBENCHMARK_OUTPUT)/classes MICROBENCHMARK_JAR_BIN := $(MICROBENCHMARK_OUTPUT)/jar MICROBENCHMARK_TOOLS_CLASSES := $(MICROBENCHMARK_OUTPUT)/tools-classes -MICROBENCHMARK_INDIFY_DONE := $(MICROBENCHMARK_CLASSES)/_indify.marker JMH_UNPACKED_DIR := $(MICROBENCHMARK_OUTPUT)/jmh_jars JMH_UNPACKED_JARS_DONE := $(JMH_UNPACKED_DIR)/_unpacked.marker @@ -71,17 +70,6 @@ MICROBENCHMARK_MANIFEST := Build: $(FULL_VERSION)\n\ \nJMH-Version: $(JMH_VERSION)\n\ \nName: OpenJDK Microbenchmark Suite -#### Compile Indify tool - -$(eval $(call SetupJavaCompilation, BUILD_INDIFY, \ - TARGET_RELEASE := $(TARGET_RELEASE_BOOTJDK), \ - SRC := $(TOPDIR)/test/jdk/java/lang/invoke, \ - INCLUDE_FILES := indify/Indify.java, \ - DISABLED_WARNINGS := this-escape rawtypes serial options, \ - BIN := $(MICROBENCHMARK_TOOLS_CLASSES), \ - JAVAC_FLAGS := -XDstringConcat=inline -Xprefer:newer, \ -)) - #### Compile Targets # Building microbenchmark requires the jdk.unsupported and java.management modules. @@ -124,14 +112,6 @@ $(eval $(call SetupJavaCompilation, BUILD_JDK_MICROBENCHMARK, \ $(BUILD_JDK_MICROBENCHMARK): $(JMH_COMPILE_JARS) -# Run Indify -$(MICROBENCHMARK_INDIFY_DONE): $(BUILD_INDIFY) $(BUILD_JDK_MICROBENCHMARK) - $(call LogWarn, Running Indify on microbenchmark classes) - $(JAVA_SMALL) -cp $(MICROBENCHMARK_TOOLS_CLASSES) \ - indify.Indify --overwrite $(MICROBENCHMARK_CLASSES) \ - $(LOG_DEBUG) 2>&1 - $(TOUCH) $@ - # Unpacking dependencies for inclusion in the benchmark JARs $(JMH_UNPACKED_JARS_DONE): $(JMH_RUNTIME_JARS) $(RM) -r $(JMH_UNPACKED_DIR) @@ -144,8 +124,7 @@ $(JMH_UNPACKED_JARS_DONE): $(JMH_RUNTIME_JARS) # Create benchmarks JAR file with benchmarks for both the old and new JDK $(eval $(call SetupJarArchive, BUILD_JDK_JAR, \ - DEPENDENCIES := $(BUILD_JDK_MICROBENCHMARK) $(JMH_UNPACKED_JARS_DONE) \ - $(MICROBENCHMARK_INDIFY_DONE), \ + DEPENDENCIES := $(BUILD_JDK_MICROBENCHMARK) $(JMH_UNPACKED_JARS_DONE), \ SRCS := $(MICROBENCHMARK_CLASSES) $(JMH_UNPACKED_DIR), \ BIN := $(MICROBENCHMARK_JAR_BIN), \ SUFFIXES := .*, \ diff --git a/test/micro/org/openjdk/bench/java/lang/invoke/CallSiteSetTarget.java b/test/micro/org/openjdk/bench/java/lang/invoke/CallSiteSetTarget.java deleted file mode 100644 index 965c0713207..00000000000 --- a/test/micro/org/openjdk/bench/java/lang/invoke/CallSiteSetTarget.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright (c) 2014, 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 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.Scope; -import org.openjdk.jmh.annotations.Setup; -import org.openjdk.jmh.annotations.State; -import org.openjdk.jmh.annotations.TearDown; -import org.openjdk.jmh.annotations.Warmup; - -import java.lang.invoke.CallSite; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; -import java.lang.invoke.MutableCallSite; -import java.lang.invoke.VolatileCallSite; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; - -/** - * This benchmark evaluates INDY performance under dynamic target updates. - */ -@BenchmarkMode(Mode.AverageTime) -@OutputTimeUnit(TimeUnit.NANOSECONDS) -@State(Scope.Thread) -@Warmup(iterations = 10, time = 2, timeUnit = TimeUnit.SECONDS) -@Measurement(iterations = 5, time = 2, timeUnit = TimeUnit.SECONDS) -@Fork(3) -public class CallSiteSetTarget { - - /* - * Implementation notes: - * - This test makes sense for mutable and volatile call sites only - * - Multiple threads are calling the same callsite, and invalidator thread tries to swap target on the fly. - * - Additional baseline includes "raw" test, calling callsite's MH directly - */ - - private static volatile CallSite cs; - - private static MethodHandle doCall1; - private static MethodHandle doCall2; - - static { - try { - doCall1 = MethodHandles.lookup().findVirtual(CallSiteSetTarget.class, "call1", MethodType.methodType(int.class)); - doCall2 = MethodHandles.lookup().findVirtual(CallSiteSetTarget.class, "call2", MethodType.methodType(int.class)); - cs = new MutableCallSite(doCall1); - } catch (NoSuchMethodException | IllegalAccessException e) { - throw new IllegalStateException(e); - } - } - - private int i1; - private int i2; - - public int call1() { - return i1++; - } - - public int call2() { - return i2++; - } - - @Benchmark - public int baselineRaw() throws Throwable { - return (int) cs.getTarget().invokeExact(this); - } - - @Benchmark - public int testMutable() throws Throwable { - return (int) INDY_Mutable().invokeExact(this); - } - - @Benchmark - public int testVolatile() throws Throwable { - return (int) INDY_Volatile().invokeExact(this); - } - - /* =========================== INDY TRAMPOLINES ============================== */ - - private static MethodType MT_bsm() { - shouldNotCallThis(); - return MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class); - } - - private static MethodHandle MH_bsm_Mutable() throws ReflectiveOperationException { - shouldNotCallThis(); - return MethodHandles.lookup().findStatic(MethodHandles.lookup().lookupClass(), "bsm_Mutable", MT_bsm()); - } - - private static MethodHandle MH_bsm_Volatile() throws ReflectiveOperationException { - shouldNotCallThis(); - return MethodHandles.lookup().findStatic(MethodHandles.lookup().lookupClass(), "bsm_Volatile", MT_bsm()); - } - - private static MethodHandle INDY_Mutable() throws Throwable { - shouldNotCallThis(); - return ((CallSite) MH_bsm_Mutable().invoke(MethodHandles.lookup(), "doCall1", MethodType.methodType(int.class, CallSiteSetTarget.class))).dynamicInvoker(); - } - - private static MethodHandle INDY_Volatile() throws Throwable { - shouldNotCallThis(); - return ((CallSite) MH_bsm_Volatile().invoke(MethodHandles.lookup(), "doCall1", MethodType.methodType(int.class, CallSiteSetTarget.class))).dynamicInvoker(); - } - - public static CallSite bsm_Mutable(MethodHandles.Lookup lookup, String name, MethodType type) { - synchronized (CallSiteSetTarget.class) { - if (cs == null) - cs = new MutableCallSite(doCall1); - return cs; - } - } - - public static CallSite bsm_Volatile(MethodHandles.Lookup lookup, String name, MethodType type) { - synchronized (CallSiteSetTarget.class) { - if (cs == null) - cs = new VolatileCallSite(doCall1); - return cs; - } - } - - private static void shouldNotCallThis() { - // if this gets called, the transformation has not taken place - throw new AssertionError("this code should be statically transformed away by Indify"); - } - - /* =========================== INVALIDATE LOGIC ============================== */ - - private final static Invalidator invalidator = new Invalidator(); - - @Setup - public void setup() { - invalidator.start(); - } - - @TearDown - public void tearDown() throws InterruptedException { - invalidator.stop(); - } - - public static class Invalidator implements Runnable { - - private final long period = Integer.getInteger("period", 1000); - - private final AtomicBoolean started = new AtomicBoolean(); - private volatile Thread thread; - - @Override - public void run() { - try { - while(!Thread.interrupted()) { - if (cs != null) { - cs.setTarget(doCall1); - } - TimeUnit.MICROSECONDS.sleep(period); - - if (cs != null) { - cs.setTarget(doCall2); - } - TimeUnit.MICROSECONDS.sleep(period); - } - } catch (InterruptedException e) { - // do nothing - } - } - - public void start() { - if (started.compareAndSet(false, true)) { - thread = new Thread(this); - thread.setPriority(Thread.MAX_PRIORITY); - thread.start(); - } - } - - public void stop() { - if (thread != null) { - thread.interrupt(); - try { - thread.join(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - started.set(false); - } - } - } - -} diff --git a/test/micro/org/openjdk/bench/java/lang/invoke/CallSiteSetTargetSelf.java b/test/micro/org/openjdk/bench/java/lang/invoke/CallSiteSetTargetSelf.java deleted file mode 100644 index ac51b4a80e7..00000000000 --- a/test/micro/org/openjdk/bench/java/lang/invoke/CallSiteSetTargetSelf.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (c) 2014, 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 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.Scope; -import org.openjdk.jmh.annotations.State; -import org.openjdk.jmh.annotations.Warmup; - -import java.lang.invoke.CallSite; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; -import java.lang.invoke.MutableCallSite; -import java.lang.invoke.VolatileCallSite; -import java.util.concurrent.TimeUnit; - -/** - * This benchmark evaluates INDY performance under dynamic target updates. - */ -@BenchmarkMode(Mode.AverageTime) -@OutputTimeUnit(TimeUnit.NANOSECONDS) -@State(Scope.Thread) -@Warmup(iterations = 10, time = 2, timeUnit = TimeUnit.SECONDS) -@Measurement(iterations = 5, time = 2, timeUnit = TimeUnit.SECONDS) -@Fork(3) -public class CallSiteSetTargetSelf { - - /* - * Implementation notes: - * - This test makes sense for mutable and volatile call sites only - * - Multiple threads are calling the same callsite, and each call is swapping the target. - * - Additional baseline includes "raw" test, calling callsite's MH directly - * - * - NOTE: invalidating shared target callsite is very bad with multiple threads. - * I.e. this test is inherently non-scalable. - */ - - private static CallSite cs; - - private static MethodHandle doCall1; - private static MethodHandle doCall2; - - static { - try { - doCall1 = MethodHandles.lookup().findVirtual(CallSiteSetTargetSelf.class, "call1", MethodType.methodType(int.class)); - doCall2 = MethodHandles.lookup().findVirtual(CallSiteSetTargetSelf.class, "call2", MethodType.methodType(int.class)); - cs = new MutableCallSite(doCall1); - } catch (NoSuchMethodException | IllegalAccessException e) { - throw new IllegalStateException(e); - } - } - - private int i1; - private int i2; - - public int call1() { - cs.setTarget(doCall2); - return i1++; - } - - public int call2() { - cs.setTarget(doCall1); - return i2++; - } - - @Benchmark - public int baselineRaw() throws Throwable { - return (int) cs.getTarget().invokeExact(this); - } - - @Benchmark - public int testMutable() throws Throwable { - return (int) INDY_Mutable().invokeExact(this); - } - - @Benchmark - public int testVolatile() throws Throwable { - return (int) INDY_Volatile().invokeExact(this); - } - - /* =========================== INDY TRAMPOLINES ============================== */ - - private static MethodType MT_bsm() { - shouldNotCallThis(); - return MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class); - } - - private static MethodHandle MH_bsm_Mutable() throws ReflectiveOperationException { - shouldNotCallThis(); - return MethodHandles.lookup().findStatic(MethodHandles.lookup().lookupClass(), "bsm_Mutable", MT_bsm()); - } - - private static MethodHandle MH_bsm_Volatile() throws ReflectiveOperationException { - shouldNotCallThis(); - return MethodHandles.lookup().findStatic(MethodHandles.lookup().lookupClass(), "bsm_Volatile", MT_bsm()); - } - - private static MethodHandle INDY_Mutable() throws Throwable { - shouldNotCallThis(); - return ((CallSite) MH_bsm_Mutable().invoke(MethodHandles.lookup(), "doCall1", MethodType.methodType(int.class, CallSiteSetTargetSelf.class))).dynamicInvoker(); - } - - private static MethodHandle INDY_Volatile() throws Throwable { - shouldNotCallThis(); - return ((CallSite) MH_bsm_Volatile().invoke(MethodHandles.lookup(), "doCall1", MethodType.methodType(int.class, CallSiteSetTargetSelf.class))).dynamicInvoker(); - } - - public static CallSite bsm_Mutable(MethodHandles.Lookup lookup, String name, MethodType type) { - synchronized (CallSiteSetTarget.class) { - if (cs == null) - cs = new MutableCallSite(doCall1); - return cs; - } - } - - public static CallSite bsm_Volatile(MethodHandles.Lookup lookup, String name, MethodType type) { - synchronized (CallSiteSetTarget.class) { - if (cs == null) - cs = new VolatileCallSite(doCall1); - return cs; - } - } - - private static void shouldNotCallThis() { - // if this gets called, the transformation has not taken place - throw new AssertionError("this code should be statically transformed away by Indify"); - } - -} diff --git a/test/micro/org/openjdk/bench/java/lang/invoke/CallSiteStable.java b/test/micro/org/openjdk/bench/java/lang/invoke/CallSiteStable.java deleted file mode 100644 index cf7c4f487f1..00000000000 --- a/test/micro/org/openjdk/bench/java/lang/invoke/CallSiteStable.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (c) 2014, 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 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.Scope; -import org.openjdk.jmh.annotations.State; -import org.openjdk.jmh.annotations.Warmup; - -import java.lang.invoke.ConstantCallSite; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; -import java.lang.invoke.MutableCallSite; -import java.lang.invoke.VolatileCallSite; -import java.util.concurrent.TimeUnit; - -/** - * This benchmark evaluates INDY performance when call sites are not changed. - */ -@BenchmarkMode(Mode.AverageTime) -@OutputTimeUnit(TimeUnit.NANOSECONDS) -@State(Scope.Thread) -@Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS) -@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) -@Fork(3) -public class CallSiteStable { - - /* - * Implementation notes: - * - Test is calling simple method via INDY - * - Additional baseline includes "raw" test, calling target method directly in virtual and static modes - */ - - private static java.lang.invoke.CallSite cs; - - private static MethodHandle doCallMH; - - static { - try { - doCallMH = MethodHandles.lookup().findVirtual(CallSiteStable.class, "doCall", MethodType.methodType(int.class, int.class)); - } catch (NoSuchMethodException | IllegalAccessException e) { - throw new IllegalStateException(e); - } - } - - private int i; - - public int doCall(int value) { - return value + 1; - } - - public static int doCallStatic(int value) { - return value + 1; - } - - @Benchmark - public void baselineVirtual() { - i = doCall(i); - } - - @Benchmark - public void baselineStatic() { - i = doCallStatic(i); - } - - @Benchmark - public void testConstant() throws Throwable { - i = (int) INDY_Constant().invokeExact(this, i); - } - - @Benchmark - public void testMutable() throws Throwable { - i = (int) INDY_Mutable().invokeExact(this, i); - } - - @Benchmark - public void testVolatile() throws Throwable { - i = (int) INDY_Volatile().invokeExact(this, i); - } - - /* =========================== INDY TRAMPOLINES ============================== */ - - private static MethodType MT_bsm() { - shouldNotCallThis(); - return MethodType.methodType(java.lang.invoke.CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class); - } - - private static MethodHandle MH_bsm_Constant() throws ReflectiveOperationException { - shouldNotCallThis(); - return MethodHandles.lookup().findStatic(MethodHandles.lookup().lookupClass(), "bsm_Constant", MT_bsm()); - } - - private static MethodHandle MH_bsm_Mutable() throws ReflectiveOperationException { - shouldNotCallThis(); - return MethodHandles.lookup().findStatic(MethodHandles.lookup().lookupClass(), "bsm_Mutable", MT_bsm()); - } - - private static MethodHandle MH_bsm_Volatile() throws ReflectiveOperationException { - shouldNotCallThis(); - return MethodHandles.lookup().findStatic(MethodHandles.lookup().lookupClass(), "bsm_Volatile", MT_bsm()); - } - - private static MethodHandle INDY_Constant() throws Throwable { - shouldNotCallThis(); - return ((java.lang.invoke.CallSite) MH_bsm_Constant().invoke(MethodHandles.lookup(), "doCall", MethodType.methodType(int.class, CallSiteStable.class, int.class))).dynamicInvoker(); - } - private static MethodHandle INDY_Mutable() throws Throwable { - shouldNotCallThis(); - return ((java.lang.invoke.CallSite) MH_bsm_Mutable().invoke(MethodHandles.lookup(), "doCall", MethodType.methodType(int.class, CallSiteStable.class, int.class))).dynamicInvoker(); - } - private static MethodHandle INDY_Volatile() throws Throwable { - shouldNotCallThis(); - return ((java.lang.invoke.CallSite) MH_bsm_Volatile().invoke(MethodHandles.lookup(), "doCall", MethodType.methodType(int.class, CallSiteStable.class, int.class))).dynamicInvoker(); - } - - public static java.lang.invoke.CallSite bsm_Constant(MethodHandles.Lookup lookup, String name, MethodType type) { - synchronized (CallSiteStable.class) { - if (cs == null) - cs = new ConstantCallSite(doCallMH); - return cs; - } - } - - public static java.lang.invoke.CallSite bsm_Mutable(MethodHandles.Lookup lookup, String name, MethodType type) { - synchronized (CallSiteStable.class) { - if (cs == null) - cs = new MutableCallSite(doCallMH); - return cs; - } - } - - public static java.lang.invoke.CallSite bsm_Volatile(MethodHandles.Lookup lookup, String name, MethodType type) { - synchronized (CallSiteStable.class) { - if (cs == null) - cs = new VolatileCallSite(doCallMH); - return cs; - } - } - - private static void shouldNotCallThis() { - // if this gets called, the transformation has not taken place - throw new AssertionError("this code should be statically transformed away by Indify"); - } - -}