Shaka Player Embedded
v8_heap_tracer.cc
Go to the documentation of this file.
1 // Copyright 2016 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
16 
17 #include <glog/logging.h>
18 
21 #include "src/util/clock.h"
22 
23 namespace shaka {
24 namespace memory {
25 
27 
29 
31  return fields_.empty();
32 }
33 
34 void V8HeapTracer::TracePrologue(TraceFlags /* flags */) {
35  VLOG(2) << "GC run started";
36  fields_ = ObjectTracker::Instance()->GetAliveObjects();
37  BeginPass();
38 }
39 
40 void V8HeapTracer::TraceEpilogue(TraceSummary* /* trace_summary */) {
41  VLOG(2) << "GC run ended";
42  CHECK(fields_.empty());
43  ObjectTracker::Instance()->FreeDeadObjects(alive());
44  ResetState();
45 }
46 
47 void V8HeapTracer::EnterFinalPause(EmbedderStackState stack_state) {}
48 
50  const std::vector<std::pair<void*, void*>>& internal_fields) {
51  VLOG(2) << "GC add " << internal_fields.size() << " objects";
52  fields_.reserve(fields_.size() + internal_fields.size());
53  for (const auto& pair : internal_fields)
54  fields_.insert(reinterpret_cast<Traceable*>(pair.first));
55 }
56 
57 bool V8HeapTracer::AdvanceTracing(double /* deadline_ms */) {
58  VLOG(2) << "GC run step";
59  util::Clock clock;
60  const uint64_t start = clock.GetMonotonicTime();
61  TraceAll(fields_);
62 
63  VLOG(2) << "Tracing " << fields_.size() << " objects took "
64  << ((clock.GetMonotonicTime() - start) / 1000.0) << " seconds";
65  fields_.clear();
66  return false;
67 }
68 
69 } // namespace memory
70 } // namespace shaka
bool AdvanceTracing(double deadline_ms) override
const std::unordered_set< const Traceable * > & alive() const
Definition: heap_tracer.h:91
void TracePrologue(TraceFlags flags) override
void TraceEpilogue(TraceSummary *trace_summary) override
virtual uint64_t GetMonotonicTime() const
Definition: clock.cc:29
void EnterFinalPause(EmbedderStackState stack_state) override
void TraceAll(const std::unordered_set< const Traceable *> &ref_alive)
Definition: heap_tracer.cc:52
void RegisterV8References(const std::vector< std::pair< void *, void *>> &internal_fields) override