src/hotspot/share/services/gcNotifier.cpp
author coleenp
Fri, 16 Mar 2018 09:12:13 -0400
changeset 49449 ef5d5d343e2a
parent 47216 71c04702a3d5
child 50217 843fc56f4686
permissions -rw-r--r--
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files Summary: interfaceSupport.hpp is an inline file so moved to interfaceSupport.inline.hpp and stopped including it in .hpp files Reviewed-by: stefank, rehn, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
     1
/*
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 37248
diff changeset
     2
 * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
     4
 *
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
     7
 * published by the Free Software Foundation.
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
     8
 *
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    13
 * accompanied this code).
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    14
 *
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    18
 *
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    21
 * questions.
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    22
 *
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    23
 */
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    24
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    25
#include "precompiled.hpp"
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    26
#include "classfile/systemDictionary.hpp"
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    27
#include "classfile/vmSymbols.hpp"
35498
392b50de06c6 8146401: Clean up oop.hpp: add inline directives and fix header files
goetz
parents: 30247
diff changeset
    28
#include "oops/objArrayOop.inline.hpp"
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    29
#include "oops/oop.inline.hpp"
49449
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47216
diff changeset
    30
#include "runtime/handles.inline.hpp"
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    31
#include "runtime/java.hpp"
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    32
#include "runtime/javaCalls.hpp"
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    33
#include "runtime/mutex.hpp"
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    34
#include "runtime/mutexLocker.hpp"
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    35
#include "services/gcNotifier.hpp"
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    36
#include "services/management.hpp"
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    37
#include "services/memoryService.hpp"
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    38
#include "memoryManager.hpp"
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    39
#include "memory/oopFactory.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 35498
diff changeset
    40
#include "memory/resourceArea.hpp"
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    41
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    42
GCNotificationRequest *GCNotifier::first_request = NULL;
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    43
GCNotificationRequest *GCNotifier::last_request = NULL;
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    44
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    45
void GCNotifier::pushNotification(GCMemoryManager *mgr, const char *action, const char *cause) {
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    46
  // Make a copy of the last GC statistics
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    47
  // GC may occur between now and the creation of the notification
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    48
  int num_pools = MemoryService::num_memory_pools();
11591
854c0dff3844 7066129: GarbageCollectorMXBean#getLastGcInfo leaks native memory
dsamersoff
parents: 10242
diff changeset
    49
  // stat is deallocated inside GCNotificationRequest
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12266
diff changeset
    50
  GCStatInfo* stat = new(ResourceObj::C_HEAP, mtGC) GCStatInfo(num_pools);
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    51
  mgr->get_last_gc_stat(stat);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    52
  GCNotificationRequest *request = new GCNotificationRequest(os::javaTimeMillis(),mgr,action,cause,stat);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    53
  addRequest(request);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    54
 }
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    55
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    56
void GCNotifier::addRequest(GCNotificationRequest *request) {
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    57
  MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    58
  if(first_request == NULL) {
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    59
    first_request = request;
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    60
  } else {
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    61
    last_request->next = request;
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    62
  }
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    63
  last_request = request;
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    64
  Service_lock->notify_all();
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    65
}
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    66
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    67
GCNotificationRequest *GCNotifier::getRequest() {
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    68
  MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    69
  GCNotificationRequest *request = first_request;
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    70
  if(first_request != NULL) {
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    71
    first_request = first_request->next;
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    72
  }
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    73
  return request;
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    74
}
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    75
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    76
bool GCNotifier::has_event() {
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    77
  return first_request != NULL;
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    78
}
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    79
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    80
static Handle getGcInfoBuilder(GCMemoryManager *gcManager,TRAPS) {
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    81
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46271
diff changeset
    82
  Klass* gcMBeanKlass = Management::com_sun_management_internal_GarbageCollectorExtImpl_klass(CHECK_NH);
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    83
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    84
  instanceOop i = gcManager->get_memory_manager_instance(THREAD);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    85
  instanceHandle ih(THREAD, i);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    86
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    87
  JavaValue result(T_OBJECT);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    88
  JavaCallArguments args(ih);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    89
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    90
  JavaCalls::call_virtual(&result,
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    91
                          gcMBeanKlass,
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    92
                          vmSymbols::getGcInfoBuilder_name(),
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    93
                          vmSymbols::getGcInfoBuilder_signature(),
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    94
                          &args,
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    95
                          CHECK_NH);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    96
  return Handle(THREAD,(oop)result.get_jobject());
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    97
}
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    98
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
    99
