Commit 2c07b0d0 authored by mstarzinger's avatar mstarzinger Committed by Commit bot

[turbofan] Preserve cached code across GCs.

This preserves the context-independent entry in an optimized code map
across GCs when the code is considered young (i.e. less than 3 ages).
Note that any context-dependent entry for the same code will still be
flushed immediately when the respective context dies, hence context
lifetime is not increased.

R=hpayer@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#29790}
parent 26ffee2c
......@@ -431,6 +431,7 @@ DEFINE_BOOL(turbo_stress_loop_peeling, false,
DEFINE_BOOL(turbo_cf_optimization, true, "optimize control flow in TurboFan")
DEFINE_BOOL(turbo_frame_elision, true, "elide frames in TurboFan")
DEFINE_BOOL(turbo_cache_shared_code, true, "cache context-independent code")
DEFINE_BOOL(turbo_preserve_shared_code, false, "keep context-independent code")
DEFINE_INT(typed_array_max_size_in_heap, 64,
"threshold for in-heap typed array")
......
......@@ -419,10 +419,10 @@ void StaticMarkingVisitor<StaticVisitor>::VisitSharedFunctionInfo(
// Add the shared function info holding an optimized code map to
// the code flusher for processing of code maps after marking.
collector->code_flusher()->AddOptimizedCodeMap(shared);
// Treat all references within the code map weakly by marking the
// Treat some references within the code map weakly by marking the
// code map itself but not pushing it onto the marking deque.
FixedArray* code_map = FixedArray::cast(shared->optimized_code_map());
StaticVisitor::MarkObjectWithoutPush(heap, code_map);
MarkOptimizedCodeMap(heap, code_map);
}
if (IsFlushable(heap, shared)) {
// This function's code looks flushable. But we have to postpone
......@@ -588,6 +588,23 @@ void StaticMarkingVisitor<StaticVisitor>::MarkTransitionArray(
}
template <typename StaticVisitor>
void StaticMarkingVisitor<StaticVisitor>::MarkOptimizedCodeMap(
Heap* heap, FixedArray* code_map) {
if (!StaticVisitor::MarkObjectWithoutPush(heap, code_map)) return;
// Mark the context-independent entry in the optimized code map. Depending on
// the age of the code object, we treat it as a strong or a weak reference.
Object* shared_object = code_map->get(SharedFunctionInfo::kSharedCodeIndex);
if (FLAG_turbo_preserve_shared_code && shared_object->IsCode() &&
FLAG_age_code && !Code::cast(shared_object)->IsOld()) {
StaticVisitor::VisitPointer(
heap,
code_map->RawFieldOfElementAt(SharedFunctionInfo::kSharedCodeIndex));
}
}
template <typename StaticVisitor>
void StaticMarkingVisitor<StaticVisitor>::MarkInlinedFunctionsCode(Heap* heap,
Code* code) {
......
......@@ -417,7 +417,6 @@ class StaticMarkingVisitor : public StaticVisitorBase {
// Skip the weak next code link in a code object.
INLINE(static void VisitNextCodeLink(Heap* heap, Object** slot)) {}
// TODO(mstarzinger): This should be made protected once refactoring is done.
// Mark non-optimize code for functions inlined into the given optimized
// code. This will prevent it from being flushed.
static void MarkInlinedFunctionsCode(Heap* heap, Code* code);
......@@ -440,6 +439,10 @@ class StaticMarkingVisitor : public StaticVisitorBase {
static void MarkMapContents(Heap* heap, Map* map);
static void MarkTransitionArray(Heap* heap, TransitionArray* transitions);
// Mark pointers in the optimized code map that should act as strong
// references, possibly treating some entries weak.
static void MarkOptimizedCodeMap(Heap* heap, FixedArray* code_map);
// Code flushing support.
INLINE(static bool IsFlushable(Heap* heap, JSFunction* function));
INLINE(static bool IsFlushable(Heap* heap, SharedFunctionInfo* shared_info));
......
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