src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.test/src/org/graalvm/compiler/test/GraalTest.java
author dlong
Thu, 15 Nov 2018 09:04:07 -0800
changeset 52578 7dd81e82d083
parent 52427 3c6aa484536c
child 52910 583fd71c47d6
permissions -rw-r--r--
8210777: Update Graal Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
     1
/*
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
     2
 * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
     4
 *
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
     8
 *
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    13
 * accompanied this code).
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    14
 *
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    18
 *
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    21
 * questions.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    22
 */
50858
2d3e99a72541 8205824: Update Graal
never
parents: 49873
diff changeset
    23
2d3e99a72541 8205824: Update Graal
never
parents: 49873
diff changeset
    24
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    25
package org.graalvm.compiler.test;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    26
46640
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
    27
import static org.graalvm.compiler.debug.DebugContext.DEFAULT_LOG_STREAM;
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
    28
import static org.graalvm.compiler.debug.DebugContext.NO_DESCRIPTION;
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
    29
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    30
import java.io.PrintStream;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    31
import java.io.PrintWriter;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    32
import java.lang.reflect.Field;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    33
import java.lang.reflect.Method;
46640
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
    34
import java.util.ArrayList;
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    35
import java.util.Arrays;
46640
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
    36
import java.util.Collection;
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
    37
import java.util.Collections;
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 52427
diff changeset
    38
import java.util.List;
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
    39
import java.util.concurrent.TimeUnit;
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    40
46640
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
    41
import org.graalvm.compiler.debug.DebugContext;
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
    42
import org.graalvm.compiler.debug.DebugDumpHandler;
48861
47f19ff9903c 8194819: Update Graal
iveresov
parents: 47798
diff changeset
    43
import org.graalvm.compiler.debug.DebugHandlersFactory;
47f19ff9903c 8194819: Update Graal
iveresov
parents: 47798
diff changeset
    44
import org.graalvm.compiler.debug.GlobalMetrics;
46640
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
    45
import org.graalvm.compiler.options.OptionValues;
49873
26ebfe8ce852 8199755: Update Graal
dlong
parents: 48861
diff changeset
    46
import org.graalvm.compiler.serviceprovider.GraalServices;
46640
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
    47
import org.junit.After;
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    48
import org.junit.Assert;
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 52427
diff changeset
    49
import org.junit.AssumptionViolatedException;
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    50
import org.junit.internal.ComparisonCriteria;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    51
import org.junit.internal.ExactComparisonCriteria;
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
    52
import org.junit.rules.DisableOnDebug;
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
    53
import org.junit.rules.TestRule;
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
    54
import org.junit.rules.Timeout;
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    55
48861
47f19ff9903c 8194819: Update Graal
iveresov
parents: 47798
diff changeset
    56
import jdk.vm.ci.meta.ResolvedJavaMethod;
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    57
import sun.misc.Unsafe;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    58
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    59
/**
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    60
 * Base class that contains common utility methods and classes useful in unit tests.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    61
 */
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    62
public class GraalTest {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    63
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    64
    public static final Unsafe UNSAFE;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    65
    static {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    66
        try {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    67
            Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    68
            theUnsafe.setAccessible(true);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    69
            UNSAFE = (Unsafe) theUnsafe.get(Unsafe.class);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    70
        } catch (Exception e) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    71
            throw new RuntimeException("exception while trying to get Unsafe", e);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    72
        }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    73
    }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    74
49873
26ebfe8ce852 8199755: Update Graal
dlong
parents: 48861
diff changeset
    75
    public static final boolean Java8OrEarlier = GraalServices.Java8OrEarlier;
52427
3c6aa484536c 8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents: 51436
diff changeset
    76
    public static final boolean Java11OrEarlier = GraalServices.Java11OrEarlier;
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    77
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    78
    protected Method getMethod(String methodName) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    79
        return getMethod(getClass(), methodName);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    80
    }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    81
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    82
    protected Method getMethod(Class<?> clazz, String methodName) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    83
        Method found = null;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    84
        for (Method m : clazz.getMethods()) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    85
            if (m.getName().equals(methodName)) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    86
                Assert.assertNull(found);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    87
                found = m;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    88
            }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    89
        }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    90
        if (found == null) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    91
            /* Now look for non-public methods (but this does not look in superclasses). */
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    92
            for (Method m : clazz.getDeclaredMethods()) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    93
                if (m.getName().equals(methodName)) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    94
                    Assert.assertNull(found);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    95
                    found = m;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    96
                }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    97
            }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    98
        }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    99
        if (found != null) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   100
            return found;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   101
        } else {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   102
            throw new RuntimeException("method not found: " + methodName);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   103
        }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   104
    }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   105
