You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "lidavidm (via GitHub)" <gi...@apache.org> on 2023/06/29 12:14:51 UTC

[GitHub] [arrow] lidavidm commented on a diff in pull request #36185: GH-35960: [Java] Detect overflow in allocation

lidavidm commented on code in PR #36185:
URL: https://github.com/apache/arrow/pull/36185#discussion_r1246538317


##########
java/memory/memory-core/src/main/java/org/apache/arrow/memory/Accountant.java:
##########
@@ -169,9 +169,14 @@ public boolean forceAllocate(long size) {
    */
   private AllocationOutcome.Status allocate(final long size, final boolean incomingUpdatePeak,
       final boolean forceAllocation, AllocationOutcomeDetails details) {
-    final long newLocal = locallyHeldMemory.addAndGet(size);
+    final long oldLocal = locallyHeldMemory.getAndAdd(size);
+    final long newLocal = oldLocal + size;
+    // Borrowed from Math.addExact (but avoid exception here)

Review Comment:
   Exception handlers may have a performance penalty (even if not invoked), and this code is meant to be fast.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org