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

VisualVM freezes if JVM stops while connecting #616

Open
jukzi opened this issue Dec 10, 2024 · 9 comments
Open

VisualVM freezes if JVM stops while connecting #616

jukzi opened this issue Dec 10, 2024 · 9 comments
Labels

Comments

@jukzi
Copy link

jukzi commented Dec 10, 2024

I clicked on a local JVM. Typically it takes some seconds to connect, which is fine. But when the target JVM terminates during that time VisualVm freezes and all previous recorded measurements are lost :-(

I took a jstack from VisualVM while it is frozen:

DataSourceWindowManager Processor" #38 daemon prio=1 os_prio=-2 tid=0x0000000030567800 nid=0x72bc runnable [0x00000000340ae000]
   java.lang.Thread.State: RUNNABLE
	at sun.tools.attach.WindowsVirtualMachine.connectPipe(Native Method)
	at sun.tools.attach.WindowsVirtualMachine.execute(WindowsVirtualMachine.java:100)
	at sun.tools.attach.HotSpotVirtualMachine.executeCommand(HotSpotVirtualMachine.java:261)
	at sun.tools.attach.HotSpotVirtualMachine.executeJCmd(HotSpotVirtualMachine.java:243)
	at sun.tools.attach.HotSpotVirtualMachine.startLocalManagementAgent(HotSpotVirtualMachine.java:204)
	at org.graalvm.visualvm.jmx.impl.JmxModelImpl$LocalVirtualMachine.loadManagementAgentViaJcmd(JmxModelImpl.java:518)
	at org.graalvm.visualvm.jmx.impl.JmxModelImpl$LocalVirtualMachine.loadManagementAgent(JmxModelImpl.java:478)
	- locked <0x00000005c3b0e3a8> (a org.graalvm.visualvm.jmx.impl.JmxModelImpl$LocalVirtualMachine)
	at org.graalvm.visualvm.jmx.impl.JmxModelImpl$LocalVirtualMachine.startManagementAgent(JmxModelImpl.java:454)
	- locked <0x00000005c3b0e3a8> (a org.graalvm.visualvm.jmx.impl.JmxModelImpl$LocalVirtualMachine)
	at org.graalvm.visualvm.jmx.impl.ProxyClient.tryConnect(ProxyClient.java:265)
	at org.graalvm.visualvm.jmx.impl.ProxyClient.connectImpl(ProxyClient.java:233)
	at org.graalvm.visualvm.jmx.impl.ProxyClient.connect(ProxyClient.java:175)
	at org.graalvm.visualvm.jmx.impl.JmxModelImpl.<init>(JmxModelImpl.java:180)
	at org.graalvm.visualvm.jmx.impl.JmxModelProvider.createModelFor(JmxModelProvider.java:67)
	at org.graalvm.visualvm.jmx.impl.JmxModelProvider.createModelFor(JmxModelProvider.java:42)
	at org.graalvm.visualvm.core.model.ModelFactory.getModel(ModelFactory.java:105)
	- locked <0x00000005c3a0ad70> (a org.graalvm.visualvm.jvmstat.application.JvmstatApplication)
	at org.graalvm.visualvm.tools.jmx.JmxModelFactory.getJmxModelFor(JmxModelFactory.java:69)
	at org.graalvm.visualvm.application.views.threads.ApplicationThreadsViewProvider.resolveThreads(ApplicationThreadsViewProvider.java:84)
	at org.graalvm.visualvm.application.views.threads.ApplicationThreadsViewProvider.supportsViewFor(ApplicationThreadsViewProvider.java:50)
	at org.graalvm.visualvm.application.views.threads.ApplicationThreadsViewProvider.supportsViewFor(ApplicationThreadsViewProvider.java:45)
	at org.graalvm.visualvm.core.ui.DataSourceViewsManager.getViews(DataSourceViewsManager.java:136)
	at org.graalvm.visualvm.core.ui.DataSourceWindowManager.openWindowAndAddView(DataSourceWindowManager.java:262)
	at org.graalvm.visualvm.core.ui.DataSourceWindowManager.access$000(DataSourceWindowManager.java:52)
	at org.graalvm.visualvm.core.ui.DataSourceWindowManager$2.run(DataSourceWindowManager.java:121)
	at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1419)
	at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
	at org.openide.util.lookup.Lookups.executeWith(Lookups.java:287)
	at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2034)

visualVMFreeze.log
image

@jukzi jukzi added the bug label Dec 10, 2024
@thurka
Copy link
Member

thurka commented Dec 16, 2024

Do you have steps to reproduce it? According to thread dump, it is blocked in native code deep in JDK. It is not immediatelly clear to me, how to prevent it.

@jukzi
Copy link
Author

jukzi commented Dec 16, 2024

Well its reproducable with the shown VerifyTests of JDT, which spawn new JDK like every second. But i have not minimal reproducer yet. A "solution"/workaround would be to have the connect in a different thread that does not block the ui. At worst such thread would just not die.

@thurka
Copy link
Member

thurka commented Dec 16, 2024

A "solution"/workaround would be to have the connect in a different thread that does not block the ui.

Hmm, "DataSourceWindowManager Processor" is not AWT thread.

@jukzi
Copy link
Author

jukzi commented Dec 16, 2024

Hmm, i tried to create a reproducer by just restarting shortliving JVMs, but i can NOT reproduce with such simple program :-( :

package my;

import java.lang.management.ManagementFactory;
import java.util.ArrayList;

public class Main {

	private static final int SLEEP = 10;

	public static void main(String[] args) throws Exception {
		if (args != null && args.length != 0) {
			Thread.sleep(SLEEP);
		} else {
			ArrayList<String> cmd = new ArrayList<>();
			cmd.add(ProcessHandle.current().info().command().get());
			for (String jvmArg : ManagementFactory.getRuntimeMXBean().getInputArguments()) {
				cmd.add(jvmArg);
			}
			cmd.add("-cp");
			cmd.add(ManagementFactory.getRuntimeMXBean().getClassPath());
			cmd.add(Main.class.getName());
			cmd.add("forked");
			for (int i = 0; i < 1000; i++) {
				System.out.println(cmd);
				Thread.sleep(SLEEP);
				Runtime.getRuntime().exec(cmd.toArray(String[]::new));
			}
		}
	}

}

@jukzi
Copy link
Author

jukzi commented Dec 16, 2024

Hmm, "DataSourceWindowManager Processor" is not AWT thread.

The AWT thread is waiting for a lock hold by the starting thread:

"AWT-EventQueue-0" #22 prio=6 os_prio=0 tid=0x0000000029b59800 nid=0x53e4 waiting for monitor entry [0x000000002c99d000]
   java.lang.Thread.State: BLOCKED (on object monitor)
	at org.graalvm.visualvm.core.datasource.DataSource.getChangeSupport(DataSource.java:304)
	- waiting to lock <0x00000005c3a0ad70> (a org.graalvm.visualvm.jvmstat.application.JvmstatApplication)
	at org.graalvm.visualvm.core.datasource.DataSource.removePropertyChangeListener(DataSource.java:215)
	at org.graalvm.visualvm.profiler.ProfileApplicationAction.updateState(ProfileApplicationAction.java:75)
	at org.graalvm.visualvm.core.ui.actions.DataSourceAction$1.selectionChanged(DataSourceAction.java:87)
	at org.graalvm.visualvm.core.explorer.ExplorerSupport$ExplorerTreeSelectionListener.valueChanged(ExplorerSupport.java:272)

@thurka
Copy link
Member

thurka commented Dec 16, 2024

The AWT thread is waiting for a lock hold by the starting thread

This shows how important is to post whole thread dump, not just the part you think is important. So, please post the whole thread dump. Thanks.

@jukzi
Copy link
Author

jukzi commented Dec 16, 2024

i did that, see "visualVMFreeze.log" in the issue

@thurka
Copy link
Member

thurka commented Dec 16, 2024

OK, this link without description is almost invisble. :-)

@thurka thurka changed the title VisualVm freezes if JVM stops while connecting VisualVM freezes if JVM stops while connecting Dec 16, 2024
@thurka
Copy link
Member

thurka commented Dec 29, 2024

Any update on the steps how to reproduce it?

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

No branches or pull requests

2 participants