From 32d8510b15aeff3e07a288d1caed5bf707a06171 Mon Sep 17 00:00:00 2001 From: Konstantin Baladurin Date: Tue, 20 Dec 2022 12:15:57 +0300 Subject: [PATCH] Draft support generics in file format Change-Id: I676dff38ae9dbcd50456c93ddb6279c669e43cf2 Signed-off-by: Konstantin Baladurin --- docs/file_format.md | 57 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/docs/file_format.md b/docs/file_format.md index 61c85b85e..987168823 100644 --- a/docs/file_format.md +++ b/docs/file_format.md @@ -165,6 +165,7 @@ RefType -> 'L' ClassName ';' | `ACC_ABSTRACT` | `0x0400` | Declared abstract; no implementation is provided. | | `ACC_STRICT` | `0x0800` | Declared strictfp; floating-point mode is FP-strict. | | `ACC_SYNTHETIC` | `0x1000` | Declared synthetic; not present in the source code. | +| `ACC_GENERIC` | `0x2000` | A generic method. | #### Class access flags @@ -178,6 +179,7 @@ RefType -> 'L' ClassName ';' | `ACC_SYNTHETIC` | `0x1000` | Declared synthetic; not present in the source code. | | `ACC_ANNOTATION` | `0x2000` | Declared as an annotation type. | | `ACC_ENUM` | `0x4000` | Declared as an enum type. | +| `ACC_GENERIC` | `0x8000` | Declared as generic type. | ## Source language @@ -242,6 +244,8 @@ Format: | `field_idx_off` | `uint32_t` | Offset to the field index structure. The offset must point to a structure in [FieldRegionIndex](#fieldregionindex) format. | | `proto_idx_size` | `uint32_t` | Number of elements in the [ProtoRegionIndex](#protoregionindex) structure. Max value is 65536. | | `proto_idx_off` | `uint32_t` | Offset to the proto index structure. The offset must point to a structure in [ProtoRegionIndex](#protoregionindex) format. | +| `generic_type_idx_size` | `uint32_t` | Number of elements in the [GenericTypeRegionIndex](#generictyperegionindex) structure. Max value is 65536. | +| `generic_type_idx_off` | `uint32_t` | Offset to the generic types index structure. The offset must point to a structure in [GenericTypeRegionIndex](#generictyperegionindex) format. | Constraint: regions must not overlap each other. @@ -368,6 +372,7 @@ Note: Proper region index to resolve `class_idx` and `proto_idx` can be found by | `TYPE_ANNOTATION` | `0x08` | `>=0` | `uint8_t[4]` | Data represents the offset to runtime **invisible** type annotation of the method. The tag may be repeated in case the method has several annotations. The offset must point to the value in [Annotation](#annotation) format. | | `RUNTIME_TYPE_ANNOTATION` | `0x09` | `>=0` | `uint8_t[4]` | Data represents the offset to runtime **visible** type annotation of the method. The tag may be repeated in case the method has several annotations. The offset must point to the value in [Annotation](#annotation) format. | | `PROFILE_INFO` | `0x0a` | `>=0` | `uint8_t[]` | Data represents the profile information. Format is unspecified and determined by the language, used in the file. +| `GENERIC_PARAMETERS` | `0x0b` | `0-1` | `uleb128 GenericParameter[]` | List of generic parameters the method have. Data contains number of generic parameters encoded in `uleb128` format followed by generic parameters in [`GenericParameter`](#genericparameter) structure. | ### ForeignClass @@ -408,6 +413,7 @@ Format: | `RUNTIME_TYPE_ANNOTATION` | `0x05` | `>=0` | `uint8_t[4]` | Offset to runtime **visible** type annotation of the class. The tag may be repeated in case the class has several annotations. The offset must point to the value in [Annotation](#annotation) format. | | `TYPE_ANNOTATION` | `0x06` | `>=0` | `uint8_t[4]` | Offset to runtime **invisible** type annotation of the class. The tag may be repeated in case the class has several annotations. The offset must point to the value in [Annotation](#annotation) format. | | `SOURCE_FILE` | `0x07` | `0-1` | `uint8_t[4]` | Offset to a file name string containing source code of this class. | +| `GENERIC_PARAMETERS` | `0x08` | `0-1` | `uleb128 GenericParameter[]` | List of generic parameters the method have. Data contains number of generic parameters encoded in `uleb128` format followed by generic parameters in [`GenericParameter`](#genericparameter) structure. | Note: Proper region index to resolve interfaces indexes can be found by class's offset. @@ -429,7 +435,8 @@ Format: | Name | Format | Description | | ---- | ------ | ----------- | | `shorty` | `uint16_t[]` | Short representation of the prototype. Encoding of the shorty is described in [Shorty](#shorty). | -| `reference_types` | `uint16_t[]` | Array of indexes of the method's signature non-primitive types. For each non-primitive type in the shorty there is the corresponding element in the array. Size of the array is equals to number of reference types in the shorty. | +| `reference_types` | `uint16_t[]` | Array of indexes of the method's signature non-primitive non-generic types. For each non-primitive non-generic type in the shorty there is the corresponding element in the array. Size of the array is equals to number of reference types in the shorty. | +| `generic_types` | `uint16_t[]` | Array of indexes of the method's signature non-primitive generic types in [GenericType](#generictype) structure. For each non-primitive generic type in the shorty there is the corresponding element in the array. Size of the array is equals to number of generic reference types in the shorty. | Note: Proper region index to resolve reference types indexes can be found by proto's offset. @@ -466,6 +473,7 @@ End -> 0x0 | `u64` | `0x0c` | | `ref` | `0x0d` | | `any` | `0x0e` | +| `gref` | `0x0f` | All shorty elements are divided into groups of 4 elements starting from the beginning. Each group is encoded in `uint16_t`. Each element is encoded in 4 bits. @@ -886,6 +894,34 @@ Format: | ---- | ------ | ----------- | | `offsets` | `uint32_t[]` | Array of offsets to [Proto](#proto) structures. | +### GenericTypeRegionIndex + +`GenericTypeRegionIndex` structure is aimed to allow runtime to find a generic type description by index. +The structure is organized as an array of offsets from the beginning og the file to the [GenericType](#generictype) structure. +Number of elements in the index is `generic_type_idx_size` from [RegionHeader](#regionheader). + +Alignment: 4 bytes + +Format: + +| Name | Format | Description | +| ---- | ------ | ----------- | +| `offsets` | `uint32_t[]` | Array of offsets to [GenericType](#generictype) structures. | + +### GenericParameterRegionIndex + +`GenericParameterRegionIndex` structure is aimed to allow runtime to find a generic parameter description by index. +The structure is organized as an array of offsets from the beginning og the file to the [GenericParameter](#genericparameter) structure. +Number of elements in the index is `generic_param_idx_size` from [RegionHeader](#regionheader). + +Alignment: 4 bytes + +Format: + +| Name | Format | Description | +| ---- | ------ | ----------- | +| `offsets` | `uint32_t[]` | Array of offsets to [GenericParameter](#genericparameter) structures. | + ### LiteralArrayIndex `LiteralArrayIndex` structure is aimed to allow runtime to find a LiteralArray definition by index. @@ -1025,3 +1061,22 @@ A bootstrap method can accept static arguments of the following types: | `Class` | `0x05` | The corresponding argument has [ClassValue](#classvalue) encoding. | | `MethodHandle` | `0x06` | The corresponding argument has [MethodHandleValue](#methodhandlevalue) encoding. | | `MethodType` | `0x07` | The corresponding argument has [MethodTypeValue](#methodtypevalue) encoding. | + +### GenericType + +Alignment: None + +Format: + +| Name | Format | Description | +| ---- | ------ | ----------- | +| `type_idx` | `uleb128` | Index of the generic type in a [`ClassRegionIndex`](#classregionindex) structure or index of the generic parameter. | +| `info` | `uleb128` | (count << 2) | variance. count = number of type arguments + 1. 0 means `type_idx` is the index of the generic parameter. | +| `type_args` | `uleb128[]` | Array of indexes of the [`GenericType`](#generictype) structures that describe type arguments of the generic type referenced by `type_idx` | + +### GenericParameter + +| Name | Format | Description | +| ---- | ------ | ----------- | +| `data` | `uleb128` | (Number of boundaries << 2) | variance | +| `boundaries` | `uleb128[]` | Array of indexes of the [`GenericType`](#generictype) structures that describe type arguments of the generic type referenced by `type_idx` | -- Gitee