You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by lc...@apache.org on 2022/05/11 21:49:04 UTC

[beam] branch master updated: [BEAM-13695] Add jamm jvm options to Java 11 (#17178)

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

lcwik pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new a1674241c68 [BEAM-13695] Add jamm jvm options to Java 11 (#17178)
a1674241c68 is described below

commit a1674241c6895302d6225c92c0a8f40956a24c04
Author: Kiley Sok <ki...@google.com>
AuthorDate: Wed May 11 14:48:57 2022 -0700

    [BEAM-13695] Add jamm jvm options to Java 11 (#17178)
    
    * Add jamm jvm options to Java 11
    
    * fix test comments
---
 sdks/java/container/boot.go                        |  3 +-
 sdks/java/container/boot_test.go                   | 74 ++++++++++++++++++++++
 sdks/java/container/common.gradle                  |  2 +-
 sdks/java/container/java11/option-jamm.json        | 13 ++++
 .../container/test/disabled/option-disabled.json   |  6 ++
 sdks/java/container/test/empty/README              |  1 +
 sdks/java/container/test/priority/option-high.json | 16 +++++
 sdks/java/container/test/priority/option-low.json  | 16 +++++
 8 files changed, 129 insertions(+), 2 deletions(-)

diff --git a/sdks/java/container/boot.go b/sdks/java/container/boot.go
index f3785730551..d067db2b304 100644
--- a/sdks/java/container/boot.go
+++ b/sdks/java/container/boot.go
@@ -343,7 +343,8 @@ func BuildOptions(metaOptions []*MetaOption) *Options {
 			continue
 		}
 
-		options.JavaArguments = append(options.JavaArguments, meta.Options.JavaArguments...)
+		// Rightmost takes precedence
+		options.JavaArguments = append(meta.Options.JavaArguments, options.JavaArguments...)
 
 		for key, value := range meta.Options.Properties {
 			_, exists := options.Properties[key]
diff --git a/sdks/java/container/boot_test.go b/sdks/java/container/boot_test.go
new file mode 100644
index 00000000000..53942f68343
--- /dev/null
+++ b/sdks/java/container/boot_test.go
@@ -0,0 +1,74 @@
+// 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.
+
+// boot is the boot code for the Java SDK harness container. It is responsible
+// for retrieving staged files and invoking the JVM correctly.
+package main
+
+import (
+  "reflect"
+  "testing"
+)
+
+func TestBuildOptionsEmpty(t *testing.T) {
+  dir := "test/empty"
+  metaOptions, err := LoadMetaOptions(dir)
+  if err != nil {
+    t.Fatalf("Got error %v running LoadMetaOptions", err)
+  }
+  if metaOptions != nil {
+    t.Fatalf("LoadMetaOptions(%v) = %v, want nil", dir, metaOptions)
+  }
+
+  javaOptions := BuildOptions(metaOptions)
+  if len(javaOptions.JavaArguments) != 0 || len(javaOptions.Classpath) != 0 || len(javaOptions.Properties) != 0 {
+    t.Errorf("BuildOptions(%v) = %v, want nil", metaOptions, javaOptions)
+  }
+}
+
+func TestBuildOptionsDisabled(t *testing.T) {
+  metaOptions, err := LoadMetaOptions("test/disabled")
+  if err != nil {
+    t.Fatalf("Got error %v running LoadMetaOptions", err)
+  }
+
+  javaOptions := BuildOptions(metaOptions)
+  if len(javaOptions.JavaArguments) != 0 || len(javaOptions.Classpath) != 0 || len(javaOptions.Properties) != 0 {
+    t.Errorf("BuildOptions(%v) = %v, want nil", metaOptions, javaOptions)
+  }
+}
+
+func TestBuildOptions(t *testing.T) {
+  metaOptions, err := LoadMetaOptions("test/priority")
+  if err != nil {
+    t.Fatalf("Got error %v running LoadMetaOptions", err)
+  }
+
+  javaOptions := BuildOptions(metaOptions)
+  wantJavaArguments := []string{"java_args=low", "java_args=high"}
+  wantClasspath := []string{"classpath_high", "classpath_low"}
+  wantProperties := map[string]string{
+                        "priority":"high",
+                    }
+  if !reflect.DeepEqual(javaOptions.JavaArguments, wantJavaArguments) {
+    t.Errorf("BuildOptions(%v).JavaArguments = %v, want %v", metaOptions, javaOptions.JavaArguments, wantJavaArguments)
+  }
+  if !reflect.DeepEqual(javaOptions.Classpath, wantClasspath) {
+    t.Errorf("BuildOptions(%v).Classpath = %v, want %v", metaOptions, javaOptions.Classpath, wantClasspath)
+  }
+  if !reflect.DeepEqual(javaOptions.Properties, wantProperties) {
+    t.Errorf("BuildOptions(%v).JavaProperties = %v, want %v", metaOptions, javaOptions.Properties, wantProperties)
+  }
+}
diff --git a/sdks/java/container/common.gradle b/sdks/java/container/common.gradle
index 72c643a0445..b9f8da73cbd 100644
--- a/sdks/java/container/common.gradle
+++ b/sdks/java/container/common.gradle
@@ -75,7 +75,7 @@ task copyGolangLicenses(type: Copy) {
 }
 
 task copyJdkOptions(type: Copy) {
-    if (imageJavaVersion == "17") {
+    if (imageJavaVersion == "17" || imageJavaVersion == "11") {
         from "option-jamm.json"
         into "build/target/options"
     }
diff --git a/sdks/java/container/java11/option-jamm.json b/sdks/java/container/java11/option-jamm.json
new file mode 100644
index 00000000000..e994648a8e2
--- /dev/null
+++ b/sdks/java/container/java11/option-jamm.json
@@ -0,0 +1,13 @@
+{
+  "name": "jamm",
+  "enabled": true,
+  "options": {
+    "java_arguments": [
+      "--add-modules=jamm",
+      "--module-path=/opt/apache/beam/jars/jamm.jar",
+      "--add-opens=java.base/java.lang=jamm",
+      "--add-opens=java.base/java.lang.ref=jamm",
+      "--add-opens=java.base/java.util=jamm"
+    ]
+  }
+}
\ No newline at end of file
diff --git a/sdks/java/container/test/disabled/option-disabled.json b/sdks/java/container/test/disabled/option-disabled.json
new file mode 100644
index 00000000000..8ba7e7ff00c
--- /dev/null
+++ b/sdks/java/container/test/disabled/option-disabled.json
@@ -0,0 +1,6 @@
+{
+  "name": "test-disabled",
+  "enabled": false,
+  "options": {
+  }
+}
\ No newline at end of file
diff --git a/sdks/java/container/test/empty/README b/sdks/java/container/test/empty/README
new file mode 100644
index 00000000000..16786ad6f5e
--- /dev/null
+++ b/sdks/java/container/test/empty/README
@@ -0,0 +1 @@
+Empty directory to test boot options
\ No newline at end of file
diff --git a/sdks/java/container/test/priority/option-high.json b/sdks/java/container/test/priority/option-high.json
new file mode 100644
index 00000000000..f7830cc4108
--- /dev/null
+++ b/sdks/java/container/test/priority/option-high.json
@@ -0,0 +1,16 @@
+{
+  "name": "high",
+  "enabled": true,
+  "priority": 100,
+  "options": {
+    "java_arguments": [
+      "java_args=high"
+    ],
+    "classpath": [
+      "classpath_high"
+    ],
+    "properties": {
+      "priority": "high"
+    }
+  }
+}
\ No newline at end of file
diff --git a/sdks/java/container/test/priority/option-low.json b/sdks/java/container/test/priority/option-low.json
new file mode 100644
index 00000000000..b67a8ccdfdf
--- /dev/null
+++ b/sdks/java/container/test/priority/option-low.json
@@ -0,0 +1,16 @@
+{
+  "name": "low",
+  "enabled": true,
+  "priority": 0,
+  "options": {
+    "java_arguments": [
+      "java_args=low"
+    ],
+    "classpath": [
+      "classpath_low"
+    ],
+    "properties": {
+      "priority": "low"
+    }
+  }
+}
\ No newline at end of file