Skip to content

Commit f8fbbb6

Browse files
committed
[GR-62935] Introduce a common timing interface
PullRequest: graal/20319
2 parents 87f9e3e + 6033ca9 commit f8fbbb6

File tree

5 files changed

+215
-153
lines changed

5 files changed

+215
-153
lines changed

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/AdaptiveCollectionPolicy.java

+10-9
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.oracle.svm.core.heap.GCCause;
3333
import com.oracle.svm.core.util.BasedOnJDKFile;
3434
import com.oracle.svm.core.util.TimeUtils;
35+
import com.oracle.svm.core.util.Timer;
3536
import com.oracle.svm.core.util.UnsignedUtils;
3637

3738
import jdk.graal.compiler.word.Word;
@@ -393,39 +394,39 @@ private static UnsignedWord spaceIncrement(UnsignedWord curSize, UnsignedWord pe
393394
}
394395

395396
private double secondsSinceMajorGc() { // time_since_major_gc
396-
return TimeUtils.nanosToSecondsDouble(System.nanoTime() - majorTimer.getOpenedTime());
397+
return TimeUtils.nanosToSecondsDouble(System.nanoTime() - majorTimer.startedNanos());
397398
}
398399

399400
@Override
400401
public void onCollectionBegin(boolean completeCollection, long requestingNanoTime) { // {major,minor}_collection_begin
401402
Timer timer = completeCollection ? majorTimer : minorTimer;
402-
timer.closeAt(requestingNanoTime);
403+
timer.stopAt(requestingNanoTime);
403404
if (completeCollection) {
404-
latestMajorMutatorIntervalNanos = timer.getMeasuredNanos();
405+
latestMajorMutatorIntervalNanos = timer.totalNanos();
405406
} else {
406-
latestMinorMutatorIntervalNanos = timer.getMeasuredNanos();
407+
latestMinorMutatorIntervalNanos = timer.totalNanos();
407408
}
408409

409410
timer.reset();
410-
timer.open(); // measure collection pause
411+
timer.start(); // measure collection pause
411412

412413
super.onCollectionBegin(completeCollection, requestingNanoTime);
413414
}
414415

415416
@Override
416417
public void onCollectionEnd(boolean completeCollection, GCCause cause) { // {major,minor}_collection_end
417418
Timer timer = completeCollection ? majorTimer : minorTimer;
418-
timer.close();
419+
timer.stop();
419420

420421
if (completeCollection) {
421422
updateCollectionEndAverages(avgMajorGcCost, avgMajorPause, majorCostEstimator, avgMajorIntervalSeconds,
422-
cause, latestMajorMutatorIntervalNanos, timer.getMeasuredNanos(), promoSize);
423+
cause, latestMajorMutatorIntervalNanos, timer.totalNanos(), promoSize);
423424
majorCount++;
424425
minorCountSinceMajorCollection = 0;
425426

426427
} else {
427428
updateCollectionEndAverages(avgMinorGcCost, avgMinorPause, minorCostEstimator, null,
428-
cause, latestMinorMutatorIntervalNanos, timer.getMeasuredNanos(), edenSize);
429+
cause, latestMinorMutatorIntervalNanos, timer.totalNanos(), edenSize);
429430
minorCount++;
430431
minorCountSinceMajorCollection++;
431432

@@ -435,7 +436,7 @@ public void onCollectionEnd(boolean completeCollection, GCCause cause) { // {maj
435436
}
436437

437438
timer.reset();
438-
timer.open();
439+
timer.start();
439440

440441
GCAccounting accounting = GCImpl.getAccounting();
441442
UnsignedWord oldLive = accounting.getOldGenerationAfterChunkBytes();

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/CompactingOldGeneration.java

+21-20
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import com.oracle.svm.core.log.Log;
5454
import com.oracle.svm.core.thread.VMThreads;
5555
import com.oracle.svm.core.threadlocal.VMThreadLocalSupport;
56+
import com.oracle.svm.core.util.Timer;
5657

5758
import jdk.graal.compiler.word.Word;
5859

@@ -251,25 +252,25 @@ void sweepAndCompact(Timers timers, ChunkReleaser chunkReleaser) {
251252
*/
252253
ReferenceObjectProcessing.updateForwardedRefs();
253254

254-
Timer oldPlanningTimer = timers.oldPlanning.open();
255+
Timer oldPlanningTimer = timers.oldPlanning.start();
255256
try {
256257
planCompaction();
257258
} finally {
258-
oldPlanningTimer.close();
259+
oldPlanningTimer.stop();
259260
}
260261

261-
Timer oldFixupTimer = timers.oldFixup.open();
262+
Timer oldFixupTimer = timers.oldFixup.start();
262263
try {
263264
fixupReferencesBeforeCompaction(chunkReleaser, timers);
264265
} finally {
265-
oldFixupTimer.close();
266+
oldFixupTimer.stop();
266267
}
267268

268-
Timer oldCompactionTimer = timers.oldCompaction.open();
269+
Timer oldCompactionTimer = timers.oldCompaction.start();
269270
try {
270271
compact(timers);
271272
} finally {
272-
oldCompactionTimer.close();
273+
oldCompactionTimer.stop();
273274
}
274275
}
275276

