8231587: Memory leak in WorkArounds.serializedForms

Reviewed-by: hannesw
This commit is contained in:
Florian Weimer 2019-10-21 13:25:36 -07:00 committed by Jonathan Gibbons
parent f5b14bd780
commit c483fbe6d6
2 changed files with 17 additions and 27 deletions

View File

@ -332,36 +332,26 @@ public class WorkArounds {
}
//------------------Start of Serializable Implementation---------------------//
private final static Map<TypeElement, NewSerializedForm> serializedForms = new HashMap<>();
private final Map<TypeElement, NewSerializedForm> serializedForms = new HashMap<>();
public SortedSet<VariableElement> getSerializableFields(Utils utils, TypeElement klass) {
NewSerializedForm sf = serializedForms.get(klass);
if (sf == null) {
sf = new NewSerializedForm(utils, configuration.docEnv.getElementUtils(), klass);
serializedForms.put(klass, sf);
}
return sf.fields;
private NewSerializedForm getSerializedForm(TypeElement typeElem) {
return serializedForms.computeIfAbsent(typeElem,
te -> new NewSerializedForm(utils, configuration.docEnv.getElementUtils(), te));
}
public SortedSet<ExecutableElement> getSerializationMethods(Utils utils, TypeElement klass) {
NewSerializedForm sf = serializedForms.get(klass);
if (sf == null) {
sf = new NewSerializedForm(utils, configuration.docEnv.getElementUtils(), klass);
serializedForms.put(klass, sf);
}
return sf.methods;
public SortedSet<VariableElement> getSerializableFields(TypeElement typeElem) {
return getSerializedForm(typeElem).fields;
}
public boolean definesSerializableFields(Utils utils, TypeElement klass) {
if (!utils.isSerializable(klass) || utils.isExternalizable(klass)) {
public SortedSet<ExecutableElement> getSerializationMethods(TypeElement typeElem) {
return getSerializedForm(typeElem).methods;
}
public boolean definesSerializableFields(TypeElement typeElem) {
if (!utils.isSerializable(typeElem) || utils.isExternalizable(typeElem)) {
return false;
} else {
NewSerializedForm sf = serializedForms.get(klass);
if (sf == null) {
sf = new NewSerializedForm(utils, configuration.docEnv.getElementUtils(), klass);
serializedForms.put(klass, sf);
}
return sf.definesSerializableFields;
return getSerializedForm(typeElem).definesSerializableFields;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -417,15 +417,15 @@ public class Utils {
}
public SortedSet<VariableElement> serializableFields(TypeElement aclass) {
return configuration.workArounds.getSerializableFields(this, aclass);
return configuration.workArounds.getSerializableFields(aclass);
}
public SortedSet<ExecutableElement> serializationMethods(TypeElement aclass) {
return configuration.workArounds.getSerializationMethods(this, aclass);
return configuration.workArounds.getSerializationMethods(aclass);
}
public boolean definesSerializableFields(TypeElement aclass) {
return configuration.workArounds.definesSerializableFields(this, aclass);
return configuration.workArounds.definesSerializableFields( aclass);
}
public String modifiersToString(Element e, boolean trailingSpace) {