View | Details | Raw Unified | Return to bug 572512 | Differences between
and this patch

Collapse All | Expand All

(-)a/plugins/org.eclipse.mat.parser/src/org/eclipse/mat/parser/internal/GarbageCleaner.java (-8 / +67 lines)
Lines 22-27 Link Here
22
import java.util.Iterator;
22
import java.util.Iterator;
23
import java.util.List;
23
import java.util.List;
24
import java.util.Map;
24
import java.util.Map;
25
import java.util.NoSuchElementException;
25
import java.util.concurrent.Callable;
26
import java.util.concurrent.Callable;
26
import java.util.concurrent.ExecutionException;
27
import java.util.concurrent.ExecutionException;
27
import java.util.concurrent.ExecutorService;
28
import java.util.concurrent.ExecutorService;
Lines 32-37 Link Here
32
import org.eclipse.mat.collect.BitField;
33
import org.eclipse.mat.collect.BitField;
33
import org.eclipse.mat.collect.HashMapIntObject;
34
import org.eclipse.mat.collect.HashMapIntObject;
34
import org.eclipse.mat.collect.IteratorInt;
35
import org.eclipse.mat.collect.IteratorInt;
36
import org.eclipse.mat.collect.IteratorLong;
35
import org.eclipse.mat.parser.index.IIndexReader.IOne2LongIndex;
37
import org.eclipse.mat.parser.index.IIndexReader.IOne2LongIndex;
36
import org.eclipse.mat.parser.index.IIndexReader.IOne2ManyIndex;
38
import org.eclipse.mat.parser.index.IIndexReader.IOne2ManyIndex;
37
import org.eclipse.mat.parser.index.IIndexReader.IOne2OneIndex;
39
import org.eclipse.mat.parser.index.IIndexReader.IOne2OneIndex;
Lines 76-84 Link Here
76
            int newNoOfObjects = 0;
78
            int newNoOfObjects = 0;
77
            int[] newRoots = idx.gcRoots.getAllKeys();
79
            int[] newRoots = idx.gcRoots.getAllKeys();
78
80
81
            IOne2LongIndex identifiersOld = idx.identifiers;
82
            File tempIndexFile = Index.IDENTIFIER.getFile(idx.snapshotInfo.getPrefix()+"temp."); //$NON-NLS-1$
83
            listener.subTask(MessageUtil.format(Messages.GarbageCleaner_Writing, tempIndexFile.getAbsolutePath()));
84
            idx.identifiers = new LongIndexStreamer().writeTo(tempIndexFile, new IteratorLong() {
85
                int i = 0;
86
                @Override
87
                public boolean hasNext()
88
                {
89
                    return i < identifiersOld.size();
90
                }
91
92
                @Override
93
                public long next()
94
                {
95
                    if (hasNext())
96
                        return identifiersOld.get(i++);
97
                    throw new NoSuchElementException();
98
                }
99
            });
100
            identifiersOld.close();
101
            identifiersOld.delete();
79
            IOne2LongIndex identifiers = idx.identifiers;
102
            IOne2LongIndex identifiers = idx.identifiers;
103
            identifiers.unload();
80
            IOne2ManyIndex preOutbound = idx.outbound;
104
            IOne2ManyIndex preOutbound = idx.outbound;
105
            IOne2OneIndex object2classIdOld = idx.object2classId;
106
            tempIndexFile = Index.O2CLASS.getFile(idx.snapshotInfo.getPrefix()+"temp."); //$NON-NLS-1$
107
            listener.subTask(MessageUtil.format(Messages.GarbageCleaner_Writing, tempIndexFile.getAbsolutePath()));
108
            idx.object2classId = new IntIndexStreamer().writeTo(tempIndexFile, new IteratorInt() {
109
                int i = 0;
110
                @Override
111
                public boolean hasNext()
112
                {
113
                    return i < object2classIdOld.size();
114
                }
115
116
                @Override
117
                public int next()
118
                {
119
                    if (hasNext())
120
                        return object2classIdOld.get(i++);
121
                    throw new NoSuchElementException();
122
                }
123
            });
124
            object2classIdOld.close();
125
            object2classIdOld.delete();
81
            IOne2OneIndex object2classId = idx.object2classId;
126
            IOne2OneIndex object2classId = idx.object2classId;
127
            object2classId.unload();
82
            HashMapIntObject<ClassImpl> classesById = idx.classesById;
128
            HashMapIntObject<ClassImpl> classesById = idx.classesById;
83
129
84
            /*
130
            /*
Lines 147-153 Link Here
147
193
148
            // create re-index map
194
            // create re-index map
149
            final int[] map = new int[oldNoOfObjects];
195
            final int[] map = new int[oldNoOfObjects];
150
            final long[] id2a = new long[newNoOfObjects];
151
196
152
            List<ClassImpl> classes2remove = new ArrayList<ClassImpl>();
197
            List<ClassImpl> classes2remove = new ArrayList<ClassImpl>();
153
198
Lines 157-164 Link Here
157
            {
202
            {
158
                if (reachable[ii])
203
                if (reachable[ii])
159
                {
204
                {
160
                    map[ii] = jj;
205
                    map[ii] = jj++;
161
                    id2a[jj++] = identifiers.get(ii);
162
                }
206
                }
163
                else
207
                else
164
                {
208
                {
Lines 217-226 Link Here
217
261
218
            reachable = null; // early gc...
262
            reachable = null; // early gc...
219
263
220
            identifiers.close();
221
            identifiers.delete();
222
            identifiers = null;
223
224
            if (listener.isCanceled())
264
            if (listener.isCanceled())
225
                throw new IProgressListener.OperationCanceledException();
265
                throw new IProgressListener.OperationCanceledException();
226
            listener.worked(1); // 4
266
            listener.worked(1); // 4
Lines 253-259 Link Here
253
293
254
            File indexFile = Index.IDENTIFIER.getFile(idx.snapshotInfo.getPrefix());
294
            File indexFile = Index.IDENTIFIER.getFile(idx.snapshotInfo.getPrefix());
255
            listener.subTask(MessageUtil.format(Messages.GarbageCleaner_Writing, indexFile.getAbsolutePath()));
295
            listener.subTask(MessageUtil.format(Messages.GarbageCleaner_Writing, indexFile.getAbsolutePath()));
256
            idxManager.setReader(Index.IDENTIFIER, new LongIndexStreamer().writeTo(indexFile, id2a));
296
            idxManager.setReader(Index.IDENTIFIER, new LongIndexStreamer().writeTo(indexFile, new IteratorLong() {
297
                int i = 0;
298
                @Override
299
                public boolean hasNext()
300
                {
301
                    while (i < map.length && map[i] == -1)
302
                        ++i;
303
                    return i < map.length;
304
                }
305
306
                @Override
307
                public long next()
308
                {
309
                    if (hasNext())
310
                        return identifiers.get(i++);
311
                    throw new NoSuchElementException();
312
                }
313
            }));
314
            identifiers.close();
315
            identifiers.delete();
257
316
258
            if (listener.isCanceled())
317
            if (listener.isCanceled())
259
                throw new IProgressListener.OperationCanceledException();
318
                throw new IProgressListener.OperationCanceledException();

Return to bug 572512