hotspot/test/runtime/SharedArchiveFile/SharedStringsWb.java
author goetz
Thu, 03 Aug 2017 10:24:34 +0200
changeset 46779 d80ca591ae48
parent 46746 ea379ebb9447
permissions -rw-r--r--
8185436: jtreg: introduce @requires property to disable cds tests Summary: Fix CompressedClassPointers test to succeed also if cds is not available. Reviewed-by: jiangli, mseledtsov, iklam
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32179
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
     1
/*
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
     2
 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
     4
 *
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
     8
 *
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    13
 * accompanied this code).
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    14
 *
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    18
 *
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    21
 * questions.
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    22
 */
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    23
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    24
import sun.hotspot.WhiteBox;
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    25
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    26
// This class is used by the test SharedStrings.java
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    27
// It should be launched in CDS mode
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    28
public class SharedStringsWb {
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    29
    public static void main(String[] args) throws Exception {
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    30
        WhiteBox wb = WhiteBox.getWhiteBox();
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    31
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    32
        if (wb.areSharedStringsIgnored()) {
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    33
            System.out.println("Shared strings are ignored, assuming PASS");
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    34
            return;
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    35
        }
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    36
32615
b6c0aafd6945 8133180: [TESTBUG] runtime/SharedArchiveFile/SharedStrings.java failed with WhiteBox.class : no such file or directory
mseledtsov
parents: 32179
diff changeset
    37
        // The string below is known to be added to CDS archive
b6c0aafd6945 8133180: [TESTBUG] runtime/SharedArchiveFile/SharedStrings.java failed with WhiteBox.class : no such file or directory
mseledtsov
parents: 32179
diff changeset
    38
        String s = "<init>";
32179
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    39
        String internedS = s.intern();
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    40
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 32615
diff changeset
    41
        // Check that it's a valid string
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 32615
diff changeset
    42
        if (s.getClass() != String.class || !(s instanceof String)) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 32615
diff changeset
    43
            throw new RuntimeException("Shared string is not a valid String: FAIL");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 32615
diff changeset
    44
        }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 32615
diff changeset
    45
32179
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    46
        if (wb.isShared(internedS)) {
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    47
            System.out.println("Found shared string, result: PASS");
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    48
        } else {
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    49
            throw new RuntimeException("String is not shared, result: FAIL");
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    50
        }
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    51
    }
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    52
}
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    53
246b2ef581b2 8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff changeset
    54