| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 // Print output to a file. This is mostly used for debugging output. | 212 // Print output to a file. This is mostly used for debugging output. |
| 213 static void FPrint(FILE* out, const char* format, ...); | 213 static void FPrint(FILE* out, const char* format, ...); |
| 214 static void VFPrint(FILE* out, const char* format, va_list args); | 214 static void VFPrint(FILE* out, const char* format, va_list args); |
| 215 | 215 |
| 216 // Print error output to console. This is mostly used for error message | 216 // Print error output to console. This is mostly used for error message |
| 217 // output. On platforms that has standard terminal output, the output | 217 // output. On platforms that has standard terminal output, the output |
| 218 // should go to stderr. | 218 // should go to stderr. |
| 219 static void PrintError(const char* format, ...); | 219 static void PrintError(const char* format, ...); |
| 220 static void VPrintError(const char* format, va_list args); | 220 static void VPrintError(const char* format, va_list args); |
| 221 | 221 |
| 222 // Allocate/Free memory used by JS heap. Pages are readable/writable, but | |
| 223 // they are not guaranteed to be executable unless 'executable' is true. | |
| 224 // Returns the address of allocated memory, or NULL if failed. | |
| 225 static void* Allocate(const size_t requested, | |
| 226 size_t* allocated, | |
| 227 bool is_executable); | |
| 228 static void Free(void* address, const size_t size); | |
| 229 | |
| 230 // This is the granularity at which the ProtectCode(...) call can set page | |
| 231 // permissions. | |
| 232 static intptr_t CommitPageSize(); | |
| 233 | |
| 234 // Mark code segments non-writable. | |
| 235 static void ProtectCode(void* address, const size_t size); | |
| 236 | |
| 237 // Assign memory as a guard page so that access will cause an exception. | |
| 238 static void Guard(void* address, const size_t size); | |
| 239 | |
| 240 // Generate a random address to be used for hinting mmap(). | |
| 241 static void* GetRandomMmapAddr(); | |
| 242 | |
| 243 // Get the Alignment guaranteed by Allocate(). | |
| 244 static size_t AllocateAlignment(); | |
| 245 | |
| 246 // Sleep for a number of milliseconds. | 222 // Sleep for a number of milliseconds. |
| 247 static void Sleep(const int milliseconds); | 223 static void Sleep(const int milliseconds); |
| 248 | 224 |
| 249 // Abort the current process. | 225 // Abort the current process. |
| 250 static void Abort(); | 226 static void Abort(); |
| 251 | 227 |
| 252 // Debug break. | 228 // Debug break. |
| 253 static void DebugBreak(); | 229 static void DebugBreak(); |
| 254 | 230 |
| 255 // Dump C++ current stack trace (only functional on Linux). | 231 // Dump C++ current stack trace (only functional on Linux). |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 static void SignalCodeMovingGC(); | 272 static void SignalCodeMovingGC(); |
| 297 | 273 |
| 298 // The return value indicates the CPU features we are sure of because of the | 274 // The return value indicates the CPU features we are sure of because of the |
| 299 // OS. For example MacOSX doesn't run on any x86 CPUs that don't have SSE2 | 275 // OS. For example MacOSX doesn't run on any x86 CPUs that don't have SSE2 |
| 300 // instructions. | 276 // instructions. |
| 301 // This is a little messy because the interpretation is subject to the cross | 277 // This is a little messy because the interpretation is subject to the cross |
| 302 // of the CPU and the OS. The bits in the answer correspond to the bit | 278 // of the CPU and the OS. The bits in the answer correspond to the bit |
| 303 // positions indicated by the members of the CpuFeature enum from globals.h | 279 // positions indicated by the members of the CpuFeature enum from globals.h |
| 304 static uint64_t CpuFeaturesImpliedByPlatform(); | 280 static uint64_t CpuFeaturesImpliedByPlatform(); |
| 305 | 281 |
| 306 // Maximum size of the virtual memory. 0 means there is no artificial | |
| 307 // limit. | |
| 308 static intptr_t MaxVirtualMemory(); | |
| 309 | |
| 310 // Returns the double constant NAN | 282 // Returns the double constant NAN |
| 311 static double nan_value(); | 283 static double nan_value(); |
| 312 | 284 |
| 313 // Support runtime detection of whether the hard float option of the | 285 // Support runtime detection of whether the hard float option of the |
| 314 // EABI is used. | 286 // EABI is used. |
| 315 static bool ArmUsingHardFloat(); | 287 static bool ArmUsingHardFloat(); |
| 316 | 288 |
| 317 // Returns the activation frame alignment constraint or zero if | 289 // Returns the activation frame alignment constraint or zero if |
| 318 // the platform doesn't care. Guaranteed to be a power of two. | 290 // the platform doesn't care. Guaranteed to be a power of two. |
| 319 static int ActivationFrameAlignment(); | 291 static int ActivationFrameAlignment(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 #endif // V8_TARGET_ARCH_IA32 | 351 #endif // V8_TARGET_ARCH_IA32 |
| 380 | 352 |
| 381 static int GetCurrentProcessId(); | 353 static int GetCurrentProcessId(); |
| 382 | 354 |
| 383 private: | 355 private: |
| 384 static const int msPerSecond = 1000; | 356 static const int msPerSecond = 1000; |
| 385 | 357 |
| 386 DISALLOW_IMPLICIT_CONSTRUCTORS(OS); | 358 DISALLOW_IMPLICIT_CONSTRUCTORS(OS); |
| 387 }; | 359 }; |
| 388 | 360 |
| 389 // Represents and controls an area of reserved memory. | |
| 390 // Control of the reserved memory can be assigned to another VirtualMemory | |
| 391 // object by assignment or copy-contructing. This removes the reserved memory | |
| 392 // from the original object. | |
| 393 class VirtualMemory { | |
| 394 public: | |
| 395 // Empty VirtualMemory object, controlling no reserved memory. | |
| 396 VirtualMemory(); | |
| 397 | |
| 398 // Reserves virtual memory with size. | |
| 399 explicit VirtualMemory(size_t size); | |
| 400 | |
| 401 // Reserves virtual memory containing an area of the given size that | |
| 402 // is aligned per alignment. This may not be at the position returned | |
| 403 // by address(). | |
| 404 VirtualMemory(size_t size, size_t alignment); | |
| 405 | |
| 406 // Releases the reserved memory, if any, controlled by this VirtualMemory | |
| 407 // object. | |
| 408 ~VirtualMemory(); | |
| 409 | |
| 410 // Returns whether the memory has been reserved. | |
| 411 bool IsReserved(); | |
| 412 | |
| 413 // Initialize or resets an embedded VirtualMemory object. | |
| 414 void Reset(); | |
| 415 | |
| 416 // Returns the start address of the reserved memory. | |
| 417 // If the memory was reserved with an alignment, this address is not | |
| 418 // necessarily aligned. The user might need to round it up to a multiple of | |
| 419 // the alignment to get the start of the aligned block. | |
| 420 void* address() { | |
| 421 ASSERT(IsReserved()); | |
| 422 return address_; | |
| 423 } | |
| 424 | |
| 425 // Returns the size of the reserved memory. The returned value is only | |
| 426 // meaningful when IsReserved() returns true. | |
| 427 // If the memory was reserved with an alignment, this size may be larger | |
| 428 // than the requested size. | |
| 429 size_t size() { return size_; } | |
| 430 | |
| 431 // Commits real memory. Returns whether the operation succeeded. | |
| 432 bool Commit(void* address, size_t size, bool is_executable); | |
| 433 | |
| 434 // Uncommit real memory. Returns whether the operation succeeded. | |
| 435 bool Uncommit(void* address, size_t size); | |
| 436 | |
| 437 // Creates a single guard page at the given address. | |
| 438 bool Guard(void* address); | |
| 439 | |
| 440 void Release() { | |
| 441 ASSERT(IsReserved()); | |
| 442 // Notice: Order is important here. The VirtualMemory object might live | |
| 443 // inside the allocated region. | |
| 444 void* address = address_; | |
| 445 size_t size = size_; | |
| 446 Reset(); | |
| 447 bool result = ReleaseRegion(address, size); | |
| 448 USE(result); | |
| 449 ASSERT(result); | |
| 450 } | |
| 451 | |
| 452 // Assign control of the reserved region to a different VirtualMemory object. | |
| 453 // The old object is no longer functional (IsReserved() returns false). | |
| 454 void TakeControl(VirtualMemory* from) { | |
| 455 ASSERT(!IsReserved()); | |
| 456 address_ = from->address_; | |
| 457 size_ = from->size_; | |
| 458 from->Reset(); | |
| 459 } | |
| 460 | |
| 461 static void* ReserveRegion(size_t size); | |
| 462 | |
| 463 static bool CommitRegion(void* base, size_t size, bool is_executable); | |
| 464 | |
| 465 static bool UncommitRegion(void* base, size_t size); | |
| 466 | |
| 467 // Must be called with a base pointer that has been returned by ReserveRegion | |
| 468 // and the same size it was reserved with. | |
| 469 static bool ReleaseRegion(void* base, size_t size); | |
| 470 | |
| 471 // Returns true if OS performs lazy commits, i.e. the memory allocation call | |
| 472 // defers actual physical memory allocation till the first memory access. | |
| 473 // Otherwise returns false. | |
| 474 static bool HasLazyCommits(); | |
| 475 | |
| 476 private: | |
| 477 void* address_; // Start address of the virtual memory. | |
| 478 size_t size_; // Size of the virtual memory. | |
| 479 }; | |
| 480 | |
| 481 | |
| 482 // ---------------------------------------------------------------------------- | 361 // ---------------------------------------------------------------------------- |
| 483 // Thread | 362 // Thread |
| 484 // | 363 // |
| 485 // Thread objects are used for creating and running threads. When the start() | 364 // Thread objects are used for creating and running threads. When the start() |
| 486 // method is called the new thread starts running the run() method in the new | 365 // method is called the new thread starts running the run() method in the new |
| 487 // thread. The Thread object should not be deallocated before the thread has | 366 // thread. The Thread object should not be deallocated before the thread has |
| 488 // terminated. | 367 // terminated. |
| 489 | 368 |
| 490 class Thread { | 369 class Thread { |
| 491 public: | 370 public: |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 char name_[kMaxThreadNameLength]; | 469 char name_[kMaxThreadNameLength]; |
| 591 int stack_size_; | 470 int stack_size_; |
| 592 Semaphore* start_semaphore_; | 471 Semaphore* start_semaphore_; |
| 593 | 472 |
| 594 DISALLOW_COPY_AND_ASSIGN(Thread); | 473 DISALLOW_COPY_AND_ASSIGN(Thread); |
| 595 }; | 474 }; |
| 596 | 475 |
| 597 } } // namespace v8::internal | 476 } } // namespace v8::internal |
| 598 | 477 |
| 599 #endif // V8_PLATFORM_H_ | 478 #endif // V8_PLATFORM_H_ |
| OLD | NEW |