Path: blob/master/test/hotspot/jtreg/compiler/compilercontrol/jcmd/StressAddMultiThreadedTest.java
41153 views
/*1* Copyright (c) 2015, 2021, 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* @key randomness26* @bug 813716727* @summary Tests jcmd to be able to add a lot of huge directive files with28* parallel executed jcmds until timeout has reached29* @modules java.base/jdk.internal.misc30* @library /test/lib /31*32* @build sun.hotspot.WhiteBox33* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox34* @run driver compiler.compilercontrol.jcmd.StressAddMultiThreadedTest35*/3637package compiler.compilercontrol.jcmd;3839import jdk.test.lib.dcmd.PidJcmdExecutor;4041import java.util.concurrent.ArrayBlockingQueue;42import java.util.concurrent.BlockingQueue;43import java.util.concurrent.ExecutorService;44import java.util.concurrent.ThreadPoolExecutor;45import java.util.concurrent.TimeUnit;4647public class StressAddMultiThreadedTest extends StressAddJcmdBase {48private static final int THREADS = Integer.getInteger(49"compiler.compilercontrol.jcmd.StressAddMultiThreadedTest.threads",505);51private volatile int commands = Integer.getInteger(52"compiler.compilercontrol.jcmd.StressAddMultiThreadedTest.commands",5320);54private final BlockingQueue<Runnable> queue;55private final ExecutorService executor;5657public StressAddMultiThreadedTest() {58queue = new ArrayBlockingQueue<>(THREADS);59executor = new ThreadPoolExecutor(THREADS, THREADS, 100,60TimeUnit.MILLISECONDS, queue,61new ThreadPoolExecutor.CallerRunsPolicy());62}6364public static void main(String[] args) {65new StressAddMultiThreadedTest().test();66}6768@Override69protected boolean makeConnection(int pid) {70String nextCommand = nextCommand();71executor.submit(() -> new PidJcmdExecutor(String.valueOf(pid))72.execute(nextCommand));73return (--commands != 0);74}7576@Override77protected void finish() {78executor.shutdown();79try {80executor.awaitTermination(10, TimeUnit.SECONDS);81} catch (InterruptedException e) {82throw new Error("Interrupted while awaiting for termination: " + e,83e);84}85executor.shutdownNow();86}87}888990