7143760: Memory leak in GarbageCollectionNotifications

Reviewed-by: dholmes, dcubed, kamg
This commit is contained in:
Frederic Parain 2012-02-14 06:54:27 -08:00
parent cfdca5342c
commit 476ee44449
2 changed files with 32 additions and 10 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -180,9 +180,35 @@ static Handle createGcInfo(GCMemoryManager *gcManager, GCStatInfo *gcStatInfo,TR
} }
void GCNotifier::sendNotification(TRAPS) { void GCNotifier::sendNotification(TRAPS) {
GCNotifier::sendNotificationInternal(THREAD);
// Clearing pending exception to avoid premature termination of
// the service thread
if (HAS_PENDING_EXCEPTION) {
CLEAR_PENDING_EXCEPTION;
}
}
class NotificationMark : public StackObj {
// This class is used in GCNotifier::sendNotificationInternal to ensure that
// the GCNotificationRequest object is properly cleaned up, whatever path
// is used to exit the method.
GCNotificationRequest* _request;
public:
NotificationMark(GCNotificationRequest* r) {
_request = r;
}
~NotificationMark() {
assert(_request != NULL, "Sanity check");
delete _request;
}
};
void GCNotifier::sendNotificationInternal(TRAPS) {
ResourceMark rm(THREAD); ResourceMark rm(THREAD);
HandleMark hm(THREAD);
GCNotificationRequest *request = getRequest(); GCNotificationRequest *request = getRequest();
if (request != NULL) { if (request != NULL) {
NotificationMark nm(request);
Handle objGcInfo = createGcInfo(request->gcManager, request->gcStatInfo, THREAD); Handle objGcInfo = createGcInfo(request->gcManager, request->gcStatInfo, THREAD);
Handle objName = java_lang_String::create_from_platform_dependent_str(request->gcManager->name(), CHECK); Handle objName = java_lang_String::create_from_platform_dependent_str(request->gcManager->name(), CHECK);
@ -213,11 +239,6 @@ void GCNotifier::sendNotification(TRAPS) {
vmSymbols::createGCNotification_signature(), vmSymbols::createGCNotification_signature(),
&args, &args,
CHECK); CHECK);
if (HAS_PENDING_EXCEPTION) {
CLEAR_PENDING_EXCEPTION;
}
delete request;
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -60,6 +60,7 @@ private:
static GCNotificationRequest *last_request; static GCNotificationRequest *last_request;
static void addRequest(GCNotificationRequest *request); static void addRequest(GCNotificationRequest *request);
static GCNotificationRequest *getRequest(); static GCNotificationRequest *getRequest();
static void sendNotificationInternal(TRAPS);
public: public:
static void pushNotification(GCMemoryManager *manager, const char *action, const char *cause); static void pushNotification(GCMemoryManager *manager, const char *action, const char *cause);
static bool has_event(); static bool has_event();