< prev index next >

test/lib/jdk/test/lib/hprof/model/Snapshot.java

Print this page

  1 /*
  2  * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  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
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any

 54     public static final long SMALL_ID_MASK = 0x0FFFFFFFFL;
 55     public static final JavaThing[] EMPTY_JAVATHING_ARRAY = new JavaThing[0];
 56 
 57     private static final JavaField[] EMPTY_FIELD_ARRAY = new JavaField[0];
 58     private static final JavaStatic[] EMPTY_STATIC_ARRAY = new JavaStatic[0];
 59 
 60     // all heap objects
 61     private Hashtable<Number, JavaHeapObject> heapObjects =
 62                  new Hashtable<Number, JavaHeapObject>();
 63 
 64     private Hashtable<Number, JavaClass> fakeClasses =
 65                  new Hashtable<Number, JavaClass>();
 66 
 67     // all Roots in this Snapshot
 68     private Vector<Root> roots = new Vector<Root>();
 69 
 70     // name-to-class map
 71     private Map<String, JavaClass> classes =
 72                  new TreeMap<String, JavaClass>();
 73 




 74     // new objects relative to a baseline - lazily initialized
 75     private volatile Map<JavaHeapObject, Boolean> newObjects;
 76 
 77     // allocation site traces for all objects - lazily initialized
 78     private volatile Map<JavaHeapObject, StackTrace> siteTraces;
 79 
 80     // object-to-Root map for all objects
 81     private Map<JavaHeapObject, Root> rootsMap =
 82                  new HashMap<JavaHeapObject, Root>();
 83 
 84     // soft cache of finalizeable objects - lazily initialized
 85     private SoftReference<Vector<?>> finalizablesCache;
 86 
 87     // represents null reference
 88     private JavaThing nullThing;
 89 
 90     // java.lang.ref.Reference class
 91     private JavaClass weakReferenceClass;
 92     // index of 'referent' field in java.lang.ref.Reference class
 93     private int referentFieldIndex;

187         int numInts = instSize / 4;
188         int numBytes = instSize % 4;
189         JavaField[] fields = new JavaField[numInts + numBytes];
190         int i;
191         for (i = 0; i < numInts; i++) {
192             fields[i] = new JavaField("unknown-field-" + i, "I");
193         }
194         for (i = 0; i < numBytes; i++) {
195             fields[i + numInts] = new JavaField("unknown-field-" +
196                                                 i + numInts, "B");
197         }
198 
199         // Create fake instance class
200         JavaClass c = new JavaClass(name, 0, 0, 0, 0, fields,
201                                  EMPTY_STATIC_ARRAY, instSize);
202         // Add the class
203         addFakeClass(makeId(classID), c);
204         return c;
205     }
206 



































207 
208     /**
209      * @return true iff it's possible that some JavaThing instances might
210      *          isNew set
211      *
212      * @see JavaThing.isNew()
213      */
214     public boolean getHasNewSet() {
215         return hasNewSet;
216     }
217 
218     //
219     // Used in the body of resolve()
220     //
221     private static class MyVisitor extends AbstractJavaHeapObjectVisitor {
222         JavaHeapObject t;
223         public void visit(JavaHeapObject other) {
224             other.addReferenceFrom(t);
225         }
226     }

  1 /*
  2  * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  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
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any

 54     public static final long SMALL_ID_MASK = 0x0FFFFFFFFL;
 55     public static final JavaThing[] EMPTY_JAVATHING_ARRAY = new JavaThing[0];
 56 
 57     private static final JavaField[] EMPTY_FIELD_ARRAY = new JavaField[0];
 58     private static final JavaStatic[] EMPTY_STATIC_ARRAY = new JavaStatic[0];
 59 
 60     // all heap objects
 61     private Hashtable<Number, JavaHeapObject> heapObjects =
 62                  new Hashtable<Number, JavaHeapObject>();
 63 
 64     private Hashtable<Number, JavaClass> fakeClasses =
 65                  new Hashtable<Number, JavaClass>();
 66 
 67     // all Roots in this Snapshot
 68     private Vector<Root> roots = new Vector<Root>();
 69 
 70     // name-to-class map
 71     private Map<String, JavaClass> classes =
 72                  new TreeMap<String, JavaClass>();
 73 
 74     private Map<Number, Number> flatArrays = new HashMap<>();
 75 
 76     private Map<Number, ClassInlinedFields[]> inlinedFields = new HashMap<>();
 77 
 78     // new objects relative to a baseline - lazily initialized
 79     private volatile Map<JavaHeapObject, Boolean> newObjects;
 80 
 81     // allocation site traces for all objects - lazily initialized
 82     private volatile Map<JavaHeapObject, StackTrace> siteTraces;
 83 
 84     // object-to-Root map for all objects
 85     private Map<JavaHeapObject, Root> rootsMap =
 86                  new HashMap<JavaHeapObject, Root>();
 87 
 88     // soft cache of finalizeable objects - lazily initialized
 89     private SoftReference<Vector<?>> finalizablesCache;
 90 
 91     // represents null reference
 92     private JavaThing nullThing;
 93 
 94     // java.lang.ref.Reference class
 95     private JavaClass weakReferenceClass;
 96     // index of 'referent' field in java.lang.ref.Reference class
 97     private int referentFieldIndex;

191         int numInts = instSize / 4;
192         int numBytes = instSize % 4;
193         JavaField[] fields = new JavaField[numInts + numBytes];
194         int i;
195         for (i = 0; i < numInts; i++) {
196             fields[i] = new JavaField("unknown-field-" + i, "I");
197         }
198         for (i = 0; i < numBytes; i++) {
199             fields[i + numInts] = new JavaField("unknown-field-" +
200                                                 i + numInts, "B");
201         }
202 
203         // Create fake instance class
204         JavaClass c = new JavaClass(name, 0, 0, 0, 0, fields,
205                                  EMPTY_STATIC_ARRAY, instSize);
206         // Add the class
207         addFakeClass(makeId(classID), c);
208         return c;
209     }
210 
211     public void addFlatArray(long objID, long elementClassID) {
212         flatArrays.put(makeId(objID), makeId(elementClassID));
213     }
214 
215     /**
216      * @return null if the array is not flat array
217      */
218     Number findFlatArrayElementType(long arrayObjectID) {
219         return flatArrays.get(makeId(arrayObjectID));
220     }
221 
222     public static class ClassInlinedFields {
223         final int fieldIndex;
224         final int synthFieldCount;
225         final String fieldName;
226         final long fieldClassID;
227 
228         public ClassInlinedFields(int fieldIndex, int synthFieldCount, String fieldName, long fieldClassID) {
229             this.fieldIndex = fieldIndex;
230             this.synthFieldCount = synthFieldCount;
231             this.fieldName = fieldName;
232             this.fieldClassID =  fieldClassID;
233         }
234     }
235 
236     public void addClassInlinedFields(long classID, ClassInlinedFields[] fields) {
237         inlinedFields.put(makeId(classID), fields);
238     }
239 
240     /**
241      * @return null if the class has no inlined fields
242      */
243     ClassInlinedFields[] findClassInlinedFields(long classID) {
244         return inlinedFields.get(makeId(classID));
245     }
246 
247     /**
248      * @return true iff it's possible that some JavaThing instances might
249      *          isNew set
250      *
251      * @see JavaThing.isNew()
252      */
253     public boolean getHasNewSet() {
254         return hasNewSet;
255     }
256 
257     //
258     // Used in the body of resolve()
259     //
260     private static class MyVisitor extends AbstractJavaHeapObjectVisitor {
261         JavaHeapObject t;
262         public void visit(JavaHeapObject other) {
263             other.addReferenceFrom(t);
264         }
265     }
< prev index next >