From 559ba2ccf01ab3f0ffe4b6d87dc4a2ebdf5cf0fc Mon Sep 17 00:00:00 2001 From: "vitalyr@chromium.org" Date: Sun, 25 Apr 2010 10:31:52 +0000 Subject: [PATCH] Don't share function result caches between contexts. A reference to the caches array was embedded directly into the builtin code and this allowed sharing objects between contexts. Unfortunately, clearing the cache on GC won't prevent sharing so we either have to have per-context builtin code or load the cache indirectly from the current context. This change implements the second approach. The first approach may be interesting to consider in the future for some perfomance critical functions, and the current approach can still be improved by putting the caches directly into the global context (or even global objects). Review URL: http://codereview.chromium.org/1731002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4486 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/arm/codegen-arm.cc | 8 +++++--- src/ia32/codegen-ia32.cc | 12 +++++++++--- src/x64/codegen-x64.cc | 12 +++++++++--- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/arm/codegen-arm.cc b/src/arm/codegen-arm.cc index af46d819f9..f775f77ed9 100644 --- a/src/arm/codegen-arm.cc +++ b/src/arm/codegen-arm.cc @@ -4460,18 +4460,20 @@ void CodeGenerator::GenerateGetFromCache(ZoneList* args) { frame_->EmitPush(r0); return; } - Handle cache_obj( - FixedArray::cast(jsfunction_result_caches->get(cache_id))); Load(args->at(1)); frame_->EmitPop(r2); + __ ldr(r1, ContextOperand(cp, Context::GLOBAL_INDEX)); + __ ldr(r1, FieldMemOperand(r1, GlobalObject::kGlobalContextOffset)); + __ ldr(r1, ContextOperand(r1, Context::JSFUNCTION_RESULT_CACHES_INDEX)); + __ ldr(r1, FieldMemOperand(r1, FixedArray::OffsetOfElementAt(cache_id))); + DeferredSearchCache* deferred = new DeferredSearchCache(r0, r1, r2); const int kFingerOffset = FixedArray::OffsetOfElementAt(JSFunctionResultCache::kFingerIndex); ASSERT(kSmiTag == 0 && kSmiTagSize == 1); - __ mov(r1, Operand(cache_obj)); __ ldr(r0, FieldMemOperand(r1, kFingerOffset)); // r0 now holds finger offset as a smi. __ add(r3, r1, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); diff --git a/src/ia32/codegen-ia32.cc b/src/ia32/codegen-ia32.cc index d0d30450b0..e1f2d66633 100644 --- a/src/ia32/codegen-ia32.cc +++ b/src/ia32/codegen-ia32.cc @@ -6553,17 +6553,23 @@ void CodeGenerator::GenerateGetFromCache(ZoneList* args) { frame_->Push(Factory::undefined_value()); return; } - Handle cache_obj( - FixedArray::cast(jsfunction_result_caches->get(cache_id))); Load(args->at(1)); Result key = frame_->Pop(); key.ToRegister(); Result cache = allocator()->Allocate(); - __ mov(cache.reg(), cache_obj); + ASSERT(cache.is_valid()); + __ mov(cache.reg(), ContextOperand(esi, Context::GLOBAL_INDEX)); + __ mov(cache.reg(), + FieldOperand(cache.reg(), GlobalObject::kGlobalContextOffset)); + __ mov(cache.reg(), + ContextOperand(cache.reg(), Context::JSFUNCTION_RESULT_CACHES_INDEX)); + __ mov(cache.reg(), + FieldOperand(cache.reg(), FixedArray::OffsetOfElementAt(cache_id))); Result tmp = allocator()->Allocate(); + ASSERT(tmp.is_valid()); DeferredSearchCache* deferred = new DeferredSearchCache(tmp.reg(), cache.reg(), diff --git a/src/x64/codegen-x64.cc b/src/x64/codegen-x64.cc index 9ce58212dc..7a3278ca86 100644 --- a/src/x64/codegen-x64.cc +++ b/src/x64/codegen-x64.cc @@ -4305,17 +4305,23 @@ void CodeGenerator::GenerateGetFromCache(ZoneList* args) { frame_->Push(Factory::undefined_value()); return; } - Handle cache_obj( - FixedArray::cast(jsfunction_result_caches->get(cache_id))); Load(args->at(1)); Result key = frame_->Pop(); key.ToRegister(); Result cache = allocator()->Allocate(); - __ movq(cache.reg(), cache_obj, RelocInfo::EMBEDDED_OBJECT); + ASSERT(cache.is_valid()); + __ movq(cache.reg(), ContextOperand(rsi, Context::GLOBAL_INDEX)); + __ movq(cache.reg(), + FieldOperand(cache.reg(), GlobalObject::kGlobalContextOffset)); + __ movq(cache.reg(), + ContextOperand(cache.reg(), Context::JSFUNCTION_RESULT_CACHES_INDEX)); + __ movq(cache.reg(), + FieldOperand(cache.reg(), FixedArray::OffsetOfElementAt(cache_id))); Result tmp = allocator()->Allocate(); + ASSERT(tmp.is_valid()); DeferredSearchCache* deferred = new DeferredSearchCache(tmp.reg(), cache.reg(),