Skip to content

Commit

Permalink
[GR-48354] Consolidate application module name detection.
Browse files Browse the repository at this point in the history
PullRequest: graal/15468
  • Loading branch information
olpaw committed Oct 12, 2023
2 parents eefd4e9 + 5f35fca commit 5e8f38e
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 226 deletions.
8 changes: 4 additions & 4 deletions java-benchmarks/mx.java-benchmarks/mx_java_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,11 @@ def extra_image_build_argument(self, benchmark, args):
'-J--add-exports=org.graalvm.nativeimage/org.graalvm.nativeimage.impl=ALL-UNNAMED',
'-J--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk=ALL-UNNAMED',
'--exclude-config' ,
'io\.netty\.netty-codec',
'/META-INF/native-image/io\.netty/netty-codec/generated/handlers/reflect-config\.json',
'io\\.netty\\.netty-codec',
'/META-INF/native-image/io\\.netty/netty-codec/generated/handlers/reflect-config\\.json',
'--exclude-config',
'io\.netty\.netty-handler',
'/META-INF/native-image/io\.netty/netty-handler/generated/handlers/reflect-config\.json',
'io\\.netty\\.netty-handler',
'/META-INF/native-image/io\\.netty/netty-handler/generated/handlers/reflect-config\\.json',
'-H:-AddAllCharsets',
'-H:+ReportExceptionStackTraces',
] + mx_sdk_vm_impl.svm_experimental_options([
Expand Down
1 change: 1 addition & 0 deletions substratevm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This changelog summarizes major changes to GraalVM Native Image.
* (GR-48304) Red Hat added support for the JFR event ThreadAllocationStatistics.
* (GR-48343) Red Hat added support for the JFR events AllocationRequiringGC and SystemGC.
* (GR-48612) Enable `--strict-image-heap` by default. The option is now deprecated and can be removed from your argument list. A blog post with more information will follow shortly.
* (GR-48354) Remove native-image-agent legacy `build`-option

## GraalVM for JDK 21 (Internal Version 23.1.0)
* (GR-35746) Lower the default aligned chunk size from 1 MB to 512 KB for the serial and epsilon GCs, reducing memory usage and image size in many cases.
Expand Down
14 changes: 6 additions & 8 deletions substratevm/mx.substratevm/mx_substratevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
# questions.
#

from __future__ import print_function

import os
import re
import tempfile
Expand All @@ -35,6 +33,7 @@
from argparse import ArgumentParser
import fnmatch
import collections
from io import StringIO

import mx
import mx_compiler
Expand All @@ -53,10 +52,6 @@
import sys


if sys.version_info[0] < 3:
from StringIO import StringIO
else:
from io import StringIO

suite = mx.suite('substratevm')
svmSuites = [suite]
Expand Down Expand Up @@ -1034,7 +1029,10 @@ def _native_image_launcher_extra_jvm_args():
'--features=com.oracle.svm.driver.APIOptionFeature',
'--initialize-at-build-time=com.oracle.svm.driver',
'--link-at-build-time=com.oracle.svm.driver,com.oracle.svm.driver.metainf',
] + svm_experimental_options([
]

driver_exe_build_args = driver_build_args + svm_experimental_options([
'-H:+AllowJRTFileSystem',
'-H:IncludeResources=com/oracle/svm/driver/launcher/.*',
'-H:-ParseRuntimeOptions',
f'-R:MaxHeapSize={256 * 1024 * 1024}',
Expand Down Expand Up @@ -1076,7 +1074,7 @@ def _native_image_launcher_extra_jvm_args():
destination="bin/<exe:native-image>",
jar_distributions=["substratevm:SVM_DRIVER"],
main_class=_native_image_launcher_main_class(),
build_args=driver_build_args,
build_args=driver_exe_build_args,
extra_jvm_args=_native_image_launcher_extra_jvm_args(),
home_finder=False,
),
Expand Down
5 changes: 5 additions & 0 deletions substratevm/mx.substratevm/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,11 @@
"requires" : [
"jdk.management",
],
"requiresConcealed" : {
"java.base" : [
"jdk.internal.jimage",
],
},
"checkstyle": "com.oracle.svm.hosted",
"workingSets": "SVM",
"annotationProcessors": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.ConcurrentModificationException;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -76,12 +75,10 @@
import com.oracle.svm.configure.filters.HierarchyFilterNode;
import com.oracle.svm.configure.trace.AccessAdvisor;
import com.oracle.svm.configure.trace.TraceProcessor;
import com.oracle.svm.core.SubstrateUtil;
import com.oracle.svm.core.configure.ConfigurationFile;
import com.oracle.svm.core.jni.headers.JNIEnvironment;
import com.oracle.svm.core.jni.headers.JNIJavaVM;
import com.oracle.svm.core.jni.headers.JNIObjectHandle;
import com.oracle.svm.driver.NativeImage;
import com.oracle.svm.driver.metainf.NativeImageMetaInfWalker;
import com.oracle.svm.jvmtiagentbase.JNIHandleSet;
import com.oracle.svm.jvmtiagentbase.JvmtiAgentBase;
Expand Down Expand Up @@ -143,7 +140,6 @@ protected int onLoadCallback(JNIJavaVM vm, JvmtiEnv jvmti, JvmtiEventCallbacks c
boolean experimentalClassDefineSupport = false;
boolean experimentalUnsafeAllocationSupport = false;
boolean experimentalOmitClasspathConfig = false;
boolean build = false;
boolean configurationWithOrigins = false;
List<String> conditionalConfigUserPackageFilterFiles = new ArrayList<>();
List<String> conditionalConfigClassNameFilterFiles = new ArrayList<>();
Expand Down Expand Up @@ -206,8 +202,6 @@ protected int onLoadCallback(JNIJavaVM vm, JvmtiEnv jvmti, JvmtiEventCallbacks c
if (configWritePeriodInitialDelay < 0) {
return usage(1, "config-write-initial-delay-secs must be an integer greater or equal to 0");
}
} else if (isBooleanOption(token, "build")) {
build = getBooleanTokenValue(token);
} else if (isBooleanOption(token, "experimental-configuration-with-origins")) {
configurationWithOrigins = getBooleanTokenValue(token);
} else if (token.startsWith("experimental-conditional-config-filter-file=")) {
Expand All @@ -223,9 +217,9 @@ protected int onLoadCallback(JNIJavaVM vm, JvmtiEnv jvmti, JvmtiEventCallbacks c
}
}

if (traceOutputFile == null && configOutputDir == null && !build) {
if (traceOutputFile == null && configOutputDir == null) {
configOutputDir = transformPath(AGENT_NAME + "_config-pid{pid}-{datetime}/");
inform("no output/build options provided, tracking dynamic accesses and writing configuration to directory: " + configOutputDir);
inform("no output options provided, tracking dynamic accesses and writing configuration to directory: " + configOutputDir);
}

if (configurationWithOrigins && !conditionalConfigUserPackageFilterFiles.isEmpty()) {
Expand Down Expand Up @@ -377,14 +371,6 @@ protected int onLoadCallback(JNIJavaVM vm, JvmtiEnv jvmti, JvmtiEventCallbacks c
}
}

if (build) {
int status = buildImage(jvmti);
if (status == 0) {
System.exit(status);
}
return status;
}

try {
BreakpointInterceptor.onLoad(jvmti, callbacks, tracer, this, interceptedStateSupplier,
experimentalClassLoaderSupport, experimentalClassDefineSupport, experimentalUnsafeAllocationSupport, trackReflectionMetadata);
Expand Down Expand Up @@ -504,46 +490,6 @@ private static void ignoreConfigFromClasspath(JvmtiEnv jvmti, ConfigurationFileC
private static final Pattern propertyBlacklist = Pattern.compile("(java\\..*)|(sun\\..*)|(jvmci\\..*)");
private static final Pattern propertyWhitelist = Pattern.compile("(java\\.library\\.path)|(java\\.io\\.tmpdir)");

private static int buildImage(JvmtiEnv jvmti) {
System.out.println("Building native image ...");
String classpath = Support.getSystemProperty(jvmti, "java.class.path");
if (classpath == null) {
return usage(1, "Build mode could not determine classpath.");
}
String javaCommand = Support.getSystemProperty(jvmti, "sun.java.command");
String mainClassMissing = "Build mode could not determine main class.";
if (javaCommand == null) {
return usage(1, mainClassMissing);
}
String mainClass = SubstrateUtil.split(javaCommand, " ")[0];
if (mainClass.isEmpty()) {
return usage(1, mainClassMissing);
}
List<String> buildArgs = new ArrayList<>();
// buildArgs.add("--verbose");
String[] keys = Support.getSystemProperties(jvmti);
for (String key : keys) {
boolean whitelisted = propertyWhitelist.matcher(key).matches();
boolean blacklisted = !whitelisted && propertyBlacklist.matcher(key).matches();
if (blacklisted) {
continue;
}
buildArgs.add("-D" + key + "=" + Support.getSystemProperty(jvmti, key));
}
if (mainClass.toLowerCase().endsWith(".jar")) {
buildArgs.add("-jar");
} else {
buildArgs.addAll(Arrays.asList("-cp", classpath));
}
buildArgs.add(mainClass);
buildArgs.add(AGENT_NAME + ".build");
// System.out.println(String.join("\n", buildArgs));
Path javaHome = Paths.get(Support.getSystemProperty(jvmti, "java.home"));
String userDirStr = Support.getSystemProperty(jvmti, "user.dir");
NativeImage.agentBuild(javaHome, userDirStr == null ? null : Paths.get(userDirStr), buildArgs);
return 0;
}

private static String transformPath(String path) {
String result = path;
if (result.contains("{pid}")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,10 @@ protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, String ol
};

@Option(help = "Builds a statically linked executable with libc dynamically linked", type = Expert, stability = OptionStability.EXPERIMENTAL)//
public static final HostedOptionKey<Boolean> StaticExecutableWithDynamicLibC = new HostedOptionKey<>(false) {
@Override
protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Boolean oldValue, Boolean newValue) {
StaticExecutable.update(values, true);
super.onValueUpdate(values, oldValue, newValue);
}
};
public static final HostedOptionKey<Boolean> StaticExecutableWithDynamicLibC = new HostedOptionKey<>(false);

@Option(help = "Builds image with libstdc++ statically linked into the image (if needed)", type = Expert, stability = OptionStability.EXPERIMENTAL)//
public static final HostedOptionKey<Boolean> StaticLibStdCpp = new HostedOptionKey<>(false);

public static final int ForceFallback = 10;
public static final int Automatic = 5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.ByteBuffer;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -115,7 +116,7 @@ final class Target_jdk_internal_module_SystemModuleFinders_SystemImage_JRTEnable
static volatile Target_jdk_internal_jimage_ImageReader_JRTEnabled READER;

@Substitute
static Object reader() {
static Target_jdk_internal_jimage_ImageReader_JRTEnabled reader() {
Target_jdk_internal_jimage_ImageReader_JRTEnabled localRef = READER;
if (localRef == null) {
synchronized (Target_jdk_internal_module_SystemModuleFinders_SystemImage_JRTEnabled.class) {
Expand Down Expand Up @@ -178,3 +179,22 @@ final class Target_jdk_internal_jrtfs_JrtFileSystemProvider_JRTDisabled {
}

// endregion Disable jimage/jrtfs

@TargetClass(className = "jdk.internal.jimage.BasicImageReader")
final class Target_jdk_internal_jimage_BasicImageReader {
/* Ensure NativeImageBuffer never gets used as part of using BasicImageReader */
@Alias //
@RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias, isFinal = true) //
// Checkstyle: stop
static boolean USE_JVM_MAP = false;
// Checkstyle: resume
}

@TargetClass(className = "jdk.internal.jimage.NativeImageBuffer")
@Substitute
final class Target_jdk_internal_jimage_NativeImageBuffer {
@Substitute
static ByteBuffer getNativeMap(String imagePath) {
throw VMError.unsupportedFeature("Using jdk.internal.jimage.NativeImageBuffer is not supported");
}
}
Loading

0 comments on commit 5e8f38e

Please sign in to comment.