[amber-record] feedback on a Record class attribute implementation

Vicente Romero vicente.romero at oracle.com
Wed Oct 31 00:59:31 UTC 2018


Hi all,

I have sent the patch to the hotspot list as this patch is touching some 
native code and I would like to have some feedback from the runtime 
wizards, please let me know if there is a better list for that. This 
patch has been pushed the the record branch in amber project [1]. The 
records project is about, well adding data classes to the language so 
that this declaration:

record Record(int i);

gets lowered to:

class Record {
     final int i;

    // automatically generated equals, getters, hashCode, toString and more
}

apart from the usual information generated for the lowered version, the 
javac compiler is generating this new attribute in the class file:

         Record {
             u2 name_index;
             u4 length;
             u2 num_record_params;
             {
                 u2 param_name_idx;  // [1]
                 u2 param_flag;
                 u2 param_desc;
                 u2 param_signature;
             } record_params[num_record_params];
         }

which have a lot in common with the fields information but we don't want 
to depend on the order of the fields etc. The attached patch provides 
for parsing this attribute, plus additional helper classes, plus all the 
pipes needed. As a way to provide a way for users to peek the 
information contained in the Record attribute, I have added a method to 
java.lang.Class, Class::getRecordParameters. In the background I'm using 
JNI to extract the information from the related InstanceKlass in the 
native world. Method java.lang.Class::getRecordParameters just returns 
an array of fields but only those that have being defined in the header 
of the record. For example if the record would have been defined as:

record Record(int i) {
     static final int j = 0;  //no instance fields can be defined in records
}

then an invocation of java.lang.Class::getRecordParameters will return 
only field `i` ignoring the static field `j`

TIA,
Vicente

[1] http://hg.openjdk.java.net/amber/amber
-------------- next part --------------
A non-text attachment was scrubbed...
Name: record.hotspot.patch
Type: text/x-patch
Size: 34444 bytes
Desc: not available
URL: <http://mail.openjdk.java.net/pipermail/amber-dev/attachments/20181030/064c6783/record.hotspot-0001.patch>


More information about the amber-dev mailing list