-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Document API added in .NET 10.0 #120670
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
base: main
Are you sure you want to change the base?
Document API added in .NET 10.0 #120670
Changes from all commits
13d1ffc
f2b78f8
28cf6a0
9e99369
ff71581
c598aa6
8295f1b
c9b043c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,35 @@ | |
|
||
namespace System.Runtime.InteropServices.Java | ||
{ | ||
/// <summary> | ||
/// Provides helpers to create and manage GC handles used for tracking references | ||
/// between the managed runtime and a Java VM. These APIs allow managed objects | ||
/// to be referenced from native Java code so the runtime can participate in | ||
/// cross-reference processing and correctly control object lifetime across | ||
/// the managed/native boundary. | ||
/// </summary> | ||
[CLSCompliant(false)] | ||
[SupportedOSPlatform("android")] | ||
public static partial class JavaMarshal | ||
{ | ||
/// <summary> | ||
/// Initializes the Java marshal subsystem with a callback used when the runtime | ||
/// needs to mark managed objects that are referenced from Java during cross- | ||
/// reference processing. | ||
/// </summary> | ||
/// <param name="markCrossReferences">A pointer to an unmanaged callback that | ||
/// will be invoked to enumerate or mark managed objects referenced from Java | ||
/// during a cross-reference sweep. The callback is expected to accept a | ||
/// <see cref="MarkCrossReferencesArgs"/> pointer describing the objects to mark.</param> | ||
/// <exception cref="ArgumentNullException">Thrown when <paramref name="markCrossReferences"/> is null.</exception> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exception text is not supposed to start with "Thrown when..." - see https://github.com/dotnet/dotnet-api-docs/wiki/Exceptions#how-to. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This wording needs to be changed throughout... |
||
/// <exception cref="InvalidOperationException">Thrown when the subsystem cannot be initialized or is reinitialized.</exception> | ||
/// <exception cref="PlatformNotSupportedException">Thrown when the runtime or platform does not support Java cross-reference marshalling.</exception> | ||
/// <remarks> | ||
/// Only a single initialization is supported for the process. The runtime | ||
/// stores the provided function pointer and will invoke it from internal | ||
/// runtime code when cross-reference marking is required. | ||
/// Additionally, this callback must be implemented in unmanaged code. | ||
/// </remarks> | ||
public static unsafe void Initialize(delegate* unmanaged<MarkCrossReferencesArgs*, void> markCrossReferences) | ||
{ | ||
ArgumentNullException.ThrowIfNull(markCrossReferences); | ||
|
@@ -20,6 +45,20 @@ public static unsafe void Initialize(delegate* unmanaged<MarkCrossReferencesArgs | |
} | ||
} | ||
|
||
/// <summary> | ||
/// Creates a GC handle that native Java code can hold to reference a managed | ||
/// object. The handle prevents the object from being reclaimed while the | ||
/// native side holds the reference, and an opaque <paramref name="context"/> | ||
/// value can be associated with the handle for later retrieval. | ||
/// </summary> | ||
/// <param name="obj">The managed object to be referenced from native code.</param> | ||
/// <param name="context">An opaque pointer-sized value that will be associated | ||
/// with the handle and can be retrieved by the runtime via <see cref="GetContext(GCHandle)"/>. | ||
/// Callers may use this to store native-side state or identifiers alongside | ||
/// the handle.</param> | ||
/// <returns>A <see cref="GCHandle"/> that represents the allocated reference-tracking handle.</returns> | ||
/// <exception cref="ArgumentNullException">Thrown when <paramref name="obj"/> is null.</exception> | ||
/// <exception cref="PlatformNotSupportedException">Thrown when the runtime or platform does not support Java cross-reference marshalling.</exception> | ||
public static unsafe GCHandle CreateReferenceTrackingHandle(object obj, void* context) | ||
{ | ||
ArgumentNullException.ThrowIfNull(obj); | ||
|
@@ -28,6 +67,18 @@ public static unsafe GCHandle CreateReferenceTrackingHandle(object obj, void* co | |
return GCHandle.FromIntPtr(handle); | ||
} | ||
|
||
/// <summary> | ||
/// Retrieves the opaque context pointer associated with a reference-tracking | ||
/// GC handle previously created using <see cref="CreateReferenceTrackingHandle(object, void*)"/>. | ||
/// </summary> | ||
/// <param name="obj">The <see cref="GCHandle"/> whose context should be returned.</param> | ||
/// <returns>The opaque context pointer associated with the handle.</returns> | ||
/// <exception cref="InvalidOperationException">Thrown when the provided handle is null or does not represent a reference-tracking handle.</exception> | ||
/// <exception cref="PlatformNotSupportedException">Thrown when the runtime or platform does not support Java cross-reference marshalling.</exception> | ||
/// <remarks> | ||
/// The returned pointer is the exact value that was originally provided as | ||
/// the context parameter when the handle was created. | ||
/// </remarks> | ||
public static unsafe void* GetContext(GCHandle obj) | ||
{ | ||
IntPtr handle = GCHandle.ToIntPtr(obj); | ||
|
@@ -40,6 +91,15 @@ public static unsafe GCHandle CreateReferenceTrackingHandle(object obj, void* co | |
return context; | ||
} | ||
|
||
/// <summary> | ||
/// Completes processing of cross references after the runtime has invoked the | ||
/// callback provided to <see cref="Initialize" />. This notifies the runtime of | ||
/// handles that are no longer reachable from native Java code so the runtime | ||
/// can release or update them accordingly. | ||
/// </summary> | ||
/// <param name="crossReferences">A pointer to the structure containing cross-reference information produced during marking.</param> | ||
/// <param name="unreachableObjectHandles">A span of <see cref="GCHandle"/> values that were determined to be unreachable from the native side.</param> | ||
/// <exception cref="PlatformNotSupportedException">Thrown when the runtime or platform does not support Java cross-reference marshalling.</exception> | ||
public static unsafe void FinishCrossReferenceProcessing( | ||
MarkCrossReferencesArgs* crossReferences, | ||
ReadOnlySpan<GCHandle> unreachableObjectHandles) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you use this prompt by any chance? https://github.com/github/awesome-copilot/blob/main/prompts/csharp-docs.prompt.md |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,35 @@ | |
|
||
namespace System.Runtime.InteropServices.Java | ||
{ | ||
/// <summary> | ||
/// Provides helpers to create and manage GC handles used for tracking references | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Summaries are supposed to be a single sentence according to https://github.com/dotnet/dotnet-api-docs/wiki/Summary. |
||
/// between the managed runtime and a Java VM. These APIs allow managed objects | ||
/// to be referenced from native Java code so the runtime can participate in | ||
/// cross-reference processing and correctly control object lifetime across | ||
/// the managed/native boundary. | ||
/// </summary> | ||
[CLSCompliant(false)] | ||
[SupportedOSPlatform("android")] | ||
public static partial class JavaMarshal | ||
{ | ||
/// <summary> | ||
/// Initializes the Java marshal subsystem with a callback used when the runtime | ||
/// needs to mark managed objects that are referenced from Java during cross- | ||
/// reference processing. | ||
/// </summary> | ||
/// <param name="markCrossReferences">A pointer to an unmanaged callback that | ||
/// will be invoked to enumerate or mark managed objects referenced from Java | ||
/// during a cross-reference sweep. The callback is expected to accept a | ||
/// <see cref="MarkCrossReferencesArgs"/> pointer describing the objects to mark.</param> | ||
/// <exception cref="ArgumentNullException">Thrown when <paramref name="markCrossReferences"/> is null.</exception> | ||
/// <exception cref="InvalidOperationException">Thrown when the subsystem cannot be initialized or is reinitialized.</exception> | ||
/// <exception cref="PlatformNotSupportedException">Thrown when the runtime or platform does not support Java cross-reference marshalling.</exception> | ||
/// <remarks> | ||
/// Only a single initialization is supported for the process. The runtime | ||
/// stores the provided function pointer and will invoke it from internal | ||
/// runtime code when cross-reference marking is required. | ||
ericstj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// Additionally, this callback must be implemented in unmanaged code. | ||
/// </remarks> | ||
public static unsafe void Initialize(delegate* unmanaged<MarkCrossReferencesArgs*, void> markCrossReferences) | ||
{ | ||
ArgumentNullException.ThrowIfNull(markCrossReferences); | ||
|
@@ -20,12 +45,38 @@ public static unsafe void Initialize(delegate* unmanaged<MarkCrossReferencesArgs | |
} | ||
} | ||
|
||
/// <summary> | ||
/// Creates a GC handle that native Java code can hold to reference a managed | ||
/// object. The handle prevents the object from being reclaimed while the | ||
/// native side holds the reference, and an opaque <paramref name="context"/> | ||
/// value can be associated with the handle for later retrieval. | ||
/// </summary> | ||
/// <param name="obj">The managed object to be referenced from native code.</param> | ||
/// <param name="context">An opaque pointer-sized value that will be associated | ||
/// with the handle and can be retrieved by the runtime via <see cref="GetContext(GCHandle)"/>. | ||
/// Callers may use this to store native-side state or identifiers alongside | ||
/// the handle.</param> | ||
/// <returns>A <see cref="GCHandle"/> that represents the allocated reference-tracking handle.</returns> | ||
/// <exception cref="ArgumentNullException">Thrown when <paramref name="obj"/> is null.</exception> | ||
/// <exception cref="PlatformNotSupportedException">Thrown when the runtime or platform does not support Java cross-reference marshalling.</exception> | ||
public static unsafe GCHandle CreateReferenceTrackingHandle(object obj, void* context) | ||
{ | ||
ArgumentNullException.ThrowIfNull(obj); | ||
return GCHandle.FromIntPtr(RuntimeImports.RhHandleAllocCrossReference(obj, (IntPtr)context)); | ||
} | ||
|
||
/// <summary> | ||
/// Retrieves the opaque context pointer associated with a reference-tracking | ||
/// GC handle previously created using <see cref="CreateReferenceTrackingHandle(object, void*)"/>. | ||
/// </summary> | ||
/// <param name="obj">The <see cref="GCHandle"/> whose context should be returned.</param> | ||
/// <returns>The opaque context pointer associated with the handle.</returns> | ||
/// <exception cref="InvalidOperationException">Thrown when the provided handle is null or does not represent a reference-tracking handle.</exception> | ||
/// <exception cref="PlatformNotSupportedException">Thrown when the runtime or platform does not support Java cross-reference marshalling.</exception> | ||
/// <remarks> | ||
/// The returned pointer is the exact value that was originally provided as | ||
/// the context parameter when the handle was created. | ||
/// </remarks> | ||
public static unsafe void* GetContext(GCHandle obj) | ||
{ | ||
IntPtr handle = GCHandle.ToIntPtr(obj); | ||
|
@@ -37,6 +88,15 @@ public static unsafe GCHandle CreateReferenceTrackingHandle(object obj, void* co | |
return (void*)context; | ||
} | ||
|
||
/// <summary> | ||
/// Completes processing of cross references after the runtime has invoked the | ||
/// callback provided to <see cref="Initialize" />. This notifies the runtime of | ||
/// handles that are no longer reachable from native Java code so the runtime | ||
/// can release or update them accordingly. | ||
/// </summary> | ||
/// <param name="crossReferences">A pointer to the structure containing cross-reference information produced during marking.</param> | ||
/// <param name="unreachableObjectHandles">A span of <see cref="GCHandle"/> values that were determined to be unreachable from the native side.</param> | ||
/// <exception cref="PlatformNotSupportedException">Thrown when the runtime or platform does not support Java cross-reference marshalling.</exception> | ||
public static unsafe void FinishCrossReferenceProcessing( | ||
MarkCrossReferencesArgs* crossReferences, | ||
ReadOnlySpan<GCHandle> unreachableObjectHandles) | ||
|
Uh oh!
There was an error while loading. Please reload this page.