S0:Heap上的 Survivor space 0 区已使用空间的百分比 S1:Heap上的 Survivor space 1 区已使用空间的百分比 E:Heap上的 Eden space 区已使用空间的百分比 O:Heap上的 Old space 区已使用空间的百分比 M:Metaspace 区已使用空间的百分比 YGC:从应用程序启动到采样时发生 Young GC 的次数 YGCT:从应用程序启动到采样时 Young GC 所用的时间(单位秒) FGC:从应用程序启动到采样时发生 Full GC 的次数 FGCT:从应用程序启动到采样时 Full GC 所用的时间(单位秒) GCT:从应用程序启动到采样时用于垃圾回收的总时间(单位秒)
[root@xxxx-nccz8-b57dd64fc-nt9dj startup]# jmap -heap 1 Attaching to process ID 1, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.191-b12
using parallel threads in the new generation. using thread-local object allocation. Concurrent Mark-Sweep GC
(6)、[CMS-concurrent-abortable-preclean-start] CMS: abort preclean due to time [CMS-concurrent-abortable-preclean: 0.558/5.093 secs][Times: user=0.57 sys=0.00, real=5.09 secs]
J2SE 1.5 added a new Java language mechanism “annotations” that allows annotation types to be used to annotate classes, fields, and methods. These annotations are typically processed either by build-time tools or by run-time libraries to achieve new semantic effects. In order to support annotation processing at build-time, this JSR will define APIs to allow annotation processors to be created using a standard pluggable API. This will simplify the task of creating annotation processors and will also allow automation of the discovery of appropriate annotation processors for a given source file. The specification will include at least two sections, a section of API modeling the Java programming language and a distinct section for declaring annotation processors and controlling how they are run. Since annotations are placed on program elements, an annotation processing framework needs to reflect program structure. Annotation processors will be able to specify what annotations they process and multiple processors will be able to run cooperatively. The processors and program structure api can be accessed at build-time; i.e. this functionality supplements core reflection support for reading annotations.
/** * Run all remaining processors on the procStateList that * have not already run this round with an empty set of * annotations. */ publicvoidrunContributingProcs(RoundEnvironment re) { if (!onProcInterator) { // 构造空的注解元素集合 Set<TypeElement> emptyTypeElements = Collections.emptySet(); // 遍历所有注册的注解处理器 while(innerIter.hasNext()) { ProcessorStateps= innerIter.next(); // 判断该注解处理器是否在之前处理过注解,未参与过的不会调用 if (ps.contributed) // 传入空的注解元素集合,重新调用一次注解处理器 callProcessor(ps.processor, emptyTypeElements, re); } } }
/** {@inheritDoc} */ @Overridepublicbooleanprocess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { // 如果禁用,则不处理lombok注解 if (lombokDisabled) returnfalse; // 是否已经处理结束 if (roundEnv.processingOver()) { cleanup.run(); returnfalse; } // We have: A sorted set of all priority levels: 'priorityLevels' // Step 1: Take all CUs which aren't already in the map. Give them the first priority level. StringrandomModuleName=null; // 标记所有编译单元的优先级 // 如果是第二次循环,因为roots已经包含了这个编译单元,所以会忽略 for (Element element : roundEnv.getRootElements()) { if (randomModuleName == null) randomModuleName = getModuleNameFor(element); JCCompilationUnitunit= toUnit(element); if (unit == null) continue; if (roots.containsKey(unit)) continue; roots.put(unit, priorityLevels[0]); } while (true) { // Step 2: For all CUs (in the map, not the roundEnv!), run them across all handlers at their current prio level. // 循环优先级列表 for (long prio : priorityLevels) { List<JCCompilationUnit> cusForThisRound = newArrayList<JCCompilationUnit>(); // 获取在该优先级下的所有编译单元并加入该优先级下需要处理的编译单元列表内 for (Map.Entry<JCCompilationUnit, Long> entry : roots.entrySet()) { LongprioOfCu= entry.getValue(); if (prioOfCu == null || prioOfCu != prio) continue; cusForThisRound.add(entry.getKey()); } // 按照优先级顺序执行编译单元 // 访问AST树并编译目标注解 transformer.transform(prio, javacProcessingEnv.getContext(), cusForThisRound, cleanup); } // Step 3: Push up all CUs to the next level. Set level to null if there is no next level. // 排除掉列表第一个优先级准备执行下一次循环 Set<Long> newLevels = newHashSet<Long>(); for (inti= priorityLevels.length - 1; i >= 0; i--) { LongcurLevel= priorityLevels[i]; LongnextLevel= (i == priorityLevels.length - 1) ? null : priorityLevels[i + 1]; List<JCCompilationUnit> cusToAdvance = newArrayList<JCCompilationUnit>(); for (Map.Entry<JCCompilationUnit, Long> entry : roots.entrySet()) { if (curLevel.equals(entry.getValue())) { cusToAdvance.add(entry.getKey()); newLevels.add(nextLevel); } } for (JCCompilationUnit unit : cusToAdvance) { roots.put(unit, nextLevel); } } newLevels.remove(null); // Step 4: If ALL values are null, quit. Else, either do another loop right now or force a resolution reset by forcing a new round in the annotation processor. // 判断是否将所有优先级排除,优先级列表为空,则结束 if (newLevels.isEmpty()) returnfalse; newLevels.retainAll(priorityLevelsRequiringResolutionReset); if (!newLevels.isEmpty()) { // Force a new round to reset resolution. The next round will cause this method (process) to be called again. forceNewRound(randomModuleName, javacFiler); returnfalse; } // None of the new levels need resolution, so just keep going. } }
➜ ~ gdb --version GNU gdb (GDB) 9.1 Copyright (C) 2020 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
➜ Desktop /Users/chenyuan/Workspaces/Openjdk/openjdk8/build/macosx-x86_64-normal-server-release/jdk/bin/javac Test.java # # A fatal error has been detected by the Java Runtime Environment: # # SIGILL (0x4) at pc=0x000000010267c7eb, pid=89116, tid=0x0000000000004f03 # # JRE version: OpenJDK Runtime Environment (8.0) (build 1.8.0-internal-chenyuan_2020_05_24_03_17-b00) # Java VM: OpenJDK 64-Bit Server VM (25.71-b00 mixed mode bsd-amd64 compressed oops) # Problematic frame: # V [libjvm.dylib+0x47c7eb] PerfDataManager::destroy()+0xab # # Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again # # An error report file with more information is saved as: # /Users/chenyuan/Desktop/hs_err_pid89116.log # # If you would like to submit a bug report, please visit: # http://bugreport.java.com/bugreport/crash.jsp # [error occurred during error reporting , id 0x4]
[1] 89116 abort Test.java ➜ Desktop ll total 112 -rw-r--r-- 1 chenyuan staff 415B May 24 21:33 Test.class -rw-r--r-- 1 chenyuan staff 116B May 24 21:31 Test.java -rw-r--r-- 1 chenyuan staff 46K May 24 21:33 hs_err_pid89116.log ➜ Desktop /Users/chenyuan/Workspaces/Openjdk/openjdk8/build/macosx-x86_64-normal-server-release/jdk/bin/java Test hello world ! ------- 牛逼的打印,无敌的HelloWorkd # # A fatal error has been detected by the Java Runtime Environment: # # SIGILL (0x4) at pc=0x000000010be7c7eb, pid=89512, tid=0x0000000000002403 # # JRE version: OpenJDK Runtime Environment (8.0) (build 1.8.0-internal-chenyuan_2020_05_24_03_17-b00) # Java VM: OpenJDK 64-Bit Server VM (25.71-b00 mixed mode bsd-amd64 compressed oops) # Problematic frame: # V [libjvm.dylib+0x47c7eb] PerfDataManager::destroy()+0xab # # Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again # # An error report file with more information is saved as: # /Users/chenyuan/Desktop/hs_err_pid89512.log # # If you would like to submit a bug report, please visit: # http://bugreport.java.com/bugreport/crash.jsp # [error occurred during error reporting , id 0x4]
➜ Desktop gdb --args /Users/chenyuan/Workspaces/Openjdk/openjdk8/build/macosx-x86_64-normal-server-release/jdk/bin/java Test GNU gdb (GDB) 9.1 Copyright (C) 2020 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-apple-darwin19.3.0". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>.
For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from /Users/chenyuan/Workspaces/Openjdk/openjdk8/build/macosx-x86_64-normal-server-release/jdk/bin/java... (gdb) break init.cpp:95 No source file named init.cpp. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (init.cpp:95) pending. (gdb) run Starting program: /Users/chenyuan/Workspaces/Openjdk/openjdk8/build/macosx-x86_64-normal-server-release/jdk/bin/java Test [New Thread 0x1803 of process 22052] [New Thread 0x2503 of process 22052] [New Thread 0x2403 of process 22052] warning: unhandled dyld version (16) [New Thread 0x180f of process 22052] [New Thread 0x2303 of process 22052]
Thread 4 received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x180f of process 22052] 0x00000001040002b4 in ?? () (gdb) l 111 // add one more to mark the end 112 margv = (char **)JLI_MemAlloc((margc + 1) * (sizeof(char *))); 113 { 114 int i = 0; 115 StdArg *stdargs = JLI_GetStdArgs(); 116 for (i = 0 ; i < margc ; i++) { 117 margv[i] = stdargs[i].arg; 118 } 119 margv[i] = NULL; 120 } (gdb) quit A debugging session is active.
public class XKDaemon { public static void main(String[] args) { Thread thread = new Thread(new DaemonRunner(),"xkDaemonRunner"); thread.setDaemon(true); thread.start();
}
static class DaemonRunner implements Runnable {
@Override public void run() { try { SleepUtils.sleep(10); } finally { System.out.println("Java小咖秀 daemonThread finally run …"); }
Java SE 1.6 中锁有4种状态。级别从低到高依次是:无锁状态、偏向锁状态、轻量级锁状态、重量级锁状态。
锁只能升级不能降级。
37.偏向锁
大多数情况,锁不仅不存在多线程竞争,而且总由同一线程多次获得。当一个线程访问同步块并获取锁时,会在对象头和栈帧中记录存储锁偏向的线程ID,以后该线程在进入和退出同步块时不需要进行 cas操作来加锁和解锁,只需测试一下对象头 Mark Word里是否存储着指向当前线程的偏向锁。如果测试成功,表示线程已经获得了锁,如果失败,则需要测试下Mark Word中偏向锁的标示是否已经设置成1(表示当前时偏向锁),如果没有设置,则使用cas竞争锁,如果设置了,则尝试使用cas将对象头的偏向锁只想当前线程。
publicThreadPoolExecutor( int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, RejectedExecutionHandler handler)
----- Build times ------- Start 2020-05-24 03:18:37 End 2020-05-24 03:30:07 00:00:19 corba 00:00:46 demos 00:01:52 docs 00:02:53 hotspot 00:01:28 images 00:00:12 jaxp 00:00:18 jaxws 00:03:07 jdk 00:00:26 langtools 00:00:09 nashorn 00:11:30 TOTAL ------------------------- Finished building OpenJDK for target 'all'
如何在CLion里面做调试,后面我再详细的写一篇。敬请期待~
遇到的坑
问题一:Xcode 4 is required to build JDK 8
1 2
configure: error: Xcode 4 is required to build JDK 8, the version found was 11.4.1. Use --with-xcode-path to specify the location of Xcode 4 or make Xcode 4 active by using xcode-select. configure exiting with result code 1
解决方案:
1 2 3 4 5 6 7
➜ openjdk8 vim common/autoconf/generated-configure.sh # Fail-fast: verify we're building on Xcode 4, we cannot build with Xcode 5 or later #XCODE_VERSION=`$XCODEBUILD -version | grep '^Xcode ' | sed 's/Xcode //'` #XC_VERSION_PARTS=( ${XCODE_VERSION//./ } ) #if test ! "${XC_VERSION_PARTS[0]}" = "4"; then # as_fn_error $? "Xcode 4 is required to build JDK 8, the version found was $XCODE_VERSION. Use --with-xcode-path to specify the l ocation of Xcode 4 or make Xcode 4 active by using xcode-select." "$LINENO" 5 #fi
configure: error: A gcc compiler is required. Try setting --with-tools-dir. configure exiting with result code # 第一处代码 eliftest"x$TOOLCHAIN_TYPE" = xgcc; then # gcc --version output typically looks like # gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 # Copyright (C) 2013 Free Software Foundation, Inc. # This is free software; see the source for copying conditions. There is NO # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. COMPILER_VERSION_OUTPUT=`$COMPILER --version 2>&1` # Check that this is likely to be GCC. $ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "Free Software Foundation" > /dev/null # 条件语句注释掉 # iftest $? -ne 0; then # { $as_echo"$as_me:${as_lineno-$LINENO}: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&5 # $as_echo"$as_me: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&6;} # { $as_echo"$as_me:${as_lineno-$LINENO}: The result from running with --version was: \"$COMPILER_VERSION\"" >&5 # $as_echo"$as_me: The result from running with --version was: \"$COMPILER_VERSION\"" >&6;} # as_fn_error $? "A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.""$LINENO" 5 # fi # 第二处代码, elif test "x$TOOLCHAIN_TYPE" = xgcc; then # gcc --version output typically looks like # gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 # Copyright (C) 2013 Free Software Foundation, Inc. # This is free software; see the source for copying conditions. There is NO # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. COMPILER_VERSION_OUTPUT=`$COMPILER --version 2>&1` # Check that this is likely to be GCC. $ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "Free Software Foundation" > /dev/null # 条件语句注释掉 # iftest $? -ne 0; then # { $as_echo"$as_me:${as_lineno-$LINENO}: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&5 # $as_echo"$as_me: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&6;} # { $as_echo"$as_me:${as_lineno-$LINENO}: The result from running with --version was: \"$COMPILER_VERSION\"" >&5 # $as_echo"$as_me: The result from running with --version was: \"$COMPILER_VERSION\"" >&6;} # as_fn_error $? "A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.""$LINENO" 5
==================================================== A new configuration has been successfully created in /Users/chenyuan/Workspaces/Openjdk/openjdk8/build/macosx-x86_64-normal-server-release using default settings.
Configuration summary: * Debug level: release * JDK variant: normal * JVM variants: server * OpenJDK target: OS: macosx, CPU architecture: x86, address length: 64
Tools summary: * Boot JDK: java version "1.8.0_162" Java(TM) SE Runtime Environment (build 1.8.0_162-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode) (at /Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home) * Toolchain: gcc (GNU Compiler Collection) * C Compiler: Version 11.0.3 (at /usr/bin/gcc) * C++ Compiler: Version 11.0.3 (at /usr/bin/g++)
clang: clangerror: include path for libstdc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Werror,-Wstdlibcxx-not-found] : error: include path for libstdc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Werror,-Wstdlibcxx-not-found] make[6]: *** [../generated/adfiles/archDesc.o] Error 1 make[6]: *** Waiting for unfinished jobs.... make[6]: *** [../generated/adfiles/adlparse.o] Error 1 clang: error: include path for libstdc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Werror,-Wstdlibcxx-not-found] make[6]: *** [../generated/adfiles/arena.o] Error 1 make[5]: *** [ad_stuff] Error 2 make[4]: *** [product] Error 2 make[3]: *** [generic_build2] Error 2 make[2]: *** [product] Error 2 make[1]: *** [/Users/chenyuan/Workspaces/Openjdk/openjdk8/build/macosx-x86_64-normal-server-release/hotspot/_hotspot.timestamp] Error 2 make: *** [hotspot-only] Error 2
问题六:invalid argument ‘-std=gnu++98’ not allowed with ‘C’
1 2 3
Making signal interposition lib... error: invalid argument '-std=gnu++98' not allowed with 'C' make[6]: *** [libjsig.dylib] Error 1
解决方案
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
if test "x$TOOLCHAIN_TYPE" = xsolstudio; then if test "x$OPENJDK_TARGET_CPU_ARCH" = "xsparc"; then CFLAGS_JDKLIB_EXTRA="${CFLAGS_JDKLIB_EXTRA} -xregs=no%appl" CXXFLAGS_JDKLIB_EXTRA="${CXXFLAGS_JDKLIB_EXTRA} -xregs=no%appl" fi elif test "x$TOOLCHAIN_TYPE" = xxlc; then LDFLAGS_JDK="${LDFLAGS_JDK} -q64 -brtl -bnolibpath -liconv -bexpall" CFLAGS_JDK="${CFLAGS_JDK} -qchars=signed -q64 -qfullpath -qsaveopt" CXXFLAGS_JDK="${CXXFLAGS_JDK} -qchars=signed -q64 -qfullpath -qsaveopt" elif test "x$TOOLCHAIN_TYPE" = xgcc; then LEGACY_EXTRA_CFLAGS="$LEGACY_EXTRA_CFLAGS -fstack-protector" LEGACY_EXTRA_CXXFLAGS="$LEGACY_EXTRA_CXXFLAGS -fstack-protector" if test "x$OPENJDK_TARGET_OS" != xmacosx; then LDFLAGS_JDK="$LDFLAGS_JDK -Wl,-z,relro" LEGACY_EXTRA_LDFLAGS="$LEGACY_EXTRA_LDFLAGS -Wl,-z,relro" fi # CXXSTD_CXXFLAG="-std=gnu++98" # 注释掉这行