Remove reinvented wheel for partial snapshot cache.

R=jkummerow@chromium.org

Review URL: https://codereview.chromium.org/946073003

Cr-Commit-Position: refs/heads/master@{#26815}
This commit is contained in:
yangguo 2015-02-24 03:31:12 -08:00 committed by Commit bot
parent 43c7345b35
commit abf122cc97
4 changed files with 17 additions and 55 deletions

View File

@ -1754,11 +1754,6 @@ void Isolate::TearDown() {
thread_data_table_->RemoveAllThreads(this);
}
if (serialize_partial_snapshot_cache_ != NULL) {
delete[] serialize_partial_snapshot_cache_;
serialize_partial_snapshot_cache_ = NULL;
}
delete this;
// Restore the previous current isolate.
@ -1822,26 +1817,6 @@ void Isolate::Deinit() {
}
void Isolate::PushToPartialSnapshotCache(Object* obj) {
int length = serialize_partial_snapshot_cache_length();
int capacity = serialize_partial_snapshot_cache_capacity();
if (length >= capacity) {
int new_capacity = static_cast<int>((capacity + 10) * 1.2);
Object** new_array = new Object*[new_capacity];
for (int i = 0; i < length; i++) {
new_array[i] = serialize_partial_snapshot_cache()[i];
}
if (capacity != 0) delete[] serialize_partial_snapshot_cache();
set_serialize_partial_snapshot_cache(new_array);
set_serialize_partial_snapshot_cache_capacity(new_capacity);
}
serialize_partial_snapshot_cache()[length] = obj;
set_serialize_partial_snapshot_cache_length(length + 1);
}
void Isolate::SetIsolateThreadLocals(Isolate* isolate,
PerIsolateThreadData* data) {
base::Thread::SetThreadLocal(isolate_key_, isolate);
@ -2085,7 +2060,7 @@ bool Isolate::Init(Deserializer* des) {
if (create_heap_objects) {
// Terminate the cache array with the sentinel so we can iterate.
PushToPartialSnapshotCache(heap_.undefined_value());
partial_snapshot_cache_.Add(heap_.undefined_value());
}
InitializeThreadLocal();

View File

@ -355,10 +355,6 @@ class ThreadLocalTop BASE_EMBEDDED {
typedef List<HeapObject*> DebugObjectCache;
#define ISOLATE_INIT_LIST(V) \
/* SerializerDeserializer state. */ \
V(int, serialize_partial_snapshot_cache_length, 0) \
V(int, serialize_partial_snapshot_cache_capacity, 0) \
V(Object**, serialize_partial_snapshot_cache, NULL) \
/* Assembler state. */ \
V(FatalErrorCallback, exception_behavior, NULL) \
V(LogEventCallback, event_logger, NULL) \
@ -643,9 +639,6 @@ class Isolate {
return exception != heap()->termination_exception();
}
// Serializer.
void PushToPartialSnapshotCache(Object* obj);
// JS execution stack (see frames.h).
static Address c_entry_fp(ThreadLocalTop* thread) {
return thread->c_entry_fp_;
@ -1133,6 +1126,8 @@ class Isolate {
void AddDetachedContext(Handle<Context> context);
void CheckDetachedContextsAfterGC();
List<Object*>* partial_snapshot_cache() { return &partial_snapshot_cache_; }
private:
explicit Isolate(bool enable_serializer);
@ -1354,6 +1349,7 @@ class Isolate {
v8::Isolate::UseCounterCallback use_counter_callback_;
BasicBlockProfiler* basic_block_profiler_;
List<Object*> partial_snapshot_cache_;
friend class ExecutionAccess;
friend class HandleScopeImplementer;

View File

@ -998,7 +998,7 @@ void Deserializer::ReadData(Object** current, Object** limit, int source_space,
emit_write_barrier = isolate->heap()->InNewSpace(new_object); \
} else if (where == kPartialSnapshotCache) { \
int cache_index = source_.GetInt(); \
new_object = isolate->serialize_partial_snapshot_cache()[cache_index]; \
new_object = isolate->partial_snapshot_cache()->at(cache_index); \
emit_write_barrier = isolate->heap()->InNewSpace(new_object); \
} else if (where == kExternalReference) { \
int skip = source_.GetInt(); \
@ -1508,43 +1508,34 @@ void Serializer::EncodeReservations(
void SerializerDeserializer::Iterate(Isolate* isolate,
ObjectVisitor* visitor) {
if (isolate->serializer_enabled()) return;
for (int i = 0; ; i++) {
if (isolate->serialize_partial_snapshot_cache_length() <= i) {
// Extend the array ready to get a value from the visitor when
// deserializing.
isolate->PushToPartialSnapshotCache(Smi::FromInt(0));
}
Object** cache = isolate->serialize_partial_snapshot_cache();
visitor->VisitPointers(&cache[i], &cache[i + 1]);
List<Object*>* cache = isolate->partial_snapshot_cache();
for (int i = 0;; ++i) {
// Extend the array ready to get a value when deserializing.
if (cache->length() <= i) cache->Add(Smi::FromInt(0));
visitor->VisitPointer(&cache->at(i));
// Sentinel is the undefined object, which is a root so it will not normally
// be found in the cache.
if (cache[i] == isolate->heap()->undefined_value()) {
break;
}
if (cache->at(i)->IsUndefined()) break;
}
}
int PartialSerializer::PartialSnapshotCacheIndex(HeapObject* heap_object) {
Isolate* isolate = this->isolate();
for (int i = 0;
i < isolate->serialize_partial_snapshot_cache_length();
i++) {
Object* entry = isolate->serialize_partial_snapshot_cache()[i];
List<Object*>* cache = isolate->partial_snapshot_cache();
for (int i = 0; i < cache->length(); ++i) {
Object* entry = cache->at(i);
if (entry == heap_object) return i;
}
// We didn't find the object in the cache. So we add it to the cache and
// then visit the pointer so that it becomes part of the startup snapshot
// and we can refer to it from the partial snapshot.
int length = isolate->serialize_partial_snapshot_cache_length();
isolate->PushToPartialSnapshotCache(heap_object);
cache->Add(heap_object);
startup_serializer_->VisitPointer(reinterpret_cast<Object**>(&heap_object));
// We don't recurse from the startup snapshot generator into the partial
// snapshot generator.
DCHECK(length == isolate->serialize_partial_snapshot_cache_length() - 1);
return length;
return cache->length() - 1;
}

View File

@ -814,7 +814,7 @@ class StartupSerializer : public Serializer {
// strong roots have been serialized we can create a partial snapshot
// which will repopulate the cache with objects needed by that partial
// snapshot.
isolate->set_serialize_partial_snapshot_cache_length(0);
isolate->partial_snapshot_cache()->Clear();
InitializeCodeAddressMap();
}