Skip to content

Commit

Permalink
Add runtime hints for VirtualThreadSchedulerMXBean
Browse files Browse the repository at this point in the history
  • Loading branch information
mhalbritter committed Jan 13, 2025
1 parent 8039030 commit 679c0e4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the original author or authors.
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
package org.springframework.boot.actuate.info;

import org.springframework.aot.hint.BindingReflectionHintsRegistrar;
import org.springframework.aot.hint.MemberCategory;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.boot.actuate.info.Info.Builder;
Expand Down Expand Up @@ -51,6 +52,9 @@ static class ProcessInfoContributorRuntimeHints implements RuntimeHintsRegistrar
@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
this.bindingRegistrar.registerReflectionHints(hints.reflection(), ProcessInfo.class);
hints.reflection()
.registerTypeIfPresent(classLoader, "jdk.management.VirtualThreadSchedulerMXBean",
MemberCategory.INVOKE_PUBLIC_METHODS);
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the original author or authors.
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,9 +17,12 @@
package org.springframework.boot.actuate.info;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledForJreRange;
import org.junit.jupiter.api.condition.JRE;

import org.springframework.aot.hint.MemberCategory;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.TypeReference;
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
import org.springframework.boot.actuate.info.ProcessInfoContributor.ProcessInfoContributorRuntimeHints;
import org.springframework.boot.info.ProcessInfo;
Expand All @@ -30,6 +33,7 @@
* Tests for {@link ProcessInfoContributor}.
*
* @author Jonatan Ivanov
* @author Moritz Halbritter
*/
class ProcessInfoContributorTests {

Expand All @@ -52,4 +56,14 @@ void shouldRegisterHints() {
.accepts(runtimeHints);
}

@Test
@EnabledForJreRange(min = JRE.JAVA_24)
void shouldRegisterRuntimeHintsForVirtualThreadSchedulerMXBean() {
RuntimeHints runtimeHints = new RuntimeHints();
new ProcessInfoContributorRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
assertThat(RuntimeHintsPredicates.reflection()
.onType(TypeReference.of("jdk.management.VirtualThreadSchedulerMXBean"))
.withMemberCategories(MemberCategory.INVOKE_PUBLIC_METHODS)).accepts(runtimeHints);
}

}

0 comments on commit 679c0e4

Please sign in to comment.