| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/experiments/memory_ablation_experiment.h" | 5 #include "chrome/browser/experiments/memory_ablation_experiment.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 if (size > 0) { | 51 if (size > 0) { |
| 52 GetInstance()->Start(task_runner, size); | 52 GetInstance()->Start(task_runner, size); |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 | 55 |
| 56 void MemoryAblationExperiment::Start( | 56 void MemoryAblationExperiment::Start( |
| 57 scoped_refptr<base::SequencedTaskRunner> task_runner, | 57 scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 58 size_t memory_size) { | 58 size_t memory_size) { |
| 59 task_runner->PostDelayedTask( | 59 task_runner->PostDelayedTask( |
| 60 FROM_HERE, | 60 FROM_HERE, |
| 61 base::Bind(&MemoryAblationExperiment::AllocateMemory, | 61 base::BindOnce(&MemoryAblationExperiment::AllocateMemory, |
| 62 base::Unretained(this), memory_size), | 62 base::Unretained(this), memory_size), |
| 63 base::TimeDelta::FromSeconds(kMemoryAblationDelaySeconds)); | 63 base::TimeDelta::FromSeconds(kMemoryAblationDelaySeconds)); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void MemoryAblationExperiment::AllocateMemory(size_t size) { | 66 void MemoryAblationExperiment::AllocateMemory(size_t size) { |
| 67 memory_size_ = size; | 67 memory_size_ = size; |
| 68 memory_.reset(new uint8_t[size]); | 68 memory_.reset(new uint8_t[size]); |
| 69 TouchMemory(); | 69 TouchMemory(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void MemoryAblationExperiment::TouchMemory() { | 72 void MemoryAblationExperiment::TouchMemory() { |
| 73 if (memory_) { | 73 if (memory_) { |
| 74 size_t page_size = base::GetPageSize(); | 74 size_t page_size = base::GetPageSize(); |
| 75 auto* memory = static_cast<volatile uint8_t*>(memory_.get()); | 75 auto* memory = static_cast<volatile uint8_t*>(memory_.get()); |
| 76 for (size_t i = 0; i < memory_size_; i += page_size) { | 76 for (size_t i = 0; i < memory_size_; i += page_size) { |
| 77 memory[i] = i; | 77 memory[i] = i; |
| 78 } | 78 } |
| 79 base::debug::Alias(memory_.get()); | 79 base::debug::Alias(memory_.get()); |
| 80 } | 80 } |
| 81 } | 81 } |
| OLD | NEW |