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

@ -26,6 +26,7 @@
package java.lang;
import jdk.internal.HotSpotIntrinsicCandidate;
import jdk.internal.misc.VM;
/**
*
@ -77,13 +78,25 @@ public final class Byte extends Number implements Comparable<Byte> {
}
private static class ByteCache {
private ByteCache(){}
private ByteCache() {}
static final Byte cache[] = new Byte[-(-128) + 127 + 1];
static final Byte[] cache;
static Byte[] archivedCache;
static {
for(int i = 0; i < cache.length; i++)
cache[i] = new Byte((byte)(i - 128));
final int size = -(-128) + 127 + 1;
// Load and use the archived cache if it exists
VM.initializeFromArchive(ByteCache.class);
if (archivedCache == null || archivedCache.length != size) {
Byte[] c = new Byte[size];
byte value = (byte)-128;
for(int i = 0; i < size; i++) {
c[i] = new Byte(value++);
}
archivedCache = c;
}
cache = archivedCache;
}
}

View file

@ -31,6 +31,7 @@ import java.util.HashMap;
import java.util.Locale;
import jdk.internal.HotSpotIntrinsicCandidate;
import jdk.internal.misc.VM;
/**
* The {@code Character} class wraps a value of the primitive
@ -7914,11 +7915,22 @@ class Character implements java.io.Serializable, Comparable<Character> {
private static class CharacterCache {
private CharacterCache(){}
static final Character cache[] = new Character[127 + 1];
static final Character[] cache;
static Character[] archivedCache;
static {
for (int i = 0; i < cache.length; i++)
cache[i] = new Character((char)i);
int size = 127 + 1;
// Load and use the archived cache if it exists
VM.initializeFromArchive(CharacterCache.class);
if (archivedCache == null || archivedCache.length != size) {
Character[] c = new Character[size];
for (int i = 0; i < size; i++) {
c[i] = new Character((char) i);
}
archivedCache = c;
}
cache = archivedCache;
}
}

View file

@ -1013,10 +1013,9 @@ public final class Integer extends Number implements Comparable<Integer> {
VM.getSavedProperty("java.lang.Integer.IntegerCache.high");
if (integerCacheHighPropValue != null) {
try {
int i = parseInt(integerCacheHighPropValue);
i = Math.max(i, 127);
h = Math.max(parseInt(integerCacheHighPropValue), 127);
// Maximum array size is Integer.MAX_VALUE
h = Math.min(i, Integer.MAX_VALUE - (-low) -1);
h = Math.min(h, Integer.MAX_VALUE - (-low) -1);
} catch( NumberFormatException nfe) {
// If the property cannot be parsed into an int, ignore it.
}
@ -1031,8 +1030,9 @@ public final class Integer extends Number implements Comparable<Integer> {
if (archivedCache == null || size > archivedCache.length) {
Integer[] c = new Integer[size];
int j = low;
for(int k = 0; k < c.length; k++)
c[k] = new Integer(j++);
for(int i = 0; i < c.length; i++) {
c[i] = new Integer(j++);
}
archivedCache = c;
}
cache = archivedCache;

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;
}
}

View file

@ -26,6 +26,7 @@
package java.lang;
import jdk.internal.HotSpotIntrinsicCandidate;
import jdk.internal.misc.VM;
/**
* The {@code Short} class wraps a value of primitive type {@code
@ -203,13 +204,25 @@ public final class Short extends Number implements Comparable<Short> {
}
private static class ShortCache {
private ShortCache(){}
private ShortCache() {}
static final Short cache[] = new Short[-(-128) + 127 + 1];
static final Short[] cache;
static Short[] archivedCache;
static {
for(int i = 0; i < cache.length; i++)
cache[i] = new Short((short)(i - 128));
int size = -(-128) + 127 + 1;
// Load and use the archived cache if it exists
VM.initializeFromArchive(ShortCache.class);
if (archivedCache == null || archivedCache.length != size) {
Short[] c = new Short[size];
short value = -128;
for(int i = 0; i < size; i++) {
c[i] = new Short(value++);
}
archivedCache = c;
}
cache = archivedCache;
}
}