46459
7d4e637d3f21 8180267: Update Graal
kvn
parents: 46371
diff changeset
   106
    protected Method getMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes) {
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   107
        try {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   108
            return clazz.getMethod(methodName, parameterTypes);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   109
        } catch (NoSuchMethodException | SecurityException e) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   110
            throw new RuntimeException("method not found: " + methodName + "" + Arrays.toString(parameterTypes));
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   111
        }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   112
    }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   113
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   114
    /**
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   115
     * Compares two given objects for {@linkplain Assert#assertEquals(Object, Object) equality}.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   116
     * Does a deep copy equality comparison if {@code expected} is an array.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   117
     */
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   118
    protected void assertDeepEquals(Object expected, Object actual) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   119
        assertDeepEquals(null, expected, actual);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   120
    }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   121
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   122
    /**
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   123
     * Compares two given objects for {@linkplain Assert#assertEquals(Object, Object) equality}.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   124
     * Does a deep copy equality comparison if {@code expected} is an array.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   125
     *
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   126
     * @param message the identifying message for the {@link AssertionError}
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   127
     */
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   128
    protected void assertDeepEquals(String message, Object expected, Object actual) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   129
        if (ulpsDelta() > 0) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   130
            assertDeepEquals(message, expected, actual, ulpsDelta());
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   131
        } else {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   132
            assertDeepEquals(message, expected, actual, equalFloatsOrDoublesDelta());
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   133
        }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   134
    }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   135
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   136
    /**
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   137
     * Compares two given values for equality, doing a recursive test if both values are arrays of
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   138
     * the same type.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   139
     *
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   140
     * @param message the identifying message for the {@link AssertionError}
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   141
     * @param delta the maximum delta between two doubles or floats for which both numbers are still
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   142
     *            considered equal.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   143
     */
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   144
    protected void assertDeepEquals(String message, Object expected, Object actual, double delta) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   145
        if (expected != null && actual != null) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   146
            Class<?> expectedClass = expected.getClass();
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   147
            Class<?> actualClass = actual.getClass();
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   148
            if (expectedClass.isArray()) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   149
                Assert.assertEquals(message, expectedClass, actual.getClass());
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   150
                if (expected instanceof int[]) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   151
                    Assert.assertArrayEquals(message, (int[]) expected, (int[]) actual);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   152
                } else if (expected instanceof byte[]) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   153
                    Assert.assertArrayEquals(message, (byte[]) expected, (byte[]) actual);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   154
                } else if (expected instanceof char[]) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   155
                    Assert.assertArrayEquals(message, (char[]) expected, (char[]) actual);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   156
                } else if (expected instanceof short[]) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   157
                    Assert.assertArrayEquals(message, (short[]) expected, (short[]) actual);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   158
                } else if (expected instanceof float[]) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   159
                    Assert.assertArrayEquals(message, (float[]) expected, (float[]) actual, (float) delta);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   160
                } else if (expected instanceof long[]) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   161
                    Assert.assertArrayEquals(message, (long[]) expected, (long[]) actual);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   162
                } else if (expected instanceof double[]) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   163
                    Assert.assertArrayEquals(message, (double[]) expected, (double[]) actual, delta);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   164
                } else if (expected instanceof boolean[]) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   165
                    new ExactComparisonCriteria().arrayEquals(message, expected, actual);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   166
                } else if (expected instanceof Object[]) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   167
                    new ComparisonCriteria() {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   168
                        @Override
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   169
                        protected void assertElementsEqual(Object e, Object a) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   170
                            assertDeepEquals(message, e, a, delta);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   171
                        }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   172
                    }.arrayEquals(message, expected, actual);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   173
                } else {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   174
                    Assert.fail((message == null ? "" : message) + "non-array value encountered: " + expected);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   175
                }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   176
            } else if (expectedClass.equals(double.class) && actualClass.equals(double.class)) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   177
                Assert.assertEquals((double) expected, (double) actual, delta);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   178
            } else if (expectedClass.equals(float.class) && actualClass.equals(float.class)) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   179
                Assert.assertEquals((float) expected, (float) actual, delta);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   180
            } else {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   181
                Assert.assertEquals(message, expected, actual);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   182
            }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   183
        } else {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   184
            Assert.assertEquals(message, expected, actual);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   185
        }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   186
    }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   187
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   188
    /**
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   189
     * Compares two given values for equality, doing a recursive test if both values are arrays of
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   190
     * the same type. Uses {@linkplain StrictMath#ulp(float) ULP}s for comparison of floats.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   191
     *
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   192
     * @param message the identifying message for the {@link AssertionError}
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   193
     * @param ulpsDelta the maximum allowed ulps difference between two doubles or floats for which
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   194
     *            both numbers are still considered equal.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   195
     */
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   196
    protected void assertDeepEquals(String message, Object expected, Object actual, int ulpsDelta) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   197
        ComparisonCriteria doubleUlpsDeltaCriteria = new ComparisonCriteria() {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   198
            @Override
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   199
            protected void assertElementsEqual(Object e, Object a) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   200
                assertTrue(message, e instanceof Double && a instanceof Double);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   201
                // determine acceptable error based on whether it is a normal number or a NaN/Inf
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   202
                double de = (Double) e;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   203
                double epsilon = (!Double.isNaN(de) && Double.isFinite(de) ? ulpsDelta * Math.ulp(de) : 0);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   204
                Assert.assertEquals(message, (Double) e, (Double) a, epsilon);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   205
            }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   206
        };
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   207
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   208
        ComparisonCriteria floatUlpsDeltaCriteria = new ComparisonCriteria() {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   209
            @Override
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   210
            protected void assertElementsEqual(Object e, Object a) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   211
                assertTrue(message, e instanceof Float && a instanceof Float);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   212
                // determine acceptable error based on whether it is a normal number or a NaN/Inf
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   213
                float fe = (Float) e;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   214
                float epsilon = (!Float.isNaN(fe) && Float.isFinite(fe) ? ulpsDelta * Math.ulp(fe) : 0);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   215
                Assert.assertEquals(message, (Float) e, (Float) a, epsilon);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   216
            }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   217
        };
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   218
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   219
        if (expected != null && actual != null) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   220
            Class<?> expectedClass = expected.getClass();
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   221
            Class<?> actualClass = actual.getClass();
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   222
            if (expectedClass.isArray()) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   223
                Assert.assertEquals(message, expectedClass, actualClass);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   224
                if (expected instanceof double[] || expected instanceof Object[]) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   225
                    doubleUlpsDeltaCriteria.arrayEquals(message, expected, actual);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   226
                    return;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   227
                } else if (expected instanceof float[] || expected instanceof Object[]) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   228
                    floatUlpsDeltaCriteria.arrayEquals(message, expected, actual);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   229
                    return;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   230
                }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   231
            } else if (expectedClass.equals(double.class) && actualClass.equals(double.class)) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   232
                doubleUlpsDeltaCriteria.arrayEquals(message, expected, actual);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   233
                return;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   234
            } else if (expectedClass.equals(float.class) && actualClass.equals(float.class)) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   235
                floatUlpsDeltaCriteria.arrayEquals(message, expected, actual);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   236
                return;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   237
            }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   238
        }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   239
        // anything else just use the non-ulps version
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   240
        assertDeepEquals(message, expected, actual, equalFloatsOrDoublesDelta());
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   241
    }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   242
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 52427
diff changeset
   243
    /** @see <a href="https://bugs.openjdk.java.net/browse/JDK-8076557">JDK-8076557</a> */
