| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 63f85d5 commit bf789b5
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,8 @@ | |||
| 1 | 1 | #include "env-inl.h" | |
| 2 | 2 | #include "base_object-inl.h" | |
| 3 | 3 | #include "debug_utils.h" | |
| 4 | + #include "memory_tracker-inl.h" | ||
| 5 | + #include "node_mem-inl.h" | ||
| 4 | 6 | #include "util-inl.h" | |
| 5 | 7 | #include "node.h" | |
| 6 | 8 | #include "uv.h" | |
@@ -84,14 +86,33 @@ WASI::WASI(Environment* env, | |||
| 84 | 86 | Local<Object> object, | |
| 85 | 87 | uvwasi_options_t* options) : BaseObject(env, object) { | |
| 86 | 88 | MakeWeak(); | |
| 89 | + alloc_info_ = MakeAllocator(); | ||
| 90 | + options->allocator = &alloc_info_; | ||
| 87 | 91 | CHECK_EQ(uvwasi_init(&uvw_, options), UVWASI_ESUCCESS); | |
| 88 | 92 | } | |
| 89 | 93 | ||
| 90 | 94 | ||
| 91 | 95 | WASI::~WASI() { | |
| 92 | 96 | uvwasi_destroy(&uvw_); | |
| 97 | + CHECK_EQ(current_uvwasi_memory_, 0); | ||
| 93 | 98 | } | |
| 94 | 99 | ||
| 100 | + void WASI::MemoryInfo(MemoryTracker* tracker) const { | ||
| 101 | + tracker->TrackField("memory", memory_); | ||
| 102 | + tracker->TrackFieldWithSize("uvwasi_memory", current_uvwasi_memory_); | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + void WASI::CheckAllocatedSize(size_t previous_size) const { | ||
| 106 | + CHECK_GE(current_uvwasi_memory_, previous_size); | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + void WASI::IncreaseAllocatedSize(size_t size) { | ||
| 110 | + current_uvwasi_memory_ += size; | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + void WASI::DecreaseAllocatedSize(size_t size) { | ||
| 114 | + current_uvwasi_memory_ -= size; | ||
| 115 | + } | ||
| 95 | 116 | ||
| 96 | 117 | void WASI::New(const FunctionCallbackInfo<Value>& args) { | |
| 97 | 118 | CHECK(args.IsConstructCall()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,24 +4,22 @@ | |||
| 4 | 4 | #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | |
| 5 | 5 | ||
| 6 | 6 | #include "base_object.h" | |
| 7 | - #include "memory_tracker-inl.h" | ||
| 7 | + #include "node_mem.h" | ||
| 8 | 8 | #include "uvwasi.h" | |
| 9 | 9 | ||
| 10 | 10 | namespace node { | |
| 11 | 11 | namespace wasi { | |
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | - class WASI : public BaseObject { | ||
| 14 | + class WASI : public BaseObject, | ||
| 15 | + public mem::NgLibMemoryManager<WASI, uvwasi_mem_t> { | ||
| 15 | 16 | public: | |
| 16 | 17 | WASI(Environment* env, | |
| 17 | 18 | v8::Local<v8::Object> object, | |
| 18 | 19 | uvwasi_options_t* options); | |
| 19 | 20 | static void New(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 20 | - void MemoryInfo(MemoryTracker* tracker) const override { | ||
| 21 | - /* TODO(cjihrig): Get memory consumption from uvwasi. */ | ||
| 22 | - tracker->TrackField("memory", memory_); | ||
| 23 | - } | ||
| 24 | 21 | ||
| 22 | + void MemoryInfo(MemoryTracker* tracker) const override; | ||
| 25 | 23 | SET_MEMORY_INFO_NAME(WASI) | |
| 26 | 24 | SET_SELF_SIZE(WASI) | |
| 27 | 25 | ||
@@ -79,6 +77,11 @@ class WASI : public BaseObject { | |||
| 79 | 77 | ||
| 80 | 78 | static void _SetMemory(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 81 | 79 | ||
| 80 | + // Implementation for mem::NgLibMemoryManager | ||
| 81 | + void CheckAllocatedSize(size_t previous_size) const; | ||
| 82 | + void IncreaseAllocatedSize(size_t size); | ||
| 83 | + void DecreaseAllocatedSize(size_t size); | ||
| 84 | + | ||
| 82 | 85 | private: | |
| 83 | 86 | ~WASI() override; | |
| 84 | 87 | inline void readUInt8(char* memory, uint8_t* value, uint32_t offset); | |
@@ -92,6 +95,8 @@ class WASI : public BaseObject { | |||
| 92 | 95 | uvwasi_errno_t backingStore(char** store, size_t* byte_length); | |
| 93 | 96 | uvwasi_t uvw_; | |
| 94 | 97 | v8::Global<v8::Object> memory_; | |
| 98 | + uvwasi_mem_t alloc_info_; | ||
| 99 | + size_t current_uvwasi_memory_ = 0; | ||
| 95 | 100 | }; | |
| 96 | 101 | ||
| 97 | 102 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments