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/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 per-isolate container of data that should be
23// persisted between compiler runs. For now it stores the code builtins
24// so they are not serialized on each compiler run.
25class PerIsolateCompilerCache : public ZoneObject {
26 public:
27 explicit PerIsolateCompilerCache(Zone* zone)
28 : zone_(zone), refs_snapshot_(nullptr) {}
29
30 RefsMap* GetSnapshot() { return refs_snapshot_; }
31 void SetSnapshot(RefsMap* refs) {
32 DCHECK_NULL(refs_snapshot_);
33 DCHECK(!refs->IsEmpty());
34 refs_snapshot_ = new (zone_) RefsMap(refs, zone_);
35 }
36
37 bool HasSnapshot() const { return refs_snapshot_; }
38
39 Zone* zone() const { return zone_; }
40
41 static void Setup(Isolate* isolate) {
42 if (isolate->compiler_cache()) return;
43
44 // The following zone is supposed to contain compiler-related objects
45 // that should live through all compilations, as opposed to the
46 // broker_zone which holds per-compilation data. It's not meant for
47 // per-compilation or heap broker data.
48 Zone* compiler_zone = new Zone(isolate->allocator(), "Compiler zone");
49 PerIsolateCompilerCache* compiler_cache =
50 new (compiler_zone) PerIsolateCompilerCache(compiler_zone);
51 isolate->set_compiler_utils(compiler_cache, compiler_zone);
52 }
53
54 private:
55 Zone* const zone_;
56
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