| OLD | NEW |
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 #endif | 206 #endif |
| 207 } | 207 } |
| 208 | 208 |
| 209 | 209 |
| 210 class PosixMemoryMappedFile : public OS::MemoryMappedFile { | 210 class PosixMemoryMappedFile : public OS::MemoryMappedFile { |
| 211 public: | 211 public: |
| 212 PosixMemoryMappedFile(FILE* file, void* memory, int size) | 212 PosixMemoryMappedFile(FILE* file, void* memory, int size) |
| 213 : file_(file), memory_(memory), size_(size) { } | 213 : file_(file), memory_(memory), size_(size) { } |
| 214 virtual ~PosixMemoryMappedFile(); | 214 virtual ~PosixMemoryMappedFile(); |
| 215 virtual void* memory() { return memory_; } | 215 virtual void* memory() { return memory_; } |
| 216 virtual int size() { return size_; } |
| 216 private: | 217 private: |
| 217 FILE* file_; | 218 FILE* file_; |
| 218 void* memory_; | 219 void* memory_; |
| 219 int size_; | 220 int size_; |
| 220 }; | 221 }; |
| 221 | 222 |
| 222 | 223 |
| 224 OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) { |
| 225 FILE* file = fopen(name, "w+"); |
| 226 if (file == NULL) return NULL; |
| 227 |
| 228 fseek(file, 0, SEEK_END); |
| 229 int size = ftell(file); |
| 230 |
| 231 void* memory = |
| 232 mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0); |
| 233 return new PosixMemoryMappedFile(file, memory, size); |
| 234 } |
| 235 |
| 236 |
| 223 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size, | 237 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size, |
| 224 void* initial) { | 238 void* initial) { |
| 225 FILE* file = fopen(name, "w+"); | 239 FILE* file = fopen(name, "w+"); |
| 226 if (file == NULL) return NULL; | 240 if (file == NULL) return NULL; |
| 227 int result = fwrite(initial, size, 1, file); | 241 int result = fwrite(initial, size, 1, file); |
| 228 if (result < 1) { | 242 if (result < 1) { |
| 229 fclose(file); | 243 fclose(file); |
| 230 return NULL; | 244 return NULL; |
| 231 } | 245 } |
| 232 void* memory = | 246 void* memory = |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 } | 648 } |
| 635 | 649 |
| 636 // This sampler is no longer the active sampler. | 650 // This sampler is no longer the active sampler. |
| 637 active_sampler_ = NULL; | 651 active_sampler_ = NULL; |
| 638 active_ = false; | 652 active_ = false; |
| 639 } | 653 } |
| 640 | 654 |
| 641 #endif // ENABLE_LOGGING_AND_PROFILING | 655 #endif // ENABLE_LOGGING_AND_PROFILING |
| 642 | 656 |
| 643 } } // namespace v8::internal | 657 } } // namespace v8::internal |
| OLD | NEW |