Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(323)

Side by Side Diff: src/ast-value-factory.cc

Issue 707483002: Revert "Parser & internalization fix: ensure no heap allocs during GetString(Handle<String>)." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/ast-value-factory.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 case THE_HOLE: 205 case THE_HOLE:
206 value_ = isolate->factory()->the_hole_value(); 206 value_ = isolate->factory()->the_hole_value();
207 break; 207 break;
208 case UNDEFINED: 208 case UNDEFINED:
209 value_ = isolate->factory()->undefined_value(); 209 value_ = isolate->factory()->undefined_value();
210 break; 210 break;
211 } 211 }
212 } 212 }
213 213
214 214
215 AstRawString* AstValueFactory::GetOneByteStringInternal( 215 const AstRawString* AstValueFactory::GetOneByteString(
216 Vector<const uint8_t> literal) { 216 Vector<const uint8_t> literal) {
217 uint32_t hash = StringHasher::HashSequentialString<uint8_t>( 217 uint32_t hash = StringHasher::HashSequentialString<uint8_t>(
218 literal.start(), literal.length(), hash_seed_); 218 literal.start(), literal.length(), hash_seed_);
219 return GetString(hash, true, literal); 219 return GetString(hash, true, literal);
220 } 220 }
221 221
222 222
223 AstRawString* AstValueFactory::GetTwoByteStringInternal( 223 const AstRawString* AstValueFactory::GetTwoByteString(
224 Vector<const uint16_t> literal) { 224 Vector<const uint16_t> literal) {
225 uint32_t hash = StringHasher::HashSequentialString<uint16_t>( 225 uint32_t hash = StringHasher::HashSequentialString<uint16_t>(
226 literal.start(), literal.length(), hash_seed_); 226 literal.start(), literal.length(), hash_seed_);
227 return GetString(hash, false, Vector<const byte>::cast(literal)); 227 return GetString(hash, false, Vector<const byte>::cast(literal));
228 } 228 }
229 229
230 230
231 const AstRawString* AstValueFactory::GetString(Handle<String> literal) { 231 const AstRawString* AstValueFactory::GetString(Handle<String> literal) {
232 // For the FlatContent to stay valid, we shouldn't do any heap
233 // allocation. Make sure we won't try to internalize the string in GetString.
234 AstRawString* result = NULL;
235 Isolate* saved_isolate = isolate_;
236 isolate_ = NULL;
237 DisallowHeapAllocation no_gc; 232 DisallowHeapAllocation no_gc;
238 String::FlatContent content = literal->GetFlatContent(); 233 String::FlatContent content = literal->GetFlatContent();
239 if (content.IsOneByte()) { 234 if (content.IsOneByte()) {
240 result = GetOneByteStringInternal(content.ToOneByteVector()); 235 return GetOneByteString(content.ToOneByteVector());
241 } else {
242 DCHECK(content.IsTwoByte());
243 result = GetTwoByteStringInternal(content.ToUC16Vector());
244 } 236 }
245 isolate_ = saved_isolate; 237 DCHECK(content.IsTwoByte());
246 result->string_ = literal; 238 return GetTwoByteString(content.ToUC16Vector());
247 return result;
248 } 239 }
249 240
250 241
251 const AstConsString* AstValueFactory::NewConsString( 242 const AstConsString* AstValueFactory::NewConsString(
252 const AstString* left, const AstString* right) { 243 const AstString* left, const AstString* right) {
253 // This Vector will be valid as long as the Collector is alive (meaning that 244 // This Vector will be valid as long as the Collector is alive (meaning that
254 // the AstRawString will not be moved). 245 // the AstRawString will not be moved).
255 AstConsString* new_string = new (zone_) AstConsString(left, right); 246 AstConsString* new_string = new (zone_) AstConsString(left, right);
256 strings_.Add(new_string); 247 strings_.Add(new_string);
257 if (isolate_) { 248 if (isolate_) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 } 341 }
351 342
352 343
353 const AstValue* AstValueFactory::NewTheHole() { 344 const AstValue* AstValueFactory::NewTheHole() {
354 GENERATE_VALUE_GETTER(the_hole_value_, AstValue::THE_HOLE); 345 GENERATE_VALUE_GETTER(the_hole_value_, AstValue::THE_HOLE);
355 } 346 }
356 347
357 348
358 #undef GENERATE_VALUE_GETTER 349 #undef GENERATE_VALUE_GETTER
359 350
360 AstRawString* AstValueFactory::GetString(uint32_t hash, bool is_one_byte, 351 const AstRawString* AstValueFactory::GetString(
361 Vector<const byte> literal_bytes) { 352 uint32_t hash, bool is_one_byte, Vector<const byte> literal_bytes) {
362 // literal_bytes here points to whatever the user passed, and this is OK 353 // literal_bytes here points to whatever the user passed, and this is OK
363 // because we use vector_compare (which checks the contents) to compare 354 // because we use vector_compare (which checks the contents) to compare
364 // against the AstRawStrings which are in the string_table_. We should not 355 // against the AstRawStrings which are in the string_table_. We should not
365 // return this AstRawString. 356 // return this AstRawString.
366 AstRawString key(is_one_byte, literal_bytes, hash); 357 AstRawString key(is_one_byte, literal_bytes, hash);
367 HashMap::Entry* entry = string_table_.Lookup(&key, hash, true); 358 HashMap::Entry* entry = string_table_.Lookup(&key, hash, true);
368 if (entry->value == NULL) { 359 if (entry->value == NULL) {
369 // Copy literal contents for later comparison. 360 // Copy literal contents for later comparison.
370 int length = literal_bytes.length(); 361 int length = literal_bytes.length();
371 byte* new_literal_bytes = zone_->NewArray<byte>(length); 362 byte* new_literal_bytes = zone_->NewArray<byte>(length);
372 memcpy(new_literal_bytes, literal_bytes.start(), length); 363 memcpy(new_literal_bytes, literal_bytes.start(), length);
373 AstRawString* new_string = new (zone_) AstRawString( 364 AstRawString* new_string = new (zone_) AstRawString(
374 is_one_byte, Vector<const byte>(new_literal_bytes, length), hash); 365 is_one_byte, Vector<const byte>(new_literal_bytes, length), hash);
375 entry->key = new_string; 366 entry->key = new_string;
376 strings_.Add(new_string); 367 strings_.Add(new_string);
377 if (isolate_) { 368 if (isolate_) {
378 new_string->Internalize(isolate_); 369 new_string->Internalize(isolate_);
379 } 370 }
380 entry->value = reinterpret_cast<void*>(1); 371 entry->value = reinterpret_cast<void*>(1);
381 } 372 }
382 return reinterpret_cast<AstRawString*>(entry->key); 373 return reinterpret_cast<AstRawString*>(entry->key);
383 } 374 }
384 375
385 376
386 } } // namespace v8::internal 377 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/ast-value-factory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698