cloud-fan commented on code in PR #52817:
URL: https://github.com/apache/spark/pull/52817#discussion_r2555447358


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/joins/HashedRelation.scala:
##########
@@ -816,35 +809,34 @@ private[execution] final class LongToUnsafeRowMap(
     } else {
       // there are some values for this key, put the address in the front of 
them.
       val pointer = toOffset(address) + toSize(address)
-      Platform.putLong(page, pointer, array(pos + 1))
+      Platform.putLong(page.getBaseObject, page.getBaseOffset + pointer, 
array(pos + 1))
       array(pos + 1) = address
     }
   }
 
   private def grow(inputRowSize: Int): Unit = {
     // There is 8 bytes for the pointer to next value
-    val neededNumWords = (cursor - Platform.LONG_ARRAY_OFFSET + 8 + 
inputRowSize + 7) / 8
-    if (neededNumWords > page.length) {
+    val usedBytes = cursor - page.getBaseOffset
+    val neededNumWords = (usedBytes + 8 + inputRowSize + 7) / 8
+    if (neededNumWords > page.size() / 8) {
       if (neededNumWords > (1 << 30)) {
         throw QueryExecutionErrors.cannotBuildHashedRelationLargerThan8GError()
       }
-      val newNumWords = math.max(neededNumWords, math.min(page.length * 2, 1 
<< 30))
-      ensureAcquireMemory(newNumWords * 8L)
-      val newPage = new Array[Long](newNumWords.toInt)
-      Platform.copyMemory(page, Platform.LONG_ARRAY_OFFSET, newPage, 
Platform.LONG_ARRAY_OFFSET,
-        cursor - Platform.LONG_ARRAY_OFFSET)
-      val used = page.length
+      val newNumWords = math.max(neededNumWords, math.min(page.size() / 8 * 2, 
1 << 30))
+      val newPage = allocatePage(newNumWords.toInt * 8)
+      Platform.copyMemory(page.getBaseObject, page.getBaseOffset, 
newPage.getBaseObject,
+        newPage.getBaseOffset, usedBytes)
+      freePage(page)
       page = newPage
-      freeMemory(used * 8L)
+      cursor = page.getBaseOffset + usedBytes
     }
   }
 
   private def growArray(): Unit = {
     var old_array = array
     val n = array.length
     numKeys = 0
-    ensureAcquireMemory(n * 2 * 8L)
-    array = new Array[Long](n * 2)
+    array = new UnsafeLongArray(n * 2)

Review Comment:
   Does `UnsafeLongArray` allocate memory from the memory manager?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to