Skip to content

Commit

Permalink
Merge pull request technomancy#2324 from acron0/fix/cgroups-jvm-opts-…
Browse files Browse the repository at this point in the history
…boolean-logic-2

Fix boolean logic in Java version check for cgroups memory limit JVM option
  • Loading branch information
technomancy authored Oct 19, 2017
2 parents 482b968 + c447b43 commit 3af03da
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 6 additions & 5 deletions leiningen-core/src/leiningen/core/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -523,13 +523,14 @@

;; give reasonable -Xmx defaults when containerized, if JVM is new enough
;; https://blogs.oracle.com/java-platform-group/java-se-support-for-docker-cpu-and-memory-limits
(defn use-cgroups-memory-limit-for-heap? [version]
(let [[v u] (re-seq #"[^-_]+" version)]
(and (= v "1.8.0") (>= (Integer. u) 131))))

(def ^:private cgroups-jvm-opts
;; this assumes the JVM version Leiningen is run under matches the project
(let [[v u] (re-seq #"[^-_]+" (System/getProperty "java.runtime.version"))]
(if (or (and (= v "1.8.0") (>= (Integer. u) 131))
(not= v "1.7.0")
(not= v "1.6.0"))
["-XX:+UnlockExperimentalVMOptions" "-XX:+UseCGroupMemoryLimitForHeap"])))
(if (use-cgroups-memory-limit-for-heap? (System/getProperty "java.runtime.version"))
["-XX:+UnlockExperimentalVMOptions" "-XX:+UseCGroupMemoryLimitForHeap"]))

(def default-jvm-opts
[;; actually does the opposite; omits trace unless this is set
Expand Down
6 changes: 6 additions & 0 deletions leiningen-core/test/leiningen/core/test/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -613,3 +613,9 @@
[:e :b :c :d] "target/e+bcd"
[:c :a :b :d] "target/c+ab+d"
[:a] "target/a")))

(deftest cgroups-applied-properly
(is (use-cgroups-memory-limit-for-heap? "1.8.0_144-b01"))
(is (not (use-cgroups-memory-limit-for-heap? "1.8.0_111-internal")))
(is (not (use-cgroups-memory-limit-for-heap? "1.7.0_103")))
(is (not (use-cgroups-memory-limit-for-heap? "1.9.0_12-b06"))))

0 comments on commit 3af03da

Please sign in to comment.