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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 #endif | 311 #endif |
312 } | 312 } |
313 | 313 |
314 | 314 |
315 class PosixMemoryMappedFile : public OS::MemoryMappedFile { | 315 class PosixMemoryMappedFile : public OS::MemoryMappedFile { |
316 public: | 316 public: |
317 PosixMemoryMappedFile(FILE* file, void* memory, int size) | 317 PosixMemoryMappedFile(FILE* file, void* memory, int size) |
318 : file_(file), memory_(memory), size_(size) { } | 318 : file_(file), memory_(memory), size_(size) { } |
319 virtual ~PosixMemoryMappedFile(); | 319 virtual ~PosixMemoryMappedFile(); |
320 virtual void* memory() { return memory_; } | 320 virtual void* memory() { return memory_; } |
| 321 virtual int size() { return size_; } |
321 private: | 322 private: |
322 FILE* file_; | 323 FILE* file_; |
323 void* memory_; | 324 void* memory_; |
324 int size_; | 325 int size_; |
325 }; | 326 }; |
326 | 327 |
327 | 328 |
| 329 OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) { |
| 330 FILE* file = fopen(name, "w+"); |
| 331 if (file == NULL) return NULL; |
| 332 |
| 333 fseek(file, 0, SEEK_END); |
| 334 int size = ftell(file); |
| 335 |
| 336 void* memory = |
| 337 mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0); |
| 338 return new PosixMemoryMappedFile(file, memory, size); |
| 339 } |
| 340 |
| 341 |
328 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size, | 342 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size, |
329 void* initial) { | 343 void* initial) { |
330 FILE* file = fopen(name, "w+"); | 344 FILE* file = fopen(name, "w+"); |
331 if (file == NULL) return NULL; | 345 if (file == NULL) return NULL; |
332 int result = fwrite(initial, size, 1, file); | 346 int result = fwrite(initial, size, 1, file); |
333 if (result < 1) { | 347 if (result < 1) { |
334 fclose(file); | 348 fclose(file); |
335 return NULL; | 349 return NULL; |
336 } | 350 } |
337 void* memory = | 351 void* memory = |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
958 } | 972 } |
959 | 973 |
960 // This sampler is no longer the active sampler. | 974 // This sampler is no longer the active sampler. |
961 active_sampler_ = NULL; | 975 active_sampler_ = NULL; |
962 } | 976 } |
963 | 977 |
964 | 978 |
965 #endif // ENABLE_LOGGING_AND_PROFILING | 979 #endif // ENABLE_LOGGING_AND_PROFILING |
966 | 980 |
967 } } // namespace v8::internal | 981 } } // namespace v8::internal |
OLD | NEW |