1 /*
   2  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   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 /*
  25  * @test TestOverloadCompileQueues
  26  * @bug 8163511
  27  * @summary Test overloading the C1 and C2 compile queues with tasks.
  28  * @requires !vm.graal.enabled
  29  * @run main/othervm -XX:-TieredCompilation -XX:CompileThreshold=2 -XX:CICompilerCount=1
  30  *                   compiler.classUnloading.methodUnloading.TestOverloadCompileQueues
  31  * @run main/othervm -XX:TieredCompileTaskTimeout=1000 -XX:CompileThresholdScaling=0.001 -XX:CICompilerCount=2
  32  *                   compiler.classUnloading.methodUnloading.TestOverloadCompileQueues
  33  */
  34 
  35 package compiler.classUnloading.methodUnloading;
  36 
  37 import java.lang.reflect.Method;
  38 import java.net.URL;
  39 import java.net.URLClassLoader;
  40 
  41 public class TestOverloadCompileQueues {
  42     public static final int ITERS = 500; // Increase for longer stress testing
  43 
  44     // Some methods to fill up the compile queue
  45     public static void test0() { }
  46     public static void test1() { }
  47     public static void test2() { }
  48     public static void test3() { }
  49     public static void test4() { }
  50     public static void test5() { }
  51     public static void test6() { }
  52     public static void test7() { }
  53     public static void test8() { }
  54     public static void test9() { }
  55     public static void test10() { }
  56     public static void test11() { }
  57     public static void test12() { }
  58     public static void test13() { }
  59     public static void test14() { }
  60     public static void test15() { }
  61     public static void test16() { }
  62     public static void test17() { }
  63     public static void test18() { }
  64     public static void test19() { }
  65 
  66     public static void main(String[] args) throws Throwable {
  67         Class<?> thisClass = TestOverloadCompileQueues.class;
  68         ClassLoader defaultLoader = thisClass.getClassLoader();
  69         URL classesDir = thisClass.getProtectionDomain().getCodeSource().getLocation();
  70 
  71         for (int i = 0; i < ITERS; ++i) {
  72             // Load test class with own class loader
  73             URLClassLoader myLoader = URLClassLoader.newInstance(new URL[] {classesDir}, defaultLoader.getParent());
  74             Class<?> testClass = Class.forName(thisClass.getCanonicalName(), true, myLoader);
  75 
  76             // Execute all test methods to trigger compilation and fill up compile queue
  77             for (int j = 1; j < 20; ++j) {
  78                 Method method = testClass.getDeclaredMethod("test" + j);
  79                 method.invoke(null);
  80                 method.invoke(null);
  81             }
  82 
  83             // Unload dead classes from ealier iterations
  84             System.gc();
  85         }
  86     }
  87 }