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

Side by Side Diff: src/objects.h

Issue 11727004: Remove InputBuffer (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 11 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
« no previous file with comments | « no previous file | src/objects.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 7295 matching lines...) Expand 10 before | Expand all | Expand 10 after
7306 // string length is used as the hash value. 7306 // string length is used as the hash value.
7307 static const int kMaxHashCalcLength = 16383; 7307 static const int kMaxHashCalcLength = 16383;
7308 7308
7309 // Limit for truncation in short printing. 7309 // Limit for truncation in short printing.
7310 static const int kMaxShortPrintLength = 1024; 7310 static const int kMaxShortPrintLength = 1024;
7311 7311
7312 // Support for regular expressions. 7312 // Support for regular expressions.
7313 const uc16* GetTwoByteData(); 7313 const uc16* GetTwoByteData();
7314 const uc16* GetTwoByteData(unsigned start); 7314 const uc16* GetTwoByteData(unsigned start);
7315 7315
7316 // Support for StringInputBuffer
7317 static const unibrow::byte* ReadBlock(String* input,
7318 unibrow::byte* util_buffer,
7319 unsigned capacity,
7320 unsigned* remaining,
7321 unsigned* offset);
7322 static const unibrow::byte* ReadBlock(String** input,
7323 unibrow::byte* util_buffer,
7324 unsigned capacity,
7325 unsigned* remaining,
7326 unsigned* offset);
7327
7328 // Helper function for flattening strings. 7316 // Helper function for flattening strings.
7329 template <typename sinkchar> 7317 template <typename sinkchar>
7330 static void WriteToFlat(String* source, 7318 static void WriteToFlat(String* source,
7331 sinkchar* sink, 7319 sinkchar* sink,
7332 int from, 7320 int from,
7333 int to); 7321 int to);
7334 7322
7335 // The return value may point to the first aligned word containing the 7323 // The return value may point to the first aligned word containing the
7336 // first non-ascii character, rather than directly to the non-ascii character. 7324 // first non-ascii character, rather than directly to the non-ascii character.
7337 // If the return value is >= the passed length, the entire string was ASCII. 7325 // If the return value is >= the passed length, the entire string was ASCII.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
7376 } 7364 }
7377 7365
7378 template<class Visitor, class ConsOp> 7366 template<class Visitor, class ConsOp>
7379 static inline void Visit(String* string, 7367 static inline void Visit(String* string,
7380 unsigned offset, 7368 unsigned offset,
7381 Visitor& visitor, 7369 Visitor& visitor,
7382 ConsOp& cons_op, 7370 ConsOp& cons_op,
7383 int32_t type, 7371 int32_t type,
7384 unsigned length); 7372 unsigned length);
7385 7373
7386 protected:
7387 class ReadBlockBuffer {
7388 public:
7389 ReadBlockBuffer(unibrow::byte* util_buffer_,
7390 unsigned cursor_,
7391 unsigned capacity_,
7392 unsigned remaining_) :
7393 util_buffer(util_buffer_),
7394 cursor(cursor_),
7395 capacity(capacity_),
7396 remaining(remaining_) {
7397 }
7398 unibrow::byte* util_buffer;
7399 unsigned cursor;
7400 unsigned capacity;
7401 unsigned remaining;
7402 };
7403
7404 static inline const unibrow::byte* ReadBlock(String* input,
7405 ReadBlockBuffer* buffer,
7406 unsigned* offset,
7407 unsigned max_chars);
7408 static void ReadBlockIntoBuffer(String* input,
7409 ReadBlockBuffer* buffer,
7410 unsigned* offset_ptr,
7411 unsigned max_chars);
7412
7413 private: 7374 private:
7414 // Try to flatten the top level ConsString that is hiding behind this 7375 // Try to flatten the top level ConsString that is hiding behind this
7415 // string. This is a no-op unless the string is a ConsString. Flatten 7376 // string. This is a no-op unless the string is a ConsString. Flatten
7416 // mutates the ConsString and might return a failure. 7377 // mutates the ConsString and might return a failure.
7417 MUST_USE_RESULT MaybeObject* SlowTryFlatten(PretenureFlag pretenure); 7378 MUST_USE_RESULT MaybeObject* SlowTryFlatten(PretenureFlag pretenure);
7418 7379
7419 static inline bool IsHashFieldComputed(uint32_t field); 7380 static inline bool IsHashFieldComputed(uint32_t field);
7420 7381
7421 // Slow case of String::Equals. This implementation works on any strings 7382 // Slow case of String::Equals. This implementation works on any strings
7422 // but it is most efficient on strings that are almost flat. 7383 // but it is most efficient on strings that are almost flat.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
7478 static int SizeFor(int length) { 7439 static int SizeFor(int length) {
7479 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize); 7440 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize);
7480 } 7441 }
7481 7442
7482 // Maximal memory usage for a single sequential ASCII string. 7443 // Maximal memory usage for a single sequential ASCII string.
7483 static const int kMaxSize = 512 * MB - 1; 7444 static const int kMaxSize = 512 * MB - 1;
7484 // Maximal length of a single sequential ASCII string. 7445 // Maximal length of a single sequential ASCII string.
7485 // Q.v. String::kMaxLength which is the maximal size of concatenated strings. 7446 // Q.v. String::kMaxLength which is the maximal size of concatenated strings.
7486 static const int kMaxLength = (kMaxSize - kHeaderSize); 7447 static const int kMaxLength = (kMaxSize - kHeaderSize);
7487 7448
7488 // Support for StringInputBuffer.
7489 inline void SeqOneByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7490 unsigned* offset,
7491 unsigned chars);
7492 inline const unibrow::byte* SeqOneByteStringReadBlock(unsigned* remaining,
7493 unsigned* offset,
7494 unsigned chars);
7495
7496 DECLARE_VERIFIER(SeqOneByteString) 7449 DECLARE_VERIFIER(SeqOneByteString)
7497 7450
7498 private: 7451 private:
7499 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqOneByteString); 7452 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqOneByteString);
7500 }; 7453 };
7501 7454
7502 7455
7503 // The TwoByteString class captures sequential unicode string objects. 7456 // The TwoByteString class captures sequential unicode string objects.
7504 // Each character in the TwoByteString is a two-byte uint16_t. 7457 // Each character in the TwoByteString is a two-byte uint16_t.
7505 class SeqTwoByteString: public SeqString { 7458 class SeqTwoByteString: public SeqString {
(...skipping 24 matching lines...) Expand all
7530 static int SizeFor(int length) { 7483 static int SizeFor(int length) {
7531 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize); 7484 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize);
7532 } 7485 }
7533 7486
7534 // Maximal memory usage for a single sequential two-byte string. 7487 // Maximal memory usage for a single sequential two-byte string.
7535 static const int kMaxSize = 512 * MB - 1; 7488 static const int kMaxSize = 512 * MB - 1;
7536 // Maximal length of a single sequential two-byte string. 7489 // Maximal length of a single sequential two-byte string.
7537 // Q.v. String::kMaxLength which is the maximal size of concatenated strings. 7490 // Q.v. String::kMaxLength which is the maximal size of concatenated strings.
7538 static const int kMaxLength = (kMaxSize - kHeaderSize) / sizeof(uint16_t); 7491 static const int kMaxLength = (kMaxSize - kHeaderSize) / sizeof(uint16_t);
7539 7492
7540 // Support for StringInputBuffer.
7541 inline void SeqTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7542 unsigned* offset_ptr,
7543 unsigned chars);
7544
7545 private: 7493 private:
7546 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqTwoByteString); 7494 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqTwoByteString);
7547 }; 7495 };
7548 7496
7549 7497
7550 // The ConsString class describes string values built by using the 7498 // The ConsString class describes string values built by using the
7551 // addition operator on strings. A ConsString is a pair where the 7499 // addition operator on strings. A ConsString is a pair where the
7552 // first and second components are pointers to other string values. 7500 // first and second components are pointers to other string values.
7553 // One or both components of a ConsString can be pointers to other 7501 // One or both components of a ConsString can be pointers to other
7554 // ConsStrings, creating a binary tree of ConsStrings where the leaves 7502 // ConsStrings, creating a binary tree of ConsStrings where the leaves
(...skipping 22 matching lines...) Expand all
7577 uint16_t ConsStringGet(int index); 7525 uint16_t ConsStringGet(int index);
7578 7526
7579 // Casting. 7527 // Casting.
7580 static inline ConsString* cast(Object* obj); 7528 static inline ConsString* cast(Object* obj);
7581 7529
7582 // Layout description. 7530 // Layout description.
7583 static const int kFirstOffset = POINTER_SIZE_ALIGN(String::kSize); 7531 static const int kFirstOffset = POINTER_SIZE_ALIGN(String::kSize);
7584 static const int kSecondOffset = kFirstOffset + kPointerSize; 7532 static const int kSecondOffset = kFirstOffset + kPointerSize;
7585 static const int kSize = kSecondOffset + kPointerSize; 7533 static const int kSize = kSecondOffset + kPointerSize;
7586 7534
7587 // Support for StringInputBuffer.
7588 inline const unibrow::byte* ConsStringReadBlock(ReadBlockBuffer* buffer,
7589 unsigned* offset_ptr,
7590 unsigned chars);
7591 inline void ConsStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7592 unsigned* offset_ptr,
7593 unsigned chars);
7594
7595 // Minimum length for a cons string. 7535 // Minimum length for a cons string.
7596 static const int kMinLength = 13; 7536 static const int kMinLength = 13;
7597 7537
7598 typedef FixedBodyDescriptor<kFirstOffset, kSecondOffset + kPointerSize, kSize> 7538 typedef FixedBodyDescriptor<kFirstOffset, kSecondOffset + kPointerSize, kSize>
7599 BodyDescriptor; 7539 BodyDescriptor;
7600 7540
7601 DECLARE_VERIFIER(ConsString) 7541 DECLARE_VERIFIER(ConsString)
7602 7542
7603 private: 7543 private:
7604 DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString); 7544 DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString);
(...skipping 24 matching lines...) Expand all
7629 uint16_t SlicedStringGet(int index); 7569 uint16_t SlicedStringGet(int index);
7630 7570
7631 // Casting. 7571 // Casting.
7632 static inline SlicedString* cast(Object* obj); 7572 static inline SlicedString* cast(Object* obj);
7633 7573
7634 // Layout description. 7574 // Layout description.
7635 static const int kParentOffset = POINTER_SIZE_ALIGN(String::kSize); 7575 static const int kParentOffset = POINTER_SIZE_ALIGN(String::kSize);
7636 static const int kOffsetOffset = kParentOffset + kPointerSize; 7576 static const int kOffsetOffset = kParentOffset + kPointerSize;
7637 static const int kSize = kOffsetOffset + kPointerSize; 7577 static const int kSize = kOffsetOffset + kPointerSize;
7638 7578
7639 // Support for StringInputBuffer
7640 inline const unibrow::byte* SlicedStringReadBlock(ReadBlockBuffer* buffer,
7641 unsigned* offset_ptr,
7642 unsigned chars);
7643 inline void SlicedStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7644 unsigned* offset_ptr,
7645 unsigned chars);
7646 // Minimum length for a sliced string. 7579 // Minimum length for a sliced string.
7647 static const int kMinLength = 13; 7580 static const int kMinLength = 13;
7648 7581
7649 typedef FixedBodyDescriptor<kParentOffset, 7582 typedef FixedBodyDescriptor<kParentOffset,
7650 kOffsetOffset + kPointerSize, kSize> 7583 kOffsetOffset + kPointerSize, kSize>
7651 BodyDescriptor; 7584 BodyDescriptor;
7652 7585
7653 DECLARE_VERIFIER(SlicedString) 7586 DECLARE_VERIFIER(SlicedString)
7654 7587
7655 private: 7588 private:
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
7712 7645
7713 // Casting. 7646 // Casting.
7714 static inline ExternalAsciiString* cast(Object* obj); 7647 static inline ExternalAsciiString* cast(Object* obj);
7715 7648
7716 // Garbage collection support. 7649 // Garbage collection support.
7717 inline void ExternalAsciiStringIterateBody(ObjectVisitor* v); 7650 inline void ExternalAsciiStringIterateBody(ObjectVisitor* v);
7718 7651
7719 template<typename StaticVisitor> 7652 template<typename StaticVisitor>
7720 inline void ExternalAsciiStringIterateBody(); 7653 inline void ExternalAsciiStringIterateBody();
7721 7654
7722 // Support for StringInputBuffer.
7723 const unibrow::byte* ExternalAsciiStringReadBlock(unsigned* remaining,
7724 unsigned* offset,
7725 unsigned chars);
7726 inline void ExternalAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7727 unsigned* offset,
7728 unsigned chars);
7729
7730 private: 7655 private:
7731 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalAsciiString); 7656 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalAsciiString);
7732 }; 7657 };
7733 7658
7734 7659
7735 // The ExternalTwoByteString class is an external string backed by a UTF-16 7660 // The ExternalTwoByteString class is an external string backed by a UTF-16
7736 // encoded string. 7661 // encoded string.
7737 class ExternalTwoByteString: public ExternalString { 7662 class ExternalTwoByteString: public ExternalString {
7738 public: 7663 public:
7739 static const bool kHasAsciiEncoding = false; 7664 static const bool kHasAsciiEncoding = false;
(...skipping 20 matching lines...) Expand all
7760 7685
7761 // Casting. 7686 // Casting.
7762 static inline ExternalTwoByteString* cast(Object* obj); 7687 static inline ExternalTwoByteString* cast(Object* obj);
7763 7688
7764 // Garbage collection support. 7689 // Garbage collection support.
7765 inline void ExternalTwoByteStringIterateBody(ObjectVisitor* v); 7690 inline void ExternalTwoByteStringIterateBody(ObjectVisitor* v);
7766 7691
7767 template<typename StaticVisitor> 7692 template<typename StaticVisitor>
7768 inline void ExternalTwoByteStringIterateBody(); 7693 inline void ExternalTwoByteStringIterateBody();
7769 7694
7770
7771 // Support for StringInputBuffer.
7772 void ExternalTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7773 unsigned* offset_ptr,
7774 unsigned chars);
7775
7776 private: 7695 private:
7777 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalTwoByteString); 7696 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalTwoByteString);
7778 }; 7697 };
7779 7698
7780 7699
7781 // Utility superclass for stack-allocated objects that must be updated 7700 // Utility superclass for stack-allocated objects that must be updated
7782 // on gc. It provides two ways for the gc to update instances, either 7701 // on gc. It provides two ways for the gc to update instances, either
7783 // iterating or updating after gc. 7702 // iterating or updating after gc.
7784 class Relocatable BASE_EMBEDDED { 7703 class Relocatable BASE_EMBEDDED {
7785 public: 7704 public:
(...skipping 26 matching lines...) Expand all
7812 inline uc32 Get(int index); 7731 inline uc32 Get(int index);
7813 int length() { return length_; } 7732 int length() { return length_; }
7814 private: 7733 private:
7815 String** str_; 7734 String** str_;
7816 bool is_ascii_; 7735 bool is_ascii_;
7817 int length_; 7736 int length_;
7818 const void* start_; 7737 const void* start_;
7819 }; 7738 };
7820 7739
7821 7740
7822 // Note that StringInputBuffers are not valid across a GC! To fix this
7823 // it would have to store a String Handle instead of a String* and
7824 // AsciiStringReadBlock would have to be modified to use memcpy.
7825 //
7826 // StringInputBuffer is able to traverse any string regardless of how
7827 // deeply nested a sequence of ConsStrings it is made of. However,
7828 // performance will be better if deep strings are flattened before they
7829 // are traversed. Since flattening requires memory allocation this is
7830 // not always desirable, however (esp. in debugging situations).
7831 class StringInputBuffer: public unibrow::InputBuffer<String, String*, 1024> {
7832 public:
7833 virtual void Seek(unsigned pos);
7834 inline StringInputBuffer(): unibrow::InputBuffer<String, String*, 1024>() {}
7835 explicit inline StringInputBuffer(String* backing):
7836 unibrow::InputBuffer<String, String*, 1024>(backing) {}
7837 };
7838
7839
7840 // A ConsStringOp that returns null. 7741 // A ConsStringOp that returns null.
7841 // Useful when the operation to apply on a ConsString 7742 // Useful when the operation to apply on a ConsString
7842 // requires an expensive data structure. 7743 // requires an expensive data structure.
7843 class ConsStringNullOp { 7744 class ConsStringNullOp {
7844 public: 7745 public:
7845 inline ConsStringNullOp() {} 7746 inline ConsStringNullOp() {}
7846 static inline String* Operate(String*, unsigned*, int32_t*, unsigned*); 7747 static inline String* Operate(String*, unsigned*, int32_t*, unsigned*);
7847 private: 7748 private:
7848 DISALLOW_COPY_AND_ASSIGN(ConsStringNullOp); 7749 DISALLOW_COPY_AND_ASSIGN(ConsStringNullOp);
7849 }; 7750 };
(...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after
8885 } else { 8786 } else {
8886 value &= ~(1 << bit_position); 8787 value &= ~(1 << bit_position);
8887 } 8788 }
8888 return value; 8789 return value;
8889 } 8790 }
8890 }; 8791 };
8891 8792
8892 } } // namespace v8::internal 8793 } } // namespace v8::internal
8893 8794
8894 #endif // V8_OBJECTS_H_ 8795 #endif // V8_OBJECTS_H_
OLDNEW
« no previous file with comments | « no previous file | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698