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 12namespace v8 { 13namespace internal { 14 15class Isolate; 16class Zone; 17 18namespace compiler { 19 20class 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. 27class PerIsolateCompilerCache : public ZoneObject { 28 public: 29 explicit PerIsolateCompilerCache(Zone* zone) 30 : zone_(zone), refs_snapshot_(nullptr) {} 31 32 bool HasSnapshot() const { return refs_snapshot_ != nullptr; } 33 RefsMap* GetSnapshot() { 34 DCHECK(HasSnapshot()); 35 return refs_snapshot_; 36 } 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 44 Zone* zone() const { return zone_; } 45 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