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 Sep 3, 2023
2 parents 3f5fd41 + 3944f9e commit d5f8078
Show file tree
Hide file tree
Showing 66 changed files with 1,292 additions and 221 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@
import org.graalvm.compiler.core.GraalCompilerOptions;
import org.graalvm.compiler.core.common.util.Util;
import org.graalvm.compiler.debug.Assertions;
import org.graalvm.compiler.hotspot.CommunityCompilerConfigurationFactory;
import org.graalvm.compiler.hotspot.CompilerConfigurationFactory;
import org.graalvm.compiler.hotspot.EconomyCompilerConfigurationFactory;
import org.graalvm.compiler.nodes.Cancellable;
import org.graalvm.compiler.options.OptionDescriptor;
import org.graalvm.compiler.options.OptionDescriptors;
import org.graalvm.compiler.options.OptionKey;
import org.graalvm.compiler.options.OptionStability;
import org.graalvm.compiler.options.OptionValues;
import org.graalvm.compiler.options.OptionsParser;
import org.graalvm.compiler.test.SubprocessUtil;
Expand Down Expand Up @@ -206,6 +210,14 @@ private List<String> filterGraalCompilerClasses(List<String> loadedGraalClassNam
}
}

// classes needed to find out whether enterprise is installed in the JDK
allowList.add(OptionStability.class);
allowList.add(CompilerConfigurationFactory.class);
allowList.add(CompilerConfigurationFactory.Options.class);
allowList.add(CompilerConfigurationFactory.ShowConfigurationLevel.class);
allowList.add(EconomyCompilerConfigurationFactory.class);
allowList.add(CommunityCompilerConfigurationFactory.class);

allowList.add(Cancellable.class);

List<String> forbiddenClasses = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@
*/
public abstract class CompilerConfigurationFactory implements Comparable<CompilerConfigurationFactory> {

enum ShowConfigurationLevel {
public enum ShowConfigurationLevel {
none,
info,
verbose
}

static class Options {
public static class Options {
// @formatter:off
@Option(help = "Names the compiler configuration to use. If omitted, the compiler configuration " +
"with the highest auto-selection priority is used. To see the set of available configurations, " +
Expand Down
39 changes: 39 additions & 0 deletions sdk/mx.sdk/mx_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import mx_gate
import mx_sdk_vm
import mx_sdk_vm_impl
import pathlib
import mx_sdk_benchmark # pylint: disable=unused-import
import mx_sdk_clangformat # pylint: disable=unused-import
import datetime
Expand Down Expand Up @@ -270,3 +271,41 @@ def description(self):
return "GraalVM JDK"

mx.addJDKFactory('graalvm', mx.get_jdk(tag='default').javaCompliance, GraalVMJDK())


def maven_deploy_public_repo_dir():
return os.path.join(_suite.get_mx_output_dir(), 'public-maven-repo')

@mx.command(_suite.name, 'maven-deploy-public')
def maven_deploy_public(args, licenses=None, deploy_snapshots=True):
"""Helper to simplify deploying all public Maven dependendencies into the mxbuild directory"""
if deploy_snapshots:
artifact_version = f'{mx_sdk_vm_impl.graalvm_version("graalvm")}-SNAPSHOT'
else:
artifact_version = f'{mx_sdk_vm_impl.graalvm_version("graalvm")}'
path = maven_deploy_public_repo_dir()
mx.rmtree(path, ignore_errors=True)
os.mkdir(path)

if not licenses:
# default licenses used
licenses = ['GFTC', 'EPL-2.0', 'PSF-License', 'GPLv2-CPE', 'ICU,GPLv2', 'BSD-simplified', 'BSD-new', 'UPL', 'MIT']

deploy_args = [
'--tags=public',
'--all-suites',
'--all-distribution-types',
f'--version-string={artifact_version}',
'--validate=full',
'--licenses', ','.join(licenses),
'local',
pathlib.Path(path).as_uri(),
]
if mx.get_jdk().javaCompliance > '17':
mx.warn("Javadoc won't be deployed as a JDK > 17 is not yet compatible with javadoc doclets. In order to deploy javadoc use a JDK 17 as a JDK on JAVA_HOME.")
deploy_args += ["--suppress-javadoc"]

mx.log(f'mx maven-deploy {" ".join(deploy_args)}')
mx.maven_deploy(deploy_args)
mx.log(f'Deployed Maven artefacts to {path}')
return path
3 changes: 2 additions & 1 deletion sdk/mx.sdk/mx_sdk_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def __init__(self, destination, jar_distributions, build_args, jvm_library=False


class LanguageLibraryConfig(LibraryConfig):
def __init__(self, jar_distributions, build_args, language, main_class=None, is_sdk_launcher=True, launchers=None, option_vars=None, default_vm_args=None, headers=False, set_default_relative_home_path=True, **kwargs):
def __init__(self, jar_distributions, build_args, language, main_class=None, is_sdk_launcher=True, launchers=None, option_vars=None, default_vm_args=None, headers=False, set_default_relative_home_path=True, isolate_library_layout_distribution=None, **kwargs):
"""
:param str language
:param str main_class
Expand All @@ -219,6 +219,7 @@ def __init__(self, jar_distributions, build_args, language, main_class=None, is_
if set_default_relative_home_path:
# Ensure the language launcher can always find the language home
self.add_relative_home_path(language, relpath('.', dirname(self.destination)))
self.isolate_library_layout_distribution = isolate_library_layout_distribution

class GraalVmComponent(object):
def __init__(self,
Expand Down
38 changes: 31 additions & 7 deletions sdk/mx.sdk/mx_sdk_vm_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2816,7 +2816,7 @@ def add_files_from_component(comp, is_main, path_prefix, excluded_paths, force_m
'path': None,
})

assert not self.is_jvm or not is_main or len(launcher_configs) == 0, "JVM standalones do not yet support main components with launcher configs, only thin launchers. Found: '{}'".format(name)
assert not self.is_jvm or not is_main or all(type(lc) == mx_sdk.LauncherConfig for lc in launcher_configs), "JVM standalones do not yet support main components with language launcher configs, only thin launchers and plain NI launchers. Found: '{}'".format(name) # pylint: disable=unidiomatic-typecheck
for launcher_config in launcher_configs:
launcher_dest = path_prefix + launcher_config.destination
if launcher_config.destination not in excluded_paths:
Expand Down Expand Up @@ -3485,6 +3485,7 @@ def mx_register_dynamic_suite_constituents(register_project, register_distributi
else:
with_non_rebuildable_configs = True
for library_config in _get_library_configs(component):
library_project = None
if with_svm:
library_project = GraalVmLibrary(component, GraalVmNativeImage.project_name(library_config), [], library_config)
register_project(library_project)
Expand All @@ -3496,11 +3497,34 @@ def mx_register_dynamic_suite_constituents(register_project, register_distributi
jmod_file = library_config.add_to_module + ('' if library_config.add_to_module.endswith('.jmod') else '.jmod')
modified_jmods.setdefault(jmod_file, []).append(library_project)
needs_stage1 = True # library configs need a stage1 even when they are skipped
if isinstance(library_config, mx_sdk.LanguageLibraryConfig) and library_config.launchers:
launcher_project = NativeLibraryLauncherProject(component, library_config)
register_project(launcher_project)
polyglot_config_project = PolyglotConfig(component, library_config)
register_project(polyglot_config_project)
if isinstance(library_config, mx_sdk.LanguageLibraryConfig):
if library_config.launchers:
launcher_project = NativeLibraryLauncherProject(component, library_config)
register_project(launcher_project)
polyglot_config_project = PolyglotConfig(component, library_config)
register_project(polyglot_config_project)
if with_svm and library_config.isolate_library_layout_distribution and not library_project.is_skipped() and has_component('tfle', stage1=True):
# Create a layout distribution with the resulting language library that can be consumed into the
# isolate resources jar distribution,
resource_base_folder = f'META-INF/resources/engine/{library_config.language}-isolate/<os>/<arch>/libvm'
attrs = {
'description': f'Contains {library_config.language} language library resources',
'hashEntry': f'{resource_base_folder}/sha256',
'fileListEntry': f'{resource_base_folder}/files',
'maven': False,
}
register_distribution(mx.LayoutDirDistribution(
suite=_suite,
name=library_config.isolate_library_layout_distribution,
deps=[],
layout={
f'{resource_base_folder}/': f'dependency:{library_project.name}'
},
path=None,
platformDependent=True,
theLicense=None,
**attrs
))
if isinstance(component, mx_sdk.GraalVmLanguage) and component.support_distributions:
ni_resources_components = dir_name_to_ni_resources_components.get(component.dir_name)
if not ni_resources_components:
Expand Down Expand Up @@ -3560,7 +3584,7 @@ def mx_register_dynamic_suite_constituents(register_project, register_distributi
mx.warn("Skipping standalone of '{}' because the following components are excluded:\n * {}".format(main_component.name, '\n * '.join(missing_dependency_names)))
else:
# JVM standalones
if len(main_component.launcher_configs):
if any(type(lc) != mx_sdk.LauncherConfig for lc in main_component.launcher_configs): # pylint: disable=unidiomatic-typecheck
if mx.get_opts().verbose:
mx.warn("Skipping JVM standalone of '{}' because it contains launcher configs that are not yet supported".format(main_component.name))
else:
Expand Down
50 changes: 43 additions & 7 deletions sdk/src/org.graalvm.polyglot/src/org/graalvm/polyglot/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,11 @@ private static AbstractPolyglotImpl loadAndValidateProviders(Iterator<? extends
Collections.sort(impls, Comparator.comparing(AbstractPolyglotImpl::getPriority));
AbstractPolyglotImpl prev = null;
for (AbstractPolyglotImpl impl : impls) {
if (impl.getPriority() == Integer.MIN_VALUE) {
// disabled
continue;
}

impl.setNext(prev);
try {
impl.setConstructors(APIAccessImpl.INSTANCE);
Expand Down Expand Up @@ -1703,6 +1708,9 @@ private Iterator<? extends AbstractPolyglotImpl> searchServiceLoader() throws In
private static class ClassPathIsolation {

private static final String TRUFFLE_MODULE_NAME = "org.graalvm.truffle";
private static final String TRUFFLE_RUNTIME_MODULE_NAME = "org.graalvm.truffle.runtime";
private static final String JVMCI_MODULE_NAME = "jdk.internal.vm.ci";
private static final String TRUFFLE_ENTERPRISE_MODULE_NAME = "com.oracle.truffle.enterprise";
private static final String POLYGLOT_MODULE_NAME = "org.graalvm.polyglot";
private static final String OPTION_DISABLE_CLASS_PATH_ISOLATION = "polyglotimpl.DisableClassPathIsolation";
private static final String OPTION_TRACE_CLASS_PATH_ISOLATION = "polyglotimpl.TraceClassPathIsolation";
Expand Down Expand Up @@ -1781,7 +1789,6 @@ static Module createIsolatedTruffleModule(Class<?> polyglotClass) {
trace("Class-path entry: %s", p);
}
}

List<Path> relevantPaths = filterClasspath(parent, classpath);
if (relevantPaths == null) {
if (TRACE_CLASS_PATH_ISOLATION) {
Expand Down Expand Up @@ -1864,6 +1871,10 @@ record ParsedModule(Path p, Set<ModuleReference> modules) {
Set<ModuleReference> modules = finder.findAll();
if (modules.size() > 0) {
parsedModules.add(new ParsedModule(path, modules));
} else {
if (TRACE_CLASS_PATH_ISOLATION) {
trace("No modules found in class-path entry %s", path);
}
}
} catch (FindException t) {
// error in module finding -> not a valid module descriptor ignore
Expand Down Expand Up @@ -1897,6 +1908,16 @@ record ParsedModule(Path p, Set<ModuleReference> modules) {
return null;
}

Set<String> excludedModules;
if (ModuleLayer.boot().findModule(JVMCI_MODULE_NAME).isPresent()) {
excludedModules = Set.of();
} else {
/*
* if jdk.internal.vm.ci is not enabled we can't load these modules on the layer.
*/
excludedModules = Set.of(TRUFFLE_RUNTIME_MODULE_NAME, TRUFFLE_ENTERPRISE_MODULE_NAME);
}

// now iteratively resolve modules until no more modules are included
List<ParsedModule> toProcess = new ArrayList<>(parsedModules);
Set<String> usedServices = new HashSet<>();
Expand All @@ -1909,6 +1930,11 @@ record ParsedModule(Path p, Set<ModuleReference> modules) {
ParsedModule module = modules.next();
for (ModuleReference m : module.modules) {
ModuleDescriptor d = m.descriptor();
if (excludedModules.contains(d.name())) {
modules.remove();
continue;
}

for (Provides p : d.provides()) {
if (usedServices.contains(p.service())) {
if (includedModules.add(d.name())) {
Expand All @@ -1922,7 +1948,15 @@ record ParsedModule(Path p, Set<ModuleReference> modules) {
if (includedModules.contains(d.name())) {
usedServices.addAll(d.uses());
for (Requires r : d.requires()) {
if (!r.modifiers().contains(Requires.Modifier.STATIC) && includedModules.add(r.name())) {
/*
* We deliberately follow static resources here, even though they
* are not real dependencies in the module-graph. If we don't follow
* static requires we might fallback to the parent class-loader for
* these classes causing weird problems. So if the module is on the
* class-path and there is a static requires we pick it up into the
* module-graph well.
*/
if (includedModules.add(r.name())) {
if (TRACE_CLASS_PATH_ISOLATION) {
trace("Include module '%s' because it is required by '%s'.", r.name(), d.name());
}
Expand All @@ -1940,6 +1974,9 @@ record ParsedModule(Path p, Set<ModuleReference> modules) {
for (ModuleReference ref : module.modules()) {
String name = ref.descriptor().name();
if (!includedModules.contains(name)) {
if (TRACE_CLASS_PATH_ISOLATION) {
trace("Filter module '%s' because not reachable on the module graph.", name);
}
continue;
}

Expand All @@ -1950,10 +1987,8 @@ record ParsedModule(Path p, Set<ModuleReference> modules) {
continue;
}

if (includedModules.contains(name)) {
filteredList.add(module.p());
break;
}
filteredList.add(module.p());
break;
}
}

Expand Down Expand Up @@ -2008,7 +2043,8 @@ private static class PolyglotInvalid extends AbstractPolyglotImpl {

@Override
public int getPriority() {
return Integer.MIN_VALUE;
// make sure polyglot invalid has lowest priority but is not filtered (hence + 1)
return Integer.MIN_VALUE + 1;
}

@Override
Expand Down
Loading

0 comments on commit d5f8078

Please sign in to comment.