Added DisableInlining flag to the ProfileData.
authorBrian Sullivan <briansul@microsoft.com>
Fri, 31 Mar 2017 01:16:58 +0000 (18:16 -0700)
committerBrian Sullivan <briansul@microsoft.com>
Fri, 31 Mar 2017 21:43:13 +0000 (14:43 -0700)
Extended CompileStatus to have both COMPILE_HOT_EXCLUDED and COMPILE_COLD_EXCLUDED.
Fixes the IsNull implementation
Fixes getBBProfileData to handle the case where pos can now be zero

Commit migrated from https://github.com/dotnet/coreclr/commit/ed8ab5793008d3a87d5518458565a30e8d9a0414

src/coreclr/src/inc/corbbtprof.h
src/coreclr/src/zap/zapimage.cpp
src/coreclr/src/zap/zapimage.h
src/coreclr/src/zap/zapinfo.cpp

index ba00984..5aa7782 100644 (file)
@@ -178,6 +178,7 @@ enum MethodProfilingDataFlags
     WriteMethodPrecode            = 12, // 0x01000
     ExcludeHotMethodCode          = 13, // 0x02000  // Hot method should be excluded from the ReadyToRun image
     ExcludeColdMethodCode         = 14, // 0x04000  // Cold method should be excluded from the ReadyToRun image
+    DisableInlining               = 15, // 0x08000  // Disable inlining of this method in optimized AOT native code
 };
 
 enum GeneralProfilingDataFlags
index 2e3aace..cb69ba9 100644 (file)
@@ -1089,14 +1089,14 @@ HANDLE ZapImage::SaveImage(LPCWSTR wszOutputFileName, CORCOMPILE_NGEN_SIGNATURE
 
     OutputTables();
 
-       // Create a empty export table.  This makes tools like symchk not think
-       // that native images are resoure-only DLLs.  It is important to NOT
-       // be a resource-only DLL because those DLL's PDBS are not put up on the
-       // symbol server and we want NEN PDBS to be placed there.  
-       ZapPEExports* exports = new(GetHeap()) ZapPEExports(wszOutputFileName);
-       m_pDebugSection->Place(exports);
-       SetDirectoryEntry(IMAGE_DIRECTORY_ENTRY_EXPORT, exports);
-
+    // Create a empty export table.  This makes tools like symchk not think
+    // that native images are resoure-only DLLs.  It is important to NOT
+    // be a resource-only DLL because those DLL's PDBS are not put up on the
+    // symbol server and we want NEN PDBS to be placed there.  
+    ZapPEExports* exports = new(GetHeap()) ZapPEExports(wszOutputFileName);
+    m_pDebugSection->Place(exports);
+    SetDirectoryEntry(IMAGE_DIRECTORY_ENTRY_EXPORT, exports);
+    
     ComputeRVAs();
 
     if (!IsReadyToRunCompilation())
@@ -1610,7 +1610,7 @@ void ZapImage::ProfileDisableInlining()
             // Hot methods can be marked to be excluded from the AOT native image.
             // We also need to disable inlining of such methods.
             //
-            if ((methodProfilingDataFlags & (1 << ExcludeHotMethodCode)) != 0)
+            if ((methodProfilingDataFlags & (1 << DisableInlining)) != 0)
             {
                 // Disable the inlining of this method
                 //
@@ -1685,7 +1685,7 @@ void ZapImage::CompileHotRegion()
                 }
             }
 
-            // Update the 'flags' saved in the profileDataHashTable hash table.
+            // Update the 'flags' and 'compileResult' saved in the profileDataHashTable hash table.
             //
             hashBBUpdateFlagsAndCompileResult(token, methodProfilingDataFlags, compileResult);
         }
