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

Commit

Permalink
Browse files Browse the repository at this point in the history
8288846: misc tests fail "assert(ms < 1000) failed: Un-interruptable …
…sleep, short time use only"

Reviewed-by: egahlin
  • Loading branch information
Markus Grönlund committed Jun 22, 2022
1 parent 8fa46c8 commit 6037ccd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
24 changes: 17 additions & 7 deletions src/hotspot/share/jfr/periodic/sampling/jfrThreadSampler.cpp
Expand Up @@ -35,6 +35,7 @@
#include "jfr/utilities/jfrTime.hpp"
#include "jfrfiles/jfrEventClasses.hpp"
#include "logging/log.hpp"
#include "runtime/atomic.hpp"
#include "runtime/frame.inline.hpp"
#include "runtime/os.hpp"
#include "runtime/semaphore.hpp"
Expand Down Expand Up @@ -353,8 +354,8 @@ class JfrThreadSampler : public NonJavaThread {
void run();
static Monitor* transition_block() { return JfrThreadSampler_lock; }
static void on_javathread_suspend(JavaThread* thread);
int64_t get_java_period() const { return _java_period_millis; };
int64_t get_native_period() const { return _native_period_millis; };
int64_t get_java_period() const { return Atomic::load(&_java_period_millis); };
int64_t get_native_period() const { return Atomic::load(&_native_period_millis); };
};

static void clear_transition_block(JavaThread* jt) {
Expand Down Expand Up @@ -417,12 +418,12 @@ JfrThreadSampler::~JfrThreadSampler() {

void JfrThreadSampler::set_java_period(int64_t period_millis) {
assert(period_millis >= 0, "invariant");
_java_period_millis = period_millis;
Atomic::store(&_java_period_millis, period_millis);
}

void JfrThreadSampler::set_native_period(int64_t period_millis) {
assert(period_millis >= 0, "invariant");
_native_period_millis = period_millis;
Atomic::store(&_native_period_millis, period_millis);
}

static inline bool is_released(JavaThread* jt) {
Expand Down Expand Up @@ -501,8 +502,17 @@ void JfrThreadSampler::run() {
last_native_ms = last_java_ms;
}
_sample.signal();
const int64_t java_period_millis = _java_period_millis == 0 ? max_jlong : MAX2<int64_t>(_java_period_millis, 1);
const int64_t native_period_millis = _native_period_millis == 0 ? max_jlong : MAX2<int64_t>(_native_period_millis, 1);

int64_t java_period_millis = get_java_period();
java_period_millis = java_period_millis == 0 ? max_jlong : MAX2<int64_t>(java_period_millis, 1);
int64_t native_period_millis = get_native_period();
native_period_millis = native_period_millis == 0 ? max_jlong : MAX2<int64_t>(native_period_millis, 1);

// If both periods are max_jlong, it implies the sampler is in the process of
// disenrolling. Loop back for graceful disenroll by means of the semaphore.
if (java_period_millis == max_jlong && native_period_millis == max_jlong) {
continue;
}

const int64_t now_ms = get_monotonic_ms();

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

if (sleep_to_next > 0) {
os::naked_short_sleep(sleep_to_next);
os::naked_sleep(sleep_to_next);
}

if ((next_j - sleep_to_next) <= 0) {
Expand Down
7 changes: 5 additions & 2 deletions test/jdk/jdk/jfr/event/sampling/TestNative.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -48,9 +48,12 @@ public class TestNative {

static volatile boolean alive = true;

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

1 comment on commit 6037ccd

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.