Skip to content

Commit

Permalink
Fix TruffleSqueak builds with Oracle GraalVM.
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Sep 22, 2023
1 parent 3c79c62 commit 152813e
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 74 deletions.
62 changes: 8 additions & 54 deletions mx.trufflesqueak/mx_trufflesqueak.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,66 +177,20 @@ def patched_init(self, *args, **kw_args):
_enable_local_compression()


def _copy_macro_and_language_jars():
staged_dist = mx_sdk_vm_impl.get_stage1_graalvm_distribution()
staged_graalvm_home = os.path.join(staged_dist.output, staged_dist.jdk_base)
# Copy macros
for macro_dir_name in ['smalltalkvm-library', 'truffle']:
macro_src_dir = os.path.join(staged_graalvm_home, 'lib', 'svm', 'macros', macro_dir_name)
macro_target_dir = os.path.join(extra_graalvm_home, 'lib', 'svm', 'macros', macro_dir_name)
if not os.path.exists(macro_src_dir):
mx.abort(f'Unable to locate macro at "{macro_src_dir}".')
if not os.path.exists(macro_target_dir):
shutil.copytree(macro_src_dir, macro_target_dir)
else:
mx.warn(f'Macros already copied to "{macro_target_dir}".')
# Copy language directories
for language_dir_name in ['smalltalk', 'nfi']:
language_src_dir = os.path.join(staged_graalvm_home, 'languages', language_dir_name)
language_target_dir = os.path.join(extra_graalvm_home, 'languages', language_dir_name)
if not os.path.exists(language_src_dir):
mx.abort(f'Unable to locate language JARs at "{language_src_dir}".')
if not os.path.exists(language_target_dir):
shutil.copytree(language_src_dir, language_target_dir)
else:
mx.warn(f'Language JARs already copied to "{language_target_dir}".')
# Copy Truffle JARs
for truffle_jar_name in ['jniutils.jar', 'locator.jar', 'truffle-api.jar', 'truffle-runtime.jar']:
truffle_src_dir = os.path.join(staged_graalvm_home, 'lib', 'truffle', truffle_jar_name)
truffle_target_dir = os.path.join(extra_graalvm_home, 'lib', 'truffle', truffle_jar_name)
if not os.path.exists(truffle_src_dir):
mx.abort(f'Unable to locate Truffle JAR at "{truffle_src_dir}".')
if not os.path.exists(truffle_target_dir):
shutil.copyfile(truffle_src_dir, truffle_target_dir)
else:
mx.warn(f'Truffle JAR already copied to "{truffle_target_dir}".')
# Copy additional JARs
for jar_name in ['trufflesqueak-launcher.jar', 'launcher-common.jar', 'jline3.jar']:
launcher_src_dir = os.path.join(staged_graalvm_home, 'lib', 'graalvm', jar_name)
launcher_target_dir = os.path.join(extra_graalvm_home, 'lib', 'graalvm', jar_name)
if not os.path.exists(launcher_src_dir):
mx.abort(f'Unable to locate JAR at "{launcher_src_dir}".')
if not os.path.exists(launcher_target_dir):
shutil.copyfile(launcher_src_dir, launcher_target_dir)
else:
mx.warn(f'JAR already copied to "{launcher_target_dir}".')


def _use_different_graalvm_home_for_native_image(extra_graalvm_home):

def patched_native_image(self, build_args, output_file, allow_server=False, nonZeroIsFatal=True, out=None, err=None):
mx.log(f'Using EXTRA_GRAALVM_HOME at "{extra_graalvm_home}" for building...')
assert self._svm_supported
_copy_macro_and_language_jars()
native_image_bin = os.path.join(extra_graalvm_home, 'bin', mx.cmd_suffix('native-image'))
native_image_command = [native_image_bin] + build_args
output_directory = os.path.dirname(output_file)
native_image_path = os.path.join(extra_graalvm_home, 'bin', mx.cmd_suffix('native-image'))
dist_names = ['TRUFFLESQUEAK', 'TRUFFLESQUEAK_LAUNCHER', 'TRUFFLE_NFI_LIBFFI', 'TRUFFLE-ENTERPRISE', 'SDK-NATIVEBRIDGE'] + mx_truffle.resolve_truffle_dist_names(use_optimized_runtime=True, use_enterprise=True)
selected_gc = 'G1' if mx.is_linux() and mx.get_arch() == 'amd64' else 'serial'
native_image_command += [
'-H:Path=' + output_directory or ".",
build_command = [native_image_path] + mx.get_runtime_jvm_args(names=dist_names, force_cp=False) + [
'-o', os.path.splitext(output_file)[0],
'--shared',
'--gc=' + selected_gc,
'--module', 'de.hpi.swa.trufflesqueak.launcher/%s.launcher.TruffleSqueakLauncher' % PACKAGE_NAME
]
return mx.run(native_image_command, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err)
mx.log('Running {} ...'.format(' '.join(build_command)))
return mx.run(build_command)

mx_sdk_vm_impl.SvmSupport.native_image = patched_native_image

Expand Down
13 changes: 0 additions & 13 deletions mx.trufflesqueak/native-image.properties

This file was deleted.

19 changes: 18 additions & 1 deletion mx.trufflesqueak/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,24 @@
"sha1": "acd1c78c07e894647e8dcbd72c4fa9a136e20d6d",
"licence" : "LGPLv21",
},
"TRUFFLE-ENTERPRISE": {
"digest": "sha512:2948bd1779fe1c2b0b70de76220582d54bb59a2d9048c4a09d5148a7358014ae6484a373a1076f5dad7f861723981407ea48e247a6ef7d4659eef28ee9c86354",
"maven": {
"groupId": "org.graalvm.truffle",
"artifactId": "truffle-enterprise",
"version": "23.1.0",
},
"useModulePath": True,
},
"SDK-NATIVEBRIDGE": {
"digest": "sha512:bc28336e23d5abc4bc7704093b0e1546ac1aa972dfabe24e94dad19b4b0a36df62c6322dc33a0dadeb2a741a8fa1cb116d4248e09362f0c16924ff25672bc61d",
"maven": {
"groupId": "org.graalvm.sdk",
"artifactId": "nativebridge",
"version": "23.1.0",
},
"useModulePath": True,
},
},

