| OLD | NEW |
| 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 30 matching lines...) Expand all Loading... |
| 41 #include "mark-compact.h" | 41 #include "mark-compact.h" |
| 42 #include "natives.h" | 42 #include "natives.h" |
| 43 #include "objects-visiting.h" | 43 #include "objects-visiting.h" |
| 44 #include "objects-visiting-inl.h" | 44 #include "objects-visiting-inl.h" |
| 45 #include "once.h" | 45 #include "once.h" |
| 46 #include "runtime-profiler.h" | 46 #include "runtime-profiler.h" |
| 47 #include "scopeinfo.h" | 47 #include "scopeinfo.h" |
| 48 #include "snapshot.h" | 48 #include "snapshot.h" |
| 49 #include "store-buffer.h" | 49 #include "store-buffer.h" |
| 50 #include "v8threads.h" | 50 #include "v8threads.h" |
| 51 #include "v8utils.h" |
| 51 #include "vm-state-inl.h" | 52 #include "vm-state-inl.h" |
| 52 #if V8_TARGET_ARCH_ARM && !V8_INTERPRETED_REGEXP | 53 #if V8_TARGET_ARCH_ARM && !V8_INTERPRETED_REGEXP |
| 53 #include "regexp-macro-assembler.h" | 54 #include "regexp-macro-assembler.h" |
| 54 #include "arm/regexp-macro-assembler-arm.h" | 55 #include "arm/regexp-macro-assembler-arm.h" |
| 55 #endif | 56 #endif |
| 56 #if V8_TARGET_ARCH_MIPS && !V8_INTERPRETED_REGEXP | 57 #if V8_TARGET_ARCH_MIPS && !V8_INTERPRETED_REGEXP |
| 57 #include "regexp-macro-assembler.h" | 58 #include "regexp-macro-assembler.h" |
| 58 #include "mips/regexp-macro-assembler-mips.h" | 59 #include "mips/regexp-macro-assembler-mips.h" |
| 59 #endif | 60 #endif |
| 60 | 61 |
| (...skipping 4322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4383 object->set_map(constructor->initial_map()); | 4384 object->set_map(constructor->initial_map()); |
| 4384 | 4385 |
| 4385 // Reinitialize the object from the constructor map. | 4386 // Reinitialize the object from the constructor map. |
| 4386 InitializeJSObjectFromMap(object, FixedArray::cast(properties), map); | 4387 InitializeJSObjectFromMap(object, FixedArray::cast(properties), map); |
| 4387 return object; | 4388 return object; |
| 4388 } | 4389 } |
| 4389 | 4390 |
| 4390 | 4391 |
| 4391 MaybeObject* Heap::AllocateStringFromAscii(Vector<const char> string, | 4392 MaybeObject* Heap::AllocateStringFromAscii(Vector<const char> string, |
| 4392 PretenureFlag pretenure) { | 4393 PretenureFlag pretenure) { |
| 4393 if (string.length() == 1) { | 4394 int length = string.length(); |
| 4395 if (length == 1) { |
| 4394 return Heap::LookupSingleCharacterStringFromCode(string[0]); | 4396 return Heap::LookupSingleCharacterStringFromCode(string[0]); |
| 4395 } | 4397 } |
| 4396 Object* result; | 4398 Object* result; |
| 4397 { MaybeObject* maybe_result = | 4399 { MaybeObject* maybe_result = |
| 4398 AllocateRawAsciiString(string.length(), pretenure); | 4400 AllocateRawAsciiString(string.length(), pretenure); |
| 4399 if (!maybe_result->ToObject(&result)) return maybe_result; | 4401 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 4400 } | 4402 } |
| 4401 | 4403 |
| 4402 // Copy the characters into the new object. | 4404 // Copy the characters into the new object. |
| 4403 SeqAsciiString* string_result = SeqAsciiString::cast(result); | 4405 CopyChars(SeqAsciiString::cast(result)->GetChars(), string.start(), length); |
| 4404 for (int i = 0; i < string.length(); i++) { | |
| 4405 string_result->SeqAsciiStringSet(i, string[i]); | |
| 4406 } | |
| 4407 return result; | 4406 return result; |
| 4408 } | 4407 } |
| 4409 | 4408 |
| 4410 | 4409 |
| 4411 MaybeObject* Heap::AllocateStringFromUtf8Slow(Vector<const char> string, | 4410 MaybeObject* Heap::AllocateStringFromUtf8Slow(Vector<const char> string, |
| 4412 PretenureFlag pretenure) { | 4411 PretenureFlag pretenure) { |
| 4413 // Count the number of characters in the UTF-8 string and check if | 4412 // Count the number of characters in the UTF-8 string and check if |
| 4414 // it is an ASCII string. | 4413 // it is an ASCII string. |
| 4415 Access<UnicodeCache::Utf8Decoder> | 4414 Access<UnicodeCache::Utf8Decoder> |
| 4416 decoder(isolate_->unicode_cache()->utf8_decoder()); | 4415 decoder(isolate_->unicode_cache()->utf8_decoder()); |
| 4417 decoder->Reset(string.start(), string.length()); | 4416 decoder->Reset(string.start(), string.length()); |
| 4418 int chars = 0; | 4417 int chars = 0; |
| 4419 while (decoder->has_more()) { | 4418 while (decoder->has_more()) { |
| 4420 uint32_t r = decoder->GetNext(); | 4419 uint32_t r = decoder->GetNext(); |
| 4421 if (r <= unibrow::Utf16::kMaxNonSurrogateCharCode) { | 4420 if (r <= unibrow::Utf16::kMaxNonSurrogateCharCode) { |
| 4422 chars++; | 4421 chars++; |
| 4423 } else { | 4422 } else { |
| 4424 chars += 2; | 4423 chars += 2; |
| 4425 } | 4424 } |
| 4426 } | 4425 } |
| 4427 | 4426 |
| 4428 Object* result; | 4427 Object* result; |
| 4429 { MaybeObject* maybe_result = AllocateRawTwoByteString(chars, pretenure); | 4428 { MaybeObject* maybe_result = AllocateRawTwoByteString(chars, pretenure); |
| 4430 if (!maybe_result->ToObject(&result)) return maybe_result; | 4429 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 4431 } | 4430 } |
| 4432 | 4431 |
| 4433 // Convert and copy the characters into the new object. | 4432 // Convert and copy the characters into the new object. |
| 4434 String* string_result = String::cast(result); | 4433 SeqTwoByteString* twobyte = SeqTwoByteString::cast(result); |
| 4435 decoder->Reset(string.start(), string.length()); | 4434 decoder->Reset(string.start(), string.length()); |
| 4436 int i = 0; | 4435 int i = 0; |
| 4437 while (i < chars) { | 4436 while (i < chars) { |
| 4438 uint32_t r = decoder->GetNext(); | 4437 uint32_t r = decoder->GetNext(); |
| 4439 if (r > unibrow::Utf16::kMaxNonSurrogateCharCode) { | 4438 if (r > unibrow::Utf16::kMaxNonSurrogateCharCode) { |
| 4440 string_result->Set(i++, unibrow::Utf16::LeadSurrogate(r)); | 4439 twobyte->SeqTwoByteStringSet(i++, unibrow::Utf16::LeadSurrogate(r)); |
| 4441 string_result->Set(i++, unibrow::Utf16::TrailSurrogate(r)); | 4440 twobyte->SeqTwoByteStringSet(i++, unibrow::Utf16::TrailSurrogate(r)); |
| 4442 } else { | 4441 } else { |
| 4443 string_result->Set(i++, r); | 4442 twobyte->SeqTwoByteStringSet(i++, r); |
| 4444 } | 4443 } |
| 4445 } | 4444 } |
| 4446 return result; | 4445 return result; |
| 4447 } | 4446 } |
| 4448 | 4447 |
| 4449 | 4448 |
| 4450 MaybeObject* Heap::AllocateStringFromTwoByte(Vector<const uc16> string, | 4449 MaybeObject* Heap::AllocateStringFromTwoByte(Vector<const uc16> string, |
| 4451 PretenureFlag pretenure) { | 4450 PretenureFlag pretenure) { |
| 4452 // Check if the string is an ASCII string. | 4451 // Check if the string is an ASCII string. |
| 4453 MaybeObject* maybe_result; | 4452 Object* result; |
| 4454 if (String::IsAscii(string.start(), string.length())) { | 4453 int length = string.length(); |
| 4455 maybe_result = AllocateRawAsciiString(string.length(), pretenure); | 4454 const uc16* start = string.start(); |
| 4455 |
| 4456 if (String::IsAscii(start, length)) { |
| 4457 MaybeObject* maybe_result = AllocateRawAsciiString(length, pretenure); |
| 4458 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 4459 CopyChars(SeqAsciiString::cast(result)->GetChars(), start, length); |
| 4456 } else { // It's not an ASCII string. | 4460 } else { // It's not an ASCII string. |
| 4457 maybe_result = AllocateRawTwoByteString(string.length(), pretenure); | 4461 MaybeObject* maybe_result = AllocateRawTwoByteString(length, pretenure); |
| 4458 } | 4462 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 4459 Object* result; | 4463 CopyChars(SeqTwoByteString::cast(result)->GetChars(), start, length); |
| 4460 if (!maybe_result->ToObject(&result)) return maybe_result; | |
| 4461 | |
| 4462 // Copy the characters into the new object, which may be either ASCII or | |
| 4463 // UTF-16. | |
| 4464 String* string_result = String::cast(result); | |
| 4465 for (int i = 0; i < string.length(); i++) { | |
| 4466 string_result->Set(i, string[i]); | |
| 4467 } | 4464 } |
| 4468 return result; | 4465 return result; |
| 4469 } | 4466 } |
| 4470 | 4467 |
| 4471 | 4468 |
| 4472 Map* Heap::SymbolMapForString(String* string) { | 4469 Map* Heap::SymbolMapForString(String* string) { |
| 4473 // If the string is in new space it cannot be used as a symbol. | 4470 // If the string is in new space it cannot be used as a symbol. |
| 4474 if (InNewSpace(string)) return NULL; | 4471 if (InNewSpace(string)) return NULL; |
| 4475 | 4472 |
| 4476 // Find the corresponding symbol map for strings. | 4473 // Find the corresponding symbol map for strings. |
| (...skipping 2844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7321 static_cast<int>(object_sizes_last_time_[index])); | 7318 static_cast<int>(object_sizes_last_time_[index])); |
| 7322 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) | 7319 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) |
| 7323 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 7320 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
| 7324 | 7321 |
| 7325 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 7322 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
| 7326 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 7323 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
| 7327 ClearObjectStats(); | 7324 ClearObjectStats(); |
| 7328 } | 7325 } |
| 7329 | 7326 |
| 7330 } } // namespace v8::internal | 7327 } } // namespace v8::internal |
| OLD | NEW |