23 |
23 |
24 |
24 |
25 |
25 |
26 package jdk.tools.jaotc; |
26 package jdk.tools.jaotc; |
27 |
27 |
|
28 import static jdk.tools.jaotc.AOTCompiledClass.getType; |
|
29 import static jdk.tools.jaotc.AOTCompiledClass.metadataName; |
|
30 |
|
31 import java.lang.reflect.Method; |
28 import java.util.ArrayList; |
32 import java.util.ArrayList; |
29 import java.util.List; |
33 import java.util.List; |
|
34 |
|
35 import org.graalvm.compiler.code.CompilationResult; |
|
36 import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider; |
30 |
37 |
31 import jdk.tools.jaotc.binformat.BinaryContainer; |
38 import jdk.tools.jaotc.binformat.BinaryContainer; |
32 import jdk.tools.jaotc.binformat.ByteContainer; |
39 import jdk.tools.jaotc.binformat.ByteContainer; |
33 import jdk.tools.jaotc.binformat.GotSymbol; |
40 import jdk.tools.jaotc.binformat.GotSymbol; |
34 import jdk.tools.jaotc.utils.NativeOrderOutputStream; |
41 import jdk.tools.jaotc.utils.NativeOrderOutputStream; |
35 import org.graalvm.compiler.code.CompilationResult; |
|
36 import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider; |
|
37 |
|
38 import jdk.vm.ci.code.StackSlot; |
42 import jdk.vm.ci.code.StackSlot; |
39 import jdk.vm.ci.code.site.DataPatch; |
43 import jdk.vm.ci.code.site.DataPatch; |
40 import jdk.vm.ci.code.site.Infopoint; |
44 import jdk.vm.ci.code.site.Infopoint; |
41 import jdk.vm.ci.code.site.Mark; |
45 import jdk.vm.ci.code.site.Mark; |
42 import jdk.vm.ci.hotspot.HotSpotCompiledCode; |
46 import jdk.vm.ci.hotspot.HotSpotCompiledCode; |
43 import jdk.vm.ci.hotspot.HotSpotMetaData; |
47 import jdk.vm.ci.hotspot.HotSpotMetaData; |
44 |
|
45 import static jdk.tools.jaotc.AOTCompiledClass.getType; |
|
46 import static jdk.tools.jaotc.AOTCompiledClass.metadataName; |
|
47 |
48 |
48 final class MetadataBuilder { |
49 final class MetadataBuilder { |
49 |
50 |
50 private final DataBuilder dataBuilder; |
51 private final DataBuilder dataBuilder; |
51 |
52 |
78 * @param compiledClass AOT Graal compilation result |
79 * @param compiledClass AOT Graal compilation result |
79 */ |
80 */ |
80 private void createMethodMetadata(AOTCompiledClass compiledClass) { |
81 private void createMethodMetadata(AOTCompiledClass compiledClass) { |
81 HotSpotGraalRuntimeProvider runtime = dataBuilder.getBackend().getRuntime(); |
82 HotSpotGraalRuntimeProvider runtime = dataBuilder.getBackend().getRuntime(); |
82 ByteContainer methodMetadataContainer = binaryContainer.getMethodMetadataContainer(); |
83 ByteContainer methodMetadataContainer = binaryContainer.getMethodMetadataContainer(); |
|
84 |
|
85 Method implicitExceptionsMethod = null; |
|
86 try { |
|
87 implicitExceptionsMethod = HotSpotMetaData.class.getDeclaredMethod("implicitExceptionBytes"); |
|
88 } catch (NoSuchMethodException e) { |
|
89 } |
83 |
90 |
84 // For each of the compiled java methods, create records holding information about them. |
91 // For each of the compiled java methods, create records holding information about them. |
85 for (CompiledMethodInfo methodInfo : compiledClass.getCompiledMethods()) { |
92 for (CompiledMethodInfo methodInfo : compiledClass.getCompiledMethods()) { |
86 // Get the current offset in the methodmetadata container. |
93 // Get the current offset in the methodmetadata container. |
87 final int startOffset = methodMetadataContainer.getByteStreamSize(); |
94 final int startOffset = methodMetadataContainer.getByteStreamSize(); |
139 |
146 |
140 NativeOrderOutputStream.PatchableInt pcDescOffset = metadataStream.patchableInt(); |
147 NativeOrderOutputStream.PatchableInt pcDescOffset = metadataStream.patchableInt(); |
141 NativeOrderOutputStream.PatchableInt scopeOffset = metadataStream.patchableInt(); |
148 NativeOrderOutputStream.PatchableInt scopeOffset = metadataStream.patchableInt(); |
142 NativeOrderOutputStream.PatchableInt relocationOffset = metadataStream.patchableInt(); |
149 NativeOrderOutputStream.PatchableInt relocationOffset = metadataStream.patchableInt(); |
143 NativeOrderOutputStream.PatchableInt exceptionOffset = metadataStream.patchableInt(); |
150 NativeOrderOutputStream.PatchableInt exceptionOffset = metadataStream.patchableInt(); |
|
151 NativeOrderOutputStream.PatchableInt implictTableOFfset = null; |
|
152 |
|
153 if (implicitExceptionsMethod != null) { |
|
154 implictTableOFfset = metadataStream.patchableInt(); |
|
155 } |
144 NativeOrderOutputStream.PatchableInt oopMapOffset = metadataStream.patchableInt(); |
156 NativeOrderOutputStream.PatchableInt oopMapOffset = metadataStream.patchableInt(); |
145 metadataStream.align(8); |
157 metadataStream.align(8); |
146 |
158 |
147 pcDescOffset.set(metadataStream.position()); |
159 pcDescOffset.set(metadataStream.position()); |
148 metadataStream.put(pcDesc).align(8); |
160 metadataStream.put(pcDesc).align(8); |
153 relocationOffset.set(metadataStream.position()); |
165 relocationOffset.set(metadataStream.position()); |
154 metadataStream.put(relocationInfo).align(8); |
166 metadataStream.put(relocationInfo).align(8); |
155 |
167 |
156 exceptionOffset.set(metadataStream.position()); |
168 exceptionOffset.set(metadataStream.position()); |
157 metadataStream.put(metaData.exceptionBytes()).align(8); |
169 metadataStream.put(metaData.exceptionBytes()).align(8); |
|
170 |
|
171 if (implicitExceptionsMethod != null) { |
|
172 implictTableOFfset.set(metadataStream.position()); |
|
173 byte[] data = (byte[]) implicitExceptionsMethod.invoke(metaData); |
|
174 metadataStream.put(data).align(8); |
|
175 } |
158 |
176 |
159 // oopmaps should be last |
177 // oopmaps should be last |
160 oopMapOffset.set(metadataStream.position()); |
178 oopMapOffset.set(metadataStream.position()); |
161 metadataStream.put(oopMapInfo).align(8); |
179 metadataStream.put(oopMapInfo).align(8); |
162 |
180 |