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
Integer x = 127; | |
System.out.println(x); // 1 | |
System.out.println(127); // 2 | |
System.out.println((Integer) 127); // 3 | |
System.out.println(new Integer(127)); // 4 |
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
static { | |
// high value may be configured by property | |
int h = 127; | |
String integerCacheHighPropValue = | |
sun.misc.VM.getSavedProperty("java.lang.Integer.IntegerCache.high"); | |
if (integerCacheHighPropValue != null) { | |
int i = parseInt(integerCacheHighPropValue); | |
i = Math.max(i, 127); | |
// Maximum array size is Integer.MAX_VALUE | |
h = Math.min(i, Integer.MAX_VALUE - (-low) -1); | |
} | |
high = h; | |
cache = new Integer[(high - low) + 1]; | |
int j = low; | |
for(int k = 0; k < cache.length; k++) | |
cache[k] = new Integer(j++); | |
} |
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
private static class LongCache { | |
private LongCache(){} | |
static final Long cache[] = new Long[-(-128) + 127 + 1]; | |
static { | |
for(int i = 0; i < cache.length; i++) | |
cache[i] = new Long(i - 128); | |
} | |
} |
- -XX:AutoBoxCacheMax=XXXX - увеличивает размер кэшей (Integer, Long) до XXXX + 128, где будут храниться значения в интервале [-128; XXXX];
- -XX:+AggressiveOpts - опция изменяет значения множества опций, среди которых увеличивает AutoBoxCacheMax до 20 000;
- -Djava.lang.Integer.IntegerCache.high=XXXX - данная опция по аналогии с AutoBoxCacheMax увеличивает размер кэша, только в данном случае только для объектов типа Integer.
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
Field value = Integer.class.getDeclaredField("value"); | |
value.setAccessible(true); | |
value.set((Integer) 127, 0); |
Такие дела,
Иван
No comments:
Post a Comment