You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by "sun wuqiang (Jira)" <ji...@apache.org> on 2022/06/08 23:14:00 UTC
[jira] [Updated] (LUCENE-10605) fix error in 32bit jvm object alignment gap calculation
[ https://issues.apache.org/jira/browse/LUCENE-10605?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
sun wuqiang updated LUCENE-10605:
---------------------------------
Issue Type: Bug (was: Improvement)
> fix error in 32bit jvm object alignment gap calculation
> -------------------------------------------------------
>
> Key: LUCENE-10605
> URL: https://issues.apache.org/jira/browse/LUCENE-10605
> Project: Lucene - Core
> Issue Type: Bug
> Components: core/other
> Affects Versions: 9.2
> Environment: jdk 7 32-bit
> jdk 8 32-bit
> Reporter: sun wuqiang
> Priority: Trivial
> Attachments: image-2022-06-08-20-50-27-712.png, image-2022-06-08-21-24-57-674.png
>
> Time Spent: 10m
> Remaining Estimate: 0h
>
> ArrayUtil.{*}oversize{*}(int minTargetSize, int bytesPerElement)
> This method is used to calculate the optimal length of an array during expansion.
>
> According to current logic,in order to avoid space waste caused by *object alignment gap.* In *32-bit* JVM,the array length will select the numbers(the +current optional+ columns) in the table below. But the results weren't perfect.
> See the table below.
> !image-2022-06-08-20-50-27-712.png!
>
> I used *jol-core* to calculate object alignment gap
> {code:java}
> <dependency>
> <groupId>org.openjdk.jol</groupId>
> <artifactId>jol-core</artifactId>
> <version>0.16</version>
> <scope>compile</scope>
> </dependency> {code}
>
> Execute the following code:
> {code:java}
> System.out.println(ClassLayout.parseInstance(new byte[6]).toPrintable()); {code}
>
> !image-2022-06-08-21-24-57-674.png!
>
> To further verify that the tool's results are correct, I wrote the following code to infer how much space the array of different lengths actually occupies based on when the OOM occursThe conclusion is consistent with jol-core.
> {code:java}
> // -Xms16m -Xmx16m
> // Used to infer the memory space occupied
> // by the length of various arrays
> public static void main(String[] args) {
> byte[][] arr = new byte[1024 * 1024][];
> for (int i = 0; i < arr.length; i++) {
> if (i % 100 == 0) {
> System.out.println(i);
> }
> // According to OOM occurrence time
> // in 32-bit JVM,
> // Arrays range in length from 5 to 12,
> // occupying the same amount of memory
> arr[i]=new byte[5];
> }
> } {code}
> *new byte[5]* and *new byte[12]* use the same amount of memory
> ----
>
> In addition +*- XX: ObjectAlignmentInBytes*+ should also affect the return value of this method. But I don't know whether it is necessary to do this function. If necessary, I will modify it together. Thank you very much!
>
--
This message was sent by Atlassian Jira
(v8.20.7#820007)
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org