Skip to content

Type loading deep type hierarchy with an intermediate or base type missing can trigger stack overflow #131679

Description

@janvorli

The type loading in the runtime is a recursive algorithm that consumes quite significant amount of stack space per type hierarchy level. Moreover, the stack consumption gets amplified if an exception is thrown when attempting to load one of the intermediate or the base type due to the behavior of native EH on Windows. On each level, there is EX_TRY with EX_HOOK block that does some state maintenance and then rethrows. That again grows the stack since native EH on Windows doesn't unwind the stack until a catch block completes without exceptions.

A first party has hit a problem when a 57 level trivial type hierarchy consumed more than 1.5MB of stack space, triggering stack overflow. Just the loading of that type hierarchy without an exception consumes ~500kB of memory.

The amplification due to the native EH can be mitigated by replacing the EX_HOOK by EX_CATCH and rethrowing after the catch (for Exception derived exceptions).
However, it seems it would make sense to remove the recursion if possible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-VM-coreclruntriagedNew issue has not been triaged by the area owner

    Type

    No type

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions