| 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" | |
| 52 #include "vm-state-inl.h" | 51 #include "vm-state-inl.h" |
| 53 #if V8_TARGET_ARCH_ARM && !V8_INTERPRETED_REGEXP | 52 #if V8_TARGET_ARCH_ARM && !V8_INTERPRETED_REGEXP |
| 54 #include "regexp-macro-assembler.h" | 53 #include "regexp-macro-assembler.h" |
| 55 #include "arm/regexp-macro-assembler-arm.h" | 54 #include "arm/regexp-macro-assembler-arm.h" |
| 56 #endif | 55 #endif |
| 57 #if V8_TARGET_ARCH_MIPS && !V8_INTERPRETED_REGEXP | 56 #if V8_TARGET_ARCH_MIPS && !V8_INTERPRETED_REGEXP |
| 58 #include "regexp-macro-assembler.h" | 57 #include "regexp-macro-assembler.h" |
| 59 #include "mips/regexp-macro-assembler-mips.h" | 58 #include "mips/regexp-macro-assembler-mips.h" |
| 60 #endif | 59 #endif |
| 61 | 60 |
| (...skipping 4322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4384 object->set_map(constructor->initial_map()); | 4383 object->set_map(constructor->initial_map()); |
| 4385 | 4384 |
| 4386 // Reinitialize the object from the constructor map. | 4385 // Reinitialize the object from the constructor map. |
| 4387 InitializeJSObjectFromMap(object, FixedArray::cast(properties), map); | 4386 InitializeJSObjectFromMap(object, FixedArray::cast(properties), map); |
| 4388 return object; | 4387 return object; |
| 4389 } | 4388 } |
| 4390 | 4389 |
| 4391 | 4390 |
| 4392 MaybeObject* Heap::AllocateStringFromAscii(Vector<const char> string, | 4391 MaybeObject* Heap::AllocateStringFromAscii(Vector<const char> string, |
| 4393 PretenureFlag pretenure) { | 4392 PretenureFlag pretenure) { |
| 4394 int length = string.length(); | 4393 if (string.length() == 1) { |
| 4395 if (length == 1) { | |
| 4396 return Heap::LookupSingleCharacterStringFromCode(string[0]); | 4394 return Heap::LookupSingleCharacterStringFromCode(string[0]); |
| 4397 } | 4395 } |
| 4398 Object* result; | 4396 Object* result; |
| 4399 { MaybeObject* maybe_result = | 4397 { MaybeObject* maybe_result = |
| 4400 AllocateRawAsciiString(string.length(), pretenure); | 4398 AllocateRawAsciiString(string.length(), pretenure); |
| 4401 if (!maybe_result->ToObject(&result)) return maybe_result; | 4399 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 4402 } | 4400 } |
| 4403 | 4401 |
| 4404 isolate_->counters()->string_length_ascii()->Increment(length); | |
| 4405 | |
| 4406 // Copy the characters into the new object. | 4402 // Copy the characters into the new object. |
| 4407 CopyChars(SeqAsciiString::cast(result)->GetChars(), string.start(), length); | 4403 SeqAsciiString* string_result = SeqAsciiString::cast(result); |
| 4404 for (int i = 0; i < string.length(); i++) { |
| 4405 string_result->SeqAsciiStringSet(i, string[i]); |
| 4406 } |
| 4408 return result; | 4407 return result; |
| 4409 } | 4408 } |
| 4410 | 4409 |
| 4411 | 4410 |
| 4412 MaybeObject* Heap::AllocateStringFromUtf8Slow(Vector<const char> string, | 4411 MaybeObject* Heap::AllocateStringFromUtf8Slow(Vector<const char> string, |
| 4413 PretenureFlag pretenure) { | 4412 PretenureFlag pretenure) { |
| 4414 // Count the number of characters in the UTF-8 string and check if | 4413 // Count the number of characters in the UTF-8 string and check if |
| 4415 // it is an ASCII string. | 4414 // it is an ASCII string. |
| 4416 Access<UnicodeCache::Utf8Decoder> | 4415 Access<UnicodeCache::Utf8Decoder> |
| 4417 decoder(isolate_->unicode_cache()->utf8_decoder()); | 4416 decoder(isolate_->unicode_cache()->utf8_decoder()); |
| 4418 decoder->Reset(string.start(), string.length()); | 4417 decoder->Reset(string.start(), string.length()); |
| 4419 int chars = 0; | 4418 int chars = 0; |
| 4420 while (decoder->has_more()) { | 4419 while (decoder->has_more()) { |
| 4421 uint32_t r = decoder->GetNext(); | 4420 uint32_t r = decoder->GetNext(); |
| 4422 if (r <= unibrow::Utf16::kMaxNonSurrogateCharCode) { | 4421 if (r <= unibrow::Utf16::kMaxNonSurrogateCharCode) { |
| 4423 chars++; | 4422 chars++; |
| 4424 } else { | 4423 } else { |
| 4425 chars += 2; | 4424 chars += 2; |
| 4426 } | 4425 } |
| 4427 } | 4426 } |
| 4428 | 4427 |
| 4429 Object* result; | 4428 Object* result; |
| 4430 { MaybeObject* maybe_result = AllocateRawTwoByteString(chars, pretenure); | 4429 { MaybeObject* maybe_result = AllocateRawTwoByteString(chars, pretenure); |
| 4431 if (!maybe_result->ToObject(&result)) return maybe_result; | 4430 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 4432 } | 4431 } |
| 4433 | 4432 |
| 4434 isolate_->counters()->string_length_utf8()->Increment(chars); | |
| 4435 | |
| 4436 // Convert and copy the characters into the new object. | 4433 // Convert and copy the characters into the new object. |
| 4437 SeqTwoByteString* twobyte = SeqTwoByteString::cast(result); | 4434 String* string_result = String::cast(result); |
| 4438 decoder->Reset(string.start(), string.length()); | 4435 decoder->Reset(string.start(), string.length()); |
| 4439 int i = 0; | 4436 int i = 0; |
| 4440 while (i < chars) { | 4437 while (i < chars) { |
| 4441 uint32_t r = decoder->GetNext(); | 4438 uint32_t r = decoder->GetNext(); |
| 4442 if (r > unibrow::Utf16::kMaxNonSurrogateCharCode) { | 4439 if (r > unibrow::Utf16::kMaxNonSurrogateCharCode) { |
| 4443 twobyte->SeqTwoByteStringSet(i++, unibrow::Utf16::LeadSurrogate(r)); | 4440 string_result->Set(i++, unibrow::Utf16::LeadSurrogate(r)); |
| 4444 twobyte->SeqTwoByteStringSet(i++, unibrow::Utf16::TrailSurrogate(r)); | 4441 string_result->Set(i++, unibrow::Utf16::TrailSurrogate(r)); |
| 4445 } else { | 4442 } else { |
| 4446 twobyte->SeqTwoByteStringSet(i++, r); | 4443 string_result->Set(i++, r); |
| 4447 } | 4444 } |
| 4448 } | 4445 } |
| 4449 return result; | 4446 return result; |
| 4450 } | 4447 } |
| 4451 | 4448 |
| 4452 | 4449 |
| 4453 MaybeObject* Heap::AllocateStringFromLatin1Slow(Vector<const char> string, | |
| 4454 PretenureFlag pretenure) { | |
| 4455 int chars = string.length(); | |
| 4456 Object* result; | |
| 4457 { MaybeObject* maybe_result = AllocateRawTwoByteString(chars, pretenure); | |
| 4458 if (!maybe_result->ToObject(&result)) return maybe_result; | |
| 4459 } | |
| 4460 | |
| 4461 isolate_->counters()->string_length_latin1()->Increment(chars); | |
| 4462 | |
| 4463 // Convert and copy the characters into the new object. | |
| 4464 SeqTwoByteString* string_result = SeqTwoByteString::cast(result); | |
| 4465 CopyChars(string_result->GetChars(), | |
| 4466 reinterpret_cast<const unsigned char*>(string.start()), | |
| 4467 chars); | |
| 4468 return result; | |
| 4469 } | |
| 4470 | |
| 4471 | |
| 4472 MaybeObject* Heap::AllocateStringFromTwoByte(Vector<const uc16> string, | 4450 MaybeObject* Heap::AllocateStringFromTwoByte(Vector<const uc16> string, |
| 4473 PretenureFlag pretenure) { | 4451 PretenureFlag pretenure) { |
| 4474 // Check if the string is an ASCII string. | 4452 // Check if the string is an ASCII string. |
| 4453 MaybeObject* maybe_result; |
| 4454 if (String::IsAscii(string.start(), string.length())) { |
| 4455 maybe_result = AllocateRawAsciiString(string.length(), pretenure); |
| 4456 } else { // It's not an ASCII string. |
| 4457 maybe_result = AllocateRawTwoByteString(string.length(), pretenure); |
| 4458 } |
| 4475 Object* result; | 4459 Object* result; |
| 4476 int length = string.length(); | 4460 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 4477 const uc16* start = string.start(); | |
| 4478 | 4461 |
| 4479 if (String::IsAscii(start, length)) { | 4462 // Copy the characters into the new object, which may be either ASCII or |
| 4480 MaybeObject* maybe_result = AllocateRawAsciiString(length, pretenure); | 4463 // UTF-16. |
| 4481 if (!maybe_result->ToObject(&result)) return maybe_result; | 4464 String* string_result = String::cast(result); |
| 4482 isolate_->counters()->string_length_ascii()->Increment(length); | 4465 for (int i = 0; i < string.length(); i++) { |
| 4483 CopyChars(SeqAsciiString::cast(result)->GetChars(), start, length); | 4466 string_result->Set(i, string[i]); |
| 4484 } else { // It's not an ASCII string. | |
| 4485 MaybeObject* maybe_result = AllocateRawTwoByteString(length, pretenure); | |
| 4486 if (!maybe_result->ToObject(&result)) return maybe_result; | |
| 4487 isolate_->counters()->string_length_utf16()->Increment(length); | |
| 4488 CopyChars(SeqTwoByteString::cast(result)->GetChars(), start, length); | |
| 4489 } | 4467 } |
| 4490 | |
| 4491 return result; | 4468 return result; |
| 4492 } | 4469 } |
| 4493 | 4470 |
| 4494 | 4471 |
| 4495 Map* Heap::SymbolMapForString(String* string) { | 4472 Map* Heap::SymbolMapForString(String* string) { |
| 4496 // If the string is in new space it cannot be used as a symbol. | 4473 // If the string is in new space it cannot be used as a symbol. |
| 4497 if (InNewSpace(string)) return NULL; | 4474 if (InNewSpace(string)) return NULL; |
| 4498 | 4475 |
| 4499 // Find the corresponding symbol map for strings. | 4476 // Find the corresponding symbol map for strings. |
| 4500 switch (string->map()->instance_type()) { | 4477 switch (string->map()->instance_type()) { |
| (...skipping 2843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7344 static_cast<int>(object_sizes_last_time_[index])); | 7321 static_cast<int>(object_sizes_last_time_[index])); |
| 7345 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) | 7322 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) |
| 7346 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 7323 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
| 7347 | 7324 |
| 7348 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 7325 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
| 7349 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 7326 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
| 7350 ClearObjectStats(); | 7327 ClearObjectStats(); |
| 7351 } | 7328 } |
| 7352 | 7329 |
| 7353 } } // namespace v8::internal | 7330 } } // namespace v8::internal |
| OLD | NEW |