From shade at openjdk.java.net Thu Nov 11 00:00:01 2021 From: shade at openjdk.java.net (Aleksey Shipilev) Date: Thu, 11 Nov 2021 00:00:01 GMT Subject: RFR: make FieldLayout#data() public In-Reply-To: References: Message-ID: On Tue, 9 Nov 2021 17:25:17 GMT, Ivan Ponomarev wrote: > Can we have this property public? This is needed for https://github.com/atp-mipt/ljv visualizer: we can use JOL to get object fields in consistent order, but then we also need `FieldData` itself in order to get fields' values I want to keep the API as narrow as possible, I am sure you understand. Do you need `data()` accessor now? Do you need `refField()` accessor? Can you pseudo-code or point the usage example? Maybe it would be better to provide the specific accessor, like: Object value(Object instance) { if (instance == null) { return null; } return ObjectUtils.value(instance, f); } Also, LJV seems to overlap with JOL quite significantly, so maybe it would be even better to merge LJV into JOL, so that it can get whatever JOL internals it needs ;) ------------- PR: https://git.openjdk.java.net/jol/pull/19 From duke at openjdk.java.net Thu Nov 11 00:00:02 2021 From: duke at openjdk.java.net (Ivan Ponomarev) Date: Thu, 11 Nov 2021 00:00:02 GMT Subject: RFR: make FieldLayout#data() public In-Reply-To: References: Message-ID: On Tue, 9 Nov 2021 17:51:17 GMT, Ivan Ponomarev wrote: > Maybe it would be better to provide the specific accessor Added accessors for field's value and the `Field` itself. The reason why `value` alone is not enough: we want exact field's type information. ------------- PR: https://git.openjdk.java.net/jol/pull/19 From duke at openjdk.java.net Thu Nov 11 00:00:00 2021 From: duke at openjdk.java.net (Ivan Ponomarev) Date: Thu, 11 Nov 2021 00:00:00 GMT Subject: RFR: make FieldLayout#data() public Message-ID: Can we have this property public? This is needed for https://github.com/atp-mipt/ljv visualizer: we can use JOL to get object fields in consistent order, but then we also need `FieldData` itself in order to get fields' values ------------- Commit messages: - add specific accessors for field and field value - make FieldLayout#data() public Changes: https://git.openjdk.java.net/jol/pull/19/files Webrev: https://webrevs.openjdk.java.net/?repo=jol&pr=19&range=00 Stats: 27 lines in 1 file changed: 27 ins; 0 del; 0 mod Patch: https://git.openjdk.java.net/jol/pull/19.diff Fetch: git fetch https://git.openjdk.java.net/jol pull/19/head:pull/19 PR: https://git.openjdk.java.net/jol/pull/19 From duke at openjdk.java.net Thu Nov 11 00:00:01 2021 From: duke at openjdk.java.net (Ivan Ponomarev) Date: Thu, 11 Nov 2021 00:00:01 GMT Subject: RFR: make FieldLayout#data() public In-Reply-To: References: Message-ID: On Tue, 9 Nov 2021 17:33:59 GMT, Aleksey Shipilev wrote: > Maybe it would be better to provide the specific accessor, like: You mean the accessor for `FieldData` class? Yeah it would be nice, but it will not be sufficient for us to have it on `FieldLayout` level (we need field's type `Class` etc.) > maybe it would be even better to merge LJV into JOL Well, definitely yes at some point... I use LJV as a playground for my students to teach them Java programming / opensource contributing and the project is being rewritten at the moment. When it stabilizes, I will try to merge it > Can you pseudo-code or point the usage example? for (FieldLayout fieldLayout : ClassLayout.parseClass(obj.getClass()).fields()) { Field f = fieldLayout.data().refField(); Object v = ObjectUtils.value(obj, f); //primitives are wrapped, type information lost! //We need everything that can be extracted from Field... refField.getAnnotations()... //e.g. paint the field a specific color refField.getGenericType()... //e.g. label the field with type information if (refField.getType() is primitive or can be treated as primitive per LJV setup){ //treat the value as primitive... } else { //walk further the object's graph... } } ------------- PR: https://git.openjdk.java.net/jol/pull/19 From shade at openjdk.java.net Thu Nov 11 00:00:03 2021 From: shade at openjdk.java.net (Aleksey Shipilev) Date: Thu, 11 Nov 2021 00:00:03 GMT Subject: RFR: make FieldLayout#data() public In-Reply-To: References: Message-ID: On Wed, 10 Nov 2021 08:04:41 GMT, Ivan Ponomarev wrote: > > Maybe it would be better to provide the specific accessor > > Added accessors for field's value and the `Field` itself. The reason why `value` alone is not enough: we want exact field's type information. There is already `typeClass()`. Do you actually need `Class` out of it? I am not sure that one is always accessible. ------------- PR: https://git.openjdk.java.net/jol/pull/19 From shade at openjdk.java.net Fri Nov 19 12:01:57 2021 From: shade at openjdk.java.net (Aleksey Shipilev) Date: Fri, 19 Nov 2021 12:01:57 GMT Subject: RFR: make FieldLayout#data() public In-Reply-To: References: Message-ID: On Wed, 10 Nov 2021 08:26:28 GMT, Ivan Ponomarev wrote: > > Can you pseudo-code or point the usage example? > > ``` > for (FieldLayout fieldLayout : ClassLayout.parseClass(obj.getClass()).fields()) { > Field f = fieldLayout.data().refField(); > > Object v = ObjectUtils.value(obj, f); //primitives are wrapped, type information lost! > > //We need everything that can be extracted from Field... > refField.getAnnotations()... //e.g. paint the field a specific color > refField.getGenericType()... //e.g. label the field with type information > > if (refField.getType() is primitive or can be treated as primitive per LJV setup){ > //treat the value as primitive... > > } else { > //walk further the object's graph... > } > } > ``` It looks to me that this code tries to do the iteration that `GraphLayout.parseInstance` already does. Maybe you just want to extend `GraphWalker` to get this walk? ------------- PR: https://git.openjdk.java.net/jol/pull/19