| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 81 |
| 82 | 82 |
| 83 double ceiling(double x) { | 83 double ceiling(double x) { |
| 84 return ceil(x); | 84 return ceil(x); |
| 85 } | 85 } |
| 86 | 86 |
| 87 | 87 |
| 88 static Mutex* limit_mutex = NULL; | 88 static Mutex* limit_mutex = NULL; |
| 89 | 89 |
| 90 | 90 |
| 91 void OS::PostSetUp() { | |
| 92 POSIXPostSetUp(); | |
| 93 } | |
| 94 | |
| 95 | |
| 96 uint64_t OS::CpuFeaturesImpliedByPlatform() { | 91 uint64_t OS::CpuFeaturesImpliedByPlatform() { |
| 97 return 0; // Linux runs on anything. | 92 return 0; // Linux runs on anything. |
| 98 } | 93 } |
| 99 | 94 |
| 100 | 95 |
| 101 #ifdef __arm__ | 96 #ifdef __arm__ |
| 102 static bool CPUInfoContainsString(const char * search_string) { | 97 static bool CPUInfoContainsString(const char * search_string) { |
| 103 const char* file_name = "/proc/cpuinfo"; | 98 const char* file_name = "/proc/cpuinfo"; |
| 104 // This is written as a straight shot one pass parser | 99 // This is written as a straight shot one pass parser |
| 105 // and not using STL string and ifstream because, | 100 // and not using STL string and ifstream because, |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 Max(highest_ever_allocated, | 372 Max(highest_ever_allocated, |
| 378 reinterpret_cast<void*>(reinterpret_cast<char*>(address) + size)); | 373 reinterpret_cast<void*>(reinterpret_cast<char*>(address) + size)); |
| 379 } | 374 } |
| 380 | 375 |
| 381 | 376 |
| 382 bool OS::IsOutsideAllocatedSpace(void* address) { | 377 bool OS::IsOutsideAllocatedSpace(void* address) { |
| 383 return address < lowest_ever_allocated || address >= highest_ever_allocated; | 378 return address < lowest_ever_allocated || address >= highest_ever_allocated; |
| 384 } | 379 } |
| 385 | 380 |
| 386 | 381 |
| 387 size_t OS::AllocateAlignment() { | |
| 388 return sysconf(_SC_PAGESIZE); | |
| 389 } | |
| 390 | |
| 391 | |
| 392 void* OS::Allocate(const size_t requested, | 382 void* OS::Allocate(const size_t requested, |
| 393 size_t* allocated, | 383 size_t* allocated, |
| 394 bool is_executable) { | 384 bool is_executable) { |
| 395 const size_t msize = RoundUp(requested, AllocateAlignment()); | 385 const size_t msize = RoundUp(requested, AllocateAlignment()); |
| 396 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); | 386 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); |
| 397 void* addr = OS::GetRandomMmapAddr(); | 387 void* addr = OS::GetRandomMmapAddr(); |
| 398 void* mbase = mmap(addr, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | 388 void* mbase = mmap(addr, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
| 399 if (mbase == MAP_FAILED) { | 389 if (mbase == MAP_FAILED) { |
| 400 LOG(i::Isolate::Current(), | 390 LOG(i::Isolate::Current(), |
| 401 StringEvent("OS::Allocate", "mmap failed")); | 391 StringEvent("OS::Allocate", "mmap failed")); |
| 402 return NULL; | 392 return NULL; |
| 403 } | 393 } |
| 404 *allocated = msize; | 394 *allocated = msize; |
| 405 UpdateAllocatedSpaceLimits(mbase, msize); | 395 UpdateAllocatedSpaceLimits(mbase, msize); |
| 406 return mbase; | 396 return mbase; |
| 407 } | 397 } |
| 408 | 398 |
| 409 | 399 |
| 410 void OS::Free(void* address, const size_t size) { | |
| 411 // TODO(1240712): munmap has a return value which is ignored here. | |
| 412 int result = munmap(address, size); | |
| 413 USE(result); | |
| 414 ASSERT(result == 0); | |
| 415 } | |
| 416 | |
| 417 | |
| 418 void OS::Sleep(int milliseconds) { | |
| 419 unsigned int ms = static_cast<unsigned int>(milliseconds); | |
| 420 usleep(1000 * ms); | |
| 421 } | |
| 422 | |
| 423 | |
| 424 int OS::NumberOfCores() { | |
| 425 return sysconf(_SC_NPROCESSORS_ONLN); | |
| 426 } | |
| 427 | |
| 428 | |
| 429 void OS::Abort() { | |
| 430 // Redirect to std abort to signal abnormal program termination. | |
| 431 if (FLAG_break_on_abort) { | |
| 432 DebugBreak(); | |
| 433 } | |
| 434 abort(); | |
| 435 } | |
| 436 | |
| 437 | |
| 438 void OS::DebugBreak() { | |
| 439 // TODO(lrn): Introduce processor define for runtime system (!= V8_ARCH_x, | |
| 440 // which is the architecture of generated code). | |
| 441 #if (defined(__arm__) || defined(__thumb__)) | |
| 442 asm("bkpt 0"); | |
| 443 #elif defined(__mips__) | |
| 444 asm("break"); | |
| 445 #elif defined(__native_client__) | |
| 446 asm("hlt"); | |
| 447 #else | |
| 448 asm("int $3"); | |
| 449 #endif | |
| 450 } | |
| 451 | |
| 452 | |
| 453 void OS::DumpBacktrace() { | 400 void OS::DumpBacktrace() { |
| 454 // backtrace is a glibc extension. | 401 // backtrace is a glibc extension. |
| 455 #if defined(__GLIBC__) && !defined(__UCLIBC__) | 402 #if defined(__GLIBC__) && !defined(__UCLIBC__) |
| 456 POSIXBacktraceHelper<backtrace, backtrace_symbols>::DumpBacktrace(); | 403 POSIXBacktraceHelper<backtrace, backtrace_symbols>::DumpBacktrace(); |
| 457 #endif | 404 #endif |
| 458 } | 405 } |
| 459 | 406 |
| 460 | 407 |
| 461 class PosixMemoryMappedFile : public OS::MemoryMappedFile { | 408 class PosixMemoryMappedFile : public OS::MemoryMappedFile { |
| 462 public: | 409 public: |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 limit_mutex = CreateMutex(); | 883 limit_mutex = CreateMutex(); |
| 937 } | 884 } |
| 938 | 885 |
| 939 | 886 |
| 940 void OS::TearDown() { | 887 void OS::TearDown() { |
| 941 delete limit_mutex; | 888 delete limit_mutex; |
| 942 } | 889 } |
| 943 | 890 |
| 944 | 891 |
| 945 } } // namespace v8::internal | 892 } } // namespace v8::internal |
| OLD | NEW |