This is an automated email from the ASF dual-hosted git repository.

hongze pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-gluten.git


The following commit(s) were added to refs/heads/main by this push:
     new 66417bf317 [VL] Add additional logging for unclosed objects when the 
native runtime is being destroyed (#9455)
66417bf317 is described below

commit 66417bf31773fbd920dd29d325299c9895957c2c
Author: Hongze Zhang <[email protected]>
AuthorDate: Wed Apr 30 14:22:52 2025 +0100

    [VL] Add additional logging for unclosed objects when the native runtime is 
being destroyed (#9455)
---
 cpp/core/utils/ObjectStore.cc | 16 ++++++++--------
 cpp/core/utils/ObjectStore.h  | 14 +++++++++++---
 2 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/cpp/core/utils/ObjectStore.cc b/cpp/core/utils/ObjectStore.cc
index 3eec544773..15254cccf7 100644
--- a/cpp/core/utils/ObjectStore.cc
+++ b/cpp/core/utils/ObjectStore.cc
@@ -29,19 +29,19 @@ gluten::ObjectStore::~ObjectStore() {
   // destructing in reversed order (the last added object destructed first)
   const std::lock_guard<std::mutex> lock(mtx_);
   for (auto itr = aliveObjects_.rbegin(); itr != aliveObjects_.rend(); itr++) {
-    ResourceHandle handle = *itr;
+    const ResourceHandle handle = (*itr).first;
+    const std::string_view description = (*itr).second;
+    VLOG(2) << "Unclosed object ["
+            << "Store ID: " << storeId_ << ", Resource handle ID: " << handle 
<< ", Description: " << description
+            << "] is found when object store is closing. Gluten will"
+               " destroy it automatically but it's recommended to manually 
close"
+               " the object through the Java closing API after use,"
+               " to minimize peak memory pressure of the application.";
     store_.erase(handle);
   }
   stores().erase(storeId_);
 }
 
-gluten::ObjectHandle gluten::ObjectStore::save(std::shared_ptr<void> obj) {
-  const std::lock_guard<std::mutex> lock(mtx_);
-  ResourceHandle handle = store_.insert(std::move(obj));
-  aliveObjects_.insert(handle);
-  return toObjHandle(handle);
-}
-
 void gluten::ObjectStore::releaseInternal(gluten::ResourceHandle handle) {
   const std::lock_guard<std::mutex> lock(mtx_);
   store_.erase(handle);
diff --git a/cpp/core/utils/ObjectStore.h b/cpp/core/utils/ObjectStore.h
index 03d1a470fd..e752c88e7f 100644
--- a/cpp/core/utils/ObjectStore.h
+++ b/cpp/core/utils/ObjectStore.h
@@ -17,7 +17,7 @@
 
 #pragma once
 
-#include <set>
+#include <map>
 #include "utils/ResourceMap.h"
 
 namespace gluten {
@@ -70,7 +70,14 @@ class ObjectStore {
     return storeId_;
   }
 
-  ObjectHandle save(std::shared_ptr<void> obj);
+  template <typename T>
+  ObjectHandle save(std::shared_ptr<T> obj) {
+    const std::lock_guard<std::mutex> lock(mtx_);
+    const std::string_view description = typeid(T).name();
+    ResourceHandle handle = store_.insert(std::move(obj));
+    aliveObjects_.emplace(handle, description);
+    return toObjHandle(handle);
+  }
 
  private:
   static ResourceMap<ObjectStore*>& stores();
@@ -95,7 +102,8 @@ class ObjectStore {
   ObjectStore(StoreHandle storeId) : storeId_(storeId){};
   StoreHandle storeId_;
   ResourceMap<std::shared_ptr<void>> store_;
-  std::set<ResourceHandle> aliveObjects_;
+  // Preserves handles of objects in the store in order, with the text 
descriptions associated with them.
+  std::map<ResourceHandle, std::string_view> aliveObjects_{};
   std::mutex mtx_;
 };
 } // namespace gluten


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to