RFR: 8330077: Allow max number of events to be buffered to be configurable to avoid OVERFLOW_EVENT [v2]

Brian Burkhalter bpb at openjdk.org
Thu Apr 11 21:06:41 UTC 2024


On Thu, 11 Apr 2024 19:51:57 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> Fabian Meumertzheim has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Rename property and use GetPropertyAction
>
> src/java.base/share/classes/sun/nio/fs/AbstractWatchKey.java line 53:
> 
>> 51:             intValue = 512;
>> 52:         }
>> 53:         MAX_EVENT_LIST_SIZE = intValue;
> 
> What if `intValue` turns on to be non-positive for some reason? Should the value also be clamped to some maximum positive value, perhaps determined by some characteristic of the system on which the code is running?

If you are going the system property route, then something like this (not tested) might be in order:


    private static final int SYSTEM_MAX_EVENT_LIST_SIZE = 100_000; // value TBD
    private static final int DEFAULT_MAX_EVENT_LIST_SIZE = 512;

    static final int MAX_EVENT_LIST_SIZE;
    static {
        String rawValue = GetPropertyAction.privilegedGetProperty
            ("jdk.nio.file.maxWatchEvents",
            String.valueOf(DEFAULT_MAX_EVENT_LIST_SIZE));
        int intValue;
        try {
            intValue = Math.min(Math.max(Math.toIntExact(Long.decode(rawValue)),
                                         DEFAULT_MAX_EVENT_LIST_SIZE),
                                SYSTEM_MAX_EVENT_LIST_SIZE);
        } catch (NumberFormatException nfe) {
            intValue = DEFAULT_MAX_EVENT_LIST_SIZE;
        } catch (ArithmeticException ae) { // rawValue overflowed an int
            intValue = SYSTEM_MAX_EVENT_LIST_SIZE;
        }
        MAX_EVENT_LIST_SIZE = intValue;
    }

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/18739#discussion_r1561717151


More information about the nio-dev mailing list