33
33
import static com .oracle .svm .core .Isolates .IMAGE_HEAP_WRITABLE_END ;
34
34
import static com .oracle .svm .core .Isolates .IMAGE_HEAP_WRITABLE_PATCHED_BEGIN ;
35
35
import static com .oracle .svm .core .Isolates .IMAGE_HEAP_WRITABLE_PATCHED_END ;
36
- import static com .oracle .svm .core .imagelayer .ImageLayerSection .SectionEntries .HEAP_ANY_RELOCATABLE_POINTER ;
37
36
import static com .oracle .svm .core .imagelayer .ImageLayerSection .SectionEntries .HEAP_BEGIN ;
38
37
import static com .oracle .svm .core .imagelayer .ImageLayerSection .SectionEntries .HEAP_END ;
39
38
import static com .oracle .svm .core .imagelayer .ImageLayerSection .SectionEntries .HEAP_RELOCATABLE_BEGIN ;
@@ -187,7 +186,8 @@ protected int initializeLayeredImage(Pointer firstHeapStart, Pointer selfReserve
187
186
Word heapEnd = currentSection .readWord (ImageLayerSection .getEntryOffset (HEAP_END ));
188
187
Word heapRelocBegin = currentSection .readWord (ImageLayerSection .getEntryOffset (HEAP_RELOCATABLE_BEGIN ));
189
188
Word heapRelocEnd = currentSection .readWord (ImageLayerSection .getEntryOffset (HEAP_RELOCATABLE_END ));
190
- Word heapAnyRelocPointer = currentSection .readWord (ImageLayerSection .getEntryOffset (HEAP_ANY_RELOCATABLE_POINTER ));
189
+ /* This value is not used for layered images. */
190
+ Word heapAnyRelocPointer = Word .nullPointer ();
191
191
Word heapWritableBegin = currentSection .readWord (ImageLayerSection .getEntryOffset (HEAP_WRITEABLE_BEGIN ));
192
192
Word heapWritableEnd = currentSection .readWord (ImageLayerSection .getEntryOffset (HEAP_WRITEABLE_END ));
193
193
Word heapWritablePatchedBegin = currentSection .readWord (ImageLayerSection .getEntryOffset (HEAP_WRITEABLE_PATCHED_BEGIN ));
@@ -284,7 +284,7 @@ private static int initializeImageHeap(Pointer imageHeap, UnsignedWord reservedS
284
284
Word heapWritablePatchedEndSym , Word heapWritableSym , Word heapWritableEndSym ) {
285
285
assert heapBeginSym .belowOrEqual (heapWritableSym ) && heapWritableSym .belowOrEqual (heapWritableEndSym ) && heapWritableEndSym .belowOrEqual (heapEndSym );
286
286
assert heapBeginSym .belowOrEqual (heapRelocsSym ) && heapRelocsSym .belowOrEqual (heapRelocsEndSym ) && heapRelocsEndSym .belowOrEqual (heapEndSym );
287
- assert heapRelocsSym .belowOrEqual (heapAnyRelocPointer ) && heapAnyRelocPointer .belowThan (heapRelocsEndSym );
287
+ assert ImageLayerBuildingSupport . buildingImageLayer () || heapRelocsSym .belowOrEqual (heapAnyRelocPointer ) && heapAnyRelocPointer .belowThan (heapRelocsEndSym );
288
288
assert heapRelocsSym .belowOrEqual (heapRelocsEndSym ) && heapRelocsEndSym .belowOrEqual (heapWritablePatchedSym ) && heapWritablePatchedSym .belowOrEqual (heapWritableEndSym );
289
289
290
290
SignedWord fd = cachedFd .read ();
@@ -444,14 +444,26 @@ private static int copyRelocations(Pointer imageHeap, UnsignedWord pageSize, Wor
444
444
Pointer sourceRelocsBoundary = cachedRelocsBoundary .isNonNull () ? cachedRelocsBoundary : linkedRelocsBoundary ;
445
445
Pointer linkedCopyStart = Word .nullPointer ();
446
446
if (heapRelocsEndSym .subtract (heapRelocsSym ).isNonNull ()) {
447
- /*
448
- * Use a representative pointer to determine whether it is necessary to copy over the
449
- * relocations from the original image, or if it has already been performed during
450
- * build-link time.
451
- */
452
- ComparableWord relocatedValue = sourceRelocsBoundary .readWord (heapAnyRelocPointer .subtract (linkedRelocsBoundary ));
453
- ComparableWord mappedValue = imageHeap .readWord (heapAnyRelocPointer .subtract (heapBeginSym ));
454
- if (relocatedValue .notEqual (mappedValue )) {
447
+ boolean copyRequired ;
448
+ if (ImageLayerBuildingSupport .buildingImageLayer ()) {
449
+ assert heapAnyRelocPointer .isNull ();
450
+ /*
451
+ * The relocatable section with layered images will normally contain relocations
452
+ * referring to both the same and different layers. Hence, it is not possible to use
453
+ * a representative pointer to determine whether copying is necessary.
454
+ */
455
+ copyRequired = true ;
456
+ } else {
457
+ /*
458
+ * Use a representative pointer to determine whether it is necessary to copy over
459
+ * the relocations from the original image, or if it has already been performed
460
+ * during build-link time.
461
+ */
462
+ ComparableWord relocatedValue = sourceRelocsBoundary .readWord (heapAnyRelocPointer .subtract (linkedRelocsBoundary ));
463
+ ComparableWord mappedValue = imageHeap .readWord (heapAnyRelocPointer .subtract (heapBeginSym ));
464
+ copyRequired = relocatedValue .notEqual (mappedValue );
465
+ }
466
+ if (copyRequired ) {
455
467
linkedCopyStart = heapRelocsSym ;
456
468
}
457
469
}
@@ -464,14 +476,17 @@ private static int copyRelocations(Pointer imageHeap, UnsignedWord pageSize, Wor
464
476
}
465
477
if (linkedCopyStart .isNonNull ()) {
466
478
/*
467
- * A portion of the image heap has relocations either resolved by the dynamic linker or
468
- * (for layered images) manually during our runtime initialization code. To preserve the
469
- * relocations, we must copy this code directly from the original image heap and not
470
- * reload it from disk.
479
+ * A portion of the image heap needs to be manually copied over from the original image.
480
+ * This is needed whenever:
481
+ *
482
+ * 1. Relocations resolved by the dynamic linker are present.
483
+ *
484
+ * 2. (For layered images only): Heap relative relocations are present (i.e. the
485
+ * heapWritablePatched section is non-zero).
471
486
*
472
- * We need to round to page boundaries, so we may copy some extra data which could be
473
- * copy-on-write. Also, we must first remap the pages to avoid loading them from disk
474
- * (only to then overwrite them) .
487
+ * To preserve this information, we must copy over this data from the original image
488
+ * heap and not reload it from disk. Note this copying must be performed at a page
489
+ * granularity, and hence may copy some extra data which could be copy-on-write .
475
490
*/
476
491
Pointer linkedCopyStartBoundary = roundDown (linkedCopyStart , pageSize );
477
492
UnsignedWord copyAlignedSize = roundUp (heapWritablePatchedEndSym .subtract (linkedCopyStartBoundary ), pageSize );
0 commit comments