6162
|
1 /*
|
|
2 * Copyright (c) 2012, 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 * @bug 7158800
|
|
27 * @run shell/timeout=400 Test7158800.sh
|
|
28 * @summary This test performs poorly if alternate hashing isn't used for
|
|
29 * string table.
|
|
30 * The timeout is handled by the shell file (which kills the process)
|
|
31 */
|
|
32 import java.util.*;
|
|
33 import java.io.*;
|
|
34
|
|
35 public class InternTest {
|
|
36 public static void main (String args[]) throws Exception {
|
|
37 final String badStringsFilename = "badstrings.txt";
|
|
38
|
|
39 if (args.length == 0 || (!args[0].equals("bad") && !args[0].equals("normal"))) {
|
|
40 System.out.println("Usage: java InternTest [normal|bad]");
|
|
41 System.exit(1);
|
|
42 }
|
|
43
|
|
44 FileInputStream fstream = new FileInputStream(badStringsFilename);
|
|
45 DataInputStream in = new DataInputStream(fstream);
|
|
46 BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
|
47 String toIntern, toDiscard;
|
|
48 int count = 0;
|
|
49 long current = 0L;
|
|
50 long last = System.currentTimeMillis();
|
|
51
|
|
52 if (args[0].equals("bad")) {
|
|
53 while ((toIntern = br.readLine()) != null) {
|
|
54 toDiscard = new String((new Integer((int)(Math.random() * Integer.MAX_VALUE))).toString());
|
|
55 toIntern.intern();
|
|
56 count++;
|
|
57 if (count % 10000 == 0 && count != 0) {
|
|
58 current = System.currentTimeMillis();
|
|
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)");
|
|
60 last = current;
|
|
61 }
|
|
62 }
|
|
63 }
|
|
64 if (args[0].equals("normal")) {
|
|
65 while ((toDiscard = br.readLine()) != null) { // do the same read from the file to try and make the test fair
|
|
66 toIntern = new String((new Integer((int)(Math.random() * Integer.MAX_VALUE))).toString());
|
|
67 toIntern.intern();
|
|
68 count++;
|
|
69 if (count % 10000 == 0 && count != 0) {
|
|
70 current = System.currentTimeMillis();
|
|
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)");
|
|
72 last = current;
|
|
73 }
|
|
74 }
|
|
75 }
|
|
76 in.close();
|
|
77 }
|
|
78 }
|
|
79
|
|
80
|