This repository was archived by the owner on Jul 6, 2026. It is now read-only.
Commit b881d21
[Java.Interop] Remove JniObjectReference SafeHandle backend (#1446)
Related to #1448
## Summary
Remove the unsupported `JniObjectReference` SafeHandle backend and make the existing `IntPtr` representation the only implementation:
- remove `FEATURE_JNIOBJECTREFERENCE_SAFEHANDLES` / `FEATURE_JNIOBJECTREFERENCE_INTPTRS` branching from `Java.Interop`
- delete the unused `JniReferenceSafeHandle`, `JniLocalReference`, `JniGlobalReference`, `JniWeakGlobalReference`, and `JniAllocObjectRef` types
- delete the excluded SafeHandle-specific test
- remove the obsolete SafeHandle invocation strategy from `jnienv-gen` and regenerate `tests/invocation-overhead/jni.cs`
- update docs to describe the SafeHandle path as a historical experiment, not a supported backend
## Decision record
The SafeHandle backend was useful when Java.Interop was exploring how JNI object references should be represented. The architecture and invocation-overhead docs show the intended goals: stronger handle separation, possible GC cleanup of leaked JNI refs, and a way to compare a safer representation against an `IntPtr` representation.
That experiment has been rejected for the current runtime model:
- the active project build always used the `IntPtr`-backed `JniObjectReference` path
- trying to enable the SafeHandle object-reference symbol conflicts with the default `FEATURE_JNIOBJECTREFERENCE_INTPTRS` define
- the SafeHandle-only test was explicitly excluded from both this repo's test project and the Android test project
- the SafeHandle branch had stale code and was not maintained as a buildable configuration
- historical benchmarks showed SafeHandle-based JNI invocation was materially slower due to allocation and thread-safety costs
- Android now depends on the `JniObjectReferenceControlBlock`/`IntPtr` model for runtime and GC-bridge integration
Since there are no current plans to resurrect the SafeHandle backend, keeping it adds noise and gives a false impression that the configuration is supported. Git history preserves the experiment if it is ever needed again.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent a2b83e3 commit b881d21
22 files changed
Lines changed: 56 additions & 5600 deletions
File tree
- Documentation
- build-tools/jnienv-gen
- src/Java.Interop
- Java.Interop
- tests
- Java.Interop-Tests
- Java.Interop
- invocation-overhead
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
237 | 237 | | |
238 | 238 | | |
239 | 239 | | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
255 | 246 | | |
256 | 247 | | |
257 | 248 | | |
| |||
289 | 280 | | |
290 | 281 | | |
291 | 282 | | |
292 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
92 | 92 | | |
93 | | - | |
| 93 | + | |
94 | 94 | | |
95 | | - | |
| 95 | + | |
96 | 96 | | |
97 | | - | |
98 | | - | |
| 97 | + | |
| 98 | + | |
99 | 99 | | |
100 | | - | |
101 | | - | |
| 100 | + | |
| 101 | + | |
102 | 102 | | |
103 | | - | |
| 103 | + | |
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | | - | |
127 | 126 | | |
128 | 127 | | |
129 | 128 | | |
| |||
149 | 148 | | |
150 | 149 | | |
151 | 150 | | |
152 | | - | |
153 | 151 | | |
154 | 152 | | |
155 | 153 | | |
| |||
172 | 170 | | |
173 | 171 | | |
174 | 172 | | |
175 | | - | |
| 173 | + | |
176 | 174 | | |
177 | 175 | | |
178 | 176 | | |
| |||
186 | 184 | | |
187 | 185 | | |
188 | 186 | | |
189 | | - | |
| 187 | + | |
190 | 188 | | |
191 | 189 | | |
192 | 190 | | |
| |||
961 | 959 | | |
962 | 960 | | |
963 | 961 | | |
964 | | - | |
965 | 962 | | |
966 | 963 | | |
967 | 964 | | |
| |||
1070 | 1067 | | |
1071 | 1068 | | |
1072 | 1069 | | |
1073 | | - | |
1074 | 1070 | | |
1075 | 1071 | | |
1076 | 1072 | | |
| |||
1084 | 1080 | | |
1085 | 1081 | | |
1086 | 1082 | | |
1087 | | - | |
1088 | 1083 | | |
1089 | 1084 | | |
1090 | 1085 | | |
| |||
1099 | 1094 | | |
1100 | 1095 | | |
1101 | 1096 | | |
1102 | | - | |
1103 | 1097 | | |
1104 | 1098 | | |
1105 | 1099 | | |
| |||
1122 | 1116 | | |
1123 | 1117 | | |
1124 | 1118 | | |
1125 | | - | |
1126 | 1119 | | |
1127 | 1120 | | |
1128 | 1121 | | |
| |||
1186 | 1179 | | |
1187 | 1180 | | |
1188 | 1181 | | |
1189 | | - | |
| 1182 | + | |
1190 | 1183 | | |
1191 | | - | |
| 1184 | + | |
1192 | 1185 | | |
1193 | 1186 | | |
1194 | | - | |
1195 | 1187 | | |
1196 | 1188 | | |
1197 | 1189 | | |
1198 | 1190 | | |
1199 | 1191 | | |
1200 | 1192 | | |
1201 | | - | |
1202 | | - | |
1203 | 1193 | | |
1204 | 1194 | | |
1205 | 1195 | | |
| |||
1212 | 1202 | | |
1213 | 1203 | | |
1214 | 1204 | | |
1215 | | - | |
1216 | 1205 | | |
1217 | 1206 | | |
1218 | 1207 | | |
| |||
1226 | 1215 | | |
1227 | 1216 | | |
1228 | 1217 | | |
1229 | | - | |
1230 | | - | |
1231 | 1218 | | |
1232 | 1219 | | |
1233 | 1220 | | |
| |||
1241 | 1228 | | |
1242 | 1229 | | |
1243 | 1230 | | |
1244 | | - | |
1245 | 1231 | | |
1246 | 1232 | | |
1247 | 1233 | | |
| |||
1262 | 1248 | | |
1263 | 1249 | | |
1264 | 1250 | | |
1265 | | - | |
1266 | 1251 | | |
1267 | 1252 | | |
1268 | 1253 | | |
| |||
1283 | 1268 | | |
1284 | 1269 | | |
1285 | 1270 | | |
1286 | | - | |
| 1271 | + | |
1287 | 1272 | | |
1288 | 1273 | | |
1289 | 1274 | | |
| |||
1300 | 1285 | | |
1301 | 1286 | | |
1302 | 1287 | | |
1303 | | - | |
| 1288 | + | |
1304 | 1289 | | |
1305 | 1290 | | |
1306 | 1291 | | |
1307 | 1292 | | |
1308 | 1293 | | |
1309 | 1294 | | |
1310 | 1295 | | |
1311 | | - | |
| 1296 | + | |
1312 | 1297 | | |
1313 | 1298 | | |
1314 | 1299 | | |
| |||
1399 | 1384 | | |
1400 | 1385 | | |
1401 | 1386 | | |
1402 | | - | |
1403 | 1387 | | |
1404 | 1388 | | |
1405 | 1389 | | |
1406 | 1390 | | |
1407 | 1391 | | |
1408 | 1392 | | |
1409 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | 17 | | |
22 | | - | |
23 | 18 | | |
24 | 19 | | |
25 | 20 | | |
| |||
96 | 91 | | |
97 | 92 | | |
98 | 93 | | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | 94 | | |
104 | 95 | | |
105 | 96 | | |
106 | 97 | | |
107 | 98 | | |
108 | | - | |
109 | 99 | | |
110 | 100 | | |
111 | 101 | | |
| |||
131 | 121 | | |
132 | 122 | | |
133 | 123 | | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | 124 | | |
139 | 125 | | |
140 | 126 | | |
| |||
143 | 129 | | |
144 | 130 | | |
145 | 131 | | |
146 | | - | |
147 | 132 | | |
148 | 133 | | |
149 | 134 | | |
| |||
287 | 272 | | |
288 | 273 | | |
289 | 274 | | |
290 | | - | |
291 | 275 | | |
292 | 276 | | |
293 | 277 | | |
294 | | - | |
295 | 278 | | |
296 | 279 | | |
297 | 280 | | |
298 | 281 | | |
299 | 282 | | |
300 | 283 | | |
301 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | 24 | | |
29 | | - | |
30 | 25 | | |
31 | 26 | | |
32 | 27 | | |
| |||
37 | 32 | | |
38 | 33 | | |
39 | 34 | | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | 35 | | |
45 | 36 | | |
46 | 37 | | |
47 | 38 | | |
48 | 39 | | |
49 | | - | |
50 | 40 | | |
51 | 41 | | |
52 | 42 | | |
| |||
86 | 76 | | |
87 | 77 | | |
88 | 78 | | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | 79 | | |
94 | 80 | | |
95 | 81 | | |
| |||
98 | 84 | | |
99 | 85 | | |
100 | 86 | | |
101 | | - | |
102 | 87 | | |
103 | 88 | | |
104 | 89 | | |
| |||
176 | 161 | | |
177 | 162 | | |
178 | 163 | | |
179 | | - | |
180 | 164 | | |
181 | 165 | | |
182 | 166 | | |
183 | | - | |
184 | 167 | | |
185 | 168 | | |
186 | 169 | | |
187 | 170 | | |
188 | 171 | | |
189 | 172 | | |
190 | | - | |
This file was deleted.
0 commit comments