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

Side by Side Diff: src/heap.cc

Issue 12223071: ES6 symbols: Introduce Symbol class, along with abstract Name class (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments Created 7 years, 10 months 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/heap.h ('k') | src/objects.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2369 matching lines...) Expand 10 before | Expand all | Expand 10 after
2380 AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel); 2380 AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
2381 if (!maybe_obj->ToObject(&obj)) return false; 2381 if (!maybe_obj->ToObject(&obj)) return false;
2382 } 2382 }
2383 set_scope_info_map(Map::cast(obj)); 2383 set_scope_info_map(Map::cast(obj));
2384 2384
2385 { MaybeObject* maybe_obj = AllocateMap(HEAP_NUMBER_TYPE, HeapNumber::kSize); 2385 { MaybeObject* maybe_obj = AllocateMap(HEAP_NUMBER_TYPE, HeapNumber::kSize);
2386 if (!maybe_obj->ToObject(&obj)) return false; 2386 if (!maybe_obj->ToObject(&obj)) return false;
2387 } 2387 }
2388 set_heap_number_map(Map::cast(obj)); 2388 set_heap_number_map(Map::cast(obj));
2389 2389
2390 { MaybeObject* maybe_obj = AllocateMap(SYMBOL_TYPE, Symbol::kSize);
2391 if (!maybe_obj->ToObject(&obj)) return false;
2392 }
2393 set_symbol_map(Map::cast(obj));
2394
2390 { MaybeObject* maybe_obj = AllocateMap(FOREIGN_TYPE, Foreign::kSize); 2395 { MaybeObject* maybe_obj = AllocateMap(FOREIGN_TYPE, Foreign::kSize);
2391 if (!maybe_obj->ToObject(&obj)) return false; 2396 if (!maybe_obj->ToObject(&obj)) return false;
2392 } 2397 }
2393 set_foreign_map(Map::cast(obj)); 2398 set_foreign_map(Map::cast(obj));
2394 2399
2395 for (unsigned i = 0; i < ARRAY_SIZE(string_type_table); i++) { 2400 for (unsigned i = 0; i < ARRAY_SIZE(string_type_table); i++) {
2396 const StringTypeTable& entry = string_type_table[i]; 2401 const StringTypeTable& entry = string_type_table[i];
2397 { MaybeObject* maybe_obj = AllocateMap(entry.type, entry.size); 2402 { MaybeObject* maybe_obj = AllocateMap(entry.type, entry.size);
2398 if (!maybe_obj->ToObject(&obj)) return false; 2403 if (!maybe_obj->ToObject(&obj)) return false;
2399 } 2404 }
(...skipping 2763 matching lines...) Expand 10 before | Expand all | Expand 10 after
5163 { MaybeObject* maybe_result = AllocateFixedArray(length, pretenure); 5168 { MaybeObject* maybe_result = AllocateFixedArray(length, pretenure);
5164 if (!maybe_result->ToObject(&result)) return maybe_result; 5169 if (!maybe_result->ToObject(&result)) return maybe_result;
5165 } 5170 }
5166 reinterpret_cast<HeapObject*>(result)->set_map_no_write_barrier( 5171 reinterpret_cast<HeapObject*>(result)->set_map_no_write_barrier(
5167 hash_table_map()); 5172 hash_table_map());
5168 ASSERT(result->IsHashTable()); 5173 ASSERT(result->IsHashTable());
5169 return result; 5174 return result;
5170 } 5175 }
5171 5176
5172 5177
5178 MaybeObject* Heap::AllocateSymbol(PretenureFlag pretenure) {
5179 // Statically ensure that it is safe to allocate symbols in paged spaces.
5180 STATIC_ASSERT(Symbol::kSize <= Page::kNonCodeObjectAreaSize);
5181 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
5182
5183 Object* result;
5184 MaybeObject* maybe = AllocateRaw(Symbol::kSize, space, OLD_DATA_SPACE);
5185 if (!maybe->ToObject(&result)) return maybe;
5186
5187 HeapObject::cast(result)->set_map_no_write_barrier(symbol_map());
5188
5189 // Generate a random hash value.
5190 int hash;
5191 int attempts = 0;
5192 do {
5193 hash = V8::RandomPrivate(isolate()) & Name::kHashBitMask;
5194 attempts++;
5195 } while (hash == 0 && attempts < 30);
5196 if (hash == 0) hash = 1; // never return 0
5197
5198 Symbol::cast(result)->set_hash_field(
5199 Name::kIsNotArrayIndexMask | (hash << Name::kHashShift));
5200
5201 ASSERT(result->IsSymbol());
5202 return result;
5203 }
5204
5205
5173 MaybeObject* Heap::AllocateNativeContext() { 5206 MaybeObject* Heap::AllocateNativeContext() {
5174 Object* result; 5207 Object* result;
5175 { MaybeObject* maybe_result = 5208 { MaybeObject* maybe_result =
5176 AllocateFixedArray(Context::NATIVE_CONTEXT_SLOTS); 5209 AllocateFixedArray(Context::NATIVE_CONTEXT_SLOTS);
5177 if (!maybe_result->ToObject(&result)) return maybe_result; 5210 if (!maybe_result->ToObject(&result)) return maybe_result;
5178 } 5211 }
5179 Context* context = reinterpret_cast<Context*>(result); 5212 Context* context = reinterpret_cast<Context*>(result);
5180 context->set_map_no_write_barrier(native_context_map()); 5213 context->set_map_no_write_barrier(native_context_map());
5181 context->set_js_array_maps(undefined_value()); 5214 context->set_js_array_maps(undefined_value());
5182 ASSERT(context->IsNativeContext()); 5215 ASSERT(context->IsNativeContext());
(...skipping 2345 matching lines...) Expand 10 before | Expand all | Expand 10 after
7528 static_cast<int>(object_sizes_last_time_[index])); 7561 static_cast<int>(object_sizes_last_time_[index]));
7529 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) 7562 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT)
7530 #undef ADJUST_LAST_TIME_OBJECT_COUNT 7563 #undef ADJUST_LAST_TIME_OBJECT_COUNT
7531 7564
7532 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); 7565 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
7533 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); 7566 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
7534 ClearObjectStats(); 7567 ClearObjectStats();
7535 } 7568 }
7536 7569
7537 } } // namespace v8::internal 7570 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.h ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698