Changed all text files to have native svn:eol-style.

Added a few samples and support for building them. The samples include a simple shell that can be used to benchmark and test V8.

Changed V8::GetVersion to return the version as a string.

Added source for lazily loaded scripts to snapshots and made serialization non-destructive.

Improved ARM support by fixing the write barrier code to use aligned loads and stores and by removing premature locals optimization that relied on broken support for callee-saved registers (removed).

Refactored the code for marking live objects during garbage collection and the code for allocating objects in paged spaces. Introduced an abstraction for the map word of a heap-allocated object and changed the memory allocator to allocate executable memory only for spaces that may contain code objects.

Moved StringBuilder to utils.h and ScopedLock to platform.h, where they can be used by debugging and logging modules. Added thread-safe message queues for dealing with debugger events.

Fixed the source code reported by toString for certain builtin empty functions and made sure that the prototype property of a function is enumerable.

Improved performance of converting values to condition flags in generated code.

Merged disassembler-{arch} files.


git-svn-id: http://v8.googlecode.com/svn/trunk@8 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
diff --git a/src/platform-linux.cc b/src/platform-linux.cc
index 68ceae0..b25891a 100644
--- a/src/platform-linux.cc
+++ b/src/platform-linux.cc
@@ -108,18 +108,16 @@
 double OS::DaylightSavingsOffset(double time) {
   time_t tv = static_cast<time_t>(floor(time/msPerSecond));
   struct tm* t = localtime(&tv);
-  return t->tm_isdst ? 3600 * msPerSecond : 0;
+  return t->tm_isdst > 0 ? 3600 * msPerSecond : 0;
 }
 
 
 double OS::LocalTimeOffset() {
-  // 1199174400 = Jan 1 2008 (UTC).
-  // Random date where daylight savings time is not in effect.
-  static const int kJan1st2008 = 1199174400;
-  time_t tv = static_cast<time_t>(kJan1st2008);
+  time_t tv = time(NULL);
   struct tm* t = localtime(&tv);
-  ASSERT(t->tm_isdst <= 0);
-  return static_cast<double>(t->tm_gmtoff * msPerSecond);
+  // tm_gmtoff includes any daylight savings offset, so subtract it.
+  return static_cast<double>(t->tm_gmtoff * msPerSecond -
+                             (t->tm_isdst > 0 ? 3600 * msPerSecond : 0));
 }
 
 
@@ -159,7 +157,13 @@
 
 
 int OS::VSNPrintF(char* str, size_t size, const char* format, va_list args) {
-  return vsnprintf(str, size, format, args);  // forward to linux.
+  int n = vsnprintf(str, size, format, args);  // forward to linux.
+  if (n < 0 || static_cast<size_t>(n) >= size) {
+    str[size - 1] = '\0';
+    return -1;
+  } else {
+    return n;
+  }
 }
 
 
@@ -192,10 +196,12 @@
 }
 
 
-void* OS::Allocate(const size_t requested, size_t* allocated) {
+void* OS::Allocate(const size_t requested,
+                   size_t* allocated,
+                   bool executable) {
   const size_t msize = RoundUp(requested, getpagesize());
-  void* mbase = mmap(NULL, msize, PROT_READ | PROT_WRITE | PROT_EXEC,
-                     MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+  int prot = PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0);
+  void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
   if (mbase == MAP_FAILED) {
     LOG(StringEvent("OS::Allocate", "mmap failed"));
     return NULL;
@@ -224,6 +230,15 @@
 }
 
 
+void OS::DebugBreak() {
+#if defined (__arm__) || defined(__thumb__)
+  asm("bkpt 0");
+#else
+  asm("int $3");
+#endif
+}
+
+
 class PosixMemoryMappedFile : public OS::MemoryMappedFile {
  public:
   PosixMemoryMappedFile(FILE* file, void* memory, int size)
@@ -351,8 +366,9 @@
 }
 
 
-bool VirtualMemory::Commit(void* address, size_t size) {
-  if (MAP_FAILED == mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC,
+bool VirtualMemory::Commit(void* address, size_t size, bool executable) {
+  int prot = PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0);
+  if (MAP_FAILED == mmap(address, size, prot,
                          MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
                          kMmapFd, kMmapFdOffset)) {
     return false;
@@ -516,40 +532,24 @@
   explicit LinuxSemaphore(int count) {  sem_init(&sem_, 0, count); }
   virtual ~LinuxSemaphore() { sem_destroy(&sem_); }
 
-  virtual void Wait() { sem_wait(&sem_); }
-
+  virtual void Wait();
   virtual void Signal() { sem_post(&sem_); }
-
  private:
   sem_t sem_;
 };
 
+void LinuxSemaphore::Wait() {
+  while (true) {
+    int result = sem_wait(&sem_);
+    if (result == 0) return;  // Successfully got semaphore.
+    CHECK(result == -1 && errno == EINTR);  // Signal caused spurious wakeup.
+  }
+}
 
 Semaphore* OS::CreateSemaphore(int count) {
   return new LinuxSemaphore(count);
 }
 
-// TODO(1233584): Implement Linux support.
-Select::Select(int len, Semaphore** sems) {
-  FATAL("Not implemented");
-}
-
-
-Select::~Select() {
-  FATAL("Not implemented");
-}
-
-
-int Select::WaitSingle() {
-  FATAL("Not implemented");
-  return 0;
-}
-
-
-void Select::WaitAll() {
-  FATAL("Not implemented");
-}
-
 #ifdef ENABLE_LOGGING_AND_PROFILING
 
 static ProfileSampler* active_sampler_ = NULL;