From 6253aa8908c55535473ddbe1db8e5a6f5e559b73 Mon Sep 17 00:00:00 2001 From: Yang Guo Date: Sat, 31 Jan 2015 21:45:28 +0100 Subject: [PATCH] Fix --max_old_space_size=4096 integer overflow. R=yangguo@chromium.org Review URL: https://codereview.chromium.org/890563003 Cr-Commit-Position: refs/heads/master@{#26371} --- src/flag-definitions.h | 28 +++++++++++++++------------- src/flags.cc | 28 ++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/src/flag-definitions.h b/src/flag-definitions.h index 5ccd47fbc..1548aa848 100644 --- a/src/flag-definitions.h +++ b/src/flag-definitions.h @@ -151,6 +151,7 @@ struct MaybeBoolFlag { #define DEFINE_MAYBE_BOOL(nam, cmt) \ FLAG(MAYBE_BOOL, MaybeBoolFlag, nam, {false COMMA false}, cmt) #define DEFINE_INT(nam, def, cmt) FLAG(INT, int, nam, def, cmt) +#define DEFINE_INTPTR(nam, def, cmt) FLAG(INTPTR, intptr_t, nam, def, cmt) #define DEFINE_FLOAT(nam, def, cmt) FLAG(FLOAT, double, nam, def, cmt) #define DEFINE_STRING(nam, def, cmt) FLAG(STRING, const char*, nam, def, cmt) #define DEFINE_ARGS(nam, cmt) FLAG(ARGS, JSArguments, nam, {0 COMMA NULL}, cmt) @@ -542,8 +543,8 @@ DEFINE_BOOL(enable_liveedit, true, "enable liveedit experimental feature") DEFINE_BOOL(hard_abort, true, "abort by crashing") // execution.cc -DEFINE_INT(stack_size, V8_DEFAULT_STACK_SIZE_KB, - "default size of stack region v8 is allowed to use (in kBytes)") +DEFINE_INTPTR(stack_size, V8_DEFAULT_STACK_SIZE_KB, + "default size of stack region v8 is allowed to use (in kBytes)") // frames.cc DEFINE_INT(max_stack_trace_source_length, 300, @@ -554,21 +555,22 @@ DEFINE_BOOL(always_inline_smi_code, false, "always inline smi code in non-opt code") // heap.cc -DEFINE_INT(min_semi_space_size, 0, - "min size of a semi-space (in MBytes), the new space consists of two" - "semi-spaces") -DEFINE_INT(target_semi_space_size, 0, - "target size of a semi-space (in MBytes) before triggering a GC") -DEFINE_INT(max_semi_space_size, 0, - "max size of a semi-space (in MBytes), the new space consists of two" - "semi-spaces") +DEFINE_INTPTR(min_semi_space_size, 0, + "min size of a semi-space (in MBytes), the new space consists " + "of two semi-spaces") +DEFINE_INTPTR(target_semi_space_size, 0, + "target size of a semi-space (in MBytes) before triggering a GC") +DEFINE_INTPTR(max_semi_space_size, 0, + "max size of a semi-space (in MBytes), the new space consists " + "of two semi-spaces") DEFINE_INT(semi_space_growth_factor, 2, "factor by which to grow the new space") DEFINE_BOOL(experimental_new_space_growth_heuristic, false, "Grow the new space based on the percentage of survivors instead " "of their absolute value.") -DEFINE_INT(max_old_space_size, 0, "max size of the old space (in Mbytes)") -DEFINE_INT(initial_old_space_size, 0, "initial old space size (in Mbytes)") -DEFINE_INT(max_executable_size, 0, "max size of executable memory (in Mbytes)") +DEFINE_INTPTR(max_old_space_size, 0, "max size of the old space (in Mbytes)") +DEFINE_INTPTR(initial_old_space_size, 0, "initial old space size (in Mbytes)") +DEFINE_INTPTR(max_executable_size, 0, + "max size of executable memory (in Mbytes)") DEFINE_BOOL(gc_global, false, "always perform global GCs") DEFINE_INT(gc_interval, -1, "garbage collect after allocations") DEFINE_BOOL(trace_gc, false, diff --git a/src/flags.cc b/src/flags.cc index 2aa4e6bd4..15836da78 100644 --- a/src/flags.cc +++ b/src/flags.cc @@ -30,8 +30,8 @@ namespace { // to the actual flag, default value, comment, etc. This is designed to be POD // initialized as to avoid requiring static constructors. struct Flag { - enum FlagType { TYPE_BOOL, TYPE_MAYBE_BOOL, TYPE_INT, TYPE_FLOAT, - TYPE_STRING, TYPE_ARGS }; + enum FlagType { TYPE_BOOL, TYPE_MAYBE_BOOL, TYPE_INT, TYPE_INTPTR, + TYPE_FLOAT, TYPE_STRING, TYPE_ARGS }; FlagType type_; // What type of flag, bool, int, or string. const char* name_; // Name of the flag, ex "my_flag". @@ -61,6 +61,11 @@ struct Flag { return reinterpret_cast(valptr_); } + intptr_t* intptr_variable() const { + DCHECK(type_ == TYPE_INTPTR); + return reinterpret_cast(valptr_); + } + double* float_variable() const { DCHECK(type_ == TYPE_FLOAT); return reinterpret_cast(valptr_); @@ -94,6 +99,11 @@ struct Flag { return *reinterpret_cast(defptr_); } + int intptr_default() const { + DCHECK(type_ == TYPE_INTPTR); + return *reinterpret_cast(defptr_); + } + double float_default() const { DCHECK(type_ == TYPE_FLOAT); return *reinterpret_cast(defptr_); @@ -118,6 +128,8 @@ struct Flag { return maybe_bool_variable()->has_value == false; case TYPE_INT: return *int_variable() == int_default(); + case TYPE_INTPTR: + return *intptr_variable() == intptr_default(); case TYPE_FLOAT: return *float_variable() == float_default(); case TYPE_STRING: { @@ -146,6 +158,9 @@ struct Flag { case TYPE_INT: *int_variable() = int_default(); break; + case TYPE_INTPTR: + *intptr_variable() = intptr_default(); + break; case TYPE_FLOAT: *float_variable() = float_default(); break; @@ -174,6 +189,7 @@ static const char* Type2String(Flag::FlagType type) { case Flag::TYPE_BOOL: return "bool"; case Flag::TYPE_MAYBE_BOOL: return "maybe_bool"; case Flag::TYPE_INT: return "int"; + case Flag::TYPE_INTPTR: return "intptr_t"; case Flag::TYPE_FLOAT: return "float"; case Flag::TYPE_STRING: return "string"; case Flag::TYPE_ARGS: return "arguments"; @@ -196,6 +212,9 @@ std::ostream& operator<<(std::ostream& os, const Flag& flag) { // NOLINT case Flag::TYPE_INT: os << *flag.int_variable(); break; + case Flag::TYPE_INTPTR: + os << *flag.intptr_variable(); + break; case Flag::TYPE_FLOAT: os << *flag.float_variable(); break; @@ -396,6 +415,11 @@ int FlagList::SetFlagsFromCommandLine(int* argc, case Flag::TYPE_INT: *flag->int_variable() = strtol(value, &endp, 10); // NOLINT break; + case Flag::TYPE_INTPTR: + // TODO(bnoordhuis) Use strtoll()? C++11 library feature + // that may not be available everywhere yet. + *flag->intptr_variable() = strtol(value, &endp, 10); // NOLINT + break; case Flag::TYPE_FLOAT: *flag->float_variable() = strtod(value, &endp); break; -- 2.34.1