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 531-540 public abstract class IndexWriter Link Here
531
531
532
    public static class IntIndexCollector extends IntIndex<ArrayIntCompressed> implements IOne2OneIndex
532
    public static class IntIndexCollector extends IntIndex<ArrayIntCompressed> implements IOne2OneIndex
533
    {
533
    {
534
        static class IndexedThreadLocalCache<T>
535
        {
536
            final ThreadLocal<Integer> pageNumber = ThreadLocal.withInitial(() -> -1);
537
            final ThreadLocal<SoftReference<T>> page = ThreadLocal.withInitial(() -> null);
538
539
            void set(int pageNumber, T page)
540
            {
541
                this.pageNumber.set(pageNumber);
542
                this.page.set(new SoftReference(page));
543
            }
544
545
            T get(int pageNumber)
546
            {
547
                return (this.pageNumber.get() == pageNumber) ? this.page.get().get() : null;
548
            }
549
        }
550
534
        final int mostSignificantBit;
551
        final int mostSignificantBit;
535
        final int size;
552
        final int size;
536
        final int pageSize = IndexWriter.PAGE_SIZE_INT;
553
        final int pageSize = IndexWriter.PAGE_SIZE_INT;
537
        final ConcurrentHashMap<Integer, ArrayIntCompressed> pages = new ConcurrentHashMap<Integer, ArrayIntCompressed>();
554
        final ConcurrentHashMap<Integer, ArrayIntCompressed> pages = new ConcurrentHashMap<Integer, ArrayIntCompressed>();
555
        final IndexedThreadLocalCache<ArrayIntCompressed> localPageCache = new IndexedThreadLocalCache<>();
538
556
539
        public IntIndexCollector(int size, int mostSignificantBit)
557
        public IntIndexCollector(int size, int mostSignificantBit)
540
        {
558
        {
Lines 544-556 public abstract class IndexWriter Link Here
544
562
545
        protected ArrayIntCompressed getPage(int page)
563
        protected ArrayIntCompressed getPage(int page)
546
        {
564
        {
547
            ArrayIntCompressed existing = pages.get(page);
565
            ArrayIntCompressed existing = localPageCache.get(page);
548
            if (existing != null) return existing;
566
            if (existing != null)
567
                return existing;
568
569
            existing = pages.get(page);
570
            if (existing != null)
571
            {
572
                localPageCache.set(page, existing);
573
                return existing;
574
            }
549
575
550
            int ps = page < (size / pageSize) ? pageSize : size % pageSize;
576
            int ps = page < (size / pageSize) ? pageSize : size % pageSize;
551
            ArrayIntCompressed newArray = new ArrayIntCompressed(ps, 31 - mostSignificantBit, 0);
577
            ArrayIntCompressed newArray = new ArrayIntCompressed(ps, 31 - mostSignificantBit, 0);
552
            existing = pages.putIfAbsent(page, newArray);
578
            existing = pages.putIfAbsent(page, newArray);
553
            return (existing != null) ? existing : newArray;
579
            final ArrayIntCompressed result = (existing != null) ? existing : newArray;
580
            localPageCache.set(page, result);
581
            return result;
554
        }
582
        }
555
583
556
        public IIndexReader.IOne2OneIndex writeTo(File indexFile) throws IOException
584
        public IIndexReader.IOne2OneIndex writeTo(File indexFile) throws IOException
(-)a/plugins/org.eclipse.mat.parser/src/org/eclipse/mat/parser/io/SimpleBufferedRandomAccessInputStream.java (-2 / +3 lines)
Lines 47-61 public class SimpleBufferedRandomAccessInputStream extends InputStream Link Here
47
47
48
    public final byte[] readDirect(long position, int length) throws IOException
48
    public final byte[] readDirect(long position, int length) throws IOException
49
    {
49
    {
50
        ByteBuffer buffer = ByteBuffer.allocate(length);
50
        int totalRead = 0;
51
        int totalRead = 0;
51
        while (totalRead < length)
52
        while (totalRead < length)
52
        {
53
        {
53
            int read += raf.getChannel().read(buffer, position);
54
            int read =+ raf.getChannel().read(buffer, position);
54
            if (read < 0)
55
            if (read < 0)
55
            {
56
            {
56
                throw new IOException("incomplete read while performing read on buffer");
57
                throw new IOException("incomplete read while performing read on buffer");
57
            }
58
            }
58
            totalRead += read;
59
            totalRead =+ read;
59
        }
60
        }
60
        return buffer.array();
61
        return buffer.array();
61
    }
62
    }

Return to bug 570670