On Mon, 15 Jun 2026 10:02:51 GMT, Kevin Walls <[email protected]> wrote:
>> Coleen Phillimore has updated the pull request incrementally with one
>> additional commit since the last revision:
>>
>> Use shouldMatch for logging message.
>
> There is also a problem if a Java process in a container uses AltTempDir, a
> jps/jcmd process listing from the host cannot see the processes, even if
> setting the same AltTempDir (jps in the host usually lists Java processes
> running in containers).
>
> "open/src/jdk.internal.jvmstat/linux/classes/sun/jvmstat/PlatformSupportImpl.java"
> needs to update getLocalVmId() as it contains knowledge of the /tmp path to
> find hsperdata, which contains host pid and namespace (in-container) pid.
>
> Suggestion below which works me for (but is not foolproof...).
>
>
> One more issue: run in a container, with AltTempDir set to a directory
> mounted (shared) from the host.
> When the host runs jps with AltTempDir set the same,
> PlatformSupportImpl.java/getTemporaryDirectories() ignores some directories,
> because they are the same as its tmp dir (this was intentional, but becomes a
> problem in this case).
>
>
> $ build/linux-x64/images/jdk/bin/jps -J-XX:AltTempDir=/work
> 2880104 Jps
> 111 -- process information unavailable
>
>
> This means a /proc/2878800/root/work/hsperfdata_kwalls/111 path got ignored
> in preference for /work/hsperfdata_kwalls/111 ..from which it can't deduce
> both hostpid and nspid.
>
> Removing that check for the files being the same in getTemporaryDirectories()
> works:
>
>
> ---
> a/src/jdk.internal.jvmstat/linux/classes/sun/jvmstat/PlatformSupportImpl.java
> +++
> b/src/jdk.internal.jvmstat/linux/classes/sun/jvmstat/PlatformSupportImpl.java
> @@ -159,9 +159,8 @@ public boolean accept(File dir, String name) {
> File containerFile = new File(containerTmpDir);
>
> if (containerFile.exists() && containerFile.isDirectory() &&
> - containerFile.canRead() &&
> - !tempDirectoryEquals(containerFile.toPath())) {
> - v.add(containerTmpDir);
> + containerFile.canRead()) {
> + v.add(containerTmpDir);
> }
> }
>
>
> ...although it shows an error in jps:
>
>
> $ build/linux-x64/images/jdk/bin/jps -J-XX:AltTempDir=/work
> 145 -- process information unavailable
> 2883758 ThreadsMem
> 2884405 Jps
>
>
> 2883758 and 145 are the same process.
>
> jcmd will ignore this trivial failure to attach (as processes may come and
> go...) and looks fine.
>
> Making jps behave the same as jcmd by ignoring this error is what I came up
> with:
>
>
>
> src/jdk.jcmd/share/classes/sun/tools/jps/Jps.java
> @@ -87,7 +86,6 @@ public static void main(String[] args) {
> // reasonable message to indicate that the requested
> // info...
Thanks @kevinjwalls for pointing out that I can use /tmp/<dir> in the tests so
not to break for overly long paths in the tests when requiring that the
AltTempDir begins with '/'.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/31407#issuecomment-4835481982