7dd81e82d083 8210777: Update Graal
dlong
parents: 52427
diff changeset
   244
    protected static void assumeManagementLibraryIsLoadable() {
7dd81e82d083 8210777: Update Graal
dlong
parents: 52427
diff changeset
   245
        try {
7dd81e82d083 8210777: Update Graal
dlong
parents: 52427
diff changeset
   246
            /* Trigger loading of the management library using the bootstrap class loader. */
7dd81e82d083 8210777: Update Graal
dlong
parents: 52427
diff changeset
   247
            GraalServices.getCurrentThreadAllocatedBytes();
7dd81e82d083 8210777: Update Graal
dlong
parents: 52427
diff changeset
   248
        } catch (UnsatisfiedLinkError | NoClassDefFoundError | UnsupportedOperationException e) {
7dd81e82d083 8210777: Update Graal
dlong
parents: 52427
diff changeset
   249
            throw new AssumptionViolatedException("Management interface is unavailable: " + e);
7dd81e82d083 8210777: Update Graal
dlong
parents: 52427
diff changeset
   250
        }
7dd81e82d083 8210777: Update Graal
dlong
parents: 52427
diff changeset
   251
    }
7dd81e82d083 8210777: Update Graal
dlong
parents: 52427
diff changeset
   252
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   253
    /**
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   254
     * Gets the value used by {@link #assertDeepEquals(Object, Object)} and
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   255
     * {@link #assertDeepEquals(String, Object, Object)} for the maximum delta between two doubles
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   256
     * or floats for which both numbers are still considered equal.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   257
     */
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   258
    protected double equalFloatsOrDoublesDelta() {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   259
        return 0.0D;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   260
    }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   261
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   262
    // unless overridden ulpsDelta is not used
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   263
    protected int ulpsDelta() {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   264
        return 0;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   265
    }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   266
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   267
    @SuppressWarnings("serial")
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   268
    public static class MultiCauseAssertionError extends AssertionError {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   269
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   270
        private Throwable[] causes;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   271
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   272
        public MultiCauseAssertionError(String message, Throwable... causes) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   273
            super(message);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   274
            this.causes = causes;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   275
        }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   276
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   277
        @Override
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   278
        public void printStackTrace(PrintStream out) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   279
            super.printStackTrace(out);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   280
            int num = 0;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   281
            for (Throwable cause : causes) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   282
                if (cause != null) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   283
                    out.print("cause " + (num++));
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   284
                    cause.printStackTrace(out);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   285
                }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   286
            }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   287
        }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   288
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   289
        @Override
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   290
        public void printStackTrace(PrintWriter out) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   291
            super.printStackTrace(out);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   292
            int num = 0;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   293
            for (Throwable cause : causes) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   294
                if (cause != null) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   295
                    out.print("cause " + (num++) + ": ");
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   296
                    cause.printStackTrace(out);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   297
                }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   298
            }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   299
        }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   300
    }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   301
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   302
    /*
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   303
     * Overrides to the normal JUnit {@link Assert} routines that provide varargs style formatting
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   304
     * and produce an exception stack trace with the assertion frames trimmed out.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   305
     */
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   306
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   307
    /**
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   308
     * Fails a test with the given message.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   309
     *
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   310
     * @param message the identifying message for the {@link AssertionError} (<code>null</code>
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   311
     *            okay)
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   312
     * @see AssertionError
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   313
     */
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   314
    public static void fail(String message, Object... objects) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   315
        AssertionError e;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   316
        if (message == null) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   317
            e = new AssertionError();
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   318
        } else {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   319
            e = new AssertionError(String.format(message, objects));
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   320
        }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   321
        // Trim the assert frames from the stack trace
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   322
        StackTraceElement[] trace = e.getStackTrace();
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   323
        int start = 1; // Skip this frame
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   324
        String thisClassName = GraalTest.class.getName();
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   325
        while (start < trace.length && trace[start].getClassName().equals(thisClassName) && (trace[start].getMethodName().equals("assertTrue") || trace[start].getMethodName().equals("assertFalse"))) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   326
            start++;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   327
        }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   328
        e.setStackTrace(Arrays.copyOfRange(trace, start, trace.length));
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   329
        throw e;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   330
    }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   331
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   332
    /**
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   333
     * Asserts that a condition is true. If it isn't it throws an {@link AssertionError} with the
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   334
     * given message.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   335
     *
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   336
     * @param message the identifying message for the {@link AssertionError} (<code>null</code>
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   337
     *            okay)
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   338
     * @param condition condition to be checked
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   339
     */
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   340
    public static void assertTrue(String message, boolean condition) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   341
        assertTrue(condition, message);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   342
    }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   343
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   344
    /**
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   345
     * Asserts that a condition is true. If it isn't it throws an {@link AssertionError} without a
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   346
     * message.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   347
     *
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   348
     * @param condition condition to be checked
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   349
     */
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   350
    public static void assertTrue(boolean condition) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   351
        assertTrue(condition, null);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   352
    }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   353
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   354
    /**
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   355
     * Asserts that a condition is false. If it isn't it throws an {@link AssertionError} with the
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   356
     * given message.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   357
     *
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   358
     * @param message the identifying message for the {@link AssertionError} (<code>null</code>
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   359
     *            okay)
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   360
     * @param condition condition to be checked
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   361
     */
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   362
    public static void assertFalse(String message, boolean condition) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   363
        assertTrue(!condition, message);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   364
    }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   365
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   366
    /**
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   367
     * Asserts that a condition is false. If it isn't it throws an {@link AssertionError} without a
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   368
     * message.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   369
     *
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   370
     * @param condition condition to be checked
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   371
     */
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   372
    public static void assertFalse(boolean condition) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   373
        assertTrue(!condition, null);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   374
    }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   375
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   376
    /**
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   377
     * Asserts that a condition is true. If it isn't it throws an {@link AssertionError} with the
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   378
     * given message.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   379
     *
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   380
     * @param condition condition to be checked
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   381
     * @param message the identifying message for the {@link AssertionError}
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   382
     * @param objects arguments to the format string
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   383
     */
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   384
    public static void assertTrue(boolean condition, String message, Object... objects) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   385
        if (!condition) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   386
            fail(message, objects);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   387
        }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   388
    }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   389
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   390
    /**
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   391
     * Asserts that a condition is false. If it isn't it throws an {@link AssertionError} with the
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   392
     * given message produced by {@link String#format}.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   393
     *
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   394
     * @param condition condition to be checked
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   395
     * @param message the identifying message for the {@link AssertionError}
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   396
     * @param objects arguments to the format string
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   397
     */
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   398
    public static void assertFalse(boolean condition, String message, Object... objects) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   399
        assertTrue(!condition, message, objects);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   400
    }
