| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/globals.h" | 5 #include "vm/globals.h" |
| 6 #if defined(TARGET_OS_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
| 7 | 7 |
| 8 #include "vm/os.h" | 8 #include "vm/os.h" |
| 9 | 9 |
| 10 #include <errno.h> // NOLINT | 10 #include <errno.h> // NOLINT |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 195 |
| 196 virtual void Notify(const char* name, | 196 virtual void Notify(const char* name, |
| 197 uword base, | 197 uword base, |
| 198 uword prologue_offset, | 198 uword prologue_offset, |
| 199 uword size, | 199 uword size, |
| 200 bool optimized) { | 200 bool optimized) { |
| 201 WriteCodeLoad(name, base, prologue_offset, size, optimized); | 201 WriteCodeLoad(name, base, prologue_offset, size, optimized); |
| 202 } | 202 } |
| 203 | 203 |
| 204 private: | 204 private: |
| 205 static const uint32_t kJitHeaderMagic = 0x4F74496A; | 205 static const uint32_t kJitHeaderMagic = 0x4A695444; |
| 206 static const uint32_t kJitHeaderVersion = 0x2; | 206 static const uint32_t kJitHeaderMagicSw = 0x4454694A; |
| 207 static const uint32_t kJitHeaderVersion = 0x1; |
| 207 static const uint32_t kElfMachIA32 = 3; | 208 static const uint32_t kElfMachIA32 = 3; |
| 208 static const uint32_t kElfMachX64 = 62; | 209 static const uint32_t kElfMachX64 = 62; |
| 209 static const uint32_t kElfMachARM = 40; | 210 static const uint32_t kElfMachARM = 40; |
| 210 // TODO(zra): Find the right ARM64 constant. | 211 // TODO(zra): Find the right ARM64 constant. |
| 211 static const uint32_t kElfMachARM64 = 40; | 212 static const uint32_t kElfMachARM64 = 40; |
| 212 static const uint32_t kElfMachMIPS = 10; | 213 static const uint32_t kElfMachMIPS = 10; |
| 213 static const int kInvalidClockId = -1; | 214 static const int kInvalidClockId = -1; |
| 214 | 215 |
| 215 struct jitheader { | 216 struct jitheader { |
| 216 uint32_t magic; | 217 uint32_t magic; /* characters "jItD" */ |
| 217 uint32_t version; | 218 uint32_t version; /* header version */ |
| 219 uint32_t total_size; /* total size of header */ |
| 220 uint32_t elf_mach; /* elf mach target */ |
| 221 uint32_t pad1; /* reserved */ |
| 222 uint32_t pid; /* JIT process id */ |
| 223 uint64_t timestamp; /* timestamp */ |
| 224 }; |
| 225 |
| 226 /* record prefix (mandatory in each record) */ |
| 227 struct jr_prefix { |
| 228 uint32_t id; |
| 218 uint32_t total_size; | 229 uint32_t total_size; |
| 219 uint32_t elf_mach; | |
| 220 uint32_t pad1; | |
| 221 uint32_t pid; | |
| 222 uint64_t timestamp; | 230 uint64_t timestamp; |
| 223 }; | 231 }; |
| 224 | 232 |
| 225 enum jit_record_type { | 233 enum jit_record_type { |
| 226 JIT_CODE_LOAD = 0, | 234 JIT_CODE_LOAD = 0, |
| 227 /* JIT_CODE_UNLOAD = 1, */ | 235 /* JIT_CODE_MOVE = 1, */ |
| 228 /* JIT_CODE_CLOSE = 2, */ | 236 /* JIT_CODE_DEBUG_INFO = 2, */ |
| 229 /* JIT_CODE_DEBUG_INFO = 3, */ | 237 /* JIT_CODE_CLOSE = 3, */ |
| 230 JIT_CODE_MAX = 4, | 238 JIT_CODE_MAX = 4, |
| 231 }; | 239 }; |
| 232 | 240 |
| 233 struct jr_code_load { | 241 struct jr_code_load { |
| 234 uint32_t id; | 242 struct jr_prefix prefix; |
| 235 uint32_t total_size; | |
| 236 uint64_t timestamp; | |
| 237 uint32_t pid; | 243 uint32_t pid; |
| 238 uint32_t tid; | 244 uint32_t tid; |
| 239 uint64_t vma; | 245 uint64_t vma; |
| 240 uint64_t code_addr; | 246 uint64_t code_addr; |
| 241 uint32_t code_size; | 247 uint64_t code_size; |
| 242 uint64_t code_index; | 248 uint64_t code_index; |
| 243 uint32_t align; | |
| 244 }; | 249 }; |
| 245 | 250 |
| 246 const char* GenerateCodeName(const char* name, bool optimized) { | 251 const char* GenerateCodeName(const char* name, bool optimized) { |
| 247 const char* format = "%s%s"; | 252 const char* format = "%s%s"; |
| 248 const char* marker = optimized ? "*" : ""; | 253 const char* marker = optimized ? "*" : ""; |
| 249 intptr_t len = OS::SNPrint(NULL, 0, format, marker, name); | 254 intptr_t len = OS::SNPrint(NULL, 0, format, marker, name); |
| 250 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(len + 1); | 255 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(len + 1); |
| 251 OS::SNPrint(buffer, len + 1, format, marker, name); | 256 OS::SNPrint(buffer, len + 1, format, marker, name); |
| 252 return buffer; | 257 return buffer; |
| 253 } | 258 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 } | 294 } |
| 290 | 295 |
| 291 void WriteHeader() { | 296 void WriteHeader() { |
| 292 Dart_FileWriteCallback file_write = Isolate::file_write_callback(); | 297 Dart_FileWriteCallback file_write = Isolate::file_write_callback(); |
| 293 ASSERT(file_write != NULL); | 298 ASSERT(file_write != NULL); |
| 294 ASSERT(out_file_ != NULL); | 299 ASSERT(out_file_ != NULL); |
| 295 jitheader header; | 300 jitheader header; |
| 296 header.magic = kJitHeaderMagic; | 301 header.magic = kJitHeaderMagic; |
| 297 header.version = kJitHeaderVersion; | 302 header.version = kJitHeaderVersion; |
| 298 header.total_size = sizeof(jitheader); | 303 header.total_size = sizeof(jitheader); |
| 299 header.pad1 = 0xdeadbeef; | 304 header.pad1 = 0x0; |
| 300 header.elf_mach = GetElfMach(); | 305 header.elf_mach = GetElfMach(); |
| 301 header.pid = getpid(); | 306 header.pid = getpid(); |
| 302 header.timestamp = GetKernelTimeNanos(); | 307 header.timestamp = GetKernelTimeNanos(); |
| 303 { | 308 { |
| 304 MutexLocker ml(CodeObservers::mutex()); | 309 MutexLocker ml(CodeObservers::mutex()); |
| 305 (*file_write)(&header, sizeof(header), out_file_); | 310 (*file_write)(&header, sizeof(header), out_file_); |
| 306 } | 311 } |
| 307 } | 312 } |
| 308 | 313 |
| 309 void WriteCodeLoad(const char* name, uword base, uword prologue_offset, | 314 void WriteCodeLoad(const char* name, uword base, uword prologue_offset, |
| 310 uword code_size, bool optimized) { | 315 uword code_size, bool optimized) { |
| 311 Dart_FileWriteCallback file_write = Isolate::file_write_callback(); | 316 Dart_FileWriteCallback file_write = Isolate::file_write_callback(); |
| 312 ASSERT(file_write != NULL); | 317 ASSERT(file_write != NULL); |
| 313 ASSERT(out_file_ != NULL); | 318 ASSERT(out_file_ != NULL); |
| 314 | 319 |
| 315 const char* code_name = GenerateCodeName(name, optimized); | 320 const char* code_name = GenerateCodeName(name, optimized); |
| 316 const intptr_t code_name_size = strlen(code_name) + 1; | 321 const intptr_t code_name_size = strlen(code_name) + 1; |
| 317 uint8_t* code_pointer = reinterpret_cast<uint8_t*>(base); | 322 uint8_t* code_pointer = reinterpret_cast<uint8_t*>(base); |
| 318 | 323 |
| 319 jr_code_load code_load; | 324 jr_code_load code_load; |
| 320 code_load.id = JIT_CODE_LOAD; | 325 code_load.prefix.id = JIT_CODE_LOAD; |
| 321 code_load.total_size = sizeof(code_load) + code_name_size + code_size; | 326 code_load.prefix.total_size = |
| 322 code_load.timestamp = GetKernelTimeNanos(); | 327 sizeof(code_load) + code_name_size + code_size; |
| 328 code_load.prefix.timestamp = GetKernelTimeNanos(); |
| 323 code_load.pid = getpid(); | 329 code_load.pid = getpid(); |
| 324 code_load.tid = gettid(); | 330 code_load.tid = gettid(); |
| 325 code_load.vma = 0x0; // Our addresses are absolute. | 331 code_load.vma = 0x0; // Our addresses are absolute. |
| 326 code_load.code_addr = base; | 332 code_load.code_addr = base; |
| 327 code_load.code_size = code_size; | 333 code_load.code_size = code_size; |
| 328 code_load.align = OS::PreferredCodeAlignment(); | |
| 329 | 334 |
| 330 { | 335 { |
| 331 MutexLocker ml(CodeObservers::mutex()); | 336 MutexLocker ml(CodeObservers::mutex()); |
| 332 // Set this field under the index. | 337 // Set this field under the index. |
| 333 code_load.code_index = code_sequence_++; | 338 code_load.code_index = code_sequence_++; |
| 334 // Write structures. | 339 // Write structures. |
| 335 (*file_write)(&code_load, sizeof(code_load), out_file_); | 340 (*file_write)(&code_load, sizeof(code_load), out_file_); |
| 336 (*file_write)(code_name, code_name_size, out_file_); | 341 (*file_write)(code_name, code_name_size, out_file_); |
| 337 (*file_write)(code_pointer, code_size, out_file_); | 342 (*file_write)(code_pointer, code_size, out_file_); |
| 338 } | 343 } |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 } | 620 } |
| 616 | 621 |
| 617 | 622 |
| 618 void OS::Exit(int code) { | 623 void OS::Exit(int code) { |
| 619 exit(code); | 624 exit(code); |
| 620 } | 625 } |
| 621 | 626 |
| 622 } // namespace dart | 627 } // namespace dart |
| 623 | 628 |
| 624 #endif // defined(TARGET_OS_LINUX) | 629 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |