Some improvments to Game test
This commit is contained in:
parent
6840297c08
commit
ce714db3f1
4 changed files with 66 additions and 37 deletions
|
|
@ -78,7 +78,7 @@ namespace GC
|
||||||
void mark(uintptr_t *start, const uintptr_t *end, std::vector<Chunk *> &worklist);
|
void mark(uintptr_t *start, const uintptr_t *end, std::vector<Chunk *> &worklist);
|
||||||
void print_line(Chunk *chunk);
|
void print_line(Chunk *chunk);
|
||||||
void print_worklist(std::vector<Chunk *> &list);
|
void print_worklist(std::vector<Chunk *> &list);
|
||||||
void mark_step(uintptr_t memory_location, std::vector<Chunk *> &worklist);
|
void mark_step(uintptr_t start, uintptr_t end, std::vector<Chunk *> &worklist);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,8 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "../include/heap.hpp"
|
//#include "../include/heap.hpp"
|
||||||
|
#include <heap.hpp>
|
||||||
|
|
||||||
using std::cout, std::endl, std::vector, std::hex, std::dec;
|
using std::cout, std::endl, std::vector, std::hex, std::dec;
|
||||||
|
|
||||||
|
|
@ -175,11 +176,11 @@ namespace GC
|
||||||
*/
|
*/
|
||||||
void Heap::mark(uintptr_t *start, const uintptr_t *end, vector<Chunk *> &worklist)
|
void Heap::mark(uintptr_t *start, const uintptr_t *end, vector<Chunk *> &worklist)
|
||||||
{
|
{
|
||||||
cout << "--- Marked was called ---" << endl;
|
cout << "--- mark() was called ---\n" << endl;
|
||||||
if (getProfilerMode())
|
if (getProfilerMode())
|
||||||
Profiler::record(MarkStart);
|
Profiler::record(MarkStart);
|
||||||
// To find adresses thats in the worklist
|
// To find adresses thats in the worklist
|
||||||
for (; start < end; start++)
|
for (; start <= end; start++)
|
||||||
{
|
{
|
||||||
auto it = worklist.begin();
|
auto it = worklist.begin();
|
||||||
auto stop = worklist.end();
|
auto stop = worklist.end();
|
||||||
|
|
@ -192,6 +193,7 @@ namespace GC
|
||||||
auto c_size = reinterpret_cast<uintptr_t>(chunk->size);
|
auto c_size = reinterpret_cast<uintptr_t>(chunk->size);
|
||||||
auto c_end = reinterpret_cast<uintptr_t>(c_start + c_size);
|
auto c_end = reinterpret_cast<uintptr_t>(c_start + c_size);
|
||||||
|
|
||||||
|
cout << "Value of Start:\t\t" << start << endl;
|
||||||
cout << "Start points to:\t" << hex << *start << endl;
|
cout << "Start points to:\t" << hex << *start << endl;
|
||||||
cout << "Chunk start:\t\t" << hex << c_start << endl;
|
cout << "Chunk start:\t\t" << hex << c_start << endl;
|
||||||
cout << "Chunk end:\t\t" << hex << c_end << "\n" << endl;
|
cout << "Chunk end:\t\t" << hex << c_end << "\n" << endl;
|
||||||
|
|
@ -209,12 +211,8 @@ namespace GC
|
||||||
// Remove the marked chunk from the worklist
|
// Remove the marked chunk from the worklist
|
||||||
it = worklist.erase(it);
|
it = worklist.erase(it);
|
||||||
// Recursively call mark, to see if the reachable chunk further points to another chunk
|
// Recursively call mark, to see if the reachable chunk further points to another chunk
|
||||||
// Previously ->
|
mark((uintptr_t *)c_start, (uintptr_t *)c_end, worklist);
|
||||||
// mark((uintptr_t *)c_start, (uintptr_t *)c_end, worklist);
|
//mark_step(c_start, c_end, worklist);
|
||||||
// Testing this, it should move to the next adress and end shouldn't be of concern
|
|
||||||
// since it is a static size of pointers
|
|
||||||
// New -> mark((uintptr_t *) c_end, (uintptr_t *) (c_end + sizeof(uintptr_t)), worklist);
|
|
||||||
mark_step(c_end, worklist);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -232,7 +230,14 @@ namespace GC
|
||||||
// Testing a strategy where if a pointer on the stack is pointing to a chunk, nested chunks,
|
// Testing a strategy where if a pointer on the stack is pointing to a chunk, nested chunks,
|
||||||
// that are not located on the stack frame, will possibly be adjecent to the found chunk,
|
// that are not located on the stack frame, will possibly be adjecent to the found chunk,
|
||||||
// allowing for a different, more efficient strategy, that doesn't have to scan the stack frame
|
// allowing for a different, more efficient strategy, that doesn't have to scan the stack frame
|
||||||
void Heap::mark_step(uintptr_t memory_location, vector<Chunk *> &worklist) {
|
void Heap::mark_step(uintptr_t start, uintptr_t end, vector<Chunk *> &worklist) {
|
||||||
|
|
||||||
|
// Should loop through the chunk size, such that if the object holds a pointer,
|
||||||
|
// wherever that pointer is located in the object, that pointer, to another chunk,
|
||||||
|
// gets detected
|
||||||
|
|
||||||
|
cout << "--- mark_step() was called ---\n" << endl;
|
||||||
|
for (; start <= end; start += sizeof(uintptr_t)) {
|
||||||
|
|
||||||
auto it = worklist.begin();
|
auto it = worklist.begin();
|
||||||
auto end = worklist.end();
|
auto end = worklist.end();
|
||||||
|
|
@ -244,14 +249,20 @@ namespace GC
|
||||||
auto c_size = reinterpret_cast<uintptr_t>(chunk->size);
|
auto c_size = reinterpret_cast<uintptr_t>(chunk->size);
|
||||||
auto c_end = reinterpret_cast<uintptr_t>(c_start + c_size);
|
auto c_end = reinterpret_cast<uintptr_t>(c_start + c_size);
|
||||||
|
|
||||||
if (c_start <= memory_location && memory_location < c_end) {
|
cout << "Value of Start:\t\t" << start << endl;
|
||||||
|
cout << "Chunk start:\t\t" << hex << c_start << endl;
|
||||||
|
cout << "Chunk end:\t\t" << hex << c_end << "\n" << endl;
|
||||||
|
|
||||||
|
if (c_start <= start && start < c_end) {
|
||||||
|
|
||||||
if (!chunk->marked) {
|
if (!chunk->marked) {
|
||||||
// Mark the chunk and erase it from the worklist
|
// Mark the chunk and erase it from the worklist
|
||||||
chunk->marked = true;
|
chunk->marked = true;
|
||||||
it = worklist.erase(it);
|
it = worklist.erase(it);
|
||||||
|
cout << "Marked this chunk ^\n" << endl;
|
||||||
// Update the memory location we want to look at
|
// Update the memory location we want to look at
|
||||||
memory_location = c_end;
|
//memory_location = c_end;
|
||||||
|
mark_step(c_start, c_end, worklist);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
it++;
|
it++;
|
||||||
|
|
@ -262,6 +273,7 @@ namespace GC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sweeps the heap, unmarks the marked chunks for the next cycle,
|
* Sweeps the heap, unmarks the marked chunks for the next cycle,
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,9 @@
|
||||||
#include "player.hpp"
|
#include "player.hpp"
|
||||||
#include "heap.hpp"
|
#include "heap.hpp"
|
||||||
|
|
||||||
#define X_LENGTH 1000;
|
#define X_LENGTH 1000
|
||||||
#define Y_LENGTH 500;
|
#define Y_LENGTH 500
|
||||||
|
#define MAX_PLAYERS 100
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Description:
|
* Description:
|
||||||
|
|
@ -20,19 +21,32 @@
|
||||||
* all objects gets allocated, but only Game object gets marked.
|
* all objects gets allocated, but only Game object gets marked.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
class Game {
|
class Game {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::vector<Player> players;
|
//std::vector<Player*> *players;
|
||||||
Point dimensions;
|
std::vector<Player> *players;
|
||||||
|
Point *dimensions;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Game() : dimensions(1000, 500) {}
|
Game() {
|
||||||
|
dimensions->x = X_LENGTH;
|
||||||
|
dimensions->y = Y_LENGTH;
|
||||||
|
}
|
||||||
|
|
||||||
void add_player(Player& p) {
|
void init() {
|
||||||
players.push_back(p);
|
//players = static_cast<std::vector<Player*>*>(GC::Heap::alloc(sizeof(Player*) * MAX_PLAYERS));
|
||||||
|
players = static_cast<std::vector<Player>*>(GC::Heap::alloc(sizeof(Player) * MAX_PLAYERS));
|
||||||
|
dimensions = static_cast<Point*>(GC::Heap::alloc(sizeof(Point)));
|
||||||
|
dimensions->x = X_LENGTH;
|
||||||
|
dimensions->y = Y_LENGTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
void add_player(Player *p) {
|
||||||
|
players->push_back(*p);
|
||||||
}
|
}
|
||||||
|
|
||||||
Player* create_player(string s, Point pos, Point size, Point dir) {
|
Player* create_player(string s, Point pos, Point size, Point dir) {
|
||||||
|
|
@ -49,19 +63,19 @@ public:
|
||||||
void create_players(int nr) {
|
void create_players(int nr) {
|
||||||
for (int i = 0; i < nr; i++) {
|
for (int i = 0; i < nr; i++) {
|
||||||
Player *p = create_player(std::to_string(i), Point(i, i), Point(2, 2), Point(0, 0));
|
Player *p = create_player(std::to_string(i), Point(i, i), Point(2, 2), Point(0, 0));
|
||||||
add_player(*p);
|
add_player(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
GC::Heap::init();
|
GC::Heap::init();
|
||||||
GC::Heap *gc = GC::Heap::debug_the();
|
GC::Heap *gc = GC::Heap::debug_the();
|
||||||
gc->check_init();
|
gc->check_init();
|
||||||
|
|
||||||
Game *game = static_cast<Game*>(gc->alloc(sizeof(Game)));
|
Game *game = static_cast<Game*>(gc->alloc(sizeof(Game)));
|
||||||
|
game->init();
|
||||||
game->create_players(2);
|
game->create_players(2);
|
||||||
|
|
||||||
std::cout << "Player size: " << sizeof(Player) << std::endl;
|
std::cout << "Player size: " << sizeof(Player) << std::endl;
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ class Point {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
int x, y;
|
int x, y;
|
||||||
|
Point() {}
|
||||||
Point(int _x, int _y) : x(_x), y(_y) {}
|
Point(int _x, int _y) : x(_x), y(_y) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -21,6 +22,8 @@ private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
Player() {}
|
||||||
|
|
||||||
Player(string n, Point pos, Point s, Point dir)
|
Player(string n, Point pos, Point s, Point dir)
|
||||||
: name(n), position(pos.x, pos.y), size(s.x, s.y), direction(dir.x, dir.y)
|
: name(n), position(pos.x, pos.y), size(s.x, s.y), direction(dir.x, dir.y)
|
||||||
{}
|
{}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue