Skip to content

Commit 81655ed

Browse files
committed
Change offsets used in heap layouting to be relative to the heap base.
1 parent ed00168 commit 81655ed

File tree

13 files changed

+60
-124
lines changed

13 files changed

+60
-124
lines changed

Diff for: substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/DebugInfoBase.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
import org.graalvm.collections.EconomicMap;
3838
import org.graalvm.collections.EconomicSet;
39-
import jdk.graal.compiler.debug.DebugContext;
4039

4140
import com.oracle.objectfile.debugentry.range.PrimaryRange;
4241
import com.oracle.objectfile.debugentry.range.Range;
@@ -49,6 +48,7 @@
4948
import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugTypeInfo.DebugTypeKind;
5049
import com.oracle.objectfile.elf.dwarf.DwarfDebugInfo;
5150

51+
import jdk.graal.compiler.debug.DebugContext;
5252
import jdk.vm.ci.meta.ResolvedJavaType;
5353

5454
/**
@@ -351,10 +351,10 @@ public void installDebugInfo(DebugInfoProvider debugInfoProvider) {
351351
String provenance = debugDataInfo.getProvenance();
352352
String typeName = debugDataInfo.getTypeName();
353353
String partitionName = debugDataInfo.getPartition();
354-
/* Address is heap-register relative pointer. */
355-
long address = debugDataInfo.getAddress();
354+
/* Offset is relative to heap-base register. */
355+
long offset = debugDataInfo.getOffset();
356356
long size = debugDataInfo.getSize();
357-
debugContext.log(DebugContext.INFO_LEVEL, "Data: address 0x%x size 0x%x type %s partition %s provenance %s ", address, size, typeName, partitionName, provenance);
357+
debugContext.log(DebugContext.INFO_LEVEL, "Data: offset 0x%x size 0x%x type %s partition %s provenance %s ", offset, size, typeName, partitionName, provenance);
358358
}
359359
}));
360360
// populate a file and dir list and associated index for each class entry

Diff for: substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debuginfo/DebugInfoProvider.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
import java.util.function.Consumer;
3232
import java.util.stream.Stream;
3333

34+
import jdk.graal.compiler.debug.DebugContext;
3435
import jdk.vm.ci.meta.JavaConstant;
3536
import jdk.vm.ci.meta.JavaKind;
3637
import jdk.vm.ci.meta.ResolvedJavaMethod;
3738
import jdk.vm.ci.meta.ResolvedJavaType;
38-
import jdk.graal.compiler.debug.DebugContext;
3939

