Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@
*/
package com.oracle.svm.core.graal.aarch64;

import static jdk.vm.ci.code.ValueUtil.asRegister;
import static jdk.graal.compiler.lir.LIRInstruction.OperandFlag.REG;
import static jdk.vm.ci.code.ValueUtil.asRegister;

import jdk.graal.compiler.asm.aarch64.AArch64Address;
import jdk.graal.compiler.asm.aarch64.AArch64MacroAssembler;
import jdk.graal.compiler.lir.LIRInstructionClass;
import jdk.graal.compiler.lir.aarch64.AArch64LIRInstruction;
import jdk.graal.compiler.lir.asm.CompilationResultBuilder;
import org.graalvm.word.Pointer;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;

import com.oracle.svm.core.SubstrateUtil;
import com.oracle.svm.core.graal.code.CGlobalDataInfo;
import com.oracle.svm.core.graal.code.CGlobalDataReference;

import jdk.graal.compiler.asm.aarch64.AArch64MacroAssembler;
import jdk.graal.compiler.lir.LIRInstructionClass;
import jdk.graal.compiler.lir.aarch64.AArch64LIRInstruction;
import jdk.graal.compiler.lir.asm.CompilationResultBuilder;
import jdk.vm.ci.code.Register;
import jdk.vm.ci.meta.AllocatableValue;

