| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 26 matching lines...) Expand all Loading... |
| 37 // independent of the V8 heap and internalizing them later. During parsing, | 37 // independent of the V8 heap and internalizing them later. During parsing, |
| 38 // AstStrings and AstValues are created and stored outside the heap, in | 38 // AstStrings and AstValues are created and stored outside the heap, in |
| 39 // AstValueFactory. After parsing, the strings and values are internalized | 39 // AstValueFactory. After parsing, the strings and values are internalized |
| 40 // (moved into the V8 heap). | 40 // (moved into the V8 heap). |
| 41 namespace v8 { | 41 namespace v8 { |
| 42 namespace internal { | 42 namespace internal { |
| 43 | 43 |
| 44 class AstString : public ZoneObject { | 44 class AstString : public ZoneObject { |
| 45 public: | 45 public: |
| 46 explicit AstString(bool is_raw) | 46 explicit AstString(bool is_raw) |
| 47 : next_(nullptr), bit_field_(IsRawStringBits::encode(is_raw)) {} | 47 : bit_field_(IsRawStringBits::encode(is_raw)) {} |
| 48 | 48 |
| 49 int length() const; | 49 int length() const; |
| 50 bool IsEmpty() const { return length() == 0; } | 50 bool IsEmpty() const { return length() == 0; } |
| 51 | 51 |
| 52 // Puts the string into the V8 heap. | 52 // Puts the string into the V8 heap. |
| 53 void Internalize(Isolate* isolate); | 53 void Internalize(Isolate* isolate); |
| 54 | 54 |
| 55 // This function can be called after internalizing. | 55 // This function can be called after internalizing. |
| 56 V8_INLINE Handle<String> string() const { | 56 V8_INLINE Handle<String> string() const { |
| 57 DCHECK(!string_.is_null()); | 57 DCHECK(!string_.is_null()); |
| 58 return string_; | 58 return string_; |
| 59 } | 59 } |
| 60 | 60 |
| 61 AstString** next_location() { return &next_; } | |
| 62 AstString* next() const { return next_; } | |
| 63 | |
| 64 protected: | 61 protected: |
| 65 // Handle<String>::null() until internalized. | 62 // Handle<String>::null() until internalized. |
| 66 Handle<String> string_; | 63 Handle<String> string_; |
| 67 AstString* next_; | |
| 68 // Poor-man's virtual dispatch to AstRawString / AstConsString. Takes less | 64 // Poor-man's virtual dispatch to AstRawString / AstConsString. Takes less |
| 69 // memory. | 65 // memory. |
| 70 class IsRawStringBits : public BitField<bool, 0, 1> {}; | 66 class IsRawStringBits : public BitField<bool, 0, 1> {}; |
| 71 int bit_field_; | 67 int bit_field_; |
| 72 }; | 68 }; |
| 73 | 69 |
| 74 | 70 |
| 75 class AstRawString final : public AstString { | 71 class AstRawString final : public AstString { |
| 76 public: | 72 public: |
| 77 int length() const { | 73 int length() const { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 Vector<const byte> literal_bytes_; | 122 Vector<const byte> literal_bytes_; |
| 127 }; | 123 }; |
| 128 | 124 |
| 129 | 125 |
| 130 class AstConsString final : public AstString { | 126 class AstConsString final : public AstString { |
| 131 public: | 127 public: |
| 132 AstConsString(const AstString* left, const AstString* right) | 128 AstConsString(const AstString* left, const AstString* right) |
| 133 : AstString(false), | 129 : AstString(false), |
| 134 length_(left->length() + right->length()), | 130 length_(left->length() + right->length()), |
| 135 left_(left), | 131 left_(left), |
| 136 right_(right) {} | 132 right_(right), |
| 133 next_(nullptr) {} |
| 137 | 134 |
| 138 int length() const { return length_; } | 135 int length() const { return length_; } |
| 139 | 136 |
| 140 void Internalize(Isolate* isolate); | 137 void Internalize(Isolate* isolate); |
| 141 | 138 |
| 139 AstConsString* next() { return next_; } |
| 140 AstConsString** next_location() { return &next_; } |
| 141 |
| 142 private: | 142 private: |
| 143 const int length_; | 143 const int length_; |
| 144 const AstString* left_; | 144 const AstString* left_; |
| 145 const AstString* right_; | 145 const AstString* right_; |
| 146 AstConsString* next_; |
| 146 }; | 147 }; |
| 147 | 148 |
| 148 | 149 |
| 149 // AstValue is either a string, a number, a string array, a boolean, or a | 150 // AstValue is either a string, a number, a string array, a boolean, or a |
| 150 // special value (null, undefined, the hole). | 151 // special value (null, undefined, the hole). |
| 151 class AstValue : public ZoneObject { | 152 class AstValue : public ZoneObject { |
| 152 public: | 153 public: |
| 153 bool IsString() const { | 154 bool IsString() const { |
| 154 return type_ == STRING; | 155 return type_ == STRING; |
| 155 } | 156 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 } | 258 } |
| 258 | 259 |
| 259 Type type_; | 260 Type type_; |
| 260 | 261 |
| 261 // Uninternalized value. | 262 // Uninternalized value. |
| 262 union { | 263 union { |
| 263 const AstRawString* string_; | 264 const AstRawString* string_; |
| 264 double number_; | 265 double number_; |
| 265 int smi_; | 266 int smi_; |
| 266 bool bool_; | 267 bool bool_; |
| 267 const AstRawString* strings_; | |
| 268 const char* symbol_name_; | 268 const char* symbol_name_; |
| 269 }; | 269 }; |
| 270 | 270 |
| 271 // Handle<String>::null() until internalized. | 271 // Handle<String>::null() until internalized. |
| 272 Handle<Object> value_; | 272 Handle<Object> value_; |
| 273 AstValue* next_; | 273 AstValue* next_; |
| 274 }; | 274 }; |
| 275 | 275 |
| 276 | 276 |
| 277 // For generating constants. | 277 // For generating constants. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 F(false_value) \ | 318 F(false_value) \ |
| 319 F(null_value) \ | 319 F(null_value) \ |
| 320 F(undefined_value) \ | 320 F(undefined_value) \ |
| 321 F(the_hole_value) | 321 F(the_hole_value) |
| 322 | 322 |
| 323 class AstValueFactory { | 323 class AstValueFactory { |
| 324 public: | 324 public: |
| 325 AstValueFactory(Zone* zone, uint32_t hash_seed) | 325 AstValueFactory(Zone* zone, uint32_t hash_seed) |
| 326 : string_table_(AstRawStringCompare), | 326 : string_table_(AstRawStringCompare), |
| 327 values_(nullptr), | 327 values_(nullptr), |
| 328 strings_end_(&strings_), | 328 cons_strings_(nullptr), |
| 329 cons_strings_end_(&cons_strings_), |
| 329 zone_(zone), | 330 zone_(zone), |
| 330 hash_seed_(hash_seed) { | 331 hash_seed_(hash_seed) { |
| 331 ResetStrings(); | |
| 332 #define F(name, str) name##_string_ = NULL; | 332 #define F(name, str) name##_string_ = NULL; |
| 333 STRING_CONSTANTS(F) | 333 STRING_CONSTANTS(F) |
| 334 #undef F | 334 #undef F |
| 335 #define F(name) name##_ = NULL; | 335 #define F(name) name##_ = NULL; |
| 336 OTHER_CONSTANTS(F) | 336 OTHER_CONSTANTS(F) |
| 337 #undef F | 337 #undef F |
| 338 } | 338 } |
| 339 | 339 |
| 340 Zone* zone() const { return zone_; } | 340 Zone* zone() const { return zone_; } |
| 341 | 341 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 const AstValue* NewNull(); | 380 const AstValue* NewNull(); |
| 381 const AstValue* NewUndefined(); | 381 const AstValue* NewUndefined(); |
| 382 const AstValue* NewTheHole(); | 382 const AstValue* NewTheHole(); |
| 383 | 383 |
| 384 private: | 384 private: |
| 385 AstValue* AddValue(AstValue* value) { | 385 AstValue* AddValue(AstValue* value) { |
| 386 value->set_next(values_); | 386 value->set_next(values_); |
| 387 values_ = value; | 387 values_ = value; |
| 388 return value; | 388 return value; |
| 389 } | 389 } |
| 390 AstString* AddString(AstString* string) { | 390 AstConsString* AddConsString(AstConsString* string) { |
| 391 *strings_end_ = string; | 391 *cons_strings_end_ = string; |
| 392 strings_end_ = string->next_location(); | 392 cons_strings_end_ = string->next_location(); |
| 393 return string; | 393 return string; |
| 394 } | 394 } |
| 395 void ResetStrings() { | 395 void ResetConsStrings() { |
| 396 strings_ = nullptr; | 396 cons_strings_ = nullptr; |
| 397 strings_end_ = &strings_; | 397 cons_strings_end_ = &cons_strings_; |
| 398 } | 398 } |
| 399 V8_EXPORT_PRIVATE AstRawString* GetOneByteStringInternal( | 399 V8_EXPORT_PRIVATE AstRawString* GetOneByteStringInternal( |
| 400 Vector<const uint8_t> literal); | 400 Vector<const uint8_t> literal); |
| 401 AstRawString* GetTwoByteStringInternal(Vector<const uint16_t> literal); | 401 AstRawString* GetTwoByteStringInternal(Vector<const uint16_t> literal); |
| 402 AstRawString* GetString(uint32_t hash, bool is_one_byte, | 402 AstRawString* GetString(uint32_t hash, bool is_one_byte, |
| 403 Vector<const byte> literal_bytes); | 403 Vector<const byte> literal_bytes); |
| 404 | 404 |
| 405 static bool AstRawStringCompare(void* a, void* b); | 405 static bool AstRawStringCompare(void* a, void* b); |
| 406 | 406 |
| 407 // All strings are copied here, one after another (no NULLs inbetween). | 407 // All strings are copied here, one after another (no NULLs inbetween). |
| 408 base::CustomMatcherHashMap string_table_; | 408 base::CustomMatcherHashMap string_table_; |
| 409 // For keeping track of all AstValues and AstRawStrings we've created (so that | 409 // For keeping track of all AstValues and AstRawStrings we've created (so that |
| 410 // they can be internalized later). | 410 // they can be internalized later). |
| 411 AstValue* values_; | 411 AstValue* values_; |
| 412 // We need to keep track of strings_ in order, since cons strings require | 412 // We need to keep track of cons_strings_ in order since they require their |
| 413 // their members to be internalized first. | 413 // members to be internalized first. |
| 414 AstString* strings_; | 414 AstConsString* cons_strings_; |
| 415 AstString** strings_end_; | 415 AstConsString** cons_strings_end_; |
| 416 Zone* zone_; | 416 Zone* zone_; |
| 417 | 417 |
| 418 uint32_t hash_seed_; | 418 uint32_t hash_seed_; |
| 419 | 419 |
| 420 #define F(name, str) const AstRawString* name##_string_; | 420 #define F(name, str) const AstRawString* name##_string_; |
| 421 STRING_CONSTANTS(F) | 421 STRING_CONSTANTS(F) |
| 422 #undef F | 422 #undef F |
| 423 | 423 |
| 424 #define F(name) AstValue* name##_; | 424 #define F(name) AstValue* name##_; |
| 425 OTHER_CONSTANTS(F) | 425 OTHER_CONSTANTS(F) |
| 426 #undef F | 426 #undef F |
| 427 }; | 427 }; |
| 428 } // namespace internal | 428 } // namespace internal |
| 429 } // namespace v8 | 429 } // namespace v8 |
| 430 | 430 |
| 431 #undef STRING_CONSTANTS | 431 #undef STRING_CONSTANTS |
| 432 #undef OTHER_CONSTANTS | 432 #undef OTHER_CONSTANTS |
| 433 | 433 |
| 434 #endif // V8_AST_AST_VALUE_FACTORY_H_ | 434 #endif // V8_AST_AST_VALUE_FACTORY_H_ |
| OLD | NEW |