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---------------------// //------------------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) { private NewSerializedForm getSerializedForm(TypeElement typeElem) {
NewSerializedForm sf = serializedForms.get(klass); return serializedForms.computeIfAbsent(typeElem,
if (sf == null) { te -> new NewSerializedForm(utils, configuration.docEnv.getElementUtils(), te));
sf = new NewSerializedForm(utils, configuration.docEnv.getElementUtils(), klass);
serializedForms.put(klass, sf);
}
return sf.fields;
} }
public SortedSet<ExecutableElement> getSerializationMethods(Utils utils, TypeElement klass) { public SortedSet<VariableElement> getSerializableFields(TypeElement typeElem) {
NewSerializedForm sf = serializedForms.get(klass); return getSerializedForm(typeElem).fields;
if (sf == null) {
sf = new NewSerializedForm(utils, configuration.docEnv.getElementUtils(), klass);
serializedForms.put(klass, sf);
}
return sf.methods;
} }
public boolean definesSerializableFields(Utils utils, TypeElement klass) { public SortedSet<ExecutableElement> getSerializationMethods(TypeElement typeElem) {
if (!utils.isSerializable(klass) || utils.isExternalizable(klass)) { return getSerializedForm(typeElem).methods;
}
public boolean definesSerializableFields(TypeElement typeElem) {
if (!utils.isSerializable(typeElem) || utils.isExternalizable(typeElem)) {
return false; return false;
} else { } else {
NewSerializedForm sf = serializedForms.get(klass); return getSerializedForm(typeElem).definesSerializableFields;
if (sf == null) {
sf = new NewSerializedForm(utils, configuration.docEnv.getElementUtils(), klass);
serializedForms.put(klass, sf);
}
return sf.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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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) { public SortedSet<VariableElement> serializableFields(TypeElement aclass) {
return configuration.workArounds.getSerializableFields(this, aclass); return configuration.workArounds.getSerializableFields(aclass);
} }
public SortedSet<ExecutableElement> serializationMethods(TypeElement aclass) { public SortedSet<ExecutableElement> serializationMethods(TypeElement aclass) {
return configuration.workArounds.getSerializationMethods(this, aclass); return configuration.workArounds.getSerializationMethods(aclass);
} }
public boolean definesSerializableFields(TypeElement aclass) { public boolean definesSerializableFields(TypeElement aclass) {
return configuration.workArounds.definesSerializableFields(this, aclass); return configuration.workArounds.definesSerializableFields( aclass);
} }
public String modifiersToString(Element e, boolean trailingSpace) { public String modifiersToString(Element e, boolean trailingSpace) {