62 */
63 private final int id;
64
65 private final AOTCompiledClass holder;
66
67 /**
68 * Method this task represents.
69 */
70 private final ResolvedJavaMethod method;
71
72 private final AOTBackend aotBackend;
73
74 /**
75 * The result of this compilation task.
76 */
77 private CompiledMethodInfo result;
78
79 public AOTCompilationTask(Main main, OptionValues graalOptions, AOTCompiledClass holder, ResolvedJavaMethod method, AOTBackend aotBackend) {
80 this.main = main;
81 this.graalOptions = graalOptions;
82 this.id = ids.getAndIncrement();
83 this.holder = holder;
84 this.method = method;
85 this.aotBackend = aotBackend;
86 }
87
88 /**
89 * Compile a method or a constructor.
90 */
91 public void run() {
92 // Ensure a JVMCI runtime is initialized prior to Debug being initialized as the former
93 // may include processing command line options used by the latter.
94 HotSpotJVMCIRuntime.runtime();
95
96 // Ensure a debug configuration for this thread is initialized
97 if (Debug.isEnabled() && DebugScope.getConfig() == null) {
98 DebugEnvironment.ensureInitialized(graalOptions);
99 }
100 AOTCompiler.logCompilation(MiscUtils.uniqueMethodName(method), "Compiling");
101
102 final long threadId = Thread.currentThread().getId();
110 final long start;
111 final long allocatedBytesBefore;
112 if (printAfterCompilation || printCompilation) {
113 start = System.currentTimeMillis();
114 allocatedBytesBefore = printAfterCompilation || printCompilation ? threadMXBean.getThreadAllocatedBytes(threadId) : 0L;
115 } else {
116 start = 0L;
117 allocatedBytesBefore = 0L;
118 }
119
120 final long startTime = System.currentTimeMillis();
121 CompilationResult compResult = aotBackend.compileMethod(method);
122 final long endTime = System.currentTimeMillis();
123
124 if (printAfterCompilation || printCompilation) {
125 final long stop = System.currentTimeMillis();
126 final int targetCodeSize = compResult != null ? compResult.getTargetCodeSize() : -1;
127 final long allocatedBytesAfter = threadMXBean.getThreadAllocatedBytes(threadId);
128 final long allocatedBytes = (allocatedBytesAfter - allocatedBytesBefore) / 1024;
129
130 if (printAfterCompilation) {
131 TTY.println(getMethodDescription() + String.format(" | %4dms %5dB %5dkB", stop - start, targetCodeSize, allocatedBytes));
132 } else if (printCompilation) {
133 TTY.println(String.format("%-6d JVMCI %-70s %-45s %-50s | %4dms %5dB %5dkB", getId(), "", "", "", stop - start, targetCodeSize, allocatedBytes));
134 }
135 }
136
137 if (compResult == null) {
138 result = null;
139 return;
140 }
141
142 // For now precision to the nearest second is sufficient.
143 Main.writeLog(" Compile Time: " + TimeUnit.MILLISECONDS.toSeconds(endTime - startTime) + "secs");
144 if (main.options.debug) {
145 aotBackend.printCompiledMethod((HotSpotResolvedJavaMethod) method, compResult);
146 }
147
148 result = new CompiledMethodInfo(compResult, new AOTHotSpotResolvedJavaMethod((HotSpotResolvedJavaMethod) method, aotBackend.getBackend()));
149 }
150
151 private String getMethodDescription() {
152 return String.format("%-6d JVMCI %-70s %-45s %-50s %s", getId(), method.getDeclaringClass().getName(), method.getName(), method.getSignature().toMethodDescriptor(),
153 getEntryBCI() == JVMCICompiler.INVOCATION_ENTRY_BCI ? "" : "(OSR@" + getEntryBCI() + ") ");
154 }
155
156 private int getId() {
157 return id;
158 }
159
160 public int getEntryBCI() {
161 return JVMCICompiler.INVOCATION_ENTRY_BCI;
162 }
163
164 public ResolvedJavaMethod getMethod() {
165 return method;
166 }
167
168 /**
169 * Returns the holder of this method as a {@link AOTCompiledClass}.
170 *
171 * @return the holder of this method
172 */
|
62 */
63 private final int id;
64
65 private final AOTCompiledClass holder;
66
67 /**
68 * Method this task represents.
69 */
70 private final ResolvedJavaMethod method;
71
72 private final AOTBackend aotBackend;
73
74 /**
75 * The result of this compilation task.
76 */
77 private CompiledMethodInfo result;
78
79 public AOTCompilationTask(Main main, OptionValues graalOptions, AOTCompiledClass holder, ResolvedJavaMethod method, AOTBackend aotBackend) {
80 this.main = main;
81 this.graalOptions = graalOptions;
82 this.id = ids.incrementAndGet();
83 this.holder = holder;
84 this.method = method;
85 this.aotBackend = aotBackend;
86 }
87
88 /**
89 * Compile a method or a constructor.
90 */
91 public void run() {
92 // Ensure a JVMCI runtime is initialized prior to Debug being initialized as the former
93 // may include processing command line options used by the latter.
94 HotSpotJVMCIRuntime.runtime();
95
96 // Ensure a debug configuration for this thread is initialized
97 if (Debug.isEnabled() && DebugScope.getConfig() == null) {
98 DebugEnvironment.ensureInitialized(graalOptions);
99 }
100 AOTCompiler.logCompilation(MiscUtils.uniqueMethodName(method), "Compiling");
101
102 final long threadId = Thread.currentThread().getId();
110 final long start;
111 final long allocatedBytesBefore;
112 if (printAfterCompilation || printCompilation) {
113 start = System.currentTimeMillis();
114 allocatedBytesBefore = printAfterCompilation || printCompilation ? threadMXBean.getThreadAllocatedBytes(threadId) : 0L;
115 } else {
116 start = 0L;
117 allocatedBytesBefore = 0L;
118 }
119
120 final long startTime = System.currentTimeMillis();
121 CompilationResult compResult = aotBackend.compileMethod(method);
122 final long endTime = System.currentTimeMillis();
123
124 if (printAfterCompilation || printCompilation) {
125 final long stop = System.currentTimeMillis();
126 final int targetCodeSize = compResult != null ? compResult.getTargetCodeSize() : -1;
127 final long allocatedBytesAfter = threadMXBean.getThreadAllocatedBytes(threadId);
128 final long allocatedBytes = (allocatedBytesAfter - allocatedBytesBefore) / 1024;
129
130 TTY.println(getMethodDescription() + String.format(" | %4dms %5dB %5dkB", stop - start, targetCodeSize, allocatedBytes));
131 }
132
133 if (compResult == null) {
134 result = null;
135 return;
136 }
137
138 // For now precision to the nearest second is sufficient.
139 Main.writeLog(" Compile Time: " + TimeUnit.MILLISECONDS.toSeconds(endTime - startTime) + "secs");
140 if (main.options.debug) {
141 aotBackend.printCompiledMethod((HotSpotResolvedJavaMethod) method, compResult);
142 }
143
144 result = new CompiledMethodInfo(compResult, new AOTHotSpotResolvedJavaMethod((HotSpotResolvedJavaMethod) method, aotBackend.getBackend()));
145 }
146
147 private String getMethodDescription() {
148 return String.format("%-6d aot %s %s", getId(), MiscUtils.uniqueMethodName(method),
149 getEntryBCI() == JVMCICompiler.INVOCATION_ENTRY_BCI ? "" : "(OSR@" + getEntryBCI() + ") ");
150 }
151
152 private int getId() {
153 return id;
154 }
155
156 public int getEntryBCI() {
157 return JVMCICompiler.INVOCATION_ENTRY_BCI;
158 }
159
160 public ResolvedJavaMethod getMethod() {
161 return method;
162 }
163
164 /**
165 * Returns the holder of this method as a {@link AOTCompiledClass}.
166 *
167 * @return the holder of this method
168 */
|