Bug 1418806 servo: Merge #19607 - hashglobe: Dump the requested aligment if out of memory while allocating a table (from BorisChiou:stylo/crash/out_of_memory_alignment); r=emilio a=gchang
authorBoris Chiou <boris.chiou@gmail.com>
Mon, 01 Jan 2018 21:32:59 -0600
changeset 445556 641211059e52792538163f95dd447766e35a7d93
parent 445555 46fabe0cc9dc12719f9f96f0146508093a6a0dfe
child 445557 cb843e26235503704b941d47370b1686ddcec11c
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio, gchang
bugs1418806, 1416903
milestone58.0
Bug 1418806 servo: Merge #19607 - hashglobe: Dump the requested aligment if out of memory while allocating a table (from BorisChiou:stylo/crash/out_of_memory_alignment); r=emilio a=gchang This is for Bug 1418806 and Bug 1416903. We need not only the requested size but also the requested alignment for debugging. --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors Source-Repo: https://github.com/servo/servo Source-Revision: 27a443fbaaf3e19fa3a753f68b20a7a7ccc5d199
servo/components/hashglobe/src/lib.rs
servo/components/hashglobe/src/table.rs
--- a/servo/components/hashglobe/src/lib.rs
+++ b/servo/components/hashglobe/src/lib.rs
@@ -22,35 +22,45 @@ trait Recover<Q: ?Sized> {
     type Key;
 
     fn get(&self, key: &Q) -> Option<&Self::Key>;
     fn take(&mut self, key: &Q) -> Option<Self::Key>;
     fn replace(&mut self, key: Self::Key) -> Option<Self::Key>;
 }
 
 #[derive(Debug)]
+pub struct AllocationInfo {
+    /// The size we are requesting.
+    size: usize,
+    /// The alignment we are requesting.
+    alignment: usize,
+}
+
+#[derive(Debug)]
 pub struct FailedAllocationError {
     reason: &'static str,
-    /// The size we are allocating, if needed.
-    allocation_size: Option<usize>,
+    /// The allocation info we are requesting, if needed.
+    allocation_info: Option<AllocationInfo>,
 }
 
 impl FailedAllocationError {
     #[inline]
     pub fn new(reason: &'static str) -> Self {
-        Self { reason, allocation_size: None }
+        Self { reason, allocation_info: None }
     }
 }
 
 impl error::Error for FailedAllocationError {
     fn description(&self) -> &str {
         self.reason
     }
 }
 
 impl fmt::Display for FailedAllocationError {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        match self.allocation_size {
-            Some(size) => write!(f, "{}, allocation size: {}", self.reason, size),
+        match self.allocation_info {
+            Some(ref info) => {
+                write!(f, "{}, allocation: (size: {}, alignment: {})", self.reason, info.size, info.alignment)
+            },
             None => self.reason.fmt(f),
         }
     }
 }
--- a/servo/components/hashglobe/src/table.rs
+++ b/servo/components/hashglobe/src/table.rs
@@ -773,19 +773,20 @@ impl<K, V> RawTable<K, V> {
             return Err(FailedAllocationError::new("capacity overflow when allocating RawTable"));
         }
 
 
         // FORK NOTE: Uses alloc shim instead of Heap.alloc
         let buffer = alloc(size, alignment);
 
         if buffer.is_null() {
+            use AllocationInfo;
             return Err(FailedAllocationError {
                 reason: "out of memory when allocating RawTable",
-                allocation_size: Some(size),
+                allocation_info: Some(AllocationInfo { size, alignment }),
             });
         }
 
         let hashes = buffer.offset(hash_offset as isize) as *mut HashUint;
 
         Ok(RawTable {
             capacity_mask: capacity.wrapping_sub(1),
             size: 0,