changeset 9667:84e09aadadf1

8153151: Call JavaScriptCore GC whenever JVM GC happens Reviewed-by: kcr, mbilla, azvegint
author arajkumar
date Thu, 07 Apr 2016 13:41:18 -0700
parents 99e46091a3a6
children b75591ee263b
files modules/web/src/main/java/com/sun/webkit/WebPage.java modules/web/src/main/native/Source/WebCore/mapfile-macosx modules/web/src/main/native/Source/WebCore/mapfile-vers modules/web/src/main/native/Source/WebCore/platform/java/WebPage.cpp
diffstat 4 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/modules/web/src/main/java/com/sun/webkit/WebPage.java	Thu Apr 07 10:31:11 2016 -0700
+++ b/modules/web/src/main/java/com/sun/webkit/WebPage.java	Thu Apr 07 13:41:18 2016 -0700
@@ -142,6 +142,17 @@
         });
     }
 
+    private static boolean firstWebPageCreated = false;
+
+    private static void collectJSCGarbages() {
+        Invoker.getInvoker().checkEventThread();
+        // Add dummy object to get notification as soon as it is collected
+        // by the JVM GC.
+        Disposer.addRecord(new Object(), WebPage::collectJSCGarbages);
+        // Invoke JavaScriptCore GC.
+        twkDoJSCGarbageCollection();
+    }
+
     public WebPage(WebPageClient pageClient,
                    UIClient uiClient,
                    PolicyClient policyClient,
@@ -174,6 +185,13 @@
             backbuffer = pageClient.createBackBuffer();
             backbuffer.ref();
         }
+
+        if (!firstWebPageCreated) {
+            // Add dummy object to get notification as soon as it is collected
+            // by the JVM GC.
+            Disposer.addRecord(new Object(), WebPage::collectJSCGarbages);
+            firstWebPageCreated = true;
+        }
     }
 
     long getPage() {
@@ -2559,4 +2577,5 @@
     private native void twkDisconnectInspectorFrontend(long pPage);
     private native void twkDispatchInspectorMessageFromFrontend(long pPage,
                                                                 String message);
+    private static native void twkDoJSCGarbageCollection();
 }
--- a/modules/web/src/main/native/Source/WebCore/mapfile-macosx	Thu Apr 07 10:31:11 2016 -0700
+++ b/modules/web/src/main/native/Source/WebCore/mapfile-macosx	Thu Apr 07 13:41:18 2016 -0700
@@ -1918,6 +1918,7 @@
                _Java_com_sun_webkit_WebPage_twkStopAll
                _Java_com_sun_webkit_WebPage_twkUpdateContent
                _Java_com_sun_webkit_WebPage_twkWorkerThreadCount
+               _Java_com_sun_webkit_WebPage_twkDoJSCGarbageCollection
                _Java_com_sun_webkit_dom_EventListenerImpl_twkCreatePeer
                _Java_com_sun_webkit_dom_EventListenerImpl_twkDispatchEvent
                _Java_com_sun_webkit_dom_EventListenerImpl_twkDisposeJSPeer
--- a/modules/web/src/main/native/Source/WebCore/mapfile-vers	Thu Apr 07 10:31:11 2016 -0700
+++ b/modules/web/src/main/native/Source/WebCore/mapfile-vers	Thu Apr 07 13:41:18 2016 -0700
@@ -1922,6 +1922,7 @@
                Java_com_sun_webkit_WebPage_twkStopAll;
                Java_com_sun_webkit_WebPage_twkUpdateContent;
                Java_com_sun_webkit_WebPage_twkWorkerThreadCount;
+               Java_com_sun_webkit_WebPage_twkDoJSCGarbageCollection;
                Java_com_sun_webkit_dom_EventListenerImpl_twkCreatePeer;
                Java_com_sun_webkit_dom_EventListenerImpl_twkDispatchEvent;
                Java_com_sun_webkit_dom_EventListenerImpl_twkDisposeJSPeer;
--- a/modules/web/src/main/native/Source/WebCore/platform/java/WebPage.cpp	Thu Apr 07 10:31:11 2016 -0700
+++ b/modules/web/src/main/native/Source/WebCore/platform/java/WebPage.cpp	Thu Apr 07 13:41:18 2016 -0700
@@ -36,6 +36,7 @@
 #include "FrameLoadRequest.h"
 #include "FrameLoaderClientJava.h"
 #include "FrameView.h"
+#include "GCController.h"
 #include "GraphicsContext.h"
 #include "HTMLFormElement.h"
 #include "IconController.h"
@@ -2219,6 +2220,12 @@
     return WorkerThread::workerThreadCount();
 }
 
+JNIEXPORT void JNICALL Java_com_sun_webkit_WebPage_twkDoJSCGarbageCollection
+  (JNIEnv*, jclass)
+{
+    gcController().garbageCollectNow();
+}
+
 #ifdef __cplusplus
 }
 #endif