test/hotspot/jtreg/runtime/LoadClass/TestResize.java
author gziemski
Tue, 21 Nov 2017 10:21:24 -0600
changeset 48013 2098785677fb
parent 47774 69c081ca110a
child 48018 8bab1e50a28a
permissions -rw-r--r--
8191580: open/test/hotspot/jtreg/runtime/LoadClass/TestResize fails on product build Summary: Guarded the test with the tag requiring debug build Reviewed-by: jiangli
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47774
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
     1
/*
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
     4
 *
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
     7
 * published by the Free Software Foundation.
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
     8
 *
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    13
 * accompanied this code).
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    14
 *
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    18
 *
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    21
 * questions.
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    22
 */
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    23
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    24
/*
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    25
 * @test
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    26
 * @bug 8184765
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    27
 * @summary make sure the SystemDictionary gets resized when load factor is too high
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    28
 * @library /test/lib
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    29
 * @modules java.base/jdk.internal.misc
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    30
 *          java.management
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    31
 * @compile TriggerResize.java
48013
2098785677fb 8191580: open/test/hotspot/jtreg/runtime/LoadClass/TestResize fails on product build
gziemski
parents: 47774
diff changeset
    32
 * @requires (vm.debug == true)
47774
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    33
 * @run driver TestResize
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    34
 */
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    35
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    36
import java.lang.ProcessBuilder;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    37
import java.lang.Process;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    38
import jdk.test.lib.process.ProcessTools;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    39
import java.io.BufferedReader;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    40
import java.io.InputStreamReader;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    41
import java.util.Scanner;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    42
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    43
public class TestResize {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    44
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    45
  static double MAX_LOAD_FACTOR = 5.0; // see _resize_load_trigger in dictionary.cpp
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    46
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    47
  static int getInt(String string) {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    48
    int start = 0;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    49
    for (int i = 0; i < string.length(); i++) {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    50
      if (!Character.isDigit(string.charAt(i))) {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    51
        start++;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    52
      } else {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    53
        break;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    54
      }
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    55
    }
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    56
    int end = start;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    57
    for (int i = end; i < string.length(); i++) {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    58
      if (Character.isDigit(string.charAt(i))) {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    59
        end++;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    60
      } else {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    61
        break;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    62
      }
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    63
    }
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    64
    return Integer.parseInt(string.substring(start, end));
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    65
  }
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    66
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    67
  static void analyzeOutputOn(ProcessBuilder pb) throws Exception {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    68
    pb.redirectErrorStream(true);
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    69
    Process process = pb.start();
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    70
    BufferedReader rd = new BufferedReader(new InputStreamReader(process.getInputStream()));
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    71
    String line = rd.readLine();
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    72
    while (line != null) {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    73
      if (line.startsWith("Java dictionary (")) {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    74
        // ex. "Java dictionary (table_size=107, classes=6)"
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    75
        // ex. "Java dictionary (table_size=20201, classes=50002)"
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    76
        Scanner scanner = new Scanner(line);
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    77
        scanner.next();
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    78
        scanner.next();
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    79
        int table_size = getInt(scanner.next());
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    80
        int classes = getInt(scanner.next());
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    81
        scanner.close();
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    82
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    83
        double loadFactor = (double)classes / (double)table_size;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    84
        if (loadFactor > MAX_LOAD_FACTOR) {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    85
          throw new RuntimeException("Load factor too high, expected MAX "+MAX_LOAD_FACTOR+", got "+loadFactor);
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    86
        } else {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    87
          System.out.println("PASS table_size:"+table_size+", classes:"+classes+" OK");
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    88
        }
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    89
      }
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    90
      line = rd.readLine();
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    91
    }
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    92
    int retval = process.waitFor();
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    93
    if (retval != 0) {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    94
      throw new RuntimeException("Error: test returned non-zero value");
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    95
    }
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    96
  }
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    97
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    98
  public static void main(String[] args) throws Exception {
48013
2098785677fb 8191580: open/test/hotspot/jtreg/runtime/LoadClass/TestResize fails on product build
gziemski
parents: 47774
diff changeset
    99
    if (Platform.isDebugBuild()) {
2098785677fb 8191580: open/test/hotspot/jtreg/runtime/LoadClass/TestResize fails on product build
gziemski
parents: 47774
diff changeset
   100
      ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+PrintSystemDictionaryAtExit",
2098785677fb 8191580: open/test/hotspot/jtreg/runtime/LoadClass/TestResize fails on product build
gziemski
parents: 47774
diff changeset
   101
                                                                "TriggerResize",
2098785677fb 8191580: open/test/hotspot/jtreg/runtime/LoadClass/TestResize fails on product build
gziemski
parents: 47774
diff changeset
   102
                                                                "50000");
2098785677fb 8191580: open/test/hotspot/jtreg/runtime/LoadClass/TestResize fails on product build
gziemski
parents: 47774
diff changeset
   103
      analyzeOutputOn(pb);
2098785677fb 8191580: open/test/hotspot/jtreg/runtime/LoadClass/TestResize fails on product build
gziemski
parents: 47774
diff changeset
   104
    }
47774
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
   105
  }
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
   106
}