Skip to content

Commit 54505e8

Browse files
authored
Remove unnecessary use of NoInlining and add traceability for valid uses, #931 (#1134)
* Use nameof for traceability to StackTraceHelper * Remove unnecessary NoInlining and add traceability, #931
1 parent 690b175 commit 54505e8

File tree

68 files changed

+111
-224
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+111
-224
lines changed

src/Lucene.Net.Misc/Util/Fst/ListOfOutputs.cs

+5-8
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
using Lucene.Net.Store;
33
using System.Collections;
44
using System.Collections.Generic;
5-
using System.Diagnostics;
6-
using System.Runtime.CompilerServices;
75
using System.Text;
86
using JCG = J2N.Collections.Generic;
97

@@ -34,11 +32,11 @@ namespace Lucene.Net.Util.Fst
3432
/// output by calling <see cref="Builder{T}.Add(Int32sRef,T)"/> multiple
3533
/// times. The builder will then combine the outputs using
3634
/// the <see cref="Outputs{T}.Merge(T,T)"/> method.
37-
///
35+
///
3836
/// <para>The resulting FST may not be minimal when an input has
3937
/// more than one output, as this requires pushing all
4038
/// multi-output values to a final state.
41-
///
39+
///
4240
/// </para>
4341
/// <para>NOTE: the only way to create multiple outputs is to
4442
/// add the same input to the FST multiple times in a row. This is
@@ -48,11 +46,11 @@ namespace Lucene.Net.Util.Fst
4846
/// <see cref="UpToTwoPositiveInt64Outputs"/> instead since it stores
4947
/// the outputs more compactly (by stealing a bit from each
5048
/// long value).
51-
///
49+
///
5250
/// </para>
5351
/// <para>NOTE: this cannot wrap itself (ie you cannot make an
5452
/// FST with List&lt;List&lt;Object&gt;&gt; outputs using this).
55-
///
53+
///
5654
/// @lucene.experimental
5755
/// </para>
5856
/// </summary>
@@ -176,7 +174,6 @@ public override string OutputToString(object output)
176174
}
177175
}
178176

179-
[MethodImpl(MethodImplOptions.NoInlining)]
180177
public override object Merge(object first, object second)
181178
{
182179
IList<T> outputList = new JCG.List<T>();
@@ -224,4 +221,4 @@ public IList<T> AsList(object output)
224221
}
225222
}
226223
}
227-
}
224+
}

src/Lucene.Net.Misc/Util/Fst/UpToTwoPositiveIntOutputs.cs

-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ public override string OutputToString(object output)
295295
return output.ToString();
296296
}
297297

298-
[MethodImpl(MethodImplOptions.NoInlining)]
299298
public override object Merge(object first, object second)
300299
{
301300
if (Debugging.AssertsEnabled)

src/Lucene.Net.TestFramework/Codecs/Lucene3x/PreFlexRWPostingsFormat.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected override bool SortTermsByUnicode
6767

6868
// LUCENENET specific: for these to work in release mode, we have added [MethodImpl(MethodImplOptions.NoInlining)]
6969
// to each possible target of the StackTraceHelper. If these change, so must the attribute on the target methods.
70-
if (StackTraceHelper.DoesStackTraceContainMethod("Merge"))
70+
if (StackTraceHelper.DoesStackTraceContainMethod(nameof(SegmentMerger.Merge)))
7171
{
7272
unicodeSortOrder = false;
7373
if (LuceneTestCase.Verbose)

src/Lucene.Net.TestFramework/Codecs/Lucene3x/PreFlexRWTermVectorsFormat.cs

+6-5
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ protected internal override bool SortTermsByUnicode()
5454
// to each possible target of the StackTraceHelper. If these change, so must the attribute on the target methods.
5555
if (StackTraceHelper.DoesStackTraceContainMethod("Merge"))
5656
{
57-
unicodeSortOrder = false;
58-
if (LuceneTestCase.Verbose)
59-
{
60-
Console.WriteLine("NOTE: PreFlexRW codec: forcing legacy UTF16 vector term sort order");
61-
}
57+
// LUCENENET TODO: This does not seem to be hit, unused?
58+
unicodeSortOrder = false;
59+
if (LuceneTestCase.Verbose)
60+
{
61+
Console.WriteLine("NOTE: PreFlexRW codec: forcing legacy UTF16 vector term sort order");
62+
}
6263
}
6364

6465
return unicodeSortOrder;

src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ private bool MustSync()
237237
return @delegate is NRTCachingDirectory;
238238
}
239239

240-
[MethodImpl(MethodImplOptions.NoInlining)]
240+
[MethodImpl(MethodImplOptions.NoInlining)] // Stack trace needed intact in TestIndexWriterExceptions,
241241
public override void Sync(ICollection<string> names)
242242
{
243243
UninterruptableMonitor.Enter(this);
@@ -519,7 +519,7 @@ internal virtual void MaybeThrowIOExceptionOnOpen(string name)
519519
}
520520
}
521521

