Skip to content

Commit

Permalink
[GR-37889] Reduce memory pressure for objectFile.write.
Browse files Browse the repository at this point in the history
PullRequest: graal/11651
  • Loading branch information
olpaw committed May 2, 2022
2 parents fa742f7 + ab92936 commit e707bb7
Show file tree
Hide file tree
Showing 9 changed files with 410 additions and 364 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ public static InputDisassembler createInputDisassembler(ByteBuffer in) {
return new AssemblyBuffer(in);
}

public static OutputAssembler createOutputAssembler(ByteBuffer out) {
public static AssemblyBuffer createOutputAssembler(ByteBuffer out) {
return new AssemblyBuffer(out);
}

public static OutputAssembler createOutputAssembler(ByteOrder order) {
public static AssemblyBuffer createOutputAssembler(ByteOrder order) {
return new AssemblyBuffer(order);
}

public static OutputAssembler createOutputAssembler() {
public static AssemblyBuffer createOutputAssembler() {
return new AssemblyBuffer();
}

Expand Down Expand Up @@ -280,23 +280,24 @@ private void ensure(int n) {
}

// grow and replace
ByteBuffer nbuf = ByteBuffer.allocate(newCap);
nbuf.order(ByteOrder.nativeOrder());
byte[] old = new byte[pos];
buf.rewind();
buf.get(old);
nbuf.put(old);
buf = nbuf;
buf = ByteBuffer.wrap(Arrays.copyOf(buf.array(), newCap));
buf.order(ByteOrder.nativeOrder());
buf.position(pos);
}
}

@Override
public byte[] getBlob() {
int len = buf.position();
byte[] bytes = new byte[len];
buf.position(0);
buf.get(bytes);
return bytes;
return getBlob(false);
}

public byte[] getBlob(boolean consume) {
byte[] array = buf.array();
int position = buf.position();
if (consume) {
buf = null;
}
return Arrays.copyOf(array, position);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ public Path[] getCCInputFiles(Path tempDirectory, String imageName) {
}

@Override
public List<ObjectFile.Symbol> getSymbols(ObjectFile objectFile, boolean onlyGlobal) {
public List<ObjectFile.Symbol> getSymbols(ObjectFile objectFile) {
return globalSymbols;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,13 @@ private void doRun(Map<Method, CEntryPointData> entryPoints,
}
}

ProgressReporter.CenteredTextPrinter breakdownsPrinter = SubstrateOptions.BuildOutputBreakdowns.getValue()
? ProgressReporter.singleton().createBreakdowns(compileQueue.getCompilationTasks(), image.getHeap().getObjects())
: null;
compileQueue.purge();

int numCompilations = codeCache.getCompilations().size();

try (StopTimer t = TimerCollection.createTimerAndStart(TimerCollection.Registry.WRITE)) {
bb.getHeartbeatCallback().run();
BeforeImageWriteAccessImpl beforeConfig = new BeforeImageWriteAccessImpl(featureHandler, loader, imageName, image,
Expand All @@ -701,9 +708,9 @@ private void doRun(Map<Method, CEntryPointData> entryPoints,
featureHandler.forEachFeature(feature -> feature.afterImageWrite(afterConfig));
}
reporter.printCreationEnd(image.getImageSize(), bb.getUniverse(), heap.getObjectCount(), image.getImageHeapSize(), codeCache.getCodeCacheSize(),
codeCache.getCompilations().size(), image.getDebugInfoSize());
if (SubstrateOptions.BuildOutputBreakdowns.getValue()) {
ProgressReporter.singleton().printBreakdowns(compileQueue.getCompilationTasks(), image.getHeap().getObjects());
numCompilations, image.getDebugInfoSize());
if (breakdownsPrinter != null) {
breakdownsPrinter.reset().flushln();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ public void ensureCreationStageEndCompleted() {
}
}

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

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

private static Map<String, Long> calculateCodeBreakdown(Collection<CompileTask> compilationTasks) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,10 @@ public Map<HostedMethod, CompileTask> getCompilations() {
return compilations;
}

public void purge() {
compilations.clear();
}

public Collection<CompileTask> getCompilationTasks() {
return compilations.values();
}
Expand Down
Loading

0 comments on commit e707bb7

Please sign in to comment.