Skip to content

Commit e707bb7

Browse files
committed
[GR-37889] Reduce memory pressure for objectFile.write.
PullRequest: graal/11651
2 parents fa742f7 + ab92936 commit e707bb7

File tree

9 files changed

+410
-364
lines changed

9 files changed

+410
-364
lines changed

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/io/AssemblyBuffer.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ public static InputDisassembler createInputDisassembler(ByteBuffer in) {
5858
return new AssemblyBuffer(in);
5959
}
6060

61-
public static OutputAssembler createOutputAssembler(ByteBuffer out) {
61+
public static AssemblyBuffer createOutputAssembler(ByteBuffer out) {
6262
return new AssemblyBuffer(out);
6363
}
6464

65-
public static OutputAssembler createOutputAssembler(ByteOrder order) {
65+
public static AssemblyBuffer createOutputAssembler(ByteOrder order) {
6666
return new AssemblyBuffer(order);
6767
}
6868

69-
public static OutputAssembler createOutputAssembler() {
69+
public static AssemblyBuffer createOutputAssembler() {
7070
return new AssemblyBuffer();
7171
}
7272

@@ -280,23 +280,24 @@ private void ensure(int n) {
280280
}
281281

282282
// grow and replace
283-
ByteBuffer nbuf = ByteBuffer.allocate(newCap);
284-
nbuf.order(ByteOrder.nativeOrder());
285-
byte[] old = new byte[pos];
286-
buf.rewind();
287-
buf.get(old);
288-
nbuf.put(old);
289-
buf = nbuf;
283+
buf = ByteBuffer.wrap(Arrays.copyOf(buf.array(), newCap));
284+
buf.order(ByteOrder.nativeOrder());
285+
buf.position(pos);
290286
}
291287
}
292288

293289
@Override
294290
public byte[] getBlob() {
295-
int len = buf.position();
296-
byte[] bytes = new byte[len];
297-
buf.position(0);
298-
buf.get(bytes);
299-
return bytes;
291+
return getBlob(false);
292+
}
293+
294+
public byte[] getBlob(boolean consume) {
295+
byte[] array = buf.array();
296+
int position = buf.position();
297+
if (consume) {
298+
buf = null;
299+
}
300+
return Arrays.copyOf(array, position);
300301
}
301302

302303
@Override

substratevm/src/com.oracle.svm.core.graal.llvm/src/com/oracle/svm/core/graal/llvm/LLVMNativeImageCodeCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ public Path[] getCCInputFiles(Path tempDirectory, String imageName) {
457457
}
458458

459459
@Override
460-
public List<ObjectFile.Symbol> getSymbols(ObjectFile objectFile, boolean onlyGlobal) {
460+
public List<ObjectFile.Symbol> getSymbols(ObjectFile objectFile) {
461461
return globalSymbols;
462462
}
463463

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,13 @@ private void doRun(Map<Method, CEntryPointData> entryPoints,
679679
}
680680
}
681681

682+
ProgressReporter.CenteredTextPrinter breakdownsPrinter = SubstrateOptions.BuildOutputBreakdowns.getValue()
683+
? ProgressReporter.singleton().createBreakdowns(compileQueue.getCompilationTasks(), image.getHeap().getObjects())
684+
: null;
685+
compileQueue.purge();
686+
687+
int numCompilations = codeCache.getCompilations().size();
688+
682689
try (StopTimer t = TimerCollection.createTimerAndStart(TimerCollection.Registry.WRITE)) {
683690
bb.getHeartbeatCallback().run();
684691
BeforeImageWriteAccessImpl beforeConfig = new BeforeImageWriteAccessImpl(featureHandler, loader, imageName, image,
@@ -701,9 +708,9 @@ private void doRun(Map<Method, CEntryPointData> entryPoints,
701708
featureHandler.forEachFeature(feature -> feature.afterImageWrite(afterConfig));
702709
}
703710
reporter.printCreationEnd(image.getImageSize(), bb.getUniverse(), heap.getObjectCount(), image.getImageHeapSize(), codeCache.getCodeCacheSize(),
704-
codeCache.getCompilations().size(), image.getDebugInfoSize());
705-
if (SubstrateOptions.BuildOutputBreakdowns.getValue()) {
706-
ProgressReporter.singleton().printBreakdowns(compileQueue.getCompilationTasks(), image.getHeap().getObjects());
711+
numCompilations, image.getDebugInfoSize());
712+
if (breakdownsPrinter != null) {
713+
breakdownsPrinter.reset().flushln();
707714
}
708715
}
709716
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ public void ensureCreationStageEndCompleted() {
412412
}
413413
}
414414

415-
public void printBreakdowns(Collection<CompileTask> compilationTasks, Collection<ObjectInfo> heapObjects) {
415+
public CenteredTextPrinter createBreakdowns(Collection<CompileTask> compilationTasks, Collection<ObjectInfo> heapObjects) {
416416
Map<String, Long> codeBreakdown = calculateCodeBreakdown(compilationTasks);
417417
Map<String, Long> heapBreakdown = calculateHeapBreakdown(heapObjects);
418418
l().printLineSeparator();
@@ -458,9 +458,8 @@ public void printBreakdowns(Collection<CompileTask> compilationTasks, Collection
458458
.jumpToMiddle()
459459
.a(" ... ").a(numHeapBreakdownItems - printedCodeSizeEntries.size()).a(" additional object types").flushln();
460460

461-
new CenteredTextPrinter().dim()
462-
.a("(use ").link("GraalVM Dashboard", "https://www.graalvm.org/dashboard/?ojr=help%3Btopic%3Dgetting-started.md").a(" to see all)")
463-
.reset().flushln();
461+
return new CenteredTextPrinter().dim()
462+
.a("(use ").link("GraalVM Dashboard", "https://www.graalvm.org/dashboard/?ojr=help%3Btopic%3Dgetting-started.md").a(" to see all)");
464463
}
465464

466465
private static Map<String, Long> calculateCodeBreakdown(Collection<CompileTask> compilationTasks) {

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CompileQueue.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,10 @@ public Map<HostedMethod, CompileTask> getCompilations() {
479479
return compilations;
480480
}
481481

482+
public void purge() {
483+
compilations.clear();
484+
}
485+
482486
public Collection<CompileTask> getCompilationTasks() {
483487
return compilations.values();
484488
}

0 commit comments

Comments
 (0)