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

Unified Diff: src/parser-symbol-table.h

Issue 231073002: WIP: Parser: delay string internalization. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: internalizing better Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: src/parser-symbol-table.h
diff --git a/src/parser-symbol-table.h b/src/parser-symbol-table.h
new file mode 100644
index 0000000000000000000000000000000000000000..40cd032b6cc3dcf484d4ad88def6b22ba2ec3c30
--- /dev/null
+++ b/src/parser-symbol-table.h
@@ -0,0 +1,173 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef V8_PARSER_SYMBOL_TABLE_H_
+#define V8_PARSER_SYMBOL_TABLE_H_
+
+#include "api.h"
+#include "hashmap.h"
+#include "utils.h"
+
+namespace v8 {
+namespace internal {
+
+struct ParserSymbol {
+ public:
+ ParserSymbol(bool i, Vector<const byte> lb, int h)
+ : is_one_byte(i),
+ literal_bytes(lb),
+ hash(h) {}
+
+ ParserSymbol()
+ : is_one_byte(true),
+ hash(0) {}
+
+ V8_INLINE Handle<String> string() {
+ ASSERT(!string_.is_null());
+ return string_;
+ }
+
+ bool is_one_byte;
+ // Weak. Points to memory owned by ParserSymbolTable.
+ Vector<const byte> literal_bytes;
+ int hash;
+
+ private:
+ friend class ParserSymbolTable;
+ // This is null until the string is internalized.
+ Handle<String> string_;
+};
+
+
+class ParserSymbolTable {
rossberg 2014/05/08 12:52:08 How about naming this just SymbolTable? It's not q
marja 2014/06/03 08:48:20 Done (AstStringTable etc. as discussed offline).
+ public:
+ typedef ParserSymbol Symbol;
+
+ ParserSymbolTable();
+ Symbol* GetOneByteSymbol(Vector<const uint8_t> literal);
+ Symbol* GetTwoByteSymbol(Vector<const uint16_t> literal);
+ Symbol* GetSymbol(Handle<String> literal);
+
+ static bool SymbolMatches(Symbol* symbol, const char* data, int length);
+
+ void Internalize(Isolate* isolate);
+ void AlwaysInternalize(Isolate* isolate) {
rossberg 2014/05/08 12:52:08 How does this differ from Internalize (which also
marja 2014/06/03 08:48:20 -> Removed AlwaysInternalize
+ isolate_ = isolate;
+ Internalize(isolate);
+ }
+
+ static bool IsArrayIndexSlow(Symbol* symbol, uint32_t* ix = NULL);
+
+ // Some constant strings which are always needed.
+ ParserSymbol* anonymous_function_string() const {
+ return anonymous_function_string_;
+ }
+ ParserSymbol* arguments_string() const {
+ return arguments_string_;
+ }
+ ParserSymbol* dot_for_string() const {
+ return dot_for_string_;
+ }
+ ParserSymbol* dot_iterator_string() const {
+ return dot_iterator_string_;
+ }
+ ParserSymbol* dot_module_string() const {
+ return dot_module_string_;
+ }
+ ParserSymbol* dot_result_string() const {
+ return dot_result_string_;
+ }
+ ParserSymbol* empty_string() const { return empty_string_; }
+ ParserSymbol* eval_string() const { return eval_string_; }
+ ParserSymbol* initialize_const_global_string() const {
+ return initialize_const_global_string_;
+ }
+ ParserSymbol* initialize_var_global_string() const {
+ return initialize_var_global_string_;
+ }
+ ParserSymbol* make_reference_error_string() const {
+ return make_reference_error_string_;
+ }
+ ParserSymbol* make_syntax_error_string() const {
+ return make_syntax_error_string_;
+ }
+ ParserSymbol* make_type_error_string() const {
+ return make_type_error_string_;
+ }
+ ParserSymbol* module_string() const {
+ return module_string_;
+ }
+ ParserSymbol* native_string() const {
+ return native_string_;
+ }
+ ParserSymbol* prototype_string() const {
+ return prototype_string_;
+ }
+ ParserSymbol* this_string() const { return this_string_; }
+ ParserSymbol* use_strict_string() const {
+ return use_strict_string_;
+ }
+
+ private:
+ Symbol* GetSymbol(int hash, bool is_one_byte,
+ Vector<const byte> literal_bytes);
+
+ static void Internalize(Symbol* symbol, Isolate* isolate);
+
+ // All symbols are copied here, one after another.
+ Collector<byte> literal_chars_;
+ // List of all Symbols we have seen; keys of string_table_ are pointers into
+ // Symbols in symbol_keys_.
+ Collector<Symbol> symbol_keys_;
+ HashMap string_table_;
+ Isolate* isolate_;
+
+ // FIXME: these are easily created with a macro.
rossberg 2014/05/08 12:52:08 I was about to suggest that. :)
marja 2014/06/03 08:48:20 Done.
+ // FIXME: .generator
+ ParserSymbol* anonymous_function_string_;
+ ParserSymbol* arguments_string_;
+ ParserSymbol* dot_for_string_;
+ ParserSymbol* dot_iterator_string_;
+ ParserSymbol* dot_result_string_;
+ ParserSymbol* dot_module_string_;
+ ParserSymbol* empty_string_;
+ ParserSymbol* eval_string_;
+ ParserSymbol* initialize_const_global_string_;
+ ParserSymbol* initialize_var_global_string_;
+ ParserSymbol* make_reference_error_string_;
+ ParserSymbol* make_syntax_error_string_;
+ ParserSymbol* make_type_error_string_;
+ ParserSymbol* module_string_;
+ ParserSymbol* native_string_;
+ ParserSymbol* prototype_string_;
+ ParserSymbol* this_string_;
+ ParserSymbol* use_strict_string_;
+};
+
+} } // namespace v8::internal
+
+#endif // V8_PARSER_SYMBOL_TABLE_H_

Powered by Google App Engine
This is Rietveld 408576698