static Handle createGcInfo(GCMemoryManager *gcManager, GCStatInfo *gcStatInfo,TRAPS) {
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   100
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   101
  // Fill the arrays of MemoryUsage objects with before and after GC
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   102
  // per pool memory usage
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   103
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46271
diff changeset
   104
  InstanceKlass* mu_klass = Management::java_lang_management_MemoryUsage_klass(CHECK_NH);
10242
ec32bf88801c 7074579: G1: JVM crash with JDK7 running ATG CRMDemo Fusion App
johnc
parents: 9623
diff changeset
   105
ec32bf88801c 7074579: G1: JVM crash with JDK7 running ATG CRMDemo Fusion App
johnc
parents: 9623
diff changeset
   106
  // The array allocations below should use a handle containing mu_klass
ec32bf88801c 7074579: G1: JVM crash with JDK7 running ATG CRMDemo Fusion App
johnc
parents: 9623
diff changeset
   107
  // as the first allocation could trigger a GC, causing the actual
ec32bf88801c 7074579: G1: JVM crash with JDK7 running ATG CRMDemo Fusion App
johnc
parents: 9623
diff changeset
   108
  // klass oop to move, and leaving mu_klass pointing to the old
ec32bf88801c 7074579: G1: JVM crash with JDK7 running ATG CRMDemo Fusion App
johnc
parents: 9623
diff changeset
   109
  // location.
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46271
diff changeset
   110
  objArrayOop bu = oopFactory::new_objArray(mu_klass, MemoryService::num_memory_pools(), CHECK_NH);
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   111
  objArrayHandle usage_before_gc_ah(THREAD, bu);
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46271
diff changeset
   112
  objArrayOop au = oopFactory::new_objArray(mu_klass, MemoryService::num_memory_pools(), CHECK_NH);
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   113
  objArrayHandle usage_after_gc_ah(THREAD, au);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   114
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   115
  for (int i = 0; i < MemoryService::num_memory_pools(); i++) {
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   116
    Handle before_usage = MemoryService::create_MemoryUsage_obj(gcStatInfo->before_gc_usage_for_pool(i), CHECK_NH);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   117
    Handle after_usage;
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   118
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   119
    MemoryUsage u = gcStatInfo->after_gc_usage_for_pool(i);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   120
    if (u.max_size() == 0 && u.used() > 0) {
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   121
      // If max size == 0, this pool is a survivor space.
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   122
      // Set max size = -1 since the pools will be swapped after GC.
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   123
      MemoryUsage usage(u.init_size(), u.used(), u.committed(), (size_t)-1);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   124
      after_usage = MemoryService::create_MemoryUsage_obj(usage, CHECK_NH);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   125
    } else {
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   126
        after_usage = MemoryService::create_MemoryUsage_obj(u, CHECK_NH);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   127
    }
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   128
    usage_before_gc_ah->obj_at_put(i, before_usage());
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   129
    usage_after_gc_ah->obj_at_put(i, after_usage());
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   130
  }
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   131
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   132
  // Current implementation only has 1 attribute (number of GC threads)
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   133
  // The type is 'I'
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   134
  objArrayOop extra_args_array = oopFactory::new_objArray(SystemDictionary::Integer_klass(), 1, CHECK_NH);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   135
  objArrayHandle extra_array (THREAD, extra_args_array);
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46271
diff changeset
   136
  InstanceKlass* intK = SystemDictionary::Integer_klass();
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   137
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   138
  instanceHandle extra_arg_val = intK->allocate_instance_handle(CHECK_NH);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   139
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   140
  {
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   141
    JavaValue res(T_VOID);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   142
    JavaCallArguments argsInt;
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   143
    argsInt.push_oop(extra_arg_val);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   144
    argsInt.push_int(gcManager->num_gc_threads());
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   145
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   146
    JavaCalls::call_special(&res,
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   147
                            intK,
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   148
                            vmSymbols::object_initializer_name(),
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   149
                            vmSymbols::int_void_signature(),
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   150
                            &argsInt,
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   151
                            CHECK_NH);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   152
  }
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   153
  extra_array->obj_at_put(0,extra_arg_val());
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   154
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46271
diff changeset
   155
  InstanceKlass* gcInfoklass = Management::com_sun_management_GcInfo_klass(CHECK_NH);
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   156
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46271
diff changeset
   157
  Handle gcInfo_instance = gcInfoklass->allocate_instance_handle(CHECK_NH);
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   158
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   159
  JavaValue constructor_result(T_VOID);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   160
  JavaCallArguments constructor_args(16);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   161
  constructor_args.push_oop(gcInfo_instance);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   162
  constructor_args.push_oop(getGcInfoBuilder(gcManager,THREAD));
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   163
  constructor_args.push_long(gcStatInfo->gc_index());
12266
a7ec6d9d767f 7087969: GarbageCollectorMXBean notification contains ticks vs millis
fparain
parents: 11766
diff changeset
   164
  constructor_args.push_long(Management::ticks_to_ms(gcStatInfo->start_time()));
a7ec6d9d767f 7087969: GarbageCollectorMXBean notification contains ticks vs millis
fparain
parents: 11766
diff changeset
   165
  constructor_args.push_long(Management::ticks_to_ms(gcStatInfo->end_time()));
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   166
  constructor_args.push_oop(usage_before_gc_ah);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   167
  constructor_args.push_oop(usage_after_gc_ah);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   168
  constructor_args.push_oop(extra_array);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   169
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   170
  JavaCalls::call_special(&constructor_result,
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46271
diff changeset
   171
                          gcInfoklass,
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   172
                          vmSymbols::object_initializer_name(),
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   173
                          vmSymbols::com_sun_management_GcInfo_constructor_signature(),
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   174
                          &constructor_args,
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   175
                          CHECK_NH);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   176
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 37248
diff changeset
   177
  return Handle(THREAD, gcInfo_instance());
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   178
}
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   179
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   180
void GCNotifier::sendNotification(TRAPS) {
11766
b1ff60353280 7143760: Memory leak in GarbageCollectionNotifications
fparain
parents: 11591
diff changeset
   181
  GCNotifier::sendNotificationInternal(THREAD);
b1ff60353280 7143760: Memory leak in GarbageCollectionNotifications
fparain
parents: 11591
diff changeset
   182
  // Clearing pending exception to avoid premature termination of
b1ff60353280 7143760: Memory leak in GarbageCollectionNotifications
fparain
parents: 11591
diff changeset
   183
  // the service thread
b1ff60353280 7143760: Memory leak in GarbageCollectionNotifications
fparain
parents: 11591
diff changeset
   184
  if (HAS_PENDING_EXCEPTION) {
b1ff60353280 7143760: Memory leak in GarbageCollectionNotifications
fparain
parents: 11591
diff changeset
   185
    CLEAR_PENDING_EXCEPTION;
b1ff60353280 7143760: Memory leak in GarbageCollectionNotifications
fparain
parents: 11591
diff changeset
   186
  }
b1ff60353280 7143760: Memory leak in GarbageCollectionNotifications
fparain
parents: 11591
diff changeset
   187
}
b1ff60353280 7143760: Memory leak in GarbageCollectionNotifications
fparain
parents: 11591
diff changeset
   188
