I am using Spoofax API with somewhat modified java front
Eclipse plugin builds java-front normally, but when I try to call Strj from my Java code I get StackOverflowError.
Environment: Ubuntu 18.04, OpenJDK 8
Code:

final Arguments arguments = new Arguments().addFile("-i", strategoFile) 
                .addFile("-o", output) 
                .addLine("-p lang.java.trans").add("--library").add("--clean")
                .addFile("-I", includeTrans)
                .addFile("-I", includeSrcGen)
                .addFile("-I", includeLib)
                .addFile("-I", includeBase) 
                .addFile("-I", Paths.get("/home/dvitel/sw/spoofax/spoofax/plugins/meta.lib.spoofax.eclipse_2.5.9/target/unpacked/latest/trans").toFile())
                .addFile("--cache-dir", cacheDir).add("-la", "stratego-lib")
                .add("-la", "stratego-sglr").add("-la", "stratego-gpp").add("-la", "stratego-xtc")
                .add("-la", "stratego-aterm").add("-la", "stratego-sdf").add("-la", "strc").add("-F");

FileObject languageSpecificationDir = spoofax.resourceService.resolve(languageDir);

final ResourceAgentTracker tracker = ...;

final ResourceAgent agent = tracker.agent();
agent.setAbsoluteWorkingDir(languageSpecificationDir);
agent.setAbsoluteDefinitionDir(languageSpecificationDir);

final ExecutionResult result = new StrategoExecutor().withStrjContext()
        .withStrategy(org.strategoxt.strj.main_0_0.instance).withTracker(tracker).withName("strj")
                .executeCLI(arguments);

executeCLI fails with next message:

