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

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

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : fa754d106c4d47fd89f89a46df704c85387722bd
This commit is contained in:
Boris Chiou 2018-01-01 21:32:59 -06:00
Родитель b5acf25317
Коммит 2bc354c080
2 изменённых файлов: 17 добавлений и 6 удалений

Просмотреть файл

@ -26,17 +26,25 @@ trait Recover<Q: ?Sized> {
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 }
}
}
@ -48,8 +56,10 @@ impl error::Error for FailedAllocationError {
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),
}
}

Просмотреть файл

@ -778,9 +778,10 @@ impl<K, V> RawTable<K, V> {
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 }),
});
}