< prev index next >

src/java.base/share/classes/java/lang/Integer.java

Print this page
rev 51374 : 8209120: Archive the Integer.IntegerCache
Reviewed-by: jiangli, alanb, plevart

*** 995,1005 **** */ private static class IntegerCache { static final int low = -128; static final int high; ! static final Integer cache[]; static { // high value may be configured by property int h = 127; String integerCacheHighPropValue = --- 995,1006 ---- */ private static class IntegerCache { static final int low = -128; static final int high; ! static final Integer[] cache; ! static Integer[] archivedCache; static { // high value may be configured by property int h = 127; String integerCacheHighPropValue =
*** 1014,1028 **** // If the property cannot be parsed into an int, ignore it. } } high = h; ! cache = new Integer[(high - low) + 1]; ! int j = low; ! for(int k = 0; k < cache.length; k++) ! cache[k] = new Integer(j++); // range [-128, 127] must be interned (JLS7 5.1.7) assert IntegerCache.high >= 127; } private IntegerCache() {} --- 1015,1037 ---- // If the property cannot be parsed into an int, ignore it. } } high = h; ! // Load IntegerCache.archivedCache from archive, if possible ! VM.initializeFromArchive(IntegerCache.class); ! int size = (high - low) + 1; + // Use the archived cache if it exists and is large enough + 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++); + archivedCache = c; + } + cache = archivedCache; // range [-128, 127] must be interned (JLS7 5.1.7) assert IntegerCache.high >= 127; } private IntegerCache() {}
< prev index next >