diff --git a/openj9.test.sharedClasses.jvmti/src/test.sharedClasses.jvmti/net/openj9/sc/api/SharedClassesCacheChecker.java b/openj9.test.sharedClasses.jvmti/src/test.sharedClasses.jvmti/net/openj9/sc/api/SharedClassesCacheChecker.java index e9008c0..16c7fa1 100644 --- a/openj9.test.sharedClasses.jvmti/src/test.sharedClasses.jvmti/net/openj9/sc/api/SharedClassesCacheChecker.java +++ b/openj9.test.sharedClasses.jvmti/src/test.sharedClasses.jvmti/net/openj9/sc/api/SharedClassesCacheChecker.java @@ -24,6 +24,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -70,7 +71,7 @@ public class SharedClassesCacheChecker { private static final String CONFIG_FILE_PROP = "configFile"; - private static final String CACHE_NAME_PROP = "cacheName"; + private static final String WORKLOAD_CACHE_LIST_PROP = "wlCacheList"; private static final String EXPECTED_CACHE_COUNT_PROP = "expectedCacheCount"; @@ -101,11 +102,11 @@ public class SharedClassesCacheChecker { ArrayList alreadySuccesfullyDeletedCaches; // Name of the Shared Classes Cache - private String cacheName; + private List workloadCacheList; - public SharedClassesCacheChecker(Properties config, String cacheName) { + public SharedClassesCacheChecker(Properties config, List wlCacheList) { this.config = config; - this.cacheName = cacheName; + this.workloadCacheList = wlCacheList; cacheDir = config.getProperty(CACHE_DIR_PROP); if (cacheDir == null || cacheDir.equals("default")) { logger.info("Using default cache directory"); @@ -153,14 +154,16 @@ boolean delete() { boolean rv = true; for (SharedClassCacheInfo info: this.caches) { - // We are running SharedClassesCacheChecker once per each cache, with the cache's name - // being sent into this utility via CACHE_NAME_PROP command line (this is to ensure we - // only attempt to verify and delete the test-related caches, and leave alone other possible - // caches that might exist on the machine where the test is running). So, we should attempt - // to destroy only the test-related cache we are given. - if (info.getCacheName() == null) { + // We want to only delete the worklaod caches here. + // Any cache that might be listed in the default location - created + // or owned by other processes should be ignored. + // Cache created and used by the SharedClassesCacheCheceker process + // can not be deleted by itself either, so must be ignored here. + // Those are deleted in SharedClassesAPI tearDown() method + String cacheName = info.getCacheName(); + if (cacheName == null) { continue; - } else if (!info.getCacheName().equals(cacheName)) { + } else if (!workloadCacheList.contains(cacheName)) { continue; } else if (this.alreadySuccesfullyDeletedCaches.contains(cacheName)) { continue; @@ -195,7 +198,7 @@ boolean delete() { rv = false; break; } - this.alreadySuccesfullyDeletedCaches.add(cacheName); + this.alreadySuccesfullyDeletedCaches.add(info.getCacheName()); break; } @@ -233,10 +236,12 @@ public String verify() { int i = 0; for (SharedClassCacheInfo info: caches) { - // We only want to verify the cache we are sent to verify and ignore the rest + // We only want to verify the workload caches + // Any cache that might be listed in the default location - created + // or owned by other processes should be ignored. if (info.getCacheName() == null) { continue; - } else if (!info.getCacheName().equals(cacheName)) { + } else if (!workloadCacheList.contains(info.getCacheName())) { continue; } @@ -383,10 +388,13 @@ public static void main(String[] args) { System.exit(1); } - String cacheName = System.getProperty(CACHE_NAME_PROP); - if (cacheName == null) { - System.out.println("No cacheName supplied via system property 'cacheName'"); + List wlCacheList = new ArrayList(); + String listAsString = System.getProperty(WORKLOAD_CACHE_LIST_PROP); + if (listAsString == null) { + System.out.println("No workload cache list supplied via system property '"+ WORKLOAD_CACHE_LIST_PROP +"'"); System.exit(1); + } else { + wlCacheList = Arrays.asList(listAsString.split("--")); } Properties config = new Properties(); @@ -399,7 +407,7 @@ public static void main(String[] args) { } - SharedClassesCacheChecker checker = new SharedClassesCacheChecker(config, cacheName); + SharedClassesCacheChecker checker = new SharedClassesCacheChecker(config, wlCacheList); try { checker.loadExpectedCacheData(); } catch (IOException e) { diff --git a/openj9.test.sharedClasses.jvmti/src/test.sharedClasses.jvmti/net/openj9/stf/SharedClassesAPI.java b/openj9.test.sharedClasses.jvmti/src/test.sharedClasses.jvmti/net/openj9/stf/SharedClassesAPI.java index bda7986..59bb9c3 100644 --- a/openj9.test.sharedClasses.jvmti/src/test.sharedClasses.jvmti/net/openj9/stf/SharedClassesAPI.java +++ b/openj9.test.sharedClasses.jvmti/src/test.sharedClasses.jvmti/net/openj9/stf/SharedClassesAPI.java @@ -91,7 +91,7 @@ private Tests(int expectedCacheCount, String api, boolean usesDefaultLocation, b private DirectoryRef configDirLocation; private ArrayList testCachesCreatedInDefaultLocation = new ArrayList(); - + private ArrayList wlCacheNameRegistry = new ArrayList(); public void help(HelpTextGenerator help) { help.outputSection("Shared Classes API test"); @@ -205,7 +205,7 @@ public void execute(StfCoreExtension test, StfSharedClassesExtension sharedClass test.createJavaProcessDefinition() .addJvmOption(sharedClassesOption) .addJvmOption("-DconfigFile=" + configFile.getSpec()) - .addJvmOption("-DcacheName=" + cacheName) + .addJvmOption("-DwlCacheList=" + wlCacheListToString()) .addProjectToClasspath("openj9.test.sharedClasses.jvmti") .runClass(SharedClassesCacheChecker.class)); } else { @@ -239,6 +239,7 @@ public void execute(StfCoreExtension test, StfSharedClassesExtension sharedClass private StfProcess startWorkload(StfCoreExtension test, Tests apiTest, String workloadName, String cacheDir, String persistantStatus, StfSharedClassesExtension sharedClasses) throws Exception { String groupAccess = (apiTest.usesGroupAccess ? ",groupAccess" : ""); String cacheName = apiTest.name() + workloadName; + this.wlCacheNameRegistry.add(cacheName); String inventoryFile = "/openjdk.test.load/config/inventories/mix/mini-mix.xml"; int totalTests = InventoryData.getNumberOfTests(test, inventoryFile); if (!cacheDir.isEmpty()) { @@ -281,6 +282,24 @@ private FileRef createConfigFile(StfCoreExtension test, Tests apiTest, String wo return configCacheFile; } + + // Creates a delimited list of workload cache names + // to be passed to SharedClassesCacheChecker + private String wlCacheListToString() { + String strList = ""; + Iterator i = this.wlCacheNameRegistry.iterator(); + while(i.hasNext()) { + String aCacheName = i.next(); + if (strList.length() == 0) { + strList = aCacheName; + } else { + strList = strList + "--" + aCacheName; + } + } + // clean up for next iteration + this.wlCacheNameRegistry.clear(); + return strList; + } public void tearDown(StfCoreExtension test, StfSharedClassesExtension sharedClasses) throws Exception {