--- old/src/share/vm/gc/parallel/gcTaskManager.cpp 2016-07-01 15:34:51.679055315 -0700 +++ new/src/share/vm/gc/parallel/gcTaskManager.cpp 2016-07-01 15:34:51.559055319 -0700 @@ -399,12 +399,8 @@ WorkerManager::log_worker_creation(this, previous_created_workers, _active_workers, _created_workers, initializing); } -char *GCTaskManager::worker_name(uint which) { - if (thread(which) != NULL) { - return thread(which)->name(); - } else { - return NULL; - } +const char* GCTaskManager::group_name() { + return GCTaskThread::task_name(); } void GCTaskManager::initialize() { --- old/src/share/vm/gc/parallel/gcTaskManager.hpp 2016-07-01 15:34:52.351055292 -0700 +++ new/src/share/vm/gc/parallel/gcTaskManager.hpp 2016-07-01 15:34:52.235055296 -0700 @@ -556,8 +556,8 @@ GCTaskThread* install_worker(uint worker_id); // Add GC workers as needed. void add_workers(bool initializing); - // Return the thread name of a worker - char *worker_name(uint which); + // Base name (without worker id #) of threads. + const char* group_name(); }; // --- old/src/share/vm/gc/parallel/gcTaskThread.cpp 2016-07-01 15:34:53.019055269 -0700 +++ new/src/share/vm/gc/parallel/gcTaskThread.cpp 2016-07-01 15:34:52.907055272 -0700 @@ -36,6 +36,8 @@ #include "runtime/os.hpp" #include "runtime/thread.hpp" +#define PARGCTHREAD "ParGC Thread" + GCTaskThread::GCTaskThread(GCTaskManager* manager, uint which, uint processor_id) : @@ -45,7 +47,7 @@ _time_stamp_index(0) { set_id(which); - set_name("ParGC Thread#%d", which); + set_name(PARGCTHREAD "#%d", which); } GCTaskThread::~GCTaskThread() { @@ -54,6 +56,8 @@ } } +const char* GCTaskThread::task_name() { return PARGCTHREAD; } + GCTaskTimeStamp* GCTaskThread::time_stamp_at(uint index) { guarantee(index < GCTaskTimeStampEntries, "increase GCTaskTimeStampEntries"); if (_time_stamps == NULL) { --- old/src/share/vm/gc/parallel/gcTaskThread.hpp 2016-07-01 15:34:53.699055245 -0700 +++ new/src/share/vm/gc/parallel/gcTaskThread.hpp 2016-07-01 15:34:53.583055249 -0700 @@ -55,6 +55,8 @@ return new GCTaskThread(manager, which, processor_id); } public: + static const char* task_name(); + static void destroy(GCTaskThread* manager) { if (manager != NULL) { delete manager; --- old/src/share/vm/gc/shared/workerManager.hpp 2016-07-01 15:34:54.371055221 -0700 +++ new/src/share/vm/gc/shared/workerManager.hpp 2016-07-01 15:34:54.251055226 -0700 @@ -47,11 +47,11 @@ // threads and a failure would not be optimal but should not be fatal. template static uint add_workers (WorkerType* holder, - uint active_workers, - uint total_workers, - uint created_workers, - os::ThreadType worker_type, - bool initializing) { + uint active_workers, + uint total_workers, + uint created_workers, + os::ThreadType worker_type, + bool initializing) { uint start = created_workers; uint end = MIN2(active_workers, total_workers); for (uint worker_id = start; worker_id < end; worker_id += 1) { @@ -73,16 +73,14 @@ // Log (at trace level) a change in the number of created workers. template static void log_worker_creation(WorkerType* holder, - uint previous_created_workers, - uint active_workers, - uint created_workers, - bool initializing) { + uint previous_created_workers, + uint active_workers, + uint created_workers, + bool initializing) { if (previous_created_workers < created_workers) { - const char* initializing_msg = initializing ? "Adding initial" : ""; - log_trace(gc, task)("AdaptiveSizePolicy::add_workers() : %s " - "active_workers: %u created_workers: %u for %s to #%u", - initializing_msg, active_workers, created_workers, - holder->worker_name(previous_created_workers), created_workers - 1); + const char* initializing_msg = initializing ? "Adding initial" : "Creating additional"; + log_trace(gc, task)("%s %s(s) active workers %u created workers %u", + initializing_msg, holder->group_name(), active_workers, created_workers); } } }; --- old/src/share/vm/gc/shared/workgroup.cpp 2016-07-01 15:34:55.035055198 -0700 +++ new/src/share/vm/gc/shared/workgroup.cpp 2016-07-01 15:34:54.919055202 -0700 @@ -79,14 +79,6 @@ WorkerManager::log_worker_creation(this, previous_created_workers, _active_workers, _created_workers, initializing); } -char* AbstractWorkGang::worker_name(uint which) { - if (worker(which) != NULL) { - return worker(which)->name(); - } else { - return NULL; - } -} - AbstractGangWorker* AbstractWorkGang::worker(uint i) const { // Array index bounds checking. AbstractGangWorker* result = NULL; --- old/src/share/vm/gc/shared/workgroup.hpp 2016-07-01 15:34:55.707055175 -0700 +++ new/src/share/vm/gc/shared/workgroup.hpp 2016-07-01 15:34:55.583055179 -0700 @@ -173,12 +173,12 @@ // Add GC workers as needed to reach the specified number of workers. void add_workers(uint active_workers, bool initializing); - // Return the name of the thread in the work gang - char* worker_name(uint which); - // Return the Ith worker. AbstractGangWorker* worker(uint i) const; + // Base name (without worker id #) of threads. + const char* group_name() { return name(); } + void threads_do(ThreadClosure* tc) const; // Create a GC worker and install it into the work gang. --- /dev/null 2016-06-13 07:50:11.513633547 -0700 +++ new/test/gc/ergonomics/TestInitialGCThreadLogging.java 2016-07-01 15:34:56.259055156 -0700 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test TestInitialGCThreadLogging + * @bug 8157240 + * @summary Check trace logging of initial GC threads. + * @requires vm.gc=="null" + * @key gc + * @modules java.base/jdk.internal.misc + * @library /testlibrary + */ + +import jdk.test.lib.ProcessTools; +import jdk.test.lib.OutputAnalyzer; + +public class TestInitialGCThreadLogging { + public static void main(String[] args) throws Exception { + + testInitialGCThreadLogging("UseConcMarkSweepGC", "GC Thread"); + + testInitialGCThreadLogging("UseG1GC", "GC Thread"); + + testInitialGCThreadLogging("UseParallelGC", "ParGC Thread"); + } + + private static void verifyDynamicNumberOfGCThreads(OutputAnalyzer output, String threadName) { + output.shouldHaveExitValue(0); // test should run succesfully + output.shouldContain(threadName); + } + + private static void testInitialGCThreadLogging(String gcFlag, String threadName) throws Exception { + // UseDynamicNumberOfGCThreads and TraceDynamicGCThreads enabled + String[] baseArgs = {"-XX:+" + gcFlag, "-Xmx10M", "-XX:+UseDynamicNumberOfGCThreads", "-Xlog:gc+task=trace", "-version"}; + + // Base test with gc and +UseDynamicNumberOfGCThreads: + ProcessBuilder pb_enabled = ProcessTools.createJavaProcessBuilder(baseArgs); + verifyDynamicNumberOfGCThreads(new OutputAnalyzer(pb_enabled.start()), threadName); + } +}