langtools/test/tools/sjavac/IncCompileChangeNative.java
author vasya
Mon, 14 Dec 2015 20:18:19 +0100
changeset 34752 9c262a013456
parent 34473 5f7202c2125d
child 35356 e919fd8db52c
permissions -rw-r--r--
8145342: Some copyright notices are inconsistently and ill formatted Summary: Adjusted formatting of copyright notices. Reviewed-by: darcy, alundblad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 28276
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
     4
 *
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
     8
 *
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    13
 * accompanied this code).
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    14
 *
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    18
 *
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    21
 * questions.
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    22
 */
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    23
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    24
/*
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    25
 * @test
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    26
 * @summary Verify native files are removed when native method is removed
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    27
 * @bug 8054689
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    28
 * @author Fredrik O
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    29
 * @author sogoel (rewrite)
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    30
 * @library /tools/lib
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 28276
diff changeset
    31
 * @modules jdk.compiler/com.sun.tools.javac.api
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 28276
diff changeset
    32
 *          jdk.compiler/com.sun.tools.javac.file
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 28276
diff changeset
    33
 *          jdk.compiler/com.sun.tools.javac.main
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 28276
diff changeset
    34
 *          jdk.compiler/com.sun.tools.sjavac
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    35
 * @build Wrapper ToolBox
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    36
 * @run main Wrapper IncCompileChangeNative
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    37
 */
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    38
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    39
import java.util.*;
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    40
import java.nio.file.*;
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    41
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    42
public class IncCompileChangeNative extends SJavacTester {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    43
    public static void main(String... args) throws Exception {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    44
        IncCompileChangeNative cn = new IncCompileChangeNative();
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    45
        cn.test();
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    46
    }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    47
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    48
    // Remember the previous bin and headers state here.
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    49
    Map<String,Long> previous_bin_state;
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    50
    Map<String,Long> previous_headers_state;
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    51
    ToolBox tb = new ToolBox();
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    52
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    53
    void test() throws Exception {
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
    54
        Files.createDirectories(GENSRC);
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
    55
        Files.createDirectories(BIN);
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
    56
        Files.createDirectories(HEADERS);
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    57
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    58
        initialCompile();
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    59
        incrementalCompileDropAllNatives();
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    60
        incrementalCompileAddNative();
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    61
    }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    62
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    63
    // Update B.java with one less native method i.e. it has no longer any methods
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    64
    // Verify that beta_B.h is removed
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    65
    void incrementalCompileDropAllNatives() throws Exception {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    66
        previous_bin_state = collectState(BIN);
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    67
        previous_headers_state = collectState(HEADERS);
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    68
        System.out.println("\nIn incrementalCompileDropAllNatives() ");
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    69
        System.out.println("Verify that beta_B.h is removed");
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    70
        tb.writeFile(GENSRC.resolve("beta/B.java"),
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
    71
                     "package beta; import alfa.omega.A; " +
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
    72
                     "public class B { private int b() { return A.DEFINITION; } }");
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    73
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
    74
        compile(GENSRC.toString(),
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
    75
                "-d", BIN.toString(),
32799
ee577901f4bb 8135131: Enable thin server mode in Sjavac
alundblad
parents: 31115
diff changeset
    76
                "--state-dir=" + BIN,
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
    77
                "-h", HEADERS.toString(),
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
    78
                "-j", "1",
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
    79
                SERVER_ARG,
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
    80
                "--log=debug");
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    81
        Map<String,Long> new_bin_state = collectState(BIN);
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    82
        verifyNewerFiles(previous_bin_state, new_bin_state,
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
    83
                         BIN + "/beta/B.class",
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
    84
                         BIN + "/beta/BINT.class",
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
    85
                         BIN + "/javac_state");
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    86
        previous_bin_state = new_bin_state;
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    87
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    88
        Map<String,Long> new_headers_state = collectState(HEADERS);
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    89
        verifyThatFilesHaveBeenRemoved(previous_headers_state, new_headers_state,
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
    90
                                       HEADERS + "/beta_B.h");
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    91
        previous_headers_state = new_headers_state;
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    92
    }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    93
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    94
    // Update the B.java with a final static annotated with @Native
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    95
    // Verify that beta_B.h is added again
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    96
    void incrementalCompileAddNative() throws Exception {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    97
        System.out.println("\nIn incrementalCompileAddNative() ");
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    98
        System.out.println("Verify that beta_B.h is added again");
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    99
        tb.writeFile(GENSRC.resolve("beta/B.java"),
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
   100
                     "package beta; import alfa.omega.A; public class B {"+
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
   101
                     "private int b() { return A.DEFINITION; } "+
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
   102
                     "@java.lang.annotation.Native final static int alfa = 42; }");
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   103
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
   104
        compile(GENSRC.toString(),
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
   105
                "-d", BIN.toString(),
32799
ee577901f4bb 8135131: Enable thin server mode in Sjavac
alundblad
parents: 31115
diff changeset
   106
                "--state-dir=" + BIN,
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
   107
                "-h", HEADERS.toString(),
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
   108
                "-j", "1",
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
   109
                SERVER_ARG,
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
   110
                "--log=debug");
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   111
        Map<String,Long> new_bin_state = collectState(BIN);
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   112
        verifyNewerFiles(previous_bin_state, new_bin_state,
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
   113
                         BIN + "/beta/B.class",
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
   114
                         BIN + "/beta/BINT.class",
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
   115
                         BIN + "/javac_state");
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   116
        previous_bin_state = new_bin_state;
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   117
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   118
        Map<String,Long> new_headers_state = collectState(HEADERS);
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   119
        verifyThatFilesHaveBeenAdded(previous_headers_state, new_headers_state,
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
   120
                                     HEADERS + "/beta_B.h");
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   121
        previous_headers_state = new_headers_state;
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   122
    }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   123
}