view src/main/java/org/openjdk/gcbench/tests/UnderPressureTest.java @ 57:1655f5729b5a

Yielding tests.
author shade
date Mon, 19 Dec 2016 18:40:11 +0100
parents
children 05f1c96b89a1
line wrap: on
line source

package org.openjdk.gcbench.tests;

import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;


@Fork(jvmArgsPrepend = {"--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED"})
@State(Scope.Benchmark)
public class UnderPressureTest {

    SuperAllocator allocator;

    @Setup
    public void setup(Blackhole bh) {
        allocator = new SuperAllocator(bh);
        allocator.start();
    }

    @TearDown
    public void tearDown() throws InterruptedException {
        allocator.interrupt();
        allocator.join();
    }

    public class SuperAllocator extends Thread {
        private final Blackhole bh;

        public SuperAllocator(Blackhole bh) {
            this.bh = bh;
        }

        @Override
        public void run() {
            while (!Thread.interrupted()) {
                bh.consume(AllocUninit.alloc(1000));
            }
        }
    }

}