jdk/src/share/classes/com/sun/tools/hat/internal/model/Snapshot.java
changeset 25798 0b2f54e47bc4
parent 25522 10d789df41bb
equal deleted inserted replaced
25797:671124b407ce 25798:0b2f54e47bc4
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    79     // object-to-Root map for all objects
    79     // object-to-Root map for all objects
    80     private Map<JavaHeapObject, Root> rootsMap =
    80     private Map<JavaHeapObject, Root> rootsMap =
    81                  new HashMap<JavaHeapObject, Root>();
    81                  new HashMap<JavaHeapObject, Root>();
    82 
    82 
    83     // soft cache of finalizeable objects - lazily initialized
    83     // soft cache of finalizeable objects - lazily initialized
    84     private SoftReference<Vector> finalizablesCache;
    84     private SoftReference<Vector<?>> finalizablesCache;
    85 
    85 
    86     // represents null reference
    86     // represents null reference
    87     private JavaThing nullThing;
    87     private JavaThing nullThing;
    88 
    88 
    89     // java.lang.ref.Reference class
    89     // java.lang.ref.Reference class
   381     }
   381     }
   382 
   382 
   383     /**
   383     /**
   384      * Return an Iterator of all of the classes in this snapshot.
   384      * Return an Iterator of all of the classes in this snapshot.
   385      **/
   385      **/
   386     public Iterator getClasses() {
   386     public Iterator<JavaClass> getClasses() {
   387         // note that because classes is a TreeMap
   387         // note that because classes is a TreeMap
   388         // classes are already sorted by name
   388         // classes are already sorted by name
   389         return classes.values().iterator();
   389         return classes.values().iterator();
   390     }
   390     }
   391 
   391 
   393         JavaClass[] res = new JavaClass[classes.size()];
   393         JavaClass[] res = new JavaClass[classes.size()];
   394         classes.values().toArray(res);
   394         classes.values().toArray(res);
   395         return res;
   395         return res;
   396     }
   396     }
   397 
   397 
   398     public synchronized Enumeration getFinalizerObjects() {
   398     public synchronized Enumeration<?> getFinalizerObjects() {
   399         Vector obj;
   399         Vector<?> obj;
   400         if (finalizablesCache != null &&
   400         if (finalizablesCache != null &&
   401             (obj = finalizablesCache.get()) != null) {
   401             (obj = finalizablesCache.get()) != null) {
   402             return obj.elements();
   402             return obj.elements();
   403         }
   403         }
   404 
   404 
   416                 }
   416                 }
   417                 head = (JavaObject) next;
   417                 head = (JavaObject) next;
   418                 finalizables.add(referent);
   418                 finalizables.add(referent);
   419             }
   419             }
   420         }
   420         }
   421         finalizablesCache = new SoftReference<Vector>(finalizables);
   421         finalizablesCache = new SoftReference<Vector<?>>(finalizables);
   422         return finalizables.elements();
   422         return finalizables.elements();
   423     }
   423     }
   424 
   424 
   425     public Enumeration<Root> getRoots() {
   425     public Enumeration<Root> getRoots() {
   426         return roots.elements();
   426         return roots.elements();
   453             if (curr.getRoot() != null) {
   453             if (curr.getRoot() != null) {
   454                 result.addElement(chain);
   454                 result.addElement(chain);
   455                 // Even though curr is in the rootset, we want to explore its
   455                 // Even though curr is in the rootset, we want to explore its
   456                 // referers, because they might be more interesting.
   456                 // referers, because they might be more interesting.
   457             }
   457             }
   458             Enumeration referers = curr.getReferers();
   458             Enumeration<JavaThing> referers = curr.getReferers();
   459             while (referers.hasMoreElements()) {
   459             while (referers.hasMoreElements()) {
   460                 JavaHeapObject t = (JavaHeapObject) referers.nextElement();
   460                 JavaHeapObject t = (JavaHeapObject) referers.nextElement();
   461                 if (t != null && !visited.containsKey(t)) {
   461                 if (t != null && !visited.containsKey(t)) {
   462                     if (includeWeak || !t.refersOnlyWeaklyTo(this, curr)) {
   462                     if (includeWeak || !t.refersOnlyWeaklyTo(this, curr)) {
   463                         visited.put(t, t);
   463                         visited.put(t, t);