1
1
/*
2
- * Copyright (c) 1995, 2020 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 1995, 2021 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -284,9 +284,8 @@ JLI_Launch(int argc, char ** argv, /* main argc, argv */
284
284
jvmpath , sizeof (jvmpath ),
285
285
jvmcfg , sizeof (jvmcfg ));
286
286
287
- if (!IsJavaArgs ()) {
288
- SetJvmEnvironment (argc ,argv );
289
- }
287
+ /* Set env. Must be done before LoadJavaVM. */
288
+ SetJvmEnvironment (argc , argv );
290
289
291
290
ifn .CreateJavaVM = 0 ;
292
291
ifn .GetDefaultJavaVMInitArgs = 0 ;
@@ -806,18 +805,22 @@ static void
806
805
SetJvmEnvironment (int argc , char * * argv ) {
807
806
808
807
static const char * NMT_Env_Name = "NMT_LEVEL_" ;
808
+ const char * NMT_Arg_Name = IsJavaArgs () ? "-J-XX:NativeMemoryTracking=" : "-XX:NativeMemoryTracking=" ;
809
809
int i ;
810
810
/* process only the launcher arguments */
811
811
for (i = 0 ; i < argc ; i ++ ) {
812
812
char * arg = argv [i ];
813
813
/*
814
- * Since this must be a VM flag we stop processing once we see
815
- * an argument the launcher would not have processed beyond (such
816
- * as -version or -h), or an argument that indicates the following
817
- * arguments are for the application (i.e. the main class name, or
818
- * the -jar argument).
814
+ * Java launcher (!IsJavaArgs()):
815
+ * Since this must be a VM flag we stop processing once we see
816
+ * an argument the launcher would not have processed beyond (such
817
+ * as -version or -h), or an argument that indicates the following
818
+ * arguments are for the application (i.e. the main class name, or
819
+ * the -jar argument).
820
+ * Other launchers (IsJavaArgs()):
821
+ * All arguments have to be scanned to see if it is a -J argument.
819
822
*/
820
- if (i > 0 ) {
823
+ if (! IsJavaArgs () && i > 0 ) {
821
824
char * prev = argv [i - 1 ];
822
825
// skip non-dash arg preceded by class path specifiers
823
826
if (* arg != '-' && IsWhiteSpaceOption (prev )) {
@@ -835,10 +838,10 @@ SetJvmEnvironment(int argc, char **argv) {
835
838
* The argument is passed to the JVM, which will check validity.
836
839
* The JVM is responsible for removing the env variable.
837
840
*/
838
- if (JLI_StrCCmp (arg , "-XX:NativeMemoryTracking=" ) == 0 ) {
841
+ if (JLI_StrCCmp (arg , NMT_Arg_Name ) == 0 ) {
839
842
int retval ;
840
843
// get what follows this parameter, include "="
841
- size_t pnlen = JLI_StrLen ("-XX:NativeMemoryTracking=" );
844
+ size_t pnlen = JLI_StrLen (NMT_Arg_Name );
842
845
if (JLI_StrLen (arg ) > pnlen ) {
843
846
char * value = arg + pnlen ;
844
847
size_t pbuflen = pnlen + JLI_StrLen (value ) + 10 ; // 10 max pid digits
0 commit comments