Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8285513: JFR: Add more static support for event classes #8810

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -114,23 +114,23 @@ record FieldInfo(String fieldName, String fieldDescriptor, String internalClassN
private final Method staticCommitMethod;
private final long eventTypeId;
private final boolean guardEventConfiguration;
private final boolean bootClass;
private final boolean isJDK;

EventInstrumentation(Class<?> superClass, byte[] bytes, long id, boolean bootClass, boolean guardEventConfiguration) {
EventInstrumentation(Class<?> superClass, byte[] bytes, long id, boolean isJDK, boolean guardEventConfiguration) {
this.eventTypeId = id;
this.superClass = superClass;
this.classNode = createClassNode(bytes);
this.settingInfos = buildSettingInfos(superClass, classNode);
this.fieldInfos = buildFieldInfos(superClass, classNode);
String n = annotationValue(classNode, ANNOTATION_NAME_DESCRIPTOR, String.class);
this.eventName = n == null ? classNode.name.replace("/", ".") : n;
this.staticCommitMethod = bootClass ? findStaticCommitMethod(classNode, fieldInfos) : null;
this.staticCommitMethod = isJDK ? findStaticCommitMethod(classNode, fieldInfos) : null;
this.untypedEventConfiguration = hasUntypedConfiguration();
// Corner case when we are forced to generate bytecode (bytesForEagerInstrumentation)
// We can't reference EventConfiguration::isEnabled() before event class has been registered,
// so we add a guard against a null reference.
this.guardEventConfiguration = guardEventConfiguration;
this.bootClass = bootClass;
this.isJDK = isJDK;
}

public static Method findStaticCommitMethod(ClassNode classNode, List<FieldInfo> fields) {
@@ -338,7 +338,7 @@ public byte[] buildUninstrumented() {
}

private void makeInstrumented() {
// MyEvent#isEnabbled()
// MyEvent#isEnabled()
updateEnabledMethod(METHOD_IS_ENABLED);

// MyEvent#begin()
@@ -659,11 +659,11 @@ private void makeInstrumented() {
methodVisitor.visitInsn(Opcodes.IRETURN);
});

if (bootClass) {
if (hasMethod(METHOD_ENABLED)) {
if (isJDK) {
if (hasStaticMethod(METHOD_ENABLED)) {
updateEnabledMethod(METHOD_ENABLED);
};
UpdateIfExists(METHOD_SHOULD_COMMIT_LONG, methodVisitor -> {
updateIfStaticMethodExists(METHOD_SHOULD_COMMIT_LONG, methodVisitor -> {
Label fail = new Label();
if (guardEventConfiguration) {
// if (eventConfiguration == null) goto fail;
@@ -683,7 +683,7 @@ private void makeInstrumented() {
methodVisitor.visitMaxs(0, 0);
methodVisitor.visitEnd();
});
UpdateIfExists(METHOD_TIME_STAMP, methodVisitor -> {
updateIfStaticMethodExists(METHOD_TIME_STAMP, methodVisitor -> {
invokeStatic(methodVisitor, TYPE_EVENT_CONFIGURATION.getInternalName(), METHOD_TIME_STAMP);
methodVisitor.visitInsn(Opcodes.LRETURN);
methodVisitor.visitMaxs(0, 0);
@@ -713,16 +713,16 @@ private void updateEnabledMethod(Method method) {
});
}

private void UpdateIfExists(Method method, Consumer<MethodVisitor> code) {
if (hasMethod(method)) {
private void updateIfStaticMethodExists(Method method, Consumer<MethodVisitor> code) {
if (hasStaticMethod(method)) {
updateMethod(method, code);
}
}

private boolean hasMethod(Method method) {
private boolean hasStaticMethod(Method method) {
for (MethodNode m : classNode.methods) {
if (m.name.equals(method.getName()) && m.desc.equals(method.getDescriptor())) {
return true;
return Modifier.isStatic(m.access);
}
}
return false;