| 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 5053 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5064 1, 1, 1, 1, 1, 1, 1, 1, | 5064 1, 1, 1, 1, 1, 1, 1, 1, |
| 5065 1, 1, 1, 1, 2, 1, 1, 1, | 5065 1, 1, 1, 1, 2, 1, 1, 1, |
| 5066 1, 1, 1, 1, 1, 1, 1, 1, | 5066 1, 1, 1, 1, 1, 1, 1, 1, |
| 5067 1, 1, 1, 1, 1, 1, 1, 1, | 5067 1, 1, 1, 1, 1, 1, 1, 1, |
| 5068 1, 1, 1, 1, 1, 1, 1, 1, | 5068 1, 1, 1, 1, 1, 1, 1, 1, |
| 5069 1, 1, 1, 1, 1, 1, 1, 1, | 5069 1, 1, 1, 1, 1, 1, 1, 1, |
| 5070 }; | 5070 }; |
| 5071 | 5071 |
| 5072 | 5072 |
| 5073 template <typename StringType> | 5073 template <typename StringType> |
| 5074 MaybeObject* AllocateRawString(int length); | 5074 MaybeObject* AllocateRawString(Isolate* isolate, int length); |
| 5075 | 5075 |
| 5076 | 5076 |
| 5077 template <> | 5077 template <> |
| 5078 MaybeObject* AllocateRawString<SeqTwoByteString>(int length) { | 5078 MaybeObject* AllocateRawString<SeqTwoByteString>(Isolate* isolate, int length) { |
| 5079 return HEAP->AllocateRawTwoByteString(length); | 5079 return isolate->heap()->AllocateRawTwoByteString(length); |
| 5080 } | 5080 } |
| 5081 | 5081 |
| 5082 | 5082 |
| 5083 template <> | 5083 template <> |
| 5084 MaybeObject* AllocateRawString<SeqAsciiString>(int length) { | 5084 MaybeObject* AllocateRawString<SeqAsciiString>(Isolate* isolate, int length) { |
| 5085 return HEAP->AllocateRawAsciiString(length); | 5085 return isolate->heap()->AllocateRawAsciiString(length); |
| 5086 } | 5086 } |
| 5087 | 5087 |
| 5088 | 5088 |
| 5089 template <typename Char, typename StringType, bool comma> | 5089 template <typename Char, typename StringType, bool comma> |
| 5090 static MaybeObject* SlowQuoteJsonString(Vector<const Char> characters) { | 5090 static MaybeObject* SlowQuoteJsonString(Isolate* isolate, |
| 5091 Vector<const Char> characters) { |
| 5091 int length = characters.length(); | 5092 int length = characters.length(); |
| 5092 const Char* read_cursor = characters.start(); | 5093 const Char* read_cursor = characters.start(); |
| 5093 const Char* end = read_cursor + length; | 5094 const Char* end = read_cursor + length; |
| 5094 const int kSpaceForQuotes = 2 + (comma ? 1 :0); | 5095 const int kSpaceForQuotes = 2 + (comma ? 1 :0); |
| 5095 int quoted_length = kSpaceForQuotes; | 5096 int quoted_length = kSpaceForQuotes; |
| 5096 while (read_cursor < end) { | 5097 while (read_cursor < end) { |
| 5097 Char c = *(read_cursor++); | 5098 Char c = *(read_cursor++); |
| 5098 if (sizeof(Char) > 1u && static_cast<unsigned>(c) >= kQuoteTableLength) { | 5099 if (sizeof(Char) > 1u && static_cast<unsigned>(c) >= kQuoteTableLength) { |
| 5099 quoted_length++; | 5100 quoted_length++; |
| 5100 } else { | 5101 } else { |
| 5101 quoted_length += JsonQuoteLengths[static_cast<unsigned>(c)]; | 5102 quoted_length += JsonQuoteLengths[static_cast<unsigned>(c)]; |
| 5102 } | 5103 } |
| 5103 } | 5104 } |
| 5104 MaybeObject* new_alloc = AllocateRawString<StringType>(quoted_length); | 5105 MaybeObject* new_alloc = AllocateRawString<StringType>(isolate, |
| 5106 quoted_length); |
| 5105 Object* new_object; | 5107 Object* new_object; |
| 5106 if (!new_alloc->ToObject(&new_object)) { | 5108 if (!new_alloc->ToObject(&new_object)) { |
| 5107 return new_alloc; | 5109 return new_alloc; |
| 5108 } | 5110 } |
| 5109 StringType* new_string = StringType::cast(new_object); | 5111 StringType* new_string = StringType::cast(new_object); |
| 5110 | 5112 |
| 5111 Char* write_cursor = reinterpret_cast<Char*>( | 5113 Char* write_cursor = reinterpret_cast<Char*>( |
| 5112 new_string->address() + SeqAsciiString::kHeaderSize); | 5114 new_string->address() + SeqAsciiString::kHeaderSize); |
| 5113 if (comma) *(write_cursor++) = ','; | 5115 if (comma) *(write_cursor++) = ','; |
| 5114 *(write_cursor++) = '"'; | 5116 *(write_cursor++) = '"'; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 5126 *write_cursor++ = *replacement++; | 5128 *write_cursor++ = *replacement++; |
| 5127 } | 5129 } |
| 5128 } | 5130 } |
| 5129 } | 5131 } |
| 5130 *(write_cursor++) = '"'; | 5132 *(write_cursor++) = '"'; |
| 5131 return new_string; | 5133 return new_string; |
| 5132 } | 5134 } |
| 5133 | 5135 |
| 5134 | 5136 |
| 5135 template <typename Char, typename StringType, bool comma> | 5137 template <typename Char, typename StringType, bool comma> |
| 5136 static MaybeObject* QuoteJsonString(Vector<const Char> characters) { | 5138 static MaybeObject* QuoteJsonString(Isolate* isolate, |
| 5139 Vector<const Char> characters) { |
| 5137 int length = characters.length(); | 5140 int length = characters.length(); |
| 5138 COUNTERS->quote_json_char_count()->Increment(length); | 5141 isolate->counters()->quote_json_char_count()->Increment(length); |
| 5139 const int kSpaceForQuotes = 2 + (comma ? 1 :0); | 5142 const int kSpaceForQuotes = 2 + (comma ? 1 :0); |
| 5140 int worst_case_length = length * kJsonQuoteWorstCaseBlowup + kSpaceForQuotes; | 5143 int worst_case_length = length * kJsonQuoteWorstCaseBlowup + kSpaceForQuotes; |
| 5141 if (worst_case_length > kMaxGuaranteedNewSpaceString) { | 5144 if (worst_case_length > kMaxGuaranteedNewSpaceString) { |
| 5142 return SlowQuoteJsonString<Char, StringType, comma>(characters); | 5145 return SlowQuoteJsonString<Char, StringType, comma>(isolate, characters); |
| 5143 } | 5146 } |
| 5144 | 5147 |
| 5145 MaybeObject* new_alloc = AllocateRawString<StringType>(worst_case_length); | 5148 MaybeObject* new_alloc = AllocateRawString<StringType>(isolate, |
| 5149 worst_case_length); |
| 5146 Object* new_object; | 5150 Object* new_object; |
| 5147 if (!new_alloc->ToObject(&new_object)) { | 5151 if (!new_alloc->ToObject(&new_object)) { |
| 5148 return new_alloc; | 5152 return new_alloc; |
| 5149 } | 5153 } |
| 5150 if (!HEAP->new_space()->Contains(new_object)) { | 5154 if (!isolate->heap()->new_space()->Contains(new_object)) { |
| 5151 // Even if our string is small enough to fit in new space we still have to | 5155 // Even if our string is small enough to fit in new space we still have to |
| 5152 // handle it being allocated in old space as may happen in the third | 5156 // handle it being allocated in old space as may happen in the third |
| 5153 // attempt. See CALL_AND_RETRY in heap-inl.h and similar code in | 5157 // attempt. See CALL_AND_RETRY in heap-inl.h and similar code in |
| 5154 // CEntryStub::GenerateCore. | 5158 // CEntryStub::GenerateCore. |
| 5155 return SlowQuoteJsonString<Char, StringType, comma>(characters); | 5159 return SlowQuoteJsonString<Char, StringType, comma>(isolate, characters); |
| 5156 } | 5160 } |
| 5157 StringType* new_string = StringType::cast(new_object); | 5161 StringType* new_string = StringType::cast(new_object); |
| 5158 ASSERT(HEAP->new_space()->Contains(new_string)); | 5162 ASSERT(isolate->heap()->new_space()->Contains(new_string)); |
| 5159 | 5163 |
| 5160 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqAsciiString::kHeaderSize); | 5164 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqAsciiString::kHeaderSize); |
| 5161 Char* write_cursor = reinterpret_cast<Char*>( | 5165 Char* write_cursor = reinterpret_cast<Char*>( |
| 5162 new_string->address() + SeqAsciiString::kHeaderSize); | 5166 new_string->address() + SeqAsciiString::kHeaderSize); |
| 5163 if (comma) *(write_cursor++) = ','; | 5167 if (comma) *(write_cursor++) = ','; |
| 5164 *(write_cursor++) = '"'; | 5168 *(write_cursor++) = '"'; |
| 5165 | 5169 |
| 5166 const Char* read_cursor = characters.start(); | 5170 const Char* read_cursor = characters.start(); |
| 5167 const Char* end = read_cursor + length; | 5171 const Char* end = read_cursor + length; |
| 5168 while (read_cursor < end) { | 5172 while (read_cursor < end) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 5185 } | 5189 } |
| 5186 } | 5190 } |
| 5187 write_cursor += len; | 5191 write_cursor += len; |
| 5188 } | 5192 } |
| 5189 } | 5193 } |
| 5190 *(write_cursor++) = '"'; | 5194 *(write_cursor++) = '"'; |
| 5191 | 5195 |
| 5192 int final_length = static_cast<int>( | 5196 int final_length = static_cast<int>( |
| 5193 write_cursor - reinterpret_cast<Char*>( | 5197 write_cursor - reinterpret_cast<Char*>( |
| 5194 new_string->address() + SeqAsciiString::kHeaderSize)); | 5198 new_string->address() + SeqAsciiString::kHeaderSize)); |
| 5195 HEAP->new_space()->ShrinkStringAtAllocationBoundary<StringType>(new_string, | 5199 isolate->heap()->new_space()->ShrinkStringAtAllocationBoundary<StringType>( |
| 5196 final_length); | 5200 new_string, final_length); |
| 5197 return new_string; | 5201 return new_string; |
| 5198 } | 5202 } |
| 5199 | 5203 |
| 5200 | 5204 |
| 5201 static MaybeObject* Runtime_QuoteJSONString(RUNTIME_CALLING_CONVENTION) { | 5205 static MaybeObject* Runtime_QuoteJSONString(RUNTIME_CALLING_CONVENTION) { |
| 5202 RUNTIME_GET_ISOLATE; | 5206 RUNTIME_GET_ISOLATE; |
| 5203 NoHandleAllocation ha; | 5207 NoHandleAllocation ha; |
| 5204 CONVERT_CHECKED(String, str, args[0]); | 5208 CONVERT_CHECKED(String, str, args[0]); |
| 5205 if (!str->IsFlat()) { | 5209 if (!str->IsFlat()) { |
| 5206 MaybeObject* try_flatten = str->TryFlatten(); | 5210 MaybeObject* try_flatten = str->TryFlatten(); |
| 5207 Object* flat; | 5211 Object* flat; |
| 5208 if (!try_flatten->ToObject(&flat)) { | 5212 if (!try_flatten->ToObject(&flat)) { |
| 5209 return try_flatten; | 5213 return try_flatten; |
| 5210 } | 5214 } |
| 5211 str = String::cast(flat); | 5215 str = String::cast(flat); |
| 5212 ASSERT(str->IsFlat()); | 5216 ASSERT(str->IsFlat()); |
| 5213 } | 5217 } |
| 5214 if (str->IsTwoByteRepresentation()) { | 5218 if (str->IsTwoByteRepresentation()) { |
| 5215 return QuoteJsonString<uc16, SeqTwoByteString, false>(str->ToUC16Vector()); | 5219 return QuoteJsonString<uc16, SeqTwoByteString, false>(isolate, |
| 5220 str->ToUC16Vector()); |
| 5216 } else { | 5221 } else { |
| 5217 return QuoteJsonString<char, SeqAsciiString, false>(str->ToAsciiVector()); | 5222 return QuoteJsonString<char, SeqAsciiString, false>(isolate, |
| 5223 str->ToAsciiVector()); |
| 5218 } | 5224 } |
| 5219 } | 5225 } |
| 5220 | 5226 |
| 5221 | 5227 |
| 5222 static MaybeObject* Runtime_QuoteJSONStringComma(RUNTIME_CALLING_CONVENTION) { | 5228 static MaybeObject* Runtime_QuoteJSONStringComma(RUNTIME_CALLING_CONVENTION) { |
| 5223 RUNTIME_GET_ISOLATE; | 5229 RUNTIME_GET_ISOLATE; |
| 5224 NoHandleAllocation ha; | 5230 NoHandleAllocation ha; |
| 5225 CONVERT_CHECKED(String, str, args[0]); | 5231 CONVERT_CHECKED(String, str, args[0]); |
| 5226 if (!str->IsFlat()) { | 5232 if (!str->IsFlat()) { |
| 5227 MaybeObject* try_flatten = str->TryFlatten(); | 5233 MaybeObject* try_flatten = str->TryFlatten(); |
| 5228 Object* flat; | 5234 Object* flat; |
| 5229 if (!try_flatten->ToObject(&flat)) { | 5235 if (!try_flatten->ToObject(&flat)) { |
| 5230 return try_flatten; | 5236 return try_flatten; |
| 5231 } | 5237 } |
| 5232 str = String::cast(flat); | 5238 str = String::cast(flat); |
| 5233 ASSERT(str->IsFlat()); | 5239 ASSERT(str->IsFlat()); |
| 5234 } | 5240 } |
| 5235 if (str->IsTwoByteRepresentation()) { | 5241 if (str->IsTwoByteRepresentation()) { |
| 5236 return QuoteJsonString<uc16, SeqTwoByteString, true>(str->ToUC16Vector()); | 5242 return QuoteJsonString<uc16, SeqTwoByteString, true>(isolate, |
| 5243 str->ToUC16Vector()); |
| 5237 } else { | 5244 } else { |
| 5238 return QuoteJsonString<char, SeqAsciiString, true>(str->ToAsciiVector()); | 5245 return QuoteJsonString<char, SeqAsciiString, true>(isolate, |
| 5246 str->ToAsciiVector()); |
| 5239 } | 5247 } |
| 5240 } | 5248 } |
| 5241 | 5249 |
| 5242 static MaybeObject* Runtime_StringParseInt(RUNTIME_CALLING_CONVENTION) { | 5250 static MaybeObject* Runtime_StringParseInt(RUNTIME_CALLING_CONVENTION) { |
| 5243 RUNTIME_GET_ISOLATE; | 5251 RUNTIME_GET_ISOLATE; |
| 5244 NoHandleAllocation ha; | 5252 NoHandleAllocation ha; |
| 5245 | 5253 |
| 5246 CONVERT_CHECKED(String, s, args[0]); | 5254 CONVERT_CHECKED(String, s, args[0]); |
| 5247 CONVERT_SMI_CHECKED(radix, args[1]); | 5255 CONVERT_SMI_CHECKED(radix, args[1]); |
| 5248 | 5256 |
| (...skipping 6934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12183 } else { | 12191 } else { |
| 12184 // Handle last resort GC and make sure to allow future allocations | 12192 // Handle last resort GC and make sure to allow future allocations |
| 12185 // to grow the heap without causing GCs (if possible). | 12193 // to grow the heap without causing GCs (if possible). |
| 12186 COUNTERS->gc_last_resort_from_js()->Increment(); | 12194 COUNTERS->gc_last_resort_from_js()->Increment(); |
| 12187 HEAP->CollectAllGarbage(false); | 12195 HEAP->CollectAllGarbage(false); |
| 12188 } | 12196 } |
| 12189 } | 12197 } |
| 12190 | 12198 |
| 12191 | 12199 |
| 12192 } } // namespace v8::internal | 12200 } } // namespace v8::internal |
| OLD | NEW |