Skip to content

Commit

Permalink
.NET: Speed up generation time, fix massive local GC heap overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Sep 17, 2024
1 parent 18b301f commit fe3b0d5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 23 deletions.
34 changes: 11 additions & 23 deletions csharp-api/REFrameworkNET/Method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,18 @@ ManagedObject^ Method::GetRuntimeMethod() {
return nullptr;
}

// System.Type
auto runtimeType = declaringType->GetRuntimeType()/*->As<System::Type^>()*/;

if (runtimeType == nullptr) {
return nullptr;
}

// Iterate over all methods in the runtime type
auto methods = (REFrameworkNET::ManagedObject^)runtimeType->Call("GetMethods(System.Reflection.BindingFlags)", System::Reflection::BindingFlags::Public | System::Reflection::BindingFlags::NonPublic | System::Reflection::BindingFlags::Instance | System::Reflection::BindingFlags::Static);

if (methods != nullptr) {
auto methodDefName = this->Name;
for each (REFrameworkNET::ManagedObject^ method in methods) {
// Get the type handle and compare it to this (raw pointer stored in the Method object)
// System.RuntimeMethodHandle automatically gets converted to a Method object
auto methodHandle = (Method^)method->Call("get_MethodHandle");

if (methodHandle == nullptr) {
continue;
}
auto methods = declaringType->GetRuntimeMethods();
for each (REFrameworkNET::ManagedObject^ method in methods) {
// Get the type handle and compare it to this (raw pointer stored in the Method object)
// System.RuntimeMethodHandle automatically gets converted to a Method object
auto methodHandle = (Method^)method->Call("get_MethodHandle");

if (methodHandle == nullptr) {
continue;
}

if (methodHandle->GetRaw() == this->GetRaw()) {
return method;
}
if (methodHandle->GetRaw() == this->GetRaw()) {
return method;
}
}

Expand Down
29 changes: 29 additions & 0 deletions csharp-api/REFrameworkNET/TypeDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,33 @@ namespace REFrameworkNET {

return m_elementType;
}

System::Collections::Generic::List<REFrameworkNET::ManagedObject^>^ TypeDefinition::GetRuntimeMethods() {
if (m_runtimeMethods == nullptr) {
m_runtimeMethods = gcnew System::Collections::Generic::List<ManagedObject^>();
auto runtimeType = GetRuntimeType();

m_lock->EnterWriteLock();

try {
if (runtimeType != nullptr) {
auto methods = (REFrameworkNET::ManagedObject^)runtimeType->Call("GetMethods(System.Reflection.BindingFlags)", System::Reflection::BindingFlags::Public | System::Reflection::BindingFlags::NonPublic | System::Reflection::BindingFlags::Instance | System::Reflection::BindingFlags::Static);

if (methods != nullptr) {
for each (REFrameworkNET::ManagedObject^ method in methods) {
if (method == nullptr) {
continue;
}

m_runtimeMethods->Add(method);
}
}
}
} finally {
m_lock->ExitWriteLock();
}
}

return m_runtimeMethods;
}
}
4 changes: 4 additions & 0 deletions csharp-api/REFrameworkNET/TypeDefinition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ public ref class TypeDefinition : public System::Dynamic::DynamicObject,
}
}

System::Collections::Generic::List<REFrameworkNET::ManagedObject^>^ GetRuntimeMethods();

/*Void* GetInstance()
{
return m_type->get_instance();
Expand Down Expand Up @@ -525,5 +527,7 @@ public ref class TypeDefinition : public System::Dynamic::DynamicObject,
System::Collections::Generic::List<REFrameworkNET::Method^>^ m_methods{nullptr};
System::Collections::Generic::List<REFrameworkNET::Field^>^ m_fields{nullptr};
System::Collections::Generic::List<REFrameworkNET::Property^>^ m_properties{nullptr};

System::Collections::Generic::List<REFrameworkNET::ManagedObject^>^ m_runtimeMethods{nullptr};
};
}

0 comments on commit fe3b0d5

Please sign in to comment.