diff --git a/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_jdk_internal_foreign_Utils_BaseAndScale.java b/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_jdk_internal_foreign_Utils_BaseAndScale.java new file mode 100644 index 000000000000..8b08d4a9c54e --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_jdk_internal_foreign_Utils_BaseAndScale.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2024, 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.foreign; + +import com.oracle.svm.core.annotate.Alias; +import com.oracle.svm.core.annotate.RecomputeFieldValue; +import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.config.ConfigurationValues; +import com.oracle.svm.core.fieldvaluetransformer.FieldValueTransformerWithAvailability; +import com.oracle.svm.core.util.VMError; + +import jdk.internal.foreign.Utils; +import jdk.vm.ci.meta.JavaKind; + +@TargetClass(className = "jdk.internal.foreign.Utils", innerClass = "BaseAndScale", onlyWith = ForeignFunctionsEnabled.class) +final class Target_jdk_internal_foreign_Utils_BaseAndScale { + @Alias // + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = BaseFieldRecomputer.class) // + int base; +} + +final class BaseFieldRecomputer implements FieldValueTransformerWithAvailability { + + @Override + public ValueAvailability valueAvailability() { + return ValueAvailability.BeforeAnalysis; + } + + @Override + public Object transform(Object receiver, Object originalValue) { + JavaKind kind; + if (receiver == Utils.BaseAndScale.BYTE) { + kind = JavaKind.Byte; + } else if (receiver == Utils.BaseAndScale.CHAR) { + kind = JavaKind.Char; + } else if (receiver == Utils.BaseAndScale.SHORT) { + kind = JavaKind.Short; + } else if (receiver == Utils.BaseAndScale.INT) { + kind = JavaKind.Int; + } else if (receiver == Utils.BaseAndScale.LONG) { + kind = JavaKind.Long; + } else if (receiver == Utils.BaseAndScale.FLOAT) { + kind = JavaKind.Float; + } else if (receiver == Utils.BaseAndScale.DOUBLE) { + kind = JavaKind.Double; + } else { + throw VMError.shouldNotReachHere("Unexpected BaseAndScale instance: " + receiver); + } + return ConfigurationValues.getObjectLayout().getArrayBaseOffset(kind); + } +} diff --git a/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_jdk_internal_foreign_abi_AbstractLinker.java b/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_jdk_internal_foreign_abi_AbstractLinker.java new file mode 100644 index 000000000000..50901b3a2fcd --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_jdk_internal_foreign_abi_AbstractLinker.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024, 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.foreign; + +import com.oracle.svm.core.annotate.Alias; +import com.oracle.svm.core.annotate.RecomputeFieldValue; +import com.oracle.svm.core.annotate.TargetClass; + +import jdk.internal.foreign.abi.AbstractLinker; + +@TargetClass(AbstractLinker.class) +public final class Target_jdk_internal_foreign_abi_AbstractLinker { + @Alias // + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClassName = "jdk.internal.foreign.abi.SoftReferenceCache") // + private Target_jdk_internal_foreign_abi_SoftReferenceCache DOWNCALL_CACHE; + + @Alias // + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClassName = "jdk.internal.foreign.abi.SoftReferenceCache") // + private Target_jdk_internal_foreign_abi_SoftReferenceCache UPCALL_CACHE; +} + +@TargetClass(className = "jdk.internal.foreign.abi.SoftReferenceCache") +final class Target_jdk_internal_foreign_abi_SoftReferenceCache { +} diff --git a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/DefaultOptionHandler.java b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/DefaultOptionHandler.java index 5f277a36a631..fcd80ae024f5 100644 --- a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/DefaultOptionHandler.java +++ b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/DefaultOptionHandler.java @@ -136,7 +136,7 @@ public boolean consume(ArgumentQueue args) { if (modules == null) { NativeImage.showError(nativeAccessOption + moduleSetModifierOptionErrorMessage); } - nativeImage.addCustomJavaArgs(nativeAccessOption + "=" + modules + ",org.graalvm.nativeimage.builder"); + nativeImage.addCustomJavaArgs(nativeAccessOption + "=" + modules + ",org.graalvm.nativeimage.foreign"); return true; } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageDebugInfoProviderBase.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageDebugInfoProviderBase.java index 87ca9b83eabe..8cc142de39b4 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageDebugInfoProviderBase.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageDebugInfoProviderBase.java @@ -449,7 +449,12 @@ protected SubstrateCallingConvention getCallingConvention(HostedMethod method) { HostedType declaringClass = method.getDeclaringClass(); HostedType receiverType = method.isStatic() ? null : declaringClass; var signature = method.getSignature(); - SubstrateCallingConventionType type = callingConventionKind.toType(false); + final SubstrateCallingConventionType type; + if (callingConventionKind.isCustom()) { + type = method.getCustomCallingConventionType(); + } else { + type = callingConventionKind.toType(false); + } Backend backend = runtimeConfiguration.lookupBackend(method); RegisterConfig registerConfig = backend.getCodeCache().getRegisterConfig(); assert registerConfig instanceof SubstrateRegisterConfig;