{"id":322975,"date":"2021-05-12T15:00:41","date_gmt":"2021-05-12T15:00:41","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=322975"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=322975","title":{"rendered":"\u041f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c\u044e \u0434\u043e \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u044b\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u0420\u0430\u0431\u043e\u0442\u0430\u044f \u043d\u0430\u0434 \u0442\u0435\u043c\u043e\u0439 \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u044f \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0433\u043e \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430 \u043f\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0438 \u0441\u0431\u043e\u0440\u0443 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430. \u0412\u0441\u0451 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u043c\u0443 \u043f\u0443\u0442\u0451\u043c \u043f\u0440\u043e\u0431 \u0438 \u043e\u0448\u0438\u0431\u043e\u043a. \u0418\u0442\u043e\u0433\u043e\u043c \u0441\u0442\u0430\u043b\u0430 \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044f \u043f\u043e \u0448\u0430\u0433\u0430\u043c \u043e\u043f\u0438\u0441\u0430\u043b \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430, \u0433\u043e\u0440\u044f\u0447\u0435\u0435 \u043c\u0435\u0441\u0442\u043e \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0435 \u0432 \u0441\u0438\u043b\u0430\u0445 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u0439 VisualVM, \u043d\u043e \u0438 \u0441\u0432\u0435\u0440\u0445\u0442\u043e\u0447\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0432\u0440\u043e\u0434\u0435 async-profiler-\u0430.  \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u043a\u043e\u0434 \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/psy-lob-saw.blogspot.com\/2014\/08\/the-volatile-read-suprise.html\" rel=\"noopener noreferrer nofollow\">The volatile read surprise<\/a>.<\/p>\n<h4>\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438<\/h4>\n<p>\u041a\u043e\u0433\u0434\u0430-\u0442\u043e \u0434\u0430\u0432\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0432 \u0441\u0442\u0430\u0442\u044c\u044e <a href=\"http:\/\/psy-lob-saw.blogspot.com\/2014\/08\/the-volatile-read-suprise.html\" rel=\"noopener noreferrer nofollow\">The volatile read surprise<\/a> \u043c\u043d\u0435 \u0441\u0442\u0430\u043b\u043e \u043b\u044e\u0431\u043e\u043f\u044b\u0442\u043d\u043e, \u043a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e \u0430\u0432\u0442\u043e\u0440 \u043f\u0440\u0438\u0448\u0451\u043b \u043a \u0441\u0434\u0435\u043b\u0430\u043d\u043d\u044b\u043c \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u0432\u044b\u0432\u043e\u0434\u0430\u043c. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043a\u0440\u0430\u0442\u043a\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u043c\u0441\u044f \u0441 \u043c\u0430\u0442\u0447\u0430\u0441\u0442\u044c\u044e:<\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u043e\u0434\u043e\u043f\u044b\u0442\u043d\u044b\u0439 \u043a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">@BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) @State(Scope.Thread) public class LoopyBenchmarks {   @Param({ \"32\", \"1024\", \"32768\" })   int size;    byte[] bunn;    @Setup   public void prepare() {     bunn = new byte[size];   }    @Benchmark   public void goodOldLoop(Blackhole fox) {     for (int y = 0; y &lt; bunn.length; y++) { \/\/ good old C style for (the win?)       fox.consume(bunn[y]);     }   }    @Benchmark   public void sweetLoop(Blackhole fox) {     for (byte bunny : bunn) { \/\/ syntactic sugar loop goodness       fox.consume(bunny);     }   } }<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a \u043c\u044b \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u0432 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b:<\/p>\n<pre><code>Benchmark              (size)     Score   Error  Units  goodOldLoop               32     46.630   0.097  ns\/op goodOldLoop             1024   1199.338   0.705  ns\/op goodOldLoop            32768  37813.600  56.081  ns\/op  sweetLoop                 32     19.304   0.010  ns\/op sweetLoop               1024    475.141   1.227  ns\/op sweetLoop              32768  14295.800  36.071  ns\/op<\/code><\/pre>\n<p>\u0413\u0434\u0435 \u0436\u0435 \u0432 \u043a\u043e\u0434\u0435 \u0433\u043e\u0440\u044f\u0447\u0435\u0435 \u043c\u0435\u0441\u0442\u043e? \u041a\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e\u0440\u043c\u043e\u0437\u0438\u0442 \u0432 \u043e\u0431\u044b\u0447\u043d\u043e\u043c \u0441\u0447\u0451\u0442\u043d\u043e\u043c \u0446\u0438\u043a\u043b\u0435? \u041f\u043e\u0447\u0435\u043c\u0443 \u0441\u0447\u0451\u0442\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u0432 \u0434\u0432\u0430 \u0440\u0430\u0437\u0430 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0447\u0435\u043c <code>for-each<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0441\u043b\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 <em>\u043f\u043e\u0447\u0442\u0438<\/em> \u0442\u043e\u0442 \u0436\u0435 \u0441\u0430\u043c\u044b\u0439 \u0441\u0447\u0451\u0442\u043d\u044b\u0439 \u0446\u0438\u043a\u043b.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041a\u0430\u043a \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435<\/summary>\n<div class=\"spoiler__content\">\n<p>The assembly code for the <code>goodOldLoop<\/code>is long and painful to read through, and that in itself is a clue.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0412\u044b\u0432\u043e\u0434 \u0430\u0432\u0442\u043e\u0440\u0430<\/summary>\n<div class=\"spoiler__content\">\n<p>The thing that stands out (when the assembly smoke clears) is that&nbsp;<em>bunn<\/em>&nbsp;is loaded on every iteration,&nbsp;<em>bunn.length<\/em>&nbsp;is loaded and an array boundary check happens. This is surely a terrible way to interpret a for loop. The culprit turns out to be a volatile read in Blackhole.consume(). &#8230; A volatile load of one value requires the JVM to load all subsequent loads from memory to force happens before relationships, in this case the field&nbsp;<em>bunn&nbsp;<\/em>is reloaded on every iteration of the loop. <\/p>\n<\/div>\n<\/details>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>-XX:+PrintAssembly<\/code> \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u0432\u0441\u0435\u0433\u043e \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439  \u0432 \u0441\u044b\u0440\u043e\u043c \u0432\u0438\u0434\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<details class=\"spoiler\">\n<summary>\u042d\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0430\u043b\u0430\u044f \u0447\u0430\u0441\u0442\u044c<\/summary>\n<div class=\"spoiler__content\">\n<pre><code>[Verified Entry Point]   0x00007f6605205020: mov    %eax,-0x14000(%rsp)   0x00007f6605205027: push   %rbp   0x00007f6605205028: sub    $0x30,%rsp         ;*synchronization entry                                                 ; - org.tsypanov.sb.misc.LoopyBenchmarks::goodOldLoop@-1 (line 24)    0x00007f660520502c: mov    %rdx,0x8(%rsp)   0x00007f6605205031: mov    %rsi,(%rsp)   0x00007f6605205035: mov    0x10(%rsi),%r11d   ;*getfield bunn                                                 ; - org.tsypanov.sb.misc.LoopyBenchmarks::goodOldLoop@4 (line 24)    0x00007f6605205039: mov    0xc(%r12,%r11,8),%r10d  ; implicit exception: dispatches to 0x00007f66052050e5   0x00007f660520503e: test   %r10d,%r10d   0x00007f6605205041: jle    0x00007f6605205084  ;*if_icmpge                                                 ; - org.tsypanov.sb.misc.LoopyBenchmarks::goodOldLoop@8 (line 24)    0x00007f6605205043: test   %rdx,%rdx   0x00007f6605205046: je     0x00007f66052050a5   0x00007f6605205048: xor    %ebp,%ebp   0x00007f660520504a: nopw   0x0(%rax,%rax,1)   ;*aload_1                                                 ; - org.tsypanov.sb.misc.LoopyBenchmarks::goodOldLoop@11 (line 25)    0x00007f6605205050: mov    0xc(%r12,%r11,8),%r10d  ; implicit exception: dispatches to 0x00007f66052050c6   0x00007f6605205055: cmp    %r10d,%ebp   0x00007f6605205058: jae    0x00007f6605205090   0x00007f660520505a: lea    (%r12,%r11,8),%r10   0x00007f660520505e: movsbl 0x10(%r10,%rbp,1),%edx  ;*baload                                                 ; - org.tsypanov.sb.misc.LoopyBenchmarks::goodOldLoop@17 (line 25)<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0418 \u0432\u0440\u043e\u0434\u0435 \u0431\u044b \u0442\u0443\u0442 \u0435\u0441\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u043d\u0430 \u0431\u0430\u0439\u0442-\u043a\u043e\u0434, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0442\u043e\u043c\u0443 \u0438\u043b\u0438 \u0438\u043d\u043e\u043c\u0443 \u043d\u0430\u0431\u043e\u0440\u0443 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439, \u0438  \u0434\u0430\u0436\u0435 \u0435\u0441\u0442\u044c \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 Java-\u043a\u043e\u0434\u0435, \u043d\u043e \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0433\u0434\u0435 \u0438 \u043d\u0430 \u0447\u0442\u043e \u0442\u0440\u0430\u0442\u0438\u0442\u0441\u044f \u043b\u044c\u0432\u0438\u043d\u0430\u044f \u0434\u043e\u043b\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u0438! \u0425\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043d\u0443\u0436\u0434\u044b \u0432\u044b\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u043d\u0438 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u0430 \u0438 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0439 \u043f\u0440\u043e\u0444\u0438\u043b\u044c.<\/p>\n<p>\u042f \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b \u0440\u0430\u0437\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b, \u043e\u0434\u043d\u0430\u043a\u043e \u043a\u043e\u0434\u0430 \u043e\u0447\u0435\u043d\u044c \u043c\u0430\u043b\u043e, \u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u043e\u0439 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c. \u041e\u0441\u0442\u0430\u0432\u0430\u043b\u043e\u0441\u044c \u043e\u0434\u043d\u043e: \u043f\u043e\u0433\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0433\u043b\u0443\u0431\u0438\u043d\u0443 \u0432 \u0445\u043e\u043b\u043e\u0434\u043d\u044b\u0435 \u0438 \u043c\u0440\u0430\u0447\u043d\u044b\u0435 \u0433\u043b\u0443\u0431\u0438\u043d\u044b.<\/p>\n<h4>\u041d\u044b\u0440\u044f\u0435\u043c<\/h4>\n<p>\u0411\u0430\u0442\u0438\u0441\u043a\u0430\u0444\u043e\u043c \u043d\u0430\u043c \u043f\u043e\u0441\u043b\u0443\u0436\u0438\u0442 <code>org.openjdk.jmh.profile.LinuxPerfAsmProfiler<\/code>, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0439 \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 JMH. \u0414\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d \u043f\u0440\u044f\u043c\u043e \u0432 \u043a\u043e\u0434\u0435 (\u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0442\u0430\u043a\u0436\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 <code>-prof perfasm<\/code>):<\/p>\n<pre><code class=\"java\">public class BenchmarkRunner {    public static void main(String[] args) throws RunnerException {     Options opt = new OptionsBuilder()       .include(LoopyBenchmark.class.getSimpleName())       .warmupIterations(10)       .warmupTime(TimeValue.seconds(1))       .measurementIterations(1)       .measurementTime(TimeValue.seconds(10))       .addProfiler(LinuxPerfAsmProfiler.class)       .forks(1) \/\/0 makes debugging possible       .build();      new Runner(opt).run();   } }<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u044f \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u043d\u043e \u0432\u044b\u0441\u0442\u0430\u0432\u0438\u043b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>forks<\/code> (\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 Java-\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432) \u0440\u0430\u0432\u043d\u044b\u043c 1. \u041e\u0431\u044b\u0447\u043d\u043e \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0439 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 Java-\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0436\u0435 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0443\u0436\u0435\u043d \u043e\u0434\u0438\u043d, \u0442. \u043a. \u0430\u0434\u0440\u0435\u0441\u0430 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u044b\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 \u043c\u043e\u0433\u0443\u0442 \u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u043e\u0442 \u043f\u0440\u043e\u0433\u043e\u043d\u0430 \u043a \u043f\u0440\u043e\u0433\u043e\u043d\u0443, \u0447\u0442\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e <a href=\"https:\/\/hg.openjdk.java.net\/code-tools\/jmh\/file\/037acc4657c3\/jmh-samples\/src\/main\/java\/org\/openjdk\/jmh\/samples\/JMHSample_35_Profilers.java#l596\" rel=\"noopener noreferrer nofollow\">\u043e\u0433\u043e\u0432\u043e\u0440\u0435\u043d\u043e \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>.<\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c:<\/p>\n<pre><code>[Cannot run program \"perf\": error=2, No such file or directory] Exception in thread \"main\" org.openjdk.jmh.runner.ProfilersFailedException: Profilers failed to initialize, exiting.     at org.openjdk.jmh.runner.Runner.internalRun(Runner.java:244)     at org.openjdk.jmh.runner.Runner.run(Runner.java:209)<\/code><\/pre>\n<p>\u0418\u0442\u0430\u043a, \u043f\u0435\u0440\u0432\u043e\u0435 \u043f\u0440\u0435\u043f\u044f\u0442\u0441\u0442\u0432\u0438\u0435: \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 <code>perf<\/code>. \u0422\u0443\u0442 \u043f\u0440\u043e\u0441\u0442\u043e: \u0431\u0435\u0433\u043b\u044b\u0439 \u043f\u043e\u0438\u0441\u043a \u0432 \u042f\u043d\u0434\u0435\u043a\u0441\u0435 \u0434\u0430\u0451\u0442 <a href=\"https:\/\/askubuntu.com\/a\/50148\" rel=\"noopener noreferrer nofollow\">\u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0443<\/a>:<\/p>\n<blockquote>\n<p>The perf utility can be found in the linux-tools package<\/p>\n<\/blockquote>\n<p>\u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"bash\">$ sudo apt-get install linux-tools-generic<\/code><\/pre>\n<p>\u0417\u0430\u0432\u043e\u0434\u0438\u043c \u0435\u0449\u0451 \u0440\u0430\u0437:<\/p>\n<pre><code>[WARNING: perf not found for kernel 5.4.0-42    You may need to install the following packages for this specific kernel:     linux-tools-5.4.0-42-generic     linux-cloud-tools-5.4.0-42-generic    You may also want to install one of the following packages to keep up to date:     linux-tools-generic     linux-cloud-tools-generic ] Exception in thread \"main\" org.openjdk.jmh.runner.ProfilersFailedException: Profilers failed to initialize, exiting.<\/code><\/pre>\n<p>\u0425\u043c, \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043d\u0443\u0436\u043d\u044b\u0439 \u043d\u0430\u043c <code>perf<\/code> \u043d\u0435 \u0434\u043e\u0435\u0445\u0430\u043b. \u0418\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c:<\/p>\n<pre><code class=\"bash\">$ sudo apt-get install linux-tools-5.4.0-42-generic<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0435 <code>5.4.0-42-generic<\/code> \u0434\u043e\u043b\u0436\u043d\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0440\u0441\u0438\u0438 \u0432\u0430\u0448\u0435\u0433\u043e \u044f\u0434\u0440\u0430. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435: \u0435\u0441\u043b\u0438 \u043f\u043e\u0441\u043b\u0435 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0433\u043e <code>sudo apt-get dist-upgrade<\/code> \u0443 \u0432\u0430\u0441 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u044f\u0434\u0440\u043e, \u0442\u043e <code>linux-tools<\/code> \u0442\u043e\u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c.<\/p>\n<p>\u041f\u0443\u0441\u043a\u0430\u0435\u043c \u0435\u0449\u0451 \u0440\u0430\u0437:<\/p>\n<pre><code>[Error: You may not have permission to collect stats.  Consider tweaking \/proc\/sys\/kernel\/perf_event_paranoid, which controls use of the performance events system by unprivileged users (without CAP_SYS_ADMIN).  The current value is 3:    -1: Allow use of (almost) all events by all users       Ignore mlock limit after perf_event_mlock_kb without CAP_IPC_LOCK &gt;= 0: Disallow ftrace function tracepoint by users without CAP_SYS_ADMIN       Disallow raw tracepoint access by users without CAP_SYS_ADMIN &gt;= 1: Disallow CPU event access by users without CAP_SYS_ADMIN &gt;= 2: Disallow kernel profiling by users without CAP_SYS_ADMIN  To make this setting permanent, edit \/etc\/sysctl.conf too, e.g.:     kernel.perf_event_paranoid = -1 ]<\/code><\/pre>\n<p>\u0422\u0430\u043a, \u043f\u0435\u0440\u0444 \u0437\u0430\u0432\u0451\u043b\u0441\u044f, \u0443\u0436\u0435 \u0445\u043e\u0440\u043e\u0448\u043e. \u041e\u0448\u0438\u0431\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u0441 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u043e\u0431\u044b\u0442\u0438\u044f\u043c \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u044f\u0434\u0440\u0430. \u041e\u043d\u0430 \u0445\u043e\u0440\u043e\u0448\u043e \u0437\u043d\u0430\u043a\u043e\u043c\u0430 \u0442\u0435\u043c, \u043a\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 async-profiler-\u043e\u043c, \u0438 \u0432 \u041b\u0438\u043d\u0443\u043a\u0441\u0435 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u044b\u0447\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"bash\">$ sudo sh -c 'echo 1 &gt; \/proc\/sys\/kernel\/perf_event_paranoid'<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0414\u043b\u044f \u043b\u0435\u043d\u0438\u0432\u044b\u0445 \u043f\u043e\u043a\u0430\u0436\u0443 \u043e\u0434\u0438\u043d \u0444\u0438\u043d\u0442 \u0443\u0448\u0430\u043c\u0438<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0414\u0435\u043b\u0430\u0439 \u0440\u0430\u0437: \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u043a \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430 \u0441 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u043e\u043c <\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/wx\/iw\/ei\/wxiweinas9ascwme6v7yfdptzxs.png\" width=\"838\" height=\"146\"><figcaption><\/figcaption><\/figure>\n<p>\u0414\u0435\u043b\u0430\u0439 \u0434\u0432\u0430: \u043d\u0430\u0436\u0438\u043c\u0430\u0435\u043c \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 \u0432\u043e \u0432\u0441\u043f\u043b\u044b\u0432\u0430\u044e\u0449\u0435\u0439 \u043e\u0448\u0438\u0431\u043a\u0435 <\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/fl\/lu\/kj\/fllukjdl8wr32ole-gytwzx2k6k.png\" width=\"601\" height=\"177\"><figcaption><\/figcaption><\/figure>\n<p>\u0414\u0435\u043b\u0430\u0439 \u0442\u0440\u0438: \u0441\u043e\u0433\u043b\u0430\u0448\u0430\u0435\u043c\u0441\u044f \u0438 \u0432\u0432\u043e\u0434\u0438\u043c \u043f\u0430\u0440\u043e\u043b\u044c <\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/i8\/nn\/fc\/i8nnfcpdpfizybj3jbdcifcseaa.png\" width=\"1236\" height=\"523\"><figcaption><\/figcaption><\/figure>\n<\/div>\n<\/details>\n<p>\u041d\u0443 \u0442\u0435\u043f\u0435\u0440\u044c-\u0442\u043e \u0442\u043e\u0447\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0437\u0430\u0432\u0435\u0441\u0442\u0438\u0441\u044c! \u0418 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0432\u0441\u0451 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e. \u0411\u0435\u043d\u0447\u043c\u0430\u0440\u043a \u0434\u043e\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u0432\u043e\u0451, \u043c\u044b \u043f\u0440\u043e\u043c\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0438\u2026 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u043e\u0431\u043b\u043e\u043c:<\/p>\n<pre><code>ERROR: No address lines detected in assembly capture. Make sure your JDK is properly configured to print generated assembly. The most probable cause for this failure is that hsdis is not available, or resides at the wrong path within the JDK. Try to run the same JDK with -XX:+PrintAssembly with a simple non-JMH program and look for warning messages. For details, see the link below:     https:\/\/wiki.openjdk.java.net\/display\/HotSpot\/PrintAssembly<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0447\u0438\u0442\u0430\u0432 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 <a href=\"https:\/\/wiki.openjdk.java.net\/display\/HotSpot\/PrintAssembly\" rel=\"noopener noreferrer nofollow\">\u0441\u0441\u044b\u043b\u043a\u0435<\/a> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u043a <code>BenchmarkRunner<\/code>-\u0443 \u0438 \u0434\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u043e\u0435:<\/p>\n<pre><code class=\"java\">Options opt = new OptionsBuilder()   .include(ConcurrentReferenceHashMapBenchmark.class.getSimpleName())   .warmupIterations(10)   .warmupTime(TimeValue.seconds(1))   .measurementIterations(10)   .measurementTime(TimeValue.seconds(10))   .addProfiler(LinuxPerfAsmProfiler.class)   .jvmArgsAppend(     \"-XX:+UnlockDiagnosticVMOptions\",           \/\/ &lt;-------     \"-XX:+PrintAssembly\"   )   .forks(1)   .build();  new Runner(opt).run();<\/code><\/pre>\n<p>\u041d\u043e \u0438 \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e, \u0432\u0435\u0434\u044c \u043a\u0440\u043e\u043c\u0435 \u043f\u0440\u043e\u0447\u0435\u0433\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0432 \u0412\u041c \u043f\u043b\u0430\u0433\u0438\u043d <code>hsdis<\/code> \u0434\u043b\u044f \u0434\u0438\u0437\u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043f\u0440\u0438 \u0447\u0451\u043c \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 \u0432\u044b\u0448\u0435 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0435\u0433\u043e \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u043e\u0432. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e \u0434\u043b\u044f \u043d\u0430\u0441 \u0434\u043e\u0431\u0440\u044b\u0435 \u043b\u044e\u0434\u0438 \u0443\u0436\u0435 \u0432\u0441\u0451 \u0441\u0434\u0435\u043b\u0430\u043b\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0433\u043e\u0442\u043e\u0432\u0443\u044e \u0441\u0431\u043e\u0440\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0441 <a href=\"https:\/\/github.com\/liuzhengyang\/hsdis\/blob\/master\/build\/linux-amd64\/hsdis-amd64.so\" rel=\"noopener noreferrer nofollow\">\u0413\u0438\u0442\u0425\u0430\u0431\u0430<\/a>. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0432 \u043c\u043e\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044f \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u044e <code>hsdis-amd64.so<\/code>. \u0412 \u044d\u0442\u043e\u043c \u0436\u0435 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f <code>hsdis-amd64.dylib<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u041c\u0430\u043a\u043e\u0432.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0435\u0433\u043e \u0432 \u043f\u0430\u043f\u043a\u0443, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0444\u0430\u0439\u043b <code>libjvm.so<\/code>, \u0443 \u043c\u0435\u043d\u044f \u0441 openjdk-8 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a:<\/p>\n<pre><code class=\"bash\">$ find \/usr -name libjvm.so \/usr\/lib\/jvm\/java-8-openjdk-amd64\/jre\/lib\/amd64\/server\/libjvm.so  $ sudo cp hsdis-amd64.so \/usr\/lib\/jvm\/java-8-openjdk-amd64\/jre\/lib\/amd64\/server\/<\/code><\/pre>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0443 \u0432\u0430\u0441 \u0438\u043d\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0438 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440. \u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c? \u0421\u0430\u043c\u044b\u0439 \u0432\u0435\u0440\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 &#8212; \u0441\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e. \u0417\u0434\u0435\u0441\u044c \u0434\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430:<\/p>\n<p>1) \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0443, \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u043c\u0443 \u0432 <a href=\"https:\/\/github.com\/liuzhengyang\/hsdis\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/liuzhengyang\/hsdis<\/a><br \/>2) \u0441\u043e\u0431\u0440\u0430\u0442\u044c <code>hsdis<\/code> \u0438\u0437 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0445 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 OpenJDK \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u043e\u0432<\/p>\n<p>\u0412\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c <a href=\"https:\/\/hg.openjdk.java.net\/jdk\/jdk\/\" rel=\"noopener noreferrer nofollow\">OpenJDK<\/a> \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<pre><code class=\"bash\"># \u043f\u0440\u0435\u0434\u043f\u043e\u0436\u0438\u043c, \u0432\u044b \u0432\u044b\u043a\u0430\u0447\u0430\u043b\u0438 \u043f\u0440\u043e\u0435\u043a\u0442 \u0432 ~\/IdeaProjects\/jdk14 $ cd ~\/IdeaProjects\/jdk14\/src\/utils\/hsdis\/ # \u043a\u0430\u0447\u0430\u0435\u043c \u0441\u0432\u0435\u0436\u0438\u0439 binutils (\u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u0435\u0440\u0441\u0438\u044f 2.26) $ wget http:\/\/ftpmirror.gnu.org\/gnu\/binutils\/binutils-2.35.tar.gz # \u0440\u0430\u0437\u0436\u0438\u043c\u0430\u0435\u043c $ tar zxvf binutils-2.35.tar.gz # \u0437\u0430\u0434\u0430\u0451\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f BINUTILS $ export BINUTILS=binutils-2.35 # \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u043e\u0434 amd64, \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u043f\u043e\u0434 i356, \u0442\u043e make ARCH=i356 \u0438 \u0442.\u043f. $ make ARCH=amd64 # \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c 64 \u0431\u0438\u0442\u043d\u0443\u044e \u043b\u0438\u043d\u0443\u043a\u0441\u043e\u0432\u0443\u044e \u0441\u0431\u043e\u0440\u043a\u0443 \u0432 \u0442\u0443 \u0436\u0435 \u043f\u0430\u043f\u043a\u0443, \u0433\u0434\u0435 \u043b\u0435\u0436\u0438\u0442 libjvm.so $ sudo cp build\/linux\/amd64\/hsdis-amd64.so \/usr\/lib\/jvm\/java-8-openjdk-amd64\/jre\/lib\/amd64\/server\/ <\/code><\/pre>\n<p>\u0418 \u0432\u043e\u0442 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043c\u044b, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0432\u0438\u0434\u0438\u043c \u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440, \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u043e\u043c. \u0412\u044b\u0432\u043e\u0434 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0434\u0432\u0443\u0445 \u0433\u043e\u0440\u044f\u0447\u0438\u0445 \u043c\u0435\u0441\u0442 \u0432 \u043a\u043e\u0434\u0435 (\u0446\u0435\u043b\u0438\u043a\u043e\u043c <a href=\"https:\/\/gist.github.com\/stsypanov\/2132afe210c704dc0efd1462ac948251\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>):<\/p>\n<pre><code>....[Hottest Methods (after inlining)]..............................................................  54.56%         C2, level 4  org.tsypanov.sb.misc.jmh_generated.LoopyBenchmarks_goodOldLoop_jmhTest::goodOldLoop_avgt_jmhStub, version 584  43.41%         C2, level 4  org.openjdk.jmh.infra.Blackhole::consume, version 561   0.59%   [kernel.kallsyms]  native_write_msr   0.08%   [kernel.kallsyms]  do_syscall_64   0.06%   [kernel.kallsyms]  entry_SYSCALL_64   0.04%           libjvm.so  fileStream::write   0.03%           libjvm.so  is_error_reported   0.02%   [kernel.kallsyms]  _raw_spin_lock_irq   0.02%   [kernel.kallsyms]  syscall_return_via_sysret   0.02%   [kernel.kallsyms]  prepare_exit_to_usermode   0.02%   [kernel.kallsyms]  __fget   0.02%           libjvm.so  SpinPause   0.02%      hsdis-amd64.so  print_insn   0.02%           libjvm.so  outputStream::print   0.02%   [kernel.kallsyms]  iov_iter_copy_from_user_atomic   0.02%   [kernel.kallsyms]  vfs_write   0.02%   [kernel.kallsyms]  kill_fasync   0.02%   [kernel.kallsyms]  __x64_sys_write   0.02%   [kernel.kallsyms]  psi_task_change   0.02%        libc-2.27.so  __GI___libc_write   0.94%  &lt;...other 81 warm methods...&gt; ....................................................................................................  99.99%  &lt;totals&gt;<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>[Hottest Region 1]<\/summary>\n<div class=\"spoiler__content\">\n<pre><code>C2, level 4, org.tsypanov.sb.misc.jmh_generated.LoopyBenchmarks_goodOldLoop_jmhTest::goodOldLoop_avgt_jmhStub, version 584 (130 bytes)                  0x00007fb4512539bd: mov    0x50(%rsp),%r9                 0x00007fb4512539c2: movzbl 0x94(%r9),%r11d    ;*getfield isDone                                                               ; - org.tsypanov.sb.misc.jmh_generated.LoopyBenchmarks_goodOldLoop_jmhTest::goodOldLoop_avgt_jmhStub@27 (line 188)                                                               ; implicit exception: dispatches to 0x00007fb451253bb5                 0x00007fb4512539ca: test   %r11d,%r11d                 0x00007fb4512539cd: jne    0x00007fb451253a85  ;*ifeq                                                               ; - org.tsypanov.sb.misc.jmh_generated.LoopyBenchmarks_goodOldLoop_jmhTest::goodOldLoop_avgt_jmhStub@30 (line 188)                 0x00007fb4512539d3: mov    $0x1,%ebx          \u256d      0x00007fb4512539d8: jmp    0x00007fb451253a45          \u2502      0x00007fb4512539da: nopw   0x0(%rax,%rax,1)   9.48%  \u2502     0x00007fb4512539e0: mov    0x50(%rsp),%r9   0.02%  \u2502 \u2502    0x00007fb4512539e5: mov    (%rsp),%rbx        ;*aload_1          \u2502 \u2502                                                  ; - org.tsypanov.sb.misc.LoopyBenchmarks::goodOldLoop@11 (line 25)          \u2502 \u2502                                                  ; - org.tsypanov.sb.misc.jmh_generated.LoopyBenchmarks_goodOldLoop_jmhTest::goodOldLoop_avgt_jmhStub@17 (line 186)   0.82%  \u2502 \u2502   0x00007fb4512539e9: mov    0xc(%r12,%r11,8),%r8d  ; implicit exception: dispatches to 0x00007fb451253b2d   0.08%  \u2502 \u2502 \u2502  0x00007fb4512539ee: cmp    %r8d,%ebp   0.01%  \u2502\u256d\u2502 \u2502  0x00007fb4512539f1: jae    0x00007fb451253a66   9.32%  \u2502\u2502\u2502 \u2502  0x00007fb4512539f3: mov    %rbx,(%rsp)   0.03%  \u2502\u2502\u2502 \u2502  0x00007fb4512539f7: mov    %r9,0x50(%rsp)   0.76%  \u2502\u2502\u2502 \u2502  0x00007fb4512539fc: lea    (%r12,%r11,8),%r10   0.02%  \u2502\u2502\u2502 \u2502  0x00007fb451253a00: movsbl 0x10(%r10,%rbp,1),%edx  ;*baload          \u2502\u2502\u2502 \u2502                                                ; - org.tsypanov.sb.misc.LoopyBenchmarks::goodOldLoop@17 (line 25)          \u2502\u2502\u2502 \u2502                                                ; - org.tsypanov.sb.misc.jmh_generated.LoopyBenchmarks_goodOldLoop_jmhTest::goodOldLoop_avgt_jmhStub@17 (line 186)   9.52%  \u2502\u2502\u2502 \u2502  0x00007fb451253a06: mov    0x18(%rsp),%rsi   0.06%  \u2502\u2502\u2502 \u2502  0x00007fb451253a0b: callq  0x00007fb451045de0  ; OopMap{[80]=Oop [88]=Oop [96]=Oop [24]=Oop off=240}          \u2502\u2502\u2502 \u2502                                                ;*invokevirtual consume          \u2502\u2502\u2502 \u2502                                                ; - org.tsypanov.sb.misc.LoopyBenchmarks::goodOldLoop@18 (line 25)          \u2502\u2502\u2502 \u2502                                                ; - org.tsypanov.sb.misc.jmh_generated.LoopyBenchmarks_goodOldLoop_jmhTest::goodOldLoop_avgt_jmhStub@17 (line 186)          \u2502\u2502\u2502 \u2502                                                ;   {optimized virtual_call}   6.61%  \u2502\u2502\u2502 \u2502  0x00007fb451253a10: mov    0x60(%rsp),%r10   9.18%  \u2502\u2502\u2502 \u2502  0x00007fb451253a15: mov    0x10(%r10),%r11d   ;*getfield bunn          \u2502\u2502\u2502 \u2502                                                ; - org.tsypanov.sb.misc.LoopyBenchmarks::goodOldLoop@4 (line 24)          \u2502\u2502\u2502 \u2502                                                ; - org.tsypanov.sb.misc.jmh_generated.LoopyBenchmarks_goodOldLoop_jmhTest::goodOldLoop_avgt_jmhStub@17 (line 186)   0.15%  \u2502\u2502\u2502 \u2502  0x00007fb451253a19: mov    0xc(%r12,%r11,8),%r8d  ; implicit exception: dispatches to 0x00007fb451253b3d   6.78%  \u2502\u2502\u2502 \u2502  0x00007fb451253a1e: inc    %ebp               ;*iinc          \u2502\u2502\u2502 \u2502                                                ; - org.tsypanov.sb.misc.LoopyBenchmarks::goodOldLoop@21 (line 24)          \u2502\u2502\u2502 \u2502                                                ; - org.tsypanov.sb.misc.jmh_generated.LoopyBenchmarks_goodOldLoop_jmhTest::goodOldLoop_avgt_jmhStub@17 (line 186)   0.01%  \u2502\u2502\u2502 \u2502  0x00007fb451253a20: cmp    %r8d,%ebp   0.02%  \u2502\u2502\u2570 \u2502  0x00007fb451253a23: jl     0x00007fb4512539e0   0.41%  \u2502\u2502  \u2502  0x00007fb451253a25: mov    0x50(%rsp),%r9   0.07%  \u2502\u2502  \u2502  0x00007fb451253a2a: mov    (%rsp),%rbx        ;*if_icmpge          \u2502\u2502  \u2502                                                ; - org.tsypanov.sb.misc.LoopyBenchmarks::goodOldLoop@8 (line 24)          \u2502\u2502  \u2502                                                ; - org.tsypanov.sb.misc.jmh_generated.LoopyBenchmarks_goodOldLoop_jmhTest::goodOldLoop_avgt_jmhStub@17 (line 186)   0.02%  \u2502\u2502 \u2502  0x00007fb451253a2e: movzbl 0x94(%r9),%r10d    ;*getfield isDone          \u2502\u2502 \u2502\u2502                                                ; - org.tsypanov.sb.misc.jmh_generated.LoopyBenchmarks_goodOldLoop_jmhTest::goodOldLoop_avgt_jmhStub@27 (line 188)   0.07%  \u2502\u2502 \u2502\u2502  0x00007fb451253a36: add    $0x1,%rbx          ; OopMap{r9=Oop [88]=Oop [96]=Oop [24]=Oop off=282}          \u2502\u2502 \u2502\u2502                                                ;*ifeq          \u2502\u2502 \u2502\u2502                                                ; - org.tsypanov.sb.misc.jmh_generated.LoopyBenchmarks_goodOldLoop_jmhTest::goodOldLoop_avgt_jmhStub@30 (line 188)   0.28%  \u2502\u2502 \u2502\u2502  0x00007fb451253a3a: test   %eax,0x1837a5c0(%rip)        # 0x00007fb4695ce000          \u2502\u2502 \u2502\u2502                                                ;   {poll}   0.01%  \u2502\u2502 \u2502\u2502  0x00007fb451253a40: test   %r10d,%r10d          \u2502\u2502 \u2502\u2502  0x00007fb451253a43: jne    0x00007fb451253a8a  ;*aload          \u2502\u2502 \u2502\u2502                                                ; - org.tsypanov.sb.misc.jmh_generated.LoopyBenchmarks_goodOldLoop_jmhTest::goodOldLoop_avgt_jmhStub@13 (line 186)   0.03%  \u2502 \u2502\u2502  0x00007fb451253a45: mov    0x60(%rsp),%r10   0.02%   \u2502 \u2502\u2502  0x00007fb451253a4a: mov    0x10(%r10),%r11d   ;*getfield bunn           \u2502 \u2502\u2502                                                ; - org.tsypanov.sb.misc.LoopyBenchmarks::goodOldLoop@4 (line 24)           \u2502 \u2502\u2502                                                ; - org.tsypanov.sb.misc.jmh_generated.LoopyBenchmarks_goodOldLoop_jmhTest::goodOldLoop_avgt_jmhStub@17 (line 186)   0.35%   \u2502 \u2502\u2502  0x00007fb451253a4e: mov    0xc(%r12,%r11,8),%r10d  ; implicit exception: dispatches to 0x00007fb451253b4d   0.06%   \u2502 \u2502\u2502  0x00007fb451253a53: test   %r10d,%r10d           \u2502 \u2570\u2502  0x00007fb451253a56: jle    0x00007fb451253a2e  ;*if_icmpge           \u2502  \u2502                                                ; - org.tsypanov.sb.misc.LoopyBenchmarks::goodOldLoop@8 (line 24)           \u2502  \u2502                                                ; - org.tsypanov.sb.misc.jmh_generated.LoopyBenchmarks_goodOldLoop_jmhTest::goodOldLoop_avgt_jmhStub@17 (line 186)   0.11%   \u2502  \u2502  0x00007fb451253a58: mov    0x18(%rsp),%r10           \u2502  \u2502  0x00007fb451253a5d: test   %r10,%r10           \u2502  \u2502  0x00007fb451253a60: je     0x00007fb451253ab4  ;*aload_1           \u2502  \u2502                                                ; - org.tsypanov.sb.misc.LoopyBenchmarks::goodOldLoop@11 (line 25)           \u2502  \u2502                                                ; - org.tsypanov.sb.misc.jmh_generated.LoopyBenchmarks_goodOldLoop_jmhTest::goodOldLoop_avgt_jmhStub@17 (line 186)   0.24%   \u2502  \u2502  0x00007fb451253a62: xor    %ebp,%ebp           \u2502  \u2570  0x00007fb451253a64: jmp    0x00007fb4512539e9                0x00007fb451253a66: mov    $0xffffffe4,%esi                 0x00007fb451253a6b: mov    %r9,0x50(%rsp)                 0x00007fb451253a70: mov    %rbx,0x8(%rsp)                 0x00007fb451253a75: mov    %r11d,0x28(%rsp)                 0x00007fb451253a7a: nop                 0x00007fb451253a7b: callq  0x00007fb4510453e0  ; OopMap{[80]=Oop [88]=Oop [96]=Oop [24]=Oop [40]=NarrowOop off=352}                                                               ;*baload<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u041f\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0443: \u0441\u043b\u0435\u0432\u0430 \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u0434\u043e\u043b\u044e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u0442\u043e\u0442 \u0438\u043b\u0438 \u0438\u043d\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u0430, \u0441\u043b\u0435\u0432\u0430 &#8212; \u0441\u0430\u043c\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0438\u043c \u0431\u0430\u0439\u0442-\u043a\u043e\u0434, \u0430 \u0435\u0449\u0451 \u043b\u0435\u0432\u0435\u0435 &#8212; \u0442\u043e\u0447\u043d\u043e\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u043d\u0430 \u043c\u0435\u0442\u043e\u0434 \u0438 \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c Java-\u043a\u043e\u0434\u0435!<\/p>\n<p>\u0412\u0430\u0436\u043d\u043e\u0435 \u0437\u0434\u0435\u0441\u044c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0441\u0442\u0440\u043e\u043a\u0430\u0445 14, 23, 33, \u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0449\u0438\u0445, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0447\u0442\u0435\u043d\u0438\u0435 <code>this<\/code>, \u0447\u0442\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f <code>bunn<\/code>\u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u0438\u043d\u044b \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0447\u0442\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u0436\u0435 \u043f\u043e\u043b\u044f \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0431\u0430\u0439\u0442\u0430 \u0432 <code>Blackhole::consume<\/code>.<\/p>\n<details class=\"spoiler\">\n<summary>[Hottest Region 2]<\/summary>\n<div class=\"spoiler__content\">\n<pre><code>C2, level 4, org.openjdk.jmh.infra.Blackhole::consume, version 561 (53 bytes)              # parm0:    rdx       = byte             #           [sp+0x30]  (sp of caller)             0x00007fb45123b7a0: mov    0x8(%rsi),%r10d             0x00007fb45123b7a4: shl    $0x3,%r10             0x00007fb45123b7a8: cmp    %r10,%rax             0x00007fb45123b7ab: jne    0x00007fb451045ba0  ;   {runtime_call}             0x00007fb45123b7b1: data16 xchg %ax,%ax             0x00007fb45123b7b4: nopl   0x0(%rax,%rax,1)             0x00007fb45123b7bc: data16 data16 xchg %ax,%ax           [Verified Entry Point]   0.95%     0x00007fb45123b7c0: mov    %eax,-0x14000(%rsp)   9.97%     0x00007fb45123b7c7: push   %rbp   1.11%     0x00007fb45123b7c8: sub    $0x20,%rsp         ;*synchronization entry                                                           ; - org.openjdk.jmh.infra.Blackhole::consume@-1 (line 322)   9.93%     0x00007fb45123b7cc: movsbl 0xd0(%rsi),%r10d   ;*getfield b1                                                           ; - org.openjdk.jmh.infra.Blackhole::consume@1 (line 322)   0.11%     0x00007fb45123b7d4: mov    %edx,%r8d   0.83%     0x00007fb45123b7d7: xor    %r10d,%r8d         ;*ixor                                                           ; - org.openjdk.jmh.infra.Blackhole::consume@12 (line 324)   0.08%     0x00007fb45123b7da: movsbl 0xd2(%rsi),%r11d   9.38%     0x00007fb45123b7e2: xor    %edx,%r11d         ;*ixor                                                           ; - org.openjdk.jmh.infra.Blackhole::consume@15 (line 324)   0.06%     0x00007fb45123b7e5: cmp    %r11d,%r8d          \u256d  0x00007fb45123b7e8: je     0x00007fb45123b7f6  ;*if_icmpne          \u2502                                                ; - org.openjdk.jmh.infra.Blackhole::consume@16 (line 324)   0.81%  \u2502  0x00007fb45123b7ea: add    $0x20,%rsp   0.01%  \u2502  0x00007fb45123b7ee: pop    %rbp  10.09%  \u2502  0x00007fb45123b7ef: test   %eax,0x1839280b(%rip)        # 0x00007fb4695ce000          \u2502                                                ;   {poll_return}   0.08%  \u2502  0x00007fb45123b7f5: retq            0x00007fb45123b7f6: mov    %rsi,%rbp             0x00007fb45123b7f9: mov    %edx,(%rsp)             0x00007fb45123b7fc: mov    %r8d,0x4(%rsp)             0x00007fb45123b801: mov    %r11d,0x8(%rsp)             0x00007fb45123b806: mov    $0xffffff65,%esi             0x00007fb45123b80b: callq  0x00007fb4510453e0  ; OopMap{rbp=Oop off=112}                                                           ;*if_icmpne                                                           ; - org.openjdk.jmh.infra.Blackhole::consume@16 (line 324)                                                           ;   {runtime_call}<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0417\u0434\u0435\u0441\u044c \u0431\u0435\u0437 \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u043e\u0441\u0442\u0435\u0439: \u043b\u044c\u0432\u0438\u043d\u0430\u044f \u0434\u043e\u043b\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0442\u0440\u0430\u0442\u0438\u0442\u0441\u044f \u043d\u0430 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u043b\u0438 \u0432\u044b\u0432\u043e\u0434 \u0430\u0432\u0442\u043e\u0440\u0430: \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u0432\u043d\u0443\u0442\u0440\u0438 \u0446\u0438\u043a\u043b\u0430, \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u044e\u0449\u0435\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432 \u043f\u0443\u0442\u0451\u043c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u043f\u043e\u043b\u044e \u0441\u0438\u043b\u044c\u043d\u043e \u0431\u044c\u0451\u0442 \u043f\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438\u0437-\u0437\u0430 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0439 JMM \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u044c \u0432\u0441\u0435\u0445 \u0447\u0442\u0435\u043d\u0438\u0439. \u041d\u0430 \u0434\u0435\u043b\u0435 \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u044f \u0438 \u0447\u0442\u0435\u043d\u0438\u0435 \u0435\u0433\u043e \u0438\u0437 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u043f\u0440\u043e\u0445\u043e\u0434\u0435 \u043f\u043e \u0446\u0438\u043a\u043b\u0443.<\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0451, \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0437\u0430\u043c\u0435\u0442\u043a\u0430 \u0441\u0442\u0430\u043d\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u0434\u043b\u044f \u0432\u0430\u0441 \u0438 \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0447\u0430\u0449\u0435 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 \u0441\u0430\u043c\u0443\u044e \u0433\u043b\u0443\u0431\u0438\u043d\u0443 \u0432\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430 \u0438 \u0438\u0441\u043a\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0439. \u0414\u043e \u043d\u043e\u0432\u044b\u0445 \u0432\u0441\u0442\u0440\u0435\u0447.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/542148\/\"> https:\/\/habr.com\/ru\/post\/542148\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u0420\u0430\u0431\u043e\u0442\u0430\u044f \u043d\u0430\u0434 \u0442\u0435\u043c\u043e\u0439 \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u044f \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0433\u043e \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430 \u043f\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0438 \u0441\u0431\u043e\u0440\u0443 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430. \u0412\u0441\u0451 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u043c\u0443 \u043f\u0443\u0442\u0451\u043c \u043f\u0440\u043e\u0431 \u0438 \u043e\u0448\u0438\u0431\u043e\u043a. \u0418\u0442\u043e\u0433\u043e\u043c \u0441\u0442\u0430\u043b\u0430 \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044f \u043f\u043e \u0448\u0430\u0433\u0430\u043c \u043e\u043f\u0438\u0441\u0430\u043b \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430, \u0433\u043e\u0440\u044f\u0447\u0435\u0435 \u043c\u0435\u0441\u0442\u043e \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0435 \u0432 \u0441\u0438\u043b\u0430\u0445 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u0439 VisualVM, \u043d\u043e \u0438 \u0441\u0432\u0435\u0440\u0445\u0442\u043e\u0447\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0432\u0440\u043e\u0434\u0435 async-profiler-\u0430.  \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u043a\u043e\u0434 \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/psy-lob-saw.blogspot.com\/2014\/08\/the-volatile-read-suprise.html\" rel=\"noopener noreferrer nofollow\">The volatile read surprise<\/a>.<\/p>\n<h4>\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438<\/h4>\n<p>\u041a\u043e\u0433\u0434\u0430-\u0442\u043e \u0434\u0430\u0432\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0432 \u0441\u0442\u0430\u0442\u044c\u044e <a href=\"http:\/\/psy-lob-saw.blogspot.com\/2014\/08\/the-volatile-read-suprise.html\" rel=\"noopener noreferrer nofollow\">The volatile read surprise<\/a> \u043c\u043d\u0435 \u0441\u0442\u0430\u043b\u043e \u043b\u044e\u0431\u043e\u043f\u044b\u0442\u043d\u043e, \u043a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e \u0430\u0432\u0442\u043e\u0440 \u043f\u0440\u0438\u0448\u0451\u043b \u043a \u0441\u0434\u0435\u043b\u0430\u043d\u043d\u044b\u043c \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u0432\u044b\u0432\u043e\u0434\u0430\u043c. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043a\u0440\u0430\u0442\u043a\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u043c\u0441\u044f \u0441 \u043c\u0430\u0442\u0447\u0430\u0441\u0442\u044c\u044e:<\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u043e\u0434\u043e\u043f\u044b\u0442\u043d\u044b\u0439 \u043a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">@BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) @State(Scope.Thread) public class LoopyBenchmarks {   @Param({ \"32\", \"1024\", \"32768\" })   int size;    byte[] bunn;    @Setup   public void prepare() {     bunn = new byte[size];   }    @Benchmark   public void goodOldLoop(Blackhole fox) {     for (int y = 0; y &lt; bunn.length; y++) { \/\/ good old C style for (the win?)       fox.consume(bunn[y]);     }   }    @Benchmark   public void sweetLoop(Blackhole fox) {     for (byte bunny : bunn) { \/\/ syntactic sugar loop goodness       fox.consume(bunny);     }   } }<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a \u043c\u044b \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u0432 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b:<\/p>\n<pre><code>Benchmark              (size)     Score   Error  Units  goodOldLoop               32     46.630   0.097  ns\/op goodOldLoop             1024   1199.338   0.705  ns\/op goodOldLoop            32768  37813.600  56.081  ns\/op  sweetLoop                 32     19.304   0.010  ns\/op sweetLoop               1024    475.141   1.227  ns\/op sweetLoop              32768  14295.800  36.071  ns\/op<\/code><\/pre>\n<p>\u0413\u0434\u0435 \u0436\u0435 \u0432 \u043a\u043e\u0434\u0435 \u0433\u043e\u0440\u044f\u0447\u0435\u0435 \u043c\u0435\u0441\u0442\u043e? \u041a\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e\u0440\u043c\u043e\u0437\u0438\u0442 \u0432 \u043e\u0431\u044b\u0447\u043d\u043e\u043c \u0441\u0447\u0451\u0442\u043d\u043e\u043c \u0446\u0438\u043a\u043b\u0435? \u041f\u043e\u0447\u0435\u043c\u0443 \u0441\u0447\u0451\u0442\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u0432 \u0434\u0432\u0430 \u0440\u0430\u0437\u0430 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0447\u0435\u043c <code>for-each<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0441\u043b\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 <em>\u043f\u043e\u0447\u0442\u0438<\/em> \u0442\u043e\u0442 \u0436\u0435 \u0441\u0430\u043c\u044b\u0439 \u0441\u0447\u0451\u0442\u043d\u044b\u0439 \u0446\u0438\u043a\u043b.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041a\u0430\u043a \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435<\/summary>\n<div class=\"spoiler__content\">\n<p>The assembly code for the <code>goodOldLoop<\/code>is long and painful to read through, and that in itself is a clue.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0412\u044b\u0432\u043e\u0434 \u0430\u0432\u0442\u043e\u0440\u0430<\/summary>\n<div class=\"spoiler__content\">\n<p>The thing that stands out (when the assembly smoke clears) is that&nbsp;<em>bunn<\/em>&nbsp;is loaded on every iteration,&nbsp;<em>bunn.length<\/em>&nbsp;is loaded and an array boundary check happens. This is surely a terrible way to interpret a for loop. The culprit turns out to be a volatile read in Blackhole.consume(). &#8230; A volatile load of one value requires the JVM to load all subsequent loads from memory to force happens before relationships, in this case the field&nbsp;<em>bunn&nbsp;<\/em>is reloaded on every iteration of the loop. <\/p>\n<\/div>\n<\/details>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>-XX:+PrintAssembly<\/code> \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u0432\u0441\u0435\u0433\u043e \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439  \u0432 \u0441\u044b\u0440\u043e\u043c \u0432\u0438\u0434\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<details class=\"spoiler\">\n<summary>\u042d\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0430\u043b\u0430\u044f \u0447\u0430\u0441\u0442\u044c<\/summary>\n<div class=\"spoiler__content\">\n<pre><code>[Verified Entry Point]   0x00007f6605205020: mov    %eax,-0x14000(%rsp)   0x00007f6605205027: push   %rbp   0x00007f6605205028: sub    $0x30,%rsp         ;*synchronization entry                                                 ; - org.tsypanov.sb.misc.LoopyBenchmarks::goodOldLoop@-1 (line 24)    0x00007f660520502c: mov    %rdx,0x8(%rsp)   0x00007f6605205031: mov    %rsi,(%rsp)   0x00007f6605205035: mov    0x10(%rsi),%r11d   ;*getfield bunn                                                 ; - org.tsypanov.sb.misc.LoopyBenchmarks::goodOldLoop@4 (line 24)    0x00007f6605205039: mov    0xc(%r12,%r11,8),%r10d  ; implicit exception: dispatches to 0x00007f66052050e5   0x00007f660520503e: test   %r10d,%r10d   0x00007f6605205041: jle    0x00007f6605205084  ;*if_icmpge                                                 ; - org.tsypanov.sb.misc.LoopyBenchmarks::goodOldLoop@8 (line 24)    0x00007f6605205043: test   %rdx,%rdx   0x00007f6605205046: je     0x00007f66052050a5   0x00007f6605205048: xor    %ebp,%ebp   0x00007f660520504a: nopw   0x0(%rax,%rax,1)   ;*aload_1                                                 ; - org.tsypanov.sb.misc.LoopyBenchmarks::goodOldLoop@11 (line 25)    0x00007f6605205050: mov    0xc(%r12,%r11,8),%r10d  ; implicit exception: dispatches to 0x00007f66052050c6   0x00007f6605205055: cmp    %r10d,%ebp   0x00007f6605205058: jae    0x00007f6605205090   0x00007f660520505a: lea    (%r12,%r11,8),%r10   0x00007f660520505e: movsbl 0x10(%r10,%rbp,1),%edx  ;*baload                                                 ; - org.tsypanov.sb.misc.LoopyBenchmarks::goodOldLoop@17 (line 25)<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0418 \u0432\u0440\u043e\u0434\u0435 \u0431\u044b \u0442\u0443\u0442 \u0435\u0441\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u043d\u0430 \u0431\u0430\u0439\u0442-\u043a\u043e\u0434, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0442\u043e\u043c\u0443 \u0438\u043b\u0438 \u0438\u043d\u043e\u043c\u0443 \u043d\u0430\u0431\u043e\u0440\u0443 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439, \u0438  \u0434\u0430\u0436\u0435 \u0435\u0441\u0442\u044c \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 Java-\u043a\u043e\u0434\u0435, \u043d\u043e \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0433\u0434\u0435 \u0438 \u043d\u0430 \u0447\u0442\u043e \u0442\u0440\u0430\u0442\u0438\u0442\u0441\u044f \u043b\u044c\u0432\u0438\u043d\u0430\u044f \u0434\u043e\u043b\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u0438! \u0425\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043d\u0443\u0436\u0434\u044b \u0432\u044b\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u043d\u0438 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u0430 \u0438 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0439 \u043f\u0440\u043e\u0444\u0438\u043b\u044c.<\/p>\n<p>\u042f \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b \u0440\u0430\u0437\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b, \u043e\u0434\u043d\u0430\u043a\u043e \u043a\u043e\u0434\u0430 \u043e\u0447\u0435\u043d\u044c \u043c\u0430\u043b\u043e, \u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u043e\u0439 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c. \u041e\u0441\u0442\u0430\u0432\u0430\u043b\u043e\u0441\u044c \u043e\u0434\u043d\u043e: \u043f\u043e\u0433\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0433\u043b\u0443\u0431\u0438\u043d\u0443 \u0432 \u0445\u043e\u043b\u043e\u0434\u043d\u044b\u0435 \u0438 \u043c\u0440\u0430\u0447\u043d\u044b\u0435 \u0433\u043b\u0443\u0431\u0438\u043d\u044b.<\/p>\n<h4>\u041d\u044b\u0440\u044f\u0435\u043c<\/h4>\n<p>\u0411\u0430\u0442\u0438\u0441\u043a\u0430\u0444\u043e\u043c \u043d\u0430\u043c \u043f\u043e\u0441\u043b\u0443\u0436\u0438\u0442 <code>org.openjdk.jmh.profile.LinuxPerfAsmProfiler<\/code>, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0439 \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 JMH. \u0414\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d \u043f\u0440\u044f\u043c\u043e \u0432 \u043a\u043e\u0434\u0435 (\u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0442\u0430\u043a\u0436\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 <code>-prof perfasm<\/code>):<\/p>\n<pre><code class=\"java\">public class BenchmarkRunner {    public static void main(String[] args) throws RunnerException {     Options opt = new OptionsBuilder()       .include(LoopyBenchmark.class.getSimpleName())       .warmupIterations(10)       .warmupTime(TimeValue.seconds(1))       .measurementIterations(1)       .measurementTime(TimeValue.seconds(10))       .addProfiler(LinuxPerfAsmProfiler.class)       .forks(1) \/\/0 makes debugging possible       .build();      new Runner(opt).run();   } }<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u044f \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u043d\u043e \u0432\u044b\u0441\u0442\u0430\u0432\u0438\u043b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>forks<\/code> (\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 Java-\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432) \u0440\u0430\u0432\u043d\u044b\u043c 1. \u041e\u0431\u044b\u0447\u043d\u043e \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0439 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 Java-\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0436\u0435 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0443\u0436\u0435\u043d \u043e\u0434\u0438\u043d, \u0442. \u043a. \u0430\u0434\u0440\u0435\u0441\u0430 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u044b\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 \u043c\u043e\u0433\u0443\u0442 \u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u043e\u0442 \u043f\u0440\u043e\u0433\u043e\u043d\u0430 \u043a \u043f\u0440\u043e\u0433\u043e\u043d\u0443, \u0447\u0442\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e <a href=\"https:\/\/hg.openjdk.java.net\/code-tools\/jmh\/file\/037acc4657c3\/jmh-samples\/src\/main\/java\/org\/openjdk\/jmh\/samples\/JMHSample_35_Profilers.java#l596\" rel=\"noopener noreferrer nofollow\">\u043e\u0433\u043e\u0432\u043e\u0440\u0435\u043d\u043e \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>.<\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c:<\/p>\n<pre><code>[Cannot run program \"perf\": error=2, No such file or directory] Exception in thread \"main\" org.openjdk.jmh.runner.ProfilersFailedException: Profilers failed to initialize, exiting.     at org.openjdk.jmh.runner.Runner.internalRun(Runner.java:244)     at org.openjdk.jmh.runner.Runner.run(Runner.java:209)<\/code><\/pre>\n<p>\u0418\u0442\u0430\u043a, \u043f\u0435\u0440\u0432\u043e\u0435 \u043f\u0440\u0435\u043f\u044f\u0442\u0441\u0442\u0432\u0438\u0435: \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 <code>perf<\/code>. \u0422\u0443\u0442 \u043f\u0440\u043e\u0441\u0442\u043e: \u0431\u0435\u0433\u043b\u044b\u0439 \u043f\u043e\u0438\u0441\u043a \u0432 \u042f\u043d\u0434\u0435\u043a\u0441\u0435 \u0434\u0430\u0451\u0442 <a href=\"https:\/\/askubuntu.com\/a\/50148\" rel=\"noopener noreferrer nofollow\">\u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0443<\/a>:<\/p>\n<blockquote>\n<p>The perf utility can be found in the linux-tools package<\/p>\n<\/blockquote>\n<p>\u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"bash\">$ sudo apt-get install linux-tools-generic<\/code><\/pre>\n<p>\u0417\u0430\u0432\u043e\u0434\u0438\u043c \u0435\u0449\u0451 \u0440\u0430\u0437:<\/p>\n<pre><code>[WARNING: perf not found for kernel 5.4.0-42    You may need to install the following packages for this specific kernel:     linux-tools-5.4.0-42-generic     linux-cloud-tools-5.4.0-42-generic    You may also want to install one of the following packages to keep up to date:     linux-tools-generic     linux-cloud-tools-generic ] Exception in thread \"main\" org.openjdk.jmh.runner.ProfilersFailedException: Profilers failed to initialize, exiting.<\/code><\/pre>\n<p>\u0425\u043c, \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043d\u0443\u0436\u043d\u044b\u0439 \u043d\u0430\u043c <code>perf<\/code> \u043d\u0435 \u0434\u043e\u0435\u0445\u0430\u043b. \u0418\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c:<\/p>\n<pre><code class=\"bash\">$ sudo apt-get install linux-tools-5.4.0-42-generic<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0435 <code>5.4.0-42-generic<\/code> \u0434\u043e\u043b\u0436\u043d\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0440\u0441\u0438\u0438 \u0432\u0430\u0448\u0435\u0433\u043e \u044f\u0434\u0440\u0430. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435: \u0435\u0441\u043b\u0438 \u043f\u043e\u0441\u043b\u0435 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0433\u043e <code>sudo apt-get dist-upgrade<\/code> \u0443 \u0432\u0430\u0441 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u044f\u0434\u0440\u043e, \u0442\u043e <code>linux-tools<\/code> \u0442\u043e\u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c.<\/p>\n<p>\u041f\u0443\u0441\u043a\u0430\u0435\u043c \u0435\u0449\u0451 \u0440\u0430\u0437:<\/p>\n<pre><code>[Error: You may not have permission to collect stats.  Consider tweaking \/proc\/sys\/kernel\/perf_event_paranoid, which controls use of the performance events system by unprivileged users (without CAP_SYS_ADMIN).  The current value is 3:    -1: Allow use of (almost) all events by all users       Ignore mlock limit after perf_event_mlock_kb without CAP_IPC_LOCK &gt;= 0: Disallow ftrace function tracepoint by users without CAP_SYS_ADMIN       Disallow raw tracepoint access by users without CAP_SYS_ADMIN &gt;= 1: Disallow CPU event access by users without CAP_SYS_ADMIN &gt;= 2: Disallow kernel profiling by users without CAP_SYS_ADMIN  To make this setting permanent, edit \/etc\/sysctl.conf too, e.g.:     kernel.perf_event_paranoid = -1 ]<\/code><\/pre>\n<p>\u0422\u0430\u043a, \u043f\u0435\u0440\u0444 \u0437\u0430\u0432\u0451\u043b\u0441\u044f, \u0443\u0436\u0435 \u0445\u043e\u0440\u043e\u0448\u043e. \u041e\u0448\u0438\u0431\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u0441 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u043e\u0431\u044b\u0442\u0438\u044f\u043c \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u044f\u0434\u0440\u0430. \u041e\u043d\u0430 \u0445\u043e\u0440\u043e\u0448\u043e \u0437\u043d\u0430\u043a\u043e\u043c\u0430 \u0442\u0435\u043c, \u043a\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 async-profiler-\u043e\u043c, \u0438 \u0432 \u041b\u0438\u043d\u0443\u043a\u0441\u0435 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u044b\u0447\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"bash\">$ sudo sh -c 'echo 1 &gt; \/proc\/sys\/kernel\/perf_event_paranoid'<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0414\u043b\u044f \u043b\u0435\u043d\u0438\u0432\u044b\u0445 \u043f\u043e\u043a\u0430\u0436\u0443 \u043e\u0434\u0438\u043d \u0444\u0438\u043d\u0442 \u0443\u0448\u0430\u043c\u0438<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0414\u0435\u043b\u0430\u0439 \u0440\u0430\u0437: \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u043a \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430 \u0441 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u043e\u043c <\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0414\u0435\u043b\u0430\u0439 \u0434\u0432\u0430: \u043d\u0430\u0436\u0438\u043c\u0430\u0435\u043c \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 \u0432\u043e \u0432\u0441\u043f\u043b\u044b\u0432\u0430\u044e\u0449\u0435\u0439 \u043e\u0448\u0438\u0431\u043a\u0435 <\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0414\u0435\u043b\u0430\u0439 \u0442\u0440\u0438: \u0441\u043e\u0433\u043b\u0430\u0448\u0430\u0435\u043c\u0441\u044f \u0438 \u0432\u0432\u043e\u0434\u0438\u043c \u043f\u0430\u0440\u043e\u043b\u044c <\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<\/div>\n<\/details>\n<p>\u041d\u0443 \u0442\u0435\u043f\u0435\u0440\u044c-\u0442\u043e \u0442\u043e\u0447\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0437\u0430\u0432\u0435\u0441\u0442\u0438\u0441\u044c! \u0418 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0432\u0441\u0451 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e. \u0411\u0435\u043d\u0447\u043c\u0430\u0440\u043a \u0434\u043e\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u0432\u043e\u0451, \u043c\u044b \u043f\u0440\u043e\u043c\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0438\u2026 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u043e\u0431\u043b\u043e\u043c:<\/p>\n<pre><code>ERROR: No address lines detected in assembly capture. Make sure your JDK is properly configured to print generated assembly. The most probable cause for this failure is that hsdis is not available, or resides at the wrong path within the JDK. Try to run the same JDK with -XX:+PrintAssembly with a simple non-JMH program and look for warning messages. For details, see the link below:     https:\/\/wiki.openjdk.java.net\/display\/HotSpot\/PrintAssembly<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0447\u0438\u0442\u0430\u0432 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 <a href=\"https:\/\/wiki.openjdk.java.net\/display\/HotSpot\/PrintAssembly\" rel=\"noopener noreferrer nofollow\">\u0441\u0441\u044b\u043b\u043a\u0435<\/a> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u043a <code>BenchmarkRunner<\/code>-\u0443 \u0438 \u0434\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u043e\u0435:<\/p>\n<pre><code class=\"java\">Options opt = new OptionsBuilder()   .include(ConcurrentReferenceHashMapBenchmark.class.getSimpleName())   .warmupIterations(10)   .warmupTime(TimeValue.seconds(1))   .measurementIterations(10)   .measurementTime(TimeValue.seconds(10))   .addProfiler(LinuxPerfAsmProfiler.class)   .jvmArgsAppend(     \"-XX:+UnlockDiagnosticVMOptions\",           \/\/ &lt;-------     \"-XX:+PrintAssembly\"   )   .forks(1)   .build();  new Runner(opt).run();<\/code><\/pre>\n<p>\u041d\u043e \u0438 \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e, \u0432\u0435\u0434\u044c \u043a\u0440\u043e\u043c\u0435 \u043f\u0440\u043e\u0447\u0435\u0433\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0432 \u0412\u041c \u043f\u043b\u0430\u0433\u0438\u043d <code>hsdis<\/code> \u0434\u043b\u044f \u0434\u0438\u0437\u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043f\u0440\u0438 \u0447\u0451\u043c \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 \u0432\u044b\u0448\u0435 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0435\u0433\u043e \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u043e\u0432. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e \u0434\u043b\u044f \u043d\u0430\u0441 \u0434\u043e\u0431\u0440\u044b\u0435 \u043b\u044e\u0434\u0438 \u0443\u0436\u0435 \u0432\u0441\u0451 \u0441\u0434\u0435\u043b\u0430\u043b\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0433\u043e\u0442\u043e\u0432\u0443\u044e \u0441\u0431\u043e\u0440\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0441 <a href=\"https:\/\/github.com\/liuzhengyang\/hsdis\/blob\/master\/build\/linux-amd64\/hsdis-amd64.so\" rel=\"noopener noreferrer nofollow\">\u0413\u0438\u0442\u0425\u0430\u0431\u0430<\/a>. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0432 \u043c\u043e\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044f \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u044e <code>hsdis-amd64.so<\/code>. \u0412 \u044d\u0442\u043e\u043c \u0436\u0435 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f <code>hsdis-amd64.dylib<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u041c\u0430\u043a\u043e\u0432.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0435\u0433\u043e \u0432 \u043f\u0430\u043f\u043a\u0443, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0444\u0430\u0439\u043b <code>libj<\/code><\/p>\n<\/div>\n<\/details>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-322975","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/322975","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=322975"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/322975\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=322975"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=322975"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=322975"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}