Commit b58a08d9 authored by ishell@chromium.org's avatar ishell@chromium.org

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
parent 56a486c3
...@@ -5853,9 +5853,8 @@ void PathTracer::MarkRecursively(Object** p, MarkVisitor* mark_visitor) { ...@@ -5853,9 +5853,8 @@ void PathTracer::MarkRecursively(Object** p, MarkVisitor* mark_visitor) {
HeapObject* obj = HeapObject::cast(*p); HeapObject* obj = HeapObject::cast(*p);
Object* map = obj->map(); MapWord map_word = obj->map_word();
if (!map_word.ToMap()->IsHeapObject()) return; // visited before
if (!map->IsHeapObject()) return; // visited before
if (found_target_in_trace_) return; // stop if target found if (found_target_in_trace_) return; // stop if target found
object_stack_.Add(obj); object_stack_.Add(obj);
...@@ -5869,11 +5868,11 @@ void PathTracer::MarkRecursively(Object** p, MarkVisitor* mark_visitor) { ...@@ -5869,11 +5868,11 @@ void PathTracer::MarkRecursively(Object** p, MarkVisitor* mark_visitor) {
bool is_native_context = SafeIsNativeContext(obj); bool is_native_context = SafeIsNativeContext(obj);
// not visited yet // 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. // Scan the object body.
if (is_native_context && (visit_mode_ == VISIT_ONLY_STRONG)) { if (is_native_context && (visit_mode_ == VISIT_ONLY_STRONG)) {
...@@ -5884,17 +5883,16 @@ void PathTracer::MarkRecursively(Object** p, MarkVisitor* mark_visitor) { ...@@ -5884,17 +5883,16 @@ void PathTracer::MarkRecursively(Object** p, MarkVisitor* mark_visitor) {
Context::kHeaderSize + Context::FIRST_WEAK_SLOT * kPointerSize); Context::kHeaderSize + Context::FIRST_WEAK_SLOT * kPointerSize);
mark_visitor->VisitPointers(start, end); mark_visitor->VisitPointers(start, end);
} else { } else {
obj->IterateBody(map_p->instance_type(), obj->IterateBody(map->instance_type(), obj->SizeFromMap(map), mark_visitor);
obj->SizeFromMap(map_p),
mark_visitor);
} }
// Scan the map after the body because the body is a lot more interesting // Scan the map after the body because the body is a lot more interesting
// when doing leak detection. // 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(); object_stack_.RemoveLast();
}
} }
...@@ -5903,25 +5901,18 @@ void PathTracer::UnmarkRecursively(Object** p, UnmarkVisitor* unmark_visitor) { ...@@ -5903,25 +5901,18 @@ void PathTracer::UnmarkRecursively(Object** p, UnmarkVisitor* unmark_visitor) {
HeapObject* obj = HeapObject::cast(*p); 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
Address map_addr = reinterpret_cast<Address>(map);
map_addr -= kMarkTag;
ASSERT_TAG_ALIGNED(map_addr);
HeapObject* map_p = HeapObject::FromAddress(map_addr); MapWord unmarked_map_word =
MapWord::FromRawValue(map_word.ToRawValue() - kMarkTag);
obj->set_map_word(unmarked_map_word);
obj->set_map_no_write_barrier(reinterpret_cast<Map*>(map_p)); Map* map = Map::cast(unmarked_map_word.ToMap());
UnmarkRecursively(reinterpret_cast<Object**>(&map_p), unmark_visitor); UnmarkRecursively(reinterpret_cast<Object**>(&map), unmark_visitor);
obj->IterateBody(Map::cast(map_p)->instance_type(), obj->IterateBody(map->instance_type(), obj->SizeFromMap(map), unmark_visitor);
obj->SizeFromMap(Map::cast(map_p)),
unmark_visitor);
} }
......
...@@ -2727,6 +2727,9 @@ class PathTracer : public ObjectVisitor { ...@@ -2727,6 +2727,9 @@ class PathTracer : public ObjectVisitor {
FIND_FIRST // Will stop the search after first match. 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 // 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 // after the first match. If FIND_ALL is specified, then tracing will be
// done for all matches. // done for all matches.
...@@ -2758,9 +2761,6 @@ class PathTracer : public ObjectVisitor { ...@@ -2758,9 +2761,6 @@ class PathTracer : public ObjectVisitor {
void UnmarkRecursively(Object** p, UnmarkVisitor* unmark_visitor); void UnmarkRecursively(Object** p, UnmarkVisitor* unmark_visitor);
virtual void ProcessResults(); virtual void ProcessResults();
// Tags 0, 1, and 3 are used. Use 2 for marking visited HeapObject.
static const int kMarkTag = 2;
Object* search_target_; Object* search_target_;
bool found_target_; bool found_target_;
bool found_target_in_trace_; bool found_target_in_trace_;
......
...@@ -1328,7 +1328,14 @@ Isolate* HeapObject::GetIsolate() { ...@@ -1328,7 +1328,14 @@ Isolate* HeapObject::GetIsolate() {
Map* HeapObject::map() { 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(); return map_word().ToMap();
#endif
} }
......
...@@ -4325,8 +4325,6 @@ TEST(ArrayShiftSweeping) { ...@@ -4325,8 +4325,6 @@ TEST(ArrayShiftSweeping) {
#ifdef DEBUG #ifdef DEBUG
TEST(PathTracer) { TEST(PathTracer) {
// Type cast checks fail because the path tracer abuses the map for marking.
if (i::FLAG_enable_slow_asserts) return;
CcTest::InitializeVM(); CcTest::InitializeVM();
v8::HandleScope scope(CcTest::isolate()); v8::HandleScope scope(CcTest::isolate());
......
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