forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hybrid Java buffer release: Support both manual and auto release at t…
…he same time (apache#34) * Revert "Add AutoBufferLedger (apache#31)" This reverts commit e48da37. * Commit 1 * Commit 2 * Fix config builder visibility in Scala * Commit 2 Fixup * Commit 3 * Commit 3 Fixup
- Loading branch information
1 parent
587a920
commit b57e5e4
Showing
42 changed files
with
2,228 additions
and
1,673 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeUnderlyingMemory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.arrow.dataset.jni; | ||
|
||
import org.apache.arrow.memory.*; | ||
|
||
/** | ||
* MemoryChunkManager implementation for native allocated memory. | ||
*/ | ||
public class NativeUnderlyingMemory implements MemoryChunk { | ||
|
||
private final int size; | ||
private final long nativeInstanceId; | ||
private final long address; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param size Size of underlying memory (in bytes) | ||
* @param nativeInstanceId ID of the native instance | ||
* @param address Address of underlying memory | ||
*/ | ||
NativeUnderlyingMemory(int size, long nativeInstanceId, long address) { | ||
this.size = size; | ||
this.nativeInstanceId = nativeInstanceId; | ||
this.address = address; | ||
} | ||
|
||
@Override | ||
public long size() { | ||
return size; | ||
} | ||
|
||
@Override | ||
public long memoryAddress() { | ||
return address; | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
JniWrapper.get().releaseBuffer(nativeInstanceId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +0,0 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.arrow.memory; | ||
|
||
import org.apache.arrow.dataset.jni.JniWrapper; | ||
|
||
/** | ||
* AllocationManager implementation for native allocated memory. | ||
*/ | ||
public class NativeUnderlyingMemory extends AllocationManager { | ||
|
||
private final int size; | ||
private final long nativeInstanceId; | ||
private final long address; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param accountingAllocator The accounting allocator instance | ||
* @param size Size of underlying memory (in bytes) | ||
* @param nativeInstanceId ID of the native instance | ||
*/ | ||
public NativeUnderlyingMemory(BufferAllocator accountingAllocator, int size, long nativeInstanceId, long address) { | ||
super(accountingAllocator); | ||
this.size = size; | ||
this.nativeInstanceId = nativeInstanceId; | ||
this.address = address; | ||
// pre-allocate bytes on accounting allocator | ||
final AllocationListener listener = accountingAllocator.getListener(); | ||
try (final AllocationReservation reservation = accountingAllocator.newReservation()) { | ||
listener.onPreAllocation(size); | ||
reservation.reserve(size); | ||
listener.onAllocation(size); | ||
} catch (Exception e) { | ||
release0(); | ||
throw e; | ||
} | ||
} | ||
|
||
/** | ||
* Alias to constructor. | ||
*/ | ||
public static NativeUnderlyingMemory create(BufferAllocator bufferAllocator, int size, long nativeInstanceId, | ||
long address) { | ||
return new NativeUnderlyingMemory(bufferAllocator, size, nativeInstanceId, address); | ||
} | ||
|
||
public ReferenceManager createReferenceManager(BufferAllocator allocator) { | ||
return super.associate(allocator).newReferenceManager(); | ||
} | ||
|
||
@Override | ||
protected void release0() { | ||
JniWrapper.get().releaseBuffer(nativeInstanceId); | ||
} | ||
|
||
@Override | ||
public long getSize() { | ||
return size; | ||
} | ||
|
||
@Override | ||
protected long memoryAddress() { | ||
return address; | ||
} | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.