| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 5474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5485 } | 5485 } |
| 5486 MaybeObject* new_alloc = AllocateRawString<StringType>(isolate, | 5486 MaybeObject* new_alloc = AllocateRawString<StringType>(isolate, |
| 5487 quoted_length); | 5487 quoted_length); |
| 5488 Object* new_object; | 5488 Object* new_object; |
| 5489 if (!new_alloc->ToObject(&new_object)) { | 5489 if (!new_alloc->ToObject(&new_object)) { |
| 5490 return new_alloc; | 5490 return new_alloc; |
| 5491 } | 5491 } |
| 5492 StringType* new_string = StringType::cast(new_object); | 5492 StringType* new_string = StringType::cast(new_object); |
| 5493 | 5493 |
| 5494 Char* write_cursor = reinterpret_cast<Char*>( | 5494 Char* write_cursor = reinterpret_cast<Char*>( |
| 5495 new_string->address() + SeqAsciiString::kHeaderSize); | 5495 new_string->address() + SeqString::kHeaderSize); |
| 5496 if (comma) *(write_cursor++) = ','; | 5496 if (comma) *(write_cursor++) = ','; |
| 5497 *(write_cursor++) = '"'; | 5497 *(write_cursor++) = '"'; |
| 5498 | 5498 |
| 5499 read_cursor = characters.start(); | 5499 read_cursor = characters.start(); |
| 5500 while (read_cursor < end) { | 5500 while (read_cursor < end) { |
| 5501 Char c = *(read_cursor++); | 5501 Char c = *(read_cursor++); |
| 5502 if (sizeof(Char) > 1u && static_cast<unsigned>(c) >= kQuoteTableLength) { | 5502 if (sizeof(Char) > 1u && static_cast<unsigned>(c) >= kQuoteTableLength) { |
| 5503 *(write_cursor++) = c; | 5503 *(write_cursor++) = c; |
| 5504 } else { | 5504 } else { |
| 5505 int len = JsonQuoteLengths[static_cast<unsigned>(c)]; | 5505 int len = JsonQuoteLengths[static_cast<unsigned>(c)]; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5573 if (!isolate->heap()->new_space()->Contains(new_object)) { | 5573 if (!isolate->heap()->new_space()->Contains(new_object)) { |
| 5574 // Even if our string is small enough to fit in new space we still have to | 5574 // Even if our string is small enough to fit in new space we still have to |
| 5575 // handle it being allocated in old space as may happen in the third | 5575 // handle it being allocated in old space as may happen in the third |
| 5576 // attempt. See CALL_AND_RETRY in heap-inl.h and similar code in | 5576 // attempt. See CALL_AND_RETRY in heap-inl.h and similar code in |
| 5577 // CEntryStub::GenerateCore. | 5577 // CEntryStub::GenerateCore. |
| 5578 return SlowQuoteJsonString<Char, StringType, comma>(isolate, characters); | 5578 return SlowQuoteJsonString<Char, StringType, comma>(isolate, characters); |
| 5579 } | 5579 } |
| 5580 StringType* new_string = StringType::cast(new_object); | 5580 StringType* new_string = StringType::cast(new_object); |
| 5581 ASSERT(isolate->heap()->new_space()->Contains(new_string)); | 5581 ASSERT(isolate->heap()->new_space()->Contains(new_string)); |
| 5582 | 5582 |
| 5583 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqAsciiString::kHeaderSize); | |
| 5584 Char* write_cursor = reinterpret_cast<Char*>( | 5583 Char* write_cursor = reinterpret_cast<Char*>( |
| 5585 new_string->address() + SeqAsciiString::kHeaderSize); | 5584 new_string->address() + SeqString::kHeaderSize); |
| 5586 if (comma) *(write_cursor++) = ','; | 5585 if (comma) *(write_cursor++) = ','; |
| 5587 write_cursor = WriteQuoteJsonString<Char, Char>(isolate, | 5586 write_cursor = WriteQuoteJsonString<Char, Char>(isolate, |
| 5588 write_cursor, | 5587 write_cursor, |
| 5589 characters); | 5588 characters); |
| 5590 int final_length = static_cast<int>( | 5589 int final_length = static_cast<int>( |
| 5591 write_cursor - reinterpret_cast<Char*>( | 5590 write_cursor - reinterpret_cast<Char*>( |
| 5592 new_string->address() + SeqAsciiString::kHeaderSize)); | 5591 new_string->address() + SeqString::kHeaderSize)); |
| 5593 isolate->heap()->new_space()-> | 5592 isolate->heap()->new_space()-> |
| 5594 template ShrinkStringAtAllocationBoundary<StringType>( | 5593 template ShrinkStringAtAllocationBoundary<StringType>( |
| 5595 new_string, final_length); | 5594 new_string, final_length); |
| 5596 return new_string; | 5595 return new_string; |
| 5597 } | 5596 } |
| 5598 | 5597 |
| 5599 | 5598 |
| 5600 RUNTIME_FUNCTION(MaybeObject*, Runtime_QuoteJSONString) { | 5599 RUNTIME_FUNCTION(MaybeObject*, Runtime_QuoteJSONString) { |
| 5601 NoHandleAllocation ha; | 5600 NoHandleAllocation ha; |
| 5602 CONVERT_CHECKED(String, str, args[0]); | 5601 CONVERT_CHECKED(String, str, args[0]); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5660 // Even if our string is small enough to fit in new space we still have to | 5659 // Even if our string is small enough to fit in new space we still have to |
| 5661 // handle it being allocated in old space as may happen in the third | 5660 // handle it being allocated in old space as may happen in the third |
| 5662 // attempt. See CALL_AND_RETRY in heap-inl.h and similar code in | 5661 // attempt. See CALL_AND_RETRY in heap-inl.h and similar code in |
| 5663 // CEntryStub::GenerateCore. | 5662 // CEntryStub::GenerateCore. |
| 5664 return isolate->heap()->undefined_value(); | 5663 return isolate->heap()->undefined_value(); |
| 5665 } | 5664 } |
| 5666 AssertNoAllocation no_gc; | 5665 AssertNoAllocation no_gc; |
| 5667 StringType* new_string = StringType::cast(new_object); | 5666 StringType* new_string = StringType::cast(new_object); |
| 5668 ASSERT(isolate->heap()->new_space()->Contains(new_string)); | 5667 ASSERT(isolate->heap()->new_space()->Contains(new_string)); |
| 5669 | 5668 |
| 5670 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqAsciiString::kHeaderSize); | |
| 5671 Char* write_cursor = reinterpret_cast<Char*>( | 5669 Char* write_cursor = reinterpret_cast<Char*>( |
| 5672 new_string->address() + SeqAsciiString::kHeaderSize); | 5670 new_string->address() + SeqString::kHeaderSize); |
| 5673 *(write_cursor++) = '['; | 5671 *(write_cursor++) = '['; |
| 5674 for (int i = 0; i < length; i++) { | 5672 for (int i = 0; i < length; i++) { |
| 5675 if (i != 0) *(write_cursor++) = ','; | 5673 if (i != 0) *(write_cursor++) = ','; |
| 5676 String* str = String::cast(array->get(i)); | 5674 String* str = String::cast(array->get(i)); |
| 5677 String::FlatContent content = str->GetFlatContent(); | 5675 String::FlatContent content = str->GetFlatContent(); |
| 5678 ASSERT(content.IsFlat()); | 5676 ASSERT(content.IsFlat()); |
| 5679 if (content.IsTwoByte()) { | 5677 if (content.IsTwoByte()) { |
| 5680 write_cursor = WriteQuoteJsonString<Char, uc16>(isolate, | 5678 write_cursor = WriteQuoteJsonString<Char, uc16>(isolate, |
| 5681 write_cursor, | 5679 write_cursor, |
| 5682 content.ToUC16Vector()); | 5680 content.ToUC16Vector()); |
| 5683 } else { | 5681 } else { |
| 5684 write_cursor = WriteQuoteJsonString<Char, char>(isolate, | 5682 write_cursor = WriteQuoteJsonString<Char, char>(isolate, |
| 5685 write_cursor, | 5683 write_cursor, |
| 5686 content.ToAsciiVector()); | 5684 content.ToAsciiVector()); |
| 5687 } | 5685 } |
| 5688 } | 5686 } |
| 5689 *(write_cursor++) = ']'; | 5687 *(write_cursor++) = ']'; |
| 5690 | 5688 |
| 5691 int final_length = static_cast<int>( | 5689 int final_length = static_cast<int>( |
| 5692 write_cursor - reinterpret_cast<Char*>( | 5690 write_cursor - reinterpret_cast<Char*>( |
| 5693 new_string->address() + SeqAsciiString::kHeaderSize)); | 5691 new_string->address() + SeqString::kHeaderSize)); |
| 5694 isolate->heap()->new_space()-> | 5692 isolate->heap()->new_space()-> |
| 5695 template ShrinkStringAtAllocationBoundary<StringType>( | 5693 template ShrinkStringAtAllocationBoundary<StringType>( |
| 5696 new_string, final_length); | 5694 new_string, final_length); |
| 5697 return new_string; | 5695 return new_string; |
| 5698 } | 5696 } |
| 5699 | 5697 |
| 5700 | 5698 |
| 5701 RUNTIME_FUNCTION(MaybeObject*, Runtime_QuoteJSONStringArray) { | 5699 RUNTIME_FUNCTION(MaybeObject*, Runtime_QuoteJSONStringArray) { |
| 5702 NoHandleAllocation ha; | 5700 NoHandleAllocation ha; |
| 5703 ASSERT(args.length() == 1); | 5701 ASSERT(args.length() == 1); |
| (...skipping 7492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13196 } else { | 13194 } else { |
| 13197 // Handle last resort GC and make sure to allow future allocations | 13195 // Handle last resort GC and make sure to allow future allocations |
| 13198 // to grow the heap without causing GCs (if possible). | 13196 // to grow the heap without causing GCs (if possible). |
| 13199 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13197 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 13200 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); | 13198 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 13201 } | 13199 } |
| 13202 } | 13200 } |
| 13203 | 13201 |
| 13204 | 13202 |
| 13205 } } // namespace v8::internal | 13203 } } // namespace v8::internal |
| OLD | NEW |