@@ -36,6 +36,11 @@ export const HEAP_DUMP = '-XX:+HeapDumpOnOutOfMemoryError';
3636const DEPENDENCY_COLLECTOR_IMPL = '-Daether.dependencyCollector.impl=' ;
3737const 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+
3944export function prepareExecutable ( requirements : RequirementsData , workspacePath , context : ExtensionContext , isSyntaxServer : boolean ) : Executable {
4045 const executable : Executable = Object . create ( null ) ;
4146 const options : ExecutableOptions = Object . create ( null ) ;
@@ -90,8 +95,8 @@ export function awaitServerConnection(port): Thenable<StreamInfo> {
9095function prepareParams ( requirements : RequirementsData , workspacePath , context : ExtensionContext , isSyntaxServer : boolean ) : string [ ] {
9196 const params : string [ ] = [ ] ;
9297 if ( DEBUG ) {
93- const port = isSyntaxServer ? 1045 : 1044 ;
94- params . push ( `-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=${ port } ,quiet=y` ) ;
98+ // const port = isSyntaxServer ? 1045 : 1044;
99+ // params.push(`-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=${port},quiet=y`);
95100 // suspend=y is the default. Use this form if you need to debug the server startup code:
96101 // params.push('-agentlib:jdwp=transport=dt_socket,server=y,address=1044');
97102 }
@@ -217,6 +222,18 @@ function prepareParams(requirements: RequirementsData, workspacePath, context: E
217222 if ( sharedIndexLocation ) {
218223 params . push ( `-Djdt.core.sharedIndexLocation=${ sharedIndexLocation } ` ) ;
219224 }
225+
226+ const hasJDWP = params . find ( ( param : string ) => param . includes ( 'jdwp' ) ) !== undefined ;
227+ const version = getVersion ( context . extensionPath ) ;
228+ const globalStoragePath = path . resolve ( context . globalStorageUri ?. fsPath , version ) ; // .../Code/User/globalStorage/redhat.java/1.42.0/
229+ ensureExists ( globalStoragePath ) ;
230+ const sharedArchiveLocation = globalStoragePath ? path . join ( globalStoragePath , "jdtls.jsa" ) : undefined ;
231+ if ( vmargs . indexOf ( SHARED_ARCHIVE_FILE_LOC ) < 0 && ! hasJDWP ) {
232+ params . push ( UNLOCK_DIAGNOSTIC_VM_OPTIONS ) ;
233+ params . push ( ALLOW_ARCHIVING_WITH_JAVA_AGENT ) ; // required due to use of '-javaagent'
234+ params . push ( AUTO_CREATE_SHARED_ARCHIVE ) ;
235+ params . push ( `${ SHARED_ARCHIVE_FILE_LOC } ${ sharedArchiveLocation } ` ) ;
236+ }
220237 }
221238
222239 // "OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify
0 commit comments