@@ -1444,34 +1444,45 @@ static jl_method_instance_t *cache_method(
1444
1444
1445
1445
static jl_method_match_t * _gf_invoke_lookup (jl_value_t * types JL_PROPAGATES_ROOT , jl_value_t * mt , size_t world , size_t * min_valid , size_t * max_valid );
1446
1446
1447
- static jl_method_instance_t * jl_mt_assoc_by_type (jl_methtable_t * mt JL_PROPAGATES_ROOT , jl_datatype_t * tt , size_t world )
1447
+ static jl_method_instance_t * jl_mt_assoc_by_type (jl_methtable_t * mt JL_PROPAGATES_ROOT , jl_datatype_t * tt JL_MAYBE_UNROOTED , size_t world )
1448
1448
{
1449
- // caller must hold the mt->writelock
1449
+ jl_genericmemory_t * leafcache = jl_atomic_load_relaxed (& mt -> leafcache );
1450
+ jl_typemap_entry_t * entry = lookup_leafcache (leafcache , (jl_value_t * )tt , world );
1451
+ if (entry )
1452
+ return entry -> func .linfo ;
1453
+ JL_TIMING (METHOD_LOOKUP_SLOW , METHOD_LOOKUP_SLOW );
1454
+ jl_method_match_t * matc = NULL ;
1455
+ JL_GC_PUSH2 (& tt , & matc );
1456
+ JL_LOCK (& mt -> writelock );
1450
1457
assert (tt -> isdispatchtuple || tt -> hasfreetypevars );
1458
+ jl_method_instance_t * mi = NULL ;
1451
1459
if (tt -> isdispatchtuple ) {
1452
1460
jl_genericmemory_t * leafcache = jl_atomic_load_relaxed (& mt -> leafcache );
1453
1461
jl_typemap_entry_t * entry = lookup_leafcache (leafcache , (jl_value_t * )tt , world );
1454
1462
if (entry )
1455
- return entry -> func .linfo ;
1463
+ mi = entry -> func .linfo ;
1456
1464
}
1457
1465
1458
- struct jl_typemap_assoc search = {(jl_value_t * )tt , world , NULL , 0 , ~(size_t )0 };
1459
- jl_typemap_entry_t * entry = jl_typemap_assoc_by_type (jl_atomic_load_relaxed (& mt -> cache ), & search , jl_cachearg_offset (mt ), /*subtype*/ 1 );
1460
- if (entry )
1461
- return entry -> func .linfo ;
1466
+ if (!mi ) {
1467
+ struct jl_typemap_assoc search = {(jl_value_t * )tt , world , NULL , 0 , ~(size_t )0 };
1468
+ jl_typemap_entry_t * entry = jl_typemap_assoc_by_type (jl_atomic_load_relaxed (& mt -> cache ), & search , jl_cachearg_offset (mt ), /*subtype*/ 1 );
1469
+ if (entry )
1470
+ mi = entry -> func .linfo ;
1471
+ }
1462
1472
1463
- size_t min_valid = 0 ;
1464
- size_t max_valid = ~(size_t )0 ;
1465
- jl_method_match_t * matc = _gf_invoke_lookup ((jl_value_t * )tt , jl_nothing , world , & min_valid , & max_valid );
1466
- jl_method_instance_t * nf = NULL ;
1467
- if (matc ) {
1468
- JL_GC_PUSH1 (& matc );
1469
- jl_method_t * m = matc -> method ;
1470
- jl_svec_t * env = matc -> sparams ;
1471
- nf = cache_method (mt , & mt -> cache , (jl_value_t * )mt , tt , m , world , min_valid , max_valid , env );
1472
- JL_GC_POP ();
1473
+ if (!mi ) {
1474
+ size_t min_valid = 0 ;
1475
+ size_t max_valid = ~(size_t )0 ;
1476
+ matc = _gf_invoke_lookup ((jl_value_t * )tt , jl_nothing , world , & min_valid , & max_valid );
1477
+ if (matc ) {
1478
+ jl_method_t * m = matc -> method ;
1479
+ jl_svec_t * env = matc -> sparams ;
1480
+ mi = cache_method (mt , & mt -> cache , (jl_value_t * )mt , tt , m , world , min_valid , max_valid , env );
1481
+ }
1473
1482
}
1474
- return nf ;
1483
+ JL_UNLOCK (& mt -> writelock );
1484
+ JL_GC_POP ();
1485
+ return mi ;
1475
1486
}
1476
1487
1477
1488
@@ -2233,7 +2244,19 @@ static jl_tupletype_t *lookup_arg_type_tuple(jl_value_t *arg1 JL_PROPAGATES_ROOT
2233
2244
return jl_lookup_arg_tuple_type (arg1 , args , nargs , 1 );
2234
2245
}
2235
2246
2236
- jl_method_instance_t * jl_method_lookup (jl_value_t * * args , size_t nargs , size_t world )
2247
+ JL_DLLEXPORT jl_method_instance_t * jl_method_lookup_by_tt (jl_tupletype_t * tt , size_t world , jl_value_t * _mt )
2248
+ {
2249
+ jl_methtable_t * mt = NULL ;
2250
+ if (_mt == jl_nothing )
2251
+ mt = jl_gf_ft_mtable (jl_tparam0 (tt ));
2252
+ else {
2253
+ assert (jl_isa (_mt , (jl_value_t * )jl_methtable_type ));
2254
+ mt = (jl_methtable_t * ) _mt ;
2255
+ }
2256
+ return jl_mt_assoc_by_type (mt , tt , world );
2257
+ }
2258
+
2259
+ JL_DLLEXPORT jl_method_instance_t * jl_method_lookup (jl_value_t * * args , size_t nargs , size_t world )
2237
2260
{
2238
2261
assert (nargs > 0 && "expected caller to handle this case" );
2239
2262
jl_methtable_t * mt = jl_gf_mtable (args [0 ]);
@@ -2242,16 +2265,7 @@ jl_method_instance_t *jl_method_lookup(jl_value_t **args, size_t nargs, size_t w
2242
2265
if (entry )
2243
2266
return entry -> func .linfo ;
2244
2267
jl_tupletype_t * tt = arg_type_tuple (args [0 ], & args [1 ], nargs );
2245
- jl_genericmemory_t * leafcache = jl_atomic_load_relaxed (& mt -> leafcache );
2246
- entry = lookup_leafcache (leafcache , (jl_value_t * )tt , world );
2247
- if (entry )
2248
- return entry -> func .linfo ;
2249
- JL_GC_PUSH1 (& tt );
2250
- JL_LOCK (& mt -> writelock );
2251
- jl_method_instance_t * sf = jl_mt_assoc_by_type (mt , tt , world );
2252
- JL_UNLOCK (& mt -> writelock );
2253
- JL_GC_POP ();
2254
- return sf ;
2268
+ return jl_mt_assoc_by_type (mt , tt , world );
2255
2269
}
2256
2270
2257
2271
// return a Vector{Any} of svecs, each describing a method match:
@@ -3051,14 +3065,9 @@ STATIC_INLINE jl_method_instance_t *jl_lookup_generic_(jl_value_t *F, jl_value_t
3051
3065
mfunc = entry -> func .linfo ;
3052
3066
}
3053
3067
else {
3054
- JL_GC_PUSH1 (& tt );
3055
3068
assert (tt );
3056
- JL_LOCK (& mt -> writelock );
3057
3069
// cache miss case
3058
- JL_TIMING (METHOD_LOOKUP_SLOW , METHOD_LOOKUP_SLOW );
3059
3070
mfunc = jl_mt_assoc_by_type (mt , tt , world );
3060
- JL_UNLOCK (& mt -> writelock );
3061
- JL_GC_POP ();
3062
3071
if (jl_options .malloc_log )
3063
3072
jl_gc_sync_total_bytes (last_alloc ); // discard allocation count from compilation
3064
3073
if (mfunc == NULL ) {
0 commit comments