Skip to content

Commit

Permalink
8208249: TriggerUnloadingByFillingMetaspace generates garbage class n…
Browse files Browse the repository at this point in the history
…ames

Put a ThreadLocal around the object to be thread safe

Backport-of: 3d94ce7
  • Loading branch information
GoeLin committed Mar 9, 2022
1 parent 87b6007 commit 571d323
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ public class TriggerUnloadingByFillingMetaspace implements
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; }

Expand All @@ -48,7 +54,7 @@ private class FillMetaspaceTask implements Callable<Object> {
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.");
Expand Down

1 comment on commit 571d323

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.