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

Side by Side Diff: src/objects.h

Issue 8677006: Recommit introducing short external strings. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixing webkit failures. 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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) \
235 V(SHORT_EXTERNAL_SYMBOL_TYPE) \
236 V(SHORT_EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE) \
237 V(SHORT_EXTERNAL_ASCII_SYMBOL_TYPE) \
235 V(STRING_TYPE) \ 238 V(STRING_TYPE) \
236 V(ASCII_STRING_TYPE) \ 239 V(ASCII_STRING_TYPE) \
237 V(CONS_STRING_TYPE) \ 240 V(CONS_STRING_TYPE) \
238 V(CONS_ASCII_STRING_TYPE) \ 241 V(CONS_ASCII_STRING_TYPE) \
239 V(SLICED_STRING_TYPE) \ 242 V(SLICED_STRING_TYPE) \
240 V(EXTERNAL_STRING_TYPE) \ 243 V(EXTERNAL_STRING_TYPE) \
241 V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \ 244 V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \
242 V(EXTERNAL_ASCII_STRING_TYPE) \ 245 V(EXTERNAL_ASCII_STRING_TYPE) \
246 V(SHORT_EXTERNAL_STRING_TYPE) \
247 V(SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \
248 V(SHORT_EXTERNAL_ASCII_STRING_TYPE) \
243 V(PRIVATE_EXTERNAL_ASCII_STRING_TYPE) \ 249 V(PRIVATE_EXTERNAL_ASCII_STRING_TYPE) \
244 \ 250 \
245 V(MAP_TYPE) \ 251 V(MAP_TYPE) \
246 V(CODE_TYPE) \ 252 V(CODE_TYPE) \
247 V(ODDBALL_TYPE) \ 253 V(ODDBALL_TYPE) \
248 V(JS_GLOBAL_PROPERTY_CELL_TYPE) \ 254 V(JS_GLOBAL_PROPERTY_CELL_TYPE) \
249 \ 255 \
250 V(HEAP_NUMBER_TYPE) \ 256 V(HEAP_NUMBER_TYPE) \
251 V(FOREIGN_TYPE) \ 257 V(FOREIGN_TYPE) \
252 V(BYTE_ARRAY_TYPE) \ 258 V(BYTE_ARRAY_TYPE) \
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 external_symbol, \ 339 external_symbol, \
334 ExternalSymbol) \ 340 ExternalSymbol) \
335 V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \ 341 V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \
336 ExternalTwoByteString::kSize, \ 342 ExternalTwoByteString::kSize, \
337 external_symbol_with_ascii_data, \ 343 external_symbol_with_ascii_data, \
338 ExternalSymbolWithAsciiData) \ 344 ExternalSymbolWithAsciiData) \
339 V(EXTERNAL_ASCII_SYMBOL_TYPE, \ 345 V(EXTERNAL_ASCII_SYMBOL_TYPE, \
340 ExternalAsciiString::kSize, \ 346 ExternalAsciiString::kSize, \
341 external_ascii_symbol, \ 347 external_ascii_symbol, \
342 ExternalAsciiSymbol) \ 348 ExternalAsciiSymbol) \
349 V(SHORT_EXTERNAL_SYMBOL_TYPE, \
350 ExternalTwoByteString::kShortSize, \
351 short_external_symbol, \
352 ShortExternalSymbol) \
353 V(SHORT_EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \
354 ExternalTwoByteString::kShortSize, \
355 short_external_symbol_with_ascii_data, \
356 ShortExternalSymbolWithAsciiData) \
357 V(SHORT_EXTERNAL_ASCII_SYMBOL_TYPE, \
358 ExternalAsciiString::kShortSize, \
359 short_external_ascii_symbol, \
360 ShortExternalAsciiSymbol) \
343 V(STRING_TYPE, \ 361 V(STRING_TYPE, \
344 kVariableSizeSentinel, \ 362 kVariableSizeSentinel, \
345 string, \ 363 string, \
346 String) \ 364 String) \
347 V(ASCII_STRING_TYPE, \ 365 V(ASCII_STRING_TYPE, \
348 kVariableSizeSentinel, \ 366 kVariableSizeSentinel, \
349 ascii_string, \ 367 ascii_string, \
350 AsciiString) \ 368 AsciiString) \
351 V(CONS_STRING_TYPE, \ 369 V(CONS_STRING_TYPE, \
352 ConsString::kSize, \ 370 ConsString::kSize, \
(...skipping 15 matching lines...) Expand all
368 ExternalTwoByteString::kSize, \ 386 ExternalTwoByteString::kSize, \
369 external_string, \ 387 external_string, \
370 ExternalString) \ 388 ExternalString) \
371 V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \ 389 V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \
372 ExternalTwoByteString::kSize, \ 390 ExternalTwoByteString::kSize, \
373 external_string_with_ascii_data, \ 391 external_string_with_ascii_data, \
374 ExternalStringWithAsciiData) \ 392 ExternalStringWithAsciiData) \
375 V(EXTERNAL_ASCII_STRING_TYPE, \ 393 V(EXTERNAL_ASCII_STRING_TYPE, \
376 ExternalAsciiString::kSize, \ 394 ExternalAsciiString::kSize, \
377 external_ascii_string, \ 395 external_ascii_string, \
378 ExternalAsciiString) 396 ExternalAsciiString) \
397 V(SHORT_EXTERNAL_STRING_TYPE, \
398 ExternalTwoByteString::kShortSize, \
399 short_external_string, \
400 ShortExternalString) \
401 V(SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \
402 ExternalTwoByteString::kShortSize, \
403 short_external_string_with_ascii_data, \
404 ShortExternalStringWithAsciiData) \
405 V(SHORT_EXTERNAL_ASCII_STRING_TYPE, \
406 ExternalAsciiString::kShortSize, \
407 short_external_ascii_string, \
408 ShortExternalAsciiString)
379 409
380 // A struct is a simple object a set of object-valued fields. Including an 410 // 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 411 // object type in this causes the compiler to generate most of the boilerplate
382 // code for the class including allocation and garbage collection routines, 412 // code for the class including allocation and garbage collection routines,
383 // casts and predicates. All you need to define is the class, methods and 413 // casts and predicates. All you need to define is the class, methods and
384 // object verification routines. Easy, no? 414 // object verification routines. Easy, no?
385 // 415 //
386 // Note that for subtle reasons related to the ordering or numerical values of 416 // 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 417 // type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST
388 // manually. 418 // 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 482 // 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). 483 // sure that the string is one of the two (an indirect string).
454 const uint32_t kSlicedNotConsMask = kSlicedStringTag & ~kConsStringTag; 484 const uint32_t kSlicedNotConsMask = kSlicedStringTag & ~kConsStringTag;
455 STATIC_ASSERT(IS_POWER_OF_TWO(kSlicedNotConsMask) && kSlicedNotConsMask != 0); 485 STATIC_ASSERT(IS_POWER_OF_TWO(kSlicedNotConsMask) && kSlicedNotConsMask != 0);
456 486
457 // If bit 7 is clear, then bit 3 indicates whether this two-byte 487 // If bit 7 is clear, then bit 3 indicates whether this two-byte
458 // string actually contains ascii data. 488 // string actually contains ascii data.
459 const uint32_t kAsciiDataHintMask = 0x08; 489 const uint32_t kAsciiDataHintMask = 0x08;
460 const uint32_t kAsciiDataHintTag = 0x08; 490 const uint32_t kAsciiDataHintTag = 0x08;
461 491
492 // If bit 7 is clear and string representation indicates an external string,
493 // then bit 4 indicates whether the data pointer is cached.
494 const uint32_t kShortExternalStringMask = 0x10;
495 const uint32_t kShortExternalStringTag = 0x10;
496
462 497
463 // A ConsString with an empty string as the right side is a candidate 498 // 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 499 // 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 500 // symbol. It's not common to have non-flat symbols, so we do not
466 // shortcut them thereby avoiding turning symbols into strings. See 501 // shortcut them thereby avoiding turning symbols into strings. See
467 // heap.cc and mark-compact.cc. 502 // heap.cc and mark-compact.cc.
468 const uint32_t kShortcutTypeMask = 503 const uint32_t kShortcutTypeMask =
469 kIsNotStringMask | 504 kIsNotStringMask |
470 kIsSymbolMask | 505 kIsSymbolMask |
471 kStringRepresentationMask; 506 kStringRepresentationMask;
472 const uint32_t kShortcutTypeTag = kConsStringTag; 507 const uint32_t kShortcutTypeTag = kConsStringTag;
473 508
474 509
475 enum InstanceType { 510 enum InstanceType {
476 // String types. 511 // String types.
477 SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kSeqStringTag, 512 SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kSeqStringTag,
478 ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kSeqStringTag, 513 ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kSeqStringTag,
479 CONS_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kConsStringTag, 514 CONS_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kConsStringTag,
480 CONS_ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kConsStringTag, 515 CONS_ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kConsStringTag,
516 SHORT_EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag |
517 kExternalStringTag | kShortExternalStringTag,
518 SHORT_EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE =
519 kTwoByteStringTag | kSymbolTag | kExternalStringTag |
520 kAsciiDataHintTag | kShortExternalStringTag,
521 SHORT_EXTERNAL_ASCII_SYMBOL_TYPE = kAsciiStringTag | kExternalStringTag |
522 kSymbolTag | kShortExternalStringTag,
481 EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kExternalStringTag, 523 EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kExternalStringTag,
482 EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE = 524 EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE =
483 kTwoByteStringTag | kSymbolTag | kExternalStringTag | kAsciiDataHintTag, 525 kTwoByteStringTag | kSymbolTag | kExternalStringTag | kAsciiDataHintTag,
484 EXTERNAL_ASCII_SYMBOL_TYPE = 526 EXTERNAL_ASCII_SYMBOL_TYPE =
485 kAsciiStringTag | kSymbolTag | kExternalStringTag, 527 kAsciiStringTag | kSymbolTag | kExternalStringTag,
486 STRING_TYPE = kTwoByteStringTag | kSeqStringTag, 528 STRING_TYPE = kTwoByteStringTag | kSeqStringTag,
487 ASCII_STRING_TYPE = kAsciiStringTag | kSeqStringTag, 529 ASCII_STRING_TYPE = kAsciiStringTag | kSeqStringTag,
488 CONS_STRING_TYPE = kTwoByteStringTag | kConsStringTag, 530 CONS_STRING_TYPE = kTwoByteStringTag | kConsStringTag,
489 CONS_ASCII_STRING_TYPE = kAsciiStringTag | kConsStringTag, 531 CONS_ASCII_STRING_TYPE = kAsciiStringTag | kConsStringTag,
490 SLICED_STRING_TYPE = kTwoByteStringTag | kSlicedStringTag, 532 SLICED_STRING_TYPE = kTwoByteStringTag | kSlicedStringTag,
491 SLICED_ASCII_STRING_TYPE = kAsciiStringTag | kSlicedStringTag, 533 SLICED_ASCII_STRING_TYPE = kAsciiStringTag | kSlicedStringTag,
534 SHORT_EXTERNAL_STRING_TYPE =
535 kTwoByteStringTag | kExternalStringTag | kShortExternalStringTag,
536 SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE =
537 kTwoByteStringTag | kExternalStringTag |
538 kAsciiDataHintTag | kShortExternalStringTag,
539 SHORT_EXTERNAL_ASCII_STRING_TYPE =
540 kAsciiStringTag | kExternalStringTag | kShortExternalStringTag,
492 EXTERNAL_STRING_TYPE = kTwoByteStringTag | kExternalStringTag, 541 EXTERNAL_STRING_TYPE = kTwoByteStringTag | kExternalStringTag,
493 EXTERNAL_STRING_WITH_ASCII_DATA_TYPE = 542 EXTERNAL_STRING_WITH_ASCII_DATA_TYPE =
494 kTwoByteStringTag | kExternalStringTag | kAsciiDataHintTag, 543 kTwoByteStringTag | kExternalStringTag | kAsciiDataHintTag,
495 // LAST_STRING_TYPE 544 // LAST_STRING_TYPE
496 EXTERNAL_ASCII_STRING_TYPE = kAsciiStringTag | kExternalStringTag, 545 EXTERNAL_ASCII_STRING_TYPE = kAsciiStringTag | kExternalStringTag,
497 PRIVATE_EXTERNAL_ASCII_STRING_TYPE = EXTERNAL_ASCII_STRING_TYPE, 546 PRIVATE_EXTERNAL_ASCII_STRING_TYPE = EXTERNAL_ASCII_STRING_TYPE,
498 547
499 // Objects allocated in their own spaces (never in new space). 548 // Objects allocated in their own spaces (never in new space).
500 MAP_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE 549 MAP_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE
501 CODE_TYPE, 550 CODE_TYPE,
(...skipping 6246 matching lines...) Expand 10 before | Expand all | Expand 10 after
6748 // 6797 //
6749 // The API expects that all ExternalStrings are created through the 6798 // The API expects that all ExternalStrings are created through the
6750 // API. Therefore, ExternalStrings should not be used internally. 6799 // API. Therefore, ExternalStrings should not be used internally.
6751 class ExternalString: public String { 6800 class ExternalString: public String {
6752 public: 6801 public:
6753 // Casting 6802 // Casting
6754 static inline ExternalString* cast(Object* obj); 6803 static inline ExternalString* cast(Object* obj);
6755 6804
6756 // Layout description. 6805 // Layout description.
6757 static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize); 6806 static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize);
6807 static const int kShortSize = kResourceOffset + kPointerSize;
6758 static const int kResourceDataOffset = kResourceOffset + kPointerSize; 6808 static const int kResourceDataOffset = kResourceOffset + kPointerSize;
6759 static const int kSize = kResourceDataOffset + kPointerSize; 6809 static const int kSize = kResourceDataOffset + kPointerSize;
6760 6810
6761 // Clear the cached pointer to the character array provided by the resource. 6811 // Return whether external string is short (data pointer is not cached).
6762 // This cache is updated the first time the character array is accessed. 6812 inline bool is_short();
6763 inline void clear_data_cache();
6764 6813
6765 STATIC_CHECK(kResourceOffset == Internals::kStringResourceOffset); 6814 STATIC_CHECK(kResourceOffset == Internals::kStringResourceOffset);
6766 6815
6767 private: 6816 private:
6768 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString); 6817 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString);
6769 }; 6818 };
6770 6819
6771 6820
6772 // The ExternalAsciiString class is an external string backed by an 6821 // The ExternalAsciiString class is an external string backed by an
6773 // ASCII string. 6822 // ASCII string.
6774 class ExternalAsciiString: public ExternalString { 6823 class ExternalAsciiString: public ExternalString {
6775 public: 6824 public:
6776 static const bool kHasAsciiEncoding = true; 6825 static const bool kHasAsciiEncoding = true;
6777 6826
6778 typedef v8::String::ExternalAsciiStringResource Resource; 6827 typedef v8::String::ExternalAsciiStringResource Resource;
6779 6828
6780 // The underlying resource. 6829 // The underlying resource.
6781 inline const Resource* resource(); 6830 inline const Resource* resource();
6782 inline void set_resource(const Resource* buffer); 6831 inline void set_resource(const Resource* buffer);
6783 6832
6833 // Update the pointer cache to the external character array.
6834 // The cached pointer is always valid, as the external character array does =
6835 // not move during lifetime. Deserialization is the only exception, after
6836 // which the pointer cache has to be refreshed.
6837 inline void update_data_cache();
6838
6784 inline const char* GetChars(); 6839 inline const char* GetChars();
6785 6840
6786 // Dispatched behavior. 6841 // Dispatched behavior.
6787 inline uint16_t ExternalAsciiStringGet(int index); 6842 inline uint16_t ExternalAsciiStringGet(int index);
6788 6843
6789 // Casting. 6844 // Casting.
6790 static inline ExternalAsciiString* cast(Object* obj); 6845 static inline ExternalAsciiString* cast(Object* obj);
6791 6846
6792 // Garbage collection support. 6847 // Garbage collection support.
6793 inline void ExternalAsciiStringIterateBody(ObjectVisitor* v); 6848 inline void ExternalAsciiStringIterateBody(ObjectVisitor* v);
(...skipping 19 matching lines...) Expand all
6813 class ExternalTwoByteString: public ExternalString { 6868 class ExternalTwoByteString: public ExternalString {
6814 public: 6869 public:
6815 static const bool kHasAsciiEncoding = false; 6870 static const bool kHasAsciiEncoding = false;
6816 6871
6817 typedef v8::String::ExternalStringResource Resource; 6872 typedef v8::String::ExternalStringResource Resource;
6818 6873
6819 // The underlying string resource. 6874 // The underlying string resource.
6820 inline const Resource* resource(); 6875 inline const Resource* resource();
6821 inline void set_resource(const Resource* buffer); 6876 inline void set_resource(const Resource* buffer);
6822 6877
6878 // Update the pointer cache to the external character array.
6879 // The cached pointer is always valid, as the external character array does =
6880 // not move during lifetime. Deserialization is the only exception, after
6881 // which the pointer cache has to be refreshed.
6882 inline void update_data_cache();
6883
6823 inline const uint16_t* GetChars(); 6884 inline const uint16_t* GetChars();
6824 6885
6825 // Dispatched behavior. 6886 // Dispatched behavior.
6826 inline uint16_t ExternalTwoByteStringGet(int index); 6887 inline uint16_t ExternalTwoByteStringGet(int index);
6827 6888
6828 // For regexp code. 6889 // For regexp code.
6829 inline const uint16_t* ExternalTwoByteStringGetData(unsigned start); 6890 inline const uint16_t* ExternalTwoByteStringGetData(unsigned start);
6830 6891
6831 // Casting. 6892 // Casting.
6832 static inline ExternalTwoByteString* cast(Object* obj); 6893 static inline ExternalTwoByteString* cast(Object* obj);
(...skipping 1051 matching lines...) Expand 10 before | Expand all | Expand 10 after
7884 } else { 7945 } else {
7885 value &= ~(1 << bit_position); 7946 value &= ~(1 << bit_position);
7886 } 7947 }
7887 return value; 7948 return value;
7888 } 7949 }
7889 }; 7950 };
7890 7951
7891 } } // namespace v8::internal 7952 } } // namespace v8::internal
7892 7953
7893 #endif // V8_OBJECTS_H_ 7954 #endif // V8_OBJECTS_H_
OLDNEW
« src/ia32/codegen-ia32.cc ('K') | « src/ia32/codegen-ia32.cc ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698