On Tue, 6 Jul 2021 06:19:07 GMT, Denghui Dong <[email protected]> wrote:
>> Hi,
>>
>> Could I have a review of this improvement that eliminates 'is_large' check
>> if the event size range is certain?
>>
>> JDK-8246260 introduced event large checks to reduce the recording size.
>> This check could be eliminated at compile/build time when one of the
>> following conditions is satisfied:
>> 1. if the max size is < 128
>> 2. if the min size is >= 128
>>
>> The max size and the min size could be computed for the most native events
>> at the generation phase.
>>
>> And I think this improvement may also be done for JDK events.
>
> Denghui Dong has refreshed the contents of this pull request, and previous
> commits have been removed. The incremental views will show differences
> compared to the previous content of the PR.
diff --git a/src/hotspot/share/jfr/jni/jfrJniMethod.cpp
b/src/hotspot/share/jfr/jni/jfrJniMethod.cpp
index 54a4680ced8..893aaebdbd6 100644
--- a/src/hotspot/share/jfr/jni/jfrJniMethod.cpp
+++ b/src/hotspot/share/jfr/jni/jfrJniMethod.cpp
@@ -362,3 +362,11 @@ JVM_END
JVM_ENTRY_NO_ENV(jboolean, jfr_set_handler(JNIEnv * env, jobject jvm, jobject
clazz, jobject handler))
return JfrJavaSupport::set_handler(clazz, handler, thread);
JVM_END
+
+JVM_ENTRY_NO_ENV(void, jfr_emit(JNIEnv* env, jobject jvm))
+ for (int i = 0; i < 100; i++) {
+ EventTest e;
+ e.set_dummy(1);
+ e.commit();
+ }
+JVM_END
diff --git a/src/hotspot/share/jfr/jni/jfrJniMethod.hpp
b/src/hotspot/share/jfr/jni/jfrJniMethod.hpp
index 19a676c4a22..7da213c80c1 100644
--- a/src/hotspot/share/jfr/jni/jfrJniMethod.hpp
+++ b/src/hotspot/share/jfr/jni/jfrJniMethod.hpp
@@ -152,6 +152,8 @@ jboolean JNICALL jfr_set_handler(JNIEnv* env, jobject jvm,
jobject clazz, jobjec
jlong JNICALL jfr_get_type_id_from_string(JNIEnv* env, jobject jvm, jstring
type);
+void JNICALL jfr_emit(JNIEnv*, jobject jvm);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/hotspot/share/jfr/jni/jfrJniMethodRegistration.cpp
b/src/hotspot/share/jfr/jni/jfrJniMethodRegistration.cpp
index db137776f65..1aab7909f6e 100644
--- a/src/hotspot/share/jfr/jni/jfrJniMethodRegistration.cpp
+++ b/src/hotspot/share/jfr/jni/jfrJniMethodRegistration.cpp
@@ -90,7 +90,8 @@ JfrJniMethodRegistration::JfrJniMethodRegistration(JNIEnv*
env) {
(char*)"getChunkStartNanos", (char*)"()J", (void*)jfr_chunk_start_nanos,
(char*)"getHandler", (char*)"(Ljava/lang/Class;)Ljava/lang/Object;",
(void*)jfr_get_handler,
(char*)"setHandler",
(char*)"(Ljava/lang/Class;Ljdk/jfr/internal/handlers/EventHandler;)Z",
(void*)jfr_set_handler,
- (char*)"getTypeId", (char*)"(Ljava/lang/String;)J",
(void*)jfr_get_type_id_from_string
+ (char*)"getTypeId", (char*)"(Ljava/lang/String;)J",
(void*)jfr_get_type_id_from_string,
+ (char*)"emit", (char*)"()V", (void*)jfr_emit,
};
const size_t method_array_length = sizeof(method) /
sizeof(JNINativeMethod);
diff --git a/src/hotspot/share/jfr/metadata/metadata.xml
b/src/hotspot/share/jfr/metadata/metadata.xml
index 1a19b763314..633c6e3f1f1 100644
--- a/src/hotspot/share/jfr/metadata/metadata.xml
+++ b/src/hotspot/share/jfr/metadata/metadata.xml
@@ -1081,6 +1081,10 @@
<Field type="uint" name="stallCount" label="Stall Count" description="The
number of Java threads stalled by the GC locker" />
</Event>
+ <Event name="Test" category="Test" label="Dummy">
+ <Field type="uint" name="dummy" label="Dummy" description="Dummy" />
+ </Event>
+
<Type name="DeoptimizationReason" label="Deoptimization Reason">
<Field type="string" name="reason" label="Reason" />
</Type>
diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/JVM.java
b/src/jdk.jfr/share/classes/jdk/jfr/internal/JVM.java
index a88b428dac3..bd28e5b4015 100644
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/JVM.java
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/JVM.java
@@ -597,4 +597,6 @@ public final class JVM {
* @return the id, or a negative value if it does not exists.
*/
public native long getTypeId(String name);
+
+ public native void emit();
}
It's a simple benchmark, I wrote a native function to emit 100 same native
events.
package org.sample;
import jdk.jfr.Event;
import jdk.jfr.Recording;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import jdk.jfr.internal.JVM;
@State(Scope.Benchmark)
public class MyBenchmark {
@Benchmark
@Fork(value=1, jvmArgs = {"--add-exports",
"jdk.jfr/jdk.jfr.internal=ALL-UNNAMED"})
@Warmup(iterations = 5, time = 1)
public void testEmit(Blackhole bh) {
JVM.getJVM().emit();
}
}
-------------
PR: https://git.openjdk.java.net/jdk/pull/4670