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

Side by Side Diff: src/objects.h

Issue 8635011: Introduce short external strings without pointer cache. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years 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
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 // NOTE: Everything following JS_VALUE_TYPE is considered a 224 // NOTE: Everything following JS_VALUE_TYPE is considered a
225 // JSObject for GC purposes. The first four entries here have typeof 225 // JSObject for GC purposes. The first four entries here have typeof
226 // 'object', whereas JS_FUNCTION_TYPE has typeof 'function'. 226 // 'object', whereas JS_FUNCTION_TYPE has typeof 'function'.
227 #define INSTANCE_TYPE_LIST_ALL(V) \ 227 #define INSTANCE_TYPE_LIST_ALL(V) \
228 V(SYMBOL_TYPE) \ 228 V(SYMBOL_TYPE) \
229 V(ASCII_SYMBOL_TYPE) \ 229 V(ASCII_SYMBOL_TYPE) \
230 V(CONS_SYMBOL_TYPE) \ 230 V(CONS_SYMBOL_TYPE) \
231 V(CONS_ASCII_SYMBOL_TYPE) \ 231 V(CONS_ASCII_SYMBOL_TYPE) \
232 V(EXTERNAL_SYMBOL_TYPE) \ 232 V(EXTERNAL_SYMBOL_TYPE) \
233 V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE) \ 233 V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE) \
234 V(EXTERNAL_ASCII_SYMBOL_TYPE) \ 234 V(EXTERNAL_ASCII_SYMBOL_TYPE) \
Lasse Reichstein 2011/11/23 08:43:20 No SHORT_EXTERNAL_SYMBOL_TYPE etc.?
Yang 2011/11/23 09:58:48 Must have forgotten that. Included now.
235 V(STRING_TYPE) \ 235 V(STRING_TYPE) \
236 V(ASCII_STRING_TYPE) \ 236 V(ASCII_STRING_TYPE) \
237 V(CONS_STRING_TYPE) \ 237 V(CONS_STRING_TYPE) \
238 V(CONS_ASCII_STRING_TYPE) \ 238 V(CONS_ASCII_STRING_TYPE) \
239 V(SLICED_STRING_TYPE) \ 239 V(SLICED_STRING_TYPE) \
240 V(EXTERNAL_STRING_TYPE) \ 240 V(EXTERNAL_STRING_TYPE) \
241 V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \ 241 V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \
242 V(EXTERNAL_ASCII_STRING_TYPE) \ 242 V(EXTERNAL_ASCII_STRING_TYPE) \
243 V(SHORT_EXTERNAL_STRING_TYPE) \
244 V(SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \
245 V(SHORT_EXTERNAL_ASCII_STRING_TYPE) \
243 V(PRIVATE_EXTERNAL_ASCII_STRING_TYPE) \ 246 V(PRIVATE_EXTERNAL_ASCII_STRING_TYPE) \
244 \ 247 \
245 V(MAP_TYPE) \ 248 V(MAP_TYPE) \
246 V(CODE_TYPE) \ 249 V(CODE_TYPE) \
247 V(ODDBALL_TYPE) \ 250 V(ODDBALL_TYPE) \
248 V(JS_GLOBAL_PROPERTY_CELL_TYPE) \ 251 V(JS_GLOBAL_PROPERTY_CELL_TYPE) \
249 \ 252 \
250 V(HEAP_NUMBER_TYPE) \ 253 V(HEAP_NUMBER_TYPE) \
251 V(FOREIGN_TYPE) \ 254 V(FOREIGN_TYPE) \
252 V(BYTE_ARRAY_TYPE) \ 255 V(BYTE_ARRAY_TYPE) \
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 external_symbol, \ 336 external_symbol, \
334 ExternalSymbol) \ 337 ExternalSymbol) \
335 V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \ 338 V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \
336 ExternalTwoByteString::kSize, \ 339 ExternalTwoByteString::kSize, \
337 external_symbol_with_ascii_data, \ 340 external_symbol_with_ascii_data, \
338 ExternalSymbolWithAsciiData) \ 341 ExternalSymbolWithAsciiData) \
339 V(EXTERNAL_ASCII_SYMBOL_TYPE, \ 342 V(EXTERNAL_ASCII_SYMBOL_TYPE, \
340 ExternalAsciiString::kSize, \ 343 ExternalAsciiString::kSize, \
341 external_ascii_symbol, \ 344 external_ascii_symbol, \
342 ExternalAsciiSymbol) \ 345 ExternalAsciiSymbol) \
346 V(SHORT_EXTERNAL_SYMBOL_TYPE, \
347 ExternalTwoByteString::kShortSize, \
348 short_external_symbol, \
349 ShortExternalSymbol) \
350 V(SHORT_EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \
351 ExternalTwoByteString::kShortSize, \
352 short_external_symbol_with_ascii_data, \
353 ShortExternalSymbolWithAsciiData) \
354 V(SHORT_EXTERNAL_ASCII_SYMBOL_TYPE, \
355 ExternalAsciiString::kShortSize, \
356 short_external_ascii_symbol, \
357 ShortExternalAsciiSymbol) \
343 V(STRING_TYPE, \ 358 V(STRING_TYPE, \
344 kVariableSizeSentinel, \ 359 kVariableSizeSentinel, \
345 string, \ 360 string, \
346 String) \ 361 String) \
347 V(ASCII_STRING_TYPE, \ 362 V(ASCII_STRING_TYPE, \
348 kVariableSizeSentinel, \ 363 kVariableSizeSentinel, \
349 ascii_string, \ 364 ascii_string, \
350 AsciiString) \ 365 AsciiString) \
351 V(CONS_STRING_TYPE, \ 366 V(CONS_STRING_TYPE, \
352 ConsString::kSize, \ 367 ConsString::kSize, \
(...skipping 15 matching lines...) Expand all
368 ExternalTwoByteString::kSize, \ 383 ExternalTwoByteString::kSize, \
369 external_string, \ 384 external_string, \
370 ExternalString) \ 385 ExternalString) \
371 V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \ 386 V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \
372 ExternalTwoByteString::kSize, \ 387 ExternalTwoByteString::kSize, \
373 external_string_with_ascii_data, \ 388 external_string_with_ascii_data, \
374 ExternalStringWithAsciiData) \ 389 ExternalStringWithAsciiData) \
375 V(EXTERNAL_ASCII_STRING_TYPE, \ 390 V(EXTERNAL_ASCII_STRING_TYPE, \
376 ExternalAsciiString::kSize, \ 391 ExternalAsciiString::kSize, \
377 external_ascii_string, \ 392 external_ascii_string, \
378 ExternalAsciiString) 393 ExternalAsciiString) \
394 V(SHORT_EXTERNAL_STRING_TYPE, \
395 ExternalTwoByteString::kShortSize, \
396 short_external_string, \
397 ShortExternalString) \
398 V(SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \
399 ExternalTwoByteString::kShortSize, \
400 short_external_string_with_ascii_data, \
401 ShortExternalStringWithAsciiData) \
402 V(SHORT_EXTERNAL_ASCII_STRING_TYPE, \
403 ExternalAsciiString::kShortSize, \
404 short_external_ascii_string, \
405 ShortExternalAsciiString)
379 406
380 // A struct is a simple object a set of object-valued fields. Including an 407 // A struct is a simple object a set of object-valued fields. Including an
381 // object type in this causes the compiler to generate most of the boilerplate 408 // object type in this causes the compiler to generate most of the boilerplate
382 // code for the class including allocation and garbage collection routines, 409 // code for the class including allocation and garbage collection routines,
383 // casts and predicates. All you need to define is the class, methods and 410 // casts and predicates. All you need to define is the class, methods and
384 // object verification routines. Easy, no? 411 // object verification routines. Easy, no?
385 // 412 //
386 // Note that for subtle reasons related to the ordering or numerical values of 413 // Note that for subtle reasons related to the ordering or numerical values of
387 // type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST 414 // type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST
388 // manually. 415 // manually.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 // Use this mask to distinguish between cons and slice only after making 479 // Use this mask to distinguish between cons and slice only after making
453 // sure that the string is one of the two (an indirect string). 480 // sure that the string is one of the two (an indirect string).
454 const uint32_t kSlicedNotConsMask = kSlicedStringTag & ~kConsStringTag; 481 const uint32_t kSlicedNotConsMask = kSlicedStringTag & ~kConsStringTag;
455 STATIC_ASSERT(IS_POWER_OF_TWO(kSlicedNotConsMask) && kSlicedNotConsMask != 0); 482 STATIC_ASSERT(IS_POWER_OF_TWO(kSlicedNotConsMask) && kSlicedNotConsMask != 0);
456 483
457 // If bit 7 is clear, then bit 3 indicates whether this two-byte 484 // If bit 7 is clear, then bit 3 indicates whether this two-byte
458 // string actually contains ascii data. 485 // string actually contains ascii data.
459 const uint32_t kAsciiDataHintMask = 0x08; 486 const uint32_t kAsciiDataHintMask = 0x08;
460 const uint32_t kAsciiDataHintTag = 0x08; 487 const uint32_t kAsciiDataHintTag = 0x08;
461 488
489 // If bit 7 is clear and string representation indicates an external string,
490 // then bit 4 indicates whether the data pointer is cached.
491 const uint32_t kShortExternalStringMask = 0x10;
492 const uint32_t kShortExternalStringTag = 0x10;
493
462 494
463 // A ConsString with an empty string as the right side is a candidate 495 // A ConsString with an empty string as the right side is a candidate
464 // for being shortcut by the garbage collector unless it is a 496 // for being shortcut by the garbage collector unless it is a
465 // symbol. It's not common to have non-flat symbols, so we do not 497 // symbol. It's not common to have non-flat symbols, so we do not
466 // shortcut them thereby avoiding turning symbols into strings. See 498 // shortcut them thereby avoiding turning symbols into strings. See
467 // heap.cc and mark-compact.cc. 499 // heap.cc and mark-compact.cc.
468 const uint32_t kShortcutTypeMask = 500 const uint32_t kShortcutTypeMask =
469 kIsNotStringMask | 501 kIsNotStringMask |
470 kIsSymbolMask | 502 kIsSymbolMask |
471 kStringRepresentationMask; 503 kStringRepresentationMask;
472 const uint32_t kShortcutTypeTag = kConsStringTag; 504 const uint32_t kShortcutTypeTag = kConsStringTag;
473 505
474 506
475 enum InstanceType { 507 enum InstanceType {
476 // String types. 508 // String types.
477 SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kSeqStringTag, 509 SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kSeqStringTag,
478 ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kSeqStringTag, 510 ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kSeqStringTag,
479 CONS_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kConsStringTag, 511 CONS_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kConsStringTag,
480 CONS_ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kConsStringTag, 512 CONS_ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kConsStringTag,
513 SHORT_EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag |
514 kExternalStringTag | kShortExternalStringTag,
515 SHORT_EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE =
516 kTwoByteStringTag | kSymbolTag | kExternalStringTag |
517 kAsciiDataHintTag | kShortExternalStringTag,
518 SHORT_EXTERNAL_ASCII_SYMBOL_TYPE = kAsciiStringTag | kExternalStringTag |
519 kSymbolTag | kShortExternalStringTag,
481 EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kExternalStringTag, 520 EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kExternalStringTag,
482 EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE = 521 EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE =
483 kTwoByteStringTag | kSymbolTag | kExternalStringTag | kAsciiDataHintTag, 522 kTwoByteStringTag | kSymbolTag | kExternalStringTag | kAsciiDataHintTag,
484 EXTERNAL_ASCII_SYMBOL_TYPE = 523 EXTERNAL_ASCII_SYMBOL_TYPE =
485 kAsciiStringTag | kSymbolTag | kExternalStringTag, 524 kAsciiStringTag | kSymbolTag | kExternalStringTag,
486 STRING_TYPE = kTwoByteStringTag | kSeqStringTag, 525 STRING_TYPE = kTwoByteStringTag | kSeqStringTag,
487 ASCII_STRING_TYPE = kAsciiStringTag | kSeqStringTag, 526 ASCII_STRING_TYPE = kAsciiStringTag | kSeqStringTag,
488 CONS_STRING_TYPE = kTwoByteStringTag | kConsStringTag, 527 CONS_STRING_TYPE = kTwoByteStringTag | kConsStringTag,
489 CONS_ASCII_STRING_TYPE = kAsciiStringTag | kConsStringTag, 528 CONS_ASCII_STRING_TYPE = kAsciiStringTag | kConsStringTag,
490 SLICED_STRING_TYPE = kTwoByteStringTag | kSlicedStringTag, 529 SLICED_STRING_TYPE = kTwoByteStringTag | kSlicedStringTag,
491 SLICED_ASCII_STRING_TYPE = kAsciiStringTag | kSlicedStringTag, 530 SLICED_ASCII_STRING_TYPE = kAsciiStringTag | kSlicedStringTag,
531 SHORT_EXTERNAL_STRING_TYPE =
532 kTwoByteStringTag | kExternalStringTag | kShortExternalStringTag,
533 SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE =
534 kTwoByteStringTag | kExternalStringTag |
535 kAsciiDataHintTag | kShortExternalStringTag,
536 SHORT_EXTERNAL_ASCII_STRING_TYPE =
537 kAsciiStringTag | kExternalStringTag | kShortExternalStringTag,
492 EXTERNAL_STRING_TYPE = kTwoByteStringTag | kExternalStringTag, 538 EXTERNAL_STRING_TYPE = kTwoByteStringTag | kExternalStringTag,
493 EXTERNAL_STRING_WITH_ASCII_DATA_TYPE = 539 EXTERNAL_STRING_WITH_ASCII_DATA_TYPE =
494 kTwoByteStringTag | kExternalStringTag | kAsciiDataHintTag, 540 kTwoByteStringTag | kExternalStringTag | kAsciiDataHintTag,
495 // LAST_STRING_TYPE 541 // LAST_STRING_TYPE
496 EXTERNAL_ASCII_STRING_TYPE = kAsciiStringTag | kExternalStringTag, 542 EXTERNAL_ASCII_STRING_TYPE = kAsciiStringTag | kExternalStringTag,
497 PRIVATE_EXTERNAL_ASCII_STRING_TYPE = EXTERNAL_ASCII_STRING_TYPE, 543 PRIVATE_EXTERNAL_ASCII_STRING_TYPE = EXTERNAL_ASCII_STRING_TYPE,
498 544
499 // Objects allocated in their own spaces (never in new space). 545 // Objects allocated in their own spaces (never in new space).
500 MAP_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE 546 MAP_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE
501 CODE_TYPE, 547 CODE_TYPE,
(...skipping 6246 matching lines...) Expand 10 before | Expand all | Expand 10 after
6748 // 6794 //
6749 // The API expects that all ExternalStrings are created through the 6795 // The API expects that all ExternalStrings are created through the
6750 // API. Therefore, ExternalStrings should not be used internally. 6796 // API. Therefore, ExternalStrings should not be used internally.
6751 class ExternalString: public String { 6797 class ExternalString: public String {
6752 public: 6798 public:
6753 // Casting 6799 // Casting
6754 static inline ExternalString* cast(Object* obj); 6800 static inline ExternalString* cast(Object* obj);
6755 6801
6756 // Layout description. 6802 // Layout description.
6757 static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize); 6803 static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize);
6804 static const int kShortSize = kResourceOffset + kPointerSize;
6758 static const int kResourceDataOffset = kResourceOffset + kPointerSize; 6805 static const int kResourceDataOffset = kResourceOffset + kPointerSize;
6759 static const int kSize = kResourceDataOffset + kPointerSize; 6806 static const int kSize = kResourceDataOffset + kPointerSize;
6760 6807
6761 // Clear the cached pointer to the character array provided by the resource. 6808 // Return whether external string is short (data pointer is not cached).
6762 // This cache is updated the first time the character array is accessed. 6809 inline bool is_short();
6763 inline void clear_data_cache();
6764 6810
6765 STATIC_CHECK(kResourceOffset == Internals::kStringResourceOffset); 6811 STATIC_CHECK(kResourceOffset == Internals::kStringResourceOffset);
6766 6812
6767 private: 6813 private:
6768 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString); 6814 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString);
6769 }; 6815 };
6770 6816
6771 6817
6772 // The ExternalAsciiString class is an external string backed by an 6818 // The ExternalAsciiString class is an external string backed by an
6773 // ASCII string. 6819 // ASCII string.
6774 class ExternalAsciiString: public ExternalString { 6820 class ExternalAsciiString: public ExternalString {
6775 public: 6821 public:
6776 static const bool kHasAsciiEncoding = true; 6822 static const bool kHasAsciiEncoding = true;
6777 6823
6778 typedef v8::String::ExternalAsciiStringResource Resource; 6824 typedef v8::String::ExternalAsciiStringResource Resource;
6779 6825
6780 // The underlying resource. 6826 // The underlying resource.
6781 inline const Resource* resource(); 6827 inline const Resource* resource();
6782 inline void set_resource(const Resource* buffer); 6828 inline void set_resource(const Resource* buffer);
6829 inline void update_data_cache();
Lasse Reichstein 2011/11/23 08:43:20 Put a comment saying that this function is only us
Yang 2011/11/23 09:58:48 Done.
6783 6830
6784 inline const char* GetChars(); 6831 inline const char* GetChars();
6785 6832
6786 // Dispatched behavior. 6833 // Dispatched behavior.
6787 inline uint16_t ExternalAsciiStringGet(int index); 6834 inline uint16_t ExternalAsciiStringGet(int index);
6788 6835
6789 // Casting. 6836 // Casting.
6790 static inline ExternalAsciiString* cast(Object* obj); 6837 static inline ExternalAsciiString* cast(Object* obj);
6791 6838
6792 // Garbage collection support. 6839 // Garbage collection support.
(...skipping 19 matching lines...) Expand all
6812 // encoded string. 6859 // encoded string.
6813 class ExternalTwoByteString: public ExternalString { 6860 class ExternalTwoByteString: public ExternalString {
6814 public: 6861 public:
6815 static const bool kHasAsciiEncoding = false; 6862 static const bool kHasAsciiEncoding = false;
6816 6863
6817 typedef v8::String::ExternalStringResource Resource; 6864 typedef v8::String::ExternalStringResource Resource;
6818 6865
6819 // The underlying string resource. 6866 // The underlying string resource.
6820 inline const Resource* resource(); 6867 inline const Resource* resource();
6821 inline void set_resource(const Resource* buffer); 6868 inline void set_resource(const Resource* buffer);
6869 inline void update_data_cache();
6822 6870
6823 inline const uint16_t* GetChars(); 6871 inline const uint16_t* GetChars();
6824 6872
6825 // Dispatched behavior. 6873 // Dispatched behavior.
6826 inline uint16_t ExternalTwoByteStringGet(int index); 6874 inline uint16_t ExternalTwoByteStringGet(int index);
6827 6875
6828 // For regexp code. 6876 // For regexp code.
6829 inline const uint16_t* ExternalTwoByteStringGetData(unsigned start); 6877 inline const uint16_t* ExternalTwoByteStringGetData(unsigned start);
6830 6878
6831 // Casting. 6879 // Casting.
(...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after
7884 } else { 7932 } else {
7885 value &= ~(1 << bit_position); 7933 value &= ~(1 << bit_position);
7886 } 7934 }
7887 return value; 7935 return value;
7888 } 7936 }
7889 }; 7937 };
7890 7938
7891 } } // namespace v8::internal 7939 } } // namespace v8::internal
7892 7940
7893 #endif // V8_OBJECTS_H_ 7941 #endif // V8_OBJECTS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698