@@ -1054,6 +1054,7 @@ JNIEXPORT jlong JNICALL Java_org_apache_gluten_vectorized_HashJoinBuilder_native
10541054 builder->dropDuplicates (),
10551055 nullptr );
10561056 builder->setHashTable (std::move (mainTable));
1057+ builder->setHashTableMemoryUsage (builder->hashTable ()->allocatedBytes ());
10571058
10581059 auto * cache = facebook::velox::exec::HashTableCache::instance ();
10591060
@@ -1122,6 +1123,10 @@ JNIEXPORT jlong JNICALL Java_org_apache_gluten_vectorized_HashJoinBuilder_native
11221123 for (int i = 1 ; i < numThreads; ++i) {
11231124 tables.push_back (std::move (otherTables[i]));
11241125 }
1126+ int64_t otherTablesMemoryUsage = 0 ;
1127+ for (const auto & table : tables) {
1128+ otherTablesMemoryUsage += table->allocatedBytes ();
1129+ }
11251130
11261131 // TODO: Get accurate signal if parallel join build is going to be applied
11271132 // from hash table. Currently there is still a chance inside hash table that
@@ -1143,6 +1148,8 @@ JNIEXPORT jlong JNICALL Java_org_apache_gluten_vectorized_HashJoinBuilder_native
11431148 }
11441149
11451150 hashTableBuilders[0 ]->setHashTable (std::move (mainTable));
1151+ hashTableBuilders[0 ]->setHashTableMemoryUsage (
1152+ hashTableBuilders[0 ]->hashTable ()->allocatedBytes () + otherTablesMemoryUsage);
11461153
11471154 auto * cache = facebook::velox::exec::HashTableCache::instance ();
11481155 if (!cache->exist (hashTableId)) {
@@ -1260,6 +1267,16 @@ Java_org_apache_gluten_vectorized_HashJoinBuilder_getHashTableBloomFilterBlocksB
12601267 JNI_METHOD_END (0L )
12611268}
12621269
1270+ JNIEXPORT jlong JNICALL Java_org_apache_gluten_vectorized_HashJoinBuilder_getHashTableMemoryUsage ( // NOLINT
1271+ JNIEnv* env,
1272+ jclass,
1273+ jlong hashTableHandle) {
1274+ JNI_METHOD_START
1275+ auto builder = ObjectStore::retrieve<gluten::HashTableBuilder>(hashTableHandle);
1276+ return static_cast <jlong>(gluten::hashTableMemoryUsage (builder));
1277+ JNI_METHOD_END (0L )
1278+ }
1279+
12631280JNIEXPORT jlong JNICALL Java_org_apache_gluten_vectorized_HashJoinBuilder_serializedHashTableSizeDirect ( // NOLINT
12641281 JNIEnv* env,
12651282 jclass,
0 commit comments