Search in sources :

Example 1 with RelocatedPointer

use of org.graalvm.nativeimage.c.function.RelocatedPointer in project graal by oracle.

the class NativeImageHeap method writeConstant.

private void writeConstant(RelocatableBuffer buffer, int index, JavaKind kind, Object value, ObjectInfo info) {
    if (value instanceof RelocatedPointer) {
        addNonDataRelocation(buffer, index, (RelocatedPointer) value);
        return;
    }
    final JavaConstant con;
    if (value instanceof WordBase) {
        con = JavaConstant.forIntegerKind(FrameAccess.getWordKind(), ((WordBase) value).rawValue());
    } else if (value == null && kind == FrameAccess.getWordKind()) {
        con = JavaConstant.forIntegerKind(FrameAccess.getWordKind(), 0);
    } else {
        assert kind == JavaKind.Object || value != null : "primitive value must not be null";
        con = SubstrateObjectConstant.forBoxedValue(kind, value);
    }
    write(buffer, index, con, info);
}
Also used : RelocatedPointer(org.graalvm.nativeimage.c.function.RelocatedPointer) WordBase(org.graalvm.word.WordBase) JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 2 with RelocatedPointer

use of org.graalvm.nativeimage.c.function.RelocatedPointer in project graal by oracle.

the class NativeImageHeap method writeField.

private void writeField(RelocatableBuffer buffer, ObjectInfo fields, HostedField field, JavaConstant receiver, ObjectInfo info) {
    int index = fields.getIntIndexInSection(field.getLocation());
    JavaConstant value = field.readValue(receiver);
    if (value.getJavaKind() == JavaKind.Object && SubstrateObjectConstant.asObject(value) instanceof RelocatedPointer) {
        addNonDataRelocation(buffer, index, (RelocatedPointer) SubstrateObjectConstant.asObject(value));
    } else {
        write(buffer, index, value, info != null ? info : field);
    }
}
Also used : RelocatedPointer(org.graalvm.nativeimage.c.function.RelocatedPointer) JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 3 with RelocatedPointer

use of org.graalvm.nativeimage.c.function.RelocatedPointer in project graal by oracle.

the class GraalObjectReplacer method apply.

@Override
public Object apply(Object source) {
    if (source == null) {
        return null;
    }
    Object dest = source;
    if (source instanceof RelocatedPointer) {
        return dest;
    }
    if (source instanceof MetaAccessProvider) {
        dest = sMetaAccess;
    } else if (source instanceof GraalRuntime) {
        dest = sGraalRuntime;
    } else if (source instanceof AnalysisConstantReflectionProvider) {
        dest = sConstantReflectionProvider;
    } else if (source instanceof AnalysisConstantFieldProvider) {
        dest = sConstantFieldProvider;
    } else if (source instanceof ForeignCallsProvider) {
        dest = GraalSupport.getRuntimeConfig().getProviders().getForeignCalls();
    } else if (source instanceof HostedSnippetReflectionProvider) {
        dest = GraalSupport.getRuntimeConfig().getSnippetReflection();
    } else if (shouldBeReplaced(source)) {
        /*
             * The hash maps must be synchronized, because replace() may be called from
             * BigBang.finish(), which is multi-threaded.
             */
        synchronized (this) {
            if (source instanceof ResolvedJavaMethod) {
                dest = createMethod((ResolvedJavaMethod) source);
            } else if (source instanceof ResolvedJavaField) {
                dest = createField((ResolvedJavaField) source);
            } else if (source instanceof ResolvedJavaType) {
                dest = createType((ResolvedJavaType) source);
            } else if (source instanceof Signature) {
                dest = createSignature((Signature) source);
            } else if (source instanceof FieldLocationIdentity) {
                dest = fieldLocationIdentities.get(source);
                if (dest == null) {
                    SubstrateField destField = (SubstrateField) apply(((FieldLocationIdentity) source).getField());
                    dest = new SubstrateFieldLocationIdentity(destField);
                    fieldLocationIdentities.put((FieldLocationIdentity) source, (FieldLocationIdentity) dest);
                }
            }
        }
    }
    assert dest != null;
    String className = dest.getClass().getName();
    assert !className.contains(".hotspot.") || className.contains(".svm.jtt.hotspot.") : "HotSpot object in image " + className;
    assert !className.contains(".analysis.meta.") : "Analysis meta object in image " + className;
    assert !className.contains(".hosted.meta.") : "Hosted meta object in image " + className;
    return dest;
}
Also used : ForeignCallsProvider(org.graalvm.compiler.core.common.spi.ForeignCallsProvider) AnalysisConstantReflectionProvider(com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider) AnalysisConstantFieldProvider(com.oracle.svm.hosted.ameta.AnalysisConstantFieldProvider) RelocatedPointer(org.graalvm.nativeimage.c.function.RelocatedPointer) SubstrateField(com.oracle.svm.graal.meta.SubstrateField) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) HostedSnippetReflectionProvider(com.oracle.svm.hosted.meta.HostedSnippetReflectionProvider) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) GraalRuntime(org.graalvm.compiler.api.runtime.GraalRuntime) SubstrateGraalRuntime(com.oracle.svm.graal.SubstrateGraalRuntime) FieldLocationIdentity(org.graalvm.compiler.nodes.FieldLocationIdentity) SubstrateFieldLocationIdentity(com.oracle.svm.core.graal.nodes.SubstrateFieldLocationIdentity) SubstrateFieldLocationIdentity(com.oracle.svm.core.graal.nodes.SubstrateFieldLocationIdentity) Signature(jdk.vm.ci.meta.Signature) SubstrateSignature(com.oracle.svm.graal.meta.SubstrateSignature) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

RelocatedPointer (org.graalvm.nativeimage.c.function.RelocatedPointer)3 JavaConstant (jdk.vm.ci.meta.JavaConstant)2 SubstrateFieldLocationIdentity (com.oracle.svm.core.graal.nodes.SubstrateFieldLocationIdentity)1 SubstrateGraalRuntime (com.oracle.svm.graal.SubstrateGraalRuntime)1 SubstrateField (com.oracle.svm.graal.meta.SubstrateField)1 SubstrateSignature (com.oracle.svm.graal.meta.SubstrateSignature)1 AnalysisConstantFieldProvider (com.oracle.svm.hosted.ameta.AnalysisConstantFieldProvider)1 AnalysisConstantReflectionProvider (com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider)1 HostedSnippetReflectionProvider (com.oracle.svm.hosted.meta.HostedSnippetReflectionProvider)1 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)1 ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 Signature (jdk.vm.ci.meta.Signature)1 GraalRuntime (org.graalvm.compiler.api.runtime.GraalRuntime)1 ForeignCallsProvider (org.graalvm.compiler.core.common.spi.ForeignCallsProvider)1 FieldLocationIdentity (org.graalvm.compiler.nodes.FieldLocationIdentity)1 WordBase (org.graalvm.word.WordBase)1