8213033: Archive remaining primitive box caches

Reviewed-by: jiangli, alanb
This commit is contained in:
Claes Redestad 2018-11-20 21:12:46 +01:00
parent 4a235517f9
commit 4b45441ae9
9 changed files with 117 additions and 50 deletions

View file

@ -29,6 +29,7 @@ import java.lang.annotation.Native;
import java.math.*;
import java.util.Objects;
import jdk.internal.HotSpotIntrinsicCandidate;
import jdk.internal.misc.VM;
import static java.lang.String.COMPACT_STRINGS;
import static java.lang.String.LATIN1;
@ -1145,13 +1146,25 @@ public final class Long extends Number implements Comparable<Long> {
}
private static class LongCache {
private LongCache(){}
private LongCache() {}
static final Long cache[] = new Long[-(-128) + 127 + 1];
static final Long[] cache;
static Long[] archivedCache;
static {
for(int i = 0; i < cache.length; i++)
cache[i] = new Long(i - 128);
int size = -(-128) + 127 + 1;
// Load and use the archived cache if it exists
VM.initializeFromArchive(LongCache.class);
if (archivedCache == null || archivedCache.length != size) {
Long[] c = new Long[size];
long value = -128;
for(int i = 0; i < size; i++) {
c[i] = new Long(value++);
}
archivedCache = c;
}
cache = archivedCache;
}
}