src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/BoxDeoptimizationTest.java
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
       
     1 /*
       
     2  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    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 
       
    24 
       
    25 package org.graalvm.compiler.hotspot.test;
       
    26 
       
    27 import static org.graalvm.compiler.serviceprovider.JavaVersionUtil.JAVA_SPEC;
       
    28 
       
    29 import org.graalvm.compiler.api.directives.GraalDirectives;
       
    30 import org.graalvm.compiler.core.test.GraalCompilerTest;
       
    31 import org.junit.Assert;
       
    32 import org.junit.Assume;
       
    33 import org.junit.Test;
       
    34 
       
    35 public class BoxDeoptimizationTest extends GraalCompilerTest {
       
    36 
       
    37     private static void checkJDK() {
       
    38         Assume.assumeTrue(JAVA_SPEC == 8 || JAVA_SPEC >= 13);
       
    39     }
       
    40 
       
    41     public static void testIntegerSnippet() {
       
    42         Object[] values = {42, -42, new Exception()};
       
    43         GraalDirectives.deoptimize();
       
    44         Assert.assertSame(values[0], Integer.valueOf(42));
       
    45         Assert.assertSame(values[1], Integer.valueOf(-42));
       
    46     }
       
    47 
       
    48     @Test
       
    49     public void testInteger() {
       
    50         checkJDK();
       
    51         test("testIntegerSnippet");
       
    52     }
       
    53 
       
    54     public static void testLongSnippet() {
       
    55         long highBitsOnly = 2L << 40;
       
    56         Object[] values = {42L, -42L, highBitsOnly, new Exception()};
       
    57         GraalDirectives.deoptimize();
       
    58         Assert.assertSame(values[0], Long.valueOf(42));
       
    59         Assert.assertSame(values[1], Long.valueOf(-42));
       
    60         Assert.assertNotSame(values[2], highBitsOnly);
       
    61     }
       
    62 
       
    63     @Test
       
    64     public void testLong() {
       
    65         checkJDK();
       
    66         test("testLongSnippet");
       
    67     }
       
    68 
       
    69     public static void testCharSnippet() {
       
    70         Object[] values = {'a', 'Z', new Exception()};
       
    71         GraalDirectives.deoptimize();
       
    72         Assert.assertSame(values[0], Character.valueOf('a'));
       
    73         Assert.assertSame(values[1], Character.valueOf('Z'));
       
    74     }
       
    75 
       
    76     @Test
       
    77     public void testChar() {
       
    78         checkJDK();
       
    79         test("testCharSnippet");
       
    80     }
       
    81 
       
    82     public static void testShortSnippet() {
       
    83         Object[] values = {(short) 42, (short) -42, new Exception()};
       
    84         GraalDirectives.deoptimize();
       
    85         Assert.assertSame(values[0], Short.valueOf((short) 42));
       
    86         Assert.assertSame(values[1], Short.valueOf((short) -42));
       
    87     }
       
    88 
       
    89     @Test
       
    90     public void testShort() {
       
    91         checkJDK();
       
    92         test("testShortSnippet");
       
    93     }
       
    94 
       
    95     public static void testByteSnippet() {
       
    96         Object[] values = {(byte) 42, (byte) -42, new Exception()};
       
    97         GraalDirectives.deoptimize();
       
    98         Assert.assertSame(values[0], Byte.valueOf((byte) 42));
       
    99         Assert.assertSame(values[1], Byte.valueOf((byte) -42));
       
   100     }
       
   101 
       
   102     @Test
       
   103     public void testByte() {
       
   104         checkJDK();
       
   105         test("testByteSnippet");
       
   106     }
       
   107 
       
   108     public static void testBooleanSnippet() {
       
   109         Object[] values = {true, false, new Exception()};
       
   110         GraalDirectives.deoptimize();
       
   111         Assert.assertSame(values[0], Boolean.valueOf(true));
       
   112         Assert.assertSame(values[1], Boolean.valueOf(false));
       
   113     }
       
   114 
       
   115     @Test
       
   116     public void testBoolean() {
       
   117         checkJDK();
       
   118         test("testBooleanSnippet");
       
   119     }
       
   120 }