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

Side by Side Diff: src/objects.h

Issue 7477045: Tentative implementation of string slices (hidden under the flag --string-slices). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 5 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 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // - CompilationCacheTable 79 // - CompilationCacheTable
80 // - CodeCacheHashTable 80 // - CodeCacheHashTable
81 // - MapCache 81 // - MapCache
82 // - Context 82 // - Context
83 // - JSFunctionResultCache 83 // - JSFunctionResultCache
84 // - SerializedScopeInfo 84 // - SerializedScopeInfo
85 // - String 85 // - String
86 // - SeqString 86 // - SeqString
87 // - SeqAsciiString 87 // - SeqAsciiString
88 // - SeqTwoByteString 88 // - SeqTwoByteString
89 // - SlicedString
89 // - ConsString 90 // - ConsString
90 // - ExternalString 91 // - ExternalString
91 // - ExternalAsciiString 92 // - ExternalAsciiString
92 // - ExternalTwoByteString 93 // - ExternalTwoByteString
93 // - HeapNumber 94 // - HeapNumber
94 // - Code 95 // - Code
95 // - Map 96 // - Map
96 // - Oddball 97 // - Oddball
97 // - Foreign 98 // - Foreign
98 // - SharedFunctionInfo 99 // - SharedFunctionInfo
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 V(ASCII_SYMBOL_TYPE) \ 274 V(ASCII_SYMBOL_TYPE) \
274 V(CONS_SYMBOL_TYPE) \ 275 V(CONS_SYMBOL_TYPE) \
275 V(CONS_ASCII_SYMBOL_TYPE) \ 276 V(CONS_ASCII_SYMBOL_TYPE) \
276 V(EXTERNAL_SYMBOL_TYPE) \ 277 V(EXTERNAL_SYMBOL_TYPE) \
277 V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE) \ 278 V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE) \
278 V(EXTERNAL_ASCII_SYMBOL_TYPE) \ 279 V(EXTERNAL_ASCII_SYMBOL_TYPE) \
279 V(STRING_TYPE) \ 280 V(STRING_TYPE) \
280 V(ASCII_STRING_TYPE) \ 281 V(ASCII_STRING_TYPE) \
281 V(CONS_STRING_TYPE) \ 282 V(CONS_STRING_TYPE) \
282 V(CONS_ASCII_STRING_TYPE) \ 283 V(CONS_ASCII_STRING_TYPE) \
284 V(SLICED_STRING_TYPE) \
283 V(EXTERNAL_STRING_TYPE) \ 285 V(EXTERNAL_STRING_TYPE) \
284 V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \ 286 V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \
285 V(EXTERNAL_ASCII_STRING_TYPE) \ 287 V(EXTERNAL_ASCII_STRING_TYPE) \
286 V(PRIVATE_EXTERNAL_ASCII_STRING_TYPE) \ 288 V(PRIVATE_EXTERNAL_ASCII_STRING_TYPE) \
287 \ 289 \
288 V(MAP_TYPE) \ 290 V(MAP_TYPE) \
289 V(CODE_TYPE) \ 291 V(CODE_TYPE) \
290 V(ODDBALL_TYPE) \ 292 V(ODDBALL_TYPE) \
291 V(JS_GLOBAL_PROPERTY_CELL_TYPE) \ 293 V(JS_GLOBAL_PROPERTY_CELL_TYPE) \
292 \ 294 \
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 ascii_symbol, \ 363 ascii_symbol, \
362 AsciiSymbol) \ 364 AsciiSymbol) \
363 V(CONS_SYMBOL_TYPE, \ 365 V(CONS_SYMBOL_TYPE, \
364 ConsString::kSize, \ 366 ConsString::kSize, \
365 cons_symbol, \ 367 cons_symbol, \
366 ConsSymbol) \ 368 ConsSymbol) \
367 V(CONS_ASCII_SYMBOL_TYPE, \ 369 V(CONS_ASCII_SYMBOL_TYPE, \
368 ConsString::kSize, \ 370 ConsString::kSize, \
369 cons_ascii_symbol, \ 371 cons_ascii_symbol, \
370 ConsAsciiSymbol) \ 372 ConsAsciiSymbol) \
373 V(SLICED_SYMBOL_TYPE, \
374 SlicedString::kSize, \
375 sliced_symbol, \
376 SlicedSymbol) \
377 V(SLICED_ASCII_SYMBOL_TYPE, \
378 SlicedString::kSize, \
379 sliced_ascii_symbol, \
380 SlicedAsciiSymbol) \
371 V(EXTERNAL_SYMBOL_TYPE, \ 381 V(EXTERNAL_SYMBOL_TYPE, \
372 ExternalTwoByteString::kSize, \ 382 ExternalTwoByteString::kSize, \
373 external_symbol, \ 383 external_symbol, \
374 ExternalSymbol) \ 384 ExternalSymbol) \
375 V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \ 385 V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \
376 ExternalTwoByteString::kSize, \ 386 ExternalTwoByteString::kSize, \
377 external_symbol_with_ascii_data, \ 387 external_symbol_with_ascii_data, \
378 ExternalSymbolWithAsciiData) \ 388 ExternalSymbolWithAsciiData) \
379 V(EXTERNAL_ASCII_SYMBOL_TYPE, \ 389 V(EXTERNAL_ASCII_SYMBOL_TYPE, \
380 ExternalAsciiString::kSize, \ 390 ExternalAsciiString::kSize, \
381 external_ascii_symbol, \ 391 external_ascii_symbol, \
382 ExternalAsciiSymbol) \ 392 ExternalAsciiSymbol) \
383 V(STRING_TYPE, \ 393 V(STRING_TYPE, \
384 kVariableSizeSentinel, \ 394 kVariableSizeSentinel, \
385 string, \ 395 string, \
386 String) \ 396 String) \
387 V(ASCII_STRING_TYPE, \ 397 V(ASCII_STRING_TYPE, \
388 kVariableSizeSentinel, \ 398 kVariableSizeSentinel, \
389 ascii_string, \ 399 ascii_string, \
390 AsciiString) \ 400 AsciiString) \
391 V(CONS_STRING_TYPE, \ 401 V(CONS_STRING_TYPE, \
392 ConsString::kSize, \ 402 ConsString::kSize, \
393 cons_string, \ 403 cons_string, \
394 ConsString) \ 404 ConsString) \
395 V(CONS_ASCII_STRING_TYPE, \ 405 V(CONS_ASCII_STRING_TYPE, \
396 ConsString::kSize, \ 406 ConsString::kSize, \
397 cons_ascii_string, \ 407 cons_ascii_string, \
398 ConsAsciiString) \ 408 ConsAsciiString) \
409 V(SLICED_STRING_TYPE, \
410 SlicedString::kSize, \
411 sliced_string, \
412 SlicedString) \
413 V(SLICED_ASCII_STRING_TYPE, \
414 SlicedString::kSize, \
415 sliced_ascii_string, \
416 SlicedAsciiString) \
399 V(EXTERNAL_STRING_TYPE, \ 417 V(EXTERNAL_STRING_TYPE, \
400 ExternalTwoByteString::kSize, \ 418 ExternalTwoByteString::kSize, \
401 external_string, \ 419 external_string, \
402 ExternalString) \ 420 ExternalString) \
403 V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \ 421 V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \
404 ExternalTwoByteString::kSize, \ 422 ExternalTwoByteString::kSize, \
405 external_string_with_ascii_data, \ 423 external_string_with_ascii_data, \
406 ExternalStringWithAsciiData) \ 424 ExternalStringWithAsciiData) \
407 V(EXTERNAL_ASCII_STRING_TYPE, \ 425 V(EXTERNAL_ASCII_STRING_TYPE, \
408 ExternalAsciiString::kSize, \ 426 ExternalAsciiString::kSize, \
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 const uint32_t kStringEncodingMask = 0x4; 480 const uint32_t kStringEncodingMask = 0x4;
463 const uint32_t kTwoByteStringTag = 0x0; 481 const uint32_t kTwoByteStringTag = 0x0;
464 const uint32_t kAsciiStringTag = 0x4; 482 const uint32_t kAsciiStringTag = 0x4;
465 483
466 // If bit 7 is clear, the low-order 2 bits indicate the representation 484 // If bit 7 is clear, the low-order 2 bits indicate the representation
467 // of the string. 485 // of the string.
468 const uint32_t kStringRepresentationMask = 0x03; 486 const uint32_t kStringRepresentationMask = 0x03;
469 enum StringRepresentationTag { 487 enum StringRepresentationTag {
470 kSeqStringTag = 0x0, 488 kSeqStringTag = 0x0,
471 kConsStringTag = 0x1, 489 kConsStringTag = 0x1,
472 kExternalStringTag = 0x2 490 kExternalStringTag = 0x2,
491 kSlicedStringTag = 0x3
473 }; 492 };
474 const uint32_t kIsConsStringMask = 0x1; 493 const uint32_t kIsIndirectStringMask = 0x1;
494 const uint32_t kIsIndirectStringTag = 0x1;
antonm 2011/07/27 12:16:39 maybe worth adding some documentation why it works
475 495
476 // If bit 7 is clear, then bit 3 indicates whether this two-byte 496 // If bit 7 is clear, then bit 3 indicates whether this two-byte
477 // string actually contains ascii data. 497 // string actually contains ascii data.
478 const uint32_t kAsciiDataHintMask = 0x08; 498 const uint32_t kAsciiDataHintMask = 0x08;
479 const uint32_t kAsciiDataHintTag = 0x08; 499 const uint32_t kAsciiDataHintTag = 0x08;
480 500
481 501
482 // A ConsString with an empty string as the right side is a candidate 502 // A ConsString with an empty string as the right side is a candidate
483 // for being shortcut by the garbage collector unless it is a 503 // for being shortcut by the garbage collector unless it is a
484 // symbol. It's not common to have non-flat symbols, so we do not 504 // symbol. It's not common to have non-flat symbols, so we do not
485 // shortcut them thereby avoiding turning symbols into strings. See 505 // shortcut them thereby avoiding turning symbols into strings. See
486 // heap.cc and mark-compact.cc. 506 // heap.cc and mark-compact.cc.
487 const uint32_t kShortcutTypeMask = 507 const uint32_t kShortcutTypeMask =
488 kIsNotStringMask | 508 kIsNotStringMask |
489 kIsSymbolMask | 509 kIsSymbolMask |
490 kStringRepresentationMask; 510 kStringRepresentationMask;
491 const uint32_t kShortcutTypeTag = kConsStringTag; 511 const uint32_t kShortcutTypeTag = kConsStringTag;
492 512
493 513
494 enum InstanceType { 514 enum InstanceType {
495 // String types. 515 // String types.
496 SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kSeqStringTag, 516 SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kSeqStringTag,
497 ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kSeqStringTag, 517 ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kSeqStringTag,
498 CONS_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kConsStringTag, 518 CONS_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kConsStringTag,
499 CONS_ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kConsStringTag, 519 CONS_ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kConsStringTag,
520 SLICED_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kSlicedStringTag,
521 SLICED_ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kSlicedStringTag,
500 EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kExternalStringTag, 522 EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kExternalStringTag,
501 EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE = 523 EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE =
502 kTwoByteStringTag | kSymbolTag | kExternalStringTag | kAsciiDataHintTag, 524 kTwoByteStringTag | kSymbolTag | kExternalStringTag | kAsciiDataHintTag,
503 EXTERNAL_ASCII_SYMBOL_TYPE = 525 EXTERNAL_ASCII_SYMBOL_TYPE =
504 kAsciiStringTag | kSymbolTag | kExternalStringTag, 526 kAsciiStringTag | kSymbolTag | kExternalStringTag,
505 STRING_TYPE = kTwoByteStringTag | kSeqStringTag, 527 STRING_TYPE = kTwoByteStringTag | kSeqStringTag,
506 ASCII_STRING_TYPE = kAsciiStringTag | kSeqStringTag, 528 ASCII_STRING_TYPE = kAsciiStringTag | kSeqStringTag,
507 CONS_STRING_TYPE = kTwoByteStringTag | kConsStringTag, 529 CONS_STRING_TYPE = kTwoByteStringTag | kConsStringTag,
508 CONS_ASCII_STRING_TYPE = kAsciiStringTag | kConsStringTag, 530 CONS_ASCII_STRING_TYPE = kAsciiStringTag | kConsStringTag,
531 SLICED_STRING_TYPE = kTwoByteStringTag | kSlicedStringTag,
532 SLICED_ASCII_STRING_TYPE = kAsciiStringTag | kSlicedStringTag,
509 EXTERNAL_STRING_TYPE = kTwoByteStringTag | kExternalStringTag, 533 EXTERNAL_STRING_TYPE = kTwoByteStringTag | kExternalStringTag,
510 EXTERNAL_STRING_WITH_ASCII_DATA_TYPE = 534 EXTERNAL_STRING_WITH_ASCII_DATA_TYPE =
511 kTwoByteStringTag | kExternalStringTag | kAsciiDataHintTag, 535 kTwoByteStringTag | kExternalStringTag | kAsciiDataHintTag,
512 // LAST_STRING_TYPE 536 // LAST_STRING_TYPE
513 EXTERNAL_ASCII_STRING_TYPE = kAsciiStringTag | kExternalStringTag, 537 EXTERNAL_ASCII_STRING_TYPE = kAsciiStringTag | kExternalStringTag,
514 PRIVATE_EXTERNAL_ASCII_STRING_TYPE = EXTERNAL_ASCII_STRING_TYPE, 538 PRIVATE_EXTERNAL_ASCII_STRING_TYPE = EXTERNAL_ASCII_STRING_TYPE,
515 539
516 // Objects allocated in their own spaces (never in new space). 540 // Objects allocated in their own spaces (never in new space).
517 MAP_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE 541 MAP_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE
518 CODE_TYPE, 542 CODE_TYPE,
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 V(HeapObject) \ 726 V(HeapObject) \
703 V(Number) \ 727 V(Number) \
704 728
705 #define HEAP_OBJECT_TYPE_LIST(V) \ 729 #define HEAP_OBJECT_TYPE_LIST(V) \
706 V(HeapNumber) \ 730 V(HeapNumber) \
707 V(String) \ 731 V(String) \
708 V(Symbol) \ 732 V(Symbol) \
709 V(SeqString) \ 733 V(SeqString) \
710 V(ExternalString) \ 734 V(ExternalString) \
711 V(ConsString) \ 735 V(ConsString) \
736 V(SlicedString) \
712 V(ExternalTwoByteString) \ 737 V(ExternalTwoByteString) \
713 V(ExternalAsciiString) \ 738 V(ExternalAsciiString) \
714 V(SeqTwoByteString) \ 739 V(SeqTwoByteString) \
715 V(SeqAsciiString) \ 740 V(SeqAsciiString) \
716 \ 741 \
717 V(ExternalArray) \ 742 V(ExternalArray) \
718 V(ExternalByteArray) \ 743 V(ExternalByteArray) \
719 V(ExternalUnsignedByteArray) \ 744 V(ExternalUnsignedByteArray) \
720 V(ExternalShortArray) \ 745 V(ExternalShortArray) \
721 V(ExternalUnsignedShortArray) \ 746 V(ExternalUnsignedShortArray) \
(...skipping 4980 matching lines...) Expand 10 before | Expand all | Expand 10 after
5702 // prone and so we no longer put StringShapes in variables unless there is a 5727 // prone and so we no longer put StringShapes in variables unless there is a
5703 // concrete performance benefit at that particular point in the code. 5728 // concrete performance benefit at that particular point in the code.
5704 class StringShape BASE_EMBEDDED { 5729 class StringShape BASE_EMBEDDED {
5705 public: 5730 public:
5706 inline explicit StringShape(String* s); 5731 inline explicit StringShape(String* s);
5707 inline explicit StringShape(Map* s); 5732 inline explicit StringShape(Map* s);
5708 inline explicit StringShape(InstanceType t); 5733 inline explicit StringShape(InstanceType t);
5709 inline bool IsSequential(); 5734 inline bool IsSequential();
5710 inline bool IsExternal(); 5735 inline bool IsExternal();
5711 inline bool IsCons(); 5736 inline bool IsCons();
5737 inline bool IsSliced();
5712 inline bool IsExternalAscii(); 5738 inline bool IsExternalAscii();
5713 inline bool IsExternalTwoByte(); 5739 inline bool IsExternalTwoByte();
5714 inline bool IsSequentialAscii(); 5740 inline bool IsSequentialAscii();
5715 inline bool IsSequentialTwoByte(); 5741 inline bool IsSequentialTwoByte();
5716 inline bool IsSymbol(); 5742 inline bool IsSymbol();
5717 inline StringRepresentationTag representation_tag(); 5743 inline StringRepresentationTag representation_tag();
5718 inline uint32_t full_representation_tag(); 5744 inline uint32_t full_representation_tag();
5719 inline uint32_t size_tag(); 5745 inline uint32_t size_tag();
5720 #ifdef DEBUG 5746 #ifdef DEBUG
5721 inline uint32_t type() { return type_; } 5747 inline uint32_t type() { return type_; }
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
6221 static const int kMinLength = 13; 6247 static const int kMinLength = 13;
6222 6248
6223 typedef FixedBodyDescriptor<kFirstOffset, kSecondOffset + kPointerSize, kSize> 6249 typedef FixedBodyDescriptor<kFirstOffset, kSecondOffset + kPointerSize, kSize>
6224 BodyDescriptor; 6250 BodyDescriptor;
6225 6251
6226 private: 6252 private:
6227 DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString); 6253 DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString);
6228 }; 6254 };
6229 6255
6230 6256
6257 class SlicedString: public String {
6258 public:
6259
6260 inline String* parent();
6261 inline void set_parent(String* parent, WriteBarrierMode mode);
6262 inline int offset();
6263 inline void set_offset(int offset);
6264
6265 // Dispatched behavior.
6266 uint16_t SlicedStringGet(int index);
6267
6268 // Casting.
6269 static inline SlicedString* cast(Object* obj);
6270
6271 // Layout description.
6272 static const int kParentOffset = POINTER_SIZE_ALIGN(String::kSize);
6273 static const int kOffsetOffset = kParentOffset + kPointerSize;
6274 static const int kSize = kOffsetOffset + kPointerSize;
6275
6276 // Support for StringInputBuffer
6277 inline const unibrow::byte* SlicedStringReadBlock(ReadBlockBuffer* buffer,
6278 unsigned* offset_ptr,
6279 unsigned chars);
6280 inline void SlicedStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
6281 unsigned* offset_ptr,
6282 unsigned chars);
6283 // Minimum length for a sliced string.
6284 static const int kMinLength = 13;
6285
6286 typedef FixedBodyDescriptor<kParentOffset,
6287 kOffsetOffset + kPointerSize, kSize>
6288 BodyDescriptor;
6289
6290 private:
6291 DISALLOW_IMPLICIT_CONSTRUCTORS(SlicedString);
6292 };
6293
6294
6231 // The ExternalString class describes string values that are backed by 6295 // The ExternalString class describes string values that are backed by
6232 // a string resource that lies outside the V8 heap. ExternalStrings 6296 // a string resource that lies outside the V8 heap. ExternalStrings
6233 // consist of the length field common to all strings, a pointer to the 6297 // consist of the length field common to all strings, a pointer to the
6234 // external resource. It is important to ensure (externally) that the 6298 // external resource. It is important to ensure (externally) that the
6235 // resource is not deallocated while the ExternalString is live in the 6299 // resource is not deallocated while the ExternalString is live in the
6236 // V8 heap. 6300 // V8 heap.
6237 // 6301 //
6238 // The API expects that all ExternalStrings are created through the 6302 // The API expects that all ExternalStrings are created through the
6239 // API. Therefore, ExternalStrings should not be used internally. 6303 // API. Therefore, ExternalStrings should not be used internally.
6240 class ExternalString: public String { 6304 class ExternalString: public String {
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after
7203 } else { 7267 } else {
7204 value &= ~(1 << bit_position); 7268 value &= ~(1 << bit_position);
7205 } 7269 }
7206 return value; 7270 return value;
7207 } 7271 }
7208 }; 7272 };
7209 7273
7210 } } // namespace v8::internal 7274 } } // namespace v8::internal
7211 7275
7212 #endif // V8_OBJECTS_H_ 7276 #endif // V8_OBJECTS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698