< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug.test/src/org/graalvm/compiler/debug/test/TimerKeyTest.java

Print this page
rev 52509 : [mq]: graal


  22  */
  23 
  24 
  25 package org.graalvm.compiler.debug.test;
  26 
  27 import static org.graalvm.compiler.debug.DebugContext.DEFAULT_LOG_STREAM;
  28 import static org.graalvm.compiler.debug.DebugContext.NO_CONFIG_CUSTOMIZERS;
  29 import static org.graalvm.compiler.debug.DebugContext.NO_DESCRIPTION;
  30 import static org.graalvm.compiler.debug.DebugContext.NO_GLOBAL_METRIC_VALUES;
  31 import static org.junit.Assert.assertEquals;
  32 
  33 import jdk.internal.vm.compiler.collections.EconomicMap;
  34 import org.graalvm.compiler.debug.DebugCloseable;
  35 import org.graalvm.compiler.debug.DebugContext;
  36 import org.graalvm.compiler.debug.DebugOptions;
  37 import org.graalvm.compiler.debug.TimerKey;
  38 import org.graalvm.compiler.options.OptionKey;
  39 import org.graalvm.compiler.options.OptionValues;
  40 import org.graalvm.compiler.serviceprovider.GraalServices;
  41 import org.junit.Assume;

  42 import org.junit.Before;
  43 import org.junit.Test;
  44 
  45 @SuppressWarnings("try")
  46 public class TimerKeyTest {
  47 
  48     @Before
  49     public void checkCapabilities() {

  50         Assume.assumeTrue("skipping management interface test", GraalServices.isCurrentThreadCpuTimeSupported());










  51     }
  52 
  53     /**
  54      * Actively spins the current thread for at least a given number of milliseconds in such a way
  55      * that timers for the current thread keep ticking over.
  56      *
  57      * @return the number of milliseconds actually spent spinning which is guaranteed to be >=
  58      *         {@code ms}
  59      */
  60     private static long spin(long ms) {
  61         long start = GraalServices.getCurrentThreadCpuTime();
  62         do {
  63             long durationMS = (GraalServices.getCurrentThreadCpuTime() - start) / 1000;
  64             if (durationMS >= ms) {
  65                 return durationMS;
  66             }
  67         } while (true);
  68     }
  69 
  70     /**




  22  */
  23 
  24 
  25 package org.graalvm.compiler.debug.test;
  26 
  27 import static org.graalvm.compiler.debug.DebugContext.DEFAULT_LOG_STREAM;
  28 import static org.graalvm.compiler.debug.DebugContext.NO_CONFIG_CUSTOMIZERS;
  29 import static org.graalvm.compiler.debug.DebugContext.NO_DESCRIPTION;
  30 import static org.graalvm.compiler.debug.DebugContext.NO_GLOBAL_METRIC_VALUES;
  31 import static org.junit.Assert.assertEquals;
  32 
  33 import jdk.internal.vm.compiler.collections.EconomicMap;
  34 import org.graalvm.compiler.debug.DebugCloseable;
  35 import org.graalvm.compiler.debug.DebugContext;
  36 import org.graalvm.compiler.debug.DebugOptions;
  37 import org.graalvm.compiler.debug.TimerKey;
  38 import org.graalvm.compiler.options.OptionKey;
  39 import org.graalvm.compiler.options.OptionValues;
  40 import org.graalvm.compiler.serviceprovider.GraalServices;
  41 import org.junit.Assume;
  42 import org.junit.AssumptionViolatedException;
  43 import org.junit.Before;
  44 import org.junit.Test;
  45 
  46 @SuppressWarnings("try")
  47 public class TimerKeyTest {
  48 
  49     @Before
  50     public void checkCapabilities() {
  51         assumeManagementLibraryIsLoadable();
  52         Assume.assumeTrue("skipping management interface test", GraalServices.isCurrentThreadCpuTimeSupported());
  53     }
  54 
  55     /** @see <a href="https://bugs.openjdk.java.net/browse/JDK-8076557">JDK-8076557</a> */
  56     static void assumeManagementLibraryIsLoadable() {
  57         try {
  58             /* Trigger loading of the management library using the bootstrap class loader. */
  59             GraalServices.getCurrentThreadAllocatedBytes();
  60         } catch (UnsatisfiedLinkError | NoClassDefFoundError | UnsupportedOperationException e) {
  61             throw new AssumptionViolatedException("Management interface is unavailable: " + e);
  62         }
  63     }
  64 
  65     /**
  66      * Actively spins the current thread for at least a given number of milliseconds in such a way
  67      * that timers for the current thread keep ticking over.
  68      *
  69      * @return the number of milliseconds actually spent spinning which is guaranteed to be >=
  70      *         {@code ms}
  71      */
  72     private static long spin(long ms) {
  73         long start = GraalServices.getCurrentThreadCpuTime();
  74         do {
  75             long durationMS = (GraalServices.getCurrentThreadCpuTime() - start) / 1000;
  76             if (durationMS >= ms) {
  77                 return durationMS;
  78             }
  79         } while (true);
  80     }
  81 
  82     /**


< prev index next >