GDBJIT: Remove codes when they are garbage collected.
authormstarzinger@chromium.org <mstarzinger@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 3 Jul 2013 15:29:59 +0000 (15:29 +0000)
committermstarzinger@chromium.org <mstarzinger@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 3 Jul 2013 15:29:59 +0000 (15:29 +0000)
R=mstarzinger@chromium.org

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

Patch from Haitao Feng <haitao.feng@intel.com>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15477 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/gdb-jit.cc
src/gdb-jit.h
src/mark-compact.cc

index 921f2a3..825d1e7 100644 (file)
@@ -2166,6 +2166,24 @@ void GDBJITInterface::RemoveCode(Code* code) {
 }
 
 
+void GDBJITInterface::RemoveCodeRange(Address start, Address end) {
+  HashMap* entries = GetEntries();
+  Zone zone(Isolate::Current());
+  ZoneList<Code*> dead_codes(1, &zone);
+
+  for (HashMap::Entry* e = entries->Start(); e != NULL; e = entries->Next(e)) {
+    Code* code = reinterpret_cast<Code*>(e->key);
+    if (code->address() >= start && code->address() < end) {
+      dead_codes.Add(code, &zone);
+    }
+  }
+
+  for (int i = 0; i < dead_codes.length(); i++) {
+    RemoveCode(dead_codes.at(i));
+  }
+}
+
+
 void GDBJITInterface::RegisterDetailedLineInfo(Code* code,
                                                GDBJITLineInfo* line_info) {
   ScopedLock lock(mutex.Pointer());
index cc052c1..a34d3d3 100644 (file)
@@ -131,6 +131,8 @@ class GDBJITInterface: public AllStatic {
 
   static void RemoveCode(Code* code);
 
+  static void RemoveCodeRange(Address start, Address end);
+
   static void RegisterDetailedLineInfo(Code* code, GDBJITLineInfo* line_info);
 };
 
index 7eab22a..b152a27 100644 (file)
@@ -3137,6 +3137,11 @@ static void SweepPrecisely(PagedSpace* space,
       Address free_end = object_address + offsets[live_index++] * kPointerSize;
       if (free_end != free_start) {
         space->Free(free_start, static_cast<int>(free_end - free_start));
+#ifdef ENABLE_GDB_JIT_INTERFACE
+        if (FLAG_gdbjit && space->identity() == CODE_SPACE) {
+          GDBJITInterface::RemoveCodeRange(free_start, free_end);
+        }
+#endif
       }
       HeapObject* live_object = HeapObject::FromAddress(free_end);
       ASSERT(Marking::IsBlack(Marking::MarkBitFrom(live_object)));
@@ -3163,6 +3168,11 @@ static void SweepPrecisely(PagedSpace* space,
   }
   if (free_start != p->area_end()) {
     space->Free(free_start, static_cast<int>(p->area_end() - free_start));
+#ifdef ENABLE_GDB_JIT_INTERFACE
+    if (FLAG_gdbjit && space->identity() == CODE_SPACE) {
+      GDBJITInterface::RemoveCodeRange(free_start, p->area_end());
+    }
+#endif
   }
   p->ResetLiveBytes();
   if (FLAG_print_cumulative_gc_stat) {