| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 1979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1990 } | 1990 } |
| 1991 set_false_value(obj); | 1991 set_false_value(obj); |
| 1992 | 1992 |
| 1993 { MaybeObject* maybe_obj = CreateOddball("hole", | 1993 { MaybeObject* maybe_obj = CreateOddball("hole", |
| 1994 Smi::FromInt(-1), | 1994 Smi::FromInt(-1), |
| 1995 Oddball::kTheHole); | 1995 Oddball::kTheHole); |
| 1996 if (!maybe_obj->ToObject(&obj)) return false; | 1996 if (!maybe_obj->ToObject(&obj)) return false; |
| 1997 } | 1997 } |
| 1998 set_the_hole_value(obj); | 1998 set_the_hole_value(obj); |
| 1999 | 1999 |
| 2000 { MaybeObject* maybe_obj = CreateOddball("arguments_marker", |
| 2001 Smi::FromInt(-4), |
| 2002 Oddball::kArgumentMarker); |
| 2003 if (!maybe_obj->ToObject(&obj)) return false; |
| 2004 } |
| 2005 set_arguments_marker(obj); |
| 2006 |
| 2000 { MaybeObject* maybe_obj = CreateOddball("no_interceptor_result_sentinel", | 2007 { MaybeObject* maybe_obj = CreateOddball("no_interceptor_result_sentinel", |
| 2001 Smi::FromInt(-2), | 2008 Smi::FromInt(-2), |
| 2002 Oddball::kOther); | 2009 Oddball::kOther); |
| 2003 if (!maybe_obj->ToObject(&obj)) return false; | 2010 if (!maybe_obj->ToObject(&obj)) return false; |
| 2004 } | 2011 } |
| 2005 set_no_interceptor_result_sentinel(obj); | 2012 set_no_interceptor_result_sentinel(obj); |
| 2006 | 2013 |
| 2007 { MaybeObject* maybe_obj = CreateOddball("termination_exception", | 2014 { MaybeObject* maybe_obj = CreateOddball("termination_exception", |
| 2008 Smi::FromInt(-3), | 2015 Smi::FromInt(-3), |
| 2009 Oddball::kOther); | 2016 Oddball::kOther); |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2533 | 2540 |
| 2534 MaybeObject* Heap::AllocateExternalStringFromTwoByte( | 2541 MaybeObject* Heap::AllocateExternalStringFromTwoByte( |
| 2535 ExternalTwoByteString::Resource* resource) { | 2542 ExternalTwoByteString::Resource* resource) { |
| 2536 size_t length = resource->length(); | 2543 size_t length = resource->length(); |
| 2537 if (length > static_cast<size_t>(String::kMaxLength)) { | 2544 if (length > static_cast<size_t>(String::kMaxLength)) { |
| 2538 isolate()->context()->mark_out_of_memory(); | 2545 isolate()->context()->mark_out_of_memory(); |
| 2539 return Failure::OutOfMemoryException(); | 2546 return Failure::OutOfMemoryException(); |
| 2540 } | 2547 } |
| 2541 | 2548 |
| 2542 // For small strings we check whether the resource contains only | 2549 // For small strings we check whether the resource contains only |
| 2543 // ascii characters. If yes, we use a different string map. | 2550 // ASCII characters. If yes, we use a different string map. |
| 2544 bool is_ascii = true; | 2551 static const size_t kAsciiCheckLengthLimit = 32; |
| 2545 if (length >= static_cast<size_t>(String::kMinNonFlatLength)) { | 2552 bool is_ascii = length <= kAsciiCheckLengthLimit && |
| 2546 is_ascii = false; | 2553 String::IsAscii(resource->data(), static_cast<int>(length)); |
| 2547 } else { | |
| 2548 const uc16* data = resource->data(); | |
| 2549 for (size_t i = 0; i < length; i++) { | |
| 2550 if (data[i] > String::kMaxAsciiCharCode) { | |
| 2551 is_ascii = false; | |
| 2552 break; | |
| 2553 } | |
| 2554 } | |
| 2555 } | |
| 2556 | |
| 2557 Map* map = is_ascii ? | 2554 Map* map = is_ascii ? |
| 2558 external_string_with_ascii_data_map() : external_string_map(); | 2555 external_string_with_ascii_data_map() : external_string_map(); |
| 2559 Object* result; | 2556 Object* result; |
| 2560 { MaybeObject* maybe_result = Allocate(map, NEW_SPACE); | 2557 { MaybeObject* maybe_result = Allocate(map, NEW_SPACE); |
| 2561 if (!maybe_result->ToObject(&result)) return maybe_result; | 2558 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 2562 } | 2559 } |
| 2563 | 2560 |
| 2564 ExternalTwoByteString* external_string = ExternalTwoByteString::cast(result); | 2561 ExternalTwoByteString* external_string = ExternalTwoByteString::cast(result); |
| 2565 external_string->set_length(static_cast<int>(length)); | 2562 external_string->set_length(static_cast<int>(length)); |
| 2566 external_string->set_hash_field(String::kEmptyHashField); | 2563 external_string->set_hash_field(String::kEmptyHashField); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2713 if (!maybe_result->ToObject(&result)) return maybe_result; | 2710 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 2714 | 2711 |
| 2715 // Initialize the object | 2712 // Initialize the object |
| 2716 HeapObject::cast(result)->set_map(code_map()); | 2713 HeapObject::cast(result)->set_map(code_map()); |
| 2717 Code* code = Code::cast(result); | 2714 Code* code = Code::cast(result); |
| 2718 ASSERT(!isolate_->code_range()->exists() || | 2715 ASSERT(!isolate_->code_range()->exists() || |
| 2719 isolate_->code_range()->contains(code->address())); | 2716 isolate_->code_range()->contains(code->address())); |
| 2720 code->set_instruction_size(desc.instr_size); | 2717 code->set_instruction_size(desc.instr_size); |
| 2721 code->set_relocation_info(ByteArray::cast(reloc_info)); | 2718 code->set_relocation_info(ByteArray::cast(reloc_info)); |
| 2722 code->set_flags(flags); | 2719 code->set_flags(flags); |
| 2720 if (code->is_call_stub() || code->is_keyed_call_stub()) { |
| 2721 code->set_check_type(RECEIVER_MAP_CHECK); |
| 2722 } |
| 2723 code->set_deoptimization_data(empty_fixed_array()); | 2723 code->set_deoptimization_data(empty_fixed_array()); |
| 2724 // Allow self references to created code object by patching the handle to | 2724 // Allow self references to created code object by patching the handle to |
| 2725 // point to the newly allocated Code object. | 2725 // point to the newly allocated Code object. |
| 2726 if (!self_reference.is_null()) { | 2726 if (!self_reference.is_null()) { |
| 2727 *(self_reference.location()) = code; | 2727 *(self_reference.location()) = code; |
| 2728 } | 2728 } |
| 2729 // Migrate generated code. | 2729 // Migrate generated code. |
| 2730 // The generated code can contain Object** values (typically from handles) | 2730 // The generated code can contain Object** values (typically from handles) |
| 2731 // that are dereferenced during the copy to point directly to the actual heap | 2731 // that are dereferenced during the copy to point directly to the actual heap |
| 2732 // objects. These pointers can include references to the code object itself, | 2732 // objects. These pointers can include references to the code object itself, |
| (...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3328 if (r > kMaxSupportedChar) { r = unibrow::Utf8::kBadChar; } | 3328 if (r > kMaxSupportedChar) { r = unibrow::Utf8::kBadChar; } |
| 3329 string_result->Set(i, r); | 3329 string_result->Set(i, r); |
| 3330 } | 3330 } |
| 3331 return result; | 3331 return result; |
| 3332 } | 3332 } |
| 3333 | 3333 |
| 3334 | 3334 |
| 3335 MaybeObject* Heap::AllocateStringFromTwoByte(Vector<const uc16> string, | 3335 MaybeObject* Heap::AllocateStringFromTwoByte(Vector<const uc16> string, |
| 3336 PretenureFlag pretenure) { | 3336 PretenureFlag pretenure) { |
| 3337 // Check if the string is an ASCII string. | 3337 // Check if the string is an ASCII string. |
| 3338 int i = 0; | |
| 3339 while (i < string.length() && string[i] <= String::kMaxAsciiCharCode) i++; | |
| 3340 | |
| 3341 MaybeObject* maybe_result; | 3338 MaybeObject* maybe_result; |
| 3342 if (i == string.length()) { // It's an ASCII string. | 3339 if (String::IsAscii(string.start(), string.length())) { |
| 3343 maybe_result = AllocateRawAsciiString(string.length(), pretenure); | 3340 maybe_result = AllocateRawAsciiString(string.length(), pretenure); |
| 3344 } else { // It's not an ASCII string. | 3341 } else { // It's not an ASCII string. |
| 3345 maybe_result = AllocateRawTwoByteString(string.length(), pretenure); | 3342 maybe_result = AllocateRawTwoByteString(string.length(), pretenure); |
| 3346 } | 3343 } |
| 3347 Object* result; | 3344 Object* result; |
| 3348 if (!maybe_result->ToObject(&result)) return maybe_result; | 3345 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 3349 | 3346 |
| 3350 // Copy the characters into the new object, which may be either ASCII or | 3347 // Copy the characters into the new object, which may be either ASCII or |
| 3351 // UTF-16. | 3348 // UTF-16. |
| 3352 String* string_result = String::cast(result); | 3349 String* string_result = String::cast(result); |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4035 if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table; | 4032 if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table; |
| 4036 } | 4033 } |
| 4037 // Can't use set_symbol_table because SymbolTable::cast knows that | 4034 // Can't use set_symbol_table because SymbolTable::cast knows that |
| 4038 // SymbolTable is a singleton and checks for identity. | 4035 // SymbolTable is a singleton and checks for identity. |
| 4039 roots_[kSymbolTableRootIndex] = new_table; | 4036 roots_[kSymbolTableRootIndex] = new_table; |
| 4040 ASSERT(symbol != NULL); | 4037 ASSERT(symbol != NULL); |
| 4041 return symbol; | 4038 return symbol; |
| 4042 } | 4039 } |
| 4043 | 4040 |
| 4044 | 4041 |
| 4042 MaybeObject* Heap::LookupAsciiSymbol(Vector<const char> string) { |
| 4043 Object* symbol = NULL; |
| 4044 Object* new_table; |
| 4045 { MaybeObject* maybe_new_table = |
| 4046 symbol_table()->LookupAsciiSymbol(string, &symbol); |
| 4047 if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table; |
| 4048 } |
| 4049 // Can't use set_symbol_table because SymbolTable::cast knows that |
| 4050 // SymbolTable is a singleton and checks for identity. |
| 4051 roots_[kSymbolTableRootIndex] = new_table; |
| 4052 ASSERT(symbol != NULL); |
| 4053 return symbol; |
| 4054 } |
| 4055 |
| 4056 |
| 4057 MaybeObject* Heap::LookupTwoByteSymbol(Vector<const uc16> string) { |
| 4058 Object* symbol = NULL; |
| 4059 Object* new_table; |
| 4060 { MaybeObject* maybe_new_table = |
| 4061 symbol_table()->LookupTwoByteSymbol(string, &symbol); |
| 4062 if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table; |
| 4063 } |
| 4064 // Can't use set_symbol_table because SymbolTable::cast knows that |
| 4065 // SymbolTable is a singleton and checks for identity. |
| 4066 roots_[kSymbolTableRootIndex] = new_table; |
| 4067 ASSERT(symbol != NULL); |
| 4068 return symbol; |
| 4069 } |
| 4070 |
| 4071 |
| 4045 MaybeObject* Heap::LookupSymbol(String* string) { | 4072 MaybeObject* Heap::LookupSymbol(String* string) { |
| 4046 if (string->IsSymbol()) return string; | 4073 if (string->IsSymbol()) return string; |
| 4047 Object* symbol = NULL; | 4074 Object* symbol = NULL; |
| 4048 Object* new_table; | 4075 Object* new_table; |
| 4049 { MaybeObject* maybe_new_table = | 4076 { MaybeObject* maybe_new_table = |
| 4050 symbol_table()->LookupString(string, &symbol); | 4077 symbol_table()->LookupString(string, &symbol); |
| 4051 if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table; | 4078 if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table; |
| 4052 } | 4079 } |
| 4053 // Can't use set_symbol_table because SymbolTable::cast knows that | 4080 // Can't use set_symbol_table because SymbolTable::cast knows that |
| 4054 // SymbolTable is a singleton and checks for identity. | 4081 // SymbolTable is a singleton and checks for identity. |
| (...skipping 1158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5213 }; | 5240 }; |
| 5214 | 5241 |
| 5215 void MarkUnreachableObjects() { | 5242 void MarkUnreachableObjects() { |
| 5216 HeapIterator iterator; | 5243 HeapIterator iterator; |
| 5217 for (HeapObject* obj = iterator.next(); | 5244 for (HeapObject* obj = iterator.next(); |
| 5218 obj != NULL; | 5245 obj != NULL; |
| 5219 obj = iterator.next()) { | 5246 obj = iterator.next()) { |
| 5220 obj->SetMark(); | 5247 obj->SetMark(); |
| 5221 } | 5248 } |
| 5222 UnmarkingVisitor visitor; | 5249 UnmarkingVisitor visitor; |
| 5223 HEAP->IterateRoots(&visitor, VISIT_ONLY_STRONG); | 5250 HEAP->IterateRoots(&visitor, VISIT_ALL); |
| 5224 while (visitor.can_process()) | 5251 while (visitor.can_process()) |
| 5225 visitor.ProcessNext(); | 5252 visitor.ProcessNext(); |
| 5226 } | 5253 } |
| 5227 | 5254 |
| 5228 AssertNoAllocation no_alloc; | 5255 AssertNoAllocation no_alloc; |
| 5229 }; | 5256 }; |
| 5230 | 5257 |
| 5231 | 5258 |
| 5232 HeapIterator::HeapIterator() | 5259 HeapIterator::HeapIterator() |
| 5233 : filtering_(HeapIterator::kNoFiltering), | 5260 : filtering_(HeapIterator::kNoFiltering), |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5575 } | 5602 } |
| 5576 | 5603 |
| 5577 | 5604 |
| 5578 void ExternalStringTable::TearDown() { | 5605 void ExternalStringTable::TearDown() { |
| 5579 new_space_strings_.Free(); | 5606 new_space_strings_.Free(); |
| 5580 old_space_strings_.Free(); | 5607 old_space_strings_.Free(); |
| 5581 } | 5608 } |
| 5582 | 5609 |
| 5583 | 5610 |
| 5584 } } // namespace v8::internal | 5611 } } // namespace v8::internal |
| OLD | NEW |