Changeset 236362 in webkit for trunk/Source/JavaScriptCore/jsc.cpp
- Timestamp:
- Sep 21, 2018, 2:47:25 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/jsc.cpp
r236305 r236362 128 128 #endif 129 129 130 #if __has_include(<WebKitAdditions/MemoryFootprint.h>) 131 #include <WebKitAdditions/MemoryFootprint.h> 132 #else 133 struct MemoryFootprint { 134 uint64_t current; 135 uint64_t peak; 136 137 static MemoryFootprint now() 138 { 139 return { 0L, 0L }; 140 } 141 142 static void resetPeak() 143 { 144 } 145 }; 146 #endif 147 130 148 #if !defined(PATH_MAX) 131 149 #define PATH_MAX 4096 … … 268 286 static EncodedJSValue JSC_HOST_CALL functionForceGCSlowPaths(ExecState*); 269 287 static EncodedJSValue JSC_HOST_CALL functionHeapSize(ExecState*); 288 static EncodedJSValue JSC_HOST_CALL functionCreateMemoryFootprint(ExecState*); 289 static EncodedJSValue JSC_HOST_CALL functionResetMemoryPeak(ExecState*); 270 290 static EncodedJSValue JSC_HOST_CALL functionAddressOf(ExecState*); 271 291 static EncodedJSValue JSC_HOST_CALL functionVersion(ExecState*); … … 485 505 addFunction(vm, "forceGCSlowPaths", functionForceGCSlowPaths, 0); 486 506 addFunction(vm, "gcHeapSize", functionHeapSize, 0); 507 addFunction(vm, "MemoryFootprint", functionCreateMemoryFootprint, 0); 508 addFunction(vm, "resetMemoryPeak", functionResetMemoryPeak, 0); 487 509 addFunction(vm, "addressOf", functionAddressOf, 1); 488 510 addFunction(vm, "version", functionVersion, 1); … … 1180 1202 } 1181 1203 1204 class JSCMemoryFootprint : public JSDestructibleObject { 1205 using Base = JSDestructibleObject; 1206 public: 1207 JSCMemoryFootprint(VM& vm, Structure* structure) 1208 : Base(vm, structure) 1209 { } 1210 1211 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype) 1212 { 1213 return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info()); 1214 } 1215 1216 static JSCMemoryFootprint* create(VM& vm, JSGlobalObject* globalObject) 1217 { 1218 Structure* structure = createStructure(vm, globalObject, jsNull()); 1219 JSCMemoryFootprint* footprint = new (NotNull, allocateCell<JSCMemoryFootprint>(vm.heap, sizeof(JSCMemoryFootprint))) JSCMemoryFootprint(vm, structure); 1220 footprint->finishCreation(vm); 1221 return footprint; 1222 } 1223 1224 void finishCreation(VM& vm) 1225 { 1226 Base::finishCreation(vm); 1227 1228 auto addProperty = [&] (VM& vm, const char* name, JSValue value) { 1229 JSCMemoryFootprint::addProperty(vm, name, value); 1230 }; 1231 1232 MemoryFootprint footprint = MemoryFootprint::now(); 1233 1234 // Report sizes in KBytes so that values up to GB are still integers. 1235 addProperty(vm, "current", jsNumber(footprint.current / 1024)); 1236 addProperty(vm, "peak", jsNumber(footprint.peak / 1024)); 1237 } 1238 1239 DECLARE_INFO; 1240 1241 private: 1242 void addProperty(VM& vm, const char* name, JSValue value) 1243 { 1244 Identifier identifier = Identifier::fromString(&vm, name); 1245 putDirect(vm, identifier, value); 1246 } 1247 }; 1248 1249 const ClassInfo JSCMemoryFootprint::s_info = { "MemoryFootprint", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSCMemoryFootprint) }; 1250 1251 EncodedJSValue JSC_HOST_CALL functionCreateMemoryFootprint(ExecState* exec) 1252 { 1253 VM& vm = exec->vm(); 1254 JSLockHolder lock(vm); 1255 return JSValue::encode(JSCMemoryFootprint::create(vm, exec->lexicalGlobalObject())); 1256 } 1257 1258 EncodedJSValue JSC_HOST_CALL functionResetMemoryPeak(ExecState*) 1259 { 1260 MemoryFootprint::resetPeak(); 1261 return JSValue::encode(jsUndefined()); 1262 } 1263 1182 1264 // This function is not generally very helpful in 64-bit code as the tag and payload 1183 1265 // share a register. But in 32-bit JITed code the tag may not be checked if an
Note:
See TracChangeset
for help on using the changeset viewer.