Skip to content
This repository was archived by the owner on Sep 19, 2023. It is now read-only.

Commit 6037ccd

Browse files
author
Markus Grönlund
committed
8288846: misc tests fail "assert(ms < 1000) failed: Un-interruptable sleep, short time use only"
Reviewed-by: egahlin
1 parent 8fa46c8 commit 6037ccd

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

src/hotspot/share/jfr/periodic/sampling/jfrThreadSampler.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "jfr/utilities/jfrTime.hpp"
3636
#include "jfrfiles/jfrEventClasses.hpp"
3737
#include "logging/log.hpp"
38+
#include "runtime/atomic.hpp"
3839
#include "runtime/frame.inline.hpp"
3940
#include "runtime/os.hpp"
4041
#include "runtime/semaphore.hpp"
@@ -353,8 +354,8 @@ class JfrThreadSampler : public NonJavaThread {
353354
void run();
354355
static Monitor* transition_block() { return JfrThreadSampler_lock; }
355356
static void on_javathread_suspend(JavaThread* thread);
356-
int64_t get_java_period() const { return _java_period_millis; };
357-
int64_t get_native_period() const { return _native_period_millis; };
357+
int64_t get_java_period() const { return Atomic::load(&_java_period_millis); };
358+
int64_t get_native_period() const { return Atomic::load(&_native_period_millis); };
358359
};
359360

360361
static void clear_transition_block(JavaThread* jt) {
@@ -417,12 +418,12 @@ JfrThreadSampler::~JfrThreadSampler() {
417418

418419
void JfrThreadSampler::set_java_period(int64_t period_millis) {
419420
assert(period_millis >= 0, "invariant");
420-
_java_period_millis = period_millis;
421+
Atomic::store(&_java_period_millis, period_millis);
421422
}
422423

423424
void JfrThreadSampler::set_native_period(int64_t period_millis) {
424425
assert(period_millis >= 0, "invariant");
425-
_native_period_millis = period_millis;
426+
Atomic::store(&_native_period_millis, period_millis);
426427
}
427428

428429
static inline bool is_released(JavaThread* jt) {
@@ -501,8 +502,17 @@ void JfrThreadSampler::run() {
501502
last_native_ms = last_java_ms;
502503
}
503504
_sample.signal();
504-
const int64_t java_period_millis = _java_period_millis == 0 ? max_jlong : MAX2<int64_t>(_java_period_millis, 1);
505-
const int64_t native_period_millis = _native_period_millis == 0 ? max_jlong : MAX2<int64_t>(_native_period_millis, 1);
505+
506+
int64_t java_period_millis = get_java_period();
507+
java_period_millis = java_period_millis == 0 ? max_jlong : MAX2<int64_t>(java_period_millis, 1);
508+
int64_t native_period_millis = get_native_period();
509+
native_period_millis = native_period_millis == 0 ? max_jlong : MAX2<int64_t>(native_period_millis, 1);
510+
511+
// If both periods are max_jlong, it implies the sampler is in the process of
512+
// disenrolling. Loop back for graceful disenroll by means of the semaphore.
513+
if (java_period_millis == max_jlong && native_period_millis == max_jlong) {
514+
continue;
515+
}
506516

507517
const int64_t now_ms = get_monotonic_ms();
508518

@@ -521,7 +531,7 @@ void JfrThreadSampler::run() {
521531
const int64_t sleep_to_next = MIN2<int64_t>(next_j, next_n);
522532

523533
if (sleep_to_next > 0) {
524-
os::naked_short_sleep(sleep_to_next);
534+
os::naked_sleep(sleep_to_next);
525535
}
526536

527537
if ((next_j - sleep_to_next) <= 0) {

test/jdk/jdk/jfr/event/sampling/TestNative.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -48,9 +48,12 @@ public class TestNative {
4848

4949
static volatile boolean alive = true;
5050

51+
// Please resist the temptation to speed up the test by decreasing
52+
// the period. It is explicity set to 1100 ms to provoke the 1000 ms
53+
// threshold in the JVM for os::naked_short_sleep().
5154
public static void main(String[] args) throws Exception {
5255
try (RecordingStream rs = new RecordingStream()) {
53-
rs.enable(NATIVE_EVENT).withPeriod(Duration.ofMillis(1));
56+
rs.enable(NATIVE_EVENT).withPeriod(Duration.ofMillis(1100));
5457
rs.onEvent(NATIVE_EVENT, e -> {
5558
alive = false;
5659
rs.close();

0 commit comments

Comments
 (0)