< prev index next >

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

Print this page




  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.test;
  24 
  25 import static org.graalvm.compiler.debug.DebugContext.DEFAULT_LOG_STREAM;
  26 import static org.graalvm.compiler.debug.DebugContext.NO_DESCRIPTION;
  27 import static org.graalvm.compiler.debug.DebugContext.NO_GLOBAL_METRIC_VALUES;
  28 
  29 import java.io.PrintStream;
  30 import java.io.PrintWriter;
  31 import java.lang.reflect.Field;
  32 import java.lang.reflect.Method;
  33 import java.util.ArrayList;
  34 import java.util.Arrays;
  35 import java.util.Collection;
  36 import java.util.Collections;
  37 import java.util.List;
  38 

  39 import org.graalvm.compiler.debug.DebugHandlersFactory;
  40 import org.graalvm.compiler.debug.DebugContext;
  41 import org.graalvm.compiler.debug.DebugDumpHandler;
  42 import org.graalvm.compiler.options.OptionValues;
  43 import org.junit.After;
  44 import org.junit.Assert;
  45 import org.junit.internal.ComparisonCriteria;
  46 import org.junit.internal.ExactComparisonCriteria;
  47 
  48 import sun.misc.Unsafe;
  49 
  50 /**
  51  * Base class that contains common utility methods and classes useful in unit tests.
  52  */
  53 public class GraalTest {
  54 
  55     public static final Unsafe UNSAFE;
  56     static {
  57         try {
  58             Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");


 375      * @param message the identifying message for the {@link AssertionError}
 376      * @param objects arguments to the format string
 377      */
 378     public static void assertFalse(boolean condition, String message, Object... objects) {
 379         assertTrue(!condition, message, objects);
 380     }
 381 
 382     /**
 383      * Gets the {@link DebugHandlersFactory}s available for a {@link DebugContext}.
 384      */
 385     protected Collection<DebugHandlersFactory> getDebugHandlersFactories() {
 386         return Collections.emptyList();
 387     }
 388 
 389     /**
 390      * Gets a {@link DebugContext} object corresponding to {@code options}, creating a new one if
 391      * none currently exists. Debug contexts created by this method will have their
 392      * {@link DebugDumpHandler}s closed in {@link #afterTest()}.
 393      */
 394     protected DebugContext getDebugContext(OptionValues options) {














 395         List<DebugContext> cached = cachedDebugs.get();
 396         if (cached == null) {
 397             cached = new ArrayList<>();
 398             cachedDebugs.set(cached);
 399         }
 400         for (DebugContext debug : cached) {
 401             if (debug.getOptions() == options) {
 402                 return debug;
 403             }
 404         }
 405         DebugContext debug = DebugContext.create(options, NO_DESCRIPTION, NO_GLOBAL_METRIC_VALUES, DEFAULT_LOG_STREAM, getDebugHandlersFactories());






 406         cached.add(debug);
 407         return debug;
 408     }
 409 
 410     private final ThreadLocal<List<DebugContext>> cachedDebugs = new ThreadLocal<>();
 411 
 412     @After
 413     public void afterTest() {
 414         List<DebugContext> cached = cachedDebugs.get();
 415         if (cached != null) {
 416             for (DebugContext debug : cached) {
 417                 debug.closeDumpHandlers(true);
 418             }
 419         }
 420     }
 421 }


  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.test;
  24 
  25 import static org.graalvm.compiler.debug.DebugContext.DEFAULT_LOG_STREAM;
  26 import static org.graalvm.compiler.debug.DebugContext.NO_DESCRIPTION;
  27 import static org.graalvm.compiler.debug.DebugContext.NO_GLOBAL_METRIC_VALUES;
  28 
  29 import java.io.PrintStream;
  30 import java.io.PrintWriter;
  31 import java.lang.reflect.Field;
  32 import java.lang.reflect.Method;
  33 import java.util.ArrayList;
  34 import java.util.Arrays;
  35 import java.util.Collection;
  36 import java.util.Collections;
  37 import java.util.List;
  38 
  39 import jdk.vm.ci.meta.ResolvedJavaMethod;
  40 import org.graalvm.compiler.debug.DebugHandlersFactory;
  41 import org.graalvm.compiler.debug.DebugContext;
  42 import org.graalvm.compiler.debug.DebugDumpHandler;
  43 import org.graalvm.compiler.options.OptionValues;
  44 import org.junit.After;
  45 import org.junit.Assert;
  46 import org.junit.internal.ComparisonCriteria;
  47 import org.junit.internal.ExactComparisonCriteria;
  48 
  49 import sun.misc.Unsafe;
  50 
  51 /**
  52  * Base class that contains common utility methods and classes useful in unit tests.
  53  */
  54 public class GraalTest {
  55 
  56     public static final Unsafe UNSAFE;
  57     static {
  58         try {
  59             Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");


 376      * @param message the identifying message for the {@link AssertionError}
 377      * @param objects arguments to the format string
 378      */
 379     public static void assertFalse(boolean condition, String message, Object... objects) {
 380         assertTrue(!condition, message, objects);
 381     }
 382 
 383     /**
 384      * Gets the {@link DebugHandlersFactory}s available for a {@link DebugContext}.
 385      */
 386     protected Collection<DebugHandlersFactory> getDebugHandlersFactories() {
 387         return Collections.emptyList();
 388     }
 389 
 390     /**
 391      * Gets a {@link DebugContext} object corresponding to {@code options}, creating a new one if
 392      * none currently exists. Debug contexts created by this method will have their
 393      * {@link DebugDumpHandler}s closed in {@link #afterTest()}.
 394      */
 395     protected DebugContext getDebugContext(OptionValues options) {
 396         return getDebugContext(options, null, null);
 397     }
 398 
 399     /**
 400      * Gets a {@link DebugContext} object corresponding to {@code options}, creating a new one if
 401      * none currently exists.Debug contexts created by this method will have their
 402      * {@link DebugDumpHandler}s closed in {@link #afterTest()}.
 403      * 
 404      * @param options currently active options
 405      * @param id identification of the compilation or {@code null}
 406      * @param method method to use for a proper description of the context or {@code null}
 407      * @return configured context for compilation
 408      */
 409     protected DebugContext getDebugContext(OptionValues options, String id, ResolvedJavaMethod method) {
 410         List<DebugContext> cached = cachedDebugs.get();
 411         if (cached == null) {
 412             cached = new ArrayList<>();
 413             cachedDebugs.set(cached);
 414         }
 415         for (DebugContext debug : cached) {
 416             if (debug.getOptions() == options) {
 417                 return debug;
 418             }
 419         }
 420         final DebugContext.Description descr;
 421         if (method == null) {
 422             descr = NO_DESCRIPTION;
 423         } else {
 424             descr = new DebugContext.Description(method, id == null ? method.getName() : id);
 425         }
 426         DebugContext debug = DebugContext.create(options, descr, NO_GLOBAL_METRIC_VALUES, DEFAULT_LOG_STREAM, getDebugHandlersFactories());
 427         cached.add(debug);
 428         return debug;
 429     }
 430 
 431     private final ThreadLocal<List<DebugContext>> cachedDebugs = new ThreadLocal<>();
 432 
 433     @After
 434     public void afterTest() {
 435         List<DebugContext> cached = cachedDebugs.get();
 436         if (cached != null) {
 437             for (DebugContext debug : cached) {
 438                 debug.closeDumpHandlers(true);
 439             }
 440         }
 441     }
 442 }
< prev index next >