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 7777a8d7cd [VL] Support ObjectDebugInfo in ObjectStore during 
destruction of native runtime (#9477)
7777a8d7cd is described below

commit 7777a8d7cd6a641925fb863da600cae7ba610d64
Author: Arnav Balyan <[email protected]>
AuthorDate: Fri May 2 00:59:50 2025 +0530

    [VL] Support ObjectDebugInfo in ObjectStore during destruction of native 
runtime (#9477)
---
 cpp/core/utils/ObjectStore.cc |  7 +++++--
 cpp/core/utils/ObjectStore.h  | 24 ++++++++++++++++++++----
 2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/cpp/core/utils/ObjectStore.cc b/cpp/core/utils/ObjectStore.cc
index 15254cccf7..e516566e85 100644
--- a/cpp/core/utils/ObjectStore.cc
+++ b/cpp/core/utils/ObjectStore.cc
@@ -30,9 +30,12 @@ gluten::ObjectStore::~ObjectStore() {
   const std::lock_guard<std::mutex> lock(mtx_);
   for (auto itr = aliveObjects_.rbegin(); itr != aliveObjects_.rend(); itr++) {
     const ResourceHandle handle = (*itr).first;
-    const std::string_view description = (*itr).second;
+    const auto& info = (*itr).second;
+    const std::string_view typeName = info.typeName;
+    const size_t size = info.size;
     VLOG(2) << "Unclosed object ["
-            << "Store ID: " << storeId_ << ", Resource handle ID: " << handle 
<< ", Description: " << description
+            << "Store ID: " << storeId_ << ", Resource handle ID: " << handle 
<< ", TypeName: " << typeName
+            << ", Size: " << size
             << "] 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,"
diff --git a/cpp/core/utils/ObjectStore.h b/cpp/core/utils/ObjectStore.h
index e752c88e7f..e4cd3f8acc 100644
--- a/cpp/core/utils/ObjectStore.h
+++ b/cpp/core/utils/ObjectStore.h
@@ -34,6 +34,16 @@ using StoreHandle = int32_t;
 using ObjectHandle = int64_t;
 constexpr static ObjectHandle kInvalidObjectHandle = -1;
 
+template <typename T>
+struct SafeSizeOf {
+  static constexpr size_t value = sizeof(T);
+};
+
+template <>
+struct SafeSizeOf<void> {
+  static constexpr size_t value = 0;
+};
+
 // A store for caching shared-ptrs and enlarging lifecycles of the ptrs to 
match lifecycle of the store itself by
 // default, and also serving release calls to release a ptr in advance. This 
is typically used in JNI scenario to bind
 // a shared-ptr's lifecycle to a Java-side object or some kind of resource 
manager.
@@ -73,15 +83,21 @@ class ObjectStore {
   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();
+    const std::string_view typeName = typeid(T).name();
+    const size_t size = SafeSizeOf<T>::value;
     ResourceHandle handle = store_.insert(std::move(obj));
-    aliveObjects_.emplace(handle, description);
+    aliveObjects_.emplace(handle, ObjectDebugInfo{typeName, size});
     return toObjHandle(handle);
   }
 
  private:
   static ResourceMap<ObjectStore*>& stores();
 
+  struct ObjectDebugInfo {
+    const std::string_view typeName;
+    const size_t size;
+  };
+
   ObjectHandle toObjHandle(ResourceHandle rh) {
     ObjectHandle prefix = static_cast<ObjectHandle>(storeId_) << 
(sizeof(ResourceHandle) * 8);
     ObjectHandle objHandle = prefix + rh;
@@ -102,8 +118,8 @@ class ObjectStore {
   ObjectStore(StoreHandle storeId) : storeId_(storeId){};
   StoreHandle storeId_;
   ResourceMap<std::shared_ptr<void>> store_;
-  // Preserves handles of objects in the store in order, with the text 
descriptions associated with them.
-  std::map<ResourceHandle, std::string_view> aliveObjects_{};
+  // Preserves handles of objects in the store in order, with additional 
attributes associated with them.
+  std::map<ResourceHandle, ObjectDebugInfo> aliveObjects_{};
   std::mutex mtx_;
 };
 } // namespace gluten


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

Reply via email to