4040
/**
4141
* Interfaces used to allow a native image to communicate details of types, code and data to the
@@ -356,8 +356,6 @@ interface DebugDataInfo {
356356

357357
long getOffset();
358358

359-
long getAddress();
360-
361359
long getSize();
362360
}
363361

Diff for: substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/ChunkedImageHeapLayouter.java

+5-31
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import com.oracle.svm.core.genscavenge.ChunkedImageHeapAllocator.Chunk;
3636
import com.oracle.svm.core.genscavenge.ChunkedImageHeapAllocator.UnalignedChunk;
3737
import com.oracle.svm.core.genscavenge.remset.RememberedSet;
38-
import com.oracle.svm.core.heap.Heap;
3938
import com.oracle.svm.core.hub.DynamicHub;
4039
import com.oracle.svm.core.image.ImageHeap;
4140
import com.oracle.svm.core.image.ImageHeapLayoutInfo;
@@ -83,10 +82,9 @@ public class ChunkedImageHeapLayouter implements ImageHeapLayouter {
8382
private final long hugeObjectThreshold;
8483
private ChunkedImageHeapAllocator allocator;
8584

85+
/** @param startOffset Offset relative to the heap base. */
8686
@SuppressWarnings("this-escape")
8787
public ChunkedImageHeapLayouter(ImageHeapInfo heapInfo, long startOffset) {
88-
assert startOffset == 0 || startOffset >= Heap.getHeap().getImageHeapOffsetInAddressSpace() : "must be relative to the heap base";
89-
9088
this.partitions = new ChunkedImageHeapPartition[PARTITION_COUNT];
9189
this.partitions[READ_ONLY_PRIMITIVE] = new ChunkedImageHeapPartition("readOnlyPrimitive", false, false);
9290
this.partitions[READ_ONLY_REFERENCE] = new ChunkedImageHeapPartition("readOnlyReference", false, false);
@@ -107,11 +105,6 @@ public ChunkedImageHeapLayouter(ImageHeapInfo heapInfo, long startOffset) {
107105
this.hugeObjectThreshold = hugeThreshold.rawValue();
108106
}
109107

110-
@Override
111-
public long getStartOffset() {
112-
return startOffset;
113-
}
114-
115108
@Override
116109
public ChunkedImageHeapPartition[] getPartitions() {
117110
return partitions;
@@ -214,34 +207,15 @@ private ImageHeapLayoutInfo populateInfoObjects(int dynamicHubCount) {
214207
break;
215208
}
216209

217-
initializeHeapInfo(dynamicHubCount, offsetOfFirstWritableAlignedChunk, offsetOfFirstWritableUnalignedChunk);
218-
return createLayoutInfo(startOffset, offsetOfFirstWritableAlignedChunk);
219-
}
220-
221-
private void initializeHeapInfo(int dynamicHubCount, long offsetOfFirstWritableAlignedChunk, long offsetOfFirstWritableUnalignedChunk) {
222-
long writableAligned = offsetOfFirstWritableAlignedChunk;
223-
long writableUnaligned = offsetOfFirstWritableUnalignedChunk;
224-
225-
if (startOffset == 0) {
226-
// Adjust all offsets by the offset of the image heap in the address space.
227-
int imageHeapOffsetInAddressSpace = Heap.getHeap().getImageHeapOffsetInAddressSpace();
228-
writableAligned += imageHeapOffsetInAddressSpace;
229-
if (writableUnaligned >= 0) {
230-
writableUnaligned += imageHeapOffsetInAddressSpace;
231-
}
232-
}
233-
234210
heapInfo.initialize(getReadOnlyPrimitive().firstObject, getReadOnlyPrimitive().lastObject, getReadOnlyReference().firstObject, getReadOnlyReference().lastObject,
235211
getReadOnlyRelocatable().firstObject, getReadOnlyRelocatable().lastObject, getWritablePrimitive().firstObject, getWritablePrimitive().lastObject,
236212
getWritableReference().firstObject, getWritableReference().lastObject, getWritableHuge().firstObject, getWritableHuge().lastObject,
237-
getReadOnlyHuge().firstObject, getReadOnlyHuge().lastObject, writableAligned, writableUnaligned, dynamicHubCount);
238-
}
213+
getReadOnlyHuge().firstObject, getReadOnlyHuge().lastObject, offsetOfFirstWritableAlignedChunk, offsetOfFirstWritableUnalignedChunk, dynamicHubCount);
239214

240-
private ImageHeapLayoutInfo createLayoutInfo(long heapStartOffset, long writableBeginOffset) {
241215
long writableEnd = getWritableHuge().getStartOffset() + getWritableHuge().getSize();
242-
long writableSize = writableEnd - writableBeginOffset;
243-
long imageHeapSize = getReadOnlyHuge().getStartOffset() + getReadOnlyHuge().getSize() - heapStartOffset;
244-
return new ImageHeapLayoutInfo(writableBeginOffset, writableSize, getReadOnlyRelocatable().getStartOffset(), getReadOnlyRelocatable().getSize(), imageHeapSize);
216+
long writableSize = writableEnd - offsetOfFirstWritableAlignedChunk;
217+
long imageHeapSize = getReadOnlyHuge().getStartOffset() + getReadOnlyHuge().getSize() - startOffset;
218+
return new ImageHeapLayoutInfo(startOffset, offsetOfFirstWritableAlignedChunk, writableSize, getReadOnlyRelocatable().getStartOffset(), getReadOnlyRelocatable().getSize(), imageHeapSize);
245219
}
246220

247221
@Override

Diff for: substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/graal/GenScavengeGCFeature.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
142142

143143
@Override
144144
public void afterAnalysis(AfterAnalysisAccess access) {
145-
ImageHeapLayouter heapLayouter = new ChunkedImageHeapLayouter(HeapImpl.getFirstImageHeapInfo(), 0);
145+
ImageHeapLayouter heapLayouter = new ChunkedImageHeapLayouter(HeapImpl.getFirstImageHeapInfo(), Heap.getHeap().getImageHeapOffsetInAddressSpace());
146146
ImageSingletons.add(ImageHeapLayouter.class, heapLayouter);
147147
}
148148

Diff for: substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/image/ImageHeapLayoutInfo.java

