-
Notifications
You must be signed in to change notification settings - Fork 4k
GH-37739: [Java] Add experimental arrow-memory-ffm module #38016
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ecae6f1
Add experimental arrow-memory-ffm module
609e7ef
only allow explicit build for arrow-memory-ffm
1ca51fc
Remove unecessary edits
ef6665d
Clean up documentation wording
0cd7939
Add runtime exception message for version mismatch
8c05046
address comments, update maven profile
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -77,6 +77,9 @@ groups: | |
| c-glib: | ||
| - test-*c-glib* | ||
|
|
||
| java: | ||
| - "*java*" | ||
|
|
||
| python: | ||
| - test-*python* | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
77 changes: 77 additions & 0 deletions
77
...emory/memory-core/src/test/java/org/apache/arrow/memory/JavaForeignAllocationManager.java
This file contains hidden or 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,77 @@ | ||
| /* | ||
| * 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 java.lang.foreign.Arena; | ||
| import java.lang.foreign.MemorySegment; | ||
|
|
||
| /** | ||
| * Allocation manager based on java.lang.foreign API. | ||
| */ | ||
| public final class JavaForeignAllocationManager extends AllocationManager { | ||
|
|
||
| private static final ArrowBuf EMPTY = new ArrowBuf(ReferenceManager.NO_OP, | ||
| null, | ||
| 0, | ||
| MemorySegment.NULL.address() | ||
| ); | ||
|
|
||
| public static final AllocationManager.Factory FACTORY = new Factory() { | ||
| @Override | ||
| public AllocationManager create(BufferAllocator accountingAllocator, long size) { | ||
| return new JavaForeignAllocationManager(accountingAllocator, size); | ||
| } | ||
|
|
||
| @Override | ||
| public ArrowBuf empty() { | ||
| return EMPTY; | ||
| } | ||
| }; | ||
|
|
||
| private final Arena arena; | ||
|
|
||
| private final MemorySegment allocatedMemorySegment; | ||
|
|
||
| private final long allocatedSize; | ||
|
|
||
| private final long allocatedAddress; | ||
|
|
||
| JavaForeignAllocationManager(BufferAllocator accountingAllocator, long requestedSize) { | ||
| super(accountingAllocator); | ||
| arena = Arena.ofShared(); | ||
| allocatedMemorySegment = arena.allocate(requestedSize, /*byteAlignment*/ 8); | ||
| allocatedAddress = allocatedMemorySegment.address(); | ||
| allocatedSize = requestedSize; | ||
| } | ||
|
|
||
| @Override | ||
| public long getSize() { | ||
| return allocatedSize; | ||
| } | ||
|
|
||
| @Override | ||
| protected long memoryAddress() { | ||
| return allocatedAddress; | ||
| } | ||
|
|
||
| @Override | ||
| protected void release0() { | ||
| arena.close(); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or 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,30 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- 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. --> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <parent> | ||
| <artifactId>arrow-memory</artifactId> | ||
| <groupId>org.apache.arrow</groupId> | ||
| <version>15.0.0-SNAPSHOT</version> | ||
| </parent> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <artifactId>arrow-memory-foreign</artifactId> | ||
| <name>Arrow Memory - Foreign</name> | ||
| <description>Allocator and utils for allocating memory in Arrow based on java.lang.foreign</description> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.apache.arrow</groupId> | ||
| <artifactId>arrow-memory-core</artifactId> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> |
37 changes: 37 additions & 0 deletions
37
...memory-foreign/src/main/java/org/apache/arrow/memory/DefaultAllocationManagerFactory.java
This file contains hidden or 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,37 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| /** | ||
| * The default Allocation Manager Factory for a module. | ||
| * | ||
| */ | ||
| public class DefaultAllocationManagerFactory implements AllocationManager.Factory { | ||
|
|
||
| public static final AllocationManager.Factory FACTORY = JavaForeignAllocationManager.FACTORY; | ||
|
|
||
| @Override | ||
| public AllocationManager create(BufferAllocator accountingAllocator, long size) { | ||
| return FACTORY.create(accountingAllocator, size); | ||
| } | ||
|
|
||
| @Override | ||
| public ArrowBuf empty() { | ||
| return FACTORY.empty(); | ||
| } | ||
| } |
77 changes: 77 additions & 0 deletions
77
...ry/memory-foreign/src/main/java/org/apache/arrow/memory/JavaForeignAllocationManager.java
This file contains hidden or 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,77 @@ | ||
| /* | ||
| * 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 java.lang.foreign.Arena; | ||
| import java.lang.foreign.MemorySegment; | ||
|
|
||
| /** | ||
| * Allocation manager based on java.lang.foreign API. | ||
| */ | ||
| public final class JavaForeignAllocationManager extends AllocationManager { | ||
|
|
||
| private static final ArrowBuf EMPTY = new ArrowBuf(ReferenceManager.NO_OP, | ||
| null, | ||
| 0, | ||
| MemorySegment.NULL.address() | ||
| ); | ||
|
|
||
| public static final AllocationManager.Factory FACTORY = new Factory() { | ||
| @Override | ||
| public AllocationManager create(BufferAllocator accountingAllocator, long size) { | ||
| return new JavaForeignAllocationManager(accountingAllocator, size); | ||
| } | ||
|
|
||
| @Override | ||
| public ArrowBuf empty() { | ||
| return EMPTY; | ||
| } | ||
| }; | ||
|
|
||
| private final Arena arena; | ||
|
|
||
| private final MemorySegment allocatedMemorySegment; | ||
|
|
||
| private final long allocatedSize; | ||
|
|
||
| private final long allocatedAddress; | ||
|
|
||
| JavaForeignAllocationManager(BufferAllocator accountingAllocator, long requestedSize) { | ||
| super(accountingAllocator); | ||
| arena = Arena.ofShared(); | ||
| allocatedMemorySegment = arena.allocate(requestedSize, /*byteAlignment*/ 8); | ||
| allocatedAddress = allocatedMemorySegment.address(); | ||
| allocatedSize = requestedSize; | ||
| } | ||
|
|
||
| @Override | ||
| public long getSize() { | ||
| return allocatedSize; | ||
| } | ||
|
|
||
| @Override | ||
| protected long memoryAddress() { | ||
| return allocatedAddress; | ||
| } | ||
|
|
||
| @Override | ||
| protected void release0() { | ||
| arena.close(); | ||
| } | ||
|
|
||
| } |
41 changes: 41 additions & 0 deletions
41
...emory-foreign/src/test/java/org/apache/arrow/memory/TestAllocationManagerJavaForeign.java
This file contains hidden or 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,41 @@ | ||
| /* | ||
| * 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 static org.junit.Assert.assertEquals; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| /** | ||
| * Test cases for {@link AllocationManager}. | ||
| */ | ||
| public class TestAllocationManagerJavaForeign { | ||
|
|
||
| @Test | ||
| public void testAllocationManagerType() { | ||
|
|
||
| // test Java Foreign allocation manager type | ||
| System.setProperty( | ||
| DefaultAllocationManagerOption.ALLOCATION_MANAGER_TYPE_PROPERTY_NAME, "Foreign"); | ||
| DefaultAllocationManagerOption.AllocationManagerType mgrType = | ||
| DefaultAllocationManagerOption.getDefaultAllocationManagerType(); | ||
|
|
||
| assertEquals(DefaultAllocationManagerOption.AllocationManagerType.Foreign, mgrType); | ||
|
|
||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file was added as a hack to test the memory-core module with the FFM APIs. It will be useful for testing later, but can be ignored otherwise.