1.1 --- a/src/share/vm/services/gcNotifier.cpp Mon Feb 13 12:30:47 2012 -0500 1.2 +++ b/src/share/vm/services/gcNotifier.cpp Tue Feb 14 06:54:27 2012 -0800 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -180,17 +180,43 @@ 1.11 } 1.12 1.13 void GCNotifier::sendNotification(TRAPS) { 1.14 + GCNotifier::sendNotificationInternal(THREAD); 1.15 + // Clearing pending exception to avoid premature termination of 1.16 + // the service thread 1.17 + if (HAS_PENDING_EXCEPTION) { 1.18 + CLEAR_PENDING_EXCEPTION; 1.19 + } 1.20 +} 1.21 + 1.22 +class NotificationMark : public StackObj { 1.23 + // This class is used in GCNotifier::sendNotificationInternal to ensure that 1.24 + // the GCNotificationRequest object is properly cleaned up, whatever path 1.25 + // is used to exit the method. 1.26 + GCNotificationRequest* _request; 1.27 +public: 1.28 + NotificationMark(GCNotificationRequest* r) { 1.29 + _request = r; 1.30 + } 1.31 + ~NotificationMark() { 1.32 + assert(_request != NULL, "Sanity check"); 1.33 + delete _request; 1.34 + } 1.35 +}; 1.36 + 1.37 +void GCNotifier::sendNotificationInternal(TRAPS) { 1.38 ResourceMark rm(THREAD); 1.39 + HandleMark hm(THREAD); 1.40 GCNotificationRequest *request = getRequest(); 1.41 - if(request != NULL) { 1.42 - Handle objGcInfo = createGcInfo(request->gcManager,request->gcStatInfo,THREAD); 1.43 + if (request != NULL) { 1.44 + NotificationMark nm(request); 1.45 + Handle objGcInfo = createGcInfo(request->gcManager, request->gcStatInfo, THREAD); 1.46 1.47 Handle objName = java_lang_String::create_from_platform_dependent_str(request->gcManager->name(), CHECK); 1.48 Handle objAction = java_lang_String::create_from_platform_dependent_str(request->gcAction, CHECK); 1.49 Handle objCause = java_lang_String::create_from_platform_dependent_str(request->gcCause, CHECK); 1.50 1.51 klassOop k = Management::sun_management_GarbageCollectorImpl_klass(CHECK); 1.52 - instanceKlassHandle gc_mbean_klass (THREAD, k); 1.53 + instanceKlassHandle gc_mbean_klass(THREAD, k); 1.54 1.55 instanceOop gc_mbean = request->gcManager->get_memory_manager_instance(THREAD); 1.56 instanceHandle gc_mbean_h(THREAD, gc_mbean); 1.57 @@ -213,11 +239,6 @@ 1.58 vmSymbols::createGCNotification_signature(), 1.59 &args, 1.60 CHECK); 1.61 - if (HAS_PENDING_EXCEPTION) { 1.62 - CLEAR_PENDING_EXCEPTION; 1.63 - } 1.64 - 1.65 - delete request; 1.66 } 1.67 } 1.68