Commit b74c5b1e authored by sgjesse@chromium.org's avatar sgjesse@chromium.org

Moved the storage of the last script id into the heap to make it part of the...

Moved the storage of the last script id into the heap to make it part of the serialized data when starting V8 on a snapshot.

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
parent c1c5a09e
......@@ -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;
}
......
......@@ -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())
......
......@@ -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();
......
......@@ -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();
......
......@@ -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);
......
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