+16-9
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,32 @@
2727
import com.oracle.svm.core.BuildPhaseProvider.AfterHeapLayout;
2828
import com.oracle.svm.core.heap.UnknownPrimitiveField;
2929

30+
/** Layout offsets and sizes. All offsets are relative to the heap base. */
3031
public class ImageHeapLayoutInfo {
32+
@UnknownPrimitiveField(availability = AfterHeapLayout.class) private final long startOffset;
33+
@UnknownPrimitiveField(availability = AfterHeapLayout.class) private final long imageHeapSize;
34+
3135
@UnknownPrimitiveField(availability = AfterHeapLayout.class) private final long writableOffset;
3236
@UnknownPrimitiveField(availability = AfterHeapLayout.class) private final long writableSize;
3337

3438
@UnknownPrimitiveField(availability = AfterHeapLayout.class) private final long readOnlyRelocatableOffset;
3539
@UnknownPrimitiveField(availability = AfterHeapLayout.class) private final long readOnlyRelocatableSize;
3640

37-
@UnknownPrimitiveField(availability = AfterHeapLayout.class) private final long imageHeapSize;
38-
39-
public ImageHeapLayoutInfo(long writableOffset, long writableSize, long readOnlyRelocatableOffset, long readOnlyRelocatableSize, long imageHeapSize) {
41+
public ImageHeapLayoutInfo(long startOffset, long writableOffset, long writableSize, long readOnlyRelocatableOffset, long readOnlyRelocatableSize, long imageHeapSize) {
42+
this.startOffset = startOffset;
43+
this.imageHeapSize = imageHeapSize;
4044
this.writableOffset = writableOffset;
4145
this.writableSize = writableSize;
4246
this.readOnlyRelocatableOffset = readOnlyRelocatableOffset;
4347
this.readOnlyRelocatableSize = readOnlyRelocatableSize;
44-
this.imageHeapSize = imageHeapSize;
48+
}
49+
50+
public long getStartOffset() {
51+
return startOffset;
52+
}
53+
54+
public long getImageHeapSize() {
55+
return imageHeapSize;
4556
}
4657

4758
public long getWritableOffset() {
@@ -60,11 +71,7 @@ public long getReadOnlyRelocatableSize() {
6071
return readOnlyRelocatableSize;
6172
}
6273

63-
public boolean isReadOnlyRelocatable(int offset) {
74+
public boolean isReadOnlyRelocatable(long offset) {
6475
return offset >= readOnlyRelocatableOffset && offset < readOnlyRelocatableOffset + readOnlyRelocatableSize;
6576
}
66-
67-
public long getImageHeapSize() {
68-
return imageHeapSize;
69-
}
7077
}

Diff for: substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/image/ImageHeapLayouter.java

+1-11
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,12 @@
2626

2727
import java.nio.ByteBuffer;
2828

29-
import com.oracle.svm.core.heap.Heap;
30-
3129
/**
3230
* This class is responsible for computing and storing the layout of the native image heap. A native
3331
* image heap consist of multiple {@link ImageHeapPartition}s. Every object in the native image heap
3432
* is assigned to a position within a {@link ImageHeapPartition}.
3533
*/
3634
public interface ImageHeapLayouter {
37-
/**
38-
* The offset of this image heap relative to the start of the first image heap (which itself is
39-
* not the same as the heap base, see {@link Heap#getImageHeapOffsetInAddressSpace}).
40-
*/
41-
long getStartOffset();
42-
4335
/**
4436
* Returns all native image heap partitions.
4537
*/
@@ -51,9 +43,7 @@ public interface ImageHeapLayouter {
5143
void assignObjectToPartition(ImageHeapObject info, boolean immutable, boolean references, boolean relocatable);
5244

5345
/**
54-
* This method places all heap partitions as one contiguous memory block in one section. After
55-
* calling that method, all native image heap objects are assigned their final address. This
56-
* address must not change anymore.
46+
* Places all heap partitions and assigns objects their final offsets.
5747
*/
5848
ImageHeapLayoutInfo layout(ImageHeap imageHeap, int pageSize);
5949

Diff for: substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/image/ImageHeapObject.java

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public interface ImageHeapObject {
3939

4040
void setOffsetInPartition(long value);
4141

42+
/** Returns the heap-base relative offset of this object. */
4243
long getOffset();
4344

4445
ImageHeapPartition getPartition();

Diff for: substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/LIRNativeImageCodeCache.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@
3434
import java.util.stream.StreamSupport;
3535

3636
import org.graalvm.collections.Pair;
37-
import jdk.graal.compiler.code.CompilationResult;
38-
import jdk.graal.compiler.code.CompilationResult.CodeAnnotation;
39-
import jdk.graal.compiler.core.common.NumUtil;
40-
import jdk.graal.compiler.debug.DebugContext;
41-
import jdk.graal.compiler.debug.Indent;
4237

4338
import com.oracle.graal.pointsto.BigBang;
4439
import com.oracle.objectfile.ObjectFile;
@@ -52,6 +47,11 @@
5247
import com.oracle.svm.hosted.image.NativeImageHeap.ObjectInfo;
5348
import com.oracle.svm.hosted.meta.HostedMethod;
5449

50+
import jdk.graal.compiler.code.CompilationResult;
51+
import jdk.graal.compiler.code.CompilationResult.CodeAnnotation;
52+
import jdk.graal.compiler.core.common.NumUtil;
53+
import jdk.graal.compiler.debug.DebugContext;
54+
import jdk.graal.compiler.debug.Indent;
5555
import jdk.vm.ci.code.TargetDescription;
5656
import jdk.vm.ci.code.site.Call;
5757
import jdk.vm.ci.code.site.ConstantReference;
@@ -356,7 +356,7 @@ public void patchMethods(DebugContext debug, RelocatableBuffer relocs, ObjectFil
356356
HostedImageHeapConstantPatch patch = (HostedImageHeapConstantPatch) codeAnnotation;
357357

358358
ObjectInfo objectInfo = imageHeap.getConstantInfo(patch.constant);
359-
long objectAddress = objectInfo.getAddress();
359+
long objectAddress = objectInfo.getOffset();
360360

361361
if (targetCode == null) {
362362
targetCode = ByteBuffer.wrap(compilation.getTargetCode()).order(target.arch.getByteOrder());

Diff for: substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImage.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -470,16 +470,17 @@ public void build(String imageName, DebugContext debug) {
470470
heapSection = objectFile.newProgbitsSection(SectionName.SVM_HEAP.getFormatDependentName(objectFile.getFormat()), alignment, writable, false, heapSectionImpl);
471471
objectFile.createDefinedSymbol(heapSection.getName(), heapSection, 0, 0, false, false);
472472

473-
long offsetOfARelocatablePointer = writer.writeHeap(debug, heapSectionBuffer);
474-
assert !SubstrateOptions.SpawnIsolates.getValue() || heapSectionBuffer.getByteBuffer().getLong((int) offsetOfARelocatablePointer) == 0L;
473+
long sectionOffsetOfARelocatablePointer = writer.writeHeap(debug, heapSectionBuffer);
474+
assert !SubstrateOptions.SpawnIsolates.getValue() || heapSectionBuffer.getByteBuffer().getLong((int) sectionOffsetOfARelocatablePointer) == 0L;
475475

476476
defineDataSymbol(Isolates.IMAGE_HEAP_BEGIN_SYMBOL_NAME, heapSection, 0);
477477
defineDataSymbol(Isolates.IMAGE_HEAP_END_SYMBOL_NAME, heapSection, imageHeapSize);
478-
defineDataSymbol(Isolates.IMAGE_HEAP_RELOCATABLE_BEGIN_SYMBOL_NAME, heapSection, heapLayout.getReadOnlyRelocatableOffset());
479-
defineDataSymbol(Isolates.IMAGE_HEAP_RELOCATABLE_END_SYMBOL_NAME, heapSection, heapLayout.getReadOnlyRelocatableOffset() + heapLayout.getReadOnlyRelocatableSize());
480-
defineDataSymbol(Isolates.IMAGE_HEAP_A_RELOCATABLE_POINTER_SYMBOL_NAME, heapSection, offsetOfARelocatablePointer);
481-
defineDataSymbol(Isolates.IMAGE_HEAP_WRITABLE_BEGIN_SYMBOL_NAME, heapSection, heapLayout.getWritableOffset());
482-
defineDataSymbol(Isolates.IMAGE_HEAP_WRITABLE_END_SYMBOL_NAME, heapSection, heapLayout.getWritableOffset() + heapLayout.getWritableSize());
478+
defineDataSymbol(Isolates.IMAGE_HEAP_RELOCATABLE_BEGIN_SYMBOL_NAME, heapSection, heapLayout.getReadOnlyRelocatableOffset() - heapLayout.getStartOffset());
479+
defineDataSymbol(Isolates.IMAGE_HEAP_RELOCATABLE_END_SYMBOL_NAME, heapSection,
480+
heapLayout.getReadOnlyRelocatableOffset() + heapLayout.getReadOnlyRelocatableSize() - heapLayout.getStartOffset());
481+
defineDataSymbol(Isolates.IMAGE_HEAP_A_RELOCATABLE_POINTER_SYMBOL_NAME, heapSection, sectionOffsetOfARelocatablePointer);
482+
defineDataSymbol(Isolates.IMAGE_HEAP_WRITABLE_BEGIN_SYMBOL_NAME, heapSection, heapLayout.getWritableOffset() - heapLayout.getStartOffset());
483+
defineDataSymbol(Isolates.IMAGE_HEAP_WRITABLE_END_SYMBOL_NAME, heapSection, heapLayout.getWritableOffset() + heapLayout.getWritableSize() - heapLayout.getStartOffset());
483484

484485
// Mark the sections with the relocations from the maps.
485486
markRelocationSitesFromBuffer(textBuffer, textImpl);
@@ -625,8 +626,7 @@ private void markDataRelocationSite(ProgbitsSectionImpl sectionImpl, int offset,
625626
assert ConfigurationValues.getTarget().arch instanceof AArch64 || info.getRelocationSize() == 4 || info.getRelocationSize() == 8 : "AMD64 Data relocation size should be 4 or 8 bytes.";
626627
assert targetObjectInfo != null;
627628
String targetSectionName = heapSection.getName();
628-
long address = targetObjectInfo.getAddress();
629-
long relocationAddend = address + info.getAddend();
629+
long relocationAddend = targetObjectInfo.getOffset() + info.getAddend();
630630
sectionImpl.markRelocationSite(offset, info.getRelocationKind(), targetSectionName, relocationAddend);
631631
}
632632

@@ -661,7 +661,7 @@ private void markDataRelocationSiteFromText(RelocatableBuffer buffer, final Prog
661661
} else if (target instanceof ConstantReference) {
662662
// Direct object reference in code that must be patched (not a linker relocation)
663663
JavaConstant constant = (JavaConstant) ((ConstantReference) target).getConstant();
664-
long address = heap.getConstantInfo(constant).getAddress();
664+
long address = heap.getConstantInfo(constant).getOffset();
665665
int encShift = ImageSingletons.lookup(CompressEncoding.class).getShift();
666666
long targetValue = address >>> encShift;
667667
assert (targetValue << encShift) == address : "Reference compression shift discards non-zero bits: " + Long.toHexString(address);

Diff for: substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageDebugInfoProvider.java

-5
Original file line numberDiff line numberDiff line change
@@ -2622,11 +2622,6 @@ public long getOffset() {
26222622
return objectInfo.getOffset();
26232623
}
26242624

2625-
@Override
2626-
public long getAddress() {
2627-
return objectInfo.getAddress();
2628-
}
2629-
26302625
@Override
26312626
public long getSize() {
26322627
return objectInfo.getSize();

Diff for: substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageDebugInfoProviderBase.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ public NativeImageDebugInfoProviderBase(NativeImageCodeCache codeCache, NativeIm
118118
this.referenceSize = getObjectLayout().getReferenceSize();
119119
this.referenceAlignment = getObjectLayout().getAlignment();
120120
/* Offsets need to be adjusted relative to the heap base plus partition-specific offset. */
121-
primitiveStartOffset = (int) primitiveFields.getAddress();
122-
referenceStartOffset = (int) objectFields.getAddress();
121+
primitiveStartOffset = (int) primitiveFields.getOffset();
122+
referenceStartOffset = (int) objectFields.getOffset();
123123
javaKindToHostedType = initJavaKindToHostedTypes(metaAccess);
124124
}
125125

@@ -408,7 +408,7 @@ public long objectOffset(JavaConstant constant) {
408408
assert constant.getJavaKind() == JavaKind.Object && !constant.isNull() : "invalid constant for object offset lookup";
409409
NativeImageHeap.ObjectInfo objectInfo = heap.getConstantInfo(constant);
410410
if (objectInfo != null) {
411-
return objectInfo.getAddress();
411+
return objectInfo.getOffset();
412412
}
413413
return -1;
414414
}

0 commit comments

Comments
 (0)