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

Side by Side Diff: src/heap.cc

Issue 45010: Remove all uses of StringShape variables, since that has proven... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 9 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/heap.h ('k') | src/interpreter-irregexp.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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 #elif defined(DEBUG) 223 #elif defined(DEBUG)
224 if (FLAG_heap_stats) ReportHeapStatistics("After GC"); 224 if (FLAG_heap_stats) ReportHeapStatistics("After GC");
225 #elif defined(ENABLE_LOGGING_AND_PROFILING) 225 #elif defined(ENABLE_LOGGING_AND_PROFILING)
226 if (FLAG_log_gc) new_space_.ReportStatistics(); 226 if (FLAG_log_gc) new_space_.ReportStatistics();
227 #endif 227 #endif
228 } 228 }
229 #endif // defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING) 229 #endif // defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING)
230 230
231 231
232 void Heap::GarbageCollectionPrologue() { 232 void Heap::GarbageCollectionPrologue() {
233 RegExpImpl::NewSpaceCollectionPrologue();
234 gc_count_++; 233 gc_count_++;
235 #ifdef DEBUG 234 #ifdef DEBUG
236 ASSERT(allocation_allowed_ && gc_state_ == NOT_IN_GC); 235 ASSERT(allocation_allowed_ && gc_state_ == NOT_IN_GC);
237 allow_allocation(false); 236 allow_allocation(false);
238 237
239 if (FLAG_verify_heap) { 238 if (FLAG_verify_heap) {
240 Verify(); 239 Verify();
241 } 240 }
242 241
243 if (FLAG_gc_verbose) Print(); 242 if (FLAG_gc_verbose) Print();
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 context_disposed_pending_ = false; 467 context_disposed_pending_ = false;
469 } 468 }
470 469
471 470
472 void Heap::MarkCompactPrologue(bool is_compacting) { 471 void Heap::MarkCompactPrologue(bool is_compacting) {
473 // At any old GC clear the keyed lookup cache to enable collection of unused 472 // At any old GC clear the keyed lookup cache to enable collection of unused
474 // maps. 473 // maps.
475 ClearKeyedLookupCache(); 474 ClearKeyedLookupCache();
476 475
477 CompilationCache::MarkCompactPrologue(); 476 CompilationCache::MarkCompactPrologue();
478 RegExpImpl::OldSpaceCollectionPrologue();
479 477
480 Top::MarkCompactPrologue(is_compacting); 478 Top::MarkCompactPrologue(is_compacting);
481 ThreadManager::MarkCompactPrologue(is_compacting); 479 ThreadManager::MarkCompactPrologue(is_compacting);
482 } 480 }
483 481
484 482
485 void Heap::MarkCompactEpilogue(bool is_compacting) { 483 void Heap::MarkCompactEpilogue(bool is_compacting) {
486 Top::MarkCompactEpilogue(is_compacting); 484 Top::MarkCompactEpilogue(is_compacting);
487 ThreadManager::MarkCompactEpilogue(is_compacting); 485 ThreadManager::MarkCompactEpilogue(is_compacting);
488 Heap::has_store_ics_ = false; 486 Heap::has_store_ics_ = false;
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 share->set_lazy_load_data(undefined_value()); 1383 share->set_lazy_load_data(undefined_value());
1386 share->set_script(undefined_value()); 1384 share->set_script(undefined_value());
1387 share->set_start_position_and_type(0); 1385 share->set_start_position_and_type(0);
1388 share->set_debug_info(undefined_value()); 1386 share->set_debug_info(undefined_value());
1389 return result; 1387 return result;
1390 } 1388 }
1391 1389
1392 1390
1393 Object* Heap::AllocateConsString(String* first, 1391 Object* Heap::AllocateConsString(String* first,
1394 String* second) { 1392 String* second) {
1395 StringShape first_shape(first); 1393 int first_length = first->length();
1396 StringShape second_shape(second); 1394 int second_length = second->length();
1397 int first_length = first->length(first_shape);
1398 int second_length = second->length(second_shape);
1399 int length = first_length + second_length; 1395 int length = first_length + second_length;
1400 bool is_ascii = first_shape.IsAsciiRepresentation() 1396 bool is_ascii = StringShape(first).IsAsciiRepresentation()
1401 && second_shape.IsAsciiRepresentation(); 1397 && StringShape(second).IsAsciiRepresentation();
1402 1398
1403 // If the resulting string is small make a flat string. 1399 // If the resulting string is small make a flat string.
1404 if (length < String::kMinNonFlatLength) { 1400 if (length < String::kMinNonFlatLength) {
1405 ASSERT(first->IsFlat(first_shape)); 1401 ASSERT(first->IsFlat());
1406 ASSERT(second->IsFlat(second_shape)); 1402 ASSERT(second->IsFlat());
1407 if (is_ascii) { 1403 if (is_ascii) {
1408 Object* result = AllocateRawAsciiString(length); 1404 Object* result = AllocateRawAsciiString(length);
1409 if (result->IsFailure()) return result; 1405 if (result->IsFailure()) return result;
1410 // Copy the characters into the new object. 1406 // Copy the characters into the new object.
1411 char* dest = SeqAsciiString::cast(result)->GetChars(); 1407 char* dest = SeqAsciiString::cast(result)->GetChars();
1412 String::WriteToFlat(first, first_shape, dest, 0, first_length); 1408 String::WriteToFlat(first, dest, 0, first_length);
1413 String::WriteToFlat(second, 1409 String::WriteToFlat(second, dest + first_length, 0, second_length);
1414 second_shape,
1415 dest + first_length,
1416 0,
1417 second_length);
1418 return result; 1410 return result;
1419 } else { 1411 } else {
1420 Object* result = AllocateRawTwoByteString(length); 1412 Object* result = AllocateRawTwoByteString(length);
1421 if (result->IsFailure()) return result; 1413 if (result->IsFailure()) return result;
1422 // Copy the characters into the new object. 1414 // Copy the characters into the new object.
1423 uc16* dest = SeqTwoByteString::cast(result)->GetChars(); 1415 uc16* dest = SeqTwoByteString::cast(result)->GetChars();
1424 String::WriteToFlat(first, first_shape, dest, 0, first_length); 1416 String::WriteToFlat(first, dest, 0, first_length);
1425 String::WriteToFlat(second, 1417 String::WriteToFlat(second, dest + first_length, 0, second_length);
1426 second_shape,
1427 dest + first_length,
1428 0,
1429 second_length);
1430 return result; 1418 return result;
1431 } 1419 }
1432 } 1420 }
1433 1421
1434 Map* map; 1422 Map* map;
1435 if (length <= String::kMaxShortStringSize) { 1423 if (length <= String::kMaxShortStringSize) {
1436 map = is_ascii ? short_cons_ascii_string_map() 1424 map = is_ascii ? short_cons_ascii_string_map()
1437 : short_cons_string_map(); 1425 : short_cons_string_map();
1438 } else if (length <= String::kMaxMediumStringSize) { 1426 } else if (length <= String::kMaxMediumStringSize) {
1439 map = is_ascii ? medium_cons_ascii_string_map() 1427 map = is_ascii ? medium_cons_ascii_string_map()
(...skipping 10 matching lines...) Expand all
1450 cons_string->set_first(first, SKIP_WRITE_BARRIER); 1438 cons_string->set_first(first, SKIP_WRITE_BARRIER);
1451 cons_string->set_second(second, SKIP_WRITE_BARRIER); 1439 cons_string->set_second(second, SKIP_WRITE_BARRIER);
1452 cons_string->set_length(length); 1440 cons_string->set_length(length);
1453 return result; 1441 return result;
1454 } 1442 }
1455 1443
1456 1444
1457 Object* Heap::AllocateSlicedString(String* buffer, 1445 Object* Heap::AllocateSlicedString(String* buffer,
1458 int start, 1446 int start,
1459 int end) { 1447 int end) {
1460 StringShape buffer_shape(buffer);
1461 int length = end - start; 1448 int length = end - start;
1462 1449
1463 // If the resulting string is small make a sub string. 1450 // If the resulting string is small make a sub string.
1464 if (end - start <= String::kMinNonFlatLength) { 1451 if (end - start <= String::kMinNonFlatLength) {
1465 return Heap::AllocateSubString(buffer, buffer_shape, start, end); 1452 return Heap::AllocateSubString(buffer, start, end);
1466 } 1453 }
1467 1454
1468 Map* map; 1455 Map* map;
1469 if (length <= String::kMaxShortStringSize) { 1456 if (length <= String::kMaxShortStringSize) {
1470 map = buffer_shape.IsAsciiRepresentation() ? 1457 map = StringShape(buffer).IsAsciiRepresentation() ?
1471 short_sliced_ascii_string_map() : 1458 short_sliced_ascii_string_map() :
1472 short_sliced_string_map(); 1459 short_sliced_string_map();
1473 } else if (length <= String::kMaxMediumStringSize) { 1460 } else if (length <= String::kMaxMediumStringSize) {
1474 map = buffer_shape.IsAsciiRepresentation() ? 1461 map = StringShape(buffer).IsAsciiRepresentation() ?
1475 medium_sliced_ascii_string_map() : 1462 medium_sliced_ascii_string_map() :
1476 medium_sliced_string_map(); 1463 medium_sliced_string_map();
1477 } else { 1464 } else {
1478 map = buffer_shape.IsAsciiRepresentation() ? 1465 map = StringShape(buffer).IsAsciiRepresentation() ?
1479 long_sliced_ascii_string_map() : 1466 long_sliced_ascii_string_map() :
1480 long_sliced_string_map(); 1467 long_sliced_string_map();
1481 } 1468 }
1482 1469
1483 Object* result = Allocate(map, NEW_SPACE); 1470 Object* result = Allocate(map, NEW_SPACE);
1484 if (result->IsFailure()) return result; 1471 if (result->IsFailure()) return result;
1485 1472
1486 SlicedString* sliced_string = SlicedString::cast(result); 1473 SlicedString* sliced_string = SlicedString::cast(result);
1487 sliced_string->set_buffer(buffer); 1474 sliced_string->set_buffer(buffer);
1488 sliced_string->set_start(start); 1475 sliced_string->set_start(start);
1489 sliced_string->set_length(length); 1476 sliced_string->set_length(length);
1490 1477
1491 return result; 1478 return result;
1492 } 1479 }
1493 1480
1494 1481
1495 Object* Heap::AllocateSubString(String* buffer, 1482 Object* Heap::AllocateSubString(String* buffer,
1496 StringShape buffer_shape,
1497 int start, 1483 int start,
1498 int end) { 1484 int end) {
1499 int length = end - start; 1485 int length = end - start;
1500 1486
1501 if (length == 1) { 1487 if (length == 1) {
1502 return Heap::LookupSingleCharacterStringFromCode( 1488 return Heap::LookupSingleCharacterStringFromCode(
1503 buffer->Get(buffer_shape, start)); 1489 buffer->Get(start));
1504 } 1490 }
1505 1491
1506 // Make an attempt to flatten the buffer to reduce access time. 1492 // Make an attempt to flatten the buffer to reduce access time.
1507 if (!buffer->IsFlat(buffer_shape)) { 1493 if (!buffer->IsFlat()) {
1508 buffer->TryFlatten(buffer_shape); 1494 buffer->TryFlatten();
1509 buffer_shape = StringShape(buffer);
1510 } 1495 }
1511 1496
1512 Object* result = buffer_shape.IsAsciiRepresentation() 1497 Object* result = StringShape(buffer).IsAsciiRepresentation()
1513 ? AllocateRawAsciiString(length) 1498 ? AllocateRawAsciiString(length)
1514 : AllocateRawTwoByteString(length); 1499 : AllocateRawTwoByteString(length);
1515 if (result->IsFailure()) return result; 1500 if (result->IsFailure()) return result;
1516 1501
1517 // Copy the characters into the new object. 1502 // Copy the characters into the new object.
1518 String* string_result = String::cast(result); 1503 String* string_result = String::cast(result);
1519 StringShape result_shape(string_result);
1520 StringHasher hasher(length); 1504 StringHasher hasher(length);
1521 int i = 0; 1505 int i = 0;
1522 for (; i < length && hasher.is_array_index(); i++) { 1506 for (; i < length && hasher.is_array_index(); i++) {
1523 uc32 c = buffer->Get(buffer_shape, start + i); 1507 uc32 c = buffer->Get(start + i);
1524 hasher.AddCharacter(c); 1508 hasher.AddCharacter(c);
1525 string_result->Set(result_shape, i, c); 1509 string_result->Set(i, c);
1526 } 1510 }
1527 for (; i < length; i++) { 1511 for (; i < length; i++) {
1528 uc32 c = buffer->Get(buffer_shape, start + i); 1512 uc32 c = buffer->Get(start + i);
1529 hasher.AddCharacterNoIndex(c); 1513 hasher.AddCharacterNoIndex(c);
1530 string_result->Set(result_shape, i, c); 1514 string_result->Set(i, c);
1531 } 1515 }
1532 string_result->set_length_field(hasher.GetHashField()); 1516 string_result->set_length_field(hasher.GetHashField());
1533 return result; 1517 return result;
1534 } 1518 }
1535 1519
1536 1520
1537 Object* Heap::AllocateExternalStringFromAscii( 1521 Object* Heap::AllocateExternalStringFromAscii(
1538 ExternalAsciiString::Resource* resource) { 1522 ExternalAsciiString::Resource* resource) {
1539 Map* map; 1523 Map* map;
1540 int length = resource->length(); 1524 int length = resource->length();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1583 Object* result = LookupSymbol(Vector<const char>(buffer, 1)); 1567 Object* result = LookupSymbol(Vector<const char>(buffer, 1));
1584 1568
1585 if (result->IsFailure()) return result; 1569 if (result->IsFailure()) return result;
1586 Heap::single_character_string_cache()->set(code, result); 1570 Heap::single_character_string_cache()->set(code, result);
1587 return result; 1571 return result;
1588 } 1572 }
1589 1573
1590 Object* result = Heap::AllocateRawTwoByteString(1); 1574 Object* result = Heap::AllocateRawTwoByteString(1);
1591 if (result->IsFailure()) return result; 1575 if (result->IsFailure()) return result;
1592 String* answer = String::cast(result); 1576 String* answer = String::cast(result);
1593 answer->Set(StringShape(answer), 0, code); 1577 answer->Set(0, code);
1594 return answer; 1578 return answer;
1595 } 1579 }
1596 1580
1597 1581
1598 Object* Heap::AllocateByteArray(int length, PretenureFlag pretenure) { 1582 Object* Heap::AllocateByteArray(int length, PretenureFlag pretenure) {
1599 if (pretenure == NOT_TENURED) { 1583 if (pretenure == NOT_TENURED) {
1600 return AllocateByteArray(length); 1584 return AllocateByteArray(length);
1601 } 1585 }
1602 int size = ByteArray::SizeFor(length); 1586 int size = ByteArray::SizeFor(length);
1603 AllocationSpace space = 1587 AllocationSpace space =
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
2009 // If the string is ascii, we do not need to convert the characters 1993 // If the string is ascii, we do not need to convert the characters
2010 // since UTF8 is backwards compatible with ascii. 1994 // since UTF8 is backwards compatible with ascii.
2011 if (is_ascii) return AllocateStringFromAscii(string, pretenure); 1995 if (is_ascii) return AllocateStringFromAscii(string, pretenure);
2012 1996
2013 Object* result = AllocateRawTwoByteString(chars, pretenure); 1997 Object* result = AllocateRawTwoByteString(chars, pretenure);
2014 if (result->IsFailure()) return result; 1998 if (result->IsFailure()) return result;
2015 1999
2016 // Convert and copy the characters into the new object. 2000 // Convert and copy the characters into the new object.
2017 String* string_result = String::cast(result); 2001 String* string_result = String::cast(result);
2018 decoder->Reset(string.start(), string.length()); 2002 decoder->Reset(string.start(), string.length());
2019 StringShape result_shape(string_result);
2020 for (int i = 0; i < chars; i++) { 2003 for (int i = 0; i < chars; i++) {
2021 uc32 r = decoder->GetNext(); 2004 uc32 r = decoder->GetNext();
2022 string_result->Set(result_shape, i, r); 2005 string_result->Set(i, r);
2023 } 2006 }
2024 return result; 2007 return result;
2025 } 2008 }
2026 2009
2027 2010
2028 Object* Heap::AllocateStringFromTwoByte(Vector<const uc16> string, 2011 Object* Heap::AllocateStringFromTwoByte(Vector<const uc16> string,
2029 PretenureFlag pretenure) { 2012 PretenureFlag pretenure) {
2030 // Check if the string is an ASCII string. 2013 // Check if the string is an ASCII string.
2031 int i = 0; 2014 int i = 0;
2032 while (i < string.length() && string[i] <= String::kMaxAsciiCharCode) i++; 2015 while (i < string.length() && string[i] <= String::kMaxAsciiCharCode) i++;
2033 2016
2034 Object* result; 2017 Object* result;
2035 if (i == string.length()) { // It's an ASCII string. 2018 if (i == string.length()) { // It's an ASCII string.
2036 result = AllocateRawAsciiString(string.length(), pretenure); 2019 result = AllocateRawAsciiString(string.length(), pretenure);
2037 } else { // It's not an ASCII string. 2020 } else { // It's not an ASCII string.
2038 result = AllocateRawTwoByteString(string.length(), pretenure); 2021 result = AllocateRawTwoByteString(string.length(), pretenure);
2039 } 2022 }
2040 if (result->IsFailure()) return result; 2023 if (result->IsFailure()) return result;
2041 2024
2042 // Copy the characters into the new object, which may be either ASCII or 2025 // Copy the characters into the new object, which may be either ASCII or
2043 // UTF-16. 2026 // UTF-16.
2044 String* string_result = String::cast(result); 2027 String* string_result = String::cast(result);
2045 StringShape result_shape(string_result);
2046 for (int i = 0; i < string.length(); i++) { 2028 for (int i = 0; i < string.length(); i++) {
2047 string_result->Set(result_shape, i, string[i]); 2029 string_result->Set(i, string[i]);
2048 } 2030 }
2049 return result; 2031 return result;
2050 } 2032 }
2051 2033
2052 2034
2053 Map* Heap::SymbolMapForString(String* string) { 2035 Map* Heap::SymbolMapForString(String* string) {
2054 // If the string is in new space it cannot be used as a symbol. 2036 // If the string is in new space it cannot be used as a symbol.
2055 if (InNewSpace(string)) return NULL; 2037 if (InNewSpace(string)) return NULL;
2056 2038
2057 // Find the corresponding symbol map for strings. 2039 // Find the corresponding symbol map for strings.
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
2156 2138
2157 // Allocate string. 2139 // Allocate string.
2158 AllocationSpace space = 2140 AllocationSpace space =
2159 (size > MaxHeapObjectSize()) ? LO_SPACE : OLD_DATA_SPACE; 2141 (size > MaxHeapObjectSize()) ? LO_SPACE : OLD_DATA_SPACE;
2160 Object* result = AllocateRaw(size, space, OLD_DATA_SPACE); 2142 Object* result = AllocateRaw(size, space, OLD_DATA_SPACE);
2161 if (result->IsFailure()) return result; 2143 if (result->IsFailure()) return result;
2162 2144
2163 reinterpret_cast<HeapObject*>(result)->set_map(map); 2145 reinterpret_cast<HeapObject*>(result)->set_map(map);
2164 // The hash value contains the length of the string. 2146 // The hash value contains the length of the string.
2165 String* answer = String::cast(result); 2147 String* answer = String::cast(result);
2166 StringShape answer_shape(answer);
2167 answer->set_length_field(length_field); 2148 answer->set_length_field(length_field);
2168 2149
2169 ASSERT_EQ(size, answer->Size()); 2150 ASSERT_EQ(size, answer->Size());
2170 2151
2171 // Fill in the characters. 2152 // Fill in the characters.
2172 for (int i = 0; i < chars; i++) { 2153 for (int i = 0; i < chars; i++) {
2173 answer->Set(answer_shape, i, buffer->GetNext()); 2154 answer->Set(i, buffer->GetNext());
2174 } 2155 }
2175 return answer; 2156 return answer;
2176 } 2157 }
2177 2158
2178 2159
2179 Object* Heap::AllocateRawAsciiString(int length, PretenureFlag pretenure) { 2160 Object* Heap::AllocateRawAsciiString(int length, PretenureFlag pretenure) {
2180 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; 2161 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
2181 int size = SeqAsciiString::SizeFor(length); 2162 int size = SeqAsciiString::SizeFor(length);
2182 if (size > MaxHeapObjectSize()) { 2163 if (size > MaxHeapObjectSize()) {
2183 space = LO_SPACE; 2164 space = LO_SPACE;
(...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after
3344 #ifdef DEBUG 3325 #ifdef DEBUG
3345 bool Heap::GarbageCollectionGreedyCheck() { 3326 bool Heap::GarbageCollectionGreedyCheck() {
3346 ASSERT(FLAG_gc_greedy); 3327 ASSERT(FLAG_gc_greedy);
3347 if (Bootstrapper::IsActive()) return true; 3328 if (Bootstrapper::IsActive()) return true;
3348 if (disallow_allocation_failure()) return true; 3329 if (disallow_allocation_failure()) return true;
3349 return CollectGarbage(0, NEW_SPACE); 3330 return CollectGarbage(0, NEW_SPACE);
3350 } 3331 }
3351 #endif 3332 #endif
3352 3333
3353 } } // namespace v8::internal 3334 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.h ('k') | src/interpreter-irregexp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698