[v8-dev] [v8] r15327 committed - CPUProfiler: It is not clear why we are using Handle for scrip...

Tue, 25 Jun 2013 07:59:14 -0700

Revision: 15327
Author:   [email protected]
Date:     Tue Jun 25 07:57:47 2013
Log: CPUProfiler: It is not clear why we are using Handle<Object> for scriptId. Lets flip it into Smi/int.

By the nature it is integer. So we can work with it as with Smi internaly and use int in the external API.

BUG=none
TEST=existing tests
[email protected]

Review URL: https://codereview.chromium.org/17600006
http://code.google.com/p/v8/source/detail?r=15327

Modified:
 /branches/bleeding_edge/include/v8.h
 /branches/bleeding_edge/src/api.cc
 /branches/bleeding_edge/src/debug.cc
 /branches/bleeding_edge/src/factory.cc
 /branches/bleeding_edge/src/heap-inl.h
 /branches/bleeding_edge/src/heap.cc
 /branches/bleeding_edge/src/heap.h
 /branches/bleeding_edge/src/objects-inl.h
 /branches/bleeding_edge/src/objects.h

=======================================
--- /branches/bleeding_edge/include/v8.h        Tue Jun 25 01:11:50 2013
+++ /branches/bleeding_edge/include/v8.h        Tue Jun 25 07:57:47 2013
@@ -1043,9 +1043,15 @@

   /**
    * Returns the script id value.
+   * DEPRECATED: Please use GetId().
    */
   Local<Value> Id();

+  /**
+   * Returns the script id.
+   */
+  int GetId();
+
   /**
* Associate an additional data object with the script. This is mainly used
    * with the debugger as this data object is only available through the
@@ -1063,6 +1069,8 @@
    * -1 will be returned if no information available.
    */
   int GetLineNumber(int code_pos);
+
+  static const int kNoScriptId = 0;
 };


@@ -2347,7 +2355,18 @@
    * kLineOffsetNotFound if no information available.
    */
   int GetScriptColumnNumber() const;
+
+  /**
+   * Returns scriptId object.
+   * DEPRECATED: use ScriptId() instead.
+   */
   Handle<Value> GetScriptId() const;
+
+  /**
+   * Returns scriptId.
+   */
+  int ScriptId() const;
+
   ScriptOrigin GetScriptOrigin() const;
   V8_INLINE(static Function* Cast(Value* obj));
   static const int kLineOffsetNotFound;
=======================================
--- /branches/bleeding_edge/src/api.cc  Tue Jun 25 01:11:50 2013
+++ /branches/bleeding_edge/src/api.cc  Tue Jun 25 07:57:47 2013
@@ -2024,6 +2024,19 @@
   i::Handle<i::Object> id(raw_id, isolate);
   return Utils::ToLocal(id);
 }
+
+
+int Script::GetId() {
+  i::Isolate* isolate = i::Isolate::Current();
+  ON_BAILOUT(isolate, "v8::Script::Id()", return -1);
+  LOG_API(isolate, "Script::Id");
+  {
+    i::HandleScope scope(isolate);
+    i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this);
+    i::Handle<i::Script> script(i::Script::cast(function_info->script()));
+    return script->id()->value();
+  }
+}


 int Script::GetLineNumber(int code_pos) {
@@ -4335,6 +4348,7 @@
   }
   return kLineOffsetNotFound;
 }
+

 Handle<Value> Function::GetScriptId() const {
   i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
@@ -4343,6 +4357,15 @@
   i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
return Utils::ToLocal(i::Handle<i::Object>(script->id(), func->GetIsolate()));
 }
