Moved the storage of the last script id into the heap to make it part of the serializ...
authorsgjesse@chromium.org <sgjesse@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 10 Mar 2009 12:05:20 +0000 (12:05 +0000)
committersgjesse@chromium.org <sgjesse@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 10 Mar 2009 12:05:20 +0000 (12:05 +0000)
Currently the script ids wrap when positive smi value is exhausted.
Review URL: http://codereview.chromium.org/43008

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

src/factory.cc
src/heap-inl.h
src/heap.cc
src/heap.h
test/mjsunit/debug-setbreakpoint.js

index a9cdd43..cf0ec43 100644 (file)
@@ -153,17 +153,32 @@ Handle<AccessorInfo> Factory::NewAccessorInfo() {
 
 
 Handle<Script> Factory::NewScript(Handle<String> source) {
-  static uint32_t next_id = 1;
-
+  // Generate id for this script.
+  int id;
+  if (Heap::last_script_id()->IsUndefined()) {
+    // Script ids start from one.
+    id = 1;
+  } else {
+    // Increment id, wrap when positive smi is exhausted.
+    id = Smi::cast(Heap::last_script_id())->value();
+    id++;
+    if (!Smi::IsValid(id)) {
+      id = 0;
+    }
+  }
+  Heap::SetLastScriptId(Smi::FromInt(id));
+  
+  // Create and initialize script object.
   Handle<Script> script = Handle<Script>::cast(NewStruct(SCRIPT_TYPE));
   script->set_source(*source);
   script->set_name(Heap::undefined_value());
-  script->set_id(*Factory::NewNumberFromUint(next_id++));
+  script->set_id(Heap::last_script_id());
   script->set_line_offset(Smi::FromInt(0));
   script->set_column_offset(Smi::FromInt(0));
   script->set_type(Smi::FromInt(SCRIPT_TYPE_NORMAL));
   script->set_wrapper(*Factory::NewProxy(0, TENURED));
   script->set_line_ends(Heap::undefined_value());
+
   return script;
 }
 
index b75d93b..6090dd4 100644 (file)
@@ -211,6 +211,11 @@ void Heap::ClearKeyedLookupCache() {
 }
 
 
+void Heap::SetLastScriptId(Object* last_script_id) {
+  last_script_id_ = last_script_id;
+}
+
+
 #define GC_GREEDY_CHECK() \
   ASSERT(!FLAG_gc_greedy || v8::internal::Heap::GarbageCollectionGreedyCheck())
 
index 3a6f301..8159311 100644 (file)
@@ -1238,6 +1238,9 @@ bool Heap::CreateInitialObjects() {
   if (obj->IsFailure()) return false;
   natives_source_cache_ = FixedArray::cast(obj);
 
+  // Handling of script id generation is in Factory::NewScript.
+  last_script_id_ = undefined_value();
+
   // Initialize keyed lookup cache.
   ClearKeyedLookupCache();
 
index 576af6e..6fb28db 100644 (file)
@@ -123,7 +123,8 @@ namespace v8 { namespace internal {
   V(FixedArray, number_string_cache)                    \
   V(FixedArray, single_character_string_cache)          \
   V(FixedArray, natives_source_cache)                   \
-  V(Object, keyed_lookup_cache)
+  V(Object, keyed_lookup_cache)                         \
+  V(Object, last_script_id)
 
 
 #define ROOT_LIST(V)                                  \
@@ -690,6 +691,9 @@ class Heap : public AllStatic {
   static inline void SetKeyedLookupCache(LookupCache* cache);
   static inline void ClearKeyedLookupCache();
 
+  // Update the next script id.
+  static inline void SetLastScriptId(Object* last_script_id);
+
 #ifdef DEBUG
   static void Print();
   static void PrintHandles();
index 329362b..904ec18 100644 (file)
@@ -59,7 +59,6 @@ function testArguments(dcp, arguments, success, is_script) {
       assertEquals('scriptName', response.body.type, json_response);
     } else {
       assertEquals('scriptId', response.body.type, json_response);
-      print(response.body.script_id);
     }
   } else {
     assertFalse(response.success, json_response);