repo
stringlengths
1
191
file
stringlengths
23
351
code
stringlengths
0
5.32M
file_length
int64
0
5.32M
avg_line_length
float64
0
2.9k
max_line_length
int64
0
288k
extension_type
stringclasses
1 value
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/races/RaceBenchmarkStateIterationTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.races; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; 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.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.TimeUnit; /** * Baseline test: * Checks if assertions are propagated back to integration tests. */ public class RaceBenchmarkStateIterationTest { @State(Scope.Benchmark) public static class MyState { public int value = 2; @Setup(Level.Iteration) public void setup() { Assert.assertEquals("Setup", 2, value); value = 1; } @TearDown(Level.Iteration) public void tearDown() { Assert.assertEquals("TearDown", 1, value); value = 2; } } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 50, time = 10, timeUnit = TimeUnit.MILLISECONDS) @Threads(4) public void test(MyState state) { Assert.assertEquals("Run", 1, state.value); Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .forks(0) .build(); new Runner(opt).run(); } } }
3,276
33.861702
79
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/races/RaceBenchmarkStateRunTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.races; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; 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.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.TimeUnit; /** * Baseline test: * Checks if assertions are propagated back to integration tests. */ public class RaceBenchmarkStateRunTest { @State(Scope.Benchmark) public static class MyState { public int value = 2; @Setup(Level.Trial) public void setup() { Assert.assertEquals("Setup", 2, value); value = 1; } @TearDown(Level.Trial) public void tearDown() { Assert.assertEquals("TearDown", 1, value); value = 2; } } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 5, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Threads(4) public void test(MyState state) { Assert.assertEquals("Run", 1, state.value); Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .forks(0) .build(); new Runner(opt).run(); } } }
3,262
33.712766
79
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/races/RaceGroupStateInvocationTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.races; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Group; import org.openjdk.jmh.annotations.GroupThreads; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; 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 org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.TimeUnit; /** * Baseline test: * Checks if assertions are propagated back to integration tests. */ public class RaceGroupStateInvocationTest { @State(Scope.Group) public static class MyState { public int value = 2; @Setup(Level.Invocation) public void setup() { Assert.assertEquals("Setup", 2, value); value = 1; } @TearDown(Level.Invocation) public void tearDown() { Assert.assertEquals("TearDown", 1, value); value = 2; } } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) @Group("T") @GroupThreads(4) public void test(MyState state) { // Useless to test this condition here, intrinsic races. // Assert.assertEquals("Run", 1, state.value); Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .forks(0) .build(); new Runner(opt).run(); } } }
3,398
34.041237
79
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/races/RaceGroupStateIterationTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.races; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Group; import org.openjdk.jmh.annotations.GroupThreads; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; 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 org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.TimeUnit; /** * Baseline test: * Checks if assertions are propagated back to integration tests. */ public class RaceGroupStateIterationTest { @State(Scope.Group) public static class MyState { public int value = 2; @Setup(Level.Iteration) public void setup() { Assert.assertEquals("Setup", 2, value); value = 1; } @TearDown(Level.Iteration) public void tearDown() { Assert.assertEquals("TearDown", 1, value); value = 2; } } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 50, time = 10, timeUnit = TimeUnit.MILLISECONDS) @Group("T") @GroupThreads(4) public void test(MyState state) { Assert.assertEquals("Run", 1, state.value); Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .forks(0) .build(); new Runner(opt).run(); } } }
3,336
33.760417
79
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/races/RaceGroupStateRunTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.races; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Group; import org.openjdk.jmh.annotations.GroupThreads; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; 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 org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.TimeUnit; /** * Baseline test: * Checks if assertions are propagated back to integration tests. */ public class RaceGroupStateRunTest { @State(Scope.Group) public static class MyState { public int value = 2; @Setup(Level.Trial) public void setup() { Assert.assertEquals("Setup", 2, value); value = 1; } @TearDown(Level.Trial) public void tearDown() { Assert.assertEquals("TearDown", 1, value); value = 2; } } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 5, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Group("T") @GroupThreads(4) public void test(MyState state) { Assert.assertEquals("Run", 1, state.value); Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .forks(0) .build(); new Runner(opt).run(); } } }
3,322
33.614583
79
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/races/RaceThreadStateInvocationTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.races; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; 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.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.TimeUnit; /** * Baseline test: * Checks if assertions are propagated back to integration tests. */ public class RaceThreadStateInvocationTest { @State(Scope.Thread) public static class MyState { public int value = 2; @Setup(Level.Invocation) public void setup() { Assert.assertEquals("Setup", 2, value); value = 1; } @TearDown(Level.Invocation) public void tearDown() { Assert.assertEquals("TearDown", 1, value); value = 2; } } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) @Threads(4) public void test(MyState state) { Assert.assertEquals("Run", 1, state.value); Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .forks(0) .build(); new Runner(opt).run(); } } }
3,266
33.755319
79
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/races/RaceThreadStateIterationTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.races; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; 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.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.TimeUnit; /** * Baseline test: * Checks if assertions are propagated back to integration tests. */ public class RaceThreadStateIterationTest { @State(Scope.Thread) public static class MyState { public int value = 2; @Setup(Level.Iteration) public void setup() { Assert.assertEquals("Setup", 2, value); value = 1; } @TearDown(Level.Iteration) public void tearDown() { Assert.assertEquals("TearDown", 1, value); value = 2; } } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 50, time = 10, timeUnit = TimeUnit.MILLISECONDS) @Threads(4) public void test(MyState state) { Assert.assertEquals("Run", 1, state.value); Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .forks(0) .build(); new Runner(opt).run(); } } }
3,270
33.797872
79
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/races/RaceThreadStateRunTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.races; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; 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.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.TimeUnit; /** * Baseline test: * Checks if assertions are propagated back to integration tests. */ public class RaceThreadStateRunTest { @State(Scope.Thread) public static class MyState { public int value = 2; @Setup(Level.Trial) public void setup() { Assert.assertEquals("Setup", 2, value); value = 1; } @TearDown(Level.Trial) public void tearDown() { Assert.assertEquals("TearDown", 1, value); value = 2; } } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 5, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Threads(4) public void test(MyState state) { Assert.assertEquals("Run", 1, state.value); Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .forks(0) .build(); new Runner(opt).run(); } } }
3,256
33.648936
79
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/result/ResultFileNameTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.result; import org.junit.Assert; import org.junit.Test; 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.Scope; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.io.File; import java.io.IOException; import java.util.concurrent.TimeUnit; /** * Tests if harness favors the iteration count annotations. */ @State(Scope.Thread) public class ResultFileNameTest { @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 1, time = 1, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) public void test() { Fixtures.work(); } @Test public void testLower() throws RunnerException, IOException { doWith("jmh" + this.getClass().getSimpleName().toLowerCase() + ".result"); } @Test public void testUpper() throws RunnerException, IOException { doWith("JMH" + this.getClass().getSimpleName().toUpperCase() + ".RESULT"); } @Test public void testMixed() throws RunnerException, IOException { doWith("jmh" + this.getClass().getSimpleName() + ".result"); } public void doWith(String name) throws RunnerException, IOException { name = System.getProperty("java.io.tmpdir") + File.separator + name; Options opts = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .result(name) .build(); new Runner(opts).run(); File file = new File(name); Assert.assertTrue(file.exists()); file.delete(); } }
3,287
34.73913
82
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/BenchmarkMinJVMArgsSecurityManagerTest.java
/* * Copyright (c) 2014, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.security; import org.junit.Test; 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.Scope; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.net.URI; import java.net.URISyntaxException; import java.security.NoSuchAlgorithmException; import java.util.concurrent.TimeUnit; @State(Scope.Benchmark) public class BenchmarkMinJVMArgsSecurityManagerTest { @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 1, time = 1, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) public void test() { Fixtures.work(); } @Test public void invokeAPI() throws RunnerException, URISyntaxException, NoSuchAlgorithmException { URI policyFile = BenchmarkMinJVMArgsSecurityManagerTest.class.getResource("/jmh-security-minimal-runner.policy").toURI(); Options opts = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .jvmArgsAppend("-Djava.security.manager", "-Djava.security.policy=" + policyFile.toString()) .build(); new Runner(opts).run(); } }
2,856
38.680556
129
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/BenchmarkMinRunnerSecurityManagerTest.java
/* * Copyright (c) 2014, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.security; import org.junit.Test; 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.Scope; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.net.URI; import java.net.URISyntaxException; import java.security.NoSuchAlgorithmException; import java.security.Policy; import java.security.URIParameter; import java.util.concurrent.TimeUnit; @State(Scope.Benchmark) public class BenchmarkMinRunnerSecurityManagerTest { @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 1, time = 1, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) public void test() { Fixtures.work(); } @Test public void invokeAPI() throws RunnerException, URISyntaxException, NoSuchAlgorithmException { URI policyFile = BenchmarkMinRunnerSecurityManagerTest.class.getResource("/jmh-security-minimal-runner.policy").toURI(); Policy.setPolicy(Policy.getInstance("JavaPolicy", new URIParameter(policyFile))); SecurityManagerTestUtils.install(); try { Options opts = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opts).run(); } finally { SecurityManagerTestUtils.remove(); } } }
3,054
37.670886
128
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/BenchmarkMinSecurityManagerTest.java
/* * Copyright (c) 2014, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.security; import org.junit.Test; 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.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 org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.security.NoSuchAlgorithmException; import java.security.Policy; import java.security.URIParameter; import java.util.concurrent.TimeUnit; @State(Scope.Benchmark) public class BenchmarkMinSecurityManagerTest { @Setup public void setup() throws IOException, NoSuchAlgorithmException, URISyntaxException { Fixtures.work(); URI policyFile = BenchmarkMinSecurityManagerTest.class.getResource("/jmh-security-minimal.policy").toURI(); Policy.setPolicy(Policy.getInstance("JavaPolicy", new URIParameter(policyFile))); SecurityManagerTestUtils.install(); } @TearDown public void tearDown() { SecurityManagerTestUtils.remove(); } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 1, time = 1, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) public void test() { Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { Options opts = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opts).run(); } }
3,219
36.011494
115
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/BenchmarkSecurityManagerTest.java
/* * Copyright (c) 2014, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.security; import org.junit.Test; 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.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 org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.security.NoSuchAlgorithmException; import java.security.Policy; import java.security.URIParameter; import java.util.concurrent.TimeUnit; @State(Scope.Benchmark) public class BenchmarkSecurityManagerTest { @Setup public void setup() throws IOException, NoSuchAlgorithmException, URISyntaxException { Fixtures.work(); URI policyFile = BenchmarkSecurityManagerTest.class.getResource("/jmh-security.policy").toURI(); Policy.setPolicy(Policy.getInstance("JavaPolicy", new URIParameter(policyFile))); SecurityManagerTestUtils.install(); } @TearDown public void tearDown() { SecurityManagerTestUtils.remove(); } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 1, time = 1, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) public void test() { Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { Options opts = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opts).run(); } }
3,205
35.850575
104
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/GroupMinJVMArgsSecurityManagerTest.java
/* * Copyright (c) 2014, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.security; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Group; import org.openjdk.jmh.annotations.GroupThreads; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.net.URI; import java.net.URISyntaxException; import java.security.NoSuchAlgorithmException; import java.util.concurrent.TimeUnit; @State(Scope.Group) public class GroupMinJVMArgsSecurityManagerTest { @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 1, time = 1, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Group("group1") @GroupThreads(2) public void test() { Fixtures.work(); } @Test public void invokeAPI() throws RunnerException, URISyntaxException, NoSuchAlgorithmException { URI policyFile = GroupMinJVMArgsSecurityManagerTest.class.getResource("/jmh-security-minimal-runner.policy").toURI(); Options opts = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .jvmArgsAppend("-Djava.security.manager", "-Djava.security.policy=" + policyFile.toString()) .build(); new Runner(opts).run(); } }
2,977
38.184211
125
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/GroupMinRunnerSecurityManagerTest.java
/* * Copyright (c) 2014, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.security; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Group; import org.openjdk.jmh.annotations.GroupThreads; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.net.URI; import java.net.URISyntaxException; import java.security.NoSuchAlgorithmException; import java.security.Policy; import java.security.URIParameter; import java.util.concurrent.TimeUnit; @State(Scope.Group) public class GroupMinRunnerSecurityManagerTest { @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 1, time = 1, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Group("group1") @GroupThreads(2) public void test1() { Fixtures.work(); } @Test public void invokeAPI() throws RunnerException, URISyntaxException, NoSuchAlgorithmException { URI policyFile = GroupMinRunnerSecurityManagerTest.class.getResource("/jmh-security-minimal-runner.policy").toURI(); Policy.setPolicy(Policy.getInstance("JavaPolicy", new URIParameter(policyFile))); SecurityManagerTestUtils.install(); try { Options opts = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opts).run(); } finally { SecurityManagerTestUtils.remove(); } } }
3,176
37.277108
124
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/GroupMinSecurityManagerTest.java
/* * Copyright (c) 2014, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.security; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Group; import org.openjdk.jmh.annotations.GroupThreads; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; 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 org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.security.NoSuchAlgorithmException; import java.security.Policy; import java.security.URIParameter; import java.util.concurrent.TimeUnit; @State(Scope.Group) public class GroupMinSecurityManagerTest { @Setup public void setup() throws IOException, NoSuchAlgorithmException, URISyntaxException { Fixtures.work(); URI policyFile = GroupMinSecurityManagerTest.class.getResource("/jmh-security-minimal.policy").toURI(); Policy.setPolicy(Policy.getInstance("JavaPolicy", new URIParameter(policyFile))); SecurityManagerTestUtils.install(); } @TearDown public void tearDown() { SecurityManagerTestUtils.remove(); } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 1, time = 1, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Group("group1") @GroupThreads(2) public void test1() { Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { Options opts = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opts).run(); } }
3,341
35.725275
111
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/GroupSecurityManagerTest.java
/* * Copyright (c) 2014, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.security; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Group; import org.openjdk.jmh.annotations.GroupThreads; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; 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 org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.security.NoSuchAlgorithmException; import java.security.Policy; import java.security.URIParameter; import java.util.concurrent.TimeUnit; @State(Scope.Group) public class GroupSecurityManagerTest { @Setup public void setup() throws IOException, NoSuchAlgorithmException, URISyntaxException { Fixtures.work(); URI policyFile = GroupSecurityManagerTest.class.getResource("/jmh-security.policy").toURI(); Policy.setPolicy(Policy.getInstance("JavaPolicy", new URIParameter(policyFile))); SecurityManagerTestUtils.install(); } @TearDown public void tearDown() { SecurityManagerTestUtils.remove(); } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 1, time = 1, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Group("group1") @GroupThreads(2) public void test1() { Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { Options opts = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opts).run(); } }
3,327
35.571429
100
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/SecurityManagerTestUtils.java
/* * Copyright (c) 2022, Red Hat, Inc. 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.security; import java.security.AccessController; import java.security.PrivilegedAction; public class SecurityManagerTestUtils { public static void install() { try { AccessController.doPrivileged(new PrivilegedAction<Void>() { public Void run() { System.setSecurityManager(new SecurityManager()); return null; } }); } catch (UnsupportedOperationException uoe) { // Probably modern JDK without SecurityManager support. } } public static void remove() { try { AccessController.doPrivileged(new PrivilegedAction<Void>() { public Void run() { System.setSecurityManager(null); return null; } }); } catch (UnsupportedOperationException uoe) { // Probably modern JDK without SecurityManager support. } } }
2,201
36.322034
76
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/ThreadMinJVMArgsSecurityManagerTest.java
/* * Copyright (c) 2014, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.security; import org.junit.Test; 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.Scope; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.net.URI; import java.net.URISyntaxException; import java.security.NoSuchAlgorithmException; import java.util.concurrent.TimeUnit; @State(Scope.Thread) public class ThreadMinJVMArgsSecurityManagerTest { @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 1, time = 1, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) public void test() { Fixtures.work(); } @Test public void invokeAPI() throws RunnerException, URISyntaxException, NoSuchAlgorithmException { URI policyFile = ThreadMinJVMArgsSecurityManagerTest.class.getResource("/jmh-security-minimal-runner.policy").toURI(); Options opts = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .jvmArgsAppend("-Djava.security.manager", "-Djava.security.policy=" + policyFile.toString()) .build(); new Runner(opts).run(); } }
2,847
38.555556
126
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/ThreadMinRunnerSecurityManagerTest.java
/* * Copyright (c) 2014, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.security; import org.junit.Test; 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.Scope; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.net.URI; import java.net.URISyntaxException; import java.security.NoSuchAlgorithmException; import java.security.Policy; import java.security.URIParameter; import java.util.concurrent.TimeUnit; @State(Scope.Thread) public class ThreadMinRunnerSecurityManagerTest { @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 1, time = 1, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) public void test() { Fixtures.work(); } @Test public void invokeAPI() throws RunnerException, URISyntaxException, NoSuchAlgorithmException { URI policyFile = ThreadMinRunnerSecurityManagerTest.class.getResource("/jmh-security-minimal-runner.policy").toURI(); Policy.setPolicy(Policy.getInstance("JavaPolicy", new URIParameter(policyFile))); SecurityManagerTestUtils.install(); try { Options opts = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opts).run(); } finally { SecurityManagerTestUtils.remove(); } } }
3,045
37.556962
125
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/ThreadMinSecurityManagerTest.java
/* * Copyright (c) 2014, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.security; import org.junit.Test; 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.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 org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.security.NoSuchAlgorithmException; import java.security.Policy; import java.security.URIParameter; import java.util.concurrent.TimeUnit; @State(Scope.Thread) public class ThreadMinSecurityManagerTest { @Setup public void setup() throws IOException, NoSuchAlgorithmException, URISyntaxException { Fixtures.work(); URI policyFile = ThreadMinSecurityManagerTest.class.getResource("/jmh-security-minimal.policy").toURI(); Policy.setPolicy(Policy.getInstance("JavaPolicy", new URIParameter(policyFile))); SecurityManagerTestUtils.install(); } @TearDown public void tearDown() { SecurityManagerTestUtils.remove(); } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 1, time = 1, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) public void test() { Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { Options opts = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opts).run(); } }
3,210
35.908046
112
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/ThreadSecurityManagerTest.java
/* * Copyright (c) 2014, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.security; import org.junit.Test; 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.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 org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.security.NoSuchAlgorithmException; import java.security.Policy; import java.security.URIParameter; import java.util.concurrent.TimeUnit; @State(Scope.Thread) public class ThreadSecurityManagerTest { @Setup public void setup() throws IOException, NoSuchAlgorithmException, URISyntaxException { Fixtures.work(); URI policyFile = ThreadSecurityManagerTest.class.getResource("/jmh-security.policy").toURI(); Policy.setPolicy(Policy.getInstance("JavaPolicy", new URIParameter(policyFile))); SecurityManagerTestUtils.install(); } @TearDown public void tearDown() { SecurityManagerTestUtils.remove(); } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 1, time = 1, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) public void test() { Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { Options opts = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opts).run(); } }
3,196
35.747126
101
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/separatecl/SeparateClassLoaderTest.java
/* * Copyright (c) 2021, Red Hat Inc. 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.separatecl; import org.junit.Test; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.net.URI; import java.net.URISyntaxException; import java.security.NoSuchAlgorithmException; import java.util.concurrent.TimeUnit; @State(Scope.Benchmark) public class SeparateClassLoaderTest { @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 1, time = 1, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) public void test() { Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { Options opts = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .jvmArgsAppend("-Djmh.separateClassLoader=true") .build(); new Runner(opts).run(); } }
2,284
35.269841
76
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/sharing/BenchmarkBenchSharingTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.sharing; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.TearDown; import org.openjdk.jmh.annotations.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.concurrent.TimeUnit; @State(Scope.Benchmark) public class BenchmarkBenchSharingTest { final Set<Thread> visitors = Collections.synchronizedSet(new HashSet<>()); @TearDown(Level.Trial) public void tearDown() { if (Fixtures.expectStableThreads()) { Assert.assertEquals(2, visitors.size()); } else { Assert.assertTrue(visitors.size() >= 2); } } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 2, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Threads(2) public void test() { Fixtures.work(); visitors.add(Thread.currentThread()); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opt).run(); } } }
3,163
34.954545
79
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/sharing/BenchmarkStateSharingTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.sharing; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.TearDown; import org.openjdk.jmh.annotations.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.concurrent.TimeUnit; public class BenchmarkStateSharingTest { @State(Scope.Benchmark) public static class MyState { final Set<Thread> visitors = Collections.synchronizedSet(new HashSet<>()); @TearDown(Level.Trial) public void tearDown() { if (Fixtures.expectStableThreads()) { Assert.assertEquals(2, visitors.size()); } else { Assert.assertTrue(visitors.size() >= 2); } } } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 2, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Threads(2) public void test(MyState s) { Fixtures.work(); s.visitors.add(Thread.currentThread()); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opt).run(); } } }
3,254
35.166667
82
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/sharing/GroupBenchSharingTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.sharing; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Group; import org.openjdk.jmh.annotations.GroupThreads; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.TearDown; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.concurrent.TimeUnit; @State(Scope.Group) public class GroupBenchSharingTest { final Set<Thread> visitors = Collections.synchronizedSet(new HashSet<>()); @TearDown(Level.Trial) public void tearDown() { if (Fixtures.expectStableThreads()) { Assert.assertEquals(4, visitors.size()); } else { Assert.assertTrue(visitors.size() >= 4); } } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 2, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Group("group1") @GroupThreads(2) public void test1() { Fixtures.work(); visitors.add(Thread.currentThread()); } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 2, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Group("group1") @GroupThreads(2) public void test2() { Fixtures.work(); visitors.add(Thread.currentThread()); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opt).run(); } } }
3,539
33.705882
79
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/sharing/GroupDefaultBenchSharingTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.sharing; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Group; import org.openjdk.jmh.annotations.GroupThreads; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.TearDown; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.concurrent.TimeUnit; @State(Scope.Group) public class GroupDefaultBenchSharingTest { final Set<Thread> visitors = Collections.synchronizedSet(new HashSet<>()); @TearDown(Level.Trial) public void tearDown() { if (Fixtures.expectStableThreads()) { Assert.assertEquals(2, visitors.size()); } else { Assert.assertTrue(visitors.size() >= 2); } } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 2, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Group("T") @GroupThreads(2) public void test() { Fixtures.work(); visitors.add(Thread.currentThread()); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opt).run(); } } }
3,230
34.9
79
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/sharing/GroupDefaultStateSharingTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.sharing; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Group; import org.openjdk.jmh.annotations.GroupThreads; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.TearDown; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.concurrent.TimeUnit; public class GroupDefaultStateSharingTest { @State(Scope.Group) public static class MyState { final Set<Thread> visitors = Collections.synchronizedSet(new HashSet<>()); @TearDown(Level.Trial) public void tearDown() { if (Fixtures.expectStableThreads()) { Assert.assertEquals(2, visitors.size()); } else { Assert.assertTrue(visitors.size() >= 2); } } } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 2, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Group("T") @GroupThreads(2) public void test(MyState s) { Fixtures.work(); s.visitors.add(Thread.currentThread()); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opt).run(); } } }
3,321
35.108696
82
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/sharing/GroupStateSharingTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.sharing; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Group; import org.openjdk.jmh.annotations.GroupThreads; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.TearDown; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.concurrent.TimeUnit; public class GroupStateSharingTest { @State(Scope.Group) public static class MyState { final Set<Thread> visitors = Collections.synchronizedSet(new HashSet<>()); @TearDown(Level.Trial) public void tearDown() { if (Fixtures.expectStableThreads()) { Assert.assertEquals(4, visitors.size()); } else { Assert.assertTrue(visitors.size() >= 4); } } } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 2, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Group("group1") @GroupThreads(2) public void test1(MyState s) { Fixtures.work(); s.visitors.add(Thread.currentThread()); } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 2, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Group("group1") @GroupThreads(2) public void test2(MyState s) { Fixtures.work(); s.visitors.add(Thread.currentThread()); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opt).run(); } } }
3,628
34.23301
82
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/sharing/ThreadBenchSharingTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.sharing; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.TearDown; import org.openjdk.jmh.annotations.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.concurrent.TimeUnit; @State(Scope.Thread) public class ThreadBenchSharingTest { final Set<Thread> visitors = Collections.synchronizedSet(new HashSet<>()); @TearDown(Level.Trial) public void tearDown() { if (Fixtures.expectStableThreads()) { Assert.assertEquals(1, visitors.size()); } else { Assert.assertTrue(visitors.size() >= 1); } } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 2, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Threads(2) public void test() { Fixtures.work(); visitors.add(Thread.currentThread()); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opt).run(); } } }
3,157
34.886364
79
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/sharing/ThreadStateSharingTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.sharing; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.TearDown; import org.openjdk.jmh.annotations.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.concurrent.TimeUnit; public class ThreadStateSharingTest { @State(Scope.Thread) public static class MyState { final Set<Thread> visitors = Collections.synchronizedSet(new HashSet<>()); @TearDown(Level.Trial) public void tearDown() { if (Fixtures.expectStableThreads()) { Assert.assertEquals(1, visitors.size()); } else { Assert.assertTrue(visitors.size() >= 1); } } } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 2, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Threads(2) public void test(MyState s) { Fixtures.work(); s.visitors.add(Thread.currentThread()); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opt).run(); } } }
3,248
35.1
82
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/synciter/SyncIterMeasurementOnlyTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.synciter; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.TimeUnit; @State(Scope.Benchmark) public class SyncIterMeasurementOnlyTest { @Benchmark @Warmup(iterations = 0) @Measurement(iterations = 2, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Threads(2) public void test() { Assert.assertTrue(isInMeasurementLoop()); Fixtures.work(); } private boolean isInMeasurementLoop() { boolean inMeasurementLoop = false; for (StackTraceElement element : new Exception().getStackTrace()) { inMeasurementLoop |= element.getMethodName().contains("jmhStub"); } return inMeasurementLoop; } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .syncIterations(false) .build(); new Runner(opt).run(); } } }
2,882
35.961538
79
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/synciter/SyncIterNotOnlyMeasurementTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.synciter; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; 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.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.TimeUnit; @State(Scope.Benchmark) public class SyncIterNotOnlyMeasurementTest { private boolean inMeasurementLoopOnly; @Setup(Level.Trial) public void setup() { inMeasurementLoopOnly = true; } @TearDown(Level.Trial) public void check() { Assert.assertFalse(inMeasurementLoopOnly); } @Benchmark @Warmup(iterations = 0) @Measurement(iterations = 2, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Threads(2) public void test() { inMeasurementLoopOnly &= isInMeasurementLoop(); Fixtures.work(); } private boolean isInMeasurementLoop() { boolean inMeasurementLoop = false; for (StackTraceElement element : new Exception().getStackTrace()) { inMeasurementLoop |= element.getMethodName().contains("jmhStub"); } return inMeasurementLoop; } @Test public void invokeAPI() throws RunnerException { // This test is probabilistic, and it can fail sometimes, but not all the time. Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .syncIterations(true) .build(); final int trials = 200; RunnerException last = null; for (int c = 0; c < trials; c++) { try { new Runner(opt).run(); // no assert, yay, we can break away now return; } catch (RunnerException e) { last = e; } } // we consistently throw exceptions, re-throw the last one throw last; } }
3,679
32.761468
87
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/threadparams/GroupThreadParamsStabilityTest.java
/* * Copyright (c) 2014, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.threadparams; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.infra.ThreadParams; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.TimeUnit; @BenchmarkMode(Mode.All) @Warmup(iterations = 5, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Measurement(iterations = 5, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) public class GroupThreadParamsStabilityTest { @State(Scope.Thread) public static class Data { ThreadParams last; void test(ThreadParams params) { if (last == null) { last = params; } else { // simple equality suffices Assert.assertEquals(last, params); } } } @Group("T") @Benchmark public void test1(ThreadParams tp, Data d) { d.test(tp); } @Group("T") @Benchmark public void test2(ThreadParams tp, Data d) { d.test(tp); } @Test public void test() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opt).run(); } } }
2,787
32.590361
79
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/threadparams/ThreadParamsStabilityTest.java
/* * Copyright (c) 2014, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.threadparams; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.infra.ThreadParams; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.TimeUnit; @BenchmarkMode(Mode.All) @Warmup(iterations = 5, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Measurement(iterations = 5, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) public class ThreadParamsStabilityTest { @State(Scope.Thread) public static class Data { ThreadParams last; void test(ThreadParams params) { if (last == null) { last = params; } else { // simple equality suffices Assert.assertEquals(last, params); } } } @Benchmark public void test1(ThreadParams tp, Data d) { d.test(tp); } @Test public void test() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opt).run(); } } }
2,659
34
79
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/threads/BenchmarkBenchSameThreadTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.threads; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; 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.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.concurrent.TimeUnit; /** * Tests if harness executes setup, run, and tearDown in the same workers. */ @State(Scope.Benchmark) public class BenchmarkBenchSameThreadTest { private final Set<Thread> setupRunThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> setupIterationThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> setupInvocationThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> teardownRunThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> teardownIterationThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> teardownInvocationThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> testInvocationThread = Collections.synchronizedSet(new HashSet<>()); @Setup(Level.Trial) public void setupRun() { setupRunThread.add(Thread.currentThread()); } @Setup(Level.Iteration) public void setupIteration() { setupIterationThread.add(Thread.currentThread()); } @Setup(Level.Invocation) public void setupInvocation() { setupInvocationThread.add(Thread.currentThread()); } @TearDown(Level.Trial) public void tearDownRun() { teardownRunThread.add(Thread.currentThread()); } @TearDown(Level.Iteration) public void tearDownIteration() { teardownIterationThread.add(Thread.currentThread()); } @TearDown(Level.Invocation) public void tearDownInvocation() { teardownInvocationThread.add(Thread.currentThread()); } @TearDown(Level.Trial) public void teardownZZZ() { // should perform last Assert.assertFalse("Test sanity", testInvocationThread.isEmpty()); Assert.assertTrue("test <: setupRun", testInvocationThread.containsAll(setupRunThread)); Assert.assertTrue("test <: setupIteration", testInvocationThread.containsAll(setupIterationThread)); Assert.assertTrue("test <: setupInvocation", testInvocationThread.containsAll(setupInvocationThread)); Assert.assertTrue("test <: teardownRun", testInvocationThread.containsAll(teardownRunThread)); Assert.assertTrue("test <: teardownIteration", testInvocationThread.containsAll(teardownIterationThread)); Assert.assertTrue("test <: teardownInvocation", testInvocationThread.containsAll(teardownInvocationThread)); } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 5, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Threads(4) public void test() { testInvocationThread.add(Thread.currentThread()); Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opt).run(); } } }
5,259
39.461538
116
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/threads/BenchmarkStateSameThreadTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.threads; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; 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.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.concurrent.TimeUnit; /** * Tests if harness executes setup, run, and tearDown in the same workers. */ public class BenchmarkStateSameThreadTest { @State(Scope.Benchmark) public static class MyState { private final Set<Thread> setupRunThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> setupIterationThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> setupInvocationThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> teardownRunThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> teardownIterationThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> teardownInvocationThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> testInvocationThread = Collections.synchronizedSet(new HashSet<>()); @Setup(Level.Trial) public void setupRun() { setupRunThread.add(Thread.currentThread()); } @Setup(Level.Iteration) public void setupIteration() { setupIterationThread.add(Thread.currentThread()); } @Setup(Level.Invocation) public void setupInvocation() { setupInvocationThread.add(Thread.currentThread()); } @TearDown(Level.Trial) public void tearDownRun() { teardownRunThread.add(Thread.currentThread()); } @TearDown(Level.Iteration) public void tearDownIteration() { teardownIterationThread.add(Thread.currentThread()); } @TearDown(Level.Invocation) public void tearDownInvocation() { teardownInvocationThread.add(Thread.currentThread()); } @TearDown(Level.Trial) public void teardownZZZ() { // should perform last Assert.assertFalse("Test sanity", testInvocationThread.isEmpty()); Assert.assertTrue("test <: setupRun", testInvocationThread.containsAll(setupRunThread)); Assert.assertTrue("test <: setupIteration", testInvocationThread.containsAll(setupIterationThread)); Assert.assertTrue("test <: setupInvocation", testInvocationThread.containsAll(setupInvocationThread)); Assert.assertTrue("test <: teardownRun", testInvocationThread.containsAll(teardownRunThread)); Assert.assertTrue("test <: teardownIteration", testInvocationThread.containsAll(teardownIterationThread)); Assert.assertTrue("test <: teardownInvocation", testInvocationThread.containsAll(teardownInvocationThread)); } } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 5, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Threads(4) public void test(MyState state) { state.testInvocationThread.add(Thread.currentThread()); Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opt).run(); } } }
5,487
40.263158
120
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/threads/GroupBenchSameThreadTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.threads; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Group; import org.openjdk.jmh.annotations.GroupThreads; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; 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 org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.concurrent.TimeUnit; /** * Tests if harness executes setup, run, and tearDown in the same workers. */ @State(Scope.Group) public class GroupBenchSameThreadTest { private final Set<Thread> setupRunThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> setupIterationThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> setupInvocationThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> teardownRunThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> teardownIterationThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> teardownInvocationThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> testInvocationThread = Collections.synchronizedSet(new HashSet<>()); @Setup(Level.Trial) public void setupRun() { setupRunThread.add(Thread.currentThread()); } @Setup(Level.Iteration) public void setupIteration() { setupIterationThread.add(Thread.currentThread()); } @Setup(Level.Invocation) public void setupInvocation() { setupInvocationThread.add(Thread.currentThread()); } @TearDown(Level.Trial) public void tearDownRun() { teardownRunThread.add(Thread.currentThread()); } @TearDown(Level.Iteration) public void tearDownIteration() { teardownIterationThread.add(Thread.currentThread()); } @TearDown(Level.Invocation) public void tearDownInvocation() { teardownInvocationThread.add(Thread.currentThread()); } @TearDown(Level.Trial) public void teardownZZZ() { // should perform last Assert.assertFalse("Test sanity", testInvocationThread.isEmpty()); Assert.assertTrue("test <: setupRun", testInvocationThread.containsAll(setupRunThread)); Assert.assertTrue("test <: setupIteration", testInvocationThread.containsAll(setupIterationThread)); Assert.assertTrue("test <: setupInvocation", testInvocationThread.containsAll(setupInvocationThread)); Assert.assertTrue("test <: teardownRun", testInvocationThread.containsAll(teardownRunThread)); Assert.assertTrue("test <: teardownIteration", testInvocationThread.containsAll(teardownIterationThread)); Assert.assertTrue("test <: teardownInvocation", testInvocationThread.containsAll(teardownInvocationThread)); } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 5, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Group("T") @GroupThreads(4) public void test() { testInvocationThread.add(Thread.currentThread()); Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opt).run(); } } }
5,319
39.30303
116
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/threads/GroupStateSameThreadTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.threads; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Group; import org.openjdk.jmh.annotations.GroupThreads; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; 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 org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.concurrent.TimeUnit; /** * Tests if harness executes setup, run, and tearDown in the same workers. */ public class GroupStateSameThreadTest { @State(Scope.Group) public static class MyState { private final Set<Thread> setupRunThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> setupIterationThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> setupInvocationThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> teardownRunThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> teardownIterationThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> teardownInvocationThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> testInvocationThread = Collections.synchronizedSet(new HashSet<>()); @Setup(Level.Trial) public void setupRun() { setupRunThread.add(Thread.currentThread()); } @Setup(Level.Iteration) public void setupIteration() { setupIterationThread.add(Thread.currentThread()); } @Setup(Level.Invocation) public void setupInvocation() { setupInvocationThread.add(Thread.currentThread()); } @TearDown(Level.Trial) public void tearDownRun() { teardownRunThread.add(Thread.currentThread()); } @TearDown(Level.Iteration) public void tearDownIteration() { teardownIterationThread.add(Thread.currentThread()); } @TearDown(Level.Invocation) public void tearDownInvocation() { teardownInvocationThread.add(Thread.currentThread()); } @TearDown(Level.Trial) public void teardownZZZ() { // should perform last Assert.assertFalse("Test sanity", testInvocationThread.isEmpty()); Assert.assertTrue("test <: setupRun", testInvocationThread.containsAll(setupRunThread)); Assert.assertTrue("test <: setupIteration", testInvocationThread.containsAll(setupIterationThread)); Assert.assertTrue("test <: setupInvocation", testInvocationThread.containsAll(setupInvocationThread)); Assert.assertTrue("test <: teardownRun", testInvocationThread.containsAll(teardownRunThread)); Assert.assertTrue("test <: teardownIteration", testInvocationThread.containsAll(teardownIterationThread)); Assert.assertTrue("test <: teardownInvocation", testInvocationThread.containsAll(teardownInvocationThread)); } } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 5, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Group("T") @GroupThreads(4) public void test(MyState state) { state.testInvocationThread.add(Thread.currentThread()); Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opt).run(); } } }
5,547
40.096296
120
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/threads/GroupThreadGroupOrderTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.threads; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.concurrent.TimeUnit; /** * Tests if harness executes setup, run, and tearDown in the same workers. */ @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 5, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @State(Scope.Group) public class GroupThreadGroupOrderTest { private final Set<Thread> abc = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> def = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> ghi = Collections.synchronizedSet(new HashSet<>()); @Setup(Level.Iteration) public void prepare() { abc.clear(); def.clear(); ghi.clear(); } @TearDown(Level.Iteration) public void verify() { Assert.assertEquals("Test abc", 3, abc.size()); Assert.assertEquals("Test def", 1, def.size()); Assert.assertEquals("Test ghi", 2, ghi.size()); } @Benchmark @Group("T") public void abc() { abc.add(Thread.currentThread()); Fixtures.work(); } @Benchmark @Group("T") public void ghi() { ghi.add(Thread.currentThread()); Fixtures.work(); } @Benchmark @Group("T") public void def() { def.add(Thread.currentThread()); Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .threadGroups(3, 1, 2) .shouldFailOnError(true) .build(); new Runner(opt).run(); } } }
3,357
31.601942
81
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/threads/MaxThreadCountTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.threads; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.TearDown; import org.openjdk.jmh.annotations.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.concurrent.TimeUnit; @BenchmarkMode(Mode.All) @State(Scope.Benchmark) public class MaxThreadCountTest { private final Set<Thread> threads = Collections.synchronizedSet(new HashSet<>()); @TearDown(Level.Iteration) public void tearDown() { if (Fixtures.expectStableThreads()) { Assert.assertEquals(threads.size(), Runtime.getRuntime().availableProcessors()); } else { Assert.assertTrue(threads.size() >= Runtime.getRuntime().availableProcessors()); } } @Benchmark @Measurement(iterations = 1, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Warmup(iterations = 0) @Fork(1) @Threads(Threads.MAX) public void test1() { threads.add(Thread.currentThread()); Fixtures.work(); } @Benchmark @Measurement(iterations = 1, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Warmup(iterations = 0) @Fork(1) public void test2() { threads.add(Thread.currentThread()); Fixtures.work(); } @Test public void invokeAPI_1() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass()) + ".*test1") .shouldFailOnError(true) .build(); new Runner(opt).run(); } } @Test public void invokeAPI_2() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass()) + ".*test2") .shouldFailOnError(true) .threads(Threads.MAX) .build(); new Runner(opt).run(); } } }
3,928
35.37963
92
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/threads/OneThreadCountTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.threads; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.TearDown; import org.openjdk.jmh.annotations.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.concurrent.TimeUnit; @BenchmarkMode(Mode.All) @State(Scope.Benchmark) public class OneThreadCountTest { private final Set<Thread> threads = Collections.synchronizedSet(new HashSet<>()); @TearDown(Level.Iteration) public void tearDown() { if (Fixtures.expectStableThreads()) { Assert.assertEquals(1, threads.size()); } else { Assert.assertTrue(threads.size() >= 1); } } @Benchmark @Measurement(iterations = 1, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Warmup(iterations = 0) @Fork(1) @Threads(1) public void test1() { threads.add(Thread.currentThread()); Fixtures.work(); } @Benchmark @Measurement(iterations = 1, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Warmup(iterations = 0) @Fork(1) public void test2() { threads.add(Thread.currentThread()); Fixtures.work(); } @Test public void invokeAPI_1() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass()) + ".*test1") .shouldFailOnError(true) .build(); new Runner(opt).run(); } } @Test public void invokeAPI_2() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass()) + ".*test2") .shouldFailOnError(true) .threads(1) .build(); new Runner(opt).run(); } } }
3,827
34.119266
85
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/threads/ThreadBenchSameThreadTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.threads; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; 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.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.concurrent.TimeUnit; /** * Tests if harness executes setup, run, and tearDown in the same workers. */ @State(Scope.Thread) public class ThreadBenchSameThreadTest { private final Set<Thread> setupRunThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> setupIterationThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> setupInvocationThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> teardownRunThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> teardownIterationThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> teardownInvocationThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> testInvocationThread = Collections.synchronizedSet(new HashSet<>()); @Setup(Level.Trial) public void setupRun() { setupRunThread.add(Thread.currentThread()); } @Setup(Level.Iteration) public void setupIteration() { setupIterationThread.add(Thread.currentThread()); } @Setup(Level.Invocation) public void setupInvocation() { setupInvocationThread.add(Thread.currentThread()); } @TearDown(Level.Trial) public void tearDownRun() { teardownRunThread.add(Thread.currentThread()); // Threads can change iteration to iteration if (Fixtures.expectStableThreads()) { Assert.assertEquals("test == setupRun", testInvocationThread, setupRunThread); Assert.assertEquals("test == teardownRun", testInvocationThread, teardownRunThread); } else { Assert.assertTrue("test <: setupRun", testInvocationThread.containsAll(setupRunThread)); Assert.assertTrue("test <: teardownRunThread", testInvocationThread.containsAll(teardownRunThread)); } } @TearDown(Level.Iteration) public void tearDownIteration() { teardownIterationThread.add(Thread.currentThread()); // Within iteration, expect the same thread Assert.assertEquals("test == setupIteration", testInvocationThread, setupIterationThread); Assert.assertEquals("test == teardownIteration", testInvocationThread, teardownIterationThread); Assert.assertEquals("test == setupInvocation", testInvocationThread, setupInvocationThread); Assert.assertEquals("test == teardownInvocation", testInvocationThread, teardownInvocationThread); } @TearDown(Level.Invocation) public void tearDownInvocation() { teardownInvocationThread.add(Thread.currentThread()); } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 5, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Threads(4) public void test() { testInvocationThread.add(Thread.currentThread()); Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opt).run(); } } }
5,457
39.731343
113
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/threads/ThreadStateSameThreadTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.threads; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; 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.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.concurrent.TimeUnit; /** * Tests if harness executes setup, run, and tearDown in the same workers. */ public class ThreadStateSameThreadTest { @State(Scope.Thread) public static class MyState { private final Set<Thread> setupRunThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> setupIterationThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> setupInvocationThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> teardownRunThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> teardownIterationThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> teardownInvocationThread = Collections.synchronizedSet(new HashSet<>()); private final Set<Thread> testInvocationThread = Collections.synchronizedSet(new HashSet<>()); @Setup(Level.Trial) public void setupRun() { setupRunThread.add(Thread.currentThread()); } @Setup(Level.Iteration) public void setupIteration() { setupIterationThread.add(Thread.currentThread()); } @Setup(Level.Invocation) public void setupInvocation() { setupInvocationThread.add(Thread.currentThread()); } @TearDown(Level.Trial) public void tearDownRun() { teardownRunThread.add(Thread.currentThread()); // Threads can change iteration to iteration if (Fixtures.expectStableThreads()) { Assert.assertEquals("test == setupRun", testInvocationThread, setupRunThread); Assert.assertEquals("test == teardownRun", testInvocationThread, teardownRunThread); } else { Assert.assertTrue("test <: setupRun", testInvocationThread.containsAll(setupRunThread)); Assert.assertTrue("test <: teardownRunThread", testInvocationThread.containsAll(teardownRunThread)); } } @TearDown(Level.Iteration) public void tearDownIteration() { teardownIterationThread.add(Thread.currentThread()); // Within iteration, expect the same thread Assert.assertEquals("test == setupIteration", testInvocationThread, setupIterationThread); Assert.assertEquals("test == teardownIteration", testInvocationThread, teardownIterationThread); Assert.assertEquals("test == setupInvocation", testInvocationThread, setupInvocationThread); Assert.assertEquals("test == teardownInvocation", testInvocationThread, teardownInvocationThread); } @TearDown(Level.Invocation) public void tearDownInvocation() { teardownInvocationThread.add(Thread.currentThread()); } } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 5, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Threads(4) public void test(MyState state) { state.testInvocationThread.add(Thread.currentThread()); Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opt).run(); } } }
5,697
40.591241
117
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/threads/TwoThreadCountTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.threads; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.TearDown; import org.openjdk.jmh.annotations.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.concurrent.TimeUnit; @BenchmarkMode(Mode.All) @State(Scope.Benchmark) public class TwoThreadCountTest { private final Set<Thread> threads = Collections.synchronizedSet(new HashSet<>()); @TearDown(Level.Iteration) public void tearDown() { if (Fixtures.expectStableThreads()) { Assert.assertEquals(2, threads.size()); } else { Assert.assertTrue(threads.size() >= 2); } } @Benchmark @Measurement(iterations = 1, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Warmup(iterations = 0) @Fork(1) @Threads(2) public void test1() { threads.add(Thread.currentThread()); Fixtures.work(); } @Benchmark @Measurement(iterations = 1, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Warmup(iterations = 0) @Fork(1) public void test2() { threads.add(Thread.currentThread()); Fixtures.work(); } @Test public void invokeAPI_1() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass()) + ".*test1") .shouldFailOnError(true) .build(); new Runner(opt).run(); } } @Test public void invokeAPI_2() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass()) + ".*test2") .shouldFailOnError(true) .threads(2) .build(); new Runner(opt).run(); } } }
3,827
34.119266
85
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/times/BenchmarkBenchHelperTimesTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.times; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; 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.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @State(Scope.Benchmark) public class BenchmarkBenchHelperTimesTest { private final AtomicInteger countInvocations = new AtomicInteger(); private final AtomicInteger countSetupRun1 = new AtomicInteger(); private final AtomicInteger countSetupRun2 = new AtomicInteger(); private final AtomicInteger countSetupIteration1 = new AtomicInteger(); private final AtomicInteger countSetupIteration2 = new AtomicInteger(); private final AtomicInteger countSetupInvocation1 = new AtomicInteger(); private final AtomicInteger countSetupInvocation2 = new AtomicInteger(); private final AtomicInteger countTearDownRun1 = new AtomicInteger(); private final AtomicInteger countTearDownRun2 = new AtomicInteger(); private final AtomicInteger countTearDownIteration1 = new AtomicInteger(); private final AtomicInteger countTearDownIteration2 = new AtomicInteger(); private final AtomicInteger countTearDownInvocation1 = new AtomicInteger(); private final AtomicInteger countTearDownInvocation2 = new AtomicInteger(); @Setup(Level.Trial) public void setup1() { countSetupRun1.incrementAndGet(); } @Setup(Level.Trial) public void setup2() { countSetupRun2.incrementAndGet(); } @Setup(Level.Iteration) public void setup3() { countSetupIteration1.incrementAndGet(); } @Setup(Level.Iteration) public void setup4() { countSetupIteration2.incrementAndGet(); } @Setup(Level.Invocation) public void setup5() { countSetupInvocation1.incrementAndGet(); } @Setup(Level.Invocation) public void setup6() { countSetupInvocation2.incrementAndGet(); } @TearDown(Level.Trial) public void tearDown1() { countTearDownRun1.incrementAndGet(); } @TearDown(Level.Trial) public void tearDown2() { countTearDownRun2.incrementAndGet(); } @TearDown(Level.Iteration) public void tearDown3() { countTearDownIteration1.incrementAndGet(); } @TearDown(Level.Iteration) public void tearDown4() { countTearDownIteration2.incrementAndGet(); } @TearDown(Level.Invocation) public void tearDown5() { countTearDownInvocation1.incrementAndGet(); } @TearDown(Level.Invocation) public void tearDown6() { countTearDownInvocation2.incrementAndGet(); } @TearDown(Level.Trial) public void tearDownLATEST() { // this name ensures this is the latest teardown to run Assert.assertEquals("Setup1 called once", 1, countSetupRun1.get()); Assert.assertEquals("Setup2 called once", 1, countSetupRun2.get()); Assert.assertEquals("Setup3 called twice", 2, countSetupIteration1.get()); Assert.assertEquals("Setup4 called twice", 2, countSetupIteration2.get()); // These asserts make no sense for Benchmark tests // Assert.assertEquals("Setup5 = invocation count", countInvocations.get(), countSetupInvocation1.get()); // Assert.assertEquals("Setup6 = invocation count", countInvocations.get(), countSetupInvocation2.get()); Assert.assertEquals("TearDown1 called once", 1, countTearDownRun1.get()); Assert.assertEquals("TearDown2 called once", 1, countTearDownRun2.get()); Assert.assertEquals("TearDown3 called twice", 2, countTearDownIteration1.get()); Assert.assertEquals("TearDown4 called twice", 2, countTearDownIteration2.get()); // These two asserts make no sense for Benchmark tests. // Assert.assertEquals("TearDown5 = invocation count", countInvocations.get(), countTearDownInvocation1.get()); // Assert.assertEquals("TearDown6 = invocation count", countInvocations.get(), countTearDownInvocation2.get()); } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 2, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Threads(2) public void test() { Fixtures.work(); countInvocations.incrementAndGet(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .build(); new Runner(opt).run(); } } }
6,510
37.3
118
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/times/BenchmarkStateHelperTimesTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.times; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; 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.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; public class BenchmarkStateHelperTimesTest { @State(Scope.Benchmark) public static class MyState { private final AtomicInteger countInvocations = new AtomicInteger(); private final AtomicInteger countSetupRun1 = new AtomicInteger(); private final AtomicInteger countSetupRun2 = new AtomicInteger(); private final AtomicInteger countSetupIteration1 = new AtomicInteger(); private final AtomicInteger countSetupIteration2 = new AtomicInteger(); private final AtomicInteger countSetupInvocation1 = new AtomicInteger(); private final AtomicInteger countSetupInvocation2 = new AtomicInteger(); private final AtomicInteger countTearDownRun1 = new AtomicInteger(); private final AtomicInteger countTearDownRun2 = new AtomicInteger(); private final AtomicInteger countTearDownIteration1 = new AtomicInteger(); private final AtomicInteger countTearDownIteration2 = new AtomicInteger(); private final AtomicInteger countTearDownInvocation1 = new AtomicInteger(); private final AtomicInteger countTearDownInvocation2 = new AtomicInteger(); @Setup(Level.Trial) public void setup1() { countSetupRun1.incrementAndGet(); } @Setup(Level.Trial) public void setup2() { countSetupRun2.incrementAndGet(); } @Setup(Level.Iteration) public void setup3() { countSetupIteration1.incrementAndGet(); } @Setup(Level.Iteration) public void setup4() { countSetupIteration2.incrementAndGet(); } @Setup(Level.Invocation) public void setup5() { countSetupInvocation1.incrementAndGet(); } @Setup(Level.Invocation) public void setup6() { countSetupInvocation2.incrementAndGet(); } @TearDown(Level.Trial) public void tearDown1() { countTearDownRun1.incrementAndGet(); } @TearDown(Level.Trial) public void tearDown2() { countTearDownRun2.incrementAndGet(); } @TearDown(Level.Iteration) public void tearDown3() { countTearDownIteration1.incrementAndGet(); } @TearDown(Level.Iteration) public void tearDown4() { countTearDownIteration2.incrementAndGet(); } @TearDown(Level.Invocation) public void tearDown5() { countTearDownInvocation1.incrementAndGet(); } @TearDown(Level.Invocation) public void tearDown6() { countTearDownInvocation2.incrementAndGet(); } @TearDown(Level.Trial) public void tearDownLATEST() { // this name ensures this is the latest teardown to run Assert.assertEquals("Setup1 called once", 1, countSetupRun1.get()); Assert.assertEquals("Setup2 called once", 1, countSetupRun2.get()); Assert.assertEquals("Setup3 called twice", 2, countSetupIteration1.get()); Assert.assertEquals("Setup4 called twice", 2, countSetupIteration2.get()); // These asserts make no sense for Benchmark tests // Assert.assertEquals("Setup5 = invocation count", countInvocations.get(), countSetupInvocation1.get()); // Assert.assertEquals("Setup6 = invocation count", countInvocations.get(), countSetupInvocation2.get()); Assert.assertEquals("TearDown1 called once", 1, countTearDownRun1.get()); Assert.assertEquals("TearDown2 called once", 1, countTearDownRun2.get()); Assert.assertEquals("TearDown3 called twice", 2, countTearDownIteration1.get()); Assert.assertEquals("TearDown4 called twice", 2, countTearDownIteration2.get()); // These two asserts make no sense for Benchmark tests. // Assert.assertEquals("TearDown5 = invocation count", countInvocations.get(), countTearDownInvocation1.get()); // Assert.assertEquals("TearDown6 = invocation count", countInvocations.get(), countTearDownInvocation2.get()); } } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 2, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Threads(2) public void test(MyState state) { Fixtures.work(); state.countInvocations.incrementAndGet(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opt).run(); } } }
6,932
38.617143
122
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/times/GroupBenchHelperTimesTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.times; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Group; import org.openjdk.jmh.annotations.GroupThreads; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; 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 org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @State(Scope.Group) public class GroupBenchHelperTimesTest { private final AtomicInteger countInvocations = new AtomicInteger(); private final AtomicInteger countSetupRun1 = new AtomicInteger(); private final AtomicInteger countSetupRun2 = new AtomicInteger(); private final AtomicInteger countSetupIteration1 = new AtomicInteger(); private final AtomicInteger countSetupIteration2 = new AtomicInteger(); private final AtomicInteger countSetupInvocation1 = new AtomicInteger(); private final AtomicInteger countSetupInvocation2 = new AtomicInteger(); private final AtomicInteger countTearDownRun1 = new AtomicInteger(); private final AtomicInteger countTearDownRun2 = new AtomicInteger(); private final AtomicInteger countTearDownIteration1 = new AtomicInteger(); private final AtomicInteger countTearDownIteration2 = new AtomicInteger(); private final AtomicInteger countTearDownInvocation1 = new AtomicInteger(); private final AtomicInteger countTearDownInvocation2 = new AtomicInteger(); @Setup(Level.Trial) public void setup1() { countSetupRun1.incrementAndGet(); } @Setup(Level.Trial) public void setup2() { countSetupRun2.incrementAndGet(); } @Setup(Level.Iteration) public void setup3() { countSetupIteration1.incrementAndGet(); } @Setup(Level.Iteration) public void setup4() { countSetupIteration2.incrementAndGet(); } @Setup(Level.Invocation) public void setup5() { countSetupInvocation1.incrementAndGet(); } @Setup(Level.Invocation) public void setup6() { countSetupInvocation2.incrementAndGet(); } @TearDown(Level.Trial) public void tearDown1() { countTearDownRun1.incrementAndGet(); } @TearDown(Level.Trial) public void tearDown2() { countTearDownRun2.incrementAndGet(); } @TearDown(Level.Iteration) public void tearDown3() { countTearDownIteration1.incrementAndGet(); } @TearDown(Level.Iteration) public void tearDown4() { countTearDownIteration2.incrementAndGet(); } @TearDown(Level.Invocation) public void tearDown5() { countTearDownInvocation1.incrementAndGet(); } @TearDown(Level.Invocation) public void tearDown6() { countTearDownInvocation2.incrementAndGet(); } @TearDown(Level.Trial) public void tearDownLATEST() { // this name ensures this is the latest teardown to run Assert.assertEquals("Setup1 called once", 1, countSetupRun1.get()); Assert.assertEquals("Setup2 called once", 1, countSetupRun2.get()); Assert.assertEquals("Setup3 called twice", 2, countSetupIteration1.get()); Assert.assertEquals("Setup4 called twice", 2, countSetupIteration2.get()); // These asserts make no sense for Benchmark tests // Assert.assertEquals("Setup5 = invocation count", countInvocations.get(), countSetupInvocation1.get()); // Assert.assertEquals("Setup6 = invocation count", countInvocations.get(), countSetupInvocation2.get()); Assert.assertEquals("TearDown1 called once", 1, countTearDownRun1.get()); Assert.assertEquals("TearDown2 called once", 1, countTearDownRun2.get()); Assert.assertEquals("TearDown3 called twice", 2, countTearDownIteration1.get()); Assert.assertEquals("TearDown4 called twice", 2, countTearDownIteration2.get()); // These two asserts make no sense for Benchmark tests. // Assert.assertEquals("TearDown5 = invocation count", countInvocations.get(), countTearDownInvocation1.get()); // Assert.assertEquals("TearDown6 = invocation count", countInvocations.get(), countTearDownInvocation2.get()); } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 2, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Group("T") @GroupThreads(2) public void test() { Fixtures.work(); countInvocations.incrementAndGet(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opt).run(); } } }
6,615
37.242775
118
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/times/GroupStateHelperTimesTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.times; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Group; import org.openjdk.jmh.annotations.GroupThreads; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; 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 org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; public class GroupStateHelperTimesTest { @State(Scope.Group) public static class MyState { private final AtomicInteger countInvocations = new AtomicInteger(); private final AtomicInteger countSetupRun1 = new AtomicInteger(); private final AtomicInteger countSetupRun2 = new AtomicInteger(); private final AtomicInteger countSetupIteration1 = new AtomicInteger(); private final AtomicInteger countSetupIteration2 = new AtomicInteger(); private final AtomicInteger countSetupInvocation1 = new AtomicInteger(); private final AtomicInteger countSetupInvocation2 = new AtomicInteger(); private final AtomicInteger countTearDownRun1 = new AtomicInteger(); private final AtomicInteger countTearDownRun2 = new AtomicInteger(); private final AtomicInteger countTearDownIteration1 = new AtomicInteger(); private final AtomicInteger countTearDownIteration2 = new AtomicInteger(); private final AtomicInteger countTearDownInvocation1 = new AtomicInteger(); private final AtomicInteger countTearDownInvocation2 = new AtomicInteger(); @Setup(Level.Trial) public void setup1() { countSetupRun1.incrementAndGet(); } @Setup(Level.Trial) public void setup2() { countSetupRun2.incrementAndGet(); } @Setup(Level.Iteration) public void setup3() { countSetupIteration1.incrementAndGet(); } @Setup(Level.Iteration) public void setup4() { countSetupIteration2.incrementAndGet(); } @Setup(Level.Invocation) public void setup5() { countSetupInvocation1.incrementAndGet(); } @Setup(Level.Invocation) public void setup6() { countSetupInvocation2.incrementAndGet(); } @TearDown(Level.Trial) public void tearDown1() { countTearDownRun1.incrementAndGet(); } @TearDown(Level.Trial) public void tearDown2() { countTearDownRun2.incrementAndGet(); } @TearDown(Level.Iteration) public void tearDown3() { countTearDownIteration1.incrementAndGet(); } @TearDown(Level.Iteration) public void tearDown4() { countTearDownIteration2.incrementAndGet(); } @TearDown(Level.Invocation) public void tearDown5() { countTearDownInvocation1.incrementAndGet(); } @TearDown(Level.Invocation) public void tearDown6() { countTearDownInvocation2.incrementAndGet(); } @TearDown(Level.Trial) public void tearDownLATEST() { // this name ensures this is the latest teardown to run Assert.assertEquals("Setup1 called once", 1, countSetupRun1.get()); Assert.assertEquals("Setup2 called once", 1, countSetupRun2.get()); Assert.assertEquals("Setup3 called twice", 2, countSetupIteration1.get()); Assert.assertEquals("Setup4 called twice", 2, countSetupIteration2.get()); // These asserts make no sense for Benchmark tests // Assert.assertEquals("Setup5 = invocation count", countInvocations.get(), countSetupInvocation1.get()); // Assert.assertEquals("Setup6 = invocation count", countInvocations.get(), countSetupInvocation2.get()); Assert.assertEquals("TearDown1 called once", 1, countTearDownRun1.get()); Assert.assertEquals("TearDown2 called once", 1, countTearDownRun2.get()); Assert.assertEquals("TearDown3 called twice", 2, countTearDownIteration1.get()); Assert.assertEquals("TearDown4 called twice", 2, countTearDownIteration2.get()); // These two asserts make no sense for Benchmark tests. // Assert.assertEquals("TearDown5 = invocation count", countInvocations.get(), countTearDownInvocation1.get()); // Assert.assertEquals("TearDown6 = invocation count", countInvocations.get(), countTearDownInvocation2.get()); } } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 2, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Group("T") @GroupThreads(2) public void test(MyState state) { Fixtures.work(); state.countInvocations.incrementAndGet(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opt).run(); } } }
6,992
38.508475
122
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/times/GroupThreadStateHelperTimesTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.times; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; /** * Tests if harness executes setup, run, and tearDown in the same workers. */ @BenchmarkMode(Mode.All) @Warmup(iterations = 5, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Measurement(iterations = 5, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @State(Scope.Benchmark) public class GroupThreadStateHelperTimesTest { @State(Scope.Thread) public static class State1 { static final AtomicInteger setupTimes = new AtomicInteger(); static final AtomicInteger tearDownTimes = new AtomicInteger(); @Setup public void setup() { setupTimes.incrementAndGet(); } @Setup public void tearDown() { tearDownTimes.incrementAndGet(); } } @State(Scope.Thread) public static class State2 { static final AtomicInteger setupTimes = new AtomicInteger(); static final AtomicInteger tearDownTimes = new AtomicInteger(); @Setup public void setup() { setupTimes.incrementAndGet(); } @Setup public void tearDown() { tearDownTimes.incrementAndGet(); } } @Setup public void reset() { State1.setupTimes.set(0); State1.tearDownTimes.set(0); State2.setupTimes.set(0); State2.tearDownTimes.set(0); } @TearDown public void verify() { Assert.assertEquals(1, State1.setupTimes.get()); Assert.assertEquals(1, State1.tearDownTimes.get()); Assert.assertEquals(1, State2.setupTimes.get()); Assert.assertEquals(1, State2.tearDownTimes.get()); } @Benchmark @Group("T") public void test1(State1 state1) { Fixtures.work(); } @Benchmark @Group("T") public void test2(State2 state2) { Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opt).run(); } } }
3,839
30.735537
79
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/times/ThreadBenchHelperTimesTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.times; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; 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.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @State(Scope.Thread) public class ThreadBenchHelperTimesTest { private final AtomicInteger countInvocations = new AtomicInteger(); private final AtomicInteger countSetupRun1 = new AtomicInteger(); private final AtomicInteger countSetupRun2 = new AtomicInteger(); private final AtomicInteger countSetupIteration1 = new AtomicInteger(); private final AtomicInteger countSetupIteration2 = new AtomicInteger(); private final AtomicInteger countSetupInvocation1 = new AtomicInteger(); private final AtomicInteger countSetupInvocation2 = new AtomicInteger(); private final AtomicInteger countTearDownRun1 = new AtomicInteger(); private final AtomicInteger countTearDownRun2 = new AtomicInteger(); private final AtomicInteger countTearDownIteration1 = new AtomicInteger(); private final AtomicInteger countTearDownIteration2 = new AtomicInteger(); private final AtomicInteger countTearDownInvocation1 = new AtomicInteger(); private final AtomicInteger countTearDownInvocation2 = new AtomicInteger(); @Setup(Level.Trial) public void setup1() { countSetupRun1.incrementAndGet(); } @Setup(Level.Trial) public void setup2() { countSetupRun2.incrementAndGet(); } @Setup(Level.Iteration) public void setup3() { countSetupIteration1.incrementAndGet(); } @Setup(Level.Iteration) public void setup4() { countSetupIteration2.incrementAndGet(); } @Setup(Level.Invocation) public void setup5() { countSetupInvocation1.incrementAndGet(); } @Setup(Level.Invocation) public void setup6() { countSetupInvocation2.incrementAndGet(); } @TearDown(Level.Trial) public void tearDown1() { countTearDownRun1.incrementAndGet(); } @TearDown(Level.Trial) public void tearDown2() { countTearDownRun2.incrementAndGet(); } @TearDown(Level.Iteration) public void tearDown3() { countTearDownIteration1.incrementAndGet(); } @TearDown(Level.Iteration) public void tearDown4() { countTearDownIteration2.incrementAndGet(); } @TearDown(Level.Invocation) public void tearDown5() { countTearDownInvocation1.incrementAndGet(); } @TearDown(Level.Invocation) public void tearDown6() { countTearDownInvocation2.incrementAndGet(); } @TearDown(Level.Trial) public void tearDownLATEST() { // this name ensures this is the latest teardown to run Assert.assertEquals("Setup1 called once", 1, countSetupRun1.get()); Assert.assertEquals("Setup2 called once", 1, countSetupRun2.get()); Assert.assertEquals("Setup3 called twice", 2, countSetupIteration1.get()); Assert.assertEquals("Setup4 called twice", 2, countSetupIteration2.get()); Assert.assertEquals("Setup5 = invocation count", countInvocations.get(), countSetupInvocation1.get()); Assert.assertEquals("Setup6 = invocation count", countInvocations.get(), countSetupInvocation2.get()); Assert.assertEquals("TearDown1 called once", 1, countTearDownRun1.get()); Assert.assertEquals("TearDown2 called once", 1, countTearDownRun2.get()); Assert.assertEquals("TearDown3 called twice", 2, countTearDownIteration1.get()); Assert.assertEquals("TearDown4 called twice", 2, countTearDownIteration2.get()); Assert.assertEquals("TearDown5 = invocation count", countInvocations.get(), countTearDownInvocation1.get()); Assert.assertEquals("TearDown6 = invocation count", countInvocations.get(), countTearDownInvocation2.get()); } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 2, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Threads(2) public void test() { Fixtures.work(); countInvocations.incrementAndGet(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opt).run(); } } }
6,416
37.42515
116
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/times/ThreadStateHelperTimesTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.times; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; 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.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; public class ThreadStateHelperTimesTest { @State(Scope.Thread) public static class MyState { private final AtomicInteger countInvocations = new AtomicInteger(); private final AtomicInteger countSetupRun1 = new AtomicInteger(); private final AtomicInteger countSetupRun2 = new AtomicInteger(); private final AtomicInteger countSetupIteration1 = new AtomicInteger(); private final AtomicInteger countSetupIteration2 = new AtomicInteger(); private final AtomicInteger countSetupInvocation1 = new AtomicInteger(); private final AtomicInteger countSetupInvocation2 = new AtomicInteger(); private final AtomicInteger countTearDownRun1 = new AtomicInteger(); private final AtomicInteger countTearDownRun2 = new AtomicInteger(); private final AtomicInteger countTearDownIteration1 = new AtomicInteger(); private final AtomicInteger countTearDownIteration2 = new AtomicInteger(); private final AtomicInteger countTearDownInvocation1 = new AtomicInteger(); private final AtomicInteger countTearDownInvocation2 = new AtomicInteger(); @Setup(Level.Trial) public void setup1() { countSetupRun1.incrementAndGet(); } @Setup(Level.Trial) public void setup2() { countSetupRun2.incrementAndGet(); } @Setup(Level.Iteration) public void setup3() { countSetupIteration1.incrementAndGet(); } @Setup(Level.Iteration) public void setup4() { countSetupIteration2.incrementAndGet(); } @Setup(Level.Invocation) public void setup5() { countSetupInvocation1.incrementAndGet(); } @Setup(Level.Invocation) public void setup6() { countSetupInvocation2.incrementAndGet(); } @TearDown(Level.Trial) public void tearDown1() { countTearDownRun1.incrementAndGet(); } @TearDown(Level.Trial) public void tearDown2() { countTearDownRun2.incrementAndGet(); } @TearDown(Level.Iteration) public void tearDown3() { countTearDownIteration1.incrementAndGet(); } @TearDown(Level.Iteration) public void tearDown4() { countTearDownIteration2.incrementAndGet(); } @TearDown(Level.Invocation) public void tearDown5() { countTearDownInvocation1.incrementAndGet(); } @TearDown(Level.Invocation) public void tearDown6() { countTearDownInvocation2.incrementAndGet(); } @TearDown(Level.Trial) public void tearDownLATEST() { // this name ensures this is the latest teardown to run Assert.assertEquals("Setup1 called once", 1, countSetupRun1.get()); Assert.assertEquals("Setup2 called once", 1, countSetupRun2.get()); Assert.assertEquals("Setup3 called twice", 2, countSetupIteration1.get()); Assert.assertEquals("Setup4 called twice", 2, countSetupIteration2.get()); Assert.assertEquals("Setup5 = invocation count", countInvocations.get(), countSetupInvocation1.get()); Assert.assertEquals("Setup6 = invocation count", countInvocations.get(), countSetupInvocation2.get()); Assert.assertEquals("TearDown1 called once", 1, countTearDownRun1.get()); Assert.assertEquals("TearDown2 called once", 1, countTearDownRun2.get()); Assert.assertEquals("TearDown3 called twice", 2, countTearDownIteration1.get()); Assert.assertEquals("TearDown4 called twice", 2, countTearDownIteration2.get()); Assert.assertEquals("TearDown5 = invocation count", countInvocations.get(), countTearDownInvocation1.get()); Assert.assertEquals("TearDown6 = invocation count", countInvocations.get(), countTearDownInvocation2.get()); } } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 2, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Threads(2) public void test(MyState state) { Fixtures.work(); state.countInvocations.incrementAndGet(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opt).run(); } } }
6,785
38.684211
120
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/times/batches/BenchmarkBatchedBenchHelperTimesTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.times.batches; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; 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.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @State(Scope.Benchmark) public class BenchmarkBatchedBenchHelperTimesTest { private final AtomicInteger countInvocations = new AtomicInteger(); private final AtomicInteger countSetupRun = new AtomicInteger(); private final AtomicInteger countSetupIteration = new AtomicInteger(); private final AtomicInteger countSetupInvocation = new AtomicInteger(); private final AtomicInteger countTearDownRun = new AtomicInteger(); private final AtomicInteger countTearDownIteration = new AtomicInteger(); private final AtomicInteger countTearDownInvocation = new AtomicInteger(); @Setup(Level.Trial) public void setup1() { countSetupRun.incrementAndGet(); } @Setup(Level.Iteration) public void setup2() { countSetupIteration.incrementAndGet(); } @Setup(Level.Invocation) public void setup3() { countSetupInvocation.incrementAndGet(); } @TearDown(Level.Trial) public void tearDown1() { countTearDownRun.incrementAndGet(); } @TearDown(Level.Iteration) public void tearDown2() { countTearDownIteration.incrementAndGet(); } @TearDown(Level.Invocation) public void tearDown3() { countTearDownInvocation.incrementAndGet(); } @TearDown(Level.Trial) public void tearDownLATEST() { // this name ensures this is the latest teardown to run Assert.assertEquals("Setup1 called once", 1, countSetupRun.get()); Assert.assertEquals("Setup2 called twice", 2, countSetupIteration.get()); Assert.assertEquals("TearDown1 called once", 1, countTearDownRun.get()); Assert.assertEquals("TearDown2 called twice", 2, countTearDownIteration.get()); Assert.assertEquals("Setup3 and TearDown3 agree", countSetupInvocation.get(), countTearDownInvocation.get()); Assert.assertEquals("Test invocations and Setup3 agree", countInvocations.get(), countSetupInvocation.get()); Assert.assertEquals("Test invocations and TearDown3 agree", countInvocations.get(), countTearDownInvocation.get()); } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 2, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Threads(2) public void test() { Fixtures.work(); countInvocations.incrementAndGet(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .warmupBatchSize(10) .measurementBatchSize(10) .build(); new Runner(opt).run(); } } }
4,912
37.382813
123
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/times/batches/GroupBatchedBenchHelperTimesTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.times.batches; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Group; import org.openjdk.jmh.annotations.GroupThreads; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; 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 org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @State(Scope.Group) public class GroupBatchedBenchHelperTimesTest { private final AtomicInteger countInvocations = new AtomicInteger(); private final AtomicInteger countSetupRun = new AtomicInteger(); private final AtomicInteger countSetupIteration = new AtomicInteger(); private final AtomicInteger countSetupInvocation = new AtomicInteger(); private final AtomicInteger countTearDownRun = new AtomicInteger(); private final AtomicInteger countTearDownIteration = new AtomicInteger(); private final AtomicInteger countTearDownInvocation = new AtomicInteger(); @Setup(Level.Trial) public void setup1() { countSetupRun.incrementAndGet(); } @Setup(Level.Iteration) public void setup2() { countSetupIteration.incrementAndGet(); } @Setup(Level.Invocation) public void setup3() { countSetupInvocation.incrementAndGet(); } @TearDown(Level.Trial) public void tearDown1() { countTearDownRun.incrementAndGet(); } @TearDown(Level.Iteration) public void tearDown2() { countTearDownIteration.incrementAndGet(); } @TearDown(Level.Invocation) public void tearDown3() { countTearDownInvocation.incrementAndGet(); } @TearDown(Level.Trial) public void tearDownLATEST() { // this name ensures this is the latest teardown to run Assert.assertEquals("Setup1 called once", 1, countSetupRun.get()); Assert.assertEquals("Setup2 called twice", 2, countSetupIteration.get()); Assert.assertEquals("TearDown1 called once", 1, countTearDownRun.get()); Assert.assertEquals("TearDown2 called twice", 2, countTearDownIteration.get()); Assert.assertEquals("Setup3 and TearDown3 agree", countSetupInvocation.get(), countTearDownInvocation.get()); Assert.assertEquals("Test invocations and Setup3 agree", countInvocations.get(), countSetupInvocation.get()); Assert.assertEquals("Test invocations and TearDown3 agree", countInvocations.get(), countTearDownInvocation.get()); } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 2, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Group("T") @GroupThreads(2) public void test() { Fixtures.work(); countInvocations.incrementAndGet(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .warmupBatchSize(10) .measurementBatchSize(10) .build(); new Runner(opt).run(); } } }
4,972
37.253846
123
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/times/batches/ThreadBatchedBenchHelperTimesTest.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.times.batches; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; 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.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @State(Scope.Thread) public class ThreadBatchedBenchHelperTimesTest { private final AtomicInteger countInvocations = new AtomicInteger(); private final AtomicInteger countSetupRun = new AtomicInteger(); private final AtomicInteger countSetupIteration = new AtomicInteger(); private final AtomicInteger countSetupInvocation = new AtomicInteger(); private final AtomicInteger countTearDownRun = new AtomicInteger(); private final AtomicInteger countTearDownIteration = new AtomicInteger(); private final AtomicInteger countTearDownInvocation = new AtomicInteger(); @Setup(Level.Trial) public void setup1() { countSetupRun.incrementAndGet(); } @Setup(Level.Iteration) public void setup2() { countSetupIteration.incrementAndGet(); } @Setup(Level.Invocation) public void setup3() { countSetupInvocation.incrementAndGet(); } @TearDown(Level.Trial) public void tearDown1() { countTearDownRun.incrementAndGet(); } @TearDown(Level.Iteration) public void tearDown2() { countTearDownIteration.incrementAndGet(); } @TearDown(Level.Invocation) public void tearDown3() { countTearDownInvocation.incrementAndGet(); } @TearDown(Level.Trial) public void tearDownLATEST() { // this name ensures this is the latest teardown to run Assert.assertEquals("Setup1 called once", 1, countSetupRun.get()); Assert.assertEquals("Setup2 called twice", 2, countSetupIteration.get()); Assert.assertEquals("TearDown1 called once", 1, countTearDownRun.get()); Assert.assertEquals("TearDown2 called twice", 2, countTearDownIteration.get()); Assert.assertEquals("Setup3 and TearDown3 agree", countSetupInvocation.get(), countTearDownInvocation.get()); Assert.assertEquals("Test invocations and Setup3 agree", countInvocations.get(), countSetupInvocation.get()); Assert.assertEquals("Test invocations and TearDown3 agree", countInvocations.get(), countTearDownInvocation.get()); } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 2, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Threads(2) public void test() { Fixtures.work(); countInvocations.incrementAndGet(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .warmupBatchSize(10) .measurementBatchSize(10) .build(); new Runner(opt).run(); } } }
4,906
37.335938
123
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/times/fail/BenchmarkInvocationFailureTimesTest.java
/* * Copyright (c) 2016, Red Hat Inc. 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.times.fail; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.atomic.AtomicInteger; @State(Scope.Benchmark) public class BenchmarkInvocationFailureTimesTest { private static final AtomicInteger count = new AtomicInteger(); @Setup(Level.Invocation) public void setup() { count.incrementAndGet(); throw new IllegalStateException("Failing"); } @Benchmark public void test() { Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { for (Mode mode : Mode.values()) { if (mode == Mode.All) continue; count.set(0); Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .mode(mode) .threads(Threads.MAX) .forks(0) .build(); new Runner(opt).run(); Assert.assertEquals(1, count.get()); } } } }
2,606
32.857143
76
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/times/fail/BenchmarkIterationFailureTimesTest.java
/* * Copyright (c) 2016, Red Hat Inc. 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.times.fail; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.atomic.AtomicInteger; @State(Scope.Benchmark) public class BenchmarkIterationFailureTimesTest { private static final AtomicInteger count = new AtomicInteger(); @Setup(Level.Iteration) public void setup() { count.incrementAndGet(); throw new IllegalStateException("Failing"); } @Benchmark public void test() { Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { for (Mode mode : Mode.values()) { if (mode == Mode.All) continue; count.set(0); Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .mode(mode) .threads(Threads.MAX) .forks(0) .build(); new Runner(opt).run(); Assert.assertEquals(1, count.get()); } } } }
2,604
32.831169
76
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/times/fail/BenchmarkTrialFailureTimesTest.java
/* * Copyright (c) 2016, Red Hat Inc. 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.times.fail; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.atomic.AtomicInteger; @State(Scope.Benchmark) public class BenchmarkTrialFailureTimesTest { private static final AtomicInteger count = new AtomicInteger(); @Setup(Level.Trial) public void setup() { count.incrementAndGet(); throw new IllegalStateException("Failing"); } @Benchmark public void test() { Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { for (Mode mode : Mode.values()) { if (mode == Mode.All) continue; count.set(0); Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .mode(mode) .threads(Threads.MAX) .forks(0) .build(); new Runner(opt).run(); Assert.assertEquals(1, count.get()); } } } }
2,596
32.727273
76
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/times/fail/GroupInvocationFailureTimesTest.java
/* * Copyright (c) 2016, Red Hat Inc. 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.times.fail; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.atomic.AtomicInteger; @State(Scope.Group) public class GroupInvocationFailureTimesTest { private static final AtomicInteger count = new AtomicInteger(); @Setup(Level.Invocation) public void setup() { count.incrementAndGet(); throw new IllegalStateException("Failing"); } @Benchmark @Group @GroupThreads(4) // should match the total number of threads public void test() { Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { for (Mode mode : Mode.values()) { if (mode == Mode.All) continue; count.set(0); Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .mode(mode) .threads(4) .forks(0) .build(); new Runner(opt).run(); Assert.assertEquals(1, count.get()); } } } }
2,664
32.734177
76
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/times/fail/GroupIterationFailureTimesTest.java
/* * Copyright (c) 2016, Red Hat Inc. 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.times.fail; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.atomic.AtomicInteger; @State(Scope.Group) public class GroupIterationFailureTimesTest { private static final AtomicInteger count = new AtomicInteger(); @Setup(Level.Iteration) public void setup() { System.err.println("Enter " + Thread.currentThread()); count.incrementAndGet(); throw new IllegalStateException("Failing"); } @Benchmark @Group @GroupThreads(4) // should match the total number of threads public void test() { Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { for (Mode mode : Mode.values()) { if (mode == Mode.All) continue; count.set(0); Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .mode(mode) .threads(4) .forks(0) .build(); new Runner(opt).run(); Assert.assertEquals(1, count.get()); } } } }
2,725
33.075
76
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/times/fail/GroupTrialFailureTimesTest.java
/* * Copyright (c) 2016, Red Hat Inc. 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.times.fail; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.atomic.AtomicInteger; @State(Scope.Group) public class GroupTrialFailureTimesTest { private static final AtomicInteger count = new AtomicInteger(); @Setup(Level.Trial) public void setup() { count.incrementAndGet(); throw new IllegalStateException("Failing"); } @Benchmark @Group public void test() { Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { for (Mode mode : Mode.values()) { if (mode == Mode.All) continue; count.set(0); Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .mode(mode) .threads(Threads.MAX) .forks(0) .build(); new Runner(opt).run(); Assert.assertEquals(1, count.get()); } } } }
2,599
32.333333
76
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/times/fail/ThreadInvocationFailureTimesTest.java
/* * Copyright (c) 2016, Red Hat Inc. 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.times.fail; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.atomic.AtomicInteger; @State(Scope.Thread) public class ThreadInvocationFailureTimesTest { private static final AtomicInteger count = new AtomicInteger(); @Setup(Level.Invocation) public void setup() { count.incrementAndGet(); throw new IllegalStateException("Failing"); } @Benchmark public void test() { Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { for (Mode mode : Mode.values()) { if (mode == Mode.All) continue; count.set(0); Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .mode(mode) .threads(1) .forks(0) .build(); new Runner(opt).run(); Assert.assertEquals(1, count.get()); } } } }
2,590
32.649351
76
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/times/fail/ThreadIterationFailureTimesTest.java
/* * Copyright (c) 2016, Red Hat Inc. 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.times.fail; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.atomic.AtomicInteger; @State(Scope.Thread) public class ThreadIterationFailureTimesTest { private static final AtomicInteger count = new AtomicInteger(); @Setup(Level.Iteration) public void setup() { count.incrementAndGet(); throw new IllegalStateException("Failing"); } @Benchmark public void test() { Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { for (Mode mode : Mode.values()) { if (mode == Mode.All) continue; count.set(0); Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .mode(mode) .threads(1) .forks(0) .build(); new Runner(opt).run(); Assert.assertEquals(1, count.get()); } } } }
2,588
32.623377
76
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/times/fail/ThreadTrialFailureTimesTest.java
/* * Copyright (c) 2016, Red Hat Inc. 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.times.fail; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.atomic.AtomicInteger; @State(Scope.Thread) public class ThreadTrialFailureTimesTest { private static final AtomicInteger count = new AtomicInteger(); @Setup(Level.Trial) public void setup() { count.incrementAndGet(); throw new IllegalStateException("Failing"); } @Benchmark public void test() { Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { for (Mode mode : Mode.values()) { if (mode == Mode.All) continue; count.set(0); Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .mode(mode) .threads(1) .forks(0) .build(); new Runner(opt).run(); Assert.assertEquals(1, count.get()); } } } }
2,580
32.519481
76
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/times/statemerge/BenchmarkStateMergeHelperTimesTest.java
/* * Copyright (c) 2005, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.times.statemerge; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; 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.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; public class BenchmarkStateMergeHelperTimesTest { @State(Scope.Benchmark) public static class MyState { private final AtomicInteger countSetupRun = new AtomicInteger(); private final AtomicInteger countSetupIteration = new AtomicInteger(); private final AtomicInteger countSetupInvocation = new AtomicInteger(); private final AtomicInteger countTearDownRun = new AtomicInteger(); private final AtomicInteger countTearDownIteration = new AtomicInteger(); private final AtomicInteger countTearDownInvocation = new AtomicInteger(); @Setup(Level.Trial) public void setup1() { countSetupRun.incrementAndGet(); } @Setup(Level.Iteration) public void setup2() { countSetupIteration.incrementAndGet(); } @Setup(Level.Invocation) public void setup3() { countSetupInvocation.incrementAndGet(); } @TearDown(Level.Trial) public void tearDown1() { countTearDownRun.incrementAndGet(); } @TearDown(Level.Iteration) public void tearDown2() { countTearDownIteration.incrementAndGet(); } @TearDown(Level.Invocation) public void tearDown3() { countTearDownInvocation.incrementAndGet(); } @TearDown(Level.Trial) public void tearDownLATEST() { // this name ensures this is the latest teardown to run Assert.assertEquals("Setup1 called once", 1, countSetupRun.get()); Assert.assertEquals("Setup2 called twice", 2, countSetupIteration.get()); Assert.assertEquals("TearDown1 called once", 1, countTearDownRun.get()); Assert.assertEquals("TearDown2 called twice", 2, countTearDownIteration.get()); Assert.assertEquals("Setup3 and TearDown3 counters match", countSetupInvocation.get(), countTearDownInvocation.get()); } } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 2, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Threads(2) public void test(MyState state1, MyState state2) { Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opt).run(); } } }
4,748
36.992
130
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/times/statemerge/GroupStateMergeHelperTimesTest.java
/* * Copyright (c) 2005, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.times.statemerge; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Group; import org.openjdk.jmh.annotations.GroupThreads; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; 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 org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; public class GroupStateMergeHelperTimesTest { @State(Scope.Group) public static class MyState { private final AtomicInteger countSetupRun = new AtomicInteger(); private final AtomicInteger countSetupIteration = new AtomicInteger(); private final AtomicInteger countSetupInvocation = new AtomicInteger(); private final AtomicInteger countTearDownRun = new AtomicInteger(); private final AtomicInteger countTearDownIteration = new AtomicInteger(); private final AtomicInteger countTearDownInvocation = new AtomicInteger(); @Setup(Level.Trial) public void setup1() { countSetupRun.incrementAndGet(); } @Setup(Level.Iteration) public void setup2() { countSetupIteration.incrementAndGet(); } @Setup(Level.Invocation) public void setup3() { countSetupInvocation.incrementAndGet(); } @TearDown(Level.Trial) public void tearDown1() { countTearDownRun.incrementAndGet(); } @TearDown(Level.Iteration) public void tearDown2() { countTearDownIteration.incrementAndGet(); } @TearDown(Level.Invocation) public void tearDown3() { countTearDownInvocation.incrementAndGet(); } @TearDown(Level.Trial) public void tearDownLATEST() { // this name ensures this is the latest teardown to run Assert.assertEquals("Setup1 called once", 1, countSetupRun.get()); Assert.assertEquals("Setup2 called twice", 2, countSetupIteration.get()); Assert.assertEquals("TearDown1 called once", 1, countTearDownRun.get()); Assert.assertEquals("TearDown2 called twice", 2, countTearDownIteration.get()); Assert.assertEquals("Setup3 and TearDown3 counters match", countSetupInvocation.get(), countTearDownInvocation.get()); } } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 2, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Group("T") @GroupThreads(2) public void test(MyState state1, MyState state2) { Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opt).run(); } } }
4,808
36.866142
130
java
jmh
jmh-master/jmh-core-it/src/test/java/org/openjdk/jmh/it/times/statemerge/ThreadStateMergeHelperTimesTest.java
/* * Copyright (c) 2005, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.it.times.statemerge; import org.junit.Assert; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; 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.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.it.Fixtures; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; public class ThreadStateMergeHelperTimesTest { @State(Scope.Thread) public static class MyState { private final AtomicInteger countSetupRun = new AtomicInteger(); private final AtomicInteger countSetupIteration = new AtomicInteger(); private final AtomicInteger countSetupInvocation = new AtomicInteger(); private final AtomicInteger countTearDownRun = new AtomicInteger(); private final AtomicInteger countTearDownIteration = new AtomicInteger(); private final AtomicInteger countTearDownInvocation = new AtomicInteger(); @Setup(Level.Trial) public void setup1() { countSetupRun.incrementAndGet(); } @Setup(Level.Iteration) public void setup2() { countSetupIteration.incrementAndGet(); } @Setup(Level.Invocation) public void setup3() { countSetupInvocation.incrementAndGet(); } @TearDown(Level.Trial) public void tearDown1() { countTearDownRun.incrementAndGet(); } @TearDown(Level.Iteration) public void tearDown2() { countTearDownIteration.incrementAndGet(); } @TearDown(Level.Invocation) public void tearDown3() { countTearDownInvocation.incrementAndGet(); } @TearDown(Level.Trial) public void tearDownLATEST() { // this name ensures this is the latest teardown to run Assert.assertEquals("Setup1 called once", 1, countSetupRun.get()); Assert.assertEquals("Setup2 called twice", 2, countSetupIteration.get()); Assert.assertEquals("TearDown1 called once", 1, countTearDownRun.get()); Assert.assertEquals("TearDown2 called twice", 2, countTearDownIteration.get()); Assert.assertEquals("Setup3 and TearDown3 counters match", countSetupInvocation.get(), countTearDownInvocation.get()); } } @Benchmark @BenchmarkMode(Mode.All) @Warmup(iterations = 0) @Measurement(iterations = 2, time = 100, timeUnit = TimeUnit.MILLISECONDS) @Fork(1) @Threads(2) public void test(MyState state1, MyState state2) { Fixtures.work(); } @Test public void invokeAPI() throws RunnerException { for (int c = 0; c < Fixtures.repetitionCount(); c++) { Options opt = new OptionsBuilder() .include(Fixtures.getTestMask(this.getClass())) .shouldFailOnError(true) .build(); new Runner(opt).run(); } } }
4,742
36.944
130
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/Main.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh; import org.openjdk.jmh.runner.*; import org.openjdk.jmh.runner.options.CommandLineOptionException; import org.openjdk.jmh.runner.options.CommandLineOptions; import org.openjdk.jmh.runner.options.VerboseMode; import java.io.IOException; /** * Main program entry point */ public class Main { public static void main(String[] argv) throws IOException { try { CommandLineOptions cmdOptions = new CommandLineOptions(argv); Runner runner = new Runner(cmdOptions); if (cmdOptions.shouldHelp()) { cmdOptions.showHelp(); return; } if (cmdOptions.shouldList()) { runner.list(); return; } if (cmdOptions.shouldListWithParams()) { runner.listWithParams(cmdOptions); return; } if (cmdOptions.shouldListProfilers()) { cmdOptions.listProfilers(); return; } if (cmdOptions.shouldListResultFormats()) { cmdOptions.listResultFormats(); return; } try { runner.run(); } catch (NoBenchmarksException e) { System.err.println("No matching benchmarks. Miss-spelled regexp?"); if (cmdOptions.verbosity().orElse(Defaults.VERBOSITY) != VerboseMode.EXTRA) { System.err.println("Use " + VerboseMode.EXTRA + " verbose mode to debug the pattern matching."); } else { runner.list(); } System.exit(1); } catch (ProfilersFailedException e) { // This is not exactly an error, print all messages and set the non-zero exit code. Throwable ex = e; while (ex != null) { System.err.println(ex.getMessage()); for (Throwable supp : ex.getSuppressed()) { System.err.println(supp.getMessage()); } ex = ex.getCause(); } System.exit(1); } catch (RunnerException e) { System.err.print("ERROR: "); e.printStackTrace(System.err); System.exit(1); } } catch (CommandLineOptionException e) { System.err.println("Error parsing command line:"); System.err.println(" " + e.getMessage()); System.exit(1); } } }
3,809
34.943396
116
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/annotations/AuxCounters.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * <p>{@link AuxCounters} annotation can be used to mark {@link State} objects * as the bearers of auxiliary secondary results. Marking the class with this annotation * will make JMH to treat its public fields and result-returning public methods * as the base for the secondary benchmark metrics.</p> * * <p>Properties:</p> * * <ul> * <li>Auxiliary counters are not available for every {@link BenchmarkMode}, * because not every mode counts time or operations. {@link Mode#AverageTime} * and {@link Mode#Throughput} are always supported.</li> * * <li>{@link AuxCounters} annotation is only available for {@link Scope#Thread} * state objects. It is a compile-time error to use it with other states. This means * the counters are thread-local in nature.</li> * * <li>Only public fields and methods are considered as metrics. If you don't want * a field/method to be captured as metric, do not make it public.</li> * * <li>Only numeric fields and numeric-returning methods are considered as * metrics. These include all primitives and their corresponding boxed counterTypes, * except {@code boolean}/{@link Boolean} and {@code char}/{@link Character}. * It is a compile-time error to use the public field/method with incompatible type.</li> * * <li>Methods with {@code void} return type are exempted from type checking. * This means helper {@link Setup} and {@link TearDown} methods are fine in * {@link AuxCounters}.</li> * * <li>Public fields in {@link AuxCounters} instances would be reset before * starting the iteration, and read back at the end of iteration. This allows * benchmark code to avoid complicated lifecycle handling for these objects.</li> * * <li>The counter names are generated from field/method names. The namespace for * counters is shared across all states participating in the run. JMH will fail to * compile the benchmark if there is an ambiguity around what counter comes from * what {@link AuxCounters} class. * </li> * </ul> * * <p><b>CAVEAT: THIS IS AN EXPERIMENTAL API, it may be changed or removed in future * without prior warning. This is a sharp tool, use with care.</b></p> */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface AuxCounters { Type value() default Type.OPERATIONS; enum Type { /** * Counts "operations", which should be relevant to the number of * times {@link Benchmark} method was executed. If this counter is * incremented on each {@link Benchmark} method invocation, then it * will produce a metric similar to the primary benchmark result. * This counter will be normalized to benchmark time by the harness. */ OPERATIONS, /** * Counts "events", the one-off things in the lifetime of workload. * This counter would not get normalized to time. */ EVENTS, ; } }
4,427
43.28
93
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/annotations/Benchmark.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * <p>{@link Benchmark} annotates the benchmark method.</p> * * <p>JMH will produce the generated benchmark code for this method during compilation, * register this method as the benchmark in the benchmark list, read out the default * values from the annotations, and generally prepare the environment for the benchmark * to run.</p> * * <p>Benchmarks may use annotations to control different things in their operations. * See {@link org.openjdk.jmh.annotations} package for available annotations, read their * Javadocs, and/or look through * <a href="http://hg.openjdk.java.net/code-tools/jmh/file/tip/jmh-samples/src/main/java/org/openjdk/jmh/samples/"> * JMH samples</a> for their canonical uses. As the rule of thumb, most annotations * may be placed either at the {@link Benchmark} method, or at the enclosing class, * to be inherited by all {@link Benchmark} methods in the class.</p> * * <p>{@link Benchmark} demarcates the benchmark payload, and JMH treats it specifically * as the wrapper which contains the benchmark code. In order to run the benchmark reliably, * JMH enforces a few stringent properties for these wrapper methods, including, but not * limited to:</p> * <ul> * <li>Method should be public</li> * <li>Arguments may only include either {@link State} classes, which JMH will inject * while calling the method (see {@link State} for more details), or JMH infrastructure * classes, like {@link org.openjdk.jmh.infra.Control}, or {@link org.openjdk.jmh.infra.Blackhole}</li> * <li>Method can only be synchronized if a relevant {@link State} is placed * on the enclosing class.</li> * </ul> * * <p>If you want to benchmark methods that break these properties, you have to write them * out as distinct methods and call them from {@link Benchmark} method.</p> * * <p>Benchmark method may declare Exceptions and Throwables to throw. Any exception actually * raised and thrown will be treated as benchmark failure.</p> */ @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface Benchmark { }
3,509
47.75
115
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/annotations/BenchmarkMode.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * <p>Benchmark mode declares the default modes in which this benchmark * would run. See {@link Mode} for available benchmark modes.</p> * * <p>This annotation may be put at {@link Benchmark} method to have effect * on that method only, or at the enclosing class instance to have the effect * over all {@link Benchmark} methods in the class. This annotation may be * overridden with the runtime options.</p> */ @Inherited @Target({ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) public @interface BenchmarkMode { /** * @return Which benchmark modes to use. * @see Mode */ Mode[] value(); }
2,105
38
79
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/annotations/CompilerControl.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * <p>Compiler control annotation may be used to affect the compilation of * particular methods in the benchmarks.</p> * * <p>JMH interfaces with the JVM by the means of CompilerCommand interface. * These annotations only work with forking enabled. Non-forked runs will not be * able to pass the hints to the compiler. Also, these control annotations might * get freely ignored by the compiler, reduced to no-ops, or otherwise invalidated. * Be cautious, and check the compiler logs and/or the generated code to see if * the effect is there.</p> * * <p>This annotation may be put at a method to have effect on that method only, or * at the enclosing class instance to have the effect over all methods in the class. * Remarkably, this annotation works on any class/method, even those not marked by * other JMH annotations.</p> */ @Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) public @interface CompilerControl { /** * The compilation mode. * @return mode */ Mode value(); /** * Compilation mode. */ enum Mode { /** * Insert the breakpoint into the generated compiled code. */ BREAK("break"), /** * Print the method and it's profile. */ PRINT("print"), /** * Exclude the method from the compilation. */ EXCLUDE("exclude"), /** * Force inline. */ INLINE("inline"), /** * Force skip inline. */ DONT_INLINE("dontinline"), /** * Compile only this method, and nothing else. */ COMPILE_ONLY("compileonly"),; private final String command; Mode(String command) { this.command = command; } public String command() { return command; } } }
3,346
30.87619
84
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/annotations/Fork.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * <b>Fork annotation allows to set the default forking parameters for the benchmark.</b> * * <p>This annotation may be put at {@link Benchmark} method to have effect on that * method only, or at the enclosing class instance to have the effect over all * {@link Benchmark} methods in the class. This annotation may be overridden with * the runtime options.</p> */ @Inherited @Target({ElementType.METHOD,ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) public @interface Fork { int BLANK_FORKS = -1; String BLANK_ARGS = "blank_blank_blank_2014"; /** @return number of times harness should fork, zero means "no fork" */ int value() default BLANK_FORKS; /** @return number of times harness should fork and ignore the results */ int warmups() default BLANK_FORKS; /** @return JVM executable to run with */ String jvm() default BLANK_ARGS; /** @return JVM arguments to replace in the command line */ String[] jvmArgs() default { BLANK_ARGS }; /** @return JVM arguments to prepend in the command line */ String[] jvmArgsPrepend() default { BLANK_ARGS }; /** @return JVM arguments to append in the command line */ String[] jvmArgsAppend() default { BLANK_ARGS }; }
2,691
38.014493
89
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/annotations/Group.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * <p>Execution group.</p> * * <p>Multiple {@link Benchmark} methods can be bound in the execution group * to produce the asymmetric benchmark. Each execution group contains of one * or more threads. Each thread within a particular execution group executes * one of {@link Group}-annotated {@link Benchmark} methods. The number of * threads executing a particular {@link Benchmark} defaults to a single thread, * and can be overridden by {@link GroupThreads}.</p> * * <p>Multiple copies of an execution group may participate in the run, and * the number of groups depends on the number of worker threads requested. * JMH will take the requested number of worker threads, round it up to execution * group size, and then distribute the threads among the (multiple) groups. * Among other things, this guarantees fully-populated execution groups.</p> * <p>For example, running {@link Group} with two {@link Benchmark} methods, * each having {@link GroupThreads}(4), will run 8*N threads, where N is an * integer.</p> * * <p>The group tag is used as the generated benchmark name. The result of each * benchmark method in isolation is recorded as secondary result named by the * original method name.</p> */ @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface Group { /** * Group tag. Should be a valid Java identifier. * @return group tag */ String value() default "group"; }
2,864
42.409091
81
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/annotations/GroupThreads.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * <p>GroupThreads defines how many threads are participating in running * a particular {@link Benchmark} method in the group.</p> * * @see Group */ @Inherited @Target({ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) public @interface GroupThreads { /** @return number of threads to run the concrete method with. */ int value() default 1; }
1,821
36.183673
79
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/annotations/Level.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.annotations; /** * Control when to run the fixture methods. * * @see Setup * @see TearDown */ public enum Level { /** * Trial level: to be executed before/after each run of the benchmark. * * <p>Trial is the set of benchmark iterations.</p> */ Trial, /** * Iteration level: to be executed before/after each iteration of the benchmark. * * <p>Iteration is the set of benchmark invocations.</p> */ Iteration, /** * Invocation level: to be executed for each benchmark method execution. * * <p><b>WARNING: HERE BE DRAGONS! THIS IS A SHARP TOOL. * MAKE SURE YOU UNDERSTAND THE REASONING AND THE IMPLICATIONS * OF THE WARNINGS BELOW BEFORE EVEN CONSIDERING USING THIS LEVEL.</b></p> * * <p>This level is only usable for benchmarks taking more than a millisecond * per single {@link Benchmark} method invocation. It is a good idea to validate * the impact for your case on ad-hoc basis as well.</p> * * <p>WARNING #1: Since we have to subtract the setup/teardown costs from * the benchmark time, on this level, we have to timestamp *each* benchmark * invocation. If the benchmarked method is small, then we saturate the * system with timestamp requests, which introduce artificial latency, * throughput, and scalability bottlenecks.</p> * * <p>WARNING #2: Since we measure individual invocation timings with this * level, we probably set ourselves up for (coordinated) omission. That means * the hiccups in measurement can be hidden from timing measurement, and * can introduce surprising results. For example, when we use timings to * understand the benchmark throughput, the omitted timing measurement will * result in lower aggregate time, and fictionally *larger* throughput.</p> * * <p>WARNING #3: In order to maintain the same sharing behavior as other * Levels, we sometimes have to synchronize (arbitrage) the access to * {@link State} objects. Other levels do this outside the measurement, * but at this level, we have to synchronize on *critical path*, further * offsetting the measurement.</p> * * <p>WARNING #4: Current implementation allows the helper method execution * at this Level to overlap with the benchmark invocation itself in order * to simplify arbitrage. That matters in multi-threaded benchmarks, when * one worker thread executing {@link Benchmark} method may observe other * worker thread already calling {@link TearDown} for the same object.</p> */ Invocation, }
3,870
43.494253
84
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/annotations/Measurement.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.util.concurrent.TimeUnit; /** * <p>Measurement annotations allows to set the default measurement parameters for * the benchmark.</p> * * <p>This annotation may be put at {@link Benchmark} method to have effect on that * method only, or at the enclosing class instance to have the effect over all * {@link Benchmark} methods in the class. This annotation may be overridden with * the runtime options.</p> * * @see Warmup */ @Inherited @Target({ElementType.METHOD,ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) public @interface Measurement { int BLANK_ITERATIONS = -1; int BLANK_TIME = -1; int BLANK_BATCHSIZE = -1; /** @return Number of measurement iterations */ int iterations() default BLANK_ITERATIONS; /** @return Time of each measurement iteration */ int time() default BLANK_TIME; /** @return Time unit for measurement iteration duration */ TimeUnit timeUnit() default TimeUnit.SECONDS; /** @return Batch size: number of benchmark method calls per operation */ int batchSize() default BLANK_BATCHSIZE; }
2,543
36.411765
83
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/annotations/Mode.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.annotations; import java.util.ArrayList; import java.util.List; /** * Benchmark mode. */ public enum Mode { /** * <p>Throughput: operations per unit of time.</p> * * <p>Runs by continuously calling {@link Benchmark} methods, * counting the total throughput over all worker threads. This mode is time-based, and it will * run until the iteration time expires.</p> */ Throughput("thrpt", "Throughput, ops/time"), /** * <p>Average time: average time per per operation.</p> * * <p>Runs by continuously calling {@link Benchmark} methods, * counting the average time to call over all worker threads. This is the inverse of {@link Mode#Throughput}, * but with different aggregation policy. This mode is time-based, and it will run until the iteration time * expires.</p> */ AverageTime("avgt", "Average time, time/op"), /** * <p>Sample time: samples the time for each operation.</p> * * <p>Runs by continuously calling {@link Benchmark} methods, * and randomly samples the time needed for the call. This mode automatically adjusts the sampling * frequency, but may omit some pauses which missed the sampling measurement. This mode is time-based, and it will * run until the iteration time expires.</p> */ SampleTime("sample", "Sampling time"), /** * <p>Single shot time: measures the time for a single operation.</p> * * <p>Runs by calling {@link Benchmark} once and measuring its time. * This mode is useful to estimate the "cold" performance when you don't want to hide the warmup invocations, or * if you want to see the progress from call to call, or you want to record every single sample. This mode is * work-based, and will run only for a single invocation of {@link Benchmark} * method.</p> * * Caveats for this mode include: * <ul> * <li>More warmup/measurement iterations are generally required.</li> * <li>Timers overhead might be significant if benchmarks are small; switch to {@link #SampleTime} mode if * that is a problem.</li> * </ul> */ SingleShotTime("ss", "Single shot invocation time"), /** * Meta-mode: all the benchmark modes. * This is mostly useful for internal JMH testing. */ All("all", "All benchmark modes"), ; private final String shortLabel; private final String longLabel; Mode(String shortLabel, String longLabel) { this.shortLabel = shortLabel; this.longLabel = longLabel; } public String shortLabel() { return shortLabel; } public String longLabel() { return longLabel; } public static Mode deepValueOf(String name) { try { return Mode.valueOf(name); } catch (IllegalArgumentException iae) { Mode inferred = null; for (Mode type : values()) { if (type.shortLabel().startsWith(name)) { if (inferred == null) { inferred = type; } else { throw new IllegalStateException("Unable to parse benchmark mode, ambiguous prefix given: \"" + name + "\"\n" + "Known values are " + getKnown()); } } } if (inferred != null) { return inferred; } else { throw new IllegalStateException("Unable to parse benchmark mode: \"" + name + "\"\n" + "Known values are " + getKnown()); } } } public static List<String> getKnown() { List<String> res = new ArrayList<>(); for (Mode type : Mode.values()) { res.add(type.name() + "/" + type.shortLabel()); } return res; } }
5,121
35.848921
134
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/annotations/OperationsPerInvocation.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * <p>OperationsPerInvocation annotations allows to communicate the benchmark does more than * one operation, and let JMH to adjust the scores appropriately.</p> * * <p>For example, a benchmark which uses the internal loop to have multiple operations, may * want to measure the performance of a single operation:</p> * * <blockquote><pre> * &#64;Benchmark * &#64;OperationsPerInvocation(10) * public void test() { * for (int i = 0; i &lt; 10; i++) { * // do something * } * } * </pre></blockquote> * * <p>This annotation may be put at {@link Benchmark} method to have effect on that method * only, or at the enclosing class instance to have the effect over all {@link Benchmark} * methods in the class.</p> */ @Inherited @Target({ElementType.METHOD,ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) public @interface OperationsPerInvocation { /** * @return Number of operations per single {@link Benchmark} call. */ int value() default 1; }
2,461
36.30303
92
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/annotations/OutputTimeUnit.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.util.concurrent.TimeUnit; /** * <p>OutputTimeUnit provides the default time unit to report the results in.</p> * * <p>This annotation may be put at {@link Benchmark} method to have effect on that * method only, or at the enclosing class instance to have the effect over all * {@link Benchmark} methods in the class. This annotation may be overridden with * the runtime options.</p> */ @Inherited @Target({ElementType.METHOD,ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) public @interface OutputTimeUnit { /** * @return Time unit to use. */ TimeUnit value(); }
2,061
37.185185
83
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/annotations/Param.java
/* * Copyright (c) 2005, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * <p>Marks the configurable parameter in the benchmark.</p> * * <p>{@link Param} fields should be non-final fields, * and should only reside in {@link State} classes. JMH will inject * the value into the annotated field before any {@link Setup} method * is called. It is <b>not</b> guaranteed the field value would be accessible * in any initializer or any constructor of {@link State}.</p> * * <p>Parameters are acceptable on any primitive type, primitive wrapper type, * a String, or an Enum. The annotation value is given in String, and will be * coerced as required to match the field type.</p> * * <p>Parameters should normally provide the default values which make * benchmark runnable even without the explicit parameters set for the run. * The only exception is {@link Param} over {@link java.lang.Enum}, which * will implicitly have the default value set encompassing all enum constants.</p> * * <p>When multiple {@link Param}-s are needed for the benchmark run, * JMH will compute the outer product of all the parameters in the run.</p> */ @Inherited @Target({ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) public @interface Param { String BLANK_ARGS = "blank_blank_blank_2014"; /** * Default values sequence for the parameter. By default, the parameter * values will be traversed during the run in the given order. * * @return values sequence to follow. */ String[] value() default { BLANK_ARGS }; }
2,936
40.957143
82
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/annotations/Scope.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.annotations; /** * {@link State} scope. */ public enum Scope { /** * <p>Benchmark state scope.</p> * * <p>With benchmark scope, all instances of the same type will be shared across all * worker threads.</p> * * <p>{@link Setup} and {@link TearDown} methods on this state object would be performed * by one of the worker threads, and only once per {@link Level}. * No other threads would ever touch the state object.</p> */ Benchmark, /** * <p>Group state scope.</p> * * <p>With group scope, all instances of the same type will be shared across all * threads within the same group. Each thread group will be supplied with its own * state object.</p> * * <p>{@link Setup} and {@link TearDown} methods on this state object would be performed * by one of the group threads, and only once per {@link Level}. * No other threads would ever touch the state object.</p> * * @see Group */ Group, /** * <p>Thread state scope.</p> * * <p>With thread scope, all instances of the same type are distinct, even if multiple * state objects are injected in the same benchmark</p> * * <p>{@link Setup} and {@link TearDown} methods on this state object would be performed * by single worker thread exclusively, and only once per {@link Level}. * No other threads would ever touch the state object.</p> * */ Thread, }
2,720
36.273973
92
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/annotations/Setup.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * <p>Setup marks the fixture method to be run before the benchmark.</p> * * <p>Since fixture methods manage the {@link State} lifecycles, {@link Setup} * can only be declared in {@link State} classes. The {@link Setup} method will * be executed by a thread which has the access to {@link State}, and it is not * defined which thread exactly. Note that means {@link TearDown} may be executed * by a different thread, if {@link State} is shared between the threads.</p> * * <p>Uses may optionally provide the {@link Level} at which the fixture method * should run.</p> * * @see State */ @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface Setup { /** * @return Level of this method. * @see Level */ Level value() default Level.Trial; }
2,220
37.293103
81
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/annotations/State.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * <p>Marks the state object.</p> * * <p>State objects naturally encapsulate the state on which benchmark is working on. * The {@link Scope} of state object defines to which extent it is shared among the * worker threads.</p> * * <p>State objects are usually injected into {@link Benchmark} methods as arguments, * and JMH takes care of their instantiation and sharing. State objects may also be * injected into {@link Setup} and {@link TearDown} methods of other {@link State} * objects to get the staged initialization. In that case, the dependency graph * between the {@link State}-s should be directed acyclic graph.</p> * * <p>State objects may be inherited: you can place {@link State} on a super class and * use subclasses as states.</p> */ @Inherited @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface State { /** * State scope. * @return state scope * @see Scope */ Scope value(); }
2,421
38.064516
86
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/annotations/TearDown.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * <p>TearDown marks the fixture method to be run after the benchmark.</p> * * <p>Since fixture methods manage the {@link State} lifecycles, {@link TearDown} * can only be declared in {@link State} classes. The {@link TearDown} method will * be executed by a thread which has the access to {@link State}, and it is not * defined which thread exactly. Note that means {@link Setup} may be executed * by a different thread, if {@link State} is shared between the threads.</p> * * <p>Uses may optionally provide the {@link Level} at which the fixture method * should run.</p> * * @see State */ @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface TearDown { /** * @return At which level to run this fixture. * @see Level */ Level value() default Level.Trial; }
2,241
38.333333
82
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/annotations/Threads.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * <p>Threads annotation provides the default number of threads to run.</p> * * <p>This annotation may be put at {@link Benchmark} method to have effect * on that method only, or at the enclosing class instance to have the effect * over all {@link Benchmark} methods in the class. This annotation may be * overridden with the runtime options.</p> */ @Inherited @Target({ElementType.METHOD,ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) public @interface Threads { /** * The magic value for MAX threads. * This means Runtime.getRuntime().availableProcessors() threads. */ int MAX = -1; /** * @return Number of threads; use Threads.MAX to run with all available threads. */ int value(); }
2,202
36.338983
84
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/annotations/Timeout.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.util.concurrent.TimeUnit; /** * <p>Timeout annotation allows to set the default timeout parameters for the benchmark.</p> * * <p>This annotation may be put at {@link org.openjdk.jmh.annotations.Benchmark} method to have effect on that method * only, or at the enclosing class instance to have the effect over all {@link org.openjdk.jmh.annotations.Benchmark} * methods in the class. This annotation may be overridden with the runtime options.</p> */ @Target({ElementType.METHOD,ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Inherited public @interface Timeout { /** @return Timeout for each iteration */ int time(); /** @return Time unit for timeout duration */ TimeUnit timeUnit() default TimeUnit.SECONDS; }
2,210
39.944444
118
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/annotations/Warmup.java
/* * Copyright (c) 2005, 2013, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.util.concurrent.TimeUnit; /** * <p>Warmup annotation allows to set the default warmup parameters for the benchmark.</p> * * <p>This annotation may be put at {@link Benchmark} method to have effect on that method * only, or at the enclosing class instance to have the effect over all {@link Benchmark} * methods in the class. This annotation may be overridden with the runtime options.</p> * * @see Measurement */ @Target({ElementType.METHOD,ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Inherited public @interface Warmup { int BLANK_ITERATIONS = -1; int BLANK_TIME = -1; int BLANK_BATCHSIZE = -1; /** @return Number of warmup iterations */ int iterations() default BLANK_ITERATIONS; /** @return Time for each warmup iteration */ int time() default BLANK_TIME; /** @return Time unit for warmup iteration duration */ TimeUnit timeUnit() default TimeUnit.SECONDS; /** @return batch size: number of benchmark method calls per operation */ int batchSize() default BLANK_BATCHSIZE; }
2,512
37.075758
90
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGenerator.java
/* * Copyright (c) 2005, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.generators.core; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.infra.*; import org.openjdk.jmh.results.*; import org.openjdk.jmh.runner.*; import org.openjdk.jmh.runner.Defaults; import org.openjdk.jmh.util.HashMultimap; import org.openjdk.jmh.util.Multimap; import org.openjdk.jmh.util.SampleBuffer; import java.io.*; import java.lang.reflect.Field; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; /** * Benchmark generator. * * <p>Benchmark generator is the agnostic piece of code which generates * synthetic Java code for JMH benchmarks. {@link GeneratorSource} is * used to feed the generator with the required metadata.</p> */ public class BenchmarkGenerator { private static final String JMH_STUB_SUFFIX = "_jmhStub"; private static final String JMH_TESTCLASS_SUFFIX = "_jmhTest"; protected static final String JMH_GENERATED_SUBPACKAGE = "jmh_generated"; private final Set<BenchmarkInfo> benchmarkInfos; private final CompilerControlPlugin compilerControl; private final Set<String> processedBenchmarks; private final BenchmarkGeneratorSession session; public BenchmarkGenerator() { benchmarkInfos = new HashSet<>(); processedBenchmarks = new HashSet<>(); compilerControl = new CompilerControlPlugin(); session = new BenchmarkGeneratorSession(); } /** * Execute the next phase of benchmark generation. * Multiple calls to this method are acceptable, even with the difference sources * * @param source generator source to get the metadata from * @param destination generator destination to write the results to */ public void generate(GeneratorSource source, GeneratorDestination destination) { try { // Build a Set of classes with a list of annotated methods Multimap<ClassInfo, MethodInfo> clazzes = buildAnnotatedSet(source); // Generate code for all found Classes and Methods for (ClassInfo clazz : clazzes.keys()) { if (!processedBenchmarks.add(clazz.getQualifiedName())) continue; try { validateBenchmark(clazz, clazzes.get(clazz)); Collection<BenchmarkInfo> infos = makeBenchmarkInfo(clazz, clazzes.get(clazz)); for (BenchmarkInfo info : infos) { generateClass(destination, clazz, info); } benchmarkInfos.addAll(infos); } catch (GenerationException ge) { destination.printError(ge.getMessage(), ge.getElement()); } } /* * JMH stubs should not be inlined to start the inlining budget from the hottest loop. * We would like to accurately track the things we do not want to inline, but * unfortunately the Hotspot's CompilerOracle is not scaling well with the number of compiler * commands. Therefore, in order to cut down the number of compiler commands, we opt to * blankly forbid the inlining all methods that look like JMH stubs. * * See: https://bugs.openjdk.java.net/browse/JDK-8057169 */ for (Mode mode : Mode.values()) { compilerControl.alwaysDontInline("*", "*_" + mode.shortLabel() + JMH_STUB_SUFFIX); } compilerControl.process(source, destination); } catch (Throwable t) { destination.printError("Annotation generator had thrown the exception.", t); } } /** * Finish generating the benchmarks. * Must be called at the end of generation. * * @param source source generator to use * @param destination generator destination to write the results to */ public void complete(GeneratorSource source, GeneratorDestination destination) { compilerControl.finish(source, destination); // Processing completed, final round. // Collect all benchmark entries here Set<BenchmarkListEntry> entries = new HashSet<>(); // Try to read the benchmark entries from the previous generator sessions. // Incremental compilation may add or remove @Benchmark entries. New entries // are discovered and added from the current compilation session. It is harder // to detect removed @Benchmark entries. To do so, we are overwriting all benchmark // records that belong to a current compilation unit. Multimap<String, BenchmarkListEntry> entriesByQName = new HashMultimap<>(); try (InputStream stream = destination.getResource(BenchmarkList.BENCHMARK_LIST.substring(1))) { for (BenchmarkListEntry ble : BenchmarkList.readBenchmarkList(stream)) { entries.add(ble); entriesByQName.put(ble.getUserClassQName(), ble); } } catch (IOException e) { // okay, move on } catch (UnsupportedOperationException e) { destination.printError("Unable to read the existing benchmark list.", e); } // Generate new benchmark entries for (BenchmarkInfo info : benchmarkInfos) { try { MethodGroup group = info.methodGroup; for (Mode m : group.getModes()) { BenchmarkListEntry br = new BenchmarkListEntry( info.userClassQName, info.generatedClassQName, group.getName(), m, group.getTotalThreadCount(), group.getGroupThreads(), group.getGroupLabels(), group.getWarmupIterations(), group.getWarmupTime(), group.getWarmupBatchSize(), group.getMeasurementIterations(), group.getMeasurementTime(), group.getMeasurementBatchSize(), group.getForks(), group.getWarmupForks(), group.getJvm(), group.getJvmArgs(), group.getJvmArgsPrepend(), group.getJvmArgsAppend(), group.getParams(), group.getOutputTimeUnit(), group.getOperationsPerInvocation(), group.getTimeout() ); if (entriesByQName.keys().contains(info.userClassQName)) { destination.printNote("Benchmark entries for " + info.userClassQName + " already exist, overwriting"); entries.removeAll(entriesByQName.get(info.userClassQName)); entriesByQName.remove(info.userClassQName); } entries.add(br); } } catch (GenerationException ge) { destination.printError(ge.getMessage(), ge.getElement()); } } try (OutputStream stream = destination.newResource(BenchmarkList.BENCHMARK_LIST.substring(1))) { BenchmarkList.writeBenchmarkList(stream, entries); } catch (IOException ex) { destination.printError("Error writing benchmark list", ex); } } /** * Build a set of Classes which has annotated methods in them * * @return for all methods annotated with $annotation, returns Map<holder-class, Set<method>> */ private Multimap<ClassInfo, MethodInfo> buildAnnotatedSet(GeneratorSource source) { // Transitively close the hierarchy: // If superclass has a @Benchmark method, then all subclasses also have it. // We skip the generated classes, which we had probably generated during the previous rounds // of processing. Abstract classes are of no interest for us either. Multimap<ClassInfo, MethodInfo> result = new HashMultimap<>(); for (ClassInfo currentClass : source.getClasses()) { if (currentClass.getQualifiedName().contains(JMH_GENERATED_SUBPACKAGE)) continue; if (currentClass.isAbstract()) continue; ClassInfo walk = currentClass; do { for (MethodInfo mi : walk.getMethods()) { Benchmark ann = mi.getAnnotation(Benchmark.class); if (ann != null) { result.put(currentClass, mi); } } } while ((walk = walk.getSuperClass()) != null); } return result; } /** * Do basic benchmark validation. */ private void validateBenchmark(ClassInfo clazz, Collection<MethodInfo> methods) { if (clazz.getPackageName().isEmpty()) { throw new GenerationException("Benchmark class should have package other than default.", clazz); } if (clazz.isFinal()) { throw new GenerationException("Benchmark classes should not be final.", clazz); } // validate all arguments are @State-s for (MethodInfo e : methods) { StateObjectHandler.validateStateArgs(e); } boolean explicitState = BenchmarkGeneratorUtils.getAnnSuper(clazz, State.class) != null; // validate if enclosing class is implicit @State if (explicitState) { StateObjectHandler.validateState(clazz); } // validate no @State cycles for (MethodInfo e : methods) { StateObjectHandler.validateNoCycles(e); } // validate against rogue fields if (!explicitState || clazz.isAbstract()) { for (FieldInfo fi : BenchmarkGeneratorUtils.getAllFields(clazz)) { // allow static fields if (fi.isStatic()) continue; throw new GenerationException( "Field \"" + fi.getName() + "\" is declared within " + "a class not having @" + State.class.getSimpleName() + " annotation. " + "This is prohibited because it can result in unspecified behavior.", fi); } } // validate rogue annotations on classes BenchmarkGeneratorUtils.checkAnnotations(clazz); // validate rogue annotations on fields for (FieldInfo fi : BenchmarkGeneratorUtils.getAllFields(clazz)) { BenchmarkGeneratorUtils.checkAnnotations(fi); } // validate rogue annotations on methods for (MethodInfo mi : methods) { BenchmarkGeneratorUtils.checkAnnotations(mi); } // check modifiers for (MethodInfo m : methods) { if (!m.isPublic()) { throw new GenerationException("@" + Benchmark.class.getSimpleName() + " method should be public.", m); } if (m.isAbstract()) { throw new GenerationException("@" + Benchmark.class.getSimpleName() + " method can not be abstract.", m); } if (m.isSynchronized()) { State annState = BenchmarkGeneratorUtils.getAnnSuper(m, State.class); if (annState == null) { throw new GenerationException("@" + Benchmark.class.getSimpleName() + " method can only be synchronized if the enclosing class is annotated with " + "@" + State.class.getSimpleName() + ".", m); } else { if (m.isStatic() && annState.value() != Scope.Benchmark) { throw new GenerationException("@" + Benchmark.class.getSimpleName() + " method can only be static and synchronized if the enclosing class is annotated with " + "@" + State.class.getSimpleName() + "(" + Scope.class.getSimpleName() + "." + Scope.Benchmark + ").", m); } } } } // check annotations for (MethodInfo m : methods) { OperationsPerInvocation opi = BenchmarkGeneratorUtils.getAnnSuper(m, clazz, OperationsPerInvocation.class); if (opi != null && opi.value() < 1) { throw new GenerationException("The " + OperationsPerInvocation.class.getSimpleName() + " needs to be greater than 0.", m); } } // validate @Group-s for (MethodInfo m : methods) { if (m.getAnnotation(Group.class) != null && m.getAnnotation(Threads.class) != null) { throw new GenerationException("@" + Threads.class.getSimpleName() + " annotation is placed within " + "the benchmark method with @" + Group.class.getSimpleName() + " annotation. " + "This is prohibited because it is ambiguous. " + "Did you mean @" + GroupThreads.class.getSimpleName() + " instead?", m); } } } /** * validate benchmark info * * @param info benchmark info to validate */ private void validateBenchmarkInfo(BenchmarkInfo info) { // check the @Group preconditions, // ban some of the surprising configurations // MethodGroup group = info.methodGroup; if (group.methods().size() == 1) { MethodInfo meth = group.methods().iterator().next(); if (meth.getAnnotation(Group.class) == null) { for (ParameterInfo param : meth.getParameters()) { State stateAnn = BenchmarkGeneratorUtils.getAnnSuper(param.getType(), State.class); if (stateAnn != null && stateAnn.value() == Scope.Group) { throw new GenerationException( "Only @" + Group.class.getSimpleName() + " methods can reference @" + State.class.getSimpleName() + "(" + Scope.class.getSimpleName() + "." + Scope.Group + ") states.", meth); } } State stateAnn = BenchmarkGeneratorUtils.getAnnSuper(meth.getDeclaringClass(), State.class); if (stateAnn != null && stateAnn.value() == Scope.Group) { throw new GenerationException( "Only @" + Group.class.getSimpleName() + " methods can implicitly reference @" + State.class.getSimpleName() + "(" + Scope.class.getSimpleName() + "." + Scope.Group + ") states.", meth); } } } else { for (MethodInfo m : group.methods()) { if (m.getAnnotation(Group.class) == null) { throw new GenerationException( "Internal error: multiple methods per @" + Group.class.getSimpleName() + ", but not all methods have @" + Group.class.getSimpleName(), m); } } } } /** * Generate BenchmarkInfo for given class. * We will figure out method groups at this point. * * * @param clazz holder class * @param methods annotated methods * @return BenchmarkInfo */ private Collection<BenchmarkInfo> makeBenchmarkInfo(ClassInfo clazz, Collection<MethodInfo> methods) { Map<String, MethodGroup> result = new TreeMap<>(); for (MethodInfo method : methods) { Group groupAnn = method.getAnnotation(Group.class); String groupName = (groupAnn != null) ? groupAnn.value() : method.getName(); if (!BenchmarkGeneratorUtils.checkJavaIdentifier(groupName)) { throw new GenerationException("Group name should be the legal Java identifier.", method); } MethodGroup group = result.get(groupName); if (group == null) { group = new MethodGroup(clazz, groupName); result.put(groupName, group); } BenchmarkMode mbAn = BenchmarkGeneratorUtils.getAnnSuper(method, clazz, BenchmarkMode.class); if (mbAn != null) { group.addModes(mbAn.value()); } group.addStrictFP(clazz.isStrictFP()); group.addStrictFP(method.isStrictFP()); group.addMethod(method, (method.getAnnotation(GroupThreads.class) != null) ? method.getAnnotation(GroupThreads.class).value() : 1); // Discovering @Params, part 1: // For each parameter, walk the type hierarchy up to discover inherited @Param fields in @State objects. for (ParameterInfo pi : method.getParameters()) { BenchmarkGeneratorUtils.addParameterValuesToGroup(pi.getType(), group); } // Discovering @Params, part 2: // Walk the type hierarchy up to discover inherited @Param fields for class. BenchmarkGeneratorUtils.addParameterValuesToGroup(clazz, group); } // enforce the default value for (MethodGroup group : result.values()) { if (group.getModes().isEmpty()) { group.addModes(Defaults.BENCHMARK_MODE); } } Collection<BenchmarkInfo> benchmarks = new ArrayList<>(); for (MethodGroup group : result.values()) { String sourcePackage = clazz.getPackageName(); String generatedPackageName = sourcePackage + "." + JMH_GENERATED_SUBPACKAGE; String generatedClassName = BenchmarkGeneratorUtils.getGeneratedName(clazz) + "_" + group.getName() + JMH_TESTCLASS_SUFFIX; BenchmarkInfo info = new BenchmarkInfo(clazz.getQualifiedName(), generatedPackageName, generatedClassName, group); validateBenchmarkInfo(info); benchmarks.add(info); } return benchmarks; } /** * Create and generate Java code for a class and it's methods */ private void generateClass(GeneratorDestination destination, ClassInfo classInfo, BenchmarkInfo info) throws IOException { StateObjectHandler states = new StateObjectHandler(compilerControl); // bind all methods states.bindMethods(classInfo, info.methodGroup); // Create file and open an outputstream PrintWriter writer = new PrintWriter(destination.newClass(info.generatedClassQName, classInfo.getQualifiedName()), false); // Write package and imports writer.println("package " + info.generatedPackageName + ';'); writer.println(); generateImport(writer); states.addImports(writer); // Write class header writer.println("public final class " + info.generatedClassName + " {"); writer.println(); // generate padding Paddings.padding(writer, "p"); writer.println(ident(1) + "int startRndMask;"); writer.println(ident(1) + "BenchmarkParams benchmarkParams;"); writer.println(ident(1) + "IterationParams iterationParams;"); writer.println(ident(1) + "ThreadParams threadParams;"); writer.println(ident(1) + "Blackhole blackhole;"); writer.println(ident(1) + "Control notifyControl;"); // write all methods for (Mode benchmarkKind : Mode.values()) { if (benchmarkKind == Mode.All) continue; generateMethod(benchmarkKind, writer, info.methodGroup, states); } // Write out state initializers for (String s : states.getStateInitializers()) { writer.println(ident(1) + s); } writer.println(); // Write out the required fields for (String s : states.getFields()) { writer.println(ident(1) + s); } writer.println(); // Write out the required objects states.writeStateOverrides(session, destination); // Finish class writer.println("}"); writer.println(); writer.close(); } private void generateImport(PrintWriter writer) { Class<?>[] imports = new Class<?>[]{ List.class, AtomicInteger.class, Collection.class, ArrayList.class, TimeUnit.class, CompilerControl.class, InfraControl.class, ThreadParams.class, BenchmarkTaskResult.class, Result.class, ThroughputResult.class, AverageTimeResult.class, SampleTimeResult.class, SingleShotResult.class, SampleBuffer.class, Mode.class, Fork.class, Measurement.class, Threads.class, Warmup.class, BenchmarkMode.class, RawResults.class, ResultRole.class, Field.class, BenchmarkParams.class, IterationParams.class, Blackhole.class, Control.class, ScalarResult.class, AggregationPolicy.class, FailureAssistException.class }; for (Class<?> c : imports) { writer.println("import " + c.getName() + ';'); } writer.println(); } /** * Generate the method for a specific benchmark method */ private void generateMethod(Mode benchmarkKind, PrintWriter writer, MethodGroup methodGroup, StateObjectHandler states) { writer.println(); switch (benchmarkKind) { case Throughput: generateThroughput(writer, benchmarkKind, methodGroup, states); break; case AverageTime: generateAverageTime(writer, benchmarkKind, methodGroup, states); break; case SampleTime: generateSampleTime(writer, benchmarkKind, methodGroup, states); break; case SingleShotTime: generateSingleShotTime(writer, benchmarkKind, methodGroup, states); break; default: throw new AssertionError("Shouldn't be here"); } } private void generateThroughput(PrintWriter writer, Mode benchmarkKind, MethodGroup methodGroup, StateObjectHandler states) { writer.println(ident(1) + "public BenchmarkTaskResult " + methodGroup.getName() + "_" + benchmarkKind + "(InfraControl control, ThreadParams threadParams) throws Throwable {"); methodProlog(writer); boolean isSingleMethod = (methodGroup.methods().size() == 1); int subGroup = -1; for (MethodInfo method : methodGroup.methods()) { subGroup++; writer.println(ident(2) + "if (threadParams.getSubgroupIndex() == " + subGroup + ") {"); writer.println(ident(3) + "RawResults res = new RawResults();"); iterationProlog(writer, 3, method, states); // synchronize iterations prolog: announce ready writer.println(ident(3) + "control.announceWarmupReady();"); // synchronize iterations prolog: catchup loop writer.println(ident(3) + "while (control.warmupShouldWait) {"); invocationProlog(writer, 4, method, states, false); writer.println(ident(4) + emitCall(method, states) + ';'); invocationEpilog(writer, 4, method, states, false); writer.println(ident(4) + "if (control.shouldYield) Thread.yield();"); writer.println(ident(4) + "res.allOps++;"); writer.println(ident(3) + "}"); writer.println(); // control objects get a special treatment writer.println(ident(3) + "notifyControl.startMeasurement = true;"); // measurement loop call writer.println(ident(3) + method.getName() + "_" + benchmarkKind.shortLabel() + JMH_STUB_SUFFIX + "(" + getStubArgs() + prefix(states.getArgList(method)) + ");"); // control objects get a special treatment writer.println(ident(3) + "notifyControl.stopMeasurement = true;"); // synchronize iterations epilog: announce ready writer.println(ident(3) + "control.announceWarmdownReady();"); // synchronize iterations epilog: catchup loop writer.println(ident(3) + "try {"); writer.println(ident(4) + "while (control.warmdownShouldWait) {"); invocationProlog(writer, 5, method, states, false); writer.println(ident(5) + emitCall(method, states) + ';'); invocationEpilog(writer, 5, method, states, false); writer.println(ident(5) + "if (control.shouldYield) Thread.yield();"); writer.println(ident(5) + "res.allOps++;"); writer.println(ident(4) + "}"); writer.println(ident(3) + "} catch (Throwable e) {"); writer.println(ident(4) + "if (!(e instanceof InterruptedException)) throw e;"); writer.println(ident(3) + "}"); writer.println(ident(3) + "control.preTearDown();"); // iteration prolog iterationEpilog(writer, 3, method, states); writer.println(ident(3) + "res.allOps += res.measuredOps;"); /* Adjust the operation counts: 1) res.measuredOps counted the individual @Benchmark invocations. Therefore, we need to adjust for opsPerInv (pretending each @Benchmark invocation counts as $opsPerInv ops); and we need to adjust down for $batchSize (pretending we had the batched run, and $batchSize @Benchmark invocations counted as single op); 2) res.allOps counted the individual @Benchmark invocations as well; the same reasoning applies. It's prudent to make the multiplication first to get more accuracy. */ writer.println(ident(3) + "int batchSize = iterationParams.getBatchSize();"); writer.println(ident(3) + "int opsPerInv = benchmarkParams.getOpsPerInvocation();"); writer.println(ident(3) + "res.allOps *= opsPerInv;"); writer.println(ident(3) + "res.allOps /= batchSize;"); writer.println(ident(3) + "res.measuredOps *= opsPerInv;"); writer.println(ident(3) + "res.measuredOps /= batchSize;"); writer.println(ident(3) + "BenchmarkTaskResult results = new BenchmarkTaskResult((long)res.allOps, (long)res.measuredOps);"); if (isSingleMethod) { writer.println(ident(3) + "results.add(new ThroughputResult(ResultRole.PRIMARY, \"" + method.getName() + "\", res.measuredOps, res.getTime(), benchmarkParams.getTimeUnit()));"); } else { writer.println(ident(3) + "results.add(new ThroughputResult(ResultRole.PRIMARY, \"" + methodGroup.getName() + "\", res.measuredOps, res.getTime(), benchmarkParams.getTimeUnit()));"); writer.println(ident(3) + "results.add(new ThroughputResult(ResultRole.SECONDARY, \"" + method.getName() + "\", res.measuredOps, res.getTime(), benchmarkParams.getTimeUnit()));"); } addAuxCounters(writer, "ThroughputResult", states, method); methodEpilog(writer); writer.println(ident(3) + "return results;"); writer.println(ident(2) + "} else"); } writer.println(ident(3) + "throw new IllegalStateException(\"Harness failed to distribute threads among groups properly\");"); writer.println(ident(1) + "}"); writer.println(); // measurement loop bodies for (MethodInfo method : methodGroup.methods()) { String methodName = method.getName() + "_" + benchmarkKind.shortLabel() + JMH_STUB_SUFFIX; compilerControl.defaultForceInline(method); writer.println(ident(1) + "public static" + (methodGroup.isStrictFP() ? " strictfp" : "") + " void " + methodName + "(" + getStubTypeArgs() + prefix(states.getTypeArgList(method)) + ") throws Throwable {"); writer.println(ident(2) + "long operations = 0;"); writer.println(ident(2) + "long realTime = 0;"); writer.println(ident(2) + "result.startTime = System.nanoTime();"); writer.println(ident(2) + "do {"); invocationProlog(writer, 3, method, states, true); writer.println(ident(3) + emitCall(method, states) + ';'); invocationEpilog(writer, 3, method, states, true); writer.println(ident(3) + "operations++;"); writer.println(ident(2) + "} while(!control.isDone);"); writer.println(ident(2) + "result.stopTime = System.nanoTime();"); writer.println(ident(2) + "result.realTime = realTime;"); writer.println(ident(2) + "result.measuredOps = operations;"); writer.println(ident(1) + "}"); writer.println(); } } private void addAuxCounters(PrintWriter writer, String resName, StateObjectHandler states, MethodInfo method) { for (String res : states.getAuxResults(method, resName)) { writer.println(ident(3) + "results.add(" + res + ");"); } } private void generateAverageTime(PrintWriter writer, Mode benchmarkKind, MethodGroup methodGroup, StateObjectHandler states) { writer.println(ident(1) + "public BenchmarkTaskResult " + methodGroup.getName() + "_" + benchmarkKind + "(InfraControl control, ThreadParams threadParams) throws Throwable {"); methodProlog(writer); boolean isSingleMethod = (methodGroup.methods().size() == 1); int subGroup = -1; for (MethodInfo method : methodGroup.methods()) { subGroup++; writer.println(ident(2) + "if (threadParams.getSubgroupIndex() == " + subGroup + ") {"); writer.println(ident(3) + "RawResults res = new RawResults();"); iterationProlog(writer, 3, method, states); // synchronize iterations prolog: announce ready writer.println(ident(3) + "control.announceWarmupReady();"); // synchronize iterations prolog: catchup loop writer.println(ident(3) + "while (control.warmupShouldWait) {"); invocationProlog(writer, 4, method, states, false); writer.println(ident(4) + emitCall(method, states) + ';'); invocationEpilog(writer, 4, method, states, false); writer.println(ident(4) + "if (control.shouldYield) Thread.yield();"); writer.println(ident(4) + "res.allOps++;"); writer.println(ident(3) + "}"); writer.println(); // control objects get a special treatment writer.println(ident(3) + "notifyControl.startMeasurement = true;"); // measurement loop call writer.println(ident(3) + method.getName() + "_" + benchmarkKind.shortLabel() + JMH_STUB_SUFFIX + "(" + getStubArgs() + prefix(states.getArgList(method)) + ");"); // control objects get a special treatment writer.println(ident(3) + "notifyControl.stopMeasurement = true;"); // synchronize iterations epilog: announce ready writer.println(ident(3) + "control.announceWarmdownReady();"); // synchronize iterations epilog: catchup loop writer.println(ident(3) + "try {"); writer.println(ident(4) + "while (control.warmdownShouldWait) {"); invocationProlog(writer, 5, method, states, false); writer.println(ident(5) + emitCall(method, states) + ';'); invocationEpilog(writer, 5, method, states, false); writer.println(ident(5) + "if (control.shouldYield) Thread.yield();"); writer.println(ident(5) + "res.allOps++;"); writer.println(ident(4) + "}"); writer.println(ident(3) + "} catch (Throwable e) {"); writer.println(ident(4) + "if (!(e instanceof InterruptedException)) throw e;"); writer.println(ident(3) + "}"); writer.println(ident(3) + "control.preTearDown();"); iterationEpilog(writer, 3, method, states); writer.println(ident(3) + "res.allOps += res.measuredOps;"); /* Adjust the operation counts: 1) res.measuredOps counted the individual @Benchmark invocations. Therefore, we need to adjust for opsPerInv (pretending each @Benchmark invocation counts as $opsPerInv ops); and we need to adjust down for $batchSize (pretending we had the batched run, and $batchSize @Benchmark invocations counted as single op) 2) res.measuredOps counted the individual @Benchmark invocations as well; the same reasoning applies. It's prudent to make the multiplication first to get more accuracy. */ writer.println(ident(3) + "int batchSize = iterationParams.getBatchSize();"); writer.println(ident(3) + "int opsPerInv = benchmarkParams.getOpsPerInvocation();"); writer.println(ident(3) + "res.allOps *= opsPerInv;"); writer.println(ident(3) + "res.allOps /= batchSize;"); writer.println(ident(3) + "res.measuredOps *= opsPerInv;"); writer.println(ident(3) + "res.measuredOps /= batchSize;"); writer.println(ident(3) + "BenchmarkTaskResult results = new BenchmarkTaskResult((long)res.allOps, (long)res.measuredOps);"); if (isSingleMethod) { writer.println(ident(3) + "results.add(new AverageTimeResult(ResultRole.PRIMARY, \"" + method.getName() + "\", res.measuredOps, res.getTime(), benchmarkParams.getTimeUnit()));"); } else { writer.println(ident(3) + "results.add(new AverageTimeResult(ResultRole.PRIMARY, \"" + methodGroup.getName() + "\", res.measuredOps, res.getTime(), benchmarkParams.getTimeUnit()));"); writer.println(ident(3) + "results.add(new AverageTimeResult(ResultRole.SECONDARY, \"" + method.getName() + "\", res.measuredOps, res.getTime(), benchmarkParams.getTimeUnit()));"); } addAuxCounters(writer, "AverageTimeResult", states, method); methodEpilog(writer); writer.println(ident(3) + "return results;"); writer.println(ident(2) + "} else"); } writer.println(ident(3) + "throw new IllegalStateException(\"Harness failed to distribute threads among groups properly\");"); writer.println(ident(1) + "}"); writer.println(); // measurement loop bodies for (MethodInfo method : methodGroup.methods()) { String methodName = method.getName() + "_" + benchmarkKind.shortLabel() + JMH_STUB_SUFFIX; compilerControl.defaultForceInline(method); writer.println(ident(1) + "public static" + (methodGroup.isStrictFP() ? " strictfp" : "") + " void " + methodName + "(" + getStubTypeArgs() + prefix(states.getTypeArgList(method)) + ") throws Throwable {"); writer.println(ident(2) + "long operations = 0;"); writer.println(ident(2) + "long realTime = 0;"); writer.println(ident(2) + "result.startTime = System.nanoTime();"); writer.println(ident(2) + "do {"); invocationProlog(writer, 3, method, states, true); writer.println(ident(3) + emitCall(method, states) + ';'); invocationEpilog(writer, 3, method, states, true); writer.println(ident(3) + "operations++;"); writer.println(ident(2) + "} while(!control.isDone);"); writer.println(ident(2) + "result.stopTime = System.nanoTime();"); writer.println(ident(2) + "result.realTime = realTime;"); writer.println(ident(2) + "result.measuredOps = operations;"); writer.println(ident(1) + "}"); writer.println(); } } private String getStubArgs() { return "control, res, benchmarkParams, iterationParams, threadParams, blackhole, notifyControl, startRndMask"; } private String getStubTypeArgs() { return "InfraControl control, RawResults result, " + "BenchmarkParams benchmarkParams, IterationParams iterationParams, ThreadParams threadParams, " + "Blackhole blackhole, Control notifyControl, int startRndMask"; } private void methodProlog(PrintWriter writer) { // do nothing writer.println(ident(2) + "this.benchmarkParams = control.benchmarkParams;"); writer.println(ident(2) + "this.iterationParams = control.iterationParams;"); writer.println(ident(2) + "this.threadParams = threadParams;"); writer.println(ident(2) + "this.notifyControl = control.notifyControl;"); writer.println(ident(2) + "if (this.blackhole == null) {"); writer.println(ident(3) + "this.blackhole = new Blackhole(\"Today's password is swordfish. I understand instantiating Blackholes directly is dangerous.\");"); writer.println(ident(2) + "}"); } private void methodEpilog(PrintWriter writer) { writer.println(ident(3) + "this.blackhole.evaporate(\"Yes, I am Stephen Hawking, and know a thing or two about black holes.\");"); } private String prefix(String argList) { if (argList.trim().isEmpty()) { return ""; } else { return ", " + argList; } } private void generateSampleTime(PrintWriter writer, Mode benchmarkKind, MethodGroup methodGroup, StateObjectHandler states) { writer.println(ident(1) + "public BenchmarkTaskResult " + methodGroup.getName() + "_" + benchmarkKind + "(InfraControl control, ThreadParams threadParams) throws Throwable {"); methodProlog(writer); boolean isSingleMethod = (methodGroup.methods().size() == 1); int subGroup = -1; for (MethodInfo method : methodGroup.methods()) { subGroup++; writer.println(ident(2) + "if (threadParams.getSubgroupIndex() == " + subGroup + ") {"); writer.println(ident(3) + "RawResults res = new RawResults();"); iterationProlog(writer, 3, method, states); // synchronize iterations prolog: announce ready writer.println(ident(3) + "control.announceWarmupReady();"); // synchronize iterations prolog: catchup loop writer.println(ident(3) + "while (control.warmupShouldWait) {"); invocationProlog(writer, 4, method, states, false); writer.println(ident(4) + emitCall(method, states) + ';'); invocationEpilog(writer, 4, method, states, false); writer.println(ident(4) + "if (control.shouldYield) Thread.yield();"); writer.println(ident(4) + "res.allOps++;"); writer.println(ident(3) + "}"); writer.println(); // control objects get a special treatment writer.println(ident(3) + "notifyControl.startMeasurement = true;"); // measurement loop call writer.println(ident(3) + "int targetSamples = (int) (control.getDuration(TimeUnit.MILLISECONDS) * 20); // at max, 20 timestamps per millisecond"); writer.println(ident(3) + "int batchSize = iterationParams.getBatchSize();"); writer.println(ident(3) + "int opsPerInv = benchmarkParams.getOpsPerInvocation();"); writer.println(ident(3) + "SampleBuffer buffer = new SampleBuffer();"); writer.println(ident(3) + method.getName() + "_" + benchmarkKind.shortLabel() + JMH_STUB_SUFFIX + "(" + getStubArgs() + ", buffer, targetSamples, opsPerInv, batchSize" + prefix(states.getArgList(method)) + ");"); // control objects get a special treatment writer.println(ident(3) + "notifyControl.stopMeasurement = true;"); // synchronize iterations epilog: announce ready writer.println(ident(3) + "control.announceWarmdownReady();"); // synchronize iterations epilog: catchup loop writer.println(ident(3) + "try {"); writer.println(ident(4) + "while (control.warmdownShouldWait) {"); invocationProlog(writer, 5, method, states, false); writer.println(ident(5) + emitCall(method, states) + ';'); invocationEpilog(writer, 5, method, states, false); writer.println(ident(5) + "if (control.shouldYield) Thread.yield();"); writer.println(ident(5) + "res.allOps++;"); writer.println(ident(4) + "}"); writer.println(ident(3) + "} catch (Throwable e) {"); writer.println(ident(4) + "if (!(e instanceof InterruptedException)) throw e;"); writer.println(ident(3) + "}"); writer.println(ident(3) + "control.preTearDown();"); iterationEpilog(writer, 3, method, states); /* Adjust the operation counts: 1) res.measuredOps counted the batched @Benchmark invocations. Therefore, we need only to adjust for opsPerInv (pretending each @Benchmark invocation counts as $opsPerInv ops); 2) res.allOps counted the individual @Benchmark invocations; to it needs the adjustment for $batchSize. It's prudent to make the multiplication first to get more accuracy. */ writer.println(ident(3) + "res.allOps += res.measuredOps * batchSize;"); writer.println(ident(3) + "res.allOps *= opsPerInv;"); writer.println(ident(3) + "res.allOps /= batchSize;"); writer.println(ident(3) + "res.measuredOps *= opsPerInv;"); writer.println(ident(3) + "BenchmarkTaskResult results = new BenchmarkTaskResult((long)res.allOps, (long)res.measuredOps);"); if (isSingleMethod) { writer.println(ident(3) + "results.add(new SampleTimeResult(ResultRole.PRIMARY, \"" + method.getName() + "\", buffer, benchmarkParams.getTimeUnit()));"); } else { writer.println(ident(3) + "results.add(new SampleTimeResult(ResultRole.PRIMARY, \"" + methodGroup.getName() + "\", buffer, benchmarkParams.getTimeUnit()));"); writer.println(ident(3) + "results.add(new SampleTimeResult(ResultRole.SECONDARY, \"" + method.getName() + "\", buffer, benchmarkParams.getTimeUnit()));"); } addAuxCounters(writer, "SampleTimeResult", states, method); methodEpilog(writer); writer.println(ident(3) + "return results;"); writer.println(ident(2) + "} else"); } writer.println(ident(3) + "throw new IllegalStateException(\"Harness failed to distribute threads among groups properly\");"); writer.println(ident(1) + "}"); writer.println(); // measurement loop bodies for (MethodInfo method : methodGroup.methods()) { String methodName = method.getName() + "_" + benchmarkKind.shortLabel() + JMH_STUB_SUFFIX; compilerControl.defaultForceInline(method); writer.println(ident(1) + "public static" + (methodGroup.isStrictFP() ? " strictfp" : "") + " void " + methodName + "(" + getStubTypeArgs() + ", SampleBuffer buffer, int targetSamples, long opsPerInv, int batchSize" + prefix(states.getTypeArgList(method)) + ") throws Throwable {"); writer.println(ident(2) + "long realTime = 0;"); writer.println(ident(2) + "long operations = 0;"); writer.println(ident(2) + "int rnd = (int)System.nanoTime();"); writer.println(ident(2) + "int rndMask = startRndMask;"); writer.println(ident(2) + "long time = 0;"); writer.println(ident(2) + "int currentStride = 0;"); writer.println(ident(2) + "do {"); invocationProlog(writer, 3, method, states, true); writer.println(ident(3) + "rnd = (rnd * 1664525 + 1013904223);"); writer.println(ident(3) + "boolean sample = (rnd & rndMask) == 0;"); writer.println(ident(3) + "if (sample) {"); writer.println(ident(4) + "time = System.nanoTime();"); writer.println(ident(3) + "}"); writer.println(ident(3) + "for (int b = 0; b < batchSize; b++) {"); writer.println(ident(4) + "if (control.volatileSpoiler) return;"); writer.println(ident(4) + "" + emitCall(method, states) + ';'); writer.println(ident(3) + "}"); writer.println(ident(3) + "if (sample) {"); writer.println(ident(4) + "buffer.add((System.nanoTime() - time) / opsPerInv);"); writer.println(ident(4) + "if (currentStride++ > targetSamples) {"); writer.println(ident(5) + "buffer.half();"); writer.println(ident(5) + "currentStride = 0;"); writer.println(ident(5) + "rndMask = (rndMask << 1) + 1;"); writer.println(ident(4) + "}"); writer.println(ident(3) + "}"); invocationEpilog(writer, 3, method, states, true); writer.println(ident(3) + "operations++;"); writer.println(ident(2) + "} while(!control.isDone);"); writer.println(ident(2) + "startRndMask = Math.max(startRndMask, rndMask);"); writer.println(ident(2) + "result.realTime = realTime;"); writer.println(ident(2) + "result.measuredOps = operations;"); writer.println(ident(1) + "}"); writer.println(); } } private void generateSingleShotTime(PrintWriter writer, Mode benchmarkKind, MethodGroup methodGroup, StateObjectHandler states) { writer.println(ident(1) + "public BenchmarkTaskResult " + methodGroup.getName() + "_" + benchmarkKind + "(InfraControl control, ThreadParams threadParams) throws Throwable {"); methodProlog(writer); boolean isSingleMethod = (methodGroup.methods().size() == 1); int subGroup = -1; for (MethodInfo method : methodGroup.methods()) { compilerControl.defaultForceInline(method); subGroup++; writer.println(ident(2) + "if (threadParams.getSubgroupIndex() == " + subGroup + ") {"); iterationProlog(writer, 3, method, states); // control objects get a special treatment writer.println(ident(3) + "notifyControl.startMeasurement = true;"); // measurement loop call writer.println(ident(3) + "RawResults res = new RawResults();"); writer.println(ident(3) + "int batchSize = iterationParams.getBatchSize();"); writer.println(ident(3) + method.getName() + "_" + benchmarkKind.shortLabel() + JMH_STUB_SUFFIX + "(" + getStubArgs() + ", batchSize" + prefix(states.getArgList(method)) + ");"); writer.println(ident(3) + "control.preTearDown();"); iterationEpilog(writer, 3, method, states); /* * Adjust total ops: * Single shot always does single op. Therefore, we need to adjust for $opsPerInv (pretending each @Benchmark * invocation counts as $opsPerInv ops). We *don't need* to adjust down for $batchSize, because we always have * one "op". */ writer.println(ident(3) + "int opsPerInv = control.benchmarkParams.getOpsPerInvocation();"); writer.println(ident(3) + "long totalOps = opsPerInv;"); writer.println(ident(3) + "BenchmarkTaskResult results = new BenchmarkTaskResult(totalOps, totalOps);"); if (isSingleMethod) { writer.println(ident(3) + "results.add(new SingleShotResult(ResultRole.PRIMARY, \"" + method.getName() + "\", res.getTime(), totalOps, benchmarkParams.getTimeUnit()));"); } else { writer.println(ident(3) + "results.add(new SingleShotResult(ResultRole.PRIMARY, \"" + methodGroup.getName() + "\", res.getTime(), totalOps, benchmarkParams.getTimeUnit()));"); writer.println(ident(3) + "results.add(new SingleShotResult(ResultRole.SECONDARY, \"" + method.getName() + "\", res.getTime(), totalOps, benchmarkParams.getTimeUnit()));"); } addAuxCounters(writer, "SingleShotResult", states, method); methodEpilog(writer); writer.println(ident(3) + "return results;"); writer.println(ident(2) + "} else"); } writer.println(ident(3) + "throw new IllegalStateException(\"Harness failed to distribute threads among groups properly\");"); writer.println(ident(1) + "}"); writer.println(); // measurement stub bodies for (MethodInfo method : methodGroup.methods()) { String methodName = method.getName() + "_" + benchmarkKind.shortLabel() + JMH_STUB_SUFFIX; compilerControl.defaultForceInline(method); writer.println(ident(1) + "public static" + (methodGroup.isStrictFP() ? " strictfp" : "") + " void " + methodName + "(" + getStubTypeArgs() + ", int batchSize" + prefix(states.getTypeArgList(method)) + ") throws Throwable {"); writer.println(ident(2) + "long realTime = 0;"); writer.println(ident(2) + "result.startTime = System.nanoTime();"); writer.println(ident(2) + "for (int b = 0; b < batchSize; b++) {"); writer.println(ident(3) + "if (control.volatileSpoiler) return;"); invocationProlog(writer, 3, method, states, true); writer.println(ident(3) + emitCall(method, states) + ';'); invocationEpilog(writer, 3, method, states, true); writer.println(ident(2) + "}"); writer.println(ident(2) + "result.stopTime = System.nanoTime();"); writer.println(ident(2) + "result.realTime = realTime;"); writer.println(ident(1) + "}"); writer.println(); } } private void invocationProlog(PrintWriter writer, int prefix, MethodInfo method, StateObjectHandler states, boolean pauseMeasurement) { if (states.hasInvocationStubs(method)) { for (String s : states.getInvocationSetups(method)) writer.println(ident(prefix) + s); if (pauseMeasurement) writer.println(ident(prefix) + "long rt = System.nanoTime();"); } } private void invocationEpilog(PrintWriter writer, int prefix, MethodInfo method, StateObjectHandler states, boolean pauseMeasurement) { if (states.hasInvocationStubs(method)) { if (pauseMeasurement) writer.println(ident(prefix) + "realTime += (System.nanoTime() - rt);"); for (String s : states.getInvocationTearDowns(method)) writer.println(ident(prefix) + s); } } private void iterationProlog(PrintWriter writer, int prefix, MethodInfo method, StateObjectHandler states) { for (String s : states.getStateGetters(method)) writer.println(ident(prefix) + s); writer.println(); writer.println(ident(prefix) + "control.preSetup();"); for (String s : states.getIterationSetups(method)) writer.println(ident(prefix) + s); writer.println(); // reset @AuxCounters for (String s : states.getAuxResets(method)) writer.println(ident(prefix) + s); writer.println(); } private void iterationEpilog(PrintWriter writer, int prefix, MethodInfo method, StateObjectHandler states) { for (String s : states.getIterationTearDowns(method)) writer.println(ident(prefix) + s); writer.println(); writer.println(ident(prefix) + "if (control.isLastIteration()) {"); for (String s : states.getRunTearDowns(method)) writer.println(ident(prefix + 1) + s); for (String s : states.getStateDestructors(method)) writer.println(ident(prefix + 1) + s); writer.println(ident(prefix) + "}"); } private String emitCall(MethodInfo method, StateObjectHandler states) { if ("void".equalsIgnoreCase(method.getReturnType())) { return states.getImplicit("bench").localIdentifier + "." + method.getName() + "(" + states.getBenchmarkArgList(method) + ")"; } else { return "blackhole.consume(" + states.getImplicit("bench").localIdentifier + "." + method.getName() + "(" + states.getBenchmarkArgList(method) + "))"; } } static volatile String[] INDENTS; static final Object INDENTS_LOCK = new Object(); static String ident(int tabs) { String[] is = INDENTS; if (is == null || tabs >= is.length) { synchronized (INDENTS_LOCK) { is = INDENTS; if (is == null || tabs >= is.length) { final int TAB_SIZE = 4; is = new String[tabs + 1]; for (int p = 0; p <= tabs; p++) { char[] cs = new char[p * TAB_SIZE]; Arrays.fill(cs, ' '); is[p] = new String(cs); } INDENTS = is; } } } return is[tabs]; } }
54,902
46.658854
199
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGeneratorSession.java
/* * Copyright (c) 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.generators.core; import java.util.HashSet; import java.util.Set; public class BenchmarkGeneratorSession { public final Set<String> generatedStateOverrides = new HashSet<>(); }
1,419
42.030303
79
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGeneratorUtils.java
/* * Copyright (c) 2005, 2022, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.generators.core; import org.openjdk.jmh.annotations.AuxCounters; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.CompilerControl; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Group; import org.openjdk.jmh.annotations.GroupThreads; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.OperationsPerInvocation; import org.openjdk.jmh.annotations.OutputTimeUnit; import org.openjdk.jmh.annotations.Param; import org.openjdk.jmh.annotations.Setup; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.TearDown; import org.openjdk.jmh.annotations.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.util.HashMultimap; import org.openjdk.jmh.util.Multimap; import java.lang.annotation.Annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Target; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; class BenchmarkGeneratorUtils { private static final Collection<Class<? extends Annotation>> JMH_ANNOTATIONS; private static final Multimap<Class<? extends Annotation>, ElementType> JMH_ANNOTATION_TARGETS; static { JMH_ANNOTATIONS = Arrays.asList( AuxCounters.class, BenchmarkMode.class, CompilerControl.class, Fork.class, Benchmark.class, Group.class, GroupThreads.class, Measurement.class, OperationsPerInvocation.class, OutputTimeUnit.class, Param.class, Setup.class, State.class, TearDown.class, Threads.class, Warmup.class ); JMH_ANNOTATION_TARGETS = new HashMultimap<>(); for (Class<? extends Annotation> ann : JMH_ANNOTATIONS) { Target target = ann.getAnnotation(Target.class); if (target != null) { ElementType[] types = target.value(); for (ElementType type : types) { JMH_ANNOTATION_TARGETS.put(ann, type); } } } } public static boolean checkJavaIdentifier(String id) { for (int i = 0; i < id.length(); i++) { char c = id.charAt(i); if (!Character.isJavaIdentifierPart(c)) { return false; } } return true; } public static <T extends Annotation> Collection<MethodInfo> getMethodsAnnotatedWith(GeneratorSource source, Class<T> annClass) { List<MethodInfo> mis = new ArrayList<>(); for (ClassInfo ci : source.getClasses()) { for (MethodInfo mi : ci.getMethods()) { if (mi.getAnnotation(annClass) != null) { mis.add(mi); } } } return mis; } public static <T extends Annotation> Collection<ClassInfo> getClassesAnnotatedWith(GeneratorSource source, Class<T> annClass) { List<ClassInfo> cis = new ArrayList<>(); for (ClassInfo ci : source.getClasses()) { if (ci.getAnnotation(annClass) != null) { cis.add(ci); } } return cis; } public static <T extends Annotation> Collection<FieldInfo> getFieldsAnnotatedWith(GeneratorSource source, Class<T> annClass) { List<FieldInfo> mis = new ArrayList<>(); for (ClassInfo ci : source.getClasses()) { for (FieldInfo mi : ci.getFields()) { if (mi.getAnnotation(annClass) != null) { mis.add(mi); } } } return mis; } public static Collection<FieldInfo> getAllFields(ClassInfo ci) { List<FieldInfo> ls = new ArrayList<>(); do { ls.addAll(ci.getFields()); } while ((ci = ci.getSuperClass()) != null); return ls; } public static Collection<MethodInfo> getAllMethods(ClassInfo ci) { List<MethodInfo> ls = new ArrayList<>(); do { ls.addAll(ci.getMethods()); } while ((ci = ci.getSuperClass()) != null); return ls; } public static <T extends Annotation> T getAnnSuper(ClassInfo ci, Class<T> annClass) { T ann = ci.getAnnotation(annClass); if (ann != null) { return ann; } else { ClassInfo eci = ci.getSuperClass(); if (eci != null) { return getAnnSuper(eci, annClass); } } return null; } public static <T extends Annotation> T getAnnSyntax(ClassInfo ci, Class<T> annClass) { T ann = ci.getAnnotation(annClass); if (ann != null) { return ann; } else { ClassInfo eci = ci.getDeclaringClass(); if (eci != null) { return getAnnSyntax(eci, annClass); } } return null; } public static <T extends Annotation> T getAnnSyntax(MethodInfo mi, Class<T> annClass) { T ann = mi.getAnnotation(annClass); if (ann != null) { return ann; } else { return getAnnSyntax(mi.getDeclaringClass(), annClass); } } public static <T extends Annotation> T getAnnSuper(MethodInfo mi, Class<T> annClass) { T ann = mi.getAnnotation(annClass); if (ann != null) { return ann; } else { return getAnnSuper(mi.getDeclaringClass(), annClass); } } public static <T extends Annotation> T getAnnSuper(MethodInfo mi, ClassInfo startCi, Class<T> annClass) { T ann = mi.getAnnotation(annClass); if (ann != null) { return ann; } else { return getAnnSuper(startCi, annClass); } } public static <T extends Annotation> Collection<T> getAnnSuperAll(MethodInfo mi, ClassInfo startCi, Class<T> annClass) { Collection<T> results = new ArrayList<>(); { T ann = mi.getAnnotation(annClass); if (ann != null) { results.add(ann); } } ClassInfo ci = startCi; do { T ann = ci.getAnnotation(annClass); if (ann != null) { results.add(ann); } ci = ci.getSuperClass(); } while (ci != null); return results; } public static String getGeneratedName(ClassInfo ci) { String name = ""; do { name = ci.getName() + (name.isEmpty() ? "" : "_" + name); } while ((ci = ci.getDeclaringClass()) != null); return name; } public static String getNestedNames(ClassInfo ci) { String name = ""; do { name = ci.getName() + (name.isEmpty() ? "" : "$" + name); } while ((ci = ci.getDeclaringClass()) != null); return name; } public static void checkAnnotations(FieldInfo fi) { for (Class<? extends Annotation> ann : JMH_ANNOTATIONS) { if (fi.getAnnotation(ann) != null && !JMH_ANNOTATION_TARGETS.get(ann).contains(ElementType.FIELD)) { throw new GenerationException( "Annotation @" + ann.getSimpleName() + " is not applicable to fields.", fi); } } } public static void checkAnnotations(ClassInfo ci) { for (Class<? extends Annotation> ann : JMH_ANNOTATIONS) { if (ci.getAnnotation(ann) != null && !JMH_ANNOTATION_TARGETS.get(ann).contains(ElementType.TYPE)) { throw new GenerationException( "Annotation @" + ann.getSimpleName() + " is not applicable to types.", ci); } } } public static void checkAnnotations(MethodInfo mi) { for (Class<? extends Annotation> ann : JMH_ANNOTATIONS) { if (mi.getAnnotation(ann) != null && !JMH_ANNOTATION_TARGETS.get(ann).contains(ElementType.METHOD)) { throw new GenerationException( "Annotation @" + ann.getSimpleName() + " is not applicable to methods.", mi); } } } /** * <p>Gets the parameter values to be used for this field. In most cases this will be the values declared * in the {@code @Param} annotation.</p> * * <p>For an enum field type, an empty parameter list will be resolved to be the full list of enum constants * of that type.</p> * * @param fi type of the field for which to find parameters * @return string values representing the actual parameters */ private static String[] toParameterValues(FieldInfo fi) { String[] annotatedValues = fi.getAnnotation(Param.class).value(); boolean isBlankEnum = (annotatedValues.length == 1) && Param.BLANK_ARGS.equals(annotatedValues[0]) && fi.getType().isEnum(); if (isBlankEnum) { Collection<String> enumConstants = fi.getType().getEnumConstants(); if (enumConstants.isEmpty()) { throw new GenerationException("Enum type of field had no constants. " + "Declare some constants or remove the @" + Param.class.getSimpleName() + ".", fi); } return enumConstants.toArray(new String[0]); } else { return annotatedValues; } } /** * Compute the parameter space given by {@code @Param} annotations and add all them to the group. * * @param host type of the state {@code @State} in which to find {@code @Param}s * @param group method group */ static void addParameterValuesToGroup(ClassInfo host, MethodGroup group) { // Add all inherited @Param fields for (FieldInfo fi : getAllFields(host)) { if (fi.getAnnotation(Param.class) != null) { String[] values = toParameterValues(fi); group.addParamValues(fi.getName(), values); } } // Add all @Param fields reachable through the dependencies. // This recursive approach always converges because @State dependency graph is DAG. for (MethodInfo mi : getAllMethods(host)) { if (mi.getAnnotation(Setup.class) != null || mi.getAnnotation(TearDown.class) != null) { for (ParameterInfo pi : mi.getParameters()) { addParameterValuesToGroup(pi.getType(), group); } } } } }
11,773
36.377778
132
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkInfo.java
/* * Copyright (c) 2005, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.generators.core; class BenchmarkInfo { public final String userClassQName; public final String generatedClassQName; public final String generatedPackageName; public final String generatedClassName; public final MethodGroup methodGroup; public BenchmarkInfo(String userClassQName, String generatedPackageName, String generatedClassName, MethodGroup methodGroup) { this.userClassQName = userClassQName; this.generatedPackageName = generatedPackageName; this.generatedClassName = generatedClassName; this.generatedClassQName = generatedPackageName + "." + generatedClassName; this.methodGroup = methodGroup; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; BenchmarkInfo that = (BenchmarkInfo) o; if (!methodGroup.equals(that.methodGroup)) return false; if (!userClassQName.equals(that.userClassQName)) return false; return true; } @Override public int hashCode() { int result = userClassQName.hashCode(); result = 31 * result + methodGroup.hashCode(); return result; } }
2,461
38.709677
130
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/generators/core/ClassInfo.java
/* * Copyright (c) 2005, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.generators.core; import java.lang.annotation.Annotation; import java.util.Collection; /** * Class metadata. */ public interface ClassInfo extends MetadataInfo { /** * @return fully qualified package name */ String getPackageName(); /** * * @return fully qualified class name */ String getQualifiedName(); /** * @return short class name */ String getName(); /** * @return reference to super-class metadata */ ClassInfo getSuperClass(); /** * @return reference to syntactically-enclosing class */ ClassInfo getDeclaringClass(); /** * @return collection of all fields in class */ Collection<FieldInfo> getFields(); /** * @return collection of all methods in class */ Collection<MethodInfo> getMethods(); /** * @return collection of all constructors in class */ Collection<MethodInfo> getConstructors(); /** * @param annClass annotation class * @param <T> annotation type * @return class-level annotation, if any; null otherwise */ <T extends Annotation> T getAnnotation(Class<T> annClass); /** * @return true, if class is abstract */ boolean isAbstract(); /** * @return true, if class is abstract */ boolean isPublic(); /** * @return true, if class is strictfp */ boolean isStrictFP(); /** * @return true, if class is final */ boolean isFinal(); /** * @return true, if class is inner */ boolean isInner(); /** * @return true, if class is enum */ boolean isEnum(); /** * @return if class is enum, the collection of its constant values; * empty collection otherwise */ Collection<String> getEnumConstants(); }
3,071
24.6
79
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/generators/core/CompilerControlPlugin.java
/* * Copyright (c) 2005, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.generators.core; import org.openjdk.jmh.annotations.CompilerControl; import org.openjdk.jmh.runner.CompilerHints; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Writer; import java.nio.charset.StandardCharsets; import java.util.Comparator; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; class CompilerControlPlugin { private final SortedSet<String> lines = new TreeSet<>(); private final Set<MethodInfo> defaultForceInlineMethods = new TreeSet<>(Comparator.comparing(MethodInfo::getQualifiedName)); private final Set<String> alwaysDontInlineMethods = new TreeSet<>(); public void defaultForceInline(MethodInfo methodInfo) { defaultForceInlineMethods.add(methodInfo); } public void alwaysDontInline(String className, String methodName) { alwaysDontInlineMethods.add(getName(className, methodName)); } public void process(GeneratorSource source, GeneratorDestination destination) { try { for (MethodInfo element : BenchmarkGeneratorUtils.getMethodsAnnotatedWith(source, CompilerControl.class)) { CompilerControl ann = element.getAnnotation(CompilerControl.class); if (ann == null) { throw new IllegalStateException("No annotation"); } CompilerControl.Mode command = ann.value(); lines.add(command.command() + "," + getName(element)); } for (MethodInfo element : defaultForceInlineMethods) { // Skip methods annotated explicitly if (element.getAnnotation(CompilerControl.class) != null) continue; // Skip methods in classes that are annotated explicitly if (element.getDeclaringClass().getAnnotation(CompilerControl.class) != null) continue; lines.add(CompilerControl.Mode.INLINE.command() + "," + getName(element)); } for (String element : alwaysDontInlineMethods) { lines.add(CompilerControl.Mode.DONT_INLINE.command() + "," + element); } for (ClassInfo element : BenchmarkGeneratorUtils.getClassesAnnotatedWith(source, CompilerControl.class)) { CompilerControl ann = element.getAnnotation(CompilerControl.class); if (ann == null) { throw new IllegalStateException("No annotation"); } CompilerControl.Mode command = ann.value(); lines.add(command.command() + "," + getName(element)); } } catch (Throwable t) { destination.printError("Compiler control generators had thrown the unexpected exception", t); } } public void finish(GeneratorSource source, GeneratorDestination destination) { try (Writer w = new OutputStreamWriter(destination.newResource(CompilerHints.LIST.substring(1)), StandardCharsets.UTF_8)){ PrintWriter writer = new PrintWriter(w); for (String line : lines) { writer.println(line); } writer.close(); } catch (IOException ex) { destination.printError("Error writing compiler hint list ", ex); } catch (Throwable t) { destination.printError("Compiler control generators had thrown the unexpected exception", t); } } private static String getName(String className, String methodName) { return className.replaceAll("\\.", "/") + "." + methodName; } private static String getName(MethodInfo mi) { return getName(getClassName(mi.getDeclaringClass()), mi.getName()); } private static String getName(ClassInfo ci) { return getName(getClassName(ci), "*"); } private static String getClassName(ClassInfo ci) { return ci.getPackageName() + "." + BenchmarkGeneratorUtils.getNestedNames(ci); } }
5,220
39.789063
130
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/generators/core/FieldInfo.java
/* * Copyright (c) 2005, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.generators.core; import java.lang.annotation.Annotation; /** * Field metadata info. */ public interface FieldInfo extends MetadataInfo { /** * @return field name */ String getName(); /** * @return fully qualified field type */ ClassInfo getType(); /** * @return reference to syntactically-enclosing class */ ClassInfo getDeclaringClass(); /** * @param annClass annotation class * @param <T> annotation type * @return field-level annotation, if any; null otherwise */ <T extends Annotation> T getAnnotation(Class<T> annClass); /** * @return true, if field is public */ boolean isPublic(); /** * @return true, if field is static */ boolean isStatic(); /** * @return true, if field is final */ boolean isFinal(); }
2,096
28.535211
79
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/generators/core/FileSystemDestination.java
/* * Copyright (c) 2005, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.generators.core; import java.io.*; import java.util.ArrayList; import java.util.Collection; import java.util.List; public class FileSystemDestination implements GeneratorDestination { private final File resourceDir; private final File sourceDir; private final List<SourceError> sourceErrors; private final List<SourceWarning> sourceWarnings; public FileSystemDestination(File resourceDir, File sourceDir) { this.resourceDir = resourceDir; this.sourceDir = sourceDir; this.sourceErrors = new ArrayList<>(); this.sourceWarnings = new ArrayList<>(); } @Override public OutputStream newResource(String resourcePath) throws IOException { String pathName = resourceDir.getAbsolutePath() + "/" + resourcePath; File p = new File(pathName.substring(0, pathName.lastIndexOf("/"))); if (!p.mkdirs() && !p.isDirectory()) { throw new IOException("Unable to create " + p.getAbsolutePath()); } return new FileOutputStream(new File(pathName)); } @Override public InputStream getResource(String resourcePath) throws IOException { String pathName = resourceDir.getAbsolutePath() + "/" + resourcePath; File p = new File(pathName.substring(0, pathName.lastIndexOf("/"))); if (!p.isFile() && !p.exists()) { throw new IOException("Unable to open " + pathName); } return new FileInputStream(new File(pathName)); } @Override public Writer newClass(String className, String originatingClassName) throws IOException { String pathName = sourceDir.getAbsolutePath() + "/" + className.replaceAll("\\.", "/"); File p = new File(pathName.substring(0, pathName.lastIndexOf("/"))); if (!p.mkdirs() && !p.isDirectory()) { throw new IOException("Unable to create " + p.getAbsolutePath()); } return new FileWriter(new File(pathName + ".java")); } @Override public void printError(String message) { sourceErrors.add(new SourceError(message)); } @Override public void printError(String message, MetadataInfo element) { sourceErrors.add(new SourceElementError(message, element)); } @Override public void printError(String message, Throwable throwable) { sourceErrors.add(new SourceThrowableError(message, throwable)); } public boolean hasErrors() { return !sourceErrors.isEmpty(); } public Collection<SourceError> getErrors() { return sourceErrors; } @Override public void printWarning(String message) { sourceWarnings.add(new SourceWarning(message)); } @Override public void printWarning(String message, MetadataInfo element) { sourceWarnings.add(new SourceElementWarning(message, element)); } @Override public void printWarning(String message, Throwable throwable) { sourceWarnings.add(new SourceThrowableWarning(message, throwable)); } public boolean hasWarnings() { return !sourceWarnings.isEmpty(); } public Collection<SourceWarning> getWarnings() { return sourceWarnings; } @Override public void printNote(String message) { // do nothing } }
4,516
34.566929
95
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/generators/core/GenerationException.java
/* * Copyright (c) 2005, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.generators.core; public class GenerationException extends RuntimeException { private static final long serialVersionUID = -3462499052514960496L; private final MetadataInfo element; public GenerationException(String message, MetadataInfo element) { super(message); this.element = element; } public MetadataInfo getElement() { return element; } }
1,634
38.878049
79
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/generators/core/GeneratorDestination.java
/* * Copyright (c) 2005, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.generators.core; import java.io.*; /** * Generator destination. * * <p>The exit point for {@link org.openjdk.jmh.generators.core.BenchmarkGenerator}.</p> */ public interface GeneratorDestination { /** * Returns the stream for the given resource. * Callers are responsible for closing streams. * * @param resourcePath resource path * @return output stream to write the resource to. * @throws java.io.IOException if something wacked happens */ OutputStream newResource(String resourcePath) throws IOException; /** * Returns the stream for the given resource. * Callers are responsible for closing streams. * * @param resourcePath resource path * @return stream usable to read the resource * @throws java.io.IOException if something wacked happens */ InputStream getResource(String resourcePath) throws IOException; /** * Returns the Writer for the given class. * Callers are responsible for closing Writers. * * @param className class name * @param originatingClassName class name causing the creation of this class * @return writer usable to write the resource * @throws IOException if something wacked happens */ Writer newClass(String className, String originatingClassName) throws IOException; /** * Print the error. * Calling this method should not terminate anything. * * @param message error. */ void printError(String message); /** * Print the error. * Calling this method should not terminate anything. * * @param message error. * @param element metadata element, to which this error is tailored */ void printError(String message, MetadataInfo element); /** * Print the error. * Calling this method should not terminate anything. * * @param message error. * @param throwable exception causing the error */ void printError(String message, Throwable throwable); /** * Print the warning. * Calling this method should not terminate anything. * * @param message warning. */ void printWarning(String message); /** * Print the warning. * Calling this method should not terminate anything. * * @param message warning. * @param element metadata element, to which this error is tailored */ void printWarning(String message, MetadataInfo element); /** * Print the warning. * Calling this method should not terminate anything. * * @param message warning. * @param throwable exception causing the error */ void printWarning(String message, Throwable throwable); /** * Print the informative message. * Calling this method should not terminate anything. * * @param message message. */ void printNote(String message); }
4,149
31.677165
88
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/generators/core/GeneratorSource.java
/* * Copyright (c) 2005, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.generators.core; import java.util.Collection; /** * Generator source. * <p>The entry point for {@link org.openjdk.jmh.generators.core.BenchmarkGenerator}.</p> */ public interface GeneratorSource { /** * @return collection of all resolved classes */ Collection<ClassInfo> getClasses(); /** * Resolve class info for a name. * * <p>Users may call this method for the classes not * listed in {@link #getClasses()} call, the implementation * has to have the fall-back strategy for these cases.</p> * * @param className class name * @return class metainfo */ ClassInfo resolveClass(String className); }
1,913
35.113208
89
java
jmh
jmh-master/jmh-core/src/main/java/org/openjdk/jmh/generators/core/HelperMethodInvocation.java
/* * Copyright (c) 2005, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.jmh.generators.core; import org.openjdk.jmh.annotations.Level; class HelperMethodInvocation implements Comparable<HelperMethodInvocation> { public final MethodInfo method; public final StateObject state; public final Level helperLevel; public final HelperType type; public HelperMethodInvocation(MethodInfo method, StateObject state, Level helperLevel, HelperType type) { this.method = method; this.state = state; this.helperLevel = helperLevel; this.type = type; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; HelperMethodInvocation that = (HelperMethodInvocation) o; if (helperLevel != that.helperLevel) return false; if (!method.equals(that.method)) return false; if (!state.equals(that.state)) return false; if (type != that.type) return false; return true; } @Override public int hashCode() { int result = method.hashCode(); result = 31 * result + state.hashCode(); result = 31 * result + helperLevel.hashCode(); result = 31 * result + type.hashCode(); return result; } @Override public int compareTo(HelperMethodInvocation o) { return method.compareTo(o.method); } }
2,605
35.704225
109
java