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

Side by Side Diff: src/objects.h

Issue 7977001: Added ability to lock strings to prevent their representation or encoding from changing. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix bug in test when running threaded. Created 9 years, 2 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 | « src/json-parser.h ('k') | 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 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 5716 matching lines...) Expand 10 before | Expand all | Expand 10 after
5727 ASSERT(is_array_index()); 5727 ASSERT(is_array_index());
5728 return array_index_; 5728 return array_index_;
5729 } 5729 }
5730 5730
5731 inline uint32_t GetHash(); 5731 inline uint32_t GetHash();
5732 5732
5733 int length_; 5733 int length_;
5734 uint32_t raw_running_hash_; 5734 uint32_t raw_running_hash_;
5735 uint32_t array_index_; 5735 uint32_t array_index_;
5736 bool is_array_index_; 5736 bool is_array_index_;
5737 bool is_first_char_;
5738 bool is_valid_; 5737 bool is_valid_;
5739 friend class TwoCharHashTableKey; 5738 friend class TwoCharHashTableKey;
5740 }; 5739 };
5741 5740
5742 5741
5743 // Calculates string hash. 5742 // Calculates string hash.
5744 template <typename schar> 5743 template <typename schar>
5745 inline uint32_t HashSequentialString(const schar* chars, int length); 5744 inline uint32_t HashSequentialString(const schar* chars, int length);
5746 5745
5747 5746
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
6179 6178
6180 // The SeqString abstract class captures sequential string values. 6179 // The SeqString abstract class captures sequential string values.
6181 class SeqString: public String { 6180 class SeqString: public String {
6182 public: 6181 public:
6183 // Casting. 6182 // Casting.
6184 static inline SeqString* cast(Object* obj); 6183 static inline SeqString* cast(Object* obj);
6185 6184
6186 // Layout description. 6185 // Layout description.
6187 static const int kHeaderSize = String::kSize; 6186 static const int kHeaderSize = String::kSize;
6188 6187
6188 // Shortcuts for templates that know their string-type exactly.
6189 bool IsExternalAsciiString() {
6190 return false;
6191 }
6192 bool IsExternalTwoByteString() {
6193 return false;
6194 }
6195
6196
6189 private: 6197 private:
6190 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString); 6198 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString);
6191 }; 6199 };
6192 6200
6193 6201
6194 // The AsciiString class captures sequential ascii string objects. 6202 // The SeqAsciiString class captures sequential ASCII string objects.
6195 // Each character in the AsciiString is an ascii character. 6203 // Each character in the AsciiString is an ASCII character.
6196 class SeqAsciiString: public SeqString { 6204 class SeqAsciiString: public SeqString {
6197 public: 6205 public:
6206 typedef char CharType;
6198 static const bool kHasAsciiEncoding = true; 6207 static const bool kHasAsciiEncoding = true;
6199 6208
6200 // Dispatched behavior. 6209 // Dispatched behavior.
6201 inline uint16_t SeqAsciiStringGet(int index); 6210 inline uint16_t SeqAsciiStringGet(int index);
6202 inline void SeqAsciiStringSet(int index, uint16_t value); 6211 inline void SeqAsciiStringSet(int index, uint16_t value);
6203 6212
6204 // Get the address of the characters in this string. 6213 // Get the address of the characters in this string.
6205 inline Address GetCharsAddress(); 6214 inline Address GetCharsAddress();
6206 6215
6207 inline char* GetChars(); 6216 inline char* GetChars();
6208 6217
6209 // Casting 6218 // Casting
6210 static inline SeqAsciiString* cast(Object* obj); 6219 static inline SeqAsciiString* cast(Object* obj);
6211 6220
6221 bool IsSeqAsciiString() {
6222 ASSERT(this->Object::IsSeqAsciiString());
6223 return true;
6224 }
6225 bool IsSeqTwoByteString() {
6226 ASSERT(this->Object::IsSeqAsciiString());
6227 return false;
6228 }
6229
6212 // Garbage collection support. This method is called by the 6230 // Garbage collection support. This method is called by the
6213 // garbage collector to compute the actual size of an AsciiString 6231 // garbage collector to compute the actual size of an AsciiString
6214 // instance. 6232 // instance.
6215 inline int SeqAsciiStringSize(InstanceType instance_type); 6233 inline int SeqAsciiStringSize(InstanceType instance_type);
6216 6234
6217 // Computes the size for an AsciiString instance of a given length. 6235 // Computes the size for an AsciiString instance of a given length.
6218 static int SizeFor(int length) { 6236 static int SizeFor(int length) {
6219 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize); 6237 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize);
6220 } 6238 }
6221 6239
6222 // Maximal memory usage for a single sequential ASCII string. 6240 // Maximal memory usage for a single sequential ASCII string.
6223 static const int kMaxSize = 512 * MB - 1; 6241 static const int kMaxSize = 512 * MB - 1;
6224 // Maximal length of a single sequential ASCII string. 6242 // Maximal length of a single sequential ASCII string.
6225 // Q.v. String::kMaxLength which is the maximal size of concatenated strings. 6243 // Q.v. String::kMaxLength which is the maximal size of concatenated strings.
6226 static const int kMaxLength = (kMaxSize - kHeaderSize); 6244 static const int kMaxLength = (kMaxSize - kHeaderSize);
6227 6245
6228 // Support for StringInputBuffer. 6246 // Support for StringInputBuffer.
6229 inline void SeqAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, 6247 inline void SeqAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
6230 unsigned* offset, 6248 unsigned* offset,
6231 unsigned chars); 6249 unsigned chars);
6232 inline const unibrow::byte* SeqAsciiStringReadBlock(unsigned* remaining, 6250 inline const unibrow::byte* SeqAsciiStringReadBlock(unsigned* remaining,
6233 unsigned* offset, 6251 unsigned* offset,
6234 unsigned chars); 6252 unsigned chars);
6235 6253
6236 private: 6254 private:
6237 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqAsciiString); 6255 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqAsciiString);
6238 }; 6256 };
6239 6257
6240 6258
6241 // The TwoByteString class captures sequential unicode string objects. 6259 // The SeqTwoByteString class captures sequential unicode string objects.
6242 // Each character in the TwoByteString is a two-byte uint16_t. 6260 // Each character in the TwoByteString is a two-byte uint16_t.
6243 class SeqTwoByteString: public SeqString { 6261 class SeqTwoByteString: public SeqString {
6244 public: 6262 public:
6263 typedef uc16 CharType;
6264
6245 static const bool kHasAsciiEncoding = false; 6265 static const bool kHasAsciiEncoding = false;
6246 6266
6247 // Dispatched behavior. 6267 // Dispatched behavior.
6248 inline uint16_t SeqTwoByteStringGet(int index); 6268 inline uint16_t SeqTwoByteStringGet(int index);
6249 inline void SeqTwoByteStringSet(int index, uint16_t value); 6269 inline void SeqTwoByteStringSet(int index, uint16_t value);
6250 6270
6251 // Get the address of the characters in this string. 6271 // Get the address of the characters in this string.
6252 inline Address GetCharsAddress(); 6272 inline Address GetCharsAddress();
6253 6273
6254 inline uc16* GetChars(); 6274 inline uc16* GetChars();
6255 6275
6256 // For regexp code. 6276 // For regexp code.
6257 const uint16_t* SeqTwoByteStringGetData(unsigned start); 6277 const uint16_t* SeqTwoByteStringGetData(unsigned start);
6258 6278
6259 // Casting 6279 // Casting
6260 static inline SeqTwoByteString* cast(Object* obj); 6280 static inline SeqTwoByteString* cast(Object* obj);
6281 bool IsSeqTwoByteString() {
6282 ASSERT(this->Object::IsSeqTwoByteString());
6283 return true;
6284 }
6285 bool IsSeqAsciiString() {
6286 ASSERT(this->Object::IsSeqTwoByteString());
6287 return false;
6288 }
6261 6289
6262 // Garbage collection support. This method is called by the 6290 // Garbage collection support. This method is called by the
6263 // garbage collector to compute the actual size of a TwoByteString 6291 // garbage collector to compute the actual size of a TwoByteString
6264 // instance. 6292 // instance.
6265 inline int SeqTwoByteStringSize(InstanceType instance_type); 6293 inline int SeqTwoByteStringSize(InstanceType instance_type);
6266 6294
6267 // Computes the size for a TwoByteString instance of a given length. 6295 // Computes the size for a TwoByteString instance of a given length.
6268 static int SizeFor(int length) { 6296 static int SizeFor(int length) {
6269 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize); 6297 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize);
6270 } 6298 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
6411 public: 6439 public:
6412 // Casting 6440 // Casting
6413 static inline ExternalString* cast(Object* obj); 6441 static inline ExternalString* cast(Object* obj);
6414 6442
6415 // Layout description. 6443 // Layout description.
6416 static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize); 6444 static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize);
6417 static const int kSize = kResourceOffset + kPointerSize; 6445 static const int kSize = kResourceOffset + kPointerSize;
6418 6446
6419 STATIC_CHECK(kResourceOffset == Internals::kStringResourceOffset); 6447 STATIC_CHECK(kResourceOffset == Internals::kStringResourceOffset);
6420 6448
6449 // Shortcuts for templates that know their string type exactly.
6450 bool IsSeqAsciiString() {
6451 return false;
6452 }
6453 bool IsSeqTwoByteString() {
6454 return false;
6455 }
6456
6421 private: 6457 private:
6422 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString); 6458 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString);
6423 }; 6459 };
6424 6460
6425 6461
6426 // The ExternalAsciiString class is an external string backed by an 6462 // The ExternalAsciiString class is an external string backed by an
6427 // ASCII string. 6463 // ASCII string.
6428 class ExternalAsciiString: public ExternalString { 6464 class ExternalAsciiString: public ExternalString {
6429 public: 6465 public:
6466 typedef char CharType;
6467
6430 static const bool kHasAsciiEncoding = true; 6468 static const bool kHasAsciiEncoding = true;
6431 6469
6432 typedef v8::String::ExternalAsciiStringResource Resource; 6470 typedef v8::String::ExternalAsciiStringResource Resource;
6433 6471
6434 // The underlying resource. 6472 // The underlying resource.
6435 inline const Resource* resource(); 6473 inline const Resource* resource();
6436 inline void set_resource(const Resource* buffer); 6474 inline void set_resource(const Resource* buffer);
6437 6475
6438 // Dispatched behavior. 6476 // Dispatched behavior.
6439 uint16_t ExternalAsciiStringGet(int index); 6477 uint16_t ExternalAsciiStringGet(int index);
6440 6478
6441 // Casting. 6479 // Casting.
6442 static inline ExternalAsciiString* cast(Object* obj); 6480 static inline ExternalAsciiString* cast(Object* obj);
6481 bool IsExternalAsciiString() {
6482 ASSERT(this->Object::IsExternalAsciiString());
6483 return true;
6484 }
6485 bool IsExternalTwoByteString() {
6486 ASSERT(this->Object::IsExternalAsciiString());
6487 return false;
6488 }
6443 6489
6444 // Garbage collection support. 6490 // Garbage collection support.
6445 inline void ExternalAsciiStringIterateBody(ObjectVisitor* v); 6491 inline void ExternalAsciiStringIterateBody(ObjectVisitor* v);
6446 6492
6447 template<typename StaticVisitor> 6493 template<typename StaticVisitor>
6448 inline void ExternalAsciiStringIterateBody(); 6494 inline void ExternalAsciiStringIterateBody();
6449 6495
6450 // Support for StringInputBuffer. 6496 // Support for StringInputBuffer.
6451 const unibrow::byte* ExternalAsciiStringReadBlock(unsigned* remaining, 6497 const unibrow::byte* ExternalAsciiStringReadBlock(unsigned* remaining,
6452 unsigned* offset, 6498 unsigned* offset,
6453 unsigned chars); 6499 unsigned chars);
6454 inline void ExternalAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, 6500 inline void ExternalAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
6455 unsigned* offset, 6501 unsigned* offset,
6456 unsigned chars); 6502 unsigned chars);
6457 6503
6458 private: 6504 private:
6459 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalAsciiString); 6505 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalAsciiString);
6460 }; 6506 };
6461 6507
6462 6508
6463 // The ExternalTwoByteString class is an external string backed by a UTF-16 6509 // The ExternalTwoByteString class is an external string backed by a 16-bit
6464 // encoded string. 6510 // character sequence.
6465 class ExternalTwoByteString: public ExternalString { 6511 class ExternalTwoByteString: public ExternalString {
6466 public: 6512 public:
6513 typedef uc16 CharType;
6467 static const bool kHasAsciiEncoding = false; 6514 static const bool kHasAsciiEncoding = false;
6468 6515
6469 typedef v8::String::ExternalStringResource Resource; 6516 typedef v8::String::ExternalStringResource Resource;
6470 6517
6471 // The underlying string resource. 6518 // The underlying string resource.
6472 inline const Resource* resource(); 6519 inline const Resource* resource();
6473 inline void set_resource(const Resource* buffer); 6520 inline void set_resource(const Resource* buffer);
6474 6521
6475 // Dispatched behavior. 6522 // Dispatched behavior.
6476 uint16_t ExternalTwoByteStringGet(int index); 6523 uint16_t ExternalTwoByteStringGet(int index);
6477 6524
6478 // For regexp code. 6525 // For regexp code.
6479 const uint16_t* ExternalTwoByteStringGetData(unsigned start); 6526 const uint16_t* ExternalTwoByteStringGetData(unsigned start);
6480 6527
6481 // Casting. 6528 // Casting.
6482 static inline ExternalTwoByteString* cast(Object* obj); 6529 static inline ExternalTwoByteString* cast(Object* obj);
6530 bool IsExternalTwoByteString() {
6531 ASSERT(this->Object::IsExternalTwoByteString());
6532 return true;
6533 }
6534 bool IsExternalAsciiString() {
6535 ASSERT(this->Object::IsExternalTwoByteString());
6536 return false;
6537 }
6483 6538
6484 // Garbage collection support. 6539 // Garbage collection support.
6485 inline void ExternalTwoByteStringIterateBody(ObjectVisitor* v); 6540 inline void ExternalTwoByteStringIterateBody(ObjectVisitor* v);
6486 6541
6487 template<typename StaticVisitor> 6542 template<typename StaticVisitor>
6488 inline void ExternalTwoByteStringIterateBody(); 6543 inline void ExternalTwoByteStringIterateBody();
6489 6544
6490 6545
6491 // Support for StringInputBuffer. 6546 // Support for StringInputBuffer.
6492 void ExternalTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, 6547 void ExternalTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
(...skipping 983 matching lines...) Expand 10 before | Expand all | Expand 10 after
7476 } else { 7531 } else {
7477 value &= ~(1 << bit_position); 7532 value &= ~(1 << bit_position);
7478 } 7533 }
7479 return value; 7534 return value;
7480 } 7535 }
7481 }; 7536 };
7482 7537
7483 } } // namespace v8::internal 7538 } } // namespace v8::internal
7484 7539
7485 #endif // V8_OBJECTS_H_ 7540 #endif // V8_OBJECTS_H_
OLDNEW
« no previous file with comments | « src/json-parser.h ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698