@@ -880,6 +880,10 @@ static jl_method_instance_t *cache_method(
880
880
int allow_exec )
881
881
{
882
882
// caller must hold the mt->writelock
883
+ jl_typemap_entry_t * entry = jl_typemap_assoc_by_type (* cache , (jl_value_t * )tt , NULL , /*subtype*/ 1 , jl_cachearg_offset (mt ), world , /*max_world_mask*/ 0 );
884
+ if (entry && entry -> func .value )
885
+ return (jl_method_instance_t * )entry -> func .value ;
886
+
883
887
jl_value_t * decl = (jl_value_t * )definition -> sig ;
884
888
jl_value_t * temp = NULL ;
885
889
jl_value_t * temp2 = NULL ;
@@ -1082,12 +1086,17 @@ static jl_method_instance_t *jl_mt_assoc_by_type(jl_methtable_t *mt, jl_datatype
1082
1086
{
1083
1087
// caller must hold the mt->writelock
1084
1088
jl_typemap_entry_t * entry = NULL ;
1089
+ entry = jl_typemap_assoc_by_type (mt -> cache , (jl_value_t * )tt , NULL , /*subtype*/ 1 , jl_cachearg_offset (mt ), world , /*max_world_mask*/ 0 );
1090
+ if (entry && entry -> func .value ) {
1091
+ assert (entry -> func .linfo -> min_world <= entry -> min_world && entry -> func .linfo -> max_world >= entry -> max_world &&
1092
+ "typemap consistency error: MethodInstance doesn't apply to full range of its entry" );
1093
+ return entry -> func .linfo ;
1094
+ }
1095
+
1096
+ jl_method_instance_t * nf = NULL ;
1085
1097
jl_svec_t * env = jl_emptysvec ;
1086
- jl_method_t * func = NULL ;
1087
1098
jl_tupletype_t * sig = NULL ;
1088
- jl_method_instance_t * nf = NULL ;
1089
- JL_GC_PUSH4 (& env , & entry , & func , & sig );
1090
-
1099
+ JL_GC_PUSH2 (& env , & sig );
1091
1100
entry = jl_typemap_assoc_by_type (mt -> defs , (jl_value_t * )tt , & env , /*subtype*/ 1 , /*offs*/ 0 , world , /*max_world_mask*/ 0 );
1092
1101
if (entry != NULL ) {
1093
1102
jl_method_t * m = entry -> func .method ;
@@ -1101,12 +1110,10 @@ static jl_method_instance_t *jl_mt_assoc_by_type(jl_methtable_t *mt, jl_datatype
1101
1110
#endif
1102
1111
int sharp_match ;
1103
1112
sig = join_tsig (tt , m -> sig , & sharp_match );
1104
- if (!mt_cache ) {
1113
+ if (!mt_cache )
1105
1114
nf = jl_specializations_get_linfo (m , (jl_value_t * )sig , env , world );
1106
- }
1107
- else {
1115
+ else
1108
1116
nf = cache_method (mt , & mt -> cache , (jl_value_t * )mt , sig , tt , m , world , env , allow_exec );
1109
- }
1110
1117
}
1111
1118
}
1112
1119
JL_GC_POP ();
@@ -1652,8 +1659,9 @@ jl_tupletype_t *arg_type_tuple(jl_value_t **args, size_t nargs)
1652
1659
return tt ;
1653
1660
}
1654
1661
1655
- jl_method_instance_t * jl_method_lookup_by_type (jl_methtable_t * mt , jl_tupletype_t * types ,
1656
- int cache , int allow_exec , size_t world )
1662
+ static jl_method_instance_t * jl_method_lookup_by_type (
1663
+ jl_methtable_t * mt , jl_tupletype_t * types ,
1664
+ int cache , int allow_exec , size_t world )
1657
1665
{
1658
1666
jl_typemap_entry_t * entry = jl_typemap_assoc_by_type (mt -> cache , (jl_value_t * )types , NULL , /*subtype*/ 1 , jl_cachearg_offset (mt ), world , /*max_world_mask*/ 0 );
1659
1667
if (entry ) {
@@ -1663,25 +1671,10 @@ jl_method_instance_t *jl_method_lookup_by_type(jl_methtable_t *mt, jl_tupletype_
1663
1671
return linfo ;
1664
1672
}
1665
1673
JL_LOCK (& mt -> writelock );
1666
- entry = jl_typemap_assoc_by_type (mt -> cache , (jl_value_t * )types , NULL , /*subtype*/ 1 , jl_cachearg_offset (mt ), world , /*max_world_mask*/ 0 );
1667
- if (entry ) {
1668
- jl_method_instance_t * linfo = (jl_method_instance_t * )entry -> func .value ;
1669
- assert (linfo -> min_world <= entry -> min_world && linfo -> max_world >= entry -> max_world &&
1670
- "typemap consistency error: MethodInstance doesn't apply to full range of its entry" );
1671
- JL_UNLOCK (& mt -> writelock );
1672
- return linfo ;
1673
- }
1674
1674
if (jl_is_datatype ((jl_value_t * )types ) && types -> isdispatchtuple )
1675
- cache = 1 ;
1675
+ cache = 1 ; // TODO: this might be detrimental to performance, should be tested
1676
1676
jl_method_instance_t * sf = jl_mt_assoc_by_type (mt , types , cache , allow_exec , world );
1677
- if (cache ) {
1678
- JL_UNLOCK (& mt -> writelock );
1679
- }
1680
- else {
1681
- JL_GC_PUSH1 (& sf );
1682
- JL_UNLOCK (& mt -> writelock );
1683
- JL_GC_POP ();
1684
- }
1677
+ JL_UNLOCK (& mt -> writelock );
1685
1678
return sf ;
1686
1679
}
1687
1680
@@ -1696,24 +1689,11 @@ jl_method_instance_t *jl_method_lookup(jl_methtable_t *mt, jl_value_t **args, si
1696
1689
if (entry )
1697
1690
return entry -> func .linfo ;
1698
1691
JL_LOCK (& mt -> writelock );
1699
- entry = jl_typemap_assoc_exact (mt -> cache , args , nargs , jl_cachearg_offset (mt ), world );
1700
- if (entry ) {
1701
- JL_UNLOCK (& mt -> writelock );
1702
- return entry -> func .linfo ;
1703
- }
1704
1692
jl_tupletype_t * tt = arg_type_tuple (args , nargs );
1705
- jl_method_instance_t * sf = NULL ;
1706
- JL_GC_PUSH2 (& tt , & sf );
1707
- sf = jl_mt_assoc_by_type (mt , tt , cache , 1 , world );
1708
- if (cache ) {
1709
- JL_UNLOCK (& mt -> writelock );
1710
- }
1711
- else {
1712
- JL_GC_PUSH1 (& sf );
1713
- JL_UNLOCK (& mt -> writelock );
1714
- JL_GC_POP ();
1715
- }
1693
+ JL_GC_PUSH1 (& tt );
1694
+ jl_method_instance_t * sf = jl_mt_assoc_by_type (mt , tt , cache , 1 , world );
1716
1695
JL_GC_POP ();
1696
+ JL_UNLOCK (& mt -> writelock );
1717
1697
return sf ;
1718
1698
}
1719
1699
@@ -1906,6 +1886,7 @@ jl_method_instance_t *jl_get_specialization1(jl_tupletype_t *types, size_t world
1906
1886
JL_LOCK (& mt -> writelock );
1907
1887
nf = cache_method (mt , & mt -> cache , (jl_value_t * )mt , sig , ti , m , world , env , /*allow_exec*/ 1 );
1908
1888
JL_UNLOCK (& mt -> writelock );
1889
+ assert (nf -> min_world <= world && nf -> max_world >= world );
1909
1890
}
1910
1891
// // get the specialization without caching it
1911
1892
// int need_guard_entries = 0;
@@ -1917,7 +1898,6 @@ jl_method_instance_t *jl_get_specialization1(jl_tupletype_t *types, size_t world
1917
1898
// sig = jl_apply_tuple_type(newparams);
1918
1899
// nf = jl_specializations_get_linfo(m, (jl_value_t*)sig, env, world);
1919
1900
}
1920
- assert (nf == NULL || (nf -> min_world <= world && nf -> max_world >= world ));
1921
1901
JL_GC_POP ();
1922
1902
return nf ;
1923
1903
}
@@ -2123,18 +2103,12 @@ STATIC_INLINE jl_method_instance_t *jl_lookup_generic_(jl_value_t **args, uint32
2123
2103
}
2124
2104
else {
2125
2105
JL_LOCK (& mt -> writelock );
2126
- entry = jl_typemap_assoc_exact (mt -> cache , args , nargs , jl_cachearg_offset (mt ), world );
2127
- if (entry ) {
2128
- mfunc = entry -> func .linfo ;
2129
- }
2130
- else {
2131
- // cache miss case
2132
- JL_TIMING (METHOD_LOOKUP_SLOW );
2133
- jl_tupletype_t * tt = arg_type_tuple (args , nargs );
2134
- JL_GC_PUSH1 (& tt );
2135
- mfunc = jl_mt_assoc_by_type (mt , tt , /*cache*/ 1 , /*allow_exec*/ 1 , world );
2136
- JL_GC_POP ();
2137
- }
2106
+ // cache miss case
2107
+ JL_TIMING (METHOD_LOOKUP_SLOW );
2108
+ jl_tupletype_t * tt = arg_type_tuple (args , nargs );
2109
+ JL_GC_PUSH1 (& tt );
2110
+ mfunc = jl_mt_assoc_by_type (mt , tt , /*cache*/ 1 , /*allow_exec*/ 1 , world );
2111
+ JL_GC_POP ();
2138
2112
JL_UNLOCK (& mt -> writelock );
2139
2113
if (mfunc == NULL ) {
2140
2114
#ifdef JL_TRACE
@@ -2223,25 +2197,18 @@ jl_value_t *jl_gf_invoke(jl_value_t *types0, jl_value_t **args, size_t nargs)
2223
2197
}
2224
2198
else {
2225
2199
JL_LOCK (& method -> writelock );
2226
- if ( method -> invokes . unknown != NULL )
2227
- tm = jl_typemap_assoc_exact ( method -> invokes , args , nargs , jl_cachearg_offset ( mt ), world );
2228
- if ( tm ) {
2229
- mfunc = tm -> func . linfo ;
2200
+ tt = arg_type_tuple ( args , nargs );
2201
+ if ( jl_is_unionall ( method -> sig )) {
2202
+ int sub = jl_subtype_matching (( jl_value_t * ) tt , ( jl_value_t * ) method -> sig , & tpenv );
2203
+ assert ( sub ); ( void ) sub ;
2230
2204
}
2231
- else {
2232
- tt = arg_type_tuple (args , nargs );
2233
- if (jl_is_unionall (method -> sig )) {
2234
- int sub = jl_subtype_matching ((jl_value_t * )tt , (jl_value_t * )method -> sig , & tpenv );
2235
- assert (sub ); (void )sub ;
2236
- }
2237
2205
2238
- if (method -> invokes .unknown == NULL )
2239
- method -> invokes .unknown = jl_nothing ;
2206
+ if (method -> invokes .unknown == NULL )
2207
+ method -> invokes .unknown = jl_nothing ;
2240
2208
2241
- int sharp_match ;
2242
- sig = join_tsig (tt , method -> sig , & sharp_match );
2243
- mfunc = cache_method (mt , & method -> invokes , entry -> func .value , sig , tt , method , world , tpenv , 1 );
2244
- }
2209
+ int sharp_match ;
2210
+ sig = join_tsig (tt , method -> sig , & sharp_match );
2211
+ mfunc = cache_method (mt , & method -> invokes , entry -> func .value , sig , tt , method , world , tpenv , 1 );
2245
2212
JL_UNLOCK (& method -> writelock );
2246
2213
}
2247
2214
JL_GC_POP ();
0 commit comments