b1ff60353280 7143760: Memory leak in GarbageCollectionNotifications
fparain
parents: 11591
diff changeset
   189
class NotificationMark : public StackObj {
b1ff60353280 7143760: Memory leak in GarbageCollectionNotifications
fparain
parents: 11591
diff changeset
   190
  // This class is used in GCNotifier::sendNotificationInternal to ensure that
b1ff60353280 7143760: Memory leak in GarbageCollectionNotifications
fparain
parents: 11591
diff changeset
   191
  // the GCNotificationRequest object is properly cleaned up, whatever path
b1ff60353280 7143760: Memory leak in GarbageCollectionNotifications
fparain
parents: 11591
diff changeset
   192
  // is used to exit the method.
b1ff60353280 7143760: Memory leak in GarbageCollectionNotifications
fparain
parents: 11591
diff changeset
   193
  GCNotificationRequest* _request;
b1ff60353280 7143760: Memory leak in GarbageCollectionNotifications
fparain
parents: 11591
diff changeset
   194
public:
b1ff60353280 7143760: Memory leak in GarbageCollectionNotifications
fparain
parents: 11591
diff changeset
   195
  NotificationMark(GCNotificationRequest* r) {
b1ff60353280 7143760: Memory leak in GarbageCollectionNotifications
fparain
parents: 11591
diff changeset
   196
    _request = r;
b1ff60353280 7143760: Memory leak in GarbageCollectionNotifications
fparain
parents: 11591
diff changeset
   197
  }
b1ff60353280 7143760: Memory leak in GarbageCollectionNotifications
fparain
parents: 11591
diff changeset
   198
  ~NotificationMark() {
b1ff60353280 7143760: Memory leak in GarbageCollectionNotifications
fparain
parents: 11591
diff changeset
   199
    assert(_request != NULL, "Sanity check");
b1ff60353280 7143760: Memory leak in GarbageCollectionNotifications
fparain
parents: 11591
diff changeset
   200
    delete _request;
b1ff60353280 7143760: Memory leak in GarbageCollectionNotifications
fparain
parents: 11591
diff changeset
   201
  }
b1ff60353280 7143760: Memory leak in GarbageCollectionNotifications
fparain
parents: 11591
diff changeset
   202
};
b1ff60353280 7143760: Memory leak in GarbageCollectionNotifications
fparain
parents: 11591
diff changeset
   203
