Mercurial > hg > graal-compiler
comparison src/share/vm/services/gcNotifier.cpp @ 4922:1891640ca63f
7143760: Memory leak in GarbageCollectionNotifications
Reviewed-by: dholmes, dcubed, kamg
author | fparain |
---|---|
date | Tue, 14 Feb 2012 06:54:27 -0800 |
parents | bf864f701a4a |
children | 9a5bef0481c8 |
comparison
equal
deleted
inserted
replaced
4921:849412a95e45 | 4922:1891640ca63f |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 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 | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
178 | 178 |
179 return Handle(gcInfo_instance()); | 179 return Handle(gcInfo_instance()); |
180 } | 180 } |
181 | 181 |
182 void GCNotifier::sendNotification(TRAPS) { | 182 void GCNotifier::sendNotification(TRAPS) { |
183 GCNotifier::sendNotificationInternal(THREAD); | |
184 // Clearing pending exception to avoid premature termination of | |
185 // the service thread | |
186 if (HAS_PENDING_EXCEPTION) { | |
187 CLEAR_PENDING_EXCEPTION; | |
188 } | |
189 } | |
190 | |
191 class NotificationMark : public StackObj { | |
192 // This class is used in GCNotifier::sendNotificationInternal to ensure that | |
193 // the GCNotificationRequest object is properly cleaned up, whatever path | |
194 // is used to exit the method. | |
195 GCNotificationRequest* _request; | |
196 public: | |
197 NotificationMark(GCNotificationRequest* r) { | |
198 _request = r; | |
199 } | |
200 ~NotificationMark() { | |
201 assert(_request != NULL, "Sanity check"); | |
202 delete _request; | |
203 } | |
204 }; | |
205 | |
206 void GCNotifier::sendNotificationInternal(TRAPS) { | |
183 ResourceMark rm(THREAD); | 207 ResourceMark rm(THREAD); |
208 HandleMark hm(THREAD); | |
184 GCNotificationRequest *request = getRequest(); | 209 GCNotificationRequest *request = getRequest(); |
185 if(request != NULL) { | 210 if (request != NULL) { |
186 Handle objGcInfo = createGcInfo(request->gcManager,request->gcStatInfo,THREAD); | 211 NotificationMark nm(request); |
212 Handle objGcInfo = createGcInfo(request->gcManager, request->gcStatInfo, THREAD); | |
187 | 213 |
188 Handle objName = java_lang_String::create_from_platform_dependent_str(request->gcManager->name(), CHECK); | 214 Handle objName = java_lang_String::create_from_platform_dependent_str(request->gcManager->name(), CHECK); |
189 Handle objAction = java_lang_String::create_from_platform_dependent_str(request->gcAction, CHECK); | 215 Handle objAction = java_lang_String::create_from_platform_dependent_str(request->gcAction, CHECK); |
190 Handle objCause = java_lang_String::create_from_platform_dependent_str(request->gcCause, CHECK); | 216 Handle objCause = java_lang_String::create_from_platform_dependent_str(request->gcCause, CHECK); |
191 | 217 |
192 klassOop k = Management::sun_management_GarbageCollectorImpl_klass(CHECK); | 218 klassOop k = Management::sun_management_GarbageCollectorImpl_klass(CHECK); |
193 instanceKlassHandle gc_mbean_klass (THREAD, k); | 219 instanceKlassHandle gc_mbean_klass(THREAD, k); |
194 | 220 |
195 instanceOop gc_mbean = request->gcManager->get_memory_manager_instance(THREAD); | 221 instanceOop gc_mbean = request->gcManager->get_memory_manager_instance(THREAD); |
196 instanceHandle gc_mbean_h(THREAD, gc_mbean); | 222 instanceHandle gc_mbean_h(THREAD, gc_mbean); |
197 if (!gc_mbean_h->is_a(k)) { | 223 if (!gc_mbean_h->is_a(k)) { |
198 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), | 224 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
211 gc_mbean_klass, | 237 gc_mbean_klass, |
212 vmSymbols::createGCNotification_name(), | 238 vmSymbols::createGCNotification_name(), |
213 vmSymbols::createGCNotification_signature(), | 239 vmSymbols::createGCNotification_signature(), |
214 &args, | 240 &args, |
215 CHECK); | 241 CHECK); |
216 if (HAS_PENDING_EXCEPTION) { | 242 } |
217 CLEAR_PENDING_EXCEPTION; | 243 } |
218 } | 244 |
219 | |
220 delete request; | |
221 } | |
222 } | |
223 |