holy cleanup
This commit is contained in:
parent
4d427ea00e
commit
51ffd88727
5 changed files with 26 additions and 306 deletions
|
|
@ -69,7 +69,6 @@ static_lib:
|
||||||
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -c -o lib/event.o lib/event.cpp -fPIC
|
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -c -o lib/event.o lib/event.cpp -fPIC
|
||||||
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -c -o lib/profiler.o lib/profiler.cpp -fPIC
|
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -c -o lib/profiler.o lib/profiler.cpp -fPIC
|
||||||
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -c -o lib/heap.o lib/heap.cpp -fPIC
|
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -c -o lib/heap.o lib/heap.cpp -fPIC
|
||||||
<<<<<<< HEAD
|
|
||||||
# create static library
|
# create static library
|
||||||
ar r lib/gcoll.a lib/event.o lib/profiler.o lib/heap.o
|
ar r lib/gcoll.a lib/event.o lib/profiler.o lib/heap.o
|
||||||
|
|
||||||
|
|
@ -77,61 +76,18 @@ static_lib:
|
||||||
static_lib_test: static_lib
|
static_lib_test: static_lib
|
||||||
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -o tests/extern_lib.out tests/extern_lib.cpp lib/gcoll.a
|
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -o tests/extern_lib.out tests/extern_lib.cpp lib/gcoll.a
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
<<<<<<< HEAD
|
|
||||||
<<<<<<< HEAD
|
|
||||||
static_lib_c:
|
|
||||||
# remove old files
|
|
||||||
rm -f lib/event.o lib/profiler.o lib/heap.o lib/gcoll.a tests/extern_lib.out
|
|
||||||
# compile object files
|
|
||||||
=======
|
|
||||||
wrapper:
|
|
||||||
rm -f lib/event.o lib/profiler.o lib/heap.o lib/coll.a tests/wrapper.out
|
|
||||||
>>>>>>> 12816ea (Wrapper works)
|
|
||||||
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -O3 -g -c -o lib/event.o lib/event.cpp -fPIC
|
|
||||||
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -O3 -g -c -o lib/profiler.o lib/profiler.cpp -fPIC
|
|
||||||
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -O3 -g -c -o lib/heap.o lib/heap.cpp -fPIC
|
|
||||||
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -O3 -g -c -o lib/cheap.o lib/cheap.cpp -fPIC
|
|
||||||
<<<<<<< HEAD
|
|
||||||
=======
|
|
||||||
>>>>>>> 7e93aab6268ac896dea03dcd045b8bc249f2576c
|
|
||||||
# create static library
|
|
||||||
ar r lib/gcoll.a lib/event.o lib/profiler.o lib/heap.o
|
|
||||||
=======
|
|
||||||
=======
|
|
||||||
=======
|
|
||||||
alloc_free_list: static_lib
|
|
||||||
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -o tests/alloc_fl.out tests/alloc_free_list.cpp lib/gcoll.a
|
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
linked_list_test: static_lib
|
|
||||||
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -o tests/linkedlist.out tests/linkedlist.cpp lib/gcoll.a
|
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
>>>>>>> d7ea27e (testing testing...)
|
|
||||||
=======
|
|
||||||
=======
|
|
||||||
# create test program
|
|
||||||
static_lib_test: static_lib
|
|
||||||
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -o tests/extern_lib.out tests/extern_lib.cpp lib/gcoll.a
|
|
||||||
|
|
||||||
alloc_free_list: static_lib
|
alloc_free_list: static_lib
|
||||||
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -o tests/alloc_fl.out tests/alloc_free_list.cpp lib/gcoll.a
|
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -o tests/alloc_fl.out tests/alloc_free_list.cpp lib/gcoll.a
|
||||||
|
|
||||||
linked_list_test: static_lib
|
linked_list_test: static_lib
|
||||||
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -o tests/linkedlist.out tests/linkedlist.cpp lib/gcoll.a
|
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -o tests/linkedlist.out tests/linkedlist.cpp lib/gcoll.a
|
||||||
|
|
||||||
>>>>>>> 7e93aab6268ac896dea03dcd045b8bc249f2576c
|
|
||||||
revrange: static_lib
|
revrange: static_lib
|
||||||
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -o tests/revrange.out tests/revrange.cpp lib/gcoll.a
|
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -o tests/revrange.out tests/revrange.cpp lib/gcoll.a
|
||||||
|
|
||||||
pointers: static_lib
|
pointers: static_lib
|
||||||
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -o tests/pointers.out tests/pointers.cpp lib/gcoll.a
|
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -o tests/pointers.out tests/pointers.cpp lib/gcoll.a
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
>>>>>>> a910d54 (rip gc)
|
|
||||||
=======
|
|
||||||
>>>>>>> 7e93aab6268ac896dea03dcd045b8bc249f2576c
|
|
||||||
wrapper:
|
wrapper:
|
||||||
# remove old files
|
# remove old files
|
||||||
rm -f lib/event.o lib/profiler.o lib/heap.o lib/coll.a tests/wrapper.out
|
rm -f lib/event.o lib/profiler.o lib/heap.o lib/coll.a tests/wrapper.out
|
||||||
|
|
@ -141,14 +97,6 @@ wrapper:
|
||||||
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -O3 -c -o lib/heap.o lib/heap.cpp -fPIC
|
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -O3 -c -o lib/heap.o lib/heap.cpp -fPIC
|
||||||
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -O3 -c -o lib/cheap.o lib/cheap.cpp -fPIC
|
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -O3 -c -o lib/cheap.o lib/cheap.cpp -fPIC
|
||||||
# compile object files into library
|
# compile object files into library
|
||||||
<<<<<<< HEAD
|
|
||||||
>>>>>>> 01c93a6 (Wrapper docs)
|
|
||||||
ar rcs lib/gcoll.a lib/event.o lib/profiler.o lib/heap.o lib/cheap.o
|
ar rcs lib/gcoll.a lib/event.o lib/profiler.o lib/heap.o lib/cheap.o
|
||||||
# compile test program wrapper.c with normal clang
|
# compile test program wrapper.c with normal clang
|
||||||
clang -stdlib=libc++ $(WFLAGS) $(LIB_INCL) -o tests/wrapper.out tests/wrapper.c lib/gcoll.a -lstdc++
|
clang -stdlib=libc++ $(WFLAGS) $(LIB_INCL) -o tests/wrapper.out tests/wrapper.c lib/gcoll.a -lstdc++
|
||||||
>>>>>>> 12816ea (Wrapper works)
|
|
||||||
=======
|
|
||||||
ar rcs lib/gcoll.a lib/event.o lib/profiler.o lib/heap.o lib/cheap.o
|
|
||||||
# compile test program wrapper.c with normal clang
|
|
||||||
clang -stdlib=libc++ $(WFLAGS) $(LIB_INCL) -o tests/wrapper.out tests/wrapper.c lib/gcoll.a -lstdc++
|
|
||||||
>>>>>>> 7e93aab6268ac896dea03dcd045b8bc249f2576c
|
|
||||||
|
|
@ -7,16 +7,8 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
<<<<<<< HEAD
|
|
||||||
#define WRAPPER_DEBUG
|
|
||||||
=======
|
|
||||||
#define DEBUG
|
|
||||||
>>>>>>> 74e0282 (Added Hash map marking)
|
|
||||||
=======
|
|
||||||
#define DEBUG
|
#define DEBUG
|
||||||
#define WRAPPER_DEBUG
|
#define WRAPPER_DEBUG
|
||||||
>>>>>>> 7e93aab6268ac896dea03dcd045b8bc249f2576c
|
|
||||||
|
|
||||||
#ifdef WRAPPER_DEBUG
|
#ifdef WRAPPER_DEBUG
|
||||||
typedef struct cheap
|
typedef struct cheap
|
||||||
|
|
|
||||||
25
src/GC/include/chunk.hpp
Normal file
25
src/GC/include/chunk.hpp
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
namespace GC
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The basic element of what can be stored on
|
||||||
|
* the heap. A chunk contains a start address
|
||||||
|
* on the actual heap, the size of memory that
|
||||||
|
* is allocated at that address and if the
|
||||||
|
* chunk is reachable (marked).
|
||||||
|
*/
|
||||||
|
struct Chunk
|
||||||
|
{
|
||||||
|
bool m_marked {false};
|
||||||
|
uintptr_t *const m_start {nullptr};
|
||||||
|
const size_t m_size {0};
|
||||||
|
|
||||||
|
Chunk(size_t size, uintptr_t *start) : m_start(start), m_size(size) {}
|
||||||
|
Chunk(const Chunk *const c) : m_marked(c->m_marked), m_start(c->m_start), m_size(c->m_size) {}
|
||||||
|
Chunk(const Chunk &c) : m_marked(c.m_marked), m_start(c.m_start), m_size(c.m_size) {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -9,31 +9,9 @@
|
||||||
#include "chunk.hpp"
|
#include "chunk.hpp"
|
||||||
#include "profiler.hpp"
|
#include "profiler.hpp"
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
<<<<<<< HEAD
|
|
||||||
<<<<<<< HEAD
|
|
||||||
<<<<<<< HEAD
|
|
||||||
#define HEAP_SIZE 320//65536
|
|
||||||
#define FREE_THRESH (uint) 0
|
|
||||||
=======
|
|
||||||
#define HEAP_SIZE 16000//65536
|
|
||||||
#define FREE_THRESH (uint) 100
|
|
||||||
>>>>>>> c09da8a (now it works ok???)
|
|
||||||
=======
|
|
||||||
#define HEAP_SIZE 160000//65536
|
|
||||||
#define FREE_THRESH (uint) 5
|
|
||||||
>>>>>>> 5056624 (short profiler logs)
|
|
||||||
// #define HEAP_DEBUG
|
|
||||||
=======
|
|
||||||
#define HEAP_SIZE 2097152 //256 //65536 //2097152
|
|
||||||
#define FREE_THRESH (uint) 100000 //1000
|
|
||||||
#define DEBUG
|
|
||||||
>>>>>>> 74e0282 (Added Hash map marking)
|
|
||||||
=======
|
|
||||||
#define HEAP_SIZE 160000//65536
|
#define HEAP_SIZE 160000//65536
|
||||||
#define FREE_THRESH (uint) 5
|
#define FREE_THRESH (uint) 5
|
||||||
// #define HEAP_DEBUG
|
// #define HEAP_DEBUG
|
||||||
>>>>>>> 7e93aab6268ac896dea03dcd045b8bc249f2576c
|
|
||||||
|
|
||||||
namespace GC
|
namespace GC
|
||||||
{
|
{
|
||||||
|
|
@ -76,27 +54,14 @@ namespace GC
|
||||||
|
|
||||||
char *const m_heap;
|
char *const m_heap;
|
||||||
size_t m_size {0};
|
size_t m_size {0};
|
||||||
<<<<<<< HEAD
|
|
||||||
char *m_heap_top {nullptr};
|
|
||||||
=======
|
|
||||||
size_t m_total_size {0};
|
|
||||||
>>>>>>> 74e0282 (Added Hash map marking)
|
|
||||||
// static Heap *m_instance {nullptr};
|
// static Heap *m_instance {nullptr};
|
||||||
uintptr_t *m_stack_top {nullptr};
|
uintptr_t *m_stack_top {nullptr};
|
||||||
bool m_profiler_enable {false};
|
bool m_profiler_enable {false};
|
||||||
|
|
||||||
std::vector<Chunk *> m_allocated_chunks;
|
std::vector<Chunk *> m_allocated_chunks;
|
||||||
std::vector<Chunk *> m_freed_chunks;
|
std::vector<Chunk *> m_freed_chunks;
|
||||||
<<<<<<< HEAD
|
|
||||||
<<<<<<< HEAD
|
|
||||||
std::list<Chunk *> m_free_list;
|
|
||||||
=======
|
|
||||||
std::unordered_map<uintptr_t, Chunk*> m_chunk_table;
|
|
||||||
>>>>>>> 74e0282 (Added Hash map marking)
|
|
||||||
=======
|
|
||||||
std::list<Chunk *> m_free_list;
|
std::list<Chunk *> m_free_list;
|
||||||
std::unordered_map<uintptr_t, Chunk*> m_chunk_table;
|
std::unordered_map<uintptr_t, Chunk*> m_chunk_table;
|
||||||
>>>>>>> 7e93aab6268ac896dea03dcd045b8bc249f2576c
|
|
||||||
|
|
||||||
static bool profiler_enabled();
|
static bool profiler_enabled();
|
||||||
// static Chunk *get_at(std::vector<Chunk *> &list, size_t n);
|
// static Chunk *get_at(std::vector<Chunk *> &list, size_t n);
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,7 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
<<<<<<< HEAD
|
|
||||||
<<<<<<< HEAD
|
|
||||||
=======
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
>>>>>>> 7e93aab6268ac896dea03dcd045b8bc249f2576c
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
@ -16,18 +12,7 @@
|
||||||
#define time_now std::chrono::high_resolution_clock::now()
|
#define time_now std::chrono::high_resolution_clock::now()
|
||||||
#define to_us std::chrono::duration_cast<std::chrono::microseconds>
|
#define to_us std::chrono::duration_cast<std::chrono::microseconds>
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
using std::cout, std::endl, std::vector, std::hex, std::dec;
|
|
||||||
=======
|
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
#include "heap.hpp"
|
|
||||||
|
|
||||||
using std::cout, std::endl, std::vector, std::hex, std::dec, std::unordered_map;
|
using std::cout, std::endl, std::vector, std::hex, std::dec, std::unordered_map;
|
||||||
>>>>>>> 74e0282 (Added Hash map marking)
|
|
||||||
=======
|
|
||||||
using std::cout, std::endl, std::vector, std::hex, std::dec, std::unordered_map;
|
|
||||||
>>>>>>> 7e93aab6268ac896dea03dcd045b8bc249f2576c
|
|
||||||
|
|
||||||
namespace GC
|
namespace GC
|
||||||
{
|
{
|
||||||
|
|
@ -111,38 +96,17 @@ namespace GC
|
||||||
auto stack_bottom = reinterpret_cast<uintptr_t *>(__builtin_frame_address(0));
|
auto stack_bottom = reinterpret_cast<uintptr_t *>(__builtin_frame_address(0));
|
||||||
heap.collect(stack_bottom);
|
heap.collect(stack_bottom);
|
||||||
// If memory is not enough after collect, crash with OOM error
|
// If memory is not enough after collect, crash with OOM error
|
||||||
<<<<<<< HEAD
|
|
||||||
<<<<<<< HEAD
|
|
||||||
<<<<<<< HEAD
|
|
||||||
if (heap.m_size + size > HEAP_SIZE)
|
|
||||||
{
|
|
||||||
if (profiler_enabled)
|
|
||||||
Profiler::dispose();
|
|
||||||
throw std::runtime_error(std::string("Error: Heap out of memory"));
|
|
||||||
}
|
|
||||||
=======
|
|
||||||
=======
|
|
||||||
>>>>>>> 208ff86 (Fixed bug in size handling and mark hash)
|
|
||||||
=======
|
|
||||||
>>>>>>> 7e93aab6268ac896dea03dcd045b8bc249f2576c
|
|
||||||
if (heap.m_size > HEAP_SIZE)
|
if (heap.m_size > HEAP_SIZE)
|
||||||
{
|
{
|
||||||
throw std::runtime_error(std::string("Error: Heap out of memory"));
|
throw std::runtime_error(std::string("Error: Heap out of memory"));
|
||||||
}
|
}
|
||||||
//throw std::runtime_error(std::string("Error: Heap out of memory"));
|
//throw std::runtime_error(std::string("Error: Heap out of memory"));
|
||||||
<<<<<<< HEAD
|
|
||||||
<<<<<<< HEAD
|
|
||||||
>>>>>>> 74e0282 (Added Hash map marking)
|
|
||||||
=======
|
|
||||||
=======
|
|
||||||
>>>>>>> 7e93aab6268ac896dea03dcd045b8bc249f2576c
|
|
||||||
}
|
}
|
||||||
if (heap.m_size + size > HEAP_SIZE)
|
if (heap.m_size + size > HEAP_SIZE)
|
||||||
{
|
{
|
||||||
if (profiler_enabled)
|
if (profiler_enabled)
|
||||||
Profiler::dispose();
|
Profiler::dispose();
|
||||||
throw std::runtime_error(std::string("Error: Heap out of memory"));
|
throw std::runtime_error(std::string("Error: Heap out of memory"));
|
||||||
>>>>>>> 208ff86 (Fixed bug in size handling and mark hash)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a chunk was recycled, return the old chunk address
|
// If a chunk was recycled, return the old chunk address
|
||||||
|
|
@ -270,15 +234,6 @@ namespace GC
|
||||||
// create_table();
|
// create_table();
|
||||||
// mark_hash(stack_bottom, stack_top);
|
// mark_hash(stack_bottom, stack_top);
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
vector<uintptr_t *> roots;
|
|
||||||
// cout << "\nb4 find_roots\n";
|
|
||||||
find_roots(stack_bottom, roots);
|
|
||||||
|
|
||||||
// cout << "b4 mark\n";''
|
|
||||||
mark(roots);
|
|
||||||
|
|
||||||
=======
|
|
||||||
create_table();
|
create_table();
|
||||||
vector<uintptr_t *> roots;
|
vector<uintptr_t *> roots;
|
||||||
// cout << "\nb4 find_roots\n";
|
// cout << "\nb4 find_roots\n";
|
||||||
|
|
@ -287,7 +242,6 @@ namespace GC
|
||||||
// cout << "b4 mark\n";''
|
// cout << "b4 mark\n";''
|
||||||
mark(roots);
|
mark(roots);
|
||||||
|
|
||||||
>>>>>>> 7e93aab6268ac896dea03dcd045b8bc249f2576c
|
|
||||||
// cout << "b4 sweep\n";
|
// cout << "b4 sweep\n";
|
||||||
sweep(heap);
|
sweep(heap);
|
||||||
|
|
||||||
|
|
@ -345,35 +299,6 @@ namespace GC
|
||||||
}
|
}
|
||||||
|
|
||||||
void Heap::find_chunks(uintptr_t *stack_addr, std::queue<std::pair<uintptr_t, uintptr_t>> &chunk_spaces)
|
void Heap::find_chunks(uintptr_t *stack_addr, std::queue<std::pair<uintptr_t, uintptr_t>> &chunk_spaces)
|
||||||
<<<<<<< HEAD
|
|
||||||
{
|
|
||||||
auto iter = m_allocated_chunks.begin();
|
|
||||||
auto end = m_allocated_chunks.end();
|
|
||||||
|
|
||||||
while (iter != end)
|
|
||||||
{
|
|
||||||
auto chunk = *iter++;
|
|
||||||
|
|
||||||
if (chunk->m_marked)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
auto c_start = reinterpret_cast<uintptr_t>(chunk->m_start);
|
|
||||||
auto c_size = reinterpret_cast<uintptr_t>(chunk->m_size);
|
|
||||||
auto c_end = reinterpret_cast<uintptr_t>(c_start + c_size);
|
|
||||||
|
|
||||||
if (c_start < *stack_addr && *stack_addr < c_end)
|
|
||||||
{
|
|
||||||
chunk->m_marked = true;
|
|
||||||
chunk_spaces.push(std::make_pair(c_start, c_end));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
<<<<<<< HEAD
|
|
||||||
void Heap::mark_range(vector<AddrRange *> &ranges, vector<Chunk *> &worklist)
|
|
||||||
=======
|
|
||||||
>>>>>>> 7e93aab6268ac896dea03dcd045b8bc249f2576c
|
|
||||||
{
|
{
|
||||||
Heap &heap = Heap::the();
|
Heap &heap = Heap::the();
|
||||||
|
|
||||||
|
|
@ -427,139 +352,6 @@ namespace GC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Heap::mark_hash(uintptr_t *start, const uintptr_t* const end)
|
|
||||||
{
|
|
||||||
Heap &heap = Heap::the();
|
|
||||||
|
|
||||||
bool profiler_enabled = heap.m_profiler_enable;
|
|
||||||
if (profiler_enabled)
|
|
||||||
Profiler::record(MarkStart);
|
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
auto iter = ranges.begin();
|
|
||||||
auto stop = ranges.end();
|
|
||||||
|
|
||||||
while (iter != stop)
|
|
||||||
{
|
|
||||||
auto range = *iter++;
|
|
||||||
uintptr_t *start = (uintptr_t *)range->start;
|
|
||||||
const uintptr_t *end = range->end;
|
|
||||||
if (start == nullptr)
|
|
||||||
cout << "\nstart is null\n";
|
|
||||||
for (; start <= end; start++)
|
|
||||||
{
|
|
||||||
auto wliter = worklist.begin();
|
|
||||||
auto wlstop = worklist.end();
|
|
||||||
while (wliter != wlstop)
|
|
||||||
{
|
|
||||||
Chunk *chunk = *wliter;
|
|
||||||
auto c_start = reinterpret_cast<uintptr_t>(chunk->m_start);
|
|
||||||
auto c_size = reinterpret_cast<uintptr_t>(chunk->m_size);
|
|
||||||
auto c_end = reinterpret_cast<uintptr_t>(c_start + c_size);
|
|
||||||
|
|
||||||
if (c_start <= *start && *start < c_end)
|
|
||||||
{
|
|
||||||
if (!chunk->m_marked)
|
|
||||||
{
|
|
||||||
chunk->m_marked = true;
|
|
||||||
wliter = worklist.erase(wliter);
|
|
||||||
ranges.push_back(new AddrRange((uintptr_t *)c_start, (uintptr_t *)c_end));
|
|
||||||
stop = ranges.end();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wliter++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wliter++;
|
|
||||||
}
|
|
||||||
=======
|
|
||||||
void Heap::create_table()
|
|
||||||
{
|
|
||||||
Heap &heap = Heap::the();
|
|
||||||
unordered_map<uintptr_t, Chunk*> chunk_table;
|
|
||||||
for (auto chunk : heap.m_allocated_chunks) {
|
|
||||||
auto pair = std::make_pair(reinterpret_cast<uintptr_t>(chunk->m_start), chunk);
|
|
||||||
heap.m_chunk_table.insert(pair);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Heap::mark_hash(uintptr_t *start, const uintptr_t* const end)
|
|
||||||
{
|
|
||||||
Heap &heap = Heap::the();
|
|
||||||
for (; start <= end; start++)
|
|
||||||
{
|
|
||||||
auto search = heap.m_chunk_table.find(*start);
|
|
||||||
if (search != heap.m_chunk_table.end())
|
|
||||||
{
|
|
||||||
Chunk *chunk = search->second;
|
|
||||||
auto c_start = reinterpret_cast<uintptr_t>(chunk->m_start);
|
|
||||||
auto c_size = reinterpret_cast<uintptr_t>(chunk->m_size);
|
|
||||||
auto c_end = reinterpret_cast<uintptr_t*>(c_start + c_size);
|
|
||||||
if (!chunk->m_marked)
|
|
||||||
{
|
|
||||||
chunk->m_marked = true;
|
|
||||||
mark_hash(chunk->m_start, c_end);
|
|
||||||
>>>>>>> 74e0282 (Added Hash map marking)
|
|
||||||
=======
|
|
||||||
for (; start <= end; start++)
|
|
||||||
{
|
|
||||||
auto search = heap.m_chunk_table.find(*start);
|
|
||||||
if (search != heap.m_chunk_table.end())
|
|
||||||
{
|
|
||||||
Chunk *chunk = search->second;
|
|
||||||
auto c_start = reinterpret_cast<uintptr_t>(chunk->m_start);
|
|
||||||
auto c_size = reinterpret_cast<uintptr_t>(chunk->m_size);
|
|
||||||
auto c_end = reinterpret_cast<uintptr_t*>(c_start + c_size);
|
|
||||||
if (!chunk->m_marked)
|
|
||||||
{
|
|
||||||
chunk->m_marked = true;
|
|
||||||
|
|
||||||
if (profiler_enabled)
|
|
||||||
Profiler::record(ChunkMarked, chunk);
|
|
||||||
|
|
||||||
//mark_hash(chunk->m_start, c_end);
|
|
||||||
Chunk *next = find_pointer_hash((uintptr_t *) c_start, (uintptr_t *) c_end);
|
|
||||||
while (next != NULL)
|
|
||||||
{
|
|
||||||
if (!next->m_marked)
|
|
||||||
{
|
|
||||||
next->m_marked = true;
|
|
||||||
|
|
||||||
if (profiler_enabled)
|
|
||||||
Profiler::record(ChunkMarked, chunk);
|
|
||||||
|
|
||||||
auto c_start = reinterpret_cast<uintptr_t>(next->m_start);
|
|
||||||
auto c_size = reinterpret_cast<uintptr_t>(next->m_size);
|
|
||||||
auto c_end = reinterpret_cast<uintptr_t>(c_start + c_size);
|
|
||||||
next = find_pointer_hash((uintptr_t *) c_start, (uintptr_t *) c_end);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
>>>>>>> 7e93aab6268ac896dea03dcd045b8bc249f2576c
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
<<<<<<< HEAD
|
|
||||||
=======
|
|
||||||
|
|
||||||
>>>>>>> 74e0282 (Added Hash map marking)
|
|
||||||
|
|
||||||
=======
|
|
||||||
>>>>>>> 830d863 (bugfix)
|
|
||||||
void Heap::create_table()
|
|
||||||
{
|
|
||||||
Heap &heap = Heap::the();
|
|
||||||
unordered_map<uintptr_t, Chunk*> chunk_table;
|
|
||||||
for (auto chunk : heap.m_allocated_chunks) {
|
|
||||||
auto pair = std::make_pair(reinterpret_cast<uintptr_t>(chunk->m_start), chunk);
|
|
||||||
heap.m_chunk_table.insert(pair);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
void Heap::mark_hash(uintptr_t *start, const uintptr_t* const end)
|
void Heap::mark_hash(uintptr_t *start, const uintptr_t* const end)
|
||||||
{
|
{
|
||||||
Heap &heap = Heap::the();
|
Heap &heap = Heap::the();
|
||||||
|
|
@ -606,8 +398,6 @@ namespace GC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
=======
|
|
||||||
>>>>>>> 7e93aab6268ac896dea03dcd045b8bc249f2576c
|
|
||||||
/**
|
/**
|
||||||
* Sweeps the heap, unmarks the marked chunks for the next cycle,
|
* Sweeps the heap, unmarks the marked chunks for the next cycle,
|
||||||
* adds the unmarked nodes to the list of freed chunks; to be freed.
|
* adds the unmarked nodes to the list of freed chunks; to be freed.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue