RFR: 8184765: Dynamically resize SystemDictionary
Doerr, Martin
martin.doerr at sap.com
Mon Oct 30 16:01:01 UTC 2017
Hi Gerard,
I guess something like the following was meant.
(I assume overflow will not happen.)
Best regards,
Martin
int next_prime(int n) {
if (n < 2) return 2;
int p = (n+1)|1, d=3;
while (d <= p/d) {
if (p%d == 0) {
p+=2; d=3;
} else {
d+=2;
}
}
return p;
}
-----Original Message-----
From: hotspot-runtime-dev [mailto:hotspot-runtime-dev-bounces at openjdk.java.net] On Behalf Of Gerard Ziemski
Sent: Monday, October 30, 2017 4:52 PM
To: coleen.phillimore at oracle.com
Cc: hotspot-runtime-dev at openjdk.java.net
Subject: Re: RFR: 8184765: Dynamically resize SystemDictionary
> On Oct 30, 2017, at 10:36 AM, coleen.phillimore at oracle.com wrote:
>
>
>
> On 10/30/17 11:24 AM, Gerard Ziemski wrote:
>> hi Coleen,
>>
>>
>>> On Oct 30, 2017, at 10:12 AM, coleen.phillimore at oracle.com wrote:
>>>
>>>
>>> Hi Gerard,
>>>
>>> This looks great. One small question:
>>> + // straight forward brute force
>>> + inline static int _next_prime(int n) {
>>> + int p = n;
>>> + for (int i = n; i < (n * n); i++) {
>>> + if ((i % 2) != 0) {
>>> + p = i;
>>> + break;
>>> + }
>>> + }
>>> + return p;
>>> + }
>>>
>>> Is this how you calculate next prime? Wouldn't you check if it can mod by 3 and 5 as well?
>> As long as it’s not even i.e. mod 2 (and strictly speaking larger than 1). 3 and 5 are prime, so no need to check them.
>
> If you passed in 214 (2*107), 215 would look prime but it's not. I think the prime table would be better and limit resizing occurrences.
Right, need something a bit more clever here. A precomputed prime table might be good enough, but let me see how complex (a correct) function has to be.
cheers
More information about the hotspot-runtime-dev
mailing list