# ==========================================================================
Expand Down Expand Up @@ -258,7 +276,6 @@
"LICENSE_TRUFFLESQUEAK.txt": "file:LICENSE",
"README_TRUFFLESQUEAK.md": "file:README.md",
"lib/": "dependency:de.hpi.swa.trufflesqueak.ffi.native",
"native-image.properties": "file:mx.trufflesqueak/native-image.properties",
},
"maven": False,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This file contains native-image arguments needed to build TruffleSqueak
#

Requires = language:nfi

JavaArgs = -Dpolyglot.engine.PreinitializeContexts=squeak -Djava.awt.headless=false

Args = --initialize-at-build-time=de.hpi.swa.trufflesqueak,org.bouncycastle \
--initialize-at-run-time=com.sun.imageio.plugins,com.sun.java.swing,java.applet,java.awt,javax.accessibility,com.sun.java.accessibility,javax.imageio,javax.swing,sun.awt,sun.datatransfer,sun.font,sun.java2d,sun.swing,com.sun.beans.util \
--enable-url-protocols=https \
--add-exports=java.base/jdk.internal.module=de.hpi.swa.trufflesqueak \
-H:MaxRuntimeCompileMethods=5000 \
--no-fallback \
-march=compatibility \
-H\:+UnlockExperimentalVMOptions \
-H\:+AssertInitializationSpecifiedForAllClasses \
-H\:+EnforceMaxRuntimeCompileMethods \
-H\:-UnlockExperimentalVMOptions \
--link-at-build-time \
--shared \
-Dorg.graalvm.launcher.class\=de.hpi.swa.trufflesqueak.launcher.TruffleSqueakLauncher \
-Dorg.graalvm.launcher.relative.smalltalk.home\=.. \
--features\=org.graalvm.home.HomeFinderFeature \
--install-exit-handlers \
--enable-monitoring=jvmstat,heapdump,jfr \
-H\:+UnlockExperimentalVMOptions \
-H\:+DumpRuntimeCompilationOnSignal \
-H\:-UnlockExperimentalVMOptions \
-H\:+ReportExceptionStackTraces \
-H\:+DumpThreadStacksOnSignal \
-H\:+DetectUserDirectoriesInImageHeap
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,15 @@ protected InteropArray computeValue(final Class<?> type) {
try {
for (final String className : new String[]{
// Truffle runtime class and BackgroundCompileQueue
"com.oracle.svm.truffle.api.SubstrateTruffleRuntime",
"org.graalvm.compiler.truffle.runtime.BackgroundCompileQueue",
// "com.oracle.svm.truffle.api.SubstrateTruffleRuntime",
"com.oracle.truffle.runtime.BackgroundCompileQueue",
// For CallTargetBrowser
"com.oracle.svm.truffle.api.SubstrateOptimizedCallTarget",
"com.oracle.svm.enterprise.truffle.SubstrateEnterpriseOptimizedCallTarget",
"org.graalvm.compiler.truffle.runtime.OptimizedCallTarget",
"org.graalvm.compiler.truffle.runtime.OptimizedCallTarget$ArgumentsProfile",
"org.graalvm.compiler.truffle.runtime.OptimizedCallTarget$ReturnProfile",
"org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode"
"com.oracle.truffle.runtime.OptimizedCallTarget",
"com.oracle.truffle.runtime.OptimizedCallTarget$ArgumentsProfile",
"com.oracle.truffle.runtime.OptimizedCallTarget$ReturnProfile",
"com.oracle.truffle.runtime.OptimizedDirectCallNode"
}) {
CLASSES_TO_MEMBERS.get(Class.forName(className));
}
Expand Down

0 comments on commit 152813e

Please sign in to comment.