diff --git a/make/CreateJars.gmk b/make/CreateJars.gmk index 7f7179296696f7d75020a7a9ec7fe982df2547fc..f949dfad07de0b204b984ad8e8a7acbde19a32d0 100644 --- a/make/CreateJars.gmk +++ b/make/CreateJars.gmk @@ -554,7 +554,8 @@ EXCLUDE_PROPWARN_PKGS = com.sun.java.swing.plaf.windows \ # with a new module system (being discussed for JDK 8). # EXPORTED_PRIVATE_PKGS = com.oracle.net \ - com.oracle.nio + com.oracle.nio \ + com.alibaba.jwarmup $(IMAGES_OUTPUTDIR)/symbols/_the.symbols: $(IMAGES_OUTPUTDIR)/lib/rt.jar $(RM) -r $(IMAGES_OUTPUTDIR)/symbols/META-INF/sym diff --git a/make/data/classlist/classlist.linux b/make/data/classlist/classlist.linux index 2a3915c0c8d82ef55fc4defce6d9a3bf20a1ace0..5ff06e7690d0d75a674c6857554dd78ef22ca0ba 100644 --- a/make/data/classlist/classlist.linux +++ b/make/data/classlist/classlist.linux @@ -2556,4 +2556,5 @@ javax/swing/plaf/basic/BasicToolBarSeparatorUI java/awt/event/AdjustmentEvent java/awt/MenuBar sun/awt/X11/XErrorEvent +com/alibaba/jwarmup/JWarmUp # eea35d9d56e0006e diff --git a/make/lib/CoreLibraries.gmk b/make/lib/CoreLibraries.gmk index c8e4815e1174bbd934ced90764cfc13cce43809e..b40b417ade8d9e4b1d9c178514db83566ac8d382 100644 --- a/make/lib/CoreLibraries.gmk +++ b/make/lib/CoreLibraries.gmk @@ -141,6 +141,7 @@ LIBJAVA_SRC_DIRS += $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/java/l $(JDK_TOPDIR)/src/share/native/java/nio \ $(JDK_TOPDIR)/src/share/native/java/security \ $(JDK_TOPDIR)/src/share/native/common \ + $(JDK_TOPDIR)/src/share/native/com/alibaba/jwarmup \ $(JDK_TOPDIR)/src/share/native/sun/misc \ $(JDK_TOPDIR)/src/share/native/sun/reflect \ $(JDK_TOPDIR)/src/share/native/java/util \ diff --git a/make/mapfiles/libjava/mapfile-vers b/make/mapfiles/libjava/mapfile-vers index 1168c79951debe58a8c1ec806d735e30db4ea0e4..94c26f91f9d766ecda8931b489c3205a8ab0eb1b 100644 --- a/make/mapfiles/libjava/mapfile-vers +++ b/make/mapfiles/libjava/mapfile-vers @@ -215,6 +215,7 @@ SUNWprivate_1.1 { Java_java_lang_System_setIn0; Java_java_lang_System_setOut0; Java_java_lang_Thread_registerNatives; + Java_com_alibaba_jwarmup_JWarmUp_registerNatives; Java_java_lang_Throwable_fillInStackTrace; Java_java_lang_Throwable_getStackTraceDepth; Java_java_lang_Throwable_getStackTraceElement; diff --git a/make/mapfiles/libjava/reorder-x86 b/make/mapfiles/libjava/reorder-x86 index e0566b325d7f00a71e69ea2831b998715c514002..f65a66ebe3caedcc937757690ba2cef8b093b2be 100644 --- a/make/mapfiles/libjava/reorder-x86 +++ b/make/mapfiles/libjava/reorder-x86 @@ -10,6 +10,7 @@ text: .text%collapse: OUTPUTDIR/canonicalize_md.o; text: .text%Java_java_lang_Object_registerNatives; text: .text%Java_java_lang_System_registerNatives; text: .text%Java_java_lang_Thread_registerNatives; +text: .text%Java_com_alibaba_jwarmup_JWarmUp_registerNatives; text: .text%Java_java_security_AccessController_getStackAccessControlContext; text: .text%Java_java_security_AccessController_getInheritedAccessControlContext; text: .text%Java_java_lang_ClassLoader_registerNatives; diff --git a/src/share/classes/com/alibaba/jwarmup/JWarmUp.java b/src/share/classes/com/alibaba/jwarmup/JWarmUp.java new file mode 100644 index 0000000000000000000000000000000000000000..947a487114165e191deb36aef12dfef8b5e8732b --- /dev/null +++ b/src/share/classes/com/alibaba/jwarmup/JWarmUp.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2019 Alibaba Group Holding Limited. 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. Alibaba 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. + */ + +package com.alibaba.jwarmup; + +public class JWarmUp { + + /* Make sure registerNatives is the first thing does. */ + private static native void registerNatives(); + + static { + registerNatives(); + } + + private static boolean hasNotified = false; + + /** + * Notify jvm that application startup is done. + *

