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 4282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4343 object->set_map(constructor->initial_map()); | 4344 object->set_map(constructor->initial_map()); |
4344 | 4345 |
4345 // Reinitialize the object from the constructor map. | 4346 // Reinitialize the object from the constructor map. |
4346 InitializeJSObjectFromMap(object, FixedArray::cast(properties), map); | 4347 InitializeJSObjectFromMap(object, FixedArray::cast(properties), map); |
4347 return object; | 4348 return object; |
4348 } | 4349 } |
4349 | 4350 |
4350 | 4351 |
4351 MaybeObject* Heap::AllocateStringFromAscii(Vector<const char> string, | 4352 MaybeObject* Heap::AllocateStringFromAscii(Vector<const char> string, |
4352 PretenureFlag pretenure) { | 4353 PretenureFlag pretenure) { |
4353 if (string.length() == 1) { | 4354 int length = string.length(); |
| 4355 if (length == 1) { |
4354 return Heap::LookupSingleCharacterStringFromCode(string[0]); | 4356 return Heap::LookupSingleCharacterStringFromCode(string[0]); |
4355 } | 4357 } |
4356 Object* result; | 4358 Object* result; |
4357 { MaybeObject* maybe_result = | 4359 { MaybeObject* maybe_result = |
4358 AllocateRawAsciiString(string.length(), pretenure); | 4360 AllocateRawAsciiString(string.length(), pretenure); |
4359 if (!maybe_result->ToObject(&result)) return maybe_result; | 4361 if (!maybe_result->ToObject(&result)) return maybe_result; |
4360 } | 4362 } |
4361 | 4363 |
| 4364 isolate_->counters()->string_length_ascii()->Increment(length); |
| 4365 |
4362 // Copy the characters into the new object. | 4366 // Copy the characters into the new object. |
4363 SeqAsciiString* string_result = SeqAsciiString::cast(result); | 4367 CopyChars(SeqAsciiString::cast(result)->GetChars(), string.start(), length); |
4364 for (int i = 0; i < string.length(); i++) { | |
4365 string_result->SeqAsciiStringSet(i, string[i]); | |
4366 } | |
4367 return result; | 4368 return result; |
4368 } | 4369 } |
4369 | 4370 |
4370 | 4371 |
4371 MaybeObject* Heap::AllocateStringFromUtf8Slow(Vector<const char> string, | 4372 MaybeObject* Heap::AllocateStringFromUtf8Slow(Vector<const char> string, |
4372 PretenureFlag pretenure) { | 4373 PretenureFlag pretenure) { |
4373 // Count the number of characters in the UTF-8 string and check if | 4374 // Count the number of characters in the UTF-8 string and check if |
4374 // it is an ASCII string. | 4375 // it is an ASCII string. |
4375 Access<UnicodeCache::Utf8Decoder> | 4376 Access<UnicodeCache::Utf8Decoder> |
4376 decoder(isolate_->unicode_cache()->utf8_decoder()); | 4377 decoder(isolate_->unicode_cache()->utf8_decoder()); |
4377 decoder->Reset(string.start(), string.length()); | 4378 decoder->Reset(string.start(), string.length()); |
4378 int chars = 0; | 4379 int chars = 0; |
4379 while (decoder->has_more()) { | 4380 while (decoder->has_more()) { |
4380 uint32_t r = decoder->GetNext(); | 4381 uint32_t r = decoder->GetNext(); |
4381 if (r <= unibrow::Utf16::kMaxNonSurrogateCharCode) { | 4382 if (r <= unibrow::Utf16::kMaxNonSurrogateCharCode) { |
4382 chars++; | 4383 chars++; |
4383 } else { | 4384 } else { |
4384 chars += 2; | 4385 chars += 2; |
4385 } | 4386 } |
4386 } | 4387 } |
4387 | 4388 |
4388 Object* result; | 4389 Object* result; |
4389 { MaybeObject* maybe_result = AllocateRawTwoByteString(chars, pretenure); | 4390 { MaybeObject* maybe_result = AllocateRawTwoByteString(chars, pretenure); |
4390 if (!maybe_result->ToObject(&result)) return maybe_result; | 4391 if (!maybe_result->ToObject(&result)) return maybe_result; |
4391 } | 4392 } |
4392 | 4393 |
| 4394 isolate_->counters()->string_length_utf8()->Increment(chars); |
| 4395 |
4393 // Convert and copy the characters into the new object. | 4396 // Convert and copy the characters into the new object. |
4394 String* string_result = String::cast(result); | 4397 SeqTwoByteString* twobyte = SeqTwoByteString::cast(result); |
4395 decoder->Reset(string.start(), string.length()); | 4398 decoder->Reset(string.start(), string.length()); |
4396 int i = 0; | 4399 int i = 0; |
4397 while (i < chars) { | 4400 while (i < chars) { |
4398 uint32_t r = decoder->GetNext(); | 4401 uint32_t r = decoder->GetNext(); |
4399 if (r > unibrow::Utf16::kMaxNonSurrogateCharCode) { | 4402 if (r > unibrow::Utf16::kMaxNonSurrogateCharCode) { |
4400 string_result->Set(i++, unibrow::Utf16::LeadSurrogate(r)); | 4403 twobyte->SeqTwoByteStringSet(i++, unibrow::Utf16::LeadSurrogate(r)); |
4401 string_result->Set(i++, unibrow::Utf16::TrailSurrogate(r)); | 4404 twobyte->SeqTwoByteStringSet(i++, unibrow::Utf16::TrailSurrogate(r)); |
4402 } else { | 4405 } else { |
4403 string_result->Set(i++, r); | 4406 twobyte->SeqTwoByteStringSet(i++, r); |
4404 } | 4407 } |
4405 } | 4408 } |
4406 return result; | 4409 return result; |
4407 } | 4410 } |
4408 | 4411 |
4409 | 4412 |
| 4413 MaybeObject* Heap::AllocateStringFromLatin1Slow(Vector<const char> string, |
| 4414 PretenureFlag pretenure) { |
| 4415 int chars = string.length(); |
| 4416 Object* result; |
| 4417 { MaybeObject* maybe_result = AllocateRawTwoByteString(chars, pretenure); |
| 4418 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 4419 } |
| 4420 |
| 4421 isolate_->counters()->string_length_latin1()->Increment(chars); |
| 4422 |
| 4423 // Convert and copy the characters into the new object. |
| 4424 SeqTwoByteString* string_result = SeqTwoByteString::cast(result); |
| 4425 CopyChars(string_result->GetChars(), |
| 4426 reinterpret_cast<const unsigned char*>(string.start()), |
| 4427 chars); |
| 4428 return result; |
| 4429 } |
| 4430 |
| 4431 |
4410 MaybeObject* Heap::AllocateStringFromTwoByte(Vector<const uc16> string, | 4432 MaybeObject* Heap::AllocateStringFromTwoByte(Vector<const uc16> string, |
4411 PretenureFlag pretenure) { | 4433 PretenureFlag pretenure) { |
4412 // Check if the string is an ASCII string. | 4434 // Check if the string is an ASCII string. |
4413 MaybeObject* maybe_result; | 4435 Object* result; |
4414 if (String::IsAscii(string.start(), string.length())) { | 4436 int length = string.length(); |
4415 maybe_result = AllocateRawAsciiString(string.length(), pretenure); | 4437 const uc16* start = string.start(); |
| 4438 |
| 4439 if (String::IsAscii(start, length)) { |
| 4440 MaybeObject* maybe_result = AllocateRawAsciiString(length, pretenure); |
| 4441 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 4442 isolate_->counters()->string_length_ascii()->Increment(length); |
| 4443 CopyChars(SeqAsciiString::cast(result)->GetChars(), start, length); |
4416 } else { // It's not an ASCII string. | 4444 } else { // It's not an ASCII string. |
4417 maybe_result = AllocateRawTwoByteString(string.length(), pretenure); | 4445 MaybeObject* maybe_result = AllocateRawTwoByteString(length, pretenure); |
| 4446 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 4447 isolate_->counters()->string_length_utf16()->Increment(length); |
| 4448 CopyChars(SeqTwoByteString::cast(result)->GetChars(), start, length); |
4418 } | 4449 } |
4419 Object* result; | |
4420 if (!maybe_result->ToObject(&result)) return maybe_result; | |
4421 | 4450 |
4422 // Copy the characters into the new object, which may be either ASCII or | |
4423 // UTF-16. | |
4424 String* string_result = String::cast(result); | |
4425 for (int i = 0; i < string.length(); i++) { | |
4426 string_result->Set(i, string[i]); | |
4427 } | |
4428 return result; | 4451 return result; |
4429 } | 4452 } |
4430 | 4453 |
4431 | 4454 |
4432 Map* Heap::SymbolMapForString(String* string) { | 4455 Map* Heap::SymbolMapForString(String* string) { |
4433 // If the string is in new space it cannot be used as a symbol. | 4456 // If the string is in new space it cannot be used as a symbol. |
4434 if (InNewSpace(string)) return NULL; | 4457 if (InNewSpace(string)) return NULL; |
4435 | 4458 |
4436 // Find the corresponding symbol map for strings. | 4459 // Find the corresponding symbol map for strings. |
4437 switch (string->map()->instance_type()) { | 4460 switch (string->map()->instance_type()) { |
(...skipping 2824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7262 static_cast<int>(object_sizes_last_time_[index])); | 7285 static_cast<int>(object_sizes_last_time_[index])); |
7263 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) | 7286 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) |
7264 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 7287 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
7265 | 7288 |
7266 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 7289 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
7267 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 7290 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
7268 ClearObjectStats(); | 7291 ClearObjectStats(); |
7269 } | 7292 } |
7270 | 7293 |
7271 } } // namespace v8::internal | 7294 } } // namespace v8::internal |
OLD | NEW |