Skip to content

Use Java Application class data sharing (AppCDS). #4067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ The following settings are supported:
* `java.completion.engine`: [Experimental] Select code completion engine. Defaults to `ecj`.
* `java.references.includeDeclarations`: Include declarations when finding references. Defaults to `true`

New in 1.44.0
* `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.

Semantic Highlighting
===============
[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).
Expand Down
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,18 @@
"scope": "window",
"order": 95
},
"java.jdt.ls.appcds.enabled": {
"type": "string",
"enum": [
"auto",
"on",
"off"
],
"default": "auto",
"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.",
"scope": "machine-overridable",
"order": 100
},
"java.trace.server": {
"type": "string",
"enum": [
Expand Down
22 changes: 22 additions & 0 deletions src/javaServerStarter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export const HEAP_DUMP = '-XX:+HeapDumpOnOutOfMemoryError';
const DEPENDENCY_COLLECTOR_IMPL= '-Daether.dependencyCollector.impl=';
const DEPENDENCY_COLLECTOR_IMPL_BF= 'bf';

const UNLOCK_DIAGNOSTIC_VM_OPTIONS= '-XX:+UnlockDiagnosticVMOptions';
const ALLOW_ARCHIVING_WITH_JAVA_AGENT= '-XX:+AllowArchivingWithJavaAgent';
const AUTO_CREATE_SHARED_ARCHIVE= '-XX:+AutoCreateSharedArchive';
const SHARED_ARCHIVE_FILE_LOC= '-XX:SharedArchiveFile=';

export function prepareExecutable(requirements: RequirementsData, workspacePath, context: ExtensionContext, isSyntaxServer: boolean): Executable {
const executable: Executable = Object.create(null);
const options: ExecutableOptions = Object.create(null);
Expand Down Expand Up @@ -224,6 +229,23 @@ function prepareParams(requirements: RequirementsData, workspacePath, context: E
if (sharedIndexLocation) {
params.push(`-Djdt.core.sharedIndexLocation=${sharedIndexLocation}`);
}

const hasJDWP = params.find((param: string) => param.includes('jdwp')) !== undefined;
const isInsider: boolean = version.includes("insider");
const extVersion = getVersion(context.extensionPath);
const isPreReleaseVersion = /^\d+\.\d+\.\d{10}/.test(extVersion);
const globalStoragePath = path.resolve(context.globalStorageUri?.fsPath, extVersion); // .../Code/User/globalStorage/redhat.java/1.42.0/
const appCDSMode = workspace.getConfiguration().get('java.jdt.ls.appcds.enabled');
const useAppCDS = (appCDSMode === 'on') || (appCDSMode === 'auto' && (isInsider || isPreReleaseVersion));

ensureExists(globalStoragePath);
const sharedArchiveLocation = path.join(globalStoragePath, "jdtls.jsa");
if (useAppCDS && vmargs.indexOf(SHARED_ARCHIVE_FILE_LOC) < 0 && !hasJDWP) {
params.push(UNLOCK_DIAGNOSTIC_VM_OPTIONS);
params.push(ALLOW_ARCHIVING_WITH_JAVA_AGENT); // required due to use of '-javaagent'
params.push(AUTO_CREATE_SHARED_ARCHIVE);
params.push(`${SHARED_ARCHIVE_FILE_LOC}${sharedArchiveLocation}`);
}
}

// "OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify
Expand Down
3 changes: 2 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ function hasJavaConfigChanged(oldConfig: WorkspaceConfiguration, newConfig: Work
|| hasConfigKeyChanged('transport', oldConfig, newConfig)
|| hasConfigKeyChanged('diagnostic.filter', oldConfig, newConfig)
|| hasConfigKeyChanged('jdt.ls.javac.enabled', oldConfig, newConfig)
|| hasConfigKeyChanged('completion.engine', oldConfig, newConfig);
|| hasConfigKeyChanged('completion.engine', oldConfig, newConfig)
|| hasConfigKeyChanged('jdt.ls.appcds.enabled', oldConfig, newConfig);
}

function hasConfigKeyChanged(key, oldConfig, newConfig) {
Expand Down
Loading