|
| 1 | +/** |
| 2 | + * linux64: g++ -I $JULIA_HOME/include/julia/ memlayout.cpp -o memlayout |
| 3 | + * linux32: apt-get install g++-multilib |
| 4 | + * g++ -march=pentium4 -m32 -I $JULIA_HOME/include/julia/ memlayout.cpp -o memlayout |
| 5 | + * macOS: g++ -std=c++11 -I $JULIA_APP/Contents/Resources/julia/include/julia/ memlayout.cpp -o memlayout |
| 6 | + * win64: g++ -I $JULIA_HOME/include/julia/ memlayout.cpp -o memlayout |
| 7 | + * win32: g++ -I $JULIA_HOME/include/julia/ memlayout.cpp -o memlayout |
| 8 | + **/ |
| 9 | + |
| 10 | +#include <string> |
| 11 | +#include <map> |
| 12 | +#include <fstream> |
| 13 | +#include <sstream> |
| 14 | + |
| 15 | +#include <cstddef> |
| 16 | + |
| 17 | +#include "julia.h" |
| 18 | + |
| 19 | +std::string jl_ver(std::string sep=".") { |
| 20 | + std::ostringstream oss; |
| 21 | + oss << JULIA_VERSION_MAJOR << sep |
| 22 | + << JULIA_VERSION_MINOR << sep |
| 23 | + << JULIA_VERSION_PATCH; |
| 24 | + return oss.str(); |
| 25 | +} |
| 26 | + |
| 27 | +std::string platform() { |
| 28 | +#ifdef _WIN32 |
| 29 | +#ifdef _WIN64 |
| 30 | + return "windows-x86_64"; |
| 31 | +#endif |
| 32 | + return "windows-x86"; |
| 33 | +#endif |
| 34 | +#ifdef __APPLE__ |
| 35 | + return "darwin-x86_64"; |
| 36 | +#endif |
| 37 | +#ifdef __linux__ |
| 38 | +#ifdef __x86_64 |
| 39 | + return "linux-x86_64"; |
| 40 | +#else |
| 41 | + return "linux-x86"; |
| 42 | +#endif |
| 43 | +#endif |
| 44 | +} |
| 45 | + |
| 46 | +std::map<std::string, size_t> task_field_offsets() { |
| 47 | + std::map<std::string, size_t> data; |
| 48 | + |
| 49 | +#define field_info(f) data[#f] = offsetof(jl_task_t, f) |
| 50 | + |
| 51 | + field_info(next); // 131 142 153 154 160 170 |
| 52 | + field_info(queue); // 131 142 153 154 160 170 |
| 53 | + field_info(tls); // 131 142 153 154 160 170 |
| 54 | + field_info(donenotify); // 131 142 153 154 160 170 |
| 55 | + field_info(result); // 131 142 153 154 160 170 |
| 56 | + |
| 57 | +#if JULIA_VERSION_MAJOR == 1 && JULIA_VERSION_MINOR < 6 |
| 58 | + field_info(state); // 131 142 153 154 |
| 59 | + field_info(exception); // 131 142 153 154 |
| 60 | + field_info(backtrace); // 131 142 153 154 |
| 61 | +#endif |
| 62 | + |
| 63 | + field_info(logstate); // 131 142 153 154 160 170 |
| 64 | + field_info(start); // 131 142 153 154 160 170 |
| 65 | + field_info(sticky); // 131 142 153 154 160 170 |
| 66 | + |
| 67 | +#if JULIA_VERSION_MAJOR == 1 && JULIA_VERSION_MINOR > 5 |
| 68 | + field_info(_state); // 160 170 |
| 69 | + field_info(_isexception); // 160 170 |
| 70 | +#endif |
| 71 | + |
| 72 | +#if JULIA_VERSION_MAJOR == 1 && JULIA_VERSION_MINOR > 6 |
| 73 | + field_info(rngState0); // 170 |
| 74 | + field_info(rngState1); // 170 |
| 75 | + field_info(rngState2); // 170 |
| 76 | + field_info(rngState3); // 170 |
| 77 | +#endif |
| 78 | + |
| 79 | + // hidden state |
| 80 | + field_info(gcstack); // 131 142 153 154 160 170 |
| 81 | + |
| 82 | +#if JULIA_VERSION_MAJOR == 1 && \ |
| 83 | + (JULIA_VERSION_MINOR > 6 || JULIA_VERSION_MINOR < 5 || \ |
| 84 | + (JULIA_VERSION_MINOR == 5 && JULIA_VERSION_PATCH < 4)) |
| 85 | + field_info(world_age); // 131 142 153 170 |
| 86 | +#endif |
| 87 | + |
| 88 | +#if JULIA_VERSION_MAJOR == 1 && JULIA_VERSION_MINOR > 6 |
| 89 | + field_info(ptls); // 170 |
| 90 | +#endif |
| 91 | + field_info(tid); // 131 142 153 154 160 170 |
| 92 | + field_info(prio); // 131 142 153 154 160 170 |
| 93 | + field_info(excstack); // 131 142 153 154 160 170 |
| 94 | + field_info(eh); // 131 142 153 154 160 170 |
| 95 | + field_info(ctx); // 131 142 153 154 160 170 |
| 96 | + |
| 97 | +#if JULIA_VERSION_MAJOR == 1 && JULIA_VERSION_MINOR < 6 |
| 98 | + field_info(locks); // 131 142 153 154 |
| 99 | + field_info(timing_stack); // 131 142 153 154 |
| 100 | +#endif |
| 101 | + // field_info(copy_stack_ctx); |
| 102 | + |
| 103 | +#if defined(JL_TSAN_ENABLED) |
| 104 | + field_info(tsan_state); // 170 |
| 105 | +#endif |
| 106 | + |
| 107 | + field_info(stkbuf); // 131 142 153 154 160 170 |
| 108 | + field_info(bufsz); // 131 142 153 154 160 170 |
| 109 | + // field_info(copy_stack); |
| 110 | + // field_info(started); |
| 111 | + |
| 112 | +#undef field_info |
| 113 | + data["copy_stack"] = offsetof(jl_task_t, bufsz) + sizeof(size_t); |
| 114 | + data["sizeof_ctx"] = sizeof(((jl_task_t*)0)->ctx); |
| 115 | + // data["sizeof_stack_ctx"] = sizeof(((jl_task_t*)0)->copy_stack_ctx); |
| 116 | + data["tls_base_context"] = offsetof(struct _jl_tls_states_t, base_ctx); |
| 117 | + // data["tls_copy_stack_ctx"] = offsetof(struct _jl_tls_states_t, copy_stack_ctx); |
| 118 | + return data; |
| 119 | +} |
| 120 | + |
| 121 | +int main() { |
| 122 | + std::ofstream ofs(platform() +"-v" + jl_ver("_") + ".jl", std::ofstream::out); |
| 123 | + |
| 124 | + ofs << "ALL_TASK_OFFSETS[(" |
| 125 | + << '"' << platform() << '"' << ", " |
| 126 | + << "v\"" << jl_ver() <<"\"" |
| 127 | + <<")] = Dict(\n"; |
| 128 | + ofs << " :END => " << sizeof(jl_task_t) << ",\n"; |
| 129 | + |
| 130 | + std::map<std::string, size_t> data = task_field_offsets(); |
| 131 | + for(auto kv: data) { |
| 132 | + ofs << " :" << kv.first << " => " << kv.second << ",\n"; |
| 133 | + } |
| 134 | + ofs << ")\n"; |
| 135 | + |
| 136 | + ofs.close(); |
| 137 | + return 0; |
| 138 | +} |
0 commit comments