Commit c7ec0ac
[Mono.Android] JNI handles are now in a "control block" (#10179)
Originally from: #10125
Context: dotnet/java-interop#1339
These are changes to Mono's GC bridge implementation, such that the
same code can be used on both Mono and CoreCLR.
The base `JavaObject` type has changes such as:
```diff
--[NonSerialized] IntPtr handle;
--[NonSerialized] JniObjectReferenceType handle_type;
--[NonSerialized] IntPtr weak_handle;
--[NonSerialized] int refs_added;
++unsafe JniObjectReferenceControlBlock* jniObjectReferenceControlBlock;
```
And the new `JniObjectReferenceControlBlock` struct is defined as:
internal struct JniObjectReferenceControlBlock {
public IntPtr handle;
public int handle_type;
public IntPtr weak_handle;
public int refs_added;
}
* Each `JavaObject` allocation now has a `NativeMemory.AllocZeroed()`
call for this struct.
* However, we only have to read a single field now using Mono's native
embedding API:
```diff
--info->handle = mono_class_get_field_from_name (info->klass, const_cast<char*> ("handle"));
--info->handle_type = mono_class_get_field_from_name (info->klass, const_cast<char*> ("handle_type"));
--info->refs_added = mono_class_get_field_from_name (info->klass, const_cast<char*> ("refs_added"));
--info->weak_handle = mono_class_get_field_from_name (info->klass, const_cast<char*> ("weak_handle"));
++info->jniObjectReferenceControlBlock = mono_class_get_field_from_name (info->klass, const_cast<char*> ("jniObjectReferenceControlBlock"));
```
We are hoping this results in ~the same performance as before, with
the flexibility to support multiple GC bridge implementations and
runtimes.
Other changes:
* Fix SIGSEGV when using the new control block
We were using it incorrectly - there's no need to fetch/set values of managed object fields.
The correct thing to do is to read/write them on the control block itself.
Co-authored-by: Marek Habersack <grendel@twistedcode.net>1 parent cfa4209 commit c7ec0ac
File tree
5 files changed
+98
-71
lines changed- external
- src
- Microsoft.Android.Sdk.ILLink/PreserveLists
- native/mono/monodroid
5 files changed
+98
-71
lines changedSubmodule Java.Interop updated 10 files
- src/Java.Interop/Java.Interop/IJavaPeerable.cs+2
- src/Java.Interop/Java.Interop/JavaException.cs+25-11
- src/Java.Interop/Java.Interop/JavaObject.cs+27-12
- src/Java.Interop/Java.Interop/JniManagedPeerStates.cs+8
- src/Java.Interop/Java.Interop/JniObjectReferenceControlBlock.cs+30
- src/Java.Interop/PublicAPI.Unshipped.txt+1
- src/java-interop/java-interop-gc-bridge-mono.cc+137-68
- src/java-interop/java-interop-gc-bridge.h+24
- tests/Java.Interop-Tests/Java.Interop/JavaObjectArrayTest.cs+24
- tests/Java.Interop-Tests/Java.Interop/JavaObjectTest.cs+2-2
Lines changed: 2 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
| 5 | + | |
8 | 6 | | |
9 | 7 | | |
10 | | - | |
11 | | - | |
12 | | - | |
| 8 | + | |
13 | 9 | | |
14 | 10 | | |
15 | 11 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
793 | 793 | | |
794 | 794 | | |
795 | 795 | | |
796 | | - | |
797 | | - | |
798 | | - | |
799 | | - | |
| 796 | + | |
800 | 797 | | |
801 | | - | |
802 | | - | |
| 798 | + | |
803 | 799 | | |
804 | | - | |
805 | | - | |
| 800 | + | |
| 801 | + | |
806 | 802 | | |
807 | 803 | | |
808 | | - | |
809 | | - | |
810 | | - | |
811 | | - | |
| 804 | + | |
812 | 805 | | |
813 | 806 | | |
814 | 807 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | 45 | | |
49 | 46 | | |
50 | 47 | | |
| |||
76 | 73 | | |
77 | 74 | | |
78 | 75 | | |
79 | | - | |
80 | | - | |
81 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
82 | 84 | | |
83 | 85 | | |
84 | 86 | | |
| |||
102 | 104 | | |
103 | 105 | | |
104 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
105 | 120 | | |
106 | 121 | | |
107 | 122 | | |
| |||
456 | 471 | | |
457 | 472 | | |
458 | 473 | | |
459 | | - | |
460 | 474 | | |
461 | 475 | | |
462 | | - | |
463 | | - | |
| 476 | + | |
| 477 | + | |
464 | 478 | | |
| 479 | + | |
465 | 480 | | |
466 | | - | |
467 | | - | |
| 481 | + | |
| 482 | + | |
468 | 483 | | |
469 | 484 | | |
470 | 485 | | |
| |||
476 | 491 | | |
477 | 492 | | |
478 | 493 | | |
479 | | - | |
480 | | - | |
| 494 | + | |
| 495 | + | |
481 | 496 | | |
482 | 497 | | |
483 | 498 | | |
| |||
491 | 506 | | |
492 | 507 | | |
493 | 508 | | |
494 | | - | |
495 | | - | |
| 509 | + | |
| 510 | + | |
496 | 511 | | |
497 | 512 | | |
498 | 513 | | |
| |||
504 | 519 | | |
505 | 520 | | |
506 | 521 | | |
507 | | - | |
508 | 522 | | |
509 | 523 | | |
510 | | - | |
511 | | - | |
| 524 | + | |
| 525 | + | |
512 | 526 | | |
| 527 | + | |
513 | 528 | | |
514 | | - | |
| 529 | + | |
515 | 530 | | |
516 | 531 | | |
517 | 532 | | |
518 | 533 | | |
519 | 534 | | |
520 | | - | |
| 535 | + | |
521 | 536 | | |
522 | 537 | | |
523 | 538 | | |
524 | 539 | | |
525 | | - | |
526 | | - | |
| 540 | + | |
| 541 | + | |
527 | 542 | | |
528 | 543 | | |
529 | 544 | | |
| |||
558 | 573 | | |
559 | 574 | | |
560 | 575 | | |
561 | | - | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
562 | 580 | | |
563 | | - | |
564 | | - | |
565 | | - | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
566 | 585 | | |
567 | | - | |
568 | | - | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
569 | 592 | | |
570 | 593 | | |
571 | 594 | | |
| |||
574 | 597 | | |
575 | 598 | | |
576 | 599 | | |
577 | | - | |
| 600 | + | |
578 | 601 | | |
579 | 602 | | |
580 | | - | |
| 603 | + | |
581 | 604 | | |
582 | 605 | | |
583 | 606 | | |
| |||
603 | 626 | | |
604 | 627 | | |
605 | 628 | | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
606 | 633 | | |
607 | | - | |
608 | | - | |
| 634 | + | |
| 635 | + | |
609 | 636 | | |
610 | | - | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
611 | 640 | | |
612 | 641 | | |
613 | 642 | | |
| |||
648 | 677 | | |
649 | 678 | | |
650 | 679 | | |
651 | | - | |
652 | | - | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
653 | 685 | | |
654 | 686 | | |
655 | 687 | | |
| |||
867 | 899 | | |
868 | 900 | | |
869 | 901 | | |
870 | | - | |
871 | | - | |
872 | 902 | | |
873 | 903 | | |
874 | | - | |
875 | | - | |
| 904 | + | |
| 905 | + | |
876 | 906 | | |
877 | | - | |
878 | | - | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
879 | 911 | | |
880 | 912 | | |
881 | 913 | | |
| |||
884 | 916 | | |
885 | 917 | | |
886 | 918 | | |
887 | | - | |
888 | | - | |
| 919 | + | |
| 920 | + | |
889 | 921 | | |
890 | 922 | | |
891 | 923 | | |
| |||
951 | 983 | | |
952 | 984 | | |
953 | 985 | | |
954 | | - | |
| 986 | + | |
955 | 987 | | |
956 | 988 | | |
957 | | - | |
958 | | - | |
959 | | - | |
960 | | - | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
961 | 993 | | |
962 | 994 | | |
963 | 995 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
44 | 49 | | |
45 | 50 | | |
46 | 51 | | |
| |||
127 | 132 | | |
128 | 133 | | |
129 | 134 | | |
| 135 | + | |
130 | 136 | | |
131 | 137 | | |
132 | 138 | | |
| |||
0 commit comments