Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(369)

Side by Side Diff: src/flags.cc

Issue 890563003: Fix --max_old_space_size=4096 integer overflow. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/flag-definitions.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project 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 <cctype> 5 #include <cctype>
6 #include <cstdlib> 6 #include <cstdlib>
7 #include <sstream> 7 #include <sstream>
8 8
9 #include "src/v8.h" 9 #include "src/v8.h"
10 10
(...skipping 12 matching lines...) Expand all
23 // Define all of our flags default values. 23 // Define all of our flags default values.
24 #define FLAG_MODE_DEFINE_DEFAULTS 24 #define FLAG_MODE_DEFINE_DEFAULTS
25 #include "src/flag-definitions.h" // NOLINT 25 #include "src/flag-definitions.h" // NOLINT
26 26
27 namespace { 27 namespace {
28 28
29 // This structure represents a single entry in the flag system, with a pointer 29 // This structure represents a single entry in the flag system, with a pointer
30 // to the actual flag, default value, comment, etc. This is designed to be POD 30 // to the actual flag, default value, comment, etc. This is designed to be POD
31 // initialized as to avoid requiring static constructors. 31 // initialized as to avoid requiring static constructors.
32 struct Flag { 32 struct Flag {
33 enum FlagType { TYPE_BOOL, TYPE_MAYBE_BOOL, TYPE_INT, TYPE_FLOAT, 33 enum FlagType { TYPE_BOOL, TYPE_MAYBE_BOOL, TYPE_INT, TYPE_INTPTR,
34 TYPE_STRING, TYPE_ARGS }; 34 TYPE_FLOAT, TYPE_STRING, TYPE_ARGS };
35 35
36 FlagType type_; // What type of flag, bool, int, or string. 36 FlagType type_; // What type of flag, bool, int, or string.
37 const char* name_; // Name of the flag, ex "my_flag". 37 const char* name_; // Name of the flag, ex "my_flag".
38 void* valptr_; // Pointer to the global flag variable. 38 void* valptr_; // Pointer to the global flag variable.
39 const void* defptr_; // Pointer to the default value. 39 const void* defptr_; // Pointer to the default value.
40 const char* cmt_; // A comment about the flags purpose. 40 const char* cmt_; // A comment about the flags purpose.
41 bool owns_ptr_; // Does the flag own its string value? 41 bool owns_ptr_; // Does the flag own its string value?
42 42
43 FlagType type() const { return type_; } 43 FlagType type() const { return type_; }
44 44
45 const char* name() const { return name_; } 45 const char* name() const { return name_; }
46 46
47 const char* comment() const { return cmt_; } 47 const char* comment() const { return cmt_; }
48 48
49 bool* bool_variable() const { 49 bool* bool_variable() const {
50 DCHECK(type_ == TYPE_BOOL); 50 DCHECK(type_ == TYPE_BOOL);
51 return reinterpret_cast<bool*>(valptr_); 51 return reinterpret_cast<bool*>(valptr_);
52 } 52 }
53 53
54 MaybeBoolFlag* maybe_bool_variable() const { 54 MaybeBoolFlag* maybe_bool_variable() const {
55 DCHECK(type_ == TYPE_MAYBE_BOOL); 55 DCHECK(type_ == TYPE_MAYBE_BOOL);
56 return reinterpret_cast<MaybeBoolFlag*>(valptr_); 56 return reinterpret_cast<MaybeBoolFlag*>(valptr_);
57 } 57 }
58 58
59 int* int_variable() const { 59 int* int_variable() const {
60 DCHECK(type_ == TYPE_INT); 60 DCHECK(type_ == TYPE_INT);
61 return reinterpret_cast<int*>(valptr_); 61 return reinterpret_cast<int*>(valptr_);
62 } 62 }
63 63
64 intptr_t* intptr_variable() const {
65 DCHECK(type_ == TYPE_INTPTR);
66 return reinterpret_cast<intptr_t*>(valptr_);
67 }
68
64 double* float_variable() const { 69 double* float_variable() const {
65 DCHECK(type_ == TYPE_FLOAT); 70 DCHECK(type_ == TYPE_FLOAT);
66 return reinterpret_cast<double*>(valptr_); 71 return reinterpret_cast<double*>(valptr_);
67 } 72 }
68 73
69 const char* string_value() const { 74 const char* string_value() const {
70 DCHECK(type_ == TYPE_STRING); 75 DCHECK(type_ == TYPE_STRING);
71 return *reinterpret_cast<const char**>(valptr_); 76 return *reinterpret_cast<const char**>(valptr_);
72 } 77 }
73 78
(...skipping 13 matching lines...) Expand all
87 bool bool_default() const { 92 bool bool_default() const {
88 DCHECK(type_ == TYPE_BOOL); 93 DCHECK(type_ == TYPE_BOOL);
89 return *reinterpret_cast<const bool*>(defptr_); 94 return *reinterpret_cast<const bool*>(defptr_);
90 } 95 }
91 96
92 int int_default() const { 97 int int_default() const {
93 DCHECK(type_ == TYPE_INT); 98 DCHECK(type_ == TYPE_INT);
94 return *reinterpret_cast<const int*>(defptr_); 99 return *reinterpret_cast<const int*>(defptr_);
95 } 100 }
96 101
102 int intptr_default() const {
103 DCHECK(type_ == TYPE_INTPTR);
104 return *reinterpret_cast<const intptr_t*>(defptr_);
105 }
106
97 double float_default() const { 107 double float_default() const {
98 DCHECK(type_ == TYPE_FLOAT); 108 DCHECK(type_ == TYPE_FLOAT);
99 return *reinterpret_cast<const double*>(defptr_); 109 return *reinterpret_cast<const double*>(defptr_);
100 } 110 }
101 111
102 const char* string_default() const { 112 const char* string_default() const {
103 DCHECK(type_ == TYPE_STRING); 113 DCHECK(type_ == TYPE_STRING);
104 return *reinterpret_cast<const char* const *>(defptr_); 114 return *reinterpret_cast<const char* const *>(defptr_);
105 } 115 }
106 116
107 JSArguments args_default() const { 117 JSArguments args_default() const {
108 DCHECK(type_ == TYPE_ARGS); 118 DCHECK(type_ == TYPE_ARGS);
109 return *reinterpret_cast<const JSArguments*>(defptr_); 119 return *reinterpret_cast<const JSArguments*>(defptr_);
110 } 120 }
111 121
112 // Compare this flag's current value against the default. 122 // Compare this flag's current value against the default.
113 bool IsDefault() const { 123 bool IsDefault() const {
114 switch (type_) { 124 switch (type_) {
115 case TYPE_BOOL: 125 case TYPE_BOOL:
116 return *bool_variable() == bool_default(); 126 return *bool_variable() == bool_default();
117 case TYPE_MAYBE_BOOL: 127 case TYPE_MAYBE_BOOL:
118 return maybe_bool_variable()->has_value == false; 128 return maybe_bool_variable()->has_value == false;
119 case TYPE_INT: 129 case TYPE_INT:
120 return *int_variable() == int_default(); 130 return *int_variable() == int_default();
131 case TYPE_INTPTR:
132 return *intptr_variable() == intptr_default();
121 case TYPE_FLOAT: 133 case TYPE_FLOAT:
122 return *float_variable() == float_default(); 134 return *float_variable() == float_default();
123 case TYPE_STRING: { 135 case TYPE_STRING: {
124 const char* str1 = string_value(); 136 const char* str1 = string_value();
125 const char* str2 = string_default(); 137 const char* str2 = string_default();
126 if (str2 == NULL) return str1 == NULL; 138 if (str2 == NULL) return str1 == NULL;
127 if (str1 == NULL) return str2 == NULL; 139 if (str1 == NULL) return str2 == NULL;
128 return strcmp(str1, str2) == 0; 140 return strcmp(str1, str2) == 0;
129 } 141 }
130 case TYPE_ARGS: 142 case TYPE_ARGS:
131 return args_variable()->argc == 0; 143 return args_variable()->argc == 0;
132 } 144 }
133 UNREACHABLE(); 145 UNREACHABLE();
134 return true; 146 return true;
135 } 147 }
136 148
137 // Set a flag back to it's default value. 149 // Set a flag back to it's default value.
138 void Reset() { 150 void Reset() {
139 switch (type_) { 151 switch (type_) {
140 case TYPE_BOOL: 152 case TYPE_BOOL:
141 *bool_variable() = bool_default(); 153 *bool_variable() = bool_default();
142 break; 154 break;
143 case TYPE_MAYBE_BOOL: 155 case TYPE_MAYBE_BOOL:
144 *maybe_bool_variable() = MaybeBoolFlag::Create(false, false); 156 *maybe_bool_variable() = MaybeBoolFlag::Create(false, false);
145 break; 157 break;
146 case TYPE_INT: 158 case TYPE_INT:
147 *int_variable() = int_default(); 159 *int_variable() = int_default();
148 break; 160 break;
161 case TYPE_INTPTR:
162 *intptr_variable() = intptr_default();
163 break;
149 case TYPE_FLOAT: 164 case TYPE_FLOAT:
150 *float_variable() = float_default(); 165 *float_variable() = float_default();
151 break; 166 break;
152 case TYPE_STRING: 167 case TYPE_STRING:
153 set_string_value(string_default(), false); 168 set_string_value(string_default(), false);
154 break; 169 break;
155 case TYPE_ARGS: 170 case TYPE_ARGS:
156 *args_variable() = args_default(); 171 *args_variable() = args_default();
157 break; 172 break;
158 } 173 }
159 } 174 }
160 }; 175 };
161 176
162 Flag flags[] = { 177 Flag flags[] = {
163 #define FLAG_MODE_META 178 #define FLAG_MODE_META
164 #include "src/flag-definitions.h" 179 #include "src/flag-definitions.h"
165 }; 180 };
166 181
167 const size_t num_flags = sizeof(flags) / sizeof(*flags); 182 const size_t num_flags = sizeof(flags) / sizeof(*flags);
168 183
169 } // namespace 184 } // namespace
170 185
171 186
172 static const char* Type2String(Flag::FlagType type) { 187 static const char* Type2String(Flag::FlagType type) {
173 switch (type) { 188 switch (type) {
174 case Flag::TYPE_BOOL: return "bool"; 189 case Flag::TYPE_BOOL: return "bool";
175 case Flag::TYPE_MAYBE_BOOL: return "maybe_bool"; 190 case Flag::TYPE_MAYBE_BOOL: return "maybe_bool";
176 case Flag::TYPE_INT: return "int"; 191 case Flag::TYPE_INT: return "int";
192 case Flag::TYPE_INTPTR: return "intptr_t";
177 case Flag::TYPE_FLOAT: return "float"; 193 case Flag::TYPE_FLOAT: return "float";
178 case Flag::TYPE_STRING: return "string"; 194 case Flag::TYPE_STRING: return "string";
179 case Flag::TYPE_ARGS: return "arguments"; 195 case Flag::TYPE_ARGS: return "arguments";
180 } 196 }
181 UNREACHABLE(); 197 UNREACHABLE();
182 return NULL; 198 return NULL;
183 } 199 }
184 200
185 201
186 std::ostream& operator<<(std::ostream& os, const Flag& flag) { // NOLINT 202 std::ostream& operator<<(std::ostream& os, const Flag& flag) { // NOLINT
187 switch (flag.type()) { 203 switch (flag.type()) {
188 case Flag::TYPE_BOOL: 204 case Flag::TYPE_BOOL:
189 os << (*flag.bool_variable() ? "true" : "false"); 205 os << (*flag.bool_variable() ? "true" : "false");
190 break; 206 break;
191 case Flag::TYPE_MAYBE_BOOL: 207 case Flag::TYPE_MAYBE_BOOL:
192 os << (flag.maybe_bool_variable()->has_value 208 os << (flag.maybe_bool_variable()->has_value
193 ? (flag.maybe_bool_variable()->value ? "true" : "false") 209 ? (flag.maybe_bool_variable()->value ? "true" : "false")
194 : "unset"); 210 : "unset");
195 break; 211 break;
196 case Flag::TYPE_INT: 212 case Flag::TYPE_INT:
197 os << *flag.int_variable(); 213 os << *flag.int_variable();
198 break; 214 break;
215 case Flag::TYPE_INTPTR:
216 os << *flag.intptr_variable();
217 break;
199 case Flag::TYPE_FLOAT: 218 case Flag::TYPE_FLOAT:
200 os << *flag.float_variable(); 219 os << *flag.float_variable();
201 break; 220 break;
202 case Flag::TYPE_STRING: { 221 case Flag::TYPE_STRING: {
203 const char* str = flag.string_value(); 222 const char* str = flag.string_value();
204 os << (str ? str : "NULL"); 223 os << (str ? str : "NULL");
205 break; 224 break;
206 } 225 }
207 case Flag::TYPE_ARGS: { 226 case Flag::TYPE_ARGS: {
208 JSArguments args = *flag.args_variable(); 227 JSArguments args = *flag.args_variable();
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 switch (flag->type()) { 408 switch (flag->type()) {
390 case Flag::TYPE_BOOL: 409 case Flag::TYPE_BOOL:
391 *flag->bool_variable() = !is_bool; 410 *flag->bool_variable() = !is_bool;
392 break; 411 break;
393 case Flag::TYPE_MAYBE_BOOL: 412 case Flag::TYPE_MAYBE_BOOL:
394 *flag->maybe_bool_variable() = MaybeBoolFlag::Create(true, !is_bool); 413 *flag->maybe_bool_variable() = MaybeBoolFlag::Create(true, !is_bool);
395 break; 414 break;
396 case Flag::TYPE_INT: 415 case Flag::TYPE_INT:
397 *flag->int_variable() = strtol(value, &endp, 10); // NOLINT 416 *flag->int_variable() = strtol(value, &endp, 10); // NOLINT
398 break; 417 break;
418 case Flag::TYPE_INTPTR:
419 // TODO(bnoordhuis) Use strtoll()? C++11 library feature
420 // that may not be available everywhere yet.
421 *flag->intptr_variable() = strtol(value, &endp, 10); // NOLINT
422 break;
399 case Flag::TYPE_FLOAT: 423 case Flag::TYPE_FLOAT:
400 *flag->float_variable() = strtod(value, &endp); 424 *flag->float_variable() = strtod(value, &endp);
401 break; 425 break;
402 case Flag::TYPE_STRING: 426 case Flag::TYPE_STRING:
403 flag->set_string_value(value ? StrDup(value) : NULL, true); 427 flag->set_string_value(value ? StrDup(value) : NULL, true);
404 break; 428 break;
405 case Flag::TYPE_ARGS: { 429 case Flag::TYPE_ARGS: {
406 int start_pos = (value == NULL) ? i : i - 1; 430 int start_pos = (value == NULL) ? i : i - 1;
407 int js_argc = *argc - start_pos; 431 int js_argc = *argc - start_pos;
408 const char** js_argv = NewArray<const char*>(js_argc); 432 const char** js_argv = NewArray<const char*>(js_argc);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 Flag* current = &flags[i]; 581 Flag* current = &flags[i];
558 if (!current->IsDefault()) { 582 if (!current->IsDefault()) {
559 modified_args_as_string << *current; 583 modified_args_as_string << *current;
560 } 584 }
561 } 585 }
562 std::string args(modified_args_as_string.str()); 586 std::string args(modified_args_as_string.str());
563 return static_cast<uint32_t>( 587 return static_cast<uint32_t>(
564 base::hash_range(args.c_str(), args.c_str() + args.length())); 588 base::hash_range(args.c_str(), args.c_str() + args.length()));
565 } 589 }
566 } } // namespace v8::internal 590 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/flag-definitions.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698