OLD | NEW |
(Empty) | |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are |
| 4 // met: |
| 5 // |
| 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. |
| 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
| 28 // This is a supplementary file for test-log/EquivalenceOfLoggingAndTraversal. |
| 29 |
| 30 function parseState(s) { |
| 31 switch (s) { |
| 32 case "": return Profile.CodeState.COMPILED; |
| 33 case "~": return Profile.CodeState.OPTIMIZABLE; |
| 34 case "*": return Profile.CodeState.OPTIMIZED; |
| 35 } |
| 36 throw new Error("unknown code state: " + s); |
| 37 } |
| 38 |
| 39 function LogProcessor() { |
| 40 LogReader.call(this, { |
| 41 'code-creation': { |
| 42 parsers: [null, parseInt, parseInt, null, 'var-args'], |
| 43 processor: this.processCodeCreation }, |
| 44 'code-move': { parsers: [parseInt, parseInt], |
| 45 processor: this.processCodeMove }, |
| 46 'code-delete': { parsers: [parseInt], |
| 47 processor: this.processCodeDelete }, |
| 48 'sfi-move': { parsers: [parseInt, parseInt], |
| 49 processor: this.processFunctionMove }, |
| 50 'shared-library': null, |
| 51 'profiler': null, |
| 52 'tick': null }); |
| 53 this.profile = new Profile(); |
| 54 |
| 55 } |
| 56 LogProcessor.prototype.__proto__ = LogReader.prototype; |
| 57 |
| 58 LogProcessor.prototype.processCodeCreation = function( |
| 59 type, start, size, name, maybe_func) { |
| 60 if (type != "LazyCompile" && type != "Script" && type != "Function") return; |
| 61 // Discard types to avoid discrepancies in "LazyCompile" vs. "Function". |
| 62 type = ""; |
| 63 if (maybe_func.length) { |
| 64 var funcAddr = parseInt(maybe_func[0]); |
| 65 var state = parseState(maybe_func[1]); |
| 66 this.profile.addFuncCode(type, name, start, size, funcAddr, state); |
| 67 } else { |
| 68 this.profile.addCode(type, name, start, size); |
| 69 } |
| 70 }; |
| 71 |
| 72 LogProcessor.prototype.processCodeMove = function(from, to) { |
| 73 this.profile.moveCode(from, to); |
| 74 }; |
| 75 |
| 76 LogProcessor.prototype.processCodeDelete = function(start) { |
| 77 this.profile.deleteCode(start); |
| 78 }; |
| 79 |
| 80 LogProcessor.prototype.processFunctionMove = function(from, to) { |
| 81 this.profile.moveFunc(from, to); |
| 82 }; |
| 83 |
| 84 function RunTest() { |
| 85 // _log must be provided externally. |
| 86 var log_lines = _log.split("\n"); |
| 87 var line, pos = 0, log_lines_length = log_lines.length; |
| 88 if (log_lines_length < 2) |
| 89 return "log_lines_length < 2"; |
| 90 var logging_processor = new LogProcessor(); |
| 91 for ( ; pos < log_lines_length; ++pos) { |
| 92 line = log_lines[pos]; |
| 93 if (line === "test-logging-done,\"\"") { |
| 94 ++pos; |
| 95 break; |
| 96 } |
| 97 logging_processor.processLogLine(line); |
| 98 } |
| 99 logging_processor.profile.cleanUpFuncEntries(); |
| 100 var logging_entries = |
| 101 logging_processor.profile.codeMap_.getAllDynamicEntriesWithAddresses(); |
| 102 if (logging_entries.length === 0) |
| 103 return "logging_entries.length === 0"; |
| 104 var traversal_processor = new LogProcessor(); |
| 105 for ( ; pos < log_lines_length; ++pos) { |
| 106 line = log_lines[pos]; |
| 107 if (line === "test-traversal-done,\"\"") break; |
| 108 traversal_processor.processLogLine(line); |
| 109 } |
| 110 var traversal_entries = |
| 111 traversal_processor.profile.codeMap_.getAllDynamicEntriesWithAddresses(); |
| 112 if (traversal_entries.length === 0) |
| 113 return "traversal_entries.length === 0"; |
| 114 |
| 115 function addressComparator(entryA, entryB) { |
| 116 return entryA[0] < entryB[0] ? -1 : (entryA[0] > entryB[0] ? 1 : 0); |
| 117 } |
| 118 |
| 119 logging_entries.sort(addressComparator); |
| 120 traversal_entries.sort(addressComparator); |
| 121 |
| 122 function entityNamesEqual(entityA, entityB) { |
| 123 if ("getRawName" in entityB && |
| 124 entityNamesEqual.builtins.indexOf(entityB.getRawName()) !== -1) { |
| 125 return true; |
| 126 } |
| 127 if (entityNamesEqual.builtins.indexOf(entityB.getName()) !== -1) return true
; |
| 128 return entityA.getName() === entityB.getName(); |
| 129 } |
| 130 entityNamesEqual.builtins = |
| 131 ["Boolean", "Function", "Number", "Object", |
| 132 "Script", "String", "RegExp", "Date", "Error"]; |
| 133 |
| 134 function entitiesEqual(entityA, entityB) { |
| 135 if (entityA === null && entityB !== null) return true; |
| 136 if (entityA !== null && entityB === null) return false; |
| 137 return entityA.size === entityB.size && entityNamesEqual(entityA, entityB); |
| 138 } |
| 139 |
| 140 var i = 0, j = 0, k = logging_entries.length, l = traversal_entries.length; |
| 141 var comparison = []; |
| 142 var equal = true; |
| 143 // Do a merge-like comparison of entries. At the same address we expect to |
| 144 // find the same entries. We skip builtins during log parsing, but compiled |
| 145 // functions traversal may erroneously recognize them as functions, so we are |
| 146 // expecting more functions in traversal vs. logging. |
| 147 while (i < k && j < l) { |
| 148 var entryA = logging_entries[i], entryB = traversal_entries[j]; |
| 149 var cmp = addressComparator(entryA, entryB); |
| 150 var entityA = entryA[1], entityB = entryB[1]; |
| 151 var address = entryA[0]; |
| 152 if (cmp < 0) { |
| 153 ++i; |
| 154 entityB = null; |
| 155 } else if (cmp > 0) { |
| 156 ++j; |
| 157 entityA = null; |
| 158 address = entryB[0]; |
| 159 } else { |
| 160 ++i; |
| 161 ++j; |
| 162 } |
| 163 var entities_equal = entitiesEqual(entityA, entityB); |
| 164 if (!entities_equal) equal = false; |
| 165 comparison.push([entities_equal, address, entityA, entityB]); |
| 166 } |
| 167 if (i < k) equal = false; |
| 168 while (i < k) { |
| 169 var entryA = logging_entries[i++]; |
| 170 comparison.push([false, entryA[0], entryA[1], null]); |
| 171 } |
| 172 return [equal, comparison]; |
| 173 } |
| 174 |
| 175 var result = RunTest(); |
| 176 if (typeof result !== "string") { |
| 177 var out = []; |
| 178 if (!result[0]) { |
| 179 var comparison = result[1]; |
| 180 for (var i = 0, l = comparison.length; i < l; ++i) { |
| 181 var c = comparison[i]; |
| 182 out.push((c[0] ? " " : "* ") + |
| 183 c[1].toString(16) + " " + |
| 184 (c[2] ? c[2] : "---") + " " + |
| 185 (c[3] ? c[3] : "---")); |
| 186 } |
| 187 } |
| 188 result[0] ? true : out.join("\n"); |
| 189 } else { |
| 190 result; |
| 191 } |
OLD | NEW |