Skip to content

Commit 856931d

Browse files
committed
8304732: jdk/jfr/api/consumer/recordingstream/TestStop.java failed again with "Expected outer stream to have 3 events"
Reviewed-by: mgronlun
1 parent 01ee424 commit 856931d

File tree

17 files changed

+154
-70
lines changed

17 files changed

+154
-70
lines changed

src/hotspot/share/jfr/jni/jfrJniMethod.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "jfr/recorder/jfrRecorder.hpp"
3131
#include "jfr/recorder/checkpoint/jfrMetadataEvent.hpp"
3232
#include "jfr/recorder/checkpoint/types/traceid/jfrTraceId.inline.hpp"
33+
#include "jfr/recorder/repository/jfrChunk.hpp"
3334
#include "jfr/recorder/repository/jfrRepository.hpp"
3435
#include "jfr/recorder/repository/jfrChunkRotation.hpp"
3536
#include "jfr/recorder/repository/jfrChunkWriter.hpp"
@@ -425,3 +426,7 @@ JVM_END
425426
JVM_ENTRY_NO_ENV(void, jfr_unregister_stack_filter(JNIEnv* env, jclass jvm, jlong id))
426427
JfrStackFilterRegistry::remove(id);
427428
JVM_END
429+
430+
NO_TRANSITION(jlong, jfr_nanos_now(JNIEnv* env, jclass jvm))
431+
return JfrChunk::nanos_now();
432+
NO_TRANSITION_END

src/hotspot/share/jfr/jni/jfrJniMethod.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ jlong JNICALL jfr_register_stack_filter(JNIEnv* env, jclass jvm, jobjectArray cl
165165

166166
jlong JNICALL jfr_unregister_stack_filter(JNIEnv* env, jclass jvm, jlong id);
167167

168+
jlong JNICALL jfr_nanos_now(JNIEnv* env, jclass jvm);
169+
168170
#ifdef __cplusplus
169171
}
170172
#endif

src/hotspot/share/jfr/jni/jfrJniMethodRegistration.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ JfrJniMethodRegistration::JfrJniMethodRegistration(JNIEnv* env) {
100100
(char*)"hostTotalSwapMemory", (char*)"()J", (void*) jfr_host_total_swap_memory,
101101
(char*)"emitDataLoss", (char*)"(J)V", (void*)jfr_emit_data_loss,
102102
(char*)"registerStackFilter", (char*)"([Ljava/lang/String;[Ljava/lang/String;)J", (void*)jfr_register_stack_filter,
103-
(char*)"unregisterStackFilter", (char*)"(J)V", (void*)jfr_unregister_stack_filter
103+
(char*)"unregisterStackFilter", (char*)"(J)V", (void*)jfr_unregister_stack_filter,
104+
(char*)"nanosNow", (char*)"()J", (void*)jfr_nanos_now
104105
};
105106

106107
const size_t method_array_length = sizeof(method) / sizeof(JNINativeMethod);

src/hotspot/share/jfr/recorder/repository/jfrChunk.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2024, 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
@@ -35,7 +35,7 @@ static const u2 JFR_VERSION_MAJOR = 2;
3535
static const u2 JFR_VERSION_MINOR = 1;
3636