@@ -280,18 +281,18 @@ private void planCompaction() {
280281

281282
@Uninterruptible(reason = "Avoid unnecessary safepoint checks in GC for performance.")
282283
private void fixupReferencesBeforeCompaction(ChunkReleaser chunkReleaser, Timers timers) {
283-
Timer oldFixupAlignedChunksTimer = timers.oldFixupAlignedChunks.open();
284+
Timer oldFixupAlignedChunksTimer = timers.oldFixupAlignedChunks.start();
284285
try {
285286
AlignedHeapChunk.AlignedHeader aChunk = space.getFirstAlignedHeapChunk();
286287
while (aChunk.isNonNull()) {
287288
ObjectMoveInfo.walkObjects(aChunk, fixupVisitor);
288289
aChunk = HeapChunk.getNext(aChunk);
289290
}
290291
} finally {
291-
oldFixupAlignedChunksTimer.close();
292+
oldFixupAlignedChunksTimer.stop();
292293
}
293294

294-
Timer oldFixupImageHeapTimer = timers.oldFixupImageHeap.open();
295+
Timer oldFixupImageHeapTimer = timers.oldFixupImageHeap.start();
295296
try {
296297
for (ImageHeapInfo info : HeapImpl.getImageHeapInfos()) {
297298
fixupImageHeapRoots(info);
@@ -303,43 +304,43 @@ private void fixupReferencesBeforeCompaction(ChunkReleaser chunkReleaser, Timers
303304
}
304305
}
305306
} finally {
306-
oldFixupImageHeapTimer.close();
307+
oldFixupImageHeapTimer.stop();
307308
}
308309

309-
Timer oldFixupThreadLocalsTimer = timers.oldFixupThreadLocals.open();
310+
Timer oldFixupThreadLocalsTimer = timers.oldFixupThreadLocals.start();
310311
try {
311312
for (IsolateThread isolateThread = VMThreads.firstThread(); isolateThread.isNonNull(); isolateThread = VMThreads.nextThread(isolateThread)) {
312313
VMThreadLocalSupport.singleton().walk(isolateThread, refFixupVisitor);
313314
}
314315
} finally {
315-
oldFixupThreadLocalsTimer.close();
316+
oldFixupThreadLocalsTimer.stop();
316317
}
317318

318-
Timer oldFixupStackTimer = timers.oldFixupStack.open();
319+
Timer oldFixupStackTimer = timers.oldFixupStack.start();
319320
try {
320321
fixupStackReferences();
321322
} finally {
322-
oldFixupStackTimer.close();
323+
oldFixupStackTimer.stop();
323324
}
324325

325326
/*
326327
* Check each unaligned object and fix its references if the object is marked. Add the chunk
327328
* to the releaser's list in case the object is not marked and therefore won't survive.
328329
*/
329-
Timer oldFixupUnalignedChunksTimer = timers.oldFixupUnalignedChunks.open();
330+
Timer oldFixupUnalignedChunksTimer = timers.oldFixupUnalignedChunks.start();
330331
try {
331332
fixupUnalignedChunkReferences(chunkReleaser);
332333
} finally {
333-
oldFixupUnalignedChunksTimer.close();
334+
oldFixupUnalignedChunksTimer.stop();
334335
}
335336

336-
Timer oldFixupRuntimeCodeCacheTimer = timers.oldFixupRuntimeCodeCache.open();
337+
Timer oldFixupRuntimeCodeCacheTimer = timers.oldFixupRuntimeCodeCache.start();
337338
try {
338339
if (RuntimeCompilation.isEnabled()) {
339340
RuntimeCodeInfoMemory.singleton().walkRuntimeMethodsDuringGC(runtimeCodeCacheFixupWalker);
340341
}
341342
} finally {
342-
oldFixupRuntimeCodeCacheTimer.close();
343+
oldFixupRuntimeCodeCacheTimer.stop();
343344
}
344345
}
345346

@@ -394,7 +395,7 @@ private void compact(Timers timers) {
394395
chunk = HeapChunk.getNext(chunk);
395396
}
396397

397-
Timer oldCompactionRememberedSetsTimer = timers.oldCompactionRememberedSets.open();
398+
Timer oldCompactionRememberedSetsTimer = timers.oldCompactionRememberedSets.start();
398399
try {
399400
chunk = space.getFirstAlignedHeapChunk();
400401
while (chunk.isNonNull()) {
@@ -413,7 +414,7 @@ private void compact(Timers timers) {
413414
chunk = HeapChunk.getNext(chunk);
414415
}
415416
} finally {
416-
oldCompactionRememberedSetsTimer.close();
417+
oldCompactionRememberedSetsTimer.stop();
417418
}
418419
}
419420

0 commit comments

Comments
 (0)