-
-
Save frsyuki/6fce6a75a0c400740dd3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int pagePosition = (int)(position % allocationGranularity); | |
long mapPosition = position - pagePosition; | |
long mapSize = size + pagePosition; | |
try { | |
// If no exception was thrown from map0, the address is valid | |
addr = map0(imode, mapPosition, mapSize); | |
} catch (OutOfMemoryError x) { | |
// An OutOfMemoryError may indicate that we've exhausted memory | |
// so force gc and re-attempt map | |
System.gc(); | |
try { | |
Thread.sleep(100); | |
} catch (InterruptedException y) { | |
Thread.currentThread().interrupt(); | |
} | |
try { | |
addr = map0(imode, mapPosition, mapSize); | |
} catch (OutOfMemoryError y) { | |
// After a second OOME, fail | |
throw new IOException("Map failed", y); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment