V8 Project
v8::internal::compiler::NodeCache< Key > Class Template Reference

#include <node-cache.h>

+ Inheritance diagram for v8::internal::compiler::NodeCache< Key >:
+ Collaboration diagram for v8::internal::compiler::NodeCache< Key >:

Classes

struct  Entry
 

Public Member Functions

 NodeCache (int max=256)
 
Node ** Find (Zone *zone, Key key)
 

Private Member Functions

bool Resize (Zone *zone)
 

Private Attributes

Entryentries_
 
int32_t size_
 
int32_t max_
 

Detailed Description

template<typename Key>
class v8::internal::compiler::NodeCache< Key >

Definition at line 19 of file node-cache.h.

Constructor & Destructor Documentation

◆ NodeCache()

template<typename Key >
v8::internal::compiler::NodeCache< Key >::NodeCache ( int  max = 256)
inlineexplicit

Definition at line 21 of file node-cache.h.

21 : entries_(NULL), size_(0), max_(max) {}
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

Member Function Documentation

◆ Find()

template<typename Key >
Node ** v8::internal::compiler::NodeCache< Key >::Find ( Zone zone,
Key  key 
)

Definition at line 78 of file node-cache.cc.

78  {
79  int32_t hash = NodeCacheHash(key);
80  if (entries_ == NULL) {
81  // Allocate the initial entries and insert the first entry.
82  int num_entries = INITIAL_SIZE + LINEAR_PROBE;
83  entries_ = zone->NewArray<Entry>(num_entries);
85  memset(entries_, 0, sizeof(Entry) * num_entries);
86  Entry* entry = &entries_[hash & (INITIAL_SIZE - 1)];
87  entry->key_ = key;
88  return &entry->value_;
89  }
90 
91  while (true) {
92  // Search up to N entries after (linear probing).
93  int start = hash & (size_ - 1);
94  int end = start + LINEAR_PROBE;
95  for (int i = start; i < end; i++) {
96  Entry* entry = &entries_[i];
97  if (entry->key_ == key) return &entry->value_;
98  if (entry->value_ == NULL) {
99  entry->key_ = key;
100  return &entry->value_;
101  }
102  }
103 
104  if (!Resize(zone)) break; // Don't grow past the maximum size.
105  }
106 
107  // If resized to maximum and still didn't find space, overwrite an entry.
108  Entry* entry = &entries_[hash & (size_ - 1)];
109  entry->key_ = key;
110  entry->value_ = NULL;
111  return &entry->value_;
112 }
int int32_t
Definition: unicode.cc:24
int32_t NodeCacheHash(Key key)
Definition: node-cache.cc:15
#define INITIAL_SIZE
Definition: node-cache.cc:11
#define LINEAR_PROBE
Definition: node-cache.cc:12

References INITIAL_SIZE, v8::internal::compiler::NodeCache< Key >::Entry::key_, LINEAR_PROBE, v8::internal::Zone::NewArray(), v8::internal::compiler::NodeCacheHash(), NULL, and v8::internal::compiler::NodeCache< Key >::Entry::value_.

+ Here is the call graph for this function:

◆ Resize()

template<typename Key >
bool v8::internal::compiler::NodeCache< Key >::Resize ( Zone zone)
private

Definition at line 45 of file node-cache.cc.

45  {
46  if (size_ >= max_) return false; // Don't grow past the maximum size.
47 
48  // Allocate a new block of entries 4x the size.
49  Entry* old_entries = entries_;
50  int old_size = size_ + LINEAR_PROBE;
51  size_ = size_ * 4;
52  int num_entries = size_ + LINEAR_PROBE;
53  entries_ = zone->NewArray<Entry>(num_entries);
54  memset(entries_, 0, sizeof(Entry) * num_entries);
55 
56  // Insert the old entries into the new block.
57  for (int i = 0; i < old_size; i++) {
58  Entry* old = &old_entries[i];
59  if (old->value_ != NULL) {
60  int hash = NodeCacheHash(old->key_);
61  int start = hash & (size_ - 1);
62  int end = start + LINEAR_PROBE;
63  for (int j = start; j < end; j++) {
64  Entry* entry = &entries_[j];
65  if (entry->value_ == NULL) {
66  entry->key_ = old->key_;
67  entry->value_ = old->value_;
68  break;
69  }
70  }
71  }
72  }
73  return true;
74 }

References v8::internal::compiler::NodeCache< Key >::Entry::key_, LINEAR_PROBE, v8::internal::Zone::NewArray(), v8::internal::compiler::NodeCacheHash(), NULL, and v8::internal::compiler::NodeCache< Key >::Entry::value_.

+ Here is the call graph for this function:

Member Data Documentation

◆ entries_

template<typename Key >
Entry* v8::internal::compiler::NodeCache< Key >::entries_
private

Definition at line 38 of file node-cache.h.

◆ max_

template<typename Key >
int32_t v8::internal::compiler::NodeCache< Key >::max_
private

Definition at line 40 of file node-cache.h.

◆ size_

template<typename Key >
int32_t v8::internal::compiler::NodeCache< Key >::size_
private

Definition at line 39 of file node-cache.h.


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