| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 #include "platform/ScriptForbiddenScope.h" | 34 #include "platform/ScriptForbiddenScope.h" |
| 35 #include "platform/TraceEvent.h" | 35 #include "platform/TraceEvent.h" |
| 36 #include "platform/heap/AddressSanitizer.h" | 36 #include "platform/heap/AddressSanitizer.h" |
| 37 #include "platform/heap/CallbackStack.h" | 37 #include "platform/heap/CallbackStack.h" |
| 38 #include "platform/heap/Handle.h" | 38 #include "platform/heap/Handle.h" |
| 39 #include "platform/heap/Heap.h" | 39 #include "platform/heap/Heap.h" |
| 40 #include "public/platform/Platform.h" | 40 #include "public/platform/Platform.h" |
| 41 #include "public/platform/WebThread.h" | 41 #include "public/platform/WebThread.h" |
| 42 #include "wtf/ThreadingPrimitives.h" | 42 #include "wtf/ThreadingPrimitives.h" |
| 43 #if ENABLE(GC_PROFILE_HEAP) | 43 #if ENABLE(GC_PROFILE_HEAP) || ENABLE(GC_PROFILE_FREE_LIST) |
| 44 #include "platform/TracedValue.h" | 44 #include "platform/TracedValue.h" |
| 45 #endif | 45 #endif |
| 46 | 46 |
| 47 #if OS(WIN) | 47 #if OS(WIN) |
| 48 #include <stddef.h> | 48 #include <stddef.h> |
| 49 #include <windows.h> | 49 #include <windows.h> |
| 50 #include <winnt.h> | 50 #include <winnt.h> |
| 51 #elif defined(__GLIBC__) | 51 #elif defined(__GLIBC__) |
| 52 extern "C" void* __libc_stack_end; // NOLINT | 52 extern "C" void* __libc_stack_end; // NOLINT |
| 53 #endif | 53 #endif |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 | 600 |
| 601 #if ENABLE(GC_PROFILE_MARKING) | 601 #if ENABLE(GC_PROFILE_MARKING) |
| 602 const GCInfo* ThreadState::findGCInfo(Address address) | 602 const GCInfo* ThreadState::findGCInfo(Address address) |
| 603 { | 603 { |
| 604 if (BaseHeapPage* page = pageFromAddress(address)) | 604 if (BaseHeapPage* page = pageFromAddress(address)) |
| 605 return page->findGCInfo(address); | 605 return page->findGCInfo(address); |
| 606 return nullptr; | 606 return nullptr; |
| 607 } | 607 } |
| 608 #endif | 608 #endif |
| 609 | 609 |
| 610 #if ENABLE(GC_PROFILE_FREE_LIST) |
| 611 |
| 612 void ThreadState::snapshotFreeListIfNecessary() |
| 613 { |
| 614 //bool gcTracingEnabled; |
| 615 //TRACE_EVENT_CATEGORY_GROUP_ENABLED("blink_gc", &gcTracingEnabled); |
| 616 //if (!gcTracingEnabled) |
| 617 // return; |
| 618 const double kRecordInterval = 0.010; // seconds |
| 619 static double nextRecordTime = monotonicallyIncreasingTime() + kRecordInterv
al; |
| 620 if (monotonicallyIncreasingTime() > nextRecordTime) { |
| 621 snapshotFreeList(); |
| 622 nextRecordTime = monotonicallyIncreasingTime() + kRecordInterval; |
| 623 } |
| 624 } |
| 625 |
| 626 void ThreadState::snapshotFreeList() |
| 627 { |
| 628 RefPtr<TracedValue> json = TracedValue::create(); |
| 629 |
| 630 #define SNAPSHOT_FREE_LIST(HeapType) \ |
| 631 { \ |
| 632 json->beginDictionary(); \ |
| 633 json->setString("name", #HeapType); \ |
| 634 m_heaps[HeapType##Heap]->snapshotFreeList(json.get()); \ |
| 635 json->endDictionary(); \ |
| 636 json->beginDictionary(); \ |
| 637 json->setString("name", #HeapType"NonFinalized"); \ |
| 638 m_heaps[HeapType##HeapNonFinalized]->snapshotFreeList(json.get()); \ |
| 639 json->endDictionary(); \ |
| 640 } |
| 641 json->beginArray("heaps"); |
| 642 SNAPSHOT_FREE_LIST(General1); |
| 643 SNAPSHOT_FREE_LIST(General2); |
| 644 SNAPSHOT_FREE_LIST(General3); |
| 645 SNAPSHOT_FREE_LIST(General4); |
| 646 SNAPSHOT_FREE_LIST(VectorBacking); |
| 647 SNAPSHOT_FREE_LIST(HashTableBacking); |
| 648 FOR_EACH_TYPED_HEAP(SNAPSHOT_FREE_LIST); |
| 649 json->endArray(); |
| 650 #undef SNAPSHOT_FREE_LIST |
| 651 |
| 652 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID("blink_gc", "FreeList", this, json.relea
se()); |
| 653 } |
| 654 |
| 655 #endif |
| 656 |
| 610 #if ENABLE(GC_PROFILE_HEAP) | 657 #if ENABLE(GC_PROFILE_HEAP) |
| 611 size_t ThreadState::SnapshotInfo::getClassTag(const GCInfo* gcinfo) | 658 size_t ThreadState::SnapshotInfo::getClassTag(const GCInfo* gcinfo) |
| 612 { | 659 { |
| 613 HashMap<const GCInfo*, size_t>::AddResult result = classTags.add(gcinfo, cla
ssTags.size()); | 660 HashMap<const GCInfo*, size_t>::AddResult result = classTags.add(gcinfo, cla
ssTags.size()); |
| 614 if (result.isNewEntry) { | 661 if (result.isNewEntry) { |
| 615 liveCount.append(0); | 662 liveCount.append(0); |
| 616 deadCount.append(0); | 663 deadCount.append(0); |
| 617 liveSize.append(0); | 664 liveSize.append(0); |
| 618 deadSize.append(0); | 665 deadSize.append(0); |
| 619 generations.append(Vector<int, 8>()); | 666 generations.append(Vector<int, 8>()); |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 for (size_t i = 0; i < slotCount; ++i) { | 1039 for (size_t i = 0; i < slotCount; ++i) { |
| 993 m_safePointStackCopy[i] = from[i]; | 1040 m_safePointStackCopy[i] = from[i]; |
| 994 } | 1041 } |
| 995 } | 1042 } |
| 996 | 1043 |
| 997 void ThreadState::performPendingSweep() | 1044 void ThreadState::performPendingSweep() |
| 998 { | 1045 { |
| 999 checkThread(); | 1046 checkThread(); |
| 1000 if (gcState() != SweepScheduled) | 1047 if (gcState() != SweepScheduled) |
| 1001 return; | 1048 return; |
| 1049 |
| 1050 Heap::reportSweepingStats(); |
| 1051 |
| 1002 setGCState(Sweeping); | 1052 setGCState(Sweeping); |
| 1003 | 1053 |
| 1004 #if ENABLE(GC_PROFILE_HEAP) | 1054 #if ENABLE(GC_PROFILE_HEAP) |
| 1005 // We snapshot the heap prior to sweeping to get numbers for both resources | 1055 // We snapshot the heap prior to sweeping to get numbers for both resources |
| 1006 // that have been allocated since the last GC and for resources that are | 1056 // that have been allocated since the last GC and for resources that are |
| 1007 // going to be freed. | 1057 // going to be freed. |
| 1008 bool gcTracingEnabled; | 1058 bool gcTracingEnabled; |
| 1009 TRACE_EVENT_CATEGORY_GROUP_ENABLED("blink_gc", &gcTracingEnabled); | 1059 TRACE_EVENT_CATEGORY_GROUP_ENABLED("blink_gc", &gcTracingEnabled); |
| 1010 if (gcTracingEnabled) | 1060 if (gcTracingEnabled) |
| 1011 snapshot(); | 1061 snapshot(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1071 } | 1121 } |
| 1072 | 1122 |
| 1073 if (Platform::current()) { | 1123 if (Platform::current()) { |
| 1074 Platform::current()->histogramCustomCounts("BlinkGC.PerformPendingSweep"
, WTF::currentTimeMS() - timeStamp, 0, 10 * 1000, 50); | 1124 Platform::current()->histogramCustomCounts("BlinkGC.PerformPendingSweep"
, WTF::currentTimeMS() - timeStamp, 0, 10 * 1000, 50); |
| 1075 } | 1125 } |
| 1076 | 1126 |
| 1077 if (isMainThread()) { | 1127 if (isMainThread()) { |
| 1078 TRACE_EVENT_SET_NONCONST_SAMPLING_STATE(samplingState); | 1128 TRACE_EVENT_SET_NONCONST_SAMPLING_STATE(samplingState); |
| 1079 ScriptForbiddenScope::exit(); | 1129 ScriptForbiddenScope::exit(); |
| 1080 } | 1130 } |
| 1131 #if ENABLE(GC_PROFILE_FREE_LIST) |
| 1132 snapshotFreeListIfNecessary(); |
| 1133 #endif |
| 1081 } | 1134 } |
| 1082 | 1135 |
| 1083 void ThreadState::addInterruptor(Interruptor* interruptor) | 1136 void ThreadState::addInterruptor(Interruptor* interruptor) |
| 1084 { | 1137 { |
| 1085 checkThread(); | 1138 checkThread(); |
| 1086 SafePointScope scope(HeapPointersOnStack, SafePointScope::AllowNesting); | 1139 SafePointScope scope(HeapPointersOnStack, SafePointScope::AllowNesting); |
| 1087 { | 1140 { |
| 1088 MutexLocker locker(threadAttachMutex()); | 1141 MutexLocker locker(threadAttachMutex()); |
| 1089 m_interruptors.append(interruptor); | 1142 m_interruptors.append(interruptor); |
| 1090 } | 1143 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1152 return gcInfo; | 1205 return gcInfo; |
| 1153 } | 1206 } |
| 1154 } | 1207 } |
| 1155 if (needLockForIteration) | 1208 if (needLockForIteration) |
| 1156 threadAttachMutex().unlock(); | 1209 threadAttachMutex().unlock(); |
| 1157 return nullptr; | 1210 return nullptr; |
| 1158 } | 1211 } |
| 1159 #endif | 1212 #endif |
| 1160 | 1213 |
| 1161 } // namespace blink | 1214 } // namespace blink |
| OLD | NEW |