Changeset 56689 in webkit


Ignore:
Timestamp:
Mar 28, 2010 3:43:05 AM (14 years ago)
Author:
eric@webkit.org
Message:

2010-03-28 Kent Hansen <kent.hansen@nokia.com>

Reviewed by Simon Hausmann.

[Qt] Add API for reporting additional memory cost of JavaScript objects
https://bugs.webkit.org/show_bug.cgi?id=36650

  • qt/api/qscriptengine.cpp: (QScriptEngine::reportAdditionalMemoryCost):
  • qt/api/qscriptengine.h:
  • qt/api/qscriptengine_p.h: (QScriptEnginePrivate::reportAdditionalMemoryCost):
  • qt/tests/qscriptengine/tst_qscriptengine.cpp: (tst_QScriptEngine::reportAdditionalMemoryCost):
Location:
trunk/JavaScriptCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r56686 r56689  
     12010-03-28  Kent Hansen  <kent.hansen@nokia.com>
     2
     3        Reviewed by Simon Hausmann.
     4
     5        [Qt] Add API for reporting additional memory cost of JavaScript objects
     6        https://bugs.webkit.org/show_bug.cgi?id=36650
     7
     8        * qt/api/qscriptengine.cpp:
     9        (QScriptEngine::reportAdditionalMemoryCost):
     10        * qt/api/qscriptengine.h:
     11        * qt/api/qscriptengine_p.h:
     12        (QScriptEnginePrivate::reportAdditionalMemoryCost):
     13        * qt/tests/qscriptengine/tst_qscriptengine.cpp:
     14        (tst_QScriptEngine::reportAdditionalMemoryCost):
     15
    1162010-03-28  Jedrzej Nowacki  <jedrzej.nowacki@nokia.com>
    217
  • trunk/JavaScriptCore/qt/api/qscriptengine.cpp

    r56686 r56689  
    106106    have been created). However, you can call this function to explicitly request that garbage
    107107    collection should be performed as soon as possible.
     108
     109    \sa reportAdditionalMemoryCost()
    108110*/
    109111void QScriptEngine::collectGarbage()
    110112{
    111113    d_ptr->collectGarbage();
     114}
     115
     116/*!
     117  Reports an additional memory cost of the given \a size, measured in
     118  bytes, to the garbage collector.
     119
     120  This function can be called to indicate that a JavaScript object has
     121  memory associated with it that isn't managed by Qt Script itself.
     122  Reporting the additional cost makes it more likely that the garbage
     123  collector will be triggered.
     124
     125  Note that if the additional memory is shared with objects outside
     126  the scripting environment, the cost should not be reported, since
     127  collecting the JavaScript object would not cause the memory to be
     128  freed anyway.
     129
     130  Negative \a size values are ignored, i.e. this function can't be
     131  used to report that the additional memory has been deallocated.
     132
     133  \sa collectGarbage()
     134*/
     135void QScriptEngine::reportAdditionalMemoryCost(int cost)
     136{
     137    d_ptr->reportAdditionalMemoryCost(cost);
    112138}
    113139
  • trunk/JavaScriptCore/qt/api/qscriptengine.h

    r56686 r56689  
    4242    QScriptValue evaluate(const QString& program, const QString& fileName = QString(), int lineNumber = 1);
    4343    QScriptValue evaluate(const QScriptProgram& program);
     44
    4445    void collectGarbage();
     46    void reportAdditionalMemoryCost(int cost);
    4547
    4648    QScriptString toStringHandle(const QString& str);
  • trunk/JavaScriptCore/qt/api/qscriptengine_p.h

    r56686 r56689  
    2727#include "qscriptvalue.h"
    2828#include <JavaScriptCore/JavaScript.h>
     29#include <JSBasePrivate.h>
    2930#include <QtCore/qshareddata.h>
    3031#include <QtCore/qstring.h>
     
    4546    QScriptValuePrivate* evaluate(const QScriptProgramPrivate* program);
    4647    inline JSValueRef evaluate(JSStringRef program, JSStringRef fileName, int lineNumber);
     48
    4749    inline void collectGarbage();
     50    inline void reportAdditionalMemoryCost(int cost);
    4851
    4952    inline JSValueRef makeJSValue(double number) const;
     
    7780{
    7881    JSGarbageCollect(m_context);
     82}
     83
     84void QScriptEnginePrivate::reportAdditionalMemoryCost(int cost)
     85{
     86    if (cost > 0)
     87        JSReportExtraMemoryCost(m_context, cost);
    7988}
    8089
  • trunk/JavaScriptCore/qt/tests/qscriptengine/tst_qscriptengine.cpp

    r56686 r56689  
    3939    void evaluate();
    4040    void collectGarbage();
     41    void reportAdditionalMemoryCost();
    4142    void nullValue();
    4243    void undefinedValue();
     
    7374    engine.collectGarbage();
    7475    QCOMPARE(foo.call().toString(), QString::fromAscii("pong"));
     76}
     77
     78void tst_QScriptEngine::reportAdditionalMemoryCost()
     79{
     80    // There isn't any easy way to test the responsiveness of the GC;
     81    // just try to call the function a few times with various sizes.
     82    QScriptEngine eng;
     83    for (int i = 0; i < 100; ++i) {
     84        eng.reportAdditionalMemoryCost(0);
     85        eng.reportAdditionalMemoryCost(10);
     86        eng.reportAdditionalMemoryCost(1000);
     87        eng.reportAdditionalMemoryCost(10000);
     88        eng.reportAdditionalMemoryCost(100000);
     89        eng.reportAdditionalMemoryCost(1000000);
     90        eng.reportAdditionalMemoryCost(10000000);
     91        eng.reportAdditionalMemoryCost(-1);
     92        eng.reportAdditionalMemoryCost(-1000);
     93        QScriptValue obj = eng.evaluate("new Object");
     94        eng.collectGarbage();
     95    }
    7596}
    7697
Note: See TracChangeset for help on using the changeset viewer.