changeset 3226:0d9c7e282d95

8148413: Memory leak in javadoc VisibleMemberMap Reviewed-by: ksrini
author jjg
date Wed, 27 Jan 2016 14:44:33 -0800
parents 4a4f58f3b344
children 95dd89752153
files src/jdk.javadoc/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java src/jdk.javadoc/share/classes/com/sun/tools/doclets/internal/toolkit/util/VisibleMemberMap.java
diffstat 2 files changed, 15 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.javadoc/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java	Tue Jan 26 12:11:55 2016 +0000
+++ b/src/jdk.javadoc/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java	Wed Jan 27 14:44:33 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, 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
@@ -29,6 +29,7 @@
 import java.util.*;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+
 import javax.tools.JavaFileManager;
 
 import com.sun.javadoc.*;
@@ -37,6 +38,7 @@
 import com.sun.tools.doclets.internal.toolkit.builders.BuilderFactory;
 import com.sun.tools.doclets.internal.toolkit.taglets.*;
 import com.sun.tools.doclets.internal.toolkit.util.*;
+import com.sun.tools.doclets.internal.toolkit.util.VisibleMemberMap.GetterSetter;
 import com.sun.tools.javac.util.StringUtils;
 
 /**
@@ -304,6 +306,11 @@
      */
     public SortedSet<PackageDoc> packages;
 
+    // The following three fields provide caches for use by all instances of VisibleMemberMap.
+    public final Map<ClassDoc, ProgramElementDoc[]> propertiesCache = new HashMap<>();
+    public final Map<ProgramElementDoc, ProgramElementDoc> classPropertiesMap = new HashMap<>();
+    public final Map<ProgramElementDoc, GetterSetter> getterSetterMap = new HashMap<>();
+
     /**
      * Constructor. Constructs the message retriever with resource file.
      */
--- a/src/jdk.javadoc/share/classes/com/sun/tools/doclets/internal/toolkit/util/VisibleMemberMap.java	Tue Jan 26 12:11:55 2016 +0000
+++ b/src/jdk.javadoc/share/classes/com/sun/tools/doclets/internal/toolkit/util/VisibleMemberMap.java	Wed Jan 27 14:44:33 2016 -0800
@@ -101,9 +101,9 @@
     private final Configuration configuration;
     private final Utils utils;
 
-    private static final Map<ClassDoc, ProgramElementDoc[]> propertiesCache = new HashMap<>();
-    private static final Map<ProgramElementDoc, ProgramElementDoc> classPropertiesMap = new HashMap<>();
-    private static final Map<ProgramElementDoc, GetterSetter> getterSetterMap = new HashMap<>();
+    private final Map<ClassDoc, ProgramElementDoc[]> propertiesCache;
+    private final Map<ProgramElementDoc, ProgramElementDoc> classPropertiesMap;
+    private final Map<ProgramElementDoc, GetterSetter> getterSetterMap;
 
     /**
      * Construct a VisibleMemberMap of the given type for the given
@@ -123,6 +123,9 @@
         this.kind = kind;
         this.configuration = configuration;
         this.utils = configuration.utils;
+        propertiesCache = configuration.propertiesCache;
+        classPropertiesMap = configuration.classPropertiesMap;
+        getterSetterMap = configuration.getterSetterMap;
         new ClassMembers(classdoc, STARTLEVEL).build();
     }
 
@@ -713,7 +716,7 @@
         }
     }
 
-    private class GetterSetter {
+    public class GetterSetter {
         private final ProgramElementDoc getter;
         private final ProgramElementDoc setter;