源码位置https://github.com/openjdk/jdk
核心实现源码[部分截图]

/** Copyright (c) 1995, 2024, Oracle and/or its affiliates. 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.*//** This file contains the main entry point into the launcher code* this is the only file which will be repeatedly compiled by other* tools. The rest of the files will be linked in.*/#include "defines.h"#include "jli_util.h"#include "jni.h"/** Entry point.*/#ifdef JAVAWchar **__initenv;int WINAPIWinMain(HINSTANCE inst, HINSTANCE previnst, LPSTR cmdline, int cmdshow){int margc;char** margv;int jargc;char** jargv;const jboolean const_javaw = JNI_TRUE;__initenv = _environ;#else /* JAVAW */JNIEXPORT intmain(int argc, char **argv){int margc;char** margv;int jargc;char** jargv;const jboolean const_javaw = JNI_FALSE;#endif /* JAVAW */{int i, main_jargc, extra_jargc;JLI_List list;main_jargc = (sizeof(const_jargs) / sizeof(char *)) > 1? sizeof(const_jargs) / sizeof(char *): 0; // ignore the null terminator indexextra_jargc = (sizeof(const_extra_jargs) / sizeof(char *)) > 1? sizeof(const_extra_jargs) / sizeof(char *): 0; // ignore the null terminator indexif (main_jargc > 0 && extra_jargc > 0) { // combine extra java argsjargc = main_jargc + extra_jargc;list = JLI_List_new(jargc + 1);for (i = 0 ; i < extra_jargc; i++) {JLI_List_add(list, JLI_StringDup(const_extra_jargs[i]));}for (i = 0 ; i < main_jargc ; i++) {JLI_List_add(list, JLI_StringDup(const_jargs[i]));}// terminate the listJLI_List_add(list, NULL);jargv = list->elements;} else if (extra_jargc > 0) { // should never happenfprintf(stderr, "EXTRA_JAVA_ARGS defined without JAVA_ARGS");abort();} else { // no extra args, business as usualjargc = main_jargc;jargv = (char **) const_jargs;}}JLI_InitArgProcessing(jargc > 0, const_disable_argfile);#ifdef _WIN32{int i = 0;if (getenv(JLDEBUG_ENV_ENTRY) != NULL) {printf("Windows original main args:\n");for (i = 0 ; i < __argc ; i++) {printf("wwwd_args[%d] = %s\n", i, __argv[i]);}}}// Obtain the command line in UTF-16, then convert it to ANSI code page// without the "best-fit" optionLPWSTR wcCmdline = GetCommandLineW();int mbSize = WideCharToMultiByte(CP_ACP,WC_NO_BEST_FIT_CHARS | WC_COMPOSITECHECK | WC_DEFAULTCHAR,wcCmdline, -1, NULL, 0, NULL, NULL);// If the call to WideCharToMultiByte() fails, it returns 0, which// will then make the following JLI_MemAlloc() to issue exit(1)LPSTR mbCmdline = JLI_MemAlloc(mbSize);if (WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS | WC_COMPOSITECHECK | WC_DEFAULTCHAR,wcCmdline, -1, mbCmdline, mbSize, NULL, NULL) == 0) {perror("command line encoding conversion failure");exit(1);}JLI_CmdToArgs(mbCmdline);JLI_MemFree(mbCmdline);margc = JLI_GetStdArgc();// add one more to mark the endmargv = (char **)JLI_MemAlloc((margc + 1) * (sizeof(char *)));{int i = 0;StdArg *stdargs = JLI_GetStdArgs();for (i = 0 ; i < margc ; i++) {margv[i] = stdargs[i].arg;}margv[i] = NULL;}#else /* *NIXES */{// accommodate the NULL at the endJLI_List args = JLI_List_new(argc + 1);int i = 0;// Add first arg, which is the app nameJLI_List_add(args, JLI_StringDup(argv[0]));// Append JDK_JAVA_OPTIONSif (JLI_AddArgsFromEnvVar(args, JDK_JAVA_OPTIONS)) {// JLI_SetTraceLauncher is not called yet// Show _JAVA_OPTIONS content along with JDK_JAVA_OPTIONS to aid diagnosisif (getenv(JLDEBUG_ENV_ENTRY)) {char *tmp = getenv("_JAVA_OPTIONS");if (NULL != tmp) {JLI_ReportMessage(ARG_INFO_ENVVAR, "_JAVA_OPTIONS", tmp);}}}// Iterate the rest of command linefor (i = 1; i < argc; i++) {JLI_List argsInFile = JLI_PreprocessArg(argv[i], JNI_TRUE);if (NULL == argsInFile) {JLI_List_add(args, JLI_StringDup(argv[i]));} else {int cnt, idx;cnt = argsInFile->size;for (idx = 0; idx < cnt; idx++) {JLI_List_add(args, argsInFile->elements[idx]);}// Shallow free, we reuse the string to avoid copyJLI_MemFree(argsInFile->elements);JLI_MemFree(argsInFile);}}margc = args->size;// add the NULL pointer at argv[argc]JLI_List_add(args, NULL);margv = args->elements;}#endif /* WIN32 */return JLI_Launch(margc, margv,jargc, (const char**) jargv,0, NULL,VERSION_STRING,DOT_VERSION,(const_progname != NULL) ? const_progname : *margv,(const_launcher != NULL) ? const_launcher : *margv,jargc > 0,const_cpwildcard, const_javaw, 0);}

intCallJavaMainInNewThread(jlong stack_size, void* args) {int rslt;pthread_t tid;pthread_attr_t attr;pthread_attr_init(&attr);pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);size_t adjusted_stack_size;if (stack_size > 0) {if (pthread_attr_setstacksize(&attr, stack_size) == EINVAL) {// System may require stack size to be multiple of page size// Retry with adjusted valueadjusted_stack_size = adjustStackSize(stack_size);if (adjusted_stack_size != (size_t) stack_size) {pthread_attr_setstacksize(&attr, adjusted_stack_size);}}}pthread_attr_setguardsize(&attr, 0); // no pthread guard page on java threadsif (pthread_create(&tid, &attr, ThreadJavaMain, args) == 0) {void* tmp;pthread_join(tid, &tmp);rslt = (int)(intptr_t)tmp;} else {/** Continue execution in current thread if for some reason (e.g. out of* memory/LWP) a new thread can't be created. This will likely fail* later in JavaMain as JNI_CreateJavaVM needs to create quite a* few new threads, anyway, just give it a try..*/rslt = JavaMain(args);}pthread_attr_destroy(&attr);return rslt;}
## Copyright (c) 2004, 2024, Oracle and/or its affiliates. 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.## 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.##include "defs.S.inc"# NOTE WELL! The _Copy functions are called directly# from server-compiler-generated code via CallLeafNoFP,# which means that they *must* either not use floating# point or use it in the same manner as does the server# compiler..text.align 16DECLARE_FUNC(SpinPause):repnopmovq $1, %raxret# Support for void Copy::arrayof_conjoint_bytes(void* from,# void* to,# size_t count)# rdi - from# rsi - to# rdx - count, treated as ssize_t#.p2align 4,,15DECLARE_FUNC(_Copy_arrayof_conjoint_bytes):movq %rdx,%r8 # byte countshrq $3,%rdx # qword countcmpq %rdi,%rsileaq -1(%rdi,%r8,1),%rax # from + bcount*1 - 1jbe acb_CopyRightcmpq %rax,%rsijbe acb_CopyLeftacb_CopyRight:leaq -8(%rdi,%rdx,8),%rax # from + qcount*8 - 8leaq -8(%rsi,%rdx,8),%rcx # to + qcount*8 - 8negq %rdxjmp 7f.p2align 4,,151: movq 8(%rax,%rdx,8),%rsimovq %rsi,8(%rcx,%rdx,8)addq $1,%rdxjnz 1b2: testq $4,%r8 # check for trailing dwordjz 3fmovl 8(%rax),%esi # copy trailing dwordmovl %esi,8(%rcx)addq $4,%raxaddq $4,%rcx # original %rsi is trashed, so we# can't use it as a base register3: testq $2,%r8 # check for trailing wordjz 4fmovw 8(%rax),%si # copy trailing wordmovw %si,8(%rcx)addq $2,%rcx4: testq $1,%r8 # check for trailing bytejz 5fmovb -1(%rdi,%r8,1),%al # copy trailing bytemovb %al,8(%rcx)5: ret.p2align 4,,156: movq -24(%rax,%rdx,8),%rsimovq %rsi,-24(%rcx,%rdx,8)movq -16(%rax,%rdx,8),%rsimovq %rsi,-16(%rcx,%rdx,8)movq -8(%rax,%rdx,8),%rsimovq %rsi,-8(%rcx,%rdx,8)movq (%rax,%rdx,8),%rsimovq %rsi,(%rcx,%rdx,8)7: addq $4,%rdxjle 6bsubq $4,%rdxjl 1bjmp 2bacb_CopyLeft:testq $1,%r8 # check for trailing bytejz 1fmovb -1(%rdi,%r8,1),%cl # copy trailing bytemovb %cl,-1(%rsi,%r8,1)subq $1,%r8 # adjust for possible trailing word1: testq $2,%r8 # check for trailing wordjz 2fmovw -2(%rdi,%r8,1),%cx # copy trailing wordmovw %cx,-2(%rsi,%r8,1)2: testq $4,%r8 # check for trailing dwordjz 5fmovl (%rdi,%rdx,8),%ecx # copy trailing dwordmovl %ecx,(%rsi,%rdx,8)jmp 5f.p2align 4,,153: movq -8(%rdi,%rdx,8),%rcxmovq %rcx,-8(%rsi,%rdx,8)subq $1,%rdxjnz 3bret.p2align 4,,154: movq 24(%rdi,%rdx,8),%rcxmovq %rcx,24(%rsi,%rdx,8)movq 16(%rdi,%rdx,8),%rcxmovq %rcx,16(%rsi,%rdx,8)movq 8(%rdi,%rdx,8),%rcxmovq %rcx,8(%rsi,%rdx,8)movq (%rdi,%rdx,8),%rcxmovq %rcx,(%rsi,%rdx,8)5: subq $4,%rdxjge 4baddq $4,%rdxjg 3bret# Support for void Copy::arrayof_conjoint_jshorts(void* from,# void* to,# size_t count)# Equivalent to# conjoint_jshorts_atomic## If 'from' and/or 'to' are aligned on 4- or 2-byte boundaries, we# let the hardware handle it. The tow or four words within dwords# or qwords that span cache line boundaries will still be loaded# and stored atomically.## rdi - from# rsi - to# rdx - count, treated as ssize_t#.p2align 4,,15DECLARE_FUNC(_Copy_arrayof_conjoint_jshorts):DECLARE_FUNC(_Copy_conjoint_jshorts_atomic):movq %rdx,%r8 # word countshrq $2,%rdx # qword countcmpq %rdi,%rsileaq -2(%rdi,%r8,2),%rax # from + wcount*2 - 2jbe acs_CopyRightcmpq %rax,%rsijbe acs_CopyLeftacs_CopyRight:leaq -8(%rdi,%rdx,8),%rax # from + qcount*8 - 8leaq -8(%rsi,%rdx,8),%rcx # to + qcount*8 - 8negq %rdxjmp 6f1: movq 8(%rax,%rdx,8),%rsimovq %rsi,8(%rcx,%rdx,8)addq $1,%rdxjnz 1b2: testq $2,%r8 # check for trailing dwordjz 3fmovl 8(%rax),%esi # copy trailing dwordmovl %esi,8(%rcx)addq $4,%rcx # original %rsi is trashed, so we# can't use it as a base register3: testq $1,%r8 # check for trailing wordjz 4fmovw -2(%rdi,%r8,2),%si # copy trailing wordmovw %si,8(%rcx)4: ret.p2align 4,,155: movq -24(%rax,%rdx,8),%rsimovq %rsi,-24(%rcx,%rdx,8)movq -16(%rax,%rdx,8),%rsimovq %rsi,-16(%rcx,%rdx,8)movq -8(%rax,%rdx,8),%rsimovq %rsi,-8(%rcx,%rdx,8)movq (%rax,%rdx,8),%rsimovq %rsi,(%rcx,%rdx,8)6: addq $4,%rdxjle 5bsubq $4,%rdxjl 1bjmp 2bacs_CopyLeft:testq $1,%r8 # check for trailing wordjz 1fmovw -2(%rdi,%r8,2),%cx # copy trailing wordmovw %cx,-2(%rsi,%r8,2)1: testq $2,%r8 # check for trailing dwordjz 4fmovl (%rdi,%rdx,8),%ecx # copy trailing dwordmovl %ecx,(%rsi,%rdx,8)jmp 4f2: movq -8(%rdi,%rdx,8),%rcxmovq %rcx,-8(%rsi,%rdx,8)subq $1,%rdxjnz 2bret.p2align 4,,153: movq 24(%rdi,%rdx,8),%rcxmovq %rcx,24(%rsi,%rdx,8)movq 16(%rdi,%rdx,8),%rcxmovq %rcx,16(%rsi,%rdx,8)movq 8(%rdi,%rdx,8),%rcxmovq %rcx,8(%rsi,%rdx,8)movq (%rdi,%rdx,8),%rcxmovq %rcx,(%rsi,%rdx,8)4: subq $4,%rdxjge 3baddq $4,%rdxjg 2bret# Support for void Copy::arrayof_conjoint_jints(jint* from,# jint* to,# size_t count)# Equivalent to# conjoint_jints_atomic## If 'from' and/or 'to' are aligned on 4-byte boundaries, we let# the hardware handle it. The two dwords within qwords that span# cache line boundaries will still be loaded and stored atomically.## rdi - from# rsi - to# rdx - count, treated as ssize_t#.p2align 4,,15DECLARE_FUNC(_Copy_arrayof_conjoint_jints):DECLARE_FUNC(_Copy_conjoint_jints_atomic):movq %rdx,%r8 # dword countshrq %rdx # qword countcmpq %rdi,%rsileaq -4(%rdi,%r8,4),%rax # from + dcount*4 - 4jbe aci_CopyRightcmpq %rax,%rsijbe aci_CopyLeftaci_CopyRight:leaq -8(%rdi,%rdx,8),%rax # from + qcount*8 - 8leaq -8(%rsi,%rdx,8),%rcx # to + qcount*8 - 8negq %rdxjmp 5f.p2align 4,,151: movq 8(%rax,%rdx,8),%rsimovq %rsi,8(%rcx,%rdx,8)addq $1,%rdxjnz 1b2: testq $1,%r8 # check for trailing dwordjz 3fmovl 8(%rax),%esi # copy trailing dwordmovl %esi,8(%rcx)3: ret.p2align 4,,154: movq -24(%rax,%rdx,8),%rsimovq %rsi,-24(%rcx,%rdx,8)movq -16(%rax,%rdx,8),%rsimovq %rsi,-16(%rcx,%rdx,8)movq -8(%rax,%rdx,8),%rsimovq %rsi,-8(%rcx,%rdx,8)movq (%rax,%rdx,8),%rsimovq %rsi,(%rcx,%rdx,8)5: addq $4,%rdxjle 4bsubq $4,%rdxjl 1bjmp 2baci_CopyLeft:testq $1,%r8 # check for trailing dwordjz 3fmovl -4(%rdi,%r8,4),%ecx # copy trailing dwordmovl %ecx,-4(%rsi,%r8,4)jmp 3f1: movq -8(%rdi,%rdx,8),%rcxmovq %rcx,-8(%rsi,%rdx,8)subq $1,%rdxjnz 1bret.p2align 4,,152: movq 24(%rdi,%rdx,8),%rcxmovq %rcx,24(%rsi,%rdx,8)movq 16(%rdi,%rdx,8),%rcxmovq %rcx,16(%rsi,%rdx,8)movq 8(%rdi,%rdx,8),%rcxmovq %rcx,8(%rsi,%rdx,8)movq (%rdi,%rdx,8),%rcxmovq %rcx,(%rsi,%rdx,8)3: subq $4,%rdxjge 2baddq $4,%rdxjg 1bret# Support for void Copy::arrayof_conjoint_jlongs(jlong* from,# jlong* to,# size_t count)# Equivalent to# conjoint_jlongs_atomic# arrayof_conjoint_oops# conjoint_oops_atomic## rdi - from# rsi - to# rdx - count, treated as ssize_t#.p2align 4,,15DECLARE_FUNC(_Copy_arrayof_conjoint_jlongs):DECLARE_FUNC(_Copy_conjoint_jlongs_atomic):cmpq %rdi,%rsileaq -8(%rdi,%rdx,8),%rax # from + count*8 - 8jbe acl_CopyRightcmpq %rax,%rsijbe acl_CopyLeftacl_CopyRight:leaq -8(%rsi,%rdx,8),%rcx # to + count*8 - 8negq %rdxjmp 3f1: movq 8(%rax,%rdx,8),%rsimovq %rsi,8(%rcx,%rdx,8)addq $1,%rdxjnz 1bret.p2align 4,,152: movq -24(%rax,%rdx,8),%rsimovq %rsi,-24(%rcx,%rdx,8)movq -16(%rax,%rdx,8),%rsimovq %rsi,-16(%rcx,%rdx,8)movq -8(%rax,%rdx,8),%rsimovq %rsi,-8(%rcx,%rdx,8)movq (%rax,%rdx,8),%rsimovq %rsi,(%rcx,%rdx,8)3: addq $4,%rdxjle 2bsubq $4,%rdxjl 1bret4: movq -8(%rdi,%rdx,8),%rcxmovq %rcx,-8(%rsi,%rdx,8)subq $1,%rdxjnz 4bret.p2align 4,,155: movq 24(%rdi,%rdx,8),%rcxmovq %rcx,24(%rsi,%rdx,8)movq 16(%rdi,%rdx,8),%rcxmovq %rcx,16(%rsi,%rdx,8)movq 8(%rdi,%rdx,8),%rcxmovq %rcx,8(%rsi,%rdx,8)movq (%rdi,%rdx,8),%rcxmovq %rcx,(%rsi,%rdx,8)acl_CopyLeft:subq $4,%rdxjge 5baddq $4,%rdxjg 4bret


JAVA JDK的源码是C,C++,ASM实现,其中编译原理,算法,数据结构,JIT等技术点知识已经融入到代码里。




通过学习《程序员内功修炼》《编译器实现》《github c语言大型开源项目源码吸收转化实践》这3门课程足以。


https://beifengisnil.github.io/
talk is cheap, show me the code
这个code里面欧美程序员已经将编译原理,算法,数据结构,操作系统,数学,工程,AI等不计其数的知识体系已经融入实现到代码里,并且持续用了几十年,这些code是面向全球用户市场的,且具有强大的技术经济价值,创新能力,市场开发能力,这几十年的编译原理,算法,数学,工程,AI等知识早就code等着你去吸收转化。
code已经给你show了,就看你有没有一套系统的方法去吸收,这3门课程主要传授的是一套系统的方法去获取和运用各种技术知识,而不是教你一门技术,技术是会过时的。




![[Ansible实践笔记]自动化运维工具Ansible(一):初探ansibleansible的点对点模式](https://i-blog.csdnimg.cn/direct/83609d2a393f4282992311235450014f.png)














