Test the situation that the codegen cache hits the limit of capacity, in this case, eviction is needed when new insertion comes.
| 351 | /// Test the situation that the codegen cache hits the limit of capacity, in this case, |
| 352 | /// eviction is needed when new insertion comes. |
| 353 | void LlvmCodeGenCacheTest::TestAtCapacity(TCodeGenCacheMode::type mode) { |
| 354 | // Allocates memory for small examples. |
| 355 | int64_t codegen_cache_capacity = ENGINE_CACHE_SIZE + sizeof(CodeGenObjectCache) |
| 356 | + sizeof(CodeGenCacheEntry) + CodeGenCacheKey::OptimalKeySize + sizeof(std::string); |
| 357 | bool is_normal_mode = !CodeGenCacheModeAnalyzer::is_optimal(mode); |
| 358 | |
| 359 | // Create two LlvmCodeGen objects containing a different codegen function separately. |
| 360 | scoped_ptr<LlvmCodeGen> codegen; |
| 361 | |
| 362 | test_env_->ResetCodegenCache(metrics_.get()); |
| 363 | CodeGenCache* cache = test_env_->codegen_cache(); |
| 364 | EXPECT_OK(cache->Init(codegen_cache_capacity)); |
| 365 | |
| 366 | ASSERT_OK(LlvmCodeGen::CreateImpalaCodegen(fragment_state_, nullptr, "test", &codegen)); |
| 367 | AddLlvmCodegenEcho(codegen.get()); |
| 368 | codegen->GenerateFunctionNamesHashCode(); |
| 369 | scoped_ptr<LlvmCodeGen> codegen_double; |
| 370 | ASSERT_OK(LlvmCodeGen::CreateImpalaCodegen( |
| 371 | fragment_state_, nullptr, "test_double", &codegen_double)); |
| 372 | AddLlvmCodegenDouble(codegen_double.get()); |
| 373 | codegen_double->GenerateFunctionNamesHashCode(); |
| 374 | CheckObjCacheExists(codegen.get()); |
| 375 | CheckObjCacheExists(codegen_double.get()); |
| 376 | |
| 377 | CodeGenCacheKey cache_key_1; |
| 378 | CodeGenCacheKey cache_key_2; |
| 379 | string key_1 = "key1"; |
| 380 | string key_2 = "key2"; |
| 381 | CodeGenCacheKeyConstructor::construct(key_1, &cache_key_1); |
| 382 | CodeGenCacheKeyConstructor::construct(key_2, &cache_key_2); |
| 383 | int64_t mem_charge_1 = GetMemCharge(codegen.get(), cache_key_1.data(), is_normal_mode); |
| 384 | int64_t mem_charge_2 = GetMemCharge(codegen.get(), cache_key_2.data(), is_normal_mode); |
| 385 | // Make sure the memory charge of two keys is larger than capacity for testing the |
| 386 | // eviction. |
| 387 | ASSERT_LE(mem_charge_1, codegen_cache_capacity); |
| 388 | ASSERT_LE(mem_charge_2, codegen_cache_capacity); |
| 389 | ASSERT_GE(mem_charge_1 + mem_charge_2, codegen_cache_capacity); |
| 390 | |
| 391 | scoped_ptr<MetricGroup> metrics; |
| 392 | metrics.reset(new MetricGroup("codegen-test-capacity")); |
| 393 | test_env_->ResetCodegenCache(metrics.get()); |
| 394 | cache = test_env_->codegen_cache(); |
| 395 | EXPECT_OK(cache->Init(codegen_cache_capacity)); |
| 396 | |
| 397 | // Expect init metrics. |
| 398 | CheckMetrics(cache, 0 /*hit*/, 0 /*miss*/, 0 /*evict*/); |
| 399 | |
| 400 | // Store key_1 and lookup. |
| 401 | EXPECT_OK(codegen->StoreCache(cache_key_1)); |
| 402 | EXPECT_TRUE(codegen->LookupCache(cache_key_1)); |
| 403 | CheckResult(codegen.get()); |
| 404 | CheckMetrics(cache, 1 /*hit*/, 0 /*miss*/, 0 /*evict*/); |
| 405 | |
| 406 | // Store key_2, key_1 should be evicted due to hitting the capaticy limit. |
| 407 | EXPECT_OK(codegen_double->StoreCache(cache_key_2)); |
| 408 | CheckMetrics(cache, 1 /*hit*/, 0 /*miss*/, 1 /*evict*/); |
| 409 | |
| 410 | // Lookup key_1, should be gone. Lookup key_2, should be successful. |
nothing calls this directly
no test coverage detected