b1ff60353280 7143760: Memory leak in GarbageCollectionNotifications
fparain
parents: 11591
diff changeset
   204
void GCNotifier::sendNotificationInternal(TRAPS) {
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   205
  ResourceMark rm(THREAD);
11766
b1ff60353280 7143760: Memory leak in GarbageCollectionNotifications
fparain
parents: 11591
diff changeset
   206
  HandleMark hm(THREAD);
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   207
  GCNotificationRequest *request = getRequest();
11766
b1ff60353280 7143760: Memory leak in GarbageCollectionNotifications
fparain
parents: 11591
diff changeset
   208
  if (request != NULL) {
b1ff60353280 7143760: Memory leak in GarbageCollectionNotifications
fparain
parents: 11591
diff changeset
   209
    NotificationMark nm(request);
19953
bcb70cd411bc 8023478: Test fails with HS crash in GCNotifier.
kevinw
parents: 19144
diff changeset
   210
    Handle objGcInfo = createGcInfo(request->gcManager, request->gcStatInfo, CHECK);
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   211
19144
02f1ea6475c0 8020943: Memory leak when GCNotifier uses create_from_platform_dependent_str()
kevinw
parents: 13728
diff changeset
   212
    Handle objName = java_lang_String::create_from_str(request->gcManager->name(), CHECK);
02f1ea6475c0 8020943: Memory leak when GCNotifier uses create_from_platform_dependent_str()
kevinw
parents: 13728
diff changeset
   213
    Handle objAction = java_lang_String::create_from_str(request->gcAction, CHECK);
02f1ea6475c0 8020943: Memory leak when GCNotifier uses create_from_platform_dependent_str()
kevinw
parents: 13728
diff changeset
   214
    Handle objCause = java_lang_String::create_from_str(request->gcCause, CHECK);
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46271
diff changeset
   215
    InstanceKlass* gc_mbean_klass = Management::com_sun_management_internal_GarbageCollectorExtImpl_klass(CHECK);
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   216
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   217
    instanceOop gc_mbean = request->gcManager->get_memory_manager_instance(THREAD);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   218
    instanceHandle gc_mbean_h(THREAD, gc_mbean);
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46271
diff changeset
   219
    if (!gc_mbean_h->is_a(gc_mbean_klass)) {
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   220
      THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   221
                "This GCMemoryManager doesn't have a GarbageCollectorMXBean");
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   222
    }
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   223
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   224
    JavaValue result(T_VOID);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   225
    JavaCallArguments args(gc_mbean_h);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   226
    args.push_long(request->timestamp);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   227
    args.push_oop(objName);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   228
    args.push_oop(objAction);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   229
    args.push_oop(objCause);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   230
    args.push_oop(objGcInfo);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   231
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   232
    JavaCalls::call_virtual(&result,
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   233
                            gc_mbean_klass,
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   234
                            vmSymbols::createGCNotification_name(),
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   235
                            vmSymbols::createGCNotification_signature(),
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   236
                            &args,
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   237
                            CHECK);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   238
  }
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   239
}
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff changeset
   240