--- a/test/TestCommon.gmk Fri Jan 26 16:20:14 2018 -0800
+++ b/test/TestCommon.gmk Mon Jan 29 08:19:37 2018 -0500
@@ -332,9 +332,45 @@
TEST_SELECTION = $(TESTDIRS)
endif
-ifdef CONCURRENCY
- JTREG_BASIC_OPTIONS += -concurrency:$(CONCURRENCY)
+ifeq ($(UNAME_S), SunOS)
+ NUM_CORES := $(shell LC_MESSAGES=C /usr/sbin/psrinfo -v | grep -c on-line)
+endif
+ifeq ($(UNAME_S), Linux)
+ NUM_CORES := $(shell cat /proc/cpuinfo | grep -c processor)
+endif
+ifeq ($(UNAME_S), Darwin)
+ NUM_CORES := $(shell /usr/sbin/sysctl -n hw.ncpu)
+endif
+ifeq ($(findstring CYGWIN,$(UNAME_S)), CYGWIN)
+ ifneq ($(NUMBER_OF_PROCESSORS), )
+ NUM_CORES := $(NUMBER_OF_PROCESSORS)
+ else
+ ifneq ($(HOTSPOT_BUILD_JOBS), )
+ NUM_CORES := $(HOTSPOT_BUILD_JOBS)
+ else
+ NUM_CORES := 1 # fallback
+ endif
+ endif
endif
+
+ifndef CONCURRENCY_FACTOR
+ CONCURRENCY_FACTOR = 1
+endif
+
+# Concurrency based on min(cores / 2, 12) * CONCURRENCY_FACTOR
+CONCURRENCY := $(shell awk \
+ 'BEGIN { \
+ c = $(NUM_CORES) / 2; \
+ if (c > 12) c = 12; \
+ c = c * $(CONCURRENCY_FACTOR); \
+ if (c < 1) c = 1; \
+ printf "%.0f", c; \
+ }')
+JTREG_BASIC_OPTIONS += -concurrency:$(CONCURRENCY)
+
+# Make sure MaxRAMPercentage is high enough to not cause OOM or swapping since we may end up with a lot of JVM's
+JTREG_BASIC_OPTIONS += -vmoption:-XX:MaxRAMPercentage=$(shell expr 25 / $(CONCURRENCY))
+
ifdef EXTRA_JTREG_OPTIONS
JTREG_BASIC_OPTIONS += $(EXTRA_JTREG_OPTIONS)
endif