package org.openjdk; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.infra.Blackhole; import java.lang.reflect.*; import java.lang.ref.*; import java.util.concurrent.TimeUnit; @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) public class ReferenceBench { @Benchmark public boolean hasReferencePendingList() { return TestProxy.Reference_hasReferencePendingList(); } static class TestProxy { private static final Method hasReferencePendingListMethod; static { try { hasReferencePendingListMethod = Reference.class.getDeclaredMethod("hasReferencePendingList"); hasReferencePendingListMethod.setAccessible(true); } catch (Exception e) { throw new Error(e); } } static boolean Reference_hasReferencePendingList() { try { return (boolean) hasReferencePendingListMethod.invoke(null); } catch (InvocationTargetException e) { Throwable te = e.getTargetException(); if (te instanceof InterruptedException) { return true; } else if (te instanceof RuntimeException) { throw (RuntimeException) te; } else if (te instanceof Error) { throw (Error) te; } else { throw new UndeclaredThrowableException(te); } } catch (IllegalAccessException e) { throw new RuntimeException(e); } } } }