Fixing IcedTea-Web Browser Hanging
IcedTea-Web can hang Firefox due to deadlocks. This occurs in Firefox because it explicitly runs Java applets in the same process, while all other plugins are out-of-process.
The browser communicates with the native-code plugin through NPAPI. For certain NPAPI calls, the browser will wait for the call to complete.
- nice example is js->applet->js call. In this case it is sure deadlock.
The IcedTea-Web plugin has two distinct components (note that this does not apply to 'javaws' JNLP applications):
- The native code (C++) plugin that is implemented using NPAPI
- The Java application launcher that handles classloading and setting up the applet context
Spots where icedtea-web tends to hang on the C++ side:
- The 'getvalue' NPAPI call causes Firefox to block. This is ITNP_GetValue in the native plugin. It can attempt a "GetJavaObject" message to the Java process. Unfortunately, this can hang while waiting for initialization eg if the applet is awaiting confirmation.
- The 'setwindow' NPAPI call causes Firefox to block. This is ITNP_SetWindow in the native plugin. It attempts a resize action ("width" message, technically, since that is the first word used in the message). Unfortunately this also waits for initialization.
General strategies for dealing with hanging:
- Try and find if a deadlock is occurring. For this you should debug icedtea-web via the environment variable ICEDTEAPLUGIN_DEBUG=suspend and connect a Java debugger to port 8787, and see what the worker threads are doing. Generally icedtea-web hangs due to deadlock when all the worker threads are perpetually busy. Currently icedtea-web only employs 2 worker threads for all applet tasks.
- Try and do an operation that requires full applet initialization asynchronously.
- Try to avoid blocking operations (like waiting for applet initialization) all together.