Path: blob/master/test/hotspot/jtreg/compiler/profiling/unloadingconflict/TestProfileConflictClassUnloading.java
41153 views
/*1* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 802757226* @summary class unloading resets profile, method compiled after the profile is27* first set and before class loading sets unknown bit with not recorded class28* @library /29* @build compiler.profiling.unloadingconflict.B30* @run main/othervm -XX:TypeProfileLevel=222 -XX:-BackgroundCompilation31* compiler.profiling.unloadingconflict.TestProfileConflictClassUnloading32*33*/3435package compiler.profiling.unloadingconflict;3637import java.net.MalformedURLException;38import java.net.URL;39import java.net.URLClassLoader;40import java.nio.file.Paths;4142public class TestProfileConflictClassUnloading {43static class A {44}454647static void m1(Object o) {48}4950static void m2(Object o) {51m1(o);52}5354static void m3(A a, boolean do_call) {55if (!do_call) {56return;57}58m2(a);59}6061public static ClassLoader newClassLoader() {62try {63return new URLClassLoader(new URL[] {64Paths.get(System.getProperty("test.classes",".")).toUri().toURL(),65}, null);66} catch (MalformedURLException e){67throw new RuntimeException("Unexpected URL conversion failure", e);68}69}7071public static void main(String[] args) throws Exception {72ClassLoader loader = newClassLoader();73Object o = loader.loadClass("compiler.profiling.unloadingconflict.B").newInstance();74// collect conflicting profiles75for (int i = 0; i < 5000; i++) {76m2(o);77}78// prepare for conflict79A a = new A();80for (int i = 0; i < 5000; i++) {81m3(a, false);82}83// unload class in profile84o = null;85loader = null;86System.gc();87// record the conflict88m3(a, true);89// trigger another GC90System.gc();91}92}939495