Exception in thread "main" java.lang.StackOverflowError
        at org.strategoxt.strc.lifted4817.invoke(lifted4817.java:27)
        at org.strategoxt.stratego_lib.w_1200.invoke(w_1200.java:33)
        at org.strategoxt.lang.SRTS_EXT_crush_3_0.invoke(SRTS_EXT_crush_3_0.java:28)
        at org.strategoxt.lang.compat.override.performance_tweaks.foldr_3_0_override.invoke(foldr_3_0_override.java:29)
        at org.strategoxt.stratego_lib.w_1200.invoke(w_1200.java:75)
        at org.strategoxt.lang.SRTS_EXT_crush_3_0.invoke(SRTS_EXT_crush_3_0.java:28)
        at org.strategoxt.lang.compat.override.performance_tweaks.foldr_3_0_override.invoke(foldr_3_0_override.java:29)
        at org.strategoxt.stratego_lib.w_1200.invoke(w_1200.java:75)
        at org.strategoxt.lang.SRTS_EXT_crush_3_0.invoke(SRTS_EXT_crush_3_0.java:28)
        at org.strategoxt.lang.compat.override.performance_tweaks.foldr_3_0_override.invoke(foldr_3_0_override.java:29)
        at org.strategoxt.stratego_lib.w_1200.invoke(w_1200.java:75)
        at org.strategoxt.lang.SRTS_EXT_crush_3_0.invoke(SRTS_EXT_crush_3_0.java:28)
        at org.strategoxt.lang.compat.override.performance_tweaks.foldr_3_0_override.invoke(foldr_3_0_override.java:29)
        at org.strategoxt.stratego_lib.w_1200.invoke(w_1200.java:75)
        at org.strategoxt.lang.SRTS_EXT_crush_3_0.invoke(SRTS_EXT_crush_3_0.java:28)
        at org.strategoxt.lang.compat.override.performance_tweaks.foldr_3_0_override.invoke(foldr_3_0_override.java:29)
        at org.strategoxt.stratego_lib.w_1200.invoke(w_1200.java:75)
        at org.strategoxt.lang.SRTS_EXT_crush_3_0.invoke(SRTS_EXT_crush_3_0.java:28)
        at org.strategoxt.lang.compat.override.performance_tweaks.foldr_3_0_override.invoke(foldr_3_0_override.java:29)
        at org.strategoxt.stratego_lib.w_1200.invoke(w_1200.java:75)
        at org.strategoxt.lang.SRTS_EXT_crush_3_0.invoke(SRTS_EXT_crush_3_0.java:28)
        at org.strategoxt.lang.compat.override.performance_tweaks.foldr_3_0_override.invoke(foldr_3_0_override.java:29)
        at org.strategoxt.stratego_lib.w_1200.invoke(w_1200.java:75)
        at org.strategoxt.lang.SRTS_EXT_crush_3_0.invoke(SRTS_EXT_crush_3_0.java:28)
        at org.strategoxt.lang.compat.override.performance_tweaks.foldr_3_0_override.invoke(foldr_3_0_override.java:29)
        at org.strategoxt.stratego_lib.w_1200.invoke(w_1200.java:75)
        at org.strategoxt.lang.SRTS_EXT_crush_3_0.invoke(SRTS_EXT_crush_3_0.java:28)
        at org.strategoxt.lang.compat.override.performance_tweaks.foldr_3_0_override.invoke(foldr_3_0_override.java:29)
        at org.strategoxt.stratego_lib.w_1200.invoke(w_1200.java:75)
        at org.strategoxt.lang.SRTS_EXT_crush_3_0.invoke(SRTS_EXT_crush_3_0.java:28)
        at org.strategoxt.lang.compat.override.performance_tweaks.foldr_3_0_override.invoke(foldr_3_0_override.java:29)
        at org.strategoxt.stratego_lib.w_1200.invoke(w_1200.java:75)
        at org.strategoxt.lang.SRTS_EXT_crush_3_0.invoke(SRTS_EXT_crush_3_0.java:28)
        at org.strategoxt.lang.compat.override.performance_tweaks.foldr_3_0_override.invoke(foldr_3_0_override.java:29)
        at org.strategoxt.stratego_lib.w_1200.invoke(w_1200.java:75)
        at org.strategoxt.lang.SRTS_EXT_crush_3_0.invoke(SRTS_EXT_crush_3_0.java:28)
        at org.strategoxt.lang.compat.override.performance_tweaks.foldr_3_0_override.invoke(foldr_3_0_override.java:29)
        at org.strategoxt.stratego_lib.w_1200.invoke(w_1200.java:75)
        at org.strategoxt.lang.SRTS_EXT_crush_3_0.invoke(SRTS_EXT_crush_3_0.java:28)
        at org.strategoxt.lang.compat.override.performance_tweaks.foldr_3_0_override.invoke(foldr_3_0_override.java:29)
        at org.strategoxt.stratego_lib.w_1200.invoke(w_1200.java:75)
        at org.strategoxt.lang.SRTS_EXT_crush_3_0.invoke(SRTS_EXT_crush_3_0.java:28)
        at org.strategoxt.lang.compat.override.performance_tweaks.foldr_3_0_override.invoke(foldr_3_0_override.java:29)
        at org.strategoxt.stratego_lib.w_1200.invoke(w_1200.java:75)
        at org.strategoxt.lang.SRTS_EXT_crush_3_0.invoke(SRTS_EXT_crush_3_0.java:28)
        at org.strategoxt.lang.compat.override.performance_tweaks.foldr_3_0_override.invoke(foldr_3_0_override.java:29)
        at org.strategoxt.stratego_lib.w_1200.invoke(w_1200.java:75)
        at org.strategoxt.lang.SRTS_EXT_crush_3_0.invoke(SRTS_EXT_crush_3_0.java:28)
        at org.strategoxt.lang.compat.override.performance_tweaks.foldr_3_0_override.invoke(foldr_3_0_override.java:29)
        at org.strategoxt.stratego_lib.w_1200.invoke(w_1200.java:75)
        at org.strategoxt.lang.SRTS_EXT_crush_3_0.invoke(SRTS_EXT_crush_3_0.java:28)
        at org.strategoxt.lang.compat.override.performance_tweaks.foldr_3_0_override.invoke(foldr_3_0_override.java:29)
        at org.strategoxt.stratego_lib.w_1200.invoke(w_1200.java:75)
        at org.strategoxt.lang.SRTS_EXT_crush_3_0.invoke(SRTS_EXT_crush_3_0.java:28)
        at org.strategoxt.lang.compat.override.performance_tweaks.foldr_3_0_override.invoke(foldr_3_0_override.java:29)
        at org.strategoxt.stratego_lib.w_1200.invoke(w_1200.java:75)
        at org.strategoxt.stratego_lib.split_2_0.invoke(split_2_0.java:27)
        at org.strategoxt.stratego_lib.lifted1345.invoke(lifted1345.java:32)
        at org.strategoxt.strc.$R$Def$T_4_0.invoke($R$Def$T_4_0.java:55)
        at org.strategoxt.strc.tboundin_3_0.invoke(tboundin_3_0.java:105)
        at org.strategoxt.stratego_lib.w_1200.invoke(w_1200.java:63)
        at org.strategoxt.stratego_lib.free_vars_3_0.invoke(free_vars_3_0.java:33)
        at org.strategoxt.strc.tvars_0_0.invoke(tvars_0_0.java:26)
        at org.strategoxt.strc.def_tvars_0_0.invoke(def_tvars_0_0.java:30)
        at org.strategoxt.strc.lifted4357.invoke(lifted4357.java:40)
        at org.strategoxt.stratego_lib.dr_scope_1_1.invoke(dr_scope_1_1.java:31)
        at org.strategoxt.strc.lifted4356.invoke(lifted4356.java:41)
        at org.strategoxt.stratego_lib.dr_scope_1_1.invoke(dr_scope_1_1.java:31)
        at org.strategoxt.strc.lifted4355.invoke(lifted4355.java:41)
        at org.strategoxt.stratego_lib.dr_scope_1_1.invoke(dr_scope_1_1.java:31)
        at org.strategoxt.strc.lift_dynamic_rule_from_def_0_0.invoke(lift_dynamic_rule_from_def_0_0.java:48)
        at org.strategoxt.strc.lift_dynamic_rule_from_def_foo_0_0.invoke(lift_dynamic_rule_from_def_foo_0_0.java:39)
        at org.strategoxt.lang.SRTS_EXT_repeat_1_0.invoke(SRTS_EXT_repeat_1_0.java:20)
        at org.strategoxt.lang.compat.override.performance_tweaks.repeat_1_0_override.invoke(repeat_1_0_override.java:21)
        at org.strategoxt.strc.lifted4351.invoke(lifted4351.java:28)
        at org.strategoxt.stratego_lib.e_1325.invoke(e_1325.java:23)
        at org.strategoxt.stratego_lib.e_1325.invoke(e_1325.java:49)
        at org.strategoxt.stratego_lib.e_1325.invoke(e_1325.java:49)
        .... // a lot of same line
        at org.strategoxt.stratego_lib.e_1325.invoke(e_1325.java:49)
        at org.strategoxt.stratego_lib.e_1325.invoke(e_1325.java:49)
        at org.strategoxt.stratego_lib.e_1325.invoke(e_1325.java:49)

Same stratego script compiles fine in eclipse. logger in Java app produces same command line as eclipse plugin:

strj -i /home/dvitel/cereal/EvoTransform/data/lang/trans/metaborg_java.str -o /home/dvitel/cereal/EvoTransform/data/lang/target/metaborg/stratego.ctree -p lang.java.trans --library --clean -I /home/dvitel/cereal/EvoTransform/data/lang/trans -I /home/dvitel/cereal/EvoTransform/data/lang/src-gen -I /home/dvitel/cereal/EvoTransform/data/lang/lib -I /home/dvitel/cereal/EvoTransform/data/lang -I /home/dvitel/sw/spoofax/spoofax/plugins/meta.lib.spoofax.eclipse_2.5.9/target/unpacked/latest/trans --cache-dir /home/dvitel/cereal/EvoTransform/data/lang/target/stratego-cache -la stratego-lib -la stratego-sglr -la stratego-gpp -la stratego-xtc -la stratego-aterm -la stratego-sdf -la strc -F

The stratego script that I am compilling is relatively simple (metaborg_java.str):

module metaborg_java

imports

  completion/completion
  pp
  custom

rules // Debugging

  debug-show-aterm:
    (node, _, _, path, project-path) -> (filename, result)
    with
      filename := <guarantee-extension(|"aterm")> path
    ; result   := node

  time-pretty-printing:
    (node, _, _, path, project-path) -> (filename, result)
    with
      filename := <guarantee-extension(|"aterm")> path
    ; result   := <profile(!"pretty printing time: ", pp-metaborg-java-string)> node

where custom module is:

module custom
imports
  src-gen/signatures/metaborg-java-sig
rules

gp-poc =   
?|[ 
    for (~type ~x = ~initExpr;~cond;~inc) {
        ~stms*
    }
]|; //match-for gp node
![]

Could you suggest any help with this issue? Using API is critical here, custom.str is autogenerated in my case. Thanks.

Submitted on 18 July 2020 at 05:10

On 18 July 2020 at 10:35 Jeff Smits commented:

If it compiles fine in Eclipse, I think it’s a matter of JVM stack space settings. So try starting your custom java code in a JVM with more stackspace, with -Xss16m as a command line flag. Let me know if that solves your problem.

Background: Spoofax typically runs on a JVM with the following memory setting flags: -Xms512m -Xmx1024m -Xss16m. The -Xss is most relevant for your problem, that’s the increased stack space. strj (and other programs written in Stratego) use a lot of recursion and therefore a lot of JVM stack space.


On 18 July 2020 at 18:35 Dmytro Vitel commented:

Yes, it helped - thanks so much for response :) - for some reason I did not think further about the exception and possibility to increase stack size. Just some note: on Windows I observed the exception only for some cases (some generated str scripts) while on Ubuntu it happens always.
Also, some short question - is there a way to speedup the build process? - it takes 10-20 seconds on my machine even though only thing that I change is one str script (sdf definitions stay the same and already compiled). I played with optimization flag but seems that it does not change the time much:

[ strj | info ] Front-end succeeded         : [user/system] = [9.25s/0.00s]
[ strj | info ] Optimization succeeded -O 2 : [user/system] = [1.14s/0.00s]
[ strj | info ] Abstract syntax in '/home/dvitel/cereal/EvoTransform/data/lang/target/metaborg/stratego.rtree'

On 21 July 2020 at 14:46 Jeff Smits commented:

The Spoofax build does some caching of intermediate results on disk for a more incremental build. But this doesn’t include Stratego. There is an option to incrementally compile Stratego, but that system only saves things in memory (so it works in Eclipse, but perhaps not in your separate Java program if it doesn’t keep running in between compilations) and does have some changes in import behaviour. The clean build will also take longer than the usual compiler, only incremental changes have a shorter compilation time.


On 21 July 2020 at 14:46 Jeff Smits closed this issue.

Log in to post comments