| 24449 | } |
| 24450 | |
| 24451 | void BfModule::CheckHotMethod(BfMethodInstance* methodInstance, const StringImpl& inMangledName) |
| 24452 | { |
| 24453 | if (methodInstance->mHotMethod != NULL) |
| 24454 | return; |
| 24455 | |
| 24456 | if ((mCompiler->mOptions.mAllowHotSwapping) && (!methodInstance->mIsUnspecialized)) |
| 24457 | { |
| 24458 | auto srcTypeInst = methodInstance->GetOwner(); |
| 24459 | if (srcTypeInst->mHotTypeData == NULL) |
| 24460 | return; |
| 24461 | |
| 24462 | StringT<128> mangledName = inMangledName; |
| 24463 | |
| 24464 | if (mangledName.IsEmpty()) |
| 24465 | BfMangler::Mangle(mangledName, mCompiler->GetMangleKind(), methodInstance); |
| 24466 | |
| 24467 | // We always keep the current primary method at the same address |
| 24468 | BfHotMethod* hotMethod; |
| 24469 | BfHotMethod** hotMethodPtr; |
| 24470 | if (mCompiler->mHotData->mMethodMap.TryAdd(mangledName, NULL, &hotMethodPtr)) |
| 24471 | { |
| 24472 | hotMethod = new BfHotMethod(); |
| 24473 | *hotMethodPtr = hotMethod; |
| 24474 | hotMethod->mRefCount = 1; |
| 24475 | hotMethod->mFlags = (BfHotDepDataFlags)(hotMethod->mFlags | BfHotDepDataFlag_IsBound); |
| 24476 | #ifdef BF_DBG_HOTMETHOD_IDX |
| 24477 | static int sMethodIdx = 0; |
| 24478 | hotMethod->mMethodIdx = sMethodIdx++; |
| 24479 | #endif |
| 24480 | |
| 24481 | BfLogSysM("HotMethodData %p created for method %p %s - %s\n", hotMethod, methodInstance, MethodToString(methodInstance).c_str(), mangledName.c_str()); |
| 24482 | } |
| 24483 | else |
| 24484 | { |
| 24485 | hotMethod = *hotMethodPtr; |
| 24486 | if ((hotMethod->mFlags & BfHotDepDataFlag_IsBound) != 0) |
| 24487 | { |
| 24488 | // This is a duplicate mangled name - we link to this new entry via a 'BfHotDupMethod' |
| 24489 | auto prevHotMethod = *hotMethodPtr; |
| 24490 | |
| 24491 | hotMethod = new BfHotMethod(); |
| 24492 | hotMethod->mFlags = (BfHotDepDataFlags)(hotMethod->mFlags | BfHotDepDataFlag_IsBound); |
| 24493 | |
| 24494 | BfHotDupMethod* hotDupMethod = new BfHotDupMethod(hotMethod); |
| 24495 | hotDupMethod->mRefCount++; |
| 24496 | prevHotMethod->mReferences.Add(hotDupMethod); |
| 24497 | prevHotMethod->mFlags = (BfHotDepDataFlags)(hotMethod->mFlags | BfHotDepDataFlag_HasDup); |
| 24498 | |
| 24499 | BfLogSysM("HotMethodData %p (duplicate of %p) created for method %p %s - %s\n", hotMethod, prevHotMethod, methodInstance, MethodToString(methodInstance).c_str(), mangledName.c_str()); |
| 24500 | } |
| 24501 | else if (mCompiler->IsHotCompile()) |
| 24502 | { |
| 24503 | // Link the previous version into the mPrevVersion |
| 24504 | BfHotMethod* prevMethod = new BfHotMethod(); |
| 24505 | prevMethod->mRefCount = 1; |
| 24506 | prevMethod->mPrevVersion = hotMethod->mPrevVersion; |
| 24507 | hotMethod->mPrevVersion = prevMethod; |
| 24508 |
no test coverage detected