Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/OpenGraphCxx/Attribute/OGAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <OpenGraph/OGAttribute.h>
#include <OpenGraphCxx/Attribute/AttributeID.hpp>
#include <OpenGraphCxx/Util/assert.hpp>
#include <OpenGraphCxx/Misc/assert.hpp>
#include <optional>

const OGAttribute OGAttributeNil = OGAttribute(OG::AttributeID::Kind::Null);
Expand Down
20 changes: 10 additions & 10 deletions Sources/OpenGraphCxx/Data/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// table.cpp
// OpenGraphCxx
//
// Audited for 6.5.4
// Audited for 6.5.1
// Status: WIP
// Modified based Compute code

#include <OpenGraphCxx/Data/table.hpp>
#include <OpenGraphCxx/Data/page.hpp>
#include <OpenGraphCxx/Data/page_const.hpp>
#include <OpenGraphCxx/Data/zone.hpp>
#include <OpenGraphCxx/Util/assert.hpp>
#include <OpenGraphCxx/Misc/assert.hpp>
#include <sys/mman.h>
#include <dispatch/dispatch.h>
#if OG_TARGET_OS_DARWIN
Expand All @@ -29,7 +29,7 @@ namespace OG {
namespace data {

#if OG_TARGET_OS_DARWIN
malloc_zone_t *_Nullable _malloc_zone;
malloc_zone_t *table::_malloc_zone = nullptr;
#endif

table &table::ensure_shared() {
Expand Down Expand Up @@ -242,9 +242,9 @@ void table::dealloc_page_locked(ptr<page> page) OG_NOEXCEPT {
}
}

// TO BE AUDITED
uint64_t table::raw_page_seed(ptr<page> page) OG_NOEXCEPT {
page.assert_valid(_data_capacity);
OG_CONSTEXPR
uint64_t table::raw_page_seed(ptr<page> page) const OG_NOEXCEPT {
assert_valid(page);
lock();
uint32_t page_index = page.page_index();
uint32_t map_index = page_index / pages_per_map;
Expand All @@ -255,8 +255,8 @@ uint64_t table::raw_page_seed(ptr<page> page) OG_NOEXCEPT {
if (map_index < _page_metadata_maps.size() && _page_metadata_maps[map_index].test(page_index % page_size)) {
auto info = page->zone->info();
// FIXME
w22 = info.to_raw_value() & 0xffffff00;
w21 = info.to_raw_value() & 0x000000ff;
w22 = info.value() & 0xffffff00;
w21 = info.value() & 0x000000ff;
result = uint64_t(1) << 32;
}
unlock();
Expand All @@ -267,9 +267,9 @@ void table::print() const OG_NOEXCEPT {
lock();
fprintf(stderr, "data::table %p:\n %.2fKB allocated, %.2fKB used, %.2fKB reusable.\n",
this,
double(_region_capacity - page_size) / 1024.0,
double(region_capacity() - page_size) / 1024.0,
double(this->used_pages_num()) / 1024.0,
double(_reusable_pages_num) / 1024.0);
double(reusable_pages_num()) / 1024.0);
unlock();
}

Expand Down
16 changes: 13 additions & 3 deletions Sources/OpenGraphCxx/Data/zone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <OpenGraphCxx/Data/zone.hpp>
#include <OpenGraphCxx/Data/table.hpp>
#include <OpenGraphCxx/Data/page.hpp>
#include <OpenGraphCxx/Util/assert.hpp>
#include <OpenGraphCxx/Misc/assert.hpp>
#if OG_TARGET_OS_DARWIN
#include <malloc/malloc.h>
#else
Expand All @@ -15,7 +15,17 @@
namespace OG {
namespace data {

void zone::clear() OG_NOEXCEPT {
//zone::zone() : _info(info(shared_table().make_zone_id())) {}

//zone::~zone() {
// clear();
//
//}

void zone::clear() {
// for (auto &element : malloc_buffers()) {
// element.reset();
// }
shared_table().lock();
while (last_page()) {
auto page = last_page();
Expand Down Expand Up @@ -121,7 +131,7 @@ void zone::print() const OG_NOEXCEPT {
);
}

void zone::print_header() OG_NOEXCEPT {
void zone::print_header() const OG_NOEXCEPT {
fprintf(stderr, "Zones\n%-16s %6s %8s %8s %6s %6s %6s %8s\n",
"zone ptr", "pages", "total", "in-use", "free", "bytes", "malloc", "total");
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/OpenGraphCxx/DebugServer/og-debug-server.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#if OG_TARGET_OS_DARWIN

#include <OpenGraph/OGGraphDescription.h>
#include <OpenGraphCxx/Util/log.hpp>
#include <OpenGraphCxx/Util/assert.hpp>
#include <OpenGraphCxx/Misc/log.hpp>
#include <OpenGraphCxx/Misc/assert.hpp>
#include <OpenGraphCxx/Graph/Graph.hpp>

#include <iostream>
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenGraphCxx/Graph/GraphContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <OpenGraphCxx/Graph/Graph.hpp>
#include <OpenGraph/OGGraph.h>
#include <OpenGraphCxx/Util/assert.hpp>
#include <OpenGraphCxx/Misc/assert.hpp>

OG::Graph::Context &OG::Graph::Context::from_cf(OGGraphRef storage) OG_NOEXCEPT {
if (storage->context.isInvalid()) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenGraphCxx/Graph/GraphDescription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <OpenGraph/OGGraphDescription.h>
#include <OpenGraph/OGGraph.h>
#include <OpenGraphCxx/Graph/Graph.hpp>
#include <OpenGraphCxx/Util/assert.hpp>
#include <OpenGraphCxx/Misc/assert.hpp>

CFTypeRef OGGraphDescription(OGGraphRef graph, CFDictionaryRef options) {
#if OG_OBJC_FOUNDATION
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenGraphCxx/Graph/GraphDescription.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <OpenGraph/OGGraphDescription.h>
#include <OpenGraph/OGGraph.h>
#include <OpenGraphCxx/Graph/Graph.hpp>
#include <OpenGraphCxx/Util/assert.hpp>
#include <OpenGraphCxx/Misc/assert.hpp>

#if OG_OBJC_FOUNDATION

Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenGraphCxx/Graph/OGGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <OpenGraph/OGGraph.h>
#include <OpenGraphCxx/Graph/Graph.hpp>
#include <OpenGraphCxx/Util/assert.hpp>
#include <OpenGraphCxx/Misc/assert.hpp>
#include <OpenGraphCxx/Data/ClosureFunction.hpp>
#include <pthread.h>

Expand Down
4 changes: 2 additions & 2 deletions Sources/OpenGraphCxx/Graph/OGSubgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <OpenGraph/OGGraph.h>
#include <OpenGraphCxx/Graph/Subgraph.hpp>
#include <OpenGraph/OGGraphContext.h>
#include <OpenGraphCxx/Util/assert.hpp>
#include <OpenGraphCxx/Util/env.hpp>
#include <OpenGraphCxx/Misc/assert.hpp>
#include <OpenGraphCxx/Misc/env.hpp>
#include <pthread.h>
#if !OG_TARGET_OS_WASI
#include <dispatch/dispatch.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// assert.cpp
// OpenGraphCxx

#include <OpenGraphCxx/Util/assert.hpp>
#include <OpenGraphCxx/Util/log.hpp>
#include <OpenGraphCxx/Misc/assert.hpp>
#include <OpenGraphCxx/Misc/log.hpp>

#include <stdio.h>
#include <stdlib.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Audited for 2021 Release

#include <OpenGraphCxx/Util/log.hpp>
#include <OpenGraphCxx/Misc/log.hpp>

#if OG_TARGET_OS_DARWIN

Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenGraphCxx/Runtime/OGTupleType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <OpenGraph/OGTupleType.h>
#include <OpenGraphCxx/Runtime/metadata.hpp>
#include <OpenGraphCxx/Util/assert.hpp>
#include <OpenGraphCxx/Misc/assert.hpp>

#ifdef OPENGRAPH_SWIFT_TOOLCHAIN_SUPPORTED
#include <swift/Runtime/Metadata.h>
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenGraphCxx/Runtime/OGTypeID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <OpenGraph/OGTypeID.h>
#include <OpenGraphCxx/Runtime/metadata.hpp>
#include <OpenGraphCxx/Util/assert.hpp>
#include <OpenGraphCxx/Misc/assert.hpp>

#ifdef OPENGRAPH_SWIFT_TOOLCHAIN_SUPPORTED
#include <swift/Runtime/Metadata.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// realloc_vector.cpp
// OpenGraphCxx

#include <OpenGraphCxx/Util/realloc_vector.hpp>
#include <OpenGraphCxx/Util/assert.hpp>
#include <OpenGraphCxx/Vector/realloc_vector.hpp>
#include <OpenGraphCxx/Misc/assert.hpp>

#if OG_TARGET_OS_DARWIN
#include <malloc/malloc.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <OpenGraph/OGBase.h>
#include <OpenGraph/OGAttribute.h>
#include <OpenGraphCxx/Util/assert.hpp>
#include <OpenGraphCxx/Misc/assert.hpp>

namespace OG {
class AttributeID final {
Expand Down
18 changes: 6 additions & 12 deletions Sources/OpenGraphCxx/include/OpenGraphCxx/Data/ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,11 @@ template <typename T> class ptr {
using element_type = T;
using difference_type = uint32_t;

private:
difference_type _offset;

template <typename U> friend class ptr;

public:
OG_INLINE OG_CONSTEXPR ptr(difference_type offset = 0) : _offset(offset){};
OG_INLINE OG_CONSTEXPR ptr(std::nullptr_t){};

OG_INLINE
void assert_valid(uint32_t capacity = shared_table().data_capacity()) const {
if (capacity <= _offset) {
precondition_failure("invalid data offset: %u", _offset);
}
}

// FIXME: this should be put into table API
OG_INLINE
element_type *_Nonnull get(vm_address_t base = shared_table().data_base()) const OG_NOEXCEPT {
assert(_offset != 0);
Expand Down Expand Up @@ -100,6 +89,11 @@ template <typename T> class ptr {
difference_type operator-(const ptr<U> &other) const OG_NOEXCEPT {
return _offset - other._offset;
};
private:
difference_type _offset;

template <typename U> friend class ptr;
friend class table;
}; /* ptr */

} /* data */
Expand Down
25 changes: 24 additions & 1 deletion Sources/OpenGraphCxx/include/OpenGraphCxx/Data/table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <OpenGraph/OGBase.h>
#include <OpenGraphCxx/Vector/vector.hpp>

#if OG_TARGET_OS_DARWIN
#include <mach/vm_types.h>
#else
Expand All @@ -19,6 +20,8 @@ typedef vm_offset_t vm_address_t;
#include <os/lock.h>
#endif

OG_ASSUME_NONNULL_BEGIN

namespace OG {
namespace data {
class zone;
Expand All @@ -28,8 +31,17 @@ template <typename T> class ptr;
class table {
public:
class malloc_zone_deleter {
void operator()(void* ptr) const {
#if OG_TARGET_OS_DARWIN
malloc_zone_free(_malloc_zone, ptr);
#endif
}
};

#if OG_TARGET_OS_DARWIN
static malloc_zone_t *_malloc_zone;
#endif

public:
static table &ensure_shared();

Expand Down Expand Up @@ -77,6 +89,14 @@ class table {
return _zones_num;
}

template <typename T>
OG_INLINE
void assert_valid(const ptr<T>& p) const {
if (data_capacity() <= p._offset) {
precondition_failure("invalid data offset: %u", p._offset);
}
}

table();

void grow_region() OG_NOEXCEPT;
Expand All @@ -87,7 +107,8 @@ class table {

void dealloc_page_locked(ptr<page> page) OG_NOEXCEPT;

uint64_t raw_page_seed(ptr<page> page) OG_NOEXCEPT;
OG_INLINE OG_CONSTEXPR
uint64_t raw_page_seed(ptr<page> page) const OG_NOEXCEPT;

void print() const OG_NOEXCEPT;
private:
Expand Down Expand Up @@ -133,4 +154,6 @@ static table &shared_table() {
} /* data */
} /* OG */

OG_ASSUME_NONNULL_END

#endif /* table_hpp */
Loading