Focus On Oracle

Installing, Backup & Recovery, Performance Tuning,
Troubleshooting, Upgrading, Patching

Oracle Engineered System


当前位置: 首页 » 技术文章 » 开源之美

Oracle JVM HotSpot

Oracle的JVM称为HotSpot。到目前为止,在10多年中,已有数十个发参与HotSpot的开发。有近1500个c/c++头文件和源文件,包含近250,000行代码。Java HotSpot JVM的源代码,可以说是这世界上最好的。可通过链接http://openjdk.java.net/groups/hotspot/查看。学习JVM能深入地理解Java语言,JDK6是首个开源的JVM版本。

JVM架构图

更多关于JVM的架构,请参考官方文档

https://docs.oracle.com/javase/specs/jvms/se13/html/jvms-2.html

Java SE HotSpot一瞥,里面有很多官方关于JVM的文档
https://www.oracle.com/technetwork/java/javase/tech/index-jsp-136373.html


https://dzone.com/articles/jvm-architecture-explained


OpenJDK JVM源码

下面是openJDK源码的下载地址

OpenJDK&trade 6 Source Release
October 26, 2012(Build b27)
http://openjdk.java.net/projects/jdk6/
https://download.java.net/openjdk/jdk6/
https://download.java.net/openjdk/jdk6/promoted/b27/openjdk-6-src-b27-26_oct_2012.tar.gz
OpenJDK7
June 27, 2011(Build b147)
https://download.java.net/openjdk/jdk7/
https://download.java.net/openjdk/jdk7/promoted/b147/openjdk-7-fcs-src-b147-27_jun_2011.zip
OpenJDK8
March 10, 2014*(Build b132)
http://hg.openjdk.java.net/jdk8/jdk8
https://download.java.net/openjdk/jdk8/promoted/b132/openjdk-8-src-b132-03_mar_2014.zip
Kaffe JVM
http://www.kaffe.org/
https://github.com/kaffe/kaffe
编译模式

https://openjdk.java.net/groups/hotspot/docs/HotSpotGlossary.html

https://www.oracle.com/technical-resources/articles/java/architect-evans-pt1.html

Inside Java HotSpot VM, there are actually two separate JIT compiler modes, which are known as C1 and C2. C1 is used for applications where quick startup and rock-solid optimization are required; GUI applications are often good candidates for this compiler. C2, on the other hand, was originally intended for long-running, predominantly server-side applications. Prior to some of the later Java SE 7 releases, these two modes were available using the -client and -server switches, respectively.
java -version
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)

Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)

java、javac等源码的位置

平常我们编译java代码的命令javac,运行java应用的java命令就在下面的路径下

src\share\classes\sun\tools\javac\

src\share\classes\sun\tools\java\

JDK main函数入口

\src\share\bin\main.c

int
main(int argc, char ** argv)
{
    int margc;
    char** margv;
    const jboolean const_javaw = JNI_FALSE;

    margc = argc;
    margv = argv;
#endif /* JAVAW */

    return JLI_Launch(margc, margv,
                   sizeof(const_jargs) / sizeof(char *), const_jargs,
                   sizeof(const_appclasspath) / sizeof(char *), const_appclasspath,
                   FULL_VERSION,
                   DOT_VERSION,
                   (const_progname != NULL) ? const_progname : *margv,
                   (const_launcher != NULL) ? const_launcher : *margv,
                   (const_jargs != NULL) ? JNI_TRUE : JNI_FALSE,
                   const_cpwildcard, const_javaw, const_ergo_class);
}
\jdk\src\share\bin\java.c
/*
 * Entry point.
 */
int
JLI_Launch(int argc, char ** argv,              /* main argc, argc */
        int jargc, const char** jargv,          /* java args */
        int appclassc, const char** appclassv,  /* app classpath */
        const char* fullversion,                /* full version defined */
        const char* dotversion,                 /* dot version defined */
        const char* pname,                      /* program name */
        const char* lname,                      /* launcher name */
        jboolean javaargs,                      /* JAVA_ARGS */
        jboolean cpwildcard,                    /* classpath wildcard*/
        jboolean javaw,                         /* windows-only javaw */
        jint ergo                               /* ergonomics class policy */
)
{
    int mode = LM_UNKNOWN;
    char *what = NULL;
    char *cpath = 0;
    char *main_class = NULL;
    int ret;
    InvocationFunctions ifn;
    jlong start, end;
    char jvmpath[MAXPATHLEN];
    char jrepath[MAXPATHLEN];

    _fVersion = fullversion;
    _dVersion = dotversion;
    _launcher_name = lname;
    _program_name = pname;
    _is_java_args = javaargs;
    _wc_enabled = cpwildcard;
    _ergo_policy = ergo;

    InitLauncher(javaw);
    DumpState();

    /*
     * Make sure the specified version of the JRE is running.
     *
     * There are three things to note about the SelectVersion() routine:
     *  1) If the version running isn't correct, this routine doesn't
     *     return (either the correct version has been exec'd or an error
     *     was issued).
     *  2) Argc and Argv in this scope are *not* altered by this routine.
     *     It is the responsibility of subsequent code to ignore the
     *     arguments handled by this routine.
     *  3) As a side-effect, the variable "main_class" is guaranteed to
     *     be set (if it should ever be set).  This isn't exactly the
     *     poster child for structured programming, but it is a small
     *     price to pay for not processing a jar file operand twice.
     *     (Note: This side effect has been disabled.  See comment on
     *     bugid 5030265 below.)
     */
    SelectVersion(argc, argv, &main_class);

    if (JLI_IsTraceLauncher()) {
        int i;
        printf("Command line args:\n");
        for (i = 0; i < argc ; i++) {
            printf("argv[%d] = %s\n", i, argv[i]);
        }
        AddOption("-Dsun.java.launcher.diag=true", NULL);
    }

    CreateExecutionEnvironment(&argc, &argv,
                               jrepath, sizeof(jrepath),
                               jvmpath, sizeof(jvmpath));

    ifn.CreateJavaVM = 0;
    ifn.GetDefaultJavaVMInitArgs = 0;

    if (JLI_IsTraceLauncher()) {
        start = CounterGet();
    }

    if (!LoadJavaVM(jvmpath, &ifn)) {
        return(6);
    }

    if (JLI_IsTraceLauncher()) {
        end   = CounterGet();
    }

    JLI_TraceLauncher("%ld micro seconds to LoadJavaVM\n",
             (long)(jint)Counter2Micros(end-start));

    ++argv;
    --argc;

    if (IsJavaArgs()) {
        /* Preprocess wrapper arguments */
        TranslateApplicationArgs(jargc, jargv, &argc, &argv);
        if (!AddApplicationOptions(appclassc, appclassv)) {
            return(1);
        }
    } else {
        /* Set default CLASSPATH */
        cpath = getenv("CLASSPATH");
        if (cpath == NULL) {
            cpath = ".";
        }
        SetClassPath(cpath);
    }

    /* Parse command line options; if the return value of
     * ParseArguments is false, the program should exit.
     */
    if (!ParseArguments(&argc, &argv, &mode, &what, &ret, jrepath))
    {
        return(ret);
    }

    /* Override class path if -jar flag was specified */
    if (mode == LM_JAR) {
        SetClassPath(what);     /* Override class path */
    }

    /* set the -Dsun.java.command pseudo property */
    SetJavaCommandLineProp(what, argc, argv);

    /* Set the -Dsun.java.launcher pseudo property */
    SetJavaLauncherProp();

    /* set the -Dsun.java.launcher.* platform properties */
    SetJavaLauncherPlatformProps();

    /* Show the splash screen if needed */
    ShowSplashScreen();

    return ContinueInNewThread(&ifn, argc, argv, mode, what, ret);

}

下面几篇是关于JVM的文章,感觉还不错

https://www.cnblogs.com/jmcui/p/11796303.html

https://www.cnblogs.com/chanshuyi/p/jvm_serial_02_the_history_of_jvm.html

https://www.waytoeasylearn.com/learn/what-is-jvm/

https://www.cubrid.org/blog/understanding-jvm-internals/

https://metebalci.com/blog/demystifying-the-jvm-interpretation-jit-and-aot-compilation/

https://www.beyondjava.net/java-programmers-guide-java-byte-code


Reference

https://www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html

https://en.wikipedia.org/wiki/Java_virtual_machine

https://jdk.java.net/
https://openjdk.java.net/
https://openjdk.java.net/projects/code-tools/
https://openjdk.java.net/faq/
https://github.com/openjdk/jdk
https://github.com/javaee/javaee.github.io
https://javaee.github.io/javamail/#Samples
https://blogs.oracle.com/sundararajan/so-you-want-to-read-hotspot-source
https://blogs.oracle.com/sundararajan/helloworld-with-maxine-jvm-on-mac
https://www.artima.com/insidejvm/ed2/introarch.html
https://www.engr.colostate.edu/~sudeep/wp-content/uploads/CD2.15-P374493.pdf
https://stackoverflow.com/questions/421951/running-interpreting-c-on-top-of-the-jvm

https://stackoverflow.com/questions/2026093/is-jvm-open-source-code

https://stackoverflow.com/questions/16568253/difference-between-jvm-and-hotspot

https://www.cnblogs.com/jmcui/p/11796303.html

https://www.cnblogs.com/chanshuyi/p/jvm_serial_02_the_history_of_jvm.html



关键词:hotspot jvm 

相关文章

Java beginner for Oracle DBA
Oracle JVM HotSpot
Top