4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 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 import sun.hotspot.WhiteBox; 25 26 import java.lang.reflect.Method; 27 import java.net.URL; 28 import java.net.URLClassLoader; 29 30 /* 31 * @test MethodUnloadingTest 32 * @bug 8029443 33 * @summary "Tests the unloading of methods to to class unloading" 34 * @library /testlibrary /testlibrary/whitebox 35 * @build TestMethodUnloading 36 * @build WorkerClass 37 * @run main ClassFileInstaller sun.hotspot.WhiteBox 38 * sun.hotspot.WhiteBox$WhiteBoxPermission 39 * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:-BackgroundCompilation -XX:-UseCompressedOops -XX:CompileOnly=TestMethodUnloading::doWork TestMethodUnloading 40 */ 41 public class TestMethodUnloading { 42 private static final String workerClassName = "WorkerClass"; 43 private static int work = -1; 44 45 private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); 46 private static int COMP_LEVEL_SIMPLE = 1; 47 private static int COMP_LEVEL_FULL_OPTIMIZATION = 4; 48 49 /** 50 * Does some work by either using the workerClass or locally producing values. 51 * @param workerClass Class performing some work (will be unloaded) 52 * @param useWorker If true the workerClass is used 53 */ 54 static private void doWork(Class<?> workerClass, boolean useWorker) throws InstantiationException, IllegalAccessException { 55 if (useWorker) { 56 // Create a new instance 57 Object worker = workerClass.newInstance(); 58 // We would like to call a method of WorkerClass here but we cannot cast to WorkerClass | 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 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 import jdk.testlib.WhiteBox; 25 26 import java.lang.reflect.Method; 27 import java.net.URL; 28 import java.net.URLClassLoader; 29 30 /* 31 * @test MethodUnloadingTest 32 * @bug 8029443 33 * @summary "Tests the unloading of methods to to class unloading" 34 * @library /testlibrary /../../test/lib 35 * @build TestMethodUnloading 36 * @build WorkerClass 37 * @run main ClassFileInstaller jdk.testlib.WhiteBox 38 * jdk.testlib.WhiteBox$WhiteBoxPermission 39 * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:-BackgroundCompilation -XX:-UseCompressedOops -XX:CompileOnly=TestMethodUnloading::doWork TestMethodUnloading 40 */ 41 public class TestMethodUnloading { 42 private static final String workerClassName = "WorkerClass"; 43 private static int work = -1; 44 45 private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); 46 private static int COMP_LEVEL_SIMPLE = 1; 47 private static int COMP_LEVEL_FULL_OPTIMIZATION = 4; 48 49 /** 50 * Does some work by either using the workerClass or locally producing values. 51 * @param workerClass Class performing some work (will be unloaded) 52 * @param useWorker If true the workerClass is used 53 */ 54 static private void doWork(Class<?> workerClass, boolean useWorker) throws InstantiationException, IllegalAccessException { 55 if (useWorker) { 56 // Create a new instance 57 Object worker = workerClass.newInstance(); 58 // We would like to call a method of WorkerClass here but we cannot cast to WorkerClass |