Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][JNI] Trigger MemoryBuffer.onClosed after memory is freed #15351

Merged
merged 3 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 13 additions & 10 deletions java/src/main/java/ai/rapids/cudf/ColumnVector.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2019-2023, NVIDIA CORPORATION.
* Copyright (c) 2019-2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -260,15 +260,18 @@ public void noWarnLeakExpected() {
public synchronized void close() {
refCount--;
offHeap.delRef();
if (eventHandler != null) {
eventHandler.onClosed(this, refCount);
}
if (refCount == 0) {
super.close();
offHeap.clean(false);
} else if (refCount < 0) {
offHeap.logRefCountDebug("double free " + this);
throw new IllegalStateException("Close called too many times " + this);
try {
if (refCount == 0) {
super.close();
offHeap.clean(false);
} else if (refCount < 0) {
offHeap.logRefCountDebug("double free " + this);
throw new IllegalStateException("Close called too many times " + this);
}
} finally {
if (eventHandler != null) {
eventHandler.onClosed(this, refCount);
}
}
}

Expand Down
23 changes: 13 additions & 10 deletions java/src/main/java/ai/rapids/cudf/HostColumnVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,20 @@ public void noWarnLeakExpected() {
public synchronized void close() {
refCount--;
offHeap.delRef();
if (eventHandler != null) {
eventHandler.onClosed(this, refCount);
}
if (refCount == 0) {
offHeap.clean(false);
for( HostColumnVectorCore child : children) {
child.close();
try {
if (refCount == 0) {
offHeap.clean(false);
for (HostColumnVectorCore child : children) {
child.close();
}
} else if (refCount < 0) {
offHeap.logRefCountDebug("double free " + this);
throw new IllegalStateException("Close called too many times " + this);
}
} finally {
if (eventHandler != null) {
eventHandler.onClosed(this, refCount);
}
} else if (refCount < 0) {
offHeap.logRefCountDebug("double free " + this);
throw new IllegalStateException("Close called too many times " + this);
}
}

Expand Down
23 changes: 13 additions & 10 deletions java/src/main/java/ai/rapids/cudf/MemoryBuffer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2019-2022, NVIDIA CORPORATION.
* Copyright (c) 2019-2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -240,15 +240,18 @@ public synchronized void close() {
if (cleaner != null) {
refCount--;
cleaner.delRef();
if (eventHandler != null) {
eventHandler.onClosed(refCount);
}
if (refCount == 0) {
cleaner.clean(false);
closed = true;
} else if (refCount < 0) {
cleaner.logRefCountDebug("double free " + this);
throw new IllegalStateException("Close called too many times " + this);
try {
if (refCount == 0) {
cleaner.clean(false);
closed = true;
} else if (refCount < 0) {
cleaner.logRefCountDebug("double free " + this);
throw new IllegalStateException("Close called too many times " + this);
}
} finally {
if (eventHandler != null) {
eventHandler.onClosed(refCount);
}
}
abellina marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand Down