@@ -2100,8 +2100,8 @@ ZapImage::CompileStatus ZapImage::TryCompileMethodWorker(CORINFO_METHOD_HANDLE h
         //
         if ((methodProfilingDataFlags & (1 << ExcludeHotMethodCode)) != 0)
         {
-            // returning COMPILE_EXCLUDED excludes this method from the AOT native image
-            return COMPILE_EXCLUDED;
+            // returning COMPILE_HOT_EXCLUDED excludes this method from the AOT native image
+            return COMPILE_HOT_EXCLUDED;
         }
 
         // Cold methods can be marked to be excluded from the AOT native image.
@@ -2110,8 +2110,8 @@ ZapImage::CompileStatus ZapImage::TryCompileMethodWorker(CORINFO_METHOD_HANDLE h
         //
         if ((methodProfilingDataFlags & (1 << ExcludeColdMethodCode)) != 0)
         {
-            // returning COMPILE_EXCLUDED excludes this method from the AOT native image
-            return COMPILE_EXCLUDED;
+            // returning COMPILE_COLD_EXCLUDED excludes this method from the AOT native image
+            return COMPILE_COLD_EXCLUDED;
         }
 
         // If the code was never executed based on the profile data
@@ -2131,19 +2131,19 @@ ZapImage::CompileStatus ZapImage::TryCompileMethodWorker(CORINFO_METHOD_HANDLE h
         //
         if (m_zapper->m_pOpt->m_fPartialNGen)
         {
-            // returning COMPILE_EXCLUDED excludes this method from the AOT native image
-            return COMPILE_EXCLUDED;
+            // returning COMPILE_COLD_EXCLUDED excludes this method from the AOT native image
+            return COMPILE_COLD_EXCLUDED;
         }
 
         // Retrieve any information that we have about a previous compilation attempt of this method
         const ProfileDataHashEntry* pEntry = profileDataHashTable.LookupPtr(md);
 
         if (pEntry != nullptr)
-        {
-            if (pEntry->status == COMPILE_EXCLUDED)
+        { 
+            if ((pEntry->status == COMPILE_HOT_EXCLUDED) || (pEntry->status == COMPILE_COLD_EXCLUDED))
             {
-                // returning COMPILE_EXCLUDED excludes this method from the AOT native image
-                return COMPILE_EXCLUDED;
+                // returning COMPILE_HOT_EXCLUDED excludes this method from the AOT native image
+                return pEntry->status;
             }
         }
     }
index ba4bbc5..f0bcbcb 100644 (file)
@@ -338,10 +338,20 @@ private:
 
 public:
     enum CompileStatus {
-        LOOKUP_FAILED   = -2,  COMPILE_FAILED   = -1,      // Failure
-        NOT_COMPILED    =  0,  COMPILE_EXCLUDED =  1,      // Info
-        COMPILE_SUCCEED = 10,  ALREADY_COMPILED = 11
-    };      // Success
+        // Failure status values are negative
+        LOOKUP_FAILED    = -2,
+        COMPILE_FAILED   = -1,
+
+        // Info status values are [0..9]
+        NOT_COMPILED          =  0,
+        COMPILE_EXCLUDED      =  1,
+        COMPILE_HOT_EXCLUDED  =  2,
+        COMPILE_COLD_EXCLUDED =  3,
+
+        // Successful status values are 10 or greater
+        COMPILE_SUCCEED  = 10,
+        ALREADY_COMPILED = 11
+    };
 
 private:
     // A hash table entry that contains the profile infomation and the CompileStatus for a given method
@@ -376,8 +386,24 @@ private:
             return (count_t)k;
         }
 
-        static const element_t Null() { LIMITED_METHOD_CONTRACT; ProfileDataHashEntry e; e.pos = 0; e.size = 0; e.md = 0; return e; } // Assuming method profile data cannot start from position 0.
-        static bool IsNull(const element_t &e) { LIMITED_METHOD_CONTRACT; return e.pos == 0; }
+        static const element_t Null()
+        {
+            LIMITED_METHOD_CONTRACT; 
+            ProfileDataHashEntry e; 
+            e.md = 0; 
+            e.size = 0; 
+            e.pos = 0;
+            e.flags = 0;
+            e.status = NOT_COMPILED;
+            return e;
+        }
+
+        static bool IsNull(const element_t &e)
+        {
+            LIMITED_METHOD_CONTRACT;
+            // returns true if both md and pos are zero
+            return (e.md == 0) && (e.pos == 0);
+        }
     };
     typedef SHash<ProfileDataHashTraits> ProfileDataHashTable;
 
index 9713ce5..af0c41c 100644 (file)
@@ -1009,12 +1009,19 @@ HRESULT ZapInfo::getBBProfileData (
     }
 
     // The md must match.
-    _ASSERTE(foundEntry->md == md); 
+    _ASSERTE(foundEntry->md == md);
 
+    if (foundEntry->pos == 0)
+    {
+        // We might not have profile data and instead only have CompileStatus and flags
+        assert(foundEntry->size == 0);
+        return E_FAIL;
+    }
+
+    //
     //
     // We found the md. Let's retrieve the profile data.
     //
-    _ASSERTE(foundEntry->pos > 0);                                   // The target position cannot be 0.
     _ASSERTE(foundEntry->size >= sizeof(CORBBTPROF_METHOD_HEADER));   // The size must at least this
 
     ProfileReader profileReader(DataSection_MethodBlockCounts->pData, DataSection_MethodBlockCounts->dataSize);