@Platforms(Platform.HOSTED_ONLY.class)
public final class AArch64CGlobalDataLoadAddressOp extends AArch64LIRInstruction {
public static final LIRInstructionClass<AArch64CGlobalDataLoadAddressOp> TYPE = LIRInstructionClass.create(AArch64CGlobalDataLoadAddressOp.class);

Expand All @@ -58,25 +58,15 @@ public final class AArch64CGlobalDataLoadAddressOp extends AArch64LIRInstruction
public void emitCode(CompilationResultBuilder crb, AArch64MacroAssembler masm) {
int addressBitSize = result.getPlatformKind().getSizeInBytes() * Byte.SIZE;
assert addressBitSize == 64;
if (SubstrateUtil.HOSTED) {
// AOT compilation: record patch that is fixed up later
crb.compilationResult.recordDataPatch(masm.position(), new CGlobalDataReference(dataInfo));
Register resultRegister = asRegister(result);
if (dataInfo.isSymbolReference()) {
// Pure symbol reference: the data contains the symbol's address, load it
masm.adrpLdr(addressBitSize, resultRegister, resultRegister);
} else {
// Data: load its address
masm.adrpAdd(resultRegister);
}

crb.compilationResult.recordDataPatch(masm.position(), new CGlobalDataReference(dataInfo));
Register resultRegister = asRegister(result);
if (dataInfo.isSymbolReference()) {
// Pure symbol reference: the data contains the symbol's address, load it
masm.adrpLdr(addressBitSize, resultRegister, resultRegister);
} else {
// Runtime compilation: compute the actual address
Pointer globalsBase = CGlobalDataInfo.CGLOBALDATA_RUNTIME_BASE_ADDRESS.get();
Pointer address = globalsBase.add(dataInfo.getOffset());
masm.mov(asRegister(result), address.rawValue());
if (dataInfo.isSymbolReference()) { // load data, which contains symbol's address
masm.ldr(addressBitSize, asRegister(result), AArch64Address.createBaseRegisterOnlyAddress(addressBitSize, asRegister(result)));
}
// Data: load its address
masm.adrpAdd(resultRegister);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
import static jdk.graal.compiler.lir.LIRInstruction.OperandFlag.REG;
import static jdk.vm.ci.code.ValueUtil.asRegister;

import org.graalvm.word.Pointer;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;

import com.oracle.svm.core.SubstrateUtil;
import com.oracle.svm.core.graal.code.CGlobalDataInfo;
import com.oracle.svm.core.graal.code.CGlobalDataReference;

Expand All @@ -41,6 +41,7 @@
import jdk.vm.ci.code.Register;
import jdk.vm.ci.meta.AllocatableValue;

@Platforms(Platform.HOSTED_ONLY.class)
public final class AMD64CGlobalDataLoadAddressOp extends AMD64LIRInstruction {
public static final LIRInstructionClass<AMD64CGlobalDataLoadAddressOp> TYPE = LIRInstructionClass.create(AMD64CGlobalDataLoadAddressOp.class);

Expand All @@ -64,27 +65,16 @@ public final class AMD64CGlobalDataLoadAddressOp extends AMD64LIRInstruction {
@Override
public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
Register resultReg = asRegister(result);
if (SubstrateUtil.HOSTED) {
// AOT compilation: record patch that is fixed up later
int before = masm.position();
AMD64Address address = masm.getPlaceholder(before);
if (dataInfo.isSymbolReference()) {
// Pure symbol reference: the data contains the symbol's address, load it
masm.movq(resultReg, address);
} else {
// Data: load its address
masm.leaq(resultReg, address);
}
crb.compilationResult.recordDataPatch(before, new CGlobalDataReference(dataInfo));
int before = masm.position();
AMD64Address address = masm.getPlaceholder(before);
if (dataInfo.isSymbolReference()) {
// Pure symbol reference: the data contains the symbol's address, load it
masm.movq(resultReg, address);
} else {
// Runtime compilation: compute the actual address
Pointer globalsBase = CGlobalDataInfo.CGLOBALDATA_RUNTIME_BASE_ADDRESS.get();
Pointer address = globalsBase.add(dataInfo.getOffset());
masm.movq(resultReg, address.rawValue());
if (dataInfo.isSymbolReference()) { // load data, which contains symbol's address
masm.movq(resultReg, new AMD64Address(asRegister(result)));
}
// Data: load its address
masm.leaq(resultReg, address);
}
crb.compilationResult.recordDataPatch(before, new CGlobalDataReference(dataInfo));
if (addend != 0) {
masm.addq(resultReg, addend);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton;
import com.oracle.svm.core.feature.InternalFeature;
import com.oracle.svm.core.graal.RuntimeCompilation;
import com.oracle.svm.core.graal.code.CGlobalDataInfo;
import com.oracle.svm.core.graal.stackvalue.UnsafeStackValue;
import com.oracle.svm.core.heap.Heap;
import com.oracle.svm.core.heap.RestrictHeapAccess;
Expand Down Expand Up @@ -890,6 +891,7 @@ public void printDiagnostics(Log log, ErrorContext context, int maxDiagnosticLev
log.string("Runtime information:").indent(true);
log.string("Isolate id: ").signed(Isolates.getIsolateId()).newline();
log.string("Heap base: ").zhex(KnownIntrinsics.heapBase()).newline();
log.string("CGlobalData base: ").zhex(CGlobalDataInfo.CGLOBALDATA_RUNTIME_BASE_ADDRESS.getPointer()).newline();

if (Container.singleton().isContainerized()) {
log.string("CPU cores (container): ");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2025, 2025, 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.graal.code;

import static com.oracle.svm.core.util.VMError.shouldNotReachHere;

import org.graalvm.nativeimage.c.function.RelocatedPointer;
import org.graalvm.word.ComparableWord;
import org.graalvm.word.PointerBase;

import com.oracle.svm.core.c.CGlobalData;

/** Placeholder for the base address of {@link CGlobalData} memory during the image build. */
public final class CGlobalDataBasePointer implements PointerBase, RelocatedPointer {
public static final CGlobalDataBasePointer INSTANCE = new CGlobalDataBasePointer();

private CGlobalDataBasePointer() {
}

private static RuntimeException mustNotBeCalledHosted() {
throw shouldNotReachHere("must not be called in hosted mode");
}

@Override
public boolean equal(ComparableWord val) {
throw mustNotBeCalledHosted();
}

@Override
public boolean notEqual(ComparableWord val) {
throw mustNotBeCalledHosted();
}

@Override
public long rawValue() {
throw mustNotBeCalledHosted();
}

@Override
public boolean isNull() {
throw mustNotBeCalledHosted();
}

@Override
public boolean isNonNull() {
throw mustNotBeCalledHosted();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,20 @@
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platform.HOSTED_ONLY;
import org.graalvm.nativeimage.Platforms;
import org.graalvm.word.Pointer;

import com.oracle.svm.core.BuildPhaseProvider.AfterHeapLayout;
import com.oracle.svm.core.BuildPhaseProvider.AfterHostedUniverse;
import com.oracle.svm.core.c.CGlobalData;
import com.oracle.svm.core.c.CGlobalDataFactory;
import com.oracle.svm.core.c.BoxedRelocatedPointer;
import com.oracle.svm.core.c.CGlobalDataImpl;
import com.oracle.svm.core.heap.UnknownPrimitiveField;
import com.oracle.svm.core.util.VMError;

public final class CGlobalDataInfo {
public static final String CGLOBALDATA_BASE_SYMBOL_NAME = "__svm_cglobaldata_base";
public static final CGlobalData<Pointer> CGLOBALDATA_RUNTIME_BASE_ADDRESS = CGlobalDataFactory.forSymbol(CGLOBALDATA_BASE_SYMBOL_NAME);
/**
* Image heap object storing the base address of CGlobalData memory using a relocation. Before
* the image heap is set up, CGlobalData must be accessed via relocations in the code instead.
*/
public static final BoxedRelocatedPointer CGLOBALDATA_RUNTIME_BASE_ADDRESS = new BoxedRelocatedPointer(CGlobalDataBasePointer.INSTANCE);

private final CGlobalDataImpl<?> data;
private final boolean isSymbolReference;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
*/
package com.oracle.svm.core.graal.nodes;

import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;

import com.oracle.svm.core.FrameAccess;
import com.oracle.svm.core.graal.code.CGlobalDataInfo;
import com.oracle.svm.core.graal.code.SubstrateNodeLIRBuilder;

import jdk.graal.compiler.graph.NodeClass;
import jdk.graal.compiler.nodeinfo.NodeCycles;
import jdk.graal.compiler.nodeinfo.NodeInfo;
Expand All @@ -32,10 +39,12 @@
import jdk.graal.compiler.nodes.spi.LIRLowerable;
import jdk.graal.compiler.nodes.spi.NodeLIRBuilderTool;

import com.oracle.svm.core.FrameAccess;
import com.oracle.svm.core.graal.code.CGlobalDataInfo;
import com.oracle.svm.core.graal.code.SubstrateNodeLIRBuilder;

/**
* Directly load the address of {@code CGlobalData} memory.
*
* Only for use in AOT-compiled code because it uses relocations.
*/
@Platforms(Platform.HOSTED_ONLY.class)
@NodeInfo(cycles = NodeCycles.CYCLES_1, size = NodeSize.SIZE_1, sizeRationale = "same as LoadAddressNode")
public final class CGlobalDataLoadAddressNode extends FloatingNode implements LIRLowerable {
public static final NodeClass<CGlobalDataLoadAddressNode> TYPE = NodeClass.create(CGlobalDataLoadAddressNode.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ struct ConstantReference {
methodId @4 :MethodId;
}
cEntryPointLiteralCodePointer @5 :CEntryPointLiteralReference;
cGlobalDataBasePointer @6 :Void;
}
}

Expand Down
Loading
Loading