Skip to content

Commit

Permalink
[mycpp/runtime rename] PushScope/PopScope -> PushFrame/PopFrame
Browse files Browse the repository at this point in the history
To be consistent with RootsFrame.
  • Loading branch information
Andy C committed Nov 13, 2022
1 parent 2dba7b1 commit 1db3239
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions mycpp/gc_heap.h
Expand Up @@ -32,19 +32,19 @@ class RootsFrame {
explicit RootsFrame(const char* description) {
log(">>> %s", description);
#ifndef BUMP_LEAK
gHeap.root_set_.PushScope();
gHeap.root_set_.PushFrame();
#endif
}
#endif

RootsFrame() {
#ifndef BUMP_LEAK
gHeap.root_set_.PushScope();
gHeap.root_set_.PushFrame();
#endif
}
~RootsFrame() {
#ifndef BUMP_LEAK
gHeap.root_set_.PopScope();
gHeap.root_set_.PopFrame();
#endif
}
};
Expand Down
6 changes: 3 additions & 3 deletions mycpp/marksweep_heap.cc
Expand Up @@ -90,7 +90,7 @@ void* MarkSweepHeap::Allocate(size_t num_bytes) {
bytes_allocated_ += num_bytes;

// Allocate() is special: we use RootInCurrentFrame because it's a LEAF, and
// this function doesn't have RootsFrame to do PushScope/PopScope
// this function doesn't have RootsFrame to do PushFrame/PopFrame
#if RET_VAL_ROOTING
gHeap.RootInCurrentFrame(static_cast<Obj*>(result));
static_cast<Obj*>(result)->heap_tag_ = Tag::Opaque; // it is opaque to start!
Expand Down Expand Up @@ -225,15 +225,15 @@ void MarkSweepHeap::DoProcessExit(bool fast_exit) {
if (fast_exit) {
// don't collect by default; OIL_GC_ON_EXIT=1 overrides
if (e && strcmp(e, "1") == 0) {
root_set_.PopScope();
root_set_.PopFrame();
Collect();
}
} else {
// collect by default; OIL_GC_ON_EXIT=0 overrides
if (e && strcmp(e, "0") == 0) {
;
} else {
root_set_.PopScope();
root_set_.PopFrame();
Collect();
}
}
Expand Down
8 changes: 4 additions & 4 deletions mycpp/marksweep_heap.h
Expand Up @@ -21,7 +21,7 @@ class RootSet {
}

// Called on function entry
void PushScope() {
void PushFrame() {
// Construct more std::vector frames if necessary. We reuse vectors to
// avoid constructing one on every function call.
int num_constructed = stack_.size();
Expand All @@ -36,16 +36,16 @@ class RootSet {
}

num_frames_++;
// log("PushScope -> %d", num_frames_);
// log("PushFrame -> %d", num_frames_);
}

// Called on function exit
void PopScope() {
void PopFrame() {
// Remove all roots owned by the top frame. We're REUSING frames, so not
// calling vector<>::pop().
stack_[num_frames_ - 1].clear();
num_frames_--;
// log("PopScope -> %d", num_frames_);
// log("PopFrame -> %d", num_frames_);
}

// Called when returning a value (except in trivial passthrough case)
Expand Down
24 changes: 12 additions & 12 deletions mycpp/marksweep_heap_test.cc
Expand Up @@ -240,11 +240,11 @@ TEST root_set_test() {
ASSERT_EQ_FMT(0, r.NumRoots(), "%d");
ASSERT_EQ_FMT(1, r.NumFrames(), "%d");

r.PushScope(); // main() call
r.PushFrame(); // main() call
ASSERT_EQ_FMT(0, r.NumRoots(), "%d");
ASSERT_EQ_FMT(2, r.NumFrames(), "%d");

r.PushScope(); // g() call
r.PushFrame(); // g() call
ASSERT_EQ_FMT(0, r.NumRoots(), "%d");
ASSERT_EQ_FMT(3, r.NumFrames(), "%d");

Expand All @@ -255,13 +255,13 @@ TEST root_set_test() {
ASSERT_EQ_FMT(1, static_cast<int>(r.stack_[1].size()), "%d");
ASSERT_EQ_FMT(0, static_cast<int>(r.stack_[2].size()), "%d");

r.PopScope(); // g() return
r.PopFrame(); // g() return
// "X" is still live after foo() returns!
ASSERT_EQ_FMT(1, r.NumRoots(), "%d");
ASSERT_EQ_FMT(2, r.NumFrames(), "%d");
ASSERT_EQ_FMT(1, static_cast<int>(r.stack_[1].size()), "%d");

r.PushScope(); // another g() call
r.PushFrame(); // another g() call
ASSERT_EQ_FMT(1, r.NumRoots(), "%d");
ASSERT_EQ_FMT(3, r.NumFrames(), "%d");

Expand All @@ -272,12 +272,12 @@ TEST root_set_test() {
ASSERT_EQ_FMT(2, static_cast<int>(r.stack_[1].size()), "%d");
ASSERT_EQ_FMT(0, static_cast<int>(r.stack_[2].size()), "%d");

r.PopScope(); // another g() return
r.PopFrame(); // another g() return
ASSERT_EQ_FMT(2, r.NumRoots(), "%d");
ASSERT_EQ_FMT(2, r.NumFrames(), "%d");
ASSERT_EQ_FMT(2, static_cast<int>(r.stack_[1].size()), "%d");

r.PopScope(); // main() return
r.PopFrame(); // main() return
ASSERT_EQ_FMT(1, r.NumFrames(), "%d");
ASSERT_EQ_FMT(0, r.NumRoots(), "%d");

Expand All @@ -287,8 +287,8 @@ TEST root_set_test() {
TEST root_set_null_test() {
RootSet r(32);

r.PushScope();
r.PushScope();
r.PushFrame();
r.PushFrame();

r.RootOnReturn(StrFromC("X"));
ASSERT_EQ_FMT(1, r.NumRoots(), "%d");
Expand All @@ -297,8 +297,8 @@ TEST root_set_null_test() {
r.RootOnReturn(nullptr);
ASSERT_EQ_FMT(1, r.NumRoots(), "%d");

r.PopScope();
r.PopScope();
r.PopFrame();
r.PopFrame();

PASS();
}
Expand All @@ -308,10 +308,10 @@ TEST root_set_big_test() {

RootSet r(32);
// Test many frames
r.PushScope();
r.PushFrame();
for (int i = 0; i < 100; ++i) {
// log("i %d", i);
r.PushScope();
r.PushFrame();
for (int j = 0; j < 100; ++j) {
r.RootOnReturn(s);
}
Expand Down

0 comments on commit 1db3239

Please sign in to comment.