Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use enum for frametype not v table #112166

Merged
merged 20 commits into from
Feb 11, 2025

Conversation

davidwrighton
Copy link
Member

@davidwrighton davidwrighton commented Feb 5, 2025

Frames are currently identified by VTable, which is convenient for writing C++ code, but less so for writing asm, or out of process inspection. This change changes that to a FrameIdentifier enum, make the polymorphic dispatch occur using if statements, and removes GS cookies for Frame's as we no longer need to protect the vtable.

Copy link
Contributor

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

@davidwrighton davidwrighton changed the title [DRAFT] Use enum for frametype not v table Use enum for frametype not v table Feb 6, 2025
@davidwrighton davidwrighton marked this pull request as ready for review February 6, 2025 23:01
Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM otherwise. Thank you!

@@ -269,77 +512,30 @@ void Frame::LogFrameChain(

#ifndef DACCESS_COMPILE

// This hashtable contains the vtable value of every Frame type.
static PtrHashMap* s_pFrameVTables = NULL;

// static
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// static

@@ -198,19 +445,19 @@ const size_t FRAME_TYPES_COUNT =
//-----------------------------------------------------------------------
// Implementation of the global table of names. On the DAC side, just the global pointer.
// On the runtime side, the array of names.
#define FRAME_TYPE_NAME(x) {x::GetMethodFrameVPtr(), #x} ,
#define FRAME_TYPE_NAME(x) {FrameIdentifier::x, #x} ,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FrameIdentifier does not need to be in the table anymore. We can just index into the table.

@@ -198,19 +445,19 @@ const size_t FRAME_TYPES_COUNT =
//-----------------------------------------------------------------------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FRAME_TYPES_COUNT above can be deleted

} // void Frame::Init()

#endif // DACCESS_COMPILE

// Returns true if the Frame's VTablePtr is valid

// static
bool Frame::HasValidVTablePtr(Frame * pFrame)
bool Frame::HasFrameIdentifier(Frame * pFrame)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool Frame::HasFrameIdentifier(Frame * pFrame)
bool Frame::HasValidFrameIdentifier(Frame * pFrame)

?

#include "frames.h"

LIMITED_METHOD_CONTRACT;
_frameIdentifier = frameIdentifier;
} // void Frame::Init()

#endif // DACCESS_COMPILE

// Returns true if the Frame's VTablePtr is valid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Returns true if the Frame's VTablePtr is valid
// Returns true if the Frame has a valid FrameIdentifier


void Frame::GcScanRoots(promote_func *fn, ScanContext* sc)
{
switch (this->GetFrameIdentifier())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
switch (this->GetFrameIdentifier())
switch (GetFrameIdentifier())

Nit: this-> should not be needed

FRAME_POLYMORPHIC_DISPATCH_UNREACHABLE();
return NULL;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}

Comment on lines 83 to 84

#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#endif
#endif

}
}


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@max-charlamb
Copy link
Contributor

Resolves #111875

@davidwrighton
Copy link
Member Author

This change refactors the frame identification mechanism in the runtime by replacing the use of the VTable with an enum FrameIdentifier. The VTable-based approach more suited to C++ code, but presented challenges for assembly code and out-of-process inspections. By using FrameIdentifier, polymorphic dispatch is now handled via if-statements. This change also eliminates the need for GS cookies on Frame objects, as it is no longer necessary to protect the VTable.

Key changes include:

Renaming FrameType to FrameIdentifier
Introducing a GetFrameIdentifier method
This update streamlines frame management while improving performance and flexibility for various platforms.

@davidwrighton davidwrighton merged commit 44b7251 into dotnet:main Feb 11, 2025
93 of 97 checks passed
grendello added a commit to grendello/runtime that referenced this pull request Feb 12, 2025
* main:
  [Android] Run CoreCLR functional tests on Android (dotnet#112283)
  [LoongArch64] Fix some assertion failures for Debug ILC building Debug NativeAOT testcases. (dotnet#112229)
  Fix suspicious code fragments (dotnet#112384)
  `__ComObject` doesn't support dynamic interface map (dotnet#112375)
  Native DLLs: only load imported DLLs from System32 (dotnet#112359)
  [main] Update dependencies from dotnet/roslyn (dotnet#112314)
  Update SVE instructions that writes to GC regs (dotnet#112389)
  Bring up android+coreclr windows build.  (dotnet#112256)
  Never use heap for return buffers (dotnet#112060)
  Wait to complete the test before releasing the agile reference. (dotnet#112387)
  Prevent returning disposed HTTP/1.1 connections to the pool (dotnet#112383)
  Fingerprint dotnet.js if writing import map to html is enabled (dotnet#112407)
  Remove duplicate definition of CORECLR_HOSTING_API_LINKAGE (dotnet#112096)
  Update the exception message to reflect current behavior. (dotnet#112355)
  Use enum for frametype not v table (dotnet#112166)
  Enable AltJits build for LoongArch64 and RiscV64 (dotnet#110282)
  Guard members of MonoType union & fix related bugs (dotnet#111645)
  Add optional hooks for debugging OpenSSL memory allocations (dotnet#111539)
  JIT: Optimize struct parameter register accesses in the backend (dotnet#110819)
  NativeAOT: Cover more opcodes in type preinitializer (dotnet#112073)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants