V8 Project
v8::internal::ScriptCache Class Reference

#include <debug.h>

+ Inheritance diagram for v8::internal::ScriptCache:
+ Collaboration diagram for v8::internal::ScriptCache:

Public Member Functions

 ScriptCache (Isolate *isolate)
 
virtual ~ScriptCache ()
 
void Add (Handle< Script > script)
 
Handle< FixedArrayGetScripts ()
 

Private Member Functions

void Clear ()
 
- Private Member Functions inherited from v8::internal::TemplateHashMapImpl< FreeStoreAllocationPolicy >
 TemplateHashMapImpl (MatchFun match, uint32_t capacity=kDefaultHashMapCapacity, FreeStoreAllocationPolicy allocator=FreeStoreAllocationPolicy())
 
 ~TemplateHashMapImpl ()
 
Entry * Lookup (void *key, uint32_t hash, bool insert, FreeStoreAllocationPolicy allocator=FreeStoreAllocationPolicy())
 
void * Remove (void *key, uint32_t hash)
 
void Clear ()
 
uint32_t occupancy () const
 
uint32_t capacity () const
 
Entry * Start () const
 
Entry * Next (Entry *p) const
 

Static Private Member Functions

static uint32_t Hash (int key)
 
static void HandleWeakScript (const v8::WeakCallbackData< v8::Value, void > &data)
 
- Static Private Member Functions inherited from v8::internal::TemplateHashMapImpl< FreeStoreAllocationPolicy >
static bool PointersMatch (void *key1, void *key2)
 

Private Attributes

Isolateisolate_
 

Additional Inherited Members

- Private Types inherited from v8::internal::TemplateHashMapImpl< FreeStoreAllocationPolicy >
typedef bool(* MatchFun) (void *key1, void *key2)
 
- Static Private Attributes inherited from v8::internal::TemplateHashMapImpl< FreeStoreAllocationPolicy >
static const uint32_t kDefaultHashMapCapacity
 

Detailed Description

Definition at line 151 of file debug.h.

Constructor & Destructor Documentation

◆ ScriptCache()

v8::internal::ScriptCache::ScriptCache ( Isolate isolate)
explicit

Definition at line 591 of file debug.cc.

592  isolate_(isolate) {
593  Heap* heap = isolate_->heap();
594  HandleScope scope(isolate_);
595 
596  // Perform two GCs to get rid of all unreferenced scripts. The first GC gets
597  // rid of all the cached script wrappers and the second gets rid of the
598  // scripts which are no longer referenced.
599  heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, "ScriptCache");
600  heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, "ScriptCache");
601 
602  // Scan heap for Script objects.
603  HeapIterator iterator(heap);
604  DisallowHeapAllocation no_allocation;
605 
606  for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) {
607  if (obj->IsScript() && Script::cast(obj)->HasValidSource()) {
608  Add(Handle<Script>(Script::cast(obj)));
609  }
610  }
611 }
static const int kMakeHeapIterableMask
Definition: heap.h:721
void Add(Handle< Script > script)
Definition: debug.cc:614
static bool PointersMatch(void *key1, void *key2)
Definition: hashmap.h:80
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
PerThreadAssertScopeDebugOnly< HEAP_ALLOCATION_ASSERT, false > DisallowHeapAllocation
Definition: assert-scope.h:110
TemplateHashMapImpl< FreeStoreAllocationPolicy > HashMap
Definition: hashmap.h:96

References Add(), v8::internal::Heap::CollectAllGarbage(), v8::internal::Isolate::heap(), isolate_, v8::internal::Heap::kMakeHeapIterableMask, and NULL.

+ Here is the call graph for this function:

◆ ~ScriptCache()

virtual v8::internal::ScriptCache::~ScriptCache ( )
inlinevirtual

Definition at line 154 of file debug.h.

154 { Clear(); }

References Clear().

+ Here is the call graph for this function:

Member Function Documentation

◆ Add()

void v8::internal::ScriptCache::Add ( Handle< Script script)

Definition at line 614 of file debug.cc.

