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

Side by Side Diff: runtime/vm/assembler.h

Issue 1175523002: Object pool with support for untagged entries. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 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 | « runtime/observatory/tests/service/graph_test.dart ('k') | runtime/vm/assembler.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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_ASSEMBLER_H_ 5 #ifndef VM_ASSEMBLER_H_
6 #define VM_ASSEMBLER_H_ 6 #define VM_ASSEMBLER_H_
7 7
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/allocation.h" 9 #include "vm/allocation.h"
10 #include "vm/globals.h" 10 #include "vm/globals.h"
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 void ExtendCapacity(); 209 void ExtendCapacity();
210 210
211 friend class AssemblerFixup; 211 friend class AssemblerFixup;
212 }; 212 };
213 213
214 214
215 // Pair type parameter for DirectChainedHashMap used for the constant pool. 215 // Pair type parameter for DirectChainedHashMap used for the constant pool.
216 class ObjIndexPair { 216 class ObjIndexPair {
217 public: 217 public:
218 // Typedefs needed for the DirectChainedHashMap template. 218 // Typedefs needed for the DirectChainedHashMap template.
219 typedef const Object* Key; 219 typedef ObjectPool::Entry Key;
220 typedef intptr_t Value; 220 typedef intptr_t Value;
221 typedef ObjIndexPair Pair; 221 typedef ObjIndexPair Pair;
222 222
223 static const intptr_t kNoIndex = -1; 223 static const intptr_t kNoIndex = -1;
224 224
225 ObjIndexPair() : key_(NULL), value_(kNoIndex) { } 225 ObjIndexPair() : key_(static_cast<uword>(NULL), ObjectPool::kTaggedObject),
226 value_(kNoIndex) { }
226 227
227 ObjIndexPair(Key key, Value value) 228 ObjIndexPair(Key key, Value value) : value_(value) {
228 : key_(key->IsNotTemporaryScopedHandle() 229 key_.type_ = key.type_;
229 ? key : &Object::ZoneHandle(key->raw())), 230 if (key.type_ == ObjectPool::kTaggedObject) {
230 value_(value) { } 231 if (key.obj_->IsNotTemporaryScopedHandle()) {
232 key_.obj_ = key.obj_;
233 } else {
234 key_.obj_ = &Object::ZoneHandle(key.obj_->raw());
235 }
236 } else {
237 key_.raw_value_ = key.raw_value_;
238 }
239 }
231 240
232 static Key KeyOf(Pair kv) { return kv.key_; } 241 static Key KeyOf(Pair kv) { return kv.key_; }
233 242
234 static Value ValueOf(Pair kv) { return kv.value_; } 243 static Value ValueOf(Pair kv) { return kv.value_; }
235 244
236 static intptr_t Hashcode(Key key) { 245 static intptr_t Hashcode(Key key) {
237 if (key->IsSmi()) { 246 if (key.type_ != ObjectPool::kTaggedObject) {
238 return Smi::Cast(*key).Value(); 247 return key.raw_value_;
239 } 248 }
240 if (key->IsDouble()) { 249 if (key.obj_->IsSmi()) {
250 return Smi::Cast(*key.obj_).Value();
251 }
252 if (key.obj_->IsDouble()) {
241 return static_cast<intptr_t>( 253 return static_cast<intptr_t>(
242 bit_cast<int32_t, float>( 254 bit_cast<int32_t, float>(
243 static_cast<float>(Double::Cast(*key).value()))); 255 static_cast<float>(Double::Cast(*key.obj_).value())));
244 } 256 }
245 if (key->IsMint()) { 257 if (key.obj_->IsMint()) {
246 return static_cast<intptr_t>(Mint::Cast(*key).value()); 258 return static_cast<intptr_t>(Mint::Cast(*key.obj_).value());
247 } 259 }
248 if (key->IsString()) { 260 if (key.obj_->IsString()) {
249 return String::Cast(*key).Hash(); 261 return String::Cast(*key.obj_).Hash();
250 } 262 }
251 // TODO(fschneider): Add hash function for other classes commonly used as 263 // TODO(fschneider): Add hash function for other classes commonly used as
252 // compile-time constants. 264 // compile-time constants.
253 return key->GetClassId(); 265 return key.obj_->GetClassId();
254 } 266 }
255 267
256 static inline bool IsKeyEqual(Pair kv, Key key) { 268 static inline bool IsKeyEqual(Pair kv, Key key) {
257 return kv.key_->raw() == key->raw(); 269 if (kv.key_.type_ != key.type_) return false;
270 if (kv.key_.type_ == ObjectPool::kTaggedObject) {
271 return kv.key_.obj_->raw() == key.obj_->raw();
272 }
273 return kv.key_.raw_value_ == key.raw_value_;
258 } 274 }
259 275
260 private: 276 private:
261 Key key_; 277 Key key_;
262 Value value_; 278 Value value_;
263 }; 279 };
264 280
265 281
266 enum Patchability { 282 enum Patchability {
267 kPatchable, 283 kPatchable,
268 kNotPatchable, 284 kNotPatchable,
269 }; 285 };
270 286
271 287
272 class ObjectPool : public ValueObject { 288 class ObjectPoolWrapper : public ValueObject {
273 public: 289 public:
274 ObjectPool() : object_pool_(GrowableObjectArray::Handle()) { } 290 intptr_t AddObject(const Object& obj);
275 291 intptr_t AddImmediate(uword imm);
276 intptr_t AddObject(const Object& obj, Patchability patchable);
277 intptr_t AddExternalLabel(const ExternalLabel* label, 292 intptr_t AddExternalLabel(const ExternalLabel* label,
278 Patchability patchable); 293 Patchability patchable);
279 294
280 intptr_t FindObject(const Object& obj, Patchability patchable); 295 intptr_t FindObject(const Object& obj);
296 intptr_t FindImmediate(uword imm);
281 intptr_t FindExternalLabel(const ExternalLabel* label, 297 intptr_t FindExternalLabel(const ExternalLabel* label,
282 Patchability patchable); 298 Patchability patchable);
283 const GrowableObjectArray& data() const { return object_pool_; } 299
300 RawObjectPool* MakeObjectPool();
284 301
285 private: 302 private:
303 intptr_t AddObject(ObjectPool::Entry entry, Patchability patchable);
304 intptr_t FindObject(ObjectPool::Entry entry, Patchability patchable);
305
286 // Objects and jump targets. 306 // Objects and jump targets.
287 GrowableObjectArray& object_pool_; 307 GrowableArray<ObjectPool::Entry> object_pool_;
288
289 // Patchability of pool entries.
290 GrowableArray<Patchability> patchable_pool_entries_;
291 308
292 // Hashmap for fast lookup in object pool. 309 // Hashmap for fast lookup in object pool.
293 DirectChainedHashMap<ObjIndexPair> object_pool_index_table_; 310 DirectChainedHashMap<ObjIndexPair> object_pool_index_table_;
294 }; 311 };
295 312
296 } // namespace dart 313 } // namespace dart
297 314
298 315
299 #if defined(TARGET_ARCH_IA32) 316 #if defined(TARGET_ARCH_IA32)
300 #include "vm/assembler_ia32.h" 317 #include "vm/assembler_ia32.h"
301 #elif defined(TARGET_ARCH_X64) 318 #elif defined(TARGET_ARCH_X64)
302 #include "vm/assembler_x64.h" 319 #include "vm/assembler_x64.h"
303 #elif defined(TARGET_ARCH_ARM) 320 #elif defined(TARGET_ARCH_ARM)
304 #include "vm/assembler_arm.h" 321 #include "vm/assembler_arm.h"
305 #elif defined(TARGET_ARCH_ARM64) 322 #elif defined(TARGET_ARCH_ARM64)
306 #include "vm/assembler_arm64.h" 323 #include "vm/assembler_arm64.h"
307 #elif defined(TARGET_ARCH_MIPS) 324 #elif defined(TARGET_ARCH_MIPS)
308 #include "vm/assembler_mips.h" 325 #include "vm/assembler_mips.h"
309 #else 326 #else
310 #error Unknown architecture. 327 #error Unknown architecture.
311 #endif 328 #endif
312 329
313 #endif // VM_ASSEMBLER_H_ 330 #endif // VM_ASSEMBLER_H_
OLDNEW
« no previous file with comments | « runtime/observatory/tests/service/graph_test.dart ('k') | runtime/vm/assembler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698