Commit 96b18590 authored by rmcilroy@chromium.org's avatar rmcilroy@chromium.org

Enable physical memory argument to be passed as an argument to...

Enable physical memory argument to be passed as an argument to ConfigureResourceConstraintsForPlatform.

BUG=312241
R=svenpanne@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17696 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent f621f50f
......@@ -35,19 +35,13 @@
*/
namespace v8 {
/**
* Configures the constraints with reasonable default values based on the
* capabilities of the current device the VM is running on.
*/
bool V8_EXPORT ConfigureResourceConstraintsForCurrentPlatform(
ResourceConstraints* constraints);
V8_DEPRECATED("Use ResourceConstraints::ConfigureDefaults instead",
bool V8_EXPORT ConfigureResourceConstraintsForCurrentPlatform(
ResourceConstraints* constraints));
/**
* Convience function which performs SetResourceConstraints with the settings
* returned by ConfigureResourceConstraintsForCurrentPlatform.
*/
bool V8_EXPORT SetDefaultResourceConstraintsForCurrentPlatform();
V8_DEPRECATED("Use ResourceConstraints::ConfigureDefaults instead",
bool V8_EXPORT SetDefaultResourceConstraintsForCurrentPlatform());
} // namespace v8
......
......@@ -3803,6 +3803,16 @@ V8_INLINE Handle<Boolean> False(Isolate* isolate);
class V8_EXPORT ResourceConstraints {
public:
ResourceConstraints();
/**
* Configures the constraints with reasonable default values based on the
* capabilities of the current device the VM is running on.
*
* \param physical_memory The total amount of physical memory on the current
* device, in bytes.
*/
void ConfigureDefaults(uint64_t physical_memory);
int max_young_space_size() const { return max_young_space_size_; }
void set_max_young_space_size(int value) { max_young_space_size_ = value; }
int max_old_space_size() const { return max_old_space_size_; }
......
......@@ -566,6 +566,42 @@ ResourceConstraints::ResourceConstraints()
stack_limit_(NULL) { }
void ResourceConstraints::ConfigureDefaults(uint64_t physical_memory) {
const int lump_of_memory = (i::kPointerSize / 4) * i::MB;
#if V8_OS_ANDROID
// Android has higher physical memory requirements before raising the maximum
// heap size limits since it has no swap space.
const uint64_t low_limit = 512ul * i::MB;
const uint64_t medium_limit = 1ul * i::GB;
const uint64_t high_limit = 2ul * i::GB;
#else
const uint64_t low_limit = 512ul * i::MB;
const uint64_t medium_limit = 768ul * i::MB;
const uint64_t high_limit = 1ul * i::GB;
#endif
// The young_space_size should be a power of 2 and old_generation_size should
// be a multiple of Page::kPageSize.
if (physical_memory <= low_limit) {
set_max_young_space_size(2 * lump_of_memory);
set_max_old_space_size(128 * lump_of_memory);
set_max_executable_size(96 * lump_of_memory);
} else if (physical_memory <= medium_limit) {
set_max_young_space_size(8 * lump_of_memory);
set_max_old_space_size(256 * lump_of_memory);
set_max_executable_size(192 * lump_of_memory);
} else if (physical_memory <= high_limit) {
set_max_young_space_size(16 * lump_of_memory);
set_max_old_space_size(512 * lump_of_memory);
set_max_executable_size(256 * lump_of_memory);
} else {
set_max_young_space_size(16 * lump_of_memory);
set_max_old_space_size(700 * lump_of_memory);
set_max_executable_size(256 * lump_of_memory);
}
}
bool SetResourceConstraints(ResourceConstraints* constraints) {
i::Isolate* isolate = EnterIsolateIfNeeded();
return SetResourceConstraints(reinterpret_cast<Isolate*>(isolate),
......
......@@ -1679,11 +1679,13 @@ int Shell::Main(int argc, char* argv[]) {
#else
SetStandaloneFlagsViaCommandLine();
#endif
v8::SetDefaultResourceConstraintsForCurrentPlatform();
ShellArrayBufferAllocator array_buffer_allocator;
v8::V8::SetArrayBufferAllocator(&array_buffer_allocator);
int result = 0;
Isolate* isolate = Isolate::GetCurrent();
v8::ResourceConstraints constraints;
constraints.ConfigureDefaults(i::OS::TotalPhysicalMemory());
v8::SetResourceConstraints(isolate, &constraints);
DumbLineEditor dumb_line_editor(isolate);
{
Initialize(isolate);
......
......@@ -37,6 +37,7 @@
namespace v8 {
// TODO(rmcilroy): Remove this function once it is no longer used in Chrome.
bool ConfigureResourceConstraintsForCurrentPlatform(
ResourceConstraints* constraints) {
if (constraints == NULL) {
......@@ -60,6 +61,7 @@ bool ConfigureResourceConstraintsForCurrentPlatform(
}
// TODO(rmcilroy): Remove this function once it is no longer used in Chrome.
bool SetDefaultResourceConstraintsForCurrentPlatform() {
ResourceConstraints constraints;
if (!ConfigureResourceConstraintsForCurrentPlatform(&constraints))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment