Hi guys!

Here is the description of CR:
http://bt2ws.central.sun.com/CrPrint?id=7082294

Patch with changes attached.

Description of the fix:
Sometimes execution of AwtObjectList::Cleanup() could be delayed by
posting WM_AWT_OBJECTLISTCLEANUP message.
  From the other side this method is called from AwtToolkit::Dispose().
There AwtObjectList::Cleanup() is followed by AwtFont::Cleanup().
Thus, sometimes we could have the situation when AwtFont::Cleanup() is
called before the main functionality of AwtObjectList::Cleanup().
It means that all HFONT objects would be deleted from AwtFontCache.
So when AwtFont::Dispose() would be called from AwtObjectList::Cleanup()
it would not find HFONT in AwtFontCache and would try to delete HFONT
(that is deleted in AwtFontCache) once again.
There is also a custom message pump in AwtToolkit::Dispose() that allows
posted WM_AWT_OBJECTLISTCLEANUP be handled.
If we move AwtFont::Cleanup() right after that message pump we guarantee
that AwtObjectList::Cleanup() would always be called before
AwtFont::Cleanup().
That what my fix is about.

PS: I also left my changes in AwtFont to emilinate invalid HFONT usage
and access violation probability between AwtFont::Dispose() and
AwtFont::~AwtFont() calls.

PPS: This implementation is a kind of workaround for 7u4. As for JDK 8 - font caching should be improved.

Thanks,
Oleg.
--- old/src/windows/native/sun/windows/awt_Font.cpp     2012-01-26 
20:46:20.455523900 +0400
+++ new/src/windows/native/sun/windows/awt_Font.cpp     2012-01-26 
20:46:19.125447800 +0400
@@ -150,6 +150,7 @@
 
 AwtFont::~AwtFont()
 {
+    delete[] m_hFont; 
 }
 
 void AwtFont::Dispose() {
@@ -160,11 +161,12 @@
             /*  NOTE: delete of windows HFONT happens in FontCache::Remove
                       only when the final reference to the font is disposed */
         } else if (font != NULL) {
-         // if font was not in cache, its not shared and we delete it now
-           VERIFY(::DeleteObject(font));
+            // if font was not in cache, its not shared and we delete it now
+            DASSERT(::GetObjectType(font) == OBJ_FONT);
+            VERIFY(::DeleteObject(font));
         }
+        m_hFont[i] = NULL;
     }
-    delete[] m_hFont;
 
     AwtObject::Dispose();
 }
--- old/src/windows/native/sun/windows/awt_Toolkit.cpp  2012-01-26 
20:46:30.918122300 +0400
+++ new/src/windows/native/sun/windows/awt_Toolkit.cpp  2012-01-26 
20:46:29.568045100 +0400
@@ -534,7 +534,6 @@
     D3DInitializer::GetInstance().Clean();
 
     AwtObjectList::Cleanup();
-    AwtFont::Cleanup();
 
     awt_dnd_uninitialize();
     awt_clipboard_uninitialize((JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2));
@@ -554,6 +553,8 @@
         ::DispatchMessage(&msg);
     }
 
+    AwtFont::Cleanup();
+
     HWND toolkitHWndToDestroy = tk.m_toolkitHWnd;
     tk.m_toolkitHWnd = 0;
     VERIFY(::DestroyWindow(toolkitHWndToDestroy) != NULL);

Reply via email to