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/IndexReader.java (-30 / +31 lines)
Lines 169-209 public abstract class IndexReader Link Here
169
        protected ArrayIntCompressed getPage(int page)
169
        protected ArrayIntCompressed getPage(int page)
170
        {
170
        {
171
            SoftReference<ArrayIntCompressed> ref = pages.get(page);
171
            SoftReference<ArrayIntCompressed> ref = pages.get(page);
172
            ArrayIntCompressed array = ref == null ? null : ref.get();
172
            if (ref != null && ref.get() != null)
173
            if (array == null)
174
            {
173
            {
175
                synchronized (LOCK)
174
                return ref.get();
176
                {
175
            }
177
                    ref = pages.get(page);
178
                    array = ref == null ? null : ref.get();
179
180
                    if (array == null)
181
                    {
182
                        try
183
                        {
184
                            byte[] buffer = null;
185
186
                            this.in.seek(pageStart[page]);
187
188
                            buffer = new byte[(int) (pageStart[page + 1] - pageStart[page])];
189
                            if (this.in.read(buffer) != buffer.length)
190
                                throw new IOException();
191
176
192
                            array = new ArrayIntCompressed(buffer);
177
            // no read is ready with a complete read; do a read
178
            long ltoRead = pageStart[page + 1] - pageStart[page];
179
            if (ltoRead >= Integer.MAX_VALUE)
180
            {
181
                throw new RuntimeException(new IOException("want to read too many bytes"));
182
            }
183
            int toRead = (int) ltoRead;
184
            byte[] buffer;
185
            try
186
            {
187
                buffer = this.in.readDirect(pageStart[page], toRead);
188
            }
189
            catch (IOException e)
190
            {
191
                throw new RuntimeException(e);
192
            }
193
193
194
                            synchronized (pages)
194
            synchronized(pages)
195
                            {
195
            {
196
                                pages.put(page, new SoftReference<ArrayIntCompressed>(array));
196
                // if another thread finished a concurrent read, use it
197
                            }
197
                ref = pages.get(page);
198
                        }
198
                if (ref != null && ref.get() != null)
199
                        catch (IOException e)
199
                {
200
                        {
200
                    return ref.get();
201
                            throw new RuntimeException(e);
202
                        }
203
                    }
204
                }
201
                }
202
203
                // if this thread is first, it can store
204
                ArrayIntCompressed array = new ArrayIntCompressed(buffer);
205
                pages.put(page, new SoftReference<>(array));
206
                return array;
205
            }
207
            }
206
            return array;
207
        }
208
        }
208
209
209
        public void delete()
210
        public void delete()
(-)a/plugins/org.eclipse.mat.parser/src/org/eclipse/mat/parser/io/SimpleBufferedRandomAccessInputStream.java (+16 lines)
Lines 14-19 import java.io.EOFException; Link Here
14
import java.io.IOException;
14
import java.io.IOException;
15
import java.io.InputStream;
15
import java.io.InputStream;
16
import java.io.RandomAccessFile;
16
import java.io.RandomAccessFile;
17
import java.nio.ByteBuffer;
17
18
18
public class SimpleBufferedRandomAccessInputStream extends InputStream
19
public class SimpleBufferedRandomAccessInputStream extends InputStream
19
{
20
{
Lines 44-49 public class SimpleBufferedRandomAccessInputStream extends InputStream Link Here
44
        real_pos = raf.getFilePointer();
45
        real_pos = raf.getFilePointer();
45
    }
46
    }
46
47
48
    public final byte[] readDirect(long position, int length) throws IOException
49
    {
50
        int totalRead = 0;
51
        while (totalRead < length)
52
        {
53
            int read += raf.getChannel().read(buffer, position);
54
            if (read < 0)
55
            {
56
                throw new IOException("incomplete read while performing read on buffer");
57
            }
58
            totalRead += read;
59
        }
60
        return buffer.array();
61
    }
62
47
    public final int read() throws IOException
63
    public final int read() throws IOException
48
    {
64
    {
49
        if (buf_pos >= buf_end)
65
        if (buf_pos >= buf_end)

Return to bug 570670