614  {
615  GlobalHandles* global_handles = isolate_->global_handles();
616  // Create an entry in the hash map for the script.
617  int id = script->id()->value();
618  HashMap::Entry* entry =
619  HashMap::Lookup(reinterpret_cast<void*>(id), Hash(id), true);
620  if (entry->value != NULL) {
621 #ifdef DEBUG
622  // The code deserializer may introduce duplicate Script objects.
623  // Assert that the Script objects with the same id have the same name.
624  Handle<Script> found(reinterpret_cast<Script**>(entry->value));
625  DCHECK(script->id() == found->id());
626  DCHECK(!script->name()->IsString() ||
627  String::cast(script->name())->Equals(String::cast(found->name())));
628 #endif
629  return;
630  }
631  // Globalize the script object, make it weak and use the location of the
632  // global handle as the value in the hash map.
633  Handle<Script> script_ =
634  Handle<Script>::cast(global_handles->Create(*script));
635  GlobalHandles::MakeWeak(reinterpret_cast<Object**>(script_.location()),
636  this,
638  entry->value = script_.location();
639 }
static void MakeWeak(Object **location, void *parameter, WeakCallback weak_callback)
static Handle< T > cast(Handle< S > that)
Definition: handles.h:116
GlobalHandles * global_handles()
Definition: isolate.h:917
static void HandleWeakScript(const v8::WeakCallbackData< v8::Value, void > &data)
Definition: debug.cc:671
static uint32_t Hash(int key)
Definition: debug.h:164
Entry * Lookup(void *key, uint32_t hash, bool insert, FreeStoreAllocationPolicy allocator=FreeStoreAllocationPolicy())
Definition: hashmap.h:114
#define DCHECK(condition)
Definition: logging.h:205
kSerializedDataOffset Object
Definition: objects-inl.h:5322

References v8::internal::Handle< T >::cast(), v8::internal::GlobalHandles::Create(), DCHECK, v8::internal::Isolate::global_handles(), HandleWeakScript(), Hash(), isolate_, v8::internal::TemplateHashMapImpl< FreeStoreAllocationPolicy >::Lookup(), v8::internal::GlobalHandles::MakeWeak(), and NULL.

Referenced by v8::internal::Debug::OnAfterCompile(), and ScriptCache().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Clear()

void v8::internal::ScriptCache::Clear ( )
private

Definition at line 657 of file debug.cc.

657  {
658  // Iterate the script cache to get rid of all the weak handles.
659  for (HashMap::Entry* entry = Start(); entry != NULL; entry = Next(entry)) {
660  DCHECK(entry != NULL);
661  Object** location = reinterpret_cast<Object**>(entry->value);
662  DCHECK((*location)->IsScript());
664  GlobalHandles::Destroy(location);
665  }
666  // Clear the content of the hash map.
667  HashMap::Clear();
668 }
static void * ClearWeakness(Object **location)
static void Destroy(Object **location)

References v8::internal::TemplateHashMapImpl< FreeStoreAllocationPolicy >::Clear(), v8::internal::GlobalHandles::ClearWeakness(), DCHECK, v8::internal::GlobalHandles::Destroy(), v8::internal::TemplateHashMapImpl< FreeStoreAllocationPolicy >::Next(), NULL, and v8::internal::TemplateHashMapImpl< FreeStoreAllocationPolicy >::Start().

Referenced by ~ScriptCache().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetScripts()

Handle< FixedArray > v8::internal::ScriptCache::GetScripts ( )

Definition at line 642 of file debug.cc.

642  {
643  Factory* factory = isolate_->factory();
644  Handle<FixedArray> instances = factory->NewFixedArray(occupancy());
645  int count = 0;
646  for (HashMap::Entry* entry = Start(); entry != NULL; entry = Next(entry)) {
647  DCHECK(entry->value != NULL);
648  if (entry->value != NULL) {
649  instances->set(count, *reinterpret_cast<Script**>(entry->value));
650  count++;
651  }
652  }
653  return instances;
654 }
Factory * factory()
Definition: isolate.h:982

References DCHECK, v8::internal::Isolate::factory(), isolate_, v8::internal::TemplateHashMapImpl< FreeStoreAllocationPolicy >::Next(), NULL, v8::internal::TemplateHashMapImpl< FreeStoreAllocationPolicy >::occupancy(), and v8::internal::TemplateHashMapImpl< FreeStoreAllocationPolicy >::Start().

Referenced by v8::internal::Debug::GetLoadedScripts().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HandleWeakScript()

void v8::internal::ScriptCache::HandleWeakScript ( const v8::WeakCallbackData< v8::Value, void > &  data)
staticprivate

Definition at line 671 of file debug.cc.

672  {
673  // Retrieve the script identifier.
674  Handle<Object> object = Utils::OpenHandle(*data.GetValue());
675  int id = Handle<Script>::cast(object)->id()->value();
676  void* key = reinterpret_cast<void*>(id);
677  uint32_t hash = Hash(id);
678 
679  // Remove the corresponding entry from the cache.
680  ScriptCache* script_cache =
681  reinterpret_cast<ScriptCache*>(data.GetParameter());
682  HashMap::Entry* entry = script_cache->Lookup(key, hash, false);
683  Object** location = reinterpret_cast<Object**>(entry->value);
684  script_cache->Remove(key, hash);
685 
686  // Clear the weak handle.
687  GlobalHandles::Destroy(location);
688 }
static v8::internal::Handle< To > OpenHandle(v8::Local< From > handle)
Definition: api.h:288
P * GetParameter() const
Definition: v8.h:423
Local< T > GetValue() const
Definition: v8.h:422
ScriptCache(Isolate *isolate)
Definition: debug.cc:591

References v8::internal::Handle< T >::cast(), v8::internal::GlobalHandles::Destroy(), v8::WeakCallbackData< T, P >::GetParameter(), v8::WeakCallbackData< T, P >::GetValue(), Hash(), v8::internal::TemplateHashMapImpl< AllocationPolicy >::Lookup(), v8::Utils::OpenHandle(), and v8::internal::TemplateHashMapImpl< AllocationPolicy >::Remove().

Referenced by Add().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Hash()

static uint32_t v8::internal::ScriptCache::Hash ( int  key)
inlinestaticprivate

Definition at line 164 of file debug.h.

164  {
166  }
static const uint32_t kZeroHashSeed
Definition: utils.h:245
uint32_t ComputeIntegerHash(uint32_t key, uint32_t seed)
Definition: utils.h:249

References v8::internal::ComputeIntegerHash(), and v8::internal::kZeroHashSeed.

Referenced by Add(), and HandleWeakScript().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ isolate_

Isolate* v8::internal::ScriptCache::isolate_
private

Definition at line 175 of file debug.h.

Referenced by Add(), GetScripts(), and ScriptCache().


The documentation for this class was generated from the following files: