Skip to content

Add first-gate listener override handling#977

Merged
masesdevelopers merged 9 commits intomasterfrom
974-use-listenershallmanageevent-feature-of-jvmbridgelistener-to-early-discard-unused-methods
Apr 25, 2026
Merged

Add first-gate listener override handling#977
masesdevelopers merged 9 commits intomasterfrom
974-use-listenershallmanageevent-feature-of-jvmbridgelistener-to-early-discard-unused-methods

Conversation

@masesdevelopers
Copy link
Copy Markdown
Contributor

Description

Introduce a first-gate mechanism to optimize and detect CLR-side listener overrides.

  • InternalMethods.cs: added builder/strings to emit listener "first gate" parameter type lists and wiring to replace a new template placeholder; track event handler index and insert a first-gate block before listener handlers so listener dispatch can quickly test if the CLR override exists.
  • Templates: added GetMethodIsOverridden helper and a readonly flag in the generated class template to detect if ListenerShallManageEvent is overridden (second gate). Added new template placeholders/constants and formats (SINGLE_LISTENER_FIRST_GATE_FORMAT and BLOCK_LISTENER_FIRST_GATE_FORMAT). Updated single-listener template to store handler index, check override presence, and short-circuit when no override is present.
  • Misc: switched listener execution helper to use a readonly _hasOverride flag and pass listener parameter type info for the first-gate checks.

This change reduces unnecessary event processing by quickly determining whether the CLR implementation overrides the listener before doing heavier event analysis.

Related Issue

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Introduce a first-gate mechanism to optimize and detect CLR-side listener overrides.

- InternalMethods.cs: added builder/strings to emit listener "first gate" parameter type lists and wiring to replace a new template placeholder; track event handler index and insert a first-gate block before listener handlers so listener dispatch can quickly test if the CLR override exists.
- Templates: added GetMethodIsOverridden helper and a readonly flag in the generated class template to detect if ListenerShallManageEvent is overridden (second gate). Added new template placeholders/constants and formats (SINGLE_LISTENER_FIRST_GATE_FORMAT and BLOCK_LISTENER_FIRST_GATE_FORMAT). Updated single-listener template to store handler index, check override presence, and short-circuit when no override is present.
- Misc: switched listener execution helper to use a readonly _hasOverride flag and pass listener parameter type info for the first-gate checks.

This change reduces unnecessary event processing by quickly determining whether the CLR implementation overrides the listener before doing heavier event analysis.
Comment thread src/net/JNetReflector/InternalMethods.cs Fixed
{
var listenerBlock = string.Format(AllPackageClasses.ClassStub.MethodStub.BLOCK_LISTENER_HANDLER_FORMAT, classDefinition.JVMClassName(null, false, false), subListenerHandlerBlock.ToString());
returnStr = listenerBlock + returnStr;
var firstGateBlock = string.Format(AllPackageClasses.ClassStub.MethodStub.BLOCK_LISTENER_FIRST_GATE_FORMAT, subListenerFirstGateBlock.ToString());
@masesdevelopers masesdevelopers merged commit 2b07209 into master Apr 25, 2026
25 checks passed
@masesdevelopers masesdevelopers deleted the 974-use-listenershallmanageevent-feature-of-jvmbridgelistener-to-early-discard-unused-methods branch April 25, 2026 00:57
@masesdevelopers masesdevelopers self-assigned this Apr 25, 2026
@masesdevelopers masesdevelopers added enhancement New feature or request JNetReflector JNetReflector related issue .NET Pull requests that update .net code labels Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request JNetReflector JNetReflector related issue .NET Pull requests that update .net code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use ListenerShallManageEvent feature of JVMBridgeListener to early discard unused methods

1 participant