Skip to content

Commit

Permalink
Merge pull request #41399 from gimantha/2201.7.x-oom-fix
Browse files Browse the repository at this point in the history
[2201.7.x] Remove unnecessary capturedClosureEnvs
  • Loading branch information
gimantha authored Sep 26, 2023
2 parents 7e1675a + bc6f4e7 commit e31b299
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class DocumentContext {
private NodeCloner nodeCloner;
private final DocumentId documentId;
private final String name;
private final String content;
private String content;
private boolean disableSyntaxTree = false;

private DocumentContext(DocumentId documentId, String name, String content, boolean disableSyntaxTree) {
Expand Down Expand Up @@ -187,4 +187,11 @@ private void reportSyntaxDiagnostics(PackageID pkgID, SyntaxTree tree, BLangDiag
DocumentContext duplicate() {
return new DocumentContext(this.documentId, this.name, syntaxTree().toSourceCode(), false);
}

void shrink() {
if (this.compilationUnit != null) {
this.compilationUnit.topLevelNodes.clear();
}
this.content = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ private void performCodeGen() {
moduleDiagnostics.add(
new PackageDiagnostic(diagnostic, moduleContext.descriptor(), moduleContext.project()));
}

//TODO: remove this once ballerina-lang#41407 is fixed
ModuleContext.shrinkDocuments(moduleContext);
}
// add compilation diagnostics
diagnostics.addAll(moduleDiagnostics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,11 @@ static void loadPlatformSpecificCodeInternal(ModuleContext moduleContext, Compil
// TODO implement
}

//TODO: should be removed once we properly fix ballerina-lang#41407
static void shrinkDocuments(ModuleContext moduleContext) {
moduleContext.srcDocContextMap.values().forEach(DocumentContext::shrink);
}

Optional<MdDocumentContext> moduleMdContext() {
return Optional.ofNullable(this.moduleMdContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ private CompiledJarFile generate(BPackageSymbol packageSymbol) {
HashMap<String, String> originalIdentifierMap = JvmDesugarPhase.encodeModuleIdentifiers(packageSymbol.bir);

// TODO Get-rid of the following assignment
packageSymbol.compiledJarFile = jvmPackageGen.generate(packageSymbol.bir, true);
CompiledJarFile compiledJarFile = jvmPackageGen.generate(packageSymbol.bir, true);

//Revert encoding identifier names
JvmDesugarPhase.replaceEncodedModuleIdentifiers(packageSymbol.bir, originalIdentifierMap);
return packageSymbol.compiledJarFile;
return compiledJarFile;
}

private void populateExternalMap(JvmPackageGen jvmPackageGen) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ private BLangLambdaFunction addReturnAndDefineLambda(BLangFunction function, BLa

BInvokableSymbol lambdaFunctionSymbol = createInvokableSymbol(function, pkgID, owner);
BLangLambdaFunction lambdaFunction = desugar.createLambdaFunction(function, lambdaFunctionSymbol, env);
lambdaFunction.capturedClosureEnv = env.createClone();
lambdaFunction.capturedClosureEnv = env;

pkgNode.functions.add(function);
pkgNode.topLevelNodes.add(function);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,7 @@ public void visit(BLangLambdaFunction bLangLambdaFunction) {
boolean isWorker = bLangLambdaFunction.function.flagSet.contains(Flag.WORKER);
bLangLambdaFunction.enclMapSymbols = collectClosureMapSymbols(symbolEnv, enclInvokable, isWorker);
}
bLangLambdaFunction.capturedClosureEnv = null;
result = bLangLambdaFunction;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ private BLangExpression createClosureForDefaultValue(String closureName, String
BLangReturn returnStmt = ASTBuilderUtil.createReturnStmt(function.pos, (BLangBlockFunctionBody) function.body);
returnStmt.expr = varNode.expr;
BLangLambdaFunction lambdaFunction = createLambdaFunction(function);
lambdaFunction.capturedClosureEnv = env.createClone();
lambdaFunction.capturedClosureEnv = env;
BInvokableSymbol varSymbol = createSimpleVariable(function, lambdaFunction, false);
env.enclPkg.symbol.scope.define(function.symbol.name, function.symbol);
env.enclPkg.functions.add(function);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7795,6 +7795,7 @@ public void visit(BLangLambdaFunction bLangLambdaFunction) {
funcSymbol.addAnnotation(this.strandAnnotAttachement.annotationAttachmentSymbol);
funcSymbol.schedulerPolicy = SchedulerPolicy.ANY;
}
bLangLambdaFunction.capturedClosureEnv = null;
result = bLangLambdaFunction;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.ballerinalang.model.symbols.SymbolKind;
import org.ballerinalang.model.symbols.SymbolOrigin;
import org.ballerinalang.repository.CompiledPackage;
import org.wso2.ballerinalang.compiler.CompiledJarFile;
import org.wso2.ballerinalang.compiler.bir.model.BIRNode;
import org.wso2.ballerinalang.compiler.semantics.model.types.BPackageType;
import org.wso2.ballerinalang.compiler.util.Name;
Expand Down Expand Up @@ -56,9 +55,6 @@ public class BPackageSymbol extends BTypeSymbol {
public BIRNode.BIRPackage bir; // TODO try to remove this
public BIRPackageFile birPackageFile;

// kep code generated jar binary content in memory
public CompiledJarFile compiledJarFile;

// TODO Refactor following two flags
public boolean entryPointExists = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.ballerinalang.test.context.BallerinaTestException;
import org.ballerinalang.test.context.Constant;
import org.ballerinalang.test.context.Utils;
import org.eclipse.lsp4j.debug.Capabilities;
import org.eclipse.lsp4j.debug.DisconnectArguments;
import org.eclipse.lsp4j.debug.InitializeRequestArguments;
import org.eclipse.lsp4j.debug.launch.DSPLauncher;
Expand All @@ -40,6 +39,7 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand All @@ -62,7 +62,6 @@ public class DAPClientConnector {
private DAPRequestManager requestManager;
private StreamConnectionProvider streamConnectionProvider;
private Future<Void> launcherFuture;
private Capabilities initializeResult;
private ConnectionState myConnectionState;
private final DebugServerEventHolder serverEventHolder;
private final int debugAdapterPort;
Expand All @@ -73,6 +72,9 @@ public class DAPClientConnector {
private static final String CONFIG_DEBUGEE_PORT = "debuggeePort";
private static final String CONFIG_BAL_HOME = "ballerina.home";
private static final String CONFIG_IS_TEST_CMD = "debugTests";
private static final String CONFIG_COMMAND_OPTIONS = "commandOptions";

private static final String OFFLINE_CMD_OPTION = "--offline";

public DAPClientConnector(String balHome, Path projectPath, Path entryFilePath, int port,
boolean supportsRunInTerminalRequest) {
Expand Down Expand Up @@ -140,7 +142,6 @@ public void createConnection() {
initParams.setSupportsRunInTerminalRequest(this.supportsRunInTerminalRequest);

debugServer.initialize(initParams).thenApply(res -> {
initializeResult = res;
LOGGER.info("initialize response received from the debug server.");
requestManager = new DAPRequestManager(this, debugServer);
debugClient.connect(requestManager);
Expand Down Expand Up @@ -185,6 +186,13 @@ public void launchServer(DebugUtils.DebuggeeExecutionKind launchKind, Map<String
if (launchKind == DebugUtils.DebuggeeExecutionKind.TEST) {
requestArgs.put(CONFIG_IS_TEST_CMD, true);
}

// All the debugger integration tests are executed in offline mode (to reduce the build
// time of the target Ballerina program).
List<String> commandOptions = new LinkedList<>();
commandOptions.add(OFFLINE_CMD_OPTION);
requestArgs.put(CONFIG_COMMAND_OPTIONS, commandOptions);

requestManager.launch(requestArgs);
} catch (Exception e) {
LOGGER.warn("Debuggee launch request failed.", e);
Expand Down

0 comments on commit e31b299

Please sign in to comment.