blob: 24db38d1b6784c208217ce2efbba74fea655769a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
/*
* Copyright (C) 2008 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.hit;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
public abstract class Instance {
long mId;
// Id of the ClassObj of which this object is an instance
long mClassId;
// The stack in which this object was allocated
StackTrace mStack;
// The heap in which this object was allocated (app, zygote, etc)
Heap mHeap;
// The size of this object
int mSize;
public interface Filter {
public boolean accept(Instance instance);
}
// List of all objects that hold a live reference to this object
private ArrayList<Instance> mParents;
/*
* After the whole HPROF file is read and parsed this method will be
* called on all heap objects so that they can resolve their internal
* object references.
*
* The super-State is passed in because some object references (such
* as interned Strings and static class fields) may need to be searched
* for in a heap other than the one this Instance is in.
*/
public abstract void resolveReferences(State state);
/*
* Some operations require gathering all the objects in a given section
* of the object graph. If non-null, the filter is applied to each
* node in the graph to determine if it should be added to the result
* set.
*/
public abstract void visit(Set<Instance> resultSet, Filter filter);
public void setSize(int size) {
mSize = size;
}
public final int getCompositeSize() {
HashSet<Instance> set = new HashSet<Instance>();
visit(set, null);
int size = 0;
for (Instance instance: set) {
size += instance.getSize();
}
return size;
}
// Returns the instrinsic size of a given object
public int getSize() {
return mSize;
}
public abstract String getTypeName();
public void setHeap(Heap heap) {
mHeap = heap;
}
// Add to the list of objects that have a hard reference to this Instance
public void addParent(Instance parent) {
if (mParents == null) {
mParents = new ArrayList<Instance>();
}
mParents.add(parent);
}
public ArrayList<Instance> getParents() {
if (mParents == null) {
mParents = new ArrayList<Instance>();
}
return mParents;
}
/*
* If this object has a reference to the object identified by id, return
* a String describing the reference in detail.
*/
public String describeReferenceTo(long id) {
return "No reference to 0x" + Long.toHexString(id);
}
}
|