Skip to content

Commit

Permalink
[GR-51536] Backport changes from nds/foreign-upcall to include in the…
Browse files Browse the repository at this point in the history
… next release

PullRequest: graal/16773
  • Loading branch information
Solene Husseini committed Jan 31, 2024
2 parents df761b6 + 6ef8d88 commit 51e103a
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 51e103a

Please sign in to comment.