1
2
3
4
5
6
7
8
9
10
11
12
13
14 package net.sf.madmap;
15
16 import java.util.*;
17
18
19
20
21
22
23
24
25
26 public abstract class HprofHeapCollectable extends HprofHeapElement {
27
28
29 static final long _liveBits = 0x40000000;
30 static final long _claimedBits = 0x20000000;
31 static final long _sizeBits = 0x1fffffff;
32
33
34 protected Stack _visitedChildren;
35 long _retainedSize = 0;
36
37 public long getRetainedSize() { return (_retainedSize << 3) >> 3; }
38 public void claim() { _retainedSize = (_retainedSize | (_claimedBits << 32)); }
39 public boolean isClaimed() { return (_retainedSize & (_claimedBits << 32)) != 0; }
40 public void setClaimed( boolean x ) {
41 if ( x ) {
42 claim();
43 } else {
44 _retainedSize = (_retainedSize & (~(_claimedBits<<32)));
45 }
46 }
47
48 public boolean isAlive() { return (_retainedSize & (_liveBits << 32 )) != 0; }
49 public void setLiveness( boolean lv ) {
50 if ( lv ) {
51 _retainedSize = _retainedSize | (_liveBits << 32);
52 } else {
53 _retainedSize = _retainedSize & (~(_liveBits << 32));
54 }
55 }
56
57
58
59
60 public void setRetainedSize( long newSize) {
61 long oldBits = _retainedSize >> 61;
62 _retainedSize = newSize | (oldBits << 61);
63 }
64
65
66
67
68 public HprofHeapCollectable( long addr ) {
69 super( addr );
70 }
71
72 long[] longArrayListtoLongArray( ArrayList in ) {
73 if ( in == null ) {
74 return null;
75 }
76 if ( in.size() == 0 ) {
77 return null;
78 }
79 long[] out = new long[ in.size() ];
80 for ( int i = 0; i < out.length; i++ ) {
81 out[ i ] = ((Long) in.get( i )).longValue();
82 }
83 return out;
84 }
85
86
87 public abstract String className();
88 public abstract long children_size();
89 public abstract long[] children();
90 public abstract long size();
91
92
93
94
95
96 public boolean containsRef( long ref ) {
97 for ( int i = 0; i < children_size(); i ++ ) {
98 if ( children()[i] == ref ) {
99 return true;
100 }
101 }
102 return false;
103 }
104
105 void visited( HprofHeapCollectable child ) {
106 if ( _visitedChildren == null ) {
107 _visitedChildren = new Stack();
108 }
109 _visitedChildren.push( child );
110 }
111
112 Stack getVisitedStack() { return _visitedChildren; }
113 int getVisitedCount() {
114 return _visitedChildren == null ? 0 : _visitedChildren.size();
115 }
116
117 void resetVisited() {
118 _visitedChildren = null;
119 }
120 }