jdk

Форк
0
/
monitorDeflationThread.cpp 
101 строка · 3.7 Кб
1
/*
2
 * Copyright (c) 2020, 2024, 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
#include "precompiled.hpp"
26
#include "classfile/javaClasses.hpp"
27
#include "classfile/vmClasses.hpp"
28
#include "classfile/vmSymbols.hpp"
29
#include "logging/log.hpp"
30
#include "logging/logStream.hpp"
31
#include "memory/universe.hpp"
32
#include "runtime/interfaceSupport.inline.hpp"
33
#include "runtime/java.hpp"
34
#include "runtime/javaCalls.hpp"
35
#include "runtime/monitorDeflationThread.hpp"
36
#include "runtime/mutexLocker.hpp"
37
#include "runtime/synchronizer.hpp"
38

39
void MonitorDeflationThread::initialize() {
40
  EXCEPTION_MARK;
41

42
  const char* name = "Monitor Deflation Thread";
43
  Handle thread_oop = JavaThread::create_system_thread_object(name, CHECK);
44

45
  MonitorDeflationThread* thread = new MonitorDeflationThread(&monitor_deflation_thread_entry);
46
  JavaThread::vm_exit_on_osthread_failure(thread);
47

48
  JavaThread::start_internal_daemon(THREAD, thread, thread_oop, NearMaxPriority);
49
}
50

51
void MonitorDeflationThread::monitor_deflation_thread_entry(JavaThread* jt, TRAPS) {
52

53
  // We wait for the lowest of these two intervals:
54
  //  - AsyncDeflationInterval
55
  //      Normal threshold-based deflation heuristic checks the conditions at this interval.
56
  //      See is_async_deflation_needed().
57
  //  - GuaranteedAsyncDeflationInterval
58
  //      Backup deflation heuristic checks the conditions at this interval.
59
  //      See is_async_deflation_needed().
60
  //
61
  intx wait_time = max_intx;
62
  if (AsyncDeflationInterval > 0) {
63
    wait_time = MIN2(wait_time, AsyncDeflationInterval);
64
  }
65
  if (GuaranteedAsyncDeflationInterval > 0) {
66
    wait_time = MIN2(wait_time, GuaranteedAsyncDeflationInterval);
67
  }
68

69
  // If all options are disabled, then wait time is not defined, and the deflation
70
  // is effectively disabled. In that case, exit the thread immediately after printing
71
  // a warning message.
72
  if (wait_time == max_intx) {
73
    warning("Async deflation is disabled");
74
    return;
75
  }
76

77
  while (true) {
78
    {
79
      // Need state transition ThreadBlockInVM so that this thread
80
      // will be handled by safepoint correctly when this thread is
81
      // notified at a safepoint.
82

83
      ThreadBlockInVM tbivm(jt);
84

85
      MonitorLocker ml(MonitorDeflation_lock, Mutex::_no_safepoint_check_flag);
86
      while (!ObjectSynchronizer::is_async_deflation_needed()) {
87
        // Wait until notified that there is some work to do.
88
        ml.wait(wait_time);
89
      }
90
    }
91

92
    (void)ObjectSynchronizer::deflate_idle_monitors();
93

94
    if (log_is_enabled(Debug, monitorinflation)) {
95
      // The VMThread calls do_final_audit_and_print_stats() which calls
96
      // audit_and_print_stats() at the Info level at VM exit time.
97
      LogStreamHandle(Debug, monitorinflation) ls;
98
      ObjectSynchronizer::audit_and_print_stats(&ls, false /* on_exit */);
99
    }
100
  }
101
}
102

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.