åºè½ã¡ã§ç³ã訳ãªããã© jbangã§ãJavaã®ãã³ããã¼ã¯ãã¼ã«ã§ããjmhãå®è¡åºæ¥ãè¨äºãããã®ã§ããã®ãªã³ã¯ãè²¼ã£ã¦ããã ããããå¾è¿°ã®è©±ã«ç±æ¥ããã®ã ãã以ä¸ã®è¨äºã®profilerã®å®è¡ã¯ãã¾ã使ããªãã»ããè¯ãã¨æãããã jbangã«ãã£ã¦ãjmhãå®è¡ããã®ãç°¡åã«ãªã£ããã¨ã«çç®ãã¦ã»ããã
Benchmarks, Async profiler and JBang - @maxandersen
å¾æ¥ã®jmhã®å®è¡æ¹æ³ã¨ãã¦ã¯ãmavenããã¸ã§ã¯ããç¨æãã¦ãã³ã³ãã¤ã«ãã¦ãuberjarãä½ã£ã¦å®è¡ãããã¿ãããªã®ãå¤ãã£ãã
jbangã使ããã¨ã§ãmavenããã¸ã§ã¯ããuberjarãå¿
è¦ãªããpom.xmlã¨ããããã°ã§ããã.java
ãã¡ã¤ã«ã ãã§è¯ãã®ã¯æé«ã ï¼
ããã ãã§çµãã£ã¦ãã¾ãã¨ã¢ã¬ãªã®ã§ã以ä¸ã®è©±ãå°ãããã jmhæ¨æºã®profileæ©è½ã®è©±ã¨jcstressã®è©±ãæ¸ãã¦ãããã¨ã«ããã
- jmhã«ã¯ æ¨æºã§profilerã®æ©è½ãã¤ãã¦ãã
- jmhã®æ¨æºã®profiler㧠async-profilerã使ã£ã¦ã¿ã
- jcstress ã¨ã¯
- jbang㧠jcstressãå®è¡ãã¦ã¿ã
jmhã«ã¯ æ¨æºã§profilerã®æ©è½ãã¤ãã¦ãã
jmhã«ã¯æ¨æºã§æ§ã
ãªãã¼ã«ä¾åã»éä¾åã®profilingãå¯è½ã§ããã
jmhã®èµ·åæã« -lprof
ãå®è¡ããã¨ã以ä¸ã®profilerã®ä¸è¦§ã確èªã§ããã
- cl
- comp
- gc
- jfr
- pauses
- perfc2c
- safepoints
- stack
- async
- perf
- perfasm
- perfnorm
- xperfasm
å®éã« -lprof
ãä»ä¸ãã¦å®è¡ããã¨ãããªåºåãåºããå®è¡ç°å¢ãå¼æ°ã«ãã£ã¦ã¯ä½¿ããªãprofilerã«ã¤ãã¦ã表示ãã¦ãããã
Apple Siliconã®MacOSã§å®è¡ããã®ã§ãç°å¢ã«ãã£ã¦åºåãå¤ããå¯è½æ§ããããã¨ãä»è¨ãã¦ããã
jbang TestBenchmark.java -lprof Supported profilers: cl: Classloader profiling via standard MBeans comp: JIT compiler profiling via standard MBeans gc: GC profiling via standard MBeans jfr: Java Flight Recorder profiler pauses: Pauses profiler perfc2c: Linux perf c2c profiler safepoints: Safepoints profiler stack: Simple and naive Java stack profiler Unsupported profilers: async: <none> Unable to load async-profiler. Ensure asyncProfiler library is on LD_LIBRARY_PATH (Linux), DYLD_LIBRARY_PATH (Mac OS), or -Djava.library.path. Alternatively, point to explicit library location with -prof async:libPath=<path>. dtraceasm: <none> [sudo: a password is required ] perf: <none> [Cannot run program "perf": error=2, No such file or directory] perfasm: <none> [Cannot run program "perf": error=2, No such file or directory] perfnorm: <none> [Cannot run program "perf": error=2, No such file or directory] xperfasm: <none> Unable to start the profiler. Try running JMH as Administrator, and ensure that previous profiling session is stopped. Use 'xperf -stop' to stop the active profiling session.: [Cannot run program "xperf": error=2, No such file or directory]
jmhã®æ¨æºã®profiler㧠async-profilerã使ã£ã¦ã¿ã
èªåãæ®æ®µãä¸è©±ã«ãªã£ã¦ããã®ã¯ãasync-profilerãªã®ã§ãasync-profilerã試ãã¦ã¿ãã 以ä¸ã®ã³ãã³ãã§ããã³ããã¼ã¯ãã¨ã«ãflamegraphãåºåãããã
jbang TestBenchmark.java -prof async:libPath=$PWD/lib/libasyncProfiler.dylib\;output=flamegraph\;dir=profile-results
ãªããä¸çªæåã«ç´¹ä»ããã®è¨äºã®ä¸ã§ã¯ãjavaagentã§async-profilerãé©ç¨ãã¦ããããã ããjmhã®å®è¡å ¨ä½ã®profileãåããã¦ããã ã£ãã ãã®ãããjmhã§ãã³ããã¼ã¯ã®profileãåããããªã£ãããjmhæ¨æºã®æ©è½ã使ãã®ãè¯ãã¨æãããã å®éã«è©¦ãããã¹ãã±ã¼ã¹ãæªãå¯è½æ§ã¯ããããå ¨ãã³ããã¼ã¯ã®å®è¡å ¨ä½ã®ãããã¡ã¤ã«ã¯å¥ã«ã»ãããªãã jmhæ¨æºã®æ©è½ã§ã¯ããã³ããã¼ã¯ãã¨ã®profileãåå¾ã§ããããããã»ããã£ãã
jcstress ã¨ã¯
ãã¡ãã¯ãã³ããã¼ã¯ã®ããã®ãã¼ã«ã§ã¯ãªããJVMãã¯ã©ã¹ã©ã¤ãã©ãªåã³ãã¼ãã¦ã§ã¢ã«ãã並è¡æ§ã®åé¡ã調æ»ãããã¨ãç®çã¨ãããã¹ããã¼ãã¹ã¨ãã¹ãã¹ã¤ã¼ãã®ããã ã jcstressã使ãã°ä¸¦è¡å¦çã§race conditionãçºçããªããã©ãããæ¤æ»ãããã¨ãå¯è½ã«ãªããããã£ã½ã©ç¹æ®ãªäºæ ããªãéã使ããªãã¨æãã
ã¢ããªã±ã¼ã·ã§ã³ãæ¸ãããã§ãããã¾ã§é å¥ã«race conditionã®æ¤æ»ãããå¿ è¦æ§ãããã¾ã§çºçããªããã¨ãå¤ãã¨æãã®ã¨ jcstressã使ããªãã¨èª¿æ»åºæ¥ãªãããã§ã¯ãªãããã ã
ã¾ãæ°ãåããã触ã£ã¦ã¿ã¦ã並è¡æ§ã§çãããåç¾ãé£ããåé¡ã«ç´é¢ããã¨ãã«ã·ã¥ãã¨åºãããã¼ã«ã¨ãã¦ä½¿ãããã
jbang㧠jcstressãå®è¡ãã¦ã¿ã
ã¨ããããã§å®è¡ãã¦ã¿ãã
以ä¸ã®ã½ã¼ã¹ã³ã¼ããç¨æããã jcstress-samples ããæã£ã¦ãããã¡ã¤ã«ã« jbangã®ã³ã¡ã³ãããããä»ä¸ãã¦ãä¾å解決ã¨Javaã®ãã¼ã¸ã§ã³ãæå®ãã¦ããã
//JAVA 19 //DEPS org.openjdk.jcstress:jcstress-core:0.16 package com.github.wreulicke.test; // 追è¨ããã®ã¯ããããâ /* * Copyright (c) 2021, Red Hat, Inc. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ import org.openjdk.jcstress.annotations.Actor; import org.openjdk.jcstress.annotations.JCStressTest; import org.openjdk.jcstress.annotations.Outcome; import org.openjdk.jcstress.annotations.State; import org.openjdk.jcstress.infra.results.L_Result; import static org.openjdk.jcstress.annotations.Expect.*; @JCStressTest @Outcome(id = "null", expect = ACCEPTABLE, desc = "Not seeing the object yet") @Outcome(id = "class java.lang.Object", expect = ACCEPTABLE, desc = "Seeing the object, valid class") @Outcome( expect = FORBIDDEN, desc = "Other cases are illegal") @State public class TestJcstress { Object o; @Actor public void writer() { o = new Object(); } @Actor public void reader(L_Result r) { Object lo = o; if (lo != null) { try { r.r1 = lo.getClass(); } catch (NullPointerException npe) { r.r1 = npe; } } else { r.r1 = null; } } public static void main(String[] args) throws Exception { org.openjdk.jcstress.Main.main(args); } }
å®è¡æ¹æ³ã¯ä»¥ä¸ã®éãã ã
jbang TestJcstress.java
ãªããè²ã åºåãåºã¦ããããªhtmlãåºåãããã
以å触ã£ãè¨æ¶ã ã¨ã並è¡æ§ã®åé¡ã§å£ãããããã¨ã表示ãå¤ãã£ãè¨æ¶ãããã jbang ãéããå®è¡æ¹æ³ã®ã¿æ´çãã¦ããããã®ã§ããã®è¨äºã§ã¯åãæ±ããªãã
âã®ç»é¢ããããã¹ãã®ã¯ã©ã¹ãã¯ãªãã¯ããã¨ã以ä¸ã®ãããªè¡¨ç¤ºããããcompilation modeã§ç¶²ç¾ çã«æ¤æ»ãã¦ããã¦ãããã¨ãåããã便å©ã
ã¾ã¨ã
ãã®è¨äºã§ãjbangã使ã£ã¦ jmh/jcstressãå®è¡ããæ¹æ³ãç´¹ä»ãããjmhã¯å¤é¨ã®è¨äºã®ãªã³ã¯ãè²¼ã£ãã ãã ãã ã¾ããjmhæ¨æºã®profileæ©è½ã®ç´¹ä»ã¨ãjcstressã®ç´¹ä»ããã³jbangãéããå®è¡æ¹æ³ãç´¹ä»ããã
jbangã¯ãåå¨ã¯ç¥ã£ã¦ããã®ã ããæ¨æºã§Javaãã¡ã¤ã«ãã¹ã¯ãªããçã«å®è¡åºæ¥ãããã«ãªã£ã¦ãã¾ã£ãã®ã§ ãã¾ãèå³ã沸ãã使ã£ããã¨ããªãã£ãã ããããæåã®ãªã³ã¯ã®è¨äºãè¦ãã¨ãjbangã§ã¯ãä¾åé¢ä¿ããã¡ã¤ã«ã«è¨è¿°ãããã¨ãã§ããgroovyã®Grapeã®ãããªä»çµã¿ãå®è£ ããã¦ãããã¨ã«æ°ä»ããããã¯ä¾¿å©ã ãªãã¨æã£ã¦ããã
好ãããã°ã©ããã§ä½¿ãããããJavaScriptã¨ãGoã§è¯ã説ãããã çµããã