From 35e73f300e2101c436dcc23c9a0f9e12ecc81d59 Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Thu, 20 Jul 2017 16:17:36 +0300 Subject: [PATCH] Builtins and JavaModule SCL modules may leak memory Still needs a better fix though refs #7352 Change-Id: I9206376349bedf4a92763094b2859230dbf69f77 --- .../scl/compiler/elaboration/java/Builtins.java | 11 +++++++---- .../scl/compiler/elaboration/java/JavaModule.java | 7 +++++-- .../tests/modelled/utils/ModelledSTSTest.java | 6 ++++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/Builtins.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/Builtins.java index 334cb4560..4d48d1e9c 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/Builtins.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/Builtins.java @@ -9,7 +9,6 @@ import org.simantics.scl.compiler.common.precedence.Associativity; import org.simantics.scl.compiler.common.precedence.Precedence; import org.simantics.scl.compiler.constants.BooleanConstant; import org.simantics.scl.compiler.constants.Constant; -import org.simantics.scl.compiler.constants.JavaConstructor; import org.simantics.scl.compiler.constants.JavaStaticField; import org.simantics.scl.compiler.constants.JavaStaticMethod; import org.simantics.scl.compiler.constants.NoRepConstant; @@ -53,10 +52,10 @@ import org.simantics.scl.runtime.profiling.BranchPoint; public class Builtins extends ConcreteModule { - public static SCLValue[] TUPLE_CONSTRUCTORS = new SCLValue[Constants.MAX_TUPLE_LENGTH+1]; - public static SCLValue[] LIST_CONSTRUCTORS = new SCLValue[Constants.MAX_LIST_LITERAL_LENGTH+1]; + public static final SCLValue[] TUPLE_CONSTRUCTORS = new SCLValue[Constants.MAX_TUPLE_LENGTH+1]; + public static final SCLValue[] LIST_CONSTRUCTORS = new SCLValue[Constants.MAX_LIST_LITERAL_LENGTH+1]; - public static final Builtins INSTANCE = new Builtins(); + public static Builtins INSTANCE = new Builtins(); public static SCLValue Nothing; public static SCLValue Just; @@ -363,4 +362,8 @@ public class Builtins extends ConcreteModule { return documentation; } + public static void flush() { + INSTANCE = new Builtins(); + } + } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/JavaModule.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/JavaModule.java index e412a1168..aeec9a35b 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/JavaModule.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/JavaModule.java @@ -23,7 +23,7 @@ import org.simantics.scl.compiler.types.kinds.Kinds; public class JavaModule extends ConcreteModule { - public static final JavaModule INSTANCE = new JavaModule(); + public static JavaModule INSTANCE = new JavaModule(); public static final String MODULE_NAME = "JavaBuiltin"; @@ -147,6 +147,9 @@ public class JavaModule extends ConcreteModule { result = new EApplyType(result, var); return result; } - + + public static void flush() { + INSTANCE = new JavaModule(); + } } diff --git a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/utils/ModelledSTSTest.java b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/utils/ModelledSTSTest.java index e1eb08baf..0c0d8682a 100644 --- a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/utils/ModelledSTSTest.java +++ b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/utils/ModelledSTSTest.java @@ -11,9 +11,9 @@ import java.util.Set; import org.simantics.scl.compiler.commands.CommandSession; import org.simantics.scl.compiler.commands.TestScriptExecutor; +import org.simantics.scl.compiler.elaboration.java.Builtins; +import org.simantics.scl.compiler.elaboration.java.JavaModule; import org.simantics.scl.compiler.module.coverage.CombinedCoverage; -import org.simantics.scl.compiler.module.options.ModuleCompilationOptions; -import org.simantics.scl.compiler.module.options.ModuleCompilationOptionsAdvisor; import org.simantics.scl.compiler.module.repository.ModuleRepository; import org.simantics.scl.compiler.types.Type; import org.simantics.scl.compiler.types.Types; @@ -140,6 +140,8 @@ public class ModelledSTSTest { } finally { // remember to flush this repository repo.flush(); + Builtins.flush(); + JavaModule.flush(); } } -- 2.47.1