33#include < host/typemap.hh>
44#include < runtime-base/timing-internal.hh>
55#include < runtime-base/search.hh>
6+ #include < runtime-base/util.hh>
67#include < shared/xxhash.hh>
78#include < xamarin-app.hh>
89
@@ -14,10 +15,6 @@ namespace {
1415 static inline constexpr size_t MVID_SIZE = 16 ;
1516 static inline constexpr size_t NUM_HYPHENS = 4 ;
1617 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- };
2118
2219 public:
2320 explicit MonoGuidString (const uint8_t *mvid) noexcept
@@ -29,8 +26,8 @@ namespace {
2926
3027 // In the caller we trust, we have no way to validate the size here
3128 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 ;
3431 };
3532
3633 auto hyphen = [this ] (size_t &dest_idx) {
@@ -240,7 +237,7 @@ auto TypeMapper::typemap_managed_to_java (const char *typeName, const uint8_t *m
240237
241238#if defined(DEBUG)
242239[[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
244241{
245242 Helpers::abort_application (" typemap_java_to_managed not implemented for debug builds yet" );
246243}
@@ -258,32 +255,65 @@ auto TypeMapper::find_java_to_managed_entry (hash_t name_hash) noexcept -> const
258255}
259256
260257[[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
262259{
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 ;
265289 }
266290
267- hash_t name_hash = xxhash::hash (typeName , strlen (typeName ));
291+ hash_t name_hash = xxhash::hash (java_type_name , strlen (java_type_name ));
268292 TypeMapJava const * java_entry = find_java_to_managed_entry (name_hash);
269293 if (java_entry == nullptr ) {
270294 log_info (
271295 LOG_ASSEMBLY,
272296 " typemap: unable to find mapping to a managed type from Java type '{}' (hash {:x})" ,
273- optional_string (typeName ),
297+ optional_string (java_type_name ),
274298 name_hash
275299 );
276300
277- return nullptr ;
301+ return false ;
278302 }
279303
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+
280308 log_debug (
281309 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 ),
284312 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)
286315 );
287- return managed_type_names[java_entry->managed_type_name_index ];
316+
317+ return true ;
288318}
289319#endif // ndef DEBUG
0 commit comments