Revision: 4839
Author: [email protected]
Date: Thu Jun 10 11:15:06 2010
Log: [Isolates] Moving TranscendentalCache to Isolate.
Landing patch by Maxim.Mossienko with the following changes:
* Sorted TranscendentalCache members to follow the style guide.
* Renamed TranscendentalCacheEntry to SubCache to be consistent with
naming in compilation caches.
* Fixed debug-only compilation problems in ia32/x64 codegens.
Original review: http://codereview.chromium.org/2657004/show
Review URL: http://codereview.chromium.org/2718007
http://code.google.com/p/v8/source/detail?r=4839
Modified:
/branches/experimental/isolates/AUTHORS
/branches/experimental/isolates/src/assembler.cc
/branches/experimental/isolates/src/heap-inl.h
/branches/experimental/isolates/src/heap.cc
/branches/experimental/isolates/src/heap.h
/branches/experimental/isolates/src/ia32/codegen-ia32.cc
/branches/experimental/isolates/src/isolate.cc
/branches/experimental/isolates/src/isolate.h
/branches/experimental/isolates/src/runtime.cc
/branches/experimental/isolates/src/x64/codegen-x64.cc
=======================================
--- /branches/experimental/isolates/AUTHORS Fri May 7 13:02:57 2010
+++ /branches/experimental/isolates/AUTHORS Thu Jun 10 11:15:06 2010
@@ -28,4 +28,5 @@
Rodolph Perfetta <[email protected]>
Ryan Dahl <[email protected]>
Subrato K De <[email protected]>
-
+Maxim Mossienko <[email protected]>
+
=======================================
--- /branches/experimental/isolates/src/assembler.cc Thu Jun 10 10:14:01
2010
+++ /branches/experimental/isolates/src/assembler.cc Thu Jun 10 11:15:06
2010
@@ -589,7 +589,8 @@
ExternalReference ExternalReference::transcendental_cache_array_address() {
- return ExternalReference(TranscendentalCache::cache_array_address());
+ return ExternalReference(Isolate::Current()->transcendental_cache()->
+ cache_array_address());
}
=======================================
--- /branches/experimental/isolates/src/heap-inl.h Thu Jun 10 10:14:01 2010
+++ /branches/experimental/isolates/src/heap-inl.h Thu Jun 10 11:15:06 2010
@@ -509,6 +509,20 @@
set_instanceof_cache_map(HEAP->the_hole_value());
set_instanceof_cache_function(HEAP->the_hole_value());
}
+
+
+Object* TranscendentalCache::Get(Type type, double input) {
+ SubCache* cache = caches_[type];
+ if (cache == NULL) {
+ caches_[type] = cache = new SubCache(type);
+ }
+ return cache->Get(input);
+}
+
+
+Address TranscendentalCache::cache_array_address() {
+ return reinterpret_cast<Address>(caches_);
+}
Heap* _inline_get_heap_() {
=======================================
--- /branches/experimental/isolates/src/heap.cc Thu Jun 10 10:14:01 2010
+++ /branches/experimental/isolates/src/heap.cc Thu Jun 10 11:15:06 2010
@@ -324,7 +324,7 @@
void Heap::GarbageCollectionPrologue() {
- TranscendentalCache::Clear();
+ Isolate::Current()->transcendental_cache()->Clear();
ClearJSFunctionResultCaches();
gc_count_++;
unflattened_strings_length_ = 0;
@@ -4720,7 +4720,7 @@
#endif
-TranscendentalCache::TranscendentalCache(TranscendentalCache::Type t)
+TranscendentalCache::SubCache::SubCache(Type t)
: type_(t),
heap_(HEAP) {
uint32_t in0 = 0xffffffffu; // Bit-pattern for a NaN that isn't
@@ -4731,9 +4731,6 @@
elements_[i].output = NULL;
}
}
-
-
-TranscendentalCache* TranscendentalCache::caches_[kNumberOfCaches];
void TranscendentalCache::Clear() {
=======================================
--- /branches/experimental/isolates/src/heap.h Thu Jun 10 10:14:01 2010
+++ /branches/experimental/isolates/src/heap.h Thu Jun 10 11:15:06 2010
@@ -1817,97 +1817,108 @@
public:
enum Type {ACOS, ASIN, ATAN, COS, EXP, LOG, SIN, TAN, kNumberOfCaches};
- explicit TranscendentalCache(Type t);
-
// Returns a heap number with f(input), where f is a math function
specified
// by the 'type' argument.
- static inline Object* Get(Type type, double input) {
- TranscendentalCache* cache = caches_[type];
- if (cache == NULL) {
- caches_[type] = cache = new TranscendentalCache(type);
- }
- return cache->Get(input);
- }
+ inline Object* Get(Type type, double input);
// The cache contains raw Object pointers. This method disposes of
// them before a garbage collection.
- static void Clear();
+ void Clear();
private:
- inline Object* Get(double input) {
- Converter c;
- c.dbl = input;
- int hash = Hash(c);
- Element e = elements_[hash];
- if (e.in[0] == c.integers[0] &&
- e.in[1] == c.integers[1]) {
- ASSERT(e.output != NULL);
- Counters::transcendental_cache_hit.Increment();
- return e.output;
- }
- double answer = Calculate(input);
- Object* heap_number = heap_->AllocateHeapNumber(answer);
- if (!heap_number->IsFailure()) {
- elements_[hash].in[0] = c.integers[0];
- elements_[hash].in[1] = c.integers[1];
- elements_[hash].output = heap_number;
- }
- Counters::transcendental_cache_miss.Increment();
- return heap_number;
- }
-
- inline double Calculate(double input) {
- switch (type_) {
- case ACOS:
- return acos(input);
- case ASIN:
- return asin(input);
- case ATAN:
- return atan(input);
- case COS:
- return cos(input);
- case EXP:
- return exp(input);
- case LOG:
- return log(input);
- case SIN:
- return sin(input);
- case TAN:
- return tan(input);
- default:
- return 0.0; // Never happens.
- }
- }
- static const int kCacheSize = 512;
- struct Element {
- uint32_t in[2];
- Object* output;
+ class SubCache {
+ static const int kCacheSize = 512;
+
+ explicit SubCache(Type t);
+
+ inline Object* Get(double input) {
+ Converter c;
+ c.dbl = input;
+ int hash = Hash(c);
+ Element e = elements_[hash];
+ if (e.in[0] == c.integers[0] &&
+ e.in[1] == c.integers[1]) {
+ ASSERT(e.output != NULL);
+ Counters::transcendental_cache_hit.Increment();
+ return e.output;
+ }
+ double answer = Calculate(input);
+ Object* heap_number = heap_->AllocateHeapNumber(answer);
+ if (!heap_number->IsFailure()) {
+ elements_[hash].in[0] = c.integers[0];
+ elements_[hash].in[1] = c.integers[1];
+ elements_[hash].output = heap_number;
+ }
+ Counters::transcendental_cache_miss.Increment();
+ return heap_number;
+ }
+
+ inline double Calculate(double input) {
+ switch (type_) {
+ case ACOS:
+ return acos(input);
+ case ASIN:
+ return asin(input);
+ case ATAN:
+ return atan(input);
+ case COS:
+ return cos(input);
+ case EXP:
+ return exp(input);
+ case LOG:
+ return log(input);
+ case SIN:
+ return sin(input);
+ case TAN:
+ return tan(input);
+ default:
+ return 0.0; // Never happens.
+ }
+ }
+ struct Element {
+ uint32_t in[2];
+ Object* output;
+ };
+ union Converter {
+ double dbl;
+ uint32_t integers[2];
+ };
+ inline static int Hash(const Converter& c) {
+ uint32_t hash = (c.integers[0] ^ c.integers[1]);
+ hash ^= hash >> 16;
+ hash ^= hash >> 8;
+ return (hash & (kCacheSize - 1));
+ }
+
+ // Inline implementation of the caching.
+ friend class TranscendentalCacheStub;
+
+ // For evaluating value.
+ friend class TranscendentalCache;
+
+ Element elements_[kCacheSize];
+ Type type_;
+ Heap* heap_;
+
+ DISALLOW_COPY_AND_ASSIGN(SubCache);
};
- union Converter {
- double dbl;
- uint32_t integers[2];
- };
- inline static int Hash(const Converter& c) {
- uint32_t hash = (c.integers[0] ^ c.integers[1]);
- hash ^= hash >> 16;
- hash ^= hash >> 8;
- return (hash & (kCacheSize - 1));
- }
-
- static Address cache_array_address() {
- // Used to create an external reference.
- return reinterpret_cast<Address>(caches_);
+
+ TranscendentalCache() {
+ for (int i = 0; i < kNumberOfCaches; ++i) caches_[i] = NULL;
}
- // Allow access to the caches_ array as an ExternalReference.
- friend class ExternalReference;
+ // Used to create an external reference.
+ inline Address cache_array_address();
+
+ // Instantiation
+ friend class Isolate;
// Inline implementation of the caching.
friend class TranscendentalCacheStub;
-
- static TranscendentalCache* caches_[kNumberOfCaches];
- Element elements_[kCacheSize];
- Type type_;
- Heap* heap_;
+ // Allow access to the caches_ array as an ExternalReference.
+ friend class ExternalReference;
+
+ SubCache* caches_[kNumberOfCaches];
+ DISALLOW_COPY_AND_ASSIGN(TranscendentalCache);
};
=======================================
--- /branches/experimental/isolates/src/ia32/codegen-ia32.cc Wed Jun 9
16:02:44 2010
+++ /branches/experimental/isolates/src/ia32/codegen-ia32.cc Thu Jun 10
11:15:06 2010
@@ -10295,8 +10295,9 @@
__ mov(eax, ecx);
__ sar(eax, 8);
__ xor_(ecx, Operand(eax));
- ASSERT(IsPowerOf2(TranscendentalCache::kCacheSize));
- __ and_(Operand(ecx), Immediate(TranscendentalCache::kCacheSize - 1));
+ ASSERT(IsPowerOf2(TranscendentalCache::SubCache::kCacheSize));
+ __ and_(Operand(ecx),
+ Immediate(TranscendentalCache::SubCache::kCacheSize - 1));
// ST[0] == double value.
// ebx = low 32 bits of double value.
// edx = high 32 bits of double value.
@@ -10304,14 +10305,15 @@
__ mov(eax,
Immediate(ExternalReference::transcendental_cache_array_address()));
// Eax points to cache array.
- __ mov(eax, Operand(eax, type_ *
sizeof(TranscendentalCache::caches_[0])));
+ __ mov(eax, Operand(eax, type_ * sizeof(
+ Isolate::Current()->transcendental_cache()->caches_[0])));
// Eax points to the cache for the type type_.
// If NULL, the cache hasn't been initialized yet, so go through runtime.
__ test(eax, Operand(eax));
__ j(zero, &runtime_call_clear_stack);
#ifdef DEBUG
// Check that the layout of cache elements match expectations.
- { TranscendentalCache::Element test_elem[2];
+ { TranscendentalCache::SubCache::Element test_elem[2];
char* elem_start = reinterpret_cast<char*>(&test_elem[0]);
char* elem2_start = reinterpret_cast<char*>(&test_elem[1]);
char* elem_in0 = reinterpret_cast<char*>(&(test_elem[0].in[0]));
=======================================
--- /branches/experimental/isolates/src/isolate.cc Thu Jun 10 10:14:01 2010
+++ /branches/experimental/isolates/src/isolate.cc Thu Jun 10 11:15:06 2010
@@ -91,6 +91,7 @@
bootstrapper_(NULL),
break_access_(OS::CreateMutex()),
stub_cache_(NULL),
+ transcendental_cache_(new TranscendentalCache()),
handle_scope_implementer_(NULL) {
heap_.isolate_ = this;
stack_guard_.isolate_ = this;
@@ -110,6 +111,8 @@
Isolate::~Isolate() {
+ delete transcendental_cache_;
+ transcendental_cache_ = NULL;
delete stub_cache_;
stub_cache_ = NULL;
delete bootstrapper_;
=======================================
--- /branches/experimental/isolates/src/isolate.h Wed Jun 9 13:52:42 2010
+++ /branches/experimental/isolates/src/isolate.h Thu Jun 10 11:15:06 2010
@@ -85,6 +85,11 @@
StackGuard* stack_guard() { return &stack_guard_; }
Heap* heap() { return &heap_; }
StubCache* stub_cache() { return stub_cache_; }
+
+ TranscendentalCache* transcendental_cache() const {
+ return transcendental_cache_;
+ }
+
v8::ImplementationUtilities::HandleScopeData* handle_scope_data() {
return &handle_scope_data_;
}
@@ -126,6 +131,7 @@
Heap heap_;
StackGuard stack_guard_;
StubCache* stub_cache_;
+ TranscendentalCache* transcendental_cache_;
v8::ImplementationUtilities::HandleScopeData handle_scope_data_;
HandleScopeImplementer* handle_scope_implementer_;
Zone zone_;
=======================================
--- /branches/experimental/isolates/src/runtime.cc Thu Jun 10 10:14:01 2010
+++ /branches/experimental/isolates/src/runtime.cc Thu Jun 10 11:15:06 2010
@@ -5901,7 +5901,8 @@
Counters::math_acos.Increment();
CONVERT_DOUBLE_CHECKED(x, args[0]);
- return TranscendentalCache::Get(TranscendentalCache::ACOS, x);
+ Isolate* const isolate = Isolate::Current();
+ return isolate->transcendental_cache()->Get(TranscendentalCache::ACOS,
x);
}
@@ -5911,7 +5912,8 @@
Counters::math_asin.Increment();
CONVERT_DOUBLE_CHECKED(x, args[0]);
- return TranscendentalCache::Get(TranscendentalCache::ASIN, x);
+ Isolate* const isolate = Isolate::Current();
+ return isolate->transcendental_cache()->Get(TranscendentalCache::ASIN,
x);
}
@@ -5921,7 +5923,8 @@
Counters::math_atan.Increment();
CONVERT_DOUBLE_CHECKED(x, args[0]);
- return TranscendentalCache::Get(TranscendentalCache::ATAN, x);
+ Isolate* const isolate = Isolate::Current();
+ return isolate->transcendental_cache()->Get(TranscendentalCache::ATAN,
x);
}
@@ -5965,7 +5968,8 @@
Counters::math_cos.Increment();
CONVERT_DOUBLE_CHECKED(x, args[0]);
- return TranscendentalCache::Get(TranscendentalCache::COS, x);
+ Isolate* const isolate = Isolate::Current();
+ return isolate->transcendental_cache()->Get(TranscendentalCache::COS, x);
}
@@ -5975,7 +5979,8 @@
Counters::math_exp.Increment();
CONVERT_DOUBLE_CHECKED(x, args[0]);
- return TranscendentalCache::Get(TranscendentalCache::EXP, x);
+ Isolate* const isolate = Isolate::Current();
+ return isolate->transcendental_cache()->Get(TranscendentalCache::EXP, x);
}
@@ -5995,7 +6000,8 @@
Counters::math_log.Increment();
CONVERT_DOUBLE_CHECKED(x, args[0]);
- return TranscendentalCache::Get(TranscendentalCache::LOG, x);
+ Isolate* const isolate = Isolate::Current();
+ return isolate->transcendental_cache()->Get(TranscendentalCache::LOG, x);
}
@@ -6127,7 +6133,8 @@
Counters::math_sin.Increment();
CONVERT_DOUBLE_CHECKED(x, args[0]);
- return TranscendentalCache::Get(TranscendentalCache::SIN, x);
+ Isolate* const isolate = Isolate::Current();
+ return isolate->transcendental_cache()->Get(TranscendentalCache::SIN, x);
}
@@ -6147,7 +6154,8 @@
Counters::math_tan.Increment();
CONVERT_DOUBLE_CHECKED(x, args[0]);
- return TranscendentalCache::Get(TranscendentalCache::TAN, x);
+ Isolate* const isolate = Isolate::Current();
+ return isolate->transcendental_cache()->Get(TranscendentalCache::TAN, x);
}
=======================================
--- /branches/experimental/isolates/src/x64/codegen-x64.cc Wed Jun 9
16:02:44 2010
+++ /branches/experimental/isolates/src/x64/codegen-x64.cc Thu Jun 10
11:15:06 2010
@@ -8180,14 +8180,15 @@
__ xorl(rcx, rdx);
__ xorl(rax, rdi);
__ xorl(rcx, rax);
- ASSERT(IsPowerOf2(TranscendentalCache::kCacheSize));
- __ andl(rcx, Immediate(TranscendentalCache::kCacheSize - 1));
+ ASSERT(IsPowerOf2(TranscendentalCache::SubCache::kCacheSize));
+ __ andl(rcx, Immediate(TranscendentalCache::SubCache::kCacheSize - 1));
// ST[0] == double value.
// rbx = bits of double value.
// rcx = TranscendentalCache::hash(double value).
__ movq(rax, ExternalReference::transcendental_cache_array_address());
// rax points to cache array.
- __ movq(rax, Operand(rax, type_ *
sizeof(TranscendentalCache::caches_[0])));
+ __ movq(rax, Operand(rax, type_ * sizeof(Isolate::Current()->
+ transcendental_cache()->caches_[0])));
// rax points to the cache for the type type_.
// If NULL, the cache hasn't been initialized yet, so go through runtime.
__ testq(rax, rax);
@@ -8195,7 +8196,7 @@
#ifdef DEBUG
// Check that the layout of cache elements match expectations.
{ // NOLINT - doesn't like a single brace on a line.
- TranscendentalCache::Element test_elem[2];
+ TranscendentalCache::SubCache::Element test_elem[2];
char* elem_start = reinterpret_cast<char*>(&test_elem[0]);
char* elem2_start = reinterpret_cast<char*>(&test_elem[1]);
char* elem_in0 = reinterpret_cast<char*>(&(test_elem[0].in[0]));
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev