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

Side by Side Diff: src/objects.h

Issue 2762008: Track ascii-ness of data in externalized strings. (Closed)
Patch Set: Extended tests. Created 10 years, 6 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
OLDNEW
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 cons_symbol, \ 313 cons_symbol, \
314 ConsSymbol) \ 314 ConsSymbol) \
315 V(CONS_ASCII_SYMBOL_TYPE, \ 315 V(CONS_ASCII_SYMBOL_TYPE, \
316 ConsString::kSize, \ 316 ConsString::kSize, \
317 cons_ascii_symbol, \ 317 cons_ascii_symbol, \
318 ConsAsciiSymbol) \ 318 ConsAsciiSymbol) \
319 V(EXTERNAL_SYMBOL_TYPE, \ 319 V(EXTERNAL_SYMBOL_TYPE, \
320 ExternalTwoByteString::kSize, \ 320 ExternalTwoByteString::kSize, \
321 external_symbol, \ 321 external_symbol, \
322 ExternalSymbol) \ 322 ExternalSymbol) \
323 V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \
324 ExternalTwoByteString::kSize, \
325 external_symbol_with_ascii_data, \
326 ExternalSymbolWithAsciiData) \
323 V(EXTERNAL_ASCII_SYMBOL_TYPE, \ 327 V(EXTERNAL_ASCII_SYMBOL_TYPE, \
324 ExternalAsciiString::kSize, \ 328 ExternalAsciiString::kSize, \
325 external_ascii_symbol, \ 329 external_ascii_symbol, \
326 ExternalAsciiSymbol) \ 330 ExternalAsciiSymbol) \
327 V(STRING_TYPE, \ 331 V(STRING_TYPE, \
328 SeqTwoByteString::kAlignedSize, \ 332 SeqTwoByteString::kAlignedSize, \
329 string, \ 333 string, \
330 String) \ 334 String) \
331 V(ASCII_STRING_TYPE, \ 335 V(ASCII_STRING_TYPE, \
332 SeqAsciiString::kAlignedSize, \ 336 SeqAsciiString::kAlignedSize, \
333 ascii_string, \ 337 ascii_string, \
334 AsciiString) \ 338 AsciiString) \
335 V(CONS_STRING_TYPE, \ 339 V(CONS_STRING_TYPE, \
336 ConsString::kSize, \ 340 ConsString::kSize, \
337 cons_string, \ 341 cons_string, \
338 ConsString) \ 342 ConsString) \
339 V(CONS_ASCII_STRING_TYPE, \ 343 V(CONS_ASCII_STRING_TYPE, \
340 ConsString::kSize, \ 344 ConsString::kSize, \
341 cons_ascii_string, \ 345 cons_ascii_string, \
342 ConsAsciiString) \ 346 ConsAsciiString) \
343 V(EXTERNAL_STRING_TYPE, \ 347 V(EXTERNAL_STRING_TYPE, \
344 ExternalTwoByteString::kSize, \ 348 ExternalTwoByteString::kSize, \
345 external_string, \ 349 external_string, \
346 ExternalString) \ 350 ExternalString) \
351 V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \
352 ExternalTwoByteString::kSize, \
353 external_string_with_ascii_data, \
354 ExternalStringWithAsciiData) \
347 V(EXTERNAL_ASCII_STRING_TYPE, \ 355 V(EXTERNAL_ASCII_STRING_TYPE, \
348 ExternalAsciiString::kSize, \ 356 ExternalAsciiString::kSize, \
349 external_ascii_string, \ 357 external_ascii_string, \
350 ExternalAsciiString) \ 358 ExternalAsciiString) \
351 359
352 // A struct is a simple object a set of object-valued fields. Including an 360 // A struct is a simple object a set of object-valued fields. Including an
353 // object type in this causes the compiler to generate most of the boilerplate 361 // object type in this causes the compiler to generate most of the boilerplate
354 // code for the class including allocation and garbage collection routines, 362 // code for the class including allocation and garbage collection routines,
355 // casts and predicates. All you need to define is the class, methods and 363 // casts and predicates. All you need to define is the class, methods and
356 // object verification routines. Easy, no? 364 // object verification routines. Easy, no?
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 // If bit 7 is clear, the low-order 2 bits indicate the representation 413 // If bit 7 is clear, the low-order 2 bits indicate the representation
406 // of the string. 414 // of the string.
407 const uint32_t kStringRepresentationMask = 0x03; 415 const uint32_t kStringRepresentationMask = 0x03;
408 enum StringRepresentationTag { 416 enum StringRepresentationTag {
409 kSeqStringTag = 0x0, 417 kSeqStringTag = 0x0,
410 kConsStringTag = 0x1, 418 kConsStringTag = 0x1,
411 kExternalStringTag = 0x2 419 kExternalStringTag = 0x2
412 }; 420 };
413 const uint32_t kIsConsStringMask = 0x1; 421 const uint32_t kIsConsStringMask = 0x1;
414 422
423 // If bit 7 is clear, then bit 3 indicates whether this two-byte
424 // string actually contains ascii data.
425 const uint32_t kAsciiDataHintMask = 0x08;
426 const uint32_t kAsciiDataHintTag = 0x08;
427
415 428
416 // A ConsString with an empty string as the right side is a candidate 429 // A ConsString with an empty string as the right side is a candidate
417 // for being shortcut by the garbage collector unless it is a 430 // for being shortcut by the garbage collector unless it is a
418 // symbol. It's not common to have non-flat symbols, so we do not 431 // symbol. It's not common to have non-flat symbols, so we do not
419 // shortcut them thereby avoiding turning symbols into strings. See 432 // shortcut them thereby avoiding turning symbols into strings. See
420 // heap.cc and mark-compact.cc. 433 // heap.cc and mark-compact.cc.
421 const uint32_t kShortcutTypeMask = 434 const uint32_t kShortcutTypeMask =
422 kIsNotStringMask | 435 kIsNotStringMask |
423 kIsSymbolMask | 436 kIsSymbolMask |
424 kStringRepresentationMask; 437 kStringRepresentationMask;
425 const uint32_t kShortcutTypeTag = kConsStringTag; 438 const uint32_t kShortcutTypeTag = kConsStringTag;
426 439
427 440
428 enum InstanceType { 441 enum InstanceType {
429 // String types. 442 // String types.
430 SYMBOL_TYPE = kSymbolTag | kSeqStringTag, 443 SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kSeqStringTag,
431 ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kSeqStringTag, 444 ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kSeqStringTag,
432 CONS_SYMBOL_TYPE = kSymbolTag | kConsStringTag, 445 CONS_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kConsStringTag,
433 CONS_ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kConsStringTag, 446 CONS_ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kConsStringTag,
434 EXTERNAL_SYMBOL_TYPE = kSymbolTag | kExternalStringTag, 447 EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kExternalStringTag,
448 EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE =
449 kTwoByteStringTag | kSymbolTag | kExternalStringTag | kAsciiDataHintTag,
435 EXTERNAL_ASCII_SYMBOL_TYPE = 450 EXTERNAL_ASCII_SYMBOL_TYPE =
436 kAsciiStringTag | kSymbolTag | kExternalStringTag, 451 kAsciiStringTag | kSymbolTag | kExternalStringTag,
437 STRING_TYPE = kSeqStringTag, 452 STRING_TYPE = kTwoByteStringTag | kSeqStringTag,
438 ASCII_STRING_TYPE = kAsciiStringTag | kSeqStringTag, 453 ASCII_STRING_TYPE = kAsciiStringTag | kSeqStringTag,
439 CONS_STRING_TYPE = kConsStringTag, 454 CONS_STRING_TYPE = kTwoByteStringTag | kConsStringTag,
440 CONS_ASCII_STRING_TYPE = kAsciiStringTag | kConsStringTag, 455 CONS_ASCII_STRING_TYPE = kAsciiStringTag | kConsStringTag,
441 EXTERNAL_STRING_TYPE = kExternalStringTag, 456 EXTERNAL_STRING_TYPE = kTwoByteStringTag | kExternalStringTag,
457 EXTERNAL_STRING_WITH_ASCII_DATA_TYPE =
458 kTwoByteStringTag | kExternalStringTag | kAsciiDataHintTag,
442 EXTERNAL_ASCII_STRING_TYPE = kAsciiStringTag | kExternalStringTag, 459 EXTERNAL_ASCII_STRING_TYPE = kAsciiStringTag | kExternalStringTag,
443 PRIVATE_EXTERNAL_ASCII_STRING_TYPE = EXTERNAL_ASCII_STRING_TYPE, 460 PRIVATE_EXTERNAL_ASCII_STRING_TYPE = EXTERNAL_ASCII_STRING_TYPE,
444 461
445 // Objects allocated in their own spaces (never in new space). 462 // Objects allocated in their own spaces (never in new space).
446 MAP_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE 463 MAP_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE
447 CODE_TYPE, 464 CODE_TYPE,
448 ODDBALL_TYPE, 465 ODDBALL_TYPE,
449 JS_GLOBAL_PROPERTY_CELL_TYPE, 466 JS_GLOBAL_PROPERTY_CELL_TYPE,
450 467
451 // "Data", objects that cannot contain non-map-word pointers to heap 468 // "Data", objects that cannot contain non-map-word pointers to heap
(...skipping 3605 matching lines...) Expand 10 before | Expand all | Expand 10 after
4057 inline int length(); 4074 inline int length();
4058 inline void set_length(int value); 4075 inline void set_length(int value);
4059 4076
4060 // Get and set the hash field of the string. 4077 // Get and set the hash field of the string.
4061 inline uint32_t hash_field(); 4078 inline uint32_t hash_field();
4062 inline void set_hash_field(uint32_t value); 4079 inline void set_hash_field(uint32_t value);
4063 4080
4064 inline bool IsAsciiRepresentation(); 4081 inline bool IsAsciiRepresentation();
4065 inline bool IsTwoByteRepresentation(); 4082 inline bool IsTwoByteRepresentation();
4066 4083
4067 // Check whether this string is an external two-byte string that in 4084 // Returns whether this string has ascii chars, i.e. all of them can
4068 // fact contains only ascii characters. 4085 // be ascii encoded. This might be the case even if the string is
4086 // two-byte. Such strings may appear when the embedder prefers
4087 // two-byte external representations even for ascii data.
4069 // 4088 //
4070 // Such strings may appear when the embedder prefers two-byte 4089 // NOTE: this should be considered only a hint. False negatives are
4071 // representations even for ascii data. 4090 // possible.
4072 inline bool IsExternalTwoByteStringWithAsciiChars(); 4091 inline bool HasAsciiChars();
4073 4092
4074 // Get and set individual two byte chars in the string. 4093 // Get and set individual two byte chars in the string.
4075 inline void Set(int index, uint16_t value); 4094 inline void Set(int index, uint16_t value);
4076 // Get individual two byte char in the string. Repeated calls 4095 // Get individual two byte char in the string. Repeated calls
4077 // to this method are not efficient unless the string is flat. 4096 // to this method are not efficient unless the string is flat.
4078 inline uint16_t Get(int index); 4097 inline uint16_t Get(int index);
4079 4098
4080 // Try to flatten the string. Checks first inline to see if it is 4099 // Try to flatten the string. Checks first inline to see if it is
4081 // necessary. Does nothing if the string is not a cons string. 4100 // necessary. Does nothing if the string is not a cons string.
4082 // Flattening allocates a sequential string with the same data as 4101 // Flattening allocates a sequential string with the same data as
(...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after
5278 } else { 5297 } else {
5279 value &= ~(1 << bit_position); 5298 value &= ~(1 << bit_position);
5280 } 5299 }
5281 return value; 5300 return value;
5282 } 5301 }
5283 }; 5302 };
5284 5303
5285 } } // namespace v8::internal 5304 } } // namespace v8::internal
5286 5305
5287 #endif // V8_OBJECTS_H_ 5306 #endif // V8_OBJECTS_H_
OLDNEW
« no previous file with comments | « src/ia32/codegen-ia32.cc ('k') | src/objects.cc » ('j') | src/objects-inl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698