46640
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   401
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   402
    /**
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   403
     * Gets the {@link DebugHandlersFactory}s available for a {@link DebugContext}.
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   404
     */
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   405
    protected Collection<DebugHandlersFactory> getDebugHandlersFactories() {
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   406
        return Collections.emptyList();
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   407
    }
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   408
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   409
    /**
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   410
     * Gets a {@link DebugContext} object corresponding to {@code options}, creating a new one if
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   411
     * none currently exists. Debug contexts created by this method will have their
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   412
     * {@link DebugDumpHandler}s closed in {@link #afterTest()}.
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   413
     */
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   414
    protected DebugContext getDebugContext(OptionValues options) {
47798
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   415
        return getDebugContext(options, null, null);
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   416
    }
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   417
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   418
    /**
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   419
     * Gets a {@link DebugContext} object corresponding to {@code options}, creating a new one if
48861
47f19ff9903c 8194819: Update Graal
iveresov
parents: 47798
diff changeset
   420
     * none currently exists. Debug contexts created by this method will have their
47798
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   421
     * {@link DebugDumpHandler}s closed in {@link #afterTest()}.
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   422
     *
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   423
     * @param options currently active options
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   424
     * @param id identification of the compilation or {@code null}
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   425
     * @param method method to use for a proper description of the context or {@code null}
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   426
     * @return configured context for compilation
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   427
     */
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   428
    protected DebugContext getDebugContext(OptionValues options, String id, ResolvedJavaMethod method) {
46640
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   429
        List<DebugContext> cached = cachedDebugs.get();
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   430
        if (cached == null) {
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   431
            cached = new ArrayList<>();
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   432
            cachedDebugs.set(cached);
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   433
        }
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   434
        for (DebugContext debug : cached) {
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   435
            if (debug.getOptions() == options) {
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   436
                return debug;
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   437
            }
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   438
        }
47798
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   439
        final DebugContext.Description descr;
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   440
        if (method == null) {
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   441
            descr = NO_DESCRIPTION;
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   442
        } else {
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   443
            descr = new DebugContext.Description(method, id == null ? method.getName() : id);
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   444
        }
48861
47f19ff9903c 8194819: Update Graal
iveresov
parents: 47798
diff changeset
   445
        DebugContext debug = DebugContext.create(options, descr, globalMetrics, DEFAULT_LOG_STREAM, getDebugHandlersFactories());
46640
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   446
        cached.add(debug);
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   447
        return debug;
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   448
    }
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   449
48861
47f19ff9903c 8194819: Update Graal
iveresov
parents: 47798
diff changeset
   450
    private static final GlobalMetrics globalMetrics = new GlobalMetrics();
