Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Mono.Android/Android.Runtime/JNIEnvInit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ internal static unsafe void Initialize (JnienvInitializeArgs* args)
if (RuntimeFeature.IsMonoRuntime) {
valueManager = new AndroidValueManager ();
} else if (RuntimeFeature.IsCoreClrRuntime) {
valueManager = ManagedValueManager.GetOrCreateInstance ();
valueManager = ManagedValueManager.Instance;
} else {
throw new NotSupportedException ("Internal error: unknown runtime not supported");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class ManagedValueManager : JniRuntime.JniValueManager
bool _disposed;

static Lazy<ManagedValueManager> s_instance = new (() => new ManagedValueManager ());
public static ManagedValueManager GetOrCreateInstance () => s_instance.Value;

public static ManagedValueManager Instance => s_instance.Value;
Comment on lines 32 to +34
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

s_instance should be static readonly since it is only assigned once, and the blank line after it currently contains stray whitespace. Making the field readonly and removing whitespace-only indentation helps prevent accidental reassignment and keeps the file clean per typical style/linters.

Copilot uses AI. Check for mistakes.

Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

GetOrCreateInstance() has been removed/renamed to Instance, but there are still callers in the repo (e.g. src/Microsoft.Android.Runtime.NativeAOT/Android.Runtime.NativeAOT/JavaInteropRuntime.cs and src/Microsoft.Android.Runtime.NativeAOT/Java.Interop/JreRuntime.cs). This will break builds for those projects unless the call sites are updated to use ManagedValueManager.Instance (or a temporary compatibility wrapper is kept).

Suggested change
public static ManagedValueManager GetOrCreateInstance ()
{
return Instance;
}

Copilot uses AI. Check for mistakes.
unsafe ManagedValueManager ()
{
Expand Down Expand Up @@ -441,13 +442,13 @@ static unsafe void BridgeProcessingFinished (MarkCrossReferencesArgs* mcr)

// Schedule cleanup of _registeredInstances on a thread pool thread.
// The bridge thread must not take lock(_registeredInstances) — see deadlock notes.
Task.Run (GetOrCreateInstance ().CollectPeers);
Task.Run (Instance.CollectPeers);
}

static unsafe ReadOnlySpan<GCHandle> ProcessCollectedContexts (MarkCrossReferencesArgs* mcr)
{
List<GCHandle> handlesToFree = [];
ManagedValueManager instance = GetOrCreateInstance ();
ManagedValueManager instance = Instance;

for (int i = 0; (nuint)i < mcr->ComponentCount; i++) {
StronglyConnectedComponent component = mcr->Components [i];
Expand Down
Loading