Skip to content

Commit 447475c

Browse files
committed
Use Java Application class data sharing (AppCDS).
- Boost startup performance using AppCDS - Enable by default (auto) only for insiders & pre-release versions - Use java.jdt.ls.appcds.enabled to control the setting Signed-off-by: Roland Grunberg <[email protected]>
1 parent f9239a1 commit 447475c

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ The following settings are supported:
257257
* `java.completion.engine`: [Experimental] Select code completion engine. Defaults to `ecj`.
258258
* `java.references.includeDeclarations`: Include declarations when finding references. Defaults to `true`
259259

260+
New in 1.44.0
261+
* `java.jdt.ls.appcds.enabled` : [Experimental] Enable Java AppCDS (Application Class Data Sharing) for improvements to extension activation. When set to `auto`, AppCDS will be enabled in Visual Studio Code - Insiders, and for pre-release versions.
262+
260263
Semantic Highlighting
261264
===============
262265
[Semantic Highlighting](https://github.com/redhat-developer/vscode-java/wiki/Semantic-Highlighting) fixes numerous syntax highlighting issues with the default Java Textmate grammar. However, you might experience a few minor issues, particularly a delay when it kicks in, as it needs to be computed by the Java Language server, when opening a new file or when typing. Semantic highlighting can be disabled for all languages using the `editor.semanticHighlighting.enabled` setting, or for Java only using [language-specific editor settings](https://code.visualstudio.com/docs/getstarted/settings#_languagespecific-editor-settings).

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,18 @@
420420
"scope": "window",
421421
"order": 95
422422
},
423+
"java.jdt.ls.appcds.enabled": {
424+
"type": "string",
425+
"enum": [
426+
"auto",
427+
"on",
428+
"off"
429+
],
430+
"default": "auto",
431+
"markdownDescription": "[Experimental] Enable Java AppCDS (Application Class Data Sharing) for improvements to extension activation. When set to `auto`, AppCDS will be enabled in Visual Studio Code - Insiders, and for pre-release versions.",
432+
"scope": "machine-overridable",
433+
"order": 100
434+
},
423435
"java.trace.server": {
424436
"type": "string",
425437
"enum": [

src/javaServerStarter.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ export const HEAP_DUMP = '-XX:+HeapDumpOnOutOfMemoryError';
3636
const DEPENDENCY_COLLECTOR_IMPL= '-Daether.dependencyCollector.impl=';
3737
const DEPENDENCY_COLLECTOR_IMPL_BF= 'bf';
3838

39+
const UNLOCK_DIAGNOSTIC_VM_OPTIONS= '-XX:+UnlockDiagnosticVMOptions';
40+
const ALLOW_ARCHIVING_WITH_JAVA_AGENT= '-XX:+AllowArchivingWithJavaAgent';
41+
const AUTO_CREATE_SHARED_ARCHIVE= '-XX:+AutoCreateSharedArchive';
42+
const SHARED_ARCHIVE_FILE_LOC= '-XX:SharedArchiveFile=';
43+
3944
export function prepareExecutable(requirements: RequirementsData, workspacePath, context: ExtensionContext, isSyntaxServer: boolean): Executable {
4045
const executable: Executable = Object.create(null);
4146
const options: ExecutableOptions = Object.create(null);
@@ -224,6 +229,23 @@ function prepareParams(requirements: RequirementsData, workspacePath, context: E
224229
if (sharedIndexLocation) {
225230
params.push(`-Djdt.core.sharedIndexLocation=${sharedIndexLocation}`);
226231
}
232+
233+
const hasJDWP = params.find((param: string) => param.includes('jdwp')) !== undefined;
234+
const isInsider: boolean = version.includes("insider");
235+
const extVersion = getVersion(context.extensionPath);
236+
const isPreReleaseVersion = /^\d+\.\d+\.\d{10}/.test(extVersion);
237+
const globalStoragePath = path.resolve(context.globalStorageUri?.fsPath, extVersion); // .../Code/User/globalStorage/redhat.java/1.42.0/
238+
const appCDSMode = workspace.getConfiguration().get('java.jdt.ls.appcds.enabled');
239+
const useAppCDS = (appCDSMode === 'on') || (appCDSMode === 'auto' && (isInsider || isPreReleaseVersion));
240+
241+
ensureExists(globalStoragePath);
242+
const sharedArchiveLocation = path.join(globalStoragePath, "jdtls.jsa");
243+
if (useAppCDS && vmargs.indexOf(SHARED_ARCHIVE_FILE_LOC) < 0 && !hasJDWP) {
244+
params.push(UNLOCK_DIAGNOSTIC_VM_OPTIONS);
245+
params.push(ALLOW_ARCHIVING_WITH_JAVA_AGENT); // required due to use of '-javaagent'
246+
params.push(AUTO_CREATE_SHARED_ARCHIVE);
247+
params.push(`${SHARED_ARCHIVE_FILE_LOC}${sharedArchiveLocation}`);
248+
}
227249
}
228250

229251
// "OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify

src/settings.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ function hasJavaConfigChanged(oldConfig: WorkspaceConfiguration, newConfig: Work
139139
|| hasConfigKeyChanged('transport', oldConfig, newConfig)
140140
|| hasConfigKeyChanged('diagnostic.filter', oldConfig, newConfig)
141141
|| hasConfigKeyChanged('jdt.ls.javac.enabled', oldConfig, newConfig)
142-
|| hasConfigKeyChanged('completion.engine', oldConfig, newConfig);
142+
|| hasConfigKeyChanged('completion.engine', oldConfig, newConfig)
143+
|| hasConfigKeyChanged('jdt.ls.appcds.enabled', oldConfig, newConfig);
143144
}
144145

145146
function hasConfigKeyChanged(key, oldConfig, newConfig) {

0 commit comments

Comments
 (0)