hotspot/test/runtime/7158800/InternTest.java
author coleenp
Wed, 13 Jun 2012 19:52:59 -0400
changeset 13087 673ea6efaf18
permissions -rw-r--r--
7158800: Improve storage of symbol tables Summary: Use an alternate version of hashing algorithm for symbol string tables and after a certain bucket size to improve performance Reviewed-by: pbk, kamg, dlong, kvn, fparain
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
     1
/*
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
     4
 *
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
     8
 *
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    13
 * accompanied this code).
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    14
 *
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    18
 *
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    21
 * questions.
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    22
 */
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    23
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    24
/*
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    25
 * @test
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    26
 * @bug 7158800
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    27
 * @run shell/timeout=400 Test7158800.sh
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    28
 * @summary This test performs poorly if alternate hashing isn't used for
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    29
 * string table.
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    30
 * The timeout is handled by the shell file (which kills the process)
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    31
 */
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    32
import java.util.*;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    33
import java.io.*;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    34
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    35
public class InternTest {
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    36
    public static void main (String args[]) throws Exception {
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    37
        final String badStringsFilename = "badstrings.txt";
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    38
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    39
        if (args.length == 0 || (!args[0].equals("bad") && !args[0].equals("normal"))) {
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    40
            System.out.println("Usage:  java InternTest [normal|bad]");
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    41
            System.exit(1);
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    42
        }
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    43
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    44
        FileInputStream fstream = new FileInputStream(badStringsFilename);
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    45
        DataInputStream in = new DataInputStream(fstream);
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    46
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    47
        String toIntern, toDiscard;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    48
        int count = 0;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    49
        long current = 0L;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    50
        long last = System.currentTimeMillis();
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    51
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    52
        if (args[0].equals("bad")) {
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    53
            while ((toIntern = br.readLine()) != null) {
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    54
                toDiscard = new String((new Integer((int)(Math.random() * Integer.MAX_VALUE))).toString());
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    55
                toIntern.intern();
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    56
                count++;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    57
                if (count % 10000 == 0 && count != 0) {
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    58
                    current = System.currentTimeMillis();
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    59
                    System.out.println(new Date(current) + ": interned " + count + " 0-hash strings - last 10000 took " + ((float)(current - last))/1000 + "s (" + ((float)(current - last))/10000000 + "s per String)");
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    60
                    last = current;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    61
                }
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    62
            }
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    63
        }
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    64
        if (args[0].equals("normal")) {
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    65
            while ((toDiscard = br.readLine()) != null) { // do the same read from the file to try and make the test fair
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    66
                toIntern = new String((new Integer((int)(Math.random() * Integer.MAX_VALUE))).toString());
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    67
                toIntern.intern();
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    68
                count++;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    69
                if (count % 10000 == 0 && count != 0) {
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    70
                    current = System.currentTimeMillis();
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    71
                    System.out.println(new Date(current) + ": interned " + count + " normal strings - last 10000 took " + ((float)(current - last))/1000 + "s (" + ((float)(current - last))/10000000 + "s per String)");
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    72
                    last = current;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    73
                }
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    74
            }
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    75
        }
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    76
        in.close();
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    77
    }
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    78
}
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    79
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    80