Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 10 matching lines...) Expand all Loading... | |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #ifndef V8_HEAP_H_ | 28 #ifndef V8_HEAP_H_ |
| 29 #define V8_HEAP_H_ | 29 #define V8_HEAP_H_ |
| 30 | 30 |
| 31 #include <math.h> | |
| 32 | |
| 31 #include "zone-inl.h" | 33 #include "zone-inl.h" |
| 32 | 34 |
| 35 | |
| 33 namespace v8 { | 36 namespace v8 { |
| 34 namespace internal { | 37 namespace internal { |
| 35 | 38 |
| 36 // Defines all the roots in Heap. | 39 // Defines all the roots in Heap. |
| 37 #define UNCONDITIONAL_STRONG_ROOT_LIST(V) \ | 40 #define UNCONDITIONAL_STRONG_ROOT_LIST(V) \ |
| 38 /* Cluster the most popular ones in a few cache lines here at the top. */ \ | 41 /* Cluster the most popular ones in a few cache lines here at the top. */ \ |
| 39 V(Smi, stack_limit, StackLimit) \ | 42 V(Smi, stack_limit, StackLimit) \ |
| 40 V(Object, undefined_value, UndefinedValue) \ | 43 V(Object, undefined_value, UndefinedValue) \ |
| 41 V(Object, the_hole_value, TheHoleValue) \ | 44 V(Object, the_hole_value, TheHoleValue) \ |
| 42 V(Object, null_value, NullValue) \ | 45 V(Object, null_value, NullValue) \ |
| (...skipping 1469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1512 // On a full GC, a count of the number of marked objects. Incremented | 1515 // On a full GC, a count of the number of marked objects. Incremented |
| 1513 // when an object is marked and decremented when an object's mark bit is | 1516 // when an object is marked and decremented when an object's mark bit is |
| 1514 // cleared. Will be zero on a scavenge collection. | 1517 // cleared. Will be zero on a scavenge collection. |
| 1515 int marked_count_; | 1518 int marked_count_; |
| 1516 | 1519 |
| 1517 // The count from the end of the previous full GC. Will be zero if there | 1520 // The count from the end of the previous full GC. Will be zero if there |
| 1518 // was no previous full GC. | 1521 // was no previous full GC. |
| 1519 int previous_marked_count_; | 1522 int previous_marked_count_; |
| 1520 }; | 1523 }; |
| 1521 | 1524 |
| 1525 | |
| 1526 class TranscendentalCache { | |
| 1527 public: | |
| 1528 enum Type {ACOS, ASIN, ATAN, COS, EXP, LOG, SIN, TAN, kNumberOfCaches}; | |
| 1529 | |
| 1530 TranscendentalCache(Type t); | |
| 1531 | |
| 1532 static inline Object* Get(Type type, double input) { | |
|
Søren Thygesen Gjesse
2009/09/01 08:40:31
Please add a (short) comment on this public Get fu
| |
| 1533 TranscendentalCache* cache = caches_[type]; | |
|
Søren Thygesen Gjesse
2009/09/01 08:40:31
The description says "Cache the results of slow ma
Erik Corry
2009/09/01 09:02:28
The cache only works in the runtime system. If we
| |
| 1534 if (cache == NULL) { | |
| 1535 caches_[type] = cache = new TranscendentalCache(type); | |
| 1536 } | |
| 1537 return cache->Get(input); | |
| 1538 } | |
| 1539 | |
| 1540 // The cache contains raw Object pointers. This method disposes of | |
| 1541 // them before a garbage collection. | |
| 1542 static void Clear(); | |
| 1543 | |
| 1544 private: | |
| 1545 inline Object* Get(double input) { | |
| 1546 Converter c; | |
| 1547 c.dbl = input; | |
| 1548 int hash = Hash(c); | |
| 1549 Element e = elements_[hash]; | |
| 1550 if (e.in[0] == c.integers[0] && | |
| 1551 e.in[1] == c.integers[1]) { | |
| 1552 ASSERT(e.output != NULL); | |
| 1553 return e.output; | |
| 1554 } | |
| 1555 double answer = Calculate(input); | |
| 1556 Object* heap_number = Heap::AllocateHeapNumber(answer); | |
| 1557 if (!heap_number->IsFailure()) { | |
| 1558 elements_[hash].in[0] = c.integers[0]; | |
| 1559 elements_[hash].in[1] = c.integers[1]; | |
| 1560 elements_[hash].output = heap_number; | |
| 1561 } | |
| 1562 return heap_number; | |
| 1563 } | |
| 1564 | |
| 1565 inline double Calculate(double input) { | |
| 1566 switch(type_) { | |
| 1567 case ACOS: | |
| 1568 return acos(input); | |
| 1569 case ASIN: | |
| 1570 return asin(input); | |
| 1571 case ATAN: | |
| 1572 return atan(input); | |
| 1573 case COS: | |
| 1574 return cos(input); | |
| 1575 case EXP: | |
| 1576 return exp(input); | |
| 1577 case LOG: | |
| 1578 return log(input); | |
| 1579 case SIN: | |
| 1580 return sin(input); | |
| 1581 case TAN: | |
| 1582 return tan(input); | |
| 1583 default: | |
| 1584 return 0.0; // Never happens. | |
| 1585 } | |
| 1586 } | |
| 1587 static const int kCacheSize = 512; | |
| 1588 struct Element { | |
| 1589 uint32_t in[2]; | |
| 1590 Object* output; | |
| 1591 }; | |
| 1592 union Converter { | |
| 1593 double dbl; | |
| 1594 uint32_t integers[2]; | |
| 1595 }; | |
| 1596 inline static int Hash(const Converter& c) { | |
| 1597 uint32_t hash = (c.integers[0] ^ c.integers[1]); | |
| 1598 hash ^= hash >> 16; | |
| 1599 hash ^= hash >> 8; | |
| 1600 return (hash & (kCacheSize - 1)); | |
| 1601 } | |
| 1602 static TranscendentalCache* caches_[kNumberOfCaches]; | |
| 1603 Element elements_[kCacheSize]; | |
| 1604 Type type_; | |
| 1605 }; | |
| 1606 | |
| 1607 | |
| 1522 } } // namespace v8::internal | 1608 } } // namespace v8::internal |
| 1523 | 1609 |
| 1524 #endif // V8_HEAP_H_ | 1610 #endif // V8_HEAP_H_ |
| OLD | NEW |