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

Collapse All | Expand All

(-)a/plugins/org.eclipse.mat.parser/src/org/eclipse/mat/parser/index/IndexWriter.java (-3 / +31 lines)
Lines 533-542 public abstract class IndexWriter Link Here
533
533
534
    public static class IntIndexCollector extends IntIndex<ArrayIntCompressed> implements IOne2OneIndex
534
    public static class IntIndexCollector extends IntIndex<ArrayIntCompressed> implements IOne2OneIndex
535
    {
535
    {
536
        static class IndexedThreadLocalCache<T>
537
        {
538
            final ThreadLocal<Integer> pageNumber = ThreadLocal.withInitial(() -> -1);
539
            final ThreadLocal<SoftReference<T>> page = ThreadLocal.withInitial(() -> null);
540
541
            void set(int pageNumber, T page)
542
            {
543
                this.pageNumber.set(pageNumber);
544
                this.page.set(new SoftReference(page));
545
            }
546
547
            T get(int pageNumber)
548
            {
549
                return (this.pageNumber.get() == pageNumber) ? this.page.get().get() : null;
550
            }
551
        }
552
536
        final int mostSignificantBit;
553
        final int mostSignificantBit;
537
        final int size;
554
        final int size;
538
        final int pageSize = IndexWriter.PAGE_SIZE_INT;
555
        final int pageSize = IndexWriter.PAGE_SIZE_INT;
539
        final ConcurrentHashMap<Integer, ArrayIntCompressed> pages = new ConcurrentHashMap<Integer, ArrayIntCompressed>();
556
        final ConcurrentHashMap<Integer, ArrayIntCompressed> pages = new ConcurrentHashMap<Integer, ArrayIntCompressed>();
557
        final IndexedThreadLocalCache<ArrayIntCompressed> localPageCache = new IndexedThreadLocalCache<>();
540
558
541
        public IntIndexCollector(int size, int mostSignificantBit)
559
        public IntIndexCollector(int size, int mostSignificantBit)
542
        {
560
        {
Lines 546-558 public abstract class IndexWriter Link Here
546
564
547
        protected ArrayIntCompressed getPage(int page)
565
        protected ArrayIntCompressed getPage(int page)
548
        {
566
        {
549
            ArrayIntCompressed existing = pages.get(page);
567
            ArrayIntCompressed existing = localPageCache.get(page);
550
            if (existing != null) return existing;
568
            if (existing != null)
569
                return existing;
570
571
            existing = pages.get(page);
572
            if (existing != null)
573
            {
574
                localPageCache.set(page, existing);
575
                return existing;
576
            }
551
577
552
            int ps = page < (size / pageSize) ? pageSize : size % pageSize;
578
            int ps = page < (size / pageSize) ? pageSize : size % pageSize;
553
            ArrayIntCompressed newArray = new ArrayIntCompressed(ps, 31 - mostSignificantBit, 0);
579
            ArrayIntCompressed newArray = new ArrayIntCompressed(ps, 31 - mostSignificantBit, 0);
554
            existing = pages.putIfAbsent(page, newArray);
580
            existing = pages.putIfAbsent(page, newArray);
555
            return (existing != null) ? existing : newArray;
581
            final ArrayIntCompressed result = (existing != null) ? existing : newArray;
582
            localPageCache.set(page, result);
583
            return result;
556
        }
584
        }
557
585
558
        public IIndexReader.IOne2OneIndex writeTo(File indexFile) throws IOException
586
        public IIndexReader.IOne2OneIndex writeTo(File indexFile) throws IOException

Return to bug 570670