*/
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
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_; }
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),
#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);
namespace v8 {
+// TODO(rmcilroy): Remove this function once it is no longer used in Chrome.
bool ConfigureResourceConstraintsForCurrentPlatform(
ResourceConstraints* constraints) {
if (constraints == NULL) {
}
+// TODO(rmcilroy): Remove this function once it is no longer used in Chrome.
bool SetDefaultResourceConstraintsForCurrentPlatform() {
ResourceConstraints constraints;
if (!ConfigureResourceConstraintsForCurrentPlatform(&constraints))