Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | function CCAnalyzer() { |
michael@0 | 6 | } |
michael@0 | 7 | |
michael@0 | 8 | CCAnalyzer.prototype = { |
michael@0 | 9 | clear: function () { |
michael@0 | 10 | this.callback = null; |
michael@0 | 11 | this.processingCount = 0; |
michael@0 | 12 | this.graph = {}; |
michael@0 | 13 | this.roots = []; |
michael@0 | 14 | this.garbage = []; |
michael@0 | 15 | this.edges = []; |
michael@0 | 16 | this.listener = null; |
michael@0 | 17 | }, |
michael@0 | 18 | |
michael@0 | 19 | run: function (aCallback) { |
michael@0 | 20 | this.clear(); |
michael@0 | 21 | this.callback = aCallback; |
michael@0 | 22 | |
michael@0 | 23 | this.listener = Cc["@mozilla.org/cycle-collector-logger;1"]. |
michael@0 | 24 | createInstance(Ci.nsICycleCollectorListener); |
michael@0 | 25 | |
michael@0 | 26 | this.listener.disableLog = true; |
michael@0 | 27 | this.listener.wantAfterProcessing = true; |
michael@0 | 28 | |
michael@0 | 29 | this.runCC(3); |
michael@0 | 30 | }, |
michael@0 | 31 | |
michael@0 | 32 | runCC: function (aCounter) { |
michael@0 | 33 | let utils = window.QueryInterface(Ci.nsIInterfaceRequestor). |
michael@0 | 34 | getInterface(Ci.nsIDOMWindowUtils); |
michael@0 | 35 | |
michael@0 | 36 | if (aCounter > 1) { |
michael@0 | 37 | utils.garbageCollect(); |
michael@0 | 38 | setTimeout(this.runCC.bind(this, aCounter - 1), 0); |
michael@0 | 39 | } else { |
michael@0 | 40 | utils.garbageCollect(this.listener); |
michael@0 | 41 | this.processLog(); |
michael@0 | 42 | } |
michael@0 | 43 | }, |
michael@0 | 44 | |
michael@0 | 45 | processLog: function () { |
michael@0 | 46 | // Process entire heap step by step in 5K chunks |
michael@0 | 47 | for (let i = 0; i < 5000; i++) { |
michael@0 | 48 | if (!this.listener.processNext(this)) { |
michael@0 | 49 | this.callback(); |
michael@0 | 50 | this.clear(); |
michael@0 | 51 | return; |
michael@0 | 52 | } |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | // Next chunk on timeout. |
michael@0 | 56 | setTimeout(this.processLog.bind(this), 0); |
michael@0 | 57 | }, |
michael@0 | 58 | |
michael@0 | 59 | noteRefCountedObject: function (aAddress, aRefCount, aObjectDescription) { |
michael@0 | 60 | let o = this.ensureObject(aAddress); |
michael@0 | 61 | o.address = aAddress; |
michael@0 | 62 | o.refcount = aRefCount; |
michael@0 | 63 | o.name = aObjectDescription; |
michael@0 | 64 | }, |
michael@0 | 65 | |
michael@0 | 66 | noteGCedObject: function (aAddress, aMarked, aObjectDescription) { |
michael@0 | 67 | let o = this.ensureObject(aAddress); |
michael@0 | 68 | o.address = aAddress; |
michael@0 | 69 | o.gcmarked = aMarked; |
michael@0 | 70 | o.name = aObjectDescription; |
michael@0 | 71 | }, |
michael@0 | 72 | |
michael@0 | 73 | noteEdge: function (aFromAddress, aToAddress, aEdgeName) { |
michael@0 | 74 | let fromObject = this.ensureObject(aFromAddress); |
michael@0 | 75 | let toObject = this.ensureObject(aToAddress); |
michael@0 | 76 | fromObject.edges.push({name: aEdgeName, to: toObject}); |
michael@0 | 77 | toObject.owners.push({name: aEdgeName, from: fromObject}); |
michael@0 | 78 | |
michael@0 | 79 | this.edges.push({ |
michael@0 | 80 | name: aEdgeName, |
michael@0 | 81 | from: fromObject, |
michael@0 | 82 | to: toObject |
michael@0 | 83 | }); |
michael@0 | 84 | }, |
michael@0 | 85 | |
michael@0 | 86 | describeRoot: function (aAddress, aKnownEdges) { |
michael@0 | 87 | let o = this.ensureObject(aAddress); |
michael@0 | 88 | o.root = true; |
michael@0 | 89 | o.knownEdges = aKnownEdges; |
michael@0 | 90 | this.roots.push(o); |
michael@0 | 91 | }, |
michael@0 | 92 | |
michael@0 | 93 | describeGarbage: function (aAddress) { |
michael@0 | 94 | let o = this.ensureObject(aAddress); |
michael@0 | 95 | o.garbage = true; |
michael@0 | 96 | this.garbage.push(o); |
michael@0 | 97 | }, |
michael@0 | 98 | |
michael@0 | 99 | ensureObject: function (aAddress) { |
michael@0 | 100 | if (!this.graph[aAddress]) |
michael@0 | 101 | this.graph[aAddress] = new CCObject(); |
michael@0 | 102 | |
michael@0 | 103 | return this.graph[aAddress]; |
michael@0 | 104 | }, |
michael@0 | 105 | |
michael@0 | 106 | find: function (aText) { |
michael@0 | 107 | let result = []; |
michael@0 | 108 | for each (let o in this.graph) { |
michael@0 | 109 | if (!o.garbage && o.name.indexOf(aText) >= 0) |
michael@0 | 110 | result.push(o); |
michael@0 | 111 | } |
michael@0 | 112 | return result; |
michael@0 | 113 | } |
michael@0 | 114 | }; |
michael@0 | 115 | |
michael@0 | 116 | function CCObject() { |
michael@0 | 117 | this.name = ""; |
michael@0 | 118 | this.address = null; |
michael@0 | 119 | this.refcount = 0; |
michael@0 | 120 | this.gcmarked = false; |
michael@0 | 121 | this.root = false; |
michael@0 | 122 | this.garbage = false; |
michael@0 | 123 | this.knownEdges = 0; |
michael@0 | 124 | this.edges = []; |
michael@0 | 125 | this.owners = []; |
michael@0 | 126 | } |