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 print_line(Chunk *chunk);
|
||||
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:
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@
|
|||
#include <stdlib.h>
|
||||
#include <vector>
|
||||
|
||||
#include "../include/heap.hpp"
|
||||
//#include "../include/heap.hpp"
|
||||
#include <heap.hpp>
|
||||
|
||||
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)
|
||||
{
|
||||
cout << "--- Marked was called ---" << endl;
|
||||
cout << "--- mark() was called ---\n" << endl;
|
||||
if (getProfilerMode())
|
||||
Profiler::record(MarkStart);
|
||||
// To find adresses thats in the worklist
|
||||
for (; start < end; start++)
|
||||
for (; start <= end; start++)
|
||||
{
|
||||
auto it = worklist.begin();
|
||||
auto stop = worklist.end();
|
||||
|
|
@ -192,6 +193,7 @@ namespace GC
|
|||
auto c_size = reinterpret_cast<uintptr_t>(chunk->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 << "Chunk start:\t\t" << hex << c_start << endl;
|
||||
cout << "Chunk end:\t\t" << hex << c_end << "\n" << endl;
|
||||
|
|
@ -209,12 +211,8 @@ namespace GC
|
|||
// Remove the marked chunk from the worklist
|
||||
it = worklist.erase(it);
|
||||
// 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);
|
||||
// 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);
|
||||
mark((uintptr_t *)c_start, (uintptr_t *)c_end, worklist);
|
||||
//mark_step(c_start, c_end, worklist);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -232,34 +230,48 @@ namespace GC
|
|||
// 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,
|
||||
// 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) {
|
||||
|
||||
auto it = worklist.begin();
|
||||
auto end = worklist.end();
|
||||
// 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
|
||||
|
||||
while (it != end) {
|
||||
cout << "--- mark_step() was called ---\n" << endl;
|
||||
for (; start <= end; start += sizeof(uintptr_t)) {
|
||||
|
||||
Chunk *chunk = *it;
|
||||
auto c_start = reinterpret_cast<uintptr_t>(chunk->start);
|
||||
auto c_size = reinterpret_cast<uintptr_t>(chunk->size);
|
||||
auto c_end = reinterpret_cast<uintptr_t>(c_start + c_size);
|
||||
auto it = worklist.begin();
|
||||
auto end = worklist.end();
|
||||
|
||||
if (c_start <= memory_location && memory_location < c_end) {
|
||||
while (it != end) {
|
||||
|
||||
if (!chunk->marked) {
|
||||
// Mark the chunk and erase it from the worklist
|
||||
chunk->marked = true;
|
||||
it = worklist.erase(it);
|
||||
// Update the memory location we want to look at
|
||||
memory_location = c_end;
|
||||
Chunk *chunk = *it;
|
||||
auto c_start = reinterpret_cast<uintptr_t>(chunk->start);
|
||||
auto c_size = reinterpret_cast<uintptr_t>(chunk->size);
|
||||
auto c_end = reinterpret_cast<uintptr_t>(c_start + c_size);
|
||||
|
||||
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) {
|
||||
// Mark the chunk and erase it from the worklist
|
||||
chunk->marked = true;
|
||||
it = worklist.erase(it);
|
||||
cout << "Marked this chunk ^\n" << endl;
|
||||
// Update the memory location we want to look at
|
||||
//memory_location = c_end;
|
||||
mark_step(c_start, c_end, worklist);
|
||||
}
|
||||
else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,9 @@
|
|||
#include "player.hpp"
|
||||
#include "heap.hpp"
|
||||
|
||||
#define X_LENGTH 1000;
|
||||
#define Y_LENGTH 500;
|
||||
#define X_LENGTH 1000
|
||||
#define Y_LENGTH 500
|
||||
#define MAX_PLAYERS 100
|
||||
|
||||
/*
|
||||
* Description:
|
||||
|
|
@ -20,19 +21,32 @@
|
|||
* all objects gets allocated, but only Game object gets marked.
|
||||
*/
|
||||
|
||||
|
||||
class Game {
|
||||
|
||||
private:
|
||||
|
||||
std::vector<Player> players;
|
||||
Point dimensions;
|
||||
//std::vector<Player*> *players;
|
||||
std::vector<Player> *players;
|
||||
Point *dimensions;
|
||||
|
||||
public:
|
||||
|
||||
Game() : dimensions(1000, 500) {}
|
||||
Game() {
|
||||
dimensions->x = X_LENGTH;
|
||||
dimensions->y = Y_LENGTH;
|
||||
}
|
||||
|
||||
void add_player(Player& p) {
|
||||
players.push_back(p);
|
||||
void init() {
|
||||
//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) {
|
||||
|
|
@ -49,19 +63,19 @@ public:
|
|||
void create_players(int nr) {
|
||||
for (int i = 0; i < nr; i++) {
|
||||
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() {
|
||||
GC::Heap::init();
|
||||
GC::Heap *gc = GC::Heap::debug_the();
|
||||
gc->check_init();
|
||||
|
||||
Game *game = static_cast<Game*>(gc->alloc(sizeof(Game)));
|
||||
game->init();
|
||||
game->create_players(2);
|
||||
|
||||
std::cout << "Player size: " << sizeof(Player) << std::endl;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ class Point {
|
|||
public:
|
||||
|
||||
int x, y;
|
||||
Point() {}
|
||||
Point(int _x, int _y) : x(_x), y(_y) {}
|
||||
};
|
||||
|
||||
|
|
@ -21,6 +22,8 @@ private:
|
|||
|
||||
public:
|
||||
|
||||
Player() {}
|
||||
|
||||
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)
|
||||
{}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue