|
14 | 14 | #include <memory> |
15 | 15 | #include <stack> |
16 | 16 | #include <stdexcept> |
| 17 | +#include <string> |
17 | 18 | #include <thread> |
18 | 19 | #include <typeindex> |
19 | 20 | #include <variant> |
@@ -128,54 +129,6 @@ int boot(std::vector<std::string> args) |
128 | 129 | std::shared_ptr<OMClassFileParser> parser; |
129 | 130 | bool recovermode = false; |
130 | 131 |
|
131 | | - std::thread t([&]() { |
132 | | - while (true) |
133 | | - { |
134 | | - mem::castorice::printres(); |
135 | | - std::this_thread::sleep_for(std::chrono::milliseconds(500)); |
136 | | - |
137 | | - std::vector<void *> buf; |
138 | | - |
139 | | - for (auto cls : pt->classloader->classes) |
140 | | - { |
141 | | - pt->mm->seatchFromStatic(cls.second, buf); |
142 | | - } |
143 | | - |
144 | | - auto i = std::any_cast<std::shared_ptr<runtime::OMInterpreter>>(pt->interpreter); |
145 | | - |
146 | | - for (auto stks : i->stack) |
147 | | - { |
148 | | - std::stack<std::any> stk(stks.second); |
149 | | - |
150 | | - while (!stk.empty()) |
151 | | - { |
152 | | - if (std::type_index(stk.top().type()) == std::type_index(typeid(void *))) |
153 | | - { |
154 | | - pt->mm->searchFromInstance(std::any_cast<void *>(stk.top()), buf); |
155 | | - } |
156 | | - else if (std::type_index(stk.top().type()) == |
157 | | - std::type_index(typeid(std::shared_ptr<runtime::OMFrameMetadata>))) |
158 | | - { |
159 | | - auto frame = std::any_cast<std::shared_ptr<runtime::OMFrameMetadata>>(stk.top()); |
160 | | - for (auto fr : frame->local) |
161 | | - { |
162 | | - if (std::type_index(fr.type()) == std::type_index(typeid(void *))) |
163 | | - { |
164 | | - pt->mm->searchFromInstance(std::any_cast<void *>(fr), buf); |
165 | | - } |
166 | | - } |
167 | | - } |
168 | | - |
169 | | - stk.pop(); |
170 | | - } |
171 | | - } |
172 | | - |
173 | | - std::sort(buf.begin(), buf.end()); |
174 | | - buf.erase(std::unique(buf.begin(), buf.end()), buf.end()); |
175 | | - pt->mm->deallocate(buf); |
176 | | - } |
177 | | - }); |
178 | | - |
179 | 132 | if (setjmp(recoverBuffer) == 0) |
180 | 133 | { |
181 | 134 | program: |
@@ -210,7 +163,6 @@ int boot(std::vector<std::string> args) |
210 | 163 | { |
211 | 164 | if (commandBuffer[1] == "loadcls") |
212 | 165 | { |
213 | | - |
214 | 166 | try |
215 | 167 | { |
216 | 168 | pt->loadClass(std::make_shared<std::ifstream>(commandBuffer[2], std::ios::binary)); |
@@ -238,6 +190,28 @@ int boot(std::vector<std::string> args) |
238 | 190 |
|
239 | 191 | commandBuffer.clear(); |
240 | 192 | } |
| 193 | + else if (commandBuffer[1] == "memtest") |
| 194 | + { |
| 195 | + std::vector<void *> pp; |
| 196 | + try |
| 197 | + { |
| 198 | + while (true) |
| 199 | + { |
| 200 | + pp.push_back(pt->mm->allocate(pt->fetchClass("java/lang/String"))); |
| 201 | + } |
| 202 | + } |
| 203 | + catch (std::logic_error e) |
| 204 | + { |
| 205 | + pt->mm->debug(); |
| 206 | + } |
| 207 | + |
| 208 | + pt->mm->deallocate(pp[0]); |
| 209 | + pt->mm->deallocate(pp[2]); |
| 210 | + pt->mm->deallocate(pp[1]); |
| 211 | + pt->mm->debug(); |
| 212 | + |
| 213 | + commandBuffer.clear(); |
| 214 | + } |
241 | 215 | else if (commandBuffer[1] == "init") |
242 | 216 | { |
243 | 217 | std::vector<std::string> m; |
|
0 commit comments