================
@@ -58,41 +144,44 @@ class MemoryCache {
                     const lldb::DataBufferSP &data_buffer_sp);
 
 protected:
-  typedef std::map<lldb::addr_t, lldb::DataBufferSP> BlockMap;
   typedef RangeVector<lldb::addr_t, lldb::addr_t, 4> InvalidRanges;
   typedef Range<lldb::addr_t, lldb::addr_t> AddrRange;
   // Classes that inherit from MemoryCache can see and modify these
   std::recursive_mutex m_mutex;
-  BlockMap m_L1_cache; // A first level memory cache whose chunk sizes vary 
that
-                       // will be used only if the memory read fits entirely in
-                       // a chunk
-  BlockMap m_L2_cache; // A memory cache of fixed size chinks
-                       // (m_L2_cache_line_byte_size bytes in size each)
+  // L1 and L2 partition the cache.  An address is held by at most one.  L2
+  // holds whole, aligned lines; L1 holds smaller, non-overlapping pieces.
+  ChunkCache m_L1_cache; // Chunks smaller than a cache line.
+  LineCache m_L2_cache;  // Whole cache lines.
   InvalidRanges m_invalid_ranges;
   Process &m_process;
-  uint32_t m_L2_cache_line_byte_size;
 
 private:
   MemoryCache(const MemoryCache &) = delete;
   const MemoryCache &operator=(const MemoryCache &) = delete;
 
-  lldb::DataBufferSP GetL2CacheLine(lldb::addr_t addr, Status &error);
-
-  // If the entire range [addr, addr+len) is covered by a single L1 entry,
-  // returns a pointer into that entry's data at the correct offset. Returns
-  // nullptr on a miss. Caller must hold m_mutex.
-  const uint8_t *FindL1CacheEntry(lldb::addr_t addr, size_t len) const;
-
-  // If the entire range [addr, addr+len) is covered by a single cache line
-  // that is already in L2, returns a pointer into that line's data at the
-  // correct offset. Never reads from the inferior. Returns nullptr on a miss.
-  // Caller must hold m_mutex.
-  const uint8_t *FindL2CacheEntry(lldb::addr_t addr, size_t len) const;
-
-  // Looks the range [addr, addr+len) up in L1 and then L2, returning a pointer
-  // into the data of whichever entry covers it. Returns nullptr on a miss.
+  // Add a whole cache line to L2 and drop the L1 entries it supersedes.
   // Caller must hold m_mutex.
-  const uint8_t *FindCacheEntry(lldb::addr_t addr, size_t len) const;
+  void InsertWholeLine(lldb::addr_t line_base_addr,
+                       llvm::ArrayRef<uint8_t> src);
+
+  // Add the bytes of [addr, addr+src.size()) that no entry holds yet to L1.
+  // The range must lie within one cache line.  Caller must hold m_mutex.
+  void InsertPartialLine(lldb::addr_t addr, llvm::ArrayRef<uint8_t> src);
+
+  // Split [addr, addr+src.size()) at cache line boundaries: whole lines to L2,
+  // shorter pieces to L1.  Takes m_mutex.
+  void InsertData(lldb::addr_t addr, llvm::ArrayRef<uint8_t> src);
+
+  // Copy the cached bytes of [addr, addr+len), stopping at the first miss,
+  // and return the count.  Never reads from the inferior; caller holds 
m_mutex.
+  size_t ReadFromCaches(lldb::addr_t addr, void *dst, size_t len) const;
+
+  // The range to fetch for a read that ends at caller_end and whose first
+  // bytes_filled bytes the caches supplied, so read_addr is the first byte
+  // none of them holds.  Grown to whole cache lines where that costs nothing,
+  // and clipped at an invalid range.  Caller must hold m_mutex.
----------------
felipepiovezan wrote:

I'm having a hard time parsing this paragraph. For example, there is no verb 
describing what this function does. Could you try rephrasing this?

https://github.com/llvm/llvm-project/pull/222688
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to