OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 } | 294 } |
295 static const int kMinComplexMemCopy = 256; | 295 static const int kMinComplexMemCopy = 256; |
296 #endif // V8_TARGET_ARCH_IA32 | 296 #endif // V8_TARGET_ARCH_IA32 |
297 | 297 |
298 private: | 298 private: |
299 static const int msPerSecond = 1000; | 299 static const int msPerSecond = 1000; |
300 | 300 |
301 DISALLOW_IMPLICIT_CONSTRUCTORS(OS); | 301 DISALLOW_IMPLICIT_CONSTRUCTORS(OS); |
302 }; | 302 }; |
303 | 303 |
304 | 304 // Represents and controls an area of reserved memory. |
| 305 // Control of the reserved memory can be assigned to another VirtualMemory |
| 306 // object by assignment or copy-contructing. This removes the reserved memory |
| 307 // from the original object. |
305 class VirtualMemory { | 308 class VirtualMemory { |
306 public: | 309 public: |
| 310 // Empty VirtualMemory object, controlling no reserved memory. |
| 311 VirtualMemory(); |
| 312 |
307 // Reserves virtual memory with size. | 313 // Reserves virtual memory with size. |
308 explicit VirtualMemory(size_t size); | 314 explicit VirtualMemory(size_t size); |
| 315 |
| 316 // Reserves virtual memory containing an area of the given size that |
| 317 // is aligned per alignment. This may not be at the position returned |
| 318 // by address(). |
| 319 VirtualMemory(size_t size, size_t alignment); |
| 320 |
| 321 // Releases the reserved memory, if any, controlled by this VirtualMemory |
| 322 // object. |
309 ~VirtualMemory(); | 323 ~VirtualMemory(); |
310 | 324 |
311 // Returns whether the memory has been reserved. | 325 // Returns whether the memory has been reserved. |
312 bool IsReserved(); | 326 bool IsReserved(); |
313 | 327 |
| 328 // Initialize or resets an embedded VirtualMemory object. |
| 329 void Reset(); |
| 330 |
314 // Returns the start address of the reserved memory. | 331 // Returns the start address of the reserved memory. |
| 332 // If the memory was reserved with an alignment, this address is not |
| 333 // necessarily aligned. The user might need to round it up to a multiple of |
| 334 // the alignment to get the start of the aligned block. |
315 void* address() { | 335 void* address() { |
316 ASSERT(IsReserved()); | 336 ASSERT(IsReserved()); |
317 return address_; | 337 return address_; |
318 } | 338 } |
319 | 339 |
320 // Returns the size of the reserved memory. | 340 // Returns the size of the reserved memory. The returned value is only |
| 341 // meaningful when IsReserved() returns true. |
| 342 // If the memory was reserved with an alignment, this size may be larger |
| 343 // than the requested size. |
321 size_t size() { return size_; } | 344 size_t size() { return size_; } |
322 | 345 |
323 // Commits real memory. Returns whether the operation succeeded. | 346 // Commits real memory. Returns whether the operation succeeded. |
324 bool Commit(void* address, size_t size, bool is_executable); | 347 bool Commit(void* address, size_t size, bool is_executable); |
325 | 348 |
326 // Uncommit real memory. Returns whether the operation succeeded. | 349 // Uncommit real memory. Returns whether the operation succeeded. |
327 bool Uncommit(void* address, size_t size); | 350 bool Uncommit(void* address, size_t size); |
328 | 351 |
| 352 void Release() { |
| 353 ASSERT(IsReserved()); |
| 354 // Notice: Order is somportant here. The VirtualMemory object might live |
| 355 // inside the allocated region. |
| 356 void* address = address_; |
| 357 size_t size = size_; |
| 358 Reset(); |
| 359 ReleaseRegion(address, size); |
| 360 } |
| 361 |
| 362 // Assign control of the reserved region to a different VirtualMemory object. |
| 363 // The old object is no longer functional (IsReserved() returns false). |
| 364 void TakeControl(VirtualMemory* from) { |
| 365 ASSERT(!IsReserved()); |
| 366 address_ = from->address_; |
| 367 size_ = from->size_; |
| 368 from->Reset(); |
| 369 } |
| 370 |
| 371 static void* ReserveRegion(size_t size); |
| 372 |
| 373 static bool CommitRegion(void* base, size_t size, bool is_executable); |
| 374 |
| 375 static bool UncommitRegion(void* base, size_t size); |
| 376 |
| 377 // Must be called with a base pointer that has been returned by ReserveRegion |
| 378 // and the same size it was reserved with. |
| 379 static bool ReleaseRegion(void* base, size_t size); |
| 380 |
329 private: | 381 private: |
330 void* address_; // Start address of the virtual memory. | 382 void* address_; // Start address of the virtual memory. |
331 size_t size_; // Size of the virtual memory. | 383 size_t size_; // Size of the virtual memory. |
332 }; | 384 }; |
333 | 385 |
| 386 |
334 // ---------------------------------------------------------------------------- | 387 // ---------------------------------------------------------------------------- |
335 // Thread | 388 // Thread |
336 // | 389 // |
337 // Thread objects are used for creating and running threads. When the start() | 390 // Thread objects are used for creating and running threads. When the start() |
338 // method is called the new thread starts running the run() method in the new | 391 // method is called the new thread starts running the run() method in the new |
339 // thread. The Thread object should not be deallocated before the thread has | 392 // thread. The Thread object should not be deallocated before the thread has |
340 // terminated. | 393 // terminated. |
341 | 394 |
342 class Thread { | 395 class Thread { |
343 public: | 396 public: |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 Atomic32 active_; | 679 Atomic32 active_; |
627 PlatformData* data_; // Platform specific data. | 680 PlatformData* data_; // Platform specific data. |
628 int samples_taken_; // Counts stack samples taken. | 681 int samples_taken_; // Counts stack samples taken. |
629 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); | 682 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); |
630 }; | 683 }; |
631 | 684 |
632 | 685 |
633 } } // namespace v8::internal | 686 } } // namespace v8::internal |
634 | 687 |
635 #endif // V8_PLATFORM_H_ | 688 #endif // V8_PLATFORM_H_ |
OLD | NEW |