+ * Should be explicitly call after startup of application if + * CompilationWarmUpOptimistic is off. Otherwise, it does + * nothing and just prints a warning message. + * + * @version 1.8 + */ + public static synchronized void notifyApplicationStartUpIsDone() { + if (!hasNotified) { + hasNotified = true; + notifyApplicationStartUpIsDone0(); + } + } + + /** + * Notify jvm to deoptimize warmup methods + *

+ * Should be explicitly call after startup of application + * and warmup compilation is completed + * vm option CompilationWarmUpExplicitDeopt must be on + * Otherwise, it does nothing and just prints a warning message. + * + * @version 1.8 + */ + public static synchronized void notifyJVMDeoptWarmUpMethods() { + if (hasNotified && checkIfCompilationIsComplete()) { + notifyJVMDeoptWarmUpMethods0(); + } + } + + /** + * Check if the last compilation submitted by JWarmUp is complete. + *

+ * call this method after notifyApplicationStartUpIsDone + * + * @return true if the last compilation task is complete. + * + * @version 1.8 + */ + public static synchronized boolean checkIfCompilationIsComplete() { + if (!hasNotified) { + throw new IllegalStateException("Must call checkIfCompilationIsComplete() after notifyApplicationStartUpIsDone()"); + } else { + return checkIfCompilationIsComplete0(); + } + } + + + /** + * dummy function used internal, DO NOT call this + */ + private void dummy() { + throw new UnsupportedOperationException("dummy function"); + } + + private native static void notifyApplicationStartUpIsDone0(); + + private native static boolean checkIfCompilationIsComplete0(); + + private native static void notifyJVMDeoptWarmUpMethods0(); +} diff --git a/src/share/javavm/export/jvm.h b/src/share/javavm/export/jvm.h index 2dc2e202127e2f471cf8eb2c799c3825e4ad25dd..d544d4b6f50a709205d2147fe1b1e26cbf55b739 100644 --- a/src/share/javavm/export/jvm.h +++ b/src/share/javavm/export/jvm.h @@ -330,6 +330,15 @@ JNIEXPORT jclass JNICALL JVM_LoadClass0(JNIEnv *env, jobject obj, jclass currClass, jstring currClassName); +JNIEXPORT void JNICALL +JVM_NotifyApplicationStartUpIsDone(JNIEnv *env, jclass clz); + +JNIEXPORT jboolean JNICALL +JVM_CheckJWarmUpCompilationIsComplete(JNIEnv *env, jclass clz); + +JNIEXPORT void JNICALL +JVM_NotifyJVMDeoptWarmUpMethods(JNIEnv* env, jclass clz); + /* * java.lang.reflect.Array */ diff --git a/src/share/native/com/alibaba/jwarmup/JWarmUp.c b/src/share/native/com/alibaba/jwarmup/JWarmUp.c new file mode 100644 index 0000000000000000000000000000000000000000..7962395b19665fad1a288bb2b69bfdf5d7af492d --- /dev/null +++ b/src/share/native/com/alibaba/jwarmup/JWarmUp.c @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2019 Alibaba Group Holding Limited. 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. Alibaba 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. + */ + +#include "jni.h" +#include "jvm.h" +#include "com_alibaba_jwarmup_JWarmUp.h" + +#define ARRAY_LENGTH(a) (sizeof(a)/sizeof(a[0])) + +static JNINativeMethod jwarmup_methods[] = { + {"notifyApplicationStartUpIsDone0","()V", (void *)&JVM_NotifyApplicationStartUpIsDone}, + {"checkIfCompilationIsComplete0","()Z", (void *)&JVM_CheckJWarmUpCompilationIsComplete}, + {"notifyJVMDeoptWarmUpMethods0","()V", (void *)&JVM_NotifyJVMDeoptWarmUpMethods} +}; + +JNIEXPORT void JNICALL +Java_com_alibaba_jwarmup_JWarmUp_registerNatives(JNIEnv *env, jclass cls) +{ + (*env)->RegisterNatives(env, cls, jwarmup_methods, ARRAY_LENGTH(jwarmup_methods)); +}