| 108 | } |
| 109 | |
| 110 | Status CodeGenCache::Lookup(const CodeGenCacheKey& cache_key, |
| 111 | const TCodeGenCacheMode::type& mode, CodeGenCacheEntry* entry, |
| 112 | shared_ptr<CodeGenObjectCache>* cached_engine) { |
| 113 | DCHECK(!is_closed_); |
| 114 | DCHECK(cache_ != nullptr); |
| 115 | DCHECK(entry != nullptr); |
| 116 | DCHECK(cached_engine != nullptr); |
| 117 | // Use hash code and the total length as the key for optimal mode, because the whole |
| 118 | // key could be very large, using optimal mode could improve the performance and save |
| 119 | // memory consumption. However, it could lead to a collision, even though the chance |
| 120 | // is very small, in that case, we may switch to normal mode for the query or disable |
| 121 | // the codegen cache. |
| 122 | Slice key; |
| 123 | if (CodeGenCacheModeAnalyzer::is_optimal(mode)) { |
| 124 | key = cache_key.optimal_key_slice(); |
| 125 | } else { |
| 126 | key = cache_key.data_slice(); |
| 127 | } |
| 128 | Cache::UniqueHandle handle(cache_->Lookup(key)); |
| 129 | if (handle.get() != nullptr) { |
| 130 | const CodeGenCacheEntry* cached_entry = |
| 131 | reinterpret_cast<const CodeGenCacheEntry*>(cache_->Value(handle).data()); |
| 132 | // Need to find the shared pointer of the engine from the cache before return, |
| 133 | // because the shared pointer could be deleted in the eviction process. |
| 134 | // If can't find it, treat it as cache missing, because the engine is needed |
| 135 | // to look for jitted functions. |
| 136 | if (LookupEngine(cached_entry->cached_engine_pointer, cached_engine)) { |
| 137 | entry->Reset(cached_entry->cached_engine_pointer, cached_entry->num_functions, |
| 138 | cached_entry->num_instructions, cached_entry->num_opt_functions, |
| 139 | cached_entry->num_opt_instructions, cached_entry->function_names_hashcode, |
| 140 | cached_entry->total_bytes_charge, cached_entry->opt_level); |
| 141 | return Status::OK(); |
| 142 | } |
| 143 | } |
| 144 | entry->Reset(); |
| 145 | return Status::OK(); |
| 146 | } |
| 147 | |
| 148 | Status CodeGenCache::StoreInternal(const CodeGenCacheKey& cache_key, |
| 149 | LlvmCodeGen* codegen, TCodeGenCacheMode::type mode, |