kframework / k-legacy

The K tools (deprecated, see README)
http://kframework.org
Other
146 stars 61 forks source link

GC limit exceeed error when using --output smart option #236

Closed seoseokje closed 10 years ago

seoseokje commented 10 years ago

I am trying to print with smart option so that I can compile with the result. However, I encountered GC limit exceeded error when the code is larger than certain length. (code with only declaration gave me the same error). With shorter code it worked well.

source code tested: test.c

int dwmonitor(float  *X, double  *D) {
    double q3;
    double q4;
    double s1;
    double s4;
    double s5; 
    double s6; 
    double s7;
    double s8;
    double w1;
    int w2;
    int i5; 
    int i3;
    s5 = 0.0;
    s8 = X[0];
    s7 = 1.0;
    for(i5 = 0; i5 <= 2; i5++) {
        s4 = (s7*D[i5]);
        s5 = (s5 + s4);
        s7 = (s7*s8);
    }
    s1 = 0.0;
    for(i3 = 0; i3 <= 1; i3++) {
        q3 = X[(i3 + 1)];
        q4 = X[(3 + i3)];
        w1 = (q3 - q4);
        s6 = ((((w1 >= 0))) ? (w1) : (-(w1)));
        s1 = ((((s1 >= s6))) ? (s1) : (s6));
    }
    w2 = ((s1 >= s5));
    return w2;
}

result without --output smart

    (int dwmonitor ( (((float *) X), ((double *) D)) ) ({ ((double s1142126 ;)
       ((double s62025 ;) ((double w11924 ;) ((double q41823 ;) ((double 
      q31722 ;) ((int i315 ;) ((double s11421 ;) ((double s620 ;) ((double 
      w119 ;) ((double q418 ;) ((double q317 ;) ((double s114 ;) ((double 
      s771013 ;) ((double s56912 ;) ((double s4811 ;) ((int i54 ;) ((double 
      s7710 ;) ((double s569 ;) ((double s48 ;) ((double s77 ;) ((double s56 ;
      ) ((double q3 ;) ((double q4 ;) ((double s1 ;) ((double s4 ;) ((double 
      s5 ;) ((double s6 ;) ((double s7 ;) ((double s8 ;) ((double w1 ;) ((int 
      w2 ;) ((int i5 ;) ((int i3 ;) (((s5 = 0.0) ;) (((s8 = (X [ 0 ])) ;) (((
      s7 = 1.0) ;) ((for ( (i5 = 0) ; (i5 < (3 - ((3 - 0) % 2))) ; (i5 = (i5 +
       (2 * 1))) ) ({ (((s4 = (s7 * (D [ i5 ]))) ;) (((s56 = (s5 + s4)) ;) (((
      s77 = (s7 * s8)) ;) (((s48 = (s77 * (D [ (i5 + 1) ]))) ;) (((s569 = (s56
       + s48)) ;) (((s7710 = (s77 * s8)) ;) .List{""})))))) })) ((for ( (i54 =
       (0 + (((3 - 0) / 2) * 2))) ; (i54 < 3) ; (i54 = (i54 + 1)) ) ({ (((
      s4811 = (s7710 * (D [ i54 ]))) ;) (((s56912 = (s569 + s4811)) ;) (((
      s771013 = (s7710 * s8)) ;) .List{""}))) })) (((s1 = 0.0) ;) ((for ( (i3 
      = 0) ; (i3 < (2 - ((2 - 0) % 2))) ; (i3 = (i3 + (2 * 1))) ) ({ (((q3 = (
      X [ (i3 + 1) ])) ;) (((q4 = (X [ (3 + i3) ])) ;) (((w1 = (q3 - q4)) ;) (
      ((s6 = ((w1 >= 0) ? w1 : (- w1))) ;) (((s114 = ((s1 >= s6) ? s1 : s6)) ;
      ) (((q317 = (X [ ((i3 + 1) + 1) ])) ;) (((q418 = (X [ (3 + (i3 + 1)) ]))
       ;) (((w119 = (q317 - q418)) ;) (((s620 = ((w119 >= 0) ? w119 : (- w119)
      )) ;) (((s11421 = ((s1 >= s620) ? s1 : s620)) ;) .List{""})))))))))) }))
       ((for ( (i315 = (0 + (((2 - 0) / 2) * 2))) ; (i315 < 2) ; (i315 = (i315
       + 1)) ) ({ (((q31722 = (X [ (i315 + 1) ])) ;) (((q41823 = (X [ (3 + 
      i315) ])) ;) (((w11924 = (q31722 - q41823)) ;) (((s62025 = ((w11924 >= 0
      ) ? w11924 : (- w11924))) ;) (((s1142126 = ((s1 >= s62025) ? s1 : s62025
      )) ;) .List{""}))))) })) (((w2 = (s1142126 >= s56912)) ;) ((return w2 ;)
       .List{""}))))))))))))))))))))))))))))))))))))))))))) })) .K

