Skip to content
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

Fix omrsysinfo_get_memory_info for non-english locales on windows #7566

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

JamesKingdon
Copy link
Contributor

@JamesKingdon JamesKingdon commented Nov 28, 2024

The windows implementation of omrsysinfo_get_memory_info used PdhAddCounter which requires the counter path string to be localized. Since we weren't doing so the function failed on non-english windows systems. Replacing the call with the language neutral PdhAddEnglishCounter fixes the problem.

I added some debug to check and print the error code, and tested by setting Windows to the French locale.

Before the change:

omrsysinfo_get_memory_info: after GlobalMemoryStatusEx 4200
omrsysinfo_get_memory_info: after PdhOpenQuery 189500
omrsysinfo_get_memory_info: after PdhAddCounter 1 532003600
PdhAddCounter FAILED with c0000bb8

After the change:

omrsysinfo_get_memory_info: after GlobalMemoryStatusEx 5000
omrsysinfo_get_memory_info: after PdhOpenQuery 108600
omrsysinfo_get_memory_info: after PdhAddCounter 1 689300300
omrsysinfo_get_memory_info: after PdhAddCounter 2 309400
omrsysinfo_get_memory_info: after PdhAddCounter 3 161600
omrsysinfo_get_memory_info: after PdhCollectQueryData 201400
totalSwap 46477017088

Doc for PdhAddEnglishCounter: https://learn.microsoft.com/en-us/windows/win32/api/pdh/nf-pdh-pdhaddenglishcountera

The windows implementation of omrsysinfo_get_memory_info used PdhAddCounter which requires
the counter path string to be localized. Since we weren't doing so the function failed on
non-english windows systems. Replacing the call with the language neutral PdhAddEnglishCounter
fixes the problem.

I added some debug to check and print the error code.

Before the change:
```
omrsysinfo_get_memory_info: after GlobalMemoryStatusEx 4200
omrsysinfo_get_memory_info: after PdhOpenQuery 189500
omrsysinfo_get_memory_info: after PdhAddCounter 1 532003600
PdhAddCounter FAILED with c0000bb8
```

After the change:
```
omrsysinfo_get_memory_info: after GlobalMemoryStatusEx 5000
omrsysinfo_get_memory_info: after PdhOpenQuery 108600
omrsysinfo_get_memory_info: after PdhAddCounter 1 689300300
omrsysinfo_get_memory_info: after PdhAddCounter 2 309400
omrsysinfo_get_memory_info: after PdhAddCounter 3 161600
omrsysinfo_get_memory_info: after PdhCollectQueryData 201400
totalSwap 46477017088
```
@0xdaryl
Copy link
Contributor

0xdaryl commented Dec 3, 2024

@babsingh : please review

@babsingh
Copy link
Contributor

babsingh commented Dec 3, 2024

Commit guidelines: https://github.com/eclipse-omr/omr/blob/master/CONTRIBUTING.md#commit-guidelines

  • The body should be wrapped at 72 characters where reasonable. This should be enforced for the first paragraph of the commit message.
  • Markdown will remain unprocessed in the commit message. It is best to exclude it from the commit message and include it in the PR description when creating the PR.
The windows implementation of omrsysinfo_get_memory_info used PdhAddCounter which requires
the counter path string to be localized. Since we weren't doing so the function failed on
non-english windows systems. Replacing the call with the language neutral PdhAddEnglishCounter
fixes the problem.

I added some debug to check and print the error code.

Before the change:
\```
omrsysinfo_get_memory_info: after GlobalMemoryStatusEx 4200
omrsysinfo_get_memory_info: after PdhOpenQuery 189500
omrsysinfo_get_memory_info: after PdhAddCounter 1 532003600
PdhAddCounter FAILED with c0000bb8
\```

After the change:
\```
omrsysinfo_get_memory_info: after GlobalMemoryStatusEx 5000
omrsysinfo_get_memory_info: after PdhOpenQuery 108600
omrsysinfo_get_memory_info: after PdhAddCounter 1 689300300
omrsysinfo_get_memory_info: after PdhAddCounter 2 309400
omrsysinfo_get_memory_info: after PdhAddCounter 3 161600
omrsysinfo_get_memory_info: after PdhCollectQueryData 201400
totalSwap 46477017088
\```

port/win32/omrsysinfo.c Outdated Show resolved Hide resolved
port/win32/omrsysinfo.c Outdated Show resolved Hide resolved
JamesKingdon and others added 2 commits December 3, 2024 14:13
Copy link
Contributor

@babsingh babsingh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commits will need to be squashed. The primary commit will need to be updated as per #7566 (comment).

if (ERROR_SUCCESS != status) {
Trc_PRT_sysinfo_get_memory_info_failedAddingCounter("Commit Limit", status);
Trc_PRT_sysinfo_get_memory_info_Exit(OMRPORT_ERROR_SYSINFO_ERROR_READING_MEMORY_INFO);
PdhCloseQuery(statsHandle);
return OMRPORT_ERROR_SYSINFO_ERROR_READING_MEMORY_INFO;
}

status = PdhAddCounter(statsHandle,
status = PdhAddEnglishCounter(statsHandle,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#7566 (comment) also needs to be applied here.

@@ -951,7 +953,7 @@ omrsysinfo_get_memory_info(struct OMRPortLibrary *portLibrary, struct J9MemoryIn
return OMRPORT_ERROR_SYSINFO_ERROR_READING_MEMORY_INFO;
}

status = PdhAddCounter(statsHandle,
status = PdhAddEnglishCounter(statsHandle,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#7566 (comment) also needs to be applied here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants