Skip to content

Commit cf60186

Browse files
committed
GH-630 use base and offset in AbstractLongMap - this way whole Entry is in the same dumpBuffer of LongMemoryMappedData
1 parent adf305e commit cf60186

File tree

2 files changed

+70
-70
lines changed

2 files changed

+70
-70
lines changed

visualvm/libs.profiler/lib.profiler.heap/src/org/graalvm/visualvm/lib/jfluid/heap/AbstractLongMap.java

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Entry get(long key) {
8787
long index = getIndex(key);
8888

8989
while (true) {
90-
long mapKey = getID(index);
90+
long mapKey = getID(index, 0);
9191

9292
if (mapKey == key) {
9393
return createEntry(index);
@@ -105,9 +105,9 @@ Entry put(long key, long value) {
105105
long index = getIndex(key);
106106

107107
while (true) {
108-
long mapKey = getID(index);
108+
long mapKey = getID(index, 0);
109109
if (mapKey == 0L) {
110-
putID(index, key);
110+
putID(index, 0, key);
111111
return createEntry(index,value);
112112
} else if (mapKey == key) {
113113
return createEntry(index);
@@ -135,33 +135,33 @@ static Data getDumpBuffer(File f, RandomAccessFile file, int entrySize) throws I
135135
}
136136
}
137137

138-
long getID(long index) {
138+
long getID(long base, int offset) {
139139
if (ID_SIZE == 4) {
140-
return ((long)dumpBuffer.getInt(index)) & 0xFFFFFFFFL;
140+
return ((long)dumpBuffer.getInt(base, offset)) & 0xFFFFFFFFL;
141141
}
142-
return dumpBuffer.getLong(index);
142+
return dumpBuffer.getLong(base, offset);
143143
}
144144

145-
void putID(long index,long key) {
145+
void putID(long base, int offset,long key) {
146146
if (ID_SIZE == 4) {
147-
dumpBuffer.putInt(index,(int)key);
147+
dumpBuffer.putInt(base, offset,(int)key);
148148
} else {
149-
dumpBuffer.putLong(index,key);
149+
dumpBuffer.putLong(base, offset, key);
150150
}
151151
}
152152

153-
long getFoffset(long index) {
153+
long getFoffset(long base, int offset) {
154154
if (FOFFSET_SIZE == 4) {
155-
return dumpBuffer.getInt(index);
155+
return dumpBuffer.getInt(base, offset);
156156
}
157-
return dumpBuffer.getLong(index);
157+
return dumpBuffer.getLong(base, offset);
158158
}
159159

160-
void putFoffset(long index,long key) {
160+
void putFoffset(long base, int offset,long key) {
161161
if (FOFFSET_SIZE == 4) {
162-
dumpBuffer.putInt(index,(int)key);
162+
dumpBuffer.putInt(base, offset, (int)key);
163163
} else {
164-
dumpBuffer.putLong(index,key);
164+
dumpBuffer.putLong(base, offset, key);
165165
}
166166
}
167167

@@ -231,17 +231,17 @@ static Data readFromStream(DataInputStream dis, CacheDirectory cacheDir, int ent
231231
}
232232
}
233233

234-
byte getByte(long index);
234+
byte getByte(long base, int offset);
235235

236-
int getInt(long index);
236+
int getInt(long base, int offset);
237237

238-
long getLong(long index);
238+
long getLong(long base, int offset);
239239

240-
void putByte(long index, byte data);
240+
void putByte(long base, int offset, byte data);
241241

242-
void putInt(long index, int data);
242+
void putInt(long base, int offset, int data);
243243

244-
void putLong(long index, long data);
244+
void putLong(long base, int offset, long data);
245245

246246
void force() throws IOException;
247247

@@ -293,13 +293,13 @@ private static class FileData extends AbstractData {
293293

294294
//~ Methods --------------------------------------------------------------------------------------------------------------
295295

296-
public synchronized byte getByte(long index) {
297-
int i = loadBufferIfNeeded(index);
296+
public synchronized byte getByte(long base, int offset) {
297+
int i = loadBufferIfNeeded(base+offset);
298298
return buf[i];
299299
}
300300

301-
public synchronized int getInt(long index) {
302-
int i = loadBufferIfNeeded(index);
301+
public synchronized int getInt(long base, int offset) {
302+
int i = loadBufferIfNeeded(base+offset);
303303
int ch1 = ((int) buf[i++]) & 0xFF;
304304
int ch2 = ((int) buf[i++]) & 0xFF;
305305
int ch3 = ((int) buf[i++]) & 0xFF;
@@ -308,8 +308,8 @@ public synchronized int getInt(long index) {
308308
return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
309309
}
310310

311-
public synchronized long getLong(long index) {
312-
int i = loadBufferIfNeeded(index);
311+
public synchronized long getLong(long base, int offset) {
312+
int i = loadBufferIfNeeded(base+offset);
313313
return (((long)buf[i++] << 56) +
314314
((long)(buf[i++] & 255) << 48) +
315315
((long)(buf[i++] & 255) << 40) +
@@ -320,23 +320,23 @@ public synchronized long getLong(long index) {
320320
((buf[i++] & 255) << 0));
321321
}
322322

323-
public synchronized void putByte(long index, byte data) {
324-
int i = loadBufferIfNeeded(index);
323+
public synchronized void putByte(long base, int offset, byte data) {
324+
int i = loadBufferIfNeeded(base+offset);
325325
buf[i] = data;
326326
bufferModified = true;
327327
}
328328

329-
public synchronized void putInt(long index, int data) {
330-
int i = loadBufferIfNeeded(index);
329+
public synchronized void putInt(long base, int offset, int data) {
330+
int i = loadBufferIfNeeded(base+offset);
331331
buf[i++] = (byte) (data >>> 24);
332332
buf[i++] = (byte) (data >>> 16);
333333
buf[i++] = (byte) (data >>> 8);
334334
buf[i++] = (byte) (data >>> 0);
335335
bufferModified = true;
336336
}
337337

338-
public synchronized void putLong(long index, long data) {
339-
int i = loadBufferIfNeeded(index);
338+
public synchronized void putLong(long base, int offset, long data) {
339+
int i = loadBufferIfNeeded(base+offset);
340340
buf[i++] = (byte) (data >>> 56);
341341
buf[i++] = (byte) (data >>> 48);
342342
buf[i++] = (byte) (data >>> 40);
@@ -408,28 +408,28 @@ private static class MemoryMappedData extends AbstractData {
408408

409409
//~ Methods --------------------------------------------------------------------------------------------------------------
410410

411-
public byte getByte(long index) {
412-
return buf.get((int) index);
411+
public byte getByte(long base, int offset) {
412+
return buf.get((int) base+offset);
413413
}
414414

415-
public int getInt(long index) {
416-
return buf.getInt((int) index);
415+
public int getInt(long base, int offset) {
416+
return buf.getInt((int) base+offset);
417417
}
418418

419-
public long getLong(long index) {
420-
return buf.getLong((int) index);
419+
public long getLong(long base, int offset) {
420+
return buf.getLong((int) base+offset);
421421
}
422422

423-
public void putByte(long index, byte data) {
424-
buf.put((int) index, data);
423+
public void putByte(long base, int offset, byte data) {
424+
buf.put((int) base+offset, data);
425425
}
426426

427-
public void putInt(long index, int data) {
428-
buf.putInt((int) index, data);
427+
public void putInt(long base, int offset, int data) {
428+
buf.putInt((int) base+offset, data);
429429
}
430430

431-
public void putLong(long index, long data) {
432-
buf.putLong((int) index, data);
431+
public void putLong(long base, int offset, long data) {
432+
buf.putLong((int) base+offset, data);
433433
}
434434

435435
@Override
@@ -489,28 +489,28 @@ private static class LongMemoryMappedData extends AbstractData {
489489

490490
//~ Methods --------------------------------------------------------------------------------------------------------------
491491

492-
public byte getByte(long index) {
493-
return dumpBuffer[getBufferIndex(index)].get(getBufferOffset(index));
492+
public byte getByte(long base, int offset) {
493+
return dumpBuffer[getBufferIndex(base)].get(getBufferOffset(base)+offset);
494494
}
495495

496-
public int getInt(long index) {
497-
return dumpBuffer[getBufferIndex(index)].getInt(getBufferOffset(index));
496+
public int getInt(long base, int offset) {
497+
return dumpBuffer[getBufferIndex(base)].getInt(getBufferOffset(base)+offset);
498498
}
499499

500-
public long getLong(long index) {
501-
return dumpBuffer[getBufferIndex(index)].getLong(getBufferOffset(index));
500+
public long getLong(long base, int offset) {
501+
return dumpBuffer[getBufferIndex(base)].getLong(getBufferOffset(base)+offset);
502502
}
503503

504-
public void putByte(long index, byte data) {
505-
dumpBuffer[getBufferIndex(index)].put(getBufferOffset(index),data);
504+
public void putByte(long base, int offset, byte data) {
505+
dumpBuffer[getBufferIndex(base)].put(getBufferOffset(base)+offset,data);
506506
}
507507

508-
public void putInt(long index, int data) {
509-
dumpBuffer[getBufferIndex(index)].putInt(getBufferOffset(index),data);
508+
public void putInt(long base, int offset, int data) {
509+
dumpBuffer[getBufferIndex(base)].putInt(getBufferOffset(base)+offset,data);
510510
}
511511

512-
public void putLong(long index, long data) {
513-
dumpBuffer[getBufferIndex(index)].putLong(getBufferOffset(index),data);
512+
public void putLong(long base, int offset, long data) {
513+
dumpBuffer[getBufferIndex(base)].putLong(getBufferOffset(base)+offset,data);
514514
}
515515

516516
private int getBufferIndex(long index) {

visualvm/libs.profiler/lib.profiler.heap/src/org/graalvm/visualvm/lib/jfluid/heap/LongMap.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,17 @@ private Entry(long off) {
7171

7272
private Entry(long off,long value) {
7373
offset = off;
74-
putFoffset(offset + KEY_SIZE, value);
74+
putFoffset(offset, KEY_SIZE, value);
7575
}
7676

7777
//~ Methods --------------------------------------------------------------------------------------------------------------
7878

7979
void setIndex(int index) {
80-
dumpBuffer.putInt(offset + KEY_SIZE + FOFFSET_SIZE, index);
80+
dumpBuffer.putInt(offset, KEY_SIZE + FOFFSET_SIZE, index);
8181
}
8282

8383
int getIndex() {
84-
return dumpBuffer.getInt(offset + KEY_SIZE + FOFFSET_SIZE);
84+
return dumpBuffer.getInt(offset, KEY_SIZE + FOFFSET_SIZE);
8585
}
8686

8787
void setTreeObj() {
@@ -177,38 +177,38 @@ LongIterator getReferences() {
177177
}
178178

179179
long getOffset() {
180-
return getFoffset(offset + KEY_SIZE);
180+
return getFoffset(offset, KEY_SIZE);
181181
}
182182

183183
void setRetainedSize(long size) {
184184
if (FOFFSET_SIZE == 4) {
185-
dumpBuffer.putInt(offset + KEY_SIZE + FOFFSET_SIZE + 4 + 1 + ID_SIZE, (int)size);
185+
dumpBuffer.putInt(offset, KEY_SIZE + FOFFSET_SIZE + 4 + 1 + ID_SIZE, (int)size);
186186
} else {
187-
dumpBuffer.putLong(offset + KEY_SIZE + FOFFSET_SIZE + 4 + 1 + ID_SIZE, size);
187+
dumpBuffer.putLong(offset, KEY_SIZE + FOFFSET_SIZE + 4 + 1 + ID_SIZE, size);
188188
}
189189
}
190190

191191
long getRetainedSize() {
192192
if (FOFFSET_SIZE == 4) {
193-
return dumpBuffer.getInt(offset + KEY_SIZE + FOFFSET_SIZE + 4 + 1 + ID_SIZE);
193+
return dumpBuffer.getInt(offset, KEY_SIZE + FOFFSET_SIZE + 4 + 1 + ID_SIZE);
194194
}
195-
return dumpBuffer.getLong(offset + KEY_SIZE + FOFFSET_SIZE + 4 + 1 + ID_SIZE);
195+
return dumpBuffer.getLong(offset, KEY_SIZE + FOFFSET_SIZE + 4 + 1 + ID_SIZE);
196196
}
197197

198198
private void setReferencesPointer(long instanceId) {
199-
putID(offset + KEY_SIZE + FOFFSET_SIZE + 4 + 1, instanceId);
199+
putID(offset, KEY_SIZE + FOFFSET_SIZE + 4 + 1, instanceId);
200200
}
201201

202202
private long getReferencesPointer() {
203-
return getID(offset + KEY_SIZE + FOFFSET_SIZE + 4 + 1);
203+
return getID(offset, KEY_SIZE + FOFFSET_SIZE + 4 + 1);
204204
}
205205

206206
private void setFlags(byte flags) {
207-
dumpBuffer.putByte(offset + KEY_SIZE + FOFFSET_SIZE + 4, flags);
207+
dumpBuffer.putByte(offset, KEY_SIZE + FOFFSET_SIZE + 4, flags);
208208
}
209209

210210
private byte getFlags() {
211-
return dumpBuffer.getByte(offset + KEY_SIZE + FOFFSET_SIZE + 4);
211+
return dumpBuffer.getByte(offset, KEY_SIZE + FOFFSET_SIZE + 4);
212212
}
213213
}
214214

@@ -285,7 +285,7 @@ long[] getBiggestObjectsByRetainedSize(int number) {
285285
long[] bigIds = new long[number];
286286
long min = 0;
287287
for (long index=0;index<fileSize;index+=ENTRY_SIZE) {
288-
long id = getID(index);
288+
long id = getID(index, 0);
289289
if (id != 0) {
290290
long retainedSize = createEntry(index).getRetainedSize();
291291
if (bigObjects.size()<number) {

0 commit comments

Comments
 (0)