Reviewers: Yury Semikhatsky, Jakob, Sven Panne,
Description:
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
Please review this at https://codereview.chromium.org/17600006/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M include/v8.h
M src/api.cc
M src/debug.cc
M src/factory.cc
M src/heap-inl.h
M src/heap.h
M src/heap.cc
M src/objects-inl.h
M src/objects.h
M test/cctest/test-api.cc
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index
de3a40ff3388e2bd2dcbf50c15b36123c2d16286..c7ec411ecf19b0e90414d99d32a7af2efe23d4e7
100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -1044,7 +1044,12 @@ class V8EXPORT Script {
/**
* Returns the script id value.
*/
- Local<Value> Id();
+ V8_DEPRECATED(Local<Value> Id());
+
+ /**
+ * Returns the script id value.
+ */
+ int GetId();
/**
* Associate an additional data object with the script. This is mainly
used
@@ -2347,7 +2352,10 @@ class V8EXPORT Function : public Object {
* kLineOffsetNotFound if no information available.
*/
int GetScriptColumnNumber() const;
- Handle<Value> GetScriptId() const;
+
+ V8_DEPRECATED(Handle<Value> GetScriptId() const);
+
+ int ScriptId() const;
ScriptOrigin GetScriptOrigin() const;
V8_INLINE(static Function* Cast(Value* obj));
static const int kLineOffsetNotFound;
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index
a138e39f293e1610868415e4519559a2d0e426b6..e68c580d6d6a99f72b549ab3a6cab0b67bd9e57e
100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -2026,6 +2026,19 @@ Local<Value> Script::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) {
i::Isolate* isolate = i::Isolate::Current();
ON_BAILOUT(isolate, "v8::Script::GetLineNumber()", return -1);
@@ -4326,6 +4339,7 @@ int Function::GetScriptColumnNumber() const {
return kLineOffsetNotFound;
}
+
Handle<Value> Function::GetScriptId() const {
i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
if (!func->shared()->script()->IsScript())
@@ -4334,6 +4348,16 @@ Handle<Value> Function::GetScriptId() const {
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 i::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);
if (IsDeadCheck(str->GetIsolate(), "v8::String::Length()")) return 0;
Index: src/debug.cc
diff --git a/src/debug.cc b/src/debug.cc
index
0ffdd0043e57c55f6d6e92720f4f0d4f3b2f0a49..2f0442c225af83ca89daafb94193d4ab4565c963
100644
--- a/src/debug.cc
+++ b/src/debug.cc
@@ -606,7 +606,7 @@ const int Debug::kFrameDropperFrameSize = 4;
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) {
@@ -674,7 +674,7 @@ void ScriptCache::HandleWeakScript(v8::Isolate* isolate,
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);
Index: src/factory.cc
diff --git a/src/factory.cc b/src/factory.cc
index
2a03050b6de7af839c8ccd8719b3030ec55e3b25..673bb23031733ad2c5acde104e94a256b5a9ea70
100644
--- a/src/factory.cc
+++ b/src/factory.cc
@@ -434,27 +434,17 @@ Handle<ExecutableAccessorInfo>
Factory::NewExecutableAccessorInfo() {
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());
Index: src/heap-inl.h
diff --git a/src/heap-inl.h b/src/heap-inl.h
index
2d0968d34195d7ab6a2f1c87f2518323facf55b4..b9dbf45cfdec1fe694a1859cfa5524d102d14ec2
100644
--- a/src/heap-inl.h
+++ b/src/heap-inl.h
@@ -570,8 +570,8 @@ intptr_t Heap::AdjustAmountOfExternalAllocatedMemory(
}
-void Heap::SetLastScriptId(Object* last_script_id) {
- roots_[kLastScriptIdRootIndex] = last_script_id;
+void Heap::SetLastScriptId(int last_script_id) {
+ roots_[kLastScriptIdRootIndex] = Smi::FromInt(last_script_id);
}
Index: src/heap.cc
diff --git a/src/heap.cc b/src/heap.cc
index
06c54a9bc00dde300d3f53c1b9752264a7ac507a..e53f19c5421422cc6a180844eef7d28699d57bed
100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -3155,7 +3155,7 @@ bool Heap::CreateInitialObjects() {
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(0));
// Initialize keyed lookup cache.
isolate_->keyed_lookup_cache()->Clear();
Index: src/heap.h
diff --git a/src/heap.h b/src/heap.h
index
3192630a012d682635b2a960cfed04ae7ad4c6d5..f843af5930d6e4081b28b6b07730c48cdf07aa1e
100644
--- a/src/heap.h
+++ b/src/heap.h
@@ -175,7 +175,7 @@ namespace internal {
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) \
@@ -1441,7 +1441,7 @@ class Heap {
}
// Update the next script id.
- inline void SetLastScriptId(Object* last_script_id);
+ inline void SetLastScriptId(int last_script_id);
// Generated code can embed this address to get access to the roots.
Object** roots_array_start() { return roots_; }
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index
fb6ac8d678289925530f6e2fa80fcd7886cf91da..a93ccfe2766c72e60f25fd25c6de7c8eec32fa4a
100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -4446,7 +4446,7 @@ ACCESSORS(AllocationSiteInfo, payload, Object,
kPayloadOffset)
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)
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index
417411d15524222bfb59708acd5b9a6f8589e24d..b1189dc0f4a3c7355c7098e6546c3948616bd43b
100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -5755,7 +5755,7 @@ class Script: public Struct {
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)
@@ -5820,6 +5820,7 @@ class Script: public Struct {
static const int kEvalFrominstructionsOffsetOffset =
kEvalFromSharedOffset + kPointerSize;
static const int kSize = kEvalFrominstructionsOffsetOffset +
kPointerSize;
+ static const int kNoScriptId = 0;
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(Script);
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index
e417477adeb427db745d93a1d33afda3dfd77024..06a6d42e41b015e144019e6cb622bebad444f74a
100755
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -16654,8 +16654,8 @@ THREADED_TEST(FunctionGetScriptId) {
env->Global()->Get(v8::String::New("foo")));
v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::New("bar")));
- CHECK_EQ(script->Id(), foo->GetScriptId());
- CHECK_EQ(script->Id(), bar->GetScriptId());
+ CHECK_EQ(script->GetId(), foo->ScriptId());
+ CHECK_EQ(script->GetId(), bar->ScriptId());
}
--
--
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.