Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gluon-bot committed Oct 12, 2023
2 parents b1c390e + 5e8f38e commit 048b8db
Show file tree
Hide file tree
Showing 13 changed files with 240 additions and 242 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
37 changes: 28 additions & 9 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 @@ -221,6 +216,27 @@ def vm_executable_path(executable, config=None):
return join(_vm_home(config), 'bin', executable)


def _escape_for_args_file(arg):
if not (arg.startswith('\\Q') and arg.endswith('\\E')):
arg = arg.replace('\\', '\\\\')
if ' ' in arg:
arg = '\"' + arg + '\"'
return arg


def _maybe_convert_to_args_file(args):
total_command_line_args_length = sum([len(arg) for arg in args])
if total_command_line_args_length < 80:
# Do not use argument file when total command line length is reasonable,
# so that both code paths are exercised on all platforms
return args
else:
# Use argument file to avoid exceeding the command line length limit on Windows
with tempfile.NamedTemporaryFile(delete=False, mode='w', prefix='ni_args_', suffix='.args') as args_file:
args_file.write('\n'.join([_escape_for_args_file(a) for a in args]))
return ['@' + args_file.name]


@contextmanager
def native_image_context(common_args=None, hosted_assertions=True, native_image_cmd='', config=None, build_if_missing=False):
common_args = [] if common_args is None else common_args
Expand Down Expand Up @@ -251,7 +267,7 @@ def native_image_context(common_args=None, hosted_assertions=True, native_image_
raise mx.abort('The built GraalVM for config ' + str(config) + ' does not contain a native-image command')

def _native_image(args, **kwargs):
mx.run([native_image_cmd] + args, **kwargs)
mx.run([native_image_cmd] + _maybe_convert_to_args_file(args), **kwargs)

def is_launcher(launcher_path):
with open(launcher_path, 'rb') as fp:
Expand Down Expand Up @@ -1013,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 @@ -1055,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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@
import static org.graalvm.compiler.nodes.extended.BranchProbabilityNode.NOT_FREQUENT_PROBABILITY;
import static org.graalvm.compiler.nodes.extended.BranchProbabilityNode.probability;

import java.util.concurrent.locks.ReentrantLock;

import org.graalvm.nativeimage.IsolateThread;

import com.oracle.svm.core.Uninterruptible;
import com.oracle.svm.core.jfr.JfrTicks;
import com.oracle.svm.core.jfr.SubstrateJVM;
import com.oracle.svm.core.jfr.events.JavaMonitorEnterEvent;
import com.oracle.svm.core.thread.JavaThreads;
import com.oracle.svm.core.util.BasedOnJDKClass;
import com.oracle.svm.core.util.VMError;

import jdk.internal.misc.Unsafe;
Expand All @@ -55,6 +58,8 @@
* to store the number of lock acquisitions, enabling various optimizations.</li>
* </ul>
*/
@BasedOnJDKClass(ReentrantLock.class)
@BasedOnJDKClass(value = ReentrantLock.class, innerClass = "Sync")
public class JavaMonitor extends JavaMonitorQueuedSynchronizer {
protected long latestJfrTid;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (c) 2023, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.core.util;

import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.function.Function;

import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;

import com.oracle.svm.core.annotate.TargetClass;

/**
* Documents that the class is based on a JDK class without {@linkplain TargetClass substituting}
* it.
*/
@Repeatable(BasedOnJDKClass.List.class)
@Retention(RetentionPolicy.RUNTIME)
@Target(value = {ElementType.TYPE})
@Platforms(Platform.HOSTED_ONLY.class)
public @interface BasedOnJDKClass {

/**
* @see TargetClass#value()
*/
Class<?> value() default BasedOnJDKClass.class;

/**
* @see TargetClass#className()
*/
String className() default "";

/**
* @see TargetClass#classNameProvider()
*/
Class<? extends Function<BasedOnJDKClass, String>> classNameProvider() default BasedOnJDKClass.NoClassNameProvider.class;

/**
* @see TargetClass#innerClass()
*/
String[] innerClass() default {};

interface NoClassNameProvider extends Function<BasedOnJDKClass, String> {
}

/**
* Support for making {@link BasedOnJDKClass} {@linkplain Repeatable repeatable}.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(value = {ElementType.TYPE})
@Platforms(Platform.HOSTED_ONLY.class)
@interface List {
BasedOnJDKClass[] value();
}
}
Loading

0 comments on commit 048b8db

Please sign in to comment.