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

Side by Side Diff: src/flags.cc

Issue 875053005: Revert of 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_INTPTR, 33 enum FlagType { TYPE_BOOL, TYPE_MAYBE_BOOL, TYPE_INT, TYPE_FLOAT,
34 TYPE_FLOAT, TYPE_STRING, TYPE_ARGS }; 34 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
69 double* float_variable() const { 64 double* float_variable() const {
70 DCHECK(type_ == TYPE_FLOAT); 65 DCHECK(type_ == TYPE_FLOAT);
71 return reinterpret_cast<double*>(valptr_); 66 return reinterpret_cast<double*>(valptr_);
72 } 67 }
73 68
74 const char* string_value() const { 69 const char* string_value() const {
75 DCHECK(type_ == TYPE_STRING); 70 DCHECK(type_ == TYPE_STRING);
76 return *reinterpret_cast<const char**>(valptr_); 71 return *reinterpret_cast<const char**>(valptr_);
77 } 72 }
78 73
(...skipping 13 matching lines...) Expand all
92 bool bool_default() const { 87 bool bool_default() const {
93 DCHECK(type_ == TYPE_BOOL); 88 DCHECK(type_ == TYPE_BOOL);
94 return *reinterpret_cast<const bool*>(defptr_); 89 return *reinterpret_cast<const bool*>(defptr_);
95 } 90 }
96 91
97 int int_default() const { 92 int int_default() const {
98 DCHECK(type_ == TYPE_INT); 93 DCHECK(type_ == TYPE_INT);
99 return *reinterpret_cast<const int*>(defptr_); 94 return *reinterpret_cast<const int*>(defptr_);
100 } 95 }
101 96
102 int intptr_default() const {
103 DCHECK(type_ == TYPE_INTPTR);
104 return *reinterpret_cast<const intptr_t*>(defptr_);
105 }
106
107 double float_default() const { 97 double float_default() const {
108 DCHECK(type_ == TYPE_FLOAT); 98 DCHECK(type_ == TYPE_FLOAT);
109 return *reinterpret_cast<const double*>(defptr_); 99 return *reinterpret_cast<const double*>(defptr_);
110 } 100 }
111 101
112 const char* string_default() const { 102 const char* string_default() const {
113 DCHECK(type_ == TYPE_STRING); 103 DCHECK(type_ == TYPE_STRING);
114 return *reinterpret_cast<const char* const *>(defptr_); 104 return *reinterpret_cast<const char* const *>(defptr_);
115 } 105 }
116 106
117 JSArguments args_default() const { 107 JSArguments args_default() const {
118 DCHECK(type_ == TYPE_ARGS); 108 DCHECK(type_ == TYPE_ARGS);
119 return *reinterpret_cast<const JSArguments*>(defptr_); 109 return *reinterpret_cast<const JSArguments*>(defptr_);
120 } 110 }
121 111
122 // Compare this flag's current value against the default. 112 // Compare this flag's current value against the default.
123 bool IsDefault() const { 113 bool IsDefault() const {
124 switch (type_) { 114 switch (type_) {
125 case TYPE_BOOL: 115 case TYPE_BOOL:
126 return *bool_variable() == bool_default(); 116 return *bool_variable() == bool_default();
127 case TYPE_MAYBE_BOOL: 117 case TYPE_MAYBE_BOOL:
128 return maybe_bool_variable()->has_value == false; 118 return maybe_bool_variable()->has_value == false;
129 case TYPE_INT: 119 case TYPE_INT:
130 return *int_variable() == int_default(); 120 return *int_variable() == int_default();
131 case TYPE_INTPTR:
132 return *intptr_variable() == intptr_default();
133 case TYPE_FLOAT: 121 case TYPE_FLOAT:
134 return *float_variable() == float_default(); 122 return *float_variable() == float_default();
135 case TYPE_STRING: { 123 case TYPE_STRING: {
136 const char* str1 = string_value(); 124 const char* str1 = string_value();
137 const char* str2 = string_default(); 125 const char* str2 = string_default();
138 if (str2 == NULL) return str1 == NULL; 126 if (str2 == NULL) return str1 == NULL;
139 if (str1 == NULL) return str2 == NULL; 127 if (str1 == NULL) return str2 == NULL;
140 return strcmp(str1, str2) == 0; 128 return strcmp(str1, str2) == 0;
141 } 129 }
142 case TYPE_ARGS: 130 case TYPE_ARGS:
143 return args_variable()->argc == 0; 131 return args_variable()->argc == 0;
144 } 132 }
145 UNREACHABLE(); 133 UNREACHABLE();
146 return true; 134 return true;
147 } 135 }
148 136
149 // Set a flag back to it's default value. 137 // Set a flag back to it's default value.
150 void Reset() { 138 void Reset() {
151 switch (type_) { 139 switch (type_) {
152 case TYPE_BOOL: 140 case TYPE_BOOL:
153 *bool_variable() = bool_default(); 141 *bool_variable() = bool_default();
154 break; 142 break;
155 case TYPE_MAYBE_BOOL: 143 case TYPE_MAYBE_BOOL:
156 *maybe_bool_variable() = MaybeBoolFlag::Create(false, false); 144 *maybe_bool_variable() = MaybeBoolFlag::Create(false, false);
157 break; 145 break;
158 case TYPE_INT: 146 case TYPE_INT:
159 *int_variable() = int_default(); 147 *int_variable() = int_default();
160 break; 148 break;
161 case TYPE_INTPTR:
162 *intptr_variable() = intptr_default();
163 break;
164 case TYPE_FLOAT: 149 case TYPE_FLOAT:
165 *float_variable() = float_default(); 150 *float_variable() = float_default();
166 break; 151 break;
167 case TYPE_STRING: 152 case TYPE_STRING:
168 set_string_value(string_default(), false); 153 set_string_value(string_default(), false);
169 break; 154 break;
170 case TYPE_ARGS: 155 case TYPE_ARGS:
171 *args_variable() = args_default(); 156 *args_variable() = args_default();
172 break; 157 break;
173 } 158 }
174 } 159 }
175 }; 160 };
176 161
177 Flag flags[] = { 162 Flag flags[] = {
178 #define FLAG_MODE_META 163 #define FLAG_MODE_META
179 #include "src/flag-definitions.h" 164 #include "src/flag-definitions.h"
180 }; 165 };
181 166
182 const size_t num_flags = sizeof(flags) / sizeof(*flags); 167 const size_t num_flags = sizeof(flags) / sizeof(*flags);
183 168
184 } // namespace 169 } // namespace
185 170
186 171
187 static const char* Type2String(Flag::FlagType type) { 172 static const char* Type2String(Flag::FlagType type) {
188 switch (type) { 173 switch (type) {
189 case Flag::TYPE_BOOL: return "bool"; 174 case Flag::TYPE_BOOL: return "bool";
190 case Flag::TYPE_MAYBE_BOOL: return "maybe_bool"; 175 case Flag::TYPE_MAYBE_BOOL: return "maybe_bool";
191 case Flag::TYPE_INT: return "int"; 176 case Flag::TYPE_INT: return "int";
192 case Flag::TYPE_INTPTR: return "intptr_t";
193 case Flag::TYPE_FLOAT: return "float"; 177 case Flag::TYPE_FLOAT: return "float";
194 case Flag::TYPE_STRING: return "string"; 178 case Flag::TYPE_STRING: return "string";
195 case Flag::TYPE_ARGS: return "arguments"; 179 case Flag::TYPE_ARGS: return "arguments";
196 } 180 }
197 UNREACHABLE(); 181 UNREACHABLE();
198 return NULL; 182 return NULL;
199 } 183 }
200 184
201 185
202 std::ostream& operator<<(std::ostream& os, const Flag& flag) { // NOLINT 186 std::ostream& operator<<(std::ostream& os, const Flag& flag) { // NOLINT
203 switch (flag.type()) { 187 switch (flag.type()) {
204 case Flag::TYPE_BOOL: 188 case Flag::TYPE_BOOL:
205 os << (*flag.bool_variable() ? "true" : "false"); 189 os << (*flag.bool_variable() ? "true" : "false");
206 break; 190 break;
207 case Flag::TYPE_MAYBE_BOOL: 191 case Flag::TYPE_MAYBE_BOOL:
208 os << (flag.maybe_bool_variable()->has_value 192 os << (flag.maybe_bool_variable()->has_value
209 ? (flag.maybe_bool_variable()->value ? "true" : "false") 193 ? (flag.maybe_bool_variable()->value ? "true" : "false")
210 : "unset"); 194 : "unset");
211 break; 195 break;
212 case Flag::TYPE_INT: 196 case Flag::TYPE_INT:
213 os << *flag.int_variable(); 197 os << *flag.int_variable();
214 break; 198 break;
215 case Flag::TYPE_INTPTR:
216 os << *flag.intptr_variable();
217 break;
218 case Flag::TYPE_FLOAT: 199 case Flag::TYPE_FLOAT:
219 os << *flag.float_variable(); 200 os << *flag.float_variable();
220 break; 201 break;
221 case Flag::TYPE_STRING: { 202 case Flag::TYPE_STRING: {
222 const char* str = flag.string_value(); 203 const char* str = flag.string_value();
223 os << (str ? str : "NULL"); 204 os << (str ? str : "NULL");
224 break; 205 break;
225 } 206 }
226 case Flag::TYPE_ARGS: { 207 case Flag::TYPE_ARGS: {
227 JSArguments args = *flag.args_variable(); 208 JSArguments args = *flag.args_variable();
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 switch (flag->type()) { 389 switch (flag->type()) {
409 case Flag::TYPE_BOOL: 390 case Flag::TYPE_BOOL:
410 *flag->bool_variable() = !is_bool; 391 *flag->bool_variable() = !is_bool;
411 break; 392 break;
412 case Flag::TYPE_MAYBE_BOOL: 393 case Flag::TYPE_MAYBE_BOOL:
413 *flag->maybe_bool_variable() = MaybeBoolFlag::Create(true, !is_bool); 394 *flag->maybe_bool_variable() = MaybeBoolFlag::Create(true, !is_bool);
414 break; 395 break;
415 case Flag::TYPE_INT: 396 case Flag::TYPE_INT:
416 *flag->int_variable() = strtol(value, &endp, 10); // NOLINT 397 *flag->int_variable() = strtol(value, &endp, 10); // NOLINT
417 break; 398 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;
423 case Flag::TYPE_FLOAT: 399 case Flag::TYPE_FLOAT:
424 *flag->float_variable() = strtod(value, &endp); 400 *flag->float_variable() = strtod(value, &endp);
425 break; 401 break;
426 case Flag::TYPE_STRING: 402 case Flag::TYPE_STRING:
427 flag->set_string_value(value ? StrDup(value) : NULL, true); 403 flag->set_string_value(value ? StrDup(value) : NULL, true);
428 break; 404 break;
429 case Flag::TYPE_ARGS: { 405 case Flag::TYPE_ARGS: {
430 int start_pos = (value == NULL) ? i : i - 1; 406 int start_pos = (value == NULL) ? i : i - 1;
431 int js_argc = *argc - start_pos; 407 int js_argc = *argc - start_pos;
432 const char** js_argv = NewArray<const char*>(js_argc); 408 const char** js_argv = NewArray<const char*>(js_argc);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 Flag* current = &flags[i]; 557 Flag* current = &flags[i];
582 if (!current->IsDefault()) { 558 if (!current->IsDefault()) {
583 modified_args_as_string << *current; 559 modified_args_as_string << *current;
584 } 560 }
585 } 561 }
586 std::string args(modified_args_as_string.str()); 562 std::string args(modified_args_as_string.str());
587 return static_cast<uint32_t>( 563 return static_cast<uint32_t>(
588 base::hash_range(args.c_str(), args.c_str() + args.length())); 564 base::hash_range(args.c_str(), args.c_str() + args.length()));
589 } 565 }
590 } } // namespace v8::internal 566 } } // 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