522-
[MethodImpl(MethodImplOptions.NoInlining)]
522+
[MethodImpl(MethodImplOptions.NoInlining)] // Stack trace needed intact in TestIndexWriterExceptions
523523
public override void DeleteFile(string name)
524524
{
525525
UninterruptableMonitor.Enter(this);
@@ -576,7 +576,7 @@ private void MaybeYield()
576576
}
577577
}
578578

579-
[MethodImpl(MethodImplOptions.NoInlining)]
579+
[MethodImpl(MethodImplOptions.NoInlining)] // Stack trace needed intact in TestIndexWriterExceptions
580580
private void DeleteFile(string name, bool forced)
581581
{
582582
UninterruptableMonitor.Enter(this);

src/Lucene.Net.Tests/Index/TestConcurrentMergeScheduler.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ public override void Eval(MockDirectoryWrapper dir)
6666
{
6767
// LUCENENET specific: for these to work in release mode, we have added [MethodImpl(MethodImplOptions.NoInlining)]
6868
// to each possible target of the StackTraceHelper. If these change, so must the attribute on the target methods.
69-
bool isDoFlush = StackTraceHelper.DoesStackTraceContainMethod("Flush");
70-
bool isClose = StackTraceHelper.DoesStackTraceContainMethod("Close") ||
71-
StackTraceHelper.DoesStackTraceContainMethod("Dispose");
69+
bool isDoFlush = StackTraceHelper.DoesStackTraceContainMethod(nameof(DocumentsWriterPerThread.Flush));
70+
bool isClose = StackTraceHelper.DoesStackTraceContainMethod(nameof(IndexWriter.Close)) || // LUCENENET NOTE: Close is aggressively inlined, so likely won't hit this case, but would hit Dispose
71+
StackTraceHelper.DoesStackTraceContainMethod(nameof(IndexWriter.Dispose));
7272

7373
if (isDoFlush && !isClose && Random.NextBoolean())
7474
{
@@ -334,7 +334,7 @@ public ConcurrentMergeSchedulerAnonymousClass(int maxMergeCount, CountdownEvent
334334
this.failed = failed;
335335
}
336336

337-
protected override void DoMerge(MergePolicy.OneMerge merge)
337+
protected internal override void DoMerge(MergePolicy.OneMerge merge)
338338
{
339339
try
340340
{
@@ -385,7 +385,7 @@ public TrackingCMS()
385385
SetMaxMergesAndThreads(5, 5);
386386
}
387387

388-
protected override void DoMerge(MergePolicy.OneMerge merge)
388+
protected internal override void DoMerge(MergePolicy.OneMerge merge)
389389
{
390390
totMergedBytes += merge.TotalBytesSize;
391391
base.DoMerge(merge);
@@ -432,7 +432,7 @@ public override void Eval(MockDirectoryWrapper dir)
432432
{
433433
// LUCENENET specific: for these to work in release mode, we have added [MethodImpl(MethodImplOptions.NoInlining)]
434434
// to each possible target of the StackTraceHelper. If these change, so must the attribute on the target methods.
435-
if (StackTraceHelper.DoesStackTraceContainMethod("DoMerge"))
435+
if (StackTraceHelper.DoesStackTraceContainMethod(nameof(ConcurrentMergeScheduler.DoMerge)))
436436
{
437437
throw new IOException("now failing during merge");
438438
}

src/Lucene.Net.Tests/Index/TestIndexWriterDelete.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -975,8 +975,8 @@ public override void Eval(MockDirectoryWrapper dir)
975975
// LUCENENET specific: for these to work in release mode, we have added [MethodImpl(MethodImplOptions.NoInlining)]
976976
// to each possible target of the StackTraceHelper. If these change, so must the attribute on the target methods.
977977
bool seen =
978-
StackTraceHelper.DoesStackTraceContainMethod("ApplyDeletesAndUpdates") ||
979-
StackTraceHelper.DoesStackTraceContainMethod("SlowFileExists");
978+
StackTraceHelper.DoesStackTraceContainMethod(nameof(BufferedUpdatesStream.ApplyDeletesAndUpdates)) ||
979+
StackTraceHelper.DoesStackTraceContainMethod(nameof(IndexWriter.SlowFileExists));
980980

981981
if (!seen)
982982
{
@@ -994,7 +994,7 @@ public override void Eval(MockDirectoryWrapper dir)
994994
{
995995
// LUCENENET specific: for these to work in release mode, we have added [MethodImpl(MethodImplOptions.NoInlining)]
996996
// to each possible target of the StackTraceHelper. If these change, so must the attribute on the target methods.
997-
if (StackTraceHelper.DoesStackTraceContainMethod("ApplyDeletesAndUpdates"))
997+
if (StackTraceHelper.DoesStackTraceContainMethod(nameof(BufferedUpdatesStream.ApplyDeletesAndUpdates)))
998998
{
999999
if (Verbose)
10001000
{

src/Lucene.Net.Tests/Index/TestIndexWriterExceptions.cs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using J2N.Threading;
22
using J2N.Threading.Atomic;
33
using Lucene.Net.Analysis;
4+
using Lucene.Net.Codecs;
5+
using Lucene.Net.Codecs.Lucene40;
46
using Lucene.Net.Diagnostics;
57
using Lucene.Net.Documents;
68
using Lucene.Net.Index.Extensions;
@@ -699,7 +701,7 @@ public override void Eval(MockDirectoryWrapper dir)
699701
// which will always be true if the first case is true. The name of the variable implies it checking for "Append"
700702
// but that is not a method on FreqProxTermsWriterPerField.
701703
bool sawAppend = StackTraceHelper.DoesStackTraceContainMethod(nameof(FreqProxTermsWriterPerField), nameof(FreqProxTermsWriterPerField.Flush));
702-
bool sawFlush = StackTraceHelper.DoesStackTraceContainMethod("Flush");
704+
bool sawFlush = StackTraceHelper.DoesStackTraceContainMethod(nameof(FreqProxTermsWriterPerField.Flush));
703705

704706
if (sawAppend && sawFlush && count++ >= 30)
705707
{
@@ -1810,7 +1812,7 @@ public override IndexInput OpenInput(string name, IOContext context)
18101812
// to each possible target of the StackTraceHelper. If these change, so must the attribute on the target methods.
18111813
if (doFail
18121814
&& name.StartsWith("segments_", StringComparison.Ordinal)
1813-
&& StackTraceHelper.DoesStackTraceContainMethod("Read"))
1815+
&& StackTraceHelper.DoesStackTraceContainMethod(nameof(SegmentInfos.Read)))
18141816
{
18151817
throw UnsupportedOperationException.Create("expected UOE");
18161818
}
@@ -2349,9 +2351,9 @@ public override void Eval(MockDirectoryWrapper dir)
23492351

23502352
// LUCENENET specific: for these to work in release mode, we have added [MethodImpl(MethodImplOptions.NoInlining)]
23512353
// to each possible target of the StackTraceHelper. If these change, so must the attribute on the target methods.
2352-
bool sawSeal = StackTraceHelper.DoesStackTraceContainMethod("SealFlushedSegment");
2353-
bool sawWrite = StackTraceHelper.DoesStackTraceContainMethod("WriteLiveDocs")
2354-
|| StackTraceHelper.DoesStackTraceContainMethod("WriteFieldUpdates");
2354+
bool sawSeal = StackTraceHelper.DoesStackTraceContainMethod(nameof(DocumentsWriterPerThread.SealFlushedSegment));
2355+
bool sawWrite = StackTraceHelper.DoesStackTraceContainMethod(nameof(Lucene40LiveDocsFormat.WriteLiveDocs))
2356+
|| StackTraceHelper.DoesStackTraceContainMethod(nameof(ReadersAndUpdates.WriteFieldUpdates));
23552357

23562358
// Don't throw exc if we are "flushing", else
23572359
// the segment is aborted and docs are lost:
@@ -2527,7 +2529,7 @@ public override void Eval(MockDirectoryWrapper dir)
25272529
{
25282530
// LUCENENET specific: for these to work in release mode, we have added [MethodImpl(MethodImplOptions.NoInlining)]
25292531
// to each possible target of the StackTraceHelper. If these change, so must the attribute on the target methods.
2530-
bool maybeFail = StackTraceHelper.DoesStackTraceContainMethod("RollbackInternal");
2532+
bool maybeFail = StackTraceHelper.DoesStackTraceContainMethod(nameof(IndexWriter.RollbackInternal));
25312533

25322534
if (maybeFail && Random.Next(10) == 0)
25332535
{

src/Lucene.Net.Tests/Index/TestIndexWriterReader.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ public override void Eval(MockDirectoryWrapper dir)
13791379
{
13801380
// LUCENENET specific: for these to work in release mode, we have added [MethodImpl(MethodImplOptions.NoInlining)]
13811381
// to each possible target of the StackTraceHelper. If these change, so must the attribute on the target methods.
1382-
if (shouldFail && StackTraceHelper.DoesStackTraceContainMethod("GetReadOnlyClone"))
1382+
if (shouldFail && StackTraceHelper.DoesStackTraceContainMethod(nameof(ReadersAndUpdates.GetReadOnlyClone)))
13831383
{
13841384
if (Verbose)
13851385
{

src/Lucene.Net.Tests/Index/TestIndexWriterWithThreads.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -433,11 +433,11 @@ public override void Eval(MockDirectoryWrapper dir)
433433
{
434434
// LUCENENET specific: for these to work in release mode, we have added [MethodImpl(MethodImplOptions.NoInlining)]
435435
// to each possible target of the StackTraceHelper. If these change, so must the attribute on the target methods.
436-
bool sawAbortOrFlushDoc = StackTraceHelper.DoesStackTraceContainMethod("Abort")
437-
|| StackTraceHelper.DoesStackTraceContainMethod("FinishDocument");
438-
bool sawClose = StackTraceHelper.DoesStackTraceContainMethod("Close")
439-
|| StackTraceHelper.DoesStackTraceContainMethod("Dispose");
440-
bool sawMerge = StackTraceHelper.DoesStackTraceContainMethod("Merge");
436+
bool sawAbortOrFlushDoc = StackTraceHelper.DoesStackTraceContainMethod(nameof(DocumentsWriterPerThread.Abort))
437+
|| StackTraceHelper.DoesStackTraceContainMethod(nameof(DocFieldProcessor.FinishDocument));
438+
bool sawClose = StackTraceHelper.DoesStackTraceContainMethod(nameof(IndexWriter.Close))
439+
|| StackTraceHelper.DoesStackTraceContainMethod(nameof(IndexWriter.Dispose));
440+
bool sawMerge = StackTraceHelper.DoesStackTraceContainMethod(nameof(IndexWriter.Merge));
441441

442442
if (sawAbortOrFlushDoc && !sawClose && !sawMerge)
443443
{

src/Lucene.Net.Tests/TestMergeSchedulerExternal.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected override void HandleMergeException(Exception t)
8484
outerInstance.excCalled = true;
8585
}
8686

87-
protected override void DoMerge(MergePolicy.OneMerge merge)
87+
protected internal override void DoMerge(MergePolicy.OneMerge merge)
8888
{
8989
outerInstance.mergeCalled = true;
9090
base.DoMerge(merge);
@@ -97,7 +97,7 @@ public override void Eval(MockDirectoryWrapper dir)
9797
{
9898
// LUCENENET specific: for these to work in release mode, we have added [MethodImpl(MethodImplOptions.NoInlining)]
9999
// to each possible target of the StackTraceHelper. If these change, so must the attribute on the target methods.
100-
if (StackTraceHelper.DoesStackTraceContainMethod("DoMerge"))
100+
if (StackTraceHelper.DoesStackTraceContainMethod(nameof(ConcurrentMergeScheduler.DoMerge)))
101101
{
102102
throw new IOException("now failing during merge");
103103
}

src/Lucene.Net/Codecs/Compressing/CompressingStoredFieldsWriter.cs

-4
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ public override void StartDocument(int numStoredFields)
166166
++numBufferedDocs;
167167
}
168168

169-
[MethodImpl(MethodImplOptions.NoInlining)]
170169
public override void FinishDocument()
171170
{
172171
endOffsets[numBufferedDocs - 1] = bufferedDocs.Length;
@@ -240,7 +239,6 @@ private bool TriggerFlush()
240239
return bufferedDocs.Length >= chunkSize || numBufferedDocs >= MAX_DOCUMENTS_PER_CHUNK; // chunks of at least chunkSize bytes
241240
}
242241

243-
[MethodImpl(MethodImplOptions.NoInlining)]
244242
private void Flush()
245243
{
246244
indexWriter.WriteIndex(numBufferedDocs, fieldsStream.Position); // LUCENENET specific: Renamed from getFilePointer() to match FileStream
@@ -363,7 +361,6 @@ public override void WriteField(FieldInfo info, IIndexableField field)
363361
}
364362
}
365363

366-
[MethodImpl(MethodImplOptions.NoInlining)]
367364
public override void Abort()
368365
{
369366
IOUtils.DisposeWhileHandlingException(this);
@@ -389,7 +386,6 @@ public override void Finish(FieldInfos fis, int numDocs)
389386
if (Debugging.AssertsEnabled) Debugging.Assert(bufferedDocs.Length == 0);
390387
}
391388

392-
[MethodImpl(MethodImplOptions.NoInlining)]
393389
public override int Merge(MergeState mergeState)
394390
{
395391
int docCount = 0;

src/Lucene.Net/Codecs/Compressing/CompressingTermVectorsWriter.cs

-4
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ protected override void Dispose(bool disposing)
318318
}
319319
}
320320

321-
[MethodImpl(MethodImplOptions.NoInlining)]
322321
public override void Abort()
323322
{
324323
IOUtils.DisposeWhileHandlingException(this);
@@ -331,7 +330,6 @@ public override void StartDocument(int numVectorFields)
331330
curDoc = AddDocData(numVectorFields);
332331
}
333332

334-
[MethodImpl(MethodImplOptions.NoInlining)]
335333
public override void FinishDocument()
336334
{
337335
// append the payload bytes of the doc after its terms
@@ -390,7 +388,6 @@ private bool TriggerFlush()
390388
return termSuffixes.Length >= chunkSize || pendingDocs.Count >= MAX_DOCUMENTS_PER_CHUNK;
391389
}
392390

393-
[MethodImpl(MethodImplOptions.NoInlining)]
394391
private void Flush()
395392
{
396393
int chunkDocs = pendingDocs.Count;
@@ -879,7 +876,6 @@ public override void AddProx(int numProx, DataInput positions, DataInput offsets
879876
curField.totalPositions += numProx;
880877
}
881878

882-
[MethodImpl(MethodImplOptions.NoInlining)]
883879
public override int Merge(MergeState mergeState)
884880
{
885881
int docCount = 0;

src/Lucene.Net/Codecs/FieldsConsumer.cs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using Lucene.Net.Diagnostics;
22
using System;
3-
using System.Diagnostics;
4-
using System.Runtime.CompilerServices;
53

64
namespace Lucene.Net.Codecs
75
{
@@ -77,11 +75,10 @@ public void Dispose()
7775
/// <summary>
7876
/// Called during merging to merge all <see cref="Fields"/> from
7977
/// sub-readers. this must recurse to merge all postings
80-
/// (terms, docs, positions, etc.). A
78+
/// (terms, docs, positions, etc.). A
8179
/// <see cref="PostingsFormat"/> can override this default
8280
/// implementation to do its own merging.
8381
/// </summary>
84-
[MethodImpl(MethodImplOptions.NoInlining)]
8582
public virtual void Merge(MergeState mergeState, Fields fields)
8683
{
8784
foreach (string field in fields)
@@ -97,4 +94,4 @@ public virtual void Merge(MergeState mergeState, Fields fields)
9794
}
9895
}
9996
}
100-
}
97+
}

src/Lucene.Net/Codecs/Lucene40/Lucene40LiveDocsFormat.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public override IBits ReadLiveDocs(Directory dir, SegmentCommitInfo info, IOCont
100100
return liveDocs;
101101
}
102102

103-
[MethodImpl(MethodImplOptions.NoInlining)]
103+
[MethodImpl(MethodImplOptions.NoInlining)] // Stack trace needed intact in TestIndexWriterExceptions, TestIndexWriterOnDiskFull
104104
public override void WriteLiveDocs(IMutableBits bits, Directory dir, SegmentCommitInfo info, int newDelCount, IOContext context)
105105
{
106106
string filename = IndexFileNames.FileNameFromGeneration(info.Info.Name, DELETES_EXTENSION, info.NextDelGen);
@@ -122,4 +122,4 @@ public override void Files(SegmentCommitInfo info, ICollection<string> files)
122122
}
123123
}
124124
}
125-
}
125+
}

src/Lucene.Net/Codecs/Lucene40/Lucene40StoredFieldsWriter.cs

-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ protected override void Dispose(bool disposing)
147147
}
148148
}
149149

150-
[MethodImpl(MethodImplOptions.NoInlining)]
151150
public override void Abort()
152151
{
153152
try
@@ -288,7 +287,6 @@ public override void Finish(FieldInfos fis, int numDocs)
288287
}
289288
}
290289

291-
[MethodImpl(MethodImplOptions.NoInlining)]
292290
public override int Merge(MergeState mergeState)
293291
{
294292
int docCount = 0;

0 commit comments

Comments
 (0)