changeset 51976:3528ba05663a

8208249: TriggerUnloadingByFillingMetaspace generates garbage class names Summary: Put a ThreadLocal around the object to be thread safe Reviewed-by: tschatzl, iignatyev
author jcbeyler
date Tue, 31 Jul 2018 10:16:56 -0700
parents ac4f5ef0edd9
children 1129f9833589
files test/hotspot/jtreg/vmTestbase/vm/share/gc/TriggerUnloadingByFillingMetaspace.java
diffstat 1 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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.");