2016-02-10 25 views
0

我有一個合金模型,在Alloy工具(alloy4.2.jar)中運行時,可以毫無問題地生成實例。但是,當我將這個模型用作Java中Alloy api的輸入時,爲了逐個獲取所有這些實例,一段時間後會產生內存不足錯誤(在出現錯誤之前捕獲了許多實例)。當使用合金API for Java時OutOfMemoryError

在如果命令只是在try命令之後位於(對應於JDolly.java:192在打印堆棧跟蹤進一步)所述在下面的代碼完全發生該錯誤:

@Override 
    public boolean hasNext() { 
     // primeira vez 
     if (firstTime) initializeAlloyAnalyzer(); 
     if (currentAns.satisfiable() && firstTime) {    
      firstTime = false; 
      return true; 
     } 

     if (maximumPrograms > 0 && maximumPrograms == currentProgram) return false; 

     boolean result = true; 

     try { 
      if (!currentAns.next().satisfiable() || currentAns.equals(currentAns.next())){ 
       result = false; 
       System.out.println("TARCIANA -- non satisfiable, linha 194"); 
      } else { 
       currentAns = currentAns.next(); 
      } 

     } catch (Err e) { 
      result = false; 
      e.printStackTrace(); 
     } 

     return result; 
    } 

的打印堆棧跟蹤這個錯誤是:

Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded 
    at kodkod.util.collections.IdentityHashSet.<init>(IdentityHashSet.java:162) 
    at kodkod.util.nodes.AnnotatedNode$SharingDetector.sharedNodes(AnnotatedNode.java:278) 
    at kodkod.util.nodes.AnnotatedNode.<init>(AnnotatedNode.java:92) 
    at kodkod.util.nodes.AnnotatedNode.annotate(AnnotatedNode.java:114) 
    at kodkod.engine.fol2sat.Translator.evaluate(Translator.java:104) 
    at kodkod.engine.Evaluator.evaluate(Evaluator.java:117) 
    at edu.mit.csail.sdg.alloy4compiler.translator.A4Solution.rename(A4Solution.java:844) 
    at edu.mit.csail.sdg.alloy4compiler.translator.A4Solution.rename(A4Solution.java:841) 
    at edu.mit.csail.sdg.alloy4compiler.translator.A4Solution.rename(A4Solution.java:824) 
    at edu.mit.csail.sdg.alloy4compiler.translator.A4Solution.<init>(A4Solution.java:330) 
    at edu.mit.csail.sdg.alloy4compiler.translator.A4Solution.next(A4Solution.java:1031) 
    at ejdolly.JDolly.hasNext(JDolly.java:192) 
    at org.testorrery.ForLoopIterator.hasNext(ForLoopIterator.java:40) 
    at refactoringTest.RefactoringTest.runTests(RefactoringTest.java:141) 
    at refactoringTest.MainRunner.main(MainRunner.java:83) 

我覺得這個錯誤的原因可能是同中描述的: CapacityExceededException when reading a very large instance using A4SolutionReader

爲避免此錯誤,有何建議?

+0

什麼是您的-Xms和-Xmx參數?你試圖增加這個應用程序的這個參數? –

+0

當您使用該工具並在Java代碼中調用API時,您是否使用相同的求解器? 你可能想檢查A4Option類 –

+0

嗨,Loic。是的,求解器是一樣的。不同之處在於該工具立即告訴我們發現了實例。我們必須點擊next,next,next才能找到所有的實例。當使用api時,還會找到實例(超過600,000個),然後出現outofmemory錯誤,告訴我解決方案不可滿足。這是我認爲奇怪的。請幫幫我! – Tarciana

回答

0

解決方案(即A4Solution類的實例)的合金在鏈表方式組織,這意味着到next通話將主要計算基礎上,給出一個下一個解決方案,並把它放到列表中它鏈接到目前的解決方案。

如果您正在生成大量解決方案,而所有這些解決方案都正在存儲,那麼最終會導致內存不足異常。

您應該檢查您是否保留對所有解決方案(或僅第一個解決方案)的引用,從而防止它們被垃圾收集。

+0

事實並非如此。我做了一個測試,只讓每個A4Solution課程(沒有進行任何存儲或操作)來查看錯誤是否仍會發生,並且一旦生成A4Solution,就會發生錯誤。重點在於已經提供了對象實例(生成了A4Solution)並打印在我的程序中,但之後會發生錯誤。我認爲其原因可能與Loïc的問題中所描述的錯誤的原因類似:[link](http://stackoverflow.com/questions/35703242/capacityexceededexception-when-reading-a-very-large-instance-using -a4solutionrea) – Tarciana

+0

@loïcgammaitoni – Tarciana

+0

您能指出我們對您的測試有什麼展示嗎? – ivcha