• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Usage of Class Hierarchy during AOT compilation
2
3AOT compiler mode mainly described in [aot.md](../../docs/aot.md), please read it first.
4
5## Class Hierarchy Matching
6
7The class order in class path influences on resulting class hierarchy that would be available for an application. As a
8result the order of files in class path and files themselves are enough to verify the class context. The order resolves
9situations when several same classes were passed and only the first is considered by VM. To identify ark files the adler
10checksum is used.
11
12This class context is represented by a string which is written into AOT file and compared with runtime's one during AOT file loading.
13
14The typical string is:
15```
16/mnt/scratch/build/panda/pandastdlib/arkstdlib.abc*2239629066:/mnt/scratch/build/panda/Application.abc*1345224566:
17```
18
19### Class path
20
21AOT file compiled with class hierarchy requires the complete conformity of class path with runtime. It means that we
22have to pass a class path to AOT compiler identical to class path used by runtime.
23
24The example of usage
25
26```
27$ bin/ark_aot --boot-panda-files=$LIBDIR/lib1.abc:$LIBDIR/lib2.abc \
28              --paoc-panda-files application.abc \
29              --paoc-output application.an \
30              --paoc-use-cha=true
31$ bin/ark --boot-panda-files=$LIBDIR/lib1.abc:$LIBDIR/lib2.abc \
32          --aot-files=application.an \
33          application.abc \
34          Application::Main
35```
36
37The wrong usage. Some classes were omitted during AOT compilation due to the fact that they are not used.
38
39```
40$ bin/ark_aot --boot-panda-files=$LIBDIR/lib1.abc \
41              --paoc-panda-files application.abc \
42              --paoc-output application.an \
43              --paoc-use-cha=true
44$ bin/ark --boot-panda-files=$LIBDIR/lib1.abc:$LIBDIR/lib2.abc \
45          --aot-files=application.an \
46          application.abc \
47          Application::Main
48[TID 0073b5] E/aot: Failed to load AoT file: Cannot use 'application.an'.
49Runtime class context: '$LIBDIR/lib1.abc*2239629066:$LIBDIR/lib2.abc*2767220441:application.abc*2524155584'.
50AoT class context: '$LIBDIR/lib1.abc*2239629066:application.abc*2524155584'
51```
52
53The string of class context for AOT file takes into account `--paoc-location` option.
54
55### Boot class path
56The boot class path now is a part of class context string. When boot image would be implemented the checksum of the
57image should be checked during AOT file verification.
58
59As boot class path represents the core classes of VM it should not depend on any of application code. To obtain AOT file
60of boot class file the options `--paoc-boot-output` should be used. The class hierarchy verification for boot libraries
61is performed during Runtime initialization when only boot panda files are loaded. The verification of .an
62files for boot panda files is needed when the options `--enable-an` is used.
63
64Since the AOT file can be compiled on one host system and executed on different target, we need an option to specify boot
65files location according their paths on the target. `--paoc-boot-location` specifies the path where boot panda files are
66located on the target system. It works identically to `--paoc-location` but only for boot files used during compilation.
67
68It is important that for boot aot files the entire --boot-panda-files must match between `ark_aot` and `ark`. It means, that if you are compiling an AOT file for boot panda files, then all other entries of --boot-panda-files that will be used during execution should have been passed as well.
69
70## Class Hierarchy Usage
71
72### Virtual Calls
73
74Generally, the default approach of virtual call consists of the following steps:
75
761) Get class from object
772) Obtain MethodPtr of the callee virtual method
783) Retrieve the index of method in virtual table
794) Load the real MethodPtr from class (obtained in step 1) using index from previous step
805) Invoke method
81
82For JIT compiler steps 2-3-4 is merged into one, because it can obtain the index of method in virtual table during
83compilation.
84
85For AOT compilation the method and its index in virtual table is unknown because at runtime the chain of inheritance may
86differ. By this reason, the compiled code has to resolve the method during execution and retrieve index from the method.
87The [PLT Resolvers](./plt.md) help to avoid this resolution on each call and cache result (index inside virtual table
88for each method) into `.aot_table`.
89
90The usage of class hierarchy may help AOT compiler to squash 2-3-4 into one step as JIT-compiler does. It is possible
91because the MethodPtr is needed only to obtain the virtual table index. The indices inside virtual tables are still
92unchanged until the class hierarchy has changed. Therefore AOT compiler can generate code similar to JIT compiler if the
93class hierarchy of runtime matches the class hierarchy during AOT compilation.
94