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

Side by Side Diff: src/heap.h

Issue 2816006: [Isolates] KeyedLookupCache / DescriptorLookupCache / ContextSlotCache moved to Isolate. (Closed)
Patch Set: Created 10 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 | « src/assembler.cc ('k') | src/heap.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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1454 matching lines...) Expand 10 before | Expand all | Expand 10 after
1465 // Object iterator for the space currently being iterated. 1465 // Object iterator for the space currently being iterated.
1466 ObjectIterator* object_iterator_; 1466 ObjectIterator* object_iterator_;
1467 }; 1467 };
1468 1468
1469 1469
1470 // Cache for mapping (map, property name) into field offset. 1470 // Cache for mapping (map, property name) into field offset.
1471 // Cleared at startup and prior to mark sweep collection. 1471 // Cleared at startup and prior to mark sweep collection.
1472 class KeyedLookupCache { 1472 class KeyedLookupCache {
1473 public: 1473 public:
1474 // Lookup field offset for (map, name). If absent, -1 is returned. 1474 // Lookup field offset for (map, name). If absent, -1 is returned.
1475 static int Lookup(Map* map, String* name); 1475 int Lookup(Map* map, String* name);
1476 1476
1477 // Update an element in the cache. 1477 // Update an element in the cache.
1478 static void Update(Map* map, String* name, int field_offset); 1478 void Update(Map* map, String* name, int field_offset);
1479 1479
1480 // Clear the cache. 1480 // Clear the cache.
1481 static void Clear(); 1481 void Clear();
1482 1482
1483 static const int kLength = 64; 1483 static const int kLength = 64;
1484 static const int kCapacityMask = kLength - 1; 1484 static const int kCapacityMask = kLength - 1;
1485 static const int kMapHashShift = 2; 1485 static const int kMapHashShift = 2;
1486 static const int kNotFound = -1;
1486 1487
1487 private: 1488 private:
1489 KeyedLookupCache() {
1490 for (int i = 0; i < kLength; ++i) {
1491 keys_[i].map = NULL;
1492 keys_[i].name = NULL;
1493 field_offsets_[i] = kNotFound;
1494 }
1495 }
1496
1488 static inline int Hash(Map* map, String* name); 1497 static inline int Hash(Map* map, String* name);
1489 1498
1490 // Get the address of the keys and field_offsets arrays. Used in 1499 // Get the address of the keys and field_offsets arrays. Used in
1491 // generated code to perform cache lookups. 1500 // generated code to perform cache lookups.
1492 static Address keys_address() { 1501 Address keys_address() {
1493 return reinterpret_cast<Address>(&keys_); 1502 return reinterpret_cast<Address>(&keys_);
1494 } 1503 }
1495 1504
1496 static Address field_offsets_address() { 1505 Address field_offsets_address() {
1497 return reinterpret_cast<Address>(&field_offsets_); 1506 return reinterpret_cast<Address>(&field_offsets_);
1498 } 1507 }
1499 1508
1500 struct Key { 1509 struct Key {
1501 Map* map; 1510 Map* map;
1502 String* name; 1511 String* name;
1503 }; 1512 };
1504 static Key keys_[kLength]; 1513
1505 static int field_offsets_[kLength]; 1514 Key keys_[kLength];
1515 int field_offsets_[kLength];
1506 1516
1507 friend class ExternalReference; 1517 friend class ExternalReference;
1518 friend class Isolate;
1519 DISALLOW_COPY_AND_ASSIGN(KeyedLookupCache);
1508 }; 1520 };
1509 1521
1510 1522
1511 // Cache for mapping (array, property name) into descriptor index. 1523 // Cache for mapping (array, property name) into descriptor index.
1512 // The cache contains both positive and negative results. 1524 // The cache contains both positive and negative results.
1513 // Descriptor index equals kNotFound means the property is absent. 1525 // Descriptor index equals kNotFound means the property is absent.
1514 // Cleared at startup and prior to any gc. 1526 // Cleared at startup and prior to any gc.
1515 class DescriptorLookupCache { 1527 class DescriptorLookupCache {
1516 public: 1528 public:
1517 // Lookup descriptor index for (map, name). 1529 // Lookup descriptor index for (map, name).
1518 // If absent, kAbsent is returned. 1530 // If absent, kAbsent is returned.
1519 static int Lookup(DescriptorArray* array, String* name) { 1531 int Lookup(DescriptorArray* array, String* name) {
1520 if (!StringShape(name).IsSymbol()) return kAbsent; 1532 if (!StringShape(name).IsSymbol()) return kAbsent;
1521 int index = Hash(array, name); 1533 int index = Hash(array, name);
1522 Key& key = keys_[index]; 1534 Key& key = keys_[index];
1523 if ((key.array == array) && (key.name == name)) return results_[index]; 1535 if ((key.array == array) && (key.name == name)) return results_[index];
1524 return kAbsent; 1536 return kAbsent;
1525 } 1537 }
1526 1538
1527 // Update an element in the cache. 1539 // Update an element in the cache.
1528 static void Update(DescriptorArray* array, String* name, int result) { 1540 void Update(DescriptorArray* array, String* name, int result) {
1529 ASSERT(result != kAbsent); 1541 ASSERT(result != kAbsent);
1530 if (StringShape(name).IsSymbol()) { 1542 if (StringShape(name).IsSymbol()) {
1531 int index = Hash(array, name); 1543 int index = Hash(array, name);
1532 Key& key = keys_[index]; 1544 Key& key = keys_[index];
1533 key.array = array; 1545 key.array = array;
1534 key.name = name; 1546 key.name = name;
1535 results_[index] = result; 1547 results_[index] = result;
1536 } 1548 }
1537 } 1549 }
1538 1550
1539 // Clear the cache. 1551 // Clear the cache.
1540 static void Clear(); 1552 void Clear();
1541 1553
1542 static const int kAbsent = -2; 1554 static const int kAbsent = -2;
1543 private: 1555 private:
1556 DescriptorLookupCache() {
1557 for (int i = 0; i < kLength; ++i) {
1558 keys_[i].array = NULL;
1559 keys_[i].name = NULL;
1560 results_[i] = kAbsent;
1561 }
1562 }
1563
1544 static int Hash(DescriptorArray* array, String* name) { 1564 static int Hash(DescriptorArray* array, String* name) {
1545 // Uses only lower 32 bits if pointers are larger. 1565 // Uses only lower 32 bits if pointers are larger.
1546 uint32_t array_hash = 1566 uint32_t array_hash =
1547 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(array)) >> 2; 1567 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(array)) >> 2;
1548 uint32_t name_hash = 1568 uint32_t name_hash =
1549 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(name)) >> 2; 1569 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(name)) >> 2;
1550 return (array_hash ^ name_hash) % kLength; 1570 return (array_hash ^ name_hash) % kLength;
1551 } 1571 }
1552 1572
1553 static const int kLength = 64; 1573 static const int kLength = 64;
1554 struct Key { 1574 struct Key {
1555 DescriptorArray* array; 1575 DescriptorArray* array;
1556 String* name; 1576 String* name;
1557 }; 1577 };
1558 1578
1559 static Key keys_[kLength]; 1579 Key keys_[kLength];
1560 static int results_[kLength]; 1580 int results_[kLength];
1581
1582 friend class Isolate;
1583 DISALLOW_COPY_AND_ASSIGN(DescriptorLookupCache);
1561 }; 1584 };
1562 1585
1563 1586
1564 // ---------------------------------------------------------------------------- 1587 // ----------------------------------------------------------------------------
1565 // Marking stack for tracing live objects. 1588 // Marking stack for tracing live objects.
1566 1589
1567 class MarkingStack { 1590 class MarkingStack {
1568 public: 1591 public:
1569 void Initialize(Address low, Address high) { 1592 void Initialize(Address low, Address high) {
1570 top_ = low_ = reinterpret_cast<HeapObject**>(low); 1593 top_ = low_ = reinterpret_cast<HeapObject**>(low);
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
1953 // separate from old space strings. 1976 // separate from old space strings.
1954 static List<Object*> new_space_strings_; 1977 static List<Object*> new_space_strings_;
1955 static List<Object*> old_space_strings_; 1978 static List<Object*> old_space_strings_;
1956 }; 1979 };
1957 1980
1958 } } // namespace v8::internal 1981 } } // namespace v8::internal
1959 1982
1960 #undef HEAP 1983 #undef HEAP
1961 1984
1962 #endif // V8_HEAP_H_ 1985 #endif // V8_HEAP_H_
OLDNEW
« no previous file with comments | « src/assembler.cc ('k') | src/heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698