@@ -1485,17 +1485,33 @@ static void update_max_args(jl_methtable_t *mt, jl_value_t *type)
1485
1485
mt -> max_args = na ;
1486
1486
}
1487
1487
1488
- JL_DLLEXPORT int jl_debug_method_invalidation = 0 ;
1488
+ jl_array_t * _jl_debug_method_invalidation JL_GLOBALLY_ROOTED = NULL ;
1489
+ JL_DLLEXPORT jl_value_t * jl_debug_method_invalidation (int state )
1490
+ {
1491
+ /* After calling with `state = 1`, caller is responsible for
1492
+ holding a reference to the returned array until this is called
1493
+ again with `state = 0`. */
1494
+ if (state ) {
1495
+ if (_jl_debug_method_invalidation )
1496
+ return (jl_value_t * ) _jl_debug_method_invalidation ;
1497
+ _jl_debug_method_invalidation = jl_alloc_array_1d (jl_array_any_type , 0 );
1498
+ return (jl_value_t * ) _jl_debug_method_invalidation ;
1499
+ }
1500
+ _jl_debug_method_invalidation = NULL ;
1501
+ return jl_nothing ;
1502
+ }
1489
1503
1490
1504
// recursively invalidate cached methods that had an edge to a replaced method
1491
1505
static void invalidate_method_instance (jl_method_instance_t * replaced , size_t max_world , int depth )
1492
1506
{
1493
- if (jl_debug_method_invalidation ) {
1494
- int d0 = depth ;
1495
- while (d0 -- > 0 )
1496
- jl_uv_puts (JL_STDOUT , " " , 1 );
1497
- jl_static_show (JL_STDOUT , (jl_value_t * )replaced );
1498
- jl_uv_puts (JL_STDOUT , "\n" , 1 );
1507
+ if (_jl_debug_method_invalidation ) {
1508
+ jl_value_t * boxeddepth = NULL ;
1509
+ JL_GC_PUSH1 (& boxeddepth );
1510
+ jl_array_ptr_1d_push (_jl_debug_method_invalidation , (jl_value_t * )replaced );
1511
+ boxeddepth = jl_box_int32 (depth );
1512
+ jl_array_ptr_1d_push (_jl_debug_method_invalidation , boxeddepth );
1513
+ jl_gc_wb (_jl_debug_method_invalidation , boxeddepth );
1514
+ JL_GC_POP ();
1499
1515
}
1500
1516
if (!jl_is_method (replaced -> def .method ))
1501
1517
return ; // shouldn't happen, but better to be safe
@@ -1622,10 +1638,14 @@ static int invalidate_mt_cache(jl_typemap_entry_t *oldentry, void *closure0)
1622
1638
}
1623
1639
}
1624
1640
if (intersects ) {
1625
- if (jl_debug_method_invalidation ) {
1626
- jl_uv_puts (JL_STDOUT , "-- " , 3 );
1627
- jl_static_show (JL_STDOUT , (jl_value_t * )mi );
1628
- jl_uv_puts (JL_STDOUT , "\n" , 1 );
1641
+ if (_jl_debug_method_invalidation ) {
1642
+ jl_value_t * loctag = NULL ;
1643
+ JL_GC_PUSH1 (& loctag );
1644
+ jl_array_ptr_1d_push (_jl_debug_method_invalidation , (jl_value_t * )mi );
1645
+ loctag = jl_cstr_to_string ("invalidate_mt_cache" );
1646
+ jl_gc_wb (_jl_debug_method_invalidation , loctag );
1647
+ jl_array_ptr_1d_push (_jl_debug_method_invalidation , loctag );
1648
+ JL_GC_POP ();
1629
1649
}
1630
1650
oldentry -> max_world = env -> max_world ;
1631
1651
}
@@ -1673,12 +1693,33 @@ JL_DLLEXPORT void jl_method_table_disable(jl_methtable_t *mt, jl_method_t *metho
1673
1693
jl_typemap_visitor (mt -> cache , invalidate_mt_cache , (void * )& mt_cache_env );
1674
1694
// Invalidate the backedges
1675
1695
jl_svec_t * specializations = methodentry -> func .method -> specializations ;
1696
+ int invalidated = 0 ;
1697
+ jl_value_t * loctag = NULL ;
1698
+ JL_GC_PUSH1 (& loctag );
1676
1699
size_t i , l = jl_svec_len (specializations );
1677
1700
for (i = 0 ; i < l ; i ++ ) {
1678
1701
jl_method_instance_t * mi = (jl_method_instance_t * )jl_svecref (specializations , i );
1679
- if (mi )
1680
- invalidate_backedges (mi , methodentry -> max_world );
1702
+ if (mi ) {
1703
+ invalidated = 1 ;
1704
+ if (invalidate_backedges (mi , methodentry -> max_world ))
1705
+ if (_jl_debug_method_invalidation ) {
1706
+ if (!loctag ) {
1707
+ loctag = jl_cstr_to_string ("jl_method_table_disable" );
1708
+ jl_gc_wb (_jl_debug_method_invalidation , loctag );
1709
+ }
1710
+ jl_array_ptr_1d_push (_jl_debug_method_invalidation , loctag );
1711
+ }
1712
+ }
1713
+ }
1714
+ if (invalidated && _jl_debug_method_invalidation ) {
1715
+ jl_array_ptr_1d_push (_jl_debug_method_invalidation , (jl_value_t * )method );
1716
+ if (!loctag ) {
1717
+ loctag = jl_cstr_to_string ("jl_method_table_disable" );
1718
+ jl_gc_wb (_jl_debug_method_invalidation , loctag );
1719
+ }
1720
+ jl_array_ptr_1d_push (_jl_debug_method_invalidation , loctag );
1681
1721
}
1722
+ JL_GC_POP ();
1682
1723
JL_UNLOCK (& mt -> writelock );
1683
1724
}
1684
1725
@@ -1693,7 +1734,8 @@ JL_DLLEXPORT void jl_method_table_insert(jl_methtable_t *mt, jl_method_t *method
1693
1734
method -> primary_world = ++ jl_world_counter ;
1694
1735
size_t max_world = method -> primary_world - 1 ;
1695
1736
int invalidated = 0 ;
1696
- JL_GC_PUSH1 (& oldvalue );
1737
+ jl_value_t * loctag = NULL ; // debug info for invalidation
1738
+ JL_GC_PUSH2 (& oldvalue , & loctag );
1697
1739
JL_LOCK (& mt -> writelock );
1698
1740
// first delete the existing entry (we'll disable it later)
1699
1741
struct jl_typemap_assoc search = {(jl_value_t * )type , method -> primary_world , NULL , 0 , ~(size_t )0 };
@@ -1722,6 +1764,8 @@ JL_DLLEXPORT void jl_method_table_insert(jl_methtable_t *mt, jl_method_t *method
1722
1764
jl_method_instance_t * backedge = (jl_method_instance_t * )backedges [i ];
1723
1765
invalidate_method_instance (backedge , max_world , 0 );
1724
1766
invalidated = 1 ;
1767
+ if (_jl_debug_method_invalidation )
1768
+ jl_array_ptr_1d_push (_jl_debug_method_invalidation , (jl_value_t * )backedgetyp );
1725
1769
}
1726
1770
else {
1727
1771
backedges [ins ++ ] = backedges [i - 1 ];
@@ -1767,17 +1811,27 @@ JL_DLLEXPORT void jl_method_table_insert(jl_methtable_t *mt, jl_method_t *method
1767
1811
for (i = 0 ; i < l ; i ++ ) {
1768
1812
jl_method_instance_t * mi = (jl_method_instance_t * )jl_svecref (specializations , i );
1769
1813
if (mi != NULL && !jl_has_empty_intersection (type , (jl_value_t * )mi -> specTypes ))
1770
- if (invalidate_backedges (mi , max_world ))
1814
+ if (invalidate_backedges (mi , max_world )) {
1771
1815
invalidated = 1 ;
1816
+ if (_jl_debug_method_invalidation ) {
1817
+ jl_array_ptr_1d_push (_jl_debug_method_invalidation , (jl_value_t * )mi );
1818
+ if (!loctag ) {
1819
+ loctag = jl_cstr_to_string ("jl_method_table_insert" );
1820
+ jl_gc_wb (_jl_debug_method_invalidation , loctag );
1821
+ }
1822
+ jl_array_ptr_1d_push (_jl_debug_method_invalidation , loctag );
1823
+ }
1824
+ }
1772
1825
}
1773
1826
}
1774
1827
}
1775
- if (invalidated && jl_debug_method_invalidation ) {
1776
- jl_uv_puts (JL_STDOUT , ">> " , 3 );
1777
- jl_static_show (JL_STDOUT , (jl_value_t * )method );
1778
- jl_uv_puts (JL_STDOUT , " " , 1 );
1779
- jl_static_show (JL_STDOUT , (jl_value_t * )type );
1780
- jl_uv_puts (JL_STDOUT , "\n" , 1 );
1828
+ if (invalidated && _jl_debug_method_invalidation ) {
1829
+ jl_array_ptr_1d_push (_jl_debug_method_invalidation , (jl_value_t * )method );
1830
+ if (!loctag ) {
1831
+ loctag = jl_cstr_to_string ("jl_method_table_insert" );
1832
+ jl_gc_wb (_jl_debug_method_invalidation , loctag );
1833
+ }
1834
+ jl_array_ptr_1d_push (_jl_debug_method_invalidation , loctag );
1781
1835
}
1782
1836
update_max_args (mt , type );
1783
1837
JL_UNLOCK (& mt -> writelock );
0 commit comments