src/share/vm/runtime/serviceThread.cpp

Thu, 24 Nov 2016 11:27:57 +0100

author
tschatzl
date
Thu, 24 Nov 2016 11:27:57 +0100
changeset 9982
72053ed6f8d4
parent 7164
fa6c442c59ee
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

8057003: Large reference arrays cause extremely long synchronization times
Summary: Slice large object arrays into parts so that the synchronization of marking threads with an STW pause request does not take long.
Reviewed-by: ehelin, pliden
Contributed-by: maoliang.ml@alibaba-inc.com

kamg@2511 1 /*
fparain@5047 2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
kamg@2511 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
kamg@2511 4 *
kamg@2511 5 * This code is free software; you can redistribute it and/or modify it
kamg@2511 6 * under the terms of the GNU General Public License version 2 only, as
kamg@2511 7 * published by the Free Software Foundation.
kamg@2511 8 *
kamg@2511 9 * This code is distributed in the hope that it will be useful, but WITHOUT
kamg@2511 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
kamg@2511 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kamg@2511 12 * version 2 for more details (a copy is included in the LICENSE file that
kamg@2511 13 * accompanied this code).
kamg@2511 14 *
kamg@2511 15 * You should have received a copy of the GNU General Public License version
kamg@2511 16 * 2 along with this work; if not, write to the Free Software Foundation,
kamg@2511 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
kamg@2511 18 *
kamg@2511 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
kamg@2511 20 * or visit www.oracle.com if you need additional information or have any
kamg@2511 21 * questions.
kamg@2511 22 *
kamg@2511 23 */
kamg@2511 24
kamg@2511 25 #include "precompiled.hpp"
kamg@2511 26 #include "runtime/interfaceSupport.hpp"
kamg@2511 27 #include "runtime/javaCalls.hpp"
kamg@2511 28 #include "runtime/serviceThread.hpp"
kamg@2511 29 #include "runtime/mutexLocker.hpp"
kamg@2511 30 #include "prims/jvmtiImpl.hpp"
jcoomes@7164 31 #include "services/allocationContextService.hpp"
fparain@2888 32 #include "services/gcNotifier.hpp"
fparain@5047 33 #include "services/diagnosticArgument.hpp"
fparain@5047 34 #include "services/diagnosticFramework.hpp"
kamg@2511 35
kamg@2511 36 ServiceThread* ServiceThread::_instance = NULL;
kamg@2511 37
kamg@2511 38 void ServiceThread::initialize() {
kamg@2511 39 EXCEPTION_MARK;
kamg@2511 40
kamg@2511 41 instanceKlassHandle klass (THREAD, SystemDictionary::Thread_klass());
kamg@2511 42 instanceHandle thread_oop = klass->allocate_instance_handle(CHECK);
kamg@2511 43
kamg@2511 44 const char* name = JDK_Version::is_gte_jdk17x_version() ?
kamg@2511 45 "Service Thread" : "Low Memory Detector";
kamg@2511 46
kamg@2511 47 Handle string = java_lang_String::create_from_str(name, CHECK);
kamg@2511 48
kamg@2511 49 // Initialize thread_oop to put it into the system threadGroup
kamg@2511 50 Handle thread_group (THREAD, Universe::system_thread_group());
kamg@2511 51 JavaValue result(T_VOID);
kamg@2511 52 JavaCalls::call_special(&result, thread_oop,
kamg@2511 53 klass,
kamg@2511 54 vmSymbols::object_initializer_name(),
kamg@2511 55 vmSymbols::threadgroup_string_void_signature(),
kamg@2511 56 thread_group,
kamg@2511 57 string,
kamg@2511 58 CHECK);
kamg@2511 59
kamg@2511 60 {
kamg@2511 61 MutexLocker mu(Threads_lock);
kamg@2511 62 ServiceThread* thread = new ServiceThread(&service_thread_entry);
kamg@2511 63
kamg@2511 64 // At this point it may be possible that no osthread was created for the
kamg@2511 65 // JavaThread due to lack of memory. We would have to throw an exception
kamg@2511 66 // in that case. However, since this must work and we do not allow
kamg@2511 67 // exceptions anyway, check and abort if this fails.
kamg@2511 68 if (thread == NULL || thread->osthread() == NULL) {
kamg@2511 69 vm_exit_during_initialization("java.lang.OutOfMemoryError",
kamg@2511 70 "unable to create new native thread");
kamg@2511 71 }
kamg@2511 72
kamg@2511 73 java_lang_Thread::set_thread(thread_oop(), thread);
kamg@2511 74 java_lang_Thread::set_priority(thread_oop(), NearMaxPriority);
kamg@2511 75 java_lang_Thread::set_daemon(thread_oop());
kamg@2511 76 thread->set_threadObj(thread_oop());
dcubed@2623 77 _instance = thread;
kamg@2511 78
kamg@2511 79 Threads::add(thread);
kamg@2511 80 Thread::start(thread);
kamg@2511 81 }
kamg@2511 82 }
kamg@2511 83
kamg@2511 84 void ServiceThread::service_thread_entry(JavaThread* jt, TRAPS) {
kamg@2511 85 while (true) {
kamg@2511 86 bool sensors_changed = false;
kamg@2511 87 bool has_jvmti_events = false;
fparain@2888 88 bool has_gc_notification_event = false;
fparain@5047 89 bool has_dcmd_notification_event = false;
jcoomes@7164 90 bool acs_notify = false;
kamg@2511 91 JvmtiDeferredEvent jvmti_event;
kamg@2511 92 {
kamg@2511 93 // Need state transition ThreadBlockInVM so that this thread
kamg@2511 94 // will be handled by safepoint correctly when this thread is
kamg@2511 95 // notified at a safepoint.
kamg@2511 96
kamg@2511 97 // This ThreadBlockInVM object is not also considered to be
kamg@2511 98 // suspend-equivalent because ServiceThread is not visible to
kamg@2511 99 // external suspension.
kamg@2511 100
kamg@2511 101 ThreadBlockInVM tbivm(jt);
kamg@2511 102
kamg@2511 103 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
kamg@2511 104 while (!(sensors_changed = LowMemoryDetector::has_pending_requests()) &&
fparain@2888 105 !(has_jvmti_events = JvmtiDeferredEventQueue::has_events()) &&
fparain@5047 106 !(has_gc_notification_event = GCNotifier::has_event()) &&
jcoomes@7164 107 !(has_dcmd_notification_event = DCmdFactory::has_pending_jmx_notification()) &&
jcoomes@7164 108 !(acs_notify = AllocationContextService::should_notify())) {
kamg@2511 109 // wait until one of the sensors has pending requests, or there is a
fparain@2888 110 // pending JVMTI event or JMX GC notification to post
kamg@2511 111 Service_lock->wait(Mutex::_no_safepoint_check_flag);
kamg@2511 112 }
kamg@2511 113
kamg@2511 114 if (has_jvmti_events) {
kamg@2511 115 jvmti_event = JvmtiDeferredEventQueue::dequeue();
kamg@2511 116 }
kamg@2511 117 }
kamg@2511 118
kamg@2511 119 if (has_jvmti_events) {
kamg@2511 120 jvmti_event.post();
kamg@2511 121 }
kamg@2511 122
kamg@2511 123 if (sensors_changed) {
kamg@2511 124 LowMemoryDetector::process_sensor_changes(jt);
kamg@2511 125 }
fparain@2888 126
fparain@2888 127 if(has_gc_notification_event) {
fparain@2888 128 GCNotifier::sendNotification(CHECK);
fparain@2888 129 }
fparain@5047 130
fparain@5047 131 if(has_dcmd_notification_event) {
fparain@5047 132 DCmdFactory::send_notification(CHECK);
fparain@5047 133 }
jcoomes@7164 134
jcoomes@7164 135 if (acs_notify) {
jcoomes@7164 136 AllocationContextService::notify(CHECK);
jcoomes@7164 137 }
kamg@2511 138 }
kamg@2511 139 }
kamg@2511 140
kamg@2511 141 bool ServiceThread::is_service_thread(Thread* thread) {
kamg@2511 142 return thread == _instance;
kamg@2511 143 }

mercurial