From cb514b72db5f3793bf57f4d4b2c9293bdcd0d555 Mon Sep 17 00:00:00 2001 From: "lrn@chromium.org" Date: Wed, 15 Sep 2010 10:54:35 +0000 Subject: [PATCH] Made predata smaller by storing symbol data in variable length base-128. Remove position from symbol data - they must come in the correct order anyway. Review URL: http://codereview.chromium.org/3384003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5458 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/parser.cc | 134 ++++++++++++++++++++++++++++++++++++++++------------------ src/parser.h | 52 +++++++++++------------ src/utils.h | 6 +++ 3 files changed, 124 insertions(+), 68 deletions(-) diff --git a/src/parser.cc b/src/parser.cc index d41eb81..856c474 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -996,21 +996,23 @@ class CompleteParserRecorder: public PartialParserRecorder { int id = static_cast(reinterpret_cast(entry->value)); if (id == 0) { // Put (symbol_id_ + 1) into entry and increment it. - symbol_id_++; - entry->value = reinterpret_cast(symbol_id_); + id = ++symbol_id_; + entry->value = reinterpret_cast(id); Vector > symbol = symbol_entries_.AddBlock(1, literal); entry->key = &symbol[0]; - } else { - // Log a reuse of an earlier seen symbol. - symbol_store_.Add(start); - symbol_store_.Add(id - 1); } + symbol_store_.Add(id - 1); } virtual Vector ExtractData() { int function_size = function_store_.size(); + // Add terminator to symbols, then pad to unsigned size. int symbol_size = symbol_store_.size(); - int total_size = ScriptDataImpl::kHeaderSize + function_size + symbol_size; + int padding = sizeof(unsigned) - (symbol_size % sizeof(unsigned)); + symbol_store_.AddBlock(padding, ScriptDataImpl::kNumberTerminator); + symbol_size += padding; + int total_size = ScriptDataImpl::kHeaderSize + function_size + + (symbol_size / sizeof(unsigned)); Vector data = Vector::New(total_size); preamble_[ScriptDataImpl::kFunctionsSizeOffset] = function_size; preamble_[ScriptDataImpl::kSymbolCountOffset] = symbol_id_; @@ -1020,8 +1022,9 @@ class CompleteParserRecorder: public PartialParserRecorder { function_store_.WriteTo(data.SubVector(ScriptDataImpl::kHeaderSize, symbol_start)); } - if (symbol_size > 0) { - symbol_store_.WriteTo(data.SubVector(symbol_start, total_size)); + if (!has_error()) { + symbol_store_.WriteTo( + Vector::cast(data.SubVector(symbol_start, total_size))); } return data; } @@ -1029,12 +1032,7 @@ class CompleteParserRecorder: public PartialParserRecorder { virtual int symbol_position() { return symbol_store_.size(); } virtual int symbol_ids() { return symbol_id_; } private: - Collector symbol_store_; - Collector > symbol_entries_; - HashMap symbol_table_; - int symbol_id_; - - static int vector_hash(Vector string) { + static int vector_hash(Vector string) { int hash = 0; for (int i = 0; i < string.length(); i++) { int c = string[i]; @@ -1052,6 +1050,14 @@ class CompleteParserRecorder: public PartialParserRecorder { if (string2->length() != length) return false; return memcmp(string1->start(), string2->start(), length) == 0; } + + // Write a non-negative number to the symbol store. + void WriteNumber(int number); + + Collector symbol_store_; + Collector > symbol_entries_; + HashMap symbol_table_; + int symbol_id_; }; @@ -1076,18 +1082,11 @@ FunctionEntry ScriptDataImpl::GetFunctionEntry(int start) { } -int ScriptDataImpl::GetSymbolIdentifier(int start) { - int next = symbol_index_ + 2; - if (next <= store_.length() - && static_cast(store_[symbol_index_]) == start) { - symbol_index_ = next; - return store_[next - 1]; - } - return symbol_id_++; +int ScriptDataImpl::GetSymbolIdentifier() { + return ReadNumber(&symbol_data_); } - bool ScriptDataImpl::SanityCheck() { // Check that the header data is valid and doesn't specify // point to positions outside the store. @@ -1118,7 +1117,7 @@ bool ScriptDataImpl::SanityCheck() { int symbol_count = static_cast(store_[ScriptDataImpl::kSymbolCountOffset]); if (symbol_count < 0) return false; - // Check that the total size has room both function entries. + // Check that the total size has room for header and function entries. int minimum_size = ScriptDataImpl::kHeaderSize + functions_size; if (store_.length() < minimum_size) return false; @@ -1158,6 +1157,22 @@ void PartialParserRecorder::WriteString(Vector str) { } +void CompleteParserRecorder::WriteNumber(int number) { + ASSERT(number >= 0); + + int mask = (1 << 28) - 1; + for (int i = 28; i > 0; i -= 7) { + if (number > mask) { + symbol_store_.Add(static_cast(number >> i) | 0x80u); + number &= mask; + } + mask >>= 7; + } + symbol_store_.Add(static_cast(number)); +} + + + const char* ScriptDataImpl::ReadString(unsigned* start, int* chars) { int length = start[0]; char* result = NewArray(length + 1); @@ -1206,7 +1221,8 @@ const char* ScriptDataImpl::BuildMessage() { Vector ScriptDataImpl::BuildArgs() { int arg_count = Read(kMessageArgCountPos); const char** array = NewArray(arg_count); - // Position after the string starting at position 3. + // Position after text found by skipping past length field and + // length field content words. int pos = kMessageTextPos + 1 + Read(kMessageTextPos); for (int i = 0; i < arg_count; i++) { int count = 0; @@ -1287,7 +1303,8 @@ class CompletePreParser : public PreParser { public: CompletePreParser(Handle