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 11, 2023
2 parents a3f01fd + 24193ac commit b1c390e
Show file tree
Hide file tree
Showing 111 changed files with 1,675 additions and 817 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.graalvm.compiler.nodes.ConstantNode;
import org.graalvm.compiler.nodes.DeadEndNode;
import org.graalvm.compiler.nodes.EndNode;
import org.graalvm.compiler.nodes.FixedNode;
import org.graalvm.compiler.nodes.GuardPhiNode;
import org.graalvm.compiler.nodes.Invoke;
import org.graalvm.compiler.nodes.InvokeNode;
Expand Down Expand Up @@ -67,7 +66,7 @@
import org.graalvm.compiler.nodes.debug.BlackholeNode;
import org.graalvm.compiler.nodes.extended.BoxNode;
import org.graalvm.compiler.nodes.extended.BytecodeExceptionNode;
import org.graalvm.compiler.nodes.extended.ForeignCallNode;
import org.graalvm.compiler.nodes.extended.ForeignCall;
import org.graalvm.compiler.nodes.extended.GetClassNode;
import org.graalvm.compiler.nodes.extended.JavaReadNode;
import org.graalvm.compiler.nodes.extended.JavaWriteNode;
Expand Down Expand Up @@ -104,9 +103,9 @@
import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
import org.graalvm.compiler.replacements.nodes.ArrayEqualsNode;
import org.graalvm.compiler.replacements.nodes.BasicArrayCopyNode;
import org.graalvm.compiler.replacements.nodes.BasicObjectCloneNode;
import org.graalvm.compiler.replacements.nodes.BinaryMathIntrinsicNode;
import org.graalvm.compiler.replacements.nodes.IdentityHashCodeNode;
import org.graalvm.compiler.replacements.nodes.ObjectClone;
import org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode;
import org.graalvm.compiler.word.WordCastNode;

Expand Down Expand Up @@ -270,8 +269,8 @@ protected void dispatch(Node node) {
lower((ArrayEqualsNode) node);
} else if (node instanceof NewMultiArrayNode) {
lower((NewMultiArrayNode) node);
} else if (node instanceof BasicObjectCloneNode) {
lower((BasicObjectCloneNode) node);
} else if (node instanceof ObjectClone) {
lower((ObjectClone) node);
} else if (node instanceof LoadHubNode) {
lower((LoadHubNode) node);
} else if (node instanceof LoadArrayComponentHubNode) {
Expand Down Expand Up @@ -300,8 +299,8 @@ protected void dispatch(Node node) {
lower((DynamicNewArrayNode) node);
} else if (node instanceof ObjectIsArrayNode) {
lower((ObjectIsArrayNode) node);
} else if (node instanceof ForeignCallNode) {
lower((ForeignCallNode) node);
} else if (node instanceof ForeignCall) {
lower((ForeignCall) node);
} else if (node instanceof IntegerDivRemNode) {
lower((IntegerDivRemNode) node);
} else if (node instanceof BinaryArithmeticNode) {
Expand Down Expand Up @@ -384,7 +383,7 @@ protected void handleUnknownNodeType(Node node) {

protected abstract void lower(IntegerDivRemNode node);

protected abstract void lower(ForeignCallNode node);
protected abstract void lower(ForeignCall node);

protected abstract void lower(ObjectIsArrayNode node);

Expand Down Expand Up @@ -414,7 +413,7 @@ protected void handleUnknownNodeType(Node node) {

protected abstract void lower(LoadHubNode node);

protected abstract void lower(BasicObjectCloneNode node);
protected abstract void lower(ObjectClone node);

protected abstract void lower(NewMultiArrayNode node);

Expand Down Expand Up @@ -488,7 +487,7 @@ protected void handleUnknownNodeType(Node node) {

protected abstract void lower(IsNullNode node);

protected abstract <T extends FixedNode & Invoke> void lower(T node);
protected abstract void lower(Invoke node);

protected abstract void lower(UnwindNode node);

Expand Down
50 changes: 30 additions & 20 deletions sdk/mx.sdk/mx_sdk_vm_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2732,9 +2732,9 @@ def get_artifact_metadata(self):


class GraalVmStandaloneComponent(LayoutSuper): # pylint: disable=R0901
def __init__(self, component, graalvm, is_jvm, **kw_args):
def __init__(self, main_component, graalvm, is_jvm, **kw_args):
"""
:param mx_sdk.GraalVmTruffleComponent component
:param mx_sdk.GraalVmTruffleComponent main_component
:param GraalVmLayoutDistribution graalvm
:param bool is_jvm: True for JVM Standalones, False for Native Standalones
"""
Expand All @@ -2747,15 +2747,15 @@ def require_svm(components):

svm_support = _get_svm_support()
self.is_jvm = is_jvm
self.main_comp_dir_name = component.dir_name
self.main_comp_dir_name = main_component.dir_name
self.jvm_modules = []
self.jvm_libs = []
self.pre_extracted_libs = {}
self.native_image_configs = [] # type: List[mx_sdk_vm.AbstractNativeImageConfig]

other_comp_names = []
dependencies = component.standalone_dependencies_enterprise if svm_support.is_ee_supported() else component.standalone_dependencies
self.involved_components = [component] + [get_component(dep) for dep in dependencies]
dependencies = main_component.standalone_dependencies_enterprise if svm_support.is_ee_supported() else main_component.standalone_dependencies
self.involved_components = [main_component] + [get_component(dep) for dep in dependencies]

if svm_support.is_supported():
other_comp_names.append('svm')
Expand All @@ -2766,14 +2766,19 @@ def require_svm(components):

other_comp_names = sorted(other_comp_names)

name = '_'.join([component.installable_id, 'java' if self.is_jvm else 'native', 'standalone'] + other_comp_names + ['java{}'.format(_src_jdk_version)]).upper().replace('-', '_')
dir_name = component.standalone_dir_name_enterprise if svm_support.is_ee_supported() else component.standalone_dir_name
name = '_'.join([main_component.installable_id, 'java' if self.is_jvm else 'native', 'standalone'] + other_comp_names + ['java{}'.format(_src_jdk_version)]).upper().replace('-', '_')
dir_name = main_component.standalone_dir_name_enterprise if svm_support.is_ee_supported() else main_component.standalone_dir_name
self.base_dir_name = graalvm.string_substitutions.substitute(dir_name)
base_dir = './{}/'.format(self.base_dir_name)
default_jvm_modules_dir = base_dir + 'modules/'
default_jvm_libs_dir = base_dir + 'jvmlibs/'
layout = {}

# JVM standalones do not include the native libraries of LanguageLibraryConfig ('thin launchers') of:
# - the main component
# - every other component that defines a language library that overrides (i.e., has the same destination) one of the main component
main_libraries_destinations = [base_dir + library_config.destination for library_config in main_component.library_configs if isinstance(library_config, mx_sdk.LanguageLibraryConfig)]

assert require_svm(self.involved_components), "The '{}' standalone does not require SVM. This has not been tested in a while and might not work as intended. Involved components: '{}'".format(name, [c.name for c in self.involved_components])

# Compute paths from standalone component launchers to other homes
Expand Down Expand Up @@ -2804,12 +2809,11 @@ def add_jars_from_component(comp):
})
component_list.append(jar_dist)

def add_files_from_component(comp, is_main, path_prefix, excluded_paths):
def add_files_from_component(comp, path_prefix, excluded_paths):
"""
Add to the layout relevant files of a component.
:type comp: mx_sdk_vm.GraalVmComponent
:type is_main: bool
:type path_prefix: str
:type excluded_paths: list[str]
"""
Expand Down Expand Up @@ -2837,7 +2841,9 @@ def add_files_from_component(comp, is_main, path_prefix, excluded_paths):
'path': None,
})

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
if self.is_jvm and launcher_configs and any(type(lc) != mx_sdk.LauncherConfig for lc in launcher_configs): # pylint: disable=unidiomatic-typecheck
mx.abort("JVM standalones do not yet support components with language launcher configs, only thin launchers and plain NI launchers. Found: '{}' with '{}'".format(name, [lc for lc in launcher_configs if type(lc) != mx_sdk.LauncherConfig])) # 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 @@ -2882,8 +2888,9 @@ def add_files_from_component(comp, is_main, path_prefix, excluded_paths):

for library_config in library_configs:
library_dest = path_prefix + library_config.destination
is_main_library_config = library_dest in main_libraries_destinations
if library_config.destination not in excluded_paths:
if self.is_jvm and is_main:
if self.is_jvm and is_main_library_config:
if not isinstance(library_config, mx_sdk.LanguageLibraryConfig):
mx.warn("Component '{}' declares '{}' as 'library_config', which is ignored by the build process of the '{}' jvm standalone".format(comp.name, library_config, name))
else:
Expand All @@ -2907,11 +2914,11 @@ def add_files_from_component(comp, is_main, path_prefix, excluded_paths):
for executable in library_config.launchers:
layout.setdefault(path_prefix + executable, []).append({
'source_type': 'dependency',
'dependency': NativeLibraryLauncherProject.library_launcher_project_name(library_config, for_jvm_standalone=is_main and self.is_jvm),
'dependency': NativeLibraryLauncherProject.library_launcher_project_name(library_config, for_jvm_standalone=self.is_jvm and is_main_library_config),
'exclude': excluded_paths,
'path': None,
})
if is_main:
if is_main_library_config: # should probably be: `if self.is_jvm && is_main_library_config`
for jar_distribution in [j for j in library_config.jar_distributions if j not in self.jvm_modules]:
layout.setdefault(default_jvm_modules_dir, []).append({
'source_type': 'dependency',
Expand Down Expand Up @@ -2948,14 +2955,14 @@ def add_files_from_component(comp, is_main, path_prefix, excluded_paths):
assert dependency not in added_components
excluded_paths = [mx_subst.path_substitutions.substitute(excluded) for excluded in excluded_paths]
dependency_path_prefix = base_dir + ((dependency_path + '/') if dependency_path else '')
add_files_from_component(dependency, is_main=False, path_prefix=dependency_path_prefix, excluded_paths=excluded_paths)
add_files_from_component(dependency, path_prefix=dependency_path_prefix, excluded_paths=excluded_paths)
added_components.append(dependency)

# Add files from the main standalone component.
# Must be done for both Native and JVM Standalones.
assert component not in added_components
add_files_from_component(component, is_main=True, path_prefix=base_dir, excluded_paths=[])
added_components.append(component)
assert main_component not in added_components
add_files_from_component(main_component, path_prefix=base_dir, excluded_paths=[])
added_components.append(main_component)

# Add the `release` file.
sorted_suites = sorted(mx.suites(), key=lambda s: s.name)
Expand All @@ -2976,7 +2983,7 @@ def add_files_from_component(comp, is_main, path_prefix, excluded_paths):
# named) `_add_dependency()` function that computes the transitive dependencies of the main component, but
# they are excluded individually later on.
excluded_components = GraalVmStandaloneComponent.default_jvm_components() + GraalVmStandaloneComponent.default_module_components()
main_component_dependencies = GraalVmLayoutDistribution._add_dependencies([component], excluded_components)
main_component_dependencies = GraalVmLayoutDistribution._add_dependencies([main_component], excluded_components)
for main_component_dependency in main_component_dependencies:
if main_component_dependency not in added_components:
add_jars_from_component(main_component_dependency)
Expand Down Expand Up @@ -3038,7 +3045,7 @@ def add_files_from_component(comp, is_main, path_prefix, excluded_paths):
# component.
tool_component_dependencies = GraalVmLayoutDistribution._add_dependencies([tool], excluded_components + added_components)
for tool_component_dependency in tool_component_dependencies:
add_files_from_component(tool_component_dependency, is_main=False, path_prefix=default_jvm_modules_dir, excluded_paths=['native-image.properties'])
add_files_from_component(tool_component_dependency, path_prefix=default_jvm_modules_dir, excluded_paths=['native-image.properties'])
added_components.append(tool_component_dependency)

# `jvmci_parent_jars` and `boot_jars` of these components are added as modules of `java-standalone-jimage`.
Expand Down Expand Up @@ -3662,7 +3669,10 @@ def register_main_dist(dist, label):
java_standalone = GraalVmStandaloneComponent(get_component(main_component.name, fatalIfMissing=True), _final_graalvm_distribution, is_jvm=True, defaultBuild=False)
register_main_dist(java_standalone, 'graalvm_standalones')

for library_config in _get_library_configs(main_component):
# Use `main_component.library_configs` rather than `_get_library_configs(main_component)` because we
# need to create a `NativeLibraryLauncherProject` for the JVM standalone even when one of the
# libraries of the main component is overridden by another component.
for library_config in main_component.library_configs:
if isinstance(library_config, mx_sdk.LanguageLibraryConfig) and library_config.launchers:
# Register dedicated NativeLibraryLauncherProject for JVM Standalones, which can find the JVM
jvm_standalone_launcher_project = NativeLibraryLauncherProject(main_component, library_config, jvm_standalone=java_standalone, defaultBuild=False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@
import static java.nio.file.StandardOpenOption.WRITE;

import java.io.BufferedOutputStream;
import java.io.Console;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.channels.FileChannel;
import java.nio.channels.OverlappingFileLockException;
import java.nio.file.AccessDeniedException;
Expand Down Expand Up @@ -974,13 +977,44 @@ private String wrap(String s, String indent) {
return builder.toString();
}

private static final Method IS_TERMINAL_METHOD = getIsTerminalMethod();

private static Method getIsTerminalMethod() {
try {
return Console.class.getMethod("isTerminal");
} catch (NoSuchMethodException e) {
return null;
}
}

/**
* Returns true if stdin and stdout are both TTY, false otherwise.
*
* @since 24.0
*/
protected static boolean isTTY() {
Console console = System.console();
if (console == null) {
return false;
}
if (IS_TERMINAL_METHOD != null) {
try {
return (boolean) IS_TERMINAL_METHOD.invoke(console);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new Error(e);
}
} else {
return true;
}
}

private static final int FALLBACK_TERMINAL_WIDTH = 120;
private int terminalWidth = -1;

int getTerminalWidth() {
if (terminalWidth == -1) {
int width;
if (System.console() != null) {
if (isTTY()) {
try (Terminal terminal = createSystemTerminal()) {
width = terminal.getWidth();
} catch (IOException exception) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
*
* Subject to the condition set forth below, permission is hereby granted to any
* person obtaining a copy of this software, associated documentation and/or
* data (collectively the "Software"), free of charge and under any and all
* copyright rights in the Software, and any and all patent rights owned or
* freely licensable by each licensor hereunder covering either (i) the
* unmodified Software as contributed to or provided by such licensor, or (ii)
* the Larger Works (as defined below), to deal in both
*
* (a) the Software, and
*
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
* one is included with the Software each a "Larger Work" to which the Software
* is contributed by such licensors),
*
* without restriction, including without limitation the rights to copy, create
* derivative works of, display, perform, and distribute the Software and make,
* use, sell, offer for sale, import, export, have made, and have sold the
* Software and the Larger Work(s), and to sublicense the foregoing rights on
* either these or other terms.
*
* This license is subject to the following condition:
*
* The above copyright notice and either this complete permission notice or at a
* minimum a reference to the UPL must be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.graalvm.nativebridge.processor.test.overload;

import org.graalvm.nativebridge.processor.test.Service;

import java.time.Duration;

public interface CollidingOverload {

void colliding(Duration duration);

void colliding(Duration[] duration);

void byReferenceColliding(Service service);

void byReferenceColliding(NonCollidingOverload service);
}
Loading

0 comments on commit b1c390e

Please sign in to comment.