I am currently working with the JDI first time and examining the field modifiers of the local variables in a stack frame gave me interesting results. (Using JDK 17.0.6)
Here is the simplified code I use to acquire said modifier bits:
StackFrame stackFrame = thread.frame(0);
Map<LocalVariable, Value> visibleVariables = stackFrame.getValues(stackFrame.visibleVariables());
for (Map.Entry<LocalVariable, Value> entry : visibleVariables.entrySet()) {
ReferenceType type = ((ObjectReference) entry.getValue()).referenceType();
for (Field field : type.fields()) {
System.out.println(Modifier.toString(field.modifiers()) + "(" + field.modifiers() + ") ");
}
}
Interestingly this results in following ouput:
Fields:
private strictfp(2050) thesis.debuggee.HashMap$HashMapEntry[] map
private(2) int size
private(2) float maxLoadFactor
The class I am examining here is my own HashMap implementation I did as an assignment. For some reason as one can see the 12th bit is set for the private member "map" of type HashMapEntry[].
If one wants to observe this themselves just use a standard String object and look at its CASE_INSENSITIVE_ORDER public static final field as this also has the 12th bit set...
I looked into the JVM Specification and for field access and property flags the 12th bit is not used and defined as reserved for future use. The 12th bit is only used in method access and property flags for the "strictfp" flag (ACC_STRICT) which was removed in Java 17.
I tried to find out where this flag then comes from looking through the openjdk repo and other resources online but I couldn't find the reason on why for some fields the 12th bit is set. I would really appreciate if someone could at least point me into the right direction as I am very curious where this comes from and what purpose it serves.
I also looked at the byte code of my class, there the modifier flag is still 0x0002 as it should be (denoting private)
private thesis.debuggee.HashMap$HashMapEntry<K, V>[] map;
descriptor: [Lthesis/debuggee/HashMap$HashMapEntry;
flags: (0x0002) ACC_PRIVATE
Signature: #102 // [Lthesis/debuggee/HashMap$HashMapEntry<TK;TV;>;
private int size;
descriptor: I
flags: (0x0002) ACC_PRIVATE
private float maxLoadFactor;
descriptor: F
flags: (0x0002) ACC_PRIVATE