3
3
#include < host/typemap.hh>
4
4
#include < runtime-base/timing-internal.hh>
5
5
#include < runtime-base/search.hh>
6
+ #include < runtime-base/util.hh>
6
7
#include < shared/xxhash.hh>
7
8
#include < xamarin-app.hh>
8
9
@@ -14,10 +15,6 @@ namespace {
14
15
static inline constexpr size_t MVID_SIZE = 16 ;
15
16
static inline constexpr size_t NUM_HYPHENS = 4 ;
16
17
static inline constexpr size_t BUF_SIZE = (MVID_SIZE * 2 ) + NUM_HYPHENS + 1 ;
17
- static inline std::array<char , 16 > hex_map {
18
- ' 0' , ' 1' , ' 2' , ' 3' , ' 4' , ' 5' , ' 6' , ' 7' ,
19
- ' 8' , ' 9' , ' a' , ' b' , ' c' , ' d' , ' e' , ' f' ,
20
- };
21
18
22
19
public:
23
20
explicit MonoGuidString (const uint8_t *mvid) noexcept
@@ -29,8 +26,8 @@ namespace {
29
26
30
27
// In the caller we trust, we have no way to validate the size here
31
28
auto to_hex = [this , &mvid] (size_t &dest_idx, size_t src_idx) {
32
- _ascii_form[dest_idx++] = hex_map[ (mvid[src_idx] & 0xf0 ) >> 4 ] ;
33
- _ascii_form[ dest_idx++] = hex_map[mvid[src_idx] & 0x0f ] ;
29
+ Util::to_hex (mvid[src_idx], _ascii_form[dest_idx], _ascii_form[dest_idx + 1 ]) ;
30
+ dest_idx += 2 ;
34
31
};
35
32
36
33
auto hyphen = [this ] (size_t &dest_idx) {
@@ -240,7 +237,7 @@ auto TypeMapper::typemap_managed_to_java (const char *typeName, const uint8_t *m
240
237
241
238
#if defined(DEBUG)
242
239
[[gnu::flatten]]
243
- auto TypeMapper::typemap_java_to_managed (const char *typeName ) noexcept -> const char*
240
+ auto TypeMapper::typemap_java_to_managed (const char *java_type_name, char const ** assembly_name, uint32_t *managed_type_token_id ) noexcept -> bool
244
241
{
245
242
Helpers::abort_application (" typemap_java_to_managed not implemented for debug builds yet" );
246
243
}
@@ -258,32 +255,65 @@ auto TypeMapper::find_java_to_managed_entry (hash_t name_hash) noexcept -> const
258
255
}
259
256
260
257
[[gnu::flatten]]
261
- auto TypeMapper::typemap_java_to_managed (const char *typeName ) noexcept -> const char*
258
+ auto TypeMapper::typemap_java_to_managed (const char *java_type_name, char const ** assembly_name, uint32_t *managed_type_token_id ) noexcept -> bool
262
259
{
263
- if (typeName == nullptr ) [[unlikely]] {
264
- return nullptr ;
260
+ if (java_type_name == nullptr || assembly_name == nullptr || managed_type_token_id == nullptr ) [[unlikely]] {
261
+ if (java_type_name == nullptr ) {
262
+ log_warn (
263
+ LOG_ASSEMBLY,
264
+ " typemap: required parameter `{}` not passed to {}" ,
265
+ " java_type_name" sv,
266
+ __PRETTY_FUNCTION__
267
+ );
268
+ }
269
+
270
+ if (assembly_name == nullptr ) {
271
+ log_warn (
272
+ LOG_ASSEMBLY,
273
+ " typemap: required parameter `{}` not passed to {}" ,
274
+ " assembly_name" sv,
275
+ __PRETTY_FUNCTION__
276
+ );
277
+ }
278
+
279
+ if (managed_type_token_id == nullptr ) {
280
+ log_warn (
281
+ LOG_ASSEMBLY,
282
+ " typemap: required parameter `{}` not passed to {}" ,
283
+ " managed_type_token_id" sv,
284
+ __PRETTY_FUNCTION__
285
+ );
286
+ }
287
+
288
+ return false ;
265
289
}
266
290
267
- hash_t name_hash = xxhash::hash (typeName , strlen (typeName ));
291
+ hash_t name_hash = xxhash::hash (java_type_name , strlen (java_type_name ));
268
292
TypeMapJava const * java_entry = find_java_to_managed_entry (name_hash);
269
293
if (java_entry == nullptr ) {
270
294
log_info (
271
295
LOG_ASSEMBLY,
272
296
" typemap: unable to find mapping to a managed type from Java type '{}' (hash {:x})" ,
273
- optional_string (typeName ),
297
+ optional_string (java_type_name ),
274
298
name_hash
275
299
);
276
300
277
- return nullptr ;
301
+ return false ;
278
302
}
279
303
304
+ TypeMapModule const &module = managed_to_java_map[java_entry->module_index ];
305
+ *assembly_name = managed_assembly_names[module .assembly_name_index ];
306
+ *managed_type_token_id = java_entry->managed_type_token_id ;
307
+
280
308
log_debug (
281
309
LOG_ASSEMBLY,
282
- " Java type '{}' corresponds to managed type '{}' ({:p} " ,
283
- optional_string (typeName ),
310
+ " Java type '{}' corresponds to managed type '{}' (token 0x{:x} in assembly '{}') " ,
311
+ optional_string (java_type_name ),
284
312
optional_string (managed_type_names[java_entry->managed_type_name_index ]),
285
- reinterpret_cast <const void *>(managed_type_names[java_entry->managed_type_name_index ])
313
+ *managed_type_token_id,
314
+ optional_string (*assembly_name)
286
315
);
287
- return managed_type_names[java_entry->managed_type_name_index ];
316
+
317
+ return true ;
288
318
}
289
319
#endif // ndef DEBUG
0 commit comments