hotspot/test/compiler/aot/fingerprint/SuperChanged.java
changeset 43680 dd3ea9044937
parent 43379 f4aff695ffe0
parent 43490 3c43be5db478
child 43681 b810b7f4fdeb
equal deleted inserted replaced
43379:f4aff695ffe0 43680:dd3ea9044937
     1 /*
       
     2  * Copyright (c) 2016, 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  * @test
       
    26  * @summary AOT methods should be swept if a super class has changed.
       
    27  * @library /test/lib /
       
    28  * @modules java.base/jdk.internal.misc
       
    29  *          java.management
       
    30  * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
       
    31  * @build compiler.aot.fingerprint.SuperChanged
       
    32  *        compiler.aot.AotCompiler
       
    33  *
       
    34  * @run main
       
    35  *      compiler.aot.fingerprint.SuperChanged WRITE-UNMODIFIED-CLASS
       
    36  * @run main/othervm compiler.aot.AotCompiler -libname libSuperChanged.so
       
    37  *      -class compiler.aot.fingerprint.Foo
       
    38  *
       
    39  * @run main
       
    40  *      compiler.aot.fingerprint.SuperChanged TEST-UNMODIFIED
       
    41  * @run main/othervm -XX:+UseAOT -XX:+PrintAOT -XX:AOTLibrary=./libSuperChanged.so
       
    42  *      -Xlog:aot+class+fingerprint=trace -Xlog:aot+class+load=trace
       
    43  *      compiler.aot.fingerprint.SuperChanged TEST-UNMODIFIED
       
    44   *
       
    45  * @run main
       
    46  *      compiler.aot.fingerprint.SuperChanged WRITE-MODIFIED-CLASS
       
    47  * @run main
       
    48  *      compiler.aot.fingerprint.SuperChanged TEST-MODIFIED
       
    49  * @run main/othervm -XX:+UseAOT -XX:+PrintAOT -XX:AOTLibrary=./libSuperChanged.so
       
    50  *      -Xlog:aot+class+fingerprint=trace -Xlog:aot+class+load=trace
       
    51  *      compiler.aot.fingerprint.SuperChanged TEST-MODIFIED
       
    52  */
       
    53 
       
    54 package compiler.aot.fingerprint;
       
    55 
       
    56 import jdk.test.lib.Asserts;
       
    57 import jdk.test.lib.InMemoryJavaCompiler;
       
    58 
       
    59 import java.io.*;
       
    60 
       
    61 class Bar {
       
    62     volatile int x = 0;
       
    63     volatile int y = 1;
       
    64 }
       
    65 
       
    66 class Foo extends Bar {
       
    67 
       
    68     volatile int z;
       
    69     int getX() {
       
    70         for (z = 0; z < 10000; z++) {
       
    71             if (z % 7 == 1) {
       
    72                 z += 2;
       
    73             }
       
    74         }
       
    75         return x;
       
    76     }
       
    77 }
       
    78 
       
    79 public class SuperChanged {
       
    80     public static void main(String args[]) throws Throwable {
       
    81         Foo f = new Foo();
       
    82         System.out.println("f.getX = " + f.getX());
       
    83         switch (args[0]) {
       
    84         case "WRITE-UNMODIFIED-CLASS":
       
    85             compileClass(false);
       
    86             break;
       
    87         case "WRITE-MODIFIED-CLASS":
       
    88             compileClass(true);
       
    89             break;
       
    90         case "TEST-UNMODIFIED":
       
    91             Asserts.assertTrue(f.getX() == 0, "getX from unmodified Foo class should return 0");
       
    92             break;
       
    93         case "TEST-MODIFIED":
       
    94             Asserts.assertTrue(f.getX() == 1, "getX from modified Foo class should return 1");
       
    95             break;
       
    96         default:
       
    97             throw new RuntimeException("unexpected option: " + args[0]);
       
    98         }
       
    99     }
       
   100 
       
   101     static void compileClass(boolean isModified) throws Throwable {
       
   102         String class_src_0 = "package compiler.aot.fingerprint; class Bar {volatile int x = 0;  volatile int y = 1;}";
       
   103         String class_src_1 = "package compiler.aot.fingerprint; class Bar {volatile int y = 0;  volatile int x = 1;}";
       
   104         String src = (isModified) ? class_src_1 : class_src_0;
       
   105 
       
   106         String filename = System.getProperty("test.classes") + "/compiler/aot/fingerprint/Bar.class";
       
   107         FileOutputStream fos = new FileOutputStream(filename);
       
   108         fos.write(InMemoryJavaCompiler.compile("compiler.aot.fingerprint.Bar", src));
       
   109         fos.close();
       
   110     }
       
   111 }