Use HostAllocator directly when possible
authorMike Danes <onemihaid@hotmail.com>
Sat, 14 Oct 2017 11:21:28 +0000 (14:21 +0300)
committerMike Danes <onemihaid@hotmail.com>
Sun, 15 Oct 2017 10:29:47 +0000 (13:29 +0300)
Makes it easier to find unnecessary uses of IAllocator

src/jit/hostallocator.h
src/jit/jit.h
src/jit/utils.cpp
src/jit/utils.h

index c48ed45..6da736c 100644 (file)
@@ -2,7 +2,9 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
-class HostAllocator : public IAllocator
+#pragma once
+
+class HostAllocator final : public IAllocator
 {
 private:
     static HostAllocator s_hostAllocator;
@@ -20,3 +22,15 @@ public:
 
     static HostAllocator* getHostAllocator();
 };
+
+// Global operator new overloads that work with HostAllocator
+
+inline void* __cdecl operator new(size_t n, HostAllocator* alloc)
+{
+    return alloc->Alloc(n);
+}
+
+inline void* __cdecl operator new[](size_t n, HostAllocator* alloc)
+{
+    return alloc->Alloc(n);
+}
index a395756..4315f94 100644 (file)
@@ -699,7 +699,7 @@ inline size_t unsigned_abs(ssize_t x)
 class Histogram
 {
 public:
-    Histogram(IAllocator* allocator, const unsigned* const sizeTable);
+    Histogram(HostAllocator* allocator, const unsigned* const sizeTable);
     ~Histogram();
 
     void dump(FILE* output);
@@ -708,7 +708,7 @@ public:
 private:
     void ensureAllocated();
 
-    IAllocator*           m_allocator;
+    HostAllocator*        m_allocator;
     unsigned              m_sizeCount;
     const unsigned* const m_sizeTable;
     unsigned*             m_counts;
index 2bf9bd0..a203eda 100644 (file)
@@ -882,7 +882,7 @@ void ConfigMethodRange::InitRanges(const wchar_t* rangeStr, unsigned capacity)
  *  Histogram class.
  */
 
-Histogram::Histogram(IAllocator* allocator, const unsigned* const sizeTable)
+Histogram::Histogram(HostAllocator* allocator, const unsigned* const sizeTable)
     : m_allocator(allocator), m_sizeTable(sizeTable), m_counts(nullptr)
 {
     unsigned sizeCount = 0;
@@ -1540,7 +1540,7 @@ void HelperCallProperties::init()
 // MyAssembly;mscorlib;System
 // MyAssembly;mscorlib System
 
-AssemblyNamesList2::AssemblyNamesList2(const wchar_t* list, IAllocator* alloc) : m_alloc(alloc)
+AssemblyNamesList2::AssemblyNamesList2(const wchar_t* list, HostAllocator* alloc) : m_alloc(alloc)
 {
     assert(m_alloc != nullptr);
 
index e4c6975..750af2d 100644 (file)
@@ -17,6 +17,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 #define _UTILS_H_
 
 #include "iallocator.h"
+#include "hostallocator.h"
 #include "cycletimer.h"
 
 // Needed for unreached()
@@ -548,12 +549,12 @@ class AssemblyNamesList2
         AssemblyName* m_next;
     };
 
-    AssemblyName* m_pNames; // List of names
-    IAllocator*   m_alloc;  // IAllocator to use in this class
+    AssemblyName*  m_pNames; // List of names
+    HostAllocator* m_alloc;  // HostAllocator to use in this class
 
 public:
     // Take a Unicode string list of assembly names, parse it, and store it.
-    AssemblyNamesList2(const wchar_t* list, __in IAllocator* alloc);
+    AssemblyNamesList2(const wchar_t* list, __in HostAllocator* alloc);
 
     ~AssemblyNamesList2();