OLD | NEW |
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 5748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5759 ASSERT(is_array_index()); | 5759 ASSERT(is_array_index()); |
5760 return array_index_; | 5760 return array_index_; |
5761 } | 5761 } |
5762 | 5762 |
5763 inline uint32_t GetHash(); | 5763 inline uint32_t GetHash(); |
5764 | 5764 |
5765 int length_; | 5765 int length_; |
5766 uint32_t raw_running_hash_; | 5766 uint32_t raw_running_hash_; |
5767 uint32_t array_index_; | 5767 uint32_t array_index_; |
5768 bool is_array_index_; | 5768 bool is_array_index_; |
| 5769 bool is_first_char_; |
5769 bool is_valid_; | 5770 bool is_valid_; |
5770 friend class TwoCharHashTableKey; | 5771 friend class TwoCharHashTableKey; |
5771 }; | 5772 }; |
5772 | 5773 |
5773 | 5774 |
5774 // Calculates string hash. | 5775 // Calculates string hash. |
5775 template <typename schar> | 5776 template <typename schar> |
5776 inline uint32_t HashSequentialString(const schar* chars, int length); | 5777 inline uint32_t HashSequentialString(const schar* chars, int length); |
5777 | 5778 |
5778 | 5779 |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6210 | 6211 |
6211 // The SeqString abstract class captures sequential string values. | 6212 // The SeqString abstract class captures sequential string values. |
6212 class SeqString: public String { | 6213 class SeqString: public String { |
6213 public: | 6214 public: |
6214 // Casting. | 6215 // Casting. |
6215 static inline SeqString* cast(Object* obj); | 6216 static inline SeqString* cast(Object* obj); |
6216 | 6217 |
6217 // Layout description. | 6218 // Layout description. |
6218 static const int kHeaderSize = String::kSize; | 6219 static const int kHeaderSize = String::kSize; |
6219 | 6220 |
6220 // Shortcuts for templates that know their string-type exactly. | |
6221 bool IsExternalAsciiString() { | |
6222 return false; | |
6223 } | |
6224 bool IsExternalTwoByteString() { | |
6225 return false; | |
6226 } | |
6227 | |
6228 | |
6229 private: | 6221 private: |
6230 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString); | 6222 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString); |
6231 }; | 6223 }; |
6232 | 6224 |
6233 | 6225 |
6234 // The SeqAsciiString class captures sequential ASCII string objects. | 6226 // The AsciiString class captures sequential ascii string objects. |
6235 // Each character in the AsciiString is an ASCII character. | 6227 // Each character in the AsciiString is an ascii character. |
6236 class SeqAsciiString: public SeqString { | 6228 class SeqAsciiString: public SeqString { |
6237 public: | 6229 public: |
6238 typedef char CharType; | |
6239 static const bool kHasAsciiEncoding = true; | 6230 static const bool kHasAsciiEncoding = true; |
6240 | 6231 |
6241 // Dispatched behavior. | 6232 // Dispatched behavior. |
6242 inline uint16_t SeqAsciiStringGet(int index); | 6233 inline uint16_t SeqAsciiStringGet(int index); |
6243 inline void SeqAsciiStringSet(int index, uint16_t value); | 6234 inline void SeqAsciiStringSet(int index, uint16_t value); |
6244 | 6235 |
6245 // Get the address of the characters in this string. | 6236 // Get the address of the characters in this string. |
6246 inline Address GetCharsAddress(); | 6237 inline Address GetCharsAddress(); |
6247 | 6238 |
6248 inline char* GetChars(); | 6239 inline char* GetChars(); |
6249 | 6240 |
6250 // Casting | 6241 // Casting |
6251 static inline SeqAsciiString* cast(Object* obj); | 6242 static inline SeqAsciiString* cast(Object* obj); |
6252 | 6243 |
6253 bool IsSeqAsciiString() { | |
6254 ASSERT(this->Object::IsSeqAsciiString()); | |
6255 return true; | |
6256 } | |
6257 bool IsSeqTwoByteString() { | |
6258 ASSERT(this->Object::IsSeqAsciiString()); | |
6259 return false; | |
6260 } | |
6261 | |
6262 // Garbage collection support. This method is called by the | 6244 // Garbage collection support. This method is called by the |
6263 // garbage collector to compute the actual size of an AsciiString | 6245 // garbage collector to compute the actual size of an AsciiString |
6264 // instance. | 6246 // instance. |
6265 inline int SeqAsciiStringSize(InstanceType instance_type); | 6247 inline int SeqAsciiStringSize(InstanceType instance_type); |
6266 | 6248 |
6267 // Computes the size for an AsciiString instance of a given length. | 6249 // Computes the size for an AsciiString instance of a given length. |
6268 static int SizeFor(int length) { | 6250 static int SizeFor(int length) { |
6269 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize); | 6251 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize); |
6270 } | 6252 } |
6271 | 6253 |
6272 // Maximal memory usage for a single sequential ASCII string. | 6254 // Maximal memory usage for a single sequential ASCII string. |
6273 static const int kMaxSize = 512 * MB - 1; | 6255 static const int kMaxSize = 512 * MB - 1; |
6274 // Maximal length of a single sequential ASCII string. | 6256 // Maximal length of a single sequential ASCII string. |
6275 // Q.v. String::kMaxLength which is the maximal size of concatenated strings. | 6257 // Q.v. String::kMaxLength which is the maximal size of concatenated strings. |
6276 static const int kMaxLength = (kMaxSize - kHeaderSize); | 6258 static const int kMaxLength = (kMaxSize - kHeaderSize); |
6277 | 6259 |
6278 // Support for StringInputBuffer. | 6260 // Support for StringInputBuffer. |
6279 inline void SeqAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, | 6261 inline void SeqAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
6280 unsigned* offset, | 6262 unsigned* offset, |
6281 unsigned chars); | 6263 unsigned chars); |
6282 inline const unibrow::byte* SeqAsciiStringReadBlock(unsigned* remaining, | 6264 inline const unibrow::byte* SeqAsciiStringReadBlock(unsigned* remaining, |
6283 unsigned* offset, | 6265 unsigned* offset, |
6284 unsigned chars); | 6266 unsigned chars); |
6285 | 6267 |
6286 private: | 6268 private: |
6287 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqAsciiString); | 6269 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqAsciiString); |
6288 }; | 6270 }; |
6289 | 6271 |
6290 | 6272 |
6291 // The SeqTwoByteString class captures sequential unicode string objects. | 6273 // The TwoByteString class captures sequential unicode string objects. |
6292 // Each character in the TwoByteString is a two-byte uint16_t. | 6274 // Each character in the TwoByteString is a two-byte uint16_t. |
6293 class SeqTwoByteString: public SeqString { | 6275 class SeqTwoByteString: public SeqString { |
6294 public: | 6276 public: |
6295 typedef uc16 CharType; | |
6296 | |
6297 static const bool kHasAsciiEncoding = false; | 6277 static const bool kHasAsciiEncoding = false; |
6298 | 6278 |
6299 // Dispatched behavior. | 6279 // Dispatched behavior. |
6300 inline uint16_t SeqTwoByteStringGet(int index); | 6280 inline uint16_t SeqTwoByteStringGet(int index); |
6301 inline void SeqTwoByteStringSet(int index, uint16_t value); | 6281 inline void SeqTwoByteStringSet(int index, uint16_t value); |
6302 | 6282 |
6303 // Get the address of the characters in this string. | 6283 // Get the address of the characters in this string. |
6304 inline Address GetCharsAddress(); | 6284 inline Address GetCharsAddress(); |
6305 | 6285 |
6306 inline uc16* GetChars(); | 6286 inline uc16* GetChars(); |
6307 | 6287 |
6308 // For regexp code. | 6288 // For regexp code. |
6309 const uint16_t* SeqTwoByteStringGetData(unsigned start); | 6289 const uint16_t* SeqTwoByteStringGetData(unsigned start); |
6310 | 6290 |
6311 // Casting | 6291 // Casting |
6312 static inline SeqTwoByteString* cast(Object* obj); | 6292 static inline SeqTwoByteString* cast(Object* obj); |
6313 bool IsSeqTwoByteString() { | |
6314 ASSERT(this->Object::IsSeqTwoByteString()); | |
6315 return true; | |
6316 } | |
6317 bool IsSeqAsciiString() { | |
6318 ASSERT(this->Object::IsSeqTwoByteString()); | |
6319 return false; | |
6320 } | |
6321 | 6293 |
6322 // Garbage collection support. This method is called by the | 6294 // Garbage collection support. This method is called by the |
6323 // garbage collector to compute the actual size of a TwoByteString | 6295 // garbage collector to compute the actual size of a TwoByteString |
6324 // instance. | 6296 // instance. |
6325 inline int SeqTwoByteStringSize(InstanceType instance_type); | 6297 inline int SeqTwoByteStringSize(InstanceType instance_type); |
6326 | 6298 |
6327 // Computes the size for a TwoByteString instance of a given length. | 6299 // Computes the size for a TwoByteString instance of a given length. |
6328 static int SizeFor(int length) { | 6300 static int SizeFor(int length) { |
6329 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize); | 6301 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize); |
6330 } | 6302 } |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6471 public: | 6443 public: |
6472 // Casting | 6444 // Casting |
6473 static inline ExternalString* cast(Object* obj); | 6445 static inline ExternalString* cast(Object* obj); |
6474 | 6446 |
6475 // Layout description. | 6447 // Layout description. |
6476 static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize); | 6448 static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize); |
6477 static const int kSize = kResourceOffset + kPointerSize; | 6449 static const int kSize = kResourceOffset + kPointerSize; |
6478 | 6450 |
6479 STATIC_CHECK(kResourceOffset == Internals::kStringResourceOffset); | 6451 STATIC_CHECK(kResourceOffset == Internals::kStringResourceOffset); |
6480 | 6452 |
6481 // Shortcuts for templates that know their string type exactly. | |
6482 bool IsSeqAsciiString() { | |
6483 return false; | |
6484 } | |
6485 bool IsSeqTwoByteString() { | |
6486 return false; | |
6487 } | |
6488 | |
6489 private: | 6453 private: |
6490 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString); | 6454 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString); |
6491 }; | 6455 }; |
6492 | 6456 |
6493 | 6457 |
6494 // The ExternalAsciiString class is an external string backed by an | 6458 // The ExternalAsciiString class is an external string backed by an |
6495 // ASCII string. | 6459 // ASCII string. |
6496 class ExternalAsciiString: public ExternalString { | 6460 class ExternalAsciiString: public ExternalString { |
6497 public: | 6461 public: |
6498 typedef char CharType; | |
6499 | |
6500 static const bool kHasAsciiEncoding = true; | 6462 static const bool kHasAsciiEncoding = true; |
6501 | 6463 |
6502 typedef v8::String::ExternalAsciiStringResource Resource; | 6464 typedef v8::String::ExternalAsciiStringResource Resource; |
6503 | 6465 |
6504 // The underlying resource. | 6466 // The underlying resource. |
6505 inline const Resource* resource(); | 6467 inline const Resource* resource(); |
6506 inline void set_resource(const Resource* buffer); | 6468 inline void set_resource(const Resource* buffer); |
6507 | 6469 |
6508 // Dispatched behavior. | 6470 // Dispatched behavior. |
6509 uint16_t ExternalAsciiStringGet(int index); | 6471 uint16_t ExternalAsciiStringGet(int index); |
6510 | 6472 |
6511 // Casting. | 6473 // Casting. |
6512 static inline ExternalAsciiString* cast(Object* obj); | 6474 static inline ExternalAsciiString* cast(Object* obj); |
6513 bool IsExternalAsciiString() { | |
6514 ASSERT(this->Object::IsExternalAsciiString()); | |
6515 return true; | |
6516 } | |
6517 bool IsExternalTwoByteString() { | |
6518 ASSERT(this->Object::IsExternalAsciiString()); | |
6519 return false; | |
6520 } | |
6521 | 6475 |
6522 // Garbage collection support. | 6476 // Garbage collection support. |
6523 inline void ExternalAsciiStringIterateBody(ObjectVisitor* v); | 6477 inline void ExternalAsciiStringIterateBody(ObjectVisitor* v); |
6524 | 6478 |
6525 template<typename StaticVisitor> | 6479 template<typename StaticVisitor> |
6526 inline void ExternalAsciiStringIterateBody(); | 6480 inline void ExternalAsciiStringIterateBody(); |
6527 | 6481 |
6528 // Support for StringInputBuffer. | 6482 // Support for StringInputBuffer. |
6529 const unibrow::byte* ExternalAsciiStringReadBlock(unsigned* remaining, | 6483 const unibrow::byte* ExternalAsciiStringReadBlock(unsigned* remaining, |
6530 unsigned* offset, | 6484 unsigned* offset, |
6531 unsigned chars); | 6485 unsigned chars); |
6532 inline void ExternalAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, | 6486 inline void ExternalAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
6533 unsigned* offset, | 6487 unsigned* offset, |
6534 unsigned chars); | 6488 unsigned chars); |
6535 | 6489 |
6536 private: | 6490 private: |
6537 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalAsciiString); | 6491 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalAsciiString); |
6538 }; | 6492 }; |
6539 | 6493 |
6540 | 6494 |
6541 // The ExternalTwoByteString class is an external string backed by a 16-bit | 6495 // The ExternalTwoByteString class is an external string backed by a UTF-16 |
6542 // character sequence. | 6496 // encoded string. |
6543 class ExternalTwoByteString: public ExternalString { | 6497 class ExternalTwoByteString: public ExternalString { |
6544 public: | 6498 public: |
6545 typedef uc16 CharType; | |
6546 static const bool kHasAsciiEncoding = false; | 6499 static const bool kHasAsciiEncoding = false; |
6547 | 6500 |
6548 typedef v8::String::ExternalStringResource Resource; | 6501 typedef v8::String::ExternalStringResource Resource; |
6549 | 6502 |
6550 // The underlying string resource. | 6503 // The underlying string resource. |
6551 inline const Resource* resource(); | 6504 inline const Resource* resource(); |
6552 inline void set_resource(const Resource* buffer); | 6505 inline void set_resource(const Resource* buffer); |
6553 | 6506 |
6554 // Dispatched behavior. | 6507 // Dispatched behavior. |
6555 uint16_t ExternalTwoByteStringGet(int index); | 6508 uint16_t ExternalTwoByteStringGet(int index); |
6556 | 6509 |
6557 // For regexp code. | 6510 // For regexp code. |
6558 const uint16_t* ExternalTwoByteStringGetData(unsigned start); | 6511 const uint16_t* ExternalTwoByteStringGetData(unsigned start); |
6559 | 6512 |
6560 // Casting. | 6513 // Casting. |
6561 static inline ExternalTwoByteString* cast(Object* obj); | 6514 static inline ExternalTwoByteString* cast(Object* obj); |
6562 bool IsExternalTwoByteString() { | |
6563 ASSERT(this->Object::IsExternalTwoByteString()); | |
6564 return true; | |
6565 } | |
6566 bool IsExternalAsciiString() { | |
6567 ASSERT(this->Object::IsExternalTwoByteString()); | |
6568 return false; | |
6569 } | |
6570 | 6515 |
6571 // Garbage collection support. | 6516 // Garbage collection support. |
6572 inline void ExternalTwoByteStringIterateBody(ObjectVisitor* v); | 6517 inline void ExternalTwoByteStringIterateBody(ObjectVisitor* v); |
6573 | 6518 |
6574 template<typename StaticVisitor> | 6519 template<typename StaticVisitor> |
6575 inline void ExternalTwoByteStringIterateBody(); | 6520 inline void ExternalTwoByteStringIterateBody(); |
6576 | 6521 |
6577 | 6522 |
6578 // Support for StringInputBuffer. | 6523 // Support for StringInputBuffer. |
6579 void ExternalTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, | 6524 void ExternalTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7570 } else { | 7515 } else { |
7571 value &= ~(1 << bit_position); | 7516 value &= ~(1 << bit_position); |
7572 } | 7517 } |
7573 return value; | 7518 return value; |
7574 } | 7519 } |
7575 }; | 7520 }; |
7576 | 7521 |
7577 } } // namespace v8::internal | 7522 } } // namespace v8::internal |
7578 | 7523 |
7579 #endif // V8_OBJECTS_H_ | 7524 #endif // V8_OBJECTS_H_ |
OLD | NEW |