Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: src/preparse-data.cc

Issue 198903002: Only call to LogSymbol when needed. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/preparse-data.h ('k') | src/preparser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 19 matching lines...) Expand all
30 #include "preparse-data-format.h" 30 #include "preparse-data-format.h"
31 #include "preparse-data.h" 31 #include "preparse-data.h"
32 32
33 #include "checks.h" 33 #include "checks.h"
34 #include "globals.h" 34 #include "globals.h"
35 #include "hashmap.h" 35 #include "hashmap.h"
36 36
37 namespace v8 { 37 namespace v8 {
38 namespace internal { 38 namespace internal {
39 39
40 // ----------------------------------------------------------------------------
41 // FunctionLoggingParserRecorder
42 40
43 FunctionLoggingParserRecorder::FunctionLoggingParserRecorder() 41 template <typename Char>
42 static int vector_hash(Vector<const Char> string) {
43 int hash = 0;
44 for (int i = 0; i < string.length(); i++) {
45 int c = static_cast<int>(string[i]);
46 hash += c;
47 hash += (hash << 10);
48 hash ^= (hash >> 6);
49 }
50 return hash;
51 }
52
53
54 static bool vector_compare(void* a, void* b) {
55 CompleteParserRecorder::Key* string1 =
56 reinterpret_cast<CompleteParserRecorder::Key*>(a);
57 CompleteParserRecorder::Key* string2 =
58 reinterpret_cast<CompleteParserRecorder::Key*>(b);
59 if (string1->is_one_byte != string2->is_one_byte) return false;
60 int length = string1->literal_bytes.length();
61 if (string2->literal_bytes.length() != length) return false;
62 return memcmp(string1->literal_bytes.start(),
63 string2->literal_bytes.start(), length) == 0;
64 }
65
66
67 CompleteParserRecorder::CompleteParserRecorder()
44 : function_store_(0), 68 : function_store_(0),
45 is_recording_(true), 69 literal_chars_(0),
46 pause_count_(0) { 70 symbol_store_(0),
71 symbol_keys_(0),
72 string_table_(vector_compare),
73 symbol_id_(0) {
47 preamble_[PreparseDataConstants::kMagicOffset] = 74 preamble_[PreparseDataConstants::kMagicOffset] =
48 PreparseDataConstants::kMagicNumber; 75 PreparseDataConstants::kMagicNumber;
49 preamble_[PreparseDataConstants::kVersionOffset] = 76 preamble_[PreparseDataConstants::kVersionOffset] =
50 PreparseDataConstants::kCurrentVersion; 77 PreparseDataConstants::kCurrentVersion;
51 preamble_[PreparseDataConstants::kHasErrorOffset] = false; 78 preamble_[PreparseDataConstants::kHasErrorOffset] = false;
52 preamble_[PreparseDataConstants::kFunctionsSizeOffset] = 0; 79 preamble_[PreparseDataConstants::kFunctionsSizeOffset] = 0;
53 preamble_[PreparseDataConstants::kSymbolCountOffset] = 0; 80 preamble_[PreparseDataConstants::kSymbolCountOffset] = 0;
54 preamble_[PreparseDataConstants::kSizeOffset] = 0; 81 preamble_[PreparseDataConstants::kSizeOffset] = 0;
55 ASSERT_EQ(6, PreparseDataConstants::kHeaderSize); 82 ASSERT_EQ(6, PreparseDataConstants::kHeaderSize);
56 #ifdef DEBUG 83 #ifdef DEBUG
57 prev_start_ = -1; 84 prev_start_ = -1;
58 #endif 85 #endif
86 should_log_symbols_ = true;
59 } 87 }
60 88
61 89
62 void FunctionLoggingParserRecorder::LogMessage(int start_pos, 90 void CompleteParserRecorder::LogMessage(int start_pos,
63 int end_pos, 91 int end_pos,
64 const char* message, 92 const char* message,
65 const char* arg_opt) { 93 const char* arg_opt) {
66 if (has_error()) return; 94 if (has_error()) return;
67 preamble_[PreparseDataConstants::kHasErrorOffset] = true; 95 preamble_[PreparseDataConstants::kHasErrorOffset] = true;
68 function_store_.Reset(); 96 function_store_.Reset();
69 STATIC_ASSERT(PreparseDataConstants::kMessageStartPos == 0); 97 STATIC_ASSERT(PreparseDataConstants::kMessageStartPos == 0);
70 function_store_.Add(start_pos); 98 function_store_.Add(start_pos);
71 STATIC_ASSERT(PreparseDataConstants::kMessageEndPos == 1); 99 STATIC_ASSERT(PreparseDataConstants::kMessageEndPos == 1);
72 function_store_.Add(end_pos); 100 function_store_.Add(end_pos);
73 STATIC_ASSERT(PreparseDataConstants::kMessageArgCountPos == 2); 101 STATIC_ASSERT(PreparseDataConstants::kMessageArgCountPos == 2);
74 function_store_.Add((arg_opt == NULL) ? 0 : 1); 102 function_store_.Add((arg_opt == NULL) ? 0 : 1);
75 STATIC_ASSERT(PreparseDataConstants::kMessageTextPos == 3); 103 STATIC_ASSERT(PreparseDataConstants::kMessageTextPos == 3);
76 WriteString(CStrVector(message)); 104 WriteString(CStrVector(message));
77 if (arg_opt != NULL) WriteString(CStrVector(arg_opt)); 105 if (arg_opt != NULL) WriteString(CStrVector(arg_opt));
78 is_recording_ = false; 106 should_log_symbols_ = false;
79 } 107 }
80 108
81 109
82 void FunctionLoggingParserRecorder::WriteString(Vector<const char> str) { 110 void CompleteParserRecorder::WriteString(Vector<const char> str) {
83 function_store_.Add(str.length()); 111 function_store_.Add(str.length());
84 for (int i = 0; i < str.length(); i++) { 112 for (int i = 0; i < str.length(); i++) {
85 function_store_.Add(str[i]); 113 function_store_.Add(str[i]);
86 } 114 }
87 } 115 }
88 116
89 117
90 // ---------------------------------------------------------------------------- 118 void CompleteParserRecorder::LogOneByteSymbol(int start,
91 // PartialParserRecorder - Record both function entries and symbols. 119 Vector<const uint8_t> literal) {
92 120 ASSERT(should_log_symbols_);
93 Vector<unsigned> PartialParserRecorder::ExtractData() { 121 int hash = vector_hash(literal);
94 int function_size = function_store_.size(); 122 LogSymbol(start, hash, true, literal);
95 int total_size = PreparseDataConstants::kHeaderSize + function_size;
96 Vector<unsigned> data = Vector<unsigned>::New(total_size);
97 preamble_[PreparseDataConstants::kFunctionsSizeOffset] = function_size;
98 preamble_[PreparseDataConstants::kSymbolCountOffset] = 0;
99 OS::MemCopy(data.start(), preamble_, sizeof(preamble_));
100 int symbol_start = PreparseDataConstants::kHeaderSize + function_size;
101 if (function_size > 0) {
102 function_store_.WriteTo(data.SubVector(PreparseDataConstants::kHeaderSize,
103 symbol_start));
104 }
105 return data;
106 } 123 }
107 124
108 125
109 // ---------------------------------------------------------------------------- 126 void CompleteParserRecorder::LogTwoByteSymbol(int start,
110 // CompleteParserRecorder - Record both function entries and symbols. 127 Vector<const uint16_t> literal) {
111 128 ASSERT(should_log_symbols_);
112 CompleteParserRecorder::CompleteParserRecorder() 129 int hash = vector_hash(literal);
113 : FunctionLoggingParserRecorder(), 130 LogSymbol(start, hash, false, Vector<const byte>::cast(literal));
114 literal_chars_(0),
115 symbol_store_(0),
116 symbol_keys_(0),
117 string_table_(vector_compare),
118 symbol_id_(0) {
119 } 131 }
120 132
121 133
122 void CompleteParserRecorder::LogSymbol(int start, 134 void CompleteParserRecorder::LogSymbol(int start,
123 int hash, 135 int hash,
124 bool is_ascii, 136 bool is_one_byte,
125 Vector<const byte> literal_bytes) { 137 Vector<const byte> literal_bytes) {
126 Key key = { is_ascii, literal_bytes }; 138 Key key = { is_one_byte, literal_bytes };
127 HashMap::Entry* entry = string_table_.Lookup(&key, hash, true); 139 HashMap::Entry* entry = string_table_.Lookup(&key, hash, true);
128 int id = static_cast<int>(reinterpret_cast<intptr_t>(entry->value)); 140 int id = static_cast<int>(reinterpret_cast<intptr_t>(entry->value));
129 if (id == 0) { 141 if (id == 0) {
130 // Copy literal contents for later comparison. 142 // Copy literal contents for later comparison.
131 key.literal_bytes = 143 key.literal_bytes =
132 Vector<const byte>::cast(literal_chars_.AddBlock(literal_bytes)); 144 Vector<const byte>::cast(literal_chars_.AddBlock(literal_bytes));
133 // Put (symbol_id_ + 1) into entry and increment it. 145 // Put (symbol_id_ + 1) into entry and increment it.
134 id = ++symbol_id_; 146 id = ++symbol_id_;
135 entry->value = reinterpret_cast<void*>(id); 147 entry->value = reinterpret_cast<void*>(id);
136 Vector<Key> symbol = symbol_keys_.AddBlock(1, key); 148 Vector<Key> symbol = symbol_keys_.AddBlock(1, key);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 number &= mask; 197 number &= mask;
186 mask >>= 7; 198 mask >>= 7;
187 i -= 7; 199 i -= 7;
188 } 200 }
189 ASSERT(number < (1 << 7)); 201 ASSERT(number < (1 << 7));
190 symbol_store_.Add(static_cast<byte>(number)); 202 symbol_store_.Add(static_cast<byte>(number));
191 } 203 }
192 204
193 205
194 } } // namespace v8::internal. 206 } } // namespace v8::internal.
OLDNEW
« no previous file with comments | « src/preparse-data.h ('k') | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698