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

Side by Side Diff: src/serialize.cc

Issue 1003363003: Serializer: cache hashmaps on the isolate. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: remove bogus test. rebased Created 5 years, 9 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
« no previous file with comments | « src/serialize.h ('k') | src/snapshot-source-sink.cc » ('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 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/api.h" 8 #include "src/api.h"
9 #include "src/base/platform/platform.h" 9 #include "src/base/platform/platform.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 Address address = Deoptimizer::GetDeoptimizationEntry( 331 Address address = Deoptimizer::GetDeoptimizationEntry(
332 isolate, 332 isolate,
333 entry, 333 entry,
334 Deoptimizer::LAZY, 334 Deoptimizer::LAZY,
335 Deoptimizer::CALCULATE_ENTRY_ADDRESS); 335 Deoptimizer::CALCULATE_ENTRY_ADDRESS);
336 Add(address, "lazy_deopt"); 336 Add(address, "lazy_deopt");
337 } 337 }
338 } 338 }
339 339
340 340
341 ExternalReferenceEncoder::ExternalReferenceEncoder(Isolate* isolate) 341 ExternalReferenceEncoder::ExternalReferenceEncoder(Isolate* isolate) {
342 : map_(HashMap::PointersMatch) { 342 map_ = isolate->external_reference_map();
343 if (map_ != NULL) return;
344 map_ = new HashMap(HashMap::PointersMatch);
343 ExternalReferenceTable* table = ExternalReferenceTable::instance(isolate); 345 ExternalReferenceTable* table = ExternalReferenceTable::instance(isolate);
344 for (int i = 0; i < table->size(); ++i) { 346 for (int i = 0; i < table->size(); ++i) {
345 Address addr = table->address(i); 347 Address addr = table->address(i);
346 if (addr == ExternalReferenceTable::NotAvailable()) continue; 348 if (addr == ExternalReferenceTable::NotAvailable()) continue;
347 // We expect no duplicate external references entries in the table. 349 // We expect no duplicate external references entries in the table.
348 DCHECK_NULL(map_.Lookup(addr, Hash(addr), false)); 350 DCHECK_NULL(map_->Lookup(addr, Hash(addr), false));
349 map_.Lookup(addr, Hash(addr), true)->value = reinterpret_cast<void*>(i); 351 map_->Lookup(addr, Hash(addr), true)->value = reinterpret_cast<void*>(i);
350 } 352 }
353 isolate->set_external_reference_map(map_);
351 } 354 }
352 355
353 356
354 uint32_t ExternalReferenceEncoder::Encode(Address address) const { 357 uint32_t ExternalReferenceEncoder::Encode(Address address) const {
355 DCHECK_NOT_NULL(address); 358 DCHECK_NOT_NULL(address);
356 HashMap::Entry* entry = 359 HashMap::Entry* entry =
357 const_cast<HashMap&>(map_).Lookup(address, Hash(address), false); 360 const_cast<HashMap*>(map_)->Lookup(address, Hash(address), false);
358 DCHECK_NOT_NULL(entry); 361 DCHECK_NOT_NULL(entry);
359 return static_cast<uint32_t>(reinterpret_cast<intptr_t>(entry->value)); 362 return static_cast<uint32_t>(reinterpret_cast<intptr_t>(entry->value));
360 } 363 }
361 364
362 365
363 const char* ExternalReferenceEncoder::NameOfAddress(Isolate* isolate, 366 const char* ExternalReferenceEncoder::NameOfAddress(Isolate* isolate,
364 Address address) const { 367 Address address) const {
365 HashMap::Entry* entry = 368 HashMap::Entry* entry =
366 const_cast<HashMap&>(map_).Lookup(address, Hash(address), false); 369 const_cast<HashMap*>(map_)->Lookup(address, Hash(address), false);
367 if (entry == NULL) return "<unknown>"; 370 if (entry == NULL) return "<unknown>";
368 uint32_t i = static_cast<uint32_t>(reinterpret_cast<intptr_t>(entry->value)); 371 uint32_t i = static_cast<uint32_t>(reinterpret_cast<intptr_t>(entry->value));
369 return ExternalReferenceTable::instance(isolate)->name(i); 372 return ExternalReferenceTable::instance(isolate)->name(i);
370 } 373 }
371 374
372 375
373 RootIndexMap::RootIndexMap(Isolate* isolate) : map_(HashMap::PointersMatch) { 376 RootIndexMap::RootIndexMap(Isolate* isolate) {
377 map_ = isolate->root_index_map();
378 if (map_ != NULL) return;
379 map_ = new HashMap(HashMap::PointersMatch);
374 Object** root_array = isolate->heap()->roots_array_start(); 380 Object** root_array = isolate->heap()->roots_array_start();
375 for (uint32_t i = 0; i < Heap::kStrongRootListLength; i++) { 381 for (uint32_t i = 0; i < Heap::kStrongRootListLength; i++) {
376 Heap::RootListIndex root_index = static_cast<Heap::RootListIndex>(i); 382 Heap::RootListIndex root_index = static_cast<Heap::RootListIndex>(i);
377 Object* root = root_array[root_index]; 383 Object* root = root_array[root_index];
378 // Omit root entries that can be written after initialization. They must 384 // Omit root entries that can be written after initialization. They must
379 // not be referenced through the root list in the snapshot. 385 // not be referenced through the root list in the snapshot.
380 if (root->IsHeapObject() && 386 if (root->IsHeapObject() &&
381 isolate->heap()->RootCanBeTreatedAsConstant(root_index)) { 387 isolate->heap()->RootCanBeTreatedAsConstant(root_index)) {
382 HeapObject* heap_object = HeapObject::cast(root); 388 HeapObject* heap_object = HeapObject::cast(root);
383 HashMap::Entry* entry = LookupEntry(&map_, heap_object, false); 389 HashMap::Entry* entry = LookupEntry(map_, heap_object, false);
384 if (entry != NULL) { 390 if (entry != NULL) {
385 // Some are initialized to a previous value in the root list. 391 // Some are initialized to a previous value in the root list.
386 DCHECK_LT(GetValue(entry), i); 392 DCHECK_LT(GetValue(entry), i);
387 } else { 393 } else {
388 SetValue(LookupEntry(&map_, heap_object, true), i); 394 SetValue(LookupEntry(map_, heap_object, true), i);
389 } 395 }
390 } 396 }
391 } 397 }
398 isolate->set_root_index_map(map_);
392 } 399 }
393 400
394 401
395 class CodeAddressMap: public CodeEventLogger { 402 class CodeAddressMap: public CodeEventLogger {
396 public: 403 public:
397 explicit CodeAddressMap(Isolate* isolate) 404 explicit CodeAddressMap(Isolate* isolate)
398 : isolate_(isolate) { 405 : isolate_(isolate) {
399 isolate->logger()->addCodeEventListener(this); 406 isolate->logger()->addCodeEventListener(this);
400 } 407 }
401 408
(...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 CHECK(false); 1202 CHECK(false);
1196 } 1203 }
1197 } 1204 }
1198 CHECK_EQ(limit, current); 1205 CHECK_EQ(limit, current);
1199 } 1206 }
1200 1207
1201 1208
1202 Serializer::Serializer(Isolate* isolate, SnapshotByteSink* sink) 1209 Serializer::Serializer(Isolate* isolate, SnapshotByteSink* sink)
1203 : isolate_(isolate), 1210 : isolate_(isolate),
1204 sink_(sink), 1211 sink_(sink),
1205 external_reference_encoder_(new ExternalReferenceEncoder(isolate)), 1212 external_reference_encoder_(isolate),
1206 root_index_map_(isolate), 1213 root_index_map_(isolate),
1207 code_address_map_(NULL), 1214 code_address_map_(NULL),
1208 large_objects_total_size_(0), 1215 large_objects_total_size_(0),
1209 seen_large_objects_index_(0) { 1216 seen_large_objects_index_(0) {
1210 // The serializer is meant to be used only to generate initial heap images 1217 // The serializer is meant to be used only to generate initial heap images
1211 // from a context in which there is only one isolate. 1218 // from a context in which there is only one isolate.
1212 for (int i = 0; i < kNumberOfPreallocatedSpaces; i++) { 1219 for (int i = 0; i < kNumberOfPreallocatedSpaces; i++) {
1213 pending_chunk_[i] = 0; 1220 pending_chunk_[i] = 0;
1214 max_chunk_size_[i] = static_cast<uint32_t>( 1221 max_chunk_size_[i] = static_cast<uint32_t>(
1215 MemoryAllocator::PageAreaSize(static_cast<AllocationSpace>(i))); 1222 MemoryAllocator::PageAreaSize(static_cast<AllocationSpace>(i)));
1216 } 1223 }
1217 } 1224 }
1218 1225
1219 1226
1220 Serializer::~Serializer() { 1227 Serializer::~Serializer() {
1221 delete external_reference_encoder_;
1222 if (code_address_map_ != NULL) delete code_address_map_; 1228 if (code_address_map_ != NULL) delete code_address_map_;
1223 } 1229 }
1224 1230
1225 1231
1226 void StartupSerializer::SerializeStrongReferences() { 1232 void StartupSerializer::SerializeStrongReferences() {
1227 Isolate* isolate = this->isolate(); 1233 Isolate* isolate = this->isolate();
1228 // No active threads. 1234 // No active threads.
1229 CHECK_NULL(isolate->thread_manager()->FirstThreadStateInUse()); 1235 CHECK_NULL(isolate->thread_manager()->FirstThreadStateInUse());
1230 // No active or weak handles. 1236 // No active or weak handles.
1231 CHECK(isolate->handle_scope_implementer()->blocks()->is_empty()); 1237 CHECK(isolate->handle_scope_implementer()->blocks()->is_empty());
(...skipping 1286 matching lines...) Expand 10 before | Expand all | Expand 10 after
2518 DisallowHeapAllocation no_gc; 2524 DisallowHeapAllocation no_gc;
2519 SerializedCodeData* scd = new SerializedCodeData(cached_data); 2525 SerializedCodeData* scd = new SerializedCodeData(cached_data);
2520 SanityCheckResult r = scd->SanityCheck(isolate, source); 2526 SanityCheckResult r = scd->SanityCheck(isolate, source);
2521 if (r == CHECK_SUCCESS) return scd; 2527 if (r == CHECK_SUCCESS) return scd;
2522 cached_data->Reject(); 2528 cached_data->Reject();
2523 source->GetIsolate()->counters()->code_cache_reject_reason()->AddSample(r); 2529 source->GetIsolate()->counters()->code_cache_reject_reason()->AddSample(r);
2524 delete scd; 2530 delete scd;
2525 return NULL; 2531 return NULL;
2526 } 2532 }
2527 } } // namespace v8::internal 2533 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/serialize.h ('k') | src/snapshot-source-sink.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698