Commit 53eb53f4 authored by loislo@chromium.org's avatar loislo@chromium.org

CPUProfiler: It is not clear why we are using Handle<Object> for scriptId....

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
R=jkummerow@chromium.org

Review URL: https://codereview.chromium.org/17600006

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15327 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent ebfe1b8e
......@@ -1043,9 +1043,15 @@ class V8EXPORT Script {
/**
* 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 @@ class V8EXPORT Script {
* -1 will be returned if no information available.
*/
int GetLineNumber(int code_pos);
static const int kNoScriptId = 0;
};
......@@ -2347,7 +2355,18 @@ class V8EXPORT Function : public Object {
* 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;
......
......@@ -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);
......@@ -4336,6 +4349,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())
......@@ -4344,6 +4358,15 @@ 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 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);
if (IsDeadCheck(str->GetIsolate(), "v8::String::Length()")) return 0;
......
......@@ -620,7 +620,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) {
......@@ -688,7 +688,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);
......
......@@ -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());
......
......@@ -570,11 +570,6 @@ intptr_t Heap::AdjustAmountOfExternalAllocatedMemory(
}
void Heap::SetLastScriptId(Object* last_script_id) {
roots_[kLastScriptIdRootIndex] = last_script_id;
}
Isolate* Heap::isolate() {
return reinterpret_cast<Isolate*>(reinterpret_cast<intptr_t>(this) -
reinterpret_cast<size_t>(reinterpret_cast<Isolate*>(4)->heap()) + 4);
......
......@@ -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(v8::Script::kNoScriptId));
// Initialize keyed lookup cache.
isolate_->keyed_lookup_cache()->Clear();
......
......@@ -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) \
......@@ -1440,9 +1440,6 @@ class Heap {
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_; }
......
......@@ -4451,7 +4451,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)
......
......@@ -5752,7 +5752,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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment