Skip to content

Instantly share code, notes, and snippets.

@ykubota
Last active October 18, 2016 09:50
Show Gist options
  • Save ykubota/5fe84f67817f543d77fa to your computer and use it in GitHub Desktop.
Save ykubota/5fe84f67817f543d77fa to your computer and use it in GitHub Desktop.
reproduce sample: java.lang.OutOfMemoryError: GC overhead limit exceeded
javac GCLimit.java
java -Xmx1m GCLimit
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class GCLimit {
static public void main(String[] args) {
Random random = new Random();
List<String> interned = new ArrayList<>();
while(true) {
int length = random.nextInt(100);
StringBuilder builder = new StringBuilder();
String sample = "whoisyourdaddy";
for ( int i = 0; i < length; i++ ) {
builder.append(sample.charAt(random.nextInt(sample.length())));
}
interned.add(builder.toString().intern());
}
}
}
環境によっては java.lang.OutOfMemoryError: java heap space (JDK6以前の場合はPermGen space) が先に来ます。
/Users/ykubota/tmp/oome% java -version
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)
/Users/ykubota/tmp/oome% java -Xmx1m GCLimit
Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
at java.util.Arrays.copyOf(Arrays.java:3326)
at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:137)
at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:121)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:622)
at java.lang.StringBuilder.append(StringBuilder.java:202)
at Test.main(Test.java:14)
/Users/ykubota/tmp/oome% java -Xmx1m -verbose:gc GCLimit
[GC (Allocation Failure) 512K->456K(1536K), 0.0010760 secs]
[GC (Allocation Failure) 968K->552K(1536K), 0.0009200 secs]
[GC (Allocation Failure) 1064K->712K(1536K), 0.0008590 secs]
[GC (Allocation Failure) 1224K->880K(1536K), 0.0007610 secs]
[Full GC (Ergonomics) 880K->794K(1536K), 0.0048670 secs]
[Full GC (Ergonomics) 1306K->939K(1536K), 0.0048860 secs]
[Full GC (Ergonomics) 1451K->1088K(1536K), 0.0059030 secs]
[Full GC (Ergonomics) 1435K->1164K(1536K), 0.0065140 secs]
[Full GC (Ergonomics) 1410K->1235K(1536K), 0.0066530 secs]
[Full GC (Ergonomics) 1410K->1287K(1536K), 0.0055740 secs]
[Full GC (Ergonomics) 1410K->1323K(1536K), 0.0054890 secs]
[Full GC (Ergonomics) 1404K->1345K(1536K), 0.0055300 secs]
[Full GC (Ergonomics) 1410K->1365K(1536K), 0.0055450 secs]
[Full GC (Ergonomics) 1410K->1378K(1536K), 0.0056680 secs]
[Full GC (Ergonomics) 1410K->1387K(1536K), 0.0057800 secs]
[Full GC (Ergonomics) 1410K->1394K(1536K), 0.0056700 secs]
[Full GC (Ergonomics) 1410K->1399K(1536K), 0.0057180 secs]
[Full GC (Ergonomics) 1410K->1402K(1536K), 0.0057780 secs]
[Full GC (Ergonomics) 1410K->1404K(1536K), 0.0058020 secs]
[Full GC (Ergonomics) 1410K->1406K(1536K), 0.0058950 secs]
[Full GC (Ergonomics) 1410K->1407K(1536K), 0.0058290 secs]
[Full GC (Ergonomics) 1410K->1408K(1536K), 0.0056160 secs]
[Full GC (Ergonomics) 1410K->1408K(1536K), 0.0055740 secs]
[Full GC (Ergonomics) 1410K->1409K(1536K), 0.0057410 secs]
[Full GC (Ergonomics) 1410K->1409K(1536K), 0.0056570 secs]
[Full GC (Ergonomics) 1410K->1409K(1536K), 0.0056890 secs]
[Full GC (Ergonomics) 1410K->1409K(1536K), 0.0058360 secs]
[Full GC (Ergonomics) 1410K->1409K(1536K), 0.0057470 secs]
[Full GC (Ergonomics) 1410K->1409K(1536K), 0.0058670 secs]
[Full GC (Ergonomics) 1415K->1411K(1536K), 0.0059540 secs]
[Full GC (Ergonomics) 1418K->1418K(1536K), 0.0057600 secs]
[Full GC (Ergonomics) 1424K->1419K(1536K), 0.0058680 secs]
[Full GC (Ergonomics) 1424K->1421K(1536K), 0.0056690 secs]
[Full GC (Ergonomics) 1421K->1421K(1536K), 0.0059040 secs]
[Full GC (Ergonomics) 1426K->1422K(1536K), 0.0058030 secs]
[Full GC (Ergonomics) 1422K->1422K(1536K), 0.0050790 secs]
[Full GC (Ergonomics) 1427K->1424K(1536K), 0.0057510 secs]
[Full GC (Ergonomics) 1429K->1425K(1536K), 0.0050450 secs]
[Full GC (Ergonomics) 1431K->1427K(1536K), 0.0051600 secs]
[Full GC (Ergonomics) 1432K->1429K(1536K), 0.0051970 secs]
[Full GC (Ergonomics) 1434K->1430K(1536K), 0.0052740 secs]
[Full GC (Ergonomics) 1435K->1432K(1536K), 0.0052040 secs]
[Full GC (Ergonomics) 1438K->1433K(1536K), 0.0044760 secs]
[Full GC (Ergonomics) 1439K->1435K(1536K), 0.0044110 secs]
[Full GC (Ergonomics) 1441K->1437K(1536K), 0.0051670 secs]
[Full GC (Ergonomics) 1442K->1438K(1536K), 0.0050410 secs]
[Full GC (Ergonomics) 1443K->1440K(1536K), 0.0053050 secs]
[Full GC (Ergonomics) 1445K->1441K(1536K), 0.0053040 secs]
[Full GC (Ergonomics) 1446K->1443K(1536K), 0.0046440 secs]
[Full GC (Ergonomics) 1448K->1444K(1536K), 0.0051160 secs]
[Full GC (Ergonomics) 1450K->1446K(1536K), 0.0047080 secs]
[Full GC (Ergonomics) 1451K->1447K(1536K), 0.0052480 secs]
[Full GC (Ergonomics) 1452K->1448K(1536K), 0.0053350 secs]
[Full GC (Ergonomics) 1454K->1450K(1536K), 0.0052260 secs]
[Full GC (Ergonomics) 1455K->1452K(1536K), 0.0052470 secs]
[Full GC (Ergonomics) 1457K->1453K(1536K), 0.0045840 secs]
[Full GC (Ergonomics) 1458K->1454K(1536K), 0.0053780 secs]
[Full GC (Ergonomics) 1462K->1459K(1536K), 0.0053260 secs]
[Full GC (Ergonomics) 1465K->1460K(1536K), 0.0054740 secs]
[Full GC (Ergonomics) 1467K->1462K(1536K), 0.0055760 secs]
[Full GC (Ergonomics) 1468K->1464K(1536K), 0.0054630 secs]
[Full GC (Ergonomics) 1469K->1466K(1536K), 0.0054010 secs]
[Full GC (Ergonomics) 1471K->1467K(1536K), 0.0046880 secs]
[Full GC (Ergonomics) 1473K->1469K(1536K), 0.0053080 secs]
[Full GC (Ergonomics) 1474K->1470K(1536K), 0.0053090 secs]
[Full GC (Ergonomics) 1476K->1472K(1536K), 0.0051470 secs]
[Full GC (Ergonomics) 1477K->1474K(1536K), 0.0052530 secs]
[Full GC (Ergonomics) 1479K->1475K(1536K), 0.0053980 secs]
[Full GC (Ergonomics) 1480K->1477K(1536K), 0.0052260 secs]
[Full GC (Ergonomics) 1482K->1478K(1536K), 0.0050240 secs]
[Full GC (Ergonomics) 1484K->1480K(1536K), 0.0053380 secs]
[Full GC (Ergonomics) 1485K->1481K(1536K), 0.0053850 secs]
[Full GC (Ergonomics) 1487K->1483K(1536K), 0.0053050 secs]
[Full GC (Ergonomics) 1487K->1484K(1536K), 0.0052220 secs]
[Full GC (Ergonomics) 1489K->1485K(1536K), 0.0049010 secs]
[Full GC (Ergonomics) 1491K->1487K(1536K), 0.0053030 secs]
[Full GC (Ergonomics) 1491K->1488K(1536K), 0.0052330 secs]
[Full GC (Ergonomics) 1489K->1489K(1536K), 0.0054290 secs]
[Full GC (Ergonomics) 1491K->1489K(1536K), 0.0053710 secs]
[Full GC (Ergonomics) 1491K->1490K(1536K), 0.0054600 secs]
[Full GC (Ergonomics) 1491K->1490K(1536K), 0.0053380 secs]
[Full GC (Ergonomics) 1491K->1490K(1536K), 0.0053470 secs]
[Full GC (Ergonomics) 1491K->1491K(1536K), 0.0052000 secs]
[Full GC (Ergonomics) 1491K->1491K(1536K), 0.0052190 secs]
[Full GC (Ergonomics) 1491K->1491K(1536K), 0.0054330 secs]
[Full GC (Ergonomics) 1485K->1485K(1536K), 0.0087820 secs]
[Full GC (Ergonomics) 1485K->1485K(1536K), 0.0073450 secs]
[Full GC (Ergonomics) 1485K->1485K(1536K), 0.0070220 secs]
[Full GC (Ergonomics) 1485K->1485K(1536K), 0.0075500 secs]
[Full GC (Ergonomics) 1485K->1485K(1536K), 0.0076280 secs]
[Full GC (Ergonomics) 1485K->1485K(1536K), 0.0074620 secs]
[Full GC (Ergonomics) 1485K->451K(1536K), 0.0045210 secs]
Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
at java.util.Arrays.copyOf(Arrays.java:3326)
at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:137)
at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:121)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:622)
at java.lang.StringBuilder.append(StringBuilder.java:202)
at GCLimit.main(GCLimit.java:14)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment