Skip to content

Commit

Permalink
8304265: Implementation of Foreign Function and Memory API (Third Pre…
Browse files Browse the repository at this point in the history
…view)

Co-authored-by: Maurizio Cimadamore <mcimadamore@openjdk.org>
Co-authored-by: Jorn Vernee <jvernee@openjdk.org>
Co-authored-by: Paul Sandoz <psandoz@openjdk.org>
Co-authored-by: Feilong Jiang <fjiang@openjdk.org>
Co-authored-by: Per Minborg <pminborg@openjdk.org>
Reviewed-by: erikj, jvernee, vlivanov, psandoz
  • Loading branch information
5 people committed Apr 27, 2023
1 parent 41d5853 commit cbccc4c
Show file tree
Hide file tree
Showing 267 changed files with 6,924 additions and 8,006 deletions.
4 changes: 4 additions & 0 deletions make/autoconf/configure.ac
Expand Up @@ -223,6 +223,10 @@ JDKOPT_SETUP_UNDEFINED_BEHAVIOR_SANITIZER
# LeakSanitizer
JDKOPT_SETUP_LEAK_SANITIZER

# Fallback linker
# This needs to go before 'LIB_DETERMINE_DEPENDENCIES'
JDKOPT_SETUP_FALLBACK_LINKER

###############################################################################
#
# Check dependencies for external and internal libraries.
Expand Down
19 changes: 19 additions & 0 deletions make/autoconf/jdk-options.m4
Expand Up @@ -903,3 +903,22 @@ AC_DEFUN([JDKOPT_SETUP_MACOSX_SIGNING],
AC_SUBST(MACOSX_CODESIGN_MODE)
fi
])

################################################################################
#
# fallback linker
#
AC_DEFUN_ONCE([JDKOPT_SETUP_FALLBACK_LINKER],
[
FALLBACK_LINKER_DEFAULT=false
if HOTSPOT_CHECK_JVM_VARIANT(zero); then
FALLBACK_LINKER_DEFAULT=true
fi
UTIL_ARG_ENABLE(NAME: fallback-linker, DEFAULT: $FALLBACK_LINKER_DEFAULT,
RESULT: ENABLE_FALLBACK_LINKER,
DESC: [enable libffi-based fallback implementation of java.lang.foreign.Linker],
CHECKING_MSG: [if fallback linker enabled])
AC_SUBST(ENABLE_FALLBACK_LINKER)
])
2 changes: 1 addition & 1 deletion make/autoconf/libraries.m4
Expand Up @@ -82,7 +82,7 @@ AC_DEFUN_ONCE([LIB_DETERMINE_DEPENDENCIES],
fi
# Check if ffi is needed
if HOTSPOT_CHECK_JVM_VARIANT(zero); then
if HOTSPOT_CHECK_JVM_VARIANT(zero) || test "x$ENABLE_FALLBACK_LINKER" = "xtrue"; then
NEEDS_LIB_FFI=true
else
NEEDS_LIB_FFI=false
Expand Down
3 changes: 3 additions & 0 deletions make/autoconf/spec.gmk.in
Expand Up @@ -409,6 +409,9 @@ TEST_JOBS?=@TEST_JOBS@
DEFAULT_MAKE_TARGET:=@DEFAULT_MAKE_TARGET@
DEFAULT_LOG:=@DEFAULT_LOG@

# Fallback linker
ENABLE_FALLBACK_LINKER:=@ENABLE_FALLBACK_LINKER@

FREETYPE_TO_USE:=@FREETYPE_TO_USE@
FREETYPE_LIBS:=@FREETYPE_LIBS@
FREETYPE_CFLAGS:=@FREETYPE_CFLAGS@
Expand Down
46 changes: 44 additions & 2 deletions make/conf/jib-profiles.js
Expand Up @@ -587,11 +587,12 @@ var getJibProfilesProfiles = function (input, common, data) {
"linux-x64-zero": {
target_os: "linux",
target_cpu: "x64",
dependencies: ["devkit", "gtest"],
dependencies: ["devkit", "gtest", "libffi"],
configure_args: concat(common.configure_args_64bit, [
"--with-zlib=system",
"--with-jvm-variants=zero",
"--enable-libffi-bundling"
"--with-libffi=" + input.get("libffi", "home_path"),
"--enable-libffi-bundling",
])
},

Expand Down Expand Up @@ -744,6 +745,40 @@ var getJibProfilesProfiles = function (input, common, data) {
common.debug_profile_artifacts(artifactData[name]));
});

// Define artifact just for linux-x64-zero, which is the only one we test on
["linux-x64"].forEach(function (name) {
var o = artifactData[name]
var pf = o.platform
var jdk_subdir = (o.jdk_subdir != null ? o.jdk_subdir : "jdk-" + data.version);
var jdk_suffix = (o.jdk_suffix != null ? o.jdk_suffix : "tar.gz");
var zeroName = name + "-zero";
profiles[zeroName].artifacts = {
jdk: {
local: "bundles/\\(jdk.*bin." + jdk_suffix + "\\)",
remote: [
"bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-zero." + jdk_suffix,
],
subdir: jdk_subdir,
exploded: "images/jdk",
},
test: {
local: "bundles/\\(jdk.*bin-tests.tar.gz\\)",
remote: [
"bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-zero-tests.tar.gz",
],
exploded: "images/test"
},
jdk_symbols: {
local: "bundles/\\(jdk.*bin-symbols.tar.gz\\)",
remote: [
"bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-zero-symbols.tar.gz",
],
subdir: jdk_subdir,
exploded: "images/jdk"
},
};
});

buildJdkDep = input.build_os + "-" + input.build_cpu + ".jdk";
docsProfiles = {
"docs": {
Expand Down Expand Up @@ -1234,6 +1269,13 @@ var getJibProfilesDependencies = function (input, common) {
ext: "tar.gz",
revision: "1.13.0+1.0"
},

libffi: {
organization: common.organization,
module: "libffi-" + input.build_platform,
ext: "tar.gz",
revision: "3.4.2+1.0"
},
};

return dependencies;
Expand Down
3 changes: 2 additions & 1 deletion make/data/hotspot-symbols/symbols-shared
@@ -1,5 +1,5 @@
#
# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2016, 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
Expand Down Expand Up @@ -30,5 +30,6 @@ jio_vsnprintf
JNI_CreateJavaVM
JNI_GetCreatedJavaVMs
JNI_GetDefaultJavaVMInitArgs
JVM_IsForeignLinkerSupported
JVM_FindClassFromBootLoader
JVM_InitAgentProperties
111 changes: 111 additions & 0 deletions make/devkit/createLibffiBundle.sh
@@ -0,0 +1,111 @@
#!/bin/bash
#
# Copyright (c) 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.
#

# This script generates a libffi bundle. On linux by building it from source
# using a devkit, which should match the devkit used to build the JDK.
#
# Set MAKE_ARGS to add parameters to make. Ex:
#
# $ MAKE_ARGS=-j32 bash createLibffiBundle.sh
#
# The script tries to behave well on multiple invocations, only performing steps
# not already done. To redo a step, manually delete the target files from that
# step.
#
# Note that the libtool and texinfo packages are needed to build libffi
# $ sudo apt install libtool texinfo

LIBFFI_VERSION=3.4.2

BUNDLE_NAME=libffi-$LIBFFI_VERSION.tar.gz

SCRIPT_FILE="$(basename $0)"
SCRIPT_DIR="$(cd "$(dirname $0)" > /dev/null && pwd)"
OUTPUT_DIR="${SCRIPT_DIR}/../../build/libffi"
SRC_DIR="$OUTPUT_DIR/src"
DOWNLOAD_DIR="$OUTPUT_DIR/download"
INSTALL_DIR="$OUTPUT_DIR/install"
IMAGE_DIR="$OUTPUT_DIR/image"

USAGE="$0 <devkit dir>"

if [ "$1" = "" ]; then
echo $USAGE
exit 1
fi
DEVKIT_DIR="$1"

# Download source distros
mkdir -p $DOWNLOAD_DIR
cd $DOWNLOAD_DIR
SOURCE_TAR=v$LIBFFI_VERSION.tar.gz
if [ ! -f $SOURCE_TAR ]; then
wget https://github.com/libffi/libffi/archive/refs/tags/v$LIBFFI_VERSION.tar.gz
fi

# Unpack src
mkdir -p $SRC_DIR
cd $SRC_DIR
LIBFFI_DIRNAME=libffi-$LIBFFI_VERSION
LIBFFI_DIR=$SRC_DIR/$LIBFFI_DIRNAME
if [ ! -d $LIBFFI_DIRNAME ]; then
echo "Unpacking $SOURCE_TAR"
tar xf $DOWNLOAD_DIR/$SOURCE_TAR
fi

# Build
cd $LIBFFI_DIR
if [ ! -e $LIBFFI_DIR/configure ]; then
bash ./autogen.sh
fi
bash ./configure --prefix=$INSTALL_DIR CC=$DEVKIT_DIR/bin/gcc CXX=$DEVKIT_DIR/bin/g++

# Run with nice to keep system usable during build.
nice make $MAKE_ARGS install

mkdir -p $IMAGE_DIR
# Extract what we need into an image
if [ ! -e $IMAGE_DIR/lib/libffi.so ]; then
echo "Copying libffi.so* to image"
mkdir -p $IMAGE_DIR/lib
cp -a $INSTALL_DIR/lib64/libffi.so* $IMAGE_DIR/lib/
fi
if [ ! -e $IMAGE_DIR/include/ ]; then
echo "Copying include to image"
mkdir -p $IMAGE_DIR/include
cp -a $INSTALL_DIR/include/. $IMAGE_DIR/include/
fi
if [ ! -e $IMAGE_DIR/$SCRIPT_FILE ]; then
echo "Copying this script to image"
cp -a $SCRIPT_DIR/$SCRIPT_FILE $IMAGE_DIR/
fi

# Create bundle
if [ ! -e $OUTPUT_DIR/$BUNDLE_NAME ]; then
echo "Creating $OUTPUT_DIR/$BUNDLE_NAME"
cd $IMAGE_DIR
tar zcf $OUTPUT_DIR/$BUNDLE_NAME *
fi
17 changes: 16 additions & 1 deletion make/modules/java.base/Lib.gmk
@@ -1,5 +1,5 @@
#
# Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2011, 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
Expand Down Expand Up @@ -215,3 +215,18 @@ $(eval $(call SetupJdkLibrary, BUILD_SYSLOOKUPLIB, \
))

TARGETS += $(BUILD_SYSLOOKUPLIB)

################################################################################
# Create fallback linker lib

ifeq ($(ENABLE_FALLBACK_LINKER), true)
$(eval $(call SetupJdkLibrary, BUILD_LIBFALLBACKLINKER, \
NAME := fallbackLinker, \
CFLAGS := $(CFLAGS_JDKLIB) $(LIBFFI_CFLAGS), \
LDFLAGS := $(LDFLAGS_JDKLIB) \
$(call SET_SHARED_LIBRARY_ORIGIN), \
LIBS := $(LIBFFI_LIBS), \
))

TARGETS += $(BUILD_LIBFALLBACKLINKER)
endif

1 comment on commit cbccc4c

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.