Fix PathTracer.

When tracing, we abuse the map for marking, thereby mutating it.
HeapObject::map() takes care of recovering unabused value.

R=yangguo@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21626 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
ishell@chromium.org 2014-06-03 08:28:38 +00:00
parent 56a486c322
commit b58a08d998
4 changed files with 28 additions and 32 deletions

View File

@ -5853,9 +5853,8 @@ void PathTracer::MarkRecursively(Object** p, MarkVisitor* mark_visitor) {
HeapObject* obj = HeapObject::cast(*p);
Object* map = obj->map();
if (!map->IsHeapObject()) return; // visited before
MapWord map_word = obj->map_word();
if (!map_word.ToMap()->IsHeapObject()) return; // visited before
if (found_target_in_trace_) return; // stop if target found
object_stack_.Add(obj);
@ -5869,11 +5868,11 @@ void PathTracer::MarkRecursively(Object** p, MarkVisitor* mark_visitor) {
bool is_native_context = SafeIsNativeContext(obj);
// not visited yet
Map* map_p = reinterpret_cast<Map*>(HeapObject::cast(map));
Map* map = Map::cast(map_word.ToMap());
Address map_addr = map_p->address();
obj->set_map_no_write_barrier(reinterpret_cast<Map*>(map_addr + kMarkTag));
MapWord marked_map_word =
MapWord::FromRawValue(obj->map_word().ToRawValue() + kMarkTag);
obj->set_map_word(marked_map_word);
// Scan the object body.
if (is_native_context && (visit_mode_ == VISIT_ONLY_STRONG)) {
@ -5884,17 +5883,16 @@ void PathTracer::MarkRecursively(Object** p, MarkVisitor* mark_visitor) {
Context::kHeaderSize + Context::FIRST_WEAK_SLOT * kPointerSize);
mark_visitor->VisitPointers(start, end);
} else {
obj->IterateBody(map_p->instance_type(),
obj->SizeFromMap(map_p),
mark_visitor);
obj->IterateBody(map->instance_type(), obj->SizeFromMap(map), mark_visitor);
}
// Scan the map after the body because the body is a lot more interesting
// when doing leak detection.
MarkRecursively(&map, mark_visitor);
MarkRecursively(reinterpret_cast<Object**>(&map), mark_visitor);
if (!found_target_in_trace_) // don't pop if found the target
if (!found_target_in_trace_) { // don't pop if found the target
object_stack_.RemoveLast();
}
}
@ -5903,25 +5901,18 @@ void PathTracer::UnmarkRecursively(Object** p, UnmarkVisitor* unmark_visitor) {
HeapObject* obj = HeapObject::cast(*p);
Object* map = obj->map();
MapWord map_word = obj->map_word();
if (map_word.ToMap()->IsHeapObject()) return; // unmarked already
if (map->IsHeapObject()) return; // unmarked already
MapWord unmarked_map_word =
MapWord::FromRawValue(map_word.ToRawValue() - kMarkTag);
obj->set_map_word(unmarked_map_word);
Address map_addr = reinterpret_cast<Address>(map);
Map* map = Map::cast(unmarked_map_word.ToMap());
map_addr -= kMarkTag;
UnmarkRecursively(reinterpret_cast<Object**>(&map), unmark_visitor);
ASSERT_TAG_ALIGNED(map_addr);
HeapObject* map_p = HeapObject::FromAddress(map_addr);
obj->set_map_no_write_barrier(reinterpret_cast<Map*>(map_p));
UnmarkRecursively(reinterpret_cast<Object**>(&map_p), unmark_visitor);
obj->IterateBody(Map::cast(map_p)->instance_type(),
obj->SizeFromMap(Map::cast(map_p)),
unmark_visitor);
obj->IterateBody(map->instance_type(), obj->SizeFromMap(map), unmark_visitor);
}

View File

@ -2727,6 +2727,9 @@ class PathTracer : public ObjectVisitor {
FIND_FIRST // Will stop the search after first match.
};
// Tags 0, 1, and 3 are used. Use 2 for marking visited HeapObject.
static const int kMarkTag = 2;
// For the WhatToFind arg, if FIND_FIRST is specified, tracing will stop
// after the first match. If FIND_ALL is specified, then tracing will be
// done for all matches.
@ -2758,9 +2761,6 @@ class PathTracer : public ObjectVisitor {
void UnmarkRecursively(Object** p, UnmarkVisitor* unmark_visitor);
virtual void ProcessResults();
// Tags 0, 1, and 3 are used. Use 2 for marking visited HeapObject.
static const int kMarkTag = 2;
Object* search_target_;
bool found_target_;
bool found_target_in_trace_;

View File

@ -1328,7 +1328,14 @@ Isolate* HeapObject::GetIsolate() {
Map* HeapObject::map() {
#ifdef DEBUG
// Clear mark potentially added by PathTracer.
uintptr_t raw_value =
map_word().ToRawValue() & ~static_cast<uintptr_t>(PathTracer::kMarkTag);
return MapWord::FromRawValue(raw_value).ToMap();
#else
return map_word().ToMap();
#endif
}

View File

@ -4325,8 +4325,6 @@ TEST(ArrayShiftSweeping) {
#ifdef DEBUG
TEST(PathTracer) {
// Type cast checks fail because the path tracer abuses the map for marking.
if (i::FLAG_enable_slow_asserts) return;
CcTest::InitializeVM();
v8::HandleScope scope(CcTest::isolate());