Path: blob/master/test/hotspot/jtreg/serviceability/tmtools/jstack/JstackThreadTest.java
41153 views
/*1* Copyright (c) 2016, 2020, 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*/2223import java.util.Arrays;24import jdk.test.lib.JDKToolLauncher;25import jdk.test.lib.process.OutputAnalyzer;26import jdk.test.lib.process.ProcessTools;27import utils.Utils;28import java.util.concurrent.CountDownLatch;2930/*31* @test JstackThreadTest32* @bug 815144233* @summary jstack doesn't close quotation marks properly with threads' name greater than 1996 characters34* @modules java.base/jdk.internal.misc35* @library /test/lib36* @run main JstackThreadTest37*/38public class JstackThreadTest {39static class NamedThread extends Thread {40CountDownLatch latch;41NamedThread(String name, CountDownLatch latch) {42this.latch = latch;43setName(name);4445}46@Override47public void run() {48latch.countDown();49Utils.sleep();50}51}5253public static void main(String[] args) throws Exception {54StringBuilder sb = new StringBuilder();55/*create a string more than 1996 character */56for(int i = 0; i < 1998; i++){57sb.append("a");58}59testWithName(sb.toString());60}6162private static void testWithName(String name) throws Exception {63//parent thread countDown latch64CountDownLatch latch = new CountDownLatch(1);65// Start a thread with a long thread name66NamedThread thread = new NamedThread(name, latch);67thread.setDaemon(true);68thread.start();69ProcessBuilder processBuilder = new ProcessBuilder();70JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstack");71launcher.addVMArgs(jdk.test.lib.Utils.getTestJavaOpts());72launcher.addToolArg("-l");73launcher.addToolArg(Long.toString(ProcessTools.getProcessId()));74processBuilder.command(launcher.getCommand());75System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", ""));76// Ensuring that Jstack will always run after NamedThread77latch.await();78OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);79System.out.println(output.getOutput());80output.shouldContain("\""+ name + "\"");81}82}838485