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 package gc.logging;
25
26 import java.io.File;
27 import java.net.URL;
28 import java.net.URLClassLoader;
29 import java.util.function.Predicate;
30 import java.util.regex.Pattern;
31 import java.util.regex.Matcher;
32
33 import jdk.test.lib.Asserts;
34 import jdk.test.lib.process.OutputAnalyzer;
35 import jdk.test.lib.process.ProcessTools;
36 import sun.hotspot.WhiteBox;
37
38 /*
39 * @test TestMetaSpaceLog
40 * @bug 8211123
41 * @summary Ensure that the Metaspace is updated in the log
42 * @requires vm.gc=="null"
43 * @key gc
44 * @library /test/lib
45 * @modules java.base/jdk.internal.misc
46 * java.management
47 *
48 * @compile TestMetaSpaceLog.java
49 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
50 * @run main gc.logging.TestMetaSpaceLog
51 */
52
53 public class TestMetaSpaceLog {
54 private static Pattern metaSpaceRegexp;
55
56 static {
57 // Do this once here.
58 metaSpaceRegexp = Pattern.compile(".*Metaspace: ([0-9]+).*->([0-9]+).*");
59 }
60
61 public static void main(String[] args) throws Exception {
62 testMetaSpaceUpdate("UseParallelGC");
63 testMetaSpaceUpdate("UseG1GC");
64 testMetaSpaceUpdate("UseConcMarkSweepGC");
65 testMetaSpaceUpdate("UseSerialGC");
66 }
67
68 private static void verifyContainsMetaSpaceUpdate(OutputAnalyzer output) {
69 Predicate<String> collectedMetaSpace = line -> check(line);
70
71 // At least one metaspace line from GC should show GC being collected.
72 boolean foundCollectedMetaSpace = output.asLines().stream()
73 .filter(s -> s.contains("[gc,metaspace"))
74 .anyMatch(TestMetaSpaceLog::check);
75 Asserts.assertTrue(foundCollectedMetaSpace);
76 }
77
78 private static boolean check(String line) {
79 Matcher m = metaSpaceRegexp.matcher(line);
80 Asserts.assertTrue(m.matches(), "Unexpected line for metaspace logging: " + line);
81 long before = Long.parseLong(m.group(1));
82 long after = Long.parseLong(m.group(2));
83 return before > after;
84 }
85
86 private static void testMetaSpaceUpdate(String gcFlag) throws Exception {
87 // Propagate test.src for the jar file.
88 String testSrc= "-Dtest.src=" + System.getProperty("test.src", ".");
89
|
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 package gc.logging;
25
26 import java.io.File;
27 import java.net.URL;
28 import java.net.URLClassLoader;
29 import java.util.regex.Pattern;
30 import java.util.regex.Matcher;
31
32 import jdk.test.lib.Asserts;
33 import jdk.test.lib.process.OutputAnalyzer;
34 import jdk.test.lib.process.ProcessTools;
35 import sun.hotspot.WhiteBox;
36
37 /*
38 * @test TestMetaSpaceLog
39 * @bug 8211123
40 * @summary Ensure that the Metaspace is updated in the log
41 * @requires vm.gc=="null"
42 * @key gc
43 * @library /test/lib
44 * @modules java.base/jdk.internal.misc
45 * java.management
46 *
47 * @compile TestMetaSpaceLog.java
48 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
49 * @run main gc.logging.TestMetaSpaceLog
50 */
51
52 public class TestMetaSpaceLog {
53 private static Pattern metaSpaceRegexp;
54
55 static {
56 // Do this once here.
57 metaSpaceRegexp = Pattern.compile(".*Metaspace: ([0-9]+).*->([0-9]+).*");
58 }
59
60 public static void main(String[] args) throws Exception {
61 testMetaSpaceUpdate("UseParallelGC");
62 testMetaSpaceUpdate("UseG1GC");
63 testMetaSpaceUpdate("UseConcMarkSweepGC");
64 testMetaSpaceUpdate("UseSerialGC");
65 }
66
67 private static void verifyContainsMetaSpaceUpdate(OutputAnalyzer output) {
68 // At least one metaspace line from GC should show GC being collected.
69 boolean foundCollectedMetaSpace = output.asLines().stream()
70 .filter(s -> s.contains("[gc,metaspace"))
71 .anyMatch(TestMetaSpaceLog::check);
72 Asserts.assertTrue(foundCollectedMetaSpace);
73 }
74
75 private static boolean check(String line) {
76 Matcher m = metaSpaceRegexp.matcher(line);
77 Asserts.assertTrue(m.matches(), "Unexpected line for metaspace logging: " + line);
78 long before = Long.parseLong(m.group(1));
79 long after = Long.parseLong(m.group(2));
80 return before > after;
81 }
82
83 private static void testMetaSpaceUpdate(String gcFlag) throws Exception {
84 // Propagate test.src for the jar file.
85 String testSrc= "-Dtest.src=" + System.getProperty("test.src", ".");
86
|