Set a system property before forking

Weijun Wang weijun.wang at oracle.com
Tue Mar 28 14:38:27 UTC 2017


Hi Aleksey

On 03/28/2017 05:01 PM, Aleksey Shipilev wrote:
> Hi,
>
> On 03/28/2017 08:29 AM, Weijun Wang wrote:
>> I have a system property that is used by Java in a very early stage, which means
>> it has to be set on the command line with -Dx=y instead of inside a program with
>> System.setProperty().
>>
>> Now I'd like to write a benchmark to check how different values of this system
>> property affect performance. I'm now able to provide the system property on the
>> command line, run the benchmark multiple times, and compare the results. But is
>> it possible to set it inside my benchmark with different values for different
>> @Benchmark methods so I only need to run once? Since the @Benchmark methods run
>> inside forked JVMs, I assume there is a way to set the system property before
>> this forking.
>
> This is not possible with annotations. This is possible with Java API and adding
> .jvmArgs(...) to the options.

Great, I'm trying it now.

So I created 2 OptionsBuilder, the 1st one setting the system property 
to value 1 and include(method1), the 2nd one setting value2 and 
include(method2). However, it looks each option still runs both method1 
and method2. The "Forking 1 times using command" line does not show the 
include() argument at all.

Maybe I misunderstood include()? How to filter @Benchmark methods in an 
option?

Thanks
Max

>
> -Aleksey
>


More information about the jmh-dev mailing list