• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef MAPLEBE_INCLUDE_BE_RT_H
17 #define MAPLEBE_INCLUDE_BE_RT_H
18 
19 #include <cstdint>
20 #include <string>
21 
22 namespace maplebe {
23 /*
24  * This class contains constants about the ABI of the runtime, such as symbols
25  * for GC-related metadata in generated binary files.
26  */
27 class RTSupport {
28 public:
GetRTSupportInstance()29     static RTSupport &GetRTSupportInstance()
30     {
31         static RTSupport RtSupport;
32         return RtSupport;
33     }
GetObjectAlignment()34     uint64_t GetObjectAlignment() const
35     {
36         return kObjectAlignment;
37     }
GetArrayContentOffset()38     int64_t GetArrayContentOffset() const
39     {
40         return kArrayContentOffset;
41     }
GetArrayLengthOffset()42     int64_t GetArrayLengthOffset() const
43     {
44         return kArrayLengthOffset;
45     }
GetFieldSize()46     uint64_t GetFieldSize() const
47     {
48         return kRefFieldSize;
49     }
GetFieldAlign()50     uint64_t GetFieldAlign() const
51     {
52         return kRefFieldAlign;
53     }
54 
55 protected:
56     static constexpr uint64_t kObjectAlignment = 8;
57 
58 #ifdef USE_32BIT_REF
59     static constexpr uint32_t kRefFieldSize = 4;
60     static constexpr uint32_t kRefFieldAlign = 4;
61 #else
62     static constexpr uint32_t kRefFieldSize = 8;
63     static constexpr uint32_t kRefFieldAlign = 8;
64 #endif /* USE_32BIT_REF */
65     /* The array length offset is fixed since CONTENT_OFFSET is fixed to simplify code */
66     static constexpr int64_t kArrayLengthOffset = 12; /* shadow + monitor + [padding] */
67     /* The array content offset is aligned to 8B to alow hosting of size-8B elements */
68     static constexpr int64_t kArrayContentOffset = 16; /* fixed */
69 
70 private:
RTSupport()71     RTSupport() {}
72 };
73 } /* namespace maplebe */
74 
75 #endif /* MAPLEBE_INCLUDE_BE_RT_H */