47f19ff9903c 8194819: Update Graal
iveresov
parents: 47798
diff changeset
   451
47f19ff9903c 8194819: Update Graal
iveresov
parents: 47798
diff changeset
   452
    static {
47f19ff9903c 8194819: Update Graal
iveresov
parents: 47798
diff changeset
   453
        Runtime.getRuntime().addShutdownHook(new Thread("GlobalMetricsPrinter") {
47f19ff9903c 8194819: Update Graal
iveresov
parents: 47798
diff changeset
   454
            @Override
47f19ff9903c 8194819: Update Graal
iveresov
parents: 47798
diff changeset
   455
            public void run() {
47f19ff9903c 8194819: Update Graal
iveresov
parents: 47798
diff changeset
   456
                globalMetrics.print(new OptionValues(OptionValues.newOptionMap()));
47f19ff9903c 8194819: Update Graal
iveresov
parents: 47798
diff changeset
   457
            }
47f19ff9903c 8194819: Update Graal
iveresov
parents: 47798
diff changeset
   458
        });
47f19ff9903c 8194819: Update Graal
iveresov
parents: 47798
diff changeset
   459
    }
46640
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   460
    private final ThreadLocal<List<DebugContext>> cachedDebugs = new ThreadLocal<>();
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   461
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   462
    @After
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   463
    public void afterTest() {
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   464
        List<DebugContext> cached = cachedDebugs.get();
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   465
        if (cached != null) {
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   466
            for (DebugContext debug : cached) {
48861
47f19ff9903c 8194819: Update Graal
iveresov
parents: 47798
diff changeset
   467
                debug.close();
46640
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   468
                debug.closeDumpHandlers(true);
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   469
            }
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   470
        }
70bdce04c59b 8183991: Update Graal
iveresov
parents: 46459
diff changeset
   471
    }
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   472
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   473
    private static final double TIMEOUT_SCALING_FACTOR = Double.parseDouble(System.getProperty("graaltest.timeout.factor", "1.0"));
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   474
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   475
    /**
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   476
     * Creates a {@link TestRule} that applies a given timeout.
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   477
     *
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   478
     * A test harness can scale {@code length} with a factor specified by the
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   479
     * {@code graaltest.timeout.factor} system property.
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   480
     */
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   481
    public static TestRule createTimeout(long length, TimeUnit timeUnit) {
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   482
        Timeout timeout = new Timeout((long) (length * TIMEOUT_SCALING_FACTOR), timeUnit);
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   483
        try {
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   484
            return new DisableOnDebug(timeout);
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   485
        } catch (LinkageError ex) {
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   486
            return timeout;
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   487
        }
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   488
    }
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   489
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   490
    /**
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   491
     * @see #createTimeout
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   492
     */
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   493
    public static TestRule createTimeoutSeconds(int seconds) {
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   494
        return createTimeout(seconds, TimeUnit.SECONDS);
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   495
    }
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   496
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   497
    /**
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   498
     * @see #createTimeout
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   499
     */
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   500
    public static TestRule createTimeoutMillis(long milliseconds) {
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   501
        return createTimeout(milliseconds, TimeUnit.MILLISECONDS);
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   502
    }
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   503
}