-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathSharedClassesWorkloadTest_Softmx_Increase.java
173 lines (145 loc) · 10.1 KB
/
SharedClassesWorkloadTest_Softmx_Increase.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*******************************************************************************
* Copyright (c) 2016, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which accompanies this distribution
* and is available at http://eclipse.org/legal/epl-2.0 or the Apache License,
* Version 2.0 which accompanies this distribution and is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License, v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception [1] and GNU General Public License,
* version 2 with the OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] http://openjdk.java.net/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/
package net.openj9.stf;
import static net.adoptopenjdk.stf.extensions.core.StfCoreExtension.Echo.ECHO_OFF;
import net.adoptopenjdk.stf.environment.DirectoryRef;
import net.adoptopenjdk.stf.extensions.core.StfCoreExtension;
import net.adoptopenjdk.stf.processes.ExpectedOutcome;
import net.adoptopenjdk.stf.processes.StfProcess;
import net.adoptopenjdk.stf.processes.definitions.LoadTestProcessDefinition;
import net.adoptopenjdk.stf.runner.modes.HelpTextGenerator;
import net.openj9.stf.sharedClasses.SharedClassesPluginInterface;
import net.openj9.stf.sharedClasses.StfSharedClassesExtension;
import net.openj9.test.sc.SCSoftmxTestUtil;
/**
* SVT use case implementations for creating a soft limit on the contents of the shared cache.
*
* Usecase
* ~~~~~~~
* Start Jvm1 that sets softmx to say 1mb and shared cache hard limit to say 20mb.
* Jvm1 fills up cache, Jvm2 will check if cache's usage has reached softmx, if yes,
* then Jvm2 will adjust softmx to increased value of e.g. 2mb. Start Jvm3 and
* continue loading the cache.
*
* Implementation steps
* ~~~~~~~~~~~~~~~~~~~~~~
* 1) Start Jvm1 with options: "-XX:SharedCacheHardLimit=20m, -Xscmxsoftmx=1m". It should
* create the shared classes cache and run a mini-mix load test and fill up the shared
* classes cache.
* 2) Once Jvm1 finishes its work, check cache stats to ensure cache is soft full. Fail if it isn't.
* 3) Start Jvm2 that does -Xshareclasses:adjustsoftmx=2m. Check cache stats to ensure
* cache's softmx limit has been increased to 2m.
* 4) Start Jvm3 that runs the second mini-mix load. Make sure code is being written to
* the increased space of the shared classes cache.
*/
public class SharedClassesWorkloadTest_Softmx_Increase implements SharedClassesPluginInterface {
private final int CACHESIZE_HARD_LIMIT = 20;
private final int CACHESIZE_SOFTLIMIT_1MB = 1;
private final int CACHESIZE_SOFTLIMIT_2MB = 2;
private String[] CACHE_FULL_MESSAGE_99_OR_100_PERCENT = {"Cache is (100%|99%) soft full"}; // Accepting 99-100% soft full as "cache full" criteria,
// assuming last entry to be stored to the shared cache will be > 1% of the cache size
private DirectoryRef cacheDirLocation;
private String cacheSpecificGeneralOptions;
private String initialCacheSizeOptions;
private String cacheSizeAdjustmentOptions;
private String cacheDir;
public void help(HelpTextGenerator help) {
help.outputSection("Shared Classes Workload test with cache soft limit increase");
help.outputText( "The Shared Classes Softmx Workload test runs the following tests:\n");
help.outputArgDesc("- Runs a workload with shared classes creating a named cache "
+ "with a specific hard limit and soft limit in the results directory. The workload fills up the cache.\n");
help.outputArgDesc("- Checks that a cache was created and that it was filled up.\n");
help.outputArgDesc("- Increases the softlimit of the cache.\n");
help.outputArgDesc("- Does another workload run using this named cache\n");
help.outputArgDesc("- Checks no other caches exist and that the cache was filled up to its new soft limit\n");
help.outputArgDesc("- Deletes the cache\n");
}
public void pluginInit(StfCoreExtension test, StfSharedClassesExtension sharedClasses) throws Exception {
}
public void setUp(StfCoreExtension test, StfSharedClassesExtension sharedClasses) throws Exception {
// Define the location for cache.
cacheDirLocation = test.env().getResultsDir().childDirectory("cache");
cacheDir = cacheDirLocation.toString();
// Specify the cache specific variables.
cacheSpecificGeneralOptions = "-Xshareclasses:" + "name=" + SCSoftmxTestUtil.CACHE_NAME + "," + "cacheDir=" + cacheDir;
// Create the directories for the cache.
test.doMkdir("Create the cache directory", cacheDirLocation);
// Set Cache specific options for the test
initialCacheSizeOptions = cacheSpecificGeneralOptions +
" -XX:SharedCacheHardLimit=" + CACHESIZE_HARD_LIMIT + "m" +
" -Xscmx" + CACHESIZE_SOFTLIMIT_1MB + "m";
cacheSizeAdjustmentOptions = cacheSpecificGeneralOptions + "," +
"adjustsoftmx=" + CACHESIZE_SOFTLIMIT_2MB + "m";
// To ensure we run from a clean state, attempt to destroy the test related persistent/non-persistent caches
// from the default cache location which may have been left behind by a previous failed test.
sharedClasses.doDestroySpecificCache("Destroy cache", cacheSpecificGeneralOptions + "${cacheOperation}", SCSoftmxTestUtil.CACHE_NAME, cacheDir);
sharedClasses.doDestroySpecificNonPersistentCache("Destroy cache", cacheSpecificGeneralOptions + "${cacheOperation}", SCSoftmxTestUtil.CACHE_NAME, cacheDir);
}
public void execute(StfCoreExtension test, StfSharedClassesExtension sharedClasses) throws Exception {
// Abort if we are not running on IBM Java.
test.env().verifyUsingIBMJava();
// Specify the Process definition for the workload processes (jvm1).
LoadTestProcessDefinition loadTestSpecificationVM1 = test.createLoadTestSpecification()
.addJvmOption(initialCacheSizeOptions);
loadTestSpecificationVM1 = SCSoftmxTestUtil.getMiniMixLoadTestOptions(loadTestSpecificationVM1, 600);
LoadTestProcessDefinition loadTestSpecificationVM2 = test.createLoadTestSpecification()
.addJvmOption(cacheSpecificGeneralOptions);
loadTestSpecificationVM2 = SCSoftmxTestUtil.getMiniMixLoadTestOptions(loadTestSpecificationVM2, 1000);
// Start JVM1: Run a single workload process that creates a shared classes cache
// using the initial soft limit and fills it up.
test.doRunForegroundProcess("Run a single workload process to fill up the initial cache",
"Jvm1", ECHO_OFF, ExpectedOutcome.exitValue(0,1).within("15m"), loadTestSpecificationVM1);
// Check that the expected cache was created, caches exist, and the cache is 100% soft fullt.
verifyAndPrintCache(sharedClasses, SCSoftmxTestUtil.CACHE_NAME, cacheDir, SCSoftmxTestUtil.CACHE_NAME, 1, CACHE_FULL_MESSAGE_99_OR_100_PERCENT);
// Increase cache size via softmx and load more classes to fill it up again.
StfProcess p = test.doRunForegroundProcess("Increasing cache size to " + CACHESIZE_SOFTLIMIT_2MB +
"mb via -Xshareclasses:adjustsoftmx option", "SL2", ECHO_OFF, ExpectedOutcome.exitValue(1).within("1m"),
test.createJavaProcessDefinition()
.addJvmOption(cacheSizeAdjustmentOptions)
.runClass(""));
// Make sure cache size adjustment happened properly.
test.doCountFileMatches("Check output", p.getStderrFileRef(), 1,
"JVMSHRC789I The softmx bytes is set to " + (CACHESIZE_SOFTLIMIT_2MB * 1024 * 1024) + ".");
// Start JVM2 : Run a second workload to fill the cache up again, after the cache size has been increased.
test.doRunForegroundProcess("Run a second workload after the cache size has been increased",
"Jvm2", ECHO_OFF, ExpectedOutcome.exitValue(0,1).within("30m"), loadTestSpecificationVM2);
// Confirm that only the expected cache exists and no other caches were created
// Also, confirm that increasing the cache size via softmx allowed new code to be written.
verifyAndPrintCache(sharedClasses, SCSoftmxTestUtil.CACHE_NAME, cacheDir, SCSoftmxTestUtil.CACHE_NAME, 1, CACHE_FULL_MESSAGE_99_OR_100_PERCENT);
// Destroy the existing cache.
sharedClasses.doDestroySpecificCache("Destroy cache", cacheSpecificGeneralOptions + "${cacheOperation}", SCSoftmxTestUtil.CACHE_NAME, cacheDir);
// Confirm that the deletion was successful.
sharedClasses.doVerifySharedClassesCache("Verify caches", cacheSpecificGeneralOptions + "${cacheOperation}", SCSoftmxTestUtil.CACHE_NAME, cacheDir, "", 0);
}
private void verifyAndPrintCache(StfSharedClassesExtension sharedClasses, String cacheName, String cacheDir, String expectedCacheName, int expectedCaches, String[] expectedMessages) throws Exception {
// Verify cache and the number of expected caches
sharedClasses.doVerifySharedClassesCache("List all caches", cacheSpecificGeneralOptions + "${cacheOperation}", cacheName, cacheDir, expectedCacheName, expectedCaches);
// Print the status of the cache and check that the cache is 1-100% full
sharedClasses.doPrintAndVerifyCache("Print Shared Classes Cache Stats", cacheSpecificGeneralOptions + "${cacheOperation}", cacheName, cacheDir, expectedMessages);
}
public void tearDown(StfCoreExtension test, StfSharedClassesExtension sharedClasses) throws Exception {
// Destroy all test related persistent/non-persistent caches from the default cache location which may
// have been left behind by a failure. We don't care about caches left behind in results
// as those will get deleted together with results.
sharedClasses.doDestroySpecificCache("Destroy cache", cacheSpecificGeneralOptions + "${cacheOperation}", SCSoftmxTestUtil.CACHE_NAME, cacheDir);
sharedClasses.doDestroySpecificNonPersistentCache("Destroy cache", cacheSpecificGeneralOptions + "${cacheOperation}", SCSoftmxTestUtil.CACHE_NAME, cacheDir);
}
}