Skip to content

Commit 3d65c5c

Browse files
committed
[GR-64130] Update iprof version to include instanceof profiles.
PullRequest: graal/21296
2 parents 83f240c + e393f23 commit 3d65c5c

File tree

2 files changed

+408
-8
lines changed

2 files changed

+408
-8
lines changed

docs/reference-manual/native-image/PGO-IprofFileFormat.md

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,34 @@ This document outlines the structure and semantics of the _iprof_ file format.
1717

1818
## Structure
1919

20-
The full schema of the JSON format used for _iprof_ files can be found in the [iprof-v1.0.0.schema.json](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/assets/iprof-v1.0.0.schema.json) document.
20+
The full schema of the JSON format used for _iprof_ files can be found in the [iprof-v1.1.0.schema.json](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/assets/iprof-v1.1.0.schema.json) document.
2121
This JSON schema fully defines the _iprof_ file format and can be used to validate the structure of an arbitrary _iprof_ file.
2222

2323
A minimal valid _iprof_ file consists of a JSON object containing 3 fields: `types`, `methods` and `version`.
24-
The following is a minimal valid _iprof_ file for the current version (`1.0.0`).
24+
The following is a minimal valid _iprof_ file for the current version (`1.1.0`).
2525

2626
```json
2727
{
28-
"version": "1.0.0",
28+
"version": "1.1.0",
2929
"types": [],
3030
"methods": []
3131
}
3232
```
3333

3434
In addition to these fields, the _iprof_ file may optionally contain others that provide information on various run-time profiles.
35-
The following is an example of a fully populated _iprof_ file (version `1.0.0`) with the actual content of each of the fields replaced with `...`.
35+
The following is an example of a fully populated _iprof_ file (version `1.1.0`) with the actual content of each of the fields replaced with `...`.
3636

3737
```json
3838
{
39-
"version": "1.0.0",
39+
"version": "1.1.0",
4040
"types": [...],
4141
"methods": [...],
4242
"monitorProfiles": [...],
4343
"virtualInvokeProfiles": [...],
4444
"callCountProfiles": [...],
4545
"conditionalProfiles": [...],
46-
"samplingProfiles": [...]
46+
"samplingProfiles": [...],
47+
"instanceofProfiles": [...],
4748
}
4849
```
4950

@@ -115,11 +116,11 @@ The _iprof_ format uses a semantic versioning scheme (ie. `major.minor.patch`) t
115116
The major version is updated for breaking changes (for example, a new way of encoding the information),
116117
minor for non-breaking ones (for example, adding a new optional field in the top-level JSON object),
117118
and the patch version is updated for minor fixes that should not impact any client.
118-
The current version of the _iprof_ file format is `1.0.0`, which can be seen in the _iprof_ file from the example application.
119+
The current version of the _iprof_ file format is `1.1.0`, which can be seen in the _iprof_ file from the example application.
119120

120121
```json
121122
...
122-
"version": "1.0.0",
123+
"version": "1.1.0",
123124
...
124125
```
125126

@@ -713,6 +714,31 @@ In this case, it means that the context described in the previous paragraph was
713714
The other object in the sampling profiles array contains a different context and this sample was seen only once.
714715
Understanding the nature of this sample is left as an exercise to the reader.
715716

717+
## Instance-of Profiles
718+
719+
> Note: Instance-of profiles were added in the _iprof_ file format version 1.1.0. They are not present in version 1.0.0.
720+
721+
Instance-of profiles contain information on the run-time types of values that are checked at `instanceof` operators.
722+
Specifically, they record how many times a particular run-time type was encountered at a given `instanceof` operation.
723+
Thus, instance-of profiling information can be stored in the same format as [Virtual Invoke Profiles](#virtual-invoke-profiles).
724+
The only difference is that the resulting type histogram in the `records` part describes the types seen at `instanceof` checks, rather than the receiver types of virtual method calls.
725+
Consider the following Java code:
726+
727+
```java
728+
public class A {}
729+
public class B extends A {}
730+
731+
public static void doForA(Object obj) {
732+
if(obj instanceof A) {
733+
doSomething(obj);
734+
}
735+
}
736+
```
737+
738+
The `records` section of the profile will include all types (e.g., `A`, `B`, `Object`, `String`) encountered at run time for the `obj` variable, together with their occurrence counts.
739+
Thus, the length of the `records` array for instance-of profiles is always a multiple of 2,
740+
since the values represent a type ID and count pair.
741+
716742
## Related Documentation
717743
- [PGO](PGO.md)
718744
- [Optimize a Native Executable with Profile-Guided Optimization](guides/optimize-native-executable-with-pgo.md)

0 commit comments

Comments
 (0)