13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25
26 package jdk.tools.jaotc;
27
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 import java.util.List;
31 import java.util.Map.Entry;
32
33 import jdk.tools.jaotc.binformat.BinaryContainer;
34 import jdk.tools.jaotc.binformat.ByteContainer;
35 import jdk.tools.jaotc.binformat.HeaderContainer;
36
37 import org.graalvm.compiler.code.CompilationResult;
38 import org.graalvm.compiler.debug.DebugContext;
39 import org.graalvm.compiler.hotspot.HotSpotHostBackend;
40 import org.graalvm.compiler.hotspot.meta.HotSpotForeignCallsProvider;
41 import org.graalvm.compiler.hotspot.stubs.Stub;
42
43 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
44 import jdk.vm.ci.hotspot.HotSpotVMConfigStore;
45 import jdk.vm.ci.hotspot.VMField;
46
47 final class DataBuilder {
48
49 private final Main main;
50
51 private final HotSpotHostBackend backend;
52
53 private final List<AOTCompiledClass> classes;
54
55 /**
56 * Target-independent container in which text symbols and code bytes are created.
57 */
58 private final BinaryContainer binaryContainer;
59
60 private static final HashMap<Long, String> vmAddresses = new HashMap<>();
61
62 DataBuilder(Main main, HotSpotHostBackend backend, List<AOTCompiledClass> classes, BinaryContainer binaryContainer) {
173 prepareStubsBinary(stubCompiledCode);
174 }
175 try (Timer t = new Timer(main, "Preparing compiled binary")) {
176 // Should be called after Stubs because they can set dependent klasses.
177 prepareCompiledBinary();
178 }
179 }
180
181 /**
182 * Get all stubs from Graal and add them to the code section.
183 *
184 * @param debug
185 */
186 @SuppressWarnings("try")
187 private AOTCompiledClass retrieveStubCode(DebugContext debug) {
188 ArrayList<CompiledMethodInfo> stubs = new ArrayList<>();
189 HotSpotForeignCallsProvider foreignCallsProvider = backend.getProviders().getForeignCalls();
190 for (Stub stub : foreignCallsProvider.getStubs()) {
191 try (DebugContext.Scope scope = debug.scope("CompileStubs")) {
192 CompilationResult result = stub.getCompilationResult(debug, backend);
193 CompiledMethodInfo cm = new CompiledMethodInfo(result, new AOTStub(stub, backend));
194 stubs.add(cm);
195 } catch (Throwable e) {
196 throw debug.handle(e);
197 }
198 }
199 AOTCompiledClass stubCompiledCode = new AOTCompiledClass(stubs);
200 CodeSectionProcessor codeSectionProcessor = new CodeSectionProcessor(this);
201 codeSectionProcessor.process(stubCompiledCode);
202 return stubCompiledCode;
203 }
204
205 /**
206 * Prepare metaspace.offsets section.
207 */
208 private void prepareCompiledBinary() {
209 for (AOTCompiledClass c : classes) {
210 // Create records for compiled AOT methods.
211 c.putMethodsData(binaryContainer);
212 }
213 // Create records for compiled AOT classes.
|
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25
26 package jdk.tools.jaotc;
27
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 import java.util.List;
31 import java.util.Map.Entry;
32
33 import org.graalvm.compiler.code.CompilationResult;
34 import org.graalvm.compiler.debug.DebugContext;
35 import org.graalvm.compiler.hotspot.HotSpotHostBackend;
36 import org.graalvm.compiler.hotspot.meta.HotSpotForeignCallsProvider;
37 import org.graalvm.compiler.hotspot.stubs.Stub;
38
39 import jdk.tools.jaotc.binformat.BinaryContainer;
40 import jdk.tools.jaotc.binformat.ByteContainer;
41 import jdk.tools.jaotc.binformat.HeaderContainer;
42 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
43 import jdk.vm.ci.hotspot.HotSpotVMConfigStore;
44 import jdk.vm.ci.hotspot.VMField;
45
46 final class DataBuilder {
47
48 private final Main main;
49
50 private final HotSpotHostBackend backend;
51
52 private final List<AOTCompiledClass> classes;
53
54 /**
55 * Target-independent container in which text symbols and code bytes are created.
56 */
57 private final BinaryContainer binaryContainer;
58
59 private static final HashMap<Long, String> vmAddresses = new HashMap<>();
60
61 DataBuilder(Main main, HotSpotHostBackend backend, List<AOTCompiledClass> classes, BinaryContainer binaryContainer) {
172 prepareStubsBinary(stubCompiledCode);
173 }
174 try (Timer t = new Timer(main, "Preparing compiled binary")) {
175 // Should be called after Stubs because they can set dependent klasses.
176 prepareCompiledBinary();
177 }
178 }
179
180 /**
181 * Get all stubs from Graal and add them to the code section.
182 *
183 * @param debug
184 */
185 @SuppressWarnings("try")
186 private AOTCompiledClass retrieveStubCode(DebugContext debug) {
187 ArrayList<CompiledMethodInfo> stubs = new ArrayList<>();
188 HotSpotForeignCallsProvider foreignCallsProvider = backend.getProviders().getForeignCalls();
189 for (Stub stub : foreignCallsProvider.getStubs()) {
190 try (DebugContext.Scope scope = debug.scope("CompileStubs")) {
191 CompilationResult result = stub.getCompilationResult(debug, backend);
192 CompiledMethodInfo cm = new CompiledMethodInfo(result, new AOTStub(stub, backend, debug.getOptions()));
193 stubs.add(cm);
194 } catch (Throwable e) {
195 throw debug.handle(e);
196 }
197 }
198 AOTCompiledClass stubCompiledCode = new AOTCompiledClass(stubs);
199 CodeSectionProcessor codeSectionProcessor = new CodeSectionProcessor(this);
200 codeSectionProcessor.process(stubCompiledCode);
201 return stubCompiledCode;
202 }
203
204 /**
205 * Prepare metaspace.offsets section.
206 */
207 private void prepareCompiledBinary() {
208 for (AOTCompiledClass c : classes) {
209 // Create records for compiled AOT methods.
210 c.putMethodsData(binaryContainer);
211 }
212 // Create records for compiled AOT classes.
|