+
+
+int Function::ScriptId() const {
+  i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
+ if (!func->shared()->script()->IsScript()) return v8::Script::kNoScriptId;
+  i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
+  return script->id()->value();
+}
+

 int String::Length() const {
   i::Handle<i::String> str = Utils::OpenHandle(this);
=======================================
--- /branches/bleeding_edge/src/debug.cc        Tue Jun 25 06:42:44 2013
+++ /branches/bleeding_edge/src/debug.cc        Tue Jun 25 07:57:47 2013
@@ -620,7 +620,7 @@
 void ScriptCache::Add(Handle<Script> script) {
   GlobalHandles* global_handles = Isolate::Current()->global_handles();
   // Create an entry in the hash map for the script.
-  int id = Smi::cast(script->id())->value();
+  int id = script->id()->value();
   HashMap::Entry* entry =
       HashMap::Lookup(reinterpret_cast<void*>(id), Hash(id), true);
   if (entry->value != NULL) {
@@ -688,7 +688,7 @@
   ASSERT((*location)->IsScript());

   // Remove the entry from the cache.
-  int id = Smi::cast((*location)->id())->value();
+  int id = (*location)->id()->value();
   script_cache->Remove(reinterpret_cast<void*>(id), Hash(id));
   script_cache->collected_scripts_.Add(id);

=======================================
--- /branches/bleeding_edge/src/factory.cc      Fri Jun 21 06:02:38 2013
+++ /branches/bleeding_edge/src/factory.cc      Tue Jun 25 07:57:47 2013
@@ -434,27 +434,17 @@

 Handle<Script> Factory::NewScript(Handle<String> source) {
   // Generate id for this script.
-  int id;
   Heap* heap = isolate()->heap();
-  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));
+  int id = heap->last_script_id()->value() + 1;
+  if (!Smi::IsValid(id) || id < 0) id = 1;
+  heap->set_last_script_id(Smi::FromInt(id));

   // Create and initialize script object.
   Handle<Foreign> wrapper = NewForeign(0, TENURED);
   Handle<Script> script = Handle<Script>::cast(NewStruct(SCRIPT_TYPE));
   script->set_source(*source);
   script->set_name(heap->undefined_value());
-  script->set_id(heap->last_script_id());
+  script->set_id(Smi::FromInt(id));
   script->set_line_offset(Smi::FromInt(0));
   script->set_column_offset(Smi::FromInt(0));
   script->set_data(heap->undefined_value());
=======================================
--- /branches/bleeding_edge/src/heap-inl.h      Wed Jun 19 10:01:43 2013
+++ /branches/bleeding_edge/src/heap-inl.h      Tue Jun 25 07:57:47 2013
@@ -568,11 +568,6 @@
   ASSERT(amount_of_external_allocated_memory_ >= 0);
   return amount_of_external_allocated_memory_;
 }
-
-
-void Heap::SetLastScriptId(Object* last_script_id) {
-  roots_[kLastScriptIdRootIndex] = last_script_id;
-}


 Isolate* Heap::isolate() {
=======================================
--- /branches/bleeding_edge/src/heap.cc Fri Jun 21 06:02:38 2013
+++ /branches/bleeding_edge/src/heap.cc Tue Jun 25 07:57:47 2013
@@ -3155,7 +3155,7 @@
   set_empty_slow_element_dictionary(SeededNumberDictionary::cast(obj));

   // Handling of script id generation is in Factory::NewScript.
-  set_last_script_id(undefined_value());
+  set_last_script_id(Smi::FromInt(v8::Script::kNoScriptId));

   // Initialize keyed lookup cache.
   isolate_->keyed_lookup_cache()->Clear();
=======================================
--- /branches/bleeding_edge/src/heap.h  Tue Jun 25 02:09:25 2013
+++ /branches/bleeding_edge/src/heap.h  Tue Jun 25 07:57:47 2013
@@ -175,7 +175,7 @@
V(Code, js_entry_code, JsEntryCode) \ V(Code, js_construct_entry_code, JsConstructEntryCode) \ V(FixedArray, natives_source_cache, NativesSourceCache) \ - V(Object, last_script_id, LastScriptId) \ + V(Smi, last_script_id, LastScriptId) \ V(Script, empty_script, EmptyScript) \ V(Smi, real_stack_limit, RealStackLimit) \ V(NameDictionary, intrinsic_function_names, IntrinsicFunctionNames) \
@@ -1439,9 +1439,6 @@
   void public_set_store_buffer_top(Address* top) {
     roots_[kStoreBufferTopRootIndex] = reinterpret_cast<Smi*>(top);
   }
-
-  // Update the next script id.
-  inline void SetLastScriptId(Object* last_script_id);

   // Generated code can embed this address to get access to the roots.
   Object** roots_array_start() { return roots_; }
=======================================
--- /branches/bleeding_edge/src/objects-inl.h   Tue Jun 25 02:09:25 2013
+++ /branches/bleeding_edge/src/objects-inl.h   Tue Jun 25 07:57:47 2013
@@ -4451,7 +4451,7 @@

 ACCESSORS(Script, source, Object, kSourceOffset)
 ACCESSORS(Script, name, Object, kNameOffset)
-ACCESSORS(Script, id, Object, kIdOffset)
+ACCESSORS(Script, id, Smi, kIdOffset)
 ACCESSORS_TO_SMI(Script, line_offset, kLineOffsetOffset)
 ACCESSORS_TO_SMI(Script, column_offset, kColumnOffsetOffset)
 ACCESSORS(Script, data, Object, kDataOffset)
=======================================
--- /branches/bleeding_edge/src/objects.h       Tue Jun 25 02:34:22 2013
+++ /branches/bleeding_edge/src/objects.h       Tue Jun 25 07:57:47 2013
@@ -5752,7 +5752,7 @@
   DECL_ACCESSORS(name, Object)

   // [id]: the script id.
-  DECL_ACCESSORS(id, Object)
+  DECL_ACCESSORS(id, Smi)

// [line_offset]: script line offset in resource from where it was extracted.
   DECL_ACCESSORS(line_offset, Smi)

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to