Skip to content

Commit

Permalink
mmap/unsafe: include segmentSize when crashing
Browse files Browse the repository at this point in the history
  • Loading branch information
karussell committed Dec 9, 2019
1 parent 78793cf commit 982f837
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Expand Up @@ -234,9 +234,9 @@ private boolean mapIt(long offset, long byteCount) {
} catch (IOException ex) {
// we could get an exception here if buffer is too small and area too large
// e.g. I got an exception for the 65421th buffer (probably around 2**16 == 65536)
throw new RuntimeException("Couldn't map buffer " + i + " of " + segmentsToMap
+ " for " + name + " at position " + bufferStart + " for " + byteCount
+ " bytes with offset " + offset + ", new fileLength:" + newFileLength, ex);
throw new RuntimeException("Couldn't map buffer " + i + " of " + segmentsToMap + " with " + longSegmentSize
+ " for " + name + " at position " + bufferStart + " for " + byteCount + " bytes with offset " + offset
+ ", new fileLength:" + newFileLength + ", " + Helper.getMemInfo(), ex);
}
}

Expand All @@ -250,8 +250,7 @@ private ByteBuffer newByteBuffer(long offset, long byteCount) throws IOException
for (int trial = 0; trial < 1; ) {
try {
buf = raFile.getChannel().map(
allowWrites ? FileChannel.MapMode.READ_WRITE : FileChannel.MapMode.READ_ONLY,
offset, byteCount);
allowWrites ? FileChannel.MapMode.READ_WRITE : FileChannel.MapMode.READ_ONLY, offset, byteCount);
break;
} catch (IOException tmpex) {
ioex = tmpex;
Expand Down
12 changes: 10 additions & 2 deletions core/src/main/java/com/graphhopper/storage/UnsafeDataAccess.java
Expand Up @@ -17,6 +17,7 @@
*/
package com.graphhopper.storage;

import com.graphhopper.util.Helper;
import com.graphhopper.util.NotThreadSafe;

import java.io.File;
Expand Down Expand Up @@ -92,9 +93,16 @@ final boolean ensureCapacity(long bytes, boolean clearNewMem) {

try {
address = UNSAFE.reallocateMemory(address, capacity);
} catch (IllegalArgumentException ex) {
throw new IllegalArgumentException(ex.getMessage() + " - problem when allocating new memory. "
+ "address:" + address + "capacity:" + capacity + ", old capacity:" + oldCap + ", new bytes:" + newBytes
+ ", allSegments:" + allSegments + ", segmentSizeInBytes:" + segmentSizeInBytes
+ ", segmentSizePower:" + segmentSizePower + ", " + Helper.getMemInfo());
} catch (OutOfMemoryError err) {
throw new OutOfMemoryError(err.getMessage() + " - problem when allocating new memory. Old capacity: "
+ oldCap + ", new bytes:" + newBytes + ", segmentSizeIntsPower:" + segmentSizePower);
throw new OutOfMemoryError(err.getMessage() + " - problem when allocating new memory. "
+ "address:" + address + "capacity:" + capacity + ", old capacity:" + oldCap + ", new bytes:" + newBytes
+ ", allSegments:" + allSegments + ", segmentSizeInBytes:" + segmentSizeInBytes
+ ", segmentSizePower:" + segmentSizePower + ", " + Helper.getMemInfo());
}

if (clearNewMem)
Expand Down

0 comments on commit 982f837

Please sign in to comment.