RFR: 8291360: Create entry points to expose low-level class file information
Harold Seigel
hseigel at openjdk.org
Mon Aug 1 13:33:00 UTC 2022
On Sun, 31 Jul 2022 22:05:15 GMT, David Holmes <dholmes at openjdk.org> wrote:
>> Please review this change to fix JDK-8291360. This fix adds entry points getClassFileVersion() and getClassAccessFlagsRaw() to class java.lang.Class. The new entry points return the current class's class file version and its raw access flags.
>>
>> The fix was tested by running Mach5 tiers 1-2 on Linux, Mac OS, and Windows, and Mach5 tiers 1-3 on Linux x64. Additionally, the JCK lang, vm, and api tests and new regression tests were run locally on Linux x64.
>>
>> Thanks, Harold
>
> src/hotspot/share/prims/jvm.cpp line 4064:
>
>> 4062: assert(c->is_instance_klass(), "must be");
>> 4063: InstanceKlass* ik = InstanceKlass::cast(c);
>> 4064: return (ik->minor_version() << 16) | ik->major_version();
>
> I'm curious why the format is minor:major rather than major:minor ?
This was requested by @RogerRiggs
Major high vs low bits requires either:
High bits: val >>>16
Low bits: val & 0xffff
Except for preview, the minor version is 0, so putting major version in the low bits allows trivial comparison (without masking); but may lead to bugs due to carelessness.
> src/java.base/share/classes/java/lang/Class.java line 4698:
>
>> 4696: *
>> 4697: * If the class is an array type then the access flags of the component type is
>> 4698: * returned. If the class is a primitive then ACC_ABSTRACT | ACC_FINAL | ACC_PUBLIC.
>
> The `ACC_ABSTRACT` seems odd - is that way of indicating this "class" can't be instantiated? Is there some spec document that explains this choice?
I don't know why API's such as JVM_GetClassModifiers() and JVM_GetClassAccessFlags return ACC_ABSTRACT | ACC_FINAL | ACC_PUBLIC for primitives. Nor could I find a spec that discussed access flags for primitives. But, I didn't want to change what's been returned for primitives in existing code.
> test/hotspot/jtreg/runtime/ClassFile/ClassFileVersionTest.java line 31:
>
>> 29: * @modules java.base/java.lang:open
>> 30: * @compile classFileVersions.jcod
>> 31: * @run main/othervm --enable-preview ClassFileVersionTest
>
> What preview feature is being used here?
No preview feature is being used but --enable-preview is needed here for the JVM to accept a class with a minor version of 65535.
-------------
PR: https://git.openjdk.org/jdk/pull/9688
More information about the build-dev
mailing list