Skip to content

Instantly share code, notes, and snippets.

@seraphy
Created March 27, 2013 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seraphy/5255575 to your computer and use it in GitHub Desktop.
Save seraphy/5255575 to your computer and use it in GitHub Desktop.
物理メモリを大量に消費させるメモリストレスツール。 第一引数は確保するメモリをメガバイトで指定する。 "java -Xmx4000 -cp . MemFill 3000" とすることで、3GBの物理メモリを確保しようとする。
public class MemFill {
public static void main(String[] args) throws Exception {
if (args.length < 1) {
System.err.println("[usage] java -cp . MemFill <megabytes memory size>");
System.err.println("[example] java -Xmx4000m -cp . MemFill 3000");
System.exit(1);
}
int mega = 1024 * 1024;
int mx = Integer.parseInt(args[0]);
byte[][] bufs = new byte[mx][];
for (int idx = 0; idx < mx; idx++) {
bufs[idx] = new byte[mega];
System.console().printf("allocate %dMBytes\r", idx + 1);
}
System.console().printf("\r\ndone.\r\n");
System.console().readLine();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment