diff --git a/java/c/pom.xml b/java/c/pom.xml
index d66379d3566..8fc3f36994d 100644
--- a/java/c/pom.xml
+++ b/java/c/pom.xml
@@ -53,6 +53,11 @@
arrow-memory-unsafe
test
+
+ org.apache.arrow
+ arrow-format
+ test
+
com.google.guava
guava
diff --git a/java/dataset/src/test/java/org/apache/arrow/dataset/TestAllTypes.java b/java/dataset/src/test/java/org/apache/arrow/dataset/TestAllTypes.java
index 7be49079e74..5293aca0c32 100644
--- a/java/dataset/src/test/java/org/apache/arrow/dataset/TestAllTypes.java
+++ b/java/dataset/src/test/java/org/apache/arrow/dataset/TestAllTypes.java
@@ -32,7 +32,6 @@
import org.apache.arrow.dataset.file.DatasetFileWriter;
import org.apache.arrow.dataset.file.FileFormat;
import org.apache.arrow.memory.BufferAllocator;
-import org.apache.arrow.util.ArrowTestDataUtil;
import org.apache.arrow.vector.BigIntVector;
import org.apache.arrow.vector.BitVector;
import org.apache.arrow.vector.DateMilliVector;
@@ -76,6 +75,7 @@
import org.apache.arrow.vector.types.pojo.Field;
import org.apache.arrow.vector.types.pojo.FieldType;
import org.apache.arrow.vector.types.pojo.Schema;
+import org.apache.arrow.vector.util.ArrowTestDataUtil;
import org.apache.arrow.vector.util.ByteArrayReadableSeekableByteChannel;
import org.apache.arrow.vector.util.Text;
import org.junit.ClassRule;
diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/FlightTestUtil.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/FlightTestUtil.java
index 25d59d99ad7..91d7a97ceb4 100644
--- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/FlightTestUtil.java
+++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/FlightTestUtil.java
@@ -24,7 +24,7 @@
import java.util.List;
import java.util.Random;
-import org.apache.arrow.util.ArrowTestDataUtil;
+import org.apache.arrow.vector.util.ArrowTestDataUtil;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.function.Executable;
diff --git a/java/format/src/main/java/module-info.java b/java/format/src/main/java/module-info.java
new file mode 100644
index 00000000000..bda779c91af
--- /dev/null
+++ b/java/format/src/main/java/module-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+module org.apache.arrow.format {
+ exports org.apache.arrow.flatbuf;
+ requires transitive flatbuffers.java;
+}
diff --git a/java/maven/module-info-compiler-maven-plugin/pom.xml b/java/maven/module-info-compiler-maven-plugin/pom.xml
new file mode 100644
index 00000000000..ce598fc7f0f
--- /dev/null
+++ b/java/maven/module-info-compiler-maven-plugin/pom.xml
@@ -0,0 +1,130 @@
+
+
+
+ 4.0.0
+
+ org.apache.arrow.maven.plugins
+ arrow-maven-plugins
+ 15.0.0-SNAPSHOT
+
+ module-info-compiler-maven-plugin
+ maven-plugin
+
+ Module Info Compiler Maven Plugin
+
+ https://arrow.apache.org
+
+
+ ${maven.version}
+
+
+
+ 3.3.9
+
+
+
+
+ org.glavo
+ module-info-compiler
+ 2.0
+
+
+ org.apache.maven
+ maven-plugin-api
+ ${maven.version}
+ provided
+
+
+ org.apache.maven
+ maven-core
+ ${maven.version}
+ provided
+
+
+ org.apache.maven
+ maven-artifact
+ ${maven.version}
+ provided
+
+
+ org.apache.maven
+ maven-model
+ ${maven.version}
+ provided
+
+
+ org.apache.maven.plugin-tools
+ maven-plugin-annotations
+ 3.6.0
+ provided
+
+
+
+
+
+
+
+ maven-clean-plugin
+ 3.1.0
+
+
+ maven-plugin-plugin
+ 3.6.0
+
+
+ maven-jar-plugin
+ 3.0.2
+
+
+ maven-install-plugin
+ 2.5.2
+
+
+ maven-deploy-plugin
+ 2.8.2
+
+
+ maven-invoker-plugin
+ 3.1.0
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-plugin-plugin
+ 3.6.0
+
+ true
+
+
+
+ mojo-descriptor
+
+ descriptor
+
+
+
+ help-goal
+
+ helpmojo
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/java/maven/module-info-compiler-maven-plugin/src/main/java/org/apache/arrow/maven/plugins/ModuleInfoCompilerPlugin.java b/java/maven/module-info-compiler-maven-plugin/src/main/java/org/apache/arrow/maven/plugins/ModuleInfoCompilerPlugin.java
new file mode 100644
index 00000000000..0f91d0590bb
--- /dev/null
+++ b/java/maven/module-info-compiler-maven-plugin/src/main/java/org/apache/arrow/maven/plugins/ModuleInfoCompilerPlugin.java
@@ -0,0 +1,105 @@
+/*
+ * 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.maven.plugins;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.project.MavenProject;
+import org.glavo.mic.ModuleInfoCompiler;
+
+/**
+ * Compiles the first module-info.java file in the project purely syntactically.
+ */
+@Mojo(name = "module-info-compile", defaultPhase = LifecyclePhase.COMPILE)
+public class ModuleInfoCompilerPlugin extends AbstractMojo {
+ /**
+ * Source directories.
+ */
+ @Parameter(defaultValue = "${project.compileSourceRoots}", property = "compileSourceRoots",
+ required = true)
+ private final List compileSourceRoots = new ArrayList<>();
+
+ @Parameter(defaultValue = "false", property = "skip", required = false)
+ private boolean skip = false;
+
+ @Parameter(defaultValue = "${project}", readonly = true, required = true)
+ private MavenProject project;
+
+ @Override
+ public void execute() throws MojoExecutionException {
+ if (skip) {
+ getLog().info("Skipping module-info-compiler-maven-plugin");
+ return;
+ }
+
+ Optional moduleInfoFile = findFirstModuleInfo(compileSourceRoots);
+ if (moduleInfoFile.isPresent()) {
+ // The compiled module-info.class file goes into target/classes/module-info/main
+ Path outputDir = Paths.get(project.getBuild().getOutputDirectory());
+
+ outputDir.toFile().mkdirs();
+ Path targetPath = outputDir.resolve("module-info.class");
+
+ // Invoke the compiler,
+ ModuleInfoCompiler compiler = new ModuleInfoCompiler();
+ try (Reader reader = new InputStreamReader(Files.newInputStream(moduleInfoFile.get().toPath()),
+ StandardCharsets.UTF_8);
+ OutputStream output = Files.newOutputStream(targetPath)) {
+ compiler.compile(reader, output);
+ getLog().info("Successfully wrote module-info.class file.");
+ } catch (IOException ex) {
+ throw new MojoExecutionException("Error compiling module-info.java", ex);
+ }
+ } else {
+ getLog().info("No module-info.java file found. module-info.class file was not generated.");
+ }
+ }
+
+ /**
+ * Finds the first module-info.java file in the set of source directories.
+ */
+ private Optional findFirstModuleInfo(List sourceDirectories) {
+ if (sourceDirectories == null) {
+ return Optional.empty();
+ }
+
+ return sourceDirectories.stream().map(Paths::get)
+ .map(sourcePath ->
+ sourcePath.toFile().listFiles(file ->
+ file.getName().equals("module-info.java")))
+ .filter(matchingFiles -> matchingFiles != null && matchingFiles.length != 0)
+ .map(matchingFiles -> matchingFiles[0])
+ .findAny();
+ }
+}
diff --git a/java/maven/pom.xml b/java/maven/pom.xml
new file mode 100644
index 00000000000..86ac402732b
--- /dev/null
+++ b/java/maven/pom.xml
@@ -0,0 +1,287 @@
+
+
+
+ 4.0.0
+
+ org.apache.arrow.maven.plugins
+ arrow-maven-plugins
+ 15.0.0-SNAPSHOT
+ Arrow Maven Plugins
+ pom
+
+
+ module-info-compiler-maven-plugin
+
+
+
+ true
+
+
+
+
+
+ org.apache.rat
+ apache-rat-plugin
+
+
+ rat-checks
+ validate
+
+ check
+
+
+
+
+ false
+
+ **/dependency-reduced-pom.xml
+ **/*.log
+ **/*.css
+ **/*.js
+ **/*.md
+ **/*.eps
+ **/*.json
+ **/*.seq
+ **/*.parquet
+ **/*.sql
+ **/arrow-git.properties
+ **/*.csv
+ **/*.csvh
+ **/*.csvh-test
+ **/*.tsv
+ **/*.txt
+ **/*.ssv
+ **/arrow-*.conf
+ **/.buildpath
+ **/*.proto
+ **/*.fmpp
+ **/target/**
+ **/*.tdd
+ **/*.project
+ **/TAGS
+ **/*.checkstyle
+ **/.classpath
+ **/.factorypath
+ **/.settings/**
+ .*/**
+ **/*.patch
+ **/*.pb.cc
+ **/*.pb.h
+ **/*.linux
+ **/client/build/**
+ **/*.tbl
+ **/*.iml
+ **/flight.properties
+ **/*.idea/**
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+
+
+ **/logging.properties
+ **/logback-test.xml
+ **/logback.out.xml
+ **/logback.xml
+
+
+ true
+
+ true
+ true
+
+
+ org.apache.arrow
+ ${username}
+ https://arrow.apache.org/
+
+
+
+
+
+
+ test-jar
+
+
+ true
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+
+ UTF-8
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ UTF-8
+ 1.8
+ 1.8
+ 2048m
+ false
+ true
+
+
+
+ maven-enforcer-plugin
+
+
+ validate_java_and_maven_version
+ verify
+
+ enforce
+
+ false
+
+
+
+ [3.3.0,4)
+
+
+
+
+
+ avoid_bad_dependencies
+ verify
+
+ enforce
+
+
+
+
+
+ commons-logging
+ javax.servlet:servlet-api
+ org.mortbay.jetty:servlet-api
+ org.mortbay.jetty:servlet-api-2.5
+ log4j:log4j
+
+
+
+
+
+
+
+
+ pl.project13.maven
+ git-commit-id-plugin
+ 4.0.5
+
+
+ for-jars
+ true
+
+ revision
+
+
+ target/classes/arrow-git.properties
+
+
+
+ for-source-tarball
+
+ revision
+
+ false
+
+ ./arrow-git.properties
+
+
+
+
+
+ dd.MM.yyyy '@' HH:mm:ss z
+ false
+ false
+ true
+ false
+
+ false
+ false
+ 7
+ -dirty
+ true
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+ 3.1.0
+
+
+ com.puppycrawl.tools
+ checkstyle
+ 8.19
+
+
+ org.slf4j
+ jcl-over-slf4j
+ 1.7.5
+
+
+
+
+ validate
+ validate
+
+ check
+
+
+
+
+ ../dev/checkstyle/checkstyle.xml
+ ../dev/checkstyle/checkstyle.license
+ ../dev/checkstyle/suppressions.xml
+ true
+ UTF-8
+ true
+ ${checkstyle.failOnViolation}
+ ${checkstyle.failOnViolation}
+ warning
+ xml
+ html
+ ${project.build.directory}/test/checkstyle-errors.xml
+ false
+
+
+
+ org.cyclonedx
+ cyclonedx-maven-plugin
+ 2.7.10
+
+
+ package
+
+ makeBom
+
+
+
+
+
+
+
+
diff --git a/java/memory/memory-core/pom.xml b/java/memory/memory-core/pom.xml
index 8f286990453..66be9c2ff4e 100644
--- a/java/memory/memory-core/pom.xml
+++ b/java/memory/memory-core/pom.xml
@@ -42,7 +42,6 @@
org.apache.maven.plugins
maven-surefire-plugin
-
@@ -54,6 +53,30 @@
+
+ error-prone-jdk11+
+
+ [11,]
+
+ !m2e.version
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+ --add-opens=java.base/java.lang.reflect=org.apache.arrow.memory.core --add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED
+
+
+ **/TestOpens.java
+
+
+
+
+
+
opens-tests
diff --git a/java/memory/memory-core/src/main/java/module-info.java b/java/memory/memory-core/src/main/java/module-info.java
new file mode 100644
index 00000000000..815f53bed63
--- /dev/null
+++ b/java/memory/memory-core/src/main/java/module-info.java
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+
+module org.apache.arrow.memory.core {
+ exports org.apache.arrow.memory;
+ exports org.apache.arrow.memory.rounding;
+ exports org.apache.arrow.memory.util;
+ exports org.apache.arrow.memory.util.hash;
+ exports org.apache.arrow.util;
+ requires transitive jdk.unsupported;
+ requires jsr305;
+ requires org.immutables.value;
+ requires slf4j.api;
+}
diff --git a/java/memory/memory-core/src/main/java/org/apache/arrow/memory/CheckAllocator.java b/java/memory/memory-core/src/main/java/org/apache/arrow/memory/CheckAllocator.java
index 79b825aa2e8..dac4a3fcff5 100644
--- a/java/memory/memory-core/src/main/java/org/apache/arrow/memory/CheckAllocator.java
+++ b/java/memory/memory-core/src/main/java/org/apache/arrow/memory/CheckAllocator.java
@@ -31,20 +31,35 @@
*/
final class CheckAllocator {
private static final Logger logger = LoggerFactory.getLogger(CheckAllocator.class);
- private static final String ALLOCATOR_PATH = "org/apache/arrow/memory/DefaultAllocationManagerFactory.class";
+ // unique package names needed by JPMS module naming
+ private static final String ALLOCATOR_PATH_CORE =
+ "org/apache/arrow/memory/DefaultAllocationManagerFactory.class";
+ private static final String ALLOCATOR_PATH_UNSAFE =
+ "org/apache/arrow/memory/unsafe/DefaultAllocationManagerFactory.class";
+ private static final String ALLOCATOR_PATH_NETTY =
+ "org/apache/arrow/memory/netty/DefaultAllocationManagerFactory.class";
private CheckAllocator() {
-
}
static String check() {
Set urls = scanClasspath();
URL rootAllocator = assertOnlyOne(urls);
reportResult(rootAllocator);
- return "org.apache.arrow.memory.DefaultAllocationManagerFactory";
+ if (rootAllocator.getPath().contains("memory-core") ||
+ rootAllocator.getPath().contains("/org/apache/arrow/memory/core/")) {
+ return "org.apache.arrow.memory.DefaultAllocationManagerFactory";
+ } else if (rootAllocator.getPath().contains("memory-unsafe") ||
+ rootAllocator.getPath().contains("/org/apache/arrow/memory/unsafe/")) {
+ return "org.apache.arrow.memory.unsafe.DefaultAllocationManagerFactory";
+ } else if (rootAllocator.getPath().contains("memory-netty") ||
+ rootAllocator.getPath().contains("/org/apache/arrow/memory/netty/")) {
+ return "org.apache.arrow.memory.netty.DefaultAllocationManagerFactory";
+ } else {
+ throw new IllegalStateException("Unknown allocation manager type to infer. Current: " + rootAllocator.getPath());
+ }
}
-
private static Set scanClasspath() {
// LinkedHashSet appropriate here because it preserves insertion order
// during iteration
@@ -53,9 +68,21 @@ private static Set scanClasspath() {
ClassLoader allocatorClassLoader = CheckAllocator.class.getClassLoader();
Enumeration paths;
if (allocatorClassLoader == null) {
- paths = ClassLoader.getSystemResources(ALLOCATOR_PATH);
+ paths = ClassLoader.getSystemResources(ALLOCATOR_PATH_CORE);
+ if (!paths.hasMoreElements()) {
+ paths = ClassLoader.getSystemResources(ALLOCATOR_PATH_UNSAFE);
+ }
+ if (!paths.hasMoreElements()) {
+ paths = ClassLoader.getSystemResources(ALLOCATOR_PATH_NETTY);
+ }
} else {
- paths = allocatorClassLoader.getResources(ALLOCATOR_PATH);
+ paths = allocatorClassLoader.getResources(ALLOCATOR_PATH_CORE);
+ if (!paths.hasMoreElements()) {
+ paths = allocatorClassLoader.getResources(ALLOCATOR_PATH_UNSAFE);
+ }
+ if (!paths.hasMoreElements()) {
+ paths = allocatorClassLoader.getResources(ALLOCATOR_PATH_NETTY);
+ }
}
while (paths.hasMoreElements()) {
URL path = paths.nextElement();
diff --git a/java/memory/memory-core/src/main/java/org/apache/arrow/memory/DefaultAllocationManagerOption.java b/java/memory/memory-core/src/main/java/org/apache/arrow/memory/DefaultAllocationManagerOption.java
index 15120c252fc..564d59994b7 100644
--- a/java/memory/memory-core/src/main/java/org/apache/arrow/memory/DefaultAllocationManagerOption.java
+++ b/java/memory/memory-core/src/main/java/org/apache/arrow/memory/DefaultAllocationManagerOption.java
@@ -19,6 +19,8 @@
import java.lang.reflect.Field;
+import org.apache.arrow.util.VisibleForTesting;
+
/**
* A class for choosing the default allocation manager.
*/
@@ -61,7 +63,12 @@ public enum AllocationManagerType {
Unknown,
}
- static AllocationManagerType getDefaultAllocationManagerType() {
+ /**
+ * Returns the default allocation manager type.
+ * @return the default allocation manager type.
+ */
+ @VisibleForTesting
+ public static AllocationManagerType getDefaultAllocationManagerType() {
AllocationManagerType ret = AllocationManagerType.Unknown;
try {
@@ -115,7 +122,7 @@ private static AllocationManager.Factory getFactory(String clazzName) {
private static AllocationManager.Factory getUnsafeFactory() {
try {
- return getFactory("org.apache.arrow.memory.UnsafeAllocationManager");
+ return getFactory("org.apache.arrow.memory.unsafe.UnsafeAllocationManager");
} catch (RuntimeException e) {
throw new RuntimeException("Please add arrow-memory-unsafe to your classpath," +
" No DefaultAllocationManager found to instantiate an UnsafeAllocationManager", e);
@@ -124,7 +131,7 @@ private static AllocationManager.Factory getUnsafeFactory() {
private static AllocationManager.Factory getNettyFactory() {
try {
- return getFactory("org.apache.arrow.memory.NettyAllocationManager");
+ return getFactory("org.apache.arrow.memory.netty.NettyAllocationManager");
} catch (RuntimeException e) {
throw new RuntimeException("Please add arrow-memory-netty to your classpath," +
" No DefaultAllocationManager found to instantiate an NettyAllocationManager", e);
diff --git a/java/memory/memory-core/src/main/java/org/apache/arrow/memory/util/MemoryUtil.java b/java/memory/memory-core/src/main/java/org/apache/arrow/memory/util/MemoryUtil.java
index cc615c5b383..12d2ae4ce66 100644
--- a/java/memory/memory-core/src/main/java/org/apache/arrow/memory/util/MemoryUtil.java
+++ b/java/memory/memory-core/src/main/java/org/apache/arrow/memory/util/MemoryUtil.java
@@ -142,7 +142,7 @@ public Object run() {
// the static fields above get initialized
final RuntimeException failure = new RuntimeException(
"Failed to initialize MemoryUtil. You must start Java with " +
- "`--add-opens=java.base/java.nio=ALL-UNNAMED` " +
+ "`--add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED` " +
"(See https://arrow.apache.org/docs/java/install.html)", e);
failure.printStackTrace();
throw failure;
diff --git a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/CountingAllocationListener.java b/java/memory/memory-core/src/test/java/org/apache/arrow/memory/CountingAllocationListener.java
similarity index 95%
rename from java/memory/memory-netty/src/test/java/org/apache/arrow/memory/CountingAllocationListener.java
rename to java/memory/memory-core/src/test/java/org/apache/arrow/memory/CountingAllocationListener.java
index 78c78c8ad8c..f1dd7e92c5c 100644
--- a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/CountingAllocationListener.java
+++ b/java/memory/memory-core/src/test/java/org/apache/arrow/memory/CountingAllocationListener.java
@@ -17,6 +17,10 @@
package org.apache.arrow.memory;
+import org.apache.arrow.memory.AllocationListener;
+import org.apache.arrow.memory.AllocationOutcome;
+import org.apache.arrow.memory.BufferAllocator;
+
/**
* Counting allocation listener.
* It counts the number of times it has been invoked, and how much memory allocation it has seen
diff --git a/java/memory/memory-core/src/test/java/org/apache/arrow/memory/TestArrowBuf.java b/java/memory/memory-core/src/test/java/org/apache/arrow/memory/TestArrowBuf.java
index c88768c43bc..9ba42abc1ce 100644
--- a/java/memory/memory-core/src/test/java/org/apache/arrow/memory/TestArrowBuf.java
+++ b/java/memory/memory-core/src/test/java/org/apache/arrow/memory/TestArrowBuf.java
@@ -167,13 +167,15 @@ public void testEnabledHistoricalLog() {
fieldDebug.set(null, true);
try (BufferAllocator allocator = new RootAllocator(128)) {
allocator.buffer(2);
- Exception e = assertThrows(IllegalStateException.class, () -> allocator.close());
- assertTrue(e.getMessage().contains("event log for:")); // JDK8, JDK11
+ Exception e = assertThrows(IllegalStateException.class, allocator::close);
+ assertTrue("Exception had the following message: " + e.getMessage(),
+ e.getMessage().contains("event log for:")); // JDK8, JDK11
} finally {
fieldDebug.set(null, false);
}
} catch (Exception e) {
- assertTrue(e.toString().contains("java.lang.NoSuchFieldException: modifiers")); // JDK17+
+ assertTrue("Exception had the following toString(): " + e.toString(),
+ e.toString().contains("java.lang.NoSuchFieldException: modifiers")); // JDK17+
} finally {
((Logger) LoggerFactory.getLogger("org.apache.arrow")).setLevel(null);
}
diff --git a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/TestBaseAllocator.java b/java/memory/memory-core/src/test/java/org/apache/arrow/memory/TestBaseAllocator.java
similarity index 91%
rename from java/memory/memory-netty/src/test/java/org/apache/arrow/memory/TestBaseAllocator.java
rename to java/memory/memory-core/src/test/java/org/apache/arrow/memory/TestBaseAllocator.java
index 7613d073f8c..f90e2214215 100644
--- a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/TestBaseAllocator.java
+++ b/java/memory/memory-core/src/test/java/org/apache/arrow/memory/TestBaseAllocator.java
@@ -31,22 +31,16 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
-import java.util.stream.Collectors;
import org.apache.arrow.memory.AllocationOutcomeDetails.Entry;
import org.apache.arrow.memory.rounding.RoundingPolicy;
import org.apache.arrow.memory.rounding.SegmentRoundingPolicy;
import org.apache.arrow.memory.util.AssertionUtil;
+import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
-import org.slf4j.LoggerFactory;
-import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.Logger;
-import ch.qos.logback.classic.spi.ILoggingEvent;
-import ch.qos.logback.core.read.ListAppender;
-import io.netty.buffer.PooledByteBufAllocatorL;
import sun.misc.Unsafe;
public class TestBaseAllocator {
@@ -118,6 +112,7 @@ public void testRootAllocator_closeWithOutstanding() throws Exception {
}
@Test
+ @Ignore
public void testRootAllocator_getEmpty() throws Exception {
try (final RootAllocator rootAllocator =
new RootAllocator(MAX_ALLOCATION)) {
@@ -448,73 +443,73 @@ public ArrowBuf empty() {
@Test
public void testRootAllocator_listeners() throws Exception {
CountingAllocationListener l1 = new CountingAllocationListener();
- assertEquals(0, l1.getNumPreCalls());
- assertEquals(0, l1.getNumCalls());
- assertEquals(0, l1.getNumReleaseCalls());
- assertEquals(0, l1.getNumChildren());
- assertEquals(0, l1.getTotalMem());
+ Assert.assertEquals(0, l1.getNumPreCalls());
+ Assert.assertEquals(0, l1.getNumCalls());
+ Assert.assertEquals(0, l1.getNumReleaseCalls());
+ Assert.assertEquals(0, l1.getNumChildren());
+ Assert.assertEquals(0, l1.getTotalMem());
CountingAllocationListener l2 = new CountingAllocationListener();
- assertEquals(0, l2.getNumPreCalls());
- assertEquals(0, l2.getNumCalls());
- assertEquals(0, l2.getNumReleaseCalls());
- assertEquals(0, l2.getNumChildren());
- assertEquals(0, l2.getTotalMem());
+ Assert.assertEquals(0, l2.getNumPreCalls());
+ Assert.assertEquals(0, l2.getNumCalls());
+ Assert.assertEquals(0, l2.getNumReleaseCalls());
+ Assert.assertEquals(0, l2.getNumChildren());
+ Assert.assertEquals(0, l2.getTotalMem());
// root and first-level child share the first listener
// second-level and third-level child share the second listener
try (final RootAllocator rootAllocator = new RootAllocator(l1, MAX_ALLOCATION)) {
try (final BufferAllocator c1 = rootAllocator.newChildAllocator("c1", 0, MAX_ALLOCATION)) {
- assertEquals(1, l1.getNumChildren());
+ Assert.assertEquals(1, l1.getNumChildren());
final ArrowBuf buf1 = c1.buffer(16);
assertNotNull("allocation failed", buf1);
- assertEquals(1, l1.getNumPreCalls());
- assertEquals(1, l1.getNumCalls());
- assertEquals(0, l1.getNumReleaseCalls());
- assertEquals(16, l1.getTotalMem());
+ Assert.assertEquals(1, l1.getNumPreCalls());
+ Assert.assertEquals(1, l1.getNumCalls());
+ Assert.assertEquals(0, l1.getNumReleaseCalls());
+ Assert.assertEquals(16, l1.getTotalMem());
buf1.getReferenceManager().release();
try (final BufferAllocator c2 = c1.newChildAllocator("c2", l2, 0, MAX_ALLOCATION)) {
- assertEquals(2, l1.getNumChildren()); // c1 got a new child, so c1's listener (l1) is notified
- assertEquals(0, l2.getNumChildren());
+ Assert.assertEquals(2, l1.getNumChildren()); // c1 got a new child, so c1's listener (l1) is notified
+ Assert.assertEquals(0, l2.getNumChildren());
final ArrowBuf buf2 = c2.buffer(32);
assertNotNull("allocation failed", buf2);
- assertEquals(1, l1.getNumCalls());
- assertEquals(16, l1.getTotalMem());
- assertEquals(1, l2.getNumPreCalls());
- assertEquals(1, l2.getNumCalls());
- assertEquals(0, l2.getNumReleaseCalls());
- assertEquals(32, l2.getTotalMem());
+ Assert.assertEquals(1, l1.getNumCalls());
+ Assert.assertEquals(16, l1.getTotalMem());
+ Assert.assertEquals(1, l2.getNumPreCalls());
+ Assert.assertEquals(1, l2.getNumCalls());
+ Assert.assertEquals(0, l2.getNumReleaseCalls());
+ Assert.assertEquals(32, l2.getTotalMem());
buf2.getReferenceManager().release();
try (final BufferAllocator c3 = c2.newChildAllocator("c3", 0, MAX_ALLOCATION)) {
- assertEquals(2, l1.getNumChildren());
- assertEquals(1, l2.getNumChildren());
+ Assert.assertEquals(2, l1.getNumChildren());
+ Assert.assertEquals(1, l2.getNumChildren());
final ArrowBuf buf3 = c3.buffer(64);
assertNotNull("allocation failed", buf3);
- assertEquals(1, l1.getNumPreCalls());
- assertEquals(1, l1.getNumCalls());
- assertEquals(1, l1.getNumReleaseCalls());
- assertEquals(16, l1.getTotalMem());
- assertEquals(2, l2.getNumPreCalls());
- assertEquals(2, l2.getNumCalls());
- assertEquals(1, l2.getNumReleaseCalls());
- assertEquals(32 + 64, l2.getTotalMem());
+ Assert.assertEquals(1, l1.getNumPreCalls());
+ Assert.assertEquals(1, l1.getNumCalls());
+ Assert.assertEquals(1, l1.getNumReleaseCalls());
+ Assert.assertEquals(16, l1.getTotalMem());
+ Assert.assertEquals(2, l2.getNumPreCalls());
+ Assert.assertEquals(2, l2.getNumCalls());
+ Assert.assertEquals(1, l2.getNumReleaseCalls());
+ Assert.assertEquals(32 + 64, l2.getTotalMem());
buf3.getReferenceManager().release();
}
- assertEquals(2, l1.getNumChildren());
- assertEquals(0, l2.getNumChildren()); // third-level child removed
+ Assert.assertEquals(2, l1.getNumChildren());
+ Assert.assertEquals(0, l2.getNumChildren()); // third-level child removed
}
- assertEquals(1, l1.getNumChildren()); // second-level child removed
- assertEquals(0, l2.getNumChildren());
+ Assert.assertEquals(1, l1.getNumChildren()); // second-level child removed
+ Assert.assertEquals(0, l2.getNumChildren());
}
- assertEquals(0, l1.getNumChildren()); // first-level child removed
+ Assert.assertEquals(0, l1.getNumChildren()); // first-level child removed
- assertEquals(2, l2.getNumReleaseCalls());
+ Assert.assertEquals(2, l2.getNumReleaseCalls());
}
}
@Test
public void testRootAllocator_listenerAllocationFail() throws Exception {
CountingAllocationListener l1 = new CountingAllocationListener();
- assertEquals(0, l1.getNumCalls());
- assertEquals(0, l1.getTotalMem());
+ Assert.assertEquals(0, l1.getNumCalls());
+ Assert.assertEquals(0, l1.getTotalMem());
// Test attempts to allocate too much from a child whose limit is set to half of the max
// allocation. The listener's callback triggers, expanding the child allocator's limit, so then
// the allocation succeeds.
@@ -527,14 +522,14 @@ public void testRootAllocator_listenerAllocationFail() throws Exception {
} catch (OutOfMemoryException e) {
// expected
}
- assertEquals(0, l1.getNumCalls());
- assertEquals(0, l1.getTotalMem());
+ Assert.assertEquals(0, l1.getNumCalls());
+ Assert.assertEquals(0, l1.getTotalMem());
l1.setExpandOnFail(c1, MAX_ALLOCATION);
ArrowBuf arrowBuf = c1.buffer(MAX_ALLOCATION);
assertNotNull("allocation failed", arrowBuf);
- assertEquals(1, l1.getNumCalls());
- assertEquals(MAX_ALLOCATION, l1.getTotalMem());
+ Assert.assertEquals(1, l1.getNumCalls());
+ Assert.assertEquals(MAX_ALLOCATION, l1.getTotalMem());
arrowBuf.getReferenceManager().release();
}
}
@@ -1098,42 +1093,6 @@ public void testMemoryLeakWithReservation() throws Exception {
}
}
- @Test
- public void testMemoryUsage() {
- ListAppender memoryLogsAppender = new ListAppender<>();
- Logger logger = (Logger) LoggerFactory.getLogger("arrow.allocator");
- try {
- logger.setLevel(Level.TRACE);
- logger.addAppender(memoryLogsAppender);
- memoryLogsAppender.start();
- try (ArrowBuf buf = new ArrowBuf(ReferenceManager.NO_OP, null,
- 1024, new PooledByteBufAllocatorL().empty.memoryAddress())) {
- buf.memoryAddress();
- }
- boolean result = false;
- long startTime = System.currentTimeMillis();
- while ((System.currentTimeMillis() - startTime) < 10000) { // 10 seconds maximum for time to read logs
- result = memoryLogsAppender.list.stream()
- .anyMatch(
- log -> log.toString().contains("Memory Usage: \n") &&
- log.toString().contains("Large buffers outstanding: ") &&
- log.toString().contains("Normal buffers outstanding: ") &&
- log.getLevel().equals(Level.TRACE)
- );
- if (result) {
- break;
- }
- }
- assertTrue("Log messages are:\n" +
- memoryLogsAppender.list.stream().map(ILoggingEvent::toString).collect(Collectors.joining("\n")),
- result);
- } finally {
- memoryLogsAppender.stop();
- logger.detachAppender(memoryLogsAppender);
- logger.setLevel(null);
- }
- }
-
@Test
public void testOverlimit() {
try (BufferAllocator allocator = new RootAllocator(1024)) {
diff --git a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/TestForeignAllocation.java b/java/memory/memory-core/src/test/java/org/apache/arrow/memory/TestForeignAllocation.java
similarity index 93%
rename from java/memory/memory-netty/src/test/java/org/apache/arrow/memory/TestForeignAllocation.java
rename to java/memory/memory-core/src/test/java/org/apache/arrow/memory/TestForeignAllocation.java
index ec049ca6923..46e94fad37b 100644
--- a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/TestForeignAllocation.java
+++ b/java/memory/memory-core/src/test/java/org/apache/arrow/memory/TestForeignAllocation.java
@@ -23,6 +23,13 @@
import java.util.ArrayList;
import java.util.List;
+import org.apache.arrow.memory.AllocationListener;
+import org.apache.arrow.memory.AllocationOutcome;
+import org.apache.arrow.memory.ArrowBuf;
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.memory.ForeignAllocation;
+import org.apache.arrow.memory.OutOfMemoryException;
+import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.memory.util.MemoryUtil;
import org.junit.After;
import org.junit.Before;
diff --git a/java/memory/memory-netty-buffer-patch/pom.xml b/java/memory/memory-netty-buffer-patch/pom.xml
new file mode 100644
index 00000000000..1d4407c638d
--- /dev/null
+++ b/java/memory/memory-netty-buffer-patch/pom.xml
@@ -0,0 +1,44 @@
+
+
+
+
+ arrow-memory
+ org.apache.arrow
+ 15.0.0-SNAPSHOT
+
+ 4.0.0
+
+ arrow-memory-netty-buffer-patch
+ Arrow Memory - Netty Buffer
+ Netty Buffer needed to patch that is consumed by Arrow Memory Netty
+
+
+
+ org.apache.arrow
+ arrow-memory-core
+
+
+ io.netty
+ netty-buffer
+
+
+ io.netty
+ netty-common
+
+
+ org.slf4j
+ slf4j-api
+
+
+
diff --git a/java/memory/memory-netty/src/main/java/io/netty/buffer/ExpandableByteBuf.java b/java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/ExpandableByteBuf.java
similarity index 100%
rename from java/memory/memory-netty/src/main/java/io/netty/buffer/ExpandableByteBuf.java
rename to java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/ExpandableByteBuf.java
diff --git a/java/memory/memory-netty/src/main/java/io/netty/buffer/LargeBuffer.java b/java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/LargeBuffer.java
similarity index 100%
rename from java/memory/memory-netty/src/main/java/io/netty/buffer/LargeBuffer.java
rename to java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/LargeBuffer.java
diff --git a/java/memory/memory-netty/src/main/java/io/netty/buffer/MutableWrappedByteBuf.java b/java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/MutableWrappedByteBuf.java
similarity index 100%
rename from java/memory/memory-netty/src/main/java/io/netty/buffer/MutableWrappedByteBuf.java
rename to java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/MutableWrappedByteBuf.java
diff --git a/java/memory/memory-netty/src/main/java/io/netty/buffer/NettyArrowBuf.java b/java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/NettyArrowBuf.java
similarity index 94%
rename from java/memory/memory-netty/src/main/java/io/netty/buffer/NettyArrowBuf.java
rename to java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/NettyArrowBuf.java
index 71e4b7cb6d5..a5a5c2d40bc 100644
--- a/java/memory/memory-netty/src/main/java/io/netty/buffer/NettyArrowBuf.java
+++ b/java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/NettyArrowBuf.java
@@ -17,8 +17,6 @@
package io.netty.buffer;
-import static org.apache.arrow.memory.util.LargeMemoryUtil.checkedCastToInt;
-
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -29,10 +27,12 @@
import java.nio.channels.ScatteringByteChannel;
import org.apache.arrow.memory.ArrowBuf;
-import org.apache.arrow.memory.ArrowByteBufAllocator;
import org.apache.arrow.memory.BoundsChecking;
import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.memory.patch.ArrowByteBufAllocator;
+import org.apache.arrow.memory.util.LargeMemoryUtil;
import org.apache.arrow.util.Preconditions;
+import org.apache.arrow.util.VisibleForTesting;
import io.netty.util.internal.PlatformDependent;
@@ -264,7 +264,7 @@ public ByteBuffer nioBuffer(long index, int length) {
* @return ByteBuffer
*/
private ByteBuffer getDirectBuffer(long index) {
- return PlatformDependent.directBuffer(addr(index), checkedCastToInt(length - index));
+ return PlatformDependent.directBuffer(addr(index), LargeMemoryUtil.checkedCastToInt(length - index));
}
@Override
@@ -436,7 +436,8 @@ public byte getByte(int index) {
}
@Override
- protected short _getShortLE(int index) {
+ @VisibleForTesting
+ public short _getShortLE(int index) {
short s = getShort(index);
return Short.reverseBytes(s);
}
@@ -452,7 +453,8 @@ public short getShort(int index) {
}
@Override
- protected int _getIntLE(int index) {
+ @VisibleForTesting
+ public int _getIntLE(int index) {
int value = getInt(index);
return Integer.reverseBytes(value);
}
@@ -468,7 +470,8 @@ public int getInt(int index) {
}
@Override
- protected long _getLongLE(int index) {
+ @VisibleForTesting
+ public long _getLongLE(int index) {
long value = getLong(index);
return Long.reverseBytes(value);
}
@@ -509,7 +512,8 @@ protected void _setShortLE(int index, int value) {
}
@Override
- protected void _setShort(int index, int value) {
+ @VisibleForTesting
+ public void _setShort(int index, int value) {
setShort(index, value);
}
@@ -580,11 +584,13 @@ public NettyArrowBuf setMedium(int index, int value) {
}
@Override
- protected void _setInt(int index, int value) {
+ @VisibleForTesting
+ public void _setInt(int index, int value) {
setInt(index, value);
}
@Override
+ @VisibleForTesting
protected void _setIntLE(int index, int value) {
this.chk(index, 4);
PlatformDependent.putInt(this.addr(index), Integer.reverseBytes(value));
@@ -597,7 +603,8 @@ public NettyArrowBuf setInt(int index, int value) {
}
@Override
- protected void _setLong(int index, long value) {
+ @VisibleForTesting
+ public void _setLong(int index, long value) {
setLong(index, value);
}
@@ -620,9 +627,9 @@ public static NettyArrowBuf unwrapBuffer(ArrowBuf buf) {
final NettyArrowBuf nettyArrowBuf = new NettyArrowBuf(
buf,
buf.getReferenceManager().getAllocator(),
- checkedCastToInt(buf.capacity()));
- nettyArrowBuf.readerIndex(checkedCastToInt(buf.readerIndex()));
- nettyArrowBuf.writerIndex(checkedCastToInt(buf.writerIndex()));
+ LargeMemoryUtil.checkedCastToInt(buf.capacity()));
+ nettyArrowBuf.readerIndex(LargeMemoryUtil.checkedCastToInt(buf.readerIndex()));
+ nettyArrowBuf.writerIndex(LargeMemoryUtil.checkedCastToInt(buf.writerIndex()));
return nettyArrowBuf;
}
diff --git a/java/memory/memory-netty/src/main/java/io/netty/buffer/PooledByteBufAllocatorL.java b/java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/PooledByteBufAllocatorL.java
similarity index 97%
rename from java/memory/memory-netty/src/main/java/io/netty/buffer/PooledByteBufAllocatorL.java
rename to java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/PooledByteBufAllocatorL.java
index 06c6669cfd1..bc95b9df545 100644
--- a/java/memory/memory-netty/src/main/java/io/netty/buffer/PooledByteBufAllocatorL.java
+++ b/java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/PooledByteBufAllocatorL.java
@@ -17,13 +17,12 @@
package io.netty.buffer;
-import static org.apache.arrow.memory.util.AssertionUtil.ASSERT_ENABLED;
-
import java.lang.reflect.Field;
import java.nio.ByteBuffer;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.arrow.memory.OutOfMemoryException;
+import org.apache.arrow.memory.util.AssertionUtil;
import org.apache.arrow.memory.util.LargeMemoryUtil;
import io.netty.util.internal.OutOfDirectMemoryError;
@@ -51,7 +50,7 @@ public PooledByteBufAllocatorL() {
}
/**
- * Returns a {@linkplain io.netty.buffer.UnsafeDirectLittleEndian} of the given size.
+ * Returns a {@linkplain UnsafeDirectLittleEndian} of the given size.
*/
public UnsafeDirectLittleEndian allocate(long size) {
try {
@@ -183,7 +182,7 @@ private UnsafeDirectLittleEndian newDirectBufferL(int initialCapacity, int maxCa
fail();
}
- if (!ASSERT_ENABLED) {
+ if (!AssertionUtil.ASSERT_ENABLED) {
return new UnsafeDirectLittleEndian((PooledUnsafeDirectByteBuf) buf);
}
diff --git a/java/memory/memory-netty/src/main/java/io/netty/buffer/UnsafeDirectLittleEndian.java b/java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/UnsafeDirectLittleEndian.java
similarity index 100%
rename from java/memory/memory-netty/src/main/java/io/netty/buffer/UnsafeDirectLittleEndian.java
rename to java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/UnsafeDirectLittleEndian.java
diff --git a/java/memory/memory-netty/src/main/java/org/apache/arrow/memory/ArrowByteBufAllocator.java b/java/memory/memory-netty-buffer-patch/src/main/java/org/apache/arrow/memory/patch/ArrowByteBufAllocator.java
similarity index 97%
rename from java/memory/memory-netty/src/main/java/org/apache/arrow/memory/ArrowByteBufAllocator.java
rename to java/memory/memory-netty-buffer-patch/src/main/java/org/apache/arrow/memory/patch/ArrowByteBufAllocator.java
index ff40b49ff6f..6ce08b5a590 100644
--- a/java/memory/memory-netty/src/main/java/org/apache/arrow/memory/ArrowByteBufAllocator.java
+++ b/java/memory/memory-netty-buffer-patch/src/main/java/org/apache/arrow/memory/patch/ArrowByteBufAllocator.java
@@ -15,7 +15,9 @@
* limitations under the License.
*/
-package org.apache.arrow.memory;
+package org.apache.arrow.memory.patch;
+
+import org.apache.arrow.memory.BufferAllocator;
import io.netty.buffer.AbstractByteBufAllocator;
import io.netty.buffer.ByteBuf;
diff --git a/java/memory/memory-netty/src/test/java/io/netty/buffer/TestUnsafeDirectLittleEndian.java b/java/memory/memory-netty-buffer-patch/src/test/java/io/netty/buffer/TestUnsafeDirectLittleEndian.java
similarity index 95%
rename from java/memory/memory-netty/src/test/java/io/netty/buffer/TestUnsafeDirectLittleEndian.java
rename to java/memory/memory-netty-buffer-patch/src/test/java/io/netty/buffer/TestUnsafeDirectLittleEndian.java
index c2bd95bb3d9..043c2c1605a 100644
--- a/java/memory/memory-netty/src/test/java/io/netty/buffer/TestUnsafeDirectLittleEndian.java
+++ b/java/memory/memory-netty-buffer-patch/src/test/java/io/netty/buffer/TestUnsafeDirectLittleEndian.java
@@ -28,6 +28,11 @@
import org.junit.Test;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.LargeBuffer;
+import io.netty.buffer.Unpooled;
+import io.netty.buffer.UnsafeDirectLittleEndian;
+
public class TestUnsafeDirectLittleEndian {
private static final boolean LITTLE_ENDIAN = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN;
diff --git a/java/memory/memory-netty/pom.xml b/java/memory/memory-netty/pom.xml
index 307f6ad81a0..4ee4883d78d 100644
--- a/java/memory/memory-netty/pom.xml
+++ b/java/memory/memory-netty/pom.xml
@@ -26,9 +26,15 @@
org.apache.arrow
arrow-memory-core
+
+ org.apache.arrow
+ arrow-memory-netty-buffer-patch
+ ${project.version}
+
io.netty
netty-buffer
+ provided
io.netty
@@ -37,6 +43,7 @@
org.slf4j
slf4j-api
+ test
ch.qos.logback
diff --git a/java/memory/memory-netty/src/main/java/module-info.java b/java/memory/memory-netty/src/main/java/module-info.java
new file mode 100644
index 00000000000..95d1cdbd11f
--- /dev/null
+++ b/java/memory/memory-netty/src/main/java/module-info.java
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+module org.apache.arrow.memory.netty {
+ exports org.apache.arrow.memory.netty to org.apache.arrow.memory.core;
+
+ requires org.apache.arrow.memory.core;
+ requires io.netty.buffer;
+ requires io.netty.common;
+}
diff --git a/java/memory/memory-netty/src/main/java/org/apache/arrow/memory/DefaultAllocationManagerFactory.java b/java/memory/memory-netty/src/main/java/org/apache/arrow/memory/netty/DefaultAllocationManagerFactory.java
similarity index 87%
rename from java/memory/memory-netty/src/main/java/org/apache/arrow/memory/DefaultAllocationManagerFactory.java
rename to java/memory/memory-netty/src/main/java/org/apache/arrow/memory/netty/DefaultAllocationManagerFactory.java
index 10cfb5c1648..8ece77178f0 100644
--- a/java/memory/memory-netty/src/main/java/org/apache/arrow/memory/DefaultAllocationManagerFactory.java
+++ b/java/memory/memory-netty/src/main/java/org/apache/arrow/memory/netty/DefaultAllocationManagerFactory.java
@@ -15,7 +15,11 @@
* limitations under the License.
*/
-package org.apache.arrow.memory;
+package org.apache.arrow.memory.netty;
+
+import org.apache.arrow.memory.AllocationManager;
+import org.apache.arrow.memory.ArrowBuf;
+import org.apache.arrow.memory.BufferAllocator;
/**
* The default Allocation Manager Factory for a module.
diff --git a/java/memory/memory-netty/src/main/java/org/apache/arrow/memory/NettyAllocationManager.java b/java/memory/memory-netty/src/main/java/org/apache/arrow/memory/netty/NettyAllocationManager.java
similarity index 94%
rename from java/memory/memory-netty/src/main/java/org/apache/arrow/memory/NettyAllocationManager.java
rename to java/memory/memory-netty/src/main/java/org/apache/arrow/memory/netty/NettyAllocationManager.java
index 20004778307..58354d0c2ee 100644
--- a/java/memory/memory-netty/src/main/java/org/apache/arrow/memory/NettyAllocationManager.java
+++ b/java/memory/memory-netty/src/main/java/org/apache/arrow/memory/netty/NettyAllocationManager.java
@@ -15,7 +15,12 @@
* limitations under the License.
*/
-package org.apache.arrow.memory;
+package org.apache.arrow.memory.netty;
+
+import org.apache.arrow.memory.AllocationManager;
+import org.apache.arrow.memory.ArrowBuf;
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.memory.ReferenceManager;
import io.netty.buffer.PooledByteBufAllocatorL;
import io.netty.buffer.UnsafeDirectLittleEndian;
diff --git a/java/memory/memory-netty/src/test/java/io/netty/buffer/TestExpandableByteBuf.java b/java/memory/memory-netty/src/test/java/org/apache/arrow/io/netty/buffer/TestExpandableByteBuf.java
similarity index 96%
rename from java/memory/memory-netty/src/test/java/io/netty/buffer/TestExpandableByteBuf.java
rename to java/memory/memory-netty/src/test/java/org/apache/arrow/io/netty/buffer/TestExpandableByteBuf.java
index b39cca8e8e7..b4a7a70de73 100644
--- a/java/memory/memory-netty/src/test/java/io/netty/buffer/TestExpandableByteBuf.java
+++ b/java/memory/memory-netty/src/test/java/org/apache/arrow/io/netty/buffer/TestExpandableByteBuf.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package io.netty.buffer;
+package org.apache.arrow.io.netty.buffer;
import org.apache.arrow.memory.ArrowBuf;
import org.apache.arrow.memory.BufferAllocator;
@@ -23,6 +23,10 @@
import org.junit.Assert;
import org.junit.Test;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ExpandableByteBuf;
+import io.netty.buffer.NettyArrowBuf;
+
public class TestExpandableByteBuf {
@Test
diff --git a/java/memory/memory-netty/src/test/java/io/netty/buffer/TestNettyArrowBuf.java b/java/memory/memory-netty/src/test/java/org/apache/arrow/io/netty/buffer/TestNettyArrowBuf.java
similarity index 96%
rename from java/memory/memory-netty/src/test/java/io/netty/buffer/TestNettyArrowBuf.java
rename to java/memory/memory-netty/src/test/java/org/apache/arrow/io/netty/buffer/TestNettyArrowBuf.java
index 45d3b41e8a6..dc715d9b1ac 100644
--- a/java/memory/memory-netty/src/test/java/io/netty/buffer/TestNettyArrowBuf.java
+++ b/java/memory/memory-netty/src/test/java/org/apache/arrow/io/netty/buffer/TestNettyArrowBuf.java
@@ -15,17 +15,20 @@
* limitations under the License.
*/
-package io.netty.buffer;
+package org.apache.arrow.io.netty.buffer;
import java.nio.ByteBuffer;
import org.apache.arrow.memory.ArrowBuf;
-import org.apache.arrow.memory.ArrowByteBufAllocator;
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.memory.RootAllocator;
+import org.apache.arrow.memory.patch.ArrowByteBufAllocator;
import org.junit.Assert;
import org.junit.Test;
+import io.netty.buffer.CompositeByteBuf;
+import io.netty.buffer.NettyArrowBuf;
+
public class TestNettyArrowBuf {
@Test
diff --git a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/ITTestLargeArrowBuf.java b/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/ITTestLargeArrowBuf.java
similarity index 93%
rename from java/memory/memory-netty/src/test/java/org/apache/arrow/memory/ITTestLargeArrowBuf.java
rename to java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/ITTestLargeArrowBuf.java
index fa8d510e361..71dba73d289 100644
--- a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/ITTestLargeArrowBuf.java
+++ b/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/ITTestLargeArrowBuf.java
@@ -15,10 +15,13 @@
* limitations under the License.
*/
-package org.apache.arrow.memory;
+package org.apache.arrow.memory.netty;
import static org.junit.Assert.assertEquals;
+import org.apache.arrow.memory.ArrowBuf;
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.memory.RootAllocator;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/TestAllocationManagerNetty.java b/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestAllocationManagerNetty.java
similarity index 90%
rename from java/memory/memory-netty/src/test/java/org/apache/arrow/memory/TestAllocationManagerNetty.java
rename to java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestAllocationManagerNetty.java
index 2dbd56480b8..7f1e34ddc5f 100644
--- a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/TestAllocationManagerNetty.java
+++ b/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestAllocationManagerNetty.java
@@ -15,10 +15,12 @@
* limitations under the License.
*/
-package org.apache.arrow.memory;
+package org.apache.arrow.memory.netty;
import static org.junit.Assert.assertEquals;
+import org.apache.arrow.memory.AllocationManager;
+import org.apache.arrow.memory.DefaultAllocationManagerOption;
import org.junit.Test;
/**
diff --git a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/TestEmptyArrowBuf.java b/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestEmptyArrowBuf.java
similarity index 90%
rename from java/memory/memory-netty/src/test/java/org/apache/arrow/memory/TestEmptyArrowBuf.java
rename to java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestEmptyArrowBuf.java
index 3fd7ce74aab..b9948083e6f 100644
--- a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/TestEmptyArrowBuf.java
+++ b/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestEmptyArrowBuf.java
@@ -15,10 +15,13 @@
* limitations under the License.
*/
-package org.apache.arrow.memory;
+package org.apache.arrow.memory.netty;
import static org.junit.Assert.assertEquals;
+import org.apache.arrow.memory.ArrowBuf;
+import org.apache.arrow.memory.ReferenceManager;
+import org.apache.arrow.memory.RootAllocator;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -47,8 +50,8 @@ public static void afterClass() {
public void testZeroBuf() {
// Exercise the historical log inside the empty ArrowBuf. This is initialized statically, and there is a circular
// dependency between ArrowBuf and BaseAllocator, so if the initialization happens in the wrong order, the
- // historical log will be null even though BaseAllocator.DEBUG is true.
- allocator.getEmpty().print(new StringBuilder(), 0, BaseAllocator.Verbosity.LOG_WITH_STACKTRACE);
+ // historical log will be null even though RootAllocator.DEBUG is true.
+ allocator.getEmpty().print(new StringBuilder(), 0, RootAllocator.Verbosity.LOG_WITH_STACKTRACE);
}
@Test
diff --git a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/TestEndianness.java b/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestEndianness.java
similarity index 92%
rename from java/memory/memory-netty/src/test/java/org/apache/arrow/memory/TestEndianness.java
rename to java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestEndianness.java
index dcaeb24889e..a782523cbc6 100644
--- a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/TestEndianness.java
+++ b/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestEndianness.java
@@ -15,12 +15,14 @@
* limitations under the License.
*/
-package org.apache.arrow.memory;
+package org.apache.arrow.memory.netty;
import static org.junit.Assert.assertEquals;
import java.nio.ByteOrder;
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.memory.RootAllocator;
import org.junit.Test;
import io.netty.buffer.ByteBuf;
diff --git a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/TestNettyAllocationManager.java b/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestNettyAllocationManager.java
similarity index 87%
rename from java/memory/memory-netty/src/test/java/org/apache/arrow/memory/TestNettyAllocationManager.java
rename to java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestNettyAllocationManager.java
index 1b64cd73363..39692c96ceb 100644
--- a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/TestNettyAllocationManager.java
+++ b/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestNettyAllocationManager.java
@@ -15,13 +15,18 @@
* limitations under the License.
*/
-package org.apache.arrow.memory;
+package org.apache.arrow.memory.netty;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import org.apache.arrow.memory.AllocationManager;
+import org.apache.arrow.memory.ArrowBuf;
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.memory.BufferLedger;
+import org.apache.arrow.memory.RootAllocator;
import org.junit.Test;
/**
@@ -31,8 +36,8 @@ public class TestNettyAllocationManager {
static int CUSTOMIZED_ALLOCATION_CUTOFF_VALUE = 1024;
- private BaseAllocator createCustomizedAllocator() {
- return new RootAllocator(BaseAllocator.configBuilder()
+ private RootAllocator createCustomizedAllocator() {
+ return new RootAllocator(RootAllocator.configBuilder()
.allocationManagerFactory(new AllocationManager.Factory() {
@Override
public AllocationManager create(BufferAllocator accountingAllocator, long size) {
@@ -65,7 +70,7 @@ private void readWriteArrowBuf(ArrowBuf buffer) {
@Test
public void testSmallBufferAllocation() {
final long bufSize = CUSTOMIZED_ALLOCATION_CUTOFF_VALUE - 512L;
- try (BaseAllocator allocator = createCustomizedAllocator();
+ try (RootAllocator allocator = createCustomizedAllocator();
ArrowBuf buffer = allocator.buffer(bufSize)) {
assertTrue(buffer.getReferenceManager() instanceof BufferLedger);
@@ -89,7 +94,7 @@ public void testSmallBufferAllocation() {
@Test
public void testLargeBufferAllocation() {
final long bufSize = CUSTOMIZED_ALLOCATION_CUTOFF_VALUE + 1024L;
- try (BaseAllocator allocator = createCustomizedAllocator();
+ try (RootAllocator allocator = createCustomizedAllocator();
ArrowBuf buffer = allocator.buffer(bufSize)) {
assertTrue(buffer.getReferenceManager() instanceof BufferLedger);
BufferLedger bufferLedger = (BufferLedger) buffer.getReferenceManager();
diff --git a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestNettyAllocator.java b/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestNettyAllocator.java
new file mode 100644
index 00000000000..07fdc3f784e
--- /dev/null
+++ b/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestNettyAllocator.java
@@ -0,0 +1,81 @@
+/*
+ * 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.netty;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collections;
+import java.util.stream.Collectors;
+
+import org.apache.arrow.memory.ArrowBuf;
+import org.apache.arrow.memory.ReferenceManager;
+import org.junit.Test;
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.read.ListAppender;
+import io.netty.buffer.PooledByteBufAllocatorL;
+
+/**
+ * Test netty allocators.
+ */
+public class TestNettyAllocator {
+
+ @Test
+ public void testMemoryUsage() {
+ ListAppender memoryLogsAppender = new ListAppender<>();
+ memoryLogsAppender.list = Collections.synchronizedList(memoryLogsAppender.list);
+ Logger logger = (Logger) LoggerFactory.getLogger("arrow.allocator");
+ try {
+ logger.setLevel(Level.TRACE);
+ logger.addAppender(memoryLogsAppender);
+ memoryLogsAppender.start();
+ try (ArrowBuf buf = new ArrowBuf(ReferenceManager.NO_OP, null,
+ 1024, new PooledByteBufAllocatorL().empty.memoryAddress())) {
+ buf.memoryAddress();
+ }
+ boolean result = false;
+ long startTime = System.currentTimeMillis();
+ while ((System.currentTimeMillis() - startTime) < 10000) { // 10 seconds maximum for time to read logs
+ // Lock on the list backing the appender since a background thread might try to add more logs
+ // while stream() is iterating over list elements. This would throw a flakey ConcurrentModificationException.
+ synchronized (memoryLogsAppender.list) {
+ result = memoryLogsAppender.list.stream()
+ .anyMatch(
+ log -> log.toString().contains("Memory Usage: \n") &&
+ log.toString().contains("Large buffers outstanding: ") &&
+ log.toString().contains("Normal buffers outstanding: ") &&
+ log.getLevel().equals(Level.TRACE)
+ );
+ }
+ if (result) {
+ break;
+ }
+ }
+ assertTrue("Log messages are:\n" +
+ memoryLogsAppender.list.stream().map(ILoggingEvent::toString).collect(Collectors.joining("\n")),
+ result);
+ } finally {
+ memoryLogsAppender.stop();
+ logger.detachAppender(memoryLogsAppender);
+ logger.setLevel(null);
+ }
+ }
+}
diff --git a/java/memory/memory-unsafe/pom.xml b/java/memory/memory-unsafe/pom.xml
index 9f813730819..5ef4e8a9149 100644
--- a/java/memory/memory-unsafe/pom.xml
+++ b/java/memory/memory-unsafe/pom.xml
@@ -27,6 +27,10 @@
org.apache.arrow
arrow-memory-core
+
+ org.immutables
+ value
+
diff --git a/java/memory/memory-unsafe/src/main/java/module-info.java b/java/memory/memory-unsafe/src/main/java/module-info.java
new file mode 100644
index 00000000000..aa340d21716
--- /dev/null
+++ b/java/memory/memory-unsafe/src/main/java/module-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+module org.apache.arrow.memory.unsafe {
+ exports org.apache.arrow.memory.unsafe to org.apache.arrow.memory.core;
+
+ requires org.apache.arrow.memory.core;
+}
diff --git a/java/memory/memory-unsafe/src/main/java/org/apache/arrow/memory/DefaultAllocationManagerFactory.java b/java/memory/memory-unsafe/src/main/java/org/apache/arrow/memory/unsafe/DefaultAllocationManagerFactory.java
similarity index 87%
rename from java/memory/memory-unsafe/src/main/java/org/apache/arrow/memory/DefaultAllocationManagerFactory.java
rename to java/memory/memory-unsafe/src/main/java/org/apache/arrow/memory/unsafe/DefaultAllocationManagerFactory.java
index 720c3d02d23..dfb6c706856 100644
--- a/java/memory/memory-unsafe/src/main/java/org/apache/arrow/memory/DefaultAllocationManagerFactory.java
+++ b/java/memory/memory-unsafe/src/main/java/org/apache/arrow/memory/unsafe/DefaultAllocationManagerFactory.java
@@ -15,7 +15,11 @@
* limitations under the License.
*/
-package org.apache.arrow.memory;
+package org.apache.arrow.memory.unsafe;
+
+import org.apache.arrow.memory.AllocationManager;
+import org.apache.arrow.memory.ArrowBuf;
+import org.apache.arrow.memory.BufferAllocator;
/**
* The default Allocation Manager Factory for a module.
diff --git a/java/memory/memory-unsafe/src/main/java/org/apache/arrow/memory/UnsafeAllocationManager.java b/java/memory/memory-unsafe/src/main/java/org/apache/arrow/memory/unsafe/UnsafeAllocationManager.java
similarity index 89%
rename from java/memory/memory-unsafe/src/main/java/org/apache/arrow/memory/UnsafeAllocationManager.java
rename to java/memory/memory-unsafe/src/main/java/org/apache/arrow/memory/unsafe/UnsafeAllocationManager.java
index b10aba3598d..3468a6ec65c 100644
--- a/java/memory/memory-unsafe/src/main/java/org/apache/arrow/memory/UnsafeAllocationManager.java
+++ b/java/memory/memory-unsafe/src/main/java/org/apache/arrow/memory/unsafe/UnsafeAllocationManager.java
@@ -15,8 +15,12 @@
* limitations under the License.
*/
-package org.apache.arrow.memory;
+package org.apache.arrow.memory.unsafe;
+import org.apache.arrow.memory.AllocationManager;
+import org.apache.arrow.memory.ArrowBuf;
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.memory.ReferenceManager;
import org.apache.arrow.memory.util.MemoryUtil;
/**
diff --git a/java/memory/memory-unsafe/src/test/java/org/apache/arrow/memory/TestAllocationManagerUnsafe.java b/java/memory/memory-unsafe/src/test/java/org/apache/arrow/memory/unsafe/TestAllocationManagerUnsafe.java
similarity index 90%
rename from java/memory/memory-unsafe/src/test/java/org/apache/arrow/memory/TestAllocationManagerUnsafe.java
rename to java/memory/memory-unsafe/src/test/java/org/apache/arrow/memory/unsafe/TestAllocationManagerUnsafe.java
index 33abe92e50f..f1ca96eea0f 100644
--- a/java/memory/memory-unsafe/src/test/java/org/apache/arrow/memory/TestAllocationManagerUnsafe.java
+++ b/java/memory/memory-unsafe/src/test/java/org/apache/arrow/memory/unsafe/TestAllocationManagerUnsafe.java
@@ -15,10 +15,12 @@
* limitations under the License.
*/
-package org.apache.arrow.memory;
+package org.apache.arrow.memory.unsafe;
import static org.junit.Assert.assertEquals;
+import org.apache.arrow.memory.AllocationManager;
+import org.apache.arrow.memory.DefaultAllocationManagerOption;
import org.junit.Test;
/**
diff --git a/java/memory/memory-unsafe/src/test/java/org/apache/arrow/memory/TestUnsafeAllocationManager.java b/java/memory/memory-unsafe/src/test/java/org/apache/arrow/memory/unsafe/TestUnsafeAllocationManager.java
similarity index 82%
rename from java/memory/memory-unsafe/src/test/java/org/apache/arrow/memory/TestUnsafeAllocationManager.java
rename to java/memory/memory-unsafe/src/test/java/org/apache/arrow/memory/unsafe/TestUnsafeAllocationManager.java
index c15882a37a6..5d74c398e26 100644
--- a/java/memory/memory-unsafe/src/test/java/org/apache/arrow/memory/TestUnsafeAllocationManager.java
+++ b/java/memory/memory-unsafe/src/test/java/org/apache/arrow/memory/unsafe/TestUnsafeAllocationManager.java
@@ -15,11 +15,16 @@
* limitations under the License.
*/
-package org.apache.arrow.memory;
+package org.apache.arrow.memory.unsafe;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import org.apache.arrow.memory.AllocationManager;
+import org.apache.arrow.memory.ArrowBuf;
+import org.apache.arrow.memory.BufferLedger;
+import org.apache.arrow.memory.RootAllocator;
+import org.apache.arrow.memory.unsafe.UnsafeAllocationManager;
import org.junit.Test;
/**
@@ -27,8 +32,8 @@
*/
public class TestUnsafeAllocationManager {
- private BaseAllocator createUnsafeAllocator() {
- return new RootAllocator(BaseAllocator.configBuilder().allocationManagerFactory(UnsafeAllocationManager.FACTORY)
+ private RootAllocator createUnsafeAllocator() {
+ return new RootAllocator(RootAllocator.configBuilder().allocationManagerFactory(UnsafeAllocationManager.FACTORY)
.build());
}
@@ -51,7 +56,7 @@ private void readWriteArrowBuf(ArrowBuf buffer) {
@Test
public void testBufferAllocation() {
final long bufSize = 4096L;
- try (BaseAllocator allocator = createUnsafeAllocator();
+ try (RootAllocator allocator = createUnsafeAllocator();
ArrowBuf buffer = allocator.buffer(bufSize)) {
assertTrue(buffer.getReferenceManager() instanceof BufferLedger);
BufferLedger bufferLedger = (BufferLedger) buffer.getReferenceManager();
diff --git a/java/memory/pom.xml b/java/memory/pom.xml
index c10263b97f1..55fbb90353f 100644
--- a/java/memory/pom.xml
+++ b/java/memory/pom.xml
@@ -23,6 +23,7 @@
memory-core
memory-unsafe
+ memory-netty-buffer-patch
memory-netty
diff --git a/java/pom.xml b/java/pom.xml
index a9b80ccdb5d..fc9ed04f27b 100644
--- a/java/pom.xml
+++ b/java/pom.xml
@@ -321,6 +321,7 @@
+ **/module-info.java
dev/checkstyle/checkstyle.xml
dev/checkstyle/checkstyle.license
dev/checkstyle/suppressions.xml
@@ -371,6 +372,17 @@
+
+ org.apache.arrow.maven.plugins
+ module-info-compiler-maven-plugin
+
+
+
+ module-info-compile
+
+
+
+
@@ -400,6 +412,7 @@
maven-compiler-plugin
${maven-compiler-plugin.version}
+ **/module-info.java
false
@@ -546,6 +559,11 @@
+
+ org.apache.arrow.maven.plugins
+ module-info-compiler-maven-plugin
+ ${project.version}
+
@@ -735,6 +753,7 @@
+ maven
bom
format
memory
@@ -870,7 +889,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- --add-opens=java.base/java.nio=ALL-UNNAMED
+ --add-opens java.base/jdk.internal.misc=io.netty.common --patch-module=io.netty.buffer=${project.basedir}/../memory-netty-buffer-patch/target/arrow-memory-netty-buffer-patch-${project.version}.jar --add-opens=java.base/java.nio=org.apache.arrow.memory.core,io.netty.common,ALL-UNNAMED
@@ -1236,7 +1255,6 @@
-
diff --git a/java/vector/pom.xml b/java/vector/pom.xml
index 17d8f312a52..a4292449c9c 100644
--- a/java/vector/pom.xml
+++ b/java/vector/pom.xml
@@ -30,6 +30,10 @@
org.apache.arrow
arrow-memory-core
+
+ org.immutables
+ value
+
com.fasterxml.jackson.core
jackson-core
diff --git a/java/vector/src/main/java/module-info.java b/java/vector/src/main/java/module-info.java
new file mode 100644
index 00000000000..e8a4467f51c
--- /dev/null
+++ b/java/vector/src/main/java/module-info.java
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+
+module org.apache.arrow.vector {
+ exports org.apache.arrow.vector;
+ exports org.apache.arrow.vector.compare;
+ exports org.apache.arrow.vector.compare.util;
+ exports org.apache.arrow.vector.complex;
+ exports org.apache.arrow.vector.complex.impl;
+ exports org.apache.arrow.vector.complex.reader;
+ exports org.apache.arrow.vector.complex.writer;
+ exports org.apache.arrow.vector.compression;
+ exports org.apache.arrow.vector.dictionary;
+ exports org.apache.arrow.vector.holders;
+ exports org.apache.arrow.vector.ipc;
+ exports org.apache.arrow.vector.ipc.message;
+ exports org.apache.arrow.vector.table;
+ exports org.apache.arrow.vector.types;
+ exports org.apache.arrow.vector.types.pojo;
+ exports org.apache.arrow.vector.util;
+ exports org.apache.arrow.vector.validate;
+
+ opens org.apache.arrow.vector.types.pojo to com.fasterxml.jackson.databind;
+
+ requires com.fasterxml.jackson.annotation;
+ requires com.fasterxml.jackson.core;
+ requires com.fasterxml.jackson.databind;
+ requires com.fasterxml.jackson.datatype.jsr310;
+ requires flatbuffers.java;
+ requires io.netty.common;
+ requires java.sql;
+ requires jdk.unsupported;
+ requires org.apache.arrow.format;
+ requires org.apache.arrow.memory.core;
+ requires org.apache.commons.codec;
+ requires slf4j.api;
+}
diff --git a/java/vector/src/test/java/org/apache/arrow/util/ArrowTestDataUtil.java b/java/vector/src/test/java/org/apache/arrow/vector/util/ArrowTestDataUtil.java
similarity index 97%
rename from java/vector/src/test/java/org/apache/arrow/util/ArrowTestDataUtil.java
rename to java/vector/src/test/java/org/apache/arrow/vector/util/ArrowTestDataUtil.java
index 120c0adc884..1c525c0c271 100644
--- a/java/vector/src/test/java/org/apache/arrow/util/ArrowTestDataUtil.java
+++ b/java/vector/src/test/java/org/apache/arrow/vector/util/ArrowTestDataUtil.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.arrow.util;
+package org.apache.arrow.vector.util;
import java.nio.file.Path;
import java.nio.file.Paths;
diff --git a/java/vector/src/test/java/org/apache/arrow/util/TestSchemaUtil.java b/java/vector/src/test/java/org/apache/arrow/vector/util/TestSchemaUtil.java
similarity index 98%
rename from java/vector/src/test/java/org/apache/arrow/util/TestSchemaUtil.java
rename to java/vector/src/test/java/org/apache/arrow/vector/util/TestSchemaUtil.java
index cefff838232..52b65840868 100644
--- a/java/vector/src/test/java/org/apache/arrow/util/TestSchemaUtil.java
+++ b/java/vector/src/test/java/org/apache/arrow/vector/util/TestSchemaUtil.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.arrow.util;
+package org.apache.arrow.vector.util;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;