1 // Copyright 2018 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_COMPILER_PER_ISOLATE_COMPILER_CACHE_H_ 6 #define V8_COMPILER_PER_ISOLATE_COMPILER_CACHE_H_ 7 8 #include "src/compiler/refs-map.h" 9 #include "src/execution/isolate.h" 10 #include "src/zone/zone-containers.h" 11 12 namespace v8 { 13 namespace internal { 14 15 class Isolate; 16 class Zone; 17 18 namespace compiler { 19 20 class ObjectData; 21 22 // This class serves as a container of data that should persist across all 23 // (optimizing) compiler runs in an isolate. For now it stores serialized data 24 // for various common objects such as builtins, so that these objects don't have 25 // to be serialized in each compilation job. See JSHeapBroker::InitializeRefsMap 26 // for details. 27 class PerIsolateCompilerCache : public ZoneObject { 28 public: PerIsolateCompilerCache(Zone * zone)29 explicit PerIsolateCompilerCache(Zone* zone) 30 : zone_(zone), refs_snapshot_(nullptr) {} 31 HasSnapshot()32 bool HasSnapshot() const { return refs_snapshot_ != nullptr; } GetSnapshot()33 RefsMap* GetSnapshot() { 34 DCHECK(HasSnapshot()); 35 return refs_snapshot_; 36 } SetSnapshot(RefsMap * refs)37 void SetSnapshot(RefsMap* refs) { 38 DCHECK(!HasSnapshot()); 39 DCHECK(!refs->IsEmpty()); 40 refs_snapshot_ = zone_->New<RefsMap>(refs, zone_); 41 DCHECK(HasSnapshot()); 42 } 43 zone()44 Zone* zone() const { return zone_; } 45 Setup(Isolate * isolate)46 static void Setup(Isolate* isolate) { 47 if (isolate->compiler_cache() == nullptr) { 48 Zone* zone = new Zone(isolate->allocator(), "Compiler zone"); 49 PerIsolateCompilerCache* cache = zone->New<PerIsolateCompilerCache>(zone); 50 isolate->set_compiler_utils(cache, zone); 51 } 52 DCHECK_NOT_NULL(isolate->compiler_cache()); 53 } 54 55 private: 56 Zone* const zone_; 57 RefsMap* refs_snapshot_; 58 }; 59 60 } // namespace compiler 61 } // namespace internal 62 } // namespace v8 63 64 #endif // V8_COMPILER_PER_ISOLATE_COMPILER_CACHE_H_ 65