| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 #endif | 317 #endif |
| 318 } | 318 } |
| 319 | 319 |
| 320 | 320 |
| 321 class PosixMemoryMappedFile : public OS::MemoryMappedFile { | 321 class PosixMemoryMappedFile : public OS::MemoryMappedFile { |
| 322 public: | 322 public: |
| 323 PosixMemoryMappedFile(FILE* file, void* memory, int size) | 323 PosixMemoryMappedFile(FILE* file, void* memory, int size) |
| 324 : file_(file), memory_(memory), size_(size) { } | 324 : file_(file), memory_(memory), size_(size) { } |
| 325 virtual ~PosixMemoryMappedFile(); | 325 virtual ~PosixMemoryMappedFile(); |
| 326 virtual void* memory() { return memory_; } | 326 virtual void* memory() { return memory_; } |
| 327 virtual int size() { return size_; } |
| 327 private: | 328 private: |
| 328 FILE* file_; | 329 FILE* file_; |
| 329 void* memory_; | 330 void* memory_; |
| 330 int size_; | 331 int size_; |
| 331 }; | 332 }; |
| 332 | 333 |
| 333 | 334 |
| 335 OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) { |
| 336 FILE* file = fopen(name, "w+"); |
| 337 if (file == NULL) return NULL; |
| 338 |
| 339 fseek(file, 0, SEEK_END); |
| 340 int size = ftell(file); |
| 341 |
| 342 void* memory = |
| 343 mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0); |
| 344 return new PosixMemoryMappedFile(file, memory, size); |
| 345 } |
| 346 |
| 347 |
| 334 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size, | 348 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size, |
| 335 void* initial) { | 349 void* initial) { |
| 336 FILE* file = fopen(name, "w+"); | 350 FILE* file = fopen(name, "w+"); |
| 337 if (file == NULL) return NULL; | 351 if (file == NULL) return NULL; |
| 338 int result = fwrite(initial, size, 1, file); | 352 int result = fwrite(initial, size, 1, file); |
| 339 if (result < 1) { | 353 if (result < 1) { |
| 340 fclose(file); | 354 fclose(file); |
| 341 return NULL; | 355 return NULL; |
| 342 } | 356 } |
| 343 void* memory = | 357 void* memory = |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 | 1025 |
| 1012 void Sampler::Stop() { | 1026 void Sampler::Stop() { |
| 1013 ASSERT(IsActive()); | 1027 ASSERT(IsActive()); |
| 1014 SignalSender::RemoveActiveSampler(this); | 1028 SignalSender::RemoveActiveSampler(this); |
| 1015 SetActive(false); | 1029 SetActive(false); |
| 1016 } | 1030 } |
| 1017 | 1031 |
| 1018 #endif // ENABLE_LOGGING_AND_PROFILING | 1032 #endif // ENABLE_LOGGING_AND_PROFILING |
| 1019 | 1033 |
| 1020 } } // namespace v8::internal | 1034 } } // namespace v8::internal |
| OLD | NEW |