@@ -36,6 +36,11 @@ export const HEAP_DUMP = '-XX:+HeapDumpOnOutOfMemoryError';
36
36
const DEPENDENCY_COLLECTOR_IMPL = '-Daether.dependencyCollector.impl=' ;
37
37
const DEPENDENCY_COLLECTOR_IMPL_BF = 'bf' ;
38
38
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
+
39
44
export function prepareExecutable ( requirements : RequirementsData , workspacePath , context : ExtensionContext , isSyntaxServer : boolean ) : Executable {
40
45
const executable : Executable = Object . create ( null ) ;
41
46
const options : ExecutableOptions = Object . create ( null ) ;
@@ -90,8 +95,8 @@ export function awaitServerConnection(port): Thenable<StreamInfo> {
90
95
function prepareParams ( requirements : RequirementsData , workspacePath , context : ExtensionContext , isSyntaxServer : boolean ) : string [ ] {
91
96
const params : string [ ] = [ ] ;
92
97
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`);
95
100
// suspend=y is the default. Use this form if you need to debug the server startup code:
96
101
// params.push('-agentlib:jdwp=transport=dt_socket,server=y,address=1044');
97
102
}
@@ -217,6 +222,18 @@ function prepareParams(requirements: RequirementsData, workspacePath, context: E
217
222
if ( sharedIndexLocation ) {
218
223
params . push ( `-Djdt.core.sharedIndexLocation=${ sharedIndexLocation } ` ) ;
219
224
}
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
+ }
220
237
}
221
238
222
239
// "OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify
0 commit comments