8208249: TriggerUnloadingByFillingMetaspace generates garbage class names
authorjcbeyler
Tue, 31 Jul 2018 10:16:56 -0700
changeset 51284 3528ba05663a
parent 51283 ac4f5ef0edd9
child 51285 1129f9833589
8208249: TriggerUnloadingByFillingMetaspace generates garbage class names Summary: Put a ThreadLocal around the object to be thread safe Reviewed-by: tschatzl, iignatyev
test/hotspot/jtreg/vmTestbase/vm/share/gc/TriggerUnloadingByFillingMetaspace.java
--- a/test/hotspot/jtreg/vmTestbase/vm/share/gc/TriggerUnloadingByFillingMetaspace.java	Tue Jul 31 12:24:47 2018 -0700
+++ b/test/hotspot/jtreg/vmTestbase/vm/share/gc/TriggerUnloadingByFillingMetaspace.java	Tue Jul 31 10:16:56 2018 -0700
@@ -39,7 +39,13 @@
     private static class FillMetaspace {
         private volatile boolean gotOOME = false;
         private ExecutionController stresser;
-        private GeneratedClassProducer generatedClassProducer = new GeneratedClassProducer("metaspace.stressHierarchy.common.HumongousClass");
+        private final ThreadLocal<GeneratedClassProducer> generatedClassProducer =
+            new ThreadLocal<GeneratedClassProducer>() {
+              @Override
+              protected GeneratedClassProducer initialValue() {
+                return new GeneratedClassProducer("metaspace.stressHierarchy.common.HumongousClass");
+              }
+            };
 
         public FillMetaspace(ExecutionController stresser) { this.stresser = stresser; }
 
@@ -48,7 +54,7 @@
             public Object call() throws Exception {
                 while (stresser.continueExecution() && ! gotOOME) {
                     try {
-                        generatedClassProducer.create(-100500); //argument is not used.
+                        generatedClassProducer.get().create(-100500); //argument is not used.
                     } catch (OutOfMemoryError oome) {
                         if (!isInMetaspace(oome)) {
                             throw new GotWrongOOMEException("Got OOME in heap while gaining OOME in metaspace. Test result can't be valid.");