< prev index next >
test/jdk/jdk/jfr/event/runtime/TestClassLoaderStatsEvent.java
Print this page
rev 58872 : 8238358: Implementation of JEP 371: Hidden Classes
Reviewed-by: alanb, cjplummer, coleenp, dholmes, dlong, forax, jlahoda, psandoz, plevart, sspitsyn, vromero
Contributed-by: mandy.chung@oracle.com, lois.foltan@oracle.com, david.holmes@oracle.com, harold.seigel@oracle.com, serguei.spitsyn@oracle.com, alex.buckley@oracle.com, jamsheed.c.m@oracle.com, jan.lahoda@oracle.com, amy.lu@oracle.com
*** 1,7 ****
/*
! * Copyright (c) 2014, 2018, 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
--- 1,7 ----
/*
! * Copyright (c) 2014, 2020, 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
*** 26,35 ****
--- 26,36 ----
package jdk.jfr.event.runtime;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+ import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.List;
import jdk.jfr.Recording;
*** 37,51 ****
--- 38,57 ----
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.compiler.InMemoryJavaCompiler;
+
/**
* @test
* @key jfr
* @requires vm.hasJFR
* @library /test/lib /test/jdk
+ * @modules java.base/jdk.internal.misc
+ * jdk.compiler
+ * jdk.jfr
* @build jdk.jfr.event.runtime.TestClasses
* @run main/othervm jdk.jfr.event.runtime.TestClassLoaderStatsEvent
*/
public class TestClassLoaderStatsEvent {
private final static String EVENT_NAME = EventNames.ClassLoaderStatistics;
*** 71,86 ****
}
RecordedClassLoader recordedClassLoader = event.getValue("classLoader");
if (CLASSLOADER_TYPE_NAME.equals(recordedClassLoader.getType().getName())) {
Asserts.assertEquals(CLASS_LOADER_NAME, recordedClassLoader.getName(),
"Expected class loader name " + CLASS_LOADER_NAME + ", got name " + recordedClassLoader.getName());
! Events.assertField(event, "classCount").equal(1L);
Events.assertField(event, "chunkSize").above(1L);
Events.assertField(event, "blockSize").above(1L);
! Events.assertField(event, "unsafeAnonymousClassCount").equal(1L);
! Events.assertField(event, "unsafeAnonymousChunkSize").above(1L);
! Events.assertField(event, "unsafeAnonymousBlockSize").above(1L);
isAnyFound = true;
}
}
Asserts.assertTrue(isAnyFound, "No events found");
}
--- 77,95 ----
}
RecordedClassLoader recordedClassLoader = event.getValue("classLoader");
if (CLASSLOADER_TYPE_NAME.equals(recordedClassLoader.getType().getName())) {
Asserts.assertEquals(CLASS_LOADER_NAME, recordedClassLoader.getName(),
"Expected class loader name " + CLASS_LOADER_NAME + ", got name " + recordedClassLoader.getName());
! Events.assertField(event, "classCount").equal(2L);
Events.assertField(event, "chunkSize").above(1L);
Events.assertField(event, "blockSize").above(1L);
! Events.assertField(event, "unsafeAnonymousClassCount").equal(2L);
! Events.assertField(event, "unsafeAnonymousChunkSize").above(0L);
! Events.assertField(event, "unsafeAnonymousBlockSize").above(0L);
! Events.assertField(event, "hiddenClassCount").equal(2L);
! Events.assertField(event, "hiddenChunkSize").above(0L);
! Events.assertField(event, "hiddenBlockSize").above(0L);
isAnyFound = true;
}
}
Asserts.assertTrue(isAnyFound, "No events found");
}
*** 89,98 ****
--- 98,119 ----
dummyloader = new DummyClassLoader(name);
Class<?> c = Class.forName(TestClass.class.getName(), true, dummyloader);
if (c.getClassLoader() != dummyloader) {
throw new RuntimeException("TestClass defined by wrong classloader: " + c.getClassLoader());
}
+
+ // Compile a class for method createNonFindableClasses() to use to create both a
+ // weak hidden class and an anonymous class.
+ byte klassbuf[] = InMemoryJavaCompiler.compile("jdk.jfr.event.runtime.TestClass",
+ "package jdk.jfr.event.runtime; " +
+ "public class TestClass { " +
+ " public static void concat(String one, String two) throws Throwable { " +
+ " } } ");
+
+ Method m = c.getDeclaredMethod("createNonFindableClasses", byte[].class);
+ m.setAccessible(true);
+ m.invoke(null, klassbuf);
}
public static class DummyClassLoader extends ClassLoader {
static ByteBuffer readClassFile(String name) {
< prev index next >