Skip to content

Commit

Permalink
Cleanup GraalVM metadata and used Metadata Repository (#8821)
Browse files Browse the repository at this point in the history
With the GraalVM Metadata Repository now active we no longer need metadata for Netty and Logback so this PR removes that metadata. In addition this PR removes the use of all GraalVM internal APIs from core and upgrades to the latest version of SVM.

Finally, this PR deprecates AutomaticFeatureUtils because in future it should not be necessary to use this class with metadata living the repository.
  • Loading branch information
graemerocher authored Feb 24, 2023
1 parent 7091b4e commit 4398d51
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 285 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/graalvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
graalvm: [ 'latest', 'dev' ]
graalvm: [ 'latest']
java: [ '17' ]
include:
- graalvm: 'dev'
java: '19'
exclude:
- graalvm: 'dev'
java: '17'
steps:
# https://github.com/actions/virtual-environments/issues/709
- name: Free disk space
Expand Down
100 changes: 0 additions & 100 deletions buffer-netty/src/main/java/io/micronaut/buffer/netty/NettyFeature.java

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ dependencies {

implementation "org.tomlj:tomlj:1.1.0"
implementation "me.champeau.gradle:japicmp-gradle-plugin:0.4.1"
implementation "org.graalvm.buildtools.native:org.graalvm.buildtools.native.gradle.plugin:0.9.14"
implementation "org.graalvm.buildtools.native:org.graalvm.buildtools.native.gradle.plugin:0.9.20"
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
*/
package io.micronaut.core.graal;

import com.oracle.svm.core.configure.ResourcesRegistry;
import com.oracle.svm.core.jdk.proxy.DynamicProxyRegistry;
import io.micronaut.core.util.ArrayUtils;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.hosted.Feature.BeforeAnalysisAccess;
import org.graalvm.nativeimage.hosted.RuntimeClassInitialization;
import org.graalvm.nativeimage.hosted.RuntimeProxyCreation;
import org.graalvm.nativeimage.hosted.RuntimeReflection;
import org.graalvm.nativeimage.hosted.RuntimeResourceAccess;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
Expand All @@ -36,7 +35,9 @@
* @author Álvaro Sánchez-Mariscal
* @author graemerocher
* @since 2.0.0
* @deprecated Use GraalVM's own public API under {@code org.graalvm} or conditional metadata in JSON format instead
*/
@Deprecated
public final class AutomaticFeatureUtils {

/**
Expand Down Expand Up @@ -176,7 +177,7 @@ public static void addProxyClass(BeforeAnalysisAccess access, String... interfac
}
}
if (classList.size() == interfaces.length) {
ImageSingletons.lookup(DynamicProxyRegistry.class).addProxyClass(classList.toArray(new Class<?>[interfaces.length]));
RuntimeProxyCreation.register(classList.toArray(new Class<?>[interfaces.length]));
}
}

Expand All @@ -187,12 +188,12 @@ public static void addProxyClass(BeforeAnalysisAccess access, String... interfac
*/
public static void addResourcePatterns(String... patterns) {
if (ArrayUtils.isNotEmpty(patterns)) {
ResourcesRegistry resourcesRegistry = ImageSingletons.lookup(ResourcesRegistry.class);
if (resourcesRegistry != null) {
for (String resource : patterns) {
resourcesRegistry.addResources(resource);
RuntimeResourceAccess.addResource(
AutomaticFeatureUtils.class.getClassLoader().getUnnamedModule(),
resource
);
}
}
}
}

Expand All @@ -203,11 +204,11 @@ public static void addResourcePatterns(String... patterns) {
*/
public static void addResourceBundles(String... bundles) {
if (ArrayUtils.isNotEmpty(bundles)) {
ResourcesRegistry resourcesRegistry = ImageSingletons.lookup(ResourcesRegistry.class);
if (resourcesRegistry != null) {
for (String resource : bundles) {
resourcesRegistry.addResourceBundles(resource);
}
for (String resource : bundles) {
RuntimeResourceAccess.addResourceBundle(
AutomaticFeatureUtils.class.getClassLoader().getUnnamedModule(),
resource
);
}
}
}
Expand Down
68 changes: 0 additions & 68 deletions core/src/main/java/io/micronaut/core/graal/LoggingFeature.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.core.graal;
package io.micronaut.core.io.service;

import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;
import io.micronaut.core.annotation.AnnotationValue;
import io.micronaut.core.annotation.Internal;
import io.micronaut.core.annotation.NonNull;
import io.micronaut.core.beans.BeanInfo;
import io.micronaut.core.graal.GraalReflectionConfigurer;
import io.micronaut.core.io.IOUtils;
import io.micronaut.core.io.service.SoftServiceLoader;
import io.micronaut.core.io.service.ServiceScanner.StaticServiceDefinitions;
import io.micronaut.core.reflect.exception.InstantiationException;
import io.micronaut.core.util.ArrayUtils;
import org.graalvm.nativeimage.ImageSingletons;
Expand All @@ -43,13 +41,10 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
Expand All @@ -67,7 +62,7 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
configureForReflection(access);

StaticServiceDefinitions staticServiceDefinitions = buildStaticServiceDefinitions(access);
final Collection<Set<String>> allTypeNames = staticServiceDefinitions.serviceTypeMap.values();
final Collection<Set<String>> allTypeNames = staticServiceDefinitions.serviceTypeMap().values();
for (Set<String> typeNameSet : allTypeNames) {
Iterator<String> i = typeNameSet.iterator();
serviceLoop: while (i.hasNext()) {
Expand Down Expand Up @@ -119,7 +114,7 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {

@NonNull
private StaticServiceDefinitions buildStaticServiceDefinitions(BeforeAnalysisAccess access) {
StaticServiceDefinitions staticServiceDefinitions = new StaticServiceDefinitions();
StaticServiceDefinitions staticServiceDefinitions = new StaticServiceDefinitions(null);
final String path = "META-INF/micronaut/";
try {
final Enumeration<URL> micronautResources = access.getApplicationClassLoader().getResources(path);
Expand Down Expand Up @@ -160,7 +155,7 @@ private StaticServiceDefinitions buildStaticServiceDefinitions(BeforeAnalysisAcc
servicePath,
serviceTypePath -> {
if (Files.isRegularFile(serviceTypePath)) {
final Set<String> serviceTypeNames = staticServiceDefinitions.serviceTypeMap
final Set<String> serviceTypeNames = staticServiceDefinitions.serviceTypeMap()
.computeIfAbsent(servicePath,
key -> new HashSet<>());
final String serviceTypeName = serviceTypePath.getFileName().toString();
Expand Down Expand Up @@ -215,24 +210,4 @@ public void register(Constructor<?>... constructors) {
}
}

@Internal
final class StaticServiceDefinitions {
final Map<String, Set<String>> serviceTypeMap = new HashMap<>();
}

@SuppressWarnings("unused")
@TargetClass(className = "io.micronaut.core.io.service.ServiceScanner")
@Internal
final class ServiceLoaderInitialization {
private ServiceLoaderInitialization() {
}

@Substitute
private static Set<String> computeMicronautServiceTypeNames(URI uri, String path) {
final StaticServiceDefinitions ssd = ImageSingletons.lookup(StaticServiceDefinitions.class);
return ssd.serviceTypeMap.getOrDefault(
path,
Collections.emptySet()
);
}
}
Loading

0 comments on commit 4398d51

Please sign in to comment.