Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/src/share/vm/services/gcNotifier.cpp
+++ new/src/share/vm/services/gcNotifier.cpp
1 1 /*
2 2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation.
8 8 *
9 9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 12 * version 2 for more details (a copy is included in the LICENSE file that
13 13 * accompanied this code).
14 14 *
15 15 * You should have received a copy of the GNU General Public License version
16 16 * 2 along with this work; if not, write to the Free Software Foundation,
17 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 18 *
19 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 20 * or visit www.oracle.com if you need additional information or have any
21 21 * questions.
22 22 *
23 23 */
24 24
25 25 #include "precompiled.hpp"
26 26 #include "classfile/systemDictionary.hpp"
27 27 #include "classfile/vmSymbols.hpp"
28 28 #include "oops/oop.inline.hpp"
29 29 #include "runtime/interfaceSupport.hpp"
30 30 #include "runtime/java.hpp"
31 31 #include "runtime/javaCalls.hpp"
32 32 #include "runtime/mutex.hpp"
33 33 #include "runtime/mutexLocker.hpp"
34 34 #include "services/gcNotifier.hpp"
35 35 #include "services/management.hpp"
36 36 #include "services/memoryService.hpp"
37 37 #include "memoryManager.hpp"
38 38 #include "memory/oopFactory.hpp"
39 39
40 40 GCNotificationRequest *GCNotifier::first_request = NULL;
41 41 GCNotificationRequest *GCNotifier::last_request = NULL;
42 42
43 43 void GCNotifier::pushNotification(GCMemoryManager *mgr, const char *action, const char *cause) {
44 44 // Make a copy of the last GC statistics
45 45 // GC may occur between now and the creation of the notification
46 46 int num_pools = MemoryService::num_memory_pools();
47 47 GCStatInfo* stat = new GCStatInfo(num_pools);
48 48 mgr->get_last_gc_stat(stat);
49 49 GCNotificationRequest *request = new GCNotificationRequest(os::javaTimeMillis(),mgr,action,cause,stat);
50 50 addRequest(request);
51 51 }
52 52
53 53 void GCNotifier::addRequest(GCNotificationRequest *request) {
54 54 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
55 55 if(first_request == NULL) {
56 56 first_request = request;
57 57 } else {
58 58 last_request->next = request;
59 59 }
60 60 last_request = request;
61 61 Service_lock->notify_all();
62 62 }
63 63
64 64 GCNotificationRequest *GCNotifier::getRequest() {
65 65 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
66 66 GCNotificationRequest *request = first_request;
67 67 if(first_request != NULL) {
68 68 first_request = first_request->next;
69 69 }
70 70 return request;
71 71 }
72 72
73 73 bool GCNotifier::has_event() {
74 74 return first_request != NULL;
75 75 }
76 76
77 77 static Handle getGcInfoBuilder(GCMemoryManager *gcManager,TRAPS) {
78 78
79 79 klassOop k = Management::sun_management_GarbageCollectorImpl_klass(CHECK_NH);
80 80 instanceKlassHandle gcMBeanKlass (THREAD, k);
81 81
82 82 instanceOop i = gcManager->get_memory_manager_instance(THREAD);
83 83 instanceHandle ih(THREAD, i);
84 84
85 85 JavaValue result(T_OBJECT);
86 86 JavaCallArguments args(ih);
87 87
88 88 JavaCalls::call_virtual(&result,
89 89 gcMBeanKlass,
90 90 vmSymbols::getGcInfoBuilder_name(),
91 91 vmSymbols::getGcInfoBuilder_signature(),
92 92 &args,
↓ open down ↓ |
92 lines elided |
↑ open up ↑ |
93 93 CHECK_NH);
94 94 return Handle(THREAD,(oop)result.get_jobject());
95 95
96 96 }
97 97
98 98 static Handle createGcInfo(GCMemoryManager *gcManager, GCStatInfo *gcStatInfo,TRAPS) {
99 99
100 100 // Fill the arrays of MemoryUsage objects with before and after GC
101 101 // per pool memory usage
102 102
103 - klassOop muKlass = Management::java_lang_management_MemoryUsage_klass(CHECK_NH); objArrayOop bu = oopFactory::new_objArray( muKlass,MemoryService::num_memory_pools(), CHECK_NH);
103 + klassOop mu_klass = Management::java_lang_management_MemoryUsage_klass(CHECK_NH);
104 + instanceKlassHandle mu_kh(THREAD, mu_klass);
105 +
106 + // The array allocations should use a handle containing mu_klass
107 + // as the first allocation could trigger a GC, causing the actual
108 + // klass oop to move, and leaving mu_klass pointing to the old
109 + // location.
110 + objArrayOop bu = oopFactory::new_objArray(mu_kh(), MemoryService::num_memory_pools(), CHECK_NH);
104 111 objArrayHandle usage_before_gc_ah(THREAD, bu);
105 - objArrayOop au = oopFactory::new_objArray(muKlass,MemoryService::num_memory_pools(), CHECK_NH);
112 + objArrayOop au = oopFactory::new_objArray(mu_kh(), MemoryService::num_memory_pools(), CHECK_NH);
106 113 objArrayHandle usage_after_gc_ah(THREAD, au);
107 114
108 115 for (int i = 0; i < MemoryService::num_memory_pools(); i++) {
109 116 Handle before_usage = MemoryService::create_MemoryUsage_obj(gcStatInfo->before_gc_usage_for_pool(i), CHECK_NH);
110 117 Handle after_usage;
111 118
112 119 MemoryUsage u = gcStatInfo->after_gc_usage_for_pool(i);
113 120 if (u.max_size() == 0 && u.used() > 0) {
114 121 // If max size == 0, this pool is a survivor space.
115 122 // Set max size = -1 since the pools will be swapped after GC.
116 123 MemoryUsage usage(u.init_size(), u.used(), u.committed(), (size_t)-1);
117 124 after_usage = MemoryService::create_MemoryUsage_obj(usage, CHECK_NH);
118 125 } else {
119 126 after_usage = MemoryService::create_MemoryUsage_obj(u, CHECK_NH);
120 127 }
121 128 usage_before_gc_ah->obj_at_put(i, before_usage());
122 129 usage_after_gc_ah->obj_at_put(i, after_usage());
123 130 }
124 131
125 132 // Current implementation only has 1 attribute (number of GC threads)
126 133 // The type is 'I'
127 134 objArrayOop extra_args_array = oopFactory::new_objArray(SystemDictionary::Integer_klass(), 1, CHECK_NH);
128 135 objArrayHandle extra_array (THREAD, extra_args_array);
129 136 klassOop itKlass= SystemDictionary::Integer_klass();
130 137 instanceKlassHandle intK(THREAD, itKlass);
131 138
132 139 instanceHandle extra_arg_val = intK->allocate_instance_handle(CHECK_NH);
133 140
134 141 {
135 142 JavaValue res(T_VOID);
136 143 JavaCallArguments argsInt;
137 144 argsInt.push_oop(extra_arg_val);
138 145 argsInt.push_int(gcManager->num_gc_threads());
139 146
140 147 JavaCalls::call_special(&res,
141 148 intK,
142 149 vmSymbols::object_initializer_name(),
143 150 vmSymbols::int_void_signature(),
144 151 &argsInt,
145 152 CHECK_NH);
146 153 }
147 154 extra_array->obj_at_put(0,extra_arg_val());
148 155
149 156 klassOop gcInfoklass = Management::com_sun_management_GcInfo_klass(CHECK_NH);
150 157 instanceKlassHandle ik (THREAD,gcInfoklass);
151 158
152 159 Handle gcInfo_instance = ik->allocate_instance_handle(CHECK_NH);
153 160
154 161 JavaValue constructor_result(T_VOID);
155 162 JavaCallArguments constructor_args(16);
156 163 constructor_args.push_oop(gcInfo_instance);
157 164 constructor_args.push_oop(getGcInfoBuilder(gcManager,THREAD));
158 165 constructor_args.push_long(gcStatInfo->gc_index());
159 166 constructor_args.push_long(gcStatInfo->start_time());
160 167 constructor_args.push_long(gcStatInfo->end_time());
161 168 constructor_args.push_oop(usage_before_gc_ah);
162 169 constructor_args.push_oop(usage_after_gc_ah);
163 170 constructor_args.push_oop(extra_array);
164 171
165 172 JavaCalls::call_special(&constructor_result,
166 173 ik,
167 174 vmSymbols::object_initializer_name(),
168 175 vmSymbols::com_sun_management_GcInfo_constructor_signature(),
169 176 &constructor_args,
170 177 CHECK_NH);
171 178
172 179 return Handle(gcInfo_instance());
173 180 }
174 181
175 182 void GCNotifier::sendNotification(TRAPS) {
176 183 ResourceMark rm(THREAD);
177 184 GCNotificationRequest *request = getRequest();
178 185 if(request != NULL) {
179 186 Handle objGcInfo = createGcInfo(request->gcManager,request->gcStatInfo,THREAD);
180 187
181 188 Handle objName = java_lang_String::create_from_platform_dependent_str(request->gcManager->name(), CHECK);
182 189 Handle objAction = java_lang_String::create_from_platform_dependent_str(request->gcAction, CHECK);
183 190 Handle objCause = java_lang_String::create_from_platform_dependent_str(request->gcCause, CHECK);
184 191
185 192 klassOop k = Management::sun_management_GarbageCollectorImpl_klass(CHECK);
186 193 instanceKlassHandle gc_mbean_klass (THREAD, k);
187 194
188 195 instanceOop gc_mbean = request->gcManager->get_memory_manager_instance(THREAD);
189 196 instanceHandle gc_mbean_h(THREAD, gc_mbean);
190 197 if (!gc_mbean_h->is_a(k)) {
191 198 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
192 199 "This GCMemoryManager doesn't have a GarbageCollectorMXBean");
193 200 }
194 201
195 202 JavaValue result(T_VOID);
196 203 JavaCallArguments args(gc_mbean_h);
197 204 args.push_long(request->timestamp);
198 205 args.push_oop(objName);
199 206 args.push_oop(objAction);
200 207 args.push_oop(objCause);
201 208 args.push_oop(objGcInfo);
202 209
203 210 JavaCalls::call_virtual(&result,
204 211 gc_mbean_klass,
205 212 vmSymbols::createGCNotification_name(),
206 213 vmSymbols::createGCNotification_signature(),
207 214 &args,
208 215 CHECK);
209 216 if (HAS_PENDING_EXCEPTION) {
210 217 CLEAR_PENDING_EXCEPTION;
211 218 }
212 219
213 220 delete request;
214 221 }
215 222 }
216 223
↓ open down ↓ |
101 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX