From 4ad1efcfa261344c365dbc085b119cbbefa7b289 Mon Sep 17 00:00:00 2001 From: Mark Hills Date: Wed, 23 Aug 2023 17:29:39 -0400 Subject: [PATCH 1/3] Add config settings for interpreter heap and stack space. Add two configuration settings that adjust the default amount of heap and per-thread stack space for the JVM created to run a Rascal interpreter. Both settings can be either null or numeric. Numeric settings are interpreted as number of MB. The settings correspond to the -Xmx (for heap) and -Xss (for stack) flags passed to the JVM. --- rascal-vscode-extension/package.json | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/rascal-vscode-extension/package.json b/rascal-vscode-extension/package.json index 02a260711..b78d05ac2 100644 --- a/rascal-vscode-extension/package.json +++ b/rascal-vscode-extension/package.json @@ -121,7 +121,22 @@ "scopeName": "source.parametric-rascalmpl", "path": "./syntaxes/parametric.tmGrammar.json" } - ] + ], + "configuration": { + "title": "Rascal", + "properties": { + "rascal.interpreter.defaultHeapSize": { + "type": ["number", "null"], + "default": null, + "description": "Provides the default heap space, in MB, for the Rascal interpreter" + }, + "rascal.interpreter.defaultStackSize": { + "type": ["number", "null"], + "default": null, + "description": "Provides the default stack size, in MB, for the Rascal interpreter" + } + } + } }, "scripts": { "lsp4j:package": "cp ../rascal-lsp/target/rascal-lsp*.jar assets/jars/rascal-lsp.jar && cp ../rascal-lsp/target/lib/*.jar assets/jars/", From 5225f0ab1029c6dd2ec9703ba919bcae18ecfd5e Mon Sep 17 00:00:00 2001 From: Mark Hills Date: Wed, 23 Aug 2023 17:33:36 -0400 Subject: [PATCH 2/3] Use config settings for heap and stack size when creating a Rascal shell. This update modifies the code that computes the maximum heap size to take into account the heap size configuration setting, if set. This also adds new code to compute a maximum stack size, which will use the stack size configuration setting when present or the JVM default when absent. --- .../src/RascalExtension.ts | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/rascal-vscode-extension/src/RascalExtension.ts b/rascal-vscode-extension/src/RascalExtension.ts index b85751374..ad02a3a8f 100644 --- a/rascal-vscode-extension/src/RascalExtension.ts +++ b/rascal-vscode-extension/src/RascalExtension.ts @@ -133,9 +133,15 @@ export class RascalExtension implements vscode.Disposable { private buildShellArgs(classPath: string[], ide: IDEServicesConfiguration, ...extraArgs: string[]) { const shellArgs = [ calculateRascalREPLMemory() - , '-cp' - , this.buildTerminalJVMPath() + (classPath.length > 0 ? (path.delimiter + classPath.join(path.delimiter)) : ''), ]; + const replStackSize = calculateRascalREPLStackSize(); + if (replStackSize.length !== 0) { + shellArgs.push(replStackSize); + } + shellArgs.push( + '-cp' + , this.buildTerminalJVMPath() + (classPath.length > 0 ? (path.delimiter + classPath.join(path.delimiter)) : ''), + ); if (!this.isDeploy) { // for development mode we always start the terminal with debuging ready to go shellArgs.push( @@ -172,6 +178,14 @@ function gb(amount: integer) { } function calculateRascalREPLMemory() { + const config = vscode.workspace.getConfiguration(); + if (config.has('rascal.interpreter.defaultHeapSize')) { + const defaultHeapSize = config.get('rascal.interpreter.defaultHeapSize'); + if (defaultHeapSize !== null) { + return `-Xmx${defaultHeapSize}M`; + } + } + if (os.totalmem() >= gb(32)) { return "-Xmx9000M"; } @@ -182,5 +196,17 @@ function calculateRascalREPLMemory() { if (os.totalmem() >= gb(8)) { return "-Xmx2400M"; } - return "-Xmx800M"; + return "-Xmx800M"; +} + +function calculateRascalREPLStackSize() { + const config = vscode.workspace.getConfiguration(); + if (config.has('rascal.interpreter.defaultStackSize')) { + const defaultStackSize = config.get('rascal.interpreter.defaultStackSize'); + if (defaultStackSize !== null) { + return `-Xss${defaultStackSize}M`; + } + } + + return ""; } From 0f28569902396aa2dcd8f8449f7a231a456ac250 Mon Sep 17 00:00:00 2001 From: Mark Hills Date: Wed, 23 Aug 2023 21:02:10 -0400 Subject: [PATCH 3/3] Update config params and descriptions to better convey purpose Updated the names of the configuration parameters and their descriptions to better convey what they are used for. Also updated the code that refers to the parameter names. --- rascal-vscode-extension/package.json | 8 ++++---- rascal-vscode-extension/src/RascalExtension.ts | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/rascal-vscode-extension/package.json b/rascal-vscode-extension/package.json index b78d05ac2..35167c792 100644 --- a/rascal-vscode-extension/package.json +++ b/rascal-vscode-extension/package.json @@ -125,15 +125,15 @@ "configuration": { "title": "Rascal", "properties": { - "rascal.interpreter.defaultHeapSize": { + "rascal.interpreter.maxHeapSize": { "type": ["number", "null"], "default": null, - "description": "Provides the default heap space, in MB, for the Rascal interpreter" + "description": "Provides the maximum heap space, in MB, for the Rascal interpreter" }, - "rascal.interpreter.defaultStackSize": { + "rascal.interpreter.stackSize": { "type": ["number", "null"], "default": null, - "description": "Provides the default stack size, in MB, for the Rascal interpreter" + "description": "Provides the per-thread stack size, in MB, for the Rascal interpreter" } } } diff --git a/rascal-vscode-extension/src/RascalExtension.ts b/rascal-vscode-extension/src/RascalExtension.ts index ad02a3a8f..e2e7d2670 100644 --- a/rascal-vscode-extension/src/RascalExtension.ts +++ b/rascal-vscode-extension/src/RascalExtension.ts @@ -179,10 +179,10 @@ function gb(amount: integer) { function calculateRascalREPLMemory() { const config = vscode.workspace.getConfiguration(); - if (config.has('rascal.interpreter.defaultHeapSize')) { - const defaultHeapSize = config.get('rascal.interpreter.defaultHeapSize'); - if (defaultHeapSize !== null) { - return `-Xmx${defaultHeapSize}M`; + if (config.has('rascal.interpreter.maxHeapSize')) { + const maxHeapSize = config.get('rascal.interpreter.maxHeapSize'); + if (maxHeapSize !== null) { + return `-Xmx${maxHeapSize}M`; } } @@ -201,10 +201,10 @@ function calculateRascalREPLMemory() { function calculateRascalREPLStackSize() { const config = vscode.workspace.getConfiguration(); - if (config.has('rascal.interpreter.defaultStackSize')) { - const defaultStackSize = config.get('rascal.interpreter.defaultStackSize'); - if (defaultStackSize !== null) { - return `-Xss${defaultStackSize}M`; + if (config.has('rascal.interpreter.stackSize')) { + const stackSize = config.get('rascal.interpreter.stackSize'); + if (stackSize !== null) { + return `-Xss${stackSize}M`; } }