- Changed regexp logging to include the string being matched and to
authorchristian.plesner.hansen@gmail.com <christian.plesner.hansen@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 22 Oct 2008 12:00:19 +0000 (12:00 +0000)
committerchristian.plesner.hansen@gmail.com <christian.plesner.hansen@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 22 Oct 2008 12:00:19 +0000 (12:00 +0000)
  escape commas.
- Fixed issue with block-comparing unaligned strings on arm.
- Added short documentation to one of the Persistent constructors.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@554 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

include/v8.h
src/d8.cc
src/globals.h
src/log.cc
src/log.h
src/objects.cc

index cedf88c500c1b0e924d9fa1785bab4d59266a248..c683fb91bdba59dd5ecdb825d23716dd9e52c401 100644 (file)
@@ -327,6 +327,10 @@ template <class T> class EXPORT_INLINE Persistent : public Handle<T> {
 
   template <class S> inline Persistent(S* that) : Handle<T>(that) { }
 
+  /**
+   * "Casts" a plain handle which is known to be a persistent handle
+   * to a persistent handle.
+   */
   template <class S> explicit inline Persistent(Handle<S> that)
       : Handle<T>(*that) { }
 
@@ -1056,7 +1060,7 @@ class EXPORT Object : public Value {
    * Turns on access check on the object if the object is an instance of
    * a template that has access check callbacks. If an object has no
    * access check info, the object cannot be accessed by anyone.
-   */ 
+   */
   void TurnOnAccessCheck();
 
   static Local<Object> New();
index e69e3d95201725de62bc581bc957bb6fd9ec7ab0..af6eb4cf2d968d89a05ebcdf4fc2c1a6d1527020 100644 (file)
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -237,11 +237,10 @@ void Shell::Initialize() {
 
   // Install the debugger object in the utility scope
   i::Debug::Load();
-  i::JSObject* raw_debug = i::Debug::debug_context()->global();
-  i::JSGlobalObject* debug = i::JSGlobalObject::cast(raw_debug);
-  debug->set_security_token(i::Heap::undefined_value());
+  i::Debug::debug_context()->set_security_token(i::Heap::undefined_value());
+  i::JSObject* debug = i::Debug::debug_context()->global();
   utility_context_->Global()->Set(String::New("$debug"),
-                                  Utils::ToLocal(&raw_debug));
+                                  Utils::ToLocal(&debug));
 
   // Run the d8 shell utility script in the utility context
   int source_index = i::NativesCollection<i::D8>::GetIndex("d8");
index a8e3d29f1a7863aa06ad8e9aef827e06dfed2507..cc0dbdedb44156634c7edad2feebcc2d80a1f007 100644 (file)
@@ -73,6 +73,9 @@ typedef byte* Address;
 typedef uint16_t uc16;
 typedef signed int uc32;
 
+#ifndef ARM
+#define CAN_READ_UNALIGNED 1
+#endif
 
 // -----------------------------------------------------------------------------
 // Constants
index 01ca6dd49b934ba6c010563b5da7541f56f26fb6..be76b96e1bdec0a1aadca616e9cadb7023923a7c 100644 (file)
@@ -349,6 +349,24 @@ void Logger::SharedLibraryEvent(const wchar_t* library_path,
 
 
 #ifdef ENABLE_LOGGING_AND_PROFILING
+void Logger::LogString(Handle<String> str) {
+  int len = str->length();
+  if (len > 256)
+    len = 256;
+  for (int i = 0; i < len; i++) {
+    uc32 c = str->Get(i);
+    if (c < 32 || (c > 126 && c <= 255)) {
+      fprintf(logfile_, "\\x%02x", c);
+    } else if (c > 255) {
+      fprintf(logfile_, "\\u%04x", c);
+    } else if (c == ',') {
+      fprintf(logfile_, "\\,");
+    } else {
+      fprintf(logfile_, "%lc", c);
+    }
+  }
+}
+
 void Logger::LogRegExpSource(Handle<JSRegExp> regexp) {
   // Prints "/" + re.source + "/" +
   //      (re.global?"g":"") + (re.ignorecase?"i":"") + (re.multiline?"m":"")
@@ -358,9 +376,7 @@ void Logger::LogRegExpSource(Handle<JSRegExp> regexp) {
     fprintf(logfile_, "no source");
     return;
   }
-  Handle<String> source_string = Handle<String>::cast(source);
 
-  SmartPointer<uc16> cstring = source_string->ToWideCString();
   if (regexp->type()->IsSmi()) {
     switch (regexp->type_tag()) {
     case JSRegExp::ATOM:
@@ -371,16 +387,7 @@ void Logger::LogRegExpSource(Handle<JSRegExp> regexp) {
     }
   }
   fprintf(logfile_, "/");
-  for (int i = 0, n = source_string->length(); i < n; i++) {
-    uc16 c = cstring[i];
-    if (c < 32 || (c > 126 && c <= 255)) {
-      fprintf(logfile_, "\\x%02x", c);
-    } else if (c > 255) {
-      fprintf(logfile_, "\\u%04x", c);
-    } else {
-      fprintf(logfile_, "%lc", c);
-    }
-  }
+  LogString(Handle<String>::cast(source));
   fprintf(logfile_, "/");
 
   // global flag
@@ -423,8 +430,9 @@ void Logger::RegExpExecEvent(Handle<JSRegExp> regexp,
 
   fprintf(logfile_, "regexp-run,");
   LogRegExpSource(regexp);
-  fprintf(logfile_, ",0x%08x,%d..%d\n",
-      input_string->Hash(), start_index, input_string->length());
+  fprintf(logfile_, ",");
+  LogString(input_string);
+  fprintf(logfile_, ",%d..%d\n", start_index, input_string->length());
 #endif
 }
 
index ef77117b480753f3e7b0c5a28cc82ff3172f99b9..69be1038fdbf30e6a7b92005512efa33ae78e66d 100644 (file)
--- a/src/log.h
+++ b/src/log.h
@@ -199,6 +199,8 @@ class Logger {
   // Emits the source code of a regexp. Used by regexp events.
   static void LogRegExpSource(Handle<JSRegExp> regexp);
 
+  static void LogString(Handle<String> str);
+
   // Emits a profiler tick event. Used by the profiler thread.
   static void TickEvent(TickSample* sample, bool overflow);
 
index 30b724aa0d4d962f0aadc008613e8c10648d8b41..1d7d1256ffad645cd1ac5d8d2ea8f7ae4f1b8289 100644 (file)
@@ -3727,6 +3727,19 @@ static inline bool CompareRawStringContents(Vector<Char> a, Vector<Char> b) {
   int endpoint = length - kStepSize;
   const Char* pa = a.start();
   const Char* pb = b.start();
+#ifndef CAN_READ_UNALIGNED
+  // If this architecture isn't comfortable reading unaligned ints
+  // then we have to check that the strings are alingned and fall back
+  // to the standard comparison if they are not.
+  const int kAlignmentMask = sizeof(uint32_t) - 1;  // NOLINT
+  uint32_t pa_addr = reinterpret_cast<uint32_t>(pa);
+  uint32_t pb_addr = reinterpret_cast<uint32_t>(pb);
+  if ((pa_addr & kAlignmentMask) | (pb_addr & kAlignmentMask) != 0) {
+    VectorIterator<Char> ia(a);
+    VectorIterator<Char> ib(b);
+    return CompareStringContents(&ia, &ib);
+  }
+#endif
   int i;
   // Compare blocks until we reach near the end of the string.
   for (i = 0; i <= endpoint; i += kStepSize) {