Generalized the EvalCache into a CompilationCache and enabled it for scripts too.  The current strategy is to retire all entries whenever a mark-sweep collection is started.

Fixed bug where switch statements containing only a default case would lead to an unbalanced stack (issue 69).

Fixed bug that made access to the function in a named function expression impossible in certain situations (issue 24).

Fixed even more build issues.

Optimized calling conventions on ARM.  The conventions on ARM and IA-32 now match.

Removed static initializers for flags and counters.

Improved inline caching behavior for uncommon cases where lazily loading Date and RegExp code could force certain code paths go megamorphic.

Removed arguments adaption for builtins written in C++.  This makes Array.prototype.push and Array.prototype.pop slightly faster.


git-svn-id: http://v8.googlecode.com/svn/trunk@329 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
diff --git a/src/platform-win32.cc b/src/platform-win32.cc
index 6035465..747f0a4 100644
--- a/src/platform-win32.cc
+++ b/src/platform-win32.cc
@@ -156,14 +156,14 @@
 // Case-insensitive string comparisons. Use stricmp() on Win32. Usually defined
 // in strings.h.
 int strcasecmp(const char* s1, const char* s2) {
-  return stricmp(s1, s2);
+  return _stricmp(s1, s2);
 }
 
 
 // Case-insensitive bounded string comparisons. Use stricmp() on Win32. Usually
 // defined in strings.h.
 int strncasecmp(const char* s1, const char* s2, int n) {
-  return strnicmp(s1, s2, n);
+  return _strnicmp(s1, s2, n);
 }
 
 namespace v8 { namespace internal {
@@ -341,9 +341,13 @@
   }
 
   // Make standard and DST timezone names.
-  _snprintf(std_tz_name_, kTzNameSize, "%S", tzinfo_.StandardName);
+  OS::SNPrintF(Vector<char>(std_tz_name_, kTzNameSize),
+               "%S",
+               tzinfo_.StandardName);
   std_tz_name_[kTzNameSize - 1] = '\0';
-  _snprintf(dst_tz_name_, kTzNameSize, "%S", tzinfo_.DaylightName);
+  OS::SNPrintF(Vector<char>(dst_tz_name_, kTzNameSize),
+               "%S",
+               tzinfo_.DaylightName);
   dst_tz_name_[kTzNameSize - 1] = '\0';
 
   // If OS returned empty string or resource id (like "@tzres.dll,-211")
@@ -351,12 +355,14 @@
   // To properly resolve the resource identifier requires a library load,
   // which is not possible in a sandbox.
   if (std_tz_name_[0] == '\0' || std_tz_name_[0] == '@') {
-    _snprintf(std_tz_name_, kTzNameSize - 1, "%s Standard Time",
-              GuessTimezoneNameFromBias(tzinfo_.Bias));
+    OS::SNPrintF(Vector<char>(std_tz_name_, kTzNameSize - 1),
+                 "%s Standard Time",
+                 GuessTimezoneNameFromBias(tzinfo_.Bias));
   }
   if (dst_tz_name_[0] == '\0' || dst_tz_name_[0] == '@') {
-    _snprintf(dst_tz_name_, kTzNameSize - 1, "%s Daylight Time",
-              GuessTimezoneNameFromBias(tzinfo_.Bias));
+    OS::SNPrintF(Vector<char>(dst_tz_name_, kTzNameSize - 1),
+                 "%s Daylight Time",
+                 GuessTimezoneNameFromBias(tzinfo_.Bias));
   }
 
   // Timezone information initialized.
@@ -607,10 +613,19 @@
     // It is important to use safe print here in order to avoid
     // overflowing the buffer. We might truncate the output, but this
     // does not crash.
-    static const int kBufferSize = 4096;
-    char buffer[kBufferSize];
-    OS::VSNPrintF(buffer, kBufferSize, format, args);
-    OutputDebugStringA(buffer);
+    EmbeddedVector<char, 4096> buffer;
+    OS::VSNPrintF(buffer, format, args);
+    OutputDebugStringA(buffer.start());
+  }
+}
+
+
+FILE* OS::FOpen(const char* path, const char* mode) {
+  FILE* result;
+  if (fopen_s(&result, path, mode) == 0) {
+    return result;
+  } else {
+    return NULL;
   }
 }
 
@@ -643,24 +658,21 @@
 }
 
 
-int OS::SNPrintF(char* str, size_t size, const char* format, ...) {
+int OS::SNPrintF(Vector<char> str, const char* format, ...) {
   va_list args;
   va_start(args, format);
-  int result = VSNPrintF(str, size, format, args);
+  int result = VSNPrintF(str, format, args);
   va_end(args);
   return result;
 }
 
 
-int OS::VSNPrintF(char* str, size_t size, const char* format, va_list args) {
-  // Print formated output to string. The _vsnprintf function has been
-  // deprecated in MSVC. We need to define _CRT_NONSTDC_NO_DEPRECATE
-  // during compilation to use it anyway. Usually defined in stdio.h.
-  int n = _vsnprintf(str, size, format, args);
+int OS::VSNPrintF(Vector<char> str, const char* format, va_list args) {
+  int n = _vsnprintf_s(str.start(), str.length(), _TRUNCATE, format, args);
   // Make sure to zero-terminate the string if the output was
   // truncated or if there was an error.
-  if (n < 0 || static_cast<size_t>(n) >= size) {
-    str[size - 1] = '\0';
+  if (n < 0 || n >= str.length()) {
+    str[str.length() - 1] = '\0';
     return -1;
   } else {
     return n;
@@ -668,6 +680,25 @@
 }
 
 
+void OS::StrNCpy(Vector<char> dest, const char* src, size_t n) {
+  int result = strncpy_s(dest.start(), dest.length(), src, n);
+  USE(result);
+  ASSERT(result == 0);
+}
+
+
+void OS::WcsCpy(Vector<wchar_t> dest, const wchar_t* src) {
+  int result = wcscpy_s(dest.start(), dest.length(), src);
+  USE(result);
+  ASSERT(result == 0);
+}
+
+
+char *OS::StrDup(const char* str) {
+  return _strdup(str);
+}
+
+
 // We keep the lowest and highest addresses mapped as a quick way of
 // determining that pointers are outside the heap (used mostly in assertions
 // and verification).  The estimate is conservative, ie, not all addresses in
@@ -1132,11 +1163,15 @@
       // Format a text representation of the frame based on the information
       // available.
       if (ok) {
-        SNPrintF(frames[frames_count].text, kStackWalkMaxTextLen, "%s %s:%d:%d",
+        SNPrintF(MutableCStrVector(frames[frames_count].text,
+                                   kStackWalkMaxTextLen),
+                 "%s %s:%d:%d",
                  symbol->Name, Line.FileName, Line.LineNumber,
                  line_displacement);
       } else {
-        SNPrintF(frames[frames_count].text, kStackWalkMaxTextLen, "%s",
+        SNPrintF(MutableCStrVector(frames[frames_count].text,
+                                   kStackWalkMaxTextLen),
+                 "%s",
                  symbol->Name);
       }
       // Make sure line termination is in place.