3737
// strictly monotone
38-
static jlong nanos_now() {
38+
jlong JfrChunk::nanos_now() {
3939
static jlong last = 0;
4040

4141
jlong seconds;
@@ -147,7 +147,7 @@ void JfrChunk::update_start_ticks() {
147147
}
148148

149149
void JfrChunk::update_start_nanos() {
150-
const jlong now = nanos_now();
150+
const jlong now = JfrChunk::nanos_now();
151151
assert(now >= _start_nanos, "invariant");
152152
assert(now >= _last_update_nanos, "invariant");
153153
_start_nanos = _last_update_nanos = now;

src/hotspot/share/jfr/recorder/repository/jfrChunk.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2024, 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
@@ -34,6 +34,8 @@ const u1 PAD = 0;
3434
class JfrChunk : public JfrCHeapObj {
3535
friend class JfrChunkWriter;
3636
friend class JfrChunkHeadWriter;
37+
public:
38+
static jlong nanos_now();
3739
private:
3840
char* _path;
3941
int64_t _start_ticks;

src/hotspot/share/jfr/support/jfrIntrinsics.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2024, 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
@@ -47,13 +47,13 @@ class JfrIntrinsicSupport : AllStatic {
4747
#define JFR_HAVE_INTRINSICS
4848

4949
#define JFR_TEMPLATES(template) \
50+
template(jdk_jfr_internal_HiddenWait, "jdk/jfr/internal/HiddenWait") \
5051
template(jdk_jfr_internal_JVM, "jdk/jfr/internal/JVM") \
5152
template(jdk_jfr_internal_event_EventWriterFactory, "jdk/jfr/internal/event/EventWriterFactory") \
5253
template(jdk_jfr_internal_event_EventConfiguration_signature, "Ljdk/jfr/internal/event/EventConfiguration;") \
5354
template(getEventWriter_signature, "()Ljdk/jfr/internal/event/EventWriter;") \
5455
template(eventConfiguration_name, "eventConfiguration") \
5556
template(commit_name, "commit") \
56-
template(jfr_chunk_rotation_monitor, "jdk/jfr/internal/JVM$ChunkRotationMonitor") \
5757

5858
#define JFR_INTRINSICS(do_intrinsic, do_class, do_name, do_signature, do_alias) \
5959
do_intrinsic(_counterTime, jdk_jfr_internal_JVM, counterTime_name, void_long_signature, F_SN) \

src/hotspot/share/runtime/objectMonitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,7 @@ bool ObjectMonitor::check_owner(TRAPS) {
14421442
static inline bool is_excluded(const Klass* monitor_klass) {
14431443
assert(monitor_klass != nullptr, "invariant");
14441444
NOT_JFR_RETURN_(false);
1445-
JFR_ONLY(return vmSymbols::jfr_chunk_rotation_monitor() == monitor_klass->name();)
1445+
JFR_ONLY(return vmSymbols::jdk_jfr_internal_HiddenWait() == monitor_klass->name();)
14461446
}
14471447

14481448
static void post_monitor_wait_event(EventJavaMonitorWait* event,
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package jdk.jfr.internal;
26+
27+
/**
28+
* The HiddenWait class is used to exclude jdk.JavaMonitorWait events
29+
* from being generated when Object.wait() is called on an object of this type.
30+
*/
31+
public final class HiddenWait {
32+
}

src/jdk.jfr/share/classes/jdk/jfr/internal/JVM.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2024, 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
@@ -41,14 +41,10 @@ public final class JVM {
4141

4242
static final long RESERVED_CLASS_ID_LIMIT = 500;
4343

44-
private static class ChunkRotationMonitor {}
45-
4644
/*
4745
* The JVM uses the chunk rotation monitor to notify Java that a rotation is warranted.
48-
* The monitor type is used to exclude jdk.JavaMonitorWait events from being generated
49-
* when Object.wait() is called on this monitor.
5046
*/
51-
public static final Object CHUNK_ROTATION_MONITOR = new ChunkRotationMonitor();
47+
public static final Object CHUNK_ROTATION_MONITOR = new HiddenWait();
5248

5349
private static volatile boolean nativeOK;
5450

@@ -174,6 +170,11 @@ private static class ChunkRotationMonitor {}
174170
*/
175171
public static native long getTicksFrequency();
176172

173+
/**
174+
* Returns the same clock that sets the start time of a chunk (in nanos).
175+
*/
176+
public static native long nanosNow();
177+
177178
/**
178179
* Write message to log. Should swallow null or empty message, and be able
179180
* to handle any Java character and not crash with very large message

src/jdk.jfr/share/classes/jdk/jfr/internal/JVMSupport.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2024, 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
@@ -119,11 +119,7 @@ private static void awaitUniqueTimestamp() {
119119
lastTimestamp = time;
120120
return;
121121
}
122-
try {
123-
Thread.sleep(0, 100);
124-
} catch (InterruptedException iex) {
125-
// ignore
126-
}
122+
Utils.takeNap(1);
127123
}
128124
}
129125

0 commit comments

Comments
 (0)