test/hotspot/jtreg/compiler/aot/fingerprint/SelfChanged.java
author rraghavan
Thu, 08 Aug 2019 14:13:16 +0530
changeset 57681 41f2f2829a09
parent 49367 6a532ba7d9e9
permissions -rw-r--r--
8227439: Turn off AOT by default Summary: Made UseAOT, AOTLibrary experimental and UseAOT false by default Reviewed-by: iignatyev, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49367
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
     1
/*
57681
41f2f2829a09 8227439: Turn off AOT by default
rraghavan
parents: 49367
diff changeset
     2
 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
49367
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
     4
 *
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
     8
 *
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    13
 * accompanied this code).
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    14
 *
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    18
 *
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    21
 * questions.
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    22
 */
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    23
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    24
/*
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    25
 * @test
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    26
 * @summary AOT methods should be swept if a super class has changed.
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    27
 * @library /test/lib /
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    28
 * @modules java.base/jdk.internal.misc
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    29
 *          java.management
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    30
 * @requires vm.aot
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    31
 * @build compiler.aot.fingerprint.SelfChanged
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    32
 *        compiler.aot.AotCompiler
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    33
 *
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    34
 * @run main
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    35
 *      compiler.aot.fingerprint.SelfChanged WRITE-UNMODIFIED-CLASS
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    36
 * @run driver compiler.aot.AotCompiler -libname libSelfChanged.so
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    37
 *      -class compiler.aot.fingerprint.Blah
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    38
 *
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    39
 * @run main/othervm
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    40
 *      compiler.aot.fingerprint.SelfChanged TEST-UNMODIFIED
57681
41f2f2829a09 8227439: Turn off AOT by default
rraghavan
parents: 49367
diff changeset
    41
 * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseAOT -XX:+PrintAOT
41f2f2829a09 8227439: Turn off AOT by default
rraghavan
parents: 49367
diff changeset
    42
 *      -XX:AOTLibrary=./libSelfChanged.so
49367
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    43
 *      -Xlog:aot+class+fingerprint=trace -Xlog:aot+class+load=trace
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    44
 *      compiler.aot.fingerprint.SelfChanged TEST-UNMODIFIED
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    45
 *
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    46
 * @run main
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    47
 *      compiler.aot.fingerprint.SelfChanged WRITE-MODIFIED-CLASS
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    48
 * @run main
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    49
 *      compiler.aot.fingerprint.SelfChanged TEST-MODIFIED
57681
41f2f2829a09 8227439: Turn off AOT by default
rraghavan
parents: 49367
diff changeset
    50
 * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseAOT -XX:+PrintAOT
41f2f2829a09 8227439: Turn off AOT by default
rraghavan
parents: 49367
diff changeset
    51
 *      -XX:AOTLibrary=./libSelfChanged.so
49367
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    52
 *      -Xlog:aot+class+fingerprint=trace -Xlog:aot+class+load=trace
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    53
 *      compiler.aot.fingerprint.SelfChanged TEST-MODIFIED
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    54
 */
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    55
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    56
package compiler.aot.fingerprint;
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    57
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    58
import jdk.test.lib.Asserts;
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    59
import jdk.test.lib.compiler.InMemoryJavaCompiler;
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    60
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    61
import java.io.*;
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    62
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    63
class Blah {
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    64
    volatile int z;
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    65
    int getX() {
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    66
        for (z = 0; z < 10000; z++) {
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    67
            if (z % 7 == 1) {
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    68
                z += 2;
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    69
            }
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    70
        }
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    71
        return 0;
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    72
    }
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    73
}
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    74
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    75
public class SelfChanged {
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    76
    public static void main(String args[]) throws Throwable {
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    77
        Blah f = new Blah();
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    78
        System.out.println("f.getX = " + f.getX());
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    79
        switch (args[0]) {
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    80
        case "WRITE-UNMODIFIED-CLASS":
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    81
            compileClass(false);
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    82
            break;
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    83
        case "WRITE-MODIFIED-CLASS":
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    84
            compileClass(true);
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    85
            break;
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    86
        case "TEST-UNMODIFIED":
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    87
            Asserts.assertTrue(f.getX() == 0, "getX from unmodified Blah class should return 0");
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    88
            break;
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    89
        case "TEST-MODIFIED":
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    90
            Asserts.assertTrue(f.getX() == 1, "getX from modified Blah class should return 1");
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    91
            break;
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    92
        default:
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    93
            throw new RuntimeException("unexpected option: " + args[0]);
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    94
        }
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    95
    }
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    96
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    97
    static void compileClass(boolean isModified) throws Throwable {
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    98
        String src =
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
    99
               "package compiler.aot.fingerprint;"
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   100
             + "public class Blah {"
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   101
             + "    volatile int z;"
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   102
             + "    int getX() {"
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   103
             + "        for (z = 0; z < 10000; z++) {"
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   104
             + "            if (z % 7 == 1) {"
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   105
             + "                z += 2;"
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   106
             + "            }"
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   107
             + "        }"
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   108
             + "        return " + ((isModified) ? "1" : "0") + ";"
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   109
             + "    }"
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   110
             + "    int getY() {return 255;}"
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   111
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   112
            // The following is for the SelfChangedCDS.java test case. We always load an unmodified
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   113
            // version of Blah from the CDS archive. However, we would load an AOT library that
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   114
            // was compiled using a modified version of Blah. The getX method in this AOT library should
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   115
            // not be used.
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   116
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   117
            + "    public static void main(String args[]) {"
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   118
             + "        Blah b = new Blah();"
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   119
             + "        int n = b.getX();"
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   120
             + "        if (n != 0) {"
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   121
             + "            throw new RuntimeException(args[0] +  \" : \" + n);"
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   122
             + "        }"
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   123
             + "        System.out.println(\"PASSED\");"
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   124
             + "    }"
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   125
             + "}";
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   126
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   127
        String filename = System.getProperty("test.classes") + "/compiler/aot/fingerprint/Blah.class";
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   128
        FileOutputStream fos = new FileOutputStream(filename);
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   129
        fos.write(InMemoryJavaCompiler.compile("compiler.aot.fingerprint.Blah", src));
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   130
        fos.close();
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   131
    }
6a532ba7d9e9 8198591: compiler/aot/fingerprint tests should be moved to open
kvn
parents:
diff changeset
   132
}