< prev index next >

test/javax/management/mxbean/LeakTest.java

Print this page
rev 11832 : 8078896: Add @modules as needed to the jdk_svc tests
Reviewed-by: alanb, mchung

*** 1,7 **** /* ! * Copyright (c) 2006, 2008, 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. --- 1,7 ---- /* ! * Copyright (c) 2006, 2015, 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.
*** 23,32 **** --- 23,34 ---- /* @test * @bug 6482247 * @summary Test that creating MXBeans does not introduce memory leaks. * @author Eamonn McManus + * @modules java.desktop + * java.management * @run build LeakTest RandomMXBeanTest * @run main LeakTest */ /* In this test we create a ClassLoader, then use it to load and run another
*** 36,51 **** --- 38,55 ---- * which implies a memory leak. * * This test can be applied to any jtreg test, not just the MXBean tests. */ + import java.io.File; import java.lang.ref.Reference; import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; + import java.nio.file.Paths; public class LeakTest { /* Ideally we would include MXBeanTest in the list of tests, since it * has fairly complete coverage. However, the ClassLoader fails to be * gc'd when we do that, and I am unable to figure out why. Examining
*** 93,107 **** fail(originalTestClass.getName() + " kept ClassLoader reference"); } private static WeakReference<ClassLoader> testShadow(Class<?> originalTestClass) throws Exception { ! URLClassLoader originalLoader = ! (URLClassLoader) originalTestClass.getClassLoader(); ! URL[] urls = originalLoader.getURLs(); URLClassLoader shadowLoader = ! new ShadowClassLoader(urls, originalLoader.getParent()); System.out.println("Shadow loader is " + shadowLoader); String className = originalTestClass.getName(); Class<?> testClass = Class.forName(className, false, shadowLoader); if (testClass.getClassLoader() != shadowLoader) { throw new IllegalArgumentException("Loader didn't work: " + --- 97,115 ---- fail(originalTestClass.getName() + " kept ClassLoader reference"); } private static WeakReference<ClassLoader> testShadow(Class<?> originalTestClass) throws Exception { ! String[] cpaths = System.getProperty("test.classes", ".") ! .split(File.pathSeparator); ! URL[] urls = new URL[cpaths.length]; ! for (int i=0; i < cpaths.length; i++) { ! urls[i] = Paths.get(cpaths[i]).toUri().toURL(); ! } ! URLClassLoader shadowLoader = ! new ShadowClassLoader(urls, originalTestClass.getClassLoader().getParent()); System.out.println("Shadow loader is " + shadowLoader); String className = originalTestClass.getName(); Class<?> testClass = Class.forName(className, false, shadowLoader); if (testClass.getClassLoader() != shadowLoader) { throw new IllegalArgumentException("Loader didn't work: " +
< prev index next >