# HG changeset patch # User twisti # Date 1395790648 25200 # Node ID b5cdbf6d793af9d60b45312a1cd60cee18830252 # Parent 311bf6c7488b46f974293313107ed888c8ca5cb7 print total allocated bytes for compilations diff -r 311bf6c7488b -r b5cdbf6d793a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Tue Mar 25 16:25:02 2014 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Tue Mar 25 16:37:28 2014 -0700 @@ -31,6 +31,7 @@ import static com.oracle.graal.phases.common.InliningUtil.*; import java.io.*; +import java.lang.management.*; import java.lang.reflect.*; import java.util.*; import java.util.concurrent.*; @@ -106,6 +107,12 @@ private boolean blocking; + /** + * A {@link com.sun.management.ThreadMXBean} to be able to query some information about the + * current compiler thread, e.g. total allocated bytes. + */ + private final com.sun.management.ThreadMXBean threadMXBean = (com.sun.management.ThreadMXBean) ManagementFactory.getThreadMXBean(); + public CompilationTask(HotSpotBackend backend, HotSpotResolvedJavaMethod method, int entryBCI, boolean blocking) { this.backend = backend; this.method = method; @@ -208,9 +215,11 @@ */ HotSpotVMConfig config = backend.getRuntime().getConfig(); + final long threadId = Thread.currentThread().getId(); long previousInlinedBytecodes = InlinedBytecodes.getCurrentValue(); long previousCompilationTime = CompilationTime.getCurrentValue(); HotSpotInstalledCode installedCode = null; + try (TimerCloseable a = CompilationTime.start()) { if (!tryToChangeStatus(CompilationStatus.Queued, CompilationStatus.Running)) { return; @@ -235,7 +244,9 @@ CompilationResult result = null; TTY.Filter filter = new TTY.Filter(PrintFilter.getValue(), method); - long start = System.currentTimeMillis(); + final long start = System.currentTimeMillis(); + final long allocatedBytesBefore = threadMXBean.getThreadAllocatedBytes(threadId); + try (Scope s = Debug.scope("Compiling", new DebugDumpScope(String.valueOf(id), true))) { Map graphCache = null; if (GraalOptions.CacheGraphs.getValue()) { @@ -272,10 +283,18 @@ } finally { filter.remove(); final boolean printAfterCompilation = PrintAfterCompilation.getValue() && !TTY.isSuppressed(); - if (printAfterCompilation) { - TTY.println(getMethodDescription() + String.format(" | %4dms %5dB", System.currentTimeMillis() - start, (result != null ? result.getTargetCodeSize() : -1))); - } else if (printCompilation) { - TTY.println(String.format("%-6d Graal %-70s %-45s %-50s | %4dms %5dB", id, "", "", "", System.currentTimeMillis() - start, (result != null ? result.getTargetCodeSize() : -1))); + + if (printAfterCompilation || printCompilation) { + final long stop = System.currentTimeMillis(); + final int targetCodeSize = result != null ? result.getTargetCodeSize() : -1; + final long allocatedBytesAfter = threadMXBean.getThreadAllocatedBytes(threadId); + final long allocatedBytes = (allocatedBytesAfter - allocatedBytesBefore) / 1024; + + if (printAfterCompilation) { + TTY.println(getMethodDescription() + String.format(" | %4dms %5dB %5dkB", stop - start, targetCodeSize, allocatedBytes)); + } else if (printCompilation) { + TTY.println(String.format("%-6d Graal %-70s %-45s %-50s | %4dms %5dB %5dkB", id, "", "", "", stop - start, targetCodeSize, allocatedBytes)); + } } }