RFR: Extend API to support JOL IntelliJ Idea plugin
Sergey Ponomarev
github.com+415502+stokito at openjdk.java.net
Tue Oct 6 14:55:17 UTC 2020
On Thu, 1 Oct 2020 07:40:09 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:
>> [JOL Intellij Idea Plugin](https://github.com/stokito/IdeaJol) internally uses JOL.
>> Internally in the
>> [PsiClassAdapter](https://github.com/stokito/IdeaJol/blob/master/src/main/java/com/github/stokito/IdeaJol/PsiClassAdapter.java)
>> it makes exactly the same as `org.openjdk.jol.info.ClassData#parse` but it creates the ClassData from Idea's AST/Psi
>> tree instead of raw `Class`. Unfortunately to be able to do this we need to extend API a little bit. Here is a short
>> list of changes that I did: 1. Added an overloaded method ClassData.addSuperClassData(ClassData) so I can create an
>> instance of `ClassData` 2. Added `lossesInternal`, `lossesExternal` and `lossesTotal` fields to `ClassLayout` so they
>> calculated only once on instance creation and then can be accessed multiple times via geters by JTable 3.
>> `FieldData.create()` internally evaluate if the field is contended but we do this based on Psi tree. So we need to open
>> and make public the `FieldData` constructor.
>
> Looks sensible. Please rename the PR to e.g. "Extend API to support JOL IntelliJ Idea plugin"?
I fixed all your review comments but I wondered that I'm not listed as signed OCA. I'll sign it again but this may take
for weeks
> jol-core/src/main/java/org/openjdk/jol/info/ClassLayout.java line 145:
>
>> 143: }
>> 144: long lossesExternal = instanceSize != nextFree ? instanceSize - nextFree : 0;
>> 145: long lossesTotal = lossesInternal + lossesExternal;
>
> I think this whole block would be more readable if we shorten the variable names.
>
> long next = headerSize;
> long internal = 0;
> for (FieldLayout fl : fields) {
> if (fl.offset() > nextFree) {
> internal += fl.offset() - nextFree;
> }
> next = fl.offset() + fl.size();
> }
> long external = (instanceSize != next) ? (instanceSize - next) : 0;
> long total = internal + external;
ok, I just kept original variable names for more clear history
-------------
PR: https://git.openjdk.java.net/jol/pull/4
More information about the jol-dev
mailing list