This is an automated email from the ASF dual-hosted git repository.

dpitkin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new a49dbcc8bd GH-43394: [Java][Benchmarking] Fix Java benchmarks for Java 
17+ (#43395)
a49dbcc8bd is described below

commit a49dbcc8bda170f48f3cc07f5453105129015db0
Author: Dane Pitkin <[email protected]>
AuthorDate: Wed Jul 24 11:11:43 2024 -0400

    GH-43394: [Java][Benchmarking] Fix Java benchmarks for Java 17+ (#43395)
    
    ### Rationale for this change
    
    Now that Arrow Java has moved from Java 8 -> Java 11, we need to add 
`--add-opens` when running Java.
    
    ### What changes are included in this PR?
    
    * Add 
`--add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED` to 
`_JAVA_OPTIONS` in archery.
    * Clean up test code only used for Java 8
    
    ### Are these changes tested?
    
    To be verified via CI and ursabot.
    
    ### Are there any user-facing changes?
    
    No
    * GitHub Issue: #43394
    
    Authored-by: Dane Pitkin <[email protected]>
    Signed-off-by: Dane Pitkin <[email protected]>
---
 dev/archery/archery/integration/tester_java.py | 29 ++++----------------------
 dev/archery/archery/lang/java.py               | 12 ++++++++++-
 2 files changed, 15 insertions(+), 26 deletions(-)

diff --git a/dev/archery/archery/integration/tester_java.py 
b/dev/archery/archery/integration/tester_java.py
index 9b14c6939c..8d207d3393 100644
--- a/dev/archery/archery/integration/tester_java.py
+++ b/dev/archery/archery/integration/tester_java.py
@@ -46,6 +46,7 @@ def load_version_from_pom():
 _JAVA_OPTS = [
     "-Dio.netty.tryReflectionSetAccessible=true",
     "-Darrow.struct.conflict.policy=CONFLICT_APPEND",
+    "--add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED",
     # GH-39113: avoid failures accessing files in `/tmp/hsperfdata_...`
     "-XX:-UsePerfData",
 ]
@@ -88,24 +89,13 @@ def setup_jpype():
     import jpype
     jar_path = f"{_ARROW_TOOLS_JAR}:{_ARROW_C_DATA_JAR}"
     # XXX Didn't manage to tone down the logging level here (DEBUG -> INFO)
-    java_opts = _JAVA_OPTS[:]
-    proc = subprocess.run(
-        ['java', '--add-opens'],
-        stderr=subprocess.PIPE,
-        stdout=subprocess.PIPE,
-        text=True)
-    if 'Unrecognized option: --add-opens' not in proc.stderr:
-        # Java 9+
-        java_opts.append(
-            '--add-opens=java.base/java.nio='
-            'org.apache.arrow.memory.core,ALL-UNNAMED')
     jpype.startJVM(jpype.getDefaultJVMPath(),
                    "-Djava.class.path=" + jar_path,
                    # This flag is too heavy for IPC and Flight tests
                    "-Darrow.memory.debug.allocator=true",
                    # Reduce internal use of signals by the JVM
                    "-Xrs",
-                   *java_opts)
+                   *_JAVA_OPTS)
 
 
 class _CDataBase:
@@ -253,20 +243,9 @@ class JavaTester(Tester):
 
     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
-        # Detect whether we're on Java 8 or Java 9+
         self._java_opts = _JAVA_OPTS[:]
-        proc = subprocess.run(
-            ['java', '--add-opens'],
-            stderr=subprocess.PIPE,
-            stdout=subprocess.PIPE,
-            text=True)
-        if 'Unrecognized option: --add-opens' not in proc.stderr:
-            # Java 9+
-            self._java_opts.append(
-                '--add-opens=java.base/java.nio='
-                'org.apache.arrow.memory.core,ALL-UNNAMED')
-            self._java_opts.append(
-                '--add-reads=org.apache.arrow.flight.core=ALL-UNNAMED')
+        self._java_opts.append(
+            '--add-reads=org.apache.arrow.flight.core=ALL-UNNAMED')
 
     def _run(self, arrow_path=None, json_path=None, command='VALIDATE'):
         cmd = (
diff --git a/dev/archery/archery/lang/java.py b/dev/archery/archery/lang/java.py
index bc169adf64..0087208d34 100644
--- a/dev/archery/archery/lang/java.py
+++ b/dev/archery/archery/lang/java.py
@@ -34,8 +34,11 @@ class Jar(CommandStackMixin, Java):
 
 
 class JavaConfiguration:
-    def __init__(self,
+    REQUIRED_JAVA_OPTIONS = [
+        
"--add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED",
+    ]
 
+    def __init__(self,
                  # toolchain
                  java_home=None, java_options=None,
                  # build & benchmark
@@ -43,6 +46,13 @@ class JavaConfiguration:
         self.java_home = java_home
         self.java_options = java_options
 
+        if self.java_options is None:
+            self.java_options = " ".join(self.REQUIRED_JAVA_OPTIONS)
+        else:
+            for option in self.REQUIRED_JAVA_OPTIONS:
+                if option not in self.java_options:
+                    self.java_options += " " + option
+
         self.build_extras = list(build_extras) if build_extras else []
         self.benchmark_extras = list(
             benchmark_extras) if benchmark_extras else []

Reply via email to