Skip to content

Commit 83e211f

Browse files
Move to Java 17 (migrate source code from Java 8) (#6462)
* Prepare to use Java 17 as minimal version * See #6219 Pattern Matching for instanceof uses (Java 14/16) * See #6219 - Implicit Typing with var (Java 10) * See #6219 - Using Switch Expressions / yield Keyword (Java 14) * See #6219 - Using Text Blocks (Java 15) * See #6219 - some tunning / formating style * See #6219 - tunning code * See #6219 - Update Java argline params / remove java 8 / 9 args/comments * See #6219 - formating code * Remove not standard options for Java 17 * See #6219 - refactor CompOper to an enum * See #6219 - fix unnecessary yield usage in the switch expression * See #6219 - Optimize the code, fix formatting issue
1 parent 77675e0 commit 83e211f

38 files changed

Lines changed: 496 additions & 510 deletions

File tree

bin/jmeter

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,19 @@ if [ -z "$JAVA_HOME" ]; then
115115
JAVA_HOME="$JRE_HOME"
116116
fi
117117

118-
#--add-opens if JAVA 9
119-
JAVA9_OPTS=
118+
# Module access for modern Java versions (required for JMeter components)
119+
JAVA_OPTS="--add-opens java.desktop/sun.awt=ALL-UNNAMED --add-opens java.desktop/sun.swing=ALL-UNNAMED --add-opens java.desktop/javax.swing.text.html=ALL-UNNAMED --add-opens java.desktop/java.awt=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.text=ALL-UNNAMED --add-opens=java.desktop/sun.awt.X11=ALL-UNNAMED --add-opens=java.desktop/sun.awt.shell=ALL-UNNAMED"
120120

121121
# Minimal version to run JMeter
122-
MINIMAL_VERSION=8
122+
MINIMAL_VERSION=17
123123

124-
# Check if version is from OpenJDK or Oracle Hotspot JVM prior to 9 containing 1.${version}.x
124+
# Check if version meets the minimal requirement
125125
CURRENT_VERSION=`"${JAVA_HOME}/bin/java" -version 2>&1 | awk -F'"' '/version/ {gsub("^1[.]", "", $2); gsub("[^0-9].*$", "", $2); print $2}'`
126126

127-
# Check if Java is present and the minimal version requirement
128-
if [ "$CURRENT_VERSION" -gt "$MINIMAL_VERSION" ]; then
129-
JAVA9_OPTS="--add-opens java.desktop/sun.awt=ALL-UNNAMED --add-opens java.desktop/sun.swing=ALL-UNNAMED --add-opens java.desktop/javax.swing.text.html=ALL-UNNAMED --add-opens java.desktop/java.awt=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.text=ALL-UNNAMED --add-opens=java.desktop/sun.awt.X11=ALL-UNNAMED --add-opens=java.desktop/sun.awt.shell=ALL-UNNAMED"
127+
# Check if Java is present and meets the minimal version requirement
128+
if [ "$CURRENT_VERSION" -lt "$MINIMAL_VERSION" ]; then
129+
echo "ERROR: Java version $CURRENT_VERSION is too low. JMeter requires Java $MINIMAL_VERSION or higher."
130+
exit 1
130131
fi
131132

132133
: "${JMETER_OPTS:=""}"
@@ -169,15 +170,19 @@ esac
169170
# Default to en_EN
170171
: "${JMETER_LANGUAGE:="-Duser.language=en -Duser.region=EN"}"
171172

172-
# Uncomment this to generate GC verbose file with Java prior to 9
173-
# VERBOSE_GC="-verbose:gc -Xloggc:gc_jmeter_%p.log -XX:+PrintGCDetails -XX:+PrintGCCause -XX:+PrintTenuringDistribution -XX:+PrintHeapAtGC -XX:+PrintGCApplicationConcurrentTime -XX:+PrintAdaptiveSizePolicy -XX:+PrintGCApplicationStoppedTime -XX:+PrintGCDateStamps"
173+
# Legacy GC verbose options removed (Java 8/9 support discontinued)
174+
175+
# Optimized GC logging for Java 17 with structured output and performance analysis
176+
# Uncomment to enable comprehensive GC logging with rotation and detailed metrics
177+
# VERBOSE_GC="-Xlog:gc,gc+heap,gc+regions,gc+refine,gc+phases:gc_jmeter_%p_%t.log:time,level,tags:filecount=5,filesize=50M"
178+
179+
# Alternative: Minimal GC logging for production (uncomment if needed)
180+
# VERBOSE_GC="-Xlog:gc:gc_jmeter_%p.log:time"
174181

175-
# Uncomment this to generate GC verbose file with Java 9 and above
176-
# VERBOSE_GC="-Xlog:gc*,gc+age=trace,gc+heap=debug:file=gc_jmeter_%p.log"
182+
# Docker support for Java 17+
183+
# Modern container memory detection is automatic in Java 17+
184+
# RUN_IN_DOCKER="-XX:+UseContainerSupport"
177185

178-
# Uncomment this if you run JMeter in DOCKER (need Java SE 8u131 or JDK 9)
179-
# see https://blogs.oracle.com/java-platform-group/java-se-support-for-docker-cpu-and-memory-limits
180-
# RUN_IN_DOCKER="-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap"
181186

182187
# Finally, some tracing to help in case things go astray:
183188
# You may want to add those settings:
@@ -191,7 +196,7 @@ SYSTEM_PROPS="-Djava.security.egd=file:/dev/urandom"
191196
SERVER="-server"
192197

193198
if [ -z "${JMETER_COMPLETE_ARGS}" ]; then
194-
ARGS="$JAVA9_OPTS $SERVER $DUMP $HEAP $VERBOSE_GC $GC_ALGO $SYSTEM_PROPS $JMETER_LANGUAGE $RUN_IN_DOCKER"
199+
ARGS="$JAVA_OPTS $SERVER $DUMP $HEAP $VERBOSE_GC $GC_ALGO $SYSTEM_PROPS $JMETER_LANGUAGE $RUN_IN_DOCKER"
195200
else
196201
ARGS=""
197202
fi

bin/jmeter.bat

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,19 @@ if not defined JMETER_LANGUAGE (
7878
)
7979

8080
rem Minimal version to run JMeter
81-
set MINIMAL_VERSION=1.8.0
81+
set MINIMAL_VERSION=17.0.0
8282

8383

84-
rem --add-opens if JAVA 9
85-
set JAVA9_OPTS=
84+
rem Optimized GC logging for Java 17 with structured output and performance analysis
85+
rem Uncomment to enable comprehensive GC logging with rotation and detailed metrics
86+
rem set VERBOSE_GC=-Xlog:gc,gc+heap,gc+regions,gc+refine,gc+phases:gc_jmeter_%%p_%%t.log:time,level,tags:filecount=5,filesize=50M
8687

88+
rem Alternative: Minimal GC logging for production (uncomment if needed)
89+
rem set VERBOSE_GC=-Xlog:gc:gc_jmeter_%%p.log:time
90+
91+
92+
rem Module access for modern Java versions (required for JMeter components)
93+
set JAVA_OPTS=--add-opens java.desktop/sun.awt=ALL-UNNAMED --add-opens java.desktop/sun.swing=ALL-UNNAMED --add-opens java.desktop/javax.swing.text.html=ALL-UNNAMED --add-opens java.desktop/java.awt=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.text=ALL-UNNAMED --add-opens=java.desktop/sun.awt.shell=ALL-UNNAMED
8794

8895
for /f "tokens=3" %%g in ('java -version 2^>^&1 ^| findstr /i "version"') do (
8996
rem @echo Debug Output: %%g
@@ -95,36 +102,24 @@ if not defined JAVAVER (
95102
goto pause
96103
)
97104

98-
99-
100-
rem Check if version is from OpenJDK or Oracle Hotspot JVM prior to 9 containing 1.${version}.x
101-
rem JAVAVER will be equal to "9.0.4" (quotes are part of the value) for Oracle Java 9
102-
rem JAVAVER will be equal to "1.8.0_161" (quotes are part of the value) for Oracle Java 8
103-
rem so we extract 2 chars starting from index 1
104-
IF "%JAVAVER:~1,2%"=="1." (
105-
set JAVAVER=%JAVAVER:"=%
106-
for /f "delims=. tokens=1-3" %%v in ("%JAVAVER%") do (
107-
set current_minor=%%w
105+
rem Extract major version number from Java version string
106+
for /f "delims=. tokens=1" %%v in ("%JAVAVER:~1,-1%") do (
107+
set current_major=%%v
108108
)
109-
) else (
110-
rem Java 9 at least
111-
set current_minor=9
112-
set JAVA9_OPTS=--add-opens java.desktop/sun.awt=ALL-UNNAMED --add-opens java.desktop/sun.swing=ALL-UNNAMED --add-opens java.desktop/javax.swing.text.html=ALL-UNNAMED --add-opens java.desktop/java.awt=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.text=ALL-UNNAMED --add-opens=java.desktop/sun.awt.shell=ALL-UNNAMED
113-
)
114-
115109

116-
for /f "delims=. tokens=1-3" %%v in ("%MINIMAL_VERSION%") do (
117-
set minimal_minor=%%w
110+
rem Extract minimal major version
111+
for /f "delims=. tokens=1" %%v in ("%MINIMAL_VERSION%") do (
112+
set minimal_major=%%v
118113
)
119114

120-
if not defined current_minor (
115+
if not defined current_major (
121116
@echo Not able to find Java executable or version. Please check your Java installation.
122117
set ERRORLEVEL=2
123118
goto pause
124119
)
125-
rem @echo Debug: CURRENT=%current_minor% - MINIMAL=%minimal_minor%
126-
if %current_minor% LSS %minimal_minor% (
127-
@echo Error: Java version -- %JAVAVER% -- is too low to run JMeter. Needs a Java version greater than or equal to %MINIMAL_VERSION%
120+
121+
if %current_major% LSS %minimal_major% (
122+
@echo Error: Java version -- %JAVAVER% -- is too low to run JMeter. Needs Java %MINIMAL_VERSION% or higher.
128123
set ERRORLEVEL=3
129124
goto pause
130125
)
@@ -151,13 +146,7 @@ if not defined HEAP (
151146
set HEAP=-Xms1g -Xmx1g -XX:MaxMetaspaceSize=256m
152147
)
153148

154-
rem Uncomment this to generate GC verbose file with Java prior to 9
155-
rem set VERBOSE_GC=-verbose:gc -Xloggc:gc_jmeter_%%p.log -XX:+PrintGCDetails -XX:+PrintGCCause -XX:+PrintTenuringDistribution -XX:+PrintHeapAtGC -XX:+PrintGCApplicationConcurrentTime -XX:+PrintGCApplicationStoppedTime -XX:+PrintGCDateStamps -XX:+PrintAdaptiveSizePolicy
156-
157-
rem Uncomment this to generate GC verbose file with Java 9 and above
158-
rem set VERBOSE_GC=-Xlog:gc*,gc+age=trace,gc+heap=debug:file=gc_jmeter_%%p.log
159-
rem You may want to add those settings
160-
rem -XX:+ParallelRefProcEnabled -XX:+PerfDisableSharedMem
149+
rem Legacy GC verbose options removed (Java 8/9 support discontinued)
161150
if not defined GC_ALGO (
162151
set GC_ALGO=-XX:+UseG1GC -XX:MaxGCPauseMillis=100 -XX:G1ReservePercent=20
163152
)
@@ -167,9 +156,9 @@ set SYSTEM_PROPS=-Djava.security.egd=file:/dev/urandom
167156
rem Always dump on OOM (does not cost anything unless triggered)
168157
set DUMP=-XX:+HeapDumpOnOutOfMemoryError
169158

170-
rem Uncomment this if you run JMeter in DOCKER (need Java SE 8u131 or JDK 9)
171-
rem see https://blogs.oracle.com/java-platform-group/java-se-support-for-docker-cpu-and-memory-limits
172-
rem set RUN_IN_DOCKER=-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap
159+
rem Docker support for Java 17+
160+
rem Modern container memory detection is automatic in Java 17+
161+
rem set RUN_IN_DOCKER=-XX:+UseContainerSupport
173162

174163
rem Additional settings that might help improve GUI performance on some platforms
175164
rem See: http://www.oracle.com/technetwork/java/perf-graphics-135933.html
@@ -188,7 +177,7 @@ if not defined DDRAW (
188177

189178
rem Collect the settings defined above
190179
if not defined JMETER_COMPLETE_ARGS (
191-
set ARGS=%JAVA9_OPTS% %DUMP% %HEAP% %VERBOSE_GC% %GC_ALGO% %DDRAW% %SYSTEM_PROPS% %JMETER_LANGUAGE% %RUN_IN_DOCKER%
180+
set ARGS=%JAVA_OPTS% %DUMP% %HEAP% %VERBOSE_GC% %GC_ALGO% %DDRAW% %SYSTEM_PROPS% %JMETER_LANGUAGE% %RUN_IN_DOCKER%
192181
) else (
193182
set ARGS=
194183
)

bin/jmeter.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,17 @@ fi
9090
JAVA9_OPTS=
9191

9292
# Minimal version to run JMeter
93-
MINIMAL_VERSION=8
93+
MINIMAL_VERSION=17
9494

9595
# Check if version is from OpenJDK or Oracle Hotspot JVM prior to 9 containing 1.${version}.x
9696
CURRENT_VERSION=`"${JAVA_HOME}/bin/java" -version 2>&1 | awk -F'"' '/version/ {gsub("^1[.]", "", $2); gsub("[^0-9].*$", "", $2); print $2}'`
9797

9898
# Check if Java is present and the minimal version requirement
99-
if [ "$CURRENT_VERSION" -gt "$MINIMAL_VERSION" ]; then
99+
if [ "$CURRENT_VERSION" -ge "$MINIMAL_VERSION" ]; then
100100
JAVA9_OPTS="--add-opens java.desktop/sun.awt=ALL-UNNAMED --add-opens java.desktop/sun.swing=ALL-UNNAMED --add-opens java.desktop/javax.swing.text.html=ALL-UNNAMED --add-opens java.desktop/java.awt=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.text=ALL-UNNAMED --add-opens=java.desktop/sun.awt.X11=ALL-UNNAMED --add-opens=java.desktop/sun.awt.shell=ALL-UNNAMED"
101+
else
102+
echo "JMeter requires Java $MINIMAL_VERSION or later. Current Java version is $CURRENT_VERSION"
103+
exit 1
101104
fi
102105

103106
# Don't add additional arguments to the JVM start, except those needed for Java 9

build-logic/jvm/src/main/kotlin/build-logic.java.gradle.kts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,14 @@ tasks.configureEach<Javadoc> {
121121
docTitle = "Apache JMeter ${project.name} API"
122122
windowTitle = "Apache JMeter ${project.name} API"
123123
header = "<b>Apache JMeter</b>"
124-
addStringOption("source", "8")
124+
addStringOption("source", "17")
125125
addStringOption("Xmaxwarns", "10")
126126
addBooleanOption("Xdoclint:all,-missing", true)
127127
val lastEditYear: String by rootProject.extra
128128
bottom =
129129
"Copyright &copy; 1998-$lastEditYear Apache Software Foundation. All Rights Reserved."
130-
if (buildParameters.buildJdkVersion > 8) {
131-
addBooleanOption("html5", true)
132-
links("https://docs.oracle.com/en/java/javase/11/docs/api/")
133-
} else {
134-
links("https://docs.oracle.com/javase/8/docs/api/")
135-
}
130+
addBooleanOption("html5", true)
131+
links("https://docs.oracle.com/en/java/javase/17/docs/api/")
136132
}
137133
}
138134

src/components/src/main/java/org/apache/jmeter/assertions/SizeAssertion.java

Lines changed: 79 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,86 @@ public class SizeAssertion extends AbstractScopedAssertion implements Serializab
3535

3636
private static final long serialVersionUID = 241L;
3737

38-
// Static int to signify the type of logical comparator to assert
38+
/**
39+
* Comparison operators for size assertions
40+
*/
41+
public enum ComparisonOperator {
42+
EQUAL(1, "size_assertion_comparator_error_equal"),
43+
NOTEQUAL(2, "size_assertion_comparator_error_notequal"),
44+
GREATERTHAN(3, "size_assertion_comparator_error_greater"),
45+
LESSTHAN(4, "size_assertion_comparator_error_less"),
46+
GREATERTHANEQUAL(5, "size_assertion_comparator_error_greaterequal"),
47+
LESSTHANEQUAL(6, "size_assertion_comparator_error_lessequal");
48+
49+
private static final ComparisonOperator[] VALUES = values();
50+
51+
private final int value;
52+
private final String errorMessageKey;
53+
54+
ComparisonOperator(int value, String errorMessageKey) {
55+
this.value = value;
56+
this.errorMessageKey = errorMessageKey;
57+
}
58+
59+
public int getValue() {
60+
return value;
61+
}
62+
63+
public String getErrorMessageKey() {
64+
return errorMessageKey;
65+
}
66+
67+
public static ComparisonOperator fromValue(int value) {
68+
for (ComparisonOperator op : VALUES) {
69+
if (op.value == value) {
70+
return op;
71+
}
72+
}
73+
return null;
74+
}
75+
76+
public boolean evaluate(long actual, long expected) {
77+
switch (this) {
78+
case EQUAL:
79+
return actual == expected;
80+
case NOTEQUAL:
81+
return actual != expected;
82+
case GREATERTHAN:
83+
return actual > expected;
84+
case LESSTHAN:
85+
return actual < expected;
86+
case GREATERTHANEQUAL:
87+
return actual >= expected;
88+
case LESSTHANEQUAL:
89+
return actual <= expected;
90+
}
91+
throw new IllegalStateException("Unexpected value: " + this);
92+
}
93+
}
94+
95+
// Backward compatibility constants - deprecated
96+
/** @deprecated Use {@link ComparisonOperator#EQUAL} instead */
97+
@Deprecated
3998
public static final int EQUAL = 1;
4099

100+
/** @deprecated Use {@link ComparisonOperator#NOTEQUAL} instead */
101+
@Deprecated
41102
public static final int NOTEQUAL = 2;
42103

104+
/** @deprecated Use {@link ComparisonOperator#GREATERTHAN} instead */
105+
@Deprecated
43106
public static final int GREATERTHAN = 3;
44107

108+
/** @deprecated Use {@link ComparisonOperator#LESSTHAN} instead */
109+
@Deprecated
45110
public static final int LESSTHAN = 4;
46111

112+
/** @deprecated Use {@link ComparisonOperator#GREATERTHANEQUAL} instead */
113+
@Deprecated
47114
public static final int GREATERTHANEQUAL = 5;
48115

116+
/** @deprecated Use {@link ComparisonOperator#LESSTHANEQUAL} instead */
117+
@Deprecated
49118
public static final int LESSTHANEQUAL = 6;
50119

51120
/** Key for storing assertion-information in the jmx-file. */
@@ -175,41 +244,17 @@ public void setAllowedSize(long size) {
175244
*
176245
*/
177246
private String compareSize(long resultSize) {
178-
String comparatorErrorMessage;
179247
long allowedSize = Long.parseLong(getAllowedSize());
180-
boolean result;
181-
int comp = getCompOper();
182-
switch (comp) {
183-
case EQUAL:
184-
result = resultSize == allowedSize;
185-
comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_equal"); //$NON-NLS-1$
186-
break;
187-
case NOTEQUAL:
188-
result = resultSize != allowedSize;
189-
comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_notequal"); //$NON-NLS-1$
190-
break;
191-
case GREATERTHAN:
192-
result = resultSize > allowedSize;
193-
comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_greater"); //$NON-NLS-1$
194-
break;
195-
case LESSTHAN:
196-
result = resultSize < allowedSize;
197-
comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_less"); //$NON-NLS-1$
198-
break;
199-
case GREATERTHANEQUAL:
200-
result = resultSize >= allowedSize;
201-
comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_greaterequal"); //$NON-NLS-1$
202-
break;
203-
case LESSTHANEQUAL:
204-
result = resultSize <= allowedSize;
205-
comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_lessequal"); //$NON-NLS-1$
206-
break;
207-
default:
208-
result = false;
209-
comparatorErrorMessage = "ERROR - invalid condition";
210-
break;
248+
ComparisonOperator operator = ComparisonOperator.fromValue(getCompOper());
249+
if (operator == null) {
250+
return "ERROR - invalid condition";
251+
}
252+
253+
if (operator.evaluate(resultSize, allowedSize)) {
254+
return "";
255+
} else {
256+
return JMeterUtils.getResString(operator.getErrorMessageKey());
211257
}
212-
return result ? "" : comparatorErrorMessage;
213258
}
214259

215260
private void setTestField(String testField) {

0 commit comments

Comments
 (0)