On Tue, 19 May 2026 13:48:01 GMT, Alan Bateman <[email protected]> wrote:

> > We could create a HotSpotCoreFileOrMiniDumpProvider, which would get its 
> > chance to open a (id, env) pair. But then I can't say if that is before or 
> > after the exising PID attempt, and whether that will be the same for 
> > everybody, or will change.
> 
> The Attach API was designed to allow for multiple providers. The intention 
> was that a provider throw AttachNotSupportedException if invoked to attach to 
> something that it doesn't recognize, then move on to try the next provider. 
> The existing provider should be throwing AttachNotSupportedException already 
> if the id is not a process ID. Can you confirm this is the case? I'd hate to 
> see the ambiguous case ("123" is both the PID of a live VM, and "123" is the 
> core file) to influence this.


If iterating separate providers, a core file name clash with a PID I own that 
is non-Java, would mean a 10-second delay while the attach times out, and then 
opening the core.  If that's the order it happens in.


What was working, for a core and PID both existing and being the same 
characters, was:

jcmd 123    ...opened the PID.
jcmd -c 123 ...opened the core.

Aha but of course, since adding: 


"open/src/jdk.attach/share/classes/sun/tools/attach/HotSpotAttachProvider.java"
attachVirtualMachine(String vmid, Map<String, ?> env)
 63         try {
 64             if (env.isEmpty() && Integer.parseInt(vmid) > 0) {
 65                 return attachVirtualMachine(vmid);

```  
...if there's a clash, I can only open the pid. 8-( 

That delegation back to the 1-arg (vmid) attach stops this new method 
preferring the core if it exists.   (Need to revert that.)

(JCmd.java has its own argument parsing, and can choose different attach 
methods to call for pids vs core.)


On AttachNotSupportedException:
Yes, com.sun.tools.attach.AttachNotSupportedException delivers the attach 
failure for a non-java process,
although a pid you don't own might get java.nio.file.AccessDeniedException or 
java.io.IOException in different java versions.

There's also AttachOperationFailedException (of IOException) I see that if I 
give a PID of a non-existent process.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/31011#issuecomment-4488896703

Reply via email to