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

Side by Side Diff: src/types-inl.h

Issue 577563002: Re-reland "Use unsigned type bitsets to limit undefined behaviour" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « src/types.cc ('k') | test/cctest/test-types.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 #ifndef V8_TYPES_INL_H_ 5 #ifndef V8_TYPES_INL_H_
6 #define V8_TYPES_INL_H_ 6 #define V8_TYPES_INL_H_
7 7
8 #include "src/types.h" 8 #include "src/types.h"
9 9
10 #include "src/factory.h" 10 #include "src/factory.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 // static 64 // static
65 template<class T> 65 template<class T>
66 T* ZoneTypeConfig::cast(Type* type) { 66 T* ZoneTypeConfig::cast(Type* type) {
67 return static_cast<T*>(type); 67 return static_cast<T*>(type);
68 } 68 }
69 69
70 70
71 // static 71 // static
72 bool ZoneTypeConfig::is_bitset(Type* type) { 72 bool ZoneTypeConfig::is_bitset(Type* type) {
73 return reinterpret_cast<intptr_t>(type) & 1; 73 return reinterpret_cast<uintptr_t>(type) & 1;
74 } 74 }
75 75
76 76
77 // static 77 // static
78 bool ZoneTypeConfig::is_struct(Type* type, int tag) { 78 bool ZoneTypeConfig::is_struct(Type* type, int tag) {
79 return !is_bitset(type) && struct_tag(as_struct(type)) == tag; 79 return !is_bitset(type) && struct_tag(as_struct(type)) == tag;
80 } 80 }
81 81
82 82
83 // static 83 // static
84 bool ZoneTypeConfig::is_class(Type* type) { 84 bool ZoneTypeConfig::is_class(Type* type) {
85 return false; 85 return false;
86 } 86 }
87 87
88 88
89 // static 89 // static
90 int ZoneTypeConfig::as_bitset(Type* type) { 90 ZoneTypeConfig::Type::bitset ZoneTypeConfig::as_bitset(Type* type) {
91 DCHECK(is_bitset(type)); 91 DCHECK(is_bitset(type));
92 return static_cast<int>(reinterpret_cast<intptr_t>(type) >> 1); 92 return static_cast<Type::bitset>(reinterpret_cast<uintptr_t>(type) ^ 1u);
93 } 93 }
94 94
95 95
96 // static 96 // static
97 ZoneTypeConfig::Struct* ZoneTypeConfig::as_struct(Type* type) { 97 ZoneTypeConfig::Struct* ZoneTypeConfig::as_struct(Type* type) {
98 DCHECK(!is_bitset(type)); 98 DCHECK(!is_bitset(type));
99 return reinterpret_cast<Struct*>(type); 99 return reinterpret_cast<Struct*>(type);
100 } 100 }
101 101
102 102
103 // static 103 // static
104 i::Handle<i::Map> ZoneTypeConfig::as_class(Type* type) { 104 i::Handle<i::Map> ZoneTypeConfig::as_class(Type* type) {
105 UNREACHABLE(); 105 UNREACHABLE();
106 return i::Handle<i::Map>(); 106 return i::Handle<i::Map>();
107 } 107 }
108 108
109 109
110 // static 110 // static
111 ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(int bitset) { 111 ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(Type::bitset bitset) {
112 return reinterpret_cast<Type*>((bitset << 1) | 1); 112 return reinterpret_cast<Type*>(static_cast<uintptr_t>(bitset | 1u));
113 } 113 }
114 114
115 115
116 // static 116 // static
117 ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(int bitset, Zone* Zone) { 117 ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(
118 Type::bitset bitset, Zone* Zone) {
118 return from_bitset(bitset); 119 return from_bitset(bitset);
119 } 120 }
120 121
121 122
122 // static 123 // static
123 ZoneTypeConfig::Type* ZoneTypeConfig::from_struct(Struct* structure) { 124 ZoneTypeConfig::Type* ZoneTypeConfig::from_struct(Struct* structure) {
124 return reinterpret_cast<Type*>(structure); 125 return reinterpret_cast<Type*>(structure);
125 } 126 }
126 127
127 128
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } 223 }
223 224
224 225
225 // static 226 // static
226 bool HeapTypeConfig::is_struct(Type* type, int tag) { 227 bool HeapTypeConfig::is_struct(Type* type, int tag) {
227 return type->IsFixedArray() && struct_tag(as_struct(type)) == tag; 228 return type->IsFixedArray() && struct_tag(as_struct(type)) == tag;
228 } 229 }
229 230
230 231
231 // static 232 // static
232 int HeapTypeConfig::as_bitset(Type* type) { 233 HeapTypeConfig::Type::bitset HeapTypeConfig::as_bitset(Type* type) {
233 return i::Smi::cast(type)->value(); 234 // TODO(rossberg): Breaks the Smi abstraction. Fix once there is a better way.
235 return static_cast<Type::bitset>(reinterpret_cast<uintptr_t>(type));
234 } 236 }
235 237
236 238
237 // static 239 // static
238 i::Handle<i::Map> HeapTypeConfig::as_class(Type* type) { 240 i::Handle<i::Map> HeapTypeConfig::as_class(Type* type) {
239 return i::handle(i::Map::cast(type)); 241 return i::handle(i::Map::cast(type));
240 } 242 }
241 243
242 244
243 // static 245 // static
244 i::Handle<HeapTypeConfig::Struct> HeapTypeConfig::as_struct(Type* type) { 246 i::Handle<HeapTypeConfig::Struct> HeapTypeConfig::as_struct(Type* type) {
245 return i::handle(Struct::cast(type)); 247 return i::handle(Struct::cast(type));
246 } 248 }
247 249
248 250
249 // static 251 // static
250 HeapTypeConfig::Type* HeapTypeConfig::from_bitset(int bitset) { 252 HeapTypeConfig::Type* HeapTypeConfig::from_bitset(Type::bitset bitset) {
251 return Type::cast(i::Smi::FromInt(bitset)); 253 // TODO(rossberg): Breaks the Smi abstraction. Fix once there is a better way.
254 return reinterpret_cast<Type*>(static_cast<uintptr_t>(bitset));
252 } 255 }
253 256
254 257
255 // static 258 // static
256 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_bitset( 259 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_bitset(
257 int bitset, Isolate* isolate) { 260 Type::bitset bitset, Isolate* isolate) {
258 return i::handle(from_bitset(bitset), isolate); 261 return i::handle(from_bitset(bitset), isolate);
259 } 262 }
260 263
261 264
262 // static 265 // static
263 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_class( 266 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_class(
264 i::Handle<i::Map> map, Isolate* isolate) { 267 i::Handle<i::Map> map, Isolate* isolate) {
265 return i::Handle<Type>::cast(i::Handle<Object>::cast(map)); 268 return i::Handle<Type>::cast(i::Handle<Object>::cast(map));
266 } 269 }
267 270
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 // static 330 // static
328 template<class V> 331 template<class V>
329 void HeapTypeConfig::struct_set_value( 332 void HeapTypeConfig::struct_set_value(
330 i::Handle<Struct> structure, int i, i::Handle<V> x) { 333 i::Handle<Struct> structure, int i, i::Handle<V> x) {
331 structure->set(i + 1, *x); 334 structure->set(i + 1, *x);
332 } 335 }
333 336
334 } } // namespace v8::internal 337 } } // namespace v8::internal
335 338
336 #endif // V8_TYPES_INL_H_ 339 #endif // V8_TYPES_INL_H_
OLDNEW
« no previous file with comments | « src/types.cc ('k') | test/cctest/test-types.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698