コード例 #1
0
ファイル: TestAll.java プロジェクト: rgb/intellij-community
  private boolean checkAvaliableMemory(int neededMemory, TestResult testResult) {
    if ((ourMode & CHECK_MEMORY) == 0) return true;

    boolean possibleOutOfMemoryError = possibleOutOfMemory(neededMemory);
    if (possibleOutOfMemoryError) {
      tryGc(5);
      possibleOutOfMemoryError = possibleOutOfMemory(neededMemory);
      if (possibleOutOfMemoryError) {
        log("OutOfMemoryError: dumping memory");
        Runtime runtime = Runtime.getRuntime();
        long total = runtime.totalMemory();
        long free = runtime.freeMemory();
        String errorMessage =
            "Too much memory used. Total: "
                + total
                + " free: "
                + free
                + " used: "
                + (total - free)
                + "\n";
        addErrorMessage(testResult, errorMessage);
      }
    }
    return !possibleOutOfMemoryError;
  }
コード例 #2
0
ファイル: TestAll.java プロジェクト: rgb/intellij-community
 private static boolean possibleOutOfMemory(int neededMemory) {
   Runtime runtime = Runtime.getRuntime();
   long maxMemory = runtime.maxMemory();
   long realFreeMemory = runtime.freeMemory() + (maxMemory - runtime.totalMemory());
   long meg = 1024 * 1024;
   long needed = neededMemory * meg;
   return realFreeMemory < needed;
 }
コード例 #3
0
ファイル: TestAll.java プロジェクト: rgb/intellij-community
  // [myakovlev] Do not delete - it is for debugging
  public static void tryGc(int times) {
    if ((ourMode & RUN_GC) == 0) return;

    for (int qqq = 1; qqq < times; qqq++) {
      try {
        Thread.sleep(qqq * 1000);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      System.gc();
      // long mem = Runtime.getRuntime().totalMemory();
      log("Runtime.getRuntime().totalMemory() = " + Runtime.getRuntime().totalMemory());
    }
  }