@@ -7571,10 +7571,16 @@ public enum CodeAddressIndex
7571
7571
/// </summary>
7572
7572
public sealed class TraceCodeAddresses : IFastSerializable , IEnumerable < TraceCodeAddress >
7573
7573
{
7574
+ /// <summary>
7575
+ /// Chunk size for <see cref="codeAddressObjects"/>
7576
+ /// </summary>
7577
+ private const int ChunkSize = 4096 ;
7578
+
7574
7579
/// <summary>
7575
7580
/// Returns the count of code address indexes (all code address indexes are strictly less than this).
7576
7581
/// </summary>
7577
7582
public int Count { get { return codeAddresses . Count ; } }
7583
+
7578
7584
/// <summary>
7579
7585
/// Given a code address index, return the name associated with it (the method name). It will
7580
7586
/// have the form MODULE!METHODNAME. If the module name is unknown a ? is used, and if the
@@ -7587,7 +7593,8 @@ public string Name(CodeAddressIndex codeAddressIndex)
7587
7593
names = new string [ Count ] ;
7588
7594
}
7589
7595
7590
- string name = names [ ( int ) codeAddressIndex ] ;
7596
+ string name = this . names [ ( int ) codeAddressIndex ] ;
7597
+
7591
7598
if ( name == null )
7592
7599
{
7593
7600
string moduleName = "?" ;
@@ -7608,8 +7615,9 @@ public string Name(CodeAddressIndex codeAddressIndex)
7608
7615
methodName = "0x" + ( ( ulong ) Address ( codeAddressIndex ) ) . ToString ( "x" ) ;
7609
7616
}
7610
7617
7611
- name = moduleName + "!" + methodName ;
7618
+ this . names [ ( int ) codeAddressIndex ] = name = moduleName + "!" + methodName ;
7612
7619
}
7620
+
7613
7621
return name ;
7614
7622
}
7615
7623
/// <summary>
@@ -7654,29 +7662,46 @@ public int ILOffset(CodeAddressIndex codeAddressIndex)
7654
7662
7655
7663
return ilMap . GetILOffsetForNativeAddress ( Address ( codeAddressIndex ) ) ;
7656
7664
}
7665
+
7657
7666
/// <summary>
7658
7667
/// Given a code address index, returns a TraceCodeAddress for it.
7659
7668
/// </summary>
7660
7669
public TraceCodeAddress this [ CodeAddressIndex codeAddressIndex ]
7661
7670
{
7662
7671
get
7663
7672
{
7664
- if ( codeAddressObjects == null || ( int ) codeAddressIndex >= codeAddressObjects . Length )
7673
+ if ( codeAddressIndex == CodeAddressIndex . Invalid )
7665
7674
{
7666
- codeAddressObjects = new TraceCodeAddress [ ( int ) codeAddressIndex + 16 ] ;
7675
+ return null ;
7667
7676
}
7668
7677
7669
- if ( codeAddressIndex == CodeAddressIndex . Invalid )
7678
+ int chunk = ( int ) codeAddressIndex / ChunkSize ;
7679
+ int offset = ( int ) codeAddressIndex % ChunkSize ;
7680
+
7681
+ if ( this . codeAddressObjects == null )
7670
7682
{
7671
- return null ;
7683
+ this . codeAddressObjects = new TraceCodeAddress [ chunk + 1 ] [ ] ;
7684
+ }
7685
+ else if ( chunk >= this . codeAddressObjects . Length )
7686
+ {
7687
+ Array . Resize ( ref this . codeAddressObjects , Math . Max ( this . codeAddressObjects . Length * 2 , chunk + 1 ) ) ;
7688
+ }
7689
+
7690
+ TraceCodeAddress [ ] data = this . codeAddressObjects [ chunk ] ;
7691
+
7692
+ if ( data == null )
7693
+ {
7694
+ data = this . codeAddressObjects [ chunk ] = new TraceCodeAddress [ ChunkSize ] ;
7672
7695
}
7673
7696
7674
- TraceCodeAddress ret = codeAddressObjects [ ( int ) codeAddressIndex ] ;
7697
+ TraceCodeAddress ret = data [ offset ] ;
7698
+
7675
7699
if ( ret == null )
7676
7700
{
7677
7701
ret = new TraceCodeAddress ( this , codeAddressIndex ) ;
7678
- codeAddressObjects [ ( int ) codeAddressIndex ] = ret ;
7702
+ data [ offset ] = ret ;
7679
7703
}
7704
+
7680
7705
return ret ;
7681
7706
}
7682
7707
}
@@ -8999,7 +9024,7 @@ void IFastSerializable.FromStream(Deserializer deserializer)
8999
9024
private GrowableArray < ILToNativeMap > ILToNativeMaps ; // only Jitted code has these, indexed by ILMapIndex
9000
9025
private Dictionary < long , ILMapIndex > methodIDToILToNativeMap ;
9001
9026
9002
- private TraceCodeAddress [ ] codeAddressObjects ; // If we were asked for TraceCodeAddresses (instead of indexes) we cache them
9027
+ private TraceCodeAddress [ ] [ ] codeAddressObjects ; // If we were asked for TraceCodeAddresses (instead of indexes) we cache them, in sparse array
9003
9028
private string [ ] names ; // A cache (one per code address) of the string name of the address
9004
9029
private int managedMethodRecordCount ; // Remembers how many code addresses are managed methods (currently not serialized)
9005
9030
internal int totalCodeAddresses ; // Count of the number of times a code address appears in the log.
0 commit comments