Changeset 56689 in webkit
- Timestamp:
- Mar 28, 2010 3:43:05 AM (14 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r56686 r56689 1 2010-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 1 16 2010-03-28 Jedrzej Nowacki <jedrzej.nowacki@nokia.com> 2 17 -
trunk/JavaScriptCore/qt/api/qscriptengine.cpp
r56686 r56689 106 106 have been created). However, you can call this function to explicitly request that garbage 107 107 collection should be performed as soon as possible. 108 109 \sa reportAdditionalMemoryCost() 108 110 */ 109 111 void QScriptEngine::collectGarbage() 110 112 { 111 113 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 */ 135 void QScriptEngine::reportAdditionalMemoryCost(int cost) 136 { 137 d_ptr->reportAdditionalMemoryCost(cost); 112 138 } 113 139 -
trunk/JavaScriptCore/qt/api/qscriptengine.h
r56686 r56689 42 42 QScriptValue evaluate(const QString& program, const QString& fileName = QString(), int lineNumber = 1); 43 43 QScriptValue evaluate(const QScriptProgram& program); 44 44 45 void collectGarbage(); 46 void reportAdditionalMemoryCost(int cost); 45 47 46 48 QScriptString toStringHandle(const QString& str); -
trunk/JavaScriptCore/qt/api/qscriptengine_p.h
r56686 r56689 27 27 #include "qscriptvalue.h" 28 28 #include <JavaScriptCore/JavaScript.h> 29 #include <JSBasePrivate.h> 29 30 #include <QtCore/qshareddata.h> 30 31 #include <QtCore/qstring.h> … … 45 46 QScriptValuePrivate* evaluate(const QScriptProgramPrivate* program); 46 47 inline JSValueRef evaluate(JSStringRef program, JSStringRef fileName, int lineNumber); 48 47 49 inline void collectGarbage(); 50 inline void reportAdditionalMemoryCost(int cost); 48 51 49 52 inline JSValueRef makeJSValue(double number) const; … … 77 80 { 78 81 JSGarbageCollect(m_context); 82 } 83 84 void QScriptEnginePrivate::reportAdditionalMemoryCost(int cost) 85 { 86 if (cost > 0) 87 JSReportExtraMemoryCost(m_context, cost); 79 88 } 80 89 -
trunk/JavaScriptCore/qt/tests/qscriptengine/tst_qscriptengine.cpp
r56686 r56689 39 39 void evaluate(); 40 40 void collectGarbage(); 41 void reportAdditionalMemoryCost(); 41 42 void nullValue(); 42 43 void undefinedValue(); … … 73 74 engine.collectGarbage(); 74 75 QCOMPARE(foo.call().toString(), QString::fromAscii("pong")); 76 } 77 78 void 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 } 75 96 } 76 97
Note: See TracChangeset
for help on using the changeset viewer.