K_OPTS

export K_OPTS="-Xms1G -Xmx4G -Xss32m"
~/k-framework/bin/krun test.c --output smart
Fatal error at
    javaParseStringRules_0_0
    parse_string_1_2
    parse_string_1_3
    jsglr_parse_string_1_3
Exception in thread "main" java.lang.RuntimeException: java.lang.OutOfMemoryError: GC overhead limit exceeded
    at org.strategoxt.lang.StackSaver.invokeStackFriendly(StackSaver.java)
    at org.strategoxt.lang.Context.invokeStrategyCLI(Context.java)
    at org.kframework.parser.concrete.KParser.ParseKRuleString(KParser.java:224)
    at org.kframework.parser.DefinitionLoader.parsePatternAmbiguous(DefinitionLoader.java:369)
    at org.kframework.backend.unparser.AddBracketsFilter2.postpare(AddBracketsFilter2.java:117)
    at org.kframework.backend.unparser.AddBracketsFilter2.transform(AddBracketsFilter2.java:37)
    at org.kframework.kil.TermCons.accept(TermCons.java:155)
    at org.kframework.kil.visitors.BasicTransformer.transform(BasicTransformer.java:505)
    at org.kframework.backend.unparser.AddBracketsFilter2.transform(AddBracketsFilter2.java:36)
    at org.kframework.kil.TermCons.accept(TermCons.java:155)
    at org.kframework.kil.visitors.BasicTransformer.transform(BasicTransformer.java:505)
    at org.kframework.backend.unparser.AddBracketsFilter2.transform(AddBracketsFilter2.java:36)
    at org.kframework.kil.TermCons.accept(TermCons.java:155)
    at org.kframework.kil.visitors.BasicTransformer.transform(BasicTransformer.java:505)
    at org.kframework.backend.unparser.AddBracketsFilter2.transform(AddBracketsFilter2.java:36)
    at org.kframework.kil.TermCons.accept(TermCons.java:155)
    at org.kframework.kil.visitors.BasicTransformer.transform(BasicTransformer.java:505)
    at org.kframework.backend.unparser.AddBracketsFilter2.transform(AddBracketsFilter2.java:36)
    at org.kframework.kil.TermCons.accept(TermCons.java:155)
    at org.kframework.kil.visitors.BasicTransformer.transform(BasicTransformer.java:505)
    at org.kframework.backend.unparser.AddBracketsFilter2.transform(AddBracketsFilter2.java:36)
    at org.kframework.kil.TermCons.accept(TermCons.java:155)
    at org.kframework.kil.visitors.BasicTransformer.transform(BasicTransformer.java:505)
    at org.kframework.backend.unparser.AddBracketsFilter2.transform(AddBracketsFilter2.java:36)
    at org.kframework.kil.TermCons.accept(TermCons.java:155)
    at org.kframework.kil.visitors.BasicTransformer.transform(BasicTransformer.java:505)
    at org.kframework.backend.unparser.AddBracketsFilter2.transform(AddBracketsFilter2.java:36)
    at org.kframework.kil.TermCons.accept(TermCons.java:155)
    at org.kframework.kil.visitors.BasicTransformer.transform(BasicTransformer.java:505)
    at org.kframework.backend.unparser.AddBracketsFilter2.transform(AddBracketsFilter2.java:36)
    at org.kframework.kil.TermCons.accept(TermCons.java:155)
    at org.kframework.kil.visitors.BasicTransformer.transform(BasicTransformer.java:505)
    at org.kframework.backend.unparser.AddBracketsFilter2.transform(AddBracketsFilter2.java:36)
    at org.kframework.kil.TermCons.accept(TermCons.java:155)
    at org.kframework.kil.visitors.BasicTransformer.transform(BasicTransformer.java:192)
    at org.kframework.backend.unparser.AddBracketsFilter2.transform(AddBracketsFilter2.java:60)
    at org.kframework.kil.Cell.accept(Cell.java:274)
    at org.kframework.kil.visitors.BasicTransformer.transform(BasicTransformer.java:199)
    at org.kframework.backend.unparser.AddBracketsFilter2.transform(AddBracketsFilter2.java:44)
    at org.kframework.kil.visitors.BasicTransformer.transform(BasicTransformer.java:229)
    at org.kframework.kil.Bag.accept(Bag.java:77)
    at org.kframework.kil.visitors.BasicTransformer.transform(BasicTransformer.java:192)
    at org.kframework.backend.unparser.AddBracketsFilter2.transform(AddBracketsFilter2.java:60)
    at org.kframework.kil.Cell.accept(Cell.java:274)
    at org.kframework.krun.api.KRunState.concretize(KRunState.java:71)
    at org.kframework.krun.api.KRunState.getResult(KRunState.java:128)
    at org.kframework.krun.api.KRunState.toString(KRunState.java:118)
    at org.kframework.krun.api.KRunResult.toString(KRunResult.java:41)
    at org.kframework.krun.Main.normalExecution(Main.java:408)
    at org.kframework.krun.Main.execute_Krun(Main.java:1289)
    at org.kframework.main.Main.main(Main.java:71)
Caused by: java.lang.OutOfMemoryError: GC overhead limit exceeded
    at org.spoofax.jsglr.client.Disambiguator.applyPriorityFilter(Disambiguator.java:676)
    at org.spoofax.jsglr.client.Disambiguator.applyAssociativityPriorityFilter(Disambiguator.java:554)
    at org.spoofax.jsglr.client.Disambiguator.filterTree(Disambiguator.java:456)
    at org.spoofax.jsglr.client.Disambiguator.filterAmbiguities(Disambiguator.java:820)
    at org.spoofax.jsglr.client.Disambiguator.filterTree(Disambiguator.java:478)
    at org.spoofax.jsglr.client.Disambiguator.filterAmbiguities(Disambiguator.java:820)
    at org.spoofax.jsglr.client.Disambiguator.filterTree(Disambiguator.java:478)
    at org.spoofax.jsglr.client.Disambiguator.filterAmbiguities(Disambiguator.java:820)
    at org.spoofax.jsglr.client.Disambiguator.filterTree(Disambiguator.java:469)
    at org.spoofax.jsglr.client.Disambiguator.filterAmbiguities(Disambiguator.java:820)
    at org.spoofax.jsglr.client.Disambiguator.filterTree(Disambiguator.java:469)
    at org.spoofax.jsglr.client.Disambiguator.filterAmbiguities(Disambiguator.java:820)
    at org.spoofax.jsglr.client.Disambiguator.filterTree(Disambiguator.java:478)
    at org.spoofax.jsglr.client.Disambiguator.filterAmbiguities(Disambiguator.java:820)
    at org.spoofax.jsglr.client.Disambiguator.filterTree(Disambiguator.java:478)
    at org.spoofax.jsglr.client.Disambiguator.filterAmbiguities(Disambiguator.java:820)
    at org.spoofax.jsglr.client.Disambiguator.filterTree(Disambiguator.java:469)
    at org.spoofax.jsglr.client.Disambiguator.filterAmbiguities(Disambiguator.java:820)
    at org.spoofax.jsglr.client.Disambiguator.filterTree(Disambiguator.java:478)
    at org.spoofax.jsglr.client.Disambiguator.filterAmbiguities(Disambiguator.java:820)
    at org.spoofax.jsglr.client.Disambiguator.filterTree(Disambiguator.java:478)
    at org.spoofax.jsglr.client.Disambiguator.filterAmbiguities(Disambiguator.java:820)
    at org.spoofax.jsglr.client.Disambiguator.filterTree(Disambiguator.java:469)
    at org.spoofax.jsglr.client.Disambiguator.filterAmbiguities(Disambiguator.java:820)
    at org.spoofax.jsglr.client.Disambiguator.filterTree(Disambiguator.java:469)
    at org.spoofax.jsglr.client.Disambiguator.filterAmbiguities(Disambiguator.java:820)
    at org.spoofax.jsglr.client.Disambiguator.filterTree(Disambiguator.java:469)
    at org.spoofax.jsglr.client.Disambiguator.filterAmbiguities(Disambiguator.java:820)
    at org.spoofax.jsglr.client.Disambiguator.filterTree(Disambiguator.java:478)
    at org.spoofax.jsglr.client.Disambiguator.filterAmbiguities(Disambiguator.java:820)
    at org.spoofax.jsglr.client.Disambiguator.filterTree(Disambiguator.java:478)
    at org.spoofax.jsglr.client.Disambiguator.filterAmbiguities(Disambiguator.java:820)
liyili2 commented 10 years ago

I wonder if you can try the new version of the K and see what is the output now without using smart option. I think the output can be parsed at least.

seoseokje commented 10 years ago

I really appreciate your attention.

I updated k-framework to the newest version and I run it without smart option. and It WORKS! I am really appreciated!

I have one question for you.

what is difference between default output and --output smart? Is there anything I should be aware of?

liyili2 commented 10 years ago

output with smart option is supposed to print out a nice format with minimum parentheses, so that the output looks nicer. As you can see, the current output can be parsed but it looks ugly in some places. The output with smart option is supposed to solve the problem. However, this option is not fully developed yet. It can work in some semantics but not all. I think you can use the normal option in this few months.

seoseokje commented 10 years ago

I tried to compiled output with normal version and it was compiled. It seems normal mode is good for now. Thank you very much!

grosu commented 10 years ago

This is very good news! Can you please show us the new pretty printed code, just to take a look?

Great work, Liyi!

seoseokje commented 10 years ago

int dwmonitor ( double * X, double * D ) { double s121 ; double s620 ; double w119 ; double q418 ; double q317 ; double z116 ; double s5914 ; double s4813 ; double z7712 ; double z5611 ; int i54 ; double s710 ; double s59 ; double s48 ; double z77 ; double z56 ; double q3 ; double q4 ; double s1 ; double s4 ; double s5 ; double s6 ; double s7 ; double s8 ; double w1 ; int w2 ; int i5 ; int i3 ; double z1 ; double z5 ; double z7 ; s8 = X [ 0 ] ; for ( i5 = 0 ; (i5 < 2) ; i5 = (i5 + 2) ) { z5 = ((i5 == 0) ? 0.0 : s59) ; z7 = ((i5 == 0) ? 1.0 : s710) ; s4 = (z7 * D [ i5 ]) ; s5 = (z5 + s4) ; s7 = (z7 * s8) ; z56 = s5 ; z77 = s7 ; s48 = (z77 * D [ (i5 + 1) ]) ; s59 = (z56 + s48) ; s710 = (z77 * s8) ; } for ( i54 = 2 ; (i54 < 3) ; i54 = (i54 + 1) ) { z5611 = ((i54 == 0) ? 0.0 : s59) ; z7712 = ((i54 == 0) ? 1.0 : s710) ; s4813 = (z7712 * D [ i54 ]) ; s5914 = (z5611 + s4813) ; } for ( i3 = 0 ; (i3 < 2) ; i3 = (i3

this is the result I got from normal printing. This was good enough to compile. and I only need to remove .K at the end of it. I had to replace many part when I was using --output smart before.

Thank you!

grosu commented 10 years ago

Not bad! I think if we had a bit a whitespacing a la Maude's format attribute, then this code would actually look good for humans, too. There aren't too many parentheses. But the .K at the end does not make much sense. Why is it there, Liyi, do you know?

liyili2 commented 10 years ago

Actually, I do not know. I tested the code in C and similar code in Simple. I found that the simple version was fine but the C code had problem. I think I take care of this in my pretty printer. I will not print out .K if a K term is not empty. From the output of the code, we can see that it actually prints out the .K. It means that the term is divided into two part before we get the result term for pretty printer. One part is the actual C program, it is a K term. However, there is another K term which is an empty K term. I do not know if the c-semantics will use a ml parser to parse all terms. If it is, I think the problem might be from there, OR it is from some backend.

On Thu, Feb 20, 2014 at 5:38 PM, Grigore Rosu notifications@github.comwrote:

Not bad! I think if we had a bit a whitespacing a la Maude's format attribute, then this code would actually look good for humans, too. There aren't too many parentheses. But the .K at the end does not make much sense. Why is it there, Liyi, do you know?

Reply to this email directly or view it on GitHubhttps://github.com/kframework/k/issues/236#issuecomment-35683165 .