/* * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package jdk.jfr.event.runtime; import java.io.IOException; import java.time.Duration; import java.util.List; import jdk.jfr.Recording; import jdk.jfr.consumer.RecordedClass; import jdk.jfr.consumer.RecordedClassLoader; import jdk.jfr.consumer.RecordedEvent; import jdk.test.lib.Asserts; import jdk.test.lib.jfr.EventNames; import jdk.test.lib.jfr.Events; import jdk.test.lib.jfr.TestClassLoader; /** * @test * @key jfr * @requires vm.hasJFR * @library /test/lib /test/jdk * @build jdk.jfr.event.runtime.TestClasses * @run main/othervm jdk.jfr.event.runtime.TestTableStatisticsEvent */ public final class TestTableStatisticsEvent { static private void exerciseStringTable() { final int SIZE = 10000; String strings[] = new String[SIZE]; for (int i=0; i0), "No buckets for " + name); Asserts.assertTrue((totalFootprint>0), "Zero sized table for " + name); Asserts.assertTrue((maximumBucketCount>=averageBucketCount), "Maximum bucket count not equal to or greater than the average for " + name); if ((addRate > 0.0) && (addRate > removeRate)) { Asserts.assertTrue((numberOfEntries>0), "Entries marked as added, but no entries found for " + name); } } static private void validateStringTableEvent(RecordedEvent event, String name) throws IOException { validateCommonTableEvent(event, name); Long numberOfEntries = event.getValue("numberOfEntries"); Asserts.assertTrue((numberOfEntries>0), "No entries for " + name); } static private void testStringTableStatisticsEvent(Recording recording, String name) throws IOException { boolean gotEvent = false; List events = Events.fromRecording(recording); for (RecordedEvent event : events) { if (event.toString().contains(name)) { gotEvent = true; validateStringTableEvent(event, name); } } Asserts.assertTrue(gotEvent, "No table statistics event found for " + name); } static private void testCommonTableStatisticsEvent(Recording recording, String name) throws IOException { boolean gotEvent = false; List events = Events.fromRecording(recording); for (RecordedEvent event : events) { if (event.toString().contains(name)) { gotEvent = true; validateCommonTableEvent(event, name); } } Asserts.assertTrue(gotEvent, "No table statistics event found for " + name); } public static void main(String[] args) throws Throwable { final long DURATION_MS = 2000; Recording recording = new Recording(); recording.enable(EventNames.SymbolTableStatistics).withThreshold(Duration.ofMillis(DURATION_MS)); recording.enable(EventNames.StringTableStatistics).withThreshold(Duration.ofMillis(DURATION_MS)); recording.enable(EventNames.PlaceholderTableStatistics).withThreshold(Duration.ofMillis(DURATION_MS)); recording.enable(EventNames.LoaderConstraintsTableStatistics).withThreshold(Duration.ofMillis(DURATION_MS)); recording.enable(EventNames.ProtectionDomainCacheTableStatistics).withThreshold(Duration.ofMillis(DURATION_MS)); recording.start(); exerciseStringTable(); Thread.currentThread().sleep(DURATION_MS/1000); System.gc(); recording.stop(); testCommonTableStatisticsEvent(recording, "SymbolTable"); testStringTableStatisticsEvent(recording, "StringTable"); testCommonTableStatisticsEvent(recording, "PlaceholderTable"); testCommonTableStatisticsEvent(recording, "StringTable"); testCommonTableStatisticsEvent(recording, "LoaderConstraintsTable"); testCommonTableStatisticsEvent(recording, "ProtectionDomainCacheTable"); } }