Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(527)

Unified Diff: src/heap.cc

Issue 3120006: Put direct code pointers into JSFunction objects. This is a first step... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/handles.cc ('k') | src/ia32/builtins-ia32.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/heap.cc
===================================================================
--- src/heap.cc (revision 5232)
+++ src/heap.cc (working copy)
@@ -2452,39 +2452,62 @@
};
-static void FlushCodeForFunction(SharedFunctionInfo* function_info) {
+static bool CodeIsActive(Code* code) {
+ // Make sure we are not referencing the code from the stack.
+ for (StackFrameIterator it; !it.done(); it.Advance()) {
+ if (code->contains(it.frame()->pc())) return true;
+ }
+ // Iterate the archived stacks in all threads to check if
+ // the code is referenced.
+ FlushingStackVisitor threadvisitor(code);
+ ThreadManager::IterateArchivedThreads(&threadvisitor);
+ if (threadvisitor.FoundCode()) return true;
+ return false;
+}
+
+
+static void FlushCodeForFunction(JSFunction* function) {
+ SharedFunctionInfo* shared_info = function->shared();
+
+ // Special handling if the function and shared info objects
+ // have different code objects.
+ if (function->code() != shared_info->code()) {
+ // If the shared function has been flushed but the function has not,
+ // we flush the function if possible.
+ if (!shared_info->is_compiled() && function->is_compiled() &&
+ !CodeIsActive(function->code())) {
+ function->set_code(shared_info->code());
+ }
+ return;
+ }
+
// The function must be compiled and have the source code available,
// to be able to recompile it in case we need the function again.
- if (!(function_info->is_compiled() && function_info->HasSourceCode())) return;
+ if (!(shared_info->is_compiled() && shared_info->HasSourceCode())) return;
// We never flush code for Api functions.
- if (function_info->IsApiFunction()) return;
+ if (shared_info->IsApiFunction()) return;
// Only flush code for functions.
- if (!function_info->code()->kind() == Code::FUNCTION) return;
+ if (!shared_info->code()->kind() == Code::FUNCTION) return;
// Function must be lazy compilable.
- if (!function_info->allows_lazy_compilation()) return;
+ if (!shared_info->allows_lazy_compilation()) return;
// If this is a full script wrapped in a function we do no flush the code.
- if (function_info->is_toplevel()) return;
+ if (shared_info->is_toplevel()) return;
// If this function is in the compilation cache we do not flush the code.
- if (CompilationCache::HasFunction(function_info)) return;
+ if (CompilationCache::HasFunction(shared_info)) return;
- // Make sure we are not referencing the code from the stack.
- for (StackFrameIterator it; !it.done(); it.Advance()) {
- if (function_info->code()->contains(it.frame()->pc())) return;
- }
- // Iterate the archived stacks in all threads to check if
- // the code is referenced.
- FlushingStackVisitor threadvisitor(function_info->code());
- ThreadManager::IterateArchivedThreads(&threadvisitor);
- if (threadvisitor.FoundCode()) return;
+ // Check stack and archived threads for the code.
+ if (CodeIsActive(shared_info->code())) return;
// Compute the lazy compilable version of the code.
HandleScope scope;
- function_info->set_code(*ComputeLazyCompile(function_info->length()));
+ Code* code = *ComputeLazyCompile(shared_info->length());
+ shared_info->set_code(code);
+ function->set_code(code);
}
@@ -2496,12 +2519,12 @@
HeapObjectIterator it(old_pointer_space());
for (HeapObject* obj = it.next(); obj != NULL; obj = it.next()) {
if (obj->IsJSFunction()) {
- JSFunction* jsfunction = JSFunction::cast(obj);
+ JSFunction* function = JSFunction::cast(obj);
// The function must have a valid context and not be a builtin.
- if (jsfunction->unchecked_context()->IsContext() &&
- !jsfunction->IsBuiltin()) {
- FlushCodeForFunction(jsfunction->shared());
+ if (function->unchecked_context()->IsContext() &&
+ !function->IsBuiltin()) {
+ FlushCodeForFunction(function);
}
}
}
@@ -2651,6 +2674,7 @@
function->initialize_properties();
function->initialize_elements();
function->set_shared(shared);
+ function->set_code(shared->code());
function->set_prototype_or_initial_map(prototype);
function->set_context(undefined_value());
function->set_literals(empty_fixed_array());
« no previous file with comments | « src/handles.